[PATCH 4/8] lib: extend private string map API with iterators
[notmuch-archives.git] / 36 / 0708d7b7cf38ad52a679d12160757b4d1d2e65
1 Return-Path: <tomi.ollila@iki.fi>\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 AD934431FAF\r
6         for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 13:07:40 -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: 2.438\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
12         tests=[DNS_FROM_AHBL_RHSBL=2.438] 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 odb7M8y4-6VO for <notmuch@notmuchmail.org>;\r
16         Sun, 18 Jan 2015 13:07:37 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id C17B0431FAE\r
19         for <notmuch@notmuchmail.org>; Sun, 18 Jan 2015 13:07:36 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id D71771000E0;\r
22         Sun, 18 Jan 2015 23:07:04 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH] cli: add a tool for starting new message in the emacs ui\r
26 In-Reply-To: <1421598115-4889-1-git-send-email-david@tethera.net>\r
27 References: <1404244957-3671-1-git-send-email-david@tethera.net>\r
28         <1421598115-4889-1-git-send-email-david@tethera.net>\r
29 User-Agent: Notmuch/0.19+29~g7367d27 (http://notmuchmail.org) Emacs/24.3.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Sun, 18 Jan 2015 23:07:04 +0200\r
35 Message-ID: <m2h9vnssqv.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain; charset=utf-8\r
38 Content-Transfer-Encoding: quoted-printable\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Sun, 18 Jan 2015 21:07:40 -0000\r
52 \r
53 On Sun, Jan 18 2015, David Bremner <david@tethera.net> wrote:\r
54 \r
55 > From: Jani Nikula <jani@nikula.org>\r
56 >\r
57 > Add a tool to start composing an email in the Notmuch Emacs UI with\r
58 > the specified subject, recipients, and message body.\r
59 > ---\r
60 >\r
61 > This version fixes my complaint about the previous version not\r
62 > starting emacs.  It does this by starting a new "frame", either at the\r
63 > window system level, or in the current terminal.  The traditional\r
64 > "-nw" short form of the argument "--no-window-system" seems maybe more\r
65 > work to parse than it's worth.\r
66 \r
67 Well, id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi (*) had -nw\r
68 parsing, but I can live without...\r
69 \r
70 But more than that one important feature has to be agreed before initial\r
71 interface is locked down -- how to provide body content from command line\r
72 without resorting to temporary files. In (*) --body was adding those lines\r
73 instead of reading file and I later suggested that --include or --insert\r
74 could do the same as -i ... but I am open to any solution that gives me\r
75 opportunity to provide body *content* from command line.\r
76 \r
77 Tomi\r
78 \r
79 >\r
80 >  doc/conf.py                    |   4 ++\r
81 >  doc/man1/notmuch-emacs-mua.rst |  53 ++++++++++++++++++\r
82 >  notmuch-emacs-mua              | 122 +++++++++++++++++++++++++++++++++++=\r
83 ++++++\r
84 >  3 files changed, 179 insertions(+)\r
85 >  create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
86 >  create mode 100755 notmuch-emacs-mua\r
87 >\r
88 > diff --git a/doc/conf.py b/doc/conf.py\r
89 > index fb49f6e..8fbc854 100644\r
90 > --- a/doc/conf.py\r
91 > +++ b/doc/conf.py\r
92 > @@ -78,6 +78,10 @@ man_pages =3D [\r
93 >          u'creates a plain-text dump of the tags of each message',\r
94 >          [u'Carl Worth and many others'], 1),\r
95 >=20=20\r
96 > +('man1/notmuch-emacs-mua','notmuch-emacs-mua',\r
97 > +        u'send mail with notmuch and emacs',\r
98 > +        [u'Carl Worth and many others'], 1),\r
99 > +\r
100 >  ('man5/notmuch-hooks','notmuch-hooks',\r
101 >          u'hooks for notmuch',\r
102 >          [u'Carl Worth and many others'], 5),\r
103 > diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.=\r
104 rst\r
105 > new file mode 100644\r
106 > index 0000000..bf8c3aa\r
107 > --- /dev/null\r
108 > +++ b/doc/man1/notmuch-emacs-mua.rst\r
109 > @@ -0,0 +1,53 @@\r
110 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
111 > +notmuch-emacs-mua\r
112 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
113 > +\r
114 > +SYNOPSIS\r
115 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
116 > +\r
117 > +**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
118 > +\r
119 > +DESCRIPTION\r
120 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
121 > +\r
122 > +Start composing an email in the Notmuch Emacs UI with the specified\r
123 > +subject, recipients, and message body.\r
124 > +\r
125 > +For **notmuch-emacs-mua** to work, you need **emacsclient** and an\r
126 > +already running Emacs with a server.\r
127 > +\r
128 > +Supported options for **notmuch-emacs-mua** include\r
129 > +\r
130 > +    ``-h, --help``\r
131 > +        Display help.\r
132 > +\r
133 > +    ``-s, --subject=3D``\ <subject>\r
134 > +        Specify the subject of the message.\r
135 > +\r
136 > +    ``--to=3D``\ <to-address>\r
137 > +        Specify a recipient (To).\r
138 > +\r
139 > +    ``-c, --cc=3D``\ <cc-address>\r
140 > +        Specify a carbon-copy (Cc) recipient.\r
141 > +\r
142 > +    ``-b, --bcc=3D``\ <bcc-address>\r
143 > +        Specify a blind-carbon-copy (Bcc) recipient.\r
144 > +\r
145 > +    ``-i, --body=3D``\ <file>\r
146 > +        Specify a file to include into the body of the message.\r
147 > +\r
148 > +    ``--no-window-system``\r
149 > +        Even if a window system is available, use the current terminal\r
150 > +\r
151 > +    ``--print``\r
152 > +        Output the resulting elisp to stdout instead of evaluating it.\r
153 > +\r
154 > +The supported positional parameters and short options are a compatible\r
155 > +subset of the **mutt** MUA command-line options.\r
156 > +\r
157 > +Options may be specified multiple times.\r
158 > +\r
159 > +SEE ALSO\r
160 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
161 > +\r
162 > +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
163 > diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
164 > new file mode 100755\r
165 > index 0000000..fdf4024\r
166 > --- /dev/null\r
167 > +++ b/notmuch-emacs-mua\r
168 > @@ -0,0 +1,122 @@\r
169 > +#!/usr/bin/env bash\r
170 > +#\r
171 > +# notmuch-emacs-mua - start composing a mail on the command line\r
172 > +#\r
173 > +# Copyright =C2=A9 2014 Jani Nikula\r
174 > +#\r
175 > +# This program is free software: you can redistribute it and/or modify\r
176 > +# it under the terms of the GNU General Public License as published by\r
177 > +# the Free Software Foundation, either version 3 of the License, or\r
178 > +# (at your option) any later version.\r
179 > +#\r
180 > +# This program is distributed in the hope that it will be useful,\r
181 > +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
182 > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
183 > +# GNU General Public License for more details.\r
184 > +#\r
185 > +# You should have received a copy of the GNU General Public License\r
186 > +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
187 > +#\r
188 > +# Authors: Jani Nikula <jani@nikula.org>\r
189 > +#\r
190 > +\r
191 > +set -eu\r
192 > +\r
193 > +escape ()\r
194 > +{\r
195 > +    echo "${1//\"/\\\"}"\r
196 > +}\r
197 > +\r
198 > +PRINT_ONLY=3D\r
199 > +CLIENT_TYPE=3D"-c"\r
200 > +\r
201 > +# The crux of it all: construct an elisp progn and eval it.\r
202 > +ELISP=3D"(prog1 'done (require 'notmuch) (notmuch-mua-new-mail)"\r
203 > +\r
204 > +while getopts :s:c:b:i:h opt; do\r
205 > +    # Handle errors and long options.\r
206 > +    case "${opt}" in\r
207 > +     :)\r
208 > +         echo "$0: short option -${OPTARG} requires an argument." >&2\r
209 > +         exit 1\r
210 > +         ;;\r
211 > +     \?)\r
212 > +         opt=3D$1\r
213 > +         if [ "${OPTARG}" !=3D "-" ]; then\r
214 > +             echo "$0: unknown short option -${OPTARG}." >&2\r
215 > +             exit 1\r
216 > +         fi\r
217 > +\r
218 > +         case "${opt}" in\r
219 > +             # Long options with arguments.\r
220 > +             --subject=3D*|--to=3D*|--cc=3D*|--bcc=3D*|--body=3D*)\r
221 > +                 OPTARG=3D${opt#--*=3D}\r
222 > +                 opt=3D${opt%%=3D*}\r
223 > +                 ;;\r
224 > +             # Long options without arguments.\r
225 > +             --help|--print|--no-window-system)\r
226 > +                 ;;\r
227 > +             *)\r
228 > +                 echo "$0: unknown long option ${opt}, or argument mismatch." >&2\r
229 > +                 exit 1\r
230 > +                 ;;\r
231 > +         esac\r
232 > +         # getopts does not do this for what it considers errors.\r
233 > +         OPTIND=3D$((OPTIND + 1))\r
234 > +         ;;\r
235 > +    esac\r
236 > +\r
237 > +    OPTARG=3D"$(escape "${OPTARG}")"\r
238 > +\r
239 > +    case "${opt}" in\r
240 > +     --help|h)\r
241 > +         exec man notmuch-emacs-mua\r
242 > +         ;;\r
243 > +     --subject|s)\r
244 > +         ELISP=3D"${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
245 > +         ;;\r
246 > +     --to)\r
247 > +         ELISP=3D"${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
248 > +         ;;\r
249 > +     --cc|c)\r
250 > +         ELISP=3D"${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
251 > +         ;;\r
252 > +     --bcc|b)\r
253 > +         ELISP=3D"${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
254 > +         ;;\r
255 > +     --body|i)\r
256 > +         ELISP=3D"${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file =\r
257 \"${OPTARG}\")"\r
258 > +         ;;\r
259 > +     --print)\r
260 > +         PRINT_ONLY=3D1\r
261 > +         ;;\r
262 > +     --no-window-system)\r
263 > +         CLIENT_TYPE=3D"-t"\r
264 > +         ;;\r
265 > +     *)\r
266 > +         # We should never end up here.\r
267 > +         echo "$0: internal error (option ${opt})." >&2\r
268 > +         exit 1\r
269 > +         ;;\r
270 > +    esac\r
271 > +\r
272 > +    shift $((OPTIND - 1))\r
273 > +    OPTIND=3D1\r
274 > +done\r
275 > +\r
276 > +# Positional parameters.\r
277 > +for arg; do\r
278 > +    arg=3D"$(escape "${arg}")"\r
279 > +    ELISP=3D"${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
280 > +done\r
281 > +\r
282 > +# End progn.\r
283 > +ELISP=3D"${ELISP})"\r
284 > +\r
285 > +if [ -n "$PRINT_ONLY" ]; then\r
286 > +    echo ${ELISP}\r
287 > +    exit 0\r
288 > +fi\r
289 > +\r
290 > +# Evaluate the progn.\r
291 > +exec emacsclient ${CLIENT_TYPE} -a '' --eval "${ELISP}"\r
292 > --=20\r
293 > 2.1.4\r