From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27558 invoked by alias); 27 Oct 2010 10:41:19 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28373 Received: (qmail 18849 invoked from network); 27 Oct 2010 10:41:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at kth.se does not designate permitted sender hosts) X-Virus-Scanned: by amavisd-new at kth.se X-KTH-Auth: auno [213.100.34.83] X-KTH-mail-from: auno@kth.se Message-ID: <4CC801C1.1020109@kth.se> Date: Wed, 27 Oct 2010 12:41:05 +0200 From: Mikael Auno User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100915 Thunderbird/3.0.8 MIME-Version: 1.0 To: Peter Stephenson CC: zsh-workers@zsh.org Subject: Re: Prefixed backslash removed when completing command References: <4BF51CF3.8010609@kth.se> <4CC7EB88.8020105@kth.se> <20101027110240.16941d1f@pwslap01u.europe.root.pri> In-Reply-To: <20101027110240.16941d1f@pwslap01u.europe.root.pri> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2010-10-27 12:02, Peter Stephenson wrote: > On Wed, 27 Oct 2010 11:06:16 +0200 > Mikael Auno wrote: >> If I am not completely misunderstanding your reply, I think you >> misunderstood my issue. My issue has nothing to do with either single >> or double quotes (they are only there in the original message to >> separate the examples from the rest of the text), but with the >> backslash. > > No, you've misunderstood my reply. > >> When I try to tab complete something starting with a leading >> backslash, e.g. \mpla, then it is completed to mplayer (without a >> leading backslash) instead of \mplayer (with a leading backslash) as >> I would expect. > > Yes, I realise that. Here's my reply rephrased. > > The internals of completion are complicated. There is no prospect of it > ever being able to preserve quotations in a general way. In particular > there is no prospect of it ever being able to retain backslashes that > have no basic syntactic effect. > > Slight digression on what I mean by a "basic syntactic effect". Aliases > are a special case as they are expanded on input, so things that are > usually ignored in the usual shell grammar become significant; > completion doesn't know anything about this. Completion just tries to > muddle through and produce an expression that (ignoring the alias > problem) is quoted in an appropriate way for the shell to process the > word on the command line. > > If quoting is done using backslashes the only backslashes left will be > those needed for special characters. Completion makes no attempt to try > to remember how the original word looked and reconstruct it. > > However, if quoting is done with a single or double quote character at > the start of the word, that form of quoting is preserved even if it's > not (apparently) needed to quote special characters. In this case, > completion remembers the whole word is quoted. This is much simpler > than trying to remember what happens character by character. > > So if you really insist on having a backslash, you are stuck, as far as > completion is concerned. (You still have the possibility of writing > line editor, non-completion, functions to quote the word how you want.) > > However, *if* it happens to be the case that you are simply trying to > ensure the word is quoted, somehow, you can get away with starting it > with a single quote, and forget about the backslash. The single quote > is preserved during completion, unlike the backslash, and a closing > quote appended. So it all works, and you have completed a quoted word. > > I'm not aware of anywhere in the shell that requires you to quote a word > as \mplayer rather than 'mplayer'. They should have the same effect in > every case except the bizarre one where you have defined 'mplayer', > including the quotes, as an alias. So if you started with a single > quote (I know that's not what you asked about) it should do the right > thing, or I'd like to hear why it doesn't. You are completely correct. I misunderstood your reply as I did not know that the backslash was at all related to quoting or that ordinary quoting had the same result as prefixing a command with a backslash with respect to suppressing alias expansion. Prefixing with single or double quotes works great, especially as the closing quote is appended automatically. Thank you for this insight, Mikael Auno