unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: William Casarin <jb55@jb55.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2] emacs: replace oldest-first with sort-order
Date: Sat,  9 Sep 2017 17:35:26 -0700	[thread overview]
Message-ID: <20170910003526.21661-1-jb55@jb55.com> (raw)
In-Reply-To: <20170910001710.1570-1-jb55@jb55.com>

This generalizes notmuch-search-oldest-first to
notmuch-search-sort-order. notmuch-search-sort-order can now be one
of:

  * oldest-first
  * newest-first
  * subject-ascending
  * subject-descending
  * from-ascending
  * from-descending

Order toggling now simply inverts the corresponding option.
---

Was missing notmuch-hello changes from previous patch :(

 emacs/notmuch-hello.el | 14 ++++++++------
 emacs/notmuch-jump.el  | 13 +++++--------
 emacs/notmuch-lib.el   | 10 ++++++++--
 emacs/notmuch-tree.el  |  2 +-
 emacs/notmuch.el       | 52 ++++++++++++++++++++++++++++----------------------
 5 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c858a20b..8f700f03 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -95,7 +95,11 @@ 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 "Subject-ascending" subject-ascending)
+				    (const :tag "Subject-descending" subject-descending)
+				    (const :tag "From-ascending" from-ascending)
+				    (const :tag "From-descending" from-descending)))
 		     (group :format "%v" :inline t (const :format "" :search-type)
 			    (choice :tag " Search Type"
 				    (const :tag "Search mode" nil)
@@ -575,10 +579,8 @@ with `notmuch-hello-query-counts'."
 		  (widget-insert (make-string column-indent ? )))
 	      (let* ((name (plist-get elem :name))
 		     (query (plist-get elem :query))
-		     (oldest-first (case (plist-get elem :sort-order)
-				     (newest-first nil)
-				     (oldest-first t)
-				     (otherwise notmuch-search-oldest-first)))
+		     (order (plist-get elem :sort-order))
+		     (sort-order (if (not order) notmuch-search-sort-order order))
 		     (search-type (eq (plist-get elem :search-type) 'tree))
 		     (msg-count (plist-get elem :count)))
 		(widget-insert (format "%8s "
@@ -586,7 +588,7 @@ with `notmuch-hello-query-counts'."
 		(widget-create 'push-button
 			       :notify #'notmuch-hello-widget-search
 			       :notmuch-search-terms query
-			       :notmuch-search-oldest-first oldest-first
+			       :notmuch-search-sort-order sort-order
 			       :notmuch-search-type search-type
 			       name)
 		(setq column-indent
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 3e20b8c7..5fd654fb 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -48,17 +48,14 @@ fast way to jump to a saved search from anywhere in Notmuch."
       (let* ((saved-search (notmuch-hello-saved-search-to-plist saved-search))
 	     (key (plist-get saved-search :key)))
 	(when key
-	  (let ((name (plist-get saved-search :name))
-		(query (plist-get saved-search :query))
-		(oldest-first
-		 (case (plist-get saved-search :sort-order)
-		   (newest-first nil)
-		   (oldest-first t)
-		   (otherwise (default-value 'notmuch-search-oldest-first)))))
+	  (let* ((name (plist-get saved-search :name))
+		 (query (plist-get saved-search :query))
+		 (order (plist-get saved-search :sort-order))
+		 (sort-order (if (not order) notmuch-search-sort-order order)))
 	    (push (list key name
 			(if (eq (plist-get saved-search :search-type) 'tree)
 			    `(lambda () (notmuch-tree ',query))
-			  `(lambda () (notmuch-search ',query ',oldest-first))))
+			  `(lambda () (notmuch-search ',query ',sort-order))))
 		  action-map)))))
     (setq action-map (nreverse action-map))
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 010be454..ee7b67d3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -92,14 +92,20 @@ $PATH)."
   :type 'string
   :group 'notmuch-external)
 
-(defcustom notmuch-search-oldest-first t
+(defcustom notmuch-search-sort-order 'oldest-first
   "Show the oldest mail first when searching.
 
 This variable defines the default sort order for displaying
 search results. Note that any filtered searches created by
 `notmuch-search-filter' retain the search order of the parent
 search."
-  :type 'boolean
+  :type '(choice :tag " Sort Order"
+		 (const :tag "Oldest-first" oldest-first)
+		 (const :tag "Newest-first" newest-first)
+		 (const :tag "Subject-ascending" subject-ascending)
+		 (const :tag "Subject-descending" subject-descending)
+		 (const :tag "From-ascending" from-ascending)
+		 (const :tag "From-descending" from-descending))
   :group 'notmuch-search)
 
 (defcustom notmuch-poll-script nil
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index c00315e8..b95ff71f 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -33,7 +33,7 @@
 (require 'notmuch-parser)
 
 (eval-when-compile (require 'cl))
-(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line))
+(declare-function notmuch-search "notmuch" (&optional query sort-order target-thread target-line))
 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
 (declare-function notmuch-read-query "notmuch" (prompt))
 (declare-function notmuch-search-find-thread-id "notmuch" (&optional bare))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 44402f8a..334458b7 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -380,7 +380,7 @@ Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
   (make-local-variable 'notmuch-search-query-string)
-  (make-local-variable 'notmuch-search-oldest-first)
+  (make-local-variable 'notmuch-search-sort-order)
   (make-local-variable 'notmuch-search-target-thread)
   (make-local-variable 'notmuch-search-target-line)
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
@@ -959,7 +959,7 @@ PROMPT is the string to prompt with."
 
 (put 'notmuch-search 'notmuch-doc "Search for messages.")
 ;;;###autoload
-(defun notmuch-search (&optional query oldest-first target-thread target-line no-display)
+(defun notmuch-search (&optional query sort-order target-thread target-line no-display)
   "Display threads matching QUERY in a notmuch-search buffer.
 
 If QUERY is nil, it is read interactively from the minibuffer.
@@ -982,7 +982,7 @@ the configured default sort order."
     nil
     ;; Use the default search order (if we're doing a search from a
     ;; search buffer, ignore any buffer-local overrides)
-    (default-value 'notmuch-search-oldest-first)))
+    (default-value 'notmuch-search-sort-order)))
 
   (let* ((query (or query (notmuch-read-query "Notmuch search: ")))
 	 (buffer (get-buffer-create (notmuch-search-buffer-title query))))
@@ -993,29 +993,26 @@ the configured default sort order."
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
     (set 'notmuch-search-query-string query)
-    (set 'notmuch-search-oldest-first oldest-first)
+    (set 'notmuch-search-sort-order sort-order)
     (set 'notmuch-search-target-thread target-thread)
     (set 'notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
     (let ((proc (get-buffer-process (current-buffer)))
 	  (inhibit-read-only t))
       (if proc
-	  (error "notmuch search process already running for query `%s'" query)
-	)
+	  (error "notmuch search process already running for query `%s'" query))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
-	(let ((proc (notmuch-start-notmuch
-		     "notmuch-search" buffer #'notmuch-search-process-sentinel
-		     "search" "--format=sexp" "--format-version=4"
-		     (if oldest-first
-			 "--sort=oldest-first"
-		       "--sort=newest-first")
-		     query))
-	      ;; Use a scratch buffer to accumulate partial output.
-	      ;; This buffer will be killed by the sentinel, which
-	      ;; should be called no matter how the process dies.
-	      (parse-buf (generate-new-buffer " *notmuch search parse*")))
+	(let* ((proc (notmuch-start-notmuch
+		      "notmuch-search" buffer #'notmuch-search-process-sentinel
+		      "search" "--format=sexp" "--format-version=4"
+		      (concat "--sort=" (symbol-name sort-order))
+		      query))
+	       ;; Use a scratch buffer to accumulate partial output.
+	       ;; This buffer will be killed by the sentinel, which
+	       ;; should be called no matter how the process dies.
+	       (parse-buf (generate-new-buffer " *notmuch search parse*")))
 	  (process-put proc 'parse-buf parse-buf)
 	  (set-process-filter proc 'notmuch-search-process-filter)
 	  (set-process-query-on-exit-flag proc nil))))
@@ -1031,20 +1028,29 @@ thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
   (let ((target-line (line-number-at-pos))
-	(oldest-first notmuch-search-oldest-first)
+	(sort-order notmuch-search-sort-order)
 	(target-thread (notmuch-search-find-thread-id 'bare))
 	(query notmuch-search-query-string))
     ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
+    (notmuch-search query sort-order target-thread target-line t)
     (goto-char (point-min))))
 
+(defun notmuch-toggle-order (order)
+  (case order
+    (newest-first 'oldest-first)
+    (oldest-first 'newest-first)
+    (from-ascending 'from-descending)
+    (from-descending 'from-ascending)
+    (subject-ascending 'subject-descending)
+    (subject-descending 'subject-ascending)))
+
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
 
 This command toggles the sort order for the current search. The
-default sort order is defined by `notmuch-search-oldest-first'."
+default sort order is defined by `notmuch-search-sort-order'."
   (interactive)
-  (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first))
+  (set 'notmuch-search-sort-order (notmuch-toggle-order notmuch-search-sort-order))
   (notmuch-search-refresh-view))
 
 (defun notmuch-group-disjunctive-query-string (query-string)
@@ -1068,7 +1074,7 @@ current search results AND the additional query string provided."
     (notmuch-search (if (string= grouped-original-query "*")
 			grouped-query
 		      (concat grouped-original-query " and " grouped-query))
-		    notmuch-search-oldest-first)))
+		    notmuch-search-sort-order)))
 
 (defun notmuch-search-filter-by-tag (tag)
   "Filter the current search results based on a single tag.
@@ -1077,7 +1083,7 @@ Runs a new search matching only messages that match both the
 current search results AND that are tagged with the given tag."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: ")))
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
+  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-sort-order))
 
 ;;;###autoload
 (defun notmuch ()
-- 
2.13.2

  reply	other threads:[~2017-09-10  0:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 16:00 [PATCH 1/3] sorting: add the ability to sort by from and subject William Casarin
2017-09-04 16:00 ` [PATCH 2/3] sorting: update ruby bindings for " William Casarin
2017-09-04 16:00 ` [PATCH 3/3] sorting: update man page William Casarin
2017-09-04 19:04 ` [PATCH 1/3] sorting: add the ability to sort by from and subject Jani Nikula
     [not found]   ` <87wp5ew7v6.fsf@jb55.com>
2017-09-04 20:33     ` William Casarin
2017-09-04 22:02       ` David Bremner
2017-09-07 19:42         ` William Casarin
2017-09-10  0:17           ` [PATCH] emacs: replace oldest-first with sort-order William Casarin
2017-09-10  0:35             ` William Casarin [this message]
2017-09-10  1:21               ` [PATCH v2] " William Casarin

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=20170910003526.21661-1-jb55@jb55.com \
    --to=jb55@jb55.com \
    --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).