Skip to content

Commit 61d6776

Browse files
committed
main: Introduce *-quoted-argument-unclosed styles
Closes zsh-users#277.
1 parent 35546fc commit 61d6776

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}
@@ -839,7 +842,7 @@ _zsh_highlight_main_highlighter_highlight_argument()
839842
# Highlight single-quoted strings
840843
_zsh_highlight_main_highlighter_highlight_single_quote()
841844
{
842-
local arg1=$1 i q=\'
845+
local arg1=$1 i q=\' style
843846
local -a highlights
844847
i=$arg[(ib:arg1+1:)$q]
845848

@@ -850,7 +853,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote()
850853
done
851854
fi
852855

853-
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights)
856+
if [[ $arg[i] == "'" ]]; then
857+
style=single-quoted-argument
858+
else
859+
style=single-quoted-argument-unclosed
860+
fi
861+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
854862
_zsh_highlight_main_add_region_highlights $highlights
855863
REPLY=$i
856864
}
@@ -910,7 +918,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote()
910918
highlights+=($j $k $style)
911919
done
912920

913-
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights)
921+
if [[ $arg[i] == '"' ]]; then
922+
style=double-quoted-argument
923+
else
924+
style=double-quoted-argument-unclosed
925+
fi
926+
highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights)
914927
_zsh_highlight_main_add_region_highlights $highlights
915928
REPLY=$i
916929
}
@@ -957,7 +970,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote()
957970
highlights+=($j $k $style)
958971
done
959972

960-
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights)
973+
if [[ $arg[i] == "'" ]]; then
974+
style=dollar-quoted-argument
975+
else
976+
style=dollar-quoted-argument-unclosed
977+
fi
978+
highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights)
961979
_zsh_highlight_main_add_region_highlights $highlights
962980
REPLY=$i
963981
}

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)