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 110DE429E27 for ; Sat, 14 Jul 2012 16:02:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 PlW3kCVAcO29 for ; Sat, 14 Jul 2012 16:02:30 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 35C74429E29 for ; Sat, 14 Jul 2012 16:02:26 -0700 (PDT) X-AuditID: 1209190f-b7f306d0000008b4-09-5001fa825829 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id F1.36.02228.28AF1005; Sat, 14 Jul 2012 19:02:26 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6EN2P7Z010942; Sat, 14 Jul 2012 19:02:25 -0400 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6EN2NSG008494 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 14 Jul 2012 19:02:24 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1SqBLz-0002G5-Pd; Sat, 14 Jul 2012 19:02:23 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 2/8] emacs: Use text properties instead of overlays for tag coloring Date: Sat, 14 Jul 2012 19:02:14 -0400 Message-Id: <1342306940-7499-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1342306940-7499-1-git-send-email-amdragon@mit.edu> References: <1342140319-19859-1-git-send-email-amdragon@mit.edu> <1342306940-7499-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsUixG6nrtv0izHAoO2NjMWefV4Wq+fyWFy/ OZPZgdnj7mkuj52z7rJ7PFt1izmAOYrLJiU1J7MstUjfLoErY/bGlIIZ0hVrdnezNjB2iXUx cnJICJhITJ+4kR3CFpO4cG89WxcjF4eQwD5GiZmb17NDOBsYJY4emMgE4Txikvh7/jMrhDOX UWLWl8nMIP1sAhoS2/YvZwSxRQSkJXbenc0KYjMLpEl8b38LFOfgEBYIl3j4SRUkzCKgKvH/ 4nMmEJtXwF5i3vM1zBBnyEs8vd/HBmJzCjhIHL5wAmyMkECZxI0n31knMPIvYGRYxSibklul m5uYmVOcmqxbnJyYl5dapGuil5tZopeaUrqJERRWnJL8Oxi/HVQ6xCjAwajEw9s8nTFAiDWx rLgy9xCjJAeTkijv5q9AIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8EiA53pTEyqrUonyYlDQH i5I479WUm/5CAumJJanZqakFqUUwWRkODiUJ3sKfQI2CRanpqRVpmTklCGkmDk6Q4TxAw7tB aniLCxJzizPTIfKnGBWlxHl7QRICIImM0jy4Xljcv2IUB3pFmDcbpIoHmDLgul8BDWYCGjzr 5z9/oMEliQgpqQbG8ESn/weCH+7Kfftr6h2RidlH2vnmLAqo3qPTLvhMxWSFg3FY5ZZ1Ba/2 ZYcdyk3pEmbYUWP7nHPZ25UJjfOE/n1qq1ioZf7UdsYOSY/KyKwr3888eJprnxlt4HVk4mZR kVXJDVvCvXc9mnp8yy0F5VUvTrc8DxX+3dax7o5bz9LJ9/m9L0XsUmIpzkg01GIuKk4EACr7 KKrWAgAA 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: Sat, 14 Jul 2012 23:02:32 -0000 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. --- 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