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