From: Tomi Ollila Date: Tue, 20 Jan 2015 17:53:44 +0000 (+0200) Subject: [DRAFT PATCH v2] modified notmuch-emacs-mua v2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=be31c1123e2613947150c85bb116ab8534afe392;p=notmuch-archives.git [DRAFT PATCH v2] modified notmuch-emacs-mua v2 --- diff --git a/a9/05454ff0c23f0393c208acd67ad202f5864a17 b/a9/05454ff0c23f0393c208acd67ad202f5864a17 new file mode 100644 index 000000000..4d51c496a --- /dev/null +++ b/a9/05454ff0c23f0393c208acd67ad202f5864a17 @@ -0,0 +1,334 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 878E4431FCB + for ; Tue, 20 Jan 2015 09:54:15 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.438 +X-Spam-Level: ** +X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 5oI+kXYniMRP for ; + Tue, 20 Jan 2015 09:54:12 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id AB2F8431FC9 + for ; Tue, 20 Jan 2015 09:54:11 -0800 (PST) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 317D21000F3; Tue, 20 Jan 2015 19:53:46 +0200 (EET) +From: Tomi Ollila +To: David Bremner , notmuch@notmuchmail.org, + Jani Nikula +Subject: [DRAFT PATCH v2] modified notmuch-emacs-mua v2 +Date: Tue, 20 Jan 2015 19:53:44 +0200 +Message-Id: <1421776424-24304-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1421598115-4889-1-git-send-email-david@tethera.net> +References: <1421598115-4889-1-git-send-email-david@tethera.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Cc: tomi.ollila@iki.fi +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 20 Jan 2015 17:54:15 -0000 + +This is second draft patch of (first being) + +id:1405026779-29966-1-git-send-email-tomi.ollila@iki.fi + +I saw potential problem with only supporting emacsclient(1) in +the version David sent: +id:1421598115-4889-1-git-send-email-david@tethera.net + +(no emacs server running and no tty -- new X client not started) + +therefore I started to modify that part -- and soon adding all features +I'd like to see there. As I expect some bikeshedding to continue I skip +doc update for the time being (to avoid unnecessary work), therefore +calling this as "draft patch". + +This implIments many of my first draft features: + +mailto: is handled if given as first argument (not yet all the nice stuff +Jameson suggested, we'll perhaps get there later...) + +--from option when sending non-mailto: way + +And, -nw (*) in a new way... + +The -i and --body are done as in initial Jani's version ( also as in +id:1421598115-4889-1-git-send-email-david@tethera.net ) + +Also, --long SPC value is not implemented, format is --long=value + +In case emacsclient(1) is used and no --no-window-system, '-c' arg is +given to emacsclient like in the version David sent. + +(this means that if emacs is not running on X, user may get this message: + "emacsclient: could not get terminal name" -- we need to document user + to give -nw (--no-window-system) option then) + +Other "new" things: + +Option --bodytext to give body content from command line (not documented +yet, but I'll add privacy warning when updating NaMual page. + +Final cursor position goes based on last option given from command line, +unless to: or subject: is missing -- cursor is positioned after these +headers in this case. + +(*) -nw works so that the 'n' is given to getopts and it expects an +argument; the argument is checked being w (this means -nw and -n w are +accepted). this also gives interesting output when one attempts to use +plain '-n' (error message shows next arg concatenated into this or... +"./notmuch-emacs-mua: short option -n requires an argument." -- OK, +forgot to handle this special case at this time...) + +Anyway, I'd rather have -nw and some peculiarity than no -nw at all ;) + +Tomi +--- + notmuch-emacs-mua | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 217 insertions(+) + create mode 100755 notmuch-emacs-mua + +diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua +new file mode 100755 +index 000000000000..42275cd1a563 +--- /dev/null ++++ b/notmuch-emacs-mua +@@ -0,0 +1,217 @@ ++#!/usr/bin/env bash ++# -*- mode: shell-script; sh-basic-offset: 4; tab-width: 8 -*- ++# ++# notmuch-emacs-mua - start composing a mail on the command line ++# ++# Copyright © 2014 Jani Nikula ++# ++# This program is free software: you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation, either version 3 of the License, or ++# (at your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see http://www.gnu.org/licenses/ . ++# ++# Authors: Jani Nikula ++# Tomi Ollila ++# ++ ++set -eu ++ ++# Cannot use [[ ]] until we know we have bash. ++case ${BASH_VERSION-} in '') ++ echo "Not BASH!" >&2 ++ exit 1 ++esac ++ ++# escape: "expand" '\' to '\\' & '"' to '\"' ++# Calling convention: escape -v var "$arg" (like in bash printf). ++escape () ++{ ++ local arg=${3//\\/\\\\} ++ eval $2='${arg//\"/\\\"}' ++} ++ ++unset ALTERNATE_EDITOR ++exec_mua () ++{ ++ if "${EMACSCLIENT:=emacsclient}" --eval t >/dev/null 2>&1 ++ then ++ emacs=$EMACSCLIENT ++ # Close stdout in case no --no-window-system (and no --print). ++ test -n "$W$X" || exec >/dev/null ++ # W/ emacsclient, use '-c' in case no --no-window-system. ++ [[ -n $W ]] || W=-c ++ else ++ emacs=${EMACS:-emacs} ++ fi ++ ${X:-exec} "${emacs}" $W --eval "(prog1 'done $*)" ++ exit ++} ++ ++X= # This is chaged to 'echo' when --print is used. ++W= # This is changed to '-nw' when --no-window-system is used. ++ ++SUBJECT= TO= CC= BCC= BODY= FROM= ++ ++unset message_goto # Final elisp function to execute, when defined. ++cddone=false ++ ++# "Short circuit" mailto handling. ++case ${1-} in mailto:*) ++ oIFS=$IFS; IFS= ++ escape -v OPTARG "$*" ++ IFS=$oIFS ++ exec_mua "(require 'notmuch) (browse-url-mail \"$OPTARG\")" ++ exit ++esac ++ ++while getopts :s:c:b:i:n:h opt; do ++ # Handle errors and long options. ++ case "${opt}" in ++ :) ++ echo "$0: short option -${OPTARG} requires an argument." >&2 ++ exit 1 ++ ;; ++ \?) ++ opt=$1 ++ if [[ ${OPTARG} != '-' ]]; then ++ echo "$0: unknown short option -${OPTARG}." >&2 ++ exit 1 ++ fi ++ ++ case "${opt}" in ++ # Long options with arguments. ++ --subject=*|--to=*|--cc=*|--bcc=*|--body=*|--from=*|--bodytext=*) ++ OPTARG=${opt#--*=} ++ opt=${opt%%=*} ++ ;; ++ # Long options without arguments. ++ --help|--print|--no-window-system) ++ ;; ++ *) ++ echo "$0: unknown long option ${opt}, or argument mismatch." >&2 ++ exit 1 ++ ;; ++ esac ++ # Getopts does not do this for what it considers errors. ++ OPTIND=$((OPTIND + 1)) ++ ;; ++ esac ++ ++ escape -v OPTARG "${OPTARG}" ++ ++ case "${opt}" in ++ --help|h) ++ exec man notmuch-emacs-mua ++ ;; ++ --from) ++ escape -v FROM "${OPTARG}" ++ ;; ++ --subject|s) ++ escape -v OPTARG "${OPTARG}" ++ SUBJECT=${SUBJECT:+$SUBJECT }${OPTARG} ++ message_goto='(message-goto-subject)' ++ ;; ++ --to) ++ escape -v OPTARG "${OPTARG}" ++ TO=${TO:+$TO, }${OPTARG} ++ message_goto='(message-goto-to)' ++ ;; ++ --cc|c) ++ escape -v OPTARG "${OPTARG}" ++ CC=${CC:+$CC, }${OPTARG} ++ message_goto='(message-goto-cc)' ++ ;; ++ --bcc|b) ++ escape -v OPTARG "${OPTARG}" ++ BCC=${BCC:+$BCC, }${OPTARG} ++ message_goto='(message-goto-bcc)' ++ ;; ++ --body|i) ++ escape -v OPTARG "${OPTARG}" ++ if [[ ! -f ${OPTARG} ]]; then ++ echo "$0: '${OPTARG}': no such file" >&2 ++ exit 1 ++ fi ++ if [[ $cddone == 'false' ]]; then ++ BODY=${BODY}$'\n'" (cd \"${PWD}\")" ++ cddone=true ++ fi ++ BODY=${BODY}$'\n'" (insert-file \"${OPTARG}\")" ++ BODY=${BODY}$'\n'" (if (/= (point) (line-beginning-position)) (insert \"\\n\"))" ++ unset message_goto ++ ;; ++ --bodytext) ++ escape -v OPTARG "${OPTARG}" ++ BODY=${BODY}$'\n'" (insert \"${OPTARG}\\n\")" ++ unset message_goto ++ ;; ++ --no-window-system) ++ W=-nw ++ ;; ++ n) # -nw !!! ++ if [[ $OPTARG == 'w' ]]; then ++ W=-nw ++ else ++ echo "$0: unknown option -n${OPTARG}, or argument mismatch." >&2 ++ exit 1 ++ fi ++ ;; ++ --print) ++ X=echo ++ ;; ++ *) ++ # We should never end up here. ++ echo "$0: internal error (option ${opt})." >&2 ++ exit 1 ++ ;; ++ esac ++ ++ shift $((OPTIND - 1)) ++ OPTIND=1 ++done ++ ++# Positional parameters. ++for arg; do ++ escape -v arg "${arg}" ++ TO=${TO:+$TO, }${arg} ++ message_goto='(message-goto-to)' ++done ++ ++# The newlines are here for --print (only) output. ++NL=$'\n' ++ELISP="\ ++${CC:+$NL (message-goto-cc) (insert \"$CC\")}\ ++${BCC:+$NL (message-goto-bcc) (insert \"$BCC\")}\ ++${BODY:+$NL (message-goto-body)$BODY}" ++ ++if [[ $TO == '' && $SUBJECT == '' && $ELISP == '' ]] ++then ++ exec_mua "(require 'notmuch) (notmuch-hello)" ++else ++ [[ $FROM != '' ]] && OH="(list (cons 'From \"$FROM\"))" || OH=nil ++ ++ if [[ $SUBJECT == '' ]]; then ++ SUBJECT=nil ++ message_goto='(message-goto-subject)' ++ else ++ SUBJECT=\"$SUBJECT\" ++ fi ++ if [[ $TO == '' ]]; then ++ TO=nil ++ message_goto='(message-goto-to)' ++ else ++ TO=\"$TO\" ++ fi ++ exec_mua "(require 'notmuch) ++ (notmuch-mua-mail ${TO} ${SUBJECT} ++ ${OH} nil (notmuch-mua-get-switch-function))\ ++${ELISP}${NL} (set-buffer-modified-p nil)${message_goto+ $message_goto}" ++fi +-- +2.0.0 +