Skip to content

Unsuccessful completion removes highlighting #90

Closed
@hedning

Description

@hedning

If completion returns an error all highlighting will be removed.
Eg. failed file expansion cat filethatdoesntexist<tab>

This patch fixes it:

diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh
index cbd63e9..4ad0106 100644
--- a/zsh-syntax-highlighting.zsh
+++ b/zsh-syntax-highlighting.zsh
@@ -105,9 +105,12 @@ typeset -gA ZSH_HIGHLIGHT_STYLES
 # Whether the command line buffer has been modified or not.
 #
 # Returns 0 if the buffer has changed since _zsh_highlight was last called.
+# This doesn't work reliably. As the buffer might be modified, but without
+# changing the text content. Eg. when file expansion fail when
+# autocompelting.
 _zsh_highlight_buffer_modified()
 {
-  [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]]
+  true
 }

 # Whether the cursor has moved or not.
@@ -147,7 +150,7 @@ _zsh_highlight_bind_widgets()

       # Completion widget: override and rebind old one with prefix "orig-".
       completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
-                          _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
+                          _zsh_highlight_widget_$cur_widget() { { builtin zle orig-$cur_widget -- \"\$@\"; } always { _zsh_highlight; } }; \
                           zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;

       # Builtin widget: override and make it call the builtin ".widget".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions