Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] fix option -A of _arguments
- X-seq: zsh-workers 49496
- From: Jun T <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] fix option -A of _arguments
- Date: Tue, 19 Oct 2021 19:23:25 +0900
- Archived-at: <https://zsh.org/workers/49496>
- List-id: <zsh-workers.zsh.org>
Consider the following example:
% _cmd () { _arguments -A '-*' : -a -b '*: :_file' }
% compdef _cmd cmd
cmd -x -<TAB>
No match for: `file'
But zshcompsys(1) says:
-A pat
Do not complete options after the first non-option argument on the line.
pat is a pattern matching all strings which are not to be taken as arguments.
For example, to make _arguments stop completing options after the first
normal argument, but ignoring all strings starting with a hyphen even if they
are not described by one of the optspecs, the form is `-A "-*"'.
In the example above, -x should not be taken as a normal argument since it
matches the pattern '-*' (although it is not in the optspecs), and the
options -a and -b should still be offered here (if I understand the document
correctly).
With the patch below, ca_inactive() is called only if
-A pat is given, and
the word under inspection ('-x' in the example above) does not
match the pat so it can be considered as a normal argument, and
the word ('-x') is before the cursor.
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index e08788e89..9d9a09543 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1995,7 +1995,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first)
Caopt ptr, wasopt = NULL, dopt;
struct castate state;
char *line, *oline, *pe, **argxor = NULL;
- int cur, doff, argend, arglast;
+ int cur, doff, argend, arglast, notmatch;
Patprog endpat = NULL, napat = NULL;
LinkList sopts = NULL;
#if 0
@@ -2236,9 +2236,10 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first)
&& (ca_foreign_opt(d, all, line)))
return 1;
else if (state.arg &&
- (!napat || cur <= compcurrent || !pattry(napat, line))) {
+ (!napat || (notmatch = !pattry(napat, line)) ||
+ cur <= compcurrent)) {
/* Otherwise it's a normal argument. */
- if (napat && cur <= compcurrent)
+ if (napat && notmatch && cur <= compcurrent)
ca_inactive(d, NULL, cur + 1, 1);
arglast = 1;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author