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

Reply via email to