From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: cworth@cworth.org
Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org
Subject: [PATCH -V3] notmuch.el: Support for customizing search result display
Date: Thu, 11 Feb 2010 22:11:46 +0530 [thread overview]
Message-ID: <1265906506-10395-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <87bpg3e9u9.fsf@yoom.home.cworth.org>
From: Aneesh Kumar K.V <aneesh.kumar@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.
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
notmuch.el | 56 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/notmuch.el b/notmuch.el
index 040997e..a4a89ac 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -141,6 +141,19 @@ remaining lines into a button.")
(defvar notmuch-show-body-read-visible nil)
(defvar notmuch-show-citations-visible nil)
(defvar notmuch-show-signatures-visible nil)
+(defcustom notmuch-search-result-format
+ '(("date" . "%s")
+ ("count" . "%-7s")
+ ("authors" . "%-40s")
+ ("subject" . "%s")
+ ("tags" . "%s"))
+ "Search result formating. Supported fields are
+ date, count, authors, subject, tags
+ex: (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)
+ \(\"subject\" . \"%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
@@ -1175,11 +1188,6 @@ matching this search term are shown if non-nil. "
"Notmuch search mode face used to highligh tags."
:group 'notmuch)
-(defvar notmuch-tag-face-alist nil
- "List containing the tag list that need to be highlighed")
-
-(defvar notmuch-search-font-lock-keywords nil)
-
;;;###autoload
(defun notmuch-search-mode ()
"Major mode displaying results of a notmuch search.
@@ -1215,17 +1223,7 @@ Complete list of currently available key bindings:
(setq truncate-lines t)
(setq major-mode 'notmuch-search-mode
mode-name "notmuch-search")
- (setq buffer-read-only t)
- (if (not notmuch-tag-face-alist)
- (add-to-list 'notmuch-search-font-lock-keywords (list
- "(\\([^)]*\\))$" '(1 'notmuch-tag-face)))
- (let ((notmuch-search-tags (mapcar 'car notmuch-tag-face-alist)))
- (loop for notmuch-search-tag in notmuch-search-tags
- do (add-to-list 'notmuch-search-font-lock-keywords (list
- (concat "([^)]*\\(" notmuch-search-tag "\\)[^)]*)$")
- `(1 ,(cdr (assoc notmuch-search-tag notmuch-tag-face-alist))))))))
- (set (make-local-variable 'font-lock-defaults)
- '(notmuch-search-font-lock-keywords t)))
+ (setq buffer-read-only t))
(defun notmuch-search-find-thread-id ()
"Return the thread for the current thread"
@@ -1340,6 +1338,30 @@ This function advances the next thread when finished."
(insert (format " (process returned %d)" exit-status)))
(insert "\n"))))))))))
+(defun insert-tags (tags)
+ (insert (concat "(" (propertize tags
+ 'font-lock-face 'notmuch-tag-face) ")")))
+
+(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-tags (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)))
@@ -1362,7 +1384,7 @@ This function advances the next thread 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))
+ (notmuch-search-show-result date count authors subject tags)
(put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)
(put-text-property beg (point-marker) 'notmuch-search-authors authors)
(put-text-property beg (point-marker) 'notmuch-search-subject subject))
--
1.7.0.rc2
next prev parent reply other threads:[~2010-02-11 16:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-01 16:15 [PATCH 1/3] Use default face for the button types so that the underlines go away aneesh.kumar
2009-12-01 16:15 ` [PATCH 2/3] notmuch.el: Fix the message summary button to be active even on first column aneesh.kumar
2009-12-01 16:15 ` [PATCH 3/3] notmuch.el: Support for customizing search result display aneesh.kumar
2009-12-02 12:49 ` [PATCH -v2] " Aneesh Kumar K.V
2009-12-11 5:34 ` Aneesh Kumar K. V
2010-02-05 19:55 ` Carl Worth
2010-02-11 16:41 ` Aneesh Kumar K.V [this message]
2010-02-11 17:17 ` [PATCH -V3] " Aneesh Kumar K. V
2009-12-03 21:04 ` [PATCH 1/3] Use default face for the button types so that the underlines go away Carl Worth
-- strict thread matches above, loose matches on Subject: below --
2010-01-23 10:09 [PATCH -V2] notmuch.el: Support for customizing search result display Aneesh Kumar K.V
2010-03-10 16:33 ` [PATCH -V3] " Aneesh Kumar K.V
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1265906506-10395-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
--to=aneesh.kumar@linux.vnet.ibm.com \
--cc=aneesh.kumar@gmail.com \
--cc=cworth@cworth.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).