Skip to content

Commit 2a50614

Browse files
committed
main: Save user options in a single variable
1 parent 749b302 commit 2a50614

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

highlighters/main/main-highlighter.zsh

+18-25
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,8 @@ _zsh_highlight_main__stack_pop() {
194194
# Main syntax highlighting function.
195195
_zsh_highlight_highlighter_main_paint()
196196
{
197-
## Before we even 'emulate -L', we must test a few options that would reset.
198-
if [[ -o interactive_comments ]]; then
199-
local interactive_comments= # set to empty
200-
fi
201-
if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then
202-
local right_brace_is_recognised_everywhere=false
203-
else
204-
local right_brace_is_recognised_everywhere=true
205-
fi
206-
if [[ -o path_dirs ]]; then
207-
integer path_dirs_was_set=1
208-
else
209-
integer path_dirs_was_set=0
210-
fi
211-
if [[ -o multi_func_def ]]; then
212-
integer multi_func_def=1
213-
else
214-
integer multi_func_def=0
215-
fi
197+
# Before we even 'emulate -L', save the user's options
198+
local -A useroptions=("${(@kv)options}")
216199
emulate -L zsh
217200
setopt localoptions extendedglob bareglobqual
218201

@@ -245,10 +228,15 @@ _zsh_highlight_highlighter_main_paint()
245228
# ":" for 'then'
246229
local braces_stack
247230

248-
if (( path_dirs_was_set )); then
231+
if [[ $useroptions[ignorebraces] == on || ${useroptions[ignoreclosebraces]:-off} == on ]]; then
232+
local right_brace_is_recognised_everywhere=false
233+
else
234+
local right_brace_is_recognised_everywhere=true
235+
fi
236+
237+
if [[ $useroptions[pathdirs] == on ]]; then
249238
options_to_set+=( PATH_DIRS )
250239
fi
251-
unset path_dirs_was_set
252240

253241
ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=(
254242
'|' '||' ';' '&' '&&'
@@ -322,8 +310,13 @@ _zsh_highlight_highlighter_main_paint()
322310
integer in_redirection
323311
# Processing buffer
324312
local proc_buf="$buf"
325-
for arg in ${interactive_comments-${(z)buf}} \
326-
${interactive_comments+${(zZ+c+)buf}}; do
313+
local -a args
314+
if [[ $useroptions[interactivecomments] == on ]]; then
315+
args=(${(zZ+c+)buf})
316+
else
317+
args=(${(z)buf})
318+
fi
319+
for arg in $args; do
327320
# Initialize $next_word.
328321
if (( in_redirection )); then
329322
(( --in_redirection ))
@@ -412,7 +405,7 @@ _zsh_highlight_highlighter_main_paint()
412405
# Handle the INTERACTIVE_COMMENTS option.
413406
#
414407
# We use the (Z+c+) flag so the entire comment is presented as one token in $arg.
415-
if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then
408+
if [[ $useroptions[interactivecomments] == on && $arg[1] == $histchars[3] ]]; then
416409
if [[ $this_word == *(':regular:'|':start:')* ]]; then
417410
style=comment
418411
else
@@ -648,7 +641,7 @@ _zsh_highlight_highlighter_main_paint()
648641
_zsh_highlight_main__stack_pop 'R' style=reserved-word
649642
fi;;
650643
$'\x28\x29') # possibly a function definition
651-
if (( multi_func_def )) || false # TODO: or if the previous word was a command word
644+
if [[ $useroptions[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word
652645
then
653646
next_word+=':start:'
654647
fi

0 commit comments

Comments
 (0)