unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/3] emacs: allow show to colour based on tags and flags
@ 2012-04-14 19:21 Mark Walters
  2012-04-14 19:21 ` [PATCH 1/3] emacs: Move colour line from search to lib Mark Walters
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mark Walters @ 2012-04-14 19:21 UTC (permalink / raw)
  To: notmuch

These three patches allow emacs to colour the headerline in show mode
according to the messages tags and flags (ie match or excluded).

The first two are David Edmondson's patch
id:"1325006003-27152-1-git-send-email-dme@dme.org" rebased to master
and split into one which is trivial code movement and one which adds
the show colouring functionality.

The first two give a very similar result to notmuch-search-line-faces
and just allow colouring based on tags (not flags). The final one adds
the colouring by flag: it does this by passing to the line colouring
code a list of tags prefixed by "tag:" and flags prefixed by "flag:"

The final patch could be folded into the second, and this would somewhat reduce the diff. 

Mark Walters (3):
  emacs: Move colour line from search to lib
  emacs: Add `notmuch-show-line-faces' and apply it.
  emacs: allow notmuch-show-line-faces to use flags for colouring

 emacs/notmuch-lib.el  |   18 ++++++++++++++++++
 emacs/notmuch-show.el |   44 ++++++++++++++++++++++++++++++++++++++++----
 emacs/notmuch.el      |   15 +--------------
 3 files changed, 59 insertions(+), 18 deletions(-)

-- 
1.7.9.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] emacs: Move colour line from search to lib
  2012-04-14 19:21 [PATCH 0/3] emacs: allow show to colour based on tags and flags Mark Walters
@ 2012-04-14 19:21 ` Mark Walters
  2012-04-14 19:21 ` [PATCH 2/3] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
  2012-04-14 19:21 ` [PATCH 3/3] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Walters @ 2012-04-14 19:21 UTC (permalink / raw)
  To: notmuch

This patch moves the overlay/colouring from notmuch.el to
notmuch-lib.el. This is in preparation for its use by notmuch-show in
the next patch. This is just a rebased version of the emacs/notmuch.el
and emacs/notmuch-lib.el parts of David Edmondson's patch (see
id:"1325006003-27152-1-git-send-email-dme@dme.org")
---
 emacs/notmuch-lib.el |   18 ++++++++++++++++++
 emacs/notmuch.el     |   15 +--------------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 6907a5f..c8a9351 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -148,6 +148,24 @@ the user hasn't set this variable with the old or new value."
   "Return a query that matches the message with id ID."
   (concat "id:\"" (replace-regexp-in-string "\"" "\"\"" id t t) "\""))
 
+(defun notmuch-color-line (start end line-tag-list spec)
+  "Colorize a line based on tags."
+  ;; Create the overlay only if the message has tags which match one
+  ;; of those specified in `spec'.
+  (let (overlay)
+    (mapc (lambda (elem)
+	    (let ((tag (car elem))
+		  (attributes (cdr elem)))
+	      (when (member tag line-tag-list)
+		(when (not overlay)
+		  (setq overlay (make-overlay start end))
+		  (overlay-put overlay 'priority 5))
+		;; Merge the specified properties with any already
+		;; applied from an earlier match.
+		(overlay-put overlay 'face
+			     (append (overlay-get overlay 'face) attributes)))))
+	  spec)))
+
 ;;
 
 (defun notmuch-common-do-stash (text)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index ba833e6..09f6c50 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -728,20 +728,7 @@ foreground and blue background."
 
 (defun notmuch-search-color-line (start end line-tag-list)
   "Colorize lines in `notmuch-show' based on tags."
-  ;; Create the overlay only if the message has tags which match one
-  ;; of those specified in `notmuch-search-line-faces'.
-  (let (overlay)
-    (mapc (lambda (elem)
-	    (let ((tag (car elem))
-		  (attributes (cdr elem)))
-	      (when (member tag line-tag-list)
-		(when (not overlay)
-		  (setq overlay (make-overlay start end)))
-		;; Merge the specified properties with any already
-		;; applied from an earlier match.
-		(overlay-put overlay 'face
-			     (append (overlay-get overlay 'face) attributes)))))
-	  notmuch-search-line-faces)))
+  (notmuch-color-line start end line-tag-list notmuch-search-line-faces))
 
 (defun notmuch-search-author-propertize (authors)
   "Split `authors' into matching and non-matching authors and
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] emacs: Add `notmuch-show-line-faces' and apply it.
  2012-04-14 19:21 [PATCH 0/3] emacs: allow show to colour based on tags and flags Mark Walters
  2012-04-14 19:21 ` [PATCH 1/3] emacs: Move colour line from search to lib Mark Walters
@ 2012-04-14 19:21 ` Mark Walters
  2012-04-14 19:21 ` [PATCH 3/3] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Walters @ 2012-04-14 19:21 UTC (permalink / raw)
  To: notmuch

Similar to `notmuch-search-line-faces', `notmuch-show-line-faces'
allows the header line in `notmuch-show-mode' buffers to be coloured
according to the tags of the message. This is just a rebased version of
the  emacs/notmuch-show.el of David Edmondson's patch
id:"1325006003-27152-1-git-send-email-dme@dme.org"
---
 emacs/notmuch-show.el |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 30b26d1..3dbb25f 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -94,6 +94,24 @@ any given message."
   :group 'notmuch-show
   :group 'notmuch-hooks)
 
+(defcustom notmuch-show-line-faces nil
+  "Tag to face mapping for header line highlighting in `notmuch-show-mode'.
+
+Here is an example of how to color search results based on tags.
+ (the following text would be placed in your ~/.emacs file):
+
+ (setq notmuch-search-line-faces '((\"delete\" . (:foreground \"red\"
+						  :background \"blue\"))
+                                   (\"unread\" . (:foreground \"green\"))))
+
+The attributes defined for matching tags are merged, with later
+attributes overriding earlier. A message having both \"delete\"
+and \"unread\" tags with the above settings would have a green
+foreground and blue background."
+  :type '(alist :key-type (string) :value-type (custom-face-edit))
+  :group 'notmuch-show
+  :group 'notmuch-faces)
+
 ;; Mostly useful for debugging.
 (defcustom notmuch-show-all-multipart/alternative-parts t
   "Should all parts of multipart/alternative parts be shown?"
@@ -412,7 +430,8 @@ unchanged ADDRESS if parsing fails."
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
 message at DEPTH in the current thread."
-  (let ((start (point)))
+  (let ((start (point))
+	overlay)
     (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))
 	    (notmuch-show-clean-address (plist-get headers :From))
 	    " ("
@@ -421,7 +440,9 @@ message at DEPTH in the current thread."
 	    (propertize (mapconcat 'identity tags " ")
 			'face 'notmuch-tag-face)
 	    ")\n")
-    (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
+    (setq overlay (make-overlay start (point)))
+    (overlay-put overlay 'face 'notmuch-message-summary-face)
+    (overlay-put overlay 'priority 2)))
 
 (defun notmuch-show-insert-header (header header-value)
   "Insert a single header."
@@ -853,7 +874,8 @@ current buffer, if possible."
 	 body-start body-end
 	 (headers-invis-spec (notmuch-show-make-symbol "header"))
 	 (message-invis-spec (notmuch-show-make-symbol "message"))
-	 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject))))
+	 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))
+	 (tags (plist-get msg :tags)))
 
     ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise
     ;; removing items from `buffer-invisibility-spec' (which is what
@@ -878,10 +900,13 @@ current buffer, if possible."
 					    (plist-get msg :date_relative)
 					  nil)
 					(plist-get headers :Date))
-				    (plist-get msg :tags) depth)
+				    tags depth)
 
     (setq content-start (point-marker))
 
+    ;; Colour the header line according to the tags of the message.
+    (notmuch-color-line message-start content-start tags notmuch-show-line-faces)
+
     (plist-put msg :headers-invis-spec headers-invis-spec)
     (plist-put msg :message-invis-spec message-invis-spec)
 
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] emacs: allow notmuch-show-line-faces to use flags for colouring
  2012-04-14 19:21 [PATCH 0/3] emacs: allow show to colour based on tags and flags Mark Walters
  2012-04-14 19:21 ` [PATCH 1/3] emacs: Move colour line from search to lib Mark Walters
  2012-04-14 19:21 ` [PATCH 2/3] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
@ 2012-04-14 19:21 ` Mark Walters
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Walters @ 2012-04-14 19:21 UTC (permalink / raw)
  To: notmuch

This allows header-lines `notmuch-show-mode' buffers to be coloured
based on the flags (match/excluded) of the message. It supplies the
line colouring function with a list of tags each prefixed with "tag:"
and a list of flags ("match" or "excluded") each prefixed with
"flag:".

The match flag is obviously not equivalent to a tag; the excluded flag
looks equivalent but is subtly different: a message is not marked
excluded if that tag appeared in the query.
---
 emacs/notmuch-show.el |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 3dbb25f..66b8ec7 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -97,14 +97,16 @@ any given message."
 (defcustom notmuch-show-line-faces nil
   "Tag to face mapping for header line highlighting in `notmuch-show-mode'.
 
-Here is an example of how to color search results based on tags.
+Here is an example of how to color search results based on tags
+and flags (match and excluded).
  (the following text would be placed in your ~/.emacs file):
 
- (setq notmuch-search-line-faces '((\"delete\" . (:foreground \"red\"
+ (setq notmuch-search-line-faces '((\"tag:delete\" . (:foreground \"red\"
 						  :background \"blue\"))
-                                   (\"unread\" . (:foreground \"green\"))))
+                                   (\"tag:unread\" . (:foreground \"green\"))
+                                   (\"flag:excluded\" . (:background \"grey\"))))
 
-The attributes defined for matching tags are merged, with later
+The attributes defined for matching tags/flags are merged, with later
 attributes overriding earlier. A message having both \"delete\"
 and \"unread\" tags with the above settings would have a green
 foreground and blue background."
@@ -872,11 +874,20 @@ current buffer, if possible."
 	 content-start content-end
 	 headers-start headers-end
 	 body-start body-end
+	 tags-and-flags
 	 (headers-invis-spec (notmuch-show-make-symbol "header"))
 	 (message-invis-spec (notmuch-show-make-symbol "message"))
 	 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject)))
 	 (tags (plist-get msg :tags)))
 
+    (mapc (lambda (tag)
+	    (setq tags-and-flags (cons (concat "tag:" tag) tags-and-flags)))
+	  tags)
+    (if (plist-get msg :match)
+	(setq tags-and-flags (cons "flag:match" tags-and-flags)))
+    (if (plist-get msg :excluded)
+	(setq tags-and-flags (cons "flag:excluded" tags-and-flags)))
+
     ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise
     ;; removing items from `buffer-invisibility-spec' (which is what
     ;; `notmuch-show-headers-visible' and
@@ -905,7 +916,7 @@ current buffer, if possible."
     (setq content-start (point-marker))
 
     ;; Colour the header line according to the tags of the message.
-    (notmuch-color-line message-start content-start tags notmuch-show-line-faces)
+    (notmuch-color-line message-start content-start tags-and-flags notmuch-show-line-faces)
 
     (plist-put msg :headers-invis-spec headers-invis-spec)
     (plist-put msg :message-invis-spec message-invis-spec)
-- 
1.7.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-14 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 19:21 [PATCH 0/3] emacs: allow show to colour based on tags and flags Mark Walters
2012-04-14 19:21 ` [PATCH 1/3] emacs: Move colour line from search to lib Mark Walters
2012-04-14 19:21 ` [PATCH 2/3] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
2012-04-14 19:21 ` [PATCH 3/3] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).