[PATCH 3/3] emacs: notmuch-search: add filesize sorting

Ioan-Adrian Ratiu adi at adirat.com
Sat May 6 13:45:30 PDT 2017

Besides the previous date-based result orderings (oldest-first and
newest-first) add two more filesize-based orderings: biggest-first

The orderings are interchangeable, you can specify any one as the
default via notmuch-search-default-sort-order or as the preffered
ordering for a saved search (via the :sort-order property).

The only restriction I've imposed is that you can't toggle from a
date-based result ordering to a filesize-based one. Meaning you can
toggle as before from oldest-first to newest-first or from the new
smallest-first to biggest-first and viceversa, but you can't toggle
from oldest-first to biggest-first. I've found this kind of toggling
confusing so I've prohibited it, but enabling it is trivial if need be.

Signed-off-by: Ioan-Adrian Ratiu <adi at adirat.com>
 emacs/notmuch-hello.el |  9 ++++++---
 emacs/notmuch-lib.el   |  4 +++-
 emacs/notmuch.el       | 12 ++++++++++--
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 3ba2a16b..51117577 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -95,7 +95,9 @@ searches so they still work in customize."
 			    (choice :tag " Sort Order"
 				    (const :tag "Default" nil)
 				    (const :tag "Oldest-first" oldest-first)
-				    (const :tag "Newest-first" newest-first)))
+				    (const :tag "Newest-first" newest-first)
+				    (const :tag "Biggest-first" biggest-first)
+				    (const :tag "Smallest-first" smallest-first)))
 		     (group :format "%v" :inline t (const :format "" :search-type)
 			    (choice :tag " Search Type"
 				    (const :tag "Search mode" nil)
@@ -120,8 +122,9 @@ a plist. Supported properties are
                    shown. If not present then the :query property
                    is used.
   :sort-order      Specify the sort order to be used for the search.
-                   Possible values are 'oldest-first 'newest-first or
-                   nil. Nil means use the default sort order.
+                   Possible values are 'oldest-first 'newest-first
+                   'biggest-first 'smallest-first or nil.
+                   Nil means use the default sort order.
   :search-type     Specify whether to run the search in search-mode
                    or tree mode. Set to 'tree to specify tree
                    mode, set to nil (or anything except tree) to
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 34ffa712..ded75c2e 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -100,7 +100,9 @@ search results. Note that any filtered searches created by
 `notmuch-search-filter' retain the search order of the parent
   :type '(choice (const :tag "oldest-first" oldest-first)
-		 (const :tag "newest-first" newest-first))
+		 (const :tag "newest-first" newest-first)
+		 (const :tag "biggest-first" biggest-first)
+		 (const :tag "smallest-first" smallest-first))
   :group 'notmuch-search)
 (defcustom notmuch-poll-script nil
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 248b97c7..4ba29880 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1023,12 +1023,20 @@ same relative position within the new buffer."
   "Toggle the current search order.
 This command toggles the sort order for the current search. The
-default sort order is defined by `notmuch-search-default-sort-order'."
+default sort order is defined by `notmuch-search-default-sort-order'.
+There are two types of orderings: by date and by filesize. Toggling is
+permitted only within a specific type (for ex. you can't toggle from
+oldest-first to smallest-first, only from oldest-first to newest-first)
+to avoid confusion."
   (setq notmuch-search-default-sort-order
 	(case notmuch-search-default-sort-order
 	  ('oldest-first 'newest-first)
-	  (otherwise 'oldest-first)))
+	  ('newest-first 'oldest-first)
+	  ('biggest-first 'smallest-first)
+	  ('smallest-first 'biggest-first)
+	  (otherwise notmuch-search-default-sort-order)))
 (defun notmuch-group-disjunctive-query-string (query-string)

More information about the notmuch mailing list