* PATCH: Redo _zle using _arguments
@ 2000-09-11 5:13 Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-09-11 5:13 UTC (permalink / raw)
To: zsh-workers
I started out to tweak one thing so that "zle -C" would complete properly,
and just got carried away.
This patch also fixes a couple of small documentation errors, related only
in that I saw them while re-reading the docs for zle and _arguments.
I also suspect there may be a bug in comparguments -- the '(*)-x' form of
optspec is supposed to mean that the '*:msg:act' form is not completed
when -x is on the command line, but that doesn't seem to happen (or at
least, not always). I imagine a fix is going to have to wait a few weeks
for Sven to return, though.
Random other question: Why isn't list-expand a completion widget for the
purposes of "zle -C"?
Index: Completion/Builtins/_zle
===================================================================
@@ -1,10 +1,77 @@
#compdef zle
-local expl
+local expl ret=1 st
+local -a opts compwids state
-if [[ "$words[2]" = -N && CURRENT -eq 3 ]]; then
- _wanted -C -N functions expl 'widget shell function' \
- compadd "$@" -k functions
-else
- _wanted widgets expl widget compadd -k widgets
-fi
+compwids=(accept-and-menu-complete
+ complete-word
+ delete-char-or-list
+ expand-or-complete
+ expand-or-complete-prefix
+ list-choices
+ menu-complete
+ menu-expand-or-complete
+ reverse-menu-complete)
+
+opts=(-A -C -D -L -M -N -R -U -a -c -l \* :)
+
+_arguments -s \
+ "($opts)-A[define widget alias]:old widget:->widget :new widget:->widget" \
+ "($opts)-C[define completion widget]:new widget name:->comp-widget :completion widget:->builtin-comp-widget :widget shell function:->function" \
+ "($opts)-D[delete widget]:*:widget:->widget" \
+ "(${opts#-l})-L+[with -l, list as commands]:*:-:->listing" \
+ "(${opts#-[La]})-l+[list user-defined widgets]:*:-:->listing" \
+ "(${opts#-l})-a+[with -l, list all widgets]:*:-:->listing" \
+ "($opts)-M[display message]:message: " \
+ "($opts)-N[define new widget]:widget name:->widget-or-function ::widget shell function:->function" \
+ "(${opts#-c})-R+[redisplay]:*:-:->redisplay" \
+ "(${opts#-R})-c+[with -R, clear listing]:*:-:->redisplay" \
+ "($opts)-U[unget to input stack]:string: " \
+ '(-)::widget name:->call'
+
+[[ $state == listing ]] &&
+ _arguments -s \
+ "-l[list user-defined widgets]" \
+ "(-a)-L[list as commands]" \
+ "(-L)-a[list all widgets]" \
+ '(-)*:widget name:->widget'
+
+for st in $state; do
+ case $st in
+ (call)
+ if ((CURRENT > 2)); then
+ _arguments \
+ '(-N)-n[numeric prefix]:number: ' \
+ '(-n)-N[reset numeric prefix]' \
+ ':widget::' '(-)*:widget arguments: ' && ret=0
+ # :widget:: is a placeholder so we needn't shift words
+ continue
+ fi
+ ;&
+ (widget*)
+ _wanted widgets expl widget compadd -k widgets && ret=0
+ [[ $st != *function ]] && continue
+ ;&
+ (function)
+ _wanted functions expl 'widget shell function' \
+ compadd -k functions && ret=0
+ ;;
+ (comp-widget)
+ _wanted widgets expl 'completion widget' \
+ compadd -k "widgets[(R)(*:|)(.|)(${(j(|))compwids})(|:*)]" && ret=0
+ ;&
+ (builtin-comp-widget)
+ _wanted widgets expl 'builtin completion widget' \
+ compadd -k "widgets[(I)(.|)(${(j(|))compwids})]" && ret=0
+ ;;
+ (redisplay)
+ _arguments -s \
+ "-R[redisplay]" \
+ "(*)-c[clear listing]" \
+ "(-)::status line: " "*:strings to list: " && ret=0
+ ;;
+ (*) ret=$?;;
+ esac
+done
+
+return ret
Index: Doc/Zsh/compwid.yo
===================================================================
@@ -640,7 +640,8 @@
match, the var(n)'th element of the var(array) is removed. Elements
for which the corresponding var(word) is matched are retained.
)
-item(tt(-), tt(--))(
+xitem(tt(-))
+item(tt(-)tt(-))(
This flag ends the list of flags and options. All arguments after it
will be taken as the words to use as matches even if they begin with
hyphens.
Index: Doc/Zsh/mod_zle.yo
===================================================================
@@ -190,7 +190,7 @@
cindex(calling widgets)
cindex(widgets, defining)
cindex(defining widgets)
-xitem(tt(zle) tt(-l) [ tt(-L) ] [ tt(-a) ] [ var(string) ... ])
+xitem(tt(zle) tt(-l) [ tt(-L) | tt(-a) ] [ var(string) ... ])
xitem(tt(zle) tt(-D) var(widget) ...)
xitem(tt(zle) tt(-A) var(old-widget) var(new-widget))
xitem(tt(zle) tt(-N) var(widget) [ var(function) ])
@@ -204,7 +204,7 @@
ZLE. Which operation it performs depends on its options:
startitem()
-item(tt(-l) [ tt(-L) ])(
+item(tt(-l) [ tt(-L) | tt(-a) ])(
List all existing user-defined widgets. If the tt(-L)
option is used, list in the form of tt(zle)
commands to create the widgets.
@@ -238,7 +238,7 @@
ifnzman(noderef(Zsh Line Editor))\
.
)
-citem(completion widgets, creating)
+cindex(completion widgets, creating)
item(tt(-C) var(widget) var(completion-widget) var(function))(
Create a user-defined completion widget named var(widget). The
completion widget will behave like the built-in completion-widget
--
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] 5+ messages in thread
* Re: PATCH: Redo _zle using _arguments
@ 2000-10-04 10:43 Sven Wischnowsky
0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2000-10-04 10:43 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> ...
>
> I also suspect there may be a bug in comparguments -- the '(*)-x' form of
> optspec is supposed to mean that the '*:msg:act' form is not completed
> when -x is on the command line, but that doesn't seem to happen (or at
> least, not always). I imagine a fix is going to have to wait a few weeks
> for Sven to return, though.
I'll have a look.
> Random other question: Why isn't list-expand a completion widget for the
> purposes of "zle -C"?
Because it never does completion, only the hard-wired form of
expansion which can't be programmed.
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: Redo _zle using _arguments
@ 2000-10-04 12:47 Sven Wischnowsky
2000-10-04 15:05 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2000-10-04 12:47 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> ...
>
> I also suspect there may be a bug in comparguments -- the '(*)-x' form of
> optspec is supposed to mean that the '*:msg:act' form is not completed
> when -x is on the command line, but that doesn't seem to happen (or at
> least, not always). I imagine a fix is going to have to wait a few weeks
> for Sven to return, though.
Hm, I had a look but couldn't find a bug. Could you give me an example?
Bye
Sven
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: PATCH: Redo _zle using _arguments
2000-10-04 12:47 Sven Wischnowsky
@ 2000-10-04 15:05 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-10-04 15:05 UTC (permalink / raw)
To: Sven Wischnowsky, zsh-workers
On Oct 4, 2:47pm, Sven Wischnowsky wrote:
}
} Bart Schaefer wrote:
}
} > I also suspect there may be a bug in comparguments -- the '(*)-x' form of
} > optspec is supposed to mean that the '*:msg:act' form is not completed
} > when -x is on the command line, but that doesn't seem to happen (or at
} > least, not always).
}
} Hm, I had a look but couldn't find a bug. Could you give me an example?
Sure. Completion after "zle -R -c":
zagzig[501] zle -R -c <TAB>
Completing status line
Completing strings to list
The call to _arguments was:
_arguments -s \
"-R[redisplay]" \
"(*)-c[clear listing]" \
"(-)::status line: " "*:strings to list: "
Since "(*)-c" is there, and -c is on the line, the "*:strings to list: "
clause should never be activated. Yet there's the description string for
it, in the listing. If I go on to add something for the status line:
zagzig[501] zle -R -c something <TAB>
Completing no more arguments
What I expected the first time was either just "Completing status line"
or that plus "no more arguments", but not "strings to list".
--
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] 5+ messages in thread
* Re: PATCH: Redo _zle using _arguments
@ 2000-10-05 8:53 Sven Wischnowsky
0 siblings, 0 replies; 5+ messages in thread
From: Sven Wischnowsky @ 2000-10-05 8:53 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> On Oct 4, 2:47pm, Sven Wischnowsky wrote:
> }
> } Bart Schaefer wrote:
> }
> } > I also suspect there may be a bug in comparguments -- the '(*)-x' form of
> } > optspec is supposed to mean that the '*:msg:act' form is not completed
> } > when -x is on the command line, but that doesn't seem to happen (or at
> } > least, not always).
> }
> } Hm, I had a look but couldn't find a bug. Could you give me an example?
>
> Sure. Completion after "zle -R -c":
>
> zagzig[501] zle -R -c <TAB>
> Completing status line
> Completing strings to list
>
> The call to _arguments was:
>
> _arguments -s \
> "-R[redisplay]" \
> "(*)-c[clear listing]" \
> "(-)::status line: " "*:strings to list: "
Aha. In combination with an optional argument. Right, it was used the
rest-spec even though that was inactivated.
Bye
Sven
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.42
diff -u -r1.42 computil.c
--- Src/Zle/computil.c 2000/08/14 08:16:45 1.42
+++ Src/Zle/computil.c 2000/10/05 08:52:07
@@ -1685,7 +1685,8 @@
if (!opt) {
if (arg->num >= 0 && !arg->next && miss)
- arg = ca_laststate.d->rest;
+ arg = (ca_laststate.d->rest && ca_laststate.d->rest->active ?
+ ca_laststate.d->rest : NULL);
else {
onum = arg->num;
rest = (onum != arg->min && onum == ca_laststate.nth);
@@ -1693,7 +1694,8 @@
if (arg->num != onum + 1)
miss = 1;
} else if (rest || (oopt > 0 && !opt)) {
- arg = ca_laststate.d->rest;
+ arg = (ca_laststate.d->rest && ca_laststate.d->rest->active ?
+ ca_laststate.d->rest : NULL);
oopt = -1;
}
}
@@ -1711,7 +1713,8 @@
}
if (!opt && oopt > 0) {
oopt = -1;
- arg = ca_laststate.d->rest;
+ arg = (ca_laststate.d->rest && ca_laststate.d->rest->active ?
+ ca_laststate.d->rest : NULL);
goto rec;
}
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2000-10-05 8:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-11 5:13 PATCH: Redo _zle using _arguments Bart Schaefer
2000-10-04 10:43 Sven Wischnowsky
2000-10-04 12:47 Sven Wischnowsky
2000-10-04 15:05 ` Bart Schaefer
2000-10-05 8:53 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).