Skip to content

Commit 06710f3

Browse files
committed
'main': Don't run _zsh_highlight_main__type on every non-command word.
Fixes #728, the performance regression from 0.7.1.
1 parent 343ec10 commit 06710f3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ _zsh_highlight_main__resolve_alias() {
273273
fi
274274
}
275275

276+
# Return true iff $1 is a global alias
277+
_zsh_highlight_main__is_global_alias() {
278+
if zmodload -e zsh/parameter; then
279+
(( ${+galiases[$arg]} ))
280+
elif [[ $arg == '='* ]]; then
281+
# avoid running into «alias -L '=foo'» erroring out with 'bad assignment'
282+
return 1
283+
else
284+
alias -L -g -- "$1" >/dev/null
285+
fi
286+
}
287+
276288
# Check that the top of $braces_stack has the expected value. If it does, set
277289
# the style according to $2; otherwise, set style=unknown-token.
278290
#
@@ -1061,7 +1073,7 @@ _zsh_highlight_main_highlighter_highlight_list()
10611073
if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then
10621074
next_word=':start::start_of_pipeline:'
10631075
fi
1064-
elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position
1076+
elif _zsh_highlight_main__is_global_alias "$arg"; then # $arg is a global alias that isn't in command position
10651077
style=global-alias
10661078
else # $arg is a non-command word
10671079
case $arg in

0 commit comments

Comments
 (0)