* [PATCH v2] emacs: show: let the user override the mime-type of an attachment
@ 2016-07-11 7:49 Mark Walters
2016-09-12 11:05 ` David Bremner
0 siblings, 1 reply; 2+ messages in thread
From: Mark Walters @ 2016-07-11 7:49 UTC (permalink / raw)
To: notmuch
This allows the user to override the mime-type of a part in the show
buffer. This takes the simple option of displaying the part with the
specified mime-type in its own buffer (in view mode). This avoids
further complicating the part handling code.
Bound to ". m" (i.e., m in the part map). Then the user can either
enter a mime-type (with completion to all mime types that mailcap (and
thus notmuch) knows about, or press return for the default choice of
text/plain.
---
Hi
This is (a rather delayed) version 2 of the patch
id:1435702585-27363-1-git-send-email-markwalters1009@gmail.com
I have fixed bremner's review comment on the naming of the function,
and since it was easy I have added completion for mime-types.
It is not heavily tested but seems to work.
Best wishes
Mark
emacs/notmuch-show.el | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 6d3149b..06ba549 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1403,6 +1403,7 @@ reset based on the original query."
(define-key map "v" 'notmuch-show-view-part)
(define-key map "o" 'notmuch-show-interactively-view-part)
(define-key map "|" 'notmuch-show-pipe-part)
+ (define-key map "m" 'notmuch-show-choose-mime-of-part)
(define-key map "?" 'notmuch-subkeymap-help)
map)
"Submap for part commands")
@@ -2337,25 +2338,27 @@ omit --in-reply-to=<Message-Id>."
(insert (notmuch-get-bodypart-binary msg part process-crypto)))
buf))
-(defun notmuch-show-current-part-handle ()
+(defun notmuch-show-current-part-handle (&optional mime-type)
"Return an mm-handle for the part containing point.
This creates a temporary buffer for the part's content; the
-caller is responsible for killing this buffer as appropriate."
+caller is responsible for killing this buffer as appropriate. If
+MIME-TYPE is given then set the handle's mime-type to MIME-TYPE."
(let* ((msg (notmuch-show-get-message-properties))
(part (notmuch-show-get-part-properties))
(buf (notmuch-show-generate-part-buffer msg part))
- (computed-type (plist-get part :computed-type))
+ (computed-type (or mime-type (plist-get part :computed-type)))
(filename (plist-get part :filename))
(disposition (if filename `(attachment (filename . ,filename)))))
(mm-make-handle buf (list computed-type) nil nil disposition)))
-(defun notmuch-show-apply-to-current-part-handle (fn)
+(defun notmuch-show-apply-to-current-part-handle (fn &optional mime-type)
"Apply FN to an mm-handle for the part containing point.
This ensures that the temporary buffer created for the mm-handle
-is destroyed when FN returns."
- (let ((handle (notmuch-show-current-part-handle)))
+is destroyed when FN returns. If MIME-TYPE is given then force
+part to be treated as if it had that mime-type."
+ (let ((handle (notmuch-show-current-part-handle mime-type)))
;; emacs 24.3+ puts stdout/stderr into the calling buffer so we
;; call it from a temp-buffer, unless
;; notmuch-show-attachment-debug is non-nil in which case we put
@@ -2400,6 +2403,27 @@ is destroyed when FN returns."
(notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
+(defun notmuch-show--mm-display-part (handle)
+ "Use mm-display-part to display HANDLE in a new buffer.
+
+If the part is displayed in an external application then close
+the new buffer."
+ (let ((buf (get-buffer-create (generate-new-buffer-name
+ (concat " *notmuch-internal-part*")))))
+ (switch-to-buffer buf)
+ (if (eq (mm-display-part handle) 'external)
+ (kill-buffer buf)
+ (goto-char (point-min))
+ (set-buffer-modified-p nil)
+ (view-buffer buf 'kill-buffer-if-not-modified))))
+
+(defun notmuch-show-choose-mime-of-part (mime-type)
+ "Choose the mime type to use for displaying part"
+ (interactive
+ (list (completing-read "Mime type to use (default text/plain): "
+ (mailcap-mime-types) nil nil nil nil "text/plain")))
+ (notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type))
+
(provide 'notmuch-show)
;;; notmuch-show.el ends here
--
2.1.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] emacs: show: let the user override the mime-type of an attachment
2016-07-11 7:49 [PATCH v2] emacs: show: let the user override the mime-type of an attachment Mark Walters
@ 2016-09-12 11:05 ` David Bremner
0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2016-09-12 11:05 UTC (permalink / raw)
To: Mark Walters, notmuch
Mark Walters <markwalters1009@gmail.com> writes:
> This allows the user to override the mime-type of a part in the show
> buffer. This takes the simple option of displaying the part with the
> specified mime-type in its own buffer (in view mode). This avoids
> further complicating the part handling code.
>
> Bound to ". m" (i.e., m in the part map). Then the user can either
> enter a mime-type (with completion to all mime types that mailcap (and
> thus notmuch) knows about, or press return for the default choice of
> text/plain.
pushed,
d
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-12 11:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-11 7:49 [PATCH v2] emacs: show: let the user override the mime-type of an attachment Mark Walters
2016-09-12 11:05 ` 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).