[PATCH v2 1/2] emacs: support defining a list of alternative parts to show
Tomi Ollila
tomi.ollila at iki.fi
Sun Feb 12 06:37:58 PST 2012
On Sun, 12 Feb 2012 14:09:57 +0200, Jani Nikula <jani at nikula.org> wrote:
> 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:
[...]
> > > + (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?
Something like this could work...
(defun notmuch-string-match-list-p (regexps string)
(loop for regexp in regexps
if (string-match-p (concat "^" regexp "$") string)
return t))
But if you-re going to pre-anchor these regexps then it is better to be
documented clearly as the final 'regexp' works in non-standard way.
> >
> > ?
Tomi
More information about the notmuch
mailing list