zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] fix option -A of _arguments
@ 2021-10-19 10:23 Jun T
  2021-10-20 17:49 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Jun T @ 2021-10-19 10:23 UTC (permalink / raw)
  To: zsh-workers

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;





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

end of thread, other threads:[~2021-10-22  4:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 10:23 [PATCH] fix option -A of _arguments Jun T
2021-10-20 17:49 ` Oliver Kiddle
2021-10-22  4:00   ` Jun T

Code repositories for project(s) associated with this 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).