--- /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 1C655431FBD\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Feb 2014 12:20:54 -0800 (PST)\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 V2RPJ8cL68Av for <notmuch@notmuchmail.org>;\r
+ Wed, 19 Feb 2014 12:20:46 -0800 (PST)\r
+Received: from mail-we0-f182.google.com (mail-we0-f182.google.com\r
+ [74.125.82.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 5A141431FD4\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Feb 2014 12:20:39 -0800 (PST)\r
+Received: by mail-we0-f182.google.com with SMTP id u57so771031wes.27\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Feb 2014 12:20:38 -0800 (PST)\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=Vdm9E41asuK/JX07OyhLO/yljhes2PVpSgXCDdCfqsc=;\r
+ b=QZfUkW2xSLxYE+cUOr0U/TnAVNF34Q/3bBCIL8yu60k9AC5izv8jg4cww5pvpz2Z49\r
+ B8V4NSX7brL3jyNlK77pcbN5bbf49u+2s9bJHNcdgvvfhP4en1bS/U+Tqx4H0wyiz+W5\r
+ RFplJLhP+y1yqZDdaZDrn+4WbOtuRJ65LtHG4QZo9xP8PL61lnpM7PrtCdLKW10yNRjP\r
+ GhyD4VX8WZU0DnrLFAHkIiNrOKLQ1b2TnT7BcSBEfCbWAdScu6QMw22IPSAEabYP59cK\r
+ 7RoitQMw7wnAaewLIjxQM6VQcIbq5pR7x469ihPLKx2UetB4MrwFicXszfX9TZ569B2v\r
+ ycJw==\r
+X-Received: by 10.180.96.102 with SMTP id dr6mr3401919wib.19.1392841238264;\r
+ Wed, 19 Feb 2014 12:20:38 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id bm8sm3129087wjc.12.2014.02.19.12.20.37\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Wed, 19 Feb 2014 12:20:37 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 4/7] emacs: show: mark tags changed since buffer loaded\r
+Date: Wed, 19 Feb 2014 20:20:09 +0000\r
+Message-Id: <1392841212-8494-5-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1392841212-8494-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1392841212-8494-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: Wed, 19 Feb 2014 20:20:54 -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. For convenience an entry for the empty string in the\r
+notmuch-tag-formats (and the corresponding notmuch-tag-deleted-formats\r
+notmuch-tag-added-formats) is applied to all tags which do not have an\r
+explicit match.\r
+\r
+This means that a user can tell notmuch not to show deleted tags at\r
+all by setting notmuch-tag-deleted-formats to\r
+'(("" nil))\r
+or not to show any deleted tags except "unread" by setting it to\r
+'(("" nil)\r
+ ("unread" (propertize tag 'face '(strike-through "red"))))\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 | 65 ++++++++++++++++++++++++++++++++++++++----------\r
+ emacs/notmuch-tree.el | 2 +-\r
+ emacs/notmuch.el | 2 +-\r
+ test/test-lib.el | 5 ++++\r
+ 5 files changed, 60 insertions(+), 18 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 4bddf6c..719e7d1 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -344,7 +344,7 @@ operation on the contents of the current buffer."\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 @@ message at DEPTH in the current thread."\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 064fbdb..869b97d 100644\r
+--- a/emacs/notmuch-tag.el\r
++++ b/emacs/notmuch-tag.el\r
+@@ -185,36 +185,73 @@ This can be used with `notmuch-tag-format-image-data'."\r
+ </g>\r
+ </svg>")\r
+ \r
+-(defun notmuch-tag-format-tag (tag)\r
+- "Format TAG by looking into `notmuch-tag-formats'."\r
+- (let ((formatted (gethash tag notmuch-tag--format-cache 'missing)))\r
++(defun notmuch-tag-format-tag-by-state (tag formatted-tag tag-state)\r
++ "Format TAG by looking into the appropriate `notmuch-tag-formats`.\r
++\r
++Applies formats for TAG from the appropriate one of\r
++`notmuch-tag-formats`, `notmuch-tag-deleted-formats` and\r
++`notmuch-tag-added-formats` based on TAG-STATE to the partially\r
++formatted tag FORMATTED-TAG."\r
++ (let ((formatted (gethash (cons tag tag-state) notmuch-tag--format-cache 'missing)))\r
+ (when (eq formatted 'missing)\r
+- (let* ((formats\r
++ (let* ((tag-formats (cond ((null tag-state) notmuch-tag-formats)\r
++ ((eq 'deleted tag-state) notmuch-tag-deleted-formats)\r
++ ((eq 'added tag-state) notmuch-tag-added-formats)))\r
++ (formats\r
+ (save-match-data\r
+- (assoc* tag notmuch-tag-formats\r
++ (assoc* tag 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 formats) ;; - Tag not in `tag-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 ;; - Tag was found and has formats,\r
+- (let ((tag tag)) ;; we must apply all the formats.\r
++ (t\r
++ ;; Tag was found and has formats, we must apply all\r
++ ;; the formats. FORMATTED-TAG may be null so treat\r
++ ;; that as a special case.\r
++ (let ((tag (or formatted-tag "")))\r
+ (dolist (format (cdr formats) tag)\r
+- (setq tag (eval format)))))))\r
+- (puthash tag formatted notmuch-tag--format-cache)))\r
++ (setq tag (eval format)))\r
++ (if (and (null formatted-tag)\r
++ (equal tag ""))\r
++ nil\r
++ tag)))))\r
++ (puthash (cons tag tag-state) formatted notmuch-tag--format-cache)))\r
+ formatted))\r
+ \r
+-(defun notmuch-tag-format-tags (tags &optional face)\r
++(defun notmuch-tag-format-tag (tags orig-tags tag)\r
++ "Format TAG by looking into `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* ((formatted-tag (notmuch-tag-format-tag-by-state tag tag nil)))\r
++ (cond ((not (member tag tags))\r
++ (notmuch-tag-format-tag-by-state tag formatted-tag 'deleted))\r
++ ((not (member tag orig-tags))\r
++ (notmuch-tag-format-tag-by-state tag formatted-tag 'added))\r
++ (t\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-combine-face-text-property-string\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 a106e09..7080e6f 100644\r
+--- a/emacs/notmuch-tree.el\r
++++ b/emacs/notmuch-tree.el\r
+@@ -704,7 +704,7 @@ unchanged ADDRESS if parsing fails."\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 0c767f7..04587c0 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -754,7 +754,7 @@ non-authors is found, assume that all of the authors match."\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 @@ nothing."\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.9.1\r
+\r