help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: combine-and-quote-strings


From: Emanuel Berg
Subject: Re: combine-and-quote-strings
Date: Sun, 12 Apr 2015 18:15:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

"Pascal J. Bourguignon" <address@hidden>
writes:

> Philipp Stephani <address@hidden> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]