* [PATCH v2 0/5] emacs: hello: convert saved-searches to plists
@ 2014-04-06 5:44 Mark Walters
2014-04-06 5:44 ` [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches Mark Walters
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
This is v2 of the series; v1 is at
id:1396733065-32602-1-git-send-email-markwalters1009@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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
@ 2014-04-06 5:44 ` Mark Walters
2014-04-06 5:44 ` [PATCH v2 2/5] emacs: hello: use the saved-search helper functions Mark Walters
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
Add helper functions to for saved searches to ease the transition to
the new plist form while maintaining backwards compatibility. They
will be used in the next patch.
---
emacs/notmuch-hello.el | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index e325cd3..f81ec27 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -269,6 +269,44 @@ (defun notmuch-hello-search (&optional search)
(add-to-history 'notmuch-search-history search)))
(notmuch-search search notmuch-search-oldest-first))
+(defun notmuch-saved-search-get (saved-search field)
+ "Get FIELD from SAVED-SEARCH.
+
+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
+ ((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 (first saved-search))
+ (:query (second saved-search))
+ (:count-query (third saved-search))
+ (t nil)))
+ (t ;; It is a cons-cell (NAME . QUERY)
+ (case field
+ (:name (car saved-search))
+ (:query (cdr saved-search))
+ (t nil)))))
+
+(defun notmuch-hello-saved-search-to-plist (saved-search)
+ "Return a copy of SAVED-SEARCH in plist form.
+
+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)
+ (dolist (field fields plist-search)
+ (let ((string (notmuch-saved-search-get saved-search field)))
+ (when string
+ (setq plist-search (append plist-search (list field string)))))))))
+
(defun notmuch-hello-add-saved-search (widget)
(interactive)
(let ((search (widget-value
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/5] emacs: hello: use the saved-search helper functions
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
2014-04-06 5:44 ` [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches Mark Walters
@ 2014-04-06 5:44 ` Mark Walters
2014-04-06 5:44 ` [PATCH v2 3/5] emacs: hello: add a customize for saved-searches Mark Walters
` (5 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
This uses the helper functions: the saved searches format has not
changed yet but backwards compatibility means everything still works.
---
emacs/notmuch-hello.el | 48 ++++++++++++++++++++++--------------------------
emacs/notmuch.el | 6 +++---
2 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index f81ec27..568ae47 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -318,7 +318,7 @@ (defun notmuch-hello-add-saved-search (widget)
(setq notmuch-saved-searches
(loop for elem in notmuch-saved-searches
if (not (equal name
- (car elem)))
+ (notmuch-saved-search-get elem :name)))
collect elem))
;; Add the new one.
(customize-save-variable 'notmuch-saved-searches
@@ -338,7 +338,7 @@ (defun notmuch-hello-delete-search-from-history (widget)
(defun notmuch-hello-longest-label (searches-alist)
(or (loop for elem in searches-alist
- maximize (length (car elem)))
+ maximize (length (notmuch-saved-search-get elem :name)))
0))
(defun notmuch-hello-reflect-generate-row (ncols nrows row list)
@@ -417,13 +417,12 @@ (defun notmuch-hello-filtered-query (query filter)
(concat "(" query ") and (" filter ")"))
(t query)))
-(defun notmuch-hello-query-counts (query-alist &rest options)
- "Compute list of counts of matched messages from QUERY-ALIST.
+(defun notmuch-hello-query-counts (query-list &rest options)
+ "Compute list of counts of matched messages from QUERY-LIST.
-QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
-or (NAME QUERY COUNT-QUERY). If the latter form is used,
-COUNT-QUERY specifies an alternate query to be used to generate
-the count for the associated query.
+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-searches' for details.
The result is the list of elements of the form (NAME QUERY COUNT).
@@ -431,11 +430,9 @@ (defun notmuch-hello-query-counts (query-alist &rest options)
options will be handled as specified for
`notmuch-hello-insert-searches'."
(with-temp-buffer
- (dolist (elem query-alist nil)
- (let ((count-query (if (consp (cdr elem))
- ;; do we have a different query for the message count?
- (third elem)
- (cdr elem))))
+ (dolist (elem query-list nil)
+ (let ((count-query (or (notmuch-saved-search-get elem :count-query)
+ (notmuch-saved-search-get elem :query))))
(insert
(replace-regexp-in-string
"\n" " "
@@ -457,18 +454,15 @@ (defun notmuch-hello-query-counts (query-alist &rest options)
#'identity
(mapcar
(lambda (elem)
- (let ((name (car elem))
- (search-query (if (consp (cdr elem))
- ;; do we have a different query for the message count?
- (second elem)
- (cdr elem)))
+ (let ((name (notmuch-saved-search-get elem :name))
+ (search-query (notmuch-saved-search-get elem :query))
(message-count (prog1 (read (current-buffer))
(forward-line 1))))
(and (or (plist-get options :show-empty-searches) (> message-count 0))
(list name (notmuch-hello-filtered-query
search-query (plist-get options :filter))
message-count))))
- query-alist))))
+ query-list))))
(defun notmuch-hello-insert-buttons (searches)
"Insert buttons for SEARCHES.
@@ -727,13 +721,15 @@ (defun notmuch-hello-insert-recent-searches ()
(indent-rigidly start (point) notmuch-hello-indent))
nil))
-(defun notmuch-hello-insert-searches (title query-alist &rest options)
- "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.
+(defun notmuch-hello-insert-searches (title query-list &rest options)
+ "Insert a section with TITLE showing a list of buttons made from QUERY-LIST.
-QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)
-or (NAME QUERY COUNT-QUERY). If the latter form is used,
-COUNT-QUERY specifies an alternate query to be used to generate
-the count for the associated item.
+QUERY-LIST should ideally be a plist but for backwards
+compatibility other forms are also accepted (see
+`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.
Supports the following entries in OPTIONS as a plist:
:initially-hidden - if non-nil, section will be hidden on startup
@@ -767,7 +763,7 @@ (defun notmuch-hello-insert-searches (title query-alist &rest options)
"hide"))
(widget-insert "\n")
(when (not is-hidden)
- (let ((searches (apply 'notmuch-hello-query-counts query-alist options)))
+ (let ((searches (apply 'notmuch-hello-query-counts query-list options)))
(when (or (not (plist-get options :hide-if-empty))
searches)
(widget-insert "\n")
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 233c784..1346b90 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -823,14 +823,14 @@ (defun notmuch-search-buffer-title (query)
(let (longest
(longest-length 0))
(loop for tuple in notmuch-saved-searches
- if (let ((quoted-query (regexp-quote (cdr tuple))))
+ if (let ((quoted-query (regexp-quote (notmuch-saved-search-get tuple :query))))
(and (string-match (concat "^" quoted-query) query)
(> (length (match-string 0 query))
longest-length)))
do (setq longest tuple))
longest))
- (saved-search-name (car saved-search))
- (saved-search-query (cdr saved-search)))
+ (saved-search-name (notmuch-saved-search-get saved-search :name))
+ (saved-search-query (notmuch-saved-search-get saved-search :query)))
(cond ((and saved-search (equal saved-search-query query))
;; Query is the same as saved search (ignoring case)
(concat "*notmuch-saved-search-" saved-search-name "*"))
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/5] emacs: hello: add a customize for saved-searches
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
2014-04-06 5:44 ` [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches Mark Walters
2014-04-06 5:44 ` [PATCH v2 2/5] emacs: hello: use the saved-search helper functions Mark Walters
@ 2014-04-06 5:44 ` Mark Walters
2014-04-06 5:44 ` [PATCH v2 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists Mark Walters
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
Make the defcustom for notmuch-saved-searches use the new plist
format. It should still work with oldstyle saved-searches but will
write the newstyle form.
---
emacs/notmuch-hello.el | 2 +-
emacs/notmuch-lib.el | 46 ++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 568ae47..30f26db 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -323,7 +323,7 @@ (defun notmuch-hello-add-saved-search (widget)
;; Add the new one.
(customize-save-variable 'notmuch-saved-searches
(add-to-list 'notmuch-saved-searches
- (cons name search) t))
+ (list :name name :query search) t))
(message "Saved '%s' as '%s'." search name)
(notmuch-hello-update)))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 959764e..a54a055 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -107,10 +107,48 @@ (defcustom notmuch-poll-script nil
(defvar notmuch-search-history nil
"Variable to store notmuch searches history.")
-(defcustom notmuch-saved-searches '(("inbox" . "tag:inbox")
- ("unread" . "tag:unread"))
- "A list of saved searches to display."
- :type '(alist :key-type string :value-type string)
+(defun notmuch--saved-searches-to-plist (symbol)
+ "Extract a saved-search variable into plist form.
+
+The new style saved search is just a plist, but for backwards
+compatatibility we use this function to extract old style saved
+searches so they still work in customize."
+ (let ((saved-searches (default-value symbol)))
+ (mapcar #'notmuch-hello-saved-search-to-plist saved-searches)))
+
+(define-widget 'notmuch-saved-search-plist 'list
+ "A single saved search property list."
+ :tag "Saved Search"
+ :args '((list :inline t
+ :format "%v"
+ (group :format "%v" :inline t (const :format " Name: " :name) (string :format "%v"))
+ (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))
+ (checklist :inline t
+ :format "%v"
+ (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")))))
+
+(defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
+ (:name "unread" :query "tag:unread"))
+ "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.
+
+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"
:group 'notmuch-hello)
(defcustom notmuch-archive-tags '("-inbox")
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
` (2 preceding siblings ...)
2014-04-06 5:44 ` [PATCH v2 3/5] emacs: hello: add a customize for saved-searches Mark Walters
@ 2014-04-06 5:44 ` Mark Walters
2014-04-06 5:44 ` [PATCH v2 5/5] emacs: Add a sort-order option to saved-searches Mark Walters
` (3 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
Switching notmuch-hello-insert-buttons to plists means we can easily
pass extra options through to the buttons.
---
emacs/notmuch-hello.el | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 30f26db..f440352 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -424,7 +424,9 @@ (defun notmuch-hello-query-counts (query-list &rest options)
these is a plist but other options are available for backwards
compatibility: see `notmuch-saved-searches' for details.
-The result is the list of elements of the form (NAME QUERY COUNT).
+The result is a list of plists each of which includes the
+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
@@ -454,23 +456,26 @@ (defun notmuch-hello-query-counts (query-list &rest options)
#'identity
(mapcar
(lambda (elem)
- (let ((name (notmuch-saved-search-get elem :name))
- (search-query (notmuch-saved-search-get elem :query))
- (message-count (prog1 (read (current-buffer))
+ (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))
+ (search-query (plist-get elem-plist :query))
+ (filtered-query (notmuch-hello-filtered-query
+ 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))
- (list name (notmuch-hello-filtered-query
- search-query (plist-get options :filter))
- 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 containing lists of the form (NAME QUERY COUNT), where
-QUERY is the query to start when the button for the corresponding entry is
-activated. COUNT should be the number of messages matching the query.
-Such a list can be computed with `notmuch-hello-query-counts'."
+SEARCHES must be a list of plists each of which should contain at
+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))
@@ -488,9 +493,9 @@ (defun notmuch-hello-insert-buttons (searches)
(when elem
(if (> column-indent 0)
(widget-insert (make-string column-indent ? )))
- (let* ((name (first elem))
- (query (second elem))
- (msg-count (third elem)))
+ (let* ((name (plist-get elem :name))
+ (query (plist-get elem :query))
+ (msg-count (plist-get elem :count)))
(widget-insert (format "%8s "
(notmuch-hello-nice-number msg-count)))
(widget-create 'push-button
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 5/5] emacs: Add a sort-order option to saved-searches
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
` (3 preceding siblings ...)
2014-04-06 5:44 ` [PATCH v2 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists Mark Walters
@ 2014-04-06 5:44 ` Mark Walters
2014-04-07 1:13 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Austin Clements
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-06 5:44 UTC (permalink / raw)
To: notmuch, amdragon
This adds a sort-order option to saved-searches, stores it in the
saved-search buttons (widgets), and uses the stored value when the
button is pressed.
Storing the sort-order in the widget was suggested by Jani in
id:4c3876274126985683e888641b29cf18142a5eb8.1391771337.git.jani@nikula.org.
---
emacs/notmuch-hello.el | 8 +++++++-
emacs/notmuch-lib.el | 10 +++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index f440352..f0675f2 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -363,7 +363,8 @@ (defun notmuch-hello-reflect (list ncols)
(defun notmuch-hello-widget-search (widget &rest ignore)
(notmuch-search (widget-get widget
:notmuch-search-terms)
- notmuch-search-oldest-first))
+ (widget-get widget
+ :notmuch-search-oldest-first)))
(defun notmuch-saved-search-count (search)
(car (process-lines notmuch-command "count" search)))
@@ -495,12 +496,17 @@ (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 (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)))
(widget-create 'push-button
:notify #'notmuch-hello-widget-search
:notmuch-search-terms query
+ :notmuch-search-oldest-first oldest-first
name)
(setq column-indent
(1+ (max 0 (- column-width (length name)))))))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index a54a055..3a3c69d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -125,7 +125,12 @@ (define-widget 'notmuch-saved-search-plist 'list
(group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))
(checklist :inline t
:format "%v"
- (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v")))))
+ (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))
+ (group :format "%v" :inline t (const :format "" :sort-order)
+ (choice :tag " Sort Order"
+ (const :tag "Default" nil)
+ (const :tag "Oldest-first" oldest-first)
+ (const :tag "Newest-first" newest-first))))))
(defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
(:name "unread" :query "tag:unread"))
@@ -139,6 +144,9 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
: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)."
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/5] emacs: hello: convert saved-searches to plists
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
` (4 preceding siblings ...)
2014-04-06 5:44 ` [PATCH v2 5/5] emacs: Add a sort-order option to saved-searches Mark Walters
@ 2014-04-07 1:13 ` Austin Clements
2014-04-09 17:09 ` [PATCH] News for emacs saved-searches change Mark Walters
2014-04-11 13:40 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists David Bremner
7 siblings, 0 replies; 12+ messages in thread
From: Austin Clements @ 2014-04-07 1:13 UTC (permalink / raw)
To: Mark Walters; +Cc: notmuch
LGTM.
Quoth Mark Walters on Apr 06 at 6:44 am:
> This is v2 of the series; v1 is at
> id:1396733065-32602-1-git-send-email-markwalters1009@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
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH] News for emacs saved-searches change.
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
` (5 preceding siblings ...)
2014-04-07 1:13 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Austin Clements
@ 2014-04-09 17:09 ` Mark Walters
2014-04-11 13:37 ` Tomi Ollila
2014-04-11 13:41 ` David Bremner
2014-04-11 13:40 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists David Bremner
7 siblings, 2 replies; 12+ messages in thread
From: Mark Walters @ 2014-04-09 17:09 UTC (permalink / raw)
To: notmuch
---
The important point is that the changed search variable is not forward
compatible (it *is* backwards compatible): that is previous version of
notmuch-emacs will be unusable with a new style notmuch-saved-search
variable.
Best wishes
Mark
NEWS | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/NEWS b/NEWS
index d4f4ea4..8aa4182 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,23 @@ Command-Line Interface
Emacs Interface
---------------
+Changed format for saved searches.
+
+ The format for `notmuch-saved-searches` has changed, but old style
+ saved searches are still supported. The new style means that a saved
+ search can store the desired sort order for the search, and it can
+ store a separate query to use for generating the count notmuch
+ shows.
+
+ The variable is fully customizable and any configuration done
+ through customize should `just work', with the additional options
+ mentioned above. For manual customization see the documentation for
+ `notmuch-saved-searches`.
+
+ IMPORTANT: a new style notmuch-saved-searches variable will break
+ previous versions of notmuch-emacs (even search will not work); to
+ fix remove the customization for notmuch-saved-searches.
+
Bug fix for saved searches with newlines in them.
Split lines confuse `notmuch count --batch`, so we remove embedded
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] News for emacs saved-searches change.
2014-04-09 17:09 ` [PATCH] News for emacs saved-searches change Mark Walters
@ 2014-04-11 13:37 ` Tomi Ollila
2014-04-11 15:38 ` David Bremner
2014-04-11 13:41 ` David Bremner
1 sibling, 1 reply; 12+ messages in thread
From: Tomi Ollila @ 2014-04-11 13:37 UTC (permalink / raw)
To: Mark Walters, notmuch
On Wed, Apr 09 2014, Mark Walters <markwalters1009@gmail.com> wrote:
> ---
> The important point is that the changed search variable is not forward
> compatible (it *is* backwards compatible): that is previous version of
> notmuch-emacs will be unusable with a new style notmuch-saved-search
> variable.
the above part could be before '---' so that it is added to the commit
message, too.
>
> Best wishes
>
> Mark
>
>
>
> NEWS | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/NEWS b/NEWS
> index d4f4ea4..8aa4182 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -15,6 +15,23 @@ Command-Line Interface
> Emacs Interface
> ---------------
>
> +Changed format for saved searches.
> +
> + The format for `notmuch-saved-searches` has changed, but old style
> + saved searches are still supported. The new style means that a saved
> + search can store the desired sort order for the search, and it can
> + store a separate query to use for generating the count notmuch
> + shows.
> +
> + The variable is fully customizable and any configuration done
> + through customize should `just work', with the additional options
I'm afraid the `just work' work badly when contained in markdown page
(perhaps *just work*?).
Tomi
> + mentioned above. For manual customization see the documentation for
> + `notmuch-saved-searches`.
> +
> + IMPORTANT: a new style notmuch-saved-searches variable will break
> + previous versions of notmuch-emacs (even search will not work); to
> + fix remove the customization for notmuch-saved-searches.
> +
> Bug fix for saved searches with newlines in them.
>
> Split lines confuse `notmuch count --batch`, so we remove embedded
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/5] emacs: hello: convert saved-searches to plists
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
` (6 preceding siblings ...)
2014-04-09 17:09 ` [PATCH] News for emacs saved-searches change Mark Walters
@ 2014-04-11 13:40 ` David Bremner
7 siblings, 0 replies; 12+ messages in thread
From: David Bremner @ 2014-04-11 13:40 UTC (permalink / raw)
To: Mark Walters, notmuch, amdragon
Mark Walters <markwalters1009@gmail.com> writes:
> This is v2 of the series; v1 is at
> id:1396733065-32602-1-git-send-email-markwalters1009@gmail.com
pushed,
d
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] News for emacs saved-searches change.
2014-04-09 17:09 ` [PATCH] News for emacs saved-searches change Mark Walters
2014-04-11 13:37 ` Tomi Ollila
@ 2014-04-11 13:41 ` David Bremner
1 sibling, 0 replies; 12+ messages in thread
From: David Bremner @ 2014-04-11 13:41 UTC (permalink / raw)
To: Mark Walters, notmuch
Mark Walters <markwalters1009@gmail.com> writes:
> ---
> The important point is that the changed search variable is not forward
> compatible (it *is* backwards compatible): that is previous version of
> notmuch-emacs will be unusable with a new style notmuch-saved-search
> variable.
pushed, with that paragraph as commit message
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] News for emacs saved-searches change.
2014-04-11 13:37 ` Tomi Ollila
@ 2014-04-11 15:38 ` David Bremner
0 siblings, 0 replies; 12+ messages in thread
From: David Bremner @ 2014-04-11 15:38 UTC (permalink / raw)
To: Tomi Ollila, Mark Walters, notmuch
Tomi Ollila <tomi.ollila@iki.fi> writes:
>
> I'm afraid the `just work' work badly when contained in markdown page
> (perhaps *just work*?).
>
sorry missed that. Care to fixup my mess? ;)
d
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-04-11 15:39 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-06 5:44 [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Mark Walters
2014-04-06 5:44 ` [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches Mark Walters
2014-04-06 5:44 ` [PATCH v2 2/5] emacs: hello: use the saved-search helper functions Mark Walters
2014-04-06 5:44 ` [PATCH v2 3/5] emacs: hello: add a customize for saved-searches Mark Walters
2014-04-06 5:44 ` [PATCH v2 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists Mark Walters
2014-04-06 5:44 ` [PATCH v2 5/5] emacs: Add a sort-order option to saved-searches Mark Walters
2014-04-07 1:13 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists Austin Clements
2014-04-09 17:09 ` [PATCH] News for emacs saved-searches change Mark Walters
2014-04-11 13:37 ` Tomi Ollila
2014-04-11 15:38 ` David Bremner
2014-04-11 13:41 ` David Bremner
2014-04-11 13:40 ` [PATCH v2 0/5] emacs: hello: convert saved-searches to plists David Bremner
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).