From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Leech-Pepin Subject: Re: org-date-toggle-inactive Date: Tue, 25 Sep 2012 14:26:28 -0400 Message-ID: References: <8fff6f801a80accbc63d7607c303ed59@ndblom.se> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e6d77fa832af2504ca8ad821 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGZq3-0001lI-CZ for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 14:26:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGZq1-0001qi-QC for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 14:26:31 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:49844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGZq1-0001qK-G9 for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 14:26:29 -0400 Received: by wibhj13 with SMTP id hj13so827596wib.12 for ; Tue, 25 Sep 2012 11:26:28 -0700 (PDT) In-Reply-To: <8fff6f801a80accbc63d7607c303ed59@ndblom.se> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Johan Sandblom Cc: Emacs orgmode --0016e6d77fa832af2504ca8ad821 Content-Type: text/plain; charset=UTF-8 Hello Johan, On 25 September 2012 14:09, Johan Sandblom 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 --0016e6d77fa832af2504ca8ad821 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 fil= e 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 apprecia= te feedback.

Regards, Johan

(setq org-date-regexp
=C2=A0 =C2=A0 =C2=A0 "[\\[<][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-= 9] [[:alpha:]]\\{2,3\\} ?.*?[]>]")

(defun org-at-date-p ()
=C2=A0 "Am I inside an org date?"
=C2=A0 (interactive)
=C2=A0 (save-excursion
=C2=A0 =C2=A0 (if (looking-at org-date-regexp)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 t
=C2=A0 =C2=A0 =C2=A0 (if (> (skip-chars-backward "-[:alnum:]: "= ;) -40)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((left (- (point) 1)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (search-backward-regexp &q= uot;[\\[<]" left t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (looking-at org-date-regexp)<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t)))))))

(defun org-date-toggle-inactive ()
=C2=A0 (interactive)
=C2=A0 (if (org-at-date-p)
=C2=A0 =C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (search-backward-regexp "[\\[<]&= quot;)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (string-equal "<" (matc= h-string 0))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-match "[&quo= t;)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-match "<"))=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (search-forward-regexp "[]>]&quo= t;)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (string-equal ">" (matc= h-string 0))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-match "]&quo= t;)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-match ">"))=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 t))
=C2=A0 =C2=A0 nil))

(add-hook 'org-ctrl-c-ctrl-c-hook
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'org-date-toggle-inactive)
You should be able to just use =3Dorg-toggle-timestamp-type=3D
instead of your snippet.=C2=A0 It performs the check and will toggle
back and forth between active and inactive timestamps.

(add-hook 'org-ctrl-c-ctrl-c-hook
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'org-toggle-time= stamp-type)
=C2=A0

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