Browse Source

New option org-tags-sort-function.

This allows tags to be sorted by string<, string> or a custom function.
Patch submitted by James TD Smith.
Bastien Guerry 16 years ago
parent
commit
69e14025f4
2 changed files with 20 additions and 0 deletions
  1. 6 0
      lisp/ChangeLog
  2. 14 0
      lisp/org.el

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-07-17  James TD Smith  <ahktenzero@mohorovi.cc>
+
+	* 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  <bzg@altern.org>
 
 	* org-clock.el (org-clock-in-prepare-hook): New hook.

+ 14 - 0
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 ":")))