zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: PATCH: Improve handling of b/n/s subscript flags
Date: Sun, 6 May 2001 19:42:40 +0000	[thread overview]
Message-ID: <1010506194240.ZM21879@candle.brasslantern.com> (raw)

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   


             reply	other threads:[~2001-05-06 19:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-06 19:42 Bart Schaefer [this message]
2001-05-08 11:51 ` Oliver Kiddle
2001-05-08 12:31   ` Sven Wischnowsky

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=1010506194240.ZM21879@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.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).