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