--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B7B35429E32\r
+ for <notmuch@notmuchmail.org>; Sat, 22 Mar 2014 04:51:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 6Mh52qNmOZyL for <notmuch@notmuchmail.org>;\r
+ Sat, 22 Mar 2014 04:51:48 -0700 (PDT)\r
+Received: from mail-we0-f177.google.com (mail-we0-f177.google.com\r
+ [74.125.82.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 44735431FD2\r
+ for <notmuch@notmuchmail.org>; Sat, 22 Mar 2014 04:51:32 -0700 (PDT)\r
+Received: by mail-we0-f177.google.com with SMTP id u57so2276276wes.36\r
+ for <notmuch@notmuchmail.org>; Sat, 22 Mar 2014 04:51:31 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=OecSWd21A69RN2EU1lK8zPP31j8UByKgDJWb33l/XzI=;\r
+ b=v9GvtP4+0ISc+NGeiYt/fpglpSvgYlAfL6w9nsCrWQNH46ciADSypgFoeHBGcvQUyk\r
+ Jw5HwxIOT573a0Ft70RvwUioDIhs0vt0mE7wtfL818PNrif5c8FqrFr3eZQvf/PIW1rw\r
+ j7nTm06wiVZlB7jMbPMh0YFNie0diyPeuglRoqwuK6s4RE7wJ+i8TohZ4+xAyxlY2TEF\r
+ wkJPtgZArvwJLcRHzSyKybhTRQCKA8DaQAZiju+wrDAcPz8eXEFX0vhZgetxxPUrf1zz\r
+ Xjjqiz/qPVPP00pn1lU07Qnf7bOGcI19m0l9GMqeIucA4E4SDSeDYMWO4Z5cLZIiOak8\r
+ ZwIg==\r
+X-Received: by 10.180.11.36 with SMTP id n4mr3235922wib.4.1395489091180;\r
+ Sat, 22 Mar 2014 04:51:31 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id lz3sm16248070wic.1.2014.03.22.04.51.30\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 22 Mar 2014 04:51:30 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+ amdragon@mit.edu\r
+Subject: [Patch v4 5/8] emacs: show: mark tags changed since buffer loaded\r
+Date: Sat, 22 Mar 2014 11:51:09 +0000\r
+Message-Id: <1395489072-19001-6-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1395489072-19001-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1395489072-19001-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 22 Mar 2014 11:51:57 -0000\r
+\r
+This allows (and requires) the original-tags to be passed along with\r
+the current-tags to be passed to notmuch-tag-format-tags. This allows\r
+the tag formatting to show added and deleted tags.By default a removed\r
+tag is displayed with strike-through in red (if strike-through is not\r
+available, eg on a terminal, inverse video is used instead) and an\r
+added tag is displayed underlined in green.\r
+\r
+If the caller does not wish to use the new feature it can pass\r
+current-tags for both arguments and, at this point, we do exactly that\r
+in the three callers of this function.\r
+\r
+Note, we cannot tidily allow original-tags to be optional because we would\r
+need to distinguish nil meaning "we are not specifying original-tags"\r
+from nil meaning there were no original-tags (an empty list).\r
+\r
+We use this in subsequent patches to make it clear when a message was\r
+unread when you first loaded a show buffer (previously the unread tag\r
+could be removed before a user realised that it had been unread).\r
+\r
+The code adds into the existing tag formatting code. The user can\r
+specify exactly how a tag should be displayed normally, when deleted,\r
+or when added.\r
+\r
+Since the formatting code matches regexps a user can match all deleted\r
+tags with a ".*" in notmuch-tag-deleted-formats. For example setting\r
+notmuch-tag-deleted-formats to '((".*" nil)) tells notmuch not to show\r
+deleted tags at all.\r
+\r
+All the variables are customizable; however, more complicated cases\r
+like changing the face depending on the type of display will require\r
+custom lisp.\r
+\r
+Currently this overrides notmuch-tag-deleted-formats for the tests\r
+setting it to '((".*" nil)) so that they get removed from the display\r
+and, thus, all tests still pass.\r
+---\r
+ emacs/notmuch-show.el | 4 +--\r
+ emacs/notmuch-tag.el | 96 +++++++++++++++++++++++++++++++------------------\r
+ emacs/notmuch-tree.el | 2 +-\r
+ emacs/notmuch.el | 2 +-\r
+ test/test-lib.el | 5 +++\r
+ 5 files changed, 70 insertions(+), 39 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 019f51d..5492be4 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -344,7 +344,7 @@ (defun notmuch-show-update-tags (tags)\r
+ (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)\r
+ (let ((inhibit-read-only t))\r
+ (replace-match (concat "("\r
+- (notmuch-tag-format-tags tags)\r
++ (notmuch-tag-format-tags tags tags)\r
+ ")"))))))\r
+ \r
+ (defun notmuch-clean-address (address)\r
+@@ -423,7 +423,7 @@ (defun notmuch-show-insert-headerline (headers date tags depth)\r
+ " ("\r
+ date\r
+ ") ("\r
+- (notmuch-tag-format-tags tags)\r
++ (notmuch-tag-format-tags tags tags)\r
+ ")\n")\r
+ (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))\r
+ \r
+diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
+index 3ae5e62..07c260e 100644\r
+--- a/emacs/notmuch-tag.el\r
++++ b/emacs/notmuch-tag.el\r
+@@ -193,45 +193,71 @@ (defun notmuch-tag-clear-cache ()\r
+ "Clear the internal cache of tag formats."\r
+ (clrhash notmuch-tag--format-cache))\r
+ \r
+-(defun notmuch-tag-format-tag (tag)\r
+- "Format TAG by according to `notmuch-tag-formats'.\r
+-\r
+-Callers must ensure that the tag format cache has been recently cleared\r
+-via `notmuch-tag-clear-cache' before using this function. For example,\r
+-it would be appropriate to clear the cache just prior to filling a\r
+-buffer that uses formatted tags."\r
+-\r
+- (let ((formatted (gethash tag notmuch-tag--format-cache 'missing)))\r
+- (when (eq formatted 'missing)\r
+- (let* ((formats\r
+- (save-match-data\r
+- ;; Don't use assoc-default since there's no way to\r
+- ;; distinguish a missing key from a present key with a\r
+- ;; null cdr:.\r
+- (assoc* tag notmuch-tag-formats\r
+- :test (lambda (tag key)\r
+- (and (eq (string-match key tag) 0)\r
+- (= (match-end 0) (length tag))))))))\r
+- (setq formatted\r
+- (cond\r
+- ((null formats) ;; - Tag not in `notmuch-tag-formats',\r
+- tag) ;; the format is the tag itself.\r
+- ((null (cdr formats)) ;; - Tag was deliberately hidden,\r
+- nil) ;; no format must be returned\r
+- (t ;; - Tag was found and has formats,\r
+- (let ((tag tag)) ;; we must apply all the formats.\r
+- (dolist (format (cdr formats) tag)\r
+- (setq tag (eval format)))))))\r
+- (puthash tag formatted notmuch-tag--format-cache)))\r
+- formatted))\r
+-\r
+-(defun notmuch-tag-format-tags (tags &optional face)\r
++(defun notmuch-tag--get-formats (tag format-alist)\r
++ "Find the first item whose car regexp-matches TAG."\r
++ (save-match-data\r
++ ;; Don't use assoc-default since there's no way to distinguish a\r
++ ;; missing key from a present key with a null cdr.\r
++ (assoc* tag format-alist\r
++ :test (lambda (tag key)\r
++ (and (eq (string-match key tag) 0)\r
++ (= (match-end 0) (length tag)))))))\r
++\r
++(defun notmuch-tag--do-format (tag formatted-tag formats)\r
++ "Apply a tag-formats entry to TAG."\r
++ (cond ((null formats) ;; - Tag not in `formats',\r
++ formatted-tag) ;; the format is the tag itself.\r
++ ((null (cdr formats)) ;; - Tag was deliberately hidden,\r
++ nil) ;; no format must be returned\r
++ (t\r
++ ;; Tag was found and has formats, we must apply all the\r
++ ;; formats. TAG may be null so treat that as a special case.\r
++ (let ((bare-tag tag)\r
++ (tag (copy-sequence (or formatted-tag ""))))\r
++ (dolist (format (cdr formats))\r
++ (setq tag (eval format)))\r
++ (if (and (null formatted-tag) (equal tag ""))\r
++ nil\r
++ tag)))))\r
++\r
++(defun notmuch-tag-format-tag (tags orig-tags tag)\r
++ "Format TAG according to `notmuch-tag-formats'.\r
++\r
++TAGS and ORIG-TAGS are lists of the current tags and the original\r
++tags; tags which have been deleted (i.e., are in ORIG-TAGS but\r
++are not in TAGS) are shown using formats from\r
++`notmuch-tag-deleted-formats'; tags which have been added (i.e.,\r
++are in TAGS but are not in ORIG-TAGS) are shown using formats\r
++from `notmuch-tag-added-formats' and tags which have not been\r
++changed (the normal case) are shown using formats from\r
++`notmuch-tag-formats'"\r
++ (let* ((tag-state (cond ((not (member tag tags)) 'deleted)\r
++ ((not (member tag orig-tags)) 'added)))\r
++ (formatted-tag (gethash (cons tag tag-state) notmuch-tag--format-cache 'missing)))\r
++ (when (eq formatted-tag 'missing)\r
++ (let ((base (notmuch-tag--get-formats tag notmuch-tag-formats))\r
++ (over (case tag-state\r
++ (deleted (notmuch-tag--get-formats\r
++ tag notmuch-tag-deleted-formats))\r
++ (added (notmuch-tag--get-formats\r
++ tag notmuch-tag-added-formats))\r
++ (otherwise nil))))\r
++ (setq formatted-tag (notmuch-tag--do-format tag tag base))\r
++ (setq formatted-tag (notmuch-tag--do-format tag formatted-tag over))\r
++\r
++ (puthash (cons tag tag-state) formatted-tag notmuch-tag--format-cache)))\r
++ formatted-tag))\r
++\r
++(defun notmuch-tag-format-tags (tags orig-tags &optional face)\r
+ "Return a string representing formatted TAGS."\r
+- (let ((face (or face 'notmuch-tag-face)))\r
++ (let ((face (or face 'notmuch-tag-face))\r
++ (all-tags (sort (delete-dups (append tags orig-tags nil)) #'string<)))\r
+ (notmuch-apply-face\r
+ (mapconcat #'identity\r
+ ;; nil indicated that the tag was deliberately hidden\r
+- (delq nil (mapcar #'notmuch-tag-format-tag tags))\r
++ (delq nil (mapcar\r
++ (apply-partially #'notmuch-tag-format-tag tags orig-tags)\r
++ all-tags))\r
+ " ")\r
+ face\r
+ t)))\r
+diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el\r
+index c78d9de..8bf2fbc 100644\r
+--- a/emacs/notmuch-tree.el\r
++++ b/emacs/notmuch-tree.el\r
+@@ -704,7 +704,7 @@ (defun notmuch-tree-format-field (field format-string msg)\r
+ (face (if match\r
+ 'notmuch-tree-match-tag-face\r
+ 'notmuch-tree-no-match-tag-face)))\r
+- (format format-string (notmuch-tag-format-tags tags face)))))))\r
++ (format format-string (notmuch-tag-format-tags tags tags face)))))))\r
+ \r
+ (defun notmuch-tree-format-field-list (field-list msg)\r
+ "Format fields of MSG according to FIELD-LIST and return string"\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 93a6d8b..609f408 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -754,7 +754,7 @@ (defun notmuch-search-insert-field (field format-string result)\r
+ \r
+ ((string-equal field "tags")\r
+ (let ((tags (plist-get result :tags)))\r
+- (insert (format format-string (notmuch-tag-format-tags tags)))))))\r
++ (insert (format format-string (notmuch-tag-format-tags tags tags)))))))\r
+ \r
+ (defun notmuch-search-show-result (result &optional pos)\r
+ "Insert RESULT at POS or the end of the buffer if POS is null."\r
+diff --git a/test/test-lib.el b/test/test-lib.el\r
+index 37fcb3d..437f83f 100644\r
+--- a/test/test-lib.el\r
++++ b/test/test-lib.el\r
+@@ -165,3 +165,8 @@ (defun notmuch-test-expect-equal (output expected)\r
+ \r
+ (t\r
+ (notmuch-test-report-unexpected output expected)))))\r
++\r
++;; For historical reasons, we hide deleted tags by default in the test\r
++;; suite\r
++(setq notmuch-tag-deleted-formats\r
++ '((".*" nil)))\r
+-- \r
+1.7.10.4\r
+\r