Skip to content

Commit a5b8158

Browse files
committed
main: Remember nest level an alias was seen in for seen_alias
Fixes #775.
1 parent ad08724 commit a5b8158

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

highlighters/main/main-highlighter.zsh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,12 @@ _zsh_highlight_main_highlighter_highlight_list()
602602
while (( $#in_alias && in_alias[-1] == 0 )); do
603603
in_alias=($in_alias[1,-2])
604604
done
605+
(){
606+
local alias_name
607+
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
608+
unset "seen_alias[$alias_name]"
609+
done
610+
}
605611
if (( $#in_alias == 0 )); then
606612
seen_alias=()
607613
# start_pos and end_pos are of the alias (previous $arg) here
@@ -700,7 +706,7 @@ _zsh_highlight_main_highlighter_highlight_list()
700706
_zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token
701707
continue
702708
fi
703-
seen_alias[$arg]=1
709+
seen_alias[$arg]=$#in_alias
704710
_zsh_highlight_main__resolve_alias $arg
705711
local -a alias_args
706712
# Elision is desired in case alias x=''
@@ -882,7 +888,12 @@ _zsh_highlight_main_highlighter_highlight_list()
882888
next_word=':start:'
883889
highlight_glob=true
884890
saw_assignment=false
885-
seen_alias=()
891+
(){
892+
local alias_name
893+
for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do
894+
unset "seen_alias[$alias_name]"
895+
done
896+
}
886897
if [[ $arg != '|' && $arg != '|&' ]]; then
887898
next_word+=':start_of_pipeline:'
888899
fi
Lines changed: 37 additions & 0 deletions
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)