Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id DA0D8431FBC for ; Wed, 2 Dec 2009 04:49:56 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pbhvxRegn5ku for ; Wed, 2 Dec 2009 04:49:56 -0800 (PST) Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by olra.theworths.org (Postfix) with ESMTP id 58C06431FAE for ; Wed, 2 Dec 2009 04:49:56 -0800 (PST) Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp03.au.ibm.com (8.14.3/8.13.1) with ESMTP id nB2Cl8ZU001705 for ; Wed, 2 Dec 2009 23:47:08 +1100 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nB2CkD9S1487000 for ; Wed, 2 Dec 2009 23:46:13 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nB2Cnq2m009949 for ; Wed, 2 Dec 2009 23:49:52 +1100 Received: from localhost.localdomain ([9.124.212.174]) by d23av01.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nB2CnhZm009904; Wed, 2 Dec 2009 23:49:47 +1100 From: "Aneesh Kumar K.V" To: cworth@cworth.org, aneesh.kumar@linux.vnet.ibm.com Date: Wed, 2 Dec 2009 18:19:38 +0530 Message-Id: <1259758178-26584-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.5.2.74.g610f9 In-Reply-To: <1259684149-9574-3-git-send-email-aneesh.kumar@gmail.com> References: <1259684149-9574-3-git-send-email-aneesh.kumar@gmail.com> Cc: "Aneesh Kumar K.V" , notmuch@notmuchmail.org Subject: [notmuch] [PATCH -v2] notmuch.el: Support for customizing search result display X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2009 12:49:57 -0000 From: Aneesh Kumar K.V 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 --- Changes from V1: tags can be specified any where in the result format. Dropped notmuch-tag-face-alist which implies we cannot fontify select list of tag names. notmuch.el | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 39 insertions(+), 17 deletions(-) diff --git a/notmuch.el b/notmuch.el index 1e5bf5b..bd8a6ce 100644 --- a/notmuch.el +++ b/notmuch.el @@ -119,6 +119,14 @@ 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: (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 @@ -1060,11 +1068,6 @@ thread from that buffer can be show when done with this one)." "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. @@ -1100,17 +1103,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" @@ -1217,6 +1210,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))) @@ -1239,7 +1256,12 @@ 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)) + (if (not notmuch-search-result-format) + (progn (insert (format "%s %-7s %-40s %s" date count authors subject)) + ;; insert the fontified tag + (insert-tags (format "%s" tags)) + (insert "\n")) + (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