Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 37 / 663ed8d765d22fa75c5004e4ff621e93af4922
1 Return-Path: <jani@nikula.org>\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 2DD90431FC2\r
6         for <notmuch@notmuchmail.org>; Wed, 29 Oct 2014 13:14:20 -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.7\r
10 X-Spam-Level: \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 S-lI3oQpt4J5 for <notmuch@notmuchmail.org>;\r
16         Wed, 29 Oct 2014 13:14:12 -0700 (PDT)\r
17 Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com\r
18         [209.85.212.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 02B06431FC7\r
21         for <notmuch@notmuchmail.org>; Wed, 29 Oct 2014 13:14:11 -0700 (PDT)\r
22 Received: by mail-wi0-f175.google.com with SMTP id ex7so2741219wid.14\r
23         for <notmuch@notmuchmail.org>; Wed, 29 Oct 2014 13:14:10 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:cc:subject:in-reply-to:references\r
27         :user-agent:date:message-id:mime-version:content-type\r
28         :content-transfer-encoding;\r
29         bh=3Ybmdmgr6oQVtB19jfX+kqNCZvOl5SFva54kFW337fc=;\r
30         b=jVUK5WGYdXkNRL4R4W+Gak4oicDLULmAfgP11YqIvUIzxZJEkZBrE7R/C4ZwpGGyJa\r
31         LIfkhPQW6UjlsCgbsfogaW5Boc14P/RbbAPWkcSp+D2QY/sE0jkysFHNMKvhpFVP2o71\r
32         C0WKvHldyXS63Pcdsi8G37jYOM5Mi2Ouw9jlIhps1i9Kv+2Jo3KK+RYzJ/4FXMJojm8z\r
33         whDoO2ZF2iReDS6/pbojQDwOjPzRHiIoiTWiMX2xm9KbpsOV6G9JrLLnaaZQO7uRi2y0\r
34         C+iLQkQ3y1S09/RDeE0qsxoYxnrIBvgwcog3YmHEcr5/dtdjo/FYZp3NDtlKy7lzBhUA\r
35         NX8Q==\r
36 X-Gm-Message-State:\r
37  ALoCoQmMljJY+DG6IC0DZITT+P91K+Xse2ujXMo2Sx8T9I126KWRB6QSoCEJxDvAJF1Vxoe+ViiK\r
38 X-Received: by 10.180.79.38 with SMTP id g6mr14813444wix.42.1414613650477;\r
39         Wed, 29 Oct 2014 13:14:10 -0700 (PDT)\r
40 Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi.\r
41         [88.195.109.48]) by mx.google.com with ESMTPSA id\r
42         ko10sm6274874wjb.48.2014.10.29.13.14.09 for <multiple recipients>\r
43         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
44         Wed, 29 Oct 2014 13:14:09 -0700 (PDT)\r
45 From: Jani Nikula <jani@nikula.org>\r
46 To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org,\r
47         david@tethera.net, jrollins@finestructure.net\r
48 Subject: Re: [DRAFT PATCH] modified notmuch-emacs-mua\r
49 In-Reply-To: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>\r
50 References: <1405026779-29966-1-git-send-email-tomi.ollila@iki.fi>\r
51 User-Agent: Notmuch/0.18.2+148~g4214adf (http://notmuchmail.org) Emacs/24.3.1\r
52         (x86_64-pc-linux-gnu)\r
53 Date: Wed, 29 Oct 2014 22:14:07 +0200\r
54 Message-ID: <871tpq1vn4.fsf@nikula.org>\r
55 MIME-Version: 1.0\r
56 Content-Type: text/plain; charset=utf-8\r
57 Content-Transfer-Encoding: quoted-printable\r
58 Cc: tomi.ollila@iki.fi\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Wed, 29 Oct 2014 20:14:20 -0000\r
72 \r
73 On Fri, 11 Jul 2014, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
74 > Highlights:\r
75 >\r
76 > * notmuch-emacs-mua without arguments runs (notmuch-hello)\r
77 >\r
78 > * runs emacs(1) in case emacsclient(1) fails to connect to running emacs\r
79 >\r
80 > * takes -nw option\r
81 >\r
82 > * handles mailto:\r
83 >\r
84 > * --from option when sending non-mailto: way\r
85 >\r
86 > * -i includes file --body[=3D ]string inserts string\r
87 > ---\r
88 >  notmuch-emacs-mua | 200 ++++++++++++++++++++++++++++++++++++++++++++++++=\r
89 ++++++\r
90 >  1 file changed, 200 insertions(+)\r
91 >  create mode 100755 notmuch-emacs-mua\r
92 >\r
93 > diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
94 > new file mode 100755\r
95 > index 0000000..b1696f7\r
96 > --- /dev/null\r
97 > +++ b/notmuch-emacs-mua\r
98 > @@ -0,0 +1,200 @@\r
99 > +#!/usr/bin/env bash\r
100 > +# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*-\r
101 > +#\r
102 > +# notmuch-emacs-mua - start composing a mail on the command line\r
103 > +#\r
104 > +# Copyright =C2=A9 2014 Jani Nikula\r
105 > +#\r
106 > +# This program is free software: you can redistribute it and/or modify\r
107 > +# it under the terms of the GNU General Public License as published by\r
108 > +# the Free Software Foundation, either version 3 of the License, or\r
109 > +# (at your option) any later version.\r
110 > +#\r
111 > +# This program is distributed in the hope that it will be useful,\r
112 > +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
113 > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
114 > +# GNU General Public License for more details.\r
115 > +#\r
116 > +# You should have received a copy of the GNU General Public License\r
117 > +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
118 > +#\r
119 > +# Authors: Jani Nikula <jani@nikula.org>\r
120 > +#          Tomi Ollila <tomi.ollila@iki.fi>\r
121 > +#\r
122 > +\r
123 > +set -eu\r
124 > +\r
125 > +# "expand" '\' to '\\' & '"' to '\"'\r
126 > +escape_optarg ()\r
127 > +{\r
128 > +    OPTARG=3D${OPTARG//\\/\\\\}; OPTARG=3D${OPTARG//\"/\\\"}\r
129 > +}\r
130 > +\r
131 > +# ditto, in case there is '\n' sequence in the source, otherwise\r
132 > +# "expand" only trailing '\'s to '\\'s\r
133 > +escape_body_optarg ()\r
134 > +{\r
135 > +    case ${OPTARG} in\r
136 > +     *'\"'*) OPTARG=3D${OPTARG//\\/\\\\} ;;\r
137 > +     *'\') OPTARG=3D$( printf %s "${OPTARG}" | sed 's/\(\\*\)$/\1\1/' )\r
138 > +    esac\r
139 > +    OPTARG=3D${OPTARG//\"/\\\"}\r
140 > +}\r
141 > +\r
142 > +unset ALTERNATE_EDITOR\r
143 > +exec_mua ()\r
144 > +{\r
145 > +    if "${EMACSCLIENT:=3Demacsclient}" --eval t >/dev/null 2>&1\r
146 > +    then\r
147 > +     emacs=3D$EMACSCLIENT\r
148 > +     # close stdout in case no -nw (and no --print)\r
149 > +     test -n "$W$X" || exec >/dev/null\r
150 > +    else\r
151 > +     emacs=3D${EMACS:-emacs}\r
152 > +    fi\r
153 > +    ${X:-exec} "$emacs" $W --eval "$*"\r
154 > +    exit\r
155 > +    ${X:-exec "$emacs" $W --eval} "$*"\r
156 > +}\r
157 > +\r
158 > +X=3D\r
159 > +W=3D\r
160 > +\r
161 > +SUBJECT=3D TO=3D CC=3D BCC=3D BODY=3D FROM=3D IB=3D\r
162 > +\r
163 > +while\r
164 > +    # first, handle "long" options which cannot be handled by getopts\r
165 > +    case ${1-} in\r
166 > +     -nw)\r
167 > +         W=3D-nw\r
168 > +         shift\r
169 > +         continue\r
170 > +         ;;\r
171 \r
172 How about generalizing this into letting the user pass arguments after a\r
173 "--" separator to emacs(client)? Would that work?\r
174 \r
175 Alternatively, why support -nw which is neither part of the mutt\r
176 interface I was originally aiming at emulating nor conforms to notmuch\r
177 style? Just go with --nw or the more verbose --no-window-system (which\r
178 is also compatible with emacs).\r
179 \r
180 > +     mailto:*)\r
181 > +         oIFS=3D$IFS; IFS=3D; OPTARG=3D"$*" IFS=3D$oIFS\r
182 > +         escape_optarg\r
183 > +         exec_mua "(progn (require 'notmuch) (browse-url-mail \"$OPTARG\"))"\r
184 > +         exit\r
185 > +    esac\r
186 \r
187 Why does mailto: need to be handled here? I think you could either make\r
188 the usage have a special mailto: case where you only have mailto: at $1,\r
189 or you handle mailto: as a positional parameter at the end.\r
190 \r
191 With these, you could drop this one extra case here, and go back to the\r
192 more natural "while getopts" argument parsing loop.\r
193 \r
194 > +\r
195 > +    getopts :s:c:b:i:h opt\r
196 > +do\r
197 > +    # Handle errors and long options.\r
198 > +    case ${opt} in\r
199 > +     :)\r
200 > +         echo "$0: short option '-${OPTARG}' requires an argument." >&2\r
201 > +         exit 1\r
202 > +         ;;\r
203 > +     \?)\r
204 > +         opt=3D$1\r
205 > +         if [[ ${OPTARG} !=3D '-' ]]; then\r
206 > +             echo "$0: unknown short option '-${OPTARG}'." >&2\r
207 > +             exit 1\r
208 > +         fi\r
209 > +\r
210 > +         case ${opt} in\r
211 > +             # Long options with arguments.\r
212 > +             --subject=3D*|--to=3D*|--cc=3D*|--bcc=3D*|--body=3D*|--from=3D*)\r
213 > +                 OPTARG=3D${opt#--*=3D}\r
214 > +                 opt=3D${opt%%=3D*}\r
215 > +                 ;;\r
216 > +             # Long options with argument in next arg.\r
217 > +             --subject  |--to  |--cc  |--bcc  |--body  |--from  )\r
218 \r
219 This may be git-ish, but I don't think we should support this in\r
220 notmuch.\r
221 \r
222 > +                 if [[ $# < 2 ]]; then\r
223 > +                     echo "$0: option '${opt}' requires an argument." >&2\r
224 > +                     exit 1\r
225 > +                 fi\r
226 > +                 OPTARG=3D$2\r
227 > +                 OPTIND=3D$((OPTIND + 1))\r
228 > +                 ;;\r
229 > +             # Long options without arguments.\r
230 > +             --help|--nw|--print)\r
231 > +                 ;;\r
232 > +             *)\r
233 > +                 echo "$0: unknown long option '${opt}', or argument mismatch." >&2\r
234 > +                 exit 1\r
235 > +                 ;;\r
236 > +         esac\r
237 > +         # getopts does not do this for what it considers errors.\r
238 > +         OPTIND=3D$((OPTIND + 1))\r
239 > +         ;;\r
240 > +    esac\r
241 > +\r
242 > +    case ${opt} in\r
243 > +     --help|h)\r
244 > +         exec man notmuch-emacs-mua\r
245 > +         ;;\r
246 > +     --from)\r
247 > +         escape_optarg\r
248 > +         FROM=3D${OPTARG}\r
249 > +         ;;\r
250 > +     --subject|s)\r
251 > +         escape_optarg\r
252 > +         SUBJECT=3D${SUBJECT:+$SUBJECT }${OPTARG}\r
253 > +         ;;\r
254 > +     --to)\r
255 > +         escape_optarg\r
256 > +         TO=3D${TO:+$TO, }${OPTARG}\r
257 > +         ;;\r
258 > +     --cc|c)\r
259 > +         escape_optarg\r
260 > +         CC=3D${CC:+$CC, }${OPTARG}\r
261 > +         ;;\r
262 > +     --bcc|b)\r
263 > +         escape_optarg\r
264 > +         BCC=3D${BCC:+$BCC, }${OPTARG}\r
265 > +         ;;\r
266 > +     i)\r
267 > +         escape_optarg\r
268 > +         if [[ ! -f ${OPTARG} ]]; then\r
269 > +             echo "$0: '${OPTARG}': no such file" >&2\r
270 > +             exit 1\r
271 > +         fi\r
272 > +         IB=3D${IB}$'\n'"  (insert-file \"${OPTARG}\")"\r
273 \r
274 This needs the (cd \"${PWD}\") bit because --body given here may be\r
275 relative to the script, while emacs likely has a totally different cwd.\r
276 \r
277 > +         IB=3D${IB}$'\n'"  (if /=3D (point) (line-beginning-position) (inser=\r
278 t \"\\n\"))"\r
279 > +         ;;\r
280 > +     --body)\r
281 > +         escape_body_optarg\r
282 > +         IB=3D${IB}$'\n'"  (insert \"${OPTARG}\\n\")"\r
283 \r
284 Why should --body and -i be different?\r
285 \r
286 > +         ;;\r
287 > +     --nw)\r
288 > +         W=3D-nw\r
289 > +         ;;\r
290 > +     --print)\r
291 > +         X=3Decho\r
292 > +         ;;\r
293 > +     *)\r
294 > +         # We should never end up here.\r
295 > +         echo "$0: internal error (option '${opt}')." >&2\r
296 > +         exit 1\r
297 > +         ;;\r
298 > +    esac\r
299 > +\r
300 > +    shift $((OPTIND - 1))\r
301 > +    OPTIND=3D1\r
302 > +done\r
303 > +\r
304 > +# Positional parameters.\r
305 > +for arg; do\r
306 > +    arg=3D${arg//\\/\\\\}; arg=3D${arg//\"/\\\"}\r
307 > +    TO=3D${TO:+$TO, }${arg}\r
308 > +done\r
309 > +\r
310 > +NL=3D$'\n'\r
311 > +ELISP=3D"\\r
312 > +${CC:+$NL  (message-goto-cc) (insert \"$CC\")}\\r
313 > +${BCC:+$NL  (message-goto-bcc) (insert \"$BCC\")}\\r
314 > +${IB:+$NL  (message-goto-body)$IB}"\r
315 > +\r
316 > +if [[ $TO =3D=3D '' && $SUBJECT =3D=3D '' && $ELISP =3D=3D '' ]]\r
317 > +then\r
318 > +    exec_mua "(progn (require 'notmuch) (notmuch-hello))"\r
319 > +else\r
320 > +    [[ $FROM !=3D '' ]] && OH=3D"(list (cons 'From \"$FROM\"))" || OH=3D=\r
321 nil\r
322 > +    [[ $TO !=3D '' ]] && TO=3D\"$TO\" || TO=3Dnil\r
323 > +    [[ $SUBJECT !=3D '' ]] && SUBJECT=3D\"$SUBJECT\" || SUBJECT=3Dnil\r
324 > +    exec_mua "$NL(progn (require 'notmuch)\r
325 > +  (notmuch-mua-mail $TO $SUBJECT\r
326 > +     $OH nil (notmuch-mua-get-switch-function))\\r
327 > +$ELISP$NL  (set-buffer-modified-p nil) (message-goto-to))"\r
328 \r
329 I think the newlines with $NL hurt readability in the script more than\r
330 they help readability in the output... which is generally interpreted by\r
331 emacs which doesn't really care about the newlines! ;)\r
332 \r
333 BR,\r
334 Jani.\r
335 \r
336 \r
337 > +fi\r
338 > --=20\r
339 > 1.9.0\r