Skip to content

Commit

Permalink
always bind zle-line-finish and use it instead of accept-*
Browse files Browse the repository at this point in the history
Special handling for cursor imprint or partial path highlighting
is needed in more cases than accept-*. For example when accepting
a line from isearch, no accept-* widget is invoked.

The proper way is to use zle-line-finish.

Trumps #259.
Fixes #284.
  • Loading branch information
m0vie committed Apr 29, 2016
1 parent 1d855a3 commit 2ba33bb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 3 additions & 4 deletions highlighters/cursor/cursor-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
# Whether the cursor highlighter should be called or not.
_zsh_highlight_cursor_highlighter_predicate()
{
# accept-* may trigger removal of cursor highlighting
[[ $WIDGET == accept-* ]] ||
_zsh_highlight_cursor_moved
# remove cursor highlighting when the line is finished
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved
}

# Cursor highlighting function.
_zsh_highlight_cursor_highlighter()
{
[[ $WIDGET == accept-* ]] && return
[[ $WIDGET == zle-line-finish ]] && return

_zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor
}
7 changes: 3 additions & 4 deletions highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@
# Whether the highlighter should be called or not.
_zsh_highlight_main_highlighter_predicate()
{
# accept-* may trigger removal of path_prefix highlighting
[[ $WIDGET == accept-* ]] ||
_zsh_highlight_buffer_modified
# may need to remove path_prefix highlighting when the line ends
[[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified
}

# Helper to deal with tokens crossing line boundaries.
Expand Down Expand Up @@ -485,7 +484,7 @@ _zsh_highlight_main_highlighter_check_path()

# If this word ends the buffer, check if it's the prefix of a valid path.
if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] &&
[[ $WIDGET != accept-* ]]; then
[[ $WIDGET != zle-line-finish ]]; then
local -a tmp
tmp=( ${expanded_path}*(N) )
(( $#tmp > 0 )) && style_override=path_prefix && return 0
Expand Down
2 changes: 1 addition & 1 deletion highlighters/main/test-data/path_prefix2.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight
BUFFER='ls /bin/s'
WIDGET=accept-line
WIDGET=zle-line-finish

expected_region_highlight=(
"4 9 default" # /bin/s
Expand Down
5 changes: 5 additions & 0 deletions zsh-syntax-highlighting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ _zsh_highlight_bind_widgets || {
return 1
}

# Always wrap special zle-line-finish widget. This is needed to decide if the
# current line ends and special highlighting logic needs to be applied.
# E.g. remove cursor imprint, don't highlight partial paths, ...
_zsh_highlight_set_or_wrap_special_zle_widget zle-line-finish

# Resolve highlighters directory location.
_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || {
echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2
Expand Down

0 comments on commit 2ba33bb

Please sign in to comment.