unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 6/9] emacs/show: provide notmuch-show-choose-duplicate
Date: Fri,  1 Jul 2022 18:45:45 -0300	[thread overview]
Message-ID: <20220701214548.461943-7-david@tethera.net> (raw)
In-Reply-To: <20220701214548.461943-1-david@tethera.net>

This new command allows the user to interactively choose a different
duplicate (file) to display for a given message in
notmuch-show-mode. Since both tree and unthreaded view use
notmuch-show-mode, this provides the same facility there.
---
 devel/emacs-keybindings.org   |  1 +
 emacs/notmuch-lib.el          |  4 +++-
 emacs/notmuch-show.el         | 25 +++++++++++++++++++++++++
 test/T450-emacs-show.sh       | 29 +++++++++++++++++++++++++++++
 test/T460-emacs-tree.sh       | 14 ++++++++++++++
 test/T465-emacs-unthreaded.sh | 15 +++++++++++++++
 6 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/devel/emacs-keybindings.org b/devel/emacs-keybindings.org
index 00977bc3..ad7f72ef 100644
--- a/devel/emacs-keybindings.org
+++ b/devel/emacs-keybindings.org
@@ -40,6 +40,7 @@
 | Z            | notmuch-tree-from-search-current-query | notmuch-tree-from-show-current-query                  |                                         |
 | =!=          |                                        | notmuch-show-toggle-elide-non-matching                |                                         |
 | =#=          |                                        | notmuch-show-print-message                            |                                         |
+| =%=          |                                        | notmuch-show-replace-msg                              |                                         |
 | =$=          |                                        | notmuch-show-toggle-process-crypto                    |                                         |
 | =*=          | notmuch-search-tag-all                 | notmuch-show-tag-all                                  | notmuch-tree-tag-thread                 |
 | +            | notmuch-search-add-tag                 | notmuch-show-add-tag                                  | notmuch-tree-add-tag                    |
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index cc706924..84ba8c5e 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -1029,7 +1029,7 @@ status."
 
 (defvar-local notmuch-show-process-crypto nil)
 
-(defun notmuch--run-show (search-terms)
+(defun notmuch--run-show (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
@@ -1038,6 +1038,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 53493785..020a7dca 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1127,6 +1127,30 @@ 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-choose-duplicate (duplicate)
+  (interactive "Nduplicate: ")
+  (let ((count (length (notmuch-show-get-prop :filename))))
+    (when (or (> duplicate count)
+	      (< duplicate 1))
+      (error "Duplicate %d out of range [1,%d]" duplicate count)))
+  (notmuch-show-move-to-message-top)
+  (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--run-show (list id) duplicate)))
+      ;; clean up existing overlays to avoid extending them.
+      (dolist (o (overlays-in (car extent) (cdr extent)))
+	(delete-overlay o))
+      ;; pretend insertion is happening at end of buffer
+      (narrow-to-region (point-min) (car extent))
+      ;; Insert first, then delete, to avoid marker for start of next
+      ;; message being in same place as the start of this one.
+      (notmuch-show-insert-msg new-msg depth)
+      (widen)
+      (delete-region (point) (cdr extent)))))
+
 (defun notmuch-show-insert-msg (msg depth)
   "Insert the message MSG at depth DEPTH in the current thread."
   (let* ((headers (plist-get msg :headers))
@@ -1583,6 +1607,7 @@ reset based on the original query."
     (define-key map "#" 'notmuch-show-print-message)
     (define-key map "!" 'notmuch-show-toggle-elide-non-matching)
     (define-key map "$" 'notmuch-show-toggle-process-crypto)
+    (define-key map "%" 'notmuch-show-choose-duplicate)
     (define-key map "<" 'notmuch-show-toggle-thread-indentation)
     (define-key map "t" 'toggle-truncate-lines)
     (define-key map "." 'notmuch-show-part-map)
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index 64f174cf..9cc90d91 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -338,4 +338,33 @@ 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-choose-duplicate 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_begin_subtest "duplicate=0"
+test_emacs "(test-log-error
+	      (notmuch-show \"id:${ID3}\")
+	      (notmuch-show-choose-duplicate 0))"
+cat <<EOF > EXPECTED
+(error Duplicate 0 out of range [1,5])
+EOF
+test_expect_equal_file EXPECTED MESSAGES
+
+test_begin_subtest "duplicate=1000"
+test_emacs "(test-log-error
+	      (notmuch-show \"id:${ID3}\")
+	      (notmuch-show-choose-duplicate 1000))"
+cat <<EOF > EXPECTED
+(error Duplicate 1000 out of range [1,5])
+EOF
+test_expect_equal_file EXPECTED MESSAGES
 test_done
diff --git a/test/T460-emacs-tree.sh b/test/T460-emacs-tree.sh
index 0f23b418..bae26e3b 100755
--- a/test/T460-emacs-tree.sh
+++ b/test/T460-emacs-tree.sh
@@ -200,4 +200,18 @@ test_emacs '(test-log-error
 	        (notmuch-tree "*")))'
 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
 
+add_email_corpus duplicate
+
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
+test_begin_subtest "duplicate=3"
+test_emacs "(notmuch-tree \"id:${ID3}\")
+	   (notmuch-test-wait)
+	   (notmuch-tree-show-message t)
+	   (notmuch-show-choose-duplicate 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
diff --git a/test/T465-emacs-unthreaded.sh b/test/T465-emacs-unthreaded.sh
index e7bc1439..9b96c7d7 100755
--- a/test/T465-emacs-unthreaded.sh
+++ b/test/T465-emacs-unthreaded.sh
@@ -57,4 +57,19 @@ test_emacs '(test-log-error
 	        (notmuch-unthreaded "*")))'
 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
 
+add_email_corpus duplicate
+
+ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
+test_begin_subtest "duplicate=3"
+test_emacs "(let ((notmuch-tree-show-out t))
+	      (notmuch-unthreaded \"id:${ID3}\")
+	      (notmuch-test-wait)
+	      (notmuch-tree-show-message nil)
+	      (notmuch-show-choose-duplicate 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

  parent reply	other threads:[~2022-07-01 21:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 21:45 Display duplicate messages in emacs front-end David Bremner
2022-07-01 21:45 ` [PATCH 1/9] test: use notmuch_json_show_sanitize more places David Bremner
2022-07-01 21:45 ` [PATCH 2/9] test: define and use notmuch_sexp_*_sanitize functions David Bremner
2022-07-01 21:45 ` [PATCH 3/9] test: add new corpus of duplicate messages David Bremner
2022-07-05 10:07   ` David Bremner
2022-07-01 21:45 ` [PATCH 4/9] CLI/show: initial support for --duplicate for (raw output only) David Bremner
2022-07-01 21:45 ` [PATCH 5/9] CLI/show: support --duplicate for structured output David Bremner
2022-07-01 21:45 ` David Bremner [this message]
2022-07-01 21:45 ` [PATCH 7/9] emacs/show: display count of duplicates in headerline David Bremner
2022-07-01 21:45 ` [PATCH 8/9] CLI/reply: support --duplicate argument David Bremner
2022-07-01 21:45 ` [PATCH 9/9] emacs/reply: reply to correct duplicate David Bremner
2022-07-30 11:50   ` David Bremner
2022-07-02  1:47 ` Display duplicate messages in emacs front-end David Bremner
2022-11-09 14:53 ` Daniel Kahn Gillmor
2022-11-09 16:55   ` Daniel Kahn Gillmor
2022-11-09 20:58     ` Jameson Graef Rollins
2022-11-10  4:57       ` Daniel Kahn Gillmor

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=20220701214548.461943-7-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).