From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: Bug#519535: history expansion: modifier completion missing
Date: Tue, 17 Mar 2009 09:57:17 +0000 [thread overview]
Message-ID: <20090317095717.02bedf7e@news01> (raw)
In-Reply-To: <090316194434.ZM16487@torch.brasslantern.com>
On Mon, 16 Mar 2009 19:44:34 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> [-bugs.debian.org]
>
> On Mar 16, 6:18pm, Peter Stephenson wrote:
> }
> } I thought this was going to be harder than it turned out to be; as you can
> } see it's really quite simple, particularly since I already wrote modifer
> } completion and it would appear had the foresight to make it handle the
> } history case.
>
> Nit-pick: This doesn't handle the new :a/:A modifiers.
I've fixed that.
> Other nit-pick about :a itself -- get a load of this:
>
> torch% echo foo
> torch% !!:a
> /usr/local/src/zsh/zsh-build/echo foo
> zsh: no such file or directory: /usr/local/src/zsh/zsh-build/echo
>
> That's almost certainly not the intended behavior ... is it?
It depends what you mean by "intended": Michael did say the operation
didn't take account of whether the file existed (but I didn't document
this), and there was never any special behaviour for command words. You
could make it work like "=", I suppose, but that's an extension.
> Replace :a
> with :h or :t there and you get "modifier failed" (which seems odd as
> well, but ...).
I think it's always done that, although that doesn't mean it's necessarily
useful. Logically, it seems to me that for :h to fail is probably useful
(there's no directory part, so you won't get it) but for :t to fail is less
so, since you've already got a perfectly good non-directory part (even it
happens to be a directory, this isn't VMS). So we could probably change
that without anyone complaining.
> I don't know how the generic quoting code plays in, but I suspect this
> is done this way *because* history expansion takes place so early. If
> it looks like a history expansion and it got this far, then it must be
> a *failed* history expansion and needs to be quoted if it matches any
> other completion -- otherwise the history expansion will fail *again*
> after accept-line, and spoil the whole command.
That's quite possible. The quote code is hair-raising enough (see utils.c
around line 4504) that it's quite hard to tell. It's being called from
multiquote() within callcompfunc() in compcore.c, which is called for all
top-level completion widgets. The commenting in that last function is
quite amusing in an infuriating sort of way: there are three, and all of
them are in blocks marked with "#if 0".
> } I think -z $compstate[quote] ensures we're not already doing something
> } clever inside nested quotes, which would mean the expression couldn't be a
> } history expansion. I think.
>
> History expansion occurs inside double quotes, though, so if the quote
> state is double-quote then ... er, um ... perhaps it's necessary to
> run compstate -q and examine $compstate[all_quotes] ...
Hmm... I deliberately didn't make the test too hairy, so it only completes
at the start of a word, but it looks like it's not too hard to fix the
simplest case of double quoting.
Index: Completion/Base/Core/_normal
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_normal,v
retrieving revision 1.5
diff -u -r1.5 _normal
--- Completion/Base/Core/_normal 16 Mar 2009 18:29:39 -0000 1.5
+++ Completion/Base/Core/_normal 17 Mar 2009 09:42:27 -0000
@@ -13,7 +13,9 @@
# $PREFIX has a quoted form of the !, so we can't test that
# (it might the start of a real argument), but words has the
# raw McCoy.
-if [[ -o BANG_HIST && $words[CURRENT] = \!*: && -z $compstate[quote] ]]; then
+if [[ -o BANG_HIST &&
+ ( ( $words[CURRENT] = \!*: && -z $compstate[quote] ) ||
+ ( $words[CURRENT] = \"\!*: && $compstate[all_quotes] = \" ) ) ]]; then
# This looks like a real history expansion; in that case
# we'd better put the !'s back the way pfalstad intended.
PREFIX=${PREFIX//\\!/!}
Index: Completion/Zsh/Type/_history_modifiers
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_history_modifiers,v
retrieving revision 1.2
diff -u -r1.2 _history_modifiers
--- Completion/Zsh/Type/_history_modifiers 23 Feb 2008 18:34:02 -0000 1.2
+++ Completion/Zsh/Type/_history_modifiers 17 Mar 2009 09:42:27 -0000
@@ -64,6 +64,8 @@
)
if (( ! global )); then
list+=(
+ "a:absolute path"
+ "A:absolute path resolving symbolic links"
"g:globally apply s or &"
"h:head - strip trailing path element"
"t:tail - strip directories"
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
next prev parent reply other threads:[~2009-03-17 9:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090313105555.GA19025@piper.oerlikon.madduck.net>
2009-03-15 6:22 ` Clint Adams
2009-03-16 18:18 ` Peter Stephenson
2009-03-17 2:44 ` Bart Schaefer
2009-03-17 9:57 ` Peter Stephenson [this message]
2009-03-17 11:00 ` Peter Stephenson
2009-03-17 12:09 ` Peter Stephenson
2009-03-17 17:36 ` Bart Schaefer
2009-03-17 18:46 ` Modifiers, command position, and so forth (Re: Bug#519535: history expansion: modifier completion missing) Bart Schaefer
2009-03-18 19:36 ` Peter Stephenson
2009-03-19 0:34 ` Bart Schaefer
2009-03-19 14:34 ` Peter Stephenson
2009-03-19 15:28 ` Bug#519535: history expansion: modifier completion missing Mikael Magnusson
2009-03-19 16:09 ` Peter Stephenson
2009-03-19 16:18 ` Mikael Magnusson
2009-03-19 16:18 ` Bart Schaefer
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=20090317095717.02bedf7e@news01 \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/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 public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).