zsh-users
 help / color / mirror / Atom feed
* zstyle ':completion:*' menu select=4 interactive
@ 2020-11-14 10:36 Thomas Lauer
  2020-11-16 17:47 ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lauer @ 2020-11-14 10:36 UTC (permalink / raw)
  To: zsh-users

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 /)

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.

I'm sure the zsh gurus have an idea what's going on here and can
point out the problem :-) 

-- 
Tom


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

* Re: zstyle ':completion:*' menu select=4 interactive
  2020-11-14 10:36 zstyle ':completion:*' menu select=4 interactive Thomas Lauer
@ 2020-11-16 17:47 ` Daniel Shahaf
  2020-11-17 11:34   ` Thomas Lauer
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2020-11-16 17:47 UTC (permalink / raw)
  To: Thomas Lauer; +Cc: zsh-users

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?

Can you reproduce this from 'zsh -f'?

> 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.

> I'm sure the zsh gurus have an idea what's going on here and can
> point out the problem :-) 
> 



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

* Re: zstyle ':completion:*' menu select=4 interactive
  2020-11-16 17:47 ` Daniel Shahaf
@ 2020-11-17 11:34   ` Thomas Lauer
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Lauer @ 2020-11-17 11:34 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-users

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


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

end of thread, other threads:[~2020-11-17 11:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14 10:36 zstyle ':completion:*' menu select=4 interactive Thomas Lauer
2020-11-16 17:47 ` Daniel Shahaf
2020-11-17 11:34   ` Thomas Lauer

zsh-users

This inbox may be cloned and mirrored by anyone:

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

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

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


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