[notmuch] [PATCH 3/3] notmuch.el: Support for customizing search result display

aneesh.kumar at gmail.com aneesh.kumar at gmail.com
Tue Dec 1 08:15:49 PST 2009


From: Aneesh Kumar K.V <aneesh.kumar at gmail.com>

This patch helps in customizing search result display
similar to mutt's index_format. The customization is done
by defining an alist as below

(setq notmuch-search-result-format '(("date" . "%s ")
				     ("authors" . "%-40s ")
				     ("subject" . "%s ")
				     ("tags" . "(%s)")))

The supported keywords are date, count, authors, subject and tags.
tags need to be last element for it to get highlighted by notmuch-tag-face.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar at gmail.com>
---
 notmuch.el |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 6a0c119..cbee989 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -125,6 +125,13 @@ pattern can still test against the entire line).")
 (defvar notmuch-show-body-read-visible nil)
 (defvar notmuch-show-citations-visible nil)
 (defvar notmuch-show-signatures-visible nil)
+(defcustom notmuch-search-result-format nil
+  "Search result formating. Supported fields are
+	date, count, authors, subject, tags
+ex: \(\(\"date\" \"%s\"\) \(\"count\" \"%-7s\) \(\"authors\" \"%-40s\"\) \(\"subject %s\"\) \(\"tag\" \"(%s)\"\)\)"
+:type '(alist :key-type (string) :value-type (string))
+:group 'notmuch)
+
 (defvar notmuch-show-headers-visible nil)
 
 ; XXX: This should be a generic function in emacs somewhere, not here
@@ -1117,6 +1124,26 @@ This function advances point to the next line when finished."
 			    (insert (format " (process returned %d)" exit-status)))
 			(insert "\n"))))))))))
 
+(defun insert_field (field date count authors subject tags)
+(if (string-equal field "date")
+    (insert (format (cdr (assoc field notmuch-search-result-format)) date))
+  (if (string-equal field "count")
+    (insert (format (cdr (assoc field notmuch-search-result-format)) count))
+  (if (string-equal field "authors")
+    (insert (format (cdr (assoc field notmuch-search-result-format)) authors))
+  (if (string-equal field "subject")
+      (insert (format (cdr (assoc field notmuch-search-result-format)) subject))
+  (if (string-equal field "tags")
+    (insert (format (cdr (assoc field notmuch-search-result-format)) tags)))
+)))))
+
+(defun notmuch-search-show-result (date count authors subject tags)
+(let ((fields) (field))
+  (setq fields (mapcar 'car notmuch-search-result-format))
+  (loop for field in  fields
+	do (insert_field field date count authors subject tags)))
+(insert "\n"))
+
 (defun notmuch-search-process-filter (proc string)
   "Process and filter the output of \"notmuch search\""
   (let ((buffer (process-buffer proc)))
@@ -1139,7 +1166,9 @@ This function advances point to the next line when finished."
 			  (set 'authors (concat (substring authors 0 (- 40 3)) "...")))
 		      (goto-char (point-max))
 		      (let ((beg (point-marker)))
-			(insert (format "%s %-7s %-40s %s (%s)\n" date count authors subject tags))
+			(if (not notmuch-search-result-format)
+			    (insert (format "%s %-7s %-40s %s (%s)\n" date count authors subject tags))
+			  (notmuch-search-show-result date count authors subject tags))
 			(put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id))
 		      (set 'line (match-end 0)))
 		  (set 'more nil))))))
-- 
1.6.5.2.74.g610f9



More information about the notmuch mailing list