zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: completion for subscript flags
@ 2001-05-04 22:57 Oliver Kiddle
  2001-05-05  0:28 ` Bart Schaefer
  2001-05-06  4:59 ` Andrej Borsenkow
  0 siblings, 2 replies; 4+ messages in thread
From: Oliver Kiddle @ 2001-05-04 22:57 UTC (permalink / raw)
  To: zsh-workers

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


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

* Re: PATCH: completion for subscript flags
  2001-05-04 22:57 PATCH: completion for subscript flags Oliver Kiddle
@ 2001-05-05  0:28 ` Bart Schaefer
  2001-05-05 17:26   ` Bart Schaefer
  2001-05-06  4:59 ` Andrej Borsenkow
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2001-05-05  0:28 UTC (permalink / raw)
  To: Oliver Kiddle, zsh-workers

On May 4, 11:57pm, Oliver Kiddle wrote:
> Subject: PATCH: completion for subscript flags
>
> This adds completion for subscript flags in _subscript so as to further
> reduce the number of times I have to reach for the manual.

Very nice.

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

Hmm.  Something like (this is just meant as example code, not something
that would drop in anywhere):

	[[ $flags = (#b)([snb])(?)(*) ]] && {
	    local f=$match[1] d=$match[2] r=$match[3]
	    [[ $r = (#b)([^$d]##)$d* ]]
	}

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

I think you've got some of the descriptions wrong.  The wording gets
tricky here.

> +  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 k K i I)r[return first value matched by subscript]'
	'(r k K i I)R[return all values matched by subscript]'

> +      '(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 i I)k[return first value where subscript matched by key]'
	'(r R k i I)K[return all values where subscript matched by key]'

> +      '(r R k K I)i[return first matching key]'
> +      '(r R k K i)I[return all matching keys]'

These are correct, but I'd reword as:

	'(r R k K I)i[return first key matched by subscript]'
	'(r R k K i)I[return all keys matched by subscript]'

The difference is that r and R compare as [[ value = subscript ]] whereas
k and K do [[ subscript = key ]] and i and I do [[ key = subscript ]] --
do you see the analogy to which thing is treated as a pattern?

> +    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]'

You seem to have forgotten

	'(r R k K I)i[reverse subscript giving index of first match]'


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

* Re: PATCH: completion for subscript flags
  2001-05-05  0:28 ` Bart Schaefer
@ 2001-05-05 17:26   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2001-05-05 17:26 UTC (permalink / raw)
  To: Oliver Kiddle, zsh-workers

On May 4,  5:28pm, Bart Schaefer wrote:
}
} On May 4, 11:57pm, Oliver Kiddle wrote:
} >
} > 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.
} 
} I think you've got some of the descriptions wrong.  The wording gets
} tricky here.

I'll commit the following rewrite of the descriptions.  Feel free to
rewrite it yet again if you think of better language.

Index: Completion/Zsh/Context/_subscript
===================================================================
--- Completion/Zsh/Context/_subscript	2001/05/05 16:16:08	1.2
+++ Completion/Zsh/Context/_subscript	2001/05/05 17:22:11
@@ -19,12 +19,12 @@
 
   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]'
+      '(R k K i I)r[any one value matched by subscript as pattern]'
+      '(r k K i I)R[all values matched by subscript as pattern]'
+      '(r R K i I)k[any one value where subscript matched by key as pattern]'
+      '(r R k i I)K[all values where subscript matched by key as pattern]'
+      '(r R k K I)i[any one key matched by subscript as pattern]'
+      '(r R k K i)I[all keys matched by subscript as pattern]'
     );;
     (|scalar*)) flags=(
       'w[make subscripting work on words of scalar]'
@@ -32,11 +32,12 @@
       'p[recognise escape sequences in subsequent s flag]'
     );&
     array*) flags=($flags
-      'n[specify match to return]'
+      'n[Nth lowest/highest index with i/I/r/R flag]'
       '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]'
+      '(r R k K i)I[highest index of value matched by subscript]'
+      '(r R k K I)i[lowest index of value matched by subscript]'
+      '(r k K i I)R[value matched by subscript at highest index]'
+      '(R k K i I)r[value matched by subscript at lowest index]'
     );;
   esac
 

-- 
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] 4+ messages in thread

* Re: PATCH: completion for subscript flags
  2001-05-04 22:57 PATCH: completion for subscript flags Oliver Kiddle
  2001-05-05  0:28 ` Bart Schaefer
@ 2001-05-06  4:59 ` Andrej Borsenkow
  1 sibling, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 2001-05-06  4:59 UTC (permalink / raw)
  To: zsh-workers

On Fri, 4 May 2001, Oliver Kiddle wrote:

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

The next step is to complete globbing flags (exactly for the same reason
:-) It probably won't do as context completion (there is too vague
context) but nice as separate function.

-andrej


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

end of thread, other threads:[~2001-05-06  4:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-04 22:57 PATCH: completion for subscript flags Oliver Kiddle
2001-05-05  0:28 ` Bart Schaefer
2001-05-05 17:26   ` Bart Schaefer
2001-05-06  4:59 ` Andrej Borsenkow

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