From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: combine-and-quote-strings Date: Sun, 12 Apr 2015 18:15:14 +0200 Organization: Aioe.org NNTP Server Message-ID: <87twwlxqzx.fsf@debian.uxu> References: <87bnitpqdg.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1428855319 9484 80.91.229.3 (12 Apr 2015 16:15:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Apr 2015 16:15:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 12 18:15:19 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YhKXW-0004E2-7q for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2015 18:15:18 +0200 Original-Received: from localhost ([::1]:45786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YhKXV-0005aL-8m for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Apr 2015 12:15:17 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!feeds.phibee-telecom.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 99 Original-NNTP-Posting-Host: feB02bRejf23rfBm51Mt7Q.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:TT3s4lslKkRM5ks+MMMncV5Vlpk= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:211375 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:103657 Archived-At: "Pascal J. Bourguignon" writes: > Philipp Stephani 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