[PATCH v3 2/8] emacs: Use text properties instead of overlays for tag coloring
authorAustin Clements <amdragon@MIT.EDU>
Sat, 14 Jul 2012 23:02:14 +0000 (19:02 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:19 +0000 (09:48 -0800)
08/5dcee75a0abc265015b927738dbf69af1fe5a6 [new file with mode: 0644]

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