notmuch-search-toggle-order and notmuch-tree
[notmuch-archives.git] / 2d / 18ef73d04874e289ba3c73c1950b7c9a3af6f9
1 Return-Path: <markwalters1009@gmail.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 826D0431FC0\r
6         for <notmuch@notmuchmail.org>; Sun, 11 May 2014 01:35:02 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id OwnegEcCY-IC for <notmuch@notmuchmail.org>;\r
18         Sun, 11 May 2014 01:34:57 -0700 (PDT)\r
19 Received: from mail-we0-f170.google.com (mail-we0-f170.google.com\r
20         [74.125.82.170]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 51272431FC2\r
23         for <notmuch@notmuchmail.org>; Sun, 11 May 2014 01:34:52 -0700 (PDT)\r
24 Received: by mail-we0-f170.google.com with SMTP id u57so5679413wes.1\r
25         for <notmuch@notmuchmail.org>; Sun, 11 May 2014 01:34:51 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
28         bh=tFUNxtP9FiPlA6qcZwXcKL2GX0EwZefYH4nKn19Z9zo=;\r
29         b=1FhhgPygeimQUyq85gVmORWmWAXs8Y7opvKy0nUIcA2sb6J15mFGrrICNayTkwQrrY\r
30         GFgT/6/JgUbjubY2Wx6eGdsXe+TUIlVsDLWDkBekf9k6Cs98BfF/UnU7/wjESL6i1jW7\r
31         93hEm8+Akm/4AHzMLrsiwGa4bTX5nFZoa1xacdJsmLN4mjnLAeM2xnYhnu5T0b0MQBIK\r
32         h6fJwReIm/CCSptZPyNIhzsN2oGFwmjQ6LW9Ri/GGRXLC4a8AygfIq+xLoOlg7ZB3E2Q\r
33         IADRGydCl9Mz9R4fYokJcSdlQiHrLO3HWFXHY65Ng1W++7yoyfoeV/5osUMOWRTf+2bq\r
34         SXpA==\r
35 X-Received: by 10.180.107.5 with SMTP id gy5mr10704882wib.44.1399797291083;\r
36         Sun, 11 May 2014 01:34:51 -0700 (PDT)\r
37 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
38         by mx.google.com with ESMTPSA id dz5sm3841145wib.22.2014.05.11.01.34.50\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sun, 11 May 2014 01:34:50 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 2/7] emacs: hello: allow saved search display functions\r
45 Date: Sun, 11 May 2014 09:34:37 +0100\r
46 Message-Id: <1399797282-20389-3-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.10.4\r
48 In-Reply-To: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sun, 11 May 2014 08:35:02 -0000\r
63 \r
64 Extend the saved search plist to include a :display-function property\r
65 that can customise the display of the saved search. It can change the\r
66 count string displayed and the name string. Thus the user can\r
67 customise so that a particular search:\r
68 \r
69 does not show a count (and is thus hello is faster), shows a thread\r
70 count, show a combined message/thread count, changes colour of the\r
71 search button based on new messages arriving etc.\r
72 \r
73 The display function should use (&rest args) to take a keyword list of\r
74 arguments. The advantage of this is that it is easy to add extra\r
75 arguments in a backwards compatible way (existing user scripts will\r
76 still work).\r
77 \r
78 If a user uses this it will not take advantage of the batch counting\r
79 currently done so will make things slower over remote links (except in\r
80 cases where no query is done!).\r
81 \r
82 It also deletes the :count-query option from the customise for saved\r
83 searches as this method is much more general. The code still supports\r
84 the :count-query option though (just the defcustom does not).\r
85 ---\r
86  emacs/notmuch-hello.el |   47 +++++++++++++++++++++++++++++++----------------\r
87  1 file changed, 31 insertions(+), 16 deletions(-)\r
88 \r
89 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
90 index 0a7004c..7075860 100644\r
91 --- a/emacs/notmuch-hello.el\r
92 +++ b/emacs/notmuch-hello.el\r
93 @@ -85,12 +85,13 @@ (define-widget 'notmuch-saved-search-plist 'list\r
94                 (group :format "%v" :inline t (const :format "  Query: " :query) (string :format "%v")))\r
95           (checklist :inline t\r
96                      :format "%v"\r
97 -                    (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
98                      (group :format "%v" :inline t (const :format "" :sort-order)\r
99                             (choice :tag " Sort Order"\r
100                                     (const :tag "Default" nil)\r
101                                     (const :tag "Oldest-first" oldest-first)\r
102 -                                   (const :tag "Newest-first" newest-first))))))\r
103 +                                   (const :tag "Newest-first" newest-first)))\r
104 +                    (group :format "%v" :inline t (const :format "Display-function: " :display-function) (function :format "%v")))))\r
105 +\r
106  \r
107  (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
108                                     (:name "unread" :query "tag:unread"))\r
109 @@ -101,12 +102,19 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
110  \r
111    :name            Name of the search (required).\r
112    :query           Search to run (required).\r
113 -  :count-query     Optional extra query to generate the count\r
114 -                   shown. If not present then the :query property\r
115 -                   is used.\r
116    :sort-order      Specify the sort order to be used for the search.\r
117                     Possible values are 'oldest-first 'newest-first or\r
118                     nil. Nil means use the default sort order.\r
119 +  :display-function Optional function to generate the count and\r
120 +                   name to be displayed. The function takes a\r
121 +                   keyword list of arguments (it should use\r
122 +                   &rest). Keywords include :current for the\r
123 +                   current saved search plist and :options. If\r
124 +                   this function is not set then the default\r
125 +                   display of message count and name is used. The\r
126 +                   function should return an updated saved search\r
127 +                   plist including :name and :count as the name\r
128 +                   and count-string to be displayed.\r
129  \r
130  Other accepted forms are a cons cell of the form (NAME . QUERY)\r
131  or a list of the form (NAME QUERY COUNT-QUERY)."\r
132 @@ -507,15 +515,16 @@ (defun notmuch-hello-query-counts (query-list &rest options)\r
133  `notmuch-hello-insert-searches'."\r
134    (with-temp-buffer\r
135      (dolist (elem query-list nil)\r
136 -      (let ((count-query (or (notmuch-saved-search-get elem :count-query)\r
137 -                            (notmuch-saved-search-get elem :query))))\r
138 -       (insert\r
139 -        (replace-regexp-in-string\r
140 -         "\n" " "\r
141 -         (notmuch-hello-filtered-query count-query\r
142 -                                       (or (plist-get options :filter-count)\r
143 -                                           (plist-get options :filter))))\r
144 -         "\n")))\r
145 +      (unless (notmuch-saved-search-get elem :display-function)\r
146 +       (let ((count-query (or (notmuch-saved-search-get elem :count-query)\r
147 +                              (notmuch-saved-search-get elem :query))))\r
148 +         (insert\r
149 +          (replace-regexp-in-string\r
150 +           "\n" " "\r
151 +           (notmuch-hello-filtered-query count-query\r
152 +                                         (or (plist-get options :filter-count)\r
153 +                                             (plist-get options :filter))))\r
154 +          "\n"))))\r
155  \r
156      (unless (= (call-process-region (point-min) (point-max) notmuch-command\r
157                                     t t nil "count" "--batch") 0)\r
158 @@ -530,8 +539,14 @@ (defun notmuch-hello-query-counts (query-list &rest options)\r
159       #'identity\r
160       (mapcar\r
161        (lambda (elem)\r
162 -       (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)))\r
163 -         (notmuch-hello-batch-message-count elem-plist options)))\r
164 +       (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))\r
165 +              (display-function (plist-get elem-plist :display-function))\r
166 +              (result (if display-function\r
167 +                           (funcall display-function\r
168 +                                    :current elem-plist\r
169 +                                    :option options)\r
170 +                         (notmuch-hello-batch-message-count elem-plist options))))\r
171 +         result))\r
172        query-list))))\r
173  \r
174  (defun notmuch-hello-insert-buttons (searches)\r
175 -- \r
176 1.7.10.4\r
177 \r