[notmuch] [PATCH -V2] notmuch.el: Support for customizing search result display
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Sat, 23 Jan 2010 10:09:49 +0000 (15:39 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:01 +0000 (09:36 -0800)
d1/e8b1cfade892ce8dec84c543a90dc1df1cc68a [new file with mode: 0644]

diff --git a/d1/e8b1cfade892ce8dec84c543a90dc1df1cc68a b/d1/e8b1cfade892ce8dec84c543a90dc1df1cc68a
new file mode 100644 (file)
index 0000000..4ed44a1
--- /dev/null
@@ -0,0 +1,171 @@
+Return-Path: <aneesh.kumar@linux.vnet.ibm.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E0EDE431FC0\r
+       for <notmuch@notmuchmail.org>; Sat, 23 Jan 2010 02:09:59 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -4.438\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-4.438 tagged_above=-999 required=5 tests=[AWL=0.672,\r
+       BAYES_05=-1.11, RCVD_IN_DNSWL_MED=-4] autolearn=unavailable\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id CbJZVVG8R0At for <notmuch@notmuchmail.org>;\r
+       Sat, 23 Jan 2010 02:09:59 -0800 (PST)\r
+Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143])\r
+       by olra.theworths.org (Postfix) with ESMTP id CA693431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 23 Jan 2010 02:09:58 -0800 (PST)\r
+Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245])\r
+       by e23smtp01.au.ibm.com (8.14.3/8.13.1) with ESMTP id o0NA84Vt024585\r
+       for <notmuch@notmuchmail.org>; Sat, 23 Jan 2010 21:08:04 +1100\r
+Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138])\r
+       by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
+       o0NA9vFl1868022\r
+       for <notmuch@notmuchmail.org>; Sat, 23 Jan 2010 21:09:57 +1100\r
+Received: from d23av02.au.ibm.com (loopback [127.0.0.1])\r
+       by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
+       o0NA9uQP008507\r
+       for <notmuch@notmuchmail.org>; Sat, 23 Jan 2010 21:09:57 +1100\r
+Received: from localhost.localdomain ([9.77.206.84])\r
+       by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
+       o0NA9pjf008498; Sat, 23 Jan 2010 21:09:53 +1100\r
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
+To: cworth@cworth.org\r
+Date: Sat, 23 Jan 2010 15:39:49 +0530\r
+Message-Id: <1264241389-6326-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
+X-Mailer: git-send-email 1.6.6.1.394.gdedc0\r
+Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
+Subject: [notmuch] [PATCH -V2] notmuch.el: Support for customizing search\r
+       result display\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 23 Jan 2010 10:10:00 -0000\r
+\r
+From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
+\r
+This patch helps in customizing search result display\r
+similar to mutt's index_format. The customization is done\r
+by defining an alist as below\r
+\r
+(setq notmuch-search-result-format '(("date" . "%s ")\r
+                                    ("authors" . "%-40s ")\r
+                                    ("subject" . "%s ")\r
+                                    ("tags" . "(%s)")))\r
+\r
+The supported keywords are date, count, authors, subject and tags.\r
+\r
+Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
+---\r
+ notmuch.el |   56 +++++++++++++++++++++++++++++++++++++++-----------------\r
+ 1 files changed, 39 insertions(+), 17 deletions(-)\r
+\r
+diff --git a/notmuch.el b/notmuch.el\r
+index 97914f2..89dc32a 100644\r
+--- a/notmuch.el\r
++++ b/notmuch.el\r
+@@ -119,6 +119,14 @@ pattern can still test against the entire line).")\r
+ (defvar notmuch-show-body-read-visible nil)\r
+ (defvar notmuch-show-citations-visible nil)\r
+ (defvar notmuch-show-signatures-visible nil)\r
++(defcustom notmuch-search-result-format nil\r
++  "Search result formating. Supported fields are\r
++      date, count, authors, subject, tags\r
++ex: (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
++                                      \(\"subject\" . \"%s\"\)\)\)"\r
++:type '(alist :key-type (string) :value-type (string))\r
++:group 'notmuch)\r
++\r
+ (defvar notmuch-show-headers-visible nil)\r
\r
+ ; XXX: This should be a generic function in emacs somewhere, not here\r
+@@ -1065,11 +1073,6 @@ matching this search term are shown if non-nil. "\r
+   "Notmuch search mode face used to highligh tags."\r
+   :group 'notmuch)\r
\r
+-(defvar notmuch-tag-face-alist nil\r
+-  "List containing the tag list that need to be highlighed")\r
+-\r
+-(defvar notmuch-search-font-lock-keywords  nil)\r
+-\r
+ ;;;###autoload\r
+ (defun notmuch-search-mode ()\r
+   "Major mode displaying results of a notmuch search.\r
+@@ -1105,17 +1108,7 @@ Complete list of currently available key bindings:\r
+   (setq truncate-lines t)\r
+   (setq major-mode 'notmuch-search-mode\r
+       mode-name "notmuch-search")\r
+-  (setq buffer-read-only t)\r
+-  (if (not notmuch-tag-face-alist)\r
+-      (add-to-list 'notmuch-search-font-lock-keywords (list\r
+-              "(\\([^)]*\\))$" '(1  'notmuch-tag-face)))\r
+-    (let ((notmuch-search-tags (mapcar 'car notmuch-tag-face-alist)))\r
+-      (loop for notmuch-search-tag  in notmuch-search-tags\r
+-          do (add-to-list 'notmuch-search-font-lock-keywords (list\r
+-                      (concat "([^)]*\\(" notmuch-search-tag "\\)[^)]*)$")\r
+-                      `(1  ,(cdr (assoc notmuch-search-tag notmuch-tag-face-alist))))))))\r
+-  (set (make-local-variable 'font-lock-defaults)\r
+-         '(notmuch-search-font-lock-keywords t)))\r
++  (setq buffer-read-only t))\r
\r
+ (defun notmuch-search-find-thread-id ()\r
+   "Return the thread for the current thread"\r
+@@ -1230,6 +1223,30 @@ This function advances the next thread when finished."\r
+                           (insert (format " (process returned %d)" exit-status)))\r
+                       (insert "\n"))))))))))\r
\r
++(defun insert-tags (tags)\r
++  (insert (concat "(" (propertize tags\r
++        'font-lock-face 'notmuch-tag-face) ")")))\r
++\r
++(defun insert-field (field date count authors subject tags)\r
++(if (string-equal field "date")\r
++    (insert (format (cdr (assoc field notmuch-search-result-format)) date))\r
++  (if (string-equal field "count")\r
++    (insert (format (cdr (assoc field notmuch-search-result-format)) count))\r
++  (if (string-equal field "authors")\r
++    (insert (format (cdr (assoc field notmuch-search-result-format)) authors))\r
++  (if (string-equal field "subject")\r
++      (insert (format (cdr (assoc field notmuch-search-result-format)) subject))\r
++  (if (string-equal field "tags")\r
++      (insert-tags (format (cdr (assoc field notmuch-search-result-format)) tags)))\r
++)))))\r
++\r
++(defun notmuch-search-show-result (date count authors subject tags)\r
++(let ((fields) (field))\r
++  (setq fields (mapcar 'car notmuch-search-result-format))\r
++  (loop for field in  fields\r
++      do (insert-field field date count authors subject tags)))\r
++(insert "\n"))\r
++\r
+ (defun notmuch-search-process-filter (proc string)\r
+   "Process and filter the output of \"notmuch search\""\r
+   (let ((buffer (process-buffer proc)))\r
+@@ -1252,7 +1269,12 @@ This function advances the next thread when finished."\r
+                         (set 'authors (concat (substring authors 0 (- 40 3)) "...")))\r
+                     (goto-char (point-max))\r
+                     (let ((beg (point-marker)))\r
+-                      (insert (format "%s %-7s %-40s %s (%s)\n" date count authors subject tags))\r
++                      (if (not notmuch-search-result-format)\r
++                          (progn (insert (format "%s %-7s %-40s %s" date count authors subject))\r
++                                 ;; insert the fontified tag\r
++                                 (insert-tags (format "%s" tags))\r
++                                 (insert "\n"))\r
++                        (notmuch-search-show-result date count authors subject tags))\r
+                       (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)\r
+                       (put-text-property beg (point-marker) 'notmuch-search-authors authors)\r
+                       (put-text-property beg (point-marker) 'notmuch-search-subject subject))\r
+-- \r
+1.6.6.1.394.gdedc0\r
+\r