[PATCH 1/2] emacs: Add a fake Tags: header during display.

David Edmondson dme at dme.org
Thu Jan 26 10:16:28 PST 2012


If `truncate-lines' is `nil' in `notmuch-show-mode' the tags can be
lost from the right edge of the window. Create a fake 'Tags' header to
display them with the other headers.

Enable it by default by adding it to `notmuch-message-headers' and
keep it up to date during tagging operations.
---
 emacs/notmuch-show.el |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index c37479a..a975a29 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -41,7 +41,7 @@
 (declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))
 (declare-function notmuch-search-show-thread "notmuch" nil)
 
-(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
+(defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date" "Tags")
   "Headers that should be shown in a message, in this order.
 
 For an open message, all of these headers will be made visible
@@ -255,6 +255,8 @@ operation on the contents of the current buffer."
 		'message-header-subject)
 	       ((looking-at "[Ff]rom:")
 		'message-header-from)
+	       ((looking-at "Tags:")
+		'notmuch-tag-face)
 	       (t
 		'message-header-other))))
 
@@ -277,13 +279,21 @@ operation on the contents of the current buffer."
 (defun notmuch-show-update-tags (tags)
   "Update the displayed tags of the current message."
   (save-excursion
-    (goto-char (notmuch-show-message-top))
-    (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
-	(let ((inhibit-read-only t))
+    ;; Update the header line.
+    (let ((inhibit-read-only t))
+      (goto-char (notmuch-show-message-top))
+      (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
 	  (replace-match (concat "("
 				 (propertize (mapconcat 'identity tags " ")
 					     'face 'notmuch-tag-face)
-				 ")"))))))
+				 ")")))
+      ;; Update the header, if present.
+      (when (member "Tags" notmuch-message-headers)
+	(goto-char (notmuch-show-message-top))
+	(if (re-search-forward"^ *Tags: \\(.*\\)$" (notmuch-show-message-bottom) t)
+	    (replace-match (propertize (mapconcat 'identity tags " ")
+				       'face 'notmuch-tag-face)
+			   nil t nil 1))))))
 
 (defun notmuch-show-clean-address (address)
   "Try to clean a single email ADDRESS for display.  Return
@@ -789,6 +799,10 @@ current buffer, if possible."
 	 (message-invis-spec (notmuch-show-make-symbol "message"))
 	 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject))))
 
+    ;; Add a fake 'Tags' header which can be used in
+    ;; `notmuch-show-insert-headers'.
+    (plist-put headers :Tags (mapconcat #'identity (plist-get msg :tags) " "))
+
     ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise
     ;; removing items from `buffer-invisibility-spec' (which is what
     ;; `notmuch-show-headers-visible' and
-- 
1.7.8.3



More information about the notmuch mailing list