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

workaround for PAT_STATIC bug in zsh #415

Merged
merged 1 commit into from
Mar 29, 2017
Merged

workaround for PAT_STATIC bug in zsh #415

merged 1 commit into from
Mar 29, 2017

Conversation

docwhat
Copy link
Contributor

@docwhat docwhat commented Feb 7, 2017

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 #407

@m0vie
Copy link
Contributor

m0vie commented Feb 7, 2017

Isn't is-at-least itself using patterns and therefore causing the exact same bug it tries to prevent?

We should probably determine and remember this beforehand when sourcing z-sy-h, also for performance reasons.

@docwhat
Copy link
Contributor Author

docwhat commented Feb 7, 2017

@m0vie as soon as I read your comment, I realized you had to be right. I double checked in my plain-vanilla "fake" config and my work-around didn't work.

I pushed up a revised version that stores the value and uses that. It's also easier to read, which I like.

@danielshahaf
Copy link
Member

@m0vie Thanks for reviewing.

@docwhat Besides my other comment (just posted), I have only a few minor style tweaks. Will go through them once the functionality is settled.

@danielshahaf
Copy link
Member

@docwhat Feel free to join us on #zsh-syntax-highlighting on freenode.

Copy link
Member

@danielshahaf danielshahaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, @docwhat.

Would you be able to revise the PR accordingly? No problem if you can't, just please let me know either way.

README.md Outdated
or newer.
Yes!

If you're using `history-incremental-search-backward` (by default bound to <kbd>Ctrl_R</kbd>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what was the reasoning behind the change of Ctrl_R to Ctrl+R. (Not need to revert it — six of one, half a dozen of the other — just curious.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on my part. :-/

README.md Outdated
in zsh's emacs keymap) then it works with _zsh version 5.3 and newer_.

If you're using `history-incremental-pattern-search-backward`, then syntax highlighting works
in _zsh 5.3.2 and newer_ due to [a bug](http://www.zsh.org/mla/workers//2017/msg00034.html).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the X-Seq links: http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=40285

Could we qualify the term "bug" to explain it's an upstream (zsh) bug?

Could we reword this to reflect that 5.3.2 is not yet released (and will probably be called 5.4)? I'll update #412 to refer to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it describes what the code does...

  • Will zsh ever release a 5.3.2?
  • If so, would it just include security patches, or would it include this patch to?
  • Should I just change the is-at-least to 5.4?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(being discussed in the toplevel comments below)

zsh_highlight__pat_static_bug=f
else
zsh_highlight__pat_static_bug=t
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I like lisp, I think the code would be overall easier to read if it used only a single representation of booleans. We already both x=false/x=true/if $x and x=0/x=1/if (( x )) [my fault for having two]; I'd rather not introduce a third way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -67,7 +76,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 ]] && ([[ $zsh_highlight__pat_static_bug == t ]] || ! (( $+ISEARCHMATCH_ACTIVE )) ); then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a block { … } rather than a subshell.

Also, I'd like some comment explaining the second conjunct in English: it's hard enough for me to get a mental picture of the behaviour under various zsh versions as the conjunct stands before this patch.

The logic here is "Disabling highlighting during isearch (for reasons explained in README.md) unless zsh is new enough and doesn't have the 5.3.1 bug".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -53,6 +53,15 @@ fi
# Core highlighting update system
# -------------------------------------------------------------------------------------------------

# Use workaround for bug in ZSH?
# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html
autoload -U is-at-least
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another autoload is-at-least on line 397 which can be removed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@danielshahaf danielshahaf added this to the 0.6.0 milestone Feb 9, 2017
@danielshahaf danielshahaf mentioned this pull request Feb 9, 2017
2 tasks
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 #407
@docwhat
Copy link
Contributor Author

docwhat commented Feb 9, 2017

Pulling this out for visibility... The current change has everything you asked for except this...

@danielshahaf said:

Could we reword this to reflect that 5.3.2 is not yet released (and will probably be called 5.4)? I'll update #412 to refer to this.

Right now it describes what the code does...

  • Will zsh ever release a 5.3.2?
  • If so, would it just include security patches, or would it include this patch to?
  • Should I just change the is-at-least to 5.4?

in zsh's emacs keymap) then it works with _zsh version 5.3 and newer_.

If you're using `history-incremental-pattern-search-backward`, then syntax highlighting works
in _zsh 5.3.2 and newer_ due to [a bug in zsh](http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=40285).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history-incremental-search-backward or history-incremental-pattern-search-backward doesn't matter, we don't check for that. Its 5.3.2 and newer in all cases

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information in the readme is still wrong. See my comment above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Broke this out as #423

@@ -67,7 +76,9 @@ _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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a comment here stating that we must never use any pattern before this line, in order to not break things again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m0vie At this point it may be easier to ask pws to release a 5.3.2 with your patch (and other stability fixes) included?

@danielshahaf
Copy link
Member

@docwhat The next zsh feature release will be 5.4. There may be a 5.3.2 hotfix release before then. In principle, zsh may decide to release a 5.3.1.1, but that's unlikely. And in either of the three cases, we can't be sure whether the release would fix the PAT_STATIC bug: @m0vie's patch might be reverted or the bug accidentally reintroduced before upstream's release.

Now, I won't release z-sy-h with an is-at-least condition that refers to a future zsh release, and people who use zsh from master should use HEAD of master; therefore, I think it doesn't matter what version number we pass to is-at-least, so long as we have a note on #412 to fix it after zsh's release and before z-sy-h's release.

Makes sense?

@docwhat
Copy link
Contributor Author

docwhat commented Feb 13, 2017

@danielshahaf:

Just so I understand what my action item is: I should set the is-at-least check to 5.3.1.1 (as you suggested previously?

Can we push zsh to release 5.3.2 sooner rather than later and release it with that version check (as you mentioned above)?

@danielshahaf
Copy link
Member

danielshahaf commented Feb 14, 2017 via email

@docwhat
Copy link
Contributor Author

docwhat commented Mar 29, 2017

It's been a while, @danielshahaf -- Is there anything else I need to do with this PR? Or are we still good?

@danielshahaf
Copy link
Member

danielshahaf commented Mar 29, 2017

@danielshahaf danielshahaf merged commit 835fec7 into zsh-users:master Mar 29, 2017
@danielshahaf
Copy link
Member

@docwhat Apologies for dropping the ball. Merged this and updated #415 accordingly.

If anyone wants to push upstream for a 5.3.2 (as per my penultimate comment), feel free :-)

@danielshahaf danielshahaf mentioned this pull request Mar 30, 2017
@docwhat
Copy link
Contributor Author

docwhat commented Apr 5, 2017

@docwhat Apologies for dropping the ball.

No apologies necessary! Thanks!

@docwhat docwhat deleted the pr/pat_static branch April 5, 2017 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants