Skip to content

Commit 75c0eb0

Browse files
committed
main: Remember nest level an alias was seen in for seen_alias
Fixes #775.
1 parent 046cb03 commit 75c0eb0

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

highlighters/main/main-highlighter.zsh

+13-2
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,12 @@ _zsh_highlight_main_highlighter_highlight_list()
601601
(( in_alias[1]-- ))
602602
# Remove leading 0 entries
603603
in_alias=($in_alias[$in_alias[(i)<1->],-1])
604+
(){
605+
local alias_name
606+
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
607+
unset "seen_alias[$alias_name]"
608+
done
609+
}
604610
if (( $#in_alias == 0 )); then
605611
seen_alias=()
606612
# start_pos and end_pos are of the alias (previous $arg) here
@@ -699,7 +705,7 @@ _zsh_highlight_main_highlighter_highlight_list()
699705
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
700706
continue
701707
fi
702-
seen_alias[$arg]=1
708+
seen_alias[$arg]=$#in_alias
703709
_zsh_highlight_main__resolve_alias $arg
704710
local -a alias_args
705711
# Elision is desired in case alias x=''
@@ -881,7 +887,12 @@ _zsh_highlight_main_highlighter_highlight_list()
881887
next_word=':start:'
882888
highlight_glob=true
883889
saw_assignment=false
884-
seen_alias=()
890+
(){
891+
local alias_name
892+
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
893+
unset "seen_alias[$alias_name]"
894+
done
895+
}
885896
if [[ $arg != '|' && $arg != '|&' ]]; then
886897
next_word+=':start_of_pipeline:'
887898
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env zsh
2+
# -------------------------------------------------------------------------------------------------
3+
# Copyright (c) 2020 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+
alias cat='cat | cat'
32+
33+
BUFFER='cat'
34+
35+
expected_region_highlight=(
36+
'1 3 alias' # cat
37+
)

0 commit comments

Comments
 (0)