From bdc14497332fb3b0ab2c13987fe07fd50e3c3f1e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 01:27:38 +0000 Subject: [PATCH] noop: Break out a helper function. --- highlighters/main/main-highlighter.zsh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 861ed0f..d12d9bf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -80,6 +80,19 @@ _zsh_highlight_main_add_region_highlight() { region_highlight+=("$start $end $style") } +# Wrapper around 'type -w'. +# +# Takes a single argument and outputs the output of 'type -w $1'. +# +# NOTE: This runs 'setopt', but that should be safe since it'll only ever be +# called inside a $(...) subshell, so the effects will be local. +_zsh_highlight_main__type() { + if (( $#options_to_set )); then + setopt $options_to_set; + fi + LC_ALL=C builtin type -w -- $1 2>/dev/null +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -101,7 +114,7 @@ _zsh_highlight_main_highlighter() typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW - local -a options_to_set + local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" region_highlight=() @@ -253,12 +266,7 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$( - if (( $#options_to_set )); then - setopt $options_to_set; - fi - LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null - )" + local res="$(_zsh_highlight_main__type ${expanded_arg})" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias')