Skip to content

Commit 6e679ca

Browse files
committed
merging with upstream master
2 parents af03935 + 3dc5741 commit 6e679ca

File tree

6 files changed

+96
-20
lines changed

6 files changed

+96
-20
lines changed

highlighters/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Syntax highlighting is done by pluggable highlighters:
88
* [***pattern***](pattern) - matches user-defined patterns.
99
* [***cursor***](cursor) - matches the cursor position.
1010
* [***root***](root) - triggered if the current user is root.
11+
* [***line***](line) - applied to the whole command line
1112

1213

1314
How to activate highlighters

highlighters/brackets/brackets-highlighter.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ _zsh_highlight_brackets_highlighter()
4949
{
5050
local level=0 pos
5151
local -A levelpos lastoflevel matching typepos
52+
region_highlight=()
5253

5354
# Find all brackets and remember which one is matching
5455
for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do

highlighters/line/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
zsh-syntax-highlighting / highlighters / line
2+
=================================================
3+
4+
This is the ***line*** highlighter, that highlights the whole line.
5+
6+
7+
How to activate it
8+
------------------
9+
To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`:
10+
11+
ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line)
12+
13+
14+
How to tweak it
15+
---------------
16+
This highlighter defines the following styles:
17+
18+
* `line` - the style for the whole line
19+
20+
To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`:
21+
22+
ZSH_HIGHLIGHT_STYLES[line]='bold'
23+
24+
The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135).
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env zsh
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are permitted
7+
# provided that the following conditions are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright notice, this list of conditions
10+
# and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright notice, this list of
12+
# conditions and the following disclaimer in the documentation and/or other materials provided
13+
# with the distribution.
14+
# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without specific prior
16+
# written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24+
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
# -------------------------------------------------------------------------------------------------
27+
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
28+
# vim: ft=zsh sw=2 ts=2 et
29+
# -------------------------------------------------------------------------------------------------
30+
31+
32+
# Define default styles.
33+
: ${ZSH_HIGHLIGHT_STYLES[line]:=}
34+
35+
# Whether the root highlighter should be called or not.
36+
_zsh_highlight_line_highlighter_predicate()
37+
{
38+
_zsh_highlight_buffer_modified
39+
}
40+
41+
# root highlighting function.
42+
_zsh_highlight_line_highlighter()
43+
{
44+
region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[line]")
45+
}

highlighters/main/main-highlighter.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ _zsh_highlight_main_highlighter()
134134
elif _zsh_highlight_main_highlighter_check_path; then
135135
style=$ZSH_HIGHLIGHT_STYLES[path]
136136
path_found=path
137-
elif [[ $arg[0,1] = $histchars[0,1] ]]; then
137+
elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then
138138
style=$ZSH_HIGHLIGHT_STYLES[history-expansion]
139139
else
140140
style=$ZSH_HIGHLIGHT_STYLES[unknown-token]

zsh-syntax-highlighting.zsh

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,42 @@ _zsh_highlight()
5454
# Do not highlight if there are pending inputs (copy/paste).
5555
[[ $PENDING -gt 0 ]] && return $ret
5656

57+
# Reset region highlight to build it from scratch
58+
region_highlight=();
59+
5760
{
58-
local -a selected_highlighters
5961
local cache_place
62+
local -a region_highlight_copy
6063

6164
# Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked.
6265
local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do
6366

67+
# eval cache place for current highlighter and prepare it
68+
cache_place="_zsh_highlight_${highlighter}_highlighter_cache"
69+
typeset -ga ${cache_place}
70+
6471
# If highlighter needs to be invoked
6572
if "_zsh_highlight_${highlighter}_highlighter_predicate"; then
6673

67-
# Mark the highlighter as selected for update.
68-
selected_highlighters+=($highlighter)
74+
# save a copy, and cleanup region_highlight
75+
region_highlight_copy=("${region_highlight[@]}")
76+
region_highlight=()
77+
78+
# Execute highlighter and save result
79+
{
80+
"_zsh_highlight_${highlighter}_highlighter"
81+
} always {
82+
eval "${cache_place}=(\"\${region_highlight[@]}\")"
83+
}
6984

70-
# Remove what was stored in its cache from region_highlight.
71-
cache_place="_zsh_highlight_${highlighter}_highlighter_cache"
72-
typeset -ga ${cache_place}
73-
[[ ${#${(P)cache_place}} -gt 0 ]] && [[ ! -z ${region_highlight-} ]] && region_highlight=(${region_highlight:#(${(P~j.|.)cache_place})})
85+
# Restore saved region_highlight
86+
region_highlight=("${region_highlight_copy[@]}")
7487

7588
fi
76-
done
7789

78-
# Invoke each selected highlighter and store the result in its cache.
79-
local -a region_highlight_copy
80-
for highlighter in $selected_highlighters; do
81-
cache_place="_zsh_highlight_${highlighter}_highlighter_cache"
82-
region_highlight_copy=($region_highlight)
83-
{
84-
"_zsh_highlight_${highlighter}_highlighter"
85-
} always {
86-
[[ ! -z ${region_highlight-} ]] && : ${(PA)cache_place::=${region_highlight:#(${(~j.|.)region_highlight_copy})}}
87-
}
90+
# Use value form cache if any cached
91+
eval "region_highlight+=(\"\${${cache_place}[@]}\")"
92+
8893
done
8994

9095
} always {
@@ -134,7 +139,7 @@ _zsh_highlight_bind_widgets()
134139

135140
# Override ZLE widgets to make them invoke _zsh_highlight.
136141
local cur_widget
137-
for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep)}; do
142+
for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
138143
case $widgets[$cur_widget] in
139144

140145
# Already rebound event: do nothing.

0 commit comments

Comments
 (0)