From: Achim Gratz <Stromeko@nexgo.de>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-shell (was: 2 Org tests failing)
Date: Sun, 22 Jun 2014 10:35:31 +0200 [thread overview]
Message-ID: <87vbrt8hpo.fsf_-_@Rainer.invalid> (raw)
In-Reply-To: 877g4cacn9.fsf@Rainer.invalid
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
Achim Gratz writes:
> Sebastien Vauban writes:
>> I just ran `make test' and got the same error for
>> `ob-shell/bash-uses-assoc-arrays'.
>
> Yes, that's because not all versions of bash that have associative
> arrays can parse the bizarre quoting style that goes through a
> sub-process and here-document that is used to fill in the parameters.
Here's a patch that implements the suggestion and tested to work
correctly with Cygwin and Linux.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-shell-stratify-shell-variable-quoting.patch --]
[-- Type: text/x-patch, Size: 3322 bytes --]
From a79aff65d562e59ed4e01e550224eb96a665c1ae Mon Sep 17 00:00:00 2001
From: Achim Gratz <Stromeko@Stromeko.DE>
Date: Thu, 19 Jun 2014 21:23:28 +0200
Subject: [PATCH] ob-shell: stratify shell variable quoting
* lisp/ob-shell.el: Remove unused defcustom
`org-babel-sh-var-quote-fmt'.
(org-babel-variable-assignments:bash_array):
(org-babel-variable-assignments:bash_assoc): Remove superfluous
`mapcar' and double quotes around parameters.
(org-babel-sh-var-to-sh): Single-quote the whole string and escape
all single quotes in the original string.
---
lisp/ob-shell.el | 42 ++++++++++++++++++------------------------
1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 474a8f2..7d87026 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -45,12 +45,6 @@ (defcustom org-babel-sh-command shell-file-name
:group 'org-babel
:type 'string)
-(defcustom org-babel-sh-var-quote-fmt
- "$(cat <<'BABEL_TABLE'\n%s\nBABEL_TABLE\n)"
- "Format string used to escape variables when passed to shell scripts."
- :group 'org-babel
- :type 'string)
-
(defcustom org-babel-shell-names
'("sh" "bash" "csh" "ash" "dash" "ksh" "mksh" "posh")
"List of names of shell supported by babel shell code blocks."
@@ -113,28 +107,26 @@ (defun org-babel-variable-assignments:sh-generic
(defun org-babel-variable-assignments:bash_array
(varname values &optional sep hline)
"Returns a list of statements declaring the values as a bash array."
- (format "unset %s\ndeclare -a %s=( \"%s\" )"
- varname varname
- (mapconcat 'identity
- (mapcar
- (lambda (value) (org-babel-sh-var-to-sh value sep hline))
- values)
- "\" \"")))
+ (format "unset %s\ndeclare -a %s=( %s )"
+ varname varname
+ (mapconcat
+ (lambda (value) (org-babel-sh-var-to-sh value sep hline))
+ values
+ " ")))
(defun org-babel-variable-assignments:bash_assoc
(varname values &optional sep hline)
"Returns a list of statements declaring the values as bash associative array."
(format "unset %s\ndeclare -A %s\n%s"
varname varname
- (mapconcat 'identity
- (mapcar
- (lambda (items)
- (format "%s[\"%s\"]=%s"
- varname
- (org-babel-sh-var-to-sh (car items) sep hline)
- (org-babel-sh-var-to-sh (cdr items) sep hline)))
- values)
- "\n")))
+ (mapconcat
+ (lambda (items)
+ (format "%s[%s]=%s"
+ varname
+ (org-babel-sh-var-to-sh (car items) sep hline)
+ (org-babel-sh-var-to-sh (cdr items) sep hline)))
+ values
+ "\n")))
(defun org-babel-variable-assignments:bash (varname values &optional sep hline)
"Represents the parameters as useful Bash shell variables."
@@ -163,8 +155,10 @@ (defun org-babel-sh-var-to-sh (var &optional sep hline)
"Convert an elisp value to a shell variable.
Convert an elisp var into a string of shell commands specifying a
var of the same value."
- (format org-babel-sh-var-quote-fmt
- (org-babel-sh-var-to-string var sep hline)))
+ (concat "'" (replace-regexp-in-string
+ "'" "'\"'\"'"
+ (org-babel-sh-var-to-string var sep hline))
+ "'"))
(defun org-babel-sh-var-to-string (var &optional sep hline)
"Convert an elisp value to a string."
--
2.0.0
[-- Attachment #3: Type: text/plain, Size: 201 bytes --]
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs
next prev parent reply other threads:[~2014-06-22 8:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-22 10:03 2 Org tests failing Sebastien Vauban
2014-05-22 10:48 ` Bastien
[not found] ` <87tx8iks22.fsf-E3UqQZAQFPqWIDz0JBNUog@public.gmane.org>
2014-06-18 14:55 ` Sebastien Vauban
2014-06-18 21:49 ` Achim Gratz
2014-06-19 8:36 ` Sebastien Vauban
2014-06-19 9:04 ` Sebastien Vauban
2014-06-19 9:08 ` Sebastien Vauban
2014-06-19 20:05 ` Achim Gratz
2014-06-22 8:35 ` Achim Gratz [this message]
2014-06-22 12:50 ` [PATCH] ob-shell Eric Schulte
2014-06-23 6:26 ` Pascal Fleury
2014-06-23 17:20 ` Achim Gratz
2014-06-23 20:02 ` Achim Gratz
2014-07-24 7:38 ` Alan Schmitt
2014-08-04 11:56 ` Eric Schulte
2014-08-04 19:48 ` Achim Gratz
2014-08-13 13:12 ` Alan Schmitt
2014-08-13 13:20 ` Pascal Fleury
2014-08-13 13:29 ` Alan Schmitt
2014-08-22 8:52 ` Pascal Fleury
2014-08-22 13:08 ` Pascal Fleury
2014-08-22 18:16 ` Achim Gratz
2015-01-21 22:58 ` Pascal Fleury
2015-01-25 11:41 ` Achim Gratz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vbrt8hpo.fsf_-_@Rainer.invalid \
--to=stromeko@nexgo.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.