[PATCH 7/8] emacs: modify show tag functions to use new notmuch-tag interface

Jameson Graef Rollins jrollins at finestructure.net
Mon Apr 9 00:15:15 PDT 2012


On Sat, Apr 07 2012, Mark Walters <markwalters1009 at gmail.com> wrote:
> I think this is what is making the two tests fail: they count the number
> of invocations of notmuch and in case there is one invocation of notmuch
> show and one of notmuch tag -unread message-id, where before it was just
> the single notmuch show.

Good call, Mark.  After a bit of testing it looks like that is what's
going on.  I was confused, since I had thought that the call to
notmuch-show should have involved two notmuch calls originally as well,
one for retrieving the message and the other removing the unread tag.
However, it appears the messages in those tests don't have unread tags
after all.  Not sure why, but that explains it.

So I guess the upshot is that moving all the common prompting and tag
validation stuff into notmuch-tag means that in certain cases there will
be extra notmuch calls, even if no tags are changed.  Is that a problem?

What I can do, though, is add extra validation to notmuch-tag to not
actually call notmuch tag, or any of the pre- and post- tagging hooks,
if no tags are changing.  This will still require one call to notmuch to
retrieve the current set of tags for the query, but at least it wont tag
or call the hooks if nothing is changing.  That seems reasonable to me,
but please let me know if you think it's not.

I've pasted below a new version of notmuch-tag that addresses these
issues.  Let me know what you think, and I'll resubmit the series.

jamie.


(defun notmuch-tag (query &optional tag-changes)
  "Add/remove tags in TAG-CHANGES to messages matching QUERY.

QUERY should be a string containing the search-terms.
TAG-CHANGES can take multiple forms.  If TAG-CHANGES is a list of
strings of the form \"+tag\" or \"-tag\" then those are the tag
changes applied.  If TAG-CHANGES is a string then it is
interpreted as a single tag change.  If TAG-CHANGES is the string
\"-\" or \"+\", or null, then the user is prompted to enter the
tag changes.

Note: Other code should always use this function alter tags of
messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
directly, so that hooks specified in notmuch-before-tag-hook and
notmuch-after-tag-hook will be run."
  ;; Perform some validation
  (if (string-or-null-p tag-changes)
      (if (or (string= tag-changes "-") (string= tag-changes "+") (null tag-changes))
	  (setq tag-changes (notmuch-read-tag-changes tag-changes query))
	(setq tag-changes (list tag-changes))))
  (mapc (lambda (tag-change)
	  (unless (string-match-p "^[-+]\\S-+$" tag-change)
	    (error "Tag must be of the form `+this_tag' or `-that_tag'")))
	tag-changes)
  (let* ((current-tags (notmuch-tag-completions (list query)))
	 (new-tags (notmuch-update-tags current-tags tag-changes)))
    (if (equal current-tags new-tags)
	;; if no tags are changing, return nil
	nil
      (run-hooks 'notmuch-before-tag-hook)
      (apply 'notmuch-call-notmuch-process "tag"
	     (append tag-changes (list "--" query)))
      (run-hooks 'notmuch-after-tag-hook)
      ;; otherwise, return the list of actual changed tags
      tag-changes)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120409/d9120d2c/attachment.pgp>


More information about the notmuch mailing list