zsh-workers
 help / color / mirror / Atom feed
* Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
@ 2021-01-21 14:37 Marlon Richert
  2021-01-25 15:07 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Marlon Richert @ 2021-01-21 14:37 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

% cd $(mktemp -d)
% ZDOTDIR=$PWD HOME=$PWD zsh -f
% autoload -Uz compinit
% compinit
% zsh_directory_name() { [[ $1 == c ]] && compadd -S ']' foo }

Given the above setup, when


   1. $LBUFFER is `cd ~[` or `cd ~[fo`,
   2. $RBUFFER is empty, and
   3. I press ^I,
   4. then $LBUFFER becomes `cd ~[foo]`.




   1. $LBUFFER is `cd ~[`,
   2. $RBUFFER is `fo` or `]`, and
   3. I press ^I,
   4. then completion beeps and the buffer remains unchanged.


`functions -t _complete` shows that the problem is caused by
$compstate[context] becoming `tilde` instead of `subscript` as soon as
$SUFFIX is non-empty, which causes _complete() to not call _subscript(),
which is the only point of entry to _dynamic_directory_name().

[-- Attachment #2: Type: text/html, Size: 2739 bytes --]

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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-01-21 14:37 Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty Marlon Richert
@ 2021-01-25 15:07 ` Peter Stephenson
  2021-03-31  8:10   ` Marlon Richert
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2021-01-25 15:07 UTC (permalink / raw)
  To: Marlon Richert, Zsh hackers list

> On 21 January 2021 at 14:37 Marlon Richert <marlon.richert@gmail.com> wrote:
> % cd $(mktemp -d)
> % ZDOTDIR=$PWD HOME=$PWD zsh -f
> % autoload -Uz compinit
> % compinit
> % zsh_directory_name() { [[ $1 == c ]] && compadd -S ']' foo }
>
> Given the above setup, when
> 
>    1. $LBUFFER is `cd ~[` or `cd ~[fo`,
>    2. $RBUFFER is empty, and
>    3. I press ^I,
>    4. then $LBUFFER becomes `cd ~[foo]`.
>  
>    1. $LBUFFER is `cd ~[`,
>    2. $RBUFFER is `fo` or `]`, and
>    3. I press ^I,
>    4. then completion beeps and the buffer remains unchanged.
> 
> `functions -t _complete` shows that the problem is caused by
> $compstate[context] becoming `tilde` instead of `subscript` as soon as
> $SUFFIX is non-empty, which causes _complete() to not call _subscript(),
> which is the only point of entry to _dynamic_directory_name().

The following is somewhere near, but this is quite complex and somewhat
at odds with completion in other contexts --- it's not clear to me
whether or not I should need that special diversion in _main_complete
but currently I do.  (Your compadd -S ']' is going to add too many
']'s in this case, I think, but that's a separate problem.)

pws

diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index 6b2cf2bcf..2bcbd2118 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then
   if [[ -o equals ]] && compset -P 1 '='; then
     compstate[context]=equal
   elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then
-    compset -p 1
-    compstate[context]=tilde
+    if [[ "$PREFIX" = '~['[^\]]## ]]; then
+      # Inside ~[...] should be treated as a subscript.
+      compset -p 2
+      # To be consistent, we ignore all but the contents of the square
+      # brackets.
+      compset -S '\]*'
+      compstate[context]=subscript
+      [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return
+    else
+      compset -p 1
+      compstate[context]=tilde
+    fi
   fi
 fi
 
diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript
index 0c9a89ad5..0d9632864 100644
--- a/Completion/Zsh/Context/_subscript
+++ b/Completion/Zsh/Context/_subscript
@@ -1,6 +1,8 @@
 #compdef -subscript-
 
-local expl ind osuf=']' flags sep
+local expl ind osuf flags sep
+
+[[ $ISUFFIX = *\]* ]] || osuf=\]
 
 if [[ "$1" = -q ]]; then
   compquote osuf
diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr
index cb72e4600..b653e7c38 100644
--- a/Functions/Chpwd/zsh_directory_name_cdr
+++ b/Functions/Chpwd/zsh_directory_name_cdr
@@ -16,8 +16,10 @@ elif [[ $1 = c ]]; then
     typeset -a keys values
     values=(${${(f)"$(cdr -l)"}/ ##/:})
     keys=(${values%%:*})
+    local addsuffix
+    [[ $ISUFFIX = *\]* ]] || addsuffix='-S]'
     _describe -t dir-index 'recent directory index' \
-      values -V unsorted -S']'
+      values -V unsorted $addsuffix
     return
   fi
 fi
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 8c0534708..1622d8a6b 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1067,6 +1067,7 @@ redrawhook(void)
 	int old_incompfunc = incompfunc;
 	char *args[2];
 	Thingy lbindk_save = lbindk, bindk_save = bindk;
+	struct modifier zmod_save = zmod;
 
 	refthingy(lbindk_save);
 	refthingy(bindk_save);
@@ -1094,6 +1095,7 @@ redrawhook(void)
 	 * restore lastcmd manually so that we don't mess up the global state
 	 */
 	lastcmd = lastcmd_prev;
+	zmod = zmod_save;
     }
 }


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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-01-25 15:07 ` Peter Stephenson
@ 2021-03-31  8:10   ` Marlon Richert
  2021-03-31  8:25     ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Marlon Richert @ 2021-03-31  8:10 UTC (permalink / raw)
  To: Zsh hackers list

Could someone please review Peter's patch, below?

On Mon, Jan 25, 2021 at 5:07 PM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> > On 21 January 2021 at 14:37 Marlon Richert <marlon.richert@gmail.com> wrote:
> > % cd $(mktemp -d)
> > % ZDOTDIR=$PWD HOME=$PWD zsh -f
> > % autoload -Uz compinit
> > % compinit
> > % zsh_directory_name() { [[ $1 == c ]] && compadd -S ']' foo }
> >
> > Given the above setup, when
> >
> >    1. $LBUFFER is `cd ~[` or `cd ~[fo`,
> >    2. $RBUFFER is empty, and
> >    3. I press ^I,
> >    4. then $LBUFFER becomes `cd ~[foo]`.
> >
> >    1. $LBUFFER is `cd ~[`,
> >    2. $RBUFFER is `fo` or `]`, and
> >    3. I press ^I,
> >    4. then completion beeps and the buffer remains unchanged.
> >
> > `functions -t _complete` shows that the problem is caused by
> > $compstate[context] becoming `tilde` instead of `subscript` as soon as
> > $SUFFIX is non-empty, which causes _complete() to not call _subscript(),
> > which is the only point of entry to _dynamic_directory_name().
>
> The following is somewhere near, but this is quite complex and somewhat
> at odds with completion in other contexts --- it's not clear to me
> whether or not I should need that special diversion in _main_complete
> but currently I do.  (Your compadd -S ']' is going to add too many
> ']'s in this case, I think, but that's a separate problem.)
>
> diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
> index 6b2cf2bcf..2bcbd2118 100644
> --- a/Completion/Base/Core/_main_complete
> +++ b/Completion/Base/Core/_main_complete
> @@ -94,8 +94,18 @@ if [[ -z "$compstate[quote]" ]]; then
>    if [[ -o equals ]] && compset -P 1 '='; then
>      compstate[context]=equal
>    elif [[ "$PREFIX" != */* && "$PREFIX[1]" = '~' ]]; then
> -    compset -p 1
> -    compstate[context]=tilde
> +    if [[ "$PREFIX" = '~['[^\]]## ]]; then
> +      # Inside ~[...] should be treated as a subscript.
> +      compset -p 2
> +      # To be consistent, we ignore all but the contents of the square
> +      # brackets.
> +      compset -S '\]*'
> +      compstate[context]=subscript
> +      [[ -n $_comps[-subscript-] ]] && $_comps[-subscript-] && return
> +    else
> +      compset -p 1
> +      compstate[context]=tilde
> +    fi
>    fi
>  fi
>
> diff --git a/Completion/Zsh/Context/_subscript b/Completion/Zsh/Context/_subscript
> index 0c9a89ad5..0d9632864 100644
> --- a/Completion/Zsh/Context/_subscript
> +++ b/Completion/Zsh/Context/_subscript
> @@ -1,6 +1,8 @@
>  #compdef -subscript-
>
> -local expl ind osuf=']' flags sep
> +local expl ind osuf flags sep
> +
> +[[ $ISUFFIX = *\]* ]] || osuf=\]
>
>  if [[ "$1" = -q ]]; then
>    compquote osuf
> diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr
> index cb72e4600..b653e7c38 100644
> --- a/Functions/Chpwd/zsh_directory_name_cdr
> +++ b/Functions/Chpwd/zsh_directory_name_cdr
> @@ -16,8 +16,10 @@ elif [[ $1 = c ]]; then
>      typeset -a keys values
>      values=(${${(f)"$(cdr -l)"}/ ##/:})
>      keys=(${values%%:*})
> +    local addsuffix
> +    [[ $ISUFFIX = *\]* ]] || addsuffix='-S]'
>      _describe -t dir-index 'recent directory index' \
> -      values -V unsorted -S']'
> +      values -V unsorted $addsuffix
>      return
>    fi
>  fi
> diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
> index 8c0534708..1622d8a6b 100644
> --- a/Src/Zle/zle_main.c
> +++ b/Src/Zle/zle_main.c
> @@ -1067,6 +1067,7 @@ redrawhook(void)
>         int old_incompfunc = incompfunc;
>         char *args[2];
>         Thingy lbindk_save = lbindk, bindk_save = bindk;
> +       struct modifier zmod_save = zmod;
>
>         refthingy(lbindk_save);
>         refthingy(bindk_save);
> @@ -1094,6 +1095,7 @@ redrawhook(void)
>          * restore lastcmd manually so that we don't mess up the global state
>          */
>         lastcmd = lastcmd_prev;
> +       zmod = zmod_save;
>      }
>  }


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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-03-31  8:10   ` Marlon Richert
@ 2021-03-31  8:25     ` Peter Stephenson
  2021-03-31  8:29       ` Marlon Richert
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2021-03-31  8:25 UTC (permalink / raw)
  To: Marlon Richert, Zsh hackers list

> On 31 March 2021 at 09:10 Marlon Richert <marlon.richert@gmail.com> wrote:
> Could someone please review Peter's patch, below?

This change is already in.

pws


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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-03-31  8:25     ` Peter Stephenson
@ 2021-03-31  8:29       ` Marlon Richert
  2021-03-31  8:37         ` Marlon Richert
  0 siblings, 1 reply; 7+ messages in thread
From: Marlon Richert @ 2021-03-31  8:29 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, Mar 31, 2021 at 11:25 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> > On 31 March 2021 at 09:10 Marlon Richert <marlon.richert@gmail.com> wrote:
> > Could someone please review Peter's patch, below?
>
> This change is already in.

Really? I don't see it in Src/Zle/zle_main.c on the master branch.


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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-03-31  8:29       ` Marlon Richert
@ 2021-03-31  8:37         ` Marlon Richert
  2021-03-31  8:56           ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Marlon Richert @ 2021-03-31  8:37 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, Mar 31, 2021 at 11:29 AM Marlon Richert
<marlon.richert@gmail.com> wrote:
>
> On Wed, Mar 31, 2021 at 11:25 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> > > On 31 March 2021 at 09:10 Marlon Richert <marlon.richert@gmail.com> wrote:
> > > Could someone please review Peter's patch, below?
> >
> > This change is already in.
>
> Really? I don't see it in Src/Zle/zle_main.c on the master branch.

You are right that the other changes are in. Sorry, I only checked
`git log -L 1060,1100:Src/Zle/zle_main.c` and when that failed to show
any changes, I assumed that the whole patch had not been applied yet.

However, why apply only the changes in the other files and not the one
in Src/Zle/zle_main.c ? Is that intentional or an oversight?


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

* Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty
  2021-03-31  8:37         ` Marlon Richert
@ 2021-03-31  8:56           ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2021-03-31  8:56 UTC (permalink / raw)
  To: Marlon Richert, Zsh hackers list

> On 31 March 2021 at 09:37 Marlon Richert <marlon.richert@gmail.com> wrote:
> On Wed, Mar 31, 2021 at 11:29 AM Marlon Richert
> <marlon.richert@gmail.com> wrote:
> >
> > On Wed, Mar 31, 2021 at 11:25 AM Peter Stephenson
> > <p.w.stephenson@ntlworld.com> wrote:
> > > > On 31 March 2021 at 09:10 Marlon Richert <marlon.richert@gmail.com> wrote:
> > > > Could someone please review Peter's patch, below?
> > >
> > > This change is already in.
> >
> > Really? I don't see it in Src/Zle/zle_main.c on the master branch.
> 
> You are right that the other changes are in. Sorry, I only checked
> `git log -L 1060,1100:Src/Zle/zle_main.c` and when that failed to show
> any changes, I assumed that the whole patch had not been applied yet.
> 
> However, why apply only the changes in the other files and not the one
> in Src/Zle/zle_main.c ? Is that intentional or an oversight?

Apologies, that was intentional because I realised the diff I sent included
some old stuff which actually wasn't needed. The zle_main.c chunk in the
patch is irrelevant to the fix.

pws


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

end of thread, other threads:[~2021-03-31  8:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 14:37 Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty Marlon Richert
2021-01-25 15:07 ` Peter Stephenson
2021-03-31  8:10   ` Marlon Richert
2021-03-31  8:25     ` Peter Stephenson
2021-03-31  8:29       ` Marlon Richert
2021-03-31  8:37         ` Marlon Richert
2021-03-31  8:56           ` Peter Stephenson

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git