Hello Johan,

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

Reply via email to