unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH RESEND 1/2] emacs: Add new customization option to sort saved searches
Date: Fri, 23 Sep 2011 21:57:37 +0300	[thread overview]
Message-ID: <2c339e4237916241913179525f48efb7431c4e5d.1316803382.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1316803382.git.jani@nikula.org>
In-Reply-To: <cover.1316803382.git.jani@nikula.org>

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 |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 65fde75..6c8e265 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -42,6 +42,26 @@
   :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.")
 
@@ -440,6 +460,10 @@ Complete list of currently available key bindings:
 	     (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)
-- 
1.7.4.1

  reply	other threads:[~2011-09-23 18:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-23 18:57 [PATCH RESEND 0/2] emacs: sort saved searches Jani Nikula
2011-09-23 18:57 ` Jani Nikula [this message]
2011-09-23 18:57 ` [PATCH RESEND 2/2] emacs: Make saving new saved searches append, not prepend Jani Nikula
2011-11-23  2:59 ` [PATCH RESEND 0/2] emacs: sort saved searches David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2c339e4237916241913179525f48efb7431c4e5d.1316803382.git.jani@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.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).