From 9b09a138397b375a133a1a179f318e47e4281974 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 12 Feb 2014 17:57:51 +1900 Subject: [PATCH] Re: [PATCH 2/7] emacs: tag: allow default case in notmuch-tag-formats --- 36/07bcb38acb13d38f2457d65a67e5982c1978b4 | 211 ++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 36/07bcb38acb13d38f2457d65a67e5982c1978b4 diff --git a/36/07bcb38acb13d38f2457d65a67e5982c1978b4 b/36/07bcb38acb13d38f2457d65a67e5982c1978b4 new file mode 100644 index 000000000..8813af4f4 --- /dev/null +++ b/36/07bcb38acb13d38f2457d65a67e5982c1978b4 @@ -0,0 +1,211 @@ +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 3955C431FBF + for ; Tue, 11 Feb 2014 14:58:03 -0800 (PST) +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 m4uZDQQLNsLG for ; + Tue, 11 Feb 2014 14:57:59 -0800 (PST) +Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu + [18.7.68.37]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AA7F0431FBD + for ; Tue, 11 Feb 2014 14:57:58 -0800 (PST) +X-AuditID: 12074425-f79906d000000cf9-2b-52faaaf41278 +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 1E.F3.03321.4FAAAF25; Tue, 11 Feb 2014 17:57:56 -0500 (EST) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s1BMvtkg014003; + Tue, 11 Feb 2014 17:57:56 -0500 +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 s1BMvqjZ017960 + (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); + Tue, 11 Feb 2014 17:57:54 -0500 +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) + (envelope-from ) + id 1WDMH2-0002fY-C7; Tue, 11 Feb 2014 17:57:52 -0500 +From: Austin Clements +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [PATCH 2/7] emacs: tag: allow default case in notmuch-tag-formats +In-Reply-To: <87ob2e0wyp.fsf@qmul.ac.uk> +References: <1390087855-26194-1-git-send-email-markwalters1009@gmail.com> + <1390087855-26194-3-git-send-email-markwalters1009@gmail.com> + <87txc6n84q.fsf@awakening.csail.mit.edu> + <87ob2e0wyp.fsf@qmul.ac.uk> +User-Agent: Notmuch/0.17~rc2+14~g06f47e0 (http://notmuchmail.org) Emacs/23.4.1 + (i486-pc-linux-gnu) +Date: Tue, 11 Feb 2014 17:57:51 -0500 +Message-ID: <87r479mf4g.fsf@awakening.csail.mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFrrHIsWRmVeSWpSXmKPExsUixCmqrPtl1a8gg94j0har5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyni//SRTwW69ilW/9jI2ME5T7WLk5JAQMJGY + cWIhK4QtJnHh3no2EFtIYDaTxP7Ddl2MXED2RkaJcz/aWCASp5kkutYHQCSWMEr8WXiEHSTB + JqAhsW3/ckYQW0TAVeLpt8/MILawgJ/Ess0bgWo4ODiBas7vEYKYc4ZRYsd6HxBbVCBJ4vTU + 32BHsAioSryfcBJsDC/QcYe7t7NA2IISJ2c+AbOZBbQkbvx7yTSBUWAWktQsJKkFjEyrGGVT + cqt0cxMzc4pTk3WLkxPz8lKLdC30cjNL9FJTSjcxgoKR3UV1B+OEQ0qHGAU4GJV4eAUX/QoS + Yk0sK67MPcQoycGkJMrLBgxlIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8QSuBcrwpiZVVqUX5 + MClpDhYlcd5aC6CUQHpiSWp2ampBahFMVoaDQ0mCNwKkUbAoNT21Ii0zpwQhzcTBCTKcB2j4 + EbDhxQWJucWZ6RD5U4yKUuK8zCAXCYAkMkrz4HphyeIVozjQK8K8r0DaeYCJBq77FdBgJqDB + /dlgg0sSEVJSDYxrnV2fz7rw725WgpXF7533LaYoeVlrLufrVZvN5H2rJCxmhfXhOwe3Hszb + ufz96a4SiXC/CVrxiu6R1q5vlBsmPXbUZ2dMqP/52Kv6l0T24ugJR94tbynqqQo+mhvD7qQz + /+SXG7WGiuqtnKYb/3AtmhsTH3jJRHzJXt0tai1vqppL+otfXVRiKc5INNRiLipOBADTYlrH + 8QIAAA== +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: Tue, 11 Feb 2014 22:58:03 -0000 + +On Tue, 11 Feb 2014, Mark Walters wrote: +> Thanks for the review. +> +> On Mon, 10 Feb 2014, Austin Clements wrote: +>> On Sat, 18 Jan 2014, Mark Walters wrote: +>>> Allow an empty string in notmuch-tag-formats which matches all tags +>>> except those matched explicitly matched. This allows the user to tell +>> +>> Typo. +> +> Will fix. +> +>>> notmuch to hide all tags except those specified. +>>> +>>> This will be useful once formatting for deleted/added tags is added +>>> later in the series: a user might want to hide all deleted tags for +>>> example. +>>> --- +>>> emacs/notmuch-tag.el | 20 +++++++++++--------- +>>> 1 files changed, 11 insertions(+), 9 deletions(-) +>>> +>>> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el +>>> index 2153068..92c1249 100644 +>>> --- a/emacs/notmuch-tag.el +>>> +++ b/emacs/notmuch-tag.el +>>> @@ -65,14 +65,15 @@ +>>> This gives a list that maps from tag names to lists of formatting +>>> expressions. The car of each element gives a tag name and the +>>> cdr gives a list of Elisp expressions that modify the tag. If +>>> -the list is empty, the tag will simply be hidden. Otherwise, +>>> -each expression will be evaluated in order: for the first +>>> -expression, the variable `tag' will be bound to the tag name; for +>>> -each later expression, the variable `tag' will be bound to the +>>> -result of the previous expression. In this way, each expression +>>> -can build on the formatting performed by the previous expression. +>>> -The result of the last expression will displayed in place of the +>>> -tag. +>>> +the car is an empty string it matches all tags that do not have +>>> +an explicit match. If the list is empty, the tag will simply be +>> +>> Hmm. I'm not sure I like overloading of the meanings of strings. Could +>> we instead use a symbol to represent this case? For example, `t' would +>> parallel the fall-through case of `cond' and `case', or `_' would +>> parallel `pcase' [1]. Or even a separate variable like +>> notmuch-tag-default-format? +> +> I would prefer not to have a separate variable as I want the default +> case for added/deleted tags too (see next patch), so it would need to be +> 3 separate variables. But maybe that makes things clearer and is worth +> doing? + +Ah, I see. In that case I agree this shouldn't be a separate variable +(that idea was just a workaround anyway). + +> One other possibility that would solve the customize problem would be to +> allow regexps for the matches. The regexp would have to match the +> complete tag and only the first match would be used. This has advantages +> (the user can highlight all notmuch::.* tags or can hide all X- +> tags). The downside is that finding/testing for a regexp match is about +> 20 times slower than using assoc, primarily because assoc is written in +> C and the regexp match bit in lisp. + +I really like the idea of using regexps for this. I wouldn't worry +about the performance. We can almost certainly eliminate that problem +with a sprinkle of caching (which would probably be even faster than +assoc), and that can be added separately. + +>> The former would require some tweaking of the customize widget, but that +>> should probably happen anyway to support this special case. +>> Unfortunately, we may need a custom alist widget variant to do that. (I +>> tried and failed to tweak it in a way that both worked and looked +>> decent.) Hence my suggestion of a separate variable, which would only +>> require pulling out the :value-type into its own define-widget. +> +> If we go this route I may need some help getting this to work: pulling +> out value-type didn't work on my first attempt. +> +>> I'm also slightly bothered that this would introduce a second way to +>> control the default formatting of tags in addition to notmuch-tag-face, +>> but only slightly. +> +> Yes that slightly bothered me but I didn't see a solution. +> +>> [1] It's unfortunate that pcase wasn't introduced until Emacs 24. I've +>> been tempted to backport it for notmuch multiple times now. Then we +>> could just treat notmuch-tag-formats as a list of pcase conditions. +> +> Would that still involve a lisp loop so would be comparable to the +> regexp bit above? I haven't looked at pcase enough to work out its +> details. + +pcase compiles into a decision tree, which could in principle reduce +this to a fast lookup when possible, though I don't know if the +implementation is actually that smart. At any rate, I like the idea of +using regexps for this better anyway. + +> Best wishes +> +> Mark +> +> +>> +>>> +hidden. Otherwise, each expression will be evaluated in order: +>>> +for the first expression, the variable `tag' will be bound to the +>>> +tag name; for each later expression, the variable `tag' will be +>>> +bound to the result of the previous expression. In this way, +>>> +each expression can build on the formatting performed by the +>>> +previous expression. The result of the last expression will +>>> +displayed in place of the tag. +>>> +>>> For example, to replace a tag with another string, simply use +>>> that string as a formatting expression. To change the foreground +>>> @@ -140,7 +141,8 @@ This can be used with `notmuch-tag-format-image-data'." +>>> +>>> (defun notmuch-tag-format-tag (tag) +>>> "Format TAG by looking into `notmuch-tag-formats'." +>>> - (let ((formats (assoc tag notmuch-tag-formats))) +>>> + (let ((formats (or (assoc tag notmuch-tag-formats) +>>> + (assoc "" notmuch-tag-formats)))) +>>> (cond +>>> ((null formats) ;; - Tag not in `notmuch-tag-formats', +>>> tag) ;; the format is the tag itself. +>>> -- +>>> 1.7.9.1 +>>> +>>> _______________________________________________ +>>> notmuch mailing list +>>> notmuch@notmuchmail.org +>>> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2