]> git.notmuchmail.org Git - notmuch/commitdiff
emacs: insert quotable parts in reply as they are displayed in show view
authorJani Nikula <jani@nikula.org>
Sun, 1 Sep 2013 17:59:53 +0000 (20:59 +0300)
committerDavid Bremner <bremner@debian.org>
Thu, 5 Sep 2013 09:38:24 +0000 (06:38 -0300)
In reply, insert quotable parts using notmuch-show-insert-bodypart
instead of calling notmuch-mm-display-part-inline directly to render
the quoted parts as they are rendered in show view.

We use a temp buffer to not leak text properties from the show
renderer into the reply. This way we also don't need to worry about
narrowing or point placement. Credits to Mark Walters
<markwalters1009@gmail.com> and Austin Clements <amdragon@MIT.EDU> for
getting this part straight.

The notable change is that replies to text/calendar parts quote the
pretty printed output of icalendar-import-buffer rather than the ugly
raw vcalendar.

emacs/notmuch-mua.el
emacs/notmuch-show.el

index 2baae5f111f5a04c5d48c6de1ccb43bf47b7fb2d..ff8149b4bd9ec6ef50cdb3619726292a003f28b2 100644 (file)
@@ -28,6 +28,8 @@
 
 (eval-when-compile (require 'cl))
 
+(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth &optional hide))
+
 ;;
 
 (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
@@ -128,12 +130,15 @@ list."
          collect part))
 
 (defun notmuch-mua-insert-quotable-part (message part)
-  (save-restriction
-    (narrow-to-region (point) (point))
-    (notmuch-mm-display-part-inline message part (plist-get part :id)
-                                   (plist-get part :content-type)
-                                   notmuch-show-process-crypto)
-    (goto-char (point-max))))
+  ;; We don't want text properties leaking from the show renderer into
+  ;; the reply so we use a temp buffer. Also we don't want hooks, such
+  ;; as notmuch-wash-*, to be run on the quotable part so we set
+  ;; notmuch-show-insert-text/plain-hook to nil.
+  (insert (with-temp-buffer
+           (let ((notmuch-show-insert-text/plain-hook nil))
+             ;; Show the part but do not add buttons.
+             (notmuch-show-insert-bodypart message part 0 'no-buttons))
+           (buffer-substring-no-properties (point-min) (point-max)))))
 
 ;; There is a bug in emacs 23's message.el that results in a newline
 ;; not being inserted after the References header, so the next header
index 2896aae855ca78e076d2a4b098ddd108078c4203..904b98e1865fa7bfebadf1fa96b1b86419fe7a99 100644 (file)
@@ -844,7 +844,11 @@ message at DEPTH in the current thread."
 (defun notmuch-show-insert-bodypart (msg part depth &optional hide)
   "Insert the body part PART at depth DEPTH in the current thread.
 
-If HIDE is non-nil then initially hide this part."
+HIDE determines whether to show or hide the part and the button
+as follows: If HIDE is nil, show the part and the button. If HIDE
+is t, hide the part initially and show the button. If HIDE is
+'no-buttons, show the part but do not add any buttons (this is
+useful for quoting in replies)."
 
   (let* ((content-type (downcase (plist-get part :content-type)))
         (mime-type (or (and (string= content-type "application/octet-stream")
@@ -854,15 +858,19 @@ If HIDE is non-nil then initially hide this part."
                        content-type))
         (nth (plist-get part :id))
         (beg (point))
-        ;; We omit the part button for the first (or only) part if this is text/plain.
-        (button (unless (and (string= mime-type "text/plain") (<= nth 1))
+        ;; Hide the part initially if HIDE is t.
+        (show-part (not (equal hide t)))
+        ;; We omit the part button for the first (or only) part if
+        ;; this is text/plain, or HIDE is 'no-buttons.
+        (button (unless (or (equal hide 'no-buttons)
+                            (and (string= mime-type "text/plain") (<= nth 1)))
                   (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))
         (content-beg (point)))
 
     ;; Store the computed mime-type for later use (e.g. by attachment handlers).
     (plist-put part :computed-type mime-type)
 
-    (if (not hide)
+    (if show-part
         (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)
       (button-put button :notmuch-lazy-part
                   (list msg part mime-type nth depth button)))
@@ -875,7 +883,7 @@ If HIDE is non-nil then initially hide this part."
       (insert "\n"))
     ;; We do not create the overlay for hidden (lazy) parts until
     ;; they are inserted.
-    (if (not hide)
+    (if show-part
        (notmuch-show-create-part-overlays button content-beg (point))
       (save-excursion
        (notmuch-show-toggle-part-invisibility button)))