emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Utility functions for setting/clearing categories
@ 2010-01-29 17:15 Ryan Thompson
  0 siblings, 0 replies; only message in thread
From: Ryan Thompson @ 2010-01-29 17:15 UTC (permalink / raw)
  To: Org-Mode List


[-- Attachment #1.1: Type: text/plain, Size: 1733 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 2019 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-01-29 17:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-29 17:15 Utility functions for setting/clearing categories Ryan Thompson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).