From mboxrd@z Thu Jan 1 00:00:00 1970 From: James TD Smith Subject: [misc-new-features 3/5] Add an option to sort tags automatically. Date: Mon, 13 Jul 2009 09:28:00 +0100 Message-ID: <1247473682-23338-4-git-send-email-ahktenzero@mohorovi.cc> References: <1247473682-23338-1-git-send-email-ahktenzero@mohorovi.cc> <1247473682-23338-2-git-send-email-ahktenzero@mohorovi.cc> <1247473682-23338-3-git-send-email-ahktenzero@mohorovi.cc> Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MQHaU-0002nM-FU for emacs-orgmode@gnu.org; Mon, 13 Jul 2009 05:12:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MQHaP-0002lJ-EW for emacs-orgmode@gnu.org; Mon, 13 Jul 2009 05:12:41 -0400 Received: from [199.232.76.173] (port=49002 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MQHaP-0002lD-3D for emacs-orgmode@gnu.org; Mon, 13 Jul 2009 05:12:37 -0400 Received: from 81-86-40-42.dsl.pipex.com ([81.86.40.42]:62600 helo=yog-sothoth.mohorovi.cc) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MQHaO-0008Sq-EG for emacs-orgmode@gnu.org; Mon, 13 Jul 2009 05:12:36 -0400 In-Reply-To: <1247473682-23338-3-git-send-email-ahktenzero@mohorovi.cc> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --- lisp/ChangeLog | 3 +++ lisp/org.el | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 348ade3..9ce7a17 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -11,6 +11,9 @@ SINCE_IA. These give the time since any active or inactive timestamp in an entry. (org-special-properties): Add SINCE, SINCE_IA. + (org-tags-sort-function): Add custom declaration for tags + sorting function. + (org-set-tags): Sort tags if org-tags-sort-function is set 2009-07-08 Carsten Dominik diff --git a/lisp/org.el b/lisp/org.el index d08155a..854d09c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2337,6 +2337,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 @@ -10840,11 +10849,17 @@ 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 "") + (setq tags "") (unless (string-match ":$" tags) (setq tags (concat tags ":"))) (unless (string-match "^:" tags) (setq tags (concat ":" tags)))) + ;; Insert new tags at the correct column (beginning-of-line 1) (cond -- 1.6.3.3