From: Tomi Ollila Date: Sun, 29 Mar 2015 16:37:34 +0000 (+0300) Subject: [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d3155d96043be110ce0083b37a8246e096580da6;p=notmuch-archives.git [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape --- diff --git a/8a/06abd72ed9ce17efc0263f86e3cf22cd0735de b/8a/06abd72ed9ce17efc0263f86e3cf22cd0735de new file mode 100644 index 000000000..3cd5dd228 --- /dev/null +++ b/8a/06abd72ed9ce17efc0263f86e3cf22cd0735de @@ -0,0 +1,102 @@ +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 A8130431FBF + for ; Sun, 29 Mar 2015 09:38:02 -0700 (PDT) +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 O-gEmwEA-aLB for ; + Sun, 29 Mar 2015 09:37:59 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id CE23E431FAE + for ; Sun, 29 Mar 2015 09:37:58 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 8C7AB10009D; Sun, 29 Mar 2015 19:37:35 +0300 (EEST) +From: Tomi Ollila +To: notmuch@notmuchmail.org +Subject: [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash + '\' escape +Date: Sun, 29 Mar 2015 19:37:34 +0300 +Message-Id: <1427647054-7773-1-git-send-email-tomi.ollila@iki.fi> +X-Mailer: git-send-email 2.0.0 +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: Sun, 29 Mar 2015 16:38:02 -0000 + +Use the printf -v convention to give output variable as argument +to escape () function so no subshell needs to be executed for +escaping input. The '-v' option to escape () is just syntactic +sugar for better understanding. + +Also, backslash is now escaped with another backslash for emacs. This +ie especially important at the end of string. + +`echo` is no longer used to write escaped output -- it might interpret +the escapes itself. +--- + +This is first patch of the series to be continued -- next one would +already collide with Jani's work so it is left for the future... + + notmuch-emacs-mua | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/notmuch-emacs-mua b/notmuch-emacs-mua +index 13f67be..7971430 100755 +--- a/notmuch-emacs-mua ++++ b/notmuch-emacs-mua +@@ -22,9 +22,12 @@ + + set -eu + ++# escape: "expand" '\' as '\\' and '"' as '\"' ++# calling convention: escape -v var "$arg" (like in bash printf). + escape () + { +- echo "${1//\"/\\\"}" ++ local __escape_arg__=${3//\\/\\\\} ++ printf -v $2 '%s' "${__escape_arg__//\"/\\\"}" + } + + EMACS=${EMACS-emacs} +@@ -72,9 +75,7 @@ while getopts :s:c:b:i:h opt; do + ;; + esac + +- +- OPTARG="${OPTARG-none}" +- OPTARG="$(escape "${OPTARG}")" ++ escape -v OPTARG "${OPTARG-none}" + + case "${opt}" in + --help|h) +@@ -117,7 +118,7 @@ done + + # Positional parameters. + for arg; do +- arg="$(escape "${arg}")" ++ escape -v arg "${arg}" + ELISP="${ELISP} (message-goto-to) (insert \"${arg}, \")" + done + +-- +2.1.0 +