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 ECDF2431FAF for ; Sat, 24 Nov 2012 16:38:20 -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 jlzzWHYHZOAj for ; Sat, 24 Nov 2012 16:38:18 -0800 (PST) Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU [18.7.68.35]) by olra.theworths.org (Postfix) with ESMTP id A220F431FAE for ; Sat, 24 Nov 2012 16:38:18 -0800 (PST) X-AuditID: 12074423-b7fab6d0000008f9-65-50b1687a3def Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id 9E.BA.02297.A7861B05; Sat, 24 Nov 2012 19:38:18 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qAP0cHF3007359; Sat, 24 Nov 2012 19:38:18 -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.6/8.12.4) with ESMTP id qAP0cFHe007027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Sat, 24 Nov 2012 19:38:16 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) (envelope-from ) id 1TcQEh-0006c6-Ki; Sat, 24 Nov 2012 19:38:15 -0500 Date: Sat, 24 Nov 2012 19:38:15 -0500 From: Austin Clements To: markwalters1009 Subject: Re: [PATCH v2 7/7] emacs: make emacs use message-ids for tagging Message-ID: <20121125003815.GK4562@mit.edu> References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com> <1353763256-32336-8-git-send-email-markwalters1009@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1353763256-32336-8-git-send-email-markwalters1009@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT0a3K2Bhg0P+Q22L1XB6L6zdnMjsw eeycdZfd49mqW8wBTFFcNimpOZllqUX6dglcGUveLGIueKZZsba3uoHxrmIXIyeHhICJxPWD L1kgbDGJC/fWs3UxcnEICexjlLjePIEJwtnAKLHuzC8mkCohgYtMEguaJCASSxgl9q7+zQyS YBFQlTi89i2YzSagIbFt/3JGEFtEQF9iz4rbbCA2s4C0xLffzWCDhAU8Jdp/vwVbzSugLbHw Wx8zxNBORolzLTtZIRKCEidnPmGBaNaSuPHvJVAzB9ig5f84QMKcAl4Se453g+0VFVCRmHJy G9sERqFZSLpnIemehdC9gJF5FaNsSm6Vbm5iZk5xarJucXJiXl5qka6ZXm5miV5qSukmRnBQ uyjvYPxzUOkQowAHoxIP743EjQFCrIllxZW5hxglOZiURHlz0oBCfEn5KZUZicUZ8UWlOanF hxglOJiVRHitVYFyvCmJlVWpRfkwKWkOFiVx3mspN/2FBNITS1KzU1MLUotgsjIcHEoSvLHp QI2CRanpqRVpmTklCGkmDk6Q4TxAw51BaniLCxJzizPTIfKnGBWlxHk9QBICIImM0jy4XljS ecUoDvSKMO9ZkCoeYMKC634FNJgJaPDT2etABpckIqSkGhgbTC73HlZpmn/yZnnRix0iIqoL 41rLPh7ZsO/0d9amDRoKxfaBM2RlTRZyh5WIau/85Ky+VXJatrtfiplEcDeLYGm1w9XgZe4M 7QyTV3jMdRdnmS6sqG+0fWWtlciEYA/7owptLc8fyN0ua71ep7qKq+1L78RdZW/OV2aF/a69 onHi81aJNUosxRmJhlrMRcWJAHH+5CYVAwAA Cc: notmuch@notmuchmail.org 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: Sun, 25 Nov 2012 00:38:21 -0000 Quoth markwalters1009 on Nov 24 at 1:20 pm: > From: Mark Walters > > This makes emacs use the new --queries=true in search mode and use > this for tagging. This fixes the race condition in tagging from > search mode so mark the tests fixed. > --- > emacs/notmuch.el | 28 +++++++++++++++++++++++++--- > test/emacs | 2 -- > 2 files changed, 25 insertions(+), 5 deletions(-) > > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index 64b9474..6e8ef83 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -473,7 +473,8 @@ BEG." > (let (output) > (notmuch-search-foreach-result beg end > (lambda (pos) > - (push (plist-get (notmuch-search-get-result pos) property) output))) > + (let ((value (plist-get (notmuch-search-get-result pos) property))) > + (when value (push value output))))) Why is this necessary? (Assuming it is, it could use a comment, and probably an update to the docstring.) > output)) > > (defun notmuch-search-find-thread-id (&optional bare) > @@ -483,6 +484,7 @@ If BARE is set then do not prefix with \"thread:\"" > (let ((thread (plist-get (notmuch-search-get-result) :thread))) > (when thread (concat (unless bare "thread:") thread)))) > > + Unintentional? > (defun notmuch-search-find-thread-id-region (beg end) > "Return a list of threads for the current region" > (mapcar (lambda (thread) (concat "thread:" thread)) > @@ -492,6 +494,23 @@ If BARE is set then do not prefix with \"thread:\"" > "Return a search string for threads for the current region" > (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")) > > +;; The following two functions are similar to the previous two but > +;; they only match messages that were in the the thread when the > +;; initial search was run. This means that they can be used where it > +;; is important to avoid races: e.g. when tagging. > +(defun notmuch-search-find-queries-region (beg end &optional only-matching) > + (interactive) > + "Return a list of queries for the current region" > + (append (notmuch-search-properties-in-region :matching_msg_query beg end) > + (unless only-matching > + (notmuch-search-properties-in-region :nonmatching_msg_query beg end)))) Two minor performance nits: Using nconc instead of append will avoid copying the first list and swapping the two arguments will avoid needlessly traversing the non-matching list when only-matching is nil. > + > +(defun notmuch-search-find-queries-region-search (beg end &optional only-matching) > + "Return a search string for messages in threads in the current region" > + (mapconcat 'identity #'identity > + (notmuch-search-find-queries-region beg end only-matching) > + " or ")) > + > (defun notmuch-search-find-authors () > "Return the authors for the current thread" > (plist-get (notmuch-search-get-result) :authors)) > @@ -575,7 +594,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"." > > (defun notmuch-search-tag-region (beg end &optional tag-changes) > "Change tags for threads in the given region." > - (let ((search-string (notmuch-search-find-thread-id-region-search beg end))) > + (let ((search-string (notmuch-search-find-queries-region-search beg end))) > (setq tag-changes (funcall 'notmuch-tag search-string tag-changes)) > (notmuch-search-foreach-result beg end > (lambda (pos) > @@ -851,7 +870,9 @@ non-authors is found, assume that all of the authors match." > > See `notmuch-tag' for information on the format of TAG-CHANGES." > (interactive) > - (apply 'notmuch-tag notmuch-search-query-string tag-changes)) > + (apply 'notmuch-tag (notmuch-search-find-queries-region-search > + (point-min) (point-max) t) > + tag-changes)) > > (defun notmuch-search-buffer-title (query) > "Returns the title for a buffer with notmuch search results." > @@ -948,6 +969,7 @@ Other optional parameters are used as follows: > "notmuch-search" buffer > notmuch-command "search" > "--format=json" > + "--output=with-queries" --output=with-queries or --queries=true? > (if oldest-first > "--sort=oldest-first" > "--sort=newest-first") > diff --git a/test/emacs b/test/emacs > index 3788439..132768f 100755 > --- a/test/emacs > +++ b/test/emacs > @@ -123,7 +123,6 @@ output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) > test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)" > > test_begin_subtest "Tag all matching messages from search view" > -test_subtest_known_broken > notmuch tag +test-tag-race from:cworth > test_emacs "(notmuch-search \"tag:test-tag-race\") > (notmuch-test-wait)" > @@ -135,7 +134,6 @@ notmuch tag -test-tag-race '*' > notmuch tag -test-tag-race-2 '*' > > test_begin_subtest "Change tags from search view: another message arriving after thread lookup" > -test_subtest_known_broken > typsos_id="878we4qdqf.fsf@yoom.home.cworth.org" > typsos_thread=$(notmuch search --output=threads id:$typsos_id) > test_emacs "(notmuch-search \"$typsos_thread\")