From fefe2f8a3f0fab907d68f5663c99e4408bd933de Mon Sep 17 00:00:00 2001 From: markwalters1009 Date: Sat, 24 Nov 2012 13:20:56 +0000 Subject: [PATCH] [PATCH v2 7/7] emacs: make emacs use message-ids for tagging --- d8/b356c36751ee06274c0648738634b950d28df1 | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 d8/b356c36751ee06274c0648738634b950d28df1 diff --git a/d8/b356c36751ee06274c0648738634b950d28df1 b/d8/b356c36751ee06274c0648738634b950d28df1 new file mode 100644 index 000000000..d16c4c333 --- /dev/null +++ b/d8/b356c36751ee06274c0648738634b950d28df1 @@ -0,0 +1,169 @@ +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 C03A4431FBD + for ; Sat, 24 Nov 2012 05:21:20 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + 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 xpsO+ECaZSBh for ; + Sat, 24 Nov 2012 05:21:19 -0800 (PST) +Received: from mail-we0-f181.google.com (mail-we0-f181.google.com + [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7B44E431FAF + for ; Sat, 24 Nov 2012 05:21:19 -0800 (PST) +Received: by mail-we0-f181.google.com with SMTP id t11so3934097wey.26 + for ; Sat, 24 Nov 2012 05:21:18 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=x21H9sO0YJw+KzZLVr8jpQuzQBEggwvFWQGE5F7gVNs=; + b=qGRw7/RMtr2kjob00isFhYYC/fBngnVE9BTj1n2KG5BTuHFzjG9wHOUctpqK3lnWaC + zP8rcjpSCN7ufeV2TL/OdpUoZTsZdbWx6MRyXvbJdxf3swNJK/cU2310e6Q+md5IOqL5 + qSubQWzwHb6znkRFtslSIG4NDwnzQwQhP354GugVcquAnbuwuvo0htGLd4cByCCLXZRF + Xt5s5rwYvJNomjmwLoH1eUzm1XWU7cko6z4KxGbORxbHXlwuGN66QLp0XfN1Axn04HOK + sfqFrGijn3fna6yDNg2EpNG7MWH2dRrcSegbPTDQWFuzl50lWVXcLq49Ofh2TZj3OIc1 + Pb8w== +Received: by 10.180.81.170 with SMTP id b10mr9835809wiy.16.1353763278256; + Sat, 24 Nov 2012 05:21:18 -0800 (PST) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPS id b1sm14246472wix.11.2012.11.24.05.21.16 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 24 Nov 2012 05:21:17 -0800 (PST) +From: markwalters1009 +To: notmuch@notmuchmail.org +Subject: [PATCH v2 7/7] emacs: make emacs use message-ids for tagging +Date: Sat, 24 Nov 2012 13:20:56 +0000 +Message-Id: <1353763256-32336-8-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com> +References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com> +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: Sat, 24 Nov 2012 13:21:21 -0000 + +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))))) + 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)))) + ++ + (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)))) ++ ++(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 ++ (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" + (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\") +-- +1.7.9.1 + -- 2.26.2