emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-date-toggle-inactive
@ 2012-09-25 18:09 Johan Sandblom
  2012-09-25 18:26 ` org-date-toggle-inactive Jonathan Leech-Pepin
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Sandblom @ 2012-09-25 18:09 UTC (permalink / raw)
  To: Emacs orgmode

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-26  6:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-25 18:09 org-date-toggle-inactive Johan Sandblom
2012-09-25 18:26 ` org-date-toggle-inactive Jonathan Leech-Pepin
2012-09-25 21:44   ` org-date-toggle-inactive Bastien
2012-09-26  6:33     ` org-date-toggle-inactive Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).