Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Improve handling of b/n/s subscript flags



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   



Messages sorted by: Reverse Date, Date, Thread, Author