emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-date-toggle-inactive


From: Jonathan Leech-Pepin
Subject: Re: [O] org-date-toggle-inactive
Date: Tue, 25 Sep 2012 14:26:28 -0400

Hello Johan,

On 25 September 2012 14:09, Johan Sandblom <address@hidden> wrote:
I wrote the following which allows me ctrl-c-ctrl-c on a date in an org file and thereby toggle the inactive state of the date. I find it useful when applying to courses that I am later [not] admitted to. Perhaps it is useful to someone else. Perhaps also there are obvious improvements to the code. Lastly, perhaps there is a better place to submit such snippets. I appreciate feedback.

Regards, Johan

(setq org-date-regexp
      "[\\[<][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [[:alpha:]]\\{2,3\\} ?.*?[]>]")

(defun org-at-date-p ()
  "Am I inside an org date?"
  (interactive)
  (save-excursion
    (if (looking-at org-date-regexp)
        t
      (if (> (skip-chars-backward "-[:alnum:]: ") -40)
          (let ((left (- (point) 1)))
            (progn
              (search-backward-regexp "[\\[<]" left t)
            (if (looking-at org-date-regexp)
                t)))))))

(defun org-date-toggle-inactive ()
  (interactive)
  (if (org-at-date-p)
      (save-excursion
        (progn
          (search-backward-regexp "[\\[<]")
          (if (string-equal "<" (match-string 0))
              (replace-match "[")
            (replace-match "<"))
          (search-forward-regexp "[]>]")
          (if (string-equal ">" (match-string 0))
              (replace-match "]")
            (replace-match ">"))
          t))
    nil))

(add-hook 'org-ctrl-c-ctrl-c-hook
          'org-date-toggle-inactive)

You should be able to just use =org-toggle-timestamp-type=
instead of your snippet.  It performs the check and will toggle
back and forth between active and inactive timestamps.

(add-hook 'org-ctrl-c-ctrl-c-hook
          'org-toggle-timestamp-type)
 

--
Johan Sandblom, MD PhD
m +46735521477
What is wanted is not the will to believe, but the
will to find out, which is the exact opposite
--Bertrand Russell


Regards,

--
Jon

reply via email to

[Prev in Thread] Current Thread [Next in Thread]