Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / e6 / f06f12f7e6e42b52d0a30ef377f455071c30af
1 Return-Path: <aneesh.kumar@linux.vnet.ibm.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 4E01F4916AE\r
6         for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:33:44 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -5.254\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-5.254 tagged_above=-999 required=5 tests=[AWL=1.345,\r
12         BAYES_00=-2.599, RCVD_IN_DNSWL_MED=-4] autolearn=unavailable\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id J6tbIfhfgp3r for <notmuch@notmuchmail.org>;\r
16         Wed, 10 Mar 2010 08:33:44 -0800 (PST)\r
17 Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144])\r
18         by olra.theworths.org (Postfix) with ESMTP id BAD7C4916B2\r
19         for <notmuch@notmuchmail.org>; Wed, 10 Mar 2010 08:33:43 -0800 (PST)\r
20 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246])\r
21         by e23smtp02.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2AGUB9X022301\r
22         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:30:11 +1100\r
23 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138])\r
24         by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id\r
25         o2AGRgbm1630268\r
26         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:27:42 +1100\r
27 Received: from d23av02.au.ibm.com (loopback [127.0.0.1])\r
28         by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id\r
29         o2AGXOd5002277\r
30         for <notmuch@notmuchmail.org>; Thu, 11 Mar 2010 03:33:24 +1100\r
31 Received: from localhost.localdomain ([9.124.221.30])\r
32         by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id\r
33         o2AGXMIS002252; Thu, 11 Mar 2010 03:33:23 +1100\r
34 From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>\r
35 To: cworth@cworth.org\r
36 Date: Wed, 10 Mar 2010 22:03:15 +0530\r
37 Message-Id:\r
38  <1268238795-14737-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
39 X-Mailer: git-send-email 1.7.0.2.157.gb7e7f\r
40 In-Reply-To:\r
41  <1264241389-6326-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
42 References: <1264241389-6326-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>\r
43 Cc: "Aneesh Kumar K.V" <aneesh.kumar@gmail.com>, notmuch@notmuchmail.org\r
44 Subject: [notmuch] [PATCH -V3] notmuch.el: Support for customizing search\r
45         result display\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Wed, 10 Mar 2010 16:33:44 -0000\r
59 \r
60 From: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
61 \r
62 This patch helps in customizing search result display\r
63 similar to mutt's index_format. The customization is done\r
64 by defining an alist as below\r
65 \r
66 (setq notmuch-search-result-format '(("date" . "%s ")\r
67                                      ("authors" . "%-40s ")\r
68                                      ("subject" . "%s ")))\r
69 \r
70 The supported keywords are date, count, authors, subject.\r
71 \r
72 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\r
73 ---\r
74  emacs/notmuch.el |   55 +++++++++++++++++++++++++++++++++++++----------------\r
75  1 files changed, 38 insertions(+), 17 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
78 index 5b553bb..cc5167f 100644\r
79 --- a/emacs/notmuch.el\r
80 +++ b/emacs/notmuch.el\r
81 @@ -157,6 +157,18 @@ remaining lines into a button.")\r
82  (defvar notmuch-show-body-read-visible nil)\r
83  (defvar notmuch-show-citations-visible nil)\r
84  (defvar notmuch-show-signatures-visible nil)\r
85 +(defcustom notmuch-search-result-format\r
86 +  '(("date" . "%s")\r
87 +    ("count" . "%-7s")\r
88 +    ("authors" . "%-40s")\r
89 +    ("subject" . "%s"))\r
90 +  "Search result formating. Supported fields are\r
91 +       date, count, authors, subject\r
92 +ex: (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
93 +                                       \(\"subject\" . \"%s\"\)\)\)"\r
94 +:type '(alist :key-type (string) :value-type (string))\r
95 +:group 'notmuch)\r
96 +\r
97  (defvar notmuch-show-headers-visible nil)\r
98  \r
99  ; XXX: This should be a generic function in emacs somewhere, not here\r
100 @@ -1314,11 +1326,6 @@ matching this search term are shown if non-nil. "\r
101    "Notmuch search mode face used to highligh tags."\r
102    :group 'notmuch)\r
103  \r
104 -(defvar notmuch-tag-face-alist nil\r
105 -  "List containing the tag list that need to be highlighed")\r
106 -\r
107 -(defvar notmuch-search-font-lock-keywords  nil)\r
108 -\r
109  ;;;###autoload\r
110  (defun notmuch-search-mode ()\r
111    "Major mode displaying results of a notmuch search.\r
112 @@ -1356,17 +1363,7 @@ Complete list of currently available key bindings:\r
113    (setq truncate-lines t)\r
114    (setq major-mode 'notmuch-search-mode\r
115         mode-name "notmuch-search")\r
116 -  (setq buffer-read-only t)\r
117 -  (if (not notmuch-tag-face-alist)\r
118 -      (add-to-list 'notmuch-search-font-lock-keywords (list\r
119 -               "(\\([^)]*\\))$" '(1  'notmuch-tag-face)))\r
120 -    (let ((notmuch-search-tags (mapcar 'car notmuch-tag-face-alist)))\r
121 -      (loop for notmuch-search-tag  in notmuch-search-tags\r
122 -           do (add-to-list 'notmuch-search-font-lock-keywords (list\r
123 -                       (concat "([^)]*\\(" notmuch-search-tag "\\)[^)]*)$")\r
124 -                       `(1  ,(cdr (assoc notmuch-search-tag notmuch-tag-face-alist))))))))\r
125 -  (set (make-local-variable 'font-lock-defaults)\r
126 -         '(notmuch-search-font-lock-keywords t)))\r
127 +  (setq buffer-read-only t))\r
128  \r
129  (defun notmuch-search-find-thread-id ()\r
130    "Return the thread for the current thread"\r
131 @@ -1487,6 +1484,30 @@ This function advances the next thread when finished."\r
132               (if never-found-target-thread\r
133                   (goto-char notmuch-search-target-position)))))))\r
134  \r
135 +(defun insert-tags (tags)\r
136 +  (insert (concat "(" (propertize tags\r
137 +        'font-lock-face 'notmuch-tag-face) ")")))\r
138 +\r
139 +(defun insert-field (field date count authors subject tags)\r
140 +(if (string-equal field "date")\r
141 +    (insert (format (cdr (assoc field notmuch-search-result-format)) date))\r
142 +  (if (string-equal field "count")\r
143 +    (insert (format (cdr (assoc field notmuch-search-result-format)) count))\r
144 +  (if (string-equal field "authors")\r
145 +    (insert (format (cdr (assoc field notmuch-search-result-format)) authors))\r
146 +  (if (string-equal field "subject")\r
147 +      (insert (format (cdr (assoc field notmuch-search-result-format)) subject))\r
148 +  (if (string-equal field "tags")\r
149 +      (insert-tags (format "%s" tags)))\r
150 +)))))\r
151 +\r
152 +(defun notmuch-search-show-result (date count authors subject tags)\r
153 +(let ((fields) (field))\r
154 +  (setq fields (mapcar 'car notmuch-search-result-format))\r
155 +  (loop for field in  fields\r
156 +       do (insert-field field date count authors subject tags)))\r
157 +(insert "\n"))\r
158 +\r
159  (defun notmuch-search-process-filter (proc string)\r
160    "Process and filter the output of \"notmuch search\""\r
161    (let ((buffer (process-buffer proc))\r
162 @@ -1510,7 +1531,7 @@ This function advances the next thread when finished."\r
163                           (set 'authors (concat (substring authors 0 (- 40 3)) "...")))\r
164                       (goto-char (point-max))\r
165                       (let ((beg (point-marker)))\r
166 -                       (insert (format "%s %-7s %-40s %s (%s)\n" date count authors subject tags))\r
167 +                       (notmuch-search-show-result date count authors subject tags)\r
168                         (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id)\r
169                         (put-text-property beg (point-marker) 'notmuch-search-authors authors)\r
170                         (put-text-property beg (point-marker) 'notmuch-search-subject subject)\r
171 -- \r
172 1.7.0.2.157.gb7e7f\r
173 \r