unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v4 0/1] 
       [not found] <id:"20120118192147.GF16740@mit.edu">
@ 2012-01-19 21:23 ` Mark Walters
  2012-01-19 21:48   ` Mark Walters
  2012-01-19 21:23 ` [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving Mark Walters
  1 sibling, 1 reply; 10+ messages in thread
From: Mark Walters @ 2012-01-19 21:23 UTC (permalink / raw)
  To: notmuch

Here is a new version of the patch incorporating all the review comments. 
I have rebased it on master so, in particular, it fits into the recently
committed customization framework.

To deal with one corner case I decided to go with Austin's suggestion of 
using lexical-let as it is probably more robust to changes in mm-decode.
I would like to thank him for  all his other help improving my original 
patch.

It passes the test-suite and all cases I can think of work correctly.

Best wishes

Mark



Mark Walters (1):
  Make buttons for attachments allow viewing as well as saving

 emacs/notmuch-show.el |  116 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 92 insertions(+), 24 deletions(-)

-- 
1.7.2.3

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

* [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving
       [not found] <id:"20120118192147.GF16740@mit.edu">
  2012-01-19 21:23 ` [PATCH v4 0/1] Mark Walters
@ 2012-01-19 21:23 ` Mark Walters
  2012-01-20  4:30   ` Austin Clements
  1 sibling, 1 reply; 10+ messages in thread
From: Mark Walters @ 2012-01-19 21:23 UTC (permalink / raw)
  To: notmuch

Define a keymap for attachment buttons to allow multiple actions.
Define 3 possible actions:
    save attachment: exactly as currently,
    view attachment: uses mailcap entry,
    view attachment with user chosen program

Keymap on a button is: s for save, v for view and o for view with
other program. Default (i.e. enter or mouse button) is save but this
is configurable in notmuch customize.

One implementation detail: the view attachment function forces all
attachments to be "displayed" using mailcap even if emacs could
display them itself. Thus, for example, text/html appears in a browser
and text/plain asks whether to save (on a standard debian setup)
---
 emacs/notmuch-show.el |  116 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 92 insertions(+), 24 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index fc13462..1fcd72a 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -112,6 +112,16 @@ indentation."
   :type 'boolean
   :group 'notmuch-show)
 
+(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
+  "Default part header button action (on ENTER or mouse click)."
+  :group 'notmuch-show
+  :type '(choice (const :tag "Save part"
+			notmuch-show-save-part)
+		 (const :tag "View part"
+			notmuch-show-view-part)
+		 (const :tag "View interactively"
+			notmuch-show-interactively-view-part)))
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -283,10 +293,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-default
+  '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)
+    (define-key map "v" 'notmuch-show-part-button-view)
+    (define-key map "o" 'notmuch-show-part-button-interactively-view)
+    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
@@ -301,29 +322,58 @@ 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))
 
 ;; Functions handling particular MIME parts.
 
-(defun notmuch-show-save-part (message-id nth &optional filename)
-  (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 ((file (read-file-name
-		   "Filename to save as: "
-		   (or mailcap-download-directory "~/")
-		   nil nil
-		   filename)))
-	;; Don't re-compress .gz & al.  Arguably we should make
-	;; `file-name-handler-alist' nil, but that would chop
-	;; ange-ftp, which is reasonable to use here.
-	(mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
+(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
+  (declare (indent 2))
+  (let ((process-crypto (make-symbol "process-crypto")))
+    `(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))
+	 ,@body))))
+
+(defun notmuch-show-save-part (message-id nth &optional filename content-type)
+  (notmuch-with-temp-part-buffer message-id nth
+    (let ((file (read-file-name
+		 "Filename to save as: "
+		 (or mailcap-download-directory "~/")
+		 nil nil
+		 filename)))
+      ;; Don't re-compress .gz & al.  Arguably we should make
+      ;; `file-name-handler-alist' nil, but that would chop
+      ;; 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 &optional filename content-type )
+  (notmuch-with-temp-part-buffer 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))
+      ;; We override mm-save-part as notmuch-show-save-part is better
+      ;; since it offers the filename. We need to lexically bind
+      ;; everything we need for notmuch-show-save-part to prevent
+      ;; potential dynamic shadowing.
+      (lexical-let ((message-id message-id)
+		    (nth nth)
+		    (filename filename)
+		    (content-type content-type))
+		   (flet ((mm-save-part (&rest args) (notmuch-show-save-part
+						      message-id nth filename content-type)))
+		     (mm-display-part handle))))))
+
+(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
+  (notmuch-with-temp-part-buffer 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 nth content-type)
   "Use the mm-decode/mm-view functions to display a part in the
@@ -1504,12 +1554,30 @@ 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-default (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
+
+(defun notmuch-show-part-button-save (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-save-part))
+
+(defun notmuch-show-part-button-view (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-view-part))
+
+(defun notmuch-show-part-button-interactively-view (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
+
+(defun notmuch-show-part-button-internal (button handler)
+  (let ((button (or button (button-at (point)))))
+    (if button
+	(let ((nth (button-get button :notmuch-part)))
+	  (if nth
+	      (funcall handler (notmuch-show-get-message-id) nth
+		       (button-get button :notmuch-filename)
+		       (button-get button :notmuch-content-type)))))))
 
 ;;
 
-- 
1.7.2.3

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

* Re: [PATCH v4 0/1]
  2012-01-19 21:23 ` [PATCH v4 0/1] Mark Walters
@ 2012-01-19 21:48   ` Mark Walters
  0 siblings, 0 replies; 10+ messages in thread
From: Mark Walters @ 2012-01-19 21:48 UTC (permalink / raw)
  To: notmuch


Sorry this should have been in-reply-to
id:"20120118192147.GF16740@mit.edu" 

Mark

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

* Re: [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving
  2012-01-19 21:23 ` [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving Mark Walters
@ 2012-01-20  4:30   ` Austin Clements
  2012-01-20  9:42     ` Mark Walters
  0 siblings, 1 reply; 10+ messages in thread
From: Austin Clements @ 2012-01-20  4:30 UTC (permalink / raw)
  To: Mark Walters; +Cc: notmuch

One indentation nit and then this LGTM.

Quoth Mark Walters on Jan 19 at  9:23 pm:
> Define a keymap for attachment buttons to allow multiple actions.
> Define 3 possible actions:
>     save attachment: exactly as currently,
>     view attachment: uses mailcap entry,
>     view attachment with user chosen program
> 
> Keymap on a button is: s for save, v for view and o for view with
> other program. Default (i.e. enter or mouse button) is save but this
> is configurable in notmuch customize.
> 
> One implementation detail: the view attachment function forces all
> attachments to be "displayed" using mailcap even if emacs could
> display them itself. Thus, for example, text/html appears in a browser
> and text/plain asks whether to save (on a standard debian setup)
> ---
>  emacs/notmuch-show.el |  116 ++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 92 insertions(+), 24 deletions(-)
> 
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index fc13462..1fcd72a 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -112,6 +112,16 @@ indentation."
>    :type 'boolean
>    :group 'notmuch-show)
>  
> +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
> +  "Default part header button action (on ENTER or mouse click)."
> +  :group 'notmuch-show
> +  :type '(choice (const :tag "Save part"
> +			notmuch-show-save-part)
> +		 (const :tag "View part"
> +			notmuch-show-view-part)
> +		 (const :tag "View interactively"
> +			notmuch-show-interactively-view-part)))
> +
>  (defmacro with-current-notmuch-show-message (&rest body)
>    "Evaluate body with current buffer set to the text of current message"
>    `(save-excursion
> @@ -283,10 +293,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-default
> +  '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)
> +    (define-key map "v" 'notmuch-show-part-button-view)
> +    (define-key map "o" 'notmuch-show-part-button-interactively-view)
> +    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
> @@ -301,29 +322,58 @@ 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))
>  
>  ;; Functions handling particular MIME parts.
>  
> -(defun notmuch-show-save-part (message-id nth &optional filename)
> -  (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 ((file (read-file-name
> -		   "Filename to save as: "
> -		   (or mailcap-download-directory "~/")
> -		   nil nil
> -		   filename)))
> -	;; Don't re-compress .gz & al.  Arguably we should make
> -	;; `file-name-handler-alist' nil, but that would chop
> -	;; ange-ftp, which is reasonable to use here.
> -	(mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
> +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
> +  (declare (indent 2))
> +  (let ((process-crypto (make-symbol "process-crypto")))
> +    `(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))
> +	 ,@body))))
> +
> +(defun notmuch-show-save-part (message-id nth &optional filename content-type)
> +  (notmuch-with-temp-part-buffer message-id nth
> +    (let ((file (read-file-name
> +		 "Filename to save as: "
> +		 (or mailcap-download-directory "~/")
> +		 nil nil
> +		 filename)))
> +      ;; Don't re-compress .gz & al.  Arguably we should make
> +      ;; `file-name-handler-alist' nil, but that would chop
> +      ;; 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 &optional filename content-type )
> +  (notmuch-with-temp-part-buffer 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))
> +      ;; We override mm-save-part as notmuch-show-save-part is better
> +      ;; since it offers the filename. We need to lexically bind
> +      ;; everything we need for notmuch-show-save-part to prevent
> +      ;; potential dynamic shadowing.
> +      (lexical-let ((message-id message-id)
> +		    (nth nth)
> +		    (filename filename)
> +		    (content-type content-type))
> +		   (flet ((mm-save-part (&rest args) (notmuch-show-save-part

This body of lexical-let should be indented like a normal let body.
You might have to load cl to get this indentation rule.

> +						      message-id nth filename content-type)))
> +		     (mm-display-part handle))))))
> +
> +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
> +  (notmuch-with-temp-part-buffer 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 nth content-type)
>    "Use the mm-decode/mm-view functions to display a part in the
> @@ -1504,12 +1554,30 @@ 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-default (&optional button)
> +  (interactive)
> +  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
> +
> +(defun notmuch-show-part-button-save (&optional button)
> +  (interactive)
> +  (notmuch-show-part-button-internal button #'notmuch-show-save-part))
> +
> +(defun notmuch-show-part-button-view (&optional button)
> +  (interactive)
> +  (notmuch-show-part-button-internal button #'notmuch-show-view-part))
> +
> +(defun notmuch-show-part-button-interactively-view (&optional button)
> +  (interactive)
> +  (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
> +
> +(defun notmuch-show-part-button-internal (button handler)
> +  (let ((button (or button (button-at (point)))))
> +    (if button
> +	(let ((nth (button-get button :notmuch-part)))
> +	  (if nth
> +	      (funcall handler (notmuch-show-get-message-id) nth
> +		       (button-get button :notmuch-filename)
> +		       (button-get button :notmuch-content-type)))))))
>  
>  ;;
>  

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

* Re: [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving
  2012-01-20  4:30   ` Austin Clements
@ 2012-01-20  9:42     ` Mark Walters
  2012-01-20  9:44       ` [PATCH v5] " Mark Walters
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Walters @ 2012-01-20  9:42 UTC (permalink / raw)
  To: Austin Clements; +Cc: notmuch


On Thu, 19 Jan 2012 23:30:23 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
> One indentation nit and then this LGTM.
> 
> > +      (lexical-let ((message-id message-id)
> > +		    (nth nth)
> > +		    (filename filename)
> > +		    (content-type content-type))
> > +		   (flet ((mm-save-part (&rest args) (notmuch-show-save-part
> 
> This body of lexical-let should be indented like a normal let body.
> You might have to load cl to get this indentation rule.

Fixed. Patch to follow in reply.

Thanks

Mark

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

* [PATCH v5] Make buttons for attachments allow viewing as well as saving
  2012-01-20  9:42     ` Mark Walters
@ 2012-01-20  9:44       ` Mark Walters
  2012-01-20 16:42         ` Austin Clements
  2012-01-21 13:09         ` David Bremner
  0 siblings, 2 replies; 10+ messages in thread
From: Mark Walters @ 2012-01-20  9:44 UTC (permalink / raw)
  To: notmuch

Define a keymap for attachment buttons to allow multiple actions.
Define 3 possible actions:
    save attachment: exactly as currently,
    view attachment: uses mailcap entry,
    view attachment with user chosen program

Keymap on a button is: s for save, v for view and o for view with
other program. Default (i.e. enter or mouse button) is save but this
is configurable in notmuch customize.

One implementation detail: the view attachment function forces all
attachments to be "displayed" using mailcap even if emacs could
display them itself. Thus, for example, text/html appears in a browser
and text/plain asks whether to save (on a standard debian setup)
---
 emacs/notmuch-show.el |  116 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 92 insertions(+), 24 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index fc13462..6229432 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -112,6 +112,16 @@ indentation."
   :type 'boolean
   :group 'notmuch-show)
 
+(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
+  "Default part header button action (on ENTER or mouse click)."
+  :group 'notmuch-show
+  :type '(choice (const :tag "Save part"
+			notmuch-show-save-part)
+		 (const :tag "View part"
+			notmuch-show-view-part)
+		 (const :tag "View interactively"
+			notmuch-show-interactively-view-part)))
+
 (defmacro with-current-notmuch-show-message (&rest body)
   "Evaluate body with current buffer set to the text of current message"
   `(save-excursion
@@ -283,10 +293,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-default
+  '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)
+    (define-key map "v" 'notmuch-show-part-button-view)
+    (define-key map "o" 'notmuch-show-part-button-interactively-view)
+    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
@@ -301,29 +322,58 @@ 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))
 
 ;; Functions handling particular MIME parts.
 
-(defun notmuch-show-save-part (message-id nth &optional filename)
-  (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 ((file (read-file-name
-		   "Filename to save as: "
-		   (or mailcap-download-directory "~/")
-		   nil nil
-		   filename)))
-	;; Don't re-compress .gz & al.  Arguably we should make
-	;; `file-name-handler-alist' nil, but that would chop
-	;; ange-ftp, which is reasonable to use here.
-	(mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
+(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
+  (declare (indent 2))
+  (let ((process-crypto (make-symbol "process-crypto")))
+    `(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))
+	 ,@body))))
+
+(defun notmuch-show-save-part (message-id nth &optional filename content-type)
+  (notmuch-with-temp-part-buffer message-id nth
+    (let ((file (read-file-name
+		 "Filename to save as: "
+		 (or mailcap-download-directory "~/")
+		 nil nil
+		 filename)))
+      ;; Don't re-compress .gz & al.  Arguably we should make
+      ;; `file-name-handler-alist' nil, but that would chop
+      ;; 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 &optional filename content-type )
+  (notmuch-with-temp-part-buffer 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))
+      ;; We override mm-save-part as notmuch-show-save-part is better
+      ;; since it offers the filename. We need to lexically bind
+      ;; everything we need for notmuch-show-save-part to prevent
+      ;; potential dynamic shadowing.
+      (lexical-let ((message-id message-id)
+		    (nth nth)
+		    (filename filename)
+		    (content-type content-type))
+	(flet ((mm-save-part (&rest args) (notmuch-show-save-part
+					   message-id nth filename content-type)))
+	  (mm-display-part handle))))))
+
+(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
+  (notmuch-with-temp-part-buffer 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 nth content-type)
   "Use the mm-decode/mm-view functions to display a part in the
@@ -1504,12 +1554,30 @@ 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-default (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
+
+(defun notmuch-show-part-button-save (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-save-part))
+
+(defun notmuch-show-part-button-view (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-view-part))
+
+(defun notmuch-show-part-button-interactively-view (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))
+
+(defun notmuch-show-part-button-internal (button handler)
+  (let ((button (or button (button-at (point)))))
+    (if button
+	(let ((nth (button-get button :notmuch-part)))
+	  (if nth
+	      (funcall handler (notmuch-show-get-message-id) nth
+		       (button-get button :notmuch-filename)
+		       (button-get button :notmuch-content-type)))))))
 
 ;;
 
-- 
1.7.2.3

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

* Re: [PATCH v5] Make buttons for attachments allow viewing as well as saving
  2012-01-20  9:44       ` [PATCH v5] " Mark Walters
@ 2012-01-20 16:42         ` Austin Clements
  2012-01-21 13:09         ` David Bremner
  1 sibling, 0 replies; 10+ messages in thread
From: Austin Clements @ 2012-01-20 16:42 UTC (permalink / raw)
  To: Mark Walters; +Cc: notmuch

LGTM

Quoth Mark Walters on Jan 20 at  9:44 am:
> Define a keymap for attachment buttons to allow multiple actions.
> Define 3 possible actions:
>     save attachment: exactly as currently,
>     view attachment: uses mailcap entry,
>     view attachment with user chosen program
> 
> Keymap on a button is: s for save, v for view and o for view with
> other program. Default (i.e. enter or mouse button) is save but this
> is configurable in notmuch customize.
> 
> One implementation detail: the view attachment function forces all
> attachments to be "displayed" using mailcap even if emacs could
> display them itself. Thus, for example, text/html appears in a browser
> and text/plain asks whether to save (on a standard debian setup)

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

* Re: [PATCH v5] Make buttons for attachments allow viewing as well as saving
  2012-01-20  9:44       ` [PATCH v5] " Mark Walters
  2012-01-20 16:42         ` Austin Clements
@ 2012-01-21 13:09         ` David Bremner
  2012-02-29  9:31           ` [PATCH v5] News for " Mark Walters
  1 sibling, 1 reply; 10+ messages in thread
From: David Bremner @ 2012-01-21 13:09 UTC (permalink / raw)
  To: Mark Walters, notmuch

On Fri, 20 Jan 2012 09:44:06 +0000, Mark Walters <markwalters1009@gmail.com> wrote:
> Define a keymap for attachment buttons to allow multiple actions.
> Define 3 possible actions:
>     save attachment: exactly as currently,
>     view attachment: uses mailcap entry,
>     view attachment with user chosen program

pushed.

d

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

* [PATCH v5] News for Make buttons for attachments allow viewing as well as saving
  2012-01-21 13:09         ` David Bremner
@ 2012-02-29  9:31           ` Mark Walters
  2012-02-29 11:27             ` David Bremner
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Walters @ 2012-02-29  9:31 UTC (permalink / raw)
  To: David Bremner, notmuch


On Sat, 21 Jan 2012 09:09:58 -0400, David Bremner <david@tethera.net> wrote:
> On Fri, 20 Jan 2012 09:44:06 +0000, Mark Walters <markwalters1009@gmail.com> wrote:
> > Define a keymap for attachment buttons to allow multiple actions.
> > Define 3 possible actions:
> >     save attachment: exactly as currently,
> >     view attachment: uses mailcap entry,
> >     view attachment with user chosen program
> 
> pushed.

Here is a News patch for this feature.

Best wishes

Mark

From fde33258850a438f1810e4158c946b3cf185b5e8 Mon Sep 17 00:00:00 2001
From: Mark Walters <markwalters1009@gmail.com>
Date: Wed, 29 Feb 2012 09:26:17 +0000
Subject: [PATCH] News item for allowing attachment buttons to view as well as save.

---
 NEWS |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index b2bec04..8fb2f24 100644
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,15 @@ Refreshing the show view ('=' by default) no longer opens or closes messages
   To get the old behavior of putting messages back in their initial
   opened/closed state, use a prefix argument, e.g., C-u =.
 
+Attachment buttons can be used to view or save attachments.
+
+  When the cursor is on an attachment button the key 's' can be used
+  to save the attachment, the key 'v' to view the attachment in the
+  default mailcap application, and the key 'o' prompts the user for an
+  application to use to open the attachment. By default Enter or mouse
+  button 1 saves the attachment but this is customisable (option
+  Notmuch Show Part Button Default Action).
+
 Library changes
 ---------------
 
-- 
1.7.2.3

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

* Re: [PATCH v5] News for Make buttons for attachments allow viewing as well as saving
  2012-02-29  9:31           ` [PATCH v5] News for " Mark Walters
@ 2012-02-29 11:27             ` David Bremner
  0 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2012-02-29 11:27 UTC (permalink / raw)
  To: Mark Walters, notmuch

> 
> Here is a News patch for this feature.
> 

Also pushed. The commit message comes out slightly eccentric, but I
decided to leave it.

d

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

end of thread, other threads:[~2012-02-29 11:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <id:"20120118192147.GF16740@mit.edu">
2012-01-19 21:23 ` [PATCH v4 0/1] Mark Walters
2012-01-19 21:48   ` Mark Walters
2012-01-19 21:23 ` [PATCH v4 1/1] Make buttons for attachments allow viewing as well as saving Mark Walters
2012-01-20  4:30   ` Austin Clements
2012-01-20  9:42     ` Mark Walters
2012-01-20  9:44       ` [PATCH v5] " Mark Walters
2012-01-20 16:42         ` Austin Clements
2012-01-21 13:09         ` David Bremner
2012-02-29  9:31           ` [PATCH v5] News for " Mark Walters
2012-02-29 11:27             ` 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).