[PATCH v2 0/5] emacs: hello: convert saved-searches to plists
Mark Walters
markwalters1009 at gmail.com
Sat Apr 5 22:44:44 PDT 2014
This is v2 of the series; v1 is at
id:1396733065-32602-1-git-send-email-markwalters1009 at gmail.com
I have made all the changes suggested by Austin in his review of v1. I
include the diff from v1 below.
There is now one slight oddity in the patch ordering: the
documentation for the plist form appears in patch 3 while the users
and references to that documentation appear in patch 2.
Best wishes
Mark
Mark Walters (5):
emacs: hello: add helper functions for saved-searches
emacs: hello: use the saved-search helper functions
emacs: hello: add a customize for saved-searches
emacs: hello: switch notmuch-hello-insert-buttons to plists
emacs: Add a sort-order option to saved-searches
emacs/notmuch-hello.el | 127 ++++++++++++++++++++++++++++++++----------------
emacs/notmuch-lib.el | 54 ++++++++++++++++++--
emacs/notmuch.el | 6 +--
3 files changed, 139 insertions(+), 48 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 6a28372..f0675f2 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -272,17 +272,17 @@ (defun notmuch-hello-search (&optional search)
(defun notmuch-saved-search-get (saved-search field)
"Get FIELD from SAVED-SEARCH.
-In the new style saved-search (a plist) this is just plist-get
-but, for backwards compatibility, this deals with the two
-old-style forms: cons cells (NAME . QUERY) and lists (NAME QUERY
-COUNT-QUERY)."
+If SAVED-SEARCH is a plist, this is just `plist-get', but for
+backwards compatibility, this also deals with the two other
+possible formats for SAVED-SEARCH: cons cells (NAME . QUERY) and
+lists (NAME QUERY COUNT-QUERY)."
(cond
- ((plist-get saved-search :name)
+ ((keywordp (car saved-search))
(plist-get saved-search field))
;; It is not a plist so it is an old-style entry.
((consp (cdr saved-search)) ;; It is a list (NAME QUERY COUNT-QUERY)
(case field
- (:name (car saved-search))
+ (:name (first saved-search))
(:query (second saved-search))
(:count-query (third saved-search))
(t nil)))
@@ -293,16 +293,15 @@ (defun notmuch-saved-search-get (saved-search field)
(t nil)))))
(defun notmuch-hello-saved-search-to-plist (saved-search)
- "Convert a saved-search variable into plist form.
+ "Return a copy of SAVED-SEARCH in plist form.
-The new style saved search is just a plist, but for backwards
-compatatibility we use this function to give them in
-plist-form. In all cases a new copy is returned so it is safe to
-modify the returned value."
- (if (and (listp (cdr saved-search)) (plist-member saved-search :name))
+If saved search is a plist then just return a copy. In other
+cases, for backwards compatability, convert to plist form and
+return that."
+ (if (keywordp (car saved-search))
(copy-seq saved-search)
(let ((fields (list :name :query :count-query))
- (plist-search))
+ plist-search)
(dolist (field fields plist-search)
(let ((string (notmuch-saved-search-get saved-search field)))
(when string
@@ -424,11 +423,11 @@ (defun notmuch-hello-query-counts (query-list &rest options)
QUERY-LIST must be a list of saved-searches. Ideally each of
these is a plist but other options are available for backwards
-compatibility: see notmuch-saved-search-get for details.
+compatibility: see `notmuch-saved-searches' for details.
The result is a list of plists each of which includes the
-pairs :name NAME, :query QUERY and :count COUNT, together with
-any pairs in the original saved-search.
+properties :name NAME, :query QUERY and :count COUNT, together
+with any properties in the original saved-search.
The values :show-empty-searches, :filter and :filter-count from
options will be handled as specified for
@@ -464,20 +463,20 @@ (defun notmuch-hello-query-counts (query-list &rest options)
search-query (plist-get options :filter)))
(message-count (prog1 (read (current-buffer))
(forward-line 1))))
- (and (or (plist-get options :show-empty-searches) (> message-count 0))
- (setq elem-plist (plist-put elem-plist :query filtered-query))
- (plist-put elem-plist :count message-count))))
+ (when (and filtered-query (or (plist-get options :show-empty-searches) (> message-count 0)))
+ (setq elem-plist (plist-put elem-plist :query filtered-query))
+ (plist-put elem-plist :count message-count))))
query-list))))
(defun notmuch-hello-insert-buttons (searches)
"Insert buttons for SEARCHES.
SEARCHES must be a list of plists each of which should contain at
-least pairs for :name NAME :query QUERY and :count COUNT, where
-QUERY is the query to start when the button for the corresponding
-entry is activated, and COUNT should be the number of messages
-matching the query. Such a plist can be computed with
-`notmuch-hello-query-counts'."
+least the properties :name NAME :query QUERY and :count COUNT,
+where QUERY is the query to start when the button for the
+corresponding entry is activated, and COUNT should be the number
+of messages matching the query. Such a plist can be computed
+with `notmuch-hello-query-counts'."
(let* ((widest (notmuch-hello-longest-label searches))
(tags-and-width (notmuch-hello-tags-per-line widest))
(tags-per-line (car tags-and-width))
@@ -497,13 +496,10 @@ (defun notmuch-hello-insert-buttons (searches)
(widget-insert (make-string column-indent ? )))
(let* ((name (plist-get elem :name))
(query (plist-get elem :query))
- (oldest-first (cond
- ((eq (plist-get elem :sort-order) 'newest-first)
- nil)
- ((eq (plist-get elem :sort-order) 'oldest-first)
- t)
- (t
- notmuch-search-oldest-first)))
+ (oldest-first (case (plist-get elem :sort-order)
+ (newest-first nil)
+ (oldest-first t)
+ (otherwise notmuch-search-oldest-first)))
(msg-count (plist-get elem :count)))
(widget-insert (format "%8s "
(notmuch-hello-nice-number msg-count)))
@@ -741,7 +737,7 @@ (defun notmuch-hello-insert-searches (title query-list &rest options)
QUERY-LIST should ideally be a plist but for backwards
compatibility other forms are also accepted (see
-`notmuch-saved-search-get' for details). The plist should
+`notmuch-saved-searches' for details). The plist should
contain keys :name and :query; if :count-query is also present
then it specifies an alternate query to be used to generate the
count for the associated search.
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 8aa8cfc..3a3c69d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -134,7 +134,26 @@ (define-widget 'notmuch-saved-search-plist 'list
(defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
(:name "unread" :query "tag:unread"))
- "A list of saved searches to display."
+ "A list of saved searches to display.
+
+The saved search can be given in 3 forms. The preferred way is as
+a plist. Supported properties are
+
+ :name Name of the search (required).
+ :query Search to run (required).
+ :count-query Optional extra query to generate the count
+ 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.
+
+Other accepted forms are a cons cell of the form (NAME . QUERY)
+or a list of the form (NAME QUERY COUNT-QUERY)."
+;; The saved-search format is also used by the all-tags notmuch-hello
+;; section. This section generates its own saved-search list in one of
+;; the latter two forms.
+
:get 'notmuch--saved-searches-to-plist
:type '(repeat notmuch-saved-search-plist)
:tag "List of Saved Searches"
--
1.7.10.4
More information about the notmuch
mailing list