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 B4C276DE0BAC for ; Thu, 18 May 2017 15:25:47 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.085 X-Spam-Level: X-Spam-Status: No, score=-0.085 tagged_above=-999 required=5 tests=[AWL=-0.064, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] 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 SgtuY9I7WYX1 for ; Thu, 18 May 2017 15:25:46 -0700 (PDT) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by arlo.cworth.org (Postfix) with ESMTPS id 3C3956DE00D2 for ; Thu, 18 May 2017 15:25:43 -0700 (PDT) Received: by mail-wm0-f43.google.com with SMTP id 70so62299203wmq.1 for ; Thu, 18 May 2017 15:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adirat-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=fyU/LPsQhRyhmZUe2IrmUdScjSYrjTMvwum1cEDgQis=; b=SI6Ge+ddwf3uJ0QmgWHdKVPgO/bX+Ab1EqfHfcGL1k0J9g9Gv7S9id4igrvtP7crlG 13wKKHdsPPANcTiOCsTeSsN2vlWZAsyK1qtBImzEhgzd1yTjpq8Bznmi1AA0SeO6w1hD nK/ApMnEEfkyqb9bu3k1sP+y6X2co68xnPLQZC1A94aTNBZgDTVcag3KhPDUeQ4BAwAh vhTgDu5Qrex0H1gCknTamPX03ONq9EshI0WnrJBzid1hFVggXrPP9aqmTLtNvG2Bt42H Utor16wvaRQDs16jC4oaWPN+O/TtAIwPMog5DK8omkd/6S/x9iMw5iQ7SE1b0vy73Uhm uLXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=fyU/LPsQhRyhmZUe2IrmUdScjSYrjTMvwum1cEDgQis=; b=FtCiT5YgBTw8EtFctvwZkL01K+ZyqJXeu/78QvfwN8G3axuLnsazm2F14oReDDBMD6 UZlP/bKHdcVrBLzNi1rEJxfobFAGqXZuZ3cfBypS63uiZ6S6CygBpctbcyrY/ARJICw/ h1SyY+d4Mj/eRh38JCBdrSXScrUV1deSvkj+gJqpoYE9nAdOR6KwrqwQ0PgRrpYwo/gO sAq2y7r3884DVO95JRiuNoxhDr2XMl/KFbhD6YYTSRLyb6zX3gT5IB/1qzwrKm6fH4eJ 1SoKIv763J8+vT0qKArHO/hF5d84bC97JaV2XMDoYaISu5Lyosr6PnZlf378ATZvQSR4 da0w== X-Gm-Message-State: AODbwcAaII9igQpcbkjl7Rjh1CgxPvBxSppTM4Kx6ozKThB4JrQQ0vrR Y256J2i8TMJGrbjW4cE= X-Received: by 10.28.144.15 with SMTP id s15mr4030865wmd.137.1495146341402; Thu, 18 May 2017 15:25:41 -0700 (PDT) Received: from adiPC.adirat.com ([82.137.23.239]) by smtp.gmail.com with ESMTPSA id q16sm8141390wmg.2.2017.05.18.15.25.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 15:25:40 -0700 (PDT) From: Ioan-Adrian Ratiu To: notmuch@notmuchmail.org Subject: [PATCH v2 04/11] emacs: make notmuch-search-oldest-first generic Date: Fri, 19 May 2017 01:27:01 +0300 Message-Id: <20170518222708.30032-5-adi@adirat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170518222708.30032-1-adi@adirat.com> References: <20170518222708.30032-1-adi@adirat.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: Thu, 18 May 2017 22:25:47 -0000 The current search result order logic assumes results are always sorted by date and thus uses a boolean switch for oldest/newest ordering specifications. This is problematic if I want to introduce other result orderings, like for example based on the mail-file size with smallest/biggest ordering specifications. In the interest of keeping all current logic intact and reusable, while at the same time supporting multiple search result orderings, change the defcustom configuration notmuch-search-oldest-first to notmuch-search-default-sort-order which takes values 'oldest-first and 'newest-first (for now). Implementing new result orderings thus becomes a simple matter of adding more possible entries for notmuch-search-default-sort-order. Aside from the UI variable rename change, this commit should be totally transparent for the user, it does not modify or add any new result sorting logic. Signed-off-by: Ioan-Adrian Ratiu --- doc/notmuch-emacs.rst | 4 ++-- emacs/notmuch-hello.el | 15 +++++++-------- emacs/notmuch-jump.el | 11 +++++------ emacs/notmuch-lib.el | 7 ++++--- emacs/notmuch-tree.el | 2 +- emacs/notmuch.el | 29 +++++++++++++++-------------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index 5e25996f..66a69bb8 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -169,8 +169,8 @@ variables. Control how each thread of messages is presented in the ``notmuch-show-mode`` buffer -:index:`notmuch-search-oldest-first` - Display the oldest threads at the top of the buffer +:index:`notmuch-search-default-sort-order` + Control the default search result method .. _notmuch-show: diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index c858a20b..3ba2a16b 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -28,7 +28,7 @@ (require 'notmuch-lib) (require 'notmuch-mua) -(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line continuation)) +(declare-function notmuch-search "notmuch" (&optional query sort-order target-thread target-line continuation)) (declare-function notmuch-poll "notmuch" ()) (declare-function notmuch-tree "notmuch-tree" (&optional query query-context target buffer-name open-target)) @@ -381,7 +381,7 @@ afterwards.") (setq search (notmuch-hello-trim search)) (let ((history-delete-duplicates t)) (add-to-history 'notmuch-search-history search))) - (notmuch-search search notmuch-search-oldest-first)) + (notmuch-search search notmuch-search-default-sort-order)) (defun notmuch-hello-add-saved-search (widget) (interactive) @@ -443,7 +443,7 @@ diagonal." (notmuch-search (widget-get widget :notmuch-search-terms) (widget-get widget - :notmuch-search-oldest-first)))) + :notmuch-search-sort-order)))) (defun notmuch-saved-search-count (search) (car (process-lines notmuch-command "count" search))) @@ -575,10 +575,9 @@ 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))) + (sort-order (if (plist-get elem :sort-order) + (plist-get elem :sort-order) + notmuch-search-default-sort-order)) (search-type (eq (plist-get elem :search-type) 'tree)) (msg-count (plist-get elem :count))) (widget-insert (format "%8s " @@ -586,7 +585,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..716d39b8 100644 --- a/emacs/notmuch-jump.el +++ b/emacs/notmuch-jump.el @@ -50,15 +50,14 @@ fast way to jump to a saved search from anywhere in Notmuch." (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))))) + (sort-order + (if (plist-get saved-search :sort-order) + (plist-get saved-search :sort-order) + (notmuch-search-default-sort-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 337b20ac..34ffa712 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -92,14 +92,15 @@ $PATH)." :type 'string :group 'notmuch-external) -(defcustom notmuch-search-oldest-first t - "Show the oldest mail first when searching. +(defcustom notmuch-search-default-sort-order 'oldest-first + "Default result sorting to use 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 (const :tag "oldest-first" oldest-first) + (const :tag "newest-first" newest-first)) :group 'notmuch-search) (defcustom notmuch-poll-script nil diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index d4d40761..99cb098c 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 40b9fabd..248b97c7 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -367,7 +367,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-default-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) @@ -942,13 +942,13 @@ 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. Other optional parameters are used as follows: - OLDEST-FIRST: A Boolean controlling the sort order of returned threads + SORT-ORDER: Sort order of the returned threads TARGET-THREAD: A thread ID (without the thread: prefix) that will be made current if it appears in the search results. TARGET-LINE: The line number to move to if the target thread does not @@ -965,7 +965,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-default-sort-order))) (let* ((query (or query (notmuch-read-query "Notmuch search: "))) (buffer (get-buffer-create (notmuch-search-buffer-title query)))) @@ -976,7 +976,7 @@ 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-default-sort-order sort-order) (set 'notmuch-search-target-thread target-thread) (set 'notmuch-search-target-line target-line) (notmuch-tag-clear-cache) @@ -991,9 +991,7 @@ the configured default sort order." (let ((proc (notmuch-start-notmuch "notmuch-search" buffer #'notmuch-search-process-sentinel "search" "--format=sexp" "--format-version=2" - (if oldest-first - "--sort=oldest-first" - "--sort=newest-first") + (concat "--sort=" (symbol-name sort-order)) query)) ;; Use a scratch buffer to accumulate partial output. ;; This buffer will be killed by the sentinel, which @@ -1014,20 +1012,23 @@ 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-default-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-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-default-sort-order'." (interactive) - (set 'notmuch-search-oldest-first (not notmuch-search-oldest-first)) + (setq notmuch-search-default-sort-order + (case notmuch-search-default-sort-order + ('oldest-first 'newest-first) + (otherwise 'oldest-first))) (notmuch-search-refresh-view)) (defun notmuch-group-disjunctive-query-string (query-string) @@ -1051,7 +1052,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-default-sort-order))) (defun notmuch-search-filter-by-tag (tag) "Filter the current search results based on a single tag. @@ -1060,7 +1061,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-default-sort-order)) ;;;###autoload (defun notmuch () -- 2.13.0