From 957a8b4a44d0bbf182d8d6d6f3b9d8a2ed62ef93 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 01:33:00 +0200 Subject: [PATCH] 'main': Implement simple command type cache --- highlighters/main/main-highlighter.zsh | 5 +++++ zsh-syntax-highlighting.zsh | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 47d3b6e..1e6667d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -89,6 +89,10 @@ _zsh_highlight_main_add_region_highlight() { # # The result will be stored in REPLY. _zsh_highlight_main__type() { + REPLY=$_zsh_highlight_command_type_cache[(e)$1] + if [[ -n "$REPLY" ]]; then + return + fi if (( $#options_to_set )); then setopt localoptions $options_to_set; fi @@ -113,6 +117,7 @@ _zsh_highlight_main__type() { if ! (( $+REPLY )); then REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }" fi + _zsh_highlight_command_type_cache[(e)$1]=$REPLY } # Check whether the first argument is a redirection operator token. diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 676b278..07a17e3 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -322,6 +322,7 @@ _zsh_highlight_preexec_hook() { typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR= + _zsh_highlight_command_type_cache=() } autoload -U add-zsh-hook 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. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true + +# Initialize command type cache +typeset -A _zsh_highlight_command_type_cache