Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / 8c / cffc17ece34cddc8f45bb37d0760b44218bf70
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 5A505431FBF\r
6         for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:24:19 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 5InZNWLWmo9y for <notmuch@notmuchmail.org>;\r
16         Wed, 19 Mar 2014 14:24:10 -0700 (PDT)\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 B1BDE431FAE\r
19         for <notmuch@notmuchmail.org>; Wed, 19 Mar 2014 14:24:09 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 0C38810009D;\r
22         Wed, 19 Mar 2014 23:24:03 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Jani Nikula <jani@nikula.org>, 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: <1395257153-29764-1-git-send-email-jani@nikula.org>\r
27 References: <1395257153-29764-1-git-send-email-jani@nikula.org>\r
28 User-Agent: Notmuch/0.17+155~g3416ef5 (http://notmuchmail.org) Emacs/24.3.1\r
29         (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Wed, 19 Mar 2014 23:24:02 +0200\r
34 Message-ID: <m2eh1x6fwt.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain; charset=utf-8\r
37 Content-Transfer-Encoding: quoted-printable\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Wed, 19 Mar 2014 21:24:19 -0000\r
51 \r
52 On Wed, Mar 19 2014, Jani Nikula <jani@nikula.org> wrote:\r
53 \r
54 > Add a tool to start composing an email in the Notmuch Emacs UI with\r
55 > the specified subject, recipients, and message body.\r
56 >\r
57 > ---\r
58 >\r
59 > I need something like this to script some mails, particularly with the\r
60 > mutt compatible options, but I also think notmuch must have long\r
61 > options. I then got a little carried away with figuring out how to\r
62 > support both. I think it turned out pretty neat, except due to some\r
63 > subtlety it only works with bash.\r
64 >\r
65 > I didn't integrate this in the man build or install or anything,\r
66 > because I wanted to get feedback first on whether we want to have this\r
67 > at all. Or if it should live in contrib or something.\r
68 >\r
69 > BR,\r
70 > Jani.\r
71 > ---\r
72 \r
73 Quick glance to the code and some thoughts.\r
74 \r
75 >  doc/man1/notmuch-emacs-mua.rst |  50 ++++++++++++++++++\r
76 >  notmuch-emacs-mua              | 113 +++++++++++++++++++++++++++++++++++=\r
77 ++++++\r
78 >  2 files changed, 163 insertions(+)\r
79 >  create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
80 >  create mode 100755 notmuch-emacs-mua\r
81 >\r
82 > diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.=\r
83 rst\r
84 > new file mode 100644\r
85 > index 000000000000..6e63818492fb\r
86 > --- /dev/null\r
87 > +++ b/doc/man1/notmuch-emacs-mua.rst\r
88 > @@ -0,0 +1,50 @@\r
89 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
90 > +notmuch-emacs-mua\r
91 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
92 > +\r
93 > +SYNOPSIS\r
94 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
95 > +\r
96 > +**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
97 > +\r
98 > +DESCRIPTION\r
99 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
100 > +\r
101 > +Start composing an email in the Notmuch Emacs UI with the specified\r
102 > +subject, recipients, and message body.\r
103 > +\r
104 > +For **notmuch-emacs-mua** to work, you need **emacsclient** and an\r
105 > +already running Emacs with a server.\r
106 > +\r
107 > +Supported options for **notmuch-emacs-mua** include\r
108 > +\r
109 > +    ``-h, --help``\r
110 > +        Display help.\r
111 > +\r
112 > +    ``-s, --subject=3D``\ <subject>\r
113 > +        Specify the subject of the message.\r
114 > +\r
115 > +    ``--to=3D``\ <to-address>\r
116 > +        Specify a recipient (To).\r
117 > +\r
118 > +    ``-c, --cc=3D``\ <cc-address>\r
119 > +        Specify a carbon-copy (Cc) recipient.\r
120 > +\r
121 > +    ``-b, --bcc=3D``\ <bcc-address>\r
122 > +        Specify a blind-carbon-copy (Bcc) recipient.\r
123 > +\r
124 > +    ``-i, --body=3D``\ <file>\r
125 > +        Specify a file to include into the body of the message.\r
126 > +\r
127 > +    ``--print``\r
128 > +        Output the resulting elisp to stdout instead of evaluating it.\r
129 > +\r
130 > +The supported positional parameters and short options are a compatible\r
131 > +subset of the **mutt** MUA command-line options.\r
132 > +\r
133 > +Options may be specified multiple times.\r
134 > +\r
135 > +SEE ALSO\r
136 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
137 > +\r
138 > +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
139 \r
140 It would be convenient to the user to have the manual embedded in\r
141 the script in case no args are given or so (or that is convenient\r
142 to me ;) and no namual page at all...\r
143 \r
144 > diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
145 > new file mode 100755\r
146 > index 000000000000..a482fe1a8eca\r
147 > --- /dev/null\r
148 > +++ b/notmuch-emacs-mua\r
149 > @@ -0,0 +1,113 @@\r
150 > +#!/bin/bash\r
151 \r
152 #!/usr/bin/env bash\r
153 \r
154 > +#\r
155 > +# notmuch-emacs-mua - start composing a mail on the command line\r
156 > +#\r
157 > +# Copyright =C2=A9 2014 Jani Nikula\r
158 > +#\r
159 > +# This program is free software: you can redistribute it and/or modify\r
160 > +# it under the terms of the GNU General Public License as published by\r
161 > +# the Free Software Foundation, either version 3 of the License, or\r
162 > +# (at your option) any later version.\r
163 > +#\r
164 > +# This program is distributed in the hope that it will be useful,\r
165 > +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
166 > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
167 > +# GNU General Public License for more details.\r
168 > +#\r
169 > +# You should have received a copy of the GNU General Public License\r
170 > +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
171 > +#\r
172 > +# Authors: Jani Nikula <jani@nikula.org>\r
173 > +#\r
174 > +\r
175 > +set -e\r
176 \r
177 set -eu would be nice IMO...\r
178 \r
179 ... then initialize all vars to empty strings, like PRINT_ONLY=3D\r
180 ... and in cases not possible syntax ${1-} can be used.\r
181 \r
182 > +\r
183 > +# The crux of it all: construct an elisp progn and eval it.\r
184 > +ELISP=3D"(progn (notmuch-mua-new-mail)"\r
185 \r
186 ELISP=3D"(progn (require 'notmuch) (notmuch-mua-new-mail)"\r
187 \r
188 > +\r
189 > +while getopts :s:c:b:i:h opt; do\r
190 > +    # Handle errors and long options.\r
191 > +    case "${opt}" in\r
192 > +     :)\r
193 > +         echo "$0: short option -${OPTARG} requires an argument." >&2\r
194 > +         exit 1\r
195 > +         ;;\r
196 > +     \?)\r
197 > +         opt=3D$1\r
198 > +         if [ "${OPTARG}" !=3D "-" ]; then\r
199 > +             echo "$0: unknown short option -${OPTARG}." >&2\r
200 > +             exit 1\r
201 > +         fi\r
202 > +\r
203 > +         case "${opt}" in\r
204 > +             # Long options with arguments.\r
205 > +             --subject=3D*|--to=3D*|--cc=3D*|--bcc=3D*|--body=3D*)\r
206 > +                 OPTARG=3D${opt#--*=3D}\r
207 > +                 opt=3D${opt%%=3D*}\r
208 > +                 ;;\r
209 > +             # Long options without arguments.\r
210 > +             --help|--print)\r
211 > +                 ;;\r
212 > +             *)\r
213 > +                 echo "$0: unknown long option ${opt}, or argument mismatch." >&2\r
214 > +                 exit 1\r
215 > +                 ;;\r
216 > +         esac\r
217 > +         # getopts does not do this for what it considers errors.\r
218 > +         OPTIND=3D$((OPTIND + 1))\r
219 > +         ;;\r
220 > +    esac\r
221 > +\r
222 > +    case "${opt}" in\r
223 > +     --help|h)\r
224 > +         exec man notmuch-search\r
225 > +         ;;\r
226 > +     --subject|s)\r
227 > +         ELISP=3D"${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"\r
228 > +         ;;\r
229 > +     --to)\r
230 > +         ELISP=3D"${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"\r
231 > +         ;;\r
232 > +     --cc|c)\r
233 > +         ELISP=3D"${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"\r
234 > +         ;;\r
235 > +     --bcc|b)\r
236 > +         ELISP=3D"${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"\r
237 > +         ;;\r
238 > +     --body|i)\r
239 > +         ELISP=3D"${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file =\r
240 \"${OPTARG}\")"\r
241 > +         ;;\r
242 > +     --print)\r
243 > +         PRINT_ONLY=3D1\r
244 > +         ;;\r
245 > +     *)\r
246 > +         # We should never end up here.\r
247 > +         echo "$0: internal error (option ${opt})." >&2\r
248 > +         exit 1\r
249 > +         ;;\r
250 > +    esac\r
251 > +\r
252 > +    shift $((OPTIND - 1))\r
253 > +    OPTIND=3D1\r
254 > +done\r
255 > +\r
256 > +# Positional parameters.\r
257 > +while [ $# -gt 0 ]; do\r
258 > +    ELISP=3D"${ELISP} (message-goto-to) (insert \"${1}, \")"\r
259 > +    shift\r
260 > +done\r
261 \r
262 for arg; do\r
263    ELISP=3D"${ELISP} (message-goto-to) (insert \"${arg}, \")"\r
264 done\r
265 \r
266 I tried to address Austin's comment on IRC with=20\r
267 printf -v qarg %q "$arg"  -- that has problem if there is whitespace\r
268 in arg. maybe  printf -v qarg '%q ' "$arg" -- then there is always one\r
269 trailing ws (and spaces are always prefixed w/ \ -- (insert "foo\ bar")\r
270 just makes the ' ' disappear (which is not good...).\r
271 \r
272 maybe arg=3D${arg//\\/\\\\}; arg=3D${arg//"/\\"};=20\r
273 \r
274 ${parameter/pattern/string} -- Pattern substition in bash manual.\r
275 \r
276 \r
277 > +# End progn.\r
278 > +ELISP=3D"${ELISP})"\r
279 > +\r
280 > +if [ -n "$PRINT_ONLY" ]; then\r
281 > +    echo ${ELISP}\r
282 > +    exit 0\r
283 > +fi\r
284 > +\r
285 > +# Evaluate the progn.\r
286 > +emacsclient --eval "${ELISP}" &>/dev/null\r
287 \r
288 emacsclient --eval "${ELISP}" >/dev/null 2>&1\r
289 \r
290 (why do you want to redirect stdout & stderr to devnull ?)\r
291 \r
292 > +if [ $? -ne 0 ]; then\r
293 > +    echo "$0: emacsclient failed" >&2\r
294 > +    exit 1\r
295 > +fi\r
296 > --=20\r
297 > 1.9.0\r