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 4E01F4916AE for ; Wed, 10 Mar 2010 08:33:44 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -5.254 X-Spam-Level: X-Spam-Status: No, score=-5.254 tagged_above=-999 required=5 tests=[AWL=1.345, BAYES_00=-2.599, RCVD_IN_DNSWL_MED=-4] autolearn=unavailable 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 J6tbIfhfgp3r for ; Wed, 10 Mar 2010 08:33:44 -0800 (PST) Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144]) by olra.theworths.org (Postfix) with ESMTP id BAD7C4916B2 for ; Wed, 10 Mar 2010 08:33:43 -0800 (PST) Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp02.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2AGUB9X022301 for ; Thu, 11 Mar 2010 03:30:11 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2AGRgbm1630268 for ; Thu, 11 Mar 2010 03:27:42 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2AGXOd5002277 for ; Thu, 11 Mar 2010 03:33:24 +1100 Received: from localhost.localdomain ([9.124.221.30]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o2AGXMIS002252; Thu, 11 Mar 2010 03:33:23 +1100 From: "Aneesh Kumar K.V" To: cworth@cworth.org Date: Wed, 10 Mar 2010 22:03:15 +0530 Message-Id: <1268238795-14737-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.2.157.gb7e7f In-Reply-To: <1264241389-6326-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1264241389-6326-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Cc: "Aneesh Kumar K.V" , notmuch@notmuchmail.org Subject: [notmuch] [PATCH -V3] notmuch.el: Support for customizing search result display X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 10 Mar 2010 16:33:44 -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 "))) The supported keywords are date, count, authors, subject. Signed-off-by: Aneesh Kumar K.V --- emacs/notmuch.el | 55 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 38 insertions(+), 17 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 5b553bb..cc5167f 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -157,6 +157,18 @@ 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")) + "Search result formating. Supported fields are + date, count, authors, subject +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 @@ -1314,11 +1326,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. @@ -1356,17 +1363,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" @@ -1487,6 +1484,30 @@ This function advances the next thread when finished." (if never-found-target-thread (goto-char notmuch-search-target-position))))))) +(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 "%s" 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)) @@ -1510,7 +1531,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.2.157.gb7e7f