emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Utility functions for setting/clearing categories


From: Ryan Thompson
Subject: [Orgmode] Utility functions for setting/clearing categories
Date: Fri, 29 Jan 2010 09:15:18 -0800

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]