zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: Bug#519535: history expansion: modifier completion missing
Date: Thu, 19 Mar 2009 16:09:04 +0000	[thread overview]
Message-ID: <200903191609.n2JG95hf031989@news01.csr.com> (raw)
In-Reply-To: <237967ef0903190828k4b9f7edbyc85405b630c50d5d@mail.gmail.com>

Mikael Magnusson wrote:
> Is it supposed to work here? $PWD:<tab> (it doesn't for me).

No, wihin parameters the completion system doesn't handle any case
except parameter names and values properly.  It doesn't know there's
anything special to do there.  Parsing it would be horrible.  (It will,
of course, expand a complete expression as an entirely separate matter.)

> It does
> complete if you write $PWD(:<tab>, but also in ${PWD(:<tab>, but
> accepting one of the latter produces a syntax error:
> % echo ${PWD(:A)}
> zsh: bad substitution
> (regardless of which modifier you use)

That's because it is a syntax error.  Same answer: the completion system
doesn't know that's special, handling all these special cases is
horrific.  It ought to be possible for someone with that sort of time on
their hands to extend check_param() in compcore.c to add new parameter
contexts, but it seems a funny thing to do with your life.  (Actually,
in the case of brace parameters that ought to be easy, it already knows
you're in a brace parameter and it already knows the brace isn't
complete, so it could do the same as it does for completing the
parameter but set a different context to show it's in the trailing
matter.  But that still leaves the non-brace case.)

(Of course, the right way to do this is to have the shell parsed by
examining a grammar which is also used for generating the cases for
completing shell syntax.  Our infinite team of monkeys should have this
done by the next ice age.)

> Also, i get this:
> $PWD(:s-<tab>
> _history_modifiers:34: bad math expression: operand expected at `^-'
> _history_modifiers:34: bad math expression: operand expected at `^-'
> _history_modifiers:34: bad math expression: operand expected at `^-'
> _history_modifiers:34: bad math expression: operand expected at `^-'
> _history_modifiers:34: bad math expression: operand expected at `^-'
> _history_modifiers:34: bad math expression: operand expected at `^-'
> (same with / or other separator (but it says `^/' then, of course))

I obviously didn't try this bit.  It's supposed to give you hints.  Note
this doesn't currently work for !-history itself---out of fear, I used a
very simple test in _normal that only works with a trailing ":".

> As an aside, after i write $PWD(:<tab> to get the s, how do i "accept"
> the completion to make tab complete the - instead of cycling to the
> next completer? The only way i found is typing something and deleting
> it... When completing directories i usually just type a /.

Just type the string that's got to come next; it always does, or the s
is useless: there's no point typing anything you need to delete, just
use what you don't need to delete.  Actually, why don't you just type
"s-"?  The "completion" is really only there as a mnemonic of what can
go at that point, it doesn't save you any typing even in the optimal
case.

Index: Completion/Zsh/Type/_history_modifiers
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_history_modifiers,v
retrieving revision 1.3
diff -u -r1.3 _history_modifiers
--- Completion/Zsh/Type/_history_modifiers	17 Mar 2009 10:03:24 -0000	1.3
+++ Completion/Zsh/Type/_history_modifiers	19 Mar 2009 15:54:28 -0000
@@ -31,11 +31,11 @@
       fi
       delim=$PREFIX[1]
       compset -p 1
-      if ! compset "[^$delim]#$delim[^$delim]#$delim"; then
-	if compset "[^$delim]#$delim"; then
-	  _message original string
+      if ! compset -P "[^${delim}]#${delim}[^${delim}]#${delim}"; then
+	if compset -P "[^${delim}]#${delim}"; then
+	  _message "replacement string"
 	else
-	  _message replacement string
+	  _message "original string"
 	fi
 	return
       fi


-- 
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


  reply	other threads:[~2009-03-19 16:09 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
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 [this message]
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=200903191609.n2JG95hf031989@news01.csr.com \
    --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).