From: Vladimir Panteleev <git@thecybershadow.net>
To: notmuch@notmuchmail.org
Cc: Vladimir Panteleev <git@thecybershadow.net>
Subject: [PATCH 2/2] emacs: Add notmuch-update-search-tags
Date: Mon, 14 Aug 2017 05:54:57 +0000 [thread overview]
Message-ID: <20170814055457.7475-3-git@thecybershadow.net> (raw)
In-Reply-To: <20170814055457.7475-1-git@thecybershadow.net>
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
next prev parent reply other threads:[~2017-08-14 5:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-14 5:54 [PATCH 0/2] Update search results when tags change Vladimir Panteleev
2017-08-14 5:54 ` [PATCH 1/2] notmuch-tag.el: Fix minor grammar error Vladimir Panteleev
2017-08-23 11:11 ` David Bremner
2017-08-14 5:54 ` Vladimir Panteleev [this message]
2017-08-25 11:12 ` [PATCH 2/2] emacs: Add notmuch-update-search-tags David Bremner
2017-08-26 1:50 ` Vladimir Panteleev
2017-08-26 1:55 ` [PATCH v2] " Vladimir Panteleev
2017-08-26 10:23 ` Mark Walters
2017-08-26 17:15 ` Vladimir Panteleev
2017-08-27 7:46 ` Mark Walters
2017-08-29 1:18 ` David Bremner
2017-09-04 22:05 ` Vladimir Panteleev
2017-09-06 13:11 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170814055457.7475-3-git@thecybershadow.net \
--to=git@thecybershadow.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).