zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Improve handling of b/n/s subscript flags
@ 2001-05-06 19:42 Bart Schaefer
  2001-05-08 11:51 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2001-05-06 19:42 UTC (permalink / raw)
  To: zsh-workers

The delimiters following the b/n/s flags are allowed to be matched pairs of
parens, brackets, or braces, so the `compset -P' had to change so as not to
treat the close-paren of such a pair as the close-paren of the flags.  These
can't nest, so it's possible to match them with a pattern.

(I note in passing that it's impossible to use a close-paren in the string
argument of the `s' flag; that is, you can't split into words on parens, so
it's not important that you can't complete that.)

I've included code to handle e.g. (s[string]), but with `$scalar[(s[' on the
line we arrive in _subscript with the `(s[' already moved into $IPREFIX and
so `compset -P \(' fails and we branch into `_contexts -math-'.  I'm not
sure what code has to change to fix this; I suspect it's in C somewhere.

The next change to make to this is to discover that i/I/r/R are in the flags
and NOT complete in math context (for arrays) or association keys (assoc's).

--- zsh-forge/current/Completion/Zsh/Context/_subscript	Sat May  5 13:09:50 2001
+++ zsh-4.0/Completion/Zsh/Context/_subscript	Sun May  6 12:15:53 2001
@@ -8,15 +8,39 @@
   shift
 fi
 
-compset -P '\([^\)]##\)' # remove subscript flags
+compset -P '\(([^\(\)]|*\(*\)*)##\)' # remove subscript flags
 
 if [[ "$PREFIX" = :* ]]; then
   _wanted characters expl 'character class' \
       compadd -p: -S ':]' alnum alpha blank cntrl digit graph \
                           lower print punct space upper xdigit
 elif compset -P '\('; then
+  local match
   compset -S '\)*'
 
+  if [[ $PREFIX = (#b)*([bns])(?|)(*) ]]; then
+    local f=$match[1] d=$match[2] e=$match[2] v=$match[3]
+    [[ $f = s && ${(Pt)${compstate[parameter]}} != scalar ]] && return 1
+    if [[ -z $d ]]; then
+      _message 'delimiter'
+      return
+    else
+      case $d in
+      (\() e=\);;
+      (\[) e=\];;
+      (\{) e=\};;
+      esac
+      if [[ $v != *$e* ]]; then
+	case $f in
+	(s) _message 'separator string';;
+	(b|n) [[ $v = <-># ]] && _message 'number' || return 1;;
+	esac
+	[[ -n $v && $SUFFIX$ISUFFIX != *$e* ]] && _message 'delimiter'
+	return 0
+      fi
+    fi
+  fi
+
   case ${(Pt)${compstate[parameter]}} in
     assoc*) flags=(
       '(R k K i I)r[any one value matched by subscript as pattern]'

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Improve handling of b/n/s subscript flags
  2001-05-06 19:42 PATCH: Improve handling of b/n/s subscript flags Bart Schaefer
@ 2001-05-08 11:51 ` Oliver Kiddle
  2001-05-08 12:31   ` Sven Wischnowsky
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2001-05-08 11:51 UTC (permalink / raw)
  To: zsh-workers

This is great, thanks. There was one tiny mistake which I fix here.

Bart Schaefer wrote:
> 
> I've included code to handle e.g. (s[string]), but with `$scalar[(s[' on the
> line we arrive in _subscript with the `(s[' already moved into $IPREFIX and
> so `compset -P \(' fails and we branch into `_contexts -math-'.  I'm not
> sure what code has to change to fix this; I suspect it's in C somewhere.

It'll be whatever C code decides the current context. This has never
been perfect for determining whether we are in a subscript hence the
completion of character classes in _subscript. If we want similar
completion for zsh's various other flags, then I expect it is the same
bit of code that needs updating to give us access to those areas in
shell code.

> The next change to make to this is to discover that i/I/r/R are in the flags
> and NOT complete in math context (for arrays) or association keys (assoc's).

Yes, and complete array style indexes for split scalars.

Oliver

Index: Completion/Zsh/Context/_subscript
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_subscript,v
retrieving revision 1.4
diff -u -r1.4 _subscript
--- Completion/Zsh/Context/_subscript   2001/05/06 22:35:08     1.4
+++ Completion/Zsh/Context/_subscript   2001/05/08 11:49:49
@@ -20,7 +20,7 @@
 
   if [[ $PREFIX = (#b)*([bns])(?|)(*) ]]; then
     local f=$match[1] d=$match[2] e=$match[2] v=$match[3]
-    [[ $f = s && ${(Pt)${compstate[parameter]}} != scalar ]] && return 1
+    [[ $f = s && ${(Pt)${compstate[parameter]}} != scalar* ]] && return 1
     if [[ -z $d ]]; then
       _message 'delimiter'
       return


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Improve handling of b/n/s subscript flags
  2001-05-08 11:51 ` Oliver Kiddle
@ 2001-05-08 12:31   ` Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2001-05-08 12:31 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote:

> ...
> 
> It'll be whatever C code decides the current context. This has never
> been perfect for determining whether we are in a subscript hence the
> completion of character classes in _subscript. If we want similar
> completion for zsh's various other flags, then I expect it is the same
> bit of code that needs updating to give us access to those areas in
> shell code.

I meant to reply to this thread earlier and then forgot.

There are mainly two (basic) things in completion I'd like to work on
after the next release.  One is suffix handling (we had some discussion
about this quite some time ago and Bart's last mails made it spin around
in my head again).  The other is moving more of the C-code into shell
code, especially parts of the code that tries to find out where we are
completing.  This is a very ugly part of the C-code and I hope with some
clever supporting builtins this will be more manageable when in shell
code.

And then I would like to have that context-determining code to be
generic enough to be used elsewhere (we were discussing that this might
be useful to have for other zle widgets, too, e.g. word-movement).


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-08 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-06 19:42 PATCH: Improve handling of b/n/s subscript flags Bart Schaefer
2001-05-08 11:51 ` Oliver Kiddle
2001-05-08 12:31   ` Sven Wischnowsky

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