mirror of
https://github.com/zsh-users/zsh-syntax-highlighting.git
synced 2025-02-13 10:05:31 +08:00
'main': Implement simple command type cache
This commit is contained in:
parent
12b879caf7
commit
957a8b4a44
@ -89,6 +89,10 @@ _zsh_highlight_main_add_region_highlight() {
|
|||||||
#
|
#
|
||||||
# The result will be stored in REPLY.
|
# The result will be stored in REPLY.
|
||||||
_zsh_highlight_main__type() {
|
_zsh_highlight_main__type() {
|
||||||
|
REPLY=$_zsh_highlight_command_type_cache[(e)$1]
|
||||||
|
if [[ -n "$REPLY" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
if (( $#options_to_set )); then
|
if (( $#options_to_set )); then
|
||||||
setopt localoptions $options_to_set;
|
setopt localoptions $options_to_set;
|
||||||
fi
|
fi
|
||||||
@ -113,6 +117,7 @@ _zsh_highlight_main__type() {
|
|||||||
if ! (( $+REPLY )); then
|
if ! (( $+REPLY )); then
|
||||||
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }"
|
REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }"
|
||||||
fi
|
fi
|
||||||
|
_zsh_highlight_command_type_cache[(e)$1]=$REPLY
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check whether the first argument is a redirection operator token.
|
# Check whether the first argument is a redirection operator token.
|
||||||
|
@ -322,6 +322,7 @@ _zsh_highlight_preexec_hook()
|
|||||||
{
|
{
|
||||||
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
|
typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
|
||||||
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=
|
typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=
|
||||||
|
_zsh_highlight_command_type_cache=()
|
||||||
}
|
}
|
||||||
autoload -U add-zsh-hook
|
autoload -U add-zsh-hook
|
||||||
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
|
add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
|
||||||
@ -333,3 +334,6 @@ zmodload zsh/parameter 2>/dev/null || true
|
|||||||
|
|
||||||
# Initialize the array of active highlighters if needed.
|
# Initialize the array of active highlighters if needed.
|
||||||
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true
|
[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true
|
||||||
|
|
||||||
|
# Initialize command type cache
|
||||||
|
typeset -A _zsh_highlight_command_type_cache
|
||||||
|
Loading…
Reference in New Issue
Block a user