From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryan Thompson Subject: Utility functions for setting/clearing categories Date: Fri, 29 Jan 2010 09:15:18 -0800 Message-ID: <2a4ba2fd1001290915k1cd7dasfb5bf0ba2b49efb6@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1312255127==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NauRc-0002yj-LR for emacs-orgmode@gnu.org; Fri, 29 Jan 2010 12:15:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NauRY-0002wf-1d for emacs-orgmode@gnu.org; Fri, 29 Jan 2010 12:15:44 -0500 Received: from [199.232.76.173] (port=32906 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NauRX-0002wU-Nk for emacs-orgmode@gnu.org; Fri, 29 Jan 2010 12:15:39 -0500 Received: from mail-iw0-f203.google.com ([209.85.223.203]:45353) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NauRX-0000fx-4i for emacs-orgmode@gnu.org; Fri, 29 Jan 2010 12:15:39 -0500 Received: by iwn41 with SMTP id 41so2149188iwn.12 for ; Fri, 29 Jan 2010 09:15:38 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-Mode List --===============1312255127== Content-Type: multipart/alternative; boundary=005045014455cc4da1047e50c829 --005045014455cc4da1047e50c829 Content-Type: text/plain; charset=ISO-8859-1 Hi all, If anyone out there makes heavy use of categories and is sick of going through org-sort-property and org-delete-property to handle them, here's a pair of conveience functions for directly manipulating categories. It's a pity that emacs doesn't seem to support partially applying an interactive function and then having it interactively prompt for the remaining arguments. That would make org-set-category as short as org-delete-category. Moset of the code is copied from org-set-property's interactive definition, and then modified. -Ryan (defun org-set-category (property value) "In the current entry, set category to VALUE. When called interactively, this will prompt for a value, offering completion either on allowed values (via an inherited xxx_ALL property) or on existing values in other instances of this property in the current file." (interactive (let* ((completion-ignore-case t) (prop "CATEGORY") (cur (org-entry-get nil prop)) (allowed (org-property-get-allowed-values nil prop 'table)) (existing (mapcar 'list (org-property-values prop))) (val (if allowed (org-completing-read "Value: " allowed nil 'req-match) (let (org-completion-use-ido org-completion-use-iswitchb) (org-completing-read (concat "Value " (if (and cur (string-match "\\S-" cur)) (concat "[" cur "]") "") ": ") existing nil nil "" nil cur))))) (list prop (if (equal val "") cur val)))) (unless (equal (org-entry-get nil property) value) (org-entry-put nil property value))) (defun org-delete-category () "Delete the category of the current item." (interactive) (org-delete-property "CATEGORY")) --005045014455cc4da1047e50c829 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi all,

If anyone out there makes heavy use of categories and is sic= k of going through org-sort-property and org-delete-property to handle them= , here's a pair of conveience functions for directly manipulating categ= ories. It's a pity that emacs doesn't seem to support partially app= lying an interactive function and then having it interactively prompt for t= he remaining arguments. That would make org-set-category as short as org-de= lete-category. Moset of the code is copied from org-set-property's inte= ractive definition, and then modified.

-Ryan

(defun org-set-category (property value)
=A0 "In t= he current entry, set category to VALUE.
When called interactively, this= will prompt for a value, offering
completion either on allowed values (= via an inherited xxx_ALL
property) or on existing values in other instances of this
property in t= he current file."
=A0 (interactive
=A0=A0 (let* ((completion-ign= ore-case t)
=A0=A0=A0 =A0 (prop "CATEGORY")
=A0=A0=A0 =A0 (= cur (org-entry-get nil prop))
=A0=A0=A0 =A0 (allowed (org-property-get-allowed-values nil prop 'table= ))
=A0=A0=A0 =A0 (existing (mapcar 'list (org-property-values prop))= )
=A0=A0=A0 =A0 (val (if allowed
=A0=A0=A0 =A0=A0=A0 =A0=A0 (org-comp= leting-read "Value: " allowed nil 'req-match)
=A0=A0=A0 =A0=A0=A0 =A0(let (org-completion-use-ido org-completion-use-iswi= tchb)
=A0=A0=A0 =A0=A0=A0 =A0=A0 (org-completing-read
=A0=A0=A0 =A0= =A0=A0 =A0=A0=A0 (concat "Value " (if (and cur (string-match &quo= t;\\S-" cur))
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 (co= ncat "[" cur "]") "")
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ": ")
=A0=A0=A0 =A0=A0= =A0 =A0=A0=A0 existing nil nil "" nil cur)))))
=A0=A0=A0=A0 (l= ist prop (if (equal val "") cur val))))
=A0 (unless (equal (or= g-entry-get nil property) value)
=A0=A0=A0 (org-entry-put nil property v= alue)))

(defun org-delete-category ()
=A0 "Delete the category of the c= urrent item."
=A0 (interactive)
=A0 (org-delete-property "C= ATEGORY"))
--005045014455cc4da1047e50c829-- --===============1312255127== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============1312255127==--