main: Move highlighting to _main_paint
This allows for callees to prepend highlights before $reply after the length of the feature (e.g. command substution) is known.
This commit is contained in:
parent
ead8f8a1fc
commit
ce592bd5c7
@ -65,19 +65,13 @@ _zsh_highlight_highlighter_main_predicate()
|
|||||||
# Helper to deal with tokens crossing line boundaries.
|
# Helper to deal with tokens crossing line boundaries.
|
||||||
_zsh_highlight_main_add_region_highlight() {
|
_zsh_highlight_main_add_region_highlight() {
|
||||||
integer start=$1 end=$2
|
integer start=$1 end=$2
|
||||||
local reply
|
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
# The calculation was relative to $buf but region_highlight is relative to $BUFFER.
|
# The calculation was relative to $buf but region_highlight is relative to $BUFFER.
|
||||||
(( start += buf_offset ))
|
(( start += buf_offset ))
|
||||||
(( end += buf_offset ))
|
(( end += buf_offset ))
|
||||||
|
|
||||||
(( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return }
|
list_highlights+=($start $end $1)
|
||||||
(( end <= 0 )) && return
|
|
||||||
(( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings
|
|
||||||
|
|
||||||
_zsh_highlight_main_calculate_fallback $1
|
|
||||||
_zsh_highlight_add_highlight $start $end $reply
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_zsh_highlight_main_add_many_region_highlights() {
|
_zsh_highlight_main_add_many_region_highlights() {
|
||||||
@ -229,7 +223,8 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
|
||||||
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
|
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
|
||||||
local -a options_to_set # used in callees
|
local -a options_to_set reply # used in callees
|
||||||
|
local REPLY
|
||||||
|
|
||||||
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
|
if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then
|
||||||
local right_brace_is_recognised_everywhere=false
|
local right_brace_is_recognised_everywhere=false
|
||||||
@ -272,18 +267,32 @@ _zsh_highlight_highlighter_main_paint()
|
|||||||
)
|
)
|
||||||
|
|
||||||
_zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' "$PREBUFFER$BUFFER"
|
_zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' "$PREBUFFER$BUFFER"
|
||||||
|
|
||||||
|
# end is a reserved word
|
||||||
|
local start end_ style
|
||||||
|
for start end_ style in $reply; do
|
||||||
|
(( start >= end_ )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_highlighter_main_paint: start($start) >= end($end_)"; return }
|
||||||
|
(( end_ <= 0 )) && continue
|
||||||
|
(( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings
|
||||||
|
_zsh_highlight_main_calculate_fallback $style
|
||||||
|
_zsh_highlight_add_highlight $start $end_ $reply
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 is the offset of $3 from the parent buffer. Added to the returned highlights.
|
# $1 is the offset of $3 from the parent buffer. Added to the returned highlights.
|
||||||
# $2 is the initial braces_stack (for a closing paren).
|
# $2 is the initial braces_stack (for a closing paren).
|
||||||
# $3 is the buffer to highlight.
|
# $3 is the buffer to highlight.
|
||||||
|
# Returns:
|
||||||
|
# $REPLY: $buf[REPLY] is the last character parsed.
|
||||||
|
# $reply is an array of region_highlight additions.
|
||||||
_zsh_highlight_main_highlighter_highlight_list()
|
_zsh_highlight_main_highlighter_highlight_list()
|
||||||
{
|
{
|
||||||
integer start_pos=0 end_pos buf_offset=$1
|
integer start_pos=0 end_pos buf_offset=$1
|
||||||
local buf=$3 highlight_glob=true arg style
|
local buf=$3 highlight_glob=true arg style
|
||||||
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
local in_array_assignment=false # true between 'a=(' and the matching ')'
|
||||||
integer len=$#buf
|
integer len=$#buf
|
||||||
local -a match mbegin mend
|
local -a match mbegin mend list_highlights
|
||||||
|
list_highlights=()
|
||||||
|
|
||||||
# "R" for round
|
# "R" for round
|
||||||
# "Q" for square
|
# "Q" for square
|
||||||
@ -741,6 +750,9 @@ _zsh_highlight_main_highlighter_highlight_list()
|
|||||||
# Stall $this_word.
|
# Stall $this_word.
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
REPLY=$(( end_pos - 1 ))
|
||||||
|
reply=($list_highlights)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if $arg is variable assignment
|
# Check if $arg is variable assignment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user