From 79d2fcb81bd9bf67f75d1d10d5941af4ac9e0d7b Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sun, 1 Sep 2013 19:03:34 +0100 Subject: [PATCH] Re: [PATCH] emacs: insert quotable parts in reply as they are displayed in show view --- 6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d | 188 ++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d diff --git a/6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d b/6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d new file mode 100644 index 000000000..5e059f0a3 --- /dev/null +++ b/6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d @@ -0,0 +1,188 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B3BC3431FC0 + for ; Sun, 1 Sep 2013 11:03:46 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id HPsDWAnexEi2 for ; + Sun, 1 Sep 2013 11:03:42 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D4E4C431FBC + for ; Sun, 1 Sep 2013 11:03:41 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1VGBzs-0004Dm-Lf; Sun, 01 Sep 2013 19:03:37 +0100 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71) + (envelope-from ) + id 1VGBzs-0004iU-76; Sun, 01 Sep 2013 19:03:36 +0100 +From: Mark Walters +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH] emacs: insert quotable parts in reply as they are + displayed in show view +In-Reply-To: <1378058393-29590-1-git-send-email-jani@nikula.org> +References: <1378058393-29590-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.15.2+269~g01f5508 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sun, 01 Sep 2013 19:03:34 +0100 +Message-ID: <87li3gifm1.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: a75e901657806feaa64c741356378bf4 (of first 20000 bytes) +X-SpamAssassin-Score: 0.0 +X-SpamAssassin-SpamBar: / +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored 0.0 points. Summary of the scoring: + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 0.0 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 01 Sep 2013 18:03:46 -0000 + + +This version gets a +1 from me + +Mark + + +On Sun, 01 Sep 2013, Jani Nikula wrote: +> 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 +> and Austin Clements 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. +> +> --- +> +> v2: use (narrow-to-region (point-min) (point)) in +> notmuch-mua-insert-quotable-part instead of adding the ugly recenter +> in notmuch-mua-reply. Thanks to Austin and Mark for figuring this out. +> +> v3: Incorporate id:87eh98twws.fsf@qmul.ac.uk from Mark +> --- +> emacs/notmuch-mua.el | 17 +++++++++++------ +> emacs/notmuch-show.el | 18 +++++++++++++----- +> 2 files changed, 24 insertions(+), 11 deletions(-) +> +> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +> index 2baae5f..ff8149b 100644 +> --- a/emacs/notmuch-mua.el +> +++ b/emacs/notmuch-mua.el +> @@ -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 +> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +> index 2896aae..904b98e 100644 +> --- a/emacs/notmuch-show.el +> +++ b/emacs/notmuch-show.el +> @@ -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))) +> -- +> 1.8.4.rc3 -- 2.26.2