]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: Add new customization option to sort saved searches
authorJani Nikula <jani@nikula.org>
Fri, 23 Sep 2011 18:57:37 +0000 (21:57 +0300)
committerDavid Bremner <bremner@debian.org>
Wed, 23 Nov 2011 02:54:55 +0000 (22:54 -0400)
Add new customization option notmuch-saved-search-sort-function to sort
saved searches in user-defined order. Provide a sort function to sort the
saved searches in alphabetical order. Setting the search function to nil
causes the saved searches not to be sorted, as before. This also remains
the default. The function only affects display of the saved searches, not
the order in which they are stored by custom.

Signed-off-by: Jani Nikula <jani@nikula.org>
emacs/notmuch-hello.el

index 1a76c30abed9d79eafe1da8c30acc9ad5bf93561..917ad3bbe4e8ea45a8f52790021bee661842514a 100644 (file)
   :type 'boolean
   :group 'notmuch)
 
   :type 'boolean
   :group 'notmuch)
 
+(defun notmuch-sort-saved-searches (alist)
+  "Generate an alphabetically sorted saved searches alist."
+  (sort alist (lambda (a b) (string< (car a) (car b)))))
+
+(defcustom notmuch-saved-search-sort-function nil
+  "Function used to sort the saved searches for the notmuch-hello view.
+
+This variable controls how saved searches should be sorted. No
+sorting (nil) displays the saved searches in the order they are
+stored in `notmuch-saved-searches'. Sort alphabetically sorts the
+saved searches in alphabetical order. Custom sort function should
+be a function or a lambda expression that takes the saved
+searches alist as a parameter, and returns a new saved searches
+alist to be used."
+  :type '(choice (const :tag "No sorting" nil)
+                (const :tag "Sort alphabetically" notmuch-sort-saved-searches)
+                (function :tag "Custom sort function"
+                          :value notmuch-sort-saved-searches))
+  :group 'notmuch)
+
 (defvar notmuch-hello-indent 4
   "How much to indent non-headers.")
 
 (defvar notmuch-hello-indent 4
   "How much to indent non-headers.")
 
@@ -440,6 +460,10 @@ Complete list of currently available key bindings:
             (widest (max saved-widest alltags-widest)))
 
        (when saved-alist
             (widest (max saved-widest alltags-widest)))
 
        (when saved-alist
+         ;; Sort saved searches if required.
+         (when notmuch-saved-search-sort-function
+           (setq saved-alist
+                 (funcall notmuch-saved-search-sort-function saved-alist)))
          (widget-insert "\nSaved searches: ")
          (widget-create 'push-button
                         :notify (lambda (&rest ignore)
          (widget-insert "\nSaved searches: ")
          (widget-create 'push-button
                         :notify (lambda (&rest ignore)