[PATCH 1/2] emacs: Handle all face forms when combining faces
authorAustin Clements <amdragon@MIT.EDU>
Mon, 4 Feb 2013 21:37:01 +0000 (16:37 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:29 +0000 (09:53 -0800)
5b/5aff0e791e944e376d390605ae4ab8faf158f1 [new file with mode: 0644]

diff --git a/5b/5aff0e791e944e376d390605ae4ab8faf158f1 b/5b/5aff0e791e944e376d390605ae4ab8faf158f1
new file mode 100644 (file)
index 0000000..65e44b3
--- /dev/null
@@ -0,0 +1,136 @@
+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 716A9431FBC\r
+       for <notmuch@notmuchmail.org>; Mon,  4 Feb 2013 13:37:13 -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 o7GFAuKUBv40 for <notmuch@notmuchmail.org>;\r
+       Mon,  4 Feb 2013 13:37:11 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1A759431FBD\r
+       for <notmuch@notmuchmail.org>; Mon,  4 Feb 2013 13:37:11 -0800 (PST)\r
+X-AuditID: 12074423-b7f5b6d000007e03-f8-51102a0689c1\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 7F.F9.32259.60A20115; Mon,  4 Feb 2013 16:37:10 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH-1.MIT.EDU [18.9.28.11])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r14Lb8kC004394; \r
+       Mon, 4 Feb 2013 16:37:08 -0500\r
+Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r14Lb69e016770\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 4 Feb 2013 16:37:07 -0500\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1U2Tis-0001mu-55; Mon, 04 Feb 2013 16:37:06 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] emacs: Handle all face forms when combining faces\r
+Date: Mon,  4 Feb 2013 16:37:01 -0500\r
+Message-Id: <1360013822-6562-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1360013822-6562-1-git-send-email-amdragon@mit.edu>\r
+References: <1360013822-6562-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsUixCmqrcumJRBocHStgMWuu1uZLK7fnMns\r
+       wOSxc9Zddo9nq24xBzBFcdmkpOZklqUW6dslcGW0HLnBXrBIrOLJwRa2BsZHgl2MnBwSAiYS\r
+       jxfsYIewxSQu3FvP1sXIxSEksI9R4l/3UkaQhJDABkaJF29rIBKHmSQaJp1ggUjMZZRom6IL\r
+       YrMJaEhs278crEFEQFpi593ZrCA2s4C9xMZZr8E2CAu4Sbzo+QfWyyKgKjF9WzdQDQcHL1DN\r
+       hn8qEEcoSnQ/m8AGEuYUcJC4u4oHYpO9xLuL8xknMPIvYGRYxSibklulm5uYmVOcmqxbnJyY\r
+       l5dapGuml5tZopeaUrqJERRE7C7KOxj/HFQ6xCjAwajEwxt4jT9QiDWxrLgy9xCjJAeTkihv\r
+       kZJAoBBfUn5KZUZicUZ8UWlOavEhRgkOZiUR3o83gMp5UxIrq1KL8mFS0hwsSuK811Ju+gsJ\r
+       pCeWpGanphakFsFkZTg4lCR4p2sADRUsSk1PrUjLzClBSDNxcIIM5wEabg9Sw1tckJhbnJkO\r
+       kT/FqCglzpsJkhAASWSU5sH1wqL8FaM40CvCvE0gVTzABAHX/QpoMBPQYKUckKuLSxIRUlIN\r
+       jObR+rN/+urv4vxirXh6R+J39qX7rjnVSWi9/5ZuJmOz2LcuS/Ql94swjrj/drseLpJhmc0g\r
+       HDM337jn/btCzpMbPHasmegfvLKqrsS+Xb2icYnpHD7htbwnWBXktd9r7ZPVyXkd6K8/97j8\r
+       m8sTV94TaHmlXR2+TND3MLdvd5Nu4OSP3eIaSizFGYmGWsxFxYkARvfI3s0CAAA=\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: Mon, 04 Feb 2013 21:37:13 -0000\r
+\r
+Previously, notmuch-combine-face-text-property assumed that any\r
+existing face properties of the modified text were already in face\r
+list form.  This was true as long as it was the only function\r
+manipulating faces (since it always produced a list form face), but if\r
+anything else has manipulated the face, it was more likely to be\r
+either a face name or a face plist.  It also didn't correctly handle\r
+face lists as arguments, even though the doc string claimed it did.\r
+\r
+This patch fixes notmuch-combine-face-text-property to handle all face\r
+forms correctly by canonicalizing both the argument face and the\r
+existing faces into list form.  This also means we can set the face to\r
+a simpler non-list form if there's no existing face.\r
+---\r
+ emacs/notmuch-lib.el |   27 +++++++++++++++++++++++----\r
+ 1 file changed, 23 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index d78bcf8..ad2816d 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -301,6 +301,16 @@ 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-face-ensure-list-form (face)\r
++  "Return FACE in face list form.\r
++\r
++If FACE is already a face list, it will be returned as-is.  If\r
++FACE is a face name or face plist, it will be returned as a\r
++single element face list."\r
++  (if (and (listp face) (not (keywordp (car face))))\r
++      face\r
++    (list face)))\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
+@@ -309,11 +319,20 @@ 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
++  ;; A face property can have three forms: a face name (a string or\r
++  ;; symbol), a property list, or a list of these two forms.  In the\r
++  ;; list case, the faces will be combined, with the earlier faces\r
++  ;; taking precedent.  Here we canonicalize everything to list form\r
++  ;; to make it easy to combine.\r
++  (let ((pos start)\r
++      (face-list (notmuch-face-ensure-list-form face)))\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
++      (let* ((cur (get-text-property pos 'face))\r
++           (cur-list (notmuch-face-ensure-list-form cur))\r
++           (new (cond ((null cur-list) face)\r
++                      (t (append face-list cur-list))))\r
++           (next (next-single-property-change pos 'face nil end)))\r
++      (put-text-property pos next 'face new)\r
+       (setq pos next)))))\r
\r
+ (defun notmuch-logged-error (msg &optional extra)\r
+-- \r
+1.7.10.4\r
+\r