Skip to content

Commit 96ee511

Browse files
committed
Fix issue #228, "Support the PATH_DIRS option".
1 parent a636527 commit 96ee511

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,33 @@ _zsh_highlight_main_add_region_highlight() {
8383
# Main syntax highlighting function.
8484
_zsh_highlight_main_highlighter()
8585
{
86+
## Before we even 'emulate -L', we must test a few options that would reset.
8687
if [[ -o interactive_comments ]]; then
8788
local interactive_comments= # set to empty
8889
fi
90+
if [[ -o path_dirs ]]; then
91+
integer path_dirs_was_set=1
92+
else
93+
integer path_dirs_was_set=0
94+
fi
8995
emulate -L zsh
9096
setopt localoptions extendedglob bareglobqual
97+
98+
## Variable declarations and initializations
9199
local start_pos=0 end_pos highlight_glob=true arg style
92100
local in_array_assignment=false # true between 'a=(' and the matching ')'
93101
typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR
94102
typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS
95103
typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
104+
local -a options_to_set
96105
local buf="$PREBUFFER$BUFFER"
97106
region_highlight=()
98107

108+
if (( path_dirs_was_set )); then
109+
options_to_set+=( PATH_DIRS )
110+
fi
111+
unset path_dirs_was_set
112+
99113
ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=(
100114
'|' '||' ';' '&' '&&'
101115
)
@@ -239,7 +253,12 @@ _zsh_highlight_main_highlighter()
239253
else
240254
_zsh_highlight_main_highlighter_expand_path $arg
241255
local expanded_arg="$REPLY"
242-
local res="$(LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null)"
256+
local res="$(
257+
if (( $#options_to_set )); then
258+
setopt $options_to_set;
259+
fi
260+
LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null
261+
)"
243262
case $res in
244263
*': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];;
245264
*': suffix alias')

highlighters/main/test-data/option-path_dirs.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ path+=( "$PWD"/foo )
3737
BUFFER='bar/testing-issue-228'
3838

3939
expected_region_highlight=(
40-
"1 21 $ZSH_HIGHLIGHT_STYLES[command] 'issue #228'" # bar/testing-issue-228
40+
"1 21 $ZSH_HIGHLIGHT_STYLES[command]" # bar/testing-issue-228
4141
)

0 commit comments

Comments
 (0)