comments: Fix issue #163 and #167: Highlight comments.

This commit is contained in:
Daniel Shahaf
2015-10-27 19:29:06 +02:00
parent e76f208cf8
commit 693de99a90
4 changed files with 18 additions and 4 deletions

View File

@@ -55,6 +55,7 @@
: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
: ${ZSH_HIGHLIGHT_STYLES[assign]:=none}
: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none}
: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
# Whether the highlighter should be called or not.
_zsh_highlight_main_highlighter_predicate()
@@ -82,6 +83,9 @@ _zsh_highlight_main_add_region_highlight() {
# Main syntax highlighting function.
_zsh_highlight_main_highlighter()
{
if [[ -o interactive_comments ]]; then
local interactive_comments= # set to empty
fi
emulate -L zsh
setopt localoptions extendedglob bareglobqual
local start_pos=0 end_pos highlight_glob=true arg style
@@ -148,7 +152,8 @@ _zsh_highlight_main_highlighter()
#
local this_word=':start:' next_word
integer in_redirection
for arg in ${(z)buf}; do
for arg in ${interactive_comments-${(z)buf}} \
${interactive_comments+${(zZ+c+)buf}}; do
if (( in_redirection )); then
(( --in_redirection ))
fi
@@ -184,6 +189,14 @@ _zsh_highlight_main_highlighter()
((end_pos=$start_pos+${#arg}))
fi
if [[ ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then
# TODO: check $this_word
style=$ZSH_HIGHLIGHT_STYLES[comment]
_zsh_highlight_main_add_region_highlight $start_pos $end_pos $style
already_added=1
continue
fi
# Parse the sudo command line
if (( ! in_redirection )); then
if [[ $this_word == *':sudo_opt:'* ]]; then