Re: [PATCH 00/21] vim: general updates
[notmuch-archives.git] / 08 / 6d054330fd488a65a656062da3e93f705bd394
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 1D632421191\r
6         for <notmuch@notmuchmail.org>; Mon,  3 Jun 2013 02:42:24 -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 vk6-ZVVLGxw3 for <notmuch@notmuchmail.org>;\r
18         Mon,  3 Jun 2013 02:42:13 -0700 (PDT)\r
19 Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com\r
20  [74.125.82.41])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  B04AB421180    for <notmuch@notmuchmail.org>; Mon,  3 Jun 2013 02:42:13 -0700\r
23  (PDT)\r
24 Received: by mail-wg0-f41.google.com with SMTP id k13so2493258wgh.2\r
25         for <notmuch@notmuchmail.org>; Mon, 03 Jun 2013 02:42:11 -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:x-mailer;\r
28         bh=fFPkO/0noVmfeJAYHc4MG/29zRFgaNZHr45CbY0/beo=;\r
29         b=uoxGFYhzOCxCVqDZvqS9K3fH0KboIhbJuEHGqsQQm6kQkEMtlnTtXpzScRkTVDTgMT\r
30         NKgGaFu8lWcXIWSmS+ml+qPeKuoEK9GivzD6OUipttW0xd3Nhc64F5gYY2JdIl79LccY\r
31         X/LdkTP3tE6a67E7u/i9Bh5xNyRr/XM5s7EkFeANmLq+2HTxUGxqE6KN1xLW0iNKbqwQ\r
32         PeSG1NSTXX4RjuBF7Ox56ZoOEhFMO5LjrLDm909RKES1ECM1ug538XoqBOd0FyC5Q8RN\r
33         cL9vnm/53lBK1p8FQ05YR81d0m6p8uPZvMVAxCK4sIzoLPHStJhCbQtmndHBY9sDp/Rs\r
34         sF+w==\r
35 X-Received: by 10.194.249.231 with SMTP id yx7mr7432993wjc.13.1370252531175;\r
36         Mon, 03 Jun 2013 02:42:11 -0700 (PDT)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPSA id\r
39         fu14sm22205396wic.0.2013.06.03.02.42.09 for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Mon, 03 Jun 2013 02:42:10 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org,\r
44         jani@nikula.org\r
45 Subject: [RFC PATCH] emacs: search: allow command line args as part of query\r
46 Date: Mon,  3 Jun 2013 10:42:06 +0100\r
47 Message-Id: <1370252526-18003-1-git-send-email-markwalters1009@gmail.com>\r
48 X-Mailer: git-send-email 1.7.9.1\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Mon, 03 Jun 2013 09:42:24 -0000\r
62 \r
63 This allows command line arguments for notmuch-search to be part of\r
64 the query-string. The string must be of the form\r
65 [:blank:]*--cli-arguments -- query. I hope this doesn't clash with\r
66 xapian: I believe that queries shouldn't start with a "-".\r
67 \r
68 Correctly parsed example queries are\r
69 --sort=oldest-first -- tag:inbox\r
70 --exclude=false -- from:fred\r
71 \r
72 Some options (currently only sort-order) we parse in emacs, the rest\r
73 we just pass to the cli. In light testing it seems to work.\r
74 \r
75 A full custom parser would be nicer but at least here we are only parsing\r
76 the non-query part of a string which is relatively simple: indeed we\r
77 already do that in the c code.\r
78 \r
79 We could just implement the option for sort-order, but I thought for\r
80 interface consistency making all the options (sort-order exclude limit\r
81 and offset) work was worth the small extra hassle.\r
82 ---\r
83 \r
84 This is an attempt to achieve the same as\r
85 id:1349209083-7170-1-git-send-email-jani@nikula.org : that is allow a\r
86 saved search to specify the query sort order. However, this is a\r
87 rather more complete solution (note as this might be viewed a hack\r
88 minimal may be *better* than complete): it works for any search (saved\r
89 or from "s") and lets other options (exclude etc) work. What do people\r
90 think?\r
91 \r
92 Best wishes\r
93 \r
94 Mark\r
95 \r
96  emacs/notmuch.el |   31 ++++++++++++++++++++++++++-----\r
97  1 files changed, 26 insertions(+), 5 deletions(-)\r
98 \r
99 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
100 index 7994d74..26ba7e7 100644\r
101 --- a/emacs/notmuch.el\r
102 +++ b/emacs/notmuch.el\r
103 @@ -255,6 +255,7 @@ For a mouse binding, return nil."\r
104    (notmuch-common-do-stash (notmuch-search-find-thread-id)))\r
105  \r
106  (defvar notmuch-search-query-string)\r
107 +(defvar notmuch-search-full-query)\r
108  (defvar notmuch-search-target-thread)\r
109  (defvar notmuch-search-target-line)\r
110  (defvar notmuch-search-continuation)\r
111 @@ -409,6 +410,7 @@ Complete list of currently available key bindings:\r
112    (interactive)\r
113    (kill-all-local-variables)\r
114    (make-local-variable 'notmuch-search-query-string)\r
115 +  (make-local-variable 'notmuch-search-full-query)\r
116    (make-local-variable 'notmuch-search-oldest-first)\r
117    (make-local-variable 'notmuch-search-target-thread)\r
118    (make-local-variable 'notmuch-search-target-line)\r
119 @@ -896,6 +898,26 @@ PROMPT is the string to prompt with."\r
120         (read-from-minibuffer prompt nil keymap nil\r
121                               'notmuch-search-history nil nil)))))\r
122  \r
123 +(defun notmuch-search-parse-query (query oldest-first)\r
124 +  (setq notmuch-search-oldest-first oldest-first)\r
125 +  (if (string-match "^[:blank:]*--.*? -- " query)\r
126 +      (let ((actual-query (substring query (match-end 0)))\r
127 +           (args (split-string (match-string 0 query) " " t)))\r
128 +       (setq notmuch-search-query-string actual-query)\r
129 +       (dolist (arg args nil)\r
130 +         (when (equal arg "--sort=oldest-first")\r
131 +           (setq notmuch-search-oldest-first t)\r
132 +           (message "oldest first found"))\r
133 +         (when (equal arg "--sort=newest-first")\r
134 +           (setq notmuch-search-oldest-first nil)\r
135 +           (message "newest first found")))\r
136 +       (setq args (delete "--sort=oldest-first" args))\r
137 +       (setq args (delete "--sort=newest-first" args))\r
138 +       (setq notmuch-search-full-query (append args (list actual-query))))\r
139 +    ;; no special arguments\r
140 +    (setq notmuch-search-full-query (list query))\r
141 +    (setq notmuch-search-query-string query)))\r
142 +\r
143  ;;;###autoload\r
144  (defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
145    "Run \"notmuch search\" with the given `query' and display results.\r
146 @@ -915,8 +937,7 @@ Other optional parameters are used as follows:\r
147      (notmuch-search-mode)\r
148      ;; Don't track undo information for this buffer\r
149      (set 'buffer-undo-list t)\r
150 -    (set 'notmuch-search-query-string query)\r
151 -    (set 'notmuch-search-oldest-first oldest-first)\r
152 +    (notmuch-search-parse-query query oldest-first)\r
153      (set 'notmuch-search-target-thread target-thread)\r
154      (set 'notmuch-search-target-line target-line)\r
155      (set 'notmuch-search-continuation continuation)\r
156 @@ -928,13 +949,13 @@ Other optional parameters are used as follows:\r
157        (erase-buffer)\r
158        (goto-char (point-min))\r
159        (save-excursion\r
160 -       (let ((proc (notmuch-start-notmuch\r
161 +       (let ((proc (apply #'notmuch-start-notmuch\r
162                      "notmuch-search" buffer #'notmuch-search-process-sentinel\r
163                      "search" "--format=sexp" "--format-version=1"\r
164 -                    (if oldest-first\r
165 +                    (if notmuch-search-oldest-first\r
166                          "--sort=oldest-first"\r
167                        "--sort=newest-first")\r
168 -                    query))\r
169 +                    notmuch-search-full-query))\r
170               ;; Use a scratch buffer to accumulate partial output.\r
171               ;; This buffer will be killed by the sentinel, which\r
172               ;; should be called no matter how the process dies.\r
173 -- \r
174 1.7.9.1\r
175 \r