From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 3FDE46DE12A7 for ; Sun, 13 Aug 2017 22:55:15 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.003 X-Spam-Level: X-Spam-Status: No, score=-0.003 tagged_above=-999 required=5 tests=[AWL=-0.042, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.211, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KbxY3GHPo2s3 for ; Sun, 13 Aug 2017 22:55:14 -0700 (PDT) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by arlo.cworth.org (Postfix) with ESMTPS id 591E26DE11EF for ; Sun, 13 Aug 2017 22:55:14 -0700 (PDT) Received: by mail-wr0-f194.google.com with SMTP id u89so590526wrc.2 for ; Sun, 13 Aug 2017 22:55:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=o7FV3A7mAXdojz8QoRFJhzX315bVk14PAzlniHZbOaw=; b=DO6JvqWTmyCf7Fj3dZWGyawP/CE+SdNN06YrOkzf3sHjTLIMYJjWyrlE3ntL5CMRkL /se6k/D/d4pbt4qFQ5XmzyJDdOIeA7KHdzFv2BxZh+jBXk0qGEcPNW+kRwUdEoZmNSCI yhvCma2GE1vc4w6EnyQ8gy5dqbdsKR+AnQH5GD3QjjrzxXC68GDGoFdCg972CiDQryQx N8TcsrNfoQfNA9oJP9s7hapEiq1LdtSL78q8yv4dGFOK5WCfS95NkvyYBwbXGF1MJCq/ MRMsUsowbTE+HRIygbJ5xgCHfjuepz8d9TX5Utr58Kl642GU6WZj3IE61r0YMQx8vvUk vNug== X-Gm-Message-State: AHYfb5jLxsscZeiV/CZgTQ9Li1A2OnMRfvIXx2bNm2k8IcqLnh31avPz CuEBZ2rCNYSGI9gKuio= X-Received: by 10.223.178.85 with SMTP id y21mr14723907wra.92.1502690112802; Sun, 13 Aug 2017 22:55:12 -0700 (PDT) Received: from home.thecybershadow.net ([89.28.117.31]) by smtp.gmail.com with ESMTPSA id w20sm6045494wra.27.2017.08.13.22.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Aug 2017 22:55:11 -0700 (PDT) From: Vladimir Panteleev To: notmuch@notmuchmail.org Cc: Vladimir Panteleev Subject: [PATCH 2/2] emacs: Add notmuch-update-search-tags Date: Mon, 14 Aug 2017 05:54:57 +0000 Message-Id: <20170814055457.7475-3-git@thecybershadow.net> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170814055457.7475-1-git@thecybershadow.net> References: <20170814055457.7475-1-git@thecybershadow.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Mon, 14 Aug 2017 05:55:15 -0000 Implement an option which, when enabled, causes any tag changes done from within notmuch-emacs to instantly update matching threads in open search buffers. --- emacs/notmuch-tag.el | 16 ++++++++++++++++ emacs/notmuch.el | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index 0500927d..41fdeaef 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -364,6 +364,15 @@ the messages that were tagged" :options '(notmuch-hl-line-mode) :group 'notmuch-hooks) +(defcustom notmuch-update-search-tags t + "Update open `notmuch-search' buffers after tags of a message are modified. + +Instantly update any matching results in open `notmuch-search' +buffers, so that all tag changes are immediately reflected." + :type 'boolean + :group 'notmuch-search + :group 'notmuch-tag) + (defvar notmuch-select-tag-history nil "Variable to store minibuffer history for `notmuch-select-tag-with-completion' function.") @@ -477,6 +486,13 @@ notmuch-after-tag-hook will be run." (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ") " -- " query))) (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch"))) + (when notmuch-update-search-tags + (let ((results (notmuch-call-notmuch-sexp + "search" "--format=sexp" "--format-version=4" query))) + (dolist (buffer (buffer-list)) + (when (eq (buffer-local-value 'major-mode buffer) 'notmuch-search-mode) + (with-current-buffer buffer + (notmuch-search-update-results results)))))) (run-hooks 'notmuch-after-tag-hook))) (defun notmuch-tag-change-list (tags &optional reverse) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 44402f8a..b5fe4e60 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -662,6 +662,21 @@ of the result." (min init-point (- new-end 1))))) (goto-char new-point))))) +(defun notmuch-search-update-results (results) + "Replace results with threads matching RESULTS in-place and redraw them." + (let ((pos (next-single-property-change 1 'notmuch-search-result)) + (results-alist + (mapcar (lambda (result) (cons (plist-get result :thread) result)) + results))) + (while pos + (let* ((prop (get-text-property pos 'notmuch-search-result)) + (thread (when prop (plist-get prop :thread))) + (result (when thread (assoc-default thread results-alist)))) + ;; (message "found matching thread: %s" thread) + (when result + (notmuch-search-update-result result pos))) + (setq pos (next-single-property-change pos 'notmuch-search-result))))) + (defun notmuch-search-process-sentinel (proc msg) "Add a message to let user know when \"notmuch search\" exits" (let ((buffer (process-buffer proc)) -- 2.13.3