3 # notmuch-emacs-mua - start composing a mail on the command line
5 # Copyright © 2014 Jani Nikula
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see http://www.gnu.org/licenses/ .
20 # Authors: Jani Nikula <jani@nikula.org>
31 EMACSCLIENT=${EMACSCLIENT-emacsclient}
37 # The crux of it all: construct an elisp progn and eval it.
38 ELISP="(prog1 'done (require 'notmuch) (notmuch-mua-new-mail)"
39 ELISP="${ELISP} (setq message-exit-actions (list #'save-buffers-kill-terminal))"
41 while getopts :s:c:b:i:hC opt; do
42 # Handle errors and long options.
45 echo "$0: short option -${OPTARG} requires an argument." >&2
50 if [ "${OPTARG}" != "-" ]; then
51 echo "$0: unknown short option -${OPTARG}." >&2
56 # Long options with arguments.
57 --subject=*|--to=*|--cc=*|--bcc=*|--body=*)
61 # Long options without arguments.
62 --help|--print|--no-window-system|--client)
65 echo "$0: unknown long option ${opt}, or argument mismatch." >&2
69 # getopts does not do this for what it considers errors.
70 OPTIND=$((OPTIND + 1))
75 OPTARG="${OPTARG-none}"
76 OPTARG="$(escape "${OPTARG}")"
80 exec man notmuch-emacs-mua
86 ELISP="${ELISP} (message-goto-subject) (insert \"${OPTARG}\")"
89 ELISP="${ELISP} (message-goto-to) (insert \"${OPTARG}, \")"
92 ELISP="${ELISP} (message-goto-cc) (insert \"${OPTARG}, \")"
95 ELISP="${ELISP} (message-goto-bcc) (insert \"${OPTARG}, \")"
98 ELISP="${ELISP} (message-goto-body) (cd \"${PWD}\") (insert-file \"${OPTARG}\")"
107 # We should never end up here.
108 echo "$0: internal error (option ${opt})." >&2
113 shift $((OPTIND - 1))
117 # Positional parameters.
119 arg="$(escape "${arg}")"
120 ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")"
126 if [ -n "$PRINT_ONLY" ]; then
131 if [ -n "$USE_EMACSCLIENT" ]; then
132 # Evaluate the progn.
133 exec ${EMACSCLIENT} ${CLIENT_TYPE} -a '' --eval "${ELISP}"
135 exec ${EMACS} --eval "${ELISP}"