Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug report: Completion for dynamically named dirs fails when $SUFFIX is not empty



It's still not working correctly in Zsh 5.9. Now compstate[context]
becomes `command` instead of `subscript` when $RBUFFER starts with a
non-space character.

On Mon, Jan 25, 2021 at 5:07 PM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> > On 21 January 2021 at 14:37 Marlon Richert <marlon.richert@xxxxxxxxx> 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;
>      }
>  }




Messages sorted by: Reverse Date, Date, Thread, Author