Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 17D10431FB6 for ; Sat, 5 Apr 2014 17:58:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OvvoJ5CJKs6a for ; Sat, 5 Apr 2014 17:58:25 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu [18.9.25.12]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 23143431FAF for ; Sat, 5 Apr 2014 17:58:25 -0700 (PDT) X-AuditID: 1209190c-f794a6d000000c27-88-5340a6b00a96 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 14.61.03111.0B6A0435; Sat, 5 Apr 2014 20:58:24 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s360wMlr028426; Sat, 5 Apr 2014 20:58:23 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s360wKZ2013328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Sat, 5 Apr 2014 20:58:21 -0400 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) (envelope-from ) id 1WWbPg-0006wI-5q; Sat, 05 Apr 2014 20:58:20 -0400 Date: Sat, 5 Apr 2014 20:58:20 -0400 From: Austin Clements To: Mark Walters Subject: Re: [PATCH 1/5] emacs: hello: add helper functions for saved-searches Message-ID: <20140406005820.GD15472@mit.edu> References: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com> <1396733065-32602-2-git-send-email-markwalters1009@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1396733065-32602-2-git-send-email-markwalters1009@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1t2wzCHY4OxnPovVc3ksrt+cyezA 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZfz82sZW0CZZ0Xp7AmMD4wPhLkZODgkBE4lp J68wQ9hiEhfurWfrYuTiEBKYzSRx4swxZghnA6PE6rMPmCCcU0wS6/YsZgJpERJYwihxeBYP iM0ioCJxddM0FhCbTUBDYtv+5YwgtoiAjsTtQwvYQWxmAWmJb7+bwXqFBfwkDkw7DWbzAtWc /9UDtaCTUeLWj/WMEAlBiZMzn7BANGtJ3Pj3EqiIA2zQ8n8cIGFOAS+J3ct3gM0XBbphyslt bBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuoZ6uZkleqkppZsYwWEt ybOD8c1BpUOMAhyMSjy8F/IcgoVYE8uKK3MPMUpyMCmJ8nbNAArxJeWnVGYkFmfEF5XmpBYf YpTgYFYS4X0SBJTjTUmsrEotyodJSXOwKInzvrW2ChYSSE8sSc1OTS1ILYLJynBwKEnw7l0K 1ChYlJqeWpGWmVOCkGbi4AQZzgM0/B5IDW9xQWJucWY6RP4Uo6KUOO+MJUAJAZBERmkeXC8s 7bxiFAd6RZhXB6SdB5iy4LpfAQ1mAhrcEGYHMrgkESEl1cBYWCwwe5LGS+s3+hqbcmWn/Lqe dLX9cMtXPYMIK+8vrG+Vtm172JrV0r5mhrVqnmfRzA33PJse7pR/Kbtk/+ygOXMWF8e3JkfM t9hdxJe4+tP5kNTlsc3TEn1mJTQ2ZJT9bNoY2rn3zfp/50+q2+j+nG+wZtKT5Czla6kXfzM8 KtJfl1qxpm+KEktxRqKhFnNRcSIAT+c/TBYDAAA= Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Sun, 06 Apr 2014 00:58:29 -0000 Quoth Mark Walters on Apr 05 at 10:24 pm: > 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 | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el > index e325cd3..0b9ed16 100644 > --- a/emacs/notmuch-hello.el > +++ b/emacs/notmuch-hello.el > @@ -269,6 +269,45 @@ (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. > + > +In the new style saved-search (a plist) this is just plist-get It won't be "new style" once this has been in for a while. Perhaps "If SAVED-SEARCH is a plist, this is just `plist-get', but for backwards compatibility, ..." > +but, for backwards compatibility, this deals with the two > +old-style forms: cons cells (NAME . QUERY) and lists (NAME QUERY > +COUNT-QUERY)." > + (cond > + ((plist-get saved-search :name) Rather than depending on :name, maybe this should be a more generic plist test like (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)) Use `first' for consistency with the other case cases? > + (: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) > + "Convert a saved-search variable into plist form. This takes a value, not a variable. But it could be more succinct and more accurate: "Return a copy of SAVED-SEARCH in plist form." > + > +The new style saved search is just a plist, but for backwards Same comment about "new style". > +compatatibility we use this function to give them in > +plist-form. In all cases a new copy is returned so it is safe to Grammar error? > +modify the returned value." > + (if (and (listp (cdr saved-search)) (plist-member saved-search :name)) > + (copy-seq saved-search) > + (let ((fields (list :name :query :count-query)) > + (plist-search)) Personally I prefer to either explicitly initialize nil variables or to list them without the parenthesis at all (for some reason my brain automatically reads this as an application), but if you prefer this, that's fine, too. > + (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