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

Re: zstyle ':completion:*' menu select=4 interactive



Daniel Shahaf wrote on Mon, 16 Nov 2020 17:47:24 +0000:
> Thomas Lauer wrote on Sat, 14 Nov 2020 10:36 +0000:
> > Here's another long-standing problem I am having with zsh. I have
> > googgled for hours but found nothing (Google search these days is like
> > a cat: it brings home loads of things it thinks will please you but
> > which are not really what you were looking for. Google just knows
> > better than we do what we're searching for... But I digress.).
> > 
> > I have the subject line in my .zshrc (BTW this is 5.7.1). The tab is
> > bound to expand-or-complete-prefix. The trouble starts when the
> > interactive part of this kicks in, ie there are four or more items (if
> > there are fewer, all works fine) and if the cursor is somewhere in the
> > middle of a line I am editing.
> > 
> > So I do get the menu and I start navigating, with my current choice
> > being copied into the line that's edited. The problem is that this
> > choice overwrites part of the line I am editing. Consider this:
> > 
> > $ bla D<tab> somestuff # cursor behind the D when I press tab)
> > 
> > I get a few choices (say "D1/ Documents/ Dz2/ Dz3/ ..."), but nothing is
> > as yet inserted into the line. Now I press <right> and "Documents/" gets
> > inserted, overwriting the first few characters of somestuff. The line
> > now looks like this:
> > 
> > $ bla Documents/estuff # cursor behind the /)
> > 
> 
> What happens if you press ^L (clear-screen) at this point?

The screen clears and the prompt and line are reprinted with the same
problem.

> Can you reproduce this from 'zsh -f'?

Well, a bare -f doesn't do interactive menus so the problem doesn't
occur. I've tried to create a minimal .zshrc that shows the problem but
have not got very far.

> > Not what I want. So I have done an ugly hack to sort of solve this:
> > 
> > ugly() {
> > 	[[ ! -z $RBUFFER ]] && RBUFFER="          $RBUFFER"
> > 	zle expand-or-complete-prefix
> > }  
> > ...
> > zle -N ugly
> > 
> > with ugly() bound to the tab key. This (sort of) works but it's
> > pretty 'orrible.
> > 
> 
> Well, for starters:
> 
> ugly() {
>   local save_RBUFFER=$RBUFFER
>   RBUFFER=
>   { zle expand-or-complete-prefix -- "$@" } always { RBUFFER=$save_RBUFFER }
> }
> 
> Not tested.

That's nifty. I've combined it with my ugly hack as I've now done more
than enough attempts to analyse this thing and have realised that zsh is
always overwriting the first three characters, no matter how long the
inserted string is.

So the final version is:

ugly() {
  local save_RBUFFER=$RBUFFER
  RBUFFER="   $RBUFFER"
  { zle expand-or-complete-prefix -- "$@" } always { RBUFFER=$save_RBUFFER }
}

Works perfect :-) And thanks for the help.

-- 
Tom




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