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

Syntax-highlighting of command will disappear after an unsuccessful completion #919

Open
LuckyWindsck opened this issue Mar 21, 2023 · 6 comments

Comments

@LuckyWindsck
Copy link

Unexpected behavior

After I input something and pressed tab key for completion, if the completion failed, the highlighting of command would disappear.

For example, I have installed this plugin through antigen, and installed Homebrew as well as its zsh completion.

First, I typed brew z
image

and then I pressed tab key for completion.
Note that Homebrew doesn't have a subcommand started with z, so the completion will somehow fail.
Now the syntax highlighting of command brew disappeared.
image

If I try something like brew i, then press tab, this time the completion will be successful. A completion list of subcommand started with i will be displayed, and the syntax-highlighting work as expected.
image

Workaround

I am using oh-my-zsh. I found that if I uncomment the following line in the default ~/.zshrc, the problem stated above will be solved.

# COMPLETION_WAITING_DOTS="true"

I have investigated the COMPLETION_WAITING_DOTS feature of oh-my-zsh, but I cannot find anything useful to figure out the cause of unexpected behavior.

Environment

Operating System: macOS 12.6.3
Zsh: zsh 5.8.1 (x86_64-apple-darwin21.0)
zsh-users/zsh-syntax-highlighting: b2c910a (commit hash)
Antigen: v2.2.3 (ff391b5)
Homebrew: 4.0.9

@LuckyWindsck
Copy link
Author

I just found that this is a duplicate issue of #90 (as well as #102 and #113).
However all of them are closed and this problem still exists. I am not really sure what happened.

@LuckyWindsck
Copy link
Author

LuckyWindsck commented Aug 20, 2023

It seems like that the default zle widget of tab key ("^I") is expand-or-complete, and invoking the redisplay widget after expand-or-complete widget can solve this problem.

This is how Oh My Zsh implements the expand-or-complete-with-dots widget, and bind it to tab key ("^I").

So anyone who has similar problem can just use the workaround states above, or follow Oh My Zsh to define a zle widget like this:

expand-or-complete-then-redisplay() {
  zle expand-or-complete
  zle redisplay
}

zle -N expand-or-complete-then-redisplay

# Set the function as the default tab completion widget
bindkey "^I" expand-or-complete-with-dots

@phy1729
Copy link
Member

phy1729 commented Aug 20, 2023

#90 was closed by c14fcad because highlighting does not disappear when using add-zle-hook-widget. However, we need the memo feature, so using add-zle-hook-widget is gated behind a version check for 5.9 or later. If you use the homebrew version of zsh, you shouldn't keep seeing this.

@LuckyWindsck
Copy link
Author

@phy1729: If you use the homebrew version of zsh, you shouldn't keep seeing this.

I am using the default version of zsh provided by macOS, should I installed another zsh via homebrew and use that?

@phy1729
Copy link
Member

phy1729 commented Aug 20, 2023

As long at you're using at least zsh 5.9, the add-zle-hook-widget way of running will be used and the issue should no longer appear.

@LuckyWindsck
Copy link
Author

@phy1729: As long at you're using at least zsh 5.9, the add-zle-hook-widget way of running will be used and the issue should no longer appear.

I will try a newer version of zsh later. Thanks for your help.
If this solve the problem, I will close this issue.

$ echo $SHELL     
/bin/zsh
$ $SHELL --version
zsh 5.8.1 (x86_64-apple-darwin21.0)

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

No branches or pull requests

2 participants