unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org, amdragon@MIT.EDU
Subject: [PATCH v2 1/5] emacs: hello: add helper functions for saved-searches
Date: Sun,  6 Apr 2014 06:44:45 +0100	[thread overview]
Message-ID: <1396763089-32452-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1396763089-32452-1-git-send-email-markwalters1009@gmail.com>

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

  reply	other threads:[~2014-04-06  5:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1396763089-32452-2-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=amdragon@MIT.EDU \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).