Re: [PATCH 1/2] emacs: Use text properties rather than overlays in `notmuch-show...
authorDavid Edmondson <dme@dme.org>
Tue, 24 Jan 2012 16:46:44 +0000 (16:46 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:08 +0000 (09:43 -0800)
8c/53e1fe69ec2f0a8f5f2cf1dc76b123c75f6f25 [new file with mode: 0644]

diff --git a/8c/53e1fe69ec2f0a8f5f2cf1dc76b123c75f6f25 b/8c/53e1fe69ec2f0a8f5f2cf1dc76b123c75f6f25
new file mode 100644 (file)
index 0000000..21b855f
--- /dev/null
@@ -0,0 +1,266 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 068FD431FBC\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 08:46:53 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id APoJSgkbLw8Q for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Jan 2012 08:46:52 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id EE280431FB6\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 08:46:51 -0800 (PST)\r
+Received: by wibhi8 with SMTP id hi8so1726794wib.26\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 08:46:50 -0800 (PST)\r
+Received: by 10.180.95.105 with SMTP id dj9mr21920739wib.18.1327423610756;\r
+       Tue, 24 Jan 2012 08:46:50 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id df2sm19684042wib.4.2012.01.24.08.46.48\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 24 Jan 2012 08:46:49 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id B96949FD47; Tue, 24 Jan 2012 16:46:47 +0000 (GMT)\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 1/2] emacs: Use text properties rather than overlays in\r
+       `notmuch-show-mode'.\r
+In-Reply-To: <20120124161511.GC16740@mit.edu>\r
+References: <1327405007-4026-1-git-send-email-dme@dme.org>\r
+       <1327405007-4026-2-git-send-email-dme@dme.org>\r
+       <20120124161511.GC16740@mit.edu>\r
+User-Agent: Notmuch/0.11+106~g382b2a0 (http://notmuchmail.org) Emacs/24.0.92.1\r
+       (x86_64-pc-linux-gnu)\r
+From: David Edmondson <dme@dme.org>\r
+Date: Tue, 24 Jan 2012 16:46:44 +0000\r
+Message-ID: <cunlioxoxor.fsf@hotblack-desiato.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+X-Gm-Message-State:\r
+ ALoCoQkKRoBBpdT1pFXY/+pHpOgi0LDfTPERHEgf3KW0og6im0uVk1pESwki0qACJTOkrZ2UNxII\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 24 Jan 2012 16:46:53 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Tue, 24 Jan 2012 11:15:11 -0500, Austin Clements <amdragon@MIT.EDU> wrot=\r
+e:\r
+> LGTM other than one very minor nit, though I pretty reliably make\r
+> fence post errors when dealing with text properties, so perhaps\r
+> somebody else should check that.\r
+>=20\r
+> Quoth David Edmondson on Jan 24 at 11:36 am:\r
+> > Except for where invisibility is involved, replace the use of overlays\r
+> > in `notmuch-show-mode' with text properties, which are more efficient\r
+> > and can be merged together more effectively.\r
+> > ---\r
+> >  emacs/notmuch-show.el |   66 +++++++++++++++++++++++++++++++----------=\r
+-------\r
+> >  emacs/notmuch-wash.el |    8 ++++-\r
+> >  2 files changed, 48 insertions(+), 26 deletions(-)\r
+> >=20\r
+> > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> > index e6a5b31..d6a0ac0 100644\r
+> > --- a/emacs/notmuch-show.el\r
+> > +++ b/emacs/notmuch-show.el\r
+> > @@ -258,10 +258,10 @@ operation on the contents of the current buffer."\r
+> >           (t\r
+> >            'message-header-other))))\r
+> >=20=20\r
+> > -    (overlay-put (make-overlay (point) (re-search-forward ":"))\r
+> > -           'face 'message-header-name)\r
+> > -    (overlay-put (make-overlay (point) (re-search-forward ".*$"))\r
+> > -           'face face)))\r
+> > +    (put-text-property (point) (re-search-forward ":")\r
+> > +                 'face 'message-header-name)\r
+> > +    (put-text-property (point) (re-search-forward ".*$")\r
+> > +                 'face face)))\r
+>=20\r
+> Does this need rear-nonsticky or are the headers already formed enough\r
+> by this point that it isn't necessary?\r
+\r
+It isn't necessary here.=20\r
+\r
+> >  (defun notmuch-show-colour-headers ()\r
+> >    "Apply some colouring to the current headers."\r
+> > @@ -278,12 +278,11 @@ operation on the contents of the current buffer."\r
+> >    "Update the displayed tags of the current message."\r
+> >    (save-excursion\r
+> >      (goto-char (notmuch-show-message-top))\r
+> > -    (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)\r
+> > -  (let ((inhibit-read-only t))\r
+> > -    (replace-match (concat "("\r
+> > -                           (propertize (mapconcat 'identity tags " ")\r
+> > -                                       'face 'notmuch-tag-face)\r
+> > -                           ")"))))))\r
+> > +    (when (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)\r
+> > +      (let ((inhibit-read-only t))\r
+> > +  (replace-match (propertize (mapconcat 'identity tags " ")\r
+> > +                             'face '(notmuch-tag-face notmuch-message-summary-face))\r
+> > +                 nil nil nil 1)))))\r
+> >=20=20\r
+> >  (defun notmuch-show-clean-address (address)\r
+> >    "Try to clean a single email ADDRESS for display.  Return\r
+> > @@ -310,15 +309,26 @@ unchanged ADDRESS if parsing fails."\r
+> >    "Insert a notmuch style headerline based on HEADERS for a\r
+> >  message at DEPTH in the current thread."\r
+> >    (let ((start (point)))\r
+> > -    (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-wid=\r
+th depth))\r
+> > -      (notmuch-show-clean-address (plist-get headers :From))\r
+> > -      " ("\r
+> > -      date\r
+> > -      ") ("\r
+> > -      (propertize (mapconcat 'identity tags " ")\r
+> > -                  'face 'notmuch-tag-face)\r
+> > -      ")\n")\r
+> > -    (overlay-put (make-overlay start (point)) 'face 'notmuch-message-s=\r
+ummary-face)))\r
+> > +    (insert\r
+> > +     (propertize (concat (notmuch-show-clean-address (plist-get header=\r
+s :From))\r
+> > +                   " ("\r
+> > +                   date\r
+> > +                   ") (")\r
+> > +           'face 'notmuch-message-summary-face)\r
+> > +     (propertize (mapconcat 'identity tags " ")\r
+> > +           'face '(notmuch-tag-face notmuch-message-summary-face))\r
+>=20\r
+> I feel like I should know this, but what's the effect of giving a list\r
+> as the face property?  I assume it merges them in the same way it\r
+> merges, say, overlay and text property faces, but the documentation\r
+> only says that you can give a list, not what it means.\r
+\r
+It's as though they are applied in reverse order, so attributes of the\r
+faces nearer the front of the list win.\r
+\r
+> > +     (propertize ")\n"\r
+> > +           'face 'notmuch-message-summary-face))\r
+> > +\r
+> > +    ;; Ensure that any insertions at the start of this line (usually\r
+> > +    ;; just spaces for indentation purposes) inherit the face of the\r
+> > +    ;; rest of the line...\r
+> > +    (put-text-property start (1+ start)\r
+> > +                 'front-sticky '(face))\r
+> > +    ;; ...and that insertions at the end of this region do _not_\r
+> > +    ;; inherit the face of the rest of this line.\r
+> > +    (put-text-property (1- (point)) (point)\r
+> > +                 'rear-nonsticky '(face))))\r
+> >=20=20\r
+> >  (defun notmuch-show-insert-header (header header-value)\r
+> >    "Insert a single header."\r
+> > @@ -753,8 +763,15 @@ current buffer, if possible."\r
+> >  (defun notmuch-show-insert-bodypart (msg part depth)\r
+> >    "Insert the body part PART at depth DEPTH in the current thread."\r
+> >    (let ((content-type (downcase (plist-get part :content-type)))\r
+> > -  (nth (plist-get part :id)))\r
+> > -    (notmuch-show-insert-bodypart-internal msg part content-type nth d=\r
+epth content-type))\r
+> > +  (nth (plist-get part :id))\r
+> > +  (start (point)))\r
+> > +    (notmuch-show-insert-bodypart-internal msg part content-type nth d=\r
+epth content-type)\r
+> > +\r
+> > +    ;; Ensure that face properties applied to text in the buffer by\r
+> > +    ;; the part handler don't leak into the following text.\r
+> > +    (put-text-property start (point-max)\r
+> > +                 'rear-nonsticky '(face)))\r
+> > +\r
+> >    ;; Some of the body part handlers leave point somewhere up in the\r
+> >    ;; part, so we make sure that we're down at the end.\r
+> >    (goto-char (point-max))\r
+> > @@ -845,11 +862,12 @@ current buffer, if possible."\r
+> >      (setq body-end (point-marker))\r
+> >      (setq content-end (point-marker))\r
+> >=20=20\r
+> > -    ;; Indent according to the depth in the thread.\r
+> > -    (indent-rigidly content-start content-end (* notmuch-show-indent-m=\r
+essages-width depth))\r
+> > -\r
+> >      (setq message-end (point-max-marker))\r
+> >=20=20\r
+> > +    ;; Indent according to the depth in the thread.\r
+> > +    (indent-rigidly message-start message-end\r
+> > +                      (* notmuch-show-indent-messages-width depth))\r
+> > +\r
+>=20\r
+> Why swap the order of the setq and the indent-rigidly?\r
+\r
+A mistake.\r
+\r
+I spent some time trying to use `line-prefix' and `wrap-prefix'\r
+properties to replace the indentation, but couldn't get it to work well\r
+when combined with invisible overlays (the effect is as though faces\r
+start bleeding out from the end of the invisible region).\r
+\r
+>=20\r
+> >      ;; Save the extents of this message over the whole text of the\r
+> >      ;; message.\r
+> >      (put-text-property message-start message-end :notmuch-message-exte=\r
+nt (cons message-start message-end))\r
+> > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el\r
+> > index 5c1e830..84428a4 100644\r
+> > --- a/emacs/notmuch-wash.el\r
+> > +++ b/emacs/notmuch-wash.el\r
+> > @@ -183,7 +183,9 @@ insert before the button, probably for indentation."\r
+> >      (let* ((cite-start (match-beginning 0))\r
+> >       (cite-end (match-end 0))\r
+> >       (cite-lines (count-lines cite-start cite-end)))\r
+> > -      (overlay-put (make-overlay cite-start cite-end) 'face 'message-c=\r
+ited-text)\r
+> > +      (put-text-property cite-start cite-end 'face 'message-cited-text)\r
+> > +      ;; Ensure that the next line doesn't inherit our face.\r
+> > +      (put-text-property (1- cite-end) cite-end 'rear-nonsticky '(face=\r
+))\r
+> >        (when (> cite-lines (+ notmuch-wash-citation-lines-prefix\r
+> >                         notmuch-wash-citation-lines-suffix\r
+> >                         1))\r
+> > @@ -205,7 +207,9 @@ insert before the button, probably for indentation."\r
+> >              (sig-end-marker (make-marker)))\r
+> >          (set-marker sig-start-marker sig-start)\r
+> >          (set-marker sig-end-marker (point-max))\r
+> > -        (overlay-put (make-overlay sig-start-marker sig-end-marker) 'fa=\r
+ce 'message-cited-text)\r
+> > +        (put-text-property sig-start-marker sig-end-marker 'face 'messa=\r
+ge-cited-text)\r
+> > +        ;; Ensure that the next line doesn't inherit our face.\r
+> > +        (put-text-property (1- sig-end-marker) sig-end-marker 'rear-non=\r
+sticky '(face))\r
+> >          (notmuch-wash-region-to-button\r
+> >           msg sig-start-marker sig-end-marker\r
+> >           "signature" "\n"))))))\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iEYEARECAAYFAk8e4HQACgkQaezQq/BJZRaoTgCfeL6mtGBcSN00F/+2t6Wq8yfC\r
+5doAnRLScsb0XxcQ85EB79zYUo3NqV12\r
+=xr9t\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r