Re: [PATCH 2/7] emacs: Use text properties instead of overlays for tag coloring
authorMark Walters <markwalters1009@gmail.com>
Fri, 13 Jul 2012 17:59:31 +0000 (18:59 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:16 +0000 (09:48 -0800)
b2/418943381fb381e1534c713db5ea5301f24f2a [new file with mode: 0644]

diff --git a/b2/418943381fb381e1534c713db5ea5301f24f2a b/b2/418943381fb381e1534c713db5ea5301f24f2a
new file mode 100644 (file)
index 0000000..a490a35
--- /dev/null
@@ -0,0 +1,173 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 ACDCA431FC3\r
+       for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 10:59:35 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 s2hMK6ZjvsZx for <notmuch@notmuchmail.org>;\r
+       Fri, 13 Jul 2012 10:59:35 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id E82DD431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 10:59:34 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Spk9N-0003ym-7i; Fri, 13 Jul 2012 18:59:33 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Spk9M-0005hd-Se; Fri, 13 Jul 2012 18:59:33 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/7] emacs: Use text properties instead of overlays for\r
+       tag coloring\r
+In-Reply-To: <1342140319-19859-3-git-send-email-amdragon@mit.edu>\r
+References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
+       <1342140319-19859-3-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.13.2+63~g1397edd (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Fri, 13 Jul 2012 18:59:31 +0100\r
+Message-ID: <877gu78ruk.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: d08814ee630b582fb450331a739313c0 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Fri, 13 Jul 2012 17:59:35 -0000\r
+\r
+On Fri, 13 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Previously, tag-based search result highlighting was done by creating\r
+> an overlay over each search result.  However, overlays have annoying\r
+> front- and rear-advancement semantics that make it difficult to\r
+> manipulate text at their boundaries, which the next patch will do.\r
+> They also have performance problems (creating an overlay is linear in\r
+> the number of overlays between point and the new overlay, making\r
+> highlighting a search buffer quadratic in the number of results).\r
+>\r
+> Text properties have neither problem.  However, text properties make\r
+> it more difficult to apply multiple faces since, unlike with overlays,\r
+> a given character can only have a single 'face text property.  Hence,\r
+> we introduce a utility function that combines faces into any existing\r
+> 'face text properties.\r
+>\r
+> Using this utility function, it's straightforward to apply all of the\r
+> appropriate tag faces in notmuch-search-color-line.\r
+\r
+I have some recollection of people talking about text properties as\r
+opposed to overlays some time ago but saying one problem was you\r
+couldn't do invisibility with text properties. Is that correct and is it\r
+a concern? (Otherwise it all looks good)\r
+\r
+Best wishes\r
+\r
+Mark\r
+> ---\r
+>  emacs/notmuch-lib.el |   15 +++++++++++++++\r
+>  emacs/notmuch.el     |   21 +++++++--------------\r
+>  2 files changed, 22 insertions(+), 14 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index aa25513..30db58f 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -269,6 +269,21 @@ current buffer, if possible."\r
+>    (loop for (key value . rest) on plist by #'cddr\r
+>      collect (cons (intern (substring (symbol-name key) 1)) value)))\r
+>  \r
+> +(defun notmuch-combine-face-text-property (start end face)\r
+> +  "Combine FACE into the 'face text property between START and END.\r
+> +\r
+> +This function combines FACE with any existing faces between START\r
+> +and END.  Attributes specified by FACE take precedence over\r
+> +existing attributes.  FACE must be a face name (a symbol or\r
+> +string), a property list of face attributes, or a list of these."\r
+> +\r
+> +  (let ((pos start))\r
+> +    (while (< pos end)\r
+> +      (let ((cur (get-text-property pos 'face))\r
+> +        (next (next-single-property-change pos 'face nil end)))\r
+> +    (put-text-property pos next 'face (cons face cur))\r
+> +    (setq pos next)))))\r
+> +\r
+>  ;; Compatibility functions for versions of emacs before emacs 23.\r
+>  ;;\r
+>  ;; Both functions here were copied from emacs 23 with the following copyright:\r
+> diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+> index ef18927..82c148d 100644\r
+> --- a/emacs/notmuch.el\r
+> +++ b/emacs/notmuch.el\r
+> @@ -633,20 +633,13 @@ foreground and blue background."\r
+>  \r
+>  (defun notmuch-search-color-line (start end line-tag-list)\r
+>    "Colorize lines in `notmuch-show' based on tags."\r
+> -  ;; Create the overlay only if the message has tags which match one\r
+> -  ;; of those specified in `notmuch-search-line-faces'.\r
+> -  (let (overlay)\r
+> -    (mapc (lambda (elem)\r
+> -        (let ((tag (car elem))\r
+> -              (attributes (cdr elem)))\r
+> -          (when (member tag line-tag-list)\r
+> -            (when (not overlay)\r
+> -              (setq overlay (make-overlay start end)))\r
+> -            ;; Merge the specified properties with any already\r
+> -            ;; applied from an earlier match.\r
+> -            (overlay-put overlay 'face\r
+> -                         (append (overlay-get overlay 'face) attributes)))))\r
+> -      notmuch-search-line-faces)))\r
+> +  (mapc (lambda (elem)\r
+> +      (let ((tag (car elem))\r
+> +            (attributes (cdr elem)))\r
+> +        (when (member tag line-tag-list)\r
+> +          (notmuch-combine-face-text-property start end attributes))))\r
+> +    ;; Reverse the list so earlier entries take precedence\r
+> +    (reverse notmuch-search-line-faces)))\r
+>  \r
+>  (defun notmuch-search-author-propertize (authors)\r
+>    "Split `authors' into matching and non-matching authors and\r
+> -- \r
+> 1.7.10\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r