zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: [PATCH] fix option -A of _arguments
Date: Tue, 19 Oct 2021 19:23:25 +0900	[thread overview]
Message-ID: <5DB568C4-53A2-40C2-88E1-0EAB24C210AA@kba.biglobe.ne.jp> (raw)

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;





             reply	other threads:[~2021-10-19 10:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 10:23 Jun T [this message]
2021-10-20 17:49 ` Oliver Kiddle
2021-10-22  4:00   ` Jun T

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=5DB568C4-53A2-40C2-88E1-0EAB24C210AA@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /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).