-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
history-incremental-pattern-search-backward is broken after upgrading to zsh 5.3.1 #407
Comments
I use [zim](https://github.com/Eriner/zim). When I disable `zsh-syntax-highlighting`, pattern searching works again. I tried creating a new minimal zsh install, that did not source `zim` at all. As soon as I directly source `zsh-syntax-highlighting`, pattern searching breaks again. Unlike issue #387, I'm *not* using `zsh-autocorrect`.
I cannot reproduce this.
zsh -f
bindkey ^R history-incremental-pattern-search-backward
source ./zsh-syntax-highlighting.zsh
: foo
: bar
: baz
<^R>ba?<^R><^R><^R>
Can you please post a minimal example starting from `zsh -f`?
With as few third party modules as possible, please.
|
Oddly enough, your example fails for me!
I type
Then again
And it's stuck on I tested (from the start) searching with I wasn't previously familiar with |
And it's stuck on `baz`, and never gets to `bar`.
I tested (from the start) searching with `ba` instead of `ba?`, which also fails. I then tested `ba` using the default `history-incremental-search-backward`, which works as expected.
So, to clarify, you're saying that a search for just `ba` with pattern search finds baz but not bar?
I wasn't previously familiar with `zsh -f`, but my understanding is that it skips all initiation files except for the system-wide `zshenv`.
Correct.
However, I don't have any file on my system named that anyway. I'm not sure how else my system might differ from yours.
Distros sometimes change the path of zshenv to /etc/zsh/zshenv or similar. What does `zsh -fx` print before the first prompt?
What versions of everything do you use? I use:
% print -rl -- $ZSH_VERSION $ZSH_PATCHLEVEL $ZSH_HIGHLIGHT_VERSION $ZSH_HIGHLIGHT_REVISION
5.3.1-dev-0
zsh-5.3.1-1-gfa88f57
0.6.0-dev
aac4a44
Does your distro patch zsh?
Do you have more than one zsh binary on your system?
|
Correct.
Sorry, I should have been more specific.
Nothing at all.
Looks like the zsh version is slightly different to yours, but I am using the latest release. I can try the latest
It looks like it does some minimal patching, but I'm not sure if this has any effect.
No, just the one. |
```
% print -rl -- $ZSH_VERSION $ZSH_PATCHLEVEL $ZSH_HIGHLIGHT_VERSION $ZSH_HIGHLIGHT_REVISION
5.3.1
zsh-5.3.1-0-g06b1b7a
0.6.0-dev
aac4a44
```
Looks like the zsh version is slightly different to yours, but I *am* using the latest release. I can try the latest `-git` release if you think that might be more consistent with yours?
There's no need; the only difference between zsh-5.3.1-0-g06b1b7a and zsh-5.3.1-1-gfa88f57 is a patch that changes the version number reporting. (zsh-users/zsh@fa88f57)
>Does your distro patch zsh?
It looks like it does some minimal [patching](https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/zsh), but I'm not sure if this has any effect.
Nothing there accounts for the difference.
*sigh*
I see the problem. I was testing not with
aac4a44 but with that plus a local mod:
```diff
diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index 0251d1e..cce6669 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -67,7 +67,7 @@ _zsh_highlight()
# Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
# For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
- if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then
+ if [[ $WIDGET == zle-isearch-update ]]; then
region_highlight=()
return $ret
fi
```
I can reproduce your behaviour when I revert that change.
That change is a rebase artifact from one of @movie's pull requests (#288 or thereabouts; the referenced FAQ entry — "Does syntax highlighting work during incremental history search?" in README.md — points to that issue, too).
@m0vie, do you recall the background here? Did @protist's use-case work at some point during 0.5.0 development? Can it be made to work (without disabling syntax highlighting)?
|
This is actually an upstream bug. Minimal example without z-sy-h to reproduce:
The cause is that iseach uses the global I sent a patch to workers@. This bug got introduced in #288, because we deliberately hooked Question now is: Can we do anything on z-sy-h's side to prevent triggering this? This (pseudocode) should technically do it,
since we (luckily) don't use any patterns before it. Of course we'd lose z-sy-h's coloring again until then. |
This is actually an upstream bug.
Thanks for the quick resposne and analysis.
Minimal example without z-sy-h to reproduce:
: ⋮
': foo' is found instead of ': bar' because evil_hook modified the
static pattern used in isearch.
I can reproduce that on 5.3.1.
The cause is that iseach uses the global `PAT_STATIC` pattern. But inside the `zle-isearch-hook` any function that uses patterns, too, will overwrite that pattern.
I sent a patch to ***@***.***
Wonderful. (It hasn't appeared in the archives yet so can't link to it.)
This bug got introduced in #288, because we deliberately hooked `zle-isearch-update` to fix another bug.
If a user would have hooked `zle-isearch-update` himself already, the bug would have already surfaced before.
Question now is: Can we do anything on z-sy-h's side to prevent triggering this?
Can we dynamically probe for the bug? E.g., is there some
.
a=(); : $a[(r)foo*]; [[ bar = … ]]; echo $?
.
construct that gives different results with and without the upstream
patch?
Even if we wanted to fix this only for history-incremental-pattern-search-backward,
and even if we had access to the pattern entered in the minibuffer,
testing whether $BUFFER matches that pattern would not suffice (it would
be a one-sided test, specific but not sensitive, e.g., if the history
had been `: foo bar', `: bar', `: baz' in your example)).
This (pseudocode) should technically do it,
````
- if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then
+ if [[ $WIDGET == zle-isearch-update ]] && ! zsh_bug_is_fixed; then
````
since we (luckily) don't use any patterns before it.
"Luckily", aye. But that's bound to change... (and let's not say
anything about signal handlers firing asynchronously)
Of course we'd lose z-sy-h's coloring again until then.
If we have to choose between correctness and coloring, we should choose correctness.
Thanks again for getting to the bottom of this.
|
Fixed in upstream with |
Fixed in upstream with
zsh-users/zsh@48cadf4
http://www.zsh.org/mla/workers//2017/msg00034.html
That should be included in upstream 5.3.2 or 5.4 (whichever comes first).
Have you made progress on probing for this bug at runtime, or some other workaround for ≤5.3.1?
|
Further discussion on http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=40328 (same thread, but the web archive doesn't join it) |
Thank you for the quick fix upstream, but is there a way to get it working in the meantime? Thanks in advance. |
>Have you made progress on probing for this bug at runtime, or some other workaround for ≤5.3.1?
Thank you for the quick fix upstream, but is there a way to get it working in the meantime? Thanks in advance.
No runtime probe has been devised, and is-at-least wouldn't be right since some distros have backported the upstream fix to 5.3.1.
I'm not sure I have a good suggestion here. Would it work for you to just locally remove the `&& ! (( $+ISEARCHMATCH_ACTIVE ))` clause?
|
Oh yes, sorry. For some reason I forgot to try that. Yes, that certainly works; thank you. Are there any negative ramifications for removing this? |
> I'm not sure I have a good suggestion here. Would it work for you to just locally remove the `&& ! (( $+ISEARCHMATCH_ACTIVE ))` clause?
Oh yes, sorry. For some reason I forgot to try that. Yes, that certainly works; thank you. Are there any negative ramifications for removing this?
During isearch, there will be no highlighting at all.
You'll want to remember to revert your local mod when you upgrade to zsh≥5.3.2.
|
Thank you again. IMO I'm happy to close this issue now, unless you prefer it open until the fix is released. |
You're welcome. Closing, but if anyone has an idea for a runtime probe, please add it in comments. |
re: probe
I would argue that turning this off for versions less than 5.3.2 would be acceptable, since "breaking regex incremental search" is worse than "no highlighting during incremental search". When the first happens, its hard to figure out why. When highlighting goes away, you know why. This would work, though I don't know how slow
|
Good point. Reopening. If |
@danielshahaf: Should I make a pull request with my simplistic change from above:question: |
@docwhat A PR would be welcome — especially if it updates https://github.com/zsh-users/zsh-syntax-highlighting/#does-syntax-highlighting-work-during-incremental-history-search too ☺. If you see any way to do a runtime probe, that'd be even better; the relevant code is around https://github.com/zsh-users/zsh/blob/bb6c08b51a0798700b6fdd0b75581dca21dc4e5b/Src/Zle/zle_hist.c#L1220. Thanks! P.S. How about checking |
Do distros bump the 4th version number? If so, I don't know what the state of various distros are (e.g. they may have a 5.3.1.1 out already without this patch). I'd rather err on the side of caution, as I said, since tracking down the regexp-search-is-broken case is so difficult (it's involved weeks of my time over the last 6-8 months). |
@danielshahaf: PR #415 is created. |
> How about checking is-at-least 5.3.1.1, rather than 5.3.2? Just in case. (Not 5.3.1.0 because is-at-least ignores trailing zero components)
Do distros bump the 4th version number? If so, I don't know what the state of various distros are (e.g. they may have a 5.3.1.1 out already without this patch).
Distros generally add their version number after a hyphen in the package
but keep $ZSH_VERSION at its upstream value, so a 5.3.1.1 could only be
a future upstream release. (That's if pws doesn't call it 5.3.2 or 5.4,
which are progressively more likely.)
I think it's pretty common to run z-sy-h HEAD and zsh from the distro,
so if distros do change $ZSH_VERSION that'd be something we would want
to take into account.
I'd rather err on the side of caution, as I said, since tracking down the regexp-search-is-broken case is so difficult (it's involved weeks of my time over the last 6-8 months).
I think an upstream 5.3.1.1 is very unlikely, so in practice it wouldn't
matter whether we test for 5.3.1.1 or 5.3.2. Given your erring-on-the-side-of-caution
point, I'd be fine with either version number as the threshold.
|
I might be completely off target, but are there even zsh x.y.z.a releases? I think zsh just uses x.y.z? |
@protist Correct. The argument for 5.3.1.1 over 5.3.2 is that it would be correct even if zsh started using x.y.z.w. The arguments for 5.3.2 over 5.3.1.1 are that it suffices given upstream's release numbering policy (as you say) and that it's better to be conservative due to the asymmetric failure modes (as pointed out by @docwhat). |
Just to update everyone, the |
Just to update everyone, the `zsh` patch has hit [Arch Linux](https://git.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/zsh&id=0e7db42263c914ae4c7b3c74df1e6c756c94fe8b) in `5.3.1-2`. I can confirm that `history-incremental-pattern-search-backward` still works even after reverting the z-s-h hack from [this comment](#407 (comment)). Thanks again!
Thank you for the update.
Debian has also backported @m0viefreak's patch, in zsh 5.3.1-3.
|
No worries.
I'm mortified that Debian was quicker than Arch with this! 😧 |
ZSH versions less than 5.3.2 (or 5.4) have a bug that prevents `history-incremental-pattern-search-backward` for working correctly (the history stops searching after the first found item). Closes zsh-users#407
I recently upgraded zsh from 5.2-2 -> 5.3.1-1, in Arch Linux. After upgrading,
history-incremental-pattern-search-backward
andhistory-incremental-pattern-search-forward
no longer work. That is, they show the most recent match, thenfailing bck-i-search: foo
, then one other match from eons ago, then it fails to find any more. Reverting to zsh 5.2-2 fixes this problem.I use zim. When I disable
zsh-syntax-highlighting
, pattern searching works again. I tried creating a new minimal zsh install, that did not sourcezim
at all. As soon as I directly sourcezsh-syntax-highlighting
, pattern searching breaks again. Unlike issue #387, I'm not usingzsh-autocorrect
.The text was updated successfully, but these errors were encountered: