Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consecutive delete-words do not get yanked consecutively #150

Closed
eras opened this issue Sep 25, 2014 · 10 comments
Closed

Consecutive delete-words do not get yanked consecutively #150

eras opened this issue Sep 25, 2014 · 10 comments

Comments

@eras
Copy link

eras commented Sep 25, 2014

Steps to reproduce:

  1. enter "hello hello" to prompt
  2. press ^W ^W, both hellos are removed
  3. press ^Y and witness one 'hello' coming back

Expected behavior: "hello hello" would come back (works if zsh-syntax-highlighting is not enabled)

I sort of hoped #143 would have fixed this but no :).

eras pushed a commit to eras/zsh-syntax-highlighting that referenced this issue Sep 25, 2014
…andled zle widgets

This restores the ability to consecutively delete (ie.) words and
have them come back consecutively in the next yank.
vincentbernat added a commit to vincentbernat/zsh-syntax-highlighting that referenced this issue Feb 5, 2015
Otherwise, we can't do `echo hello hello^W^W^Y` and get back `echo hello
hello` (we get `echo hello` instead because ZLE doesn't detect two
consecutive calls to backward-kill-word).

I don't add more to this commit because other `*-kill-*` are less likely
to be used twice in a row when working with the shell. But maybe,
`kill-line` could be added too.

Closes zsh-users#150.
@danielshahaf
Copy link
Member

I'm inclined to call this a zsh bug. With zsh-5.1-1-ga9df6aa:

$ zsh -f
% bindkey -e
% f() { zle .backward-kill-word }
% zle -N backward-kill-word f
% echo foo bar<^W><^W><^Y>
% echo foo <CURSOR>

Without the f() wrapper, the last line has echo foo bar. (Thanks to @vincentbernat for pointing this out on #160.)

@eras @vincentbernat Would you mind reporting this to the zsh project?

@danielshahaf
Copy link
Member

This seems to be caused by the ZLE_KILL flag, which is tested in the cuttext() C function in ZLE: backward-kill-word (used in emacs mode) has that flag, but the wrapper function f doesn't, nor does the vi mode equivalent vi-backward-kill-word. The lack of that flag causes $CUTBUFFER (cutbuf in C) to be emptied before inserting the second-deleted word to it.

So one way to solve the problem would be to use @Mikachu's zle -P / zle -f patches (reposted) to set the ZLE_KILL flag on the wrapper widgets which zsh-syntax-highlighting creates.

@danielshahaf
Copy link
Member

Confirmed: Mikael's workers/36709 plus danielshahaf@bfa71c9 fix this issue.

Once Mikael's patch is merged to zsh, we can merge that bfa71c9 here and close this issue as fixed.

[edit: these patches fix issue #183 as well)

@danielshahaf
Copy link
Member

workers/36709 was merged in zsh-users/zsh@a855d7b. The way forward is either:

@ionsquare
Copy link

ionsquare commented Sep 8, 2017

Any update on this? I tried adding danielshahaf/zsh-syntax-highlighting@bfa71c9 but get _zsh_highlight:100: bad option: -f whenever I kill words and I don't know enough to fix it.

@danielshahaf
Copy link
Member

tl;dr: You need to upgrade zsh to 5.2.

The log message of that commit states that it depends on a zsh commit; that zsh commit was first released in 5.2 (more precisely, in the 5.1.1-test-* prereleases that preceded it):

% git log --grep=36709 
commit a855d7bd246ef44d5393c3088aae8214d41d2b85
Author: Mikael Magnusson <mikachu@gmail.com>
Date:   Tue Sep 29 06:11:24 2015 +0200

    36709: zle -f from inside widget to set flags and make yank start/end zle params writable
% git tag --contains=a855d7bd246ef44d5393c3088aae8214d41d2b85
5.1.1-test-2
zsh-5.1.1-test-1
zsh-5.1.1-test-2
zsh-5.1.1-test-3
zsh-5.2
⋮

@psprint
Copy link
Contributor

psprint commented Feb 23, 2020

Has the issue been resolved? I've tested HEAD and it doesn't seem to.

@danielshahaf
Copy link
Member

The issue is not fixed on current master, but is fixed on the redrawhook branch, which is scheduled to be merged at some point after 0.7.0. (IIRC, this issue was fixed on master at some point, but the fix was later reverted; this is why this issue was closed and then reopened.)

@psprint
Copy link
Contributor

psprint commented Feb 25, 2020

OK, thanks.

@danielshahaf
Copy link
Member

When redrawhook is merged, this issue will be closed as fixed, though the fix will require zsh 5.9 (not yet released). If anyone needs a fix for older versions of zsh, look into writing a pull request around zle -f (see above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants