RFC/PATCH emacs attachment handling

2011-09-08 Thread Mark Walters
>> 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


RFC/PATCH emacs attachment handling

2011-09-08 Thread Mark Walters
(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  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


Re: RFC/PATCH emacs attachment handling

2011-09-08 Thread Matthieu Lemerre

 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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


RFC/PATCH emacs attachment handling

2011-09-07 Thread Matthieu Lemerre

> 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



RFC/PATCH emacs attachment handling

2011-09-07 Thread Xavier Maillard
Hello Tomi,

On Wed, 07 Sep 2011 10:06:36 +0300, Tomi Ollila  wrote:
> On Wed 07 Sep 2011 04:20, Mark Walters  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


RFC/PATCH emacs attachment handling

2011-09-07 Thread Tomi Ollila
On Wed 07 Sep 2011 04:20, Mark Walters  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


RFC/PATCH emacs attachment handling

2011-09-07 Thread Mark Walters

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 
 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 ( 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 ( 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
+

Re: RFC/PATCH emacs attachment handling

2011-09-07 Thread Xavier Maillard
Hello Tomi,

On Wed, 07 Sep 2011 10:06:36 +0300, Tomi Ollila tomi.oll...@iki.fi wrote:
 On Wed 07 Sep 2011 04:20, Mark Walters markwalters1...@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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


RFC/PATCH emacs attachment handling

2011-09-06 Thread Mark Walters

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
+