diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 643663f9c..b83dfc7b5 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-07-17 James TD Smith + + * org.el (org-tags-sort-function): New option. Users can now use + their own function to sort tags. + (org-set-tags): Use the new option to sort tags. + 2009-07-17 Bastien Guerry * org-clock.el (org-clock-in-prepare-hook): New hook. diff --git a/lisp/org.el b/lisp/org.el index 800908907..426f89020 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2339,6 +2339,15 @@ is better to limit inheritance to certain tags using the variables (const :tag "Yes, do list them" t) (const :tag "List them, indented with leading dots" indented))) +(defcustom org-tags-sort-function nil + "When set, tags are sorted using this function as a comparator" + :group 'org-tags + :type '(choice + (const :tag "No sorting" nil) + (const :tag "Alphabetical" string<) + (const :tag "Reverse alphabetical" string>) + (function :tag "Custom function" nil))) + (defvar org-tags-history nil "History of minibuffer reads for tags.") (defvar org-last-tags-completion-table nil @@ -10839,6 +10848,11 @@ With prefix ARG, realign all tags in headings in the current buffer." ;; No boolean logic, just a list (setq tags (replace-match ":" t t tags)))) + (if org-tags-sort-function + (setq tags (mapconcat 'identity + (sort (org-split-string tags (org-re "[^[:alnum:]_@]+")) + org-tags-sort-function) ":"))) + (if (string-match "\\`[\t ]*\\'" tags) (setq tags "") (unless (string-match ":$" tags) (setq tags (concat tags ":")))