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 BF31D431FBF for ; Tue, 11 Mar 2014 07:47:11 -0700 (PDT) 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 ML7WzdCWlT1E for ; Tue, 11 Mar 2014 07:47:07 -0700 (PDT) Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu [18.9.25.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B2544431FBD for ; Tue, 11 Mar 2014 07:47:06 -0700 (PDT) X-AuditID: 1209190e-f79ee6d000000c40-67-531f21e8383f Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id F6.ED.03136.8E12F135; Tue, 11 Mar 2014 10:47:04 -0400 (EDT) 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 s2BEl2XA001010; Tue, 11 Mar 2014 10:47:02 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s2BEkxON024934 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 11 Mar 2014 10:47:01 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1WNNxL-0005t1-ML; Tue, 11 Mar 2014 10:46:59 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Combine notmuch-combine-face-text-property{,-string} Date: Tue, 11 Mar 2014 10:46:55 -0400 Message-Id: <1394549215-22508-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <8761nl31gl.fsf@awakening.csail.mit.edu> References: <8761nl31gl.fsf@awakening.csail.mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrftCUT7Y4PpBE4vVc3ksrt+cyezA 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZew8tZalYJdmxd/JO5kbGLcodjFyckgImEhs X7+KCcIWk7hwbz1bFyMXh5DAbCaJ7w87oJyNjBJrd69kBakSErjDJNF7ghMiMZdR4sSRn8wg CTYBDYlt+5czgtgiAtISO+/OBmtgFnCU+Lx/EdAkDg5hAR+JWa18IGEWAVWJE68bwDbzCjhI /PzUCXWFksTCU9vAWjkFTCUOvf/NDrHXRGLC36tsExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5O zMtLLdI11svNLNFLTSndxAgOI0m+HYxfDyodYhTgYFTi4Q3wlQsWYk0sK67MPcQoycGkJMr7 R0I+WIgvKT+lMiOxOCO+qDQntfgQowQHs5IIb7I4UI43JbGyKrUoHyYlzcGiJM7bd1YiWEgg PbEkNTs1tSC1CCYrw8GhJME7VwGoUbAoNT21Ii0zpwQhzcTBCTKcB2g4WA1vcUFibnFmOkT+ FKOilDjvDnmghABIIqM0D64XFuevGMWBXhHmTQdp5wGmCLjuV0CDmYAGf9wqBzK4JBEhJdXA ODXOb3qa/cwPuyOWBr9XPb/jwlTBuGXvpDN8Fs6Qivwcb3GYpbRhTQSjh6FQ7IG/Z08re8Xs 5DyyL8pR+Ejpac+VbrahXs+ebq2ILJITW5CwIyRqksPTu5uuxXGIdezZ/9Hk1f6kFZcTu5/7 /5S+ci+Y0WnWX58OYx2Hrv9XZ9svD1zcc+npUSWW4oxEQy3mouJEADdtqTHOAgAA 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: Tue, 11 Mar 2014 14:47:12 -0000 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. --- Here's the combined, cleaned up face combiner interface I mentioned on IRC. I think the new `notmuch-apply-face' function introduced here would be ideal for use in notmuch-tag-formats to fix the problem with propertize overriding the entire face. emacs/notmuch-lib.el | 35 ++++++++++++++++++----------------- emacs/notmuch-tag.el | 4 ++-- emacs/notmuch-tree.el | 2 +- emacs/notmuch.el | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 2fefdad..05be5b8 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -578,23 +578,32 @@ single element face list." face (list face))) -(defun notmuch-combine-face-text-property (start end face &optional below object) - "Combine FACE into the 'face text property between START and END. +(defun notmuch-apply-face (object face &optional start end below) + "Combine FACE into the 'face text property of OBJECT between START and END. This function combines FACE with any existing faces between START -and END in OBJECT (which defaults to the current buffer). -Attributes specified by FACE take precedence over existing -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 -of these. For convenience when applied to strings, this returns -OBJECT." +and END in OBJECT. Attributes specified by FACE take precedence +over existing attributes unless BELOW is non-nil. + +OBJECT may be a string, a buffer, or nil (which means the current +buffer). If object is a string, START and END are 0-based; +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 ;; 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) + (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))) (while (< pos end) (let* ((cur (get-text-property pos 'face object)) @@ -607,14 +616,6 @@ OBJECT." (setq pos next)))) 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) "Transform text property PROP using FUNC. diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index 908e7ad..d7deaf0 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -151,13 +151,13 @@ This can be used with `notmuch-tag-format-image-data'." (defun notmuch-tag-format-tags (tags &optional face) "Return a string representing formatted TAGS." (let ((face (or face 'notmuch-tag-face))) - (notmuch-combine-face-text-property-string + (notmuch-apply-face (mapconcat #'identity ;; nil indicated that the tag was deliberately hidden (delq nil (mapcar #'notmuch-tag-format-tag tags)) " ") face - t))) + nil nil t))) (defcustom notmuch-before-tag-hook nil "Hooks that are run before tags of a message are modified. diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index 4f2ac02..bc4c0b0 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -715,7 +715,7 @@ unchanged ADDRESS if parsing fails." (dolist (spec field-list result-string) (let ((field-string (notmuch-tree-format-field (car spec) (cdr spec) msg))) (setq result-string (concat result-string field-string)))) - (notmuch-combine-face-text-property-string result-string face t))) + (notmuch-apply-face result-string face nil nil t))) (defun notmuch-tree-insert-msg (msg) "Insert the message MSG according to notmuch-tree-result-format" diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 0471750..222d8b1 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -649,7 +649,7 @@ foreground and blue background." (let ((tag (car elem)) (attributes (cdr elem))) (when (member tag line-tag-list) - (notmuch-combine-face-text-property start end attributes)))) + (notmuch-apply-face nil attributes start end)))) ;; Reverse the list so earlier entries take precedence (reverse notmuch-search-line-faces))) -- 1.8.4.rc3