unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape
@ 2015-03-29 16:37 Tomi Ollila
  2015-04-01  7:15 ` David Bremner
  2015-04-03 22:40 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Tomi Ollila @ 2015-03-29 16:37 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape
  2015-03-29 16:37 [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape Tomi Ollila
@ 2015-04-01  7:15 ` David Bremner
  2015-04-03 22:40 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2015-04-01  7:15 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> 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.
>

s/ie/is/, but I can amend that. Otherwise looks ok.

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape
  2015-03-29 16:37 [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape Tomi Ollila
  2015-04-01  7:15 ` David Bremner
@ 2015-04-03 22:40 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2015-04-03 22:40 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> 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.
>

pushed,

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-03 23:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-29 16:37 [PATCH] notmuch-emacs-mua: non-forking escape () usage with backslash '\' escape Tomi Ollila
2015-04-01  7:15 ` David Bremner
2015-04-03 22:40 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).