From 3ddb4dc8065a86a1fbcd17c6a6e6f3721b4b6522 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 4 Feb 2013 16:37:01 -0500 Subject: [PATCH] emacs: Handle all face forms when combining faces 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 270e3dc6..e7e71ea6 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -316,6 +316,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. @@ -324,11 +334,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) -- 2.43.0