* completion function for Ruby and exclusion list problem.
@ 2001-06-01 5:30 Tanaka Akira
2001-06-01 8:51 ` Sven Wischnowsky
0 siblings, 1 reply; 2+ messages in thread
From: Tanaka Akira @ 2001-06-01 5:30 UTC (permalink / raw)
To: zsh-workers
I wrote a completion function for Ruby - scripting language like Perl
or Python.
It almost works, but I found a problem with exclusion list.
Z(3):akr@flux% Src/zsh -f
flux% fpath=(Completion Completion/**/*(/)); bindkey -e; autoload -U compinit; compinit -D
flux% zstyle '*' group-name ''
flux% zstyle '*:messages' format '%d'
flux% zstyle '*:descriptions' format '%d'
flux% compdef _tst tst
flux% _tst () {
function> _arguments '(1)-x' ':a:' ':b:'
function> }
flux% tst -x <TAB>
a
I think it should show `b' instead of `a' because non-option first
argument is excluded by `-x'.
Index: Completion/Unix/Command/_ruby
===================================================================
RCS file: _ruby
diff -N _ruby
--- /dev/null Thu May 24 22:33:05 2001
+++ _ruby Thu May 31 22:22:07 2001
@@ -0,0 +1,49 @@
+#compdef ruby
+
+# completion function for Ruby.
+# http://www.ruby-lang.org/
+
+local expl curcontext="$curcontext" line state
+typeset -A opt_args
+local dirs
+
+_arguments -C -s \
+ '--version[print version]' \
+ '-c[syntax check]' \
+ '-w[verbose mode without printing version message at the beginning]' \
+ '(-d)--debug[debug mode]' \
+ '(--debug)-d[debug mode]' \
+ '(-h)--help[print help message]' \
+ '(--help)-h[print help message]' \
+ '-l[automatic line-ending processing]' \
+ '-p[loop and print]' \
+ '-n[loop]' \
+ '-a[auto-split mode]' \
+ '-s[switch parsing]' \
+ '-0-[input record separator]:input record separator in octal:' \
+ '-K-[specifies KANJI (Japanese) encoding]:KANJI encoding:((e\:EUC-JP s\:Shift_JIS u\:UTF-8 N\:None))' \
+ '-F-[input field separator]:input field separator:' \
+ '-i-[in-place-edit mode]:suffix for in-place-edit mode:(.bak)' \
+ '-I+[library directory]:library directory:_files -/' \
+ '-r+[require library]:library name:->library' \
+ '-S[search ruby script in PATH]' \
+ '(--verbose)-v[verbose mode]' \
+ '(-v)--verbose[verbose mode]' \
+ '-x-[embedded script]:directory:_files -/' \
+ '-C+[chdir]:directory:_files -/' \
+ '(--yydebug)-y[compiler debug mode]' \
+ '(-y)--yydebug[compiler debug mode]' \
+ '--copyright[copyright notice]' \
+ '-T-[taint check]:taint level:' \
+ '(1)-e+[ruby command]:ruby command:' \
+ ':script file:_files' \
+ ':script argument:_files' && return 0
+
+case $state in
+ library)
+ dirs=($(_call_program directories $words[1] -e 'print\ \$:.join\(\"\\n\"\)'))
+ _wanted directories expl library \
+ _path_files -W dirs
+ ;;
+esac
+
--
Tanaka Akira
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: completion function for Ruby and exclusion list problem.
2001-06-01 5:30 completion function for Ruby and exclusion list problem Tanaka Akira
@ 2001-06-01 8:51 ` Sven Wischnowsky
0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2001-06-01 8:51 UTC (permalink / raw)
To: zsh-workers
Tanaka Akira wrote:
> It almost works, but I found a problem with exclusion list.
>
> Z(3):akr@flux% Src/zsh -f
> flux% fpath=(Completion Completion/**/*(/)); bindkey -e; autoload -U compinit; compinit -D
> flux% zstyle '*' group-name ''
> flux% zstyle '*:messages' format '%d'
> flux% zstyle '*:descriptions' format '%d'
> flux% compdef _tst tst
> flux% _tst () {
> function> _arguments '(1)-x' ':a:' ':b:'
> function> }
> flux% tst -x <TAB>
> a
>
> I think it should show `b' instead of `a' because non-option first
> argument is excluded by `-x'.
Yes. Uff. We lost that when we learned to handle cases where we might
have to use more than one action.
Bye
Sven
Index: Src/Zle/computil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/computil.c,v
retrieving revision 1.57
diff -u -r1.57 computil.c
--- Src/Zle/computil.c 2001/05/31 12:38:34 1.57
+++ Src/Zle/computil.c 2001/06/01 08:51:34
@@ -1130,9 +1130,11 @@
if (d->argsactive) {
Caarg a = d->args;
- while (a && (n < a->min || n > a->num))
+ while (a && (!a->active || n < a->min || n > a->num)) {
+ if (!a->active)
+ n++;
a = a->next;
-
+ }
if (a && a->min <= n && a->num >= n && a->active)
return a;
@@ -1154,7 +1156,7 @@
int sl = (d->set ? strlen(d->set) : -1), set = 0;
for (; (x = (opts ? "-" : *xor)); xor++) {
- if (optname && strcmp(optname, x))
+ if (optname && optname[0] == x[0] && strcmp(optname, x))
continue;
if (ca_xor)
addlinknode(ca_xor, x);
@@ -1403,7 +1405,8 @@
if (!state.oargs[state.curopt->num])
state.oargs[state.curopt->num] = znewlinklist();
- if (ca_inactive(d, state.curopt->xor, cur, 0, state.curopt->name))
+ if (ca_inactive(d, state.curopt->xor, cur, 0,
+ (cur == compcurrent ? state.curopt->name : NULL)))
return 1;
/* Collect the argument strings. Maybe. */
@@ -1456,7 +1459,8 @@
if (!state.oargs[tmpopt->num])
state.oargs[tmpopt->num] = znewlinklist();
- if (ca_inactive(d, tmpopt->xor, cur, 0, tmpopt->name))
+ if (ca_inactive(d, tmpopt->xor, cur, 0,
+ (cur == compcurrent ? tmpopt->name : NULL)))
return 1;
}
}
@@ -1523,6 +1527,8 @@
break;
}
zaddlinknode(state.args, ztrdup(line));
+ if (adef)
+ state.oopt = adef->num - state.nth;
if (state.def)
argxor = state.def->xor;
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-06-01 8:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-01 5:30 completion function for Ruby and exclusion list problem Tanaka Akira
2001-06-01 8:51 ` 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).