Skip to content

Commit dd17273

Browse files
committed
main: Add ' helper function
1 parent 0fcdec5 commit dd17273

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

highlighters/main/main-highlighter.zsh

+31-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
5050
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
5151
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
52+
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
5253
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
5354
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none}
5455
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
@@ -214,6 +215,11 @@ _zsh_highlight_highlighter_main_paint()
214215
else
215216
integer path_dirs_was_set=0
216217
fi
218+
if [[ -o rc_quotes ]]; then
219+
integer rc_quotes=1
220+
else
221+
integer rc_quotes=0
222+
fi
217223
if [[ -o multi_func_def ]]; then
218224
integer multi_func_def=1
219225
else
@@ -677,7 +683,9 @@ _zsh_highlight_highlighter_main_paint()
677683
;|
678684
'--'*) style=double-hyphen-option;;
679685
'-'*) style=single-hyphen-option;;
680-
"'"*) style=single-quoted-argument;;
686+
"'"*) _zsh_highlight_main_highlighter_highlight_single_quote 1
687+
already_added=1
688+
;;
681689
'"'*) _zsh_highlight_main_highlighter_highlight_double_quote
682690
already_added=1
683691
;;
@@ -804,6 +812,28 @@ _zsh_highlight_main_highlighter_check_path()
804812
return 1
805813
}
806814

815+
# Highlight single-quoted strings
816+
_zsh_highlight_main_highlighter_highlight_single_quote()
817+
{
818+
local arg1=$1 i q=\'
819+
i=$arg[(ib:arg1+1:)$q]
820+
821+
if (( rc_quotes )); then
822+
local -a highlights
823+
while [[ $arg[i+1] == "'" ]]; do
824+
highlights+=($(( start_pos + i - 1 )) $(( start_pos + ++i )) rc-quote)
825+
i=$arg[(ib:i+1:)$q]
826+
done
827+
828+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
829+
_zsh_highlight_main_add_region_highlights $highlights
830+
else
831+
_zsh_highlight_main_add_region_highlight $(( start_pos + $1 - 1)) $(( start_pos + i )) single-quoted-argument
832+
fi
833+
834+
REPLY=$i
835+
}
836+
807837
# Highlight special chars inside double-quoted strings
808838
_zsh_highlight_main_highlighter_highlight_double_quote()
809839
{

0 commit comments

Comments
 (0)