From: Austin Clements Date: Sun, 6 Apr 2014 01:24:25 +0000 (+2000) Subject: Re: [PATCH 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=31680a11e3aa322b579369d73ebe7a73e69c3cc6;p=notmuch-archives.git Re: [PATCH 4/5] emacs: hello: switch notmuch-hello-insert-buttons to plists --- diff --git a/ee/3381606e3f7949a53fe894534a392391dc1649 b/ee/3381606e3f7949a53fe894534a392391dc1649 new file mode 100644 index 000000000..da287d705 --- /dev/null +++ b/ee/3381606e3f7949a53fe894534a392391dc1649 @@ -0,0 +1,167 @@ +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 BD043431FB6 + for ; Sat, 5 Apr 2014 18:24:43 -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 rfuMv+UT8XwF for ; + Sat, 5 Apr 2014 18:24:32 -0700 (PDT) +Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu + [18.7.68.36]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 9FE67431FAF + for ; Sat, 5 Apr 2014 18:24:30 -0700 (PDT) +X-AuditID: 12074424-f79e26d000000c70-61-5340accb4cbe +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-7.mit.edu (Symantec Messaging Gateway) with SMTP + id F7.FA.03184.BCCA0435; Sat, 5 Apr 2014 21:24:27 -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 s361ORNH030356; + Sat, 5 Apr 2014 21:24:27 -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 s361OPWb019432 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); + Sat, 5 Apr 2014 21:24:26 -0400 +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) + (envelope-from ) + id 1WWbov-000786-If; Sat, 05 Apr 2014 21:24:25 -0400 +Date: Sat, 5 Apr 2014 21:24:25 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: [PATCH 4/5] emacs: hello: switch notmuch-hello-insert-buttons to + plists +Message-ID: <20140406012425.GF15472@mit.edu> +References: <1396733065-32602-1-git-send-email-markwalters1009@gmail.com> + <1396733065-32602-5-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-5-git-send-email-markwalters1009@gmail.com> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IR4hTV1j29xiHY4O1fG4vVc3ksrt+cyezA + 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZcxcsZ254LxcxfpTE9kaGKdJdDFyckgImEhM + mfGbHcIWk7hwbz1bFyMXh5DAbCaJt8cnMYMkhAQ2MEo0Hk2HSJxikpg6ZSM7hLOEUeLWrGVM + XYwcHCwCKhLvNkqCNLAJaEhs27+cEcQWEdCRuH1oAdgGZgFpiW+/m5lAbGGBMIm7fX/ZQGxe + oJpdPXtYIGZ2Mkq8a5rNDJEQlDg58wkLRLOWxI1/L8F2gQxa/o8DJMwp4CVx+9M3sF2iQCdM + ObmNbQKj0Cwk3bOQdM9C6F7AyLyKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI11wvN7NELzWldBMj + KKjZXVR2MDYfUjrEKMDBqMTDW5HjECzEmlhWXJl7iFGSg0lJlLdrBlCILyk/pTIjsTgjvqg0 + J7X4EKMEB7OSCO+TIKAcb0piZVVqUT5MSpqDRUmc9621VbCQQHpiSWp2ampBahFMVoaDQ0mC + d8ZqoEbBotT01Iq0zJwShDQTByfIcB6g4Q0gNbzFBYm5xZnpEPlTjIpS4rwuq4ASAiCJjNI8 + uF5Y0nnFKA70ijBvM0g7DzBhwXW/AhrMBDI4zA5kcEkiQkqqgVHl5CfhBYyzXCxNXHj6soQy + ZTM2hM6ewu38pmJCwXlOzv2vVtlXtCwP0Xpw//DT0P8C/8MWuW4NmjI3n/2zzg5/t8MJtqwx + r7a665kb7hfl1J/T3MOwra1PoLe1X/7a2cbZ+dcvLpN3DK3ZcjknzWvi2Yt/nV52tj0Qfq9x + 5ZR+yYVTvht0apVYijMSDbWYi4oTAfgMpcEVAwAA +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 01:24:43 -0000 + +Quoth Mark Walters on Apr 05 at 10:24 pm: +> Switching notmuch-hello-insert-buttons to plists means we can easily +> pass extra options through to the buttons. +> --- +> emacs/notmuch-hello.el | 33 +++++++++++++++++++-------------- +> 1 file changed, 19 insertions(+), 14 deletions(-) +> +> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el +> index c729af2..aa40e6f 100644 +> --- a/emacs/notmuch-hello.el +> +++ b/emacs/notmuch-hello.el +> @@ -425,7 +425,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-search-get 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 +> +pairs :name NAME, :query QUERY and :count COUNT, together with +> +any pairs in the original saved-search. + +"Pair" can be synonymous with "cons", which is not what you mean here. +"Properties"? + +> +> The values :show-empty-searches, :filter and :filter-count from +> options will be handled as specified for +> @@ -455,23 +457,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)))) +> + (setq elem-plist (plist-put elem-plist :query filtered-query)) + +This technically works, but `setq' is a strange thing to see in an +`and'. But the problem isn't the `setq'; it's that crazy `and'. I'd +replace the `and' with `when', keep the `setq' and `plist-put' in the +body, and squint a lot less at this code. + +> + (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 pairs for :name NAME :query QUERY and :count COUNT, where + +Same comment about "pairs". + +> +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)) +> @@ -489,9 +494,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