From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 68AD96DE0119 for ; Sat, 9 Sep 2017 17:35:46 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.012 X-Spam-Level: X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5 tests=[AWL=0.097, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FSL_HELO_NON_FQDN_1=0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R95FYL-_rYmk for ; Sat, 9 Sep 2017 17:35:45 -0700 (PDT) Received: from charon (jb55.com [45.79.91.128]) by arlo.cworth.org (Postfix) with ESMTPS id 550E86DE00D2; Sat, 9 Sep 2017 17:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d= jb55.com; h=from:to:subject:date:message-id; s=default; bh=UfSGwHevIAJ9kY6OP+S60PDDQzysb+1YDCdwB8Jxb3o=; b=qHJw3JFJraCbdqL73DsV28IkmsaGqSgrjoBqi6q5CznDL0C7BIwJr2ldoNXMGGW6MtinXKU4hIUjz8/Xi3QmNfaRrDhJj59i6lGgLuBk1OyiVsHvYrOjXNhlfLghLNQqflSHfOTTWZ+byGGi3bFXHwDYoVx63ecuctR8bbXBFujoyc5zwrF7nyd1jgPW3afPM+uUi0rjMK/sd5FDBoeh0d9PIkTyTrsKt3uDFgUpjI8e9V0eim39JZ3Gf2kEmGCBIjVsuQvB68tR2+DBBWKkqS+bkXEB3VhY+QQLdAPjgY7oWKWYm1oW9IP/pxOFb0+rw1tylH59M7DrrpgBkwrS3A== Received: from jb55.com (70-36-49-138.dyn.novuscom.net [70.36.49.138]) by jb55.com (OpenSMTPD) with ESMTPSA id 5429c27e TLS version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO; Sun, 10 Sep 2017 00:35:44 +0000 (UTC) From: William Casarin To: notmuch@notmuchmail.org Subject: [PATCH v2] emacs: replace oldest-first with sort-order Date: Sat, 9 Sep 2017 17:35:26 -0700 Message-Id: <20170910003526.21661-1-jb55@jb55.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170910001710.1570-1-jb55@jb55.com> References: <20170910001710.1570-1-jb55@jb55.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Sep 2017 00:35:46 -0000 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