emacs: Combine notmuch-combine-face-text-property{, -string}

This combines our two face combining functions into one, easy to use
function with a much shorter name: `notmuch-apply-face'.  This
function takes the full set of arguments that
`notmuch-combine-face-text-property' took, but takes them in a more
convenient order and provides smarter defaults that make the function
easy to use on both strings and buffers.
This commit is contained in:
Austin Clements 2014-03-22 11:51:05 +00:00 committed by David Bremner
parent 87c2cd78fd
commit dfab8e5e49
4 changed files with 21 additions and 20 deletions

View file

@ -578,23 +578,32 @@ single element face list."
face face
(list face))) (list face)))
(defun notmuch-combine-face-text-property (start end face &optional below object) (defun notmuch-apply-face (object face &optional below start end)
"Combine FACE into the 'face text property between START and END. "Combine FACE into the 'face text property of OBJECT between START and END.
This function combines FACE with any existing faces between START This function combines FACE with any existing faces between START
and END in OBJECT (which defaults to the current buffer). and END in OBJECT. Attributes specified by FACE take precedence
Attributes specified by FACE take precedence over existing over existing attributes unless BELOW is non-nil.
attributes unless BELOW is non-nil. FACE must be a face name (a
symbol or string), a property list of face attributes, or a list OBJECT may be a string, a buffer, or nil (which means the current
of these. For convenience when applied to strings, this returns buffer). If object is a string, START and END are 0-based;
OBJECT." otherwise they are buffer positions (integers or markers). FACE
must be a face name (a symbol or string), a property list of face
attributes, or a list of these. If START and/or END are omitted,
they default to the beginning/end of OBJECT. For convenience
when applied to strings, this returns OBJECT."
;; A face property can have three forms: a face name (a string or ;; 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 ;; symbol), a property list, or a list of these two forms. In the
;; list case, the faces will be combined, with the earlier faces ;; list case, the faces will be combined, with the earlier faces
;; taking precedent. Here we canonicalize everything to list form ;; taking precedent. Here we canonicalize everything to list form
;; to make it easy to combine. ;; to make it easy to combine.
(let ((pos start) (let ((pos (cond (start start)
((stringp object) 0)
(t 1)))
(end (cond (end end)
((stringp object) (length object))
(t (1+ (buffer-size object)))))
(face-list (notmuch-face-ensure-list-form face))) (face-list (notmuch-face-ensure-list-form face)))
(while (< pos end) (while (< pos end)
(let* ((cur (get-text-property pos 'face object)) (let* ((cur (get-text-property pos 'face object))
@ -607,14 +616,6 @@ OBJECT."
(setq pos next)))) (setq pos next))))
object) object)
(defun notmuch-combine-face-text-property-string (string face &optional below)
(notmuch-combine-face-text-property
0
(length string)
face
below
string))
(defun notmuch-map-text-property (start end prop func &optional object) (defun notmuch-map-text-property (start end prop func &optional object)
"Transform text property PROP using FUNC. "Transform text property PROP using FUNC.

View file

@ -151,7 +151,7 @@ This can be used with `notmuch-tag-format-image-data'."
(defun notmuch-tag-format-tags (tags &optional face) (defun notmuch-tag-format-tags (tags &optional face)
"Return a string representing formatted TAGS." "Return a string representing formatted TAGS."
(let ((face (or face 'notmuch-tag-face))) (let ((face (or face 'notmuch-tag-face)))
(notmuch-combine-face-text-property-string (notmuch-apply-face
(mapconcat #'identity (mapconcat #'identity
;; nil indicated that the tag was deliberately hidden ;; nil indicated that the tag was deliberately hidden
(delq nil (mapcar #'notmuch-tag-format-tag tags)) (delq nil (mapcar #'notmuch-tag-format-tag tags))

View file

@ -715,7 +715,7 @@ unchanged ADDRESS if parsing fails."
(dolist (spec field-list result-string) (dolist (spec field-list result-string)
(let ((field-string (notmuch-tree-format-field (car spec) (cdr spec) msg))) (let ((field-string (notmuch-tree-format-field (car spec) (cdr spec) msg)))
(setq result-string (concat result-string field-string)))) (setq result-string (concat result-string field-string))))
(notmuch-combine-face-text-property-string result-string face t))) (notmuch-apply-face result-string face t)))
(defun notmuch-tree-insert-msg (msg) (defun notmuch-tree-insert-msg (msg)
"Insert the message MSG according to notmuch-tree-result-format" "Insert the message MSG according to notmuch-tree-result-format"

View file

@ -649,7 +649,7 @@ foreground and blue background."
(let ((tag (car elem)) (let ((tag (car elem))
(attributes (cdr elem))) (attributes (cdr elem)))
(when (member tag line-tag-list) (when (member tag line-tag-list)
(notmuch-combine-face-text-property start end attributes)))) (notmuch-apply-face nil attributes nil start end))))
;; Reverse the list so earlier entries take precedence ;; Reverse the list so earlier entries take precedence
(reverse notmuch-search-line-faces))) (reverse notmuch-search-line-faces)))