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

The previous version of this patch set is at 
id:"1335739697-8501-1-git-send-email-markwalters1009@gmail.com".

The changes in this version: fixes in the documentation
(notmuch-search-line-faces corrected to notmuch-show-line-faces and
tag delete changed to tag deleted).

I have inserted one small patch. This 
moves notmuch-search-line-faces to require pairs of the form
("tag:TAG" . FACE) rather than ("TAG" . FACE). 

This makes it consistent with notmuch-show-line-faces which makes it
easy for the user to colour show results the same as search results (a
(setq notmuch-show-line-faces notmuch-search-line-faces) is
sufficient). See the previous thread for my reasons why we do want two
distinct variables.

NOTE It does mean that people will have to change their existing
colouring lines.






Mark Walters (5):
  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: move notmuch-search-line-faces to "tag:" style.
  emacs: inherit search-line-faces in show-line-faces.

 emacs/notmuch-lib.el  |   18 +++++++++++++++++
 emacs/notmuch-show.el |   51 +++++++++++++++++++++++++++++++++++++++++++++---
 emacs/notmuch.el      |   30 +++++++++++-----------------
 3 files changed, 77 insertions(+), 22 deletions(-)

-- 
1.7.9.1



*** BLURB HERE ***

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

 emacs/notmuch-lib.el  |   18 ++++++++++++++++++
 emacs/notmuch-show.el |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 emacs/notmuch.el      |   30 ++++++++++++------------------
 3 files changed, 75 insertions(+), 22 deletions(-)

-- 
1.7.9.1

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

* [Patch v3 1/4] emacs: Move colour line from search to lib
  2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
@ 2012-05-05 13:39 ` Mark Walters
  2012-05-05 13:39 ` [Patch v3 2/4] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-05-05 13:39 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 c6236db..d5f40e2 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -612,20 +612,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] 6+ messages in thread

* [Patch v3 2/4] emacs: Add `notmuch-show-line-faces' and apply it.
  2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
  2012-05-05 13:39 ` [Patch v3 1/4] emacs: Move colour line from search to lib Mark Walters
@ 2012-05-05 13:39 ` Mark Walters
  2012-05-05 13:39 ` [Patch v3 3/4] emacs: move notmuch-search-line-faces to "tag:" style Mark Walters
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-05-05 13:39 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 37f0ebb..e62f0a0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -93,6 +93,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-show-line-faces '((\"deleted\" . (: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?"
@@ -411,7 +429,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))
 	    " ("
@@ -420,7 +439,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."
@@ -852,7 +873,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
@@ -877,10 +899,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] 6+ messages in thread

* [Patch v3 3/4] emacs: move notmuch-search-line-faces to "tag:" style.
  2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
  2012-05-05 13:39 ` [Patch v3 1/4] emacs: Move colour line from search to lib Mark Walters
  2012-05-05 13:39 ` [Patch v3 2/4] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
@ 2012-05-05 13:39 ` Mark Walters
  2012-05-05 13:39 ` [Patch v3 4/4] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters
  2012-05-05 13:42 ` [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-05-05 13:39 UTC (permalink / raw)
  To: notmuch

notmuch-search-line-faces currently has pairs of the form ("TAG"
. FACE). This changes it so that the pairs need to be of the form
("tag:tag" . FACE). This makes it consistent with the same change to
notmuch-show-line-faces introduced in the next patch
where we allow colouring based on flags (match
and excluded) as well as tags. However, it will break people's
existing colouring lines.

It also makes it easier for the user to make the colouring rule for
search and show the same.
---
 emacs/notmuch.el |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index d5f40e2..40f0cbe 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -591,16 +591,16 @@ This function advances the next thread when finished."
 		  (goto-char (point-min))
 		  (forward-line (1- notmuch-search-target-line))))))))
 
-(defcustom notmuch-search-line-faces '(("unread" :weight bold)
-				       ("flagged" :foreground "blue"))
+(defcustom notmuch-search-line-faces '(("tag:unread" :weight bold)
+				       ("tag:flagged" :foreground "blue"))
   "Tag/face mapping for line highlighting in notmuch-search.
 
 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 '((\"deleted\" . (:foreground \"red\"
+ (setq notmuch-search-line-faces '((\"tag:deleted\" . (:foreground \"red\"
 						  :background \"blue\"))
-                                   (\"unread\" . (:foreground \"green\"))))
+                                   (\"tag:unread\" . (:foreground \"green\"))))
 
 The attributes defined for matching tags are merged, with later
 attributes overriding earlier. A message having both \"deleted\"
@@ -612,7 +612,14 @@ foreground and blue background."
 
 (defun notmuch-search-color-line (start end line-tag-list)
   "Colorize lines in `notmuch-show' based on tags."
-  (notmuch-color-line start end line-tag-list notmuch-search-line-faces))
+  ;; This is a little ugly (we do not match on flags in search-mode)
+  ;; but is done to keep the syntax consistent in
+  ;; notmuch-search-line-faces and notmuch-show-line-faces.
+  (let (tags-and-flags)
+    (mapc (lambda (tag)
+	    (setq tags-and-flags (cons (concat "tag:" tag) tags-and-flags)))
+	  line-tag-list)
+  (notmuch-color-line start end tags-and-flags 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] 6+ messages in thread

* [Patch v3 4/4] emacs: allow notmuch-show-line-faces to use flags for colouring
  2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
                   ` (2 preceding siblings ...)
  2012-05-05 13:39 ` [Patch v3 3/4] emacs: move notmuch-search-line-faces to "tag:" style Mark Walters
@ 2012-05-05 13:39 ` Mark Walters
  2012-05-05 13:42 ` [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-05-05 13:39 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 |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e62f0a0..94399c5 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -96,17 +96,24 @@ 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-show-line-faces '((\"deleted\" . (:foreground \"red\"
+ (setq notmuch-show-line-faces '((\"tag:deleted\" . (: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."
+foreground and blue background.
+
+Alternatively, here is an example of colouring using the same
+criteria as for search results:
+ (setq notmuch-show-line-faces notmuch-search-line-faces)"
+
   :type '(alist :key-type (string) :value-type (custom-face-edit))
   :group 'notmuch-show
   :group 'notmuch-faces)
@@ -871,11 +878,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
@@ -904,8 +920,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] 6+ messages in thread

* Re: [Patch v3 0/5] emacs: allow show to colour based on tags and flags
  2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
                   ` (3 preceding siblings ...)
  2012-05-05 13:39 ` [Patch v3 4/4] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters
@ 2012-05-05 13:42 ` Mark Walters
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Walters @ 2012-05-05 13:42 UTC (permalink / raw)
  To: notmuch


Sorry for the slight confusion: this series does only have 4 patches
not the 5 claimed in the subject. (I had written the cover letter and
then thought of a better way to do it but forgot to correct the subject
line)

Mark

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

end of thread, other threads:[~2012-05-05 13:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-05 13:39 [Patch v3 0/5] emacs: allow show to colour based on tags and flags Mark Walters
2012-05-05 13:39 ` [Patch v3 1/4] emacs: Move colour line from search to lib Mark Walters
2012-05-05 13:39 ` [Patch v3 2/4] emacs: Add `notmuch-show-line-faces' and apply it Mark Walters
2012-05-05 13:39 ` [Patch v3 3/4] emacs: move notmuch-search-line-faces to "tag:" style Mark Walters
2012-05-05 13:39 ` [Patch v3 4/4] emacs: allow notmuch-show-line-faces to use flags for colouring Mark Walters
2012-05-05 13:42 ` [Patch v3 0/5] emacs: allow show to colour based on tags and flags 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).