diff options
author | Mark Walters <markwalters1009@gmail.com> | 2014-04-06 06:44:45 +0100 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-04-11 10:26:19 -0300 |
commit | 4767e89bc783ba01147a4adf545ee305809a46c9 (patch) | |
tree | 58382841e325a62798783b7d85f08bce5caec167 /emacs/notmuch-hello.el | |
parent | 8977b1a25991d91aa5d0466eedd348a2aba50691 (diff) |
emacs: hello: add helper functions for saved-searches
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.
Diffstat (limited to 'emacs/notmuch-hello.el')
-rw-r--r-- | emacs/notmuch-hello.el | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 490e9929..95fd850f 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -269,6 +269,44 @@ afterwards.") (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 |