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

* Re: org-date-toggle-inactive
  2012-09-25 18:09 org-date-toggle-inactive Johan Sandblom
@ 2012-09-25 18:26 ` Jonathan Leech-Pepin
  2012-09-25 21:44   ` org-date-toggle-inactive Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Leech-Pepin @ 2012-09-25 18:26 UTC (permalink / raw)
  To: Johan Sandblom; +Cc: Emacs orgmode

[-- Attachment #1: Type: text/plain, Size: 2018 bytes --]

Hello Johan,

On 25 September 2012 14:09, Johan Sandblom <js@ndblom.se> 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

[-- Attachment #2: Type: text/html, Size: 3058 bytes --]

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

* Re: org-date-toggle-inactive
  2012-09-25 18:26 ` org-date-toggle-inactive Jonathan Leech-Pepin
@ 2012-09-25 21:44   ` Bastien
  2012-09-26  6:33     ` org-date-toggle-inactive Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2012-09-25 21:44 UTC (permalink / raw)
  To: Jonathan Leech-Pepin; +Cc: Emacs orgmode, Johan Sandblom

Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> writes:

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

Or simply M-<up/down> on the angle/bracket of the time-stamp.

-- 
 Bastien

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

* Re: org-date-toggle-inactive
  2012-09-25 21:44   ` org-date-toggle-inactive Bastien
@ 2012-09-26  6:33     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2012-09-26  6:33 UTC (permalink / raw)
  To: Jonathan Leech-Pepin; +Cc: Emacs orgmode, Johan Sandblom

Bastien <bzg@altern.org> writes:

> Or simply M-<up/down> on the angle/bracket of the time-stamp.

Er.. that's S-<up/down> of course.

-- 
 Bastien

^ 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).