1 Return-Path: <amdragon@mit.edu>
\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 BEA19429E2C
\r
6 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2011 14:55:34 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\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 KjOBEpJbPrQu for <notmuch@notmuchmail.org>;
\r
16 Sat, 4 Jun 2011 14:55:33 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id C279C431FB6
\r
20 for <notmuch@notmuchmail.org>; Sat, 4 Jun 2011 14:55:33 -0700 (PDT)
\r
21 X-AuditID: 1209190f-b7c4dae0000007bd-cb-4deaa9d71c74
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id C0.C6.01981.7D9AAED4; Sat, 4 Jun 2011 17:55:35 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p54LtWUf002615;
\r
27 Sat, 4 Jun 2011 17:55:32 -0400
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p54LtU6f009874
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sat, 4 Jun 2011 17:55:31 -0400 (EDT)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1QSyoW-0004OG-4u; Sat, 04 Jun 2011 17:55:24 -0400
\r
37 Date: Sat, 4 Jun 2011 17:55:24 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Daniel Schoepe <daniel.schoepe@googlemail.com>
\r
40 Subject: Re: [PATCH] emacs: Tab completion for notmuch-search and
\r
41 notmuch-search-filter
\r
42 Message-ID: <20110604215523.GF29861@mit.edu>
\r
43 References: <1307189970-728-1-git-send-email-daniel.schoepe@googlemail.com>
\r
44 <BANLkTimudbqYy8JhGHu67WsOS04mCm0hfA@mail.gmail.com>
\r
45 <87mxhxjrry.fsf@gilead.invalid>
\r
47 Content-Type: text/plain; charset=us-ascii
\r
48 Content-Disposition: inline
\r
49 In-Reply-To: <87mxhxjrry.fsf@gilead.invalid>
\r
50 User-Agent: Mutt/1.5.20 (2009-06-14)
\r
51 X-Brightmail-Tracker:
\r
52 H4sIAAAAAAAAA+NgFprAKsWRmVeSWpSXmKPExsUixG6nont95StfgyXLFSwWHjrDYnH95kxm
\r
53 ByaPpxMms3s8W3WLOYApissmJTUnsyy1SN8ugSvj/p9bjAW3ZSsur7/B3sB4VryLkZNDQsBE
\r
54 YkHnfkYIW0ziwr31bF2MXBxCAvsYJTY9uMMK4axnlJh0o5EdwjnBJNH44AZU2RJGic4dW8D6
\r
55 WQRUJNqP7WADsdkENCS27V8OFhcRMJJ4teYxE4jNLCAt8e13M5DNwSEsEClxbEUgSJhXQEfi
\r
56 x5Z3jHAzd/cfYoFICEqcnPmEBaJXS+LGv5dgvSBzlv/jAAlzAvUevtgIViIKdMK1/e1sExiF
\r
57 ZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6Jnq5mSV6qSmlmxhBgc0pyb+D
\r
58 8dtBpUOMAhyMSjy8rkmvfIVYE8uKK3MPMUpyMCmJ8iauAArxJeWnVGYkFmfEF5XmpBYfYpTg
\r
59 YFYS4a0TAcrxpiRWVqUW5cOkpDlYlMR5Z0mq+woJpCeWpGanphakFsFkZTg4lCR4o4ERLCRY
\r
60 lJqeWpGWmVOCkGbi4AQZzgM0PAikhre4IDG3ODMdIn+KUZfj0MlXBxmFWPLy81KlxHmVQIoE
\r
61 QIoySvPg5sAS0itGcaC3hHmlQap4gMkMbtIroCVMQEuOO4EtKUlESEk1MPLmqFcofAsVcZux
\r
62 bqvbLX+PfFUpExHxNXGdcnoZodKl9usdOp+ImNVsnWr4XeyBq9Q76TeaX/c4vWHvd795+v6j
\r
63 nCTDTjfnhSxTVufEF9ZObDZ5vvmTKRdfw9SM0Pkzmfr71tqwLf+R979m9t9dP7Y/fNARE5/w
\r
64 rCiokPvSQ86fs+duF7xiq8RSnJFoqMVcVJwIAMVxfGsjAwAA
\r
65 Cc: notmuch@notmuchmail.org
\r
66 X-BeenThere: notmuch@notmuchmail.org
\r
67 X-Mailman-Version: 2.1.13
\r
69 List-Id: "Use and development of the notmuch mail system."
\r
70 <notmuch.notmuchmail.org>
\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
74 List-Post: <mailto:notmuch@notmuchmail.org>
\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
77 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
78 X-List-Received-Date: Sat, 04 Jun 2011 21:55:34 -0000
\r
80 Quoth Daniel Schoepe on Jun 04 at 9:55 pm:
\r
81 > On Sat, 4 Jun 2011 11:32:15 -0400, Austin Clements <amdragon@mit.edu> wrote:
\r
82 > > Dynamic scoping is obnoxious, but I think programmed completion is
\r
83 > > steeped in the assumption that you'll use it. This code would be much
\r
84 > > simpler if notmuch-query-completions took only `string' and used the
\r
85 > > dynamically-bound all-compls (which should probably be renamed
\r
86 > > notmuch-completions or something if you do this). Then this could be
\r
88 > > (minibuffer-completion-table (completion-table-dynamic
\r
89 > > #'notmuch-query-completions)))
\r
90 > > and there'd be no need for quasiquoting, comments, and fake lexical scoping.
\r
92 > Sounds reasonable, I guess I really should stop fighting all those ugly
\r
93 > parts of elisp with unreadable constructs like that. I made it a global
\r
94 > variable though to avoid compilation warnings about notmuch-completion
\r
95 > being a free variable. Since it's contents are not dependent on
\r
96 > how/where notmuch-read-query is called, this shouldn't cause any
\r
97 > problems, except my personal discomfort arising from the use of side
\r
98 > effects for something as simple as this. :)
\r
100 Oh, sorry, I wasn't suggesting setq'ing a global. I agree that that's
\r
101 really ugly. Rather, something like
\r
103 (defun notmuch-query-completions (string)
\r
104 ... as you have it now ...)
\r
106 (defun notmuch-read-query (prompt)
\r
107 (let ((notmuch-completions (append (list "folder:" ...)))
\r
109 (minibuffer-completion-table ...))
\r
110 (read-from-minibuffer ...)))
\r
112 Unfortunately, you still need the global defvar to avoid compilation
\r
113 warnings, but this at least avoids the side-effects, and is probably
\r
114 how programmed completion was intended to be used.
\r
116 Alternatively, here's a completely different way to structure this
\r
117 that avoids globals and dynamic scoping entirely. This is how some of
\r
118 the standard completing read functions appear to work:
\r
120 (defun notmuch-read-query (prompt)
\r
121 "Read a notmuch-query from the minibuffer with completion.
\r
123 PROMPT is the string to prompt with."
\r
124 (lexical-let ((completions
\r
125 (append (list "folder:" "thread:" "id:" "date:" "from:" "to:"
\r
126 "subject:" "attachment:")
\r
127 (mapcar (lambda (tag)
\r
128 (concat "tag:" tag))
\r
129 (process-lines "notmuch" "search-tags")))))
\r
130 (let ((minibuffer-completion-table
\r
131 (completion-table-dynamic
\r
134 ;; this ugly regexp is used to get the last word of the
\r
135 ;; input possibly preceded by a '('
\r
136 ((string-match "\\(^\\|.* (?\\)\\([^ ]*\\)$" string)
\r
137 (mapcar (lambda (compl)
\r
138 (concat (match-string-no-properties 1 string) compl))
\r
139 (all-completions (match-string-no-properties 2 string)
\r
141 (t (list string))))))
\r
142 (keymap (copy-keymap minibuffer-local-map)))
\r
143 ;; this was simpler than convincing completing-read to accept spaces:
\r
144 (define-key keymap (kbd "<tab>") 'minibuffer-complete)
\r
145 (read-from-minibuffer prompt nil keymap nil minibuffer-history nil nil))))
\r
147 > > > + (define-key keymap (kbd "<tab>") 'minibuffer-complete)
\r
149 > > This probably deserves a comment about why you're doing so much work
\r
150 > > to avoid completing-read (which I assume is because it also binds SPC,
\r
151 > > even if require-match is nil, which is unfortunate).
\r
153 > Yes, that was the reason.
\r
155 > Another thing that bugs me, is that I did not find a better way of doing
\r
156 > the completion: Ideally I'd like to just specify a list of completions
\r
157 > for individual words and have emacs handle separating the input string
\r
158 > into individual words, but I couldn't find any options to accomplish
\r
161 Yeah, I futzed with it for a bit, swearing that there had to be a
\r
162 better way, but didn't find one either.
\r