Skip to content

Commit

Permalink
Fix issue sorin-ionescu#228, "Support the PATH_DIRS option".
Browse files Browse the repository at this point in the history
  • Loading branch information
danielshahaf committed Nov 16, 2015
1 parent a636527 commit 96ee511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion highlighters/main/main-highlighter.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
'|' '||' ';' '&' '&&'
)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion highlighters/main/test-data/option-path_dirs.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 96ee511

Please sign in to comment.