From: Mark Walters Date: Sat, 22 Mar 2014 11:51:05 +0000 (+0000) Subject: [Patch v4 1/8] emacs: Combine notmuch-combine-face-text-property{, -string} X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=26a71f758b180b5d5e771e49dd4055e2672bfc17;p=notmuch-archives.git [Patch v4 1/8] emacs: Combine notmuch-combine-face-text-property{, -string} --- diff --git a/b1/38a2da667aedcfeb593dc37555b61241cc1920 b/b1/38a2da667aedcfeb593dc37555b61241cc1920 new file mode 100644 index 000000000..4ae08c22d --- /dev/null +++ b/b1/38a2da667aedcfeb593dc37555b61241cc1920 @@ -0,0 +1,183 @@ +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 9460B431FC9 + for ; Sat, 22 Mar 2014 04:51:30 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + 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 p6z+ARD0eogM for ; + Sat, 22 Mar 2014 04:51:25 -0700 (PDT) +Received: from mail-we0-f175.google.com (mail-we0-f175.google.com + [74.125.82.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id DC31C431FC2 + for ; Sat, 22 Mar 2014 04:51:24 -0700 (PDT) +Received: by mail-we0-f175.google.com with SMTP id q58so2282275wes.34 + for ; Sat, 22 Mar 2014 04:51:23 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=gSliWsi5Qv4/R9XYHWk98eS0946wwZRKlUGWJlq/dtU=; + b=O+TnEfOkdGr9mP885PJz439OCvTU2E6FLz7PrvIt5yrmhi7agwvdGToz9EP4D+PL0K + v2eEN7BQ3oKdoiUE+mHF98WQl+DT7+3qamTq0mTfVTcM1foUMKLCC5IW0y9U0GhAbtTo + BooR6k3dtxW7s5R2uAQinGh8AAP5vMZ/OJNqhAUFkFS272CdNBzA/2CEqj1D/U04IrHO + cdFw7FRAugrZQZuMohlGJYQE4vhbWPDon2Q2FkROfORyWdxsBpsiTlqvwXYfcHZuy8Wx + F0DOYPnXJJb90WseOCxciIcmiPTGmIFlCx8YGXjFAMxbFikUDDP+4To+vM7z/JnFXpxt + 9DGg== +X-Received: by 10.180.219.44 with SMTP id pl12mr3238423wic.12.1395489083803; + Sat, 22 Mar 2014 04:51:23 -0700 (PDT) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id hp5sm16887304wjb.0.2014.03.22.04.51.22 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 22 Mar 2014 04:51:23 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org, + amdragon@mit.edu +Subject: [Patch v4 1/8] emacs: Combine notmuch-combine-face-text-property{, + -string} +Date: Sat, 22 Mar 2014 11:51:05 +0000 +Message-Id: <1395489072-19001-2-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1395489072-19001-1-git-send-email-markwalters1009@gmail.com> +References: <1395489072-19001-1-git-send-email-markwalters1009@gmail.com> +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: Sat, 22 Mar 2014 11:51:30 -0000 + +From: Austin Clements + +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. +--- + emacs/notmuch-lib.el | 35 ++++++++++++++++++----------------- + emacs/notmuch-tag.el | 2 +- + emacs/notmuch-tree.el | 2 +- + emacs/notmuch.el | 2 +- + 4 files changed, 21 insertions(+), 20 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 2fefdad..fa7646f 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -578,23 +578,32 @@ (defun notmuch-face-ensure-list-form (face) + 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 below start end) ++ "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 @@ (defun notmuch-combine-face-text-property (start end face &optional below 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..41b1687 100644 +--- a/emacs/notmuch-tag.el ++++ b/emacs/notmuch-tag.el +@@ -151,7 +151,7 @@ (defun notmuch-tag-format-tag (tag) + (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)) +diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el +index 4f2ac02..e3aa2cd 100644 +--- a/emacs/notmuch-tree.el ++++ b/emacs/notmuch-tree.el +@@ -715,7 +715,7 @@ (defun notmuch-tree-format-field-list (field-list msg) + (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 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..5cddaac 100644 +--- a/emacs/notmuch.el ++++ b/emacs/notmuch.el +@@ -649,7 +649,7 @@ (defun notmuch-search-color-line (start end line-tag-list) + (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 nil start end)))) + ;; Reverse the list so earlier entries take precedence + (reverse notmuch-search-line-faces))) + +-- +1.7.10.4 +