Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / b4 / 8b55aa0b7f45924616b782d22cd644058a57b8
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 71A2B431FAF\r
6         for <notmuch@notmuchmail.org>; Fri,  4 Jul 2014 10:36:52 -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 JWDgw+fWRNyH for <notmuch@notmuchmail.org>;\r
16         Fri,  4 Jul 2014 10:36:44 -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 9E3A8431FAE\r
19         for <notmuch@notmuchmail.org>; Fri,  4 Jul 2014 10:36:44 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 893F7100033;\r
22         Fri,  4 Jul 2014 20:36:38 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org,\r
25         "Jani Nikula" <jani@nikula.org>\r
26 Subject: Re: [PATCH] cli: add a tool for starting new message in the emacs ui\r
27 In-Reply-To: <1404244957-3671-1-git-send-email-david@tethera.net>\r
28 References: <1396799003-14855-1-git-send-email-jani@nikula.org>\r
29         <1404244957-3671-1-git-send-email-david@tethera.net>\r
30 User-Agent: Notmuch/0.18.1+25~gdaf4b6f (http://notmuchmail.org) Emacs/24.3.1\r
31         (x86_64-unknown-linux-gnu)\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
33         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
34         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
35 Date: Fri, 04 Jul 2014 20:36:38 +0300\r
36 Message-ID: <m2k37thvq1.fsf@guru.guru-group.fi>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain; charset=utf-8\r
39 Content-Transfer-Encoding: quoted-printable\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Fri, 04 Jul 2014 17:36:52 -0000\r
53 \r
54 On Tue, Jul 01 2014, David Bremner <david@tethera.net> wrote:\r
55 \r
56 > From: Jani Nikula <jani@nikula.org>\r
57 >\r
58 > Add a tool to start composing an email in the Notmuch Emacs UI with\r
59 > the specified subject, recipients, and message body.\r
60 > ---\r
61 >\r
62 > I added the necessary lines to conf.py to get the man pages built and\r
63 > installed\r
64 >\r
65 > I'd be happier with this if it could start emacs. I tried adding "-a\r
66 > ''" to the emacsclient invokation, but that doesn't quite work; the\r
67 > message-mode buffer is created in emacs but no frame is displayed. It\r
68 > could be a peculiarity of my emacs setup, of course.\r
69 \r
70 Ah, this -a '' is new acquaintance to me -- I tried -a emacs and that\r
71 obviously did not work. It would have been nicer is there is option\r
72 to just run emacs instead... (that's what I did in that mailto: patch).\r
73 \r
74 But there are plenty of other options, which needs at least be discussed,\r
75 is some tolerable subset can be agreed.\r
76 \r
77 First, this will "fail"\r
78 \r
79 $ emacs --daemon\r
80 $ emacsclient --eval '(progn (require 'notmuch) (notmuch-hello))'\r
81 \r
82 The window is "nowhere"\r
83 \r
84 $ emacsclient -nw can be used to "attach" to the emacs session and then one\r
85 can switch to the ``notmuch-hello`` -window\r
86 \r
87 -- but, someone may use such a supported setup using emacs/emacsclient\r
88 \r
89 This "problem" could be tacled so that if emasclient is to be used,\r
90 option (to be added) ``-nw`` is not given and stdout (or stderr) is=20\r
91 a tty (test -t 1 / test -t 2), after running emacsclient print\r
92 a message to the output with content something like:\r
93 \r
94 "connected to running emacs ... if the access to that emacs is hidden\r
95  you can run ``emacsclient -nw`` to find it..."\r
96 \r
97 Ok. Using emacsclient could be opportunistic -- in case using it fails\r
98 emacs(1) were used instead. The code checking this could be (*):\r
99 \r
100   unset ALTERNATE_EDITOR\r
101   if "${EMACSCLIENT:=3Demacsclient}" --eval t >/dev/null 2>&1\r
102   then  exec >/dev/null # (ok, use stderr for msg, or change this :D)\r
103         editor=3D$EMACSCLIENT\r
104   else  editor=3D${EMACS:-emacs}\r
105   fi\r
106 \r
107 (*) to save my time, copied from id:1404237992-9456-1-git-send-email-tomi.o=\r
108 llila@iki.fi\r
109 \r
110 When running emacs there is question whether to run it in background or\r
111 foreground. Probably the only always working option is to run in foreground\r
112 (unless adding an option) -- backgrounding would be possible only when all\r
113 of these apply:\r
114    1) user did not give ``-nw`` option\r
115    2) DISPLAY is not null or unset\r
116    3) emacs(1) does have X support!\r
117 \r
118 3 cannot be determined trivially.\r
119 \r
120 If backgrounding were supported the only way I see it can be done is:\r
121 \r
122 bg () {\r
123    perl -e 'use POSIX; exit if fork; POSIX::setsid(); exec @ARGV' "$@"\r
124 }\r
125 \r
126 Ok, then about the tool:\r
127 \r
128 >  doc/conf.py                    |   4 ++\r
129 >  doc/man1/notmuch-emacs-mua.rst |  50 +++++++++++++++++\r
130 >  notmuch-emacs-mua              | 122 +++++++++++++++++++++++++++++++++++=\r
131 ++++++\r
132 >  3 files changed, 176 insertions(+)\r
133 >  create mode 100644 doc/man1/notmuch-emacs-mua.rst\r
134 >  create mode 100755 notmuch-emacs-mua\r
135 >\r
136 > diff --git a/doc/conf.py b/doc/conf.py\r
137 > index 70ba1b8..8ee19f4 100644\r
138 > --- a/doc/conf.py\r
139 > +++ b/doc/conf.py\r
140 > @@ -74,6 +74,10 @@ man_pages =3D [\r
141 >          u'creates a plain-text dump of the tags of each message',\r
142 >          [u'Carl Worth and many others'], 1),\r
143 >=20=20\r
144 > +('man1/notmuch-emacs-mua','notmuch-emacs-mua',\r
145 > +        u'send mail with notmuch and emacs',\r
146 > +        [u'Carl Worth and many others'], 1),\r
147 > +\r
148 >  ('man5/notmuch-hooks','notmuch-hooks',\r
149 >          u'hooks for notmuch',\r
150 >          [u'Carl Worth and many others'], 5),\r
151 > diff --git a/doc/man1/notmuch-emacs-mua.rst b/doc/man1/notmuch-emacs-mua.=\r
152 rst\r
153 > new file mode 100644\r
154 > index 0000000..6e63818\r
155 > --- /dev/null\r
156 > +++ b/doc/man1/notmuch-emacs-mua.rst\r
157 > @@ -0,0 +1,50 @@\r
158 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
159 > +notmuch-emacs-mua\r
160 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
161 > +\r
162 > +SYNOPSIS\r
163 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
164 > +\r
165 > +**notmuch-emacs-mua** [options ...] [<to-address> ...]\r
166 > +\r
167 > +DESCRIPTION\r
168 > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\r
169 > +\r
170 > +Start composing an email in the Notmuch Emacs UI with the specified\r
171 > +subject, recipients, and message body.\r
172 > +\r
173 > +For **notmuch-emacs-mua** to work, you need **emacsclient** and an\r
174 > +already running Emacs with a server.\r
175 > +\r
176 > +Supported options for **notmuch-emacs-mua** include\r
177 > +\r
178 > +    ``-h, --help``\r
179 > +        Display help.\r
180 > +\r
181 > +    ``-s, --subject=3D``\ <subject>\r
182 > +        Specify the subject of the message.\r
183 > +\r
184 > +    ``--to=3D``\ <to-address>\r
185 > +        Specify a recipient (To).\r
186 > +\r
187 > +    ``-c, --cc=3D``\ <cc-address>\r
188 > +        Specify a carbon-copy (Cc) recipient.\r
189 > +\r
190 > +    ``-b, --bcc=3D``\ <bcc-address>\r
191 > +        Specify a blind-carbon-copy (Bcc) recipient.\r
192 > +\r
193 > +    ``-i, --body=3D``\ <file>\r
194 > +        Specify a file to include into the body of the message.\r
195 \r
196 -i option is consistent with mutt(1). mutt(1) does not have --body option.\r
197 therefore I'd suggest that --body takes the body content from command line\r
198 instead from file. If there is to be long-option along with -i it could\r
199 be --include or --insert..\r
200 \r
201 > +\r
202 > +    ``--print``\r
203 > +        Output the resulting elisp to stdout instead of evaluating it.\r
204 > +\r
205 > +The supported positional parameters and short options are a compatible\r
206 > +subset of the **mutt** MUA command-line options.\r
207 > +\r
208 > +Options may be specified multiple times.\r
209 > +\r
210 > +SEE ALSO\r
211 > +=3D=3D=3D=3D=3D=3D=3D=3D\r
212 > +\r
213 > +**notmuch(1)**, **emacsclient(1)**, **mutt(1)**\r
214 > diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
215 > new file mode 100755\r
216 > index 0000000..7f94271\r
217 > --- /dev/null\r
218 > +++ b/notmuch-emacs-mua\r
219 > @@ -0,0 +1,122 @@\r
220 > +#!/usr/bin/env bash\r
221 > +#\r
222 > +# notmuch-emacs-mua - start composing a mail on the command line\r
223 > +#\r
224 > +# Copyright =C2=A9 2014 Jani Nikula\r
225 > +#\r
226 > +# This program is free software: you can redistribute it and/or modify\r
227 > +# it under the terms of the GNU General Public License as published by\r
228 > +# the Free Software Foundation, either version 3 of the License, or\r
229 > +# (at your option) any later version.\r
230 > +#\r
231 > +# This program is distributed in the hope that it will be useful,\r
232 > +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
233 > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
234 > +# GNU General Public License for more details.\r
235 > +#\r
236 > +# You should have received a copy of the GNU General Public License\r
237 > +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
238 > +#\r
239 > +# Authors: Jani Nikula <jani@nikula.org>\r
240 > +#\r
241 > +\r
242 > +set -eu\r
243 > +\r
244 > +escape ()\r
245 > +{\r
246 > +    echo "${1//\"/\\\"}"\r
247 > +}\r
248 \r
249 This has 3 issues:\r
250 \r
251   1) This does not quote '\' which can be used to execute arbitrary code\r
252      (is that a feature)\r
253   2) echo may escape things differently in other bashes\r
254   3) running subshell just to this escape all args is not required,\r
255      there are bash builtins to do that during same process.\r
256 \r
257 If one wants to use function, escape -v var arg syntax could be deviced\r
258 with\r
259 \r
260 escape () {\r
261        local var=3D${3//\"/\\\"}; var=3D${var//\\/\\\\}\r
262        eval $2=3D\$var\r
263 }\r
264 \r
265 > +PRINT_ONLY=3D\r
266 > +\r
267 \r
268 \r
269 Tomi\r