diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ad622b8..571ebb6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -83,19 +83,33 @@ _zsh_highlight_main_add_region_highlight() { # Main syntax highlighting function. _zsh_highlight_main_highlighter() { + ## Before we even 'emulate -L', we must test a few options that would reset. if [[ -o interactive_comments ]]; then local interactive_comments= # set to empty fi + if [[ -o path_dirs ]]; then + integer path_dirs_was_set=1 + else + integer path_dirs_was_set=0 + fi emulate -L zsh setopt localoptions extendedglob bareglobqual + + ## Variable declarations and initializations local start_pos=0 end_pos highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' 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 buf="$PREBUFFER$BUFFER" region_highlight=() + if (( path_dirs_was_set )); then + options_to_set+=( PATH_DIRS ) + fi + unset path_dirs_was_set + ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' ) @@ -239,7 +253,12 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$(LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null)" + local res="$( + if (( $#options_to_set )); then + setopt $options_to_set; + fi + LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null + )" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh index 4d8ab72..21434c4 100644 --- a/highlighters/main/test-data/option-path_dirs.zsh +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -37,5 +37,5 @@ path+=( "$PWD"/foo ) BUFFER='bar/testing-issue-228' expected_region_highlight=( - "1 21 $ZSH_HIGHLIGHT_STYLES[command] 'issue #228'" # bar/testing-issue-228 + "1 21 $ZSH_HIGHLIGHT_STYLES[command]" # bar/testing-issue-228 )