Skip to content

Commit 2b24a39

Browse files
committed
main: Make " and $' helper functions responsible for highlighting quote
1 parent 5672130 commit 2b24a39

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ _zsh_highlight_main_add_region_highlight() {
103103
_zsh_highlight_add_highlight $start $end "$@"
104104
}
105105

106+
_zsh_highlight_main_add_region_highlights() {
107+
for 1 2 3; do
108+
_zsh_highlight_main_add_region_highlight $1 $2 $3
109+
done
110+
}
111+
106112
# Get the type of a command.
107113
#
108114
# Uses the zsh/parameter module if available to avoid forks, and a
@@ -665,14 +671,10 @@ _zsh_highlight_highlighter_main_paint()
665671
'--'*) style=double-hyphen-option;;
666672
'-'*) style=single-hyphen-option;;
667673
"'"*) style=single-quoted-argument;;
668-
'"'*) style=double-quoted-argument
669-
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
670-
_zsh_highlight_main_highlighter_highlight_string
674+
'"'*) _zsh_highlight_main_highlighter_highlight_double_quote
671675
already_added=1
672676
;;
673-
\$\'*) style=dollar-quoted-argument
674-
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
675-
_zsh_highlight_main_highlighter_highlight_dollar_string
677+
\$\'*) _zsh_highlight_main_highlighter_highlight_dollar_quote
676678
already_added=1
677679
;;
678680
'`'*) style=back-quoted-argument;;
@@ -796,12 +798,12 @@ _zsh_highlight_main_highlighter_check_path()
796798
}
797799

798800
# Highlight special chars inside double-quoted strings
799-
_zsh_highlight_main_highlighter_highlight_string()
801+
_zsh_highlight_main_highlighter_highlight_double_quote()
800802
{
801-
setopt localoptions noksharrays
802-
local -a match mbegin mend
803+
local -a highlights match mbegin mend
803804
local MATCH; integer MBEGIN MEND
804805
local i j k style
806+
805807
# Starting quote is at 1, so start parsing at offset 2 in the string.
806808
for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do
807809
(( j = i + start_pos - 1 ))
@@ -847,19 +849,22 @@ _zsh_highlight_main_highlighter_highlight_string()
847849
*) continue ;;
848850

849851
esac
850-
_zsh_highlight_main_add_region_highlight $j $k $style
852+
highlights+=($j $k $style)
851853
done
854+
855+
highlights=($start_pos $end_pos double-quoted-argument $highlights)
856+
_zsh_highlight_main_add_region_highlights $highlights
852857
}
853858

854859
# Highlight special chars inside dollar-quoted strings
855-
_zsh_highlight_main_highlighter_highlight_dollar_string()
860+
_zsh_highlight_main_highlighter_highlight_dollar_quote()
856861
{
857-
setopt localoptions noksharrays
858-
local -a match mbegin mend
862+
local -a highlights match mbegin mend
859863
local MATCH; integer MBEGIN MEND
860864
local i j k style
861865
local AA
862866
integer c
867+
863868
# Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string.
864869
for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do
865870
(( j = i + start_pos - 1 ))
@@ -890,8 +895,11 @@ _zsh_highlight_main_highlighter_highlight_dollar_string()
890895
*) continue ;;
891896

892897
esac
893-
_zsh_highlight_main_add_region_highlight $j $k $style
898+
highlights+=($j $k $style)
894899
done
900+
901+
highlights+=($start_pos $end_pos dollar-quoted-argument $highlights)
902+
_zsh_highlight_main_add_region_highlights $highlights
895903
}
896904

897905
# Called with a single positional argument.

0 commit comments

Comments
 (0)