Skip to content

Commit 3922b91

Browse files
authored
_chroma/-perl.ch: Support -E flag (#61)
1 parent 5ecd353 commit 3922b91

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

→chroma/-perl.ch

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Copyright (c) 2018 Sebastian Gniazdowski
33
#
44
# Chroma function for command `perl'. It highlights code passed to perl
5-
# with -e option - does syntax check by calling `perl -ce', then highlights
6-
# as correct or incorrect code.
5+
# with -e or -E option - does syntax check by calling `perl -ce' or `perl -cE',
6+
# then highlights as correct or incorrect code.
77
#
88
# $1 - 0 or 1, denoting if it's first call to the chroma, or following one
99
# $2 - the current token, also accessible by $__arg from the above scope -
@@ -43,20 +43,30 @@ integer __idx1 __idx2
4343

4444
if [[ "$__wrd" = "-e" || ("$__wrd" = -*e* && "$__wrd" != --*) ]]; then
4545
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=1
46+
elif [[ "$__wrd" = "-E" || ("$__wrd" = -*E* && "$__wrd" != --*) ]]; then
47+
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=2
4648
fi
4749
else
4850
__wrd="${__wrd//\`/x}"
4951
__arg="${__arg//\`/x}"
5052
__wrd="${(Q)__wrd}"
51-
if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then
52-
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0
53-
if perl -ce "$__wrd" >/dev/null 2>&1; then
54-
# Add correct-subtle style
55-
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
56-
else
57-
# Add incorrect-subtle style
58-
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
53+
54+
if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] )); then
55+
if (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )); then
56+
if (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 1 )); then
57+
perl -ce "$__wrd" >/dev/null 2>&1
58+
elif (( FAST_HIGHLIGHT[chrome-perl-got-eswitch] == 2 )); then
59+
perl -cE "$__wrd" >/dev/null 2>&1
60+
fi && {
61+
# Add correct-subtle style
62+
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}correct-subtle]}")
63+
} || {
64+
# Add incorrect-subtle style
65+
reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}incorrect-subtle]}")
66+
}
5967
fi
68+
69+
FAST_HIGHLIGHT[chrome-perl-got-eswitch]=0
6070
else
6171
# Pass-through to the big-loop outside
6272
return 1

0 commit comments

Comments
 (0)