'main': Enable fallback to the 'arg0' style.
This commit is contained in:
parent
b4537a972e
commit
bccc3dc269
@ -32,17 +32,11 @@
|
|||||||
: ${ZSH_HIGHLIGHT_STYLES[default]:=none}
|
: ${ZSH_HIGHLIGHT_STYLES[default]:=none}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
|
: ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
|
: ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
|
: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
|
: ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
|
: ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
|
: ${ZSH_HIGHLIGHT_STYLES[path]:=underline}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=}
|
: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline}
|
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=}
|
: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
|
: ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue}
|
||||||
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
|
: ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue}
|
||||||
@ -72,6 +66,33 @@ _zsh_highlight_main_add_region_highlight() {
|
|||||||
integer start=$1 end=$2
|
integer start=$1 end=$2
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
if (( $+argv[2] )); then
|
||||||
|
# Caller specified inheritance explicitly.
|
||||||
|
else
|
||||||
|
# Automate inheritance.
|
||||||
|
typeset -A fallback_of; fallback_of=(
|
||||||
|
alias arg0
|
||||||
|
suffix-alias arg0
|
||||||
|
builtin arg0
|
||||||
|
function arg0
|
||||||
|
command arg0
|
||||||
|
precommand arg0
|
||||||
|
hashed-command arg0
|
||||||
|
|
||||||
|
path_prefix path
|
||||||
|
# The path separator fallback won't ever be used, due to the optimisation
|
||||||
|
# in _zsh_highlight_main_highlighter_highlight_path_separators().
|
||||||
|
path_pathseparator path
|
||||||
|
path_prefix_pathseparator path_prefix
|
||||||
|
)
|
||||||
|
local needle=$1 value
|
||||||
|
while [[ -n ${value::=$fallback_of[$needle]} ]]; do
|
||||||
|
unset "fallback_of[$needle]" # paranoia against infinite loops
|
||||||
|
argv+=($value)
|
||||||
|
needle=$value
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is
|
# The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is
|
||||||
# relative to $BUFFER.
|
# relative to $BUFFER.
|
||||||
(( start -= $#PREBUFFER ))
|
(( start -= $#PREBUFFER ))
|
||||||
|
40
highlighters/main/test-data/inheritance.zsh
Normal file
40
highlighters/main/test-data/inheritance.zsh
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2016 zsh-syntax-highlighting contributors
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||||
|
# provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# * Redistributions of source code must retain the above copyright notice, this list of conditions
|
||||||
|
# and the following disclaimer.
|
||||||
|
# * Redistributions in binary form must reproduce the above copyright notice, this list of
|
||||||
|
# conditions and the following disclaimer in the documentation and/or other materials provided
|
||||||
|
# with the distribution.
|
||||||
|
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
|
||||||
|
# may be used to endorse or promote products derived from this software without specific prior
|
||||||
|
# written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
||||||
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
|
||||||
|
# vim: ft=zsh sw=2 ts=2 et
|
||||||
|
# -------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_zsh_highlight_add_highlight()
|
||||||
|
{
|
||||||
|
region_highlight+=("$1 $2 ${(j.,.)argv[3,-1]}")
|
||||||
|
}
|
||||||
|
|
||||||
|
BUFFER='type'
|
||||||
|
|
||||||
|
expected_region_highlight=(
|
||||||
|
'1 4 builtin,arg0' # type
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user