From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/4] WIP/emacs: replace message with different duplicate
Date: Sun, 12 Jun 2022 16:04:59 -0300 [thread overview]
Message-ID: <20220612190459.3804908-5-david@tethera.net> (raw)
In-Reply-To: <20220612190459.3804908-1-david@tethera.net>
---
emacs/notmuch-query.el | 4 +++-
emacs/notmuch-show.el | 11 +++++++++++
test/T450-emacs-show.sh | 12 ++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/emacs/notmuch-query.el b/emacs/notmuch-query.el
index 5c7f4f8d..865e3ccf 100644
--- a/emacs/notmuch-query.el
+++ b/emacs/notmuch-query.el
@@ -25,7 +25,7 @@
;;; Basic query function
-(defun notmuch-query-get-threads (search-terms)
+(defun notmuch-query-get-threads (search-terms &optional duplicate)
"Return a list of threads of messages matching SEARCH-TERMS.
A thread is a forest or list of trees. A tree is a two element
@@ -34,6 +34,8 @@ is a possibly empty forest of replies."
(let ((args '("show" "--format=sexp" "--format-version=5")))
(when notmuch-show-process-crypto
(setq args (append args '("--decrypt=true"))))
+ (when duplicate
+ (setq args (append args (list (format "--duplicate=%d" duplicate)))))
(setq args (append args search-terms))
(apply #'notmuch-call-notmuch-sexp args)))
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 203ca7f0..833543b0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1082,6 +1082,17 @@ is t, hide the part initially and show the button."
(defvar notmuch-show-previous-subject "")
(make-variable-buffer-local 'notmuch-show-previous-subject)
+(defun notmuch-show-replace-msg (duplicate)
+ (interactive "Nduplicate: ")
+ (save-excursion
+ (let* ((extent (notmuch-show-message-extent))
+ (id (notmuch-show-get-message-id))
+ (depth (notmuch-show-get-depth))
+ (inhibit-read-only t)
+ (new-msg (notmuch-query-get-threads (list id) duplicate)))
+ (delete-region (car extent) (cdr extent))
+ (notmuch-show-insert-msg new-msg depth))))
+
(defun notmuch-show-insert-msg (msg depth)
"Insert the message MSG at depth DEPTH in the current thread."
(let* ((headers (plist-get msg :headers))
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index 678efd8b..6141873d 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -271,4 +271,16 @@ when we detect the word "attachment" and there's no attach? :p
EOF
test_expect_equal_file EXPECTED OUTPUT
+add_email_corpus duplicate
+
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
+test_begin_subtest "duplicate=3"
+test_emacs "(notmuch-show \"id:${ID3}\")
+ (notmuch-show-replace-msg 3)
+ (test-visible-output \"OUTPUT\")"
+output=$(grep "Subject:" OUTPUT)
+file=$(notmuch search --output=files id:${ID3} | head -n 3 | tail -n 1)
+subject=$(grep '^Subject:' $file)
+test_expect_equal "$output" "$subject"
+
test_done
--
2.35.2
prev parent reply other threads:[~2022-06-12 21:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-12 19:04 WIP: allow display of duplicate messages with notmuch show / notmuch-emacs David Bremner
2022-06-12 19:04 ` [PATCH 1/4] test: add new corpus of duplicate messages David Bremner
2022-06-12 19:04 ` [PATCH 2/4] CLI/show: WIP support --duplicate for raw output David Bremner
2022-06-12 19:04 ` [PATCH 3/4] WIP: support show --duplicate for structured output David Bremner
2022-06-12 19:04 ` David Bremner [this message]
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=20220612190459.3804908-5-david@tethera.net \
--to=david@tethera.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).