emacs-orgmode
[Top][All Lists]
Advanced

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

[O] org-date-toggle-inactive


From: Johan Sandblom
Subject: [O] org-date-toggle-inactive
Date: Tue, 25 Sep 2012 20:09:26 +0200
User-agent: Binero Webmail/0.8.0

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)


--
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



reply via email to

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