[notmuch] [PATCH -V3] notmuch.el: Support for customizing search result display
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Thu, 11 Feb 2010 16:41:46 +0000 (22:11 +0530)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:10 +0000 (09:36 -0800)
18/3b37806d8559e33fda6be041522b14ec7998ef [new file with mode: 0644]

diff --git a/18/3b37806d8559e33fda6be041522b14ec7998ef b/18/3b37806d8559e33fda6be041522b14ec7998ef
new file mode 100644 (file)
index 0000000..b838e93
--- /dev/null
@@ -0,0 +1,174 @@
+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 E40B6431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 11 Feb 2010 08:41:55 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -3.879\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-3.879 tagged_above=-999 required=5 tests=[AWL=0.120,\r
+       BAYES_50=0.001, 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 Qo38WPjX93d5 for <notmuch@notmuchmail.org>;\r
+       Thu, 11 Feb 2010 08:41:54 -0800 (PST)\r
+Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140])\r
+       by olra.theworths.org (Postfix) with ESMTP id 97B7C431FBC\r
+       for <notmuch@notmuchmail.org>; Thu, 11 Feb 2010 08:41:53 -0800 (PST)\r
+Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [202.81.31.245])\r
+       by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o1BGfpPd024202\r
+       for <notmuch@notmuchmail.org>; Fri, 12 Feb 2010 03:41:51 +1100\r
+Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139])\r
+       by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
+       o1BGfpdw1642642\r
+       for <notmuch@notmuchmail.org>; Fri, 12 Feb 2010 03:41:51 +1100\r
+Received: from d23av04.au.ibm.com (loopback [127.0.0.1])\r
+       by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
+       o1BGfp4k018922\r
+       for <notmuch@notmuchmail.org>; Fri, 12 Feb 2010 03:41:51 +1100\r
+Received: from localhost.localdomain ([9.124.211.8])\r
+       by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
+       o1BGfnbn018882; Fri, 12 Feb 2010 03:41:49 +1100\r
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
+To: cworth@cworth.org\r
+Date: Thu, 11 Feb 2010 22:11:46 +0530\r
+Message-Id:\r
+ <1265906506-10395-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
+X-Mailer: git-send-email 1.7.0.rc2\r
+In-Reply-To: <87bpg3e9u9.fsf@yoom.home.cworth.org>\r
+References: <87bpg3e9u9.fsf@yoom.home.cworth.org>\r
+Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
+Subject: [notmuch] [PATCH -V3] 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: Thu, 11 Feb 2010 16:41:56 -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 040997e..a4a89ac 100644\r
+--- a/notmuch.el\r
++++ b/notmuch.el\r
+@@ -141,6 +141,19 @@ remaining lines into a button.")\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\r
++  '(("date" . "%s")\r
++    ("count" . "%-7s")\r
++    ("authors" . "%-40s")\r
++    ("subject" . "%s")\r
++    ("tags" . "%s"))\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
+@@ -1175,11 +1188,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
+@@ -1215,17 +1223,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
+@@ -1340,6 +1338,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
+@@ -1362,7 +1384,7 @@ 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
++                      (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.7.0.rc2\r
+\r