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 C466F6DE0361 for ; Sat, 6 May 2017 13:44:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.102 X-Spam-Level: X-Spam-Status: No, score=-0.102 tagged_above=-999 required=5 tests=[AWL=-0.081, 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 FTwm1z5bV_Ut for ; Sat, 6 May 2017 13:44:01 -0700 (PDT) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id 0AD816DE0318 for ; Sat, 6 May 2017 13:44:01 -0700 (PDT) Received: by mail-wm0-f67.google.com with SMTP id z129so7579251wmb.1 for ; Sat, 06 May 2017 13:44:00 -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=avakIMbUgWvkF13b+tL75He1nCO7LA92NoHNbSzSLxw=; b=TicriE2Bl1IGXind62AM+y4SvUkhX+gJiTqm20EL/4E5ctSn7fxc609zykuPr6bZlh tIodDhx6ROh5gnLTgzl9VstutvCDXSNqV2ghc/KGdEBTCIVnZURvYD6NfiQzfRoyalcu xRkvhp2qHrzxIvZiYKl/quL/JAam+8zRhchukNQDdzjzoPu5OeP4CPwxLOE+Yf41RQ6y 8X9UKeYDsmUvXbA9S/9y897PSepQ76eqm1zkcWwGekJLnn8dIopD4qpXUedKMY6ae4p/ iwgrOT0Ym9JRT7DoBhmCiQmC3tHZiHY4G7Q/7QNwRu8FVzTYF9Ccw9B70sB/+TcLqsnf EYuw== 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=avakIMbUgWvkF13b+tL75He1nCO7LA92NoHNbSzSLxw=; b=h2R6Mf56iolilVk+GCENl1IzgjOJu9rqu1YR+TNDWm/onF7hZCdSSYaiArdmMLmz9L cGMsTzNX5dNfZDap7gTXSGWXjJvgzmeioNEsH3ZF1bdatT43b5qFwHdZVdE1HAqgkFZe YJRt0nU761C1AKc6YqtcG9Hahgq82ol7b5sFHGn4HkvdlP/PrH4yHKzQA8QEG8YyRn/u cECRRvE+bxSKMqUJK44mee4Jdiu9niJYnomB5R40YGZ6nhUAH/zV96ms7/fbfJRj5bb1 jbrnhtKN0NCqtBnrCsniGiBOQtg8FurEKyJ/SsYeY+mPweFoM8F2tIjr4KVu2IfUIGOW miZQ== X-Gm-Message-State: AN3rC/5XvEBtqGVNa62R3o5U+0hLvn3/0U8JAnFJNTDnsIis79qD66RU 9vpc5iO4OzTPM3s3 X-Received: by 10.28.175.209 with SMTP id y200mr8387254wme.52.1494103439143; Sat, 06 May 2017 13:43:59 -0700 (PDT) Received: from adiPC.adirat.com ([188.24.64.45]) by smtp.gmail.com with ESMTPSA id l27sm6576487wrb.65.2017.05.06.13.43.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 May 2017 13:43:58 -0700 (PDT) From: Ioan-Adrian Ratiu To: notmuch@notmuchmail.org Subject: [PATCH 2/3] emacs: make notmuch-search-oldest-first generic Date: Sat, 6 May 2017 23:45:29 +0300 Message-Id: <20170506204530.10591-2-adi@adirat.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170506204530.10591-1-adi@adirat.com> References: <20170506204530.10591-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: Sat, 06 May 2017 20:44:02 -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 7bebdbab..cca40249 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.12.2