Re: [PATCH] create .mailmap file (for git shortlog/blame)
[notmuch-archives.git] / a9 / 05454ff0c23f0393c208acd67ad202f5864a17
1 Return-Path: <too@guru-group.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 878E4431FCB\r
6         for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 09:54:15 -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 5oI+kXYniMRP for <notmuch@notmuchmail.org>;\r
16         Tue, 20 Jan 2015 09:54:12 -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 AB2F8431FC9\r
19         for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 09:54:11 -0800 (PST)\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)\r
21         id 317D21000F3; Tue, 20 Jan 2015 19:53:46 +0200 (EET)\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>\r
23 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org,\r
24         Jani Nikula <jani@nikula.org>\r
25 Subject: [DRAFT PATCH v2] modified notmuch-emacs-mua v2\r
26 Date: Tue, 20 Jan 2015 19:53:44 +0200\r
27 Message-Id: <1421776424-24304-1-git-send-email-tomi.ollila@iki.fi>\r
28 X-Mailer: git-send-email 2.0.0\r
29 In-Reply-To: <1421598115-4889-1-git-send-email-david@tethera.net>\r
30 References: <1421598115-4889-1-git-send-email-david@tethera.net>\r
31 MIME-Version: 1.0\r
32 Content-Type: text/plain; charset=UTF-8\r
33 Content-Transfer-Encoding: 8bit\r
34 Cc: tomi.ollila@iki.fi\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Tue, 20 Jan 2015 17:54:15 -0000\r
48 \r
49 This is second draft patch of (first being)\r
50 \r
51 id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi\r
52 \r
53 I saw potential problem with only supporting emacsclient(1) in\r
54 the version David sent:\r
55 id:1421598115-4889-1-git-send-email-david@tethera.net\r
56 \r
57 (no emacs server running and no tty -- new X client not started)\r
58 \r
59 therefore I started to modify that part -- and soon adding all features\r
60 I'd like to see there. As I expect some bikeshedding to continue I skip\r
61 doc update for the time being (to avoid unnecessary work), therefore\r
62 calling this as "draft patch".\r
63 \r
64 This implIments many of my first draft features:\r
65 \r
66 mailto: is handled if given as first argument (not yet all the nice stuff\r
67 Jameson suggested, we'll perhaps get there later...)\r
68 \r
69 --from option when sending non-mailto: way\r
70 \r
71 And, -nw (*) in a new way...\r
72 \r
73 The -i and --body are done as in initial Jani's version ( also as in\r
74 id:1421598115-4889-1-git-send-email-david@tethera.net )\r
75 \r
76 Also, --long SPC value is not implemented, format is --long=value\r
77 \r
78 In case emacsclient(1) is used and no --no-window-system, '-c' arg is\r
79 given to emacsclient like in the version David sent.\r
80 \r
81 (this means that if emacs is not running on X, user may get this message:\r
82  "emacsclient: could not get terminal name" -- we need to document user\r
83  to give -nw (--no-window-system) option then)\r
84 \r
85 Other "new" things:\r
86 \r
87 Option --bodytext to give body content from command line (not documented\r
88 yet, but I'll add privacy warning when updating NaMual page.\r
89 \r
90 Final cursor position goes based on last option given from command line,\r
91 unless to: or subject: is missing -- cursor is positioned after these\r
92 headers in this case.\r
93 \r
94 (*) -nw works so that the 'n' is given to getopts and it expects an\r
95 argument; the argument is checked being w (this means -nw and -n w are\r
96 accepted). this also gives interesting output when one attempts to use\r
97 plain '-n' (error message shows next arg concatenated into this or...\r
98 "./notmuch-emacs-mua: short option -n requires an argument." -- OK,\r
99 forgot to handle this special case at this time...)\r
100 \r
101 Anyway, I'd rather have -nw and some peculiarity than no -nw at all ;)\r
102 \r
103 Tomi\r
104 ---\r
105  notmuch-emacs-mua | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
106  1 file changed, 217 insertions(+)\r
107  create mode 100755 notmuch-emacs-mua\r
108 \r
109 diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua\r
110 new file mode 100755\r
111 index 000000000000..42275cd1a563\r
112 --- /dev/null\r
113 +++ b/notmuch-emacs-mua\r
114 @@ -0,0 +1,217 @@\r
115 +#!/usr/bin/env bash\r
116 +# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*-\r
117 +#\r
118 +# notmuch-emacs-mua - start composing a mail on the command line\r
119 +#\r
120 +# Copyright © 2014 Jani Nikula\r
121 +#\r
122 +# This program is free software: you can redistribute it and/or modify\r
123 +# it under the terms of the GNU General Public License as published by\r
124 +# the Free Software Foundation, either version 3 of the License, or\r
125 +# (at your option) any later version.\r
126 +#\r
127 +# This program is distributed in the hope that it will be useful,\r
128 +# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
129 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
130 +# GNU General Public License for more details.\r
131 +#\r
132 +# You should have received a copy of the GNU General Public License\r
133 +# along with this program.  If not, see http://www.gnu.org/licenses/ .\r
134 +#\r
135 +# Authors: Jani Nikula <jani@nikula.org>\r
136 +#          Tomi Ollila <tomi.ollila@iki.fi>\r
137 +#\r
138 +\r
139 +set -eu\r
140 +\r
141 +# Cannot use [[ ]] until we know we have bash.\r
142 +case ${BASH_VERSION-} in '')\r
143 +    echo "Not BASH!" >&2\r
144 +    exit 1\r
145 +esac\r
146 +\r
147 +# escape: "expand" '\' to '\\' & '"' to '\"'\r
148 +# Calling convention: escape -v var "$arg" (like in bash printf).\r
149 +escape ()\r
150 +{\r
151 +       local arg=${3//\\/\\\\}\r
152 +       eval $2='${arg//\"/\\\"}'\r
153 +}\r
154 +\r
155 +unset ALTERNATE_EDITOR\r
156 +exec_mua ()\r
157 +{\r
158 +    if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1\r
159 +    then\r
160 +       emacs=$EMACSCLIENT\r
161 +       # Close stdout in case no --no-window-system (and no --print).\r
162 +       test -n "$W$X" || exec >/dev/null\r
163 +       # W/ emacsclient, use '-c' in case no --no-window-system.\r
164 +       [[ -n $W ]] || W=-c\r
165 +    else\r
166 +       emacs=${EMACS:-emacs}\r
167 +    fi\r
168 +    ${X:-exec} "${emacs}" $W --eval "(prog1 'done $*)"\r
169 +    exit\r
170 +}\r
171 +\r
172 +X=  # This is chaged to 'echo' when --print is used.\r
173 +W=  # This is changed to '-nw' when --no-window-system is used.\r
174 +\r
175 +SUBJECT= TO= CC= BCC= BODY= FROM=\r
176 +\r
177 +unset message_goto # Final elisp function to execute, when defined.\r
178 +cddone=false\r
179 +\r
180 +# "Short circuit" mailto handling.\r
181 +case ${1-} in mailto:*)\r
182 +       oIFS=$IFS; IFS=\r
183 +       escape -v OPTARG "$*"\r
184 +       IFS=$oIFS\r
185 +       exec_mua "(require 'notmuch) (browse-url-mail \"$OPTARG\")"\r
186 +       exit\r
187 +esac\r
188 +\r
189 +while getopts :s:c:b:i:n: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=$1\r
198 +           if [[ ${OPTARG} != '-' ]]; 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=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*|--bodytext=*)\r
206 +                   OPTARG=${opt#--*=}\r
207 +                   opt=${opt%%=*}\r
208 +                   ;;\r
209 +               # Long options without arguments.\r
210 +               --help|--print|--no-window-system)\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=$((OPTIND + 1))\r
219 +           ;;\r
220 +    esac\r
221 +\r
222 +    escape -v OPTARG "${OPTARG}"\r
223 +\r
224 +    case "${opt}" in\r
225 +       --help|h)\r
226 +           exec man notmuch-emacs-mua\r
227 +           ;;\r
228 +       --from)\r
229 +           escape -v FROM "${OPTARG}"\r
230 +           ;;\r
231 +       --subject|s)\r
232 +           escape -v OPTARG "${OPTARG}"\r
233 +           SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG}\r
234 +           message_goto='(message-goto-subject)'\r
235 +           ;;\r
236 +       --to)\r
237 +           escape -v OPTARG "${OPTARG}"\r
238 +           TO=${TO:+$TO, }${OPTARG}\r
239 +           message_goto='(message-goto-to)'\r
240 +           ;;\r
241 +       --cc|c)\r
242 +           escape -v OPTARG "${OPTARG}"\r
243 +           CC=${CC:+$CC, }${OPTARG}\r
244 +           message_goto='(message-goto-cc)'\r
245 +           ;;\r
246 +       --bcc|b)\r
247 +           escape -v OPTARG "${OPTARG}"\r
248 +           BCC=${BCC:+$BCC, }${OPTARG}\r
249 +           message_goto='(message-goto-bcc)'\r
250 +           ;;\r
251 +       --body|i)\r
252 +           escape -v OPTARG "${OPTARG}"\r
253 +           if [[ ! -f ${OPTARG} ]]; then\r
254 +               echo "$0: '${OPTARG}': no such file" >&2\r
255 +               exit 1\r
256 +           fi\r
257 +           if [[ $cddone == 'false' ]]; then\r
258 +               BODY=${BODY}$'\n'"  (cd \"${PWD}\")"\r
259 +               cddone=true\r
260 +           fi\r
261 +           BODY=${BODY}$'\n'"  (insert-file \"${OPTARG}\")"\r
262 +           BODY=${BODY}$'\n'"  (if (/= (point) (line-beginning-position)) (insert \"\\n\"))"\r
263 +           unset message_goto\r
264 +           ;;\r
265 +       --bodytext)\r
266 +           escape -v OPTARG "${OPTARG}"\r
267 +           BODY=${BODY}$'\n'"  (insert \"${OPTARG}\\n\")"\r
268 +           unset message_goto\r
269 +           ;;\r
270 +       --no-window-system)\r
271 +           W=-nw\r
272 +           ;;\r
273 +       n) # -nw !!!\r
274 +           if [[ $OPTARG == 'w' ]]; then\r
275 +               W=-nw\r
276 +           else\r
277 +               echo "$0: unknown option -n${OPTARG}, or argument mismatch." >&2\r
278 +               exit 1\r
279 +           fi\r
280 +           ;;\r
281 +       --print)\r
282 +           X=echo\r
283 +           ;;\r
284 +       *)\r
285 +           # We should never end up here.\r
286 +           echo "$0: internal error (option ${opt})." >&2\r
287 +           exit 1\r
288 +           ;;\r
289 +    esac\r
290 +\r
291 +    shift $((OPTIND - 1))\r
292 +    OPTIND=1\r
293 +done\r
294 +\r
295 +# Positional parameters.\r
296 +for arg; do\r
297 +    escape -v arg "${arg}"\r
298 +    TO=${TO:+$TO, }${arg}\r
299 +    message_goto='(message-goto-to)'\r
300 +done\r
301 +\r
302 +# The newlines are here for --print (only) output.\r
303 +NL=$'\n'\r
304 +ELISP="\\r
305 +${CC:+$NL  (message-goto-cc) (insert \"$CC\")}\\r
306 +${BCC:+$NL  (message-goto-bcc) (insert \"$BCC\")}\\r
307 +${BODY:+$NL  (message-goto-body)$BODY}"\r
308 +\r
309 +if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]]\r
310 +then\r
311 +    exec_mua "(require 'notmuch) (notmuch-hello)"\r
312 +else\r
313 +    [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil\r
314 +\r
315 +    if [[ $SUBJECT == '' ]]; then\r
316 +       SUBJECT=nil\r
317 +       message_goto='(message-goto-subject)'\r
318 +    else\r
319 +       SUBJECT=\"$SUBJECT\"\r
320 +    fi\r
321 +    if [[ $TO == '' ]]; then\r
322 +       TO=nil\r
323 +       message_goto='(message-goto-to)'\r
324 +    else\r
325 +       TO=\"$TO\"\r
326 +    fi\r
327 +    exec_mua "(require 'notmuch)\r
328 +  (notmuch-mua-mail ${TO} ${SUBJECT}\r
329 +       ${OH} nil (notmuch-mua-get-switch-function))\\r
330 +${ELISP}${NL}  (set-buffer-modified-p nil)${message_goto+ $message_goto}"\r
331 +fi\r
332 -- \r
333 2.0.0\r
334 \r