unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [RFC PATCH] emacs/show: add command to view a patch using diff mode
@ 2012-12-08 18:43 david
  2012-12-09  2:05 ` [PATCH] " Mark Walters
  0 siblings, 1 reply; 3+ messages in thread
From: david @ 2012-12-08 18:43 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

From: David Bremner <bremner@debian.org>

This enables fast navigation between hunks and better highlighting.

The use of notmuch-get-bodypart-internal could be improved; hard
coding to 1 seems to work for the output of git-format-patch. It also
not so nice to call (insert (notmuch-get-bodypart-internal ...)) since the
last thing n-g-b-i does is call buffer-string.
---

The main thing that worries me is the use of
notmuch-get-bodypart-internal.  Do we have a canonical way to get the
message body?  It would also be nice to have "q" actually kill the
buffer, but I didn't find a clean way to do that.

 emacs/notmuch-show.el |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 20f8997..442e6ce 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1694,6 +1694,22 @@ to show, nil otherwise."
     (set-buffer-modified-p nil)
     (view-buffer buf 'kill-buffer-if-not-modified)))
 
+(defun notmuch-show-view-as-patch ()
+  "View the the current message as a patch."
+  (interactive)
+  (let* ((id (notmuch-show-get-message-id))
+	 (subject (concat "Subject: " (notmuch-show-get-subject) "\n"))
+	 (diff-default-read-only t)
+	 (buf (get-buffer-create (concat "*notmuch-patch-" id "*"))))
+    (switch-to-buffer buf)
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (insert subject)
+      (insert (notmuch-get-bodypart-internal id 1 nil)))
+    (set-buffer-modified-p nil)
+    (diff-mode)
+    (goto-char (point-min))))
+
 (defun notmuch-show-pipe-message (entire-thread command)
   "Pipe the contents of the current message (or thread) to the given command.
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] emacs/show: add command to view a patch using diff mode
  2012-12-08 18:43 [RFC PATCH] emacs/show: add command to view a patch using diff mode david
@ 2012-12-09  2:05 ` Mark Walters
  2014-06-22 10:51   ` David Bremner
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Walters @ 2012-12-09  2:05 UTC (permalink / raw)
  To: notmuch

From: markwalters1009@gmail.com

This enables fast navigation between hunks and better highlighting.

The use of notmuch-get-bodypart-internal could be improved; hard
coding to 1 seems to work for the output of git-format-patch. It also
not so nice to call (insert (notmuch-get-bodypart-internal ...)) since the
last thing n-g-b-i does is call buffer-string.

Author: David Bremner <bremner@debian.org>
---

This is a hacked version of which does seem to quit on q. The
difficulty is that diff-mode sets minor-mode-overriding-map-alist to
change the map when the buffer is read-only and it seemed to be
difficult to override without affecting diff-mode maps globally.

This should be safe in that respect. However, I don't know whether it
is allowed to set a keymap to something within a "let" and what
happens to it after we exit the let. I am also not completely sure
about the lexical-let: but it was what diff-mode used to do this
(those two lines are copied from diff-mode)

Best wishes

Mark



 emacs/notmuch-show.el |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 20f8997..e150e7c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1694,6 +1694,26 @@ to show, nil otherwise."
     (set-buffer-modified-p nil)
     (view-buffer buf 'kill-buffer-if-not-modified)))
 
+(defun notmuch-show-view-as-patch ()
+  "View the the current message as a patch."
+  (interactive)
+  (let* ((id (notmuch-show-get-message-id))
+	 (subject (concat "Subject: " (notmuch-show-get-subject) "\n"))
+	 (diff-default-read-only t)
+	 (buf (get-buffer-create (concat "*notmuch-patch-" id "*")))
+	 (map (make-sparse-keymap)))
+    (define-key map "q" 'notmuch-kill-this-buffer)
+    (switch-to-buffer buf)
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (insert subject)
+      (insert (notmuch-get-bodypart-internal id 1 nil)))
+    (set-buffer-modified-p nil)
+    (diff-mode)
+    (lexical-let ((new-ro-bind (cons 'buffer-read-only map)))
+		 (add-to-list 'minor-mode-overriding-map-alist new-ro-bind))
+    (goto-char (point-min))))
+
 (defun notmuch-show-pipe-message (entire-thread command)
   "Pipe the contents of the current message (or thread) to the given command.
 
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs/show: add command to view a patch using diff mode
  2012-12-09  2:05 ` [PATCH] " Mark Walters
@ 2014-06-22 10:51   ` David Bremner
  0 siblings, 0 replies; 3+ messages in thread
From: David Bremner @ 2014-06-22 10:51 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> From: markwalters1009@gmail.com
>
> This enables fast navigation between hunks and better highlighting.
>
> The use of notmuch-get-bodypart-internal could be improved; hard
> coding to 1 seems to work for the output of git-format-patch. It also
> not so nice to call (insert (notmuch-get-bodypart-internal ...)) since the
> last thing n-g-b-i does is call buffer-string.
>
> Author: David Bremner <bremner@debian.org>

Recently I had cause to update this function to produce more
"git-format-patch" like output. I didn't yet merge with Mark's proposed
changes. Here it is in case anyone else finds this useful (I used it to
de-quoted-printable a patch).

(defun notmuch-show-view-as-patch ()
  "View the the current message as a patch."
  (interactive)
  (let* ((id (notmuch-show-get-message-id t))
	 (date (notmuch-show-get-date))
	 (from_ (concat "From " id " " date "\n"))
	 (from: (concat "From: " (notmuch-show-get-from) "\n"))
	 (date: (concat "Date: " date "\n"))
	 (subject (concat "Subject: " (notmuch-show-get-subject) "\n"))
	 (diff-default-read-only t)
	 (buf (get-buffer-create (concat "*notmuch-patch-" id "*"))))
    (switch-to-buffer buf)
    (let ((inhibit-read-only t))
      (erase-buffer)
      (insert from_)
      (insert from:)
      (insert date:)
      (insert subject)
      (insert "\n")
      (insert (notmuch-get-bodypart-internal (concat "id:" id) 1 nil)))
    (set-buffer-modified-p nil)
    (diff-mode)
    (goto-char (point-min))))

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-22 10:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-08 18:43 [RFC PATCH] emacs/show: add command to view a patch using diff mode david
2012-12-09  2:05 ` [PATCH] " Mark Walters
2014-06-22 10:51   ` David Bremner

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