zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: zsh-workers@sunsite.dk
Subject: PATCH: completion for subscript flags
Date: Fri, 04 May 2001 23:57:48 +0100	[thread overview]
Message-ID: <3AF333EC.7066178F@u.genie.co.uk> (raw)

This adds completion for subscript flags in _subscript so as to further
reduce the number of times I have to reach for the manual.

One problem is that _values is not powerful enough to handle the
arguments such as you have with the s flag (e.g. in $PATH[(s.:.)4]).
Any ideas on how to handle this or is it not worth bothering? I looked
at doing it all without _values but it would have been messy,
especially without ksh93 style back references to match the argument
delimiters both in one pattern.

unset parameters are treated like scalars.

I'd appreciate if someone could check through my descriptions,
particularly those for associative arrays. I have a suspicion that some
of the flags aren't working actually but I may just be confused.

It would be nice to do similar things in _brace_parameter but flags are
currently stripped before it is called so that will require some lower
level changes. csh history references and modifiers, glob
qualifiers and globbing flags might also be possible to do.

Oliver

Index: Completion/Zsh/Context/_subscript
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Context/_subscript,v
retrieving revision 1.1
diff -u -r1.1 _subscript
--- Completion/Zsh/Context/_subscript	2001/04/02 11:24:32	1.1
+++ Completion/Zsh/Context/_subscript	2001/05/04 22:54:48
@@ -1,6 +1,6 @@
 #compdef -subscript-
 
-local expl ind osuf=']'
+local expl ind osuf=']' flags
 
 if [[ "$1" = -q ]]; then
   osuf='] '
@@ -8,10 +8,39 @@
   shift
 fi
 
+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
+  compset -S '\)*'
+
+  case ${(Pt)${compstate[parameter]}} in
+    assoc*) flags=(
+      '(R k K i I)r[return first matching value]'
+      '(r k K i I)R[return value of first matching key]'
+      '(r R K i I)k[return all values with matching keys]'
+      '(r R k i I)K[return value of first matching key]'
+      '(r R k K I)i[return first matching key]'
+      '(r R k K i)I[return all matching keys]'
+    );;
+    (|scalar*)) flags=(
+      'w[make subscripting work on words of scalar]'
+      's[specify word separator]'
+      'p[recognise escape sequences in subsequent s flag]'
+    );&
+    array*) flags=($flags
+      'n[specify match to return]'
+      'b[begin with specified element]'
+      '(r R k K i)I[reverse subscript giving index of last match]'
+      '(r k K i I)R[reverse subscripting giving last match]'
+      '(R k K i I)r[reverse subscripting giving first match]'
+    );;
+  esac
+
+  _values -s '' 'subscript flags' $flags
 elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
   local suf

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


             reply	other threads:[~2001-05-04 22:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-04 22:57 Oliver Kiddle [this message]
2001-05-05  0:28 ` Bart Schaefer
2001-05-05 17:26   ` Bart Schaefer
2001-05-06  4:59 ` Andrej Borsenkow

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=3AF333EC.7066178F@u.genie.co.uk \
    --to=opk@u.genie.co.uk \
    --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).