* [PATCH] don't show x-foo tags in search view @ 2012-10-29 18:57 James Vasile 2012-10-29 19:22 ` David Bremner 2012-10-30 9:41 ` Damien Cassou 0 siblings, 2 replies; 11+ messages in thread From: James Vasile @ 2012-10-29 18:57 UTC (permalink / raw) To: notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 1289 bytes --] My filters create tags like x-bogotrained-spam that are for internal bookkeeping. I don't mind seeing them in the 'show' view, but I didn't want them cluttering my 'search' view. This patch omits x-foo and X-foo tags from the 'search' view. --- emacs/notmuch.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f9454d8..90fafbf 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -793,7 +793,12 @@ non-authors is found, assume that all of the authors match." (notmuch-search-insert-authors format-string (plist-get result :authors))) ((string-equal field "tags") - (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) + (let ((tags-str (mapconcat 'identity + (delq nil + (mapcar (lambda (x) (if (equal (upcase (truncate-string-to-width x 2)) "X-") + nil + (identity x))) (plist-get result :tags))) + " "))) (insert (propertize (format format-string tags-str) 'face 'notmuch-tag-face)))))) -- 1.7.10.4 [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-29 18:57 [PATCH] don't show x-foo tags in search view James Vasile @ 2012-10-29 19:22 ` David Bremner 2012-10-29 19:47 ` James Vasile 2012-10-29 21:19 ` James Vasile 2012-10-30 9:41 ` Damien Cassou 1 sibling, 2 replies; 11+ messages in thread From: David Bremner @ 2012-10-29 19:22 UTC (permalink / raw) To: James Vasile, notmuch mailing list James Vasile <james@hackervisions.org> writes: > My filters create tags like x-bogotrained-spam that are for internal > bookkeeping. I don't mind seeing them in the 'show' view, but I didn't > want them cluttering my 'search' view. This patch omits x-foo and X-foo > tags from the 'search' view. I understand this scratches your itch, but what about something more customizable? d ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-29 19:22 ` David Bremner @ 2012-10-29 19:47 ` James Vasile 2012-10-29 21:19 ` James Vasile 1 sibling, 0 replies; 11+ messages in thread From: James Vasile @ 2012-10-29 19:47 UTC (permalink / raw) To: David Bremner, notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 585 bytes --] David Bremner <david@tethera.net> writes: > James Vasile <james@hackervisions.org> writes: > >> My filters create tags like x-bogotrained-spam that are for internal >> bookkeeping. I don't mind seeing them in the 'show' view, but I didn't >> want them cluttering my 'search' view. This patch omits x-foo and X-foo >> tags from the 'search' view. > > I understand this scratches your itch, but what about something more > customizable? > > d I thought it was fairly general as is, but you're right it could be more customizable. I'll rewrite it with a regex the user can customize. [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-29 19:22 ` David Bremner 2012-10-29 19:47 ` James Vasile @ 2012-10-29 21:19 ` James Vasile 2012-10-30 0:57 ` Austin Clements 1 sibling, 1 reply; 11+ messages in thread From: James Vasile @ 2012-10-29 21:19 UTC (permalink / raw) To: David Bremner, notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 1974 bytes --] This patch hides any tags in search view that match the regex specified in `notmuch-search-hide-tag-regex`. That variable can be set via setq or the customize interface. To hide all tags that begin with "x-" or "X-", set `notmuch-search-hide-tag-regex` to "^X-". --- emacs/notmuch.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f9454d8..4bff538 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -775,6 +775,14 @@ non-authors is found, assume that all of the authors match." (overlay-put overlay 'isearch-open-invisible #'delete-overlay))) (insert padding)))) +(defcustom notmuch-search-hide-tag-regex "" + "Regex specifying tags to hide in search view. + +Leave blank to disable hiding of tags in search view. +Note: elisp regexes are case-insensitive" + :type 'string + :group 'notmuch-search) + (defun notmuch-search-insert-field (field format-string result) (cond ((string-equal field "date") @@ -793,7 +801,13 @@ non-authors is found, assume that all of the authors match." (notmuch-search-insert-authors format-string (plist-get result :authors))) ((string-equal field "tags") - (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) + (let ((tags-str (mapconcat 'identity + (delq nil + (mapcar (lambda (x) (if (and (not (equal notmuch-search-hide-tag-regex "")) + (string-match notmuch-search-hide-tag-regex x)) + nil + x)) (plist-get result :tags))) + " "))) (insert (propertize (format format-string tags-str) 'face 'notmuch-tag-face)))))) -- 1.7.10.4 [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-29 21:19 ` James Vasile @ 2012-10-30 0:57 ` Austin Clements 2012-10-30 14:57 ` James Vasile 0 siblings, 1 reply; 11+ messages in thread From: Austin Clements @ 2012-10-30 0:57 UTC (permalink / raw) To: James Vasile; +Cc: notmuch mailing list I like it. Quoth James Vasile on Oct 29 at 5:19 pm: > This patch hides any tags in search view that match the regex specified > in `notmuch-search-hide-tag-regex`. That variable can be set via setq > or the customize interface. To hide all tags that begin with "x-" or > "X-", set `notmuch-search-hide-tag-regex` to "^X-". > > --- > emacs/notmuch.el | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index f9454d8..4bff538 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -775,6 +775,14 @@ non-authors is found, assume that all of the authors match." > (overlay-put overlay 'isearch-open-invisible #'delete-overlay))) > (insert padding)))) > > +(defcustom notmuch-search-hide-tag-regex "" > + "Regex specifying tags to hide in search view. I have no idea why, but Emacs typically uses "regexp" instead of "regex". > + > +Leave blank to disable hiding of tags in search view. Saying "Leave blank" supposes that the user knows what the default value is. How about "An empty string disables hiding of tags in search view."? Even better, though, would be to use nil to indicate this, since "" is a perfectly valid regexp and matches everything. In that case, this should say something like "If nil, no tags will be hidden in search view." > +Note: elisp regexes are case-insensitive" Likewise, "regexps". Also, Elisp regexps are not, in general, case-insensitive. If we want to control this, we should bind case-fold-search to nil around the string-match below and say something here like "Matching is case-insensitive." > + :type 'string Better would be 'regexp. Or, '(choice (const :tag "None" nil) regexp) to allow nil or a regexp. > + :group 'notmuch-search) > + > (defun notmuch-search-insert-field (field format-string result) > (cond > ((string-equal field "date") > @@ -793,7 +801,13 @@ non-authors is found, assume that all of the authors match." > (notmuch-search-insert-authors format-string (plist-get result :authors))) > > ((string-equal field "tags") > - (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) > + (let ((tags-str (mapconcat 'identity > + (delq nil > + (mapcar (lambda (x) (if (and (not (equal notmuch-search-hide-tag-regex "")) > + (string-match notmuch-search-hide-tag-regex x)) > + nil > + x)) (plist-get result :tags))) > + " "))) It would be simpler and more robust to use remove-if here. What about something like (let ((tags-str (mapconcat 'identity (if notmuch-search-hide-tag-regex (let ((case-fold-search t)) (remove-if (apply-partially #'string-match notmuch-search-hide-tag-regex) (plist-get result :tags))) (plist-get result :tags)) " "))) ? > (insert (propertize (format format-string tags-str) > 'face 'notmuch-tag-face)))))) > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-30 0:57 ` Austin Clements @ 2012-10-30 14:57 ` James Vasile 2012-11-07 12:44 ` David Bremner 2012-11-07 14:37 ` Austin Clements 0 siblings, 2 replies; 11+ messages in thread From: James Vasile @ 2012-10-30 14:57 UTC (permalink / raw) To: Austin Clements; +Cc: notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 4227 bytes --] Austin, Thanks for the helpful comments. I redid the patch to take a list of regexps. That way users can banish different kinds of tags or simply list the tags themselves. I've responded to your comments in text below the patch. --- emacs/notmuch.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index f9454d8..05aa114 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -775,6 +775,21 @@ non-authors is found, assume that all of the authors match." (overlay-put overlay 'isearch-open-invisible #'delete-overlay))) (insert padding)))) + +(defcustom notmuch-search-hide-tag-regexps '() + "List of regular expressionss specifying tags to hide in search view. + +Notmuch will hide any tags in search view that match the regexps +specified in the list `notmuch-search-hide-tag-regexp`. The +match is case-insensitive. + +If you are not comfortable with regular expressions, a list of +tag words will work, assuming those tags use only alphanumeric +characters. An empty list will disable hiding of tags in search +view. The list can be set via setq or the customize interface." + :type '(repeat regexp) + :group 'notmuch-search) + (defun notmuch-search-insert-field (field format-string result) (cond ((string-equal field "date") @@ -793,7 +808,16 @@ non-authors is found, assume that all of the authors match." (notmuch-search-insert-authors format-string (plist-get result :authors))) ((string-equal field "tags") - (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) + (let ((tags-str + (mapconcat 'identity + (let ((case-fold-search t)) + (remove-if + (lambda (tag) + (find tag notmuch-search-hide-tag-regexps + :test (lambda (tag regexp) + (string-match regexp tag)))) + (plist-get result :tags))) + " "))) (insert (propertize (format format-string tags-str) 'face 'notmuch-tag-face)))))) -- 1.7.10.4 Austin Clements <amdragon@MIT.EDU> writes: > I like it. Thanks. [snip] > I have no idea why, but Emacs typically uses "regexp" instead of > "regex". It probably has something to do with rhyming with 'sexp'. ;) It's good to conform to the vernacular, so I fixed it. > >> + >> +Leave blank to disable hiding of tags in search view. > > Saying "Leave blank" supposes that the user knows what the default > value is. How about "An empty string disables hiding of tags in > search view."? I'm now using a list, but yes, "an empty list" is a good way to describe it. > > Even better, though, would be to use nil to indicate this, since "" is > a perfectly valid regexp and matches everything. In that case, this > should say something like "If nil, no tags will be hidden in search > view." "An empty list" is nil, so I think this is covered by my changes. If you think the defcustom text could be clearer, I'd appreciate edits. > >> +Note: elisp regexes are case-insensitive" > > Likewise, "regexps". Also, Elisp regexps are not, in general, > case-insensitive. If we want to control this, we should bind > case-fold-search to nil around the string-match below and say > something here like "Matching is case-insensitive." Good point. > >> + :type 'string > > Better would be 'regexp. Or, '(choice (const :tag "None" nil) regexp) > to allow nil or a regexp. Changed to 'regexp. [snip] > It would be simpler and more robust to use remove-if here. What about > something like > > (let ((tags-str > (mapconcat 'identity > (if notmuch-search-hide-tag-regex > (let ((case-fold-search t)) > (remove-if > (apply-partially #'string-match > notmuch-search-hide-tag-regex) > (plist-get result :tags))) > (plist-get result :tags)) > " "))) That's a good idea. I adjusted the code to use remove-if, and it is improved by the change. Thanks, James [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-30 14:57 ` James Vasile @ 2012-11-07 12:44 ` David Bremner 2012-11-07 14:15 ` James Vasile 2012-11-07 14:37 ` Austin Clements 1 sibling, 1 reply; 11+ messages in thread From: David Bremner @ 2012-11-07 12:44 UTC (permalink / raw) To: James Vasile; +Cc: notmuch mailing list James Vasile <james@hackervisions.org> writes: > Austin, > > Thanks for the helpful comments. I redid the patch to take a list of > regexps. That way users can banish different kinds of tags or simply > list the tags themselves. I've responded to your comments in text below > the patch. > I think the patch is probably OK now contentwise, but the commit message is what I quoted above, which is not ideal. As far as being obsoleted by Damien's labeller patches, let's cross that bridge when we come to it. Unless somebody objects, I'd be willing to push some version of this now. d ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-11-07 12:44 ` David Bremner @ 2012-11-07 14:15 ` James Vasile 0 siblings, 0 replies; 11+ messages in thread From: James Vasile @ 2012-11-07 14:15 UTC (permalink / raw) To: David Bremner; +Cc: notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 1105 bytes --] David Bremner <david@tethera.net> writes: > James Vasile <james@hackervisions.org> writes: > >> Austin, >> >> Thanks for the helpful comments. I redid the patch to take a list of >> regexps. That way users can banish different kinds of tags or simply >> list the tags themselves. I've responded to your comments in text below >> the patch. >> > > I think the patch is probably OK now contentwise, but the commit message > is what I quoted above, which is not ideal. New commit message: This patch hides any tags in search view that match the regexps specified in the list `notmuch-search-hide-tag-regexps`. The match is case-insensitive. An empty list (which is the default) will disable hiding of tags in search view. The list can be set via setq or the customize interface. To hide all tags that begin with "x-" or "X-", set `notmuch-search-hide-tag-regexps` to "^X-". > > As far as being obsoleted by Damien's labeller patches, let's cross that > bridge when we come to it. Unless somebody objects, I'd be willing to > push some version of this now. Thanks. [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-30 14:57 ` James Vasile 2012-11-07 12:44 ` David Bremner @ 2012-11-07 14:37 ` Austin Clements 1 sibling, 0 replies; 11+ messages in thread From: Austin Clements @ 2012-11-07 14:37 UTC (permalink / raw) To: James Vasile; +Cc: notmuch mailing list The code looks good to me (two minor comments below), but, as David pointed out, this needs a commit message. Quoth James Vasile on Oct 30 at 10:57 am: > Austin, > > Thanks for the helpful comments. I redid the patch to take a list of > regexps. That way users can banish different kinds of tags or simply > list the tags themselves. I've responded to your comments in text below > the patch. > > --- > emacs/notmuch.el | 26 +++++++++++++++++++++++++- > 1 file changed, 25 insertions(+), 1 deletion(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index f9454d8..05aa114 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -775,6 +775,21 @@ non-authors is found, assume that all of the authors match." > (overlay-put overlay 'isearch-open-invisible #'delete-overlay))) > (insert padding)))) > > + Extra blank link inserted. > +(defcustom notmuch-search-hide-tag-regexps '() > + "List of regular expressionss specifying tags to hide in search view. > + > +Notmuch will hide any tags in search view that match the regexps > +specified in the list `notmuch-search-hide-tag-regexp`. The > +match is case-insensitive. > + > +If you are not comfortable with regular expressions, a list of > +tag words will work, assuming those tags use only alphanumeric > +characters. An empty list will disable hiding of tags in search > +view. The list can be set via setq or the customize interface." The last sentence isn't necessary. This is true of virtually every customize variable by design. > + :type '(repeat regexp) > + :group 'notmuch-search) > + > (defun notmuch-search-insert-field (field format-string result) > (cond > ((string-equal field "date") > @@ -793,7 +808,16 @@ non-authors is found, assume that all of the authors match." > (notmuch-search-insert-authors format-string (plist-get result :authors))) > > ((string-equal field "tags") > - (let ((tags-str (mapconcat 'identity (plist-get result :tags) " "))) > + (let ((tags-str > + (mapconcat 'identity > + (let ((case-fold-search t)) > + (remove-if > + (lambda (tag) > + (find tag notmuch-search-hide-tag-regexps > + :test (lambda (tag regexp) > + (string-match regexp tag)))) > + (plist-get result :tags))) > + " "))) > (insert (propertize (format format-string tags-str) > 'face 'notmuch-tag-face)))))) > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-29 18:57 [PATCH] don't show x-foo tags in search view James Vasile 2012-10-29 19:22 ` David Bremner @ 2012-10-30 9:41 ` Damien Cassou 2012-10-30 16:42 ` James Vasile 1 sibling, 1 reply; 11+ messages in thread From: Damien Cassou @ 2012-10-30 9:41 UTC (permalink / raw) To: James Vasile; +Cc: notmuch mailing list On Mon, Oct 29, 2012 at 7:57 PM, James Vasile <james@hackervisions.org> wrote: > My filters create tags like x-bogotrained-spam that are for internal > bookkeeping. I don't mind seeing them in the 'show' view, but I didn't > want them cluttering my 'search' view. This patch omits x-foo and X-foo > tags from the 'search' view. what about using notmuch-labeler that let you hide whatever you want (or replace it by pictures)? https://github.com/DamienCassou/notmuch-labeler I'm working on integrating it inside notmuch -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] don't show x-foo tags in search view 2012-10-30 9:41 ` Damien Cassou @ 2012-10-30 16:42 ` James Vasile 0 siblings, 0 replies; 11+ messages in thread From: James Vasile @ 2012-10-30 16:42 UTC (permalink / raw) To: Damien Cassou; +Cc: notmuch mailing list [-- Attachment #1: Type: text/plain, Size: 787 bytes --] Damien Cassou <damien.cassou@gmail.com> writes: > On Mon, Oct 29, 2012 at 7:57 PM, James Vasile <james@hackervisions.org> wrote: >> My filters create tags like x-bogotrained-spam that are for internal >> bookkeeping. I don't mind seeing them in the 'show' view, but I didn't >> want them cluttering my 'search' view. This patch omits x-foo and X-foo >> tags from the 'search' view. > > what about using notmuch-labeler that let you hide whatever you want > (or replace it by pictures)? > https://github.com/DamienCassou/notmuch-labeler > > I'm working on integrating it inside notmuch > I wasn't aware of labeler. It looks like it has some nice functionality. When it gets integrated into the trunk, I'll use it, assuming it can match regexps and not just literal strings. Thanks! [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-11-07 14:37 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-10-29 18:57 [PATCH] don't show x-foo tags in search view James Vasile 2012-10-29 19:22 ` David Bremner 2012-10-29 19:47 ` James Vasile 2012-10-29 21:19 ` James Vasile 2012-10-30 0:57 ` Austin Clements 2012-10-30 14:57 ` James Vasile 2012-11-07 12:44 ` David Bremner 2012-11-07 14:15 ` James Vasile 2012-11-07 14:37 ` Austin Clements 2012-10-30 9:41 ` Damien Cassou 2012-10-30 16:42 ` James Vasile
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).