From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Redo _zle using _arguments
Date: Mon, 11 Sep 2000 05:13:51 +0000 [thread overview]
Message-ID: <1000911051352.ZM5002@candle.brasslantern.com> (raw)
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
next reply other threads:[~2000-09-11 5:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-09-11 5:13 Bart Schaefer [this message]
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
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=1000911051352.ZM5002@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=zsh-workers@sunsite.auc.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).