Skip to content

Commit 4107446

Browse files
committed
main: Introduce *-quoted-argument-unclosed styles
Closes zsh-users#277.
1 parent f1b6d52 commit 4107446

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

docs/highlighters/main.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ This highlighter defines the following styles:
3636
* `double-hyphen-option` - double hyphen options (`--option`)
3737
* `back-quoted-argument` - backquoted expressions (`` `foo` ``)
3838
* `single-quoted-argument` - single quoted arguments (`` 'foo' ``)
39+
* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``)
3940
* `double-quoted-argument` - double quoted arguments (`` "foo" ``)
41+
* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``)
4042
* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``)
43+
* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``)
4144
* `rc-quote` - two single quotes inside single quotes when `RC_QUOTES` is set (`` 'foo''bar' ``)
4245
* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
4346
* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`)

highlighters/main/main-highlighter.zsh

+22-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
: ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none}
4545
: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none}
4646
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow}
47+
: ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument-unclosed]:=fg=yellow}
4748
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow}
49+
: ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]:=fg=yellow}
4850
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
51+
: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument-unclosed]:=fg=yellow}
4952
: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan}
5053
: ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan}
5154
: ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan}
@@ -827,7 +830,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
827830
# Highlight single-quoted strings
828831
_zsh_highlight_main_highlighter_highlight_single_quote()
829832
{
830-
local arg1=$1 i q=\'
833+
local arg1=$1 i q=\' style
831834
local -a highlights
832835
i=$arg[(ib:arg1+1:)$q]
833836

@@ -838,7 +841,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote()
838841
done
839842
fi
840843

841-
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
844+
if [[ $arg[i] == "'" ]]; then
845+
style=single-quoted-argument
846+
else
847+
style=single-quoted-argument-unclosed
848+
fi
849+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
842850
_zsh_highlight_main_add_region_highlights $highlights
843851
REPLY=$i
844852
}
@@ -898,7 +906,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
898906
highlights+=($j $k $style)
899907
done
900908

901-
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights)
909+
if [[ $arg[i] == '"' ]]; then
910+
style=double-quoted-argument
911+
else
912+
style=double-quoted-argument-unclosed
913+
fi
914+
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights)
902915
_zsh_highlight_main_add_region_highlights $highlights
903916
REPLY=$i
904917
}
@@ -945,7 +958,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
945958
highlights+=($j $k $style)
946959
done
947960

948-
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights)
961+
if [[ $arg[i] == "'" ]]; then
962+
style=dollar-quoted-argument
963+
else
964+
style=dollar-quoted-argument-unclosed
965+
fi
966+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
949967
_zsh_highlight_main_add_region_highlights $highlights
950968
REPLY=$i
951969
}

highlighters/main/test-data/dollar-quoted3.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
BUFFER=": \$'\xa1"
3333

3434
expected_region_highlight=(
35-
"3 4 dollar-quoted-argument" # $'
35+
"3 4 dollar-quoted-argument-unclosed" # $'
3636
"5 8 back-dollar-quoted-argument" # \xa1
3737
)

highlighters/main/test-data/double-quoted2.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
BUFFER=': "foo$bar'
3333

3434
expected_region_highlight=(
35-
"3 6 double-quoted-argument" # "foo
35+
"3 6 double-quoted-argument-unclosed" # "foo
3636
"7 10 dollar-double-quoted-argument" # $bar
3737
)

highlighters/main/test-data/multiline-string2.zsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
BUFFER=$'echo "foo1\n'
3131

3232
expected_region_highlight=(
33-
"6 10 double-quoted-argument" # 'foo2"'
33+
"6 10 double-quoted-argument-unclosed" # 'foo2"'
3434
)

0 commit comments

Comments
 (0)