[PATCH v2 1/2] emacs: support defining a list of alternative parts to show

Jani Nikula jani at nikula.org
Sun Feb 12 04:09:57 PST 2012


On Fri, 10 Feb 2012 10:05:46 +0000, David Edmondson <dme at dme.org> wrote:
> On Thu,  9 Feb 2012 14:46:02 +0000, Jani Nikula <jani at nikula.org> wrote:
> > Make notmuch-show-all-multipart/alternative-parts accept a list of
> > regexps to match the part types to determine which parts to show in
> > addition to the preferred types. This allows the user to force display
> > some alternative part types while normally showing just the preferred
> > ones.
> > 
> > Signed-off-by: Jani Nikula <jani at nikula.org>
> > ---
> >  emacs/notmuch-show.el |   23 ++++++++++++++++++-----
> >  1 files changed, 18 insertions(+), 5 deletions(-)
> > 
> > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> > index 24fde05..5f643f1 100644
> > --- a/emacs/notmuch-show.el
> > +++ b/emacs/notmuch-show.el
> > @@ -94,10 +94,20 @@ any given message."
> >    :group 'notmuch-show
> >    :group 'notmuch-hooks)
> >  
> > -;; Mostly useful for debugging.
> >  (defcustom notmuch-show-all-multipart/alternative-parts t
> > -  "Should all parts of multipart/alternative parts be shown?"
> > -  :type 'boolean
> > +  "Which parts of multipart/alternative should be shown?
> > +
> > +This variable determines which parts of multipart/alternative
> > +should be displayed. Set to t (the default) to show all
> > +parts. Set to nil to only show the preferred parts. Set to a list
> > +of regexps to display the preferred parts, and parts matching any
> > +of the regexps, for example:
> 
> "If set to `t' (the default), all sub-parts of a
> \"multipart/alternative\" part are shown. If set to `nil', only the
> preferred part is shown. If set to a list of regexps, the preferred part
> and all parts whose type matches one of the regexps will be shown."
> 
> > +
> > + (setq notmuch-show-all-multipart/alternative-parts
> > +      '(\"text/.*calendar\" \"text/html\"))"
> > +  :type '(choice (const :tag "Show all parts" t)
> > +		 (const :tag "Show preferred parts" nil)
> > +		 (repeat :tag "Show preferred and parts matching regexps" string))
> >    :group 'notmuch-show)
> >  
> >  (defcustom notmuch-show-indent-messages-width 1
> > @@ -513,8 +523,11 @@ current buffer, if possible."
> >      ;; should be chosen if there are more than one that match?
> >      (mapc (lambda (inner-part)
> >  	    (let ((inner-type (plist-get inner-part :content-type)))
> > -	      (if (or notmuch-show-all-multipart/alternative-parts
> > -		      (string= chosen-type inner-type))
> > +	      (if (or (equal notmuch-show-all-multipart/alternative-parts t)
> > +		      (string= chosen-type inner-type)
> > +		      (and
> > +		       notmuch-show-all-multipart/alternative-parts
> > +		       (equal (string-match-p (mapconcat (lambda (s) (format "^%s$" s)) notmuch-show-all-multipart/alternative-parts "\\|") inner-type) 0)))
> 
> This is quite messy. How about we add a general helper to "notmuch-lib.el":
> 
> (defun notmuch-string-match-list-p (regexps string)
>   (loop for regexp in regexps
> 	if (string-match-p regexp string)
> 	return t))
> 
> and then write:
> 
>     (if (or (string= chosen-type inner-type)
>             (equal notmuch-show-all-multipart/alternative-parts t)
>             (notmuch-string-match-list-p notmuch-show-all-multipart/alternative-parts inner-type))
>        ...

Hmm. I wrapped the regexps between ^ and $ to not match substrings. I
think that's less surprising and better than having the user add them,
and the user can still use e.g. ".*foo.*" to explicitly match a
substring.

If this is fixed in notmuch-string-match-list-p then it's not general
anymore. But does adding a mapcar to wrap the regexps here make this
messy again...? What if notmuch-string-match-list-p were just a local
specific helper for clarity?

> 
> ?
> 
> >  		  (notmuch-show-insert-bodypart msg inner-part depth)
> >  		(notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
> >  	  inner-parts)
> > -- 
> > 1.7.1
> > 


More information about the notmuch mailing list