emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Johan Sandblom <js@ndblom.se>
To: Emacs orgmode <emacs-orgmode@gnu.org>
Subject: org-date-toggle-inactive
Date: Tue, 25 Sep 2012 20:09:26 +0200	[thread overview]
Message-ID: <8fff6f801a80accbc63d7607c303ed59@ndblom.se> (raw)

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	other threads:[~2012-09-25 18:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-25 18:09 Johan Sandblom [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fff6f801a80accbc63d7607c303ed59@ndblom.se \
    --to=js@ndblom.se \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).