unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* RFC/PATCH emacs attachment handling
@ 2011-09-07  1:20 Mark Walters
  2011-09-07  7:06 ` Tomi Ollila
  2011-09-07 16:44 ` Matthieu Lemerre
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Walters @ 2011-09-07  1:20 UTC (permalink / raw)
  To: Notmuch Mail


Hello

I have modified the emacs interface for handling attachments by adding
a keymap to the attachment button. For example pressing v when on an
attachment button views the attachment (using the mailcap method) and
pressing s saves the attachment. I find this makes it a lot easier
when dealing with message with lots of attachments.

Other comments:

"Viewing" a text/html button opens the part in the mailcap defined html viewer.

"Viewing" a part with no mailcap entry just offers to save it.

In this version I make the button default to viewing: this is obviously
trivial to change but I am not sure what the right way to make that
user-configurable is.  

Finally, I have also mapped the key "o" (other/open with) on a button to
open with user chosen program. This could be split out into a separate
patch if preferred.

Best wishes

Mark

---
 emacs/notmuch-show.el |   76 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 90f9af7..3a025c5 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -267,10 +267,21 @@ message at DEPTH in the current thread."
 	(run-hooks 'notmuch-show-markup-headers-hook)))))
 
 (define-button-type 'notmuch-show-part-button-type
-  'action 'notmuch-show-part-button-action
+  'action 'notmuch-show-part-button-view-action
+  'keymap 'notmuch-show-part-button-map
   'follow-link t
   'face 'message-mml)
 
+(defvar notmuch-show-part-button-map
+  (let ((map (make-sparse-keymap)))
+       (set-keymap-parent map button-map)
+       (define-key map "s" 'notmuch-show-part-button-save-action)
+       (define-key map "v" 'notmuch-show-part-button-view-action)
+       (define-key map "o" 'notmuch-show-part-button-interactively-view-action)
+    map)
+  "Submap for button commands")
+(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
+
 (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
   (let ((button))
     (setq button
@@ -285,7 +296,8 @@ message at DEPTH in the current thread."
 		   " ]")
 	   :type 'notmuch-show-part-button-type
 	   :notmuch-part nth
-	   :notmuch-filename name))
+	   :notmuch-filename name
+	   :notmuch-content-type content-type))
     (insert "\n")
     ;; return button
     button))
@@ -309,6 +321,28 @@ message at DEPTH in the current thread."
 	;; ange-ftp, which is reasonable to use here.
 	(mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
 
+(defun notmuch-show-view-part (message-id nth content-type)
+  (let ((process-crypto notmuch-show-process-crypto))
+    (with-temp-buffer
+      (setq notmuch-show-process-crypto process-crypto)
+      ;; Always acquires the part via `notmuch part', even if it is
+      ;; available in the JSON output.
+      (insert (notmuch-show-get-bodypart-internal message-id nth))
+      ;; set mm-inlined-types to nil to force an external viewer
+      (let ((handle (mm-make-handle (current-buffer) (list content-type)))
+	    (mm-inlined-types nil))
+	(mm-display-part handle)))))
+
+(defun notmuch-show-interactively-view-part (message-id nth content-type)
+  (let ((process-crypto notmuch-show-process-crypto))
+    (with-temp-buffer
+      (setq notmuch-show-process-crypto process-crypto)
+      ;; Always acquires the part via `notmuch part', even if it is
+      ;; available in the JSON output.
+      (insert (notmuch-show-get-bodypart-internal message-id nth))
+      (let ((handle (mm-make-handle (current-buffer) (list content-type))))
+	(mm-interactively-view-part handle)))))
+
 (defun notmuch-show-mm-display-part-inline (msg part content-type content)
   "Use the mm-decode/mm-view functions to display a part in the
 current buffer, if possible."
@@ -1418,12 +1452,38 @@ buffer."
 
 ;; Commands typically bound to buttons.
 
-(defun notmuch-show-part-button-action (button)
-  (let ((nth (button-get button :notmuch-part)))
-    (if nth
-	(notmuch-show-save-part (notmuch-show-get-message-id) nth
-				(button-get button :notmuch-filename))
-      (message "Not a valid part (is it a fake part?)."))))
+(defun notmuch-show-part-button-save-action (&optional button)
+  (interactive)
+  (let ((button (or button (button-at (point)))))
+    (if (not button)
+	nil
+      (let ((nth (button-get button :notmuch-part)))
+	(if nth
+	    (notmuch-show-save-part (notmuch-show-get-message-id) nth
+				    (button-get button :notmuch-filename))
+	  (message "Not a valid part (is it a fake part?)."))))))
+
+(defun notmuch-show-part-button-view-action (&optional button)
+  (interactive)
+  (let ((button (or button (button-at (point)))))
+    (if (not button)
+	nil
+      (let ((nth (button-get button :notmuch-part)))
+	(if nth
+	    (notmuch-show-view-part (notmuch-show-get-message-id) nth
+				    (button-get button :notmuch-content-type))
+	  (message "Not a valid part (is it a fake part?)."))))))
+
+(defun notmuch-show-part-button-interactively-view-action (&optional button)
+  (interactive)
+  (let ((button (or button (button-at (point)))))
+    (if (not button)
+	nil
+      (let ((nth (button-get button :notmuch-part)))
+	(if nth
+	    (notmuch-show-interactively-view-part (notmuch-show-get-message-id) nth
+				    (button-get button :notmuch-content-type))
+	  (message "Not a valid part (is it a fake part?)."))))))
 
 ;;
 
-- 
1.7.1

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

* Re: RFC/PATCH emacs attachment handling
  2011-09-07  1:20 RFC/PATCH emacs attachment handling Mark Walters
@ 2011-09-07  7:06 ` Tomi Ollila
  2011-09-07 15:04   ` Xavier Maillard
  2011-09-07 16:44 ` Matthieu Lemerre
  1 sibling, 1 reply; 6+ messages in thread
From: Tomi Ollila @ 2011-09-07  7:06 UTC (permalink / raw)
  To: Mark Walters; +Cc: Notmuch Mail

On Wed 07 Sep 2011 04:20, Mark Walters <markwalters1009@gmail.com> writes:

> Hello
>
> I have modified the emacs interface for handling attachments by adding
> a keymap to the attachment button. For example pressing v when on an
> attachment button views the attachment (using the mailcap method) and
> pressing s saves the attachment. I find this makes it a lot easier
> when dealing with message with lots of attachments.

In my gnus (haven't got rid the latest one, yet ;) :

Pressing ENTER (RET) on top of text/html content: w3m-safe-view-this-url
Pressing ENTER (RET) on top of text content: widget-button-press
Pressing ENTER (RET) on top of an attachment: gnus-article-press-button

Pressing 'o' on top of text executes: gnus-summary-save-article
Pressing 'o' on top of an attachment: gnus-mime-save-part

To user that is:

Pressing Enter on top of an attachment will either show the attachment on
buffer (in case there is 'converter' defined) or offer to save the
attachment. Pressing 'o' on top of an attachment will always offer to save
the attachment.

Therefore I'd check rmail / gnus / vm / mh-e to check what keybindings those
use and if there are some commonalities, align with those.

>
> Best wishes
>
> Mark
>

Tomi

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

* Re: RFC/PATCH emacs attachment handling
  2011-09-07  7:06 ` Tomi Ollila
@ 2011-09-07 15:04   ` Xavier Maillard
  2011-09-08  7:49     ` Mark Walters
  0 siblings, 1 reply; 6+ messages in thread
From: Xavier Maillard @ 2011-09-07 15:04 UTC (permalink / raw)
  To: Tomi Ollila, Mark Walters; +Cc: Notmuch Mail

Hello Tomi,

On Wed, 07 Sep 2011 10:06:36 +0300, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> On Wed 07 Sep 2011 04:20, Mark Walters <markwalters1009@gmail.com> writes:
> 
> > Hello
> >
> > I have modified the emacs interface for handling attachments by adding
> > a keymap to the attachment button. For example pressing v when on an
> > attachment button views the attachment (using the mailcap method) and
> > pressing s saves the attachment. I find this makes it a lot easier
> > when dealing with message with lots of attachments.
> 
> In my gnus (haven't got rid the latest one, yet ;) :
> 
> Pressing ENTER (RET) on top of text/html content: w3m-safe-view-this-url
> Pressing ENTER (RET) on top of text content: widget-button-press
> Pressing ENTER (RET) on top of an attachment: gnus-article-press-button
> 
> Pressing 'o' on top of text executes: gnus-summary-save-article
> Pressing 'o' on top of an attachment: gnus-mime-save-part
> 
> To user that is:
> 
> Pressing Enter on top of an attachment will either show the attachment on
> buffer (in case there is 'converter' defined) or offer to save the
> attachment. Pressing 'o' on top of an attachment will always offer to save
> the attachment.

I really do not like it this behaviour. I'd rather want easy to memorize
keybindings: 'v'iew,'s'ave, etc.

-- X=M=A

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

* Re: RFC/PATCH emacs attachment handling
  2011-09-07  1:20 RFC/PATCH emacs attachment handling Mark Walters
  2011-09-07  7:06 ` Tomi Ollila
@ 2011-09-07 16:44 ` Matthieu Lemerre
  2011-09-08  7:39   ` Mark Walters
  1 sibling, 1 reply; 6+ messages in thread
From: Matthieu Lemerre @ 2011-09-07 16:44 UTC (permalink / raw)
  To: Mark Walters, Notmuch Mail


> Finally, I have also mapped the key "o" (other/open with) on a button to
> open with user chosen program. This could be split out into a separate
> patch if preferred.

This is great! In particular many people send PDF attachments to me with
mime-type attachment/octet-stream, and notmuch could not view them and
only offered to save them... I have wanted this functionality for long!

Matthieu

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

* Re: RFC/PATCH emacs attachment handling
  2011-09-07 16:44 ` Matthieu Lemerre
@ 2011-09-08  7:39   ` Mark Walters
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2011-09-08  7:39 UTC (permalink / raw)
  To: Matthieu Lemerre; +Cc: Notmuch Mail

(Re-sent since accidentally didn't include list in reply)

> This is great! In particular many people send PDF attachments to me with
> mime-type attachment/octet-stream, and notmuch could not view them and
> only offered to save them... I have wanted this functionality for long!

In fact in most cases this patch "will just work": that is <enter> on
the button will open the file as if it were application/pdf. Notmuch has some
logic to guess the mime type of application/octet-stream from the file
extension and this patch uses that.

The view all attachments command (which is unchanged by this patch)
uses emacs mime handling directly so does not use notmuch's guess.

Best wishes

Mark

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

* Re: RFC/PATCH emacs attachment handling
  2011-09-07 15:04   ` Xavier Maillard
@ 2011-09-08  7:49     ` Mark Walters
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2011-09-08  7:49 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: Tomi Ollila, Notmuch Mail

>> To user that is:
>>
>> Pressing Enter on top of an attachment will either show the attachment on
>> buffer (in case there is 'converter' defined) or offer to save the
>> attachment. Pressing 'o' on top of an attachment will always offer to save
>> the attachment.
>
> I really do not like it this behaviour. I'd rather want easy to memorize
> keybindings: 'v'iew,'s'ave, etc.

I am happy either way. I think a bigger question is about what re-use
of keys is sensible between the normal notmuch-show map (when not over
the button) and this new button map. For example using `a' in the
button map seems like it would cause accidental archiving of threads
(when you happen not be over the button).

Perhaps using v and w so v means view and w means save: if over the
body it applies to all attachments if over a button just to that
single attachment. (We would still need a new key for the "open-with"
behaviour.)

Best wishes

Mark

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

end of thread, other threads:[~2011-09-08  7:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-07  1:20 RFC/PATCH emacs attachment handling Mark Walters
2011-09-07  7:06 ` Tomi Ollila
2011-09-07 15:04   ` Xavier Maillard
2011-09-08  7:49     ` Mark Walters
2011-09-07 16:44 ` Matthieu Lemerre
2011-09-08  7:39   ` Mark Walters

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