From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: combine-and-quote-strings
Date: Sun, 12 Apr 2015 18:15:14 +0200 [thread overview]
Message-ID: <87twwlxqzx.fsf@debian.uxu> (raw)
In-Reply-To: 87bnitpqdg.fsf@kuiper.lan.informatimago.com
"Pascal J. Bourguignon" <pjb@informatimago.com>
writes:
> Philipp Stephani <p.stephani2@gmail.com> writes:
>
>> ... the Lisp manual explains (in the section "Shell
>> Arguments"): The following two functions are useful
>> for combining a list of individual command-line
>> argument strings into a single string, This is
>> about combine-and-quote-strings (and
>> split-strings-and-unquote). However,
>> combine-and-quote-strings can't really be used for
>> that purpose because it doesn't quote many shell
>> metacharacters. The correct way to shell-quote
>> a list of arguments is (mapconcat
>> #'shell-quote-argument ARGS " ") Should
>> combine-and-quote-strings be reimplemented in terms
>> of shell-quote-argument? The current definition
>> doesn't seem to be optimal for shell quoting
>> because many inputs aren't properly quoted. Or is
>> combine-and-quote-strings not intended for shell
>> quoting at all and the documentation should
>> be adapted?
>
> The documentation of combine-and-quote-strings
> doesn't mention shell quoting at all.
Here is what the on-line help says - and I quote :)
(combine-and-quote-strings STRINGS &optional
SEPARATOR)
Concatenate the STRINGS, adding the SEPARATOR
(default " "). This tries to quote the strings to
avoid ambiguity such that
(split-string-and-unquote
(combine-and-quote-strings strs)) == strs Only
some SEPARATORs will work properly.
Here is what the Lisp manual say:
This function concatenates LIST-OF-STRINGS into
a single string, quoting each string as
necessary. It also sticks the SEPARATOR string
between each pair of strings; if SEPARATOR is
omitted or ‘nil’, it defaults to ‘" "’.
The return value is the resulting string.
The strings in LIST-OF-STRINGS that need quoting
are those that include SEPARATOR as their
substring. Quoting a string encloses it in double
quotes ‘"…"’. In the simplest case, if you are
consing a command from the individual
command-line arguments, every argument that
includes embedded blanks will be quoted.
So no, it doesn't mention shell quoting (or the
quoting of metachars as the OP puts it) but
1) I don't think the on-line help is clear and
2) the Lisp manual is clear (or more clear at least)
save for the last sentence: the "individual
command-line arguments"...
In particular, both should make clear that quoting is
not the quoting of shell (or otherwise) metachars, nor
the "Emacs quoting" (x vs. 'x) but instead the
insertion of double-quotation marks as substring
delimiters for each substring - marks that have to be
quoted to separate them from the identical delimiters
of the outer, "real" string - in the case where the
delimiter between the substrings also occurs within
the substrings.
You see? Wasn't that crystal clear?
Besides, if you don't agree that it isn't clear
(either piece of documentation), I have proof I'm
right, namely the OP which did the opposite of what
most people do - instead of ignoring the documentation
and still getting it to work somehow, he read the
documentation and it made him even more confused :)
Anyway here is how it works:
(combine-and-quote-strings
'("one two three four"
"shamen knocking at the door")) ; implicit separator is " ", so quote "strings"
; => "\"one two three four\" \"shamen knocking at the door\""
(combine-and-quote-strings
'("one two three four"
"shamen knocking at the door") ".") ; separator is "." so no quoting
; => "one two three four.shamen knocking at the door"
--
underground experts united
http://user.it.uu.se/~embe8573
next prev parent reply other threads:[~2015-04-12 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.502.1428836406.904.help-gnu-emacs@gnu.org>
2015-04-12 10:55 ` combine-and-quote-strings Pascal J. Bourguignon
2015-04-12 16:15 ` Emanuel Berg [this message]
2015-04-12 18:04 ` combine-and-quote-strings Drew Adams
2015-04-14 19:06 ` combine-and-quote-strings Philipp Stephani
2015-04-14 18:54 ` combine-and-quote-strings Philipp Stephani
2015-04-12 10:59 combine-and-quote-strings Philipp Stephani
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=87twwlxqzx.fsf@debian.uxu \
--to=embe8573@student.uu.se \
--cc=help-gnu-emacs@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.