From 47c2b7e1851375c3a9d3c1faec5851fc8409da08 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 08:14:42 -0500 Subject: [PATCH 001/297] main: Distinguish quoted/unquoted command substitutions Closes #547. --- docs/highlighters/main.md | 4 ++++ highlighters/main/main-highlighter.zsh | 15 +++++++++------ .../command-substitution-in-assignment.zsh | 6 +++--- .../test-data/command-substitution-unclosed.zsh | 4 ++-- highlighters/main/test-data/cthulhu.zsh | 6 +++--- highlighters/main/test-data/dollar-paren.zsh | 6 +++--- .../main/test-data/redirection-in-cmdsubst.zsh | 6 +++--- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 188da07..6ff2bd8 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -33,7 +33,11 @@ This highlighter defines the following styles: * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `command-substitution` - command substitutions (`$(echo foo)`) +* `command-substitution-unquoted` - an unquoted command substitution (`$(echo foo)`) +* `command-substitution-quoted` - a quoted command substitution (`"$(echo foo)"`) * `command-substitution-delimiter` - command substitution delimiters (`$(` and `)`) +* `command-substitution-delimiter-unquoted` - an unquoted command substitution delimiters (`$(` and `)`) +* `command-substitution-delimiter-quoted` - a quoted command substitution delimiters (`"$(` and `)"`) * `process-substitution` - process substitutions (`<(echo foo)`) * `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`) * `single-hyphen-option` - single-hyphen options (`-o`) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 41a4fb9..455c21f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -107,6 +107,9 @@ _zsh_highlight_main_calculate_fallback() { dollar-quoted-argument{-unclosed,} back-quoted-argument{-unclosed,} + command-substitution{-quoted,,-unquoted,} + command-substitution-delimiter{-quoted,,-unquoted,} + command-substitution{-delimiter,} process-substitution{-delimiter,} back-quoted-argument{-delimiter,} @@ -1015,12 +1018,12 @@ _zsh_highlight_main_highlighter_highlight_argument() ret=$? (( i += REPLY )) highlights+=( - $(( start_pos + start - 1)) $(( start_pos + i )) command-substitution - $(( start_pos + start - 1)) $(( start_pos + start + 1)) command-substitution-delimiter + $(( start_pos + start - 1)) $(( start_pos + i )) command-substitution-unquoted + $(( start_pos + start - 1)) $(( start_pos + start + 1)) command-substitution-delimiter-unquoted $reply ) if (( ret == 0 )); then - highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter) + highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted) fi continue fi @@ -1147,12 +1150,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( i += REPLY )) reply=( $saved_reply - $j $(( start_pos + i )) command-substitution - $j $(( j + 2 )) command-substitution-delimiter + $j $(( start_pos + i )) command-substitution-quoted + $j $(( j + 2 )) command-substitution-delimiter-quoted $reply ) if (( ret == 0 )); then - reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter) + reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter-quoted) fi continue else diff --git a/highlighters/main/test-data/command-substitution-in-assignment.zsh b/highlighters/main/test-data/command-substitution-in-assignment.zsh index 010df7f..fafda49 100644 --- a/highlighters/main/test-data/command-substitution-in-assignment.zsh +++ b/highlighters/main/test-data/command-substitution-in-assignment.zsh @@ -33,10 +33,10 @@ BUFFER=$'foo=$(echo bar) :' expected_region_highlight=( '1 15 assign' # foo=$(echo bar) '5 15 default' # $(echo bar) - '5 15 command-substitution' # $(echo bar) - '5 6 command-substitution-delimiter' # $( + '5 15 command-substitution-unquoted' # $(echo bar) + '5 6 command-substitution-delimiter-unquoted' # $( '7 10 builtin' # echo '12 14 default' # bar - '15 15 command-substitution-delimiter' # ) + '15 15 command-substitution-delimiter-unquoted' # ) '17 17 builtin' # : ) diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh index 570471b..bce6863 100644 --- a/highlighters/main/test-data/command-substitution-unclosed.zsh +++ b/highlighters/main/test-data/command-substitution-unclosed.zsh @@ -33,8 +33,8 @@ BUFFER=$': foo$(echo bar' expected_region_highlight=( '1 1 builtin' # : '3 15 default' # foo$(echo bar - '6 15 command-substitution' # $(echo bar - '6 7 command-substitution-delimiter' # $( + '6 15 command-substitution-unquoted' # $(echo bar + '6 7 command-substitution-delimiter-unquoted' # $( '8 11 builtin' # echo '13 15 default' # bar ) diff --git a/highlighters/main/test-data/cthulhu.zsh b/highlighters/main/test-data/cthulhu.zsh index 7a1b7f1..c8119a8 100644 --- a/highlighters/main/test-data/cthulhu.zsh +++ b/highlighters/main/test-data/cthulhu.zsh @@ -53,8 +53,8 @@ expected_region_highlight=( '55 58 double-quoted-argument-unclosed' # "lhu '59 62 back-quoted-argument-delimiter' # \\\` '64 112 default' # R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn - '70 109 command-substitution' # $(echo eh wag\\\`echo h\'nag\\\`'l' fht) - '70 71 command-substitution-delimiter' # $( + '70 109 command-substitution-unquoted' # $(echo eh wag\\\`echo h\'nag\\\`'l' fht) + '70 71 command-substitution-delimiter-unquoted' # $( '72 75 builtin' # echo '77 78 default' # eh '80 104 default' # wag\\\`echo h\'nag\\\`'l' @@ -65,6 +65,6 @@ expected_region_highlight=( '98 101 back-quoted-argument-delimiter' # \\\` '102 104 single-quoted-argument' # 'l' '106 108 default' # fht - '109 109 command-substitution-delimiter' # ) + '109 109 command-substitution-delimiter-unquoted' # ) '113 113 unknown-token' # ` ) diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index f051e4a..51abddb 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -34,8 +34,8 @@ expected_region_highlight=( '1 1 builtin' # : '3 8 default' # "$(:)" '3 8 double-quoted-argument' # "$(:)" - '4 7 command-substitution' # $(:) - '4 5 command-substitution-delimiter' # $( + '4 7 command-substitution-quoted' # $(:) + '4 5 command-substitution-delimiter-quoted' # $( '6 6 builtin' # : - '7 7 command-substitution-delimiter' # ) + '7 7 command-substitution-delimiter-quoted' # ) ) diff --git a/highlighters/main/test-data/redirection-in-cmdsubst.zsh b/highlighters/main/test-data/redirection-in-cmdsubst.zsh index 65c7fbf..ed5eaef 100644 --- a/highlighters/main/test-data/redirection-in-cmdsubst.zsh +++ b/highlighters/main/test-data/redirection-in-cmdsubst.zsh @@ -33,9 +33,9 @@ BUFFER=$': $( Date: Thu, 18 Oct 2018 23:45:17 +0000 Subject: [PATCH 002/297] Fix a long-standing bug in a unit test. This uncovers a regression. The test never actually defined a function named 'alias1', not even when zsh 5.4 warned it about this (see 9523d6d49cb3d4db5bd84c3cec6168a2057fe3ab, which was wrong and is hereby reverted). The test that's now failing has been filed as issue #558. --- highlighters/main/test-data/alias.zsh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index fd867bf..9a45367 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -29,10 +29,7 @@ alias alias1="unused expansion" alias -s alias2="echo" -if set -o | grep -q aliasfuncdef; then - setopt alias_func_def # 5.4+ -fi -alias1() {} # to check that it's highlighted as an alias, not as a function +function alias1() {} # to check that it's highlighted as an alias, not as a function BUFFER='x.alias2; alias1' @@ -50,5 +47,5 @@ if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then fi expected_region_highlight+=( "9 9 commandseparator" # ; - "11 16 alias" # alias1 + "11 16 alias 'issue #558'" # alias1 ) From df8b2fb867f3b91800a752bc572aee2197cdfac3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 18 Oct 2018 23:48:17 +0000 Subject: [PATCH 003/297] tests: Fix a failing test. Update the test point for f3410c5862fc6d89ee3661f7d140e570d6740e8c (#264), which changed the highlighting of aliases to consider what they resolve to. Now the test file has both ${aliases[alias1]} and ${functions[alias1]}, the expectation is 'alias', and passes; thus: Fixes #588. --- highlighters/main/test-data/alias.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 9a45367..9699f0b 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias alias1="unused expansion" +alias alias1="ls" alias -s alias2="echo" function alias1() {} # to check that it's highlighted as an alias, not as a function @@ -47,5 +47,5 @@ if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then fi expected_region_highlight+=( "9 9 commandseparator" # ; - "11 16 alias 'issue #558'" # alias1 + "11 16 alias" # alias1 ) From 6898f710165218f63bf8c2f586ddec6c4963f7f6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 21 Oct 2018 00:26:34 +0000 Subject: [PATCH 004/297] Add a test. Related to https://github.com/zsh-users/zsh-syntax-highlighting/issues/549#issuecomment-431628338 and to #556. --- highlighters/main/test-data/alias-to-dir.zsh | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/alias-to-dir.zsh diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh new file mode 100644 index 0000000..5e78e14 --- /dev/null +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +alias x=/ +BUFFER=$'x' + +expected_region_highlight=( + '1 1 unknown-token' # x +) From b9d7fe5a43a77d148608dd59e5e29a8033d993b3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 17 Oct 2018 20:08:45 -0500 Subject: [PATCH 005/297] main: Shift args rather than iterating over No functional change. Prepares for running a full alias through the state machine. --- highlighters/main/main-highlighter.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 455c21f..e6846c6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -400,9 +400,11 @@ _zsh_highlight_main_highlighter_highlight_list() else args=(${(z)buf}) fi - for arg in $args; do + while (( $#args )); do # Save an unmunged copy of the current word. + arg=$args[1] arg_raw="$arg" + shift args # Initialize this_word and next_word. if (( in_redirection == 0 )); then From 02f4a6b540c33e072a35c8a8f43adfc4e513201c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 10 Oct 2018 10:07:57 +0000 Subject: [PATCH 006/297] 'main': Optionally ignore aliases in __type --- highlighters/main/main-highlighter.zsh | 32 +++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e6846c6..8b24c42 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -128,22 +128,36 @@ _zsh_highlight_main_calculate_fallback() { # Uses the zsh/parameter module if available to avoid forks, and a # wrapper around 'type -w' as fallback. # -# Takes a single argument. +# If $2 is 0, do not consider aliases. # # The result will be stored in REPLY. _zsh_highlight_main__type() { + integer -r aliases_allowed=${2-1} + # We won't cache replies of anything that exists as an alias at all, to + # ensure the cached value is correct regardless of $aliases_allowed. + # + # ### We probably _should_ cache them in a cache that's keyed on the value of + # ### $aliases_allowed, on the assumption that aliases are the common case. + integer may_cache=1 + + # Cache lookup if (( $+_zsh_highlight_main__command_type_cache )); then REPLY=$_zsh_highlight_main__command_type_cache[(e)$1] if [[ -n "$REPLY" ]]; then return fi fi + + # Main logic if (( $#options_to_set )); then setopt localoptions $options_to_set; fi unset REPLY if zmodload -e zsh/parameter; then if (( $+aliases[(e)$1] )); then + may_cache=0 + fi + if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then REPLY=alias elif (( $+saliases[(e)${1##*.}] )); then REPLY='suffix alias' @@ -168,9 +182,21 @@ _zsh_highlight_main__type() { fi if ! (( $+REPLY )); then # Note that 'type -w' will run 'rehash' implicitly. - REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" + # + # We 'unalias' in a subshell, so the parent shell is not affected. + # + # The colon command is there just to avoid a command substitution that + # starts with an arithmetic expression [«((…))» as the first thing inside + # «$(…)»], which is area that has had some parsing bugs before 5.6 + # (approximately). + REPLY="${$(:; (( aliases_allowed )) || unalias -- $1 2>/dev/null; LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" + if [[ $REPLY == 'alias' ]]; then + may_cache=0 + fi fi - if (( $+_zsh_highlight_main__command_type_cache )); then + + # Cache population + if (( may_cache )) && (( $+_zsh_highlight_main__command_type_cache )); then _zsh_highlight_main__command_type_cache[(e)$1]=$REPLY fi [[ -n $REPLY ]] From 8f17e4e201a5d122e02e171a73be6231ad4243c8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 17 Oct 2018 21:18:32 -0500 Subject: [PATCH 007/297] main: Add trivial condition and remove whitespace to simplify next diff --- highlighters/main/main-highlighter.zsh | 192 +++++++++++++------------ 1 file changed, 97 insertions(+), 95 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8b24c42..4666f48 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -455,60 +455,62 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi - # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - start_pos=$end_pos - if [[ $arg == ';' ]] ; then - # We're looking for either a semicolon or a newline, whichever comes - # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} - # flag. - # - # We can't use the (Z+n+) flag because that elides the end-of-command - # token altogether, so 'echo foo\necho bar' (two commands) becomes - # indistinguishable from 'echo foo echo bar' (one command with three - # words for arguments). - local needle=$'[;\n]' - integer offset=$(( ${proc_buf[(i)$needle]} - 1 )) - (( start_pos += offset )) - (( end_pos = start_pos + $#arg )) - else - # The line was: - # - # integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}})) - # - # - len-start_pos is length of current proc_buf; basically: initial length minus where - # we are, and proc_buf is chopped to the "where we are" (compare the "previous value - # of start_pos" below, and the len-(start_pos-offset) = len-start_pos+offset) - # - what's after main minus sign is: length of proc_buf without spaces at the beginning - # - so what the line actually did, was computing length of the spaces! - # - this can be done via (#b) flag, like below - if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')##)* ]]; then - # The first, outer parenthesis - integer offset="${#match[1]}" + if true; then + # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. + start_pos=$end_pos + if [[ $arg == ';' ]] ; then + # We're looking for either a semicolon or a newline, whichever comes + # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} + # flag. + # + # We can't use the (Z+n+) flag because that elides the end-of-command + # token altogether, so 'echo foo\necho bar' (two commands) becomes + # indistinguishable from 'echo foo echo bar' (one command with three + # words for arguments). + local needle=$'[;\n]' + integer offset=$(( ${proc_buf[(i)$needle]} - 1 )) + (( start_pos += offset )) + (( end_pos = start_pos + $#arg )) else - integer offset=0 + # The line was: + # + # integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}})) + # + # - len-start_pos is length of current proc_buf; basically: initial length minus where + # we are, and proc_buf is chopped to the "where we are" (compare the "previous value + # of start_pos" below, and the len-(start_pos-offset) = len-start_pos+offset) + # - what's after main minus sign is: length of proc_buf without spaces at the beginning + # - so what the line actually did, was computing length of the spaces! + # - this can be done via (#b) flag, like below + if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')##)* ]]; then + # The first, outer parenthesis + integer offset="${#match[1]}" + else + integer offset=0 + fi + ((start_pos+=offset)) + ((end_pos=$start_pos+${#arg})) fi - ((start_pos+=offset)) - ((end_pos=$start_pos+${#arg})) - fi - # Compute the new $proc_buf. We advance it - # (chop off characters from the beginning) - # beyond what end_pos points to, by skipping - # as many characters as end_pos was advanced. - # - # end_pos was advanced by $offset (via start_pos) - # and by $#arg. Note the `start_pos=$end_pos` - # below. - # - # As for the [,len]. We could use [,len-start_pos+offset] - # here, but to make it easier on eyes, we use len and - # rely on the fact that Zsh simply handles that. The - # length of proc_buf is len-start_pos+offset because - # we're chopping it to match current start_pos, so its - # length matches the previous value of start_pos. - # - # Why [,-1] is slower than [,length] isn't clear. - proc_buf="${proc_buf[offset + $#arg + 1,len]}" + # Compute the new $proc_buf. We advance it + # (chop off characters from the beginning) + # beyond what end_pos points to, by skipping + # as many characters as end_pos was advanced. + # + # end_pos was advanced by $offset (via start_pos) + # and by $#arg. Note the `start_pos=$end_pos` + # below. + # + # As for the [,len]. We could use [,len-start_pos+offset] + # here, but to make it easier on eyes, we use len and + # rely on the fact that Zsh simply handles that. The + # length of proc_buf is len-start_pos+offset because + # we're chopping it to match current start_pos, so its + # length matches the previous value of start_pos. + # + # Why [,-1] is slower than [,length] isn't clear. + proc_buf="${proc_buf[offset + $#arg + 1,len]}" + fi # Handle the INTERACTIVE_COMMENTS option. # @@ -531,55 +533,55 @@ _zsh_highlight_main_highlighter_highlight_list() local res="$REPLY" if [[ $res == "alias" ]]; then () { - local -A seen_arg - while [[ $REPLY == alias ]]; do - seen_arg[$arg]=1 - _zsh_highlight_main__resolve_alias $arg - # Use a temporary array to ensure the subscript is interpreted as - # an array subscript, not as a scalar subscript - local -a reply - # TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh - reply=( ${interactive_comments-${(z)REPLY}} - ${interactive_comments+${(zZ+c+)REPLY}} ) - # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' - [[ $arg == $reply[1] ]] && break - arg=$reply[1] - if (( $+seen_arg[$arg] )); then - res=none - break - fi - _zsh_highlight_main__type "$arg" - done + local -A seen_arg + while [[ $REPLY == alias ]]; do + seen_arg[$arg]=1 + _zsh_highlight_main__resolve_alias $arg + # Use a temporary array to ensure the subscript is interpreted as + # an array subscript, not as a scalar subscript + local -a reply + # TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh + reply=( ${interactive_comments-${(z)REPLY}} + ${interactive_comments+${(zZ+c+)REPLY}} ) + # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' + [[ $arg == $reply[1] ]] && break + arg=$reply[1] + if (( $+seen_arg[$arg] )); then + res=none + break + fi + _zsh_highlight_main__type "$arg" + done } _zsh_highlight_main_highlighter_expand_path $arg arg=$REPLY () { - # Make sure to use $arg_raw here, rather than $arg. - integer insane_alias - case $arg_raw in - # Issue #263: aliases with '=' on their LHS. - # - # There are three cases: - # - # - Unsupported, breaks 'alias -L' output, but invokable: - ('='*) :;; - # - Unsupported, not invokable: - (*'='*) insane_alias=1;; - # - The common case: - (*) :;; - esac - if (( insane_alias )); then - style=unknown-token - # Calling 'type' again; since __type memoizes the answer, this call is just a hash lookup. - elif ! _zsh_highlight_main__type "$arg" || [[ $REPLY == 'none' ]]; then - style=unknown-token - else - # The common case. - style=alias - if (( ${+precommand_options[(re)"$arg"]} )) && (( ! ${+precommand_options[(re)"$arg_raw"]} )); then - precommand_options[$arg_raw]=$precommand_options[$arg] - fi + # Make sure to use $arg_raw here, rather than $arg. + integer insane_alias + case $arg_raw in + # Issue #263: aliases with '=' on their LHS. + # + # There are three cases: + # + # - Unsupported, breaks 'alias -L' output, but invokable: + ('='*) :;; + # - Unsupported, not invokable: + (*'='*) insane_alias=1;; + # - The common case: + (*) :;; + esac + if (( insane_alias )); then + style=unknown-token + # Calling 'type' again; since __type memoizes the answer, this call is just a hash lookup. + elif ! _zsh_highlight_main__type "$arg" || [[ $REPLY == 'none' ]]; then + style=unknown-token + else + # The common case. + style=alias + if (( ${+precommand_options[(re)"$arg"]} )) && (( ! ${+precommand_options[(re)"$arg_raw"]} )); then + precommand_options[$arg_raw]=$precommand_options[$arg] fi + fi } else _zsh_highlight_main_highlighter_expand_path $arg From 2d4fe988baf2390eb08d8f1604bb8daa1fc58dcc Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Oct 2018 22:36:01 -0500 Subject: [PATCH 008/297] main: Rename parameters to simplify next diff --- highlighters/main/main-highlighter.zsh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4666f48..9776ba4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -533,20 +533,20 @@ _zsh_highlight_main_highlighter_highlight_list() local res="$REPLY" if [[ $res == "alias" ]]; then () { - local -A seen_arg + local -A seen_alias while [[ $REPLY == alias ]]; do - seen_arg[$arg]=1 + seen_alias[$arg]=1 _zsh_highlight_main__resolve_alias $arg # Use a temporary array to ensure the subscript is interpreted as # an array subscript, not as a scalar subscript - local -a reply + local -a alias_args # TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh - reply=( ${interactive_comments-${(z)REPLY}} - ${interactive_comments+${(zZ+c+)REPLY}} ) + alias_args=( ${interactive_comments-${(z)REPLY}} + ${interactive_comments+${(zZ+c+)REPLY}} ) # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' - [[ $arg == $reply[1] ]] && break - arg=$reply[1] - if (( $+seen_arg[$arg] )); then + [[ $arg == $alias_args[1] ]] && break + arg=$alias_args[1] + if (( $+seen_alias[$arg] )); then res=none break fi From cb8c736a564e0023a0ef4e7635c0eb4be5eb56a4 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 17 Oct 2018 21:38:17 -0500 Subject: [PATCH 009/297] main: Run the entirety of aliases through the state machine Fixes #540 #544 #552 #554 #555 --- highlighters/main/main-highlighter.zsh | 87 ++++++++++--------- .../main/test-data/alias-comment1.zsh | 3 +- .../main/test-data/alias-comment2.zsh | 3 +- highlighters/main/test-data/alias-loop.zsh | 3 +- .../test-data/alias-nested-precommand.zsh | 1 + highlighters/main/test-data/alias-nested.zsh | 1 + ... => alias-precommand-option-argument1.zsh} | 3 +- .../alias-precommand-option-argument2.zsh | 43 +++++++++ highlighters/main/test-data/alias-quoted.zsh | 2 +- .../main/test-data/alias-redirect.zsh | 3 +- highlighters/main/test-data/alias-self.zsh | 1 + highlighters/main/test-data/alias-to-dir.zsh | 3 +- highlighters/main/test-data/alias.zsh | 1 + highlighters/main/test-data/noglob-alias.zsh | 1 + highlighters/main/test-data/off-by-one.zsh | 5 +- 15 files changed, 108 insertions(+), 52 deletions(-) rename highlighters/main/test-data/{alias-precommand-option-argument.zsh => alias-precommand-option-argument1.zsh} (97%) create mode 100644 highlighters/main/test-data/alias-precommand-option-argument2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9776ba4..7f8c47b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -72,6 +72,9 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 + (( highlighted_alias )) && return + (( in_alias )) && highlighted_alias=1 + # The calculation was relative to $buf but region_highlight is relative to $BUFFER. (( start += buf_offset )) (( end += buf_offset )) @@ -363,10 +366,18 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main_highlighter_highlight_list() { integer start_pos end_pos=0 buf_offset=$1 has_end=$3 - local buf=$4 highlight_glob=true arg arg_raw style + # last_alias is the last alias arg (lhs) expanded (if in an alias). + # This allows for expanding alias ls='ls -l' while avoiding loops. + local arg buf=$4 highlight_glob=true last_alias style local in_array_assignment=false # true between 'a=(' and the matching ')' - integer len=$#buf + # highlighted_alias is 1 when the alias arg has been highlighted with a non-alias style. + # E.g. alias x=ls; x has been highlighted as alias AND command. + # in_alias is equal to the number of shifts needed until arg=args[1] pops an + # arg from BUFFER and not added by an alias. + integer highlighted_alias=0 in_alias=0 len=$#buf local -a match mbegin mend list_highlights + # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a + local -A seen_alias list_highlights=() # "R" for round @@ -427,10 +438,12 @@ _zsh_highlight_main_highlighter_highlight_list() args=(${(z)buf}) fi while (( $#args )); do - # Save an unmunged copy of the current word. arg=$args[1] - arg_raw="$arg" shift args + if (( in_alias )); then + (( in_alias-- )) + (( in_alias == 0 )) && highlighted_alias=0 last_alias= seen_alias=() + fi # Initialize this_word and next_word. if (( in_redirection == 0 )); then @@ -455,7 +468,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi - if true; then + if (( in_alias == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. start_pos=$end_pos if [[ $arg == ';' ]] ; then @@ -531,34 +544,20 @@ _zsh_highlight_main_highlighter_highlight_list() # Expand aliases. _zsh_highlight_main__type "$arg" local res="$REPLY" - if [[ $res == "alias" ]]; then - () { - local -A seen_alias - while [[ $REPLY == alias ]]; do + if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then + # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' + if (( $+seen_alias[$arg] )); then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token + continue + fi seen_alias[$arg]=1 + last_alias=$arg _zsh_highlight_main__resolve_alias $arg - # Use a temporary array to ensure the subscript is interpreted as - # an array subscript, not as a scalar subscript local -a alias_args - # TODO: the ${interactive_comments+set} path needs to skip comments; see test-data/alias-comment1.zsh + # Elision is desired in case alias x='' alias_args=( ${interactive_comments-${(z)REPLY}} ${interactive_comments+${(zZ+c+)REPLY}} ) - # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' - [[ $arg == $alias_args[1] ]] && break - arg=$alias_args[1] - if (( $+seen_alias[$arg] )); then - res=none - break - fi - _zsh_highlight_main__type "$arg" - done - } - _zsh_highlight_main_highlighter_expand_path $arg - arg=$REPLY - () { - # Make sure to use $arg_raw here, rather than $arg. - integer insane_alias - case $arg_raw in + case $arg in # Issue #263: aliases with '=' on their LHS. # # There are three cases: @@ -566,27 +565,29 @@ _zsh_highlight_main_highlighter_highlight_list() # - Unsupported, breaks 'alias -L' output, but invokable: ('='*) :;; # - Unsupported, not invokable: - (*'='*) insane_alias=1;; + (*'='*) + _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token + continue + ;; # - The common case: (*) :;; esac - if (( insane_alias )); then - style=unknown-token - # Calling 'type' again; since __type memoizes the answer, this call is just a hash lookup. - elif ! _zsh_highlight_main__type "$arg" || [[ $REPLY == 'none' ]]; then - style=unknown-token + args=( $alias_args $args ) + if (( in_alias == 0 )); then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias + # Add one because we will in_alias-- on the next loop iteration so + # this iteration should be considered in in_alias as well + (( in_alias += $#alias_args + 1 )) else - # The common case. - style=alias - if (( ${+precommand_options[(re)"$arg"]} )) && (( ! ${+precommand_options[(re)"$arg_raw"]} )); then - precommand_options[$arg_raw]=$precommand_options[$arg] - fi + # This arg is already included in the count, so no need to + 1. + (( in_alias += $#alias_args )) fi - } + (( in_redirection++ )) # Stall this arg + continue else _zsh_highlight_main_highlighter_expand_path $arg arg=$REPLY - _zsh_highlight_main__type "$arg" + _zsh_highlight_main__type "$arg" 0 res="$REPLY" fi fi @@ -635,7 +636,7 @@ _zsh_highlight_main_highlighter_highlight_list() arg=${(P)MATCH} ;; esac - _zsh_highlight_main__type "$arg" + _zsh_highlight_main__type "$arg" 0 res=$REPLY fi } @@ -703,7 +704,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then - [[ $res != alias ]] && style=precommand + style=precommand flags_with_argument=${precommand_options[$arg]%:*} flags_sans_argument=${precommand_options[$arg]#*:} next_word=${next_word//:regular:/} diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index a2b56c6..0c449e1 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -33,5 +33,6 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - "1 1 alias 'interactivecomments applies to aliases'" # x becomes pwd + '1 1 alias' # x + '1 1 comment' # x (#) ) diff --git a/highlighters/main/test-data/alias-comment2.zsh b/highlighters/main/test-data/alias-comment2.zsh index e9ecfca..8bdc5a8 100644 --- a/highlighters/main/test-data/alias-comment2.zsh +++ b/highlighters/main/test-data/alias-comment2.zsh @@ -33,5 +33,6 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - "1 1 unknown-token" # x becomes # + '1 1 alias' # x + '1 1 unknown-token' # x (#) ) diff --git a/highlighters/main/test-data/alias-loop.zsh b/highlighters/main/test-data/alias-loop.zsh index 46e900b..b36d1c9 100644 --- a/highlighters/main/test-data/alias-loop.zsh +++ b/highlighters/main/test-data/alias-loop.zsh @@ -33,7 +33,8 @@ alias a=b b=c c=b BUFFER='a foo; :' expected_region_highlight=( - '1 1 unknown-token' # a + '1 1 alias' # a + '1 1 unknown-token' # a (invalid alias loop) '3 5 default' # foo '6 6 commandseparator' # ; '8 8 builtin' # : diff --git a/highlighters/main/test-data/alias-nested-precommand.zsh b/highlighters/main/test-data/alias-nested-precommand.zsh index 6d4172b..7c2eeeb 100644 --- a/highlighters/main/test-data/alias-nested-precommand.zsh +++ b/highlighters/main/test-data/alias-nested-precommand.zsh @@ -35,6 +35,7 @@ BUFFER='a -u phy1729 echo; :' expected_region_highlight=( '1 1 alias' # a + '1 1 precommand' # a (sudo) '3 4 single-hyphen-option' # -u '6 12 default' # phy1729 '14 17 builtin' # echo diff --git a/highlighters/main/test-data/alias-nested.zsh b/highlighters/main/test-data/alias-nested.zsh index b24b496..44ab22b 100644 --- a/highlighters/main/test-data/alias-nested.zsh +++ b/highlighters/main/test-data/alias-nested.zsh @@ -34,6 +34,7 @@ BUFFER='a foo; :' expected_region_highlight=( '1 1 alias' # a + '1 1 builtin' # a (:) '3 5 default' # foo '6 6 commandseparator' # ; '8 8 builtin' # : diff --git a/highlighters/main/test-data/alias-precommand-option-argument.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh similarity index 97% rename from highlighters/main/test-data/alias-precommand-option-argument.zsh rename to highlighters/main/test-data/alias-precommand-option-argument1.zsh index ac96ad6..ad16962 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -35,7 +35,8 @@ BUFFER='sdu phy1729 echo foo' expected_region_highlight=( '1 3 alias' # sdu - '5 11 default "issue #540"' # phy1729 + '1 3 precommand' # sdu (sudo) + '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo ) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh new file mode 100644 index 0000000..2fceff8 --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +alias sde='sudo -e' +alias seu='sde -u' +sudo(){} + +BUFFER='seu phy1729 echo foo' + +expected_region_highlight=( + '1 3 alias' # seu + '1 3 precommand' # seu (sudo) + '5 11 default' # phy1729 + '13 16 commmand "issue #540"' # echo (not builtin) + '18 20 default' # foo +) diff --git a/highlighters/main/test-data/alias-quoted.zsh b/highlighters/main/test-data/alias-quoted.zsh index bf397f9..e42e2f0 100644 --- a/highlighters/main/test-data/alias-quoted.zsh +++ b/highlighters/main/test-data/alias-quoted.zsh @@ -35,5 +35,5 @@ expected_region_highlight=( '1 3 unknown-token' # "a" '5 7 default' # foo '8 8 commandseparator' # ; - '10 12 command "issue #544' # \ls + '10 12 command' # \ls ) diff --git a/highlighters/main/test-data/alias-redirect.zsh b/highlighters/main/test-data/alias-redirect.zsh index 518cdc3..a6a0aab 100644 --- a/highlighters/main/test-data/alias-redirect.zsh +++ b/highlighters/main/test-data/alias-redirect.zsh @@ -31,7 +31,8 @@ alias x=\> BUFFER='x foo echo bar' expected_region_highlight=( - '1 1 redirection' # x becomes > + '1 1 alias' # x + '1 1 redirection' # x (>) '3 5 default' # foo '7 10 builtin' # echo '12 14 default' # bar diff --git a/highlighters/main/test-data/alias-self.zsh b/highlighters/main/test-data/alias-self.zsh index c6f12b1..88ed3c8 100644 --- a/highlighters/main/test-data/alias-self.zsh +++ b/highlighters/main/test-data/alias-self.zsh @@ -34,5 +34,6 @@ BUFFER='echo bar' expected_region_highlight=( '1 4 alias' # echo + '1 4 builtin' # echo '6 8 default' # bar ) diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh index 5e78e14..93aaa62 100644 --- a/highlighters/main/test-data/alias-to-dir.zsh +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -32,5 +32,6 @@ alias x=/ BUFFER=$'x' expected_region_highlight=( - '1 1 unknown-token' # x + '1 1 alias' # x + '1 1 unknown-token "issue #202"' # x (/) ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 9699f0b..8330a04 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -48,4 +48,5 @@ fi expected_region_highlight+=( "9 9 commandseparator" # ; "11 16 alias" # alias1 + "11 16 command" # alias1 (ls) ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 2f96445..5676b5a 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -32,5 +32,6 @@ BUFFER='x ls' expected_region_highlight=( "1 1 alias" # x + "1 1 precommand" # x (command) "3 4 command" # ls ) diff --git a/highlighters/main/test-data/off-by-one.zsh b/highlighters/main/test-data/off-by-one.zsh index 3870e20..7d6961a 100644 --- a/highlighters/main/test-data/off-by-one.zsh +++ b/highlighters/main/test-data/off-by-one.zsh @@ -33,8 +33,9 @@ f() {} BUFFER='a;f;' expected_region_highlight=( - "1 1 alias" # f + "1 1 alias" # a + "1 1 builtin" # a (:) "2 2 commandseparator" # ; - "3 3 function" # g + "3 3 function" # f "4 4 commandseparator" # ; ) From 7388adf4e86a652f76f173c33f26878ddca2142d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 19 Oct 2018 11:56:20 -0500 Subject: [PATCH 010/297] main: Add alias tests --- highlighters/main/test-data/alias-complex.zsh | 39 +++++++++++++++++++ highlighters/main/test-data/alias-empty.zsh | 38 ++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 highlighters/main/test-data/alias-complex.zsh create mode 100644 highlighters/main/test-data/alias-empty.zsh diff --git a/highlighters/main/test-data/alias-complex.zsh b/highlighters/main/test-data/alias-complex.zsh new file mode 100644 index 0000000..7a9626e --- /dev/null +++ b/highlighters/main/test-data/alias-complex.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +alias x='echo && ls; >' + +BUFFER='x file echo' + +expected_region_highlight=( + '1 1 alias' # x + '1 1 builtin' # x (echo) + '3 6 default' # file + '8 11 builtin' # echo +) diff --git a/highlighters/main/test-data/alias-empty.zsh b/highlighters/main/test-data/alias-empty.zsh new file mode 100644 index 0000000..535fccc --- /dev/null +++ b/highlighters/main/test-data/alias-empty.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +alias x='' + +BUFFER='x echo foo' + +expected_region_highlight=( + '1 1 alias' # x + '3 6 builtin' # echo + '8 10 default' # foo +) From d0c23a68b381f29847693205628a2bb562f1a70b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Oct 2018 22:42:00 -0500 Subject: [PATCH 011/297] main: Simplify proc_buf offset calculation Fixes #347 --- highlighters/main/main-highlighter.zsh | 39 +++------------------- highlighters/main/test-data/empty-line.zsh | 36 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 highlighters/main/test-data/empty-line.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7f8c47b..fc5c7db 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -470,40 +470,11 @@ _zsh_highlight_main_highlighter_highlight_list() if (( in_alias == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - start_pos=$end_pos - if [[ $arg == ';' ]] ; then - # We're looking for either a semicolon or a newline, whichever comes - # first. Both of these are rendered as a ";" (SEPER) by the ${(z)..} - # flag. - # - # We can't use the (Z+n+) flag because that elides the end-of-command - # token altogether, so 'echo foo\necho bar' (two commands) becomes - # indistinguishable from 'echo foo echo bar' (one command with three - # words for arguments). - local needle=$'[;\n]' - integer offset=$(( ${proc_buf[(i)$needle]} - 1 )) - (( start_pos += offset )) - (( end_pos = start_pos + $#arg )) - else - # The line was: - # - # integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}})) - # - # - len-start_pos is length of current proc_buf; basically: initial length minus where - # we are, and proc_buf is chopped to the "where we are" (compare the "previous value - # of start_pos" below, and the len-(start_pos-offset) = len-start_pos+offset) - # - what's after main minus sign is: length of proc_buf without spaces at the beginning - # - so what the line actually did, was computing length of the spaces! - # - this can be done via (#b) flag, like below - if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')##)* ]]; then - # The first, outer parenthesis - integer offset="${#match[1]}" - else - integer offset=0 - fi - ((start_pos+=offset)) - ((end_pos=$start_pos+${#arg})) - fi + [[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]] + # The first, outer parenthesis + integer offset="${#match[1]}" + (( start_pos = end_pos + offset )) + (( end_pos = start_pos + $#arg )) # Compute the new $proc_buf. We advance it # (chop off characters from the beginning) diff --git a/highlighters/main/test-data/empty-line.zsh b/highlighters/main/test-data/empty-line.zsh new file mode 100644 index 0000000..a4d6685 --- /dev/null +++ b/highlighters/main/test-data/empty-line.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'\\\n; ls' + +expected_region_highlight=( + '3 3 unknown-token' # ; + '5 6 command' # ls +) From f71a17c58ebae25ca1eed5410407149193062332 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Oct 2018 23:47:37 -0500 Subject: [PATCH 012/297] main: Highlight closing brackets Closes #226 --- highlighters/main/main-highlighter.zsh | 17 +++++++- .../main/test-data/brackets-matching1.zsh | 38 ++++++++++++++++++ .../main/test-data/brackets-matching2.zsh | 38 ++++++++++++++++++ .../brackets-premature-termination.zsh | 40 +++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/brackets-matching1.zsh create mode 100644 highlighters/main/test-data/brackets-matching2.zsh create mode 100644 highlighters/main/test-data/brackets-premature-termination.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index fc5c7db..24460e0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -383,6 +383,7 @@ _zsh_highlight_main_highlighter_highlight_list() # "R" for round # "Q" for square # "Y" for curly + # "T" for [[ ]] # "S" for $( ) # "D" for do/done # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) @@ -655,7 +656,10 @@ _zsh_highlight_main_highlighter_highlight_list() # The Great Fork: is this a command word? Is this a non-command word? if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - if [[ $this_word == *':regular:'* ]]; then + if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then + # Missing closing square bracket(s) + style=unknown-token + elif [[ $this_word == *':regular:'* ]]; then # This highlights empty commands (semicolon follows nothing) as an error. # Zsh accepts them, though. style=commandseparator @@ -698,6 +702,9 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':always:' fi ;; + ($'\x5b\x5b') + braces_stack='T'"$braces_stack" + ;; ('do') braces_stack='D'"$braces_stack" ;; @@ -748,7 +755,9 @@ _zsh_highlight_main_highlighter_highlight_list() ;; 'suffix alias') style=suffix-alias;; alias) :;; - builtin) style=builtin;; + builtin) style=builtin + [[ $arg == $'\x5b' ]] && braces_stack='Q'"$braces_stack" + ;; function) style=function;; command) style=command;; hashed) style=hashed-command;; @@ -864,6 +873,10 @@ _zsh_highlight_main_highlighter_highlight_list() fi elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion + elif [[ $arg == $'\x5d\x5d' ]] && _zsh_highlight_main__stack_pop 'T' reserved-word; then + : + elif [[ $arg == $'\x5d' ]] && _zsh_highlight_main__stack_pop 'Q' builtin; then + : else _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 - in_redirection )) continue diff --git a/highlighters/main/test-data/brackets-matching1.zsh b/highlighters/main/test-data/brackets-matching1.zsh new file mode 100644 index 0000000..7cc6de5 --- /dev/null +++ b/highlighters/main/test-data/brackets-matching1.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='[[ -n foo ]]' + +expected_region_highlight=( + '1 2 reserved-word' # [[ + '4 5 single-hyphen-option' # -n + '7 9 default' # foo + '11 12 reserved-word' # ]] +) diff --git a/highlighters/main/test-data/brackets-matching2.zsh b/highlighters/main/test-data/brackets-matching2.zsh new file mode 100644 index 0000000..19c7f0d --- /dev/null +++ b/highlighters/main/test-data/brackets-matching2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='[ -n foo ]' + +expected_region_highlight=( + '1 1 builtin' # [ + '3 4 single-hyphen-option' # -n + '6 8 default' # foo + '10 10 builtin' # ] +) diff --git a/highlighters/main/test-data/brackets-premature-termination.zsh b/highlighters/main/test-data/brackets-premature-termination.zsh new file mode 100644 index 0000000..fa813da --- /dev/null +++ b/highlighters/main/test-data/brackets-premature-termination.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='[[ -n foo; echo ]]' + +expected_region_highlight=( + '1 2 reserved-word' # [[ + '4 5 single-hyphen-option' # -n + '7 9 default' # foo + '10 10 unknown-token' # ; + '12 15 builtin' # echo + '17 18 default' # ]] +) From a3c9e7ebc7e7a31ab9ed49eebbe2e666b6280a9e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 21 Oct 2018 14:59:52 -0500 Subject: [PATCH 013/297] main: Simplify insane alias checking --- highlighters/main/main-highlighter.zsh | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 24460e0..7c8d647 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -518,7 +518,8 @@ _zsh_highlight_main_highlighter_highlight_list() local res="$REPLY" if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' - if (( $+seen_alias[$arg] )); then + # Also mark insane aliases as unknown-token (cf. #263). + if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi @@ -529,21 +530,6 @@ _zsh_highlight_main_highlighter_highlight_list() # Elision is desired in case alias x='' alias_args=( ${interactive_comments-${(z)REPLY}} ${interactive_comments+${(zZ+c+)REPLY}} ) - case $arg in - # Issue #263: aliases with '=' on their LHS. - # - # There are three cases: - # - # - Unsupported, breaks 'alias -L' output, but invokable: - ('='*) :;; - # - Unsupported, not invokable: - (*'='*) - _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token - continue - ;; - # - The common case: - (*) :;; - esac args=( $alias_args $args ) if (( in_alias == 0 )); then _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias From de23e759462ce292cfcd4ba51d3d7c71b653eba2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 04:27:18 +0000 Subject: [PATCH 014/297] minor: Fix the editor braces matching confusion prevention sentinel. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7c8d647..c6bf1b3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -845,7 +845,7 @@ _zsh_highlight_main_highlighter_highlight_list() ;; *) if false; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then - # Parsing rule: } + # Parsing rule: { # # Additionally, `tt(})' is recognized in any position if neither the # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. From 38c794a978cdbe9e82156029fc3ae888e2b6b075 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 04:30:43 +0000 Subject: [PATCH 015/297] 'main': Highlight named fd redirections. Fixes #238 --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 11 +++++++++-- highlighters/main/test-data/exec-redirection1.zsh | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 6ff2bd8..005fc4d 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -58,6 +58,7 @@ This highlighter defines the following styles: * `assign` - parameter assignments (`x=foo` and `x=( )`) * `redirection` - redirection operators (`<`, `>`, etc) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `named-fd` - named file descriptor (`echo foo {fd}>&2`) * `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command). * `default` - everything else diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c6bf1b3..89b2fdb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -58,6 +58,7 @@ : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} : ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} : ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} +: ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none} : ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green} # Whether the highlighter should be called or not. @@ -552,13 +553,19 @@ _zsh_highlight_main_highlighter_highlight_list() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then - if (( in_redirection )); then + if (( in_redirection && in_redirection != 2 )); then + # The condition excludes the case that BUFFER='{foo}>&2' and we're on the '>&'. _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token else in_redirection=2 _zsh_highlight_main_add_region_highlight $start_pos $end_pos redirection fi continue + elif [[ $arg == '{'*'}' ]] && _zsh_highlight_main__is_redirection $args[1]; then + # named file descriptor: {foo}>&2 + in_redirection=3 + _zsh_highlight_main_add_region_highlight $start_pos $end_pos named-fd + continue fi # Expand parameters. @@ -864,7 +871,7 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ $arg == $'\x5d' ]] && _zsh_highlight_main__stack_pop 'Q' builtin; then : else - _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 - in_redirection )) + _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection )) continue fi ;; diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh index caec2f1..78a0c62 100644 --- a/highlighters/main/test-data/exec-redirection1.zsh +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -31,8 +31,8 @@ BUFFER='exec {foo}>&/tmp ls' expected_region_highlight=( "1 4 precommand" # exec - "6 10 redirection 'issue #238'" # {foo} + "6 10 named-fd" # {foo} "11 12 redirection" # >& "13 16 path" # /tmp - "18 19 command 'issue #238'" # ls + "18 19 command" # ls ) From 9870ccc505006bfb682a510991cf1ea19715ef15 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 04:53:42 +0000 Subject: [PATCH 016/297] noop: Tweak condition at Matthew's suggestion --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 89b2fdb..b13a54e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -553,7 +553,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then - if (( in_redirection && in_redirection != 2 )); then + if (( in_redirection == 1 )); then # The condition excludes the case that BUFFER='{foo}>&2' and we're on the '>&'. _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token else From ad3a6cb3c957c35b8a52f83d245d0589611cf253 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 04:56:50 +0000 Subject: [PATCH 017/297] 'main': Tighten condition. Should rule out brace expansions such as '{foo,bar}' and '{10..20}'. --- highlighters/main/main-highlighter.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b13a54e..64622a6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -379,6 +379,8 @@ _zsh_highlight_main_highlighter_highlight_list() local -a match mbegin mend list_highlights # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a local -A seen_alias + # Pattern for parameter names + readonly parameter_name_pattern='([A-Za-z_][A-Za-z0-9_]*|[0-9]+)' list_highlights=() # "R" for round @@ -561,7 +563,7 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos redirection fi continue - elif [[ $arg == '{'*'}' ]] && _zsh_highlight_main__is_redirection $args[1]; then + elif [[ $arg == '{'${~parameter_name_pattern}'}' ]] && _zsh_highlight_main__is_redirection $args[1]; then # named file descriptor: {foo}>&2 in_redirection=3 _zsh_highlight_main_add_region_highlight $start_pos $end_pos named-fd @@ -587,7 +589,7 @@ _zsh_highlight_main_highlighter_highlight_list() parameter_name=${arg:1} fi if [[ $res == none ]] && zmodload -e zsh/parameter && - [[ ${parameter_name} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && + [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then # Set $arg. From 7d961ba1e6e88869e6cebbfa7dc9e412bec75906 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 04:58:25 +0000 Subject: [PATCH 018/297] 'main': Add a test for issue #237. --- .../main/test-data/function-altsyntax.zsh | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 highlighters/main/test-data/function-altsyntax.zsh diff --git a/highlighters/main/test-data/function-altsyntax.zsh b/highlighters/main/test-data/function-altsyntax.zsh new file mode 100644 index 0000000..0f9a833 --- /dev/null +++ b/highlighters/main/test-data/function-altsyntax.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +# Define named and anonymous function using the alternative syntax +BUFFER=$'function f { pwd }; function { pwd }' + +expected_region_highlight=( + '1 8 reserved-word' # function + '10 10 default' # f + '12 12 reserved-word "issue #237"' # { + '14 16 command "issue #237"' # pwd + '18 18 reserved-word "issue #237"' # } + '19 19 commandseparator' # ; + '21 28 reserved-word' # function + '30 30 reserved-word "issue #237"' # { + '32 34 command "issue #237"' # pwd + '36 36 reserved-word "issue #237"' # } +) From 48a20d067fb156278dc3d3f203043b26005e842c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 10:40:13 -0500 Subject: [PATCH 019/297] main: Break double-quoted-argument on command substitutions --- highlighters/main/main-highlighter.zsh | 14 ++++-- highlighters/main/test-data/dollar-paren.zsh | 12 +++++- .../quoted-command-substitution-empty.zsh | 43 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 highlighters/main/test-data/quoted-command-substitution-empty.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 64622a6..76dfad0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1120,8 +1120,8 @@ _zsh_highlight_main_highlighter_highlight_single_quote() # Highlight special chars inside double-quoted strings _zsh_highlight_main_highlighter_highlight_double_quote() { - local -a match mbegin mend saved_reply - local MATCH; integer MBEGIN MEND + local -a breaks match mbegin mend saved_reply + local MATCH; integer last_break=$(( start_pos + $1 - 1 )) MBEGIN MEND local i j k ret style reply=() @@ -1153,11 +1153,13 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( k += 1 )) # highlight both dollar signs (( i += 1 )) # don't consider the second one as introducing another parameter expansion elif [[ $arg[i+1] == $'\x28' ]]; then + breaks+=( $last_break $(( start_pos + i - 1 )) ) (( i += 2 )) saved_reply=($reply) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] ret=$? (( i += REPLY )) + last_break=$(( start_pos + i )) reply=( $saved_reply $j $(( start_pos + i )) command-substitution-quoted @@ -1200,7 +1202,13 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( i-- )) style=double-quoted-argument-unclosed fi - reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $reply) + (( last_break != start_pos + i )) && breaks+=( $last_break $(( start_pos + i )) ) + saved_reply=($reply) + reply=() + for 1 2 in $breaks; do + reply+=($1 $2 $style) + done + reply+=($saved_reply) REPLY=$i } diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index 51abddb..2bbcef1 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -28,14 +28,22 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=': "$(:)"' +BUFFER=': "$(:)" "foo$(:)bar' expected_region_highlight=( '1 1 builtin' # : '3 8 default' # "$(:)" - '3 8 double-quoted-argument' # "$(:)" + '3 3 double-quoted-argument' # "$(:)" + '8 8 double-quoted-argument' # "$(:)" '4 7 command-substitution-quoted' # $(:) '4 5 command-substitution-delimiter-quoted' # $( '6 6 builtin' # : '7 7 command-substitution-delimiter-quoted' # ) + '10 20 default' # "foo$(:)bar + '10 13 double-quoted-argument-unclosed' # "foo + '18 20 double-quoted-argument-unclosed' # bar + '14 17 command-substitution-quoted' # $(:) + '14 15 command-substitution-delimiter-quoted' # $( + '16 16 builtin' # : + '17 17 command-substitution-delimiter-quoted' # ) ) diff --git a/highlighters/main/test-data/quoted-command-substitution-empty.zsh b/highlighters/main/test-data/quoted-command-substitution-empty.zsh new file mode 100644 index 0000000..099f3b0 --- /dev/null +++ b/highlighters/main/test-data/quoted-command-substitution-empty.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "foo$(' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 11 default' # "foo$( + '6 9 double-quoted-argument-unclosed' # "foo + '10 11 command-substitution-quoted' # $( + '10 11 command-substitution-delimiter-quoted' # $( +) + +if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug + expected_region_highlight[2]='6 12 default' # "foo$( +fi From d9e326b9936660e46dd15899d7080df749d2ebfa Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Oct 2018 12:37:49 -0500 Subject: [PATCH 020/297] main: consume trailing whitespace in _highlight_list Fixes highlighting when an unclosed $( ends in whitespace. --- highlighters/main/main-highlighter.zsh | 3 ++- .../main/test-data/command-substitution-unclosed.zsh | 1 + highlighters/main/test-data/process-substitution2.zsh | 1 + .../main/test-data/quoted-command-substitution-empty.zsh | 9 +++++---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 76dfad0..b11b8f1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -881,7 +881,8 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style done - REPLY=$(( end_pos - 1 )) + [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] + REPLY=$(( end_pos + ${#match[1]} - 1 )) reply=($list_highlights) return $(( $#braces_stack > 0 )) } diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh index bce6863..3229dfc 100644 --- a/highlighters/main/test-data/command-substitution-unclosed.zsh +++ b/highlighters/main/test-data/command-substitution-unclosed.zsh @@ -41,4 +41,5 @@ expected_region_highlight=( if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug expected_region_highlight[2]='3 16 default' # foo$(echo bar + expected_region_highlight[3]='6 16 command-substitution-unquoted' # $(echo bar fi diff --git a/highlighters/main/test-data/process-substitution2.zsh b/highlighters/main/test-data/process-substitution2.zsh index c8c9ffe..cc55090 100644 --- a/highlighters/main/test-data/process-substitution2.zsh +++ b/highlighters/main/test-data/process-substitution2.zsh @@ -47,4 +47,5 @@ expected_region_highlight=( if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug expected_region_highlight[8]='17 27 default' # =(echo foo + expected_region_highlight[9]='17 27 process-substitution' # =(echo foo fi diff --git a/highlighters/main/test-data/quoted-command-substitution-empty.zsh b/highlighters/main/test-data/quoted-command-substitution-empty.zsh index 099f3b0..daf3738 100644 --- a/highlighters/main/test-data/quoted-command-substitution-empty.zsh +++ b/highlighters/main/test-data/quoted-command-substitution-empty.zsh @@ -28,16 +28,17 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='echo "foo$(' +BUFFER='echo "foo$( ' expected_region_highlight=( '1 4 builtin' # echo - '6 11 default' # "foo$( + '6 12 default' # "foo$( '6 9 double-quoted-argument-unclosed' # "foo - '10 11 command-substitution-quoted' # $( + '10 12 command-substitution-quoted' # $( '10 11 command-substitution-delimiter-quoted' # $( ) if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug - expected_region_highlight[2]='6 12 default' # "foo$( + expected_region_highlight[2]='6 13 default' # "foo$( + expected_region_highlight[4]='10 13 command-substitution-quoted' # $( fi From 298ef6a2fa30a5847ff468c4c9460fbddd764488 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 22 Oct 2018 15:44:55 +0000 Subject: [PATCH 021/297] main: Highlight the ! precommand as an error when not at the start of a pipeline. Fixes #511. --- highlighters/main/main-highlighter.zsh | 21 +++++++--- highlighters/main/test-data/bang-pipeline.zsh | 39 +++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 highlighters/main/test-data/bang-pipeline.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 64622a6..4916417 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -398,6 +398,8 @@ _zsh_highlight_main_highlighter_highlight_list() # # The states are: # - :start: Command word + # - :start_of_pipeline: Start of a 'pipeline' as defined in zshmisc(1). + # Only valid when :start: is present # - :sudo_opt: A leading-dash option to a precommand, whether it takes an # argument or not. (Example: sudo's "-u" or "-i".) # - :sudo_arg: The argument to a precommand's leading-dash option, @@ -431,7 +433,7 @@ _zsh_highlight_main_highlighter_highlight_list() # $in_redirection. The value of $next_word from the iteration that processed # the operator is discarded. # - local this_word next_word=':start:' + local this_word next_word=':start::start_of_pipeline:' integer in_redirection # Processing buffer local proc_buf="$buf" @@ -667,11 +669,14 @@ _zsh_highlight_main_highlighter_highlight_list() else next_word=':start:' highlight_glob=true + if [[ $arg != '|' && $arg != '|&' ]]; then + next_word+=':start_of_pipeline:' + fi fi elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then # try-always construct style=reserved-word # de facto a reserved word, although not de jure - next_word=':start:' + next_word=':start:' # only left brace is allowed, apparently elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then style=precommand @@ -684,6 +689,9 @@ _zsh_highlight_main_highlighter_highlight_list() case $res in reserved) # reserved word style=reserved-word + if [[ $arg == '!' && $this_word != *':start_of_pipeline:'* ]]; then + style=unknown-token + fi # # Match braces. case $arg in @@ -764,6 +772,9 @@ _zsh_highlight_main_highlighter_highlight_list() else # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) + # + # Discard :start_of_pipeline:, if present, as '!' is not valid + # after assignments. next_word+=':start:' if (( start_pos + i <= end_pos )); then () { @@ -822,7 +833,7 @@ _zsh_highlight_main_highlighter_highlight_list() esac fi if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then - next_word=':start:' + next_word=':start::start_of_pipeline:' fi else # $arg is a non-command word case $arg in @@ -830,7 +841,7 @@ _zsh_highlight_main_highlighter_highlight_list() if $in_array_assignment; then style=assign in_array_assignment=false - next_word+=':start:' + next_word+=':start::start_of_pipeline:' elif (( in_redirection )); then style=unknown-token else @@ -847,7 +858,7 @@ _zsh_highlight_main_highlighter_highlight_list() else if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word then - next_word+=':start:' + next_word+=':start::start_of_pipeline:' fi style=reserved-word fi diff --git a/highlighters/main/test-data/bang-pipeline.zsh b/highlighters/main/test-data/bang-pipeline.zsh new file mode 100644 index 0000000..fef25f1 --- /dev/null +++ b/highlighters/main/test-data/bang-pipeline.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'\! ls | \! ls' + +expected_region_highlight=( + '1 1 reserved-word' # \! + '3 4 command' # ls + '6 6 commandseparator' # | + '8 8 unknown-token' # \! + '10 11 command' # ls +) From 6cf522b7b319aa127625718e3a2f77a9d199ec22 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 23 Oct 2018 16:31:39 +0000 Subject: [PATCH 022/297] main: Fix highlighting of the ! precommand after array assignments. Add tests. --- highlighters/main/main-highlighter.zsh | 2 +- .../main/test-data/bang-assign-array.zsh | 40 +++++++++++++++++++ .../main/test-data/bang-assign-scalar.zsh | 38 ++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/bang-assign-array.zsh create mode 100644 highlighters/main/test-data/bang-assign-scalar.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4916417..2d2ed3e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -841,7 +841,7 @@ _zsh_highlight_main_highlighter_highlight_list() if $in_array_assignment; then style=assign in_array_assignment=false - next_word+=':start::start_of_pipeline:' + next_word+=':start:' elif (( in_redirection )); then style=unknown-token else diff --git a/highlighters/main/test-data/bang-assign-array.zsh b/highlighters/main/test-data/bang-assign-array.zsh new file mode 100644 index 0000000..77b57e6 --- /dev/null +++ b/highlighters/main/test-data/bang-assign-array.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=(bar abaz) \! ls' + +expected_region_highlight=( + '1 5 assign' # foo=( + '6 8 default' # bar + '10 13 default' # abaz + '14 14 assign' # ) + '16 16 unknown-token' # \! + '18 19 command' # ls +) diff --git a/highlighters/main/test-data/bang-assign-scalar.zsh b/highlighters/main/test-data/bang-assign-scalar.zsh new file mode 100644 index 0000000..e919050 --- /dev/null +++ b/highlighters/main/test-data/bang-assign-scalar.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar \! ls' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 9 unknown-token' # \! + '11 12 command' # ls +) From 0c9252ac6931f0627f8dd16f11681a004f638239 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 23 Oct 2018 16:34:35 +0000 Subject: [PATCH 023/297] Fix indentation. No functional change. --- highlighters/main/main-highlighter.zsh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2d2ed3e..26d8759 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -743,17 +743,17 @@ _zsh_highlight_main_highlighter_highlight_list() ('end') _zsh_highlight_main__stack_pop '$' reserved-word ;; - ('repeat') - # skip the repeat-count word - in_redirection=2 - # The redirection mechanism assumes $this_word describes the word - # following the redirection. Make it so. - # - # That word can be a command word with shortloops (`repeat 2 ls`) - # or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`). - # - # The repeat-count word will be handled like a redirection target. - this_word=':start::regular:' + ('repeat') + # skip the repeat-count word + in_redirection=2 + # The redirection mechanism assumes $this_word describes the word + # following the redirection. Make it so. + # + # That word can be a command word with shortloops (`repeat 2 ls`) + # or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`). + # + # The repeat-count word will be handled like a redirection target. + this_word=':start::regular:' esac ;; 'suffix alias') style=suffix-alias;; From 44b89f330755342658abf1ad68c2efb3983dd214 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 23 Oct 2018 16:36:14 +0000 Subject: [PATCH 024/297] main: Fold '!' handling in to the 'case'. No functional change. --- highlighters/main/main-highlighter.zsh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 26d8759..f553dbb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -689,11 +689,7 @@ _zsh_highlight_main_highlighter_highlight_list() case $res in reserved) # reserved word style=reserved-word - if [[ $arg == '!' && $this_word != *':start_of_pipeline:'* ]]; then - style=unknown-token - fi - # - # Match braces. + # Match braces and handle special cases. case $arg in ($'\x7b') braces_stack='Y'"$braces_stack" @@ -754,6 +750,14 @@ _zsh_highlight_main_highlighter_highlight_list() # # The repeat-count word will be handled like a redirection target. this_word=':start::regular:' + ;; + ('!') + if [[ $this_word != *':start_of_pipeline:'* ]]; then + style=unknown-token + else + # '!' reserved word at start of pipeline; style already set above + fi + ;; esac ;; 'suffix alias') style=suffix-alias;; From 3e6d1375c93a3e3eb82c7892e57243f0b69ba286 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 30 Oct 2018 21:25:59 +0000 Subject: [PATCH 025/297] main: Fix check for suffix aliases (fixes #574) --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/alias.zsh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 12e48fe..06839ce 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -163,7 +163,7 @@ _zsh_highlight_main__type() { fi if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then REPLY=alias - elif (( $+saliases[(e)${1##*.}] )); then + elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then REPLY='suffix alias' elif (( $reswords[(Ie)$1] )); then REPLY=reserved diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 8330a04..03ca0be 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -31,7 +31,7 @@ alias alias1="ls" alias -s alias2="echo" function alias1() {} # to check that it's highlighted as an alias, not as a function -BUFFER='x.alias2; alias1' +BUFFER='x.alias2; alias1; alias2' # Set expected_region_highlight as a function of zsh version. # @@ -49,4 +49,6 @@ expected_region_highlight+=( "9 9 commandseparator" # ; "11 16 alias" # alias1 "11 16 command" # alias1 (ls) + "17 17 commandseparator" # ; + "19 24 unknown-token" # alias2 ) From f087f3c6e46f7a2d3db3f5cf3a66291b269369d3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Nov 2018 04:01:05 +0000 Subject: [PATCH 026/297] main: Add a test for issue #577. --- highlighters/main/test-data/noglob-always.zsh | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 highlighters/main/test-data/noglob-always.zsh diff --git a/highlighters/main/test-data/noglob-always.zsh b/highlighters/main/test-data/noglob-always.zsh new file mode 100644 index 0000000..481722f --- /dev/null +++ b/highlighters/main/test-data/noglob-always.zsh @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'{ noglob echo * } always { echo * }' + +expected_region_highlight=( + '1 1 reserved-word' # { + '3 8 precommand' # noglob + '10 13 builtin' # echo + '15 15 default' # * + '17 17 reserved-word' # } + '19 24 reserved-word' # always + '26 26 reserved-word' # { + '28 31 builtin' # echo + '33 33 globbing "issue #577"' # * + '35 35 reserved-word' # } +) From e900ad8bad53501689afcb050456400d7a8466e5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Nov 2018 04:01:33 +0000 Subject: [PATCH 027/297] main: Add another test, inspired by #577 and #502. --- highlighters/main/test-data/noglob4.zsh | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 highlighters/main/test-data/noglob4.zsh diff --git a/highlighters/main/test-data/noglob4.zsh b/highlighters/main/test-data/noglob4.zsh new file mode 100644 index 0000000..cc7065f --- /dev/null +++ b/highlighters/main/test-data/noglob4.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'noglob cat <(print -r -- *)' + +expected_region_highlight=( + '1 6 precommand' # noglob + '8 10 command' # cat + '12 27 default' # <(print -r -- *) + '12 27 process-substitution' # <(print -r -- *) + '12 13 process-substitution-delimiter' # <( + '14 18 builtin' # print + '20 21 single-hyphen-option' # -r + '23 24 double-hyphen-option' # -- + '26 26 default' # * + '26 26 globbing' # * + '27 27 process-substitution-delimiter' # ) +) From 3dc74b5c2c71583a4523037113d644f780fb4e07 Mon Sep 17 00:00:00 2001 From: Tobias Sette Date: Wed, 12 Dec 2018 03:56:56 -0200 Subject: [PATCH 028/297] pattern, regexp: Declare the variable in the documentation example Fixes #590. --- docs/highlighters/pattern.md | 3 +++ docs/highlighters/regexp.md | 1 + 2 files changed, 4 insertions(+) diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index 3ad5f24..8853db0 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -9,6 +9,9 @@ This is the `pattern` highlighter, that highlights user-defined patterns. To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` associative array, for example in `~/.zshrc`: + # Declare the variable + typeset -A ZSH_HIGHLIGHT_PATTERNS + # To have commands starting with `rm -rf` in red: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 25f1b6c..2078525 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -10,6 +10,7 @@ patterns. To use this highlighter, associate regular expressions with styles in the `ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`: + typeset -A ZSH_HIGHLIGHT_PATTERNS ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not From 55f846c673661bde03ef97333be7889f54079c7b Mon Sep 17 00:00:00 2001 From: dana Date: Tue, 18 Dec 2018 22:43:04 -0600 Subject: [PATCH 029/297] driver: Avoid warn_create_global warnings --- zsh-syntax-highlighting.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4caf3a8..dc85426 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -28,7 +28,7 @@ # ------------------------------------------------------------------------------------------------- # First of all, ensure predictable parsing. -zsh_highlight__aliases=`builtin alias -Lm '[^+]*'` +typeset zsh_highlight__aliases="$(builtin alias -Lm '[^+]*')" # In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42') # them without a '--' guard, so they don't round trip. # @@ -57,9 +57,9 @@ fi # zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html autoload -Uz is-at-least if is-at-least 5.4; then - zsh_highlight__pat_static_bug=false + typeset -g zsh_highlight__pat_static_bug=false else - zsh_highlight__pat_static_bug=true + typeset -g zsh_highlight__pat_static_bug=true fi # Array declaring active highlighters names. From 864864442ec48746a91283a9154d38ef39198607 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 11:31:18 +0000 Subject: [PATCH 030/297] tests: Allow marking the cardinality check as TODO (XFail). Needed for next commit. --- tests/README.md | 5 +++++ tests/test-highlighting.zsh | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 8487b3c..2d87204 100644 --- a/tests/README.md +++ b/tests/README.md @@ -21,6 +21,11 @@ with the provided string as the reason. If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight` need not match the order in `$region_highlight`. +Normally, tests fail if `$expected_region_highlight` and `$region_highlight` +have different numbers of elements. Tests may set `$expected_mismatch` to an +explanation string (like `$todo`) to avoid this and mark the cardinality check +as todo. + **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 812b1a7..2498dee 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -98,6 +98,7 @@ run_test_internal() { # Load the data and prepare checking it. local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test unsorted=0 + local expected_mismatch local -a expected_region_highlight region_highlight . "$srcdir"/"$1" @@ -154,7 +155,7 @@ run_test_internal() { if (( $#expected_region_highlight == $#region_highlight )); then print -r -- "ok $i - cardinality check" else - print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries" + print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset -p expected_region_highlight)» «$(typeset -p region_highlight)»" "${expected_mismatch:+" # TODO : $expected_mismatch"}" fi } From 0efad58f30d8cb5cfecd11a3bb9ab6656d802aab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 11:31:50 +0000 Subject: [PATCH 031/297] Add a test for issue #596. --- .../main/test-data/jobsubst-isnt-glob.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/jobsubst-isnt-glob.zsh diff --git a/highlighters/main/test-data/jobsubst-isnt-glob.zsh b/highlighters/main/test-data/jobsubst-isnt-glob.zsh new file mode 100644 index 0000000..870f6a4 --- /dev/null +++ b/highlighters/main/test-data/jobsubst-isnt-glob.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018.9958 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': %? %?foo' + +expected_mismatch="fallout of issue #596" +expected_region_highlight=( + '1 1 builtin' # : + '3 4 default' # %? + '6 10 default "issue 596"' # %?foo +) From cd1647f4d4841c6e05d3e7c42d4e247d30424d69 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 11:42:34 +0000 Subject: [PATCH 032/297] tests: Follow-up to grandparent: Make the cardinality check XPASS properly when it should. --- tests/test-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 2498dee..7effc07 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -153,7 +153,7 @@ run_test_internal() { done if (( $#expected_region_highlight == $#region_highlight )); then - print -r -- "ok $i - cardinality check" + print -r -- "ok $i - cardinality check" "${expected_mismatch:+" # TODO : $expected_mismatch"}" else print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset -p expected_region_highlight)» «$(typeset -p region_highlight)»" "${expected_mismatch:+" # TODO : $expected_mismatch"}" fi From 7cb5ad0f9b3df35f04bdd2f3d091ca1edd2ecfaf Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 11:46:18 +0000 Subject: [PATCH 033/297] tests: Tweak XFAIL/XPASS output of cardinality check. Stylistic tweaks only; no functional change, no effect on TAP compliance. --- tests/test-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7effc07..c4a80ab 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -153,9 +153,9 @@ run_test_internal() { done if (( $#expected_region_highlight == $#region_highlight )); then - print -r -- "ok $i - cardinality check" "${expected_mismatch:+" # TODO : $expected_mismatch"}" + print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" else - print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset -p expected_region_highlight)» «$(typeset -p region_highlight)»" "${expected_mismatch:+" # TODO : $expected_mismatch"}" + print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset -p expected_region_highlight)» «$(typeset -p region_highlight)»" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" fi } From 580ccaebb8607793af1db6d42ee9078d8e599825 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 11:57:15 +0000 Subject: [PATCH 034/297] tests: (try to) Fix test failure under zsh<5.3, where 'typeset -p arrayvar''s is two lines long. --- tests/test-highlighting.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index c4a80ab..6040019 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -86,6 +86,13 @@ _zsh_highlight_add_highlight() # Activate the highlighter. ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) +# In zsh<5.3, 'typeset -p arrayvar' emits two lines, so we use this wrapper instead. +typeset_p() { + for 1 ; do + print -r -- "$1=( ${(@q-P)1} )" + done +} + # Runs a highlighting test # $1: data file run_test_internal() { @@ -155,7 +162,7 @@ run_test_internal() { if (( $#expected_region_highlight == $#region_highlight )); then print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" else - print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset -p expected_region_highlight)» «$(typeset -p region_highlight)»" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" fi } From 06893a387337efbd9ea3e29da97e1d2ff66aa8d9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Dec 2018 12:15:34 +0000 Subject: [PATCH 035/297] tests: Escape region_highlight and expected_region_highlight in TAP output. Required for TAP compliance in case the output ever contains '#' or '\n'. --- tests/test-highlighting.zsh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6040019..30c9c5c 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -93,6 +93,13 @@ typeset_p() { done } +# Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output +# The string to escape is «"$@"»; the result is returned in $REPLY. +tap_escape() { + local s="$@" + REPLY="${${s//'#'/♯}//$'\n'/↵}" +} + # Runs a highlighting test # $1: data file run_test_internal() { @@ -104,7 +111,7 @@ run_test_internal() { echo "# ${1:t:r}" # Load the data and prepare checking it. - local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test unsorted=0 + local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0 local expected_mismatch local -a expected_region_highlight region_highlight . "$srcdir"/"$1" @@ -140,8 +147,8 @@ run_test_internal() { fi local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} ) integer start=$(( highlight_zone[1] + 1 )) end=$highlight_zone[2] - # Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output - local desc="[$start,$end] «${${BUFFER[$start,$end]//'#'/♯}//$'\n'/↵}»" + local desc="[$start,$end] «${BUFFER[$start,$end]}»" + tap_escape $desc; desc=$REPLY if [[ $start != $exp_start ]] || [[ $end != $exp_end ]] || @@ -162,7 +169,11 @@ run_test_internal() { if (( $#expected_region_highlight == $#region_highlight )); then print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" else - print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: «$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + local details + details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " + details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" + tap_escape $details; details=$REPLY + print -r -- "not ok $i - $details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" fi } From 78b95b06959407401fe1a015191cf79ff6a720d8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Dec 2018 17:57:53 +0000 Subject: [PATCH 036/297] Add a test for the 'true negative' case of issue #596. --- .../main/test-data/jobsubst-isnt-glob2.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/jobsubst-isnt-glob2.zsh diff --git a/highlighters/main/test-data/jobsubst-isnt-glob2.zsh b/highlighters/main/test-data/jobsubst-isnt-glob2.zsh new file mode 100644 index 0000000..51930bf --- /dev/null +++ b/highlighters/main/test-data/jobsubst-isnt-glob2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': foo%?bar' + +expected_region_highlight=( + '1 1 builtin' # : + '3 10 default' # foo%?bar + '7 7 globbing' # ? +) From fd57ed94f113b82ca599ab993d472255e7806697 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Jan 2019 19:12:59 +0000 Subject: [PATCH 037/297] docs: Clarify installation instructions (cf #598) --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 468e9bd..f998726 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -69,7 +69,7 @@ your `.zshrc`. 1. Clone this repository in oh-my-zsh's plugins directory: - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + % git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting 2. Activate the plugin in `~/.zshrc`: @@ -77,7 +77,7 @@ your `.zshrc`. 3. Source `~/.zshrc` to take changes into account: - source ~/.zshrc + % source ~/.zshrc #### [Prezto](https://github.com/sorin-ionescu/prezto) From 9a06c28ddc2c6efbabc0e4d5806d89b0d63c8b8e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Jan 2019 21:25:55 +0000 Subject: [PATCH 038/297] docs: Don't recommend to `source .zshrc` That might not be idempotent (cf #598). --- INSTALL.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index f998726..6793d89 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -75,9 +75,7 @@ your `.zshrc`. plugins=( [plugins...] zsh-syntax-highlighting) -3. Source `~/.zshrc` to take changes into account: - - % source ~/.zshrc +3. Restart zsh (such as by opening a new instance of your terminal emulator). #### [Prezto](https://github.com/sorin-ionescu/prezto) From dddea5d5ddfdbf52b881f1f7d91769f017533bd3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 6 Jan 2019 21:18:41 -0600 Subject: [PATCH 039/297] tests: Set harness variables local --- tests/test-highlighting.zsh | 3 ++- tests/test-perfs.zsh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 30c9c5c..cd553e8 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -68,7 +68,7 @@ print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "# global (driver) print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "1..1" alias -- +plus=plus alias -- _other=other -original_alias_dash_L_output="$(alias -L)" +local original_alias_dash_L_output="$(alias -L)" . ${0:h:h}/zsh-syntax-highlighting.zsh if [[ $original_alias_dash_L_output == $(alias -L) ]]; then print -r -- "ok 1 # 'alias -- +foo=bar' is preserved" @@ -210,6 +210,7 @@ run_test() { # Process each test data file in test data directory. integer something_failed=0 ZSH_HIGHLIGHT_STYLES=() +local data_file for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do run_test "$data_file" | tee >($results_filter | ${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -Eq '^not ok|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 3411754..a032978 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -92,6 +92,7 @@ run_test() { } # Process each test data file in test data directory. +local data_file for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do run_test "$data_file" (( $pipestatus[1] )) && exit 2 From 9bd38c6fc075ef976d3e61cdbf06860ad208b472 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 6 Jan 2019 21:19:46 -0600 Subject: [PATCH 040/297] tests: Use root variable for root of the project --- tests/test-highlighting.zsh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index cd553e8..595ebc9 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -31,6 +31,8 @@ setopt NO_UNSET WARN_CREATE_GLOBAL +local -r root=${0:h:h} + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." @@ -38,13 +40,13 @@ setopt NO_UNSET WARN_CREATE_GLOBAL } # Check the highlighter is valid. -[[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { +[[ -f $root/highlighters/$1/$1-highlighter.zsh ]] || { echo >&2 "Bail out! Could not find highlighter ${(qq)1}." exit 2 } # Check the highlighter has test data. -[[ -d ${0:h:h}/highlighters/$1/test-data ]] || { +[[ -d $root/highlighters/$1/test-data ]] || { echo >&2 "Bail out! Highlighter ${(qq)1} has no test data." exit 2 } @@ -53,7 +55,7 @@ setopt NO_UNSET WARN_CREATE_GLOBAL local results_filter if [[ ${QUIET-} == y ]]; then if type -w perl >/dev/null; then - results_filter=${0:A:h}/tap-filter + results_filter=$root/tests/tap-filter else echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 fi @@ -64,18 +66,18 @@ fi # Load the main script. # While here, test that it doesn't eat aliases. -print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "# global (driver) tests" -print > >($results_filter | ${0:A:h}/tap-colorizer.zsh) -r -- "1..1" +print > >($results_filter | $root/tests/tap-colorizer.zsh) -r -- "# global (driver) tests" +print > >($results_filter | $root/tests/tap-colorizer.zsh) -r -- "1..1" alias -- +plus=plus alias -- _other=other local original_alias_dash_L_output="$(alias -L)" -. ${0:h:h}/zsh-syntax-highlighting.zsh +. $root/zsh-syntax-highlighting.zsh if [[ $original_alias_dash_L_output == $(alias -L) ]]; then print -r -- "ok 1 # 'alias -- +foo=bar' is preserved" else print -r -- "not ok 1 # 'alias -- +foo=bar' is preserved" exit 1 -fi > >($results_filter | ${0:A:h}/tap-colorizer.zsh) +fi > >($results_filter | $root/tests/tap-colorizer.zsh) # Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style _zsh_highlight_add_highlight() @@ -211,8 +213,8 @@ run_test() { integer something_failed=0 ZSH_HIGHLIGHT_STYLES=() local data_file -for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do - run_test "$data_file" | tee >($results_filter | ${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -Eq '^not ok|^ok.*# TODO' && (( something_failed=1 )) +for data_file in $root/highlighters/$1/test-data/*.zsh; do + run_test "$data_file" | tee >($results_filter | $root/tests/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -Eq '^not ok|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 done From ba2d8fcf7642edf0873105e8d7fdd957438e6972 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 6 Jan 2019 21:23:46 -0600 Subject: [PATCH 041/297] tests: Run tests in an anon function to catch global variables This would have caught #593. --- tests/test-highlighting.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 595ebc9..8e61cbb 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -33,6 +33,7 @@ setopt NO_UNSET WARN_CREATE_GLOBAL local -r root=${0:h:h} +(){ # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." @@ -219,3 +220,4 @@ for data_file in $root/highlighters/$1/test-data/*.zsh; do done exit $something_failed +} "$@" From 3259fe338d74ffa756a719e0fd63ad2be53c2978 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 6 Jan 2019 21:38:13 -0600 Subject: [PATCH 042/297] Revert "tests: Run tests in an anon function to catch global variables" This reverts commit ba2d8fcf7642edf0873105e8d7fdd957438e6972. Breaks 4.3.12 and .11 --- tests/test-highlighting.zsh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 8e61cbb..595ebc9 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -33,7 +33,6 @@ setopt NO_UNSET WARN_CREATE_GLOBAL local -r root=${0:h:h} -(){ # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." @@ -220,4 +219,3 @@ for data_file in $root/highlighters/$1/test-data/*.zsh; do done exit $something_failed -} "$@" From 1e34c4aa0bcbdde5173aab15600784edf0a212fd Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 6 Jan 2019 22:22:13 -0600 Subject: [PATCH 043/297] main: in arguments starting with %?, ? is not a glob Fixes #596 --- highlighters/main/main-highlighter.zsh | 5 +++++ highlighters/main/test-data/jobsubst-isnt-glob.zsh | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 06839ce..6bf02f0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -984,6 +984,11 @@ _zsh_highlight_main_highlighter_highlight_argument() local MATCH; integer MBEGIN MEND case "$arg[i]" in + '%') + if [[ $arg[i+1] == '?' ]]; then + (( i += 2 )) + fi + ;; '-') if (( option_eligible )); then if [[ $arg[i+1] == - ]]; then diff --git a/highlighters/main/test-data/jobsubst-isnt-glob.zsh b/highlighters/main/test-data/jobsubst-isnt-glob.zsh index 870f6a4..3a7e325 100644 --- a/highlighters/main/test-data/jobsubst-isnt-glob.zsh +++ b/highlighters/main/test-data/jobsubst-isnt-glob.zsh @@ -30,9 +30,8 @@ BUFFER=$': %? %?foo' -expected_mismatch="fallout of issue #596" expected_region_highlight=( '1 1 builtin' # : '3 4 default' # %? - '6 10 default "issue 596"' # %?foo + '6 10 default' # %?foo ) From 693757bfd7e6338e3b0ba4c7504ffecf122d6bde Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 12 Jan 2019 00:35:18 -0600 Subject: [PATCH 044/297] tests: Run harness in an anon function to catch global variables Thanks Daniel for the set -- suggestion. --- tests/test-highlighting.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 595ebc9..b2a6db5 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -32,7 +32,10 @@ setopt NO_UNSET WARN_CREATE_GLOBAL local -r root=${0:h:h} +local -a anon_argv; anon_argv=("$@") +(){ +set -- "${(@)anon_argv}" # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." @@ -219,3 +222,4 @@ for data_file in $root/highlighters/$1/test-data/*.zsh; do done exit $something_failed +} From 4fb570e1046fd39ee6703f45f7a6bf139c68bb69 Mon Sep 17 00:00:00 2001 From: Sean Wei Date: Sun, 13 Jan 2019 16:12:41 +0800 Subject: [PATCH 045/297] docs: Enable Syntax Highlighting for Code Snippits --- HACKING.md | 58 ++++++++------- INSTALL.md | 30 +++++--- changelog.md | 130 +++++++++++++++++++++++----------- docs/highlighters.md | 34 +++++---- docs/highlighters/brackets.md | 12 ++-- docs/highlighters/cursor.md | 4 +- docs/highlighters/line.md | 4 +- docs/highlighters/main.md | 26 ++++--- docs/highlighters/pattern.md | 10 +-- docs/highlighters/regexp.md | 6 +- docs/highlighters/root.md | 4 +- tests/README.md | 40 +++++++---- 12 files changed, 234 insertions(+), 124 deletions(-) diff --git a/HACKING.md b/HACKING.md index 5266a33..71d8a2e 100644 --- a/HACKING.md +++ b/HACKING.md @@ -11,16 +11,18 @@ The `main` highlighter The following function `pz` is useful when working on the `main` highlighting: - pq() { - (( $#argv )) || return 0 - print -r -l -- ${(qqqq)argv} - } - pz() { - local arg - for arg; do - pq ${(z)arg} - done - } +```zsh +pq() { + (( $#argv )) || return 0 + print -r -l -- ${(qqqq)argv} +} +pz() { + local arg + for arg; do + pq ${(z)arg} + done +} +``` It prints, for each argument, its token breakdown, similar to how the main loop of the `main` highlighter sees it. @@ -32,17 +34,19 @@ Since the test harness empties `ZSH_HIGHLIGHT_STYLES` and the `brackets` highlighter interrogates `ZSH_HIGHLIGHT_STYLES` to determine how to highlight, tests must set the `bracket-level-#` keys themselves. For example: - ZSH_HIGHLIGHT_STYLES[bracket-level-1]= - ZSH_HIGHLIGHT_STYLES[bracket-level-2]= +```zsh +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= - BUFFER='echo ({x})' +BUFFER='echo ({x})' - expected_region_highlight=( - "6 6 bracket-level-1" # ( - "7 7 bracket-level-2" # { - "9 9 bracket-level-2" # } - "10 10 bracket-level-1" # ) - ) +expected_region_highlight=( + "6 6 bracket-level-1" # ( + "7 7 bracket-level-2" # { + "9 9 bracket-level-2" # } + "10 10 bracket-level-1" # ) +) +``` Testing the `pattern` and `regexp` highlighters ----------------------------------------------- @@ -53,20 +57,24 @@ cannot get the `ZSH_HIGHLIGHT_STYLES` keys. Therefore, when writing tests, use the style itself as third word (cf. the [documentation for `expected_region_highlight`](docs/highlighters.md)). For example: - ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') +```zsh +ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') - BUFFER='rm -rf /' +BUFFER='rm -rf /' - expected_region_highlight=( - "1 8 fg=white,bold,bg=red" # rm -rf / - ) +expected_region_highlight=( + "1 8 fg=white,bold,bg=red" # rm -rf / +) +``` Miscellany ---------- If you work on the driver (`zsh-syntax-highlighting.zsh`), you may find the following zstyle useful: - zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-highlighting.plugin.zsh +```zsh +zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-highlighting.plugin.zsh +``` IRC channel ----------- diff --git a/INSTALL.md b/INSTALL.md index 6793d89..9a32646 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -33,17 +33,23 @@ See also [repology's cross-distro index](https://repology.org/metapackage/zsh-sy Simply clone this repository and source the script: - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git - echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc +```zsh +git clone https://github.com/zsh-users/zsh-syntax-highlighting.git +echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc +``` Then, enable syntax highlighting in the current interactive shell: - source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +```zsh +source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +``` If `git` is not installed, download and extract a snapshot of the latest development tree from: - https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz +``` +https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz +``` Note the `source` command must be **at the end** of `~/.zshrc`. @@ -69,11 +75,15 @@ your `.zshrc`. 1. Clone this repository in oh-my-zsh's plugins directory: - % git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + ```zsh + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + ``` 2. Activate the plugin in `~/.zshrc`: - plugins=( [plugins...] zsh-syntax-highlighting) + ```zsh + plugins=( [plugins...] zsh-syntax-highlighting) + ``` 3. Restart zsh (such as by opening a new instance of your terminal emulator). @@ -104,10 +114,14 @@ Any of the above methods is suitable for a single-user installation, which requires no special privileges. If, however, you desire to install zsh-syntax-highlighting system-wide, you may do so by running - make install +```zsh +make install +``` and directing your users to add - source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +```zsh +source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +``` to their `.zshrc`s. diff --git a/changelog.md b/changelog.md index f20e69d..3a2d00b 100644 --- a/changelog.md +++ b/changelog.md @@ -309,50 +309,66 @@ in this area. - incomplete sudo commands (a3047a912100, 2f05620b19ae) - sudo; - sudo -u; + ```zsh + sudo; + sudo -u; + ``` - command words following reserved words (#207, #222, b397b12ac139 et seq, 6fbd2aa9579b et seq, 8b4adbd991b0) - if ls; then ls; else ls; fi - repeat 10 do ls; done + ```zsh + if ls; then ls; else ls; fi + repeat 10 do ls; done + ``` (The `ls` are now highlighted as a command.) - comments (when `INTERACTIVE_COMMENTS` is set) (#163, #167, 693de99a9030) - echo Hello # comment + ```zsh + echo Hello # comment + ``` - closing brackets of arithmetic expansion, subshells, and blocks (#226, a59f442d2d34, et seq) - (( foo )) - ( foo ) - { foo } + ```zsh + (( foo )) + ( foo ) + { foo } + ``` - command names enabled by the `PATH_DIRS` option (#228, 96ee5116b182) - # When ~/bin/foo/bar exists, is executable, ~/bin is in $PATH, - # and 'setopt PATH_DIRS' is in effect - foo/bar + ```zsh + # When ~/bin/foo/bar exists, is executable, ~/bin is in $PATH, + # and 'setopt PATH_DIRS' is in effect + foo/bar + ``` - parameter expansions with braces inside double quotes (#186, 6e3720f39d84) - echo "${foo}" + ```zsh + echo "${foo}" + ``` - parameter expansions in command word (#101, 4fcfb15913a2) - x=/bin/ls - $x -l + ```zsh + x=/bin/ls + $x -l + ``` -- the command separators '|&', '&!', '&|' +- the command separators '\|&', '&!', '&\|' - view file.pdf &! ls + ```zsh + view file.pdf &! ls + ``` ## Fixed highlighting of: @@ -360,23 +376,31 @@ in this area. - precommand modifiers at non-command-word position (#209, 2c9f8c8c95fa) - ls command foo + ```zsh + ls command foo + ``` - sudo commands with infix redirections (#221, be006aded590, 86e924970911) - sudo -u >/tmp/foo.out user ls + ```zsh + sudo -u >/tmp/foo.out user ls + ``` - subshells; anonymous functions (#166, #194, 0d1bfbcbfa67, 9e178f9f3948) - (true) - () { true } + ```zsh + (true) + () { true } + ``` - parameter assignment statements with no command (#205, 01d7eeb3c713) - A=1; + ```zsh + A=1; + ``` (The semicolon used to be highlighted as a mistake) @@ -467,69 +491,95 @@ in this area. - suffix aliases (requires zsh 5.1.1 or newer): - alias -s png=display - foo.png + ```zsh + alias -s png=display + foo.png + ``` - prefix redirections: - foo.txt + ```zsh + echo > foo.txt + ``` - arithmetic evaluations: - (( 42 )) + ```zsh + (( 42 )) + ``` - $'' strings, including \x/\octal/\u/\U escapes - : $'foo\u0040bar' + ```zsh + : $'foo\u0040bar' + ``` - multiline strings: - % echo "line 1 - line 2" + ```zsh + % echo "line 1 + line 2" + ``` - string literals that haven't been finished: - % echo "Hello, world - + ```zsh + % echo "Hello, world + ``` - command words that involve tilde expansion: - % ~/bin/foo - + ```zsh + % ~/bin/foo + ``` ## Fixed highlighting of: - quoted command words: - % \ls + ```zsh + % \ls + ``` - backslash escapes in "" strings: - % echo "\x41" + ```zsh + % echo "\x41" + ``` - noglob after command separator: - % :; noglob echo * + ```zsh + % :; noglob echo * + ``` - glob after command separator, when the first command starts with 'noglob': - % noglob true; echo * + ```zsh + % noglob true; echo * + ``` - the region (vi visual mode / set-mark-command) (issue #165) - redirection and command separators that would be highlighted as `path_approx` - % echo foo;‸ - % echo <‸ + ```zsh + % echo foo;‸ + % echo <‸ + ``` (where `‸` represents the cursor location) - escaped globbing (outside quotes) - % echo \* + ```zsh + % echo \* + ``` ## Other changes: diff --git a/docs/highlighters.md b/docs/highlighters.md index 642d2bd..f6eba7f 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -24,7 +24,9 @@ How to activate highlighters To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in `~/.zshrc`, for example: - ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) +```zsh +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) +``` By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main` highlighter is active. @@ -58,10 +60,12 @@ To create your own `acme` highlighter: This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: - _zsh_highlight_highlighter_acme_predicate() { - # Call this highlighter in SVN working copies - [[ -d .svn ]] - } + ```zsh + _zsh_highlight_highlighter_acme_predicate() { + # Call this highlighter in SVN working copies + [[ -d .svn ]] + } + ``` * Implement the `_zsh_highlight_highlighter_acme_paint` function. This function does the actual syntax highlighting, by calling @@ -71,18 +75,22 @@ To create your own `acme` highlighter: `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix the key with your highlighter name and a colon. For example: - : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green} + ```zsh + : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green} - _zsh_highlight_highlighter_acme_paint() { - # Colorize the whole buffer with the 'aurora' style - _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora - } + _zsh_highlight_highlighter_acme_paint() { + # Colorize the whole buffer with the 'aurora' style + _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora + } + ``` If you need to test which options the user has set, test `zsyh_user_options` with a sensible default if the option is not present in supported zsh versions. For example: - [[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]] + ```zsh + [[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]] + ``` The option name must be all lowercase with no underscores and not an alias. @@ -100,6 +108,8 @@ To create your own `acme` highlighter: * Activate your highlighter in `~/.zshrc`: - ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme) + ```zsh + ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme) + ``` * [Write tests](../tests/README.md). diff --git a/docs/highlighters/brackets.md b/docs/highlighters/brackets.md index 9001074..8410135 100644 --- a/docs/highlighters/brackets.md +++ b/docs/highlighters/brackets.md @@ -16,11 +16,13 @@ This highlighter defines the following styles: To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: - # To define styles for nested brackets up to level 4 - ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold' - ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold' - ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold' - ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold' +```zsh +# To define styles for nested brackets up to level 4 +ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold' +ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=red,bold' +ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold' +ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold' +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` diff --git a/docs/highlighters/cursor.md b/docs/highlighters/cursor.md index 7295fd1..c4f22b8 100644 --- a/docs/highlighters/cursor.md +++ b/docs/highlighters/cursor.md @@ -13,7 +13,9 @@ This highlighter defines the following styles: To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: - ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' +```zsh +ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` diff --git a/docs/highlighters/line.md b/docs/highlighters/line.md index 4ba14e9..1081fe1 100644 --- a/docs/highlighters/line.md +++ b/docs/highlighters/line.md @@ -13,7 +13,9 @@ This highlighter defines the following styles: To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: - ZSH_HIGHLIGHT_STYLES[line]='bold' +```zsh +ZSH_HIGHLIGHT_STYLES[line]='bold' +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 005fc4d..f4507d8 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -65,17 +65,19 @@ This highlighter defines the following styles: To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: - # Declare the variable - typeset -A ZSH_HIGHLIGHT_STYLES +```zsh +# Declare the variable +typeset -A ZSH_HIGHLIGHT_STYLES - # To differentiate aliases from other command types - ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold' - - # To have paths colored instead of underlined - ZSH_HIGHLIGHT_STYLES[path]='fg=cyan' - - # To disable highlighting of globbing expressions - ZSH_HIGHLIGHT_STYLES[globbing]='none' +# To differentiate aliases from other command types +ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold' + +# To have paths colored instead of underlined +ZSH_HIGHLIGHT_STYLES[path]='fg=cyan' + +# To disable highlighting of globbing expressions +ZSH_HIGHLIGHT_STYLES[globbing]='none' +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` @@ -86,7 +88,9 @@ manual page][zshzle-Character-Highlighting]. To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. This interface is still experimental. - X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) +```zsh +X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) +``` ### Useless trivia diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index 8853db0..e67d79f 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -9,11 +9,13 @@ This is the `pattern` highlighter, that highlights user-defined patterns. To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` associative array, for example in `~/.zshrc`: - # Declare the variable - typeset -A ZSH_HIGHLIGHT_PATTERNS +```zsh +# Declare the variable +typeset -A ZSH_HIGHLIGHT_PATTERNS - # To have commands starting with `rm -rf` in red: - ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') +# To have commands starting with `rm -rf` in red: +ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 2078525..06b21ac 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -10,8 +10,10 @@ patterns. To use this highlighter, associate regular expressions with styles in the `ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`: - typeset -A ZSH_HIGHLIGHT_PATTERNS - ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) +```zsh +typeset -A ZSH_HIGHLIGHT_PATTERNS +ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) +``` This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not "sudoedit" diff --git a/docs/highlighters/root.md b/docs/highlighters/root.md index 0b0d41f..d120d20 100644 --- a/docs/highlighters/root.md +++ b/docs/highlighters/root.md @@ -14,7 +14,9 @@ This highlighter defines the following styles: To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: - ZSH_HIGHLIGHT_STYLES[root]='bg=red' +```zsh +ZSH_HIGHLIGHT_STYLES[root]='bg=red' +``` The syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` diff --git a/tests/README.md b/tests/README.md index 2d87204..89aef14 100644 --- a/tests/README.md +++ b/tests/README.md @@ -38,17 +38,19 @@ computes `$region_highlight`), but will not affect subsequent tests. The current working directory of tests is set to a newly-created empty directory, which is automatically cleaned up after the test exits. For example: - setopt PATH_DIRS - mkdir -p foo/bar - touch foo/bar/testing-issue-228 - chmod +x foo/bar/testing-issue-228 - path+=( "$PWD"/foo ) +```zsh +setopt PATH_DIRS +mkdir -p foo/bar +touch foo/bar/testing-issue-228 +chmod +x foo/bar/testing-issue-228 +path+=( "$PWD"/foo ) - BUFFER='bar/testing-issue-228' +BUFFER='bar/testing-issue-228' - expected_region_highlight=( - "1 21 command" # bar/testing-issue-228 - ) +expected_region_highlight=( + "1 21 command" # bar/testing-issue-228 +) +``` Writing new tests @@ -56,7 +58,9 @@ Writing new tests An experimental tool is available to generate test files: - zsh -f tests/generate.zsh 'ls -x' acme newfile +```zsh +zsh -f tests/generate.zsh 'ls -x' acme newfile +``` This generates a `highlighters/acme/test-data/newfile.zsh` test file based on the current highlighting of the given `$BUFFER` (in this case, `ls -x`). @@ -71,11 +75,15 @@ Highlighting test [`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage: - zsh test-highlighting.zsh +```zsh +zsh test-highlighting.zsh +``` All tests may be run with - make test +```zsh +make test +``` which will run all highlighting tests and report results in [TAP format][TAP]. By default, the results of all tests will be printed; to show only "interesting" @@ -91,8 +99,12 @@ Performance test [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: - zsh test-perfs.zsh +```zsh +zsh test-perfs.zsh +``` All tests may be run with - make perf +```zsh +make perf +``` From d61ebbcbbf7da8fc35040f591e37b89272623036 Mon Sep 17 00:00:00 2001 From: Timm Date: Mon, 21 Jan 2019 13:24:40 +0100 Subject: [PATCH 046/297] docs: Fix void-linux link --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 9a32646..1c2a523 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ How to install [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org//download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting -[void-package]: https://github.com/voidlinux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting +[void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) From 37d6108215b99dbb14e1aa12a83f7677bfc9f0e2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 16 Mar 2019 07:34:12 +0000 Subject: [PATCH 047/297] 'main': Work around a zsh bug reported to us as #606. As of this writing, it seems that the 'type' builtin poisons the commands hash in a way that breaks AUTO_CD to absolute paths that don't end with a slash. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6bf02f0..477b309 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -180,7 +180,7 @@ _zsh_highlight_main__type() { # # The first disjunct mimics the isrelative() C call from the zsh bug. elif { [[ $1 != */* ]] || is-at-least 5.3 } && - ! builtin type -w -- $1 >/dev/null 2>&1; then + ! (builtin type -w -- $1) >/dev/null 2>&1; then REPLY=none fi fi From 79596a84be8bdcbea099f7a7f93fadcd35325c5f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 16 Mar 2019 07:45:23 +0000 Subject: [PATCH 048/297] 'main': Document the last change. --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 477b309..71bec9d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -180,6 +180,8 @@ _zsh_highlight_main__type() { # # The first disjunct mimics the isrelative() C call from the zsh bug. elif { [[ $1 != */* ]] || is-at-least 5.3 } && + # Add a subshell to avoid a zsh upstream bug. + # ### Remove the subshell when we stop supporting zsh 5.7.1 (I assume 5.8 will have the bugfix). ! (builtin type -w -- $1) >/dev/null 2>&1; then REPLY=none fi From abec25d013fecbc29202d0b3d93bcb3155a3a557 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 16 Mar 2019 07:47:53 +0000 Subject: [PATCH 049/297] 'main': _zsh_highlight_main__type: Add comments. --- highlighters/main/main-highlighter.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 71bec9d..02be55c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -173,6 +173,10 @@ _zsh_highlight_main__type() { REPLY=builtin elif (( $+commands[(e)$1] )); then REPLY=command + # None of the special hashes had a match, so fall back to 'type -w', for + # forward compatibility with future versions of zsh that may add new command + # types. + # # zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly # runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo # exists and is in $PATH). Avoid triggering the bug, at the expense of @@ -187,6 +191,8 @@ _zsh_highlight_main__type() { fi fi if ! (( $+REPLY )); then + # zsh/parameter not available or had no matches. + # # Note that 'type -w' will run 'rehash' implicitly. # # We 'unalias' in a subshell, so the parent shell is not affected. From 809443f5c5232c89536e7d7a585f7e3976d43475 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 16 Mar 2019 07:49:04 +0000 Subject: [PATCH 050/297] 'main': Add the issue number for future reference. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 02be55c..cffe798 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -184,7 +184,7 @@ _zsh_highlight_main__type() { # # The first disjunct mimics the isrelative() C call from the zsh bug. elif { [[ $1 != */* ]] || is-at-least 5.3 } && - # Add a subshell to avoid a zsh upstream bug. + # Add a subshell to avoid a zsh upstream bug; see issue #606. # ### Remove the subshell when we stop supporting zsh 5.7.1 (I assume 5.8 will have the bugfix). ! (builtin type -w -- $1) >/dev/null 2>&1; then REPLY=none From a109ab54f0d95744c3321183011484ba1de805a7 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 21 Mar 2019 22:59:11 -0500 Subject: [PATCH 051/297] CI: Add zsh 5.7 and 5.7.1 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index cea0ad9..dffffdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ sudo: required env: - ZSH=master + - ZSH=5.7.1 + - ZSH=5.7 - ZSH=5.6.2 - ZSH=5.6.1 - ZSH=5.6 From 3e86ef59b7c2c47ff9e4ef1a0c9d0d58a615ad96 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 26 Mar 2019 22:04:50 +0000 Subject: [PATCH 052/297] 'main': precommands += stdbuf --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index cffe798..7cca060 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -313,6 +313,7 @@ _zsh_highlight_highlighter_main_paint() 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 + 'stdbuf' i:o:e: ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From 5f80147c55215469475876baaaf94712227dd424 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 27 Mar 2019 11:45:17 +0000 Subject: [PATCH 053/297] 'main': Follow-up to last commit: Fix stdbuf options spec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The effect of the bug was that «-:» was considered an option taking an argument (see the parsing of the associative array in lines 692-693). As to preventing recurrence, add a warning comment. We _could_ change the separator from colon to something else, but colon is idiomatic for this use (see, e.g., passwd(5)), and the problem will be unlikely to recur if and when we add a third field to the assoc's values. (For example, jexec(1), chroot(1), and even ssh(1) would benefit from a third field saying how many positional arguments to skip before the positional argument that's to be the command word — though in the last two cases, specifying an "inner" command is optional.) --- highlighters/main/main-highlighter.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7cca060..eb49d8a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -295,7 +295,8 @@ _zsh_highlight_highlighter_main_paint() # that wouldn't be followed by a colon in a getopts specification. local flags_sans_argument # $precommand_options maps precommand name to values of $flags_with_argument and - # $flags_sans_argument for that precommand, joined by a colon. + # $flags_sans_argument for that precommand, joined by a colon. (The value is NOT + # a getopt(3) spec, although it resembles one.) # # Currently, setting $flags_sans_argument is only important for commands that # have a non-empty $flags_with_argument; see test-data/precommand4.zsh. @@ -313,7 +314,7 @@ _zsh_highlight_highlighter_main_paint() 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 - 'stdbuf' i:o:e: + 'stdbuf' ioe: ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From bc3f77f719ae80b5258292a10a5461aee5597eb2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 29 Mar 2019 17:50:49 +0000 Subject: [PATCH 054/297] 'main': Add XFailing tests for issue #608. --- .../main/test-data/precommand-type1.zsh | 61 +++++++++++++++++++ .../main/test-data/precommand-type2.zsh | 55 +++++++++++++++++ .../main/test-data/precommand-type3.zsh | 55 +++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 highlighters/main/test-data/precommand-type1.zsh create mode 100644 highlighters/main/test-data/precommand-type2.zsh create mode 100644 highlighters/main/test-data/precommand-type3.zsh diff --git a/highlighters/main/test-data/precommand-type1.zsh b/highlighters/main/test-data/precommand-type1.zsh new file mode 100644 index 0000000..bf37f8e --- /dev/null +++ b/highlighters/main/test-data/precommand-type1.zsh @@ -0,0 +1,61 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +# Test the behaviour of a builtin that exists as a command as well. +# The spaces in $BUFFER are to align precommand-type*.zsh test files. +BUFFER=$'test ; builtin test ; builtin command test ; stdbuf test ' + +# Our expectations assumes that a 'test' external command exists (in addition +# to the 'test' builtin). Let's verify that, using the EQUALS option (which +# is on by default). If there's no 'test' command, the expansion will fail, +# diagnose a message on stdout, and the harness will detect a failure. +# +# This seems to work on all platforms, insofar as no one ever reported a bug +# about their system not having a 'test' binary in PATH. That said, if someone +# ever does see this test fail for this reason, we should explicitly create +# a 'test' executable in cwd and 'rehash'. +: =test + +expected_region_highlight=( + '1 4 builtin' # test + '7 7 commandseparator' # ; + + '9 15 precommand' # builtin + '17 20 builtin' # test + '23 23 commandseparator' # ; + + '25 31 precommand' # builtin + '33 39 precommand' # command + '41 44 command "issue #608"' # test + '47 47 commandseparator' # ; + + '49 54 precommand' # stdbuf + '56 59 command "issue #608"' # test +) diff --git a/highlighters/main/test-data/precommand-type2.zsh b/highlighters/main/test-data/precommand-type2.zsh new file mode 100644 index 0000000..c720173 --- /dev/null +++ b/highlighters/main/test-data/precommand-type2.zsh @@ -0,0 +1,55 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +# Test the behaviour of a builtin that does not exist as a command. +# The spaces in $BUFFER are to align precommand-type*.zsh test files. +BUFFER=$'zstyle; builtin zstyle; builtin command zstyle; stdbuf zstyle' + +# Verify that no $^path/zstyle(N) binary exists. +if (disable zstyle; type zstyle >/dev/null); then + echo >&2 "precommand-type2: error: 'zstyle' exists not only as a builtin" +fi + +expected_region_highlight=( + '1 6 builtin' # zstyle + '7 7 commandseparator' # ; + + '9 15 precommand' # builtin + '17 22 builtin' # zstyle + '23 23 commandseparator' # ; + + '25 31 precommand' # builtin + '33 39 precommand' # command + '41 46 unknown-token "issue #608"' # zstyle + '47 47 commandseparator' # ; + + '49 54 precommand' # stdbuf + '56 61 unknown-token "issue #608"' # zstyle +) diff --git a/highlighters/main/test-data/precommand-type3.zsh b/highlighters/main/test-data/precommand-type3.zsh new file mode 100644 index 0000000..ae001bc --- /dev/null +++ b/highlighters/main/test-data/precommand-type3.zsh @@ -0,0 +1,55 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +# Test an external command that does not exist as a builtin. +# The spaces in $BUFFER are to align precommand-type*.zsh test files. +BUFFER=$'ls ; builtin ls ; builtin command ls ; stdbuf ls ' + +# Verify that the 'ls' command isn't shadowed. +if [[ $(type -w ls) != "ls: command" ]]; then + echo >&2 "precommand-type3: error: the 'ls' command is shadowed (or possibly missing altogether)" +fi + +expected_region_highlight=( + '1 2 command' # ls + '7 7 commandseparator' # ; + + '9 15 precommand' # builtin + '17 18 unknown-token "issue #608"' # ls + '23 23 commandseparator' # ; + + '25 31 precommand' # builtin + '33 39 precommand' # command + '41 42 command' # ls + '47 47 commandseparator' # ; + + '49 54 precommand' # stdbuf + '56 57 command' # ls +) From 7ba4f0f119495cd95c9811a0afa94cfbe337fdc3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 4 Apr 2019 21:52:51 -0500 Subject: [PATCH 055/297] 'main': Use nice for tests in previous stdbuf is not present on all systems. nice is not builtin and is POSIX. --- highlighters/main/test-data/precommand-type1.zsh | 6 +++--- highlighters/main/test-data/precommand-type2.zsh | 6 +++--- highlighters/main/test-data/precommand-type3.zsh | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/highlighters/main/test-data/precommand-type1.zsh b/highlighters/main/test-data/precommand-type1.zsh index bf37f8e..4ce817c 100644 --- a/highlighters/main/test-data/precommand-type1.zsh +++ b/highlighters/main/test-data/precommand-type1.zsh @@ -30,7 +30,7 @@ # Test the behaviour of a builtin that exists as a command as well. # The spaces in $BUFFER are to align precommand-type*.zsh test files. -BUFFER=$'test ; builtin test ; builtin command test ; stdbuf test ' +BUFFER=$'test ; builtin test ; builtin command test ; nice test ' # Our expectations assumes that a 'test' external command exists (in addition # to the 'test' builtin). Let's verify that, using the EQUALS option (which @@ -56,6 +56,6 @@ expected_region_highlight=( '41 44 command "issue #608"' # test '47 47 commandseparator' # ; - '49 54 precommand' # stdbuf - '56 59 command "issue #608"' # test + '49 52 precommand' # nice + '54 57 command "issue #608"' # test ) diff --git a/highlighters/main/test-data/precommand-type2.zsh b/highlighters/main/test-data/precommand-type2.zsh index c720173..bf75f4b 100644 --- a/highlighters/main/test-data/precommand-type2.zsh +++ b/highlighters/main/test-data/precommand-type2.zsh @@ -30,7 +30,7 @@ # Test the behaviour of a builtin that does not exist as a command. # The spaces in $BUFFER are to align precommand-type*.zsh test files. -BUFFER=$'zstyle; builtin zstyle; builtin command zstyle; stdbuf zstyle' +BUFFER=$'zstyle; builtin zstyle; builtin command zstyle; nice zstyle' # Verify that no $^path/zstyle(N) binary exists. if (disable zstyle; type zstyle >/dev/null); then @@ -50,6 +50,6 @@ expected_region_highlight=( '41 46 unknown-token "issue #608"' # zstyle '47 47 commandseparator' # ; - '49 54 precommand' # stdbuf - '56 61 unknown-token "issue #608"' # zstyle + '49 52 precommand' # nice + '54 59 unknown-token "issue #608"' # zstyle ) diff --git a/highlighters/main/test-data/precommand-type3.zsh b/highlighters/main/test-data/precommand-type3.zsh index ae001bc..7fc7e4c 100644 --- a/highlighters/main/test-data/precommand-type3.zsh +++ b/highlighters/main/test-data/precommand-type3.zsh @@ -30,7 +30,7 @@ # Test an external command that does not exist as a builtin. # The spaces in $BUFFER are to align precommand-type*.zsh test files. -BUFFER=$'ls ; builtin ls ; builtin command ls ; stdbuf ls ' +BUFFER=$'ls ; builtin ls ; builtin command ls ; nice ls ' # Verify that the 'ls' command isn't shadowed. if [[ $(type -w ls) != "ls: command" ]]; then @@ -50,6 +50,6 @@ expected_region_highlight=( '41 42 command' # ls '47 47 commandseparator' # ; - '49 54 precommand' # stdbuf - '56 57 command' # ls + '49 52 precommand' # nice + '54 55 command' # ls ) From 972ad197c13d25f9b54a1c49405dc218a78781d6 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 14 Apr 2019 08:26:03 -0500 Subject: [PATCH 056/297] driver: Disable BASH_REMATCH Fixes #612. --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index dc85426..df8a1aa 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -101,7 +101,7 @@ _zsh_highlight() typeset -r zsyh_user_options emulate -L zsh - setopt localoptions warncreateglobal + setopt localoptions warncreateglobal nobashrematch local REPLY # don't leak $REPLY into global scope # Do not highlight if there are more than 300 chars in the buffer. It's most From 82cf2527fc13fefee6e87f99171c1b368f0abdb9 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 19 Apr 2019 19:48:01 -0500 Subject: [PATCH 057/297] 'main': Add test for #548 Closes #548 --- highlighters/main/test-data/loop-newline.zsh | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/loop-newline.zsh diff --git a/highlighters/main/test-data/loop-newline.zsh b/highlighters/main/test-data/loop-newline.zsh new file mode 100644 index 0000000..d39ee11 --- /dev/null +++ b/highlighters/main/test-data/loop-newline.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'for i in \\\n; do done' + +expected_region_highlight=( + '1 3 reserved-word' # for + '5 5 default' # i + '7 8 default' # in + '12 12 commandseparator' # ; + '14 15 reserved-word' # do + '17 20 reserved-word' # done +) From 650dd79d86f885f8802732e3748d8719e787d22f Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Sat, 25 May 2019 13:59:59 +0200 Subject: [PATCH 058/297] tests: use zshusers/zsh image with tags (see zsh-users/zsh-docker#16) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dffffdb..39040f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ env: - ZSH=4.3.12 - ZSH=4.3.11 -script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c 'install_packages make procps && make test' +script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps && make test' notifications: webhooks: From fd4c5db4c96aa8fd0aef25bb257dee08a163e495 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 16 Jun 2019 20:21:58 +0000 Subject: [PATCH 059/297] 'main': Fix an issue whereby a --option was highlighted as a file Regression test included. Fixes #578. Review-by: Matthew Martin --- highlighters/main/main-highlighter.zsh | 5 ++- .../option-dollar-quote-isnt-filename.zsh | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/option-dollar-quote-isnt-filename.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index eb49d8a..4c203c7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1045,9 +1045,10 @@ _zsh_highlight_main_highlighter_highlight_argument() highlights+=($reply) ;; '$') - path_eligible=0 + if [[ $arg[i+1] != "'" ]]; then + path_eligible=0 + fi if [[ $arg[i+1] == "'" ]]; then - path_eligible=1 _zsh_highlight_main_highlighter_highlight_dollar_quote $i (( i = REPLY )) highlights+=($reply) diff --git a/highlighters/main/test-data/option-dollar-quote-isnt-filename.zsh b/highlighters/main/test-data/option-dollar-quote-isnt-filename.zsh new file mode 100644 index 0000000..897a02e --- /dev/null +++ b/highlighters/main/test-data/option-dollar-quote-isnt-filename.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': -$\'n\'' + +touch ./-n + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 single-hyphen-option' # -$'n' + '4 7 dollar-quoted-argument' # $'n' +) From d766243f7a2a920b01a405d8fd0b12cb18f6d5bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 16 Jun 2019 21:42:21 +0000 Subject: [PATCH 060/297] 'main': Add an XFail regression test for issue #616. --- .../main/test-data/empty-command-newline.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/empty-command-newline.zsh diff --git a/highlighters/main/test-data/empty-command-newline.zsh b/highlighters/main/test-data/empty-command-newline.zsh new file mode 100644 index 0000000..a78a001 --- /dev/null +++ b/highlighters/main/test-data/empty-command-newline.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$':;\n' + +expected_region_highlight=( + '1 1 builtin' # : + '2 2 commandseparator' # ; + '3 3 unknown-token "issue #616"' # \n +) From ab4b6f5823ac026a17778becb4c661ab66016790 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 7 Jul 2019 18:36:38 +0000 Subject: [PATCH 061/297] 'main': Hackily unbreak 'make test'. The test point is XPASSing, which makes CI red. As a duct tape measure to turn CI green again, update the test expectations to make it XFAIL. The hacky part is that the expectation set by this commit will never be met; the test point will never XPASS now until its expectations are changed again. Issue #623 remains open to track setting the test expectation to the correct value (i.e., make the test XFAIL in a manner that _will_ XPASS if the bug is fixed; in other words, pay off the technical debt created by this commit). Issue #616 remains open to fix the actual bug. --- highlighters/main/test-data/empty-command-newline.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/empty-command-newline.zsh b/highlighters/main/test-data/empty-command-newline.zsh index a78a001..397cef8 100644 --- a/highlighters/main/test-data/empty-command-newline.zsh +++ b/highlighters/main/test-data/empty-command-newline.zsh @@ -33,5 +33,5 @@ BUFFER=$':;\n' expected_region_highlight=( '1 1 builtin' # : '2 2 commandseparator' # ; - '3 3 unknown-token "issue #616"' # \n + '3 3 issue-623 "issue #616"' # \n ) From 83249e1b230c8bcf29107d3827d97e03ae25a86f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 8 Jul 2019 17:05:42 -0500 Subject: [PATCH 062/297] main: Do not highlight empty region between two adjacent $() Should fix #624 --- highlighters/main/main-highlighter.zsh | 2 +- .../command-substitution-adjacent.zsh | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/command-substitution-adjacent.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4c203c7..f4a0cc8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1238,7 +1238,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() saved_reply=($reply) reply=() for 1 2 in $breaks; do - reply+=($1 $2 $style) + (( $1 != $2 )) && reply+=($1 $2 $style) done reply+=($saved_reply) REPLY=$i diff --git a/highlighters/main/test-data/command-substitution-adjacent.zsh b/highlighters/main/test-data/command-substitution-adjacent.zsh new file mode 100644 index 0000000..3d5c0b9 --- /dev/null +++ b/highlighters/main/test-data/command-substitution-adjacent.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "$(echo)$(echo)' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 20 default' # "$(echo)$(echo) + '6 6 double-quoted-argument-unclosed' # " + '7 13 command-substitution-quoted' # $(echo) + '7 8 command-substitution-delimiter-quoted' # $( + '9 12 builtin' # echo + '13 13 command-substitution-delimiter-quoted' # ) + '14 20 command-substitution-quoted' # $(echo) + '14 15 command-substitution-delimiter-quoted' # $( + '16 19 builtin' # echo + '20 20 command-substitution-delimiter-quoted' # ) +) From b3f66fc8748f75e8f153a68d929fe2f6880f061a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 17:14:48 -0500 Subject: [PATCH 063/297] main: Use zsyh_user_options when splitting alias RHS --- highlighters/main/main-highlighter.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f4a0cc8..b0c5c92 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -543,8 +543,11 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main__resolve_alias $arg local -a alias_args # Elision is desired in case alias x='' - alias_args=( ${interactive_comments-${(z)REPLY}} - ${interactive_comments+${(zZ+c+)REPLY}} ) + if [[ $zsyh_user_options[interactivecomments] == on ]]; then + alias_args=(${(zZ+c+)REPLY}) + else + alias_args=(${(z)REPLY}) + fi args=( $alias_args $args ) if (( in_alias == 0 )); then _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias From a88d41e095565986ddabb771b898114ee1ec6845 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 17:20:35 -0500 Subject: [PATCH 064/297] main: Fix faulty test sudo -e does not take a command, so use another flag that does. --- .../test-data/alias-precommand-option-argument2.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 2fceff8..ebbb17b 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -28,15 +28,15 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sde='sudo -e' -alias seu='sde -u' +alias sdb='sudo -b' +alias sbu='sdb -u' sudo(){} -BUFFER='seu phy1729 echo foo' +BUFFER='sbu phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # seu - '1 3 precommand' # seu (sudo) + '1 3 alias' # sbu + '1 3 precommand' # sbu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo From 9cc0060334c3773531e4f6914eb964650eecb96c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 07:50:53 -0500 Subject: [PATCH 065/297] main: Stop highlighting alias as its first word too Fixes #565 and #576 --- highlighters/main/main-highlighter.zsh | 25 +++++++++++++------ .../main/test-data/alias-comment1.zsh | 3 +-- .../main/test-data/alias-comment2.zsh | 1 - highlighters/main/test-data/alias-complex.zsh | 1 - highlighters/main/test-data/alias-loop.zsh | 1 - .../test-data/alias-nested-precommand.zsh | 1 - highlighters/main/test-data/alias-nested.zsh | 1 - .../alias-precommand-option-argument1.zsh | 1 - .../alias-precommand-option-argument2.zsh | 1 - .../main/test-data/alias-redirect.zsh | 1 - highlighters/main/test-data/alias-self.zsh | 1 - highlighters/main/test-data/alias-to-dir.zsh | 1 - highlighters/main/test-data/alias.zsh | 1 - highlighters/main/test-data/noglob-alias.zsh | 1 - highlighters/main/test-data/off-by-one.zsh | 1 - 15 files changed, 18 insertions(+), 23 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b0c5c92..91be6ca 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -73,8 +73,10 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 - (( highlighted_alias )) && return - (( in_alias )) && highlighted_alias=1 + if (( in_alias )); then + [[ $1 == unknown-token ]] && alias_style=unknown-token + return + fi # The calculation was relative to $buf but region_highlight is relative to $BUFFER. (( start += buf_offset )) @@ -377,15 +379,16 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main_highlighter_highlight_list() { integer start_pos end_pos=0 buf_offset=$1 has_end=$3 + # alias_style is the style to apply to an alias once in_alias=0 + # Usually 'alias' but set to 'unknown-token' if any word expanded from + # the alias would be highlighted as unknown-token # last_alias is the last alias arg (lhs) expanded (if in an alias). # This allows for expanding alias ls='ls -l' while avoiding loops. - local arg buf=$4 highlight_glob=true last_alias style + local alias_style arg buf=$4 highlight_glob=true last_alias style local in_array_assignment=false # true between 'a=(' and the matching ')' - # highlighted_alias is 1 when the alias arg has been highlighted with a non-alias style. - # E.g. alias x=ls; x has been highlighted as alias AND command. # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. - integer highlighted_alias=0 in_alias=0 len=$#buf + integer in_alias=0 len=$#buf local -a match mbegin mend list_highlights # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a local -A seen_alias @@ -458,7 +461,11 @@ _zsh_highlight_main_highlighter_highlight_list() shift args if (( in_alias )); then (( in_alias-- )) - (( in_alias == 0 )) && highlighted_alias=0 last_alias= seen_alias=() + if (( in_alias == 0 )); then + last_alias= seen_alias=() + # start_pos and end_pos are of the alias (previous $arg) here + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style + fi fi # Initialize this_word and next_word. @@ -535,6 +542,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' # Also mark insane aliases as unknown-token (cf. #263). if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then + (( in_alias == 0 )) && in_alias=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi @@ -550,7 +558,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi args=( $alias_args $args ) if (( in_alias == 0 )); then - _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias + alias_style=alias # Add one because we will in_alias-- on the next loop iteration so # this iteration should be considered in in_alias as well (( in_alias += $#alias_args + 1 )) @@ -909,6 +917,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style done + (( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] REPLY=$(( end_pos + ${#match[1]} - 1 )) reply=($list_highlights) diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index 0c449e1..dd5068f 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -33,6 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias' # x - '1 1 comment' # x (#) + '1 1 alias "issue #616"' # x ) diff --git a/highlighters/main/test-data/alias-comment2.zsh b/highlighters/main/test-data/alias-comment2.zsh index 8bdc5a8..5a49822 100644 --- a/highlighters/main/test-data/alias-comment2.zsh +++ b/highlighters/main/test-data/alias-comment2.zsh @@ -33,6 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias' # x '1 1 unknown-token' # x (#) ) diff --git a/highlighters/main/test-data/alias-complex.zsh b/highlighters/main/test-data/alias-complex.zsh index 7a9626e..5ad7c0a 100644 --- a/highlighters/main/test-data/alias-complex.zsh +++ b/highlighters/main/test-data/alias-complex.zsh @@ -33,7 +33,6 @@ BUFFER='x file echo' expected_region_highlight=( '1 1 alias' # x - '1 1 builtin' # x (echo) '3 6 default' # file '8 11 builtin' # echo ) diff --git a/highlighters/main/test-data/alias-loop.zsh b/highlighters/main/test-data/alias-loop.zsh index b36d1c9..baa122b 100644 --- a/highlighters/main/test-data/alias-loop.zsh +++ b/highlighters/main/test-data/alias-loop.zsh @@ -33,7 +33,6 @@ alias a=b b=c c=b BUFFER='a foo; :' expected_region_highlight=( - '1 1 alias' # a '1 1 unknown-token' # a (invalid alias loop) '3 5 default' # foo '6 6 commandseparator' # ; diff --git a/highlighters/main/test-data/alias-nested-precommand.zsh b/highlighters/main/test-data/alias-nested-precommand.zsh index 7c2eeeb..6d4172b 100644 --- a/highlighters/main/test-data/alias-nested-precommand.zsh +++ b/highlighters/main/test-data/alias-nested-precommand.zsh @@ -35,7 +35,6 @@ BUFFER='a -u phy1729 echo; :' expected_region_highlight=( '1 1 alias' # a - '1 1 precommand' # a (sudo) '3 4 single-hyphen-option' # -u '6 12 default' # phy1729 '14 17 builtin' # echo diff --git a/highlighters/main/test-data/alias-nested.zsh b/highlighters/main/test-data/alias-nested.zsh index 44ab22b..b24b496 100644 --- a/highlighters/main/test-data/alias-nested.zsh +++ b/highlighters/main/test-data/alias-nested.zsh @@ -34,7 +34,6 @@ BUFFER='a foo; :' expected_region_highlight=( '1 1 alias' # a - '1 1 builtin' # a (:) '3 5 default' # foo '6 6 commandseparator' # ; '8 8 builtin' # : diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index ad16962..ecdd9f9 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -35,7 +35,6 @@ BUFFER='sdu phy1729 echo foo' expected_region_highlight=( '1 3 alias' # sdu - '1 3 precommand' # sdu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index ebbb17b..95d71f8 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -36,7 +36,6 @@ BUFFER='sbu phy1729 echo foo' expected_region_highlight=( '1 3 alias' # sbu - '1 3 precommand' # sbu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo diff --git a/highlighters/main/test-data/alias-redirect.zsh b/highlighters/main/test-data/alias-redirect.zsh index a6a0aab..acc3dcb 100644 --- a/highlighters/main/test-data/alias-redirect.zsh +++ b/highlighters/main/test-data/alias-redirect.zsh @@ -32,7 +32,6 @@ BUFFER='x foo echo bar' expected_region_highlight=( '1 1 alias' # x - '1 1 redirection' # x (>) '3 5 default' # foo '7 10 builtin' # echo '12 14 default' # bar diff --git a/highlighters/main/test-data/alias-self.zsh b/highlighters/main/test-data/alias-self.zsh index 88ed3c8..c6f12b1 100644 --- a/highlighters/main/test-data/alias-self.zsh +++ b/highlighters/main/test-data/alias-self.zsh @@ -34,6 +34,5 @@ BUFFER='echo bar' expected_region_highlight=( '1 4 alias' # echo - '1 4 builtin' # echo '6 8 default' # bar ) diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh index 93aaa62..767d3c7 100644 --- a/highlighters/main/test-data/alias-to-dir.zsh +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -32,6 +32,5 @@ alias x=/ BUFFER=$'x' expected_region_highlight=( - '1 1 alias' # x '1 1 unknown-token "issue #202"' # x (/) ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 03ca0be..4cafa80 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -48,7 +48,6 @@ fi expected_region_highlight+=( "9 9 commandseparator" # ; "11 16 alias" # alias1 - "11 16 command" # alias1 (ls) "17 17 commandseparator" # ; "19 24 unknown-token" # alias2 ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 5676b5a..2f96445 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -32,6 +32,5 @@ BUFFER='x ls' expected_region_highlight=( "1 1 alias" # x - "1 1 precommand" # x (command) "3 4 command" # ls ) diff --git a/highlighters/main/test-data/off-by-one.zsh b/highlighters/main/test-data/off-by-one.zsh index 7d6961a..872143a 100644 --- a/highlighters/main/test-data/off-by-one.zsh +++ b/highlighters/main/test-data/off-by-one.zsh @@ -34,7 +34,6 @@ BUFFER='a;f;' expected_region_highlight=( "1 1 alias" # a - "1 1 builtin" # a (:) "2 2 commandseparator" # ; "3 3 function" # f "4 4 commandseparator" # ; From 369620dd2d0b524b7323544843375f68b498f6f3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 11 Jul 2019 21:33:37 -0500 Subject: [PATCH 066/297] main: Use longer alias name in tests --- .../alias-precommand-option-argument1.zsh | 12 ++++++------ .../alias-precommand-option-argument2.zsh | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index ecdd9f9..b78b61a 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -28,14 +28,14 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sdu='sudo -u' +alias sudo_u='sudo -u' sudo(){} -BUFFER='sdu phy1729 echo foo' +BUFFER='sudo_u phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # sdu - '5 11 default' # phy1729 - '13 16 commmand "issue #540"' # echo (not builtin) - '18 20 default' # foo + '1 6 alias' # sudo_u + '8 14 default' # phy1729 + '17 19 commmand "issue #540"' # echo (not builtin) + '21 23 default' # foo ) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 95d71f8..1ca8f7e 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -28,15 +28,15 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sdb='sudo -b' -alias sbu='sdb -u' +alias sudo_b='sudo -b' +alias sudo_b_u='sudo_b -u' sudo(){} -BUFFER='sbu phy1729 echo foo' +BUFFER='sudo_b_u phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # sbu - '5 11 default' # phy1729 - '13 16 commmand "issue #540"' # echo (not builtin) - '18 20 default' # foo + '1 8 alias' # sudo_b_u + '10 16 default' # phy1729 + '18 21 commmand "issue #540"' # echo (not builtin) + '23 25 default' # foo ) From 1fcd786f77880108414738faabd42719165947e0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 11 Jul 2019 21:39:45 -0500 Subject: [PATCH 067/297] main: Add more alias tests Suggested by Daniel. --- .../alias-precommand-option-argument3.zsh | 41 ++++++++++++++++++ .../alias-precommand-option-argument4.zsh | 42 +++++++++++++++++++ .../main/test-data/alias-unknown-token1.zsh | 37 ++++++++++++++++ .../main/test-data/alias-unknown-token2.zsh | 37 ++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 highlighters/main/test-data/alias-precommand-option-argument3.zsh create mode 100644 highlighters/main/test-data/alias-precommand-option-argument4.zsh create mode 100644 highlighters/main/test-data/alias-unknown-token1.zsh create mode 100644 highlighters/main/test-data/alias-unknown-token2.zsh diff --git a/highlighters/main/test-data/alias-precommand-option-argument3.zsh b/highlighters/main/test-data/alias-precommand-option-argument3.zsh new file mode 100644 index 0000000..2c78121 --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument3.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias sudo_u='sudo -u' +sudo(){} + +BUFFER='sudo_u phy1729 ls foo' + +expected_region_highlight=( + '1 6 alias' # sudo_u + '8 14 default' # phy1729 + '16 17 command' # ls + '19 21 default' # foo +) diff --git a/highlighters/main/test-data/alias-precommand-option-argument4.zsh b/highlighters/main/test-data/alias-precommand-option-argument4.zsh new file mode 100644 index 0000000..d47dccb --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument4.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +alias sudo_b='sudo -b' +alias sudo_b_u='sudo_b -u' +sudo(){} + +BUFFER='sudo_b_u phy1729 ls foo' + +expected_region_highlight=( + '1 8 alias' # sudo_b_u + '10 16 default' # phy1729 + '18 19 command' # ls + '21 23 default' # foo +) diff --git a/highlighters/main/test-data/alias-unknown-token1.zsh b/highlighters/main/test-data/alias-unknown-token1.zsh new file mode 100644 index 0000000..9c996bf --- /dev/null +++ b/highlighters/main/test-data/alias-unknown-token1.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias a=b b=foo + +BUFFER='a ' + +expected_region_highlight=( + '1 1 unknown-token' # a +) diff --git a/highlighters/main/test-data/alias-unknown-token2.zsh b/highlighters/main/test-data/alias-unknown-token2.zsh new file mode 100644 index 0000000..ab9facd --- /dev/null +++ b/highlighters/main/test-data/alias-unknown-token2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias a='() { ls "$@" ; foo }' + +BUFFER='a ' + +expected_region_highlight=( + '1 1 unknown-token' # a +) From 2bd709fc2878bf95cf64e631d50d8f72c3985c4a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Jul 2019 10:38:53 -0500 Subject: [PATCH 068/297] main: Fix misspelling in test expectation --- .../main/test-data/alias-precommand-option-argument1.zsh | 2 +- .../main/test-data/alias-precommand-option-argument2.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index b78b61a..30398a3 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -36,6 +36,6 @@ BUFFER='sudo_u phy1729 echo foo' expected_region_highlight=( '1 6 alias' # sudo_u '8 14 default' # phy1729 - '17 19 commmand "issue #540"' # echo (not builtin) + '17 19 command "issue #540"' # echo (not builtin) '21 23 default' # foo ) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 1ca8f7e..fbc6eec 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -37,6 +37,6 @@ BUFFER='sudo_b_u phy1729 echo foo' expected_region_highlight=( '1 8 alias' # sudo_b_u '10 16 default' # phy1729 - '18 21 commmand "issue #540"' # echo (not builtin) + '18 21 command "issue #540"' # echo (not builtin) '23 25 default' # foo ) From 8e78e9dbba673d2a6933b5e98045eabd04f554f5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 21 Jul 2019 01:44:19 +0000 Subject: [PATCH 069/297] 'main': Fix issue #623 by fixing the expectations of the regression test of issue #616. --- highlighters/main/test-data/empty-command-newline.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/empty-command-newline.zsh b/highlighters/main/test-data/empty-command-newline.zsh index 397cef8..783f4b6 100644 --- a/highlighters/main/test-data/empty-command-newline.zsh +++ b/highlighters/main/test-data/empty-command-newline.zsh @@ -28,10 +28,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=$':;\n' +# Newline after semicolon isn't unknown-token +BUFFER=$':;\n:' expected_region_highlight=( '1 1 builtin' # : '2 2 commandseparator' # ; - '3 3 issue-623 "issue #616"' # \n + '3 3 commandseparator "issue #616"' # \n + '4 4 builtin' # : ) From b55832c5f849b2416c83ce3a665cf4bef2dc4d48 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 24 Jul 2019 07:27:54 -0500 Subject: [PATCH 070/297] main: Drop X_ from X_ZSH_HIGHLIGHT_DIRS_BLACKLIST --- docs/highlighters/main.md | 4 ++-- highlighters/main/main-highlighter.zsh | 10 ++++++++-- highlighters/main/test-data/dirs_blacklist.zsh | 2 +- zsh-syntax-highlighting.zsh | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index f4507d8..3b0e853 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -85,11 +85,11 @@ manual page][zshzle-Character-Highlighting]. #### Parameters -To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. +To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. This interface is still experimental. ```zsh -X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) +ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) ``` ### Useless trivia diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 91be6ca..9c80792 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -355,6 +355,12 @@ _zsh_highlight_highlighter_main_paint() '!' # reserved word; unrelated to $histchars[1] ) + if (( $+X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )); then + print >&2 'zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.' + ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST) + unset X_ZSH_HIGHLIGHT_DIRS_BLACKLIST + fi + _zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' 1 "$PREBUFFER$BUFFER" # end is a reserved word @@ -966,7 +972,7 @@ _zsh_highlight_main_highlighter_check_path() tmp_path=$tmp_path:a while [[ $tmp_path != / ]]; do - [[ -n ${(M)X_ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1 + [[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1 tmp_path=$tmp_path:h done @@ -1411,4 +1417,4 @@ else # Make sure the cache is unset unset _zsh_highlight_main__command_type_cache fi -typeset -ga X_ZSH_HIGHLIGHT_DIRS_BLACKLIST +typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST diff --git a/highlighters/main/test-data/dirs_blacklist.zsh b/highlighters/main/test-data/dirs_blacklist.zsh index 8cf04be..2d0222f 100644 --- a/highlighters/main/test-data/dirs_blacklist.zsh +++ b/highlighters/main/test-data/dirs_blacklist.zsh @@ -30,7 +30,7 @@ mkdir foo touch foo/bar BUFFER=": foo/bar $PWD/foo foo/b" -X_ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo $PWD/bar) +ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo $PWD/bar) expected_region_highlight=( '1 1 builtin' # : diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index df8a1aa..320ce5b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -432,6 +432,12 @@ zmodload zsh/parameter 2>/dev/null || true # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) +if (( $+X_ZSH_HIGHLIGHT_DIRS_BLACKLIST )); then + print >&2 'zsh-syntax-highlighting: X_ZSH_HIGHLIGHT_DIRS_BLACKLIST is deprecated. Please use ZSH_HIGHLIGHT_DIRS_BLACKLIST.' + ZSH_HIGHLIGHT_DIRS_BLACKLIST=($X_ZSH_HIGHLIGHT_DIRS_BLACKLIST) + unset X_ZSH_HIGHLIGHT_DIRS_BLACKLIST +fi + # Restore the aliases we unned eval "$zsh_highlight__aliases" builtin unset zsh_highlight__aliases From 35c8690c0025ceef9584f64da86ced3a72ee32b6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Aug 2019 15:02:07 +0000 Subject: [PATCH 071/297] release.md: Document that release tags should be signed. That's how the previous tags were done. --- release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.md b/release.md index 55a70f5..b9398c8 100644 --- a/release.md +++ b/release.md @@ -9,7 +9,7 @@ `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; Commit that using `git commit -m "Tag version $(<.version)." .version`; - Tag it using `git tag -m "Tag version $(<.version)"`; + Tag it using `git tag -s -m "Tag version $(<.version)"`; Increment `./.version` and restore the `-dev` suffix; Commit that using `git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5 .version`. - Push with `git push && git push --tags` From be3882aeb054d01f6667facc31522e82f00b5e94 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 17 Oct 2019 16:40:45 +0200 Subject: [PATCH 072/297] driver: adjust region end for vi command mode --- zsh-syntax-highlighting.zsh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 320ce5b..5c6b478 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -157,24 +157,25 @@ _zsh_highlight() # Re-apply zle_highlight settings # region - if (( REGION_ACTIVE == 1 )); then - _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" - elif (( REGION_ACTIVE == 2 )); then - () { + () { + (( REGION_ACTIVE )) || return + integer min max + if (( MARK > CURSOR )) ; then + min=$CURSOR max=$MARK + else + min=$MARK max=$CURSOR + fi + if (( REGION_ACTIVE == 1 )); then + [[ $KEYMAP = vicmd ]] && (( max++ )) + elif (( REGION_ACTIVE == 2 )); then local needle=$'\n' - integer min max - if (( MARK > CURSOR )) ; then - min=$CURSOR max=$MARK - else - min=$MARK max=$CURSOR - fi # CURSOR and MARK are 0 indexed between letters like region_highlight # Do not include the newline in the highlight (( min = ${BUFFER[(Ib:min:)$needle]} )) (( max = ${BUFFER[(ib:max:)$needle]} - 1 )) - _zsh_highlight_apply_zle_highlight region standout "$min" "$max" - } - fi + fi + _zsh_highlight_apply_zle_highlight region standout "$min" "$max" + } # yank / paste (zsh-5.1.1 and newer) (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" From 139ea2b189819c43cc251825981c116959b15cc3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 7 Nov 2019 19:50:17 -0600 Subject: [PATCH 073/297] main: Avoid $end_pos when calculating $arg size Fixes second issue filed under #617 https://github.com/zsh-users/zsh-syntax-highlighting/issues/617#issuecomment-551253422 In the case of a command substitution in an alias, $arg[i,end_pos] would not pass to the end of $arg and i <= start_pos - end_pos would not iterate over all of $arg. Use $arg[i,-1] and $#arg respectively to avoid issues in aliases. --- highlighters/main/main-highlighter.zsh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9c80792..2a2bfc9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -807,7 +807,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Discard :start_of_pipeline:, if present, as '!' is not valid # after assignments. next_word+=':start:' - if (( start_pos + i <= end_pos )); then + if (( i <= $#arg )); then () { local highlight_glob=false [[ $zsyh_user_options[globassign] == on ]] && highlight_glob=true @@ -1030,7 +1030,7 @@ _zsh_highlight_main_highlighter_highlight_argument() '=') if [[ $arg[i+1] == $'\x28' ]]; then (( i += 2 )) - _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] ret=$? (( i += REPLY )) highlights+=( @@ -1044,7 +1044,7 @@ _zsh_highlight_main_highlighter_highlight_argument() fi esac - for (( ; i <= end_pos - start_pos ; i += 1 )); do + for (( ; i <= $#arg ; i += 1 )); do case "$arg[$i]" in "\\") (( i += 1 )); continue;; "'") @@ -1074,7 +1074,7 @@ _zsh_highlight_main_highlighter_highlight_argument() elif [[ $arg[i+1] == $'\x28' ]]; then start=$i (( i += 2 )) - _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] ret=$? (( i += REPLY )) highlights+=( @@ -1097,7 +1097,7 @@ _zsh_highlight_main_highlighter_highlight_argument() if [[ $arg[i+1] == $'\x28' ]]; then # \x28 = open paren start=$i (( i += 2 )) - _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] ret=$? (( i += REPLY )) highlights+=( @@ -1123,7 +1123,7 @@ _zsh_highlight_main_highlighter_highlight_argument() esac done - if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,end_pos]; then + if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then base_style=$REPLY _zsh_highlight_main_highlighter_highlight_path_separators $base_style highlights+=($reply) @@ -1175,7 +1175,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() local i j k ret style reply=() - for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do + for (( i = $1 + 1 ; i <= $#arg ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in @@ -1206,7 +1206,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() breaks+=( $last_break $(( start_pos + i - 1 )) ) (( i += 2 )) saved_reply=($reply) - _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] ret=$? (( i += REPLY )) last_break=$(( start_pos + i )) @@ -1272,13 +1272,13 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() integer c reply=() - for (( i = $1 + 2 ; i <= end_pos - start_pos ; i += 1 )) ; do + for (( i = $1 + 2 ; i <= $#arg ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in "'") break;; "\\") style=back-dollar-quoted-argument - for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do + for (( c = i + 1 ; c <= $#arg ; c += 1 )); do [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break done AA=$arg[$i+1,$c-1] @@ -1333,7 +1333,7 @@ _zsh_highlight_main_highlighter_highlight_backtick() last=$(( arg1 + 1 )) # Remove one layer of backslashes and find the end while i=$arg[(ib:i+1:)[\\\\\`]]; do # find the next \ or ` - if (( i > end_pos - start_pos )); then + if (( i > $#arg )); then buf=$buf$arg[last,i] offsets[i-arg1-offset]='' # So we never index past the end (( i-- )) From e7d3fbc50b0209cb9f9b0812fd40298be03c7808 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 7 Nov 2019 19:58:07 -0600 Subject: [PATCH 074/297] main: Add test for previous --- .../test-data/alias-command-substitution.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/alias-command-substitution.zsh diff --git a/highlighters/main/test-data/alias-command-substitution.zsh b/highlighters/main/test-data/alias-command-substitution.zsh new file mode 100644 index 0000000..a7b77df --- /dev/null +++ b/highlighters/main/test-data/alias-command-substitution.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +# Alias must be at least 4 characters to test the regression +# cf. 139ea2b189819c43cc251825981c116959b15cc3 +alias foobar='echo "$(echo foobar)"' +BUFFER='foobar' + +expected_region_highlight=( + "1 6 alias" # foobar +) From e209cbe61aacea60ccff7b806d2a8fab05750e18 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:20:21 +0000 Subject: [PATCH 075/297] tests: Include the name of the 'cardinality check' test point in the output --- tests/test-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b2a6db5..b55324c 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -178,7 +178,7 @@ run_test_internal() { details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY - print -r -- "not ok $i - $details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + print -r -- "not ok $i - cardinality check" "$details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" fi } From d5a4a6e1951fb2f4fbbad205405c0f6b1b349187 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:29:20 +0000 Subject: [PATCH 076/297] tests: Make $expected_mismatch skip the cardinality check, rather than consider it an expected failure. With this change, if $expected_region_highlight and $region_highlight coincidentally have the same number of elements, the test won't be considered to fail. This is useful in conjunction with the next commit, q.v.. At this time, no tests set $expected_mismatch explicitly. However, the commit after next (this commit's grandchild) will add a test that will set $expected_mismatch implicitly, using the functionality in the next commit (this commit's child). --- tests/README.md | 3 +-- tests/test-highlighting.zsh | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/README.md b/tests/README.md index 89aef14..a413e16 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,8 +23,7 @@ need not match the order in `$region_highlight`. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` have different numbers of elements. Tests may set `$expected_mismatch` to an -explanation string (like `$todo`) to avoid this and mark the cardinality check -as todo. +explanation string (like `$todo`) to avoid this and skip the cardinality check. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b55324c..7b32dbc 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -171,14 +171,17 @@ run_test_internal() { unset desc done - if (( $#expected_region_highlight == $#region_highlight )); then - print -r -- "ok $i - cardinality check" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + if [[ -n $expected_mismatch ]]; then + tap_escape $expected_mismatch; expected_mismatch=$REPLY + print "ok $i - cardinality check" "# SKIP $expected_mismatch" + elif (( $#expected_region_highlight == $#region_highlight )); then + print -r -- "ok $i - cardinality check" else local details details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY - print -r -- "not ok $i - cardinality check" "$details" "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + print -r -- "not ok $i - cardinality check - $details" fi } From 4952325051d41817485a4a3a2dfc9a70dd134c74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:35:21 +0000 Subject: [PATCH 077/297] tests: Skip cardinality tests whenever any test point is expected to fail. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When writing an expected-to-fail test case, the cardinality of $region_highlight at the time the test is written may differ from the cardinality it will have once the bug is fixed. For example, with issue #641.5, the current highlighting is ['nice', 'x=y', 'y', 'ls'] — four elements — but the correct highlighting would have three elements: ['nice', 'x=y', 'ls']. There is no point in reporting a separate test failure for the cardinality check in this case, nor for 'ls' being highlighted as 'command' rather than 'default'. At the same time, in other cases the current and correct highlighting may have the same number of elements (for example, this would be the case for a hypothetical "the command word is highlighted as an alias rather than a function" bug). Thus, the previous commit, q.v.. --- tests/README.md | 1 + tests/test-highlighting.zsh | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index a413e16..ebacae4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -24,6 +24,7 @@ need not match the order in `$region_highlight`. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` have different numbers of elements. Tests may set `$expected_mismatch` to an explanation string (like `$todo`) to avoid this and skip the cardinality check. +`$expected_mismatch` is set implicitly if the `$todo` component is present. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7b32dbc..a01df43 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -145,7 +145,10 @@ run_test_internal() { local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} ) integer exp_start=$expected_highlight_zone[1] exp_end=$expected_highlight_zone[2] local todo= - (( $+expected_highlight_zone[4] )) && todo="# TODO $expected_highlight_zone[4]" + if (( $+expected_highlight_zone[4] )); then + todo="# TODO $expected_highlight_zone[4]" + : ${expected_mismatch:="cardinality check disabled whilst regular test points are expected to fail"} + fi if ! (( $+region_highlight[i] )); then print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" continue From 926c36c1fb3f47f1a21a6a6fd699258011cc5fda Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:37:41 +0000 Subject: [PATCH 078/297] Add a test for issue #641.5, using the infrastructure added in the previous commits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current output: . # precommand-then-assignment 1..4 ok 1 - [1,4] «nice» not ok 2 - [6,8] «x=y» - expected (6 8 "unknown-token"), observed (6 8 "assign"). # TODO "issue #641.5" not ok 3 - [8,8] «y» - expected (10 11 "default"), observed (8 8 "default"). # TODO "issue #641.5 (fallout)" ok 4 - cardinality check # SKIP cardinality check disabled whilst regular test points are expected to fail --- .../test-data/precommand-then-assignment.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/precommand-then-assignment.zsh diff --git a/highlighters/main/test-data/precommand-then-assignment.zsh b/highlighters/main/test-data/precommand-then-assignment.zsh new file mode 100644 index 0000000..f0bb75f --- /dev/null +++ b/highlighters/main/test-data/precommand-then-assignment.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'nice x=y ls' + +expected_region_highlight=( + '1 4 precommand' # nice + '6 8 unknown-token "issue #641.5"' # x=y + '10 11 default "issue #641.5 (fallout)"' # ls +) From b7592e581dad4e8bba0ceb44ca85dd7c9dc293af Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:41:31 +0000 Subject: [PATCH 079/297] tests: Minor documentation readability tweak --- tests/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/README.md b/tests/README.md index ebacae4..f35a5c1 100644 --- a/tests/README.md +++ b/tests/README.md @@ -16,8 +16,10 @@ that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. `$style` is a key of `$ZSH_HIGHLIGHT_STYLES`. If `$todo` exists, the test point is marked as TODO (the failure of that test point will not fail the test), and `$todo` is used as the explanation. + If a test sets `$skip_test` to a non-empty string, the test will be skipped with the provided string as the reason. + If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight` need not match the order in `$region_highlight`. From 6647e8860698b8060eda3a2c5736c7718786743d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 25 Dec 2019 10:53:42 +0000 Subject: [PATCH 080/297] 'main': Add some precommands. --- highlighters/main/main-highlighter.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2a2bfc9..4849181 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -311,12 +311,17 @@ _zsh_highlight_highlighter_main_paint() 'exec' a:cl 'nocorrect' '' 'noglob' '' + 'time' '' 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 'stdbuf' ioe: + 'eatmydata' '' + 'catchsegv' '' + 'nohup' '' + 'setsid' :wc ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From ce10f20e77791ae0bf1c561ff64ce10993e3fc50 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Dec 2019 09:00:36 +0000 Subject: [PATCH 081/297] 'main': Add a regression test for #652. --- .../main/test-data/alias-eponymous1.zsh | 36 +++++++++++++++++++ .../main/test-data/alias-eponymous2.zsh | 36 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 highlighters/main/test-data/alias-eponymous1.zsh create mode 100644 highlighters/main/test-data/alias-eponymous2.zsh diff --git a/highlighters/main/test-data/alias-eponymous1.zsh b/highlighters/main/test-data/alias-eponymous1.zsh new file mode 100644 index 0000000..2642e14 --- /dev/null +++ b/highlighters/main/test-data/alias-eponymous1.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias ls='command ls' + +BUFFER='ls' + +expected_region_highlight=( + "1 2 alias" # ls +) diff --git a/highlighters/main/test-data/alias-eponymous2.zsh b/highlighters/main/test-data/alias-eponymous2.zsh new file mode 100644 index 0000000..dfc7404 --- /dev/null +++ b/highlighters/main/test-data/alias-eponymous2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias ls=tmp tmp='command ls' + +BUFFER='ls' + +expected_region_highlight=( + "1 2 alias 'issue #652'" # ls +) From 83862c1abb8fee19df20f4198446d4358e217df1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Dec 2019 09:37:23 +0000 Subject: [PATCH 082/297] 'main': Add two basic tests for aliases. --- highlighters/main/test-data/alias-basic.zsh | 35 +++++++++++++++++++++ highlighters/main/test-data/alias-loop2.zsh | 35 +++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 highlighters/main/test-data/alias-basic.zsh create mode 100644 highlighters/main/test-data/alias-loop2.zsh diff --git a/highlighters/main/test-data/alias-basic.zsh b/highlighters/main/test-data/alias-basic.zsh new file mode 100644 index 0000000..7af8b7c --- /dev/null +++ b/highlighters/main/test-data/alias-basic.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +alias foo="echo hello world" +BUFFER="foo" + +expected_region_highlight+=( + "1 3 alias" # foo +) diff --git a/highlighters/main/test-data/alias-loop2.zsh b/highlighters/main/test-data/alias-loop2.zsh new file mode 100644 index 0000000..29e04ac --- /dev/null +++ b/highlighters/main/test-data/alias-loop2.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2015 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 +# ------------------------------------------------------------------------------------------------- + +alias ls="ls" +BUFFER="ls" + +expected_region_highlight+=( + "1 2 alias" # ls +) From de95d50bce6f16fad7e20e9bf1fb7bff710dbcfd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Dec 2019 13:47:31 +0000 Subject: [PATCH 083/297] 'main': Fix highlighting of the 'time' and 'nocorrect reserved words Also add tests. 'time' is a regression from 6647e8860698b8060eda3a2c5736c7718786743d (last Wednesday). --- highlighters/main/main-highlighter.zsh | 7 +++- .../main/test-data/time-and-nocorrect1.zsh | 39 ++++++++++++++++++ .../main/test-data/time-and-nocorrect2.zsh | 40 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/time-and-nocorrect1.zsh create mode 100644 highlighters/main/test-data/time-and-nocorrect2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4849181..c0ca575 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -309,9 +309,8 @@ _zsh_highlight_highlighter_main_paint() 'builtin' '' 'command' :pvV 'exec' a:cl - 'nocorrect' '' 'noglob' '' - 'time' '' + # 'time' and 'nocorrect' shouldn't be added here; they're reserved words, not precommands. 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'nice' n: # as of current POSIX spec @@ -723,6 +722,10 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word # Match braces and handle special cases. case $arg in + (time|nocorrect) + next_word=${next_word//:regular:/} + next_word+=':start:' + ;; ($'\x7b') braces_stack='Y'"$braces_stack" ;; diff --git a/highlighters/main/test-data/time-and-nocorrect1.zsh b/highlighters/main/test-data/time-and-nocorrect1.zsh new file mode 100644 index 0000000..fb398ed --- /dev/null +++ b/highlighters/main/test-data/time-and-nocorrect1.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'time ls; nocorrect ls' + +expected_region_highlight=( + '1 4 reserved-word' # time + '6 7 command' # ls + '8 8 commandseparator' # ; + '10 18 reserved-word' # nocorrect + '20 21 command' # ls +) diff --git a/highlighters/main/test-data/time-and-nocorrect2.zsh b/highlighters/main/test-data/time-and-nocorrect2.zsh new file mode 100644 index 0000000..5549ee9 --- /dev/null +++ b/highlighters/main/test-data/time-and-nocorrect2.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'time ls; nocorrect ls' +alias time=':' nocorrect=':' + +expected_region_highlight=( + '1 4 alias' # time + '6 7 default' # ls + '8 8 commandseparator' # ; + '10 18 alias' # nocorrect + '20 21 default' # ls +) From 6f1f595e3ecd7c11cb096995bd32361ef624f7ac Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 7 Jan 2020 19:59:49 +0000 Subject: [PATCH 084/297] dev tools: Print the test data to stdout for convenience. --- tests/generate.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 64a1ede..811abae 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -55,15 +55,15 @@ _zsh_highlight_add_highlight() # Copyright block year="`LC_ALL=C date +%Y`" -if ! read -q "?Set copyright year to $year? "; then +if ! { read -q "?Set copyright year to $year? " } always { echo "" }; then year="YYYY" fi -exec >$fname -<$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" +<$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" > $fname # Assumes stdout is line-buffered git add -- $fname # Buffer +exec > >(tee $fname) print -n 'BUFFER=' if [[ $buffer != (#s)[$'\t -~']#(#e) ]]; then print -r -- ${(qqqq)buffer} From 8b2768ab4007d3d883c3565e7998c431ba576b51 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 20:46:14 +0000 Subject: [PATCH 085/297] 'main': Add a test for 07f259f653df042e599975261cac7be1bda17b5c. --- highlighters/main/test-data/backslash.zsh | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 highlighters/main/test-data/backslash.zsh diff --git a/highlighters/main/test-data/backslash.zsh b/highlighters/main/test-data/backslash.zsh new file mode 100644 index 0000000..ea0977f --- /dev/null +++ b/highlighters/main/test-data/backslash.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'\\' + +expected_region_highlight=( + '1 1 unknown-token' # \\ +) From c0ad50e645f37a9374076aaaf57cd79555c4482d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 20:49:12 +0000 Subject: [PATCH 086/297] dev tools: Fix regression introduced in commit "Print the test data to stdout for convenience.". tee(1) truncated $fname. Fortunately, the data that got truncated had just been `git add`-ed, so no harm was done. --- tests/generate.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 811abae..259ea75 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -63,7 +63,7 @@ fi git add -- $fname # Buffer -exec > >(tee $fname) +exec > >(tee -a $fname) print -n 'BUFFER=' if [[ $buffer != (#s)[$'\t -~']#(#e) ]]; then print -r -- ${(qqqq)buffer} From 1be58a6f45da88ad52db5c0041a9ba1faf60f208 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 21:19:52 +0000 Subject: [PATCH 087/297] Add a test for 2f03b6d704afd172d5fdf73ca5ebde8be5824056. --- .../test-data/redirection-is-not-option.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/redirection-is-not-option.zsh diff --git a/highlighters/main/test-data/redirection-is-not-option.zsh b/highlighters/main/test-data/redirection-is-not-option.zsh new file mode 100644 index 0000000..671f21e --- /dev/null +++ b/highlighters/main/test-data/redirection-is-not-option.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': > -x >> --yy' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 redirection' # > + '5 6 default' # -x + '8 9 redirection' # >> + '11 14 default' # --yy +) From f02c0bf9801143e52f78167c8e3386872b33c5a8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 21:32:21 +0000 Subject: [PATCH 088/297] Don't describe as ZSH_HIGHLIGHT_DIRS_BLACKLIST as experimental, now that it's named without the X_ prefix. --- docs/highlighters/main.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 3b0e853..43f6082 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -86,7 +86,6 @@ manual page][zshzle-Character-Highlighting]. #### Parameters To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. -This interface is still experimental. ```zsh ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) From 68fbe1a4496df4da163f795014e464f92bddaf2a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 21:47:34 +0000 Subject: [PATCH 089/297] Add a test for redirection from/to process substitution. Inspired by ab1013ae0d8c94a38141d4b75f5ff88ea59bc80e. --- ...process-substitution-after-redirection.zsh | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 highlighters/main/test-data/process-substitution-after-redirection.zsh diff --git a/highlighters/main/test-data/process-substitution-after-redirection.zsh b/highlighters/main/test-data/process-substitution-after-redirection.zsh new file mode 100644 index 0000000..2d58016 --- /dev/null +++ b/highlighters/main/test-data/process-substitution-after-redirection.zsh @@ -0,0 +1,46 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017, 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'< <(pwd) > >(nl)' + +expected_region_highlight=( + '1 1 redirection' # < + '3 8 default' # <(pwd) + '3 8 process-substitution' # <(pwd) + '3 4 process-substitution-delimiter' # <( + '5 7 builtin' # pwd + '8 8 process-substitution-delimiter' # ) + '10 10 redirection' # > + '12 16 default' # >(nl) + '12 16 process-substitution' # >(nl) + '12 13 process-substitution-delimiter' # >( + '14 15 command' # nl + '16 16 process-substitution-delimiter' # ) +) From e9b1ce1a36a2875df7df22e563fee350a8dc90ed Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 23:04:22 +0000 Subject: [PATCH 090/297] Add a unit test for dc1b2f6fa4bb477e7b9712ebdb4e82beb50258c6. --- highlighters/main/test-data/pasted-quotes.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/pasted-quotes.zsh diff --git a/highlighters/main/test-data/pasted-quotes.zsh b/highlighters/main/test-data/pasted-quotes.zsh new file mode 100644 index 0000000..f37f21b --- /dev/null +++ b/highlighters/main/test-data/pasted-quotes.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2013 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': \'foo\'bar"baz"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # \'foo\'bar"baz" + '3 7 single-quoted-argument' # \'foo\' + '11 15 double-quoted-argument' # "baz" +) From c1d5790c57b5df878fb667506124a47fe622a712 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 23:10:28 +0000 Subject: [PATCH 091/297] changelog: Start 0.7.0's changelog. --- changelog.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/changelog.md b/changelog.md index 3a2d00b..85781a3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,60 @@ +# Changes in version 0.7.0 + +**Version 0.7.0 has not been released. This changelog is a work in progress.** + +This is a stable bugfix and feature release. Major new features and changes include: + +- Add `ZSH_HIGHLIGHT_DIRS_BLACKLIST` to disable "path" and "path prefix" + highlighting for specific directories + [#379] + +- Add the "regexp" highlighter, modelled after the pattern highlighter + [4e6f60063f1c] + +- When a word uses globbing, only the globbing metacharacters will be highlighted as globbing: + in `: foo*bar`, only the `*` will be blue. + [e48af357532c] + +- Highlight pasted quotes (e.g., `: foo"bar"`) + [dc1b2f6fa4bb] + +- Highlight command substitutions (`` : `ls` ``, `: $(ls)`) + [c0e64fe13178 and parents, e86f75a840e7, et al] + +- Highlight process substitutions (`: >(nl)`, `: <(pwd)`, `: =(git diff)`) + [c0e64fe13178 and parents, e86f75a840e7, et al] + +- Highlight command substitutions inside double quotes (``: "`foo`"``) + [f16e858f0c83] + +- Highlight many precommands (e.g., `nice`, `stdbuf`, `eatmydata`; + see `$precommand_options` in the source) + +- Highlight numeric globs (e.g., `echo /lib<->`) + +- Assorted improvement to aliases highlighting + (e.g., + `alias sudo_u='sudo -u'; sudo_u jrandom ls`, + `alias x=y y=z z=nosuchcommand; x`, + `alias ls='ls -l'; \ls`) + [f3410c5862fc, 57386f30aec8, #544, and many others] + +- Highlight some more syntax errors + [dea05e44e671, 298ef6a2fa30] + +- New styles: named file descriptors, `RC_QUOTES`, and unclosed quotes (e.g., `echo "foo`) + [38c794a978cd, 25ae1c01216c, 967335dfc5fd] + + +Selected bugfixes include: + +- Highlight `sudo` correctly when it's not installed + [26a82113b08b] + +- Handle some non-default options being set in zshrc + [b07ada1255b7, a2a899b41b8, 972ad197c13d, b3f66fc8748f] + + # Changes in version 0.6.0 This is a stable release, featuring bugfixes and minor improvements. From 6a310ada5b80056940eb52bbf2ad30410be23d90 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 23:31:18 +0000 Subject: [PATCH 092/297] changelog: Add three entries --- changelog.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/changelog.md b/changelog.md index 85781a3..43842ad 100644 --- a/changelog.md +++ b/changelog.md @@ -45,6 +45,9 @@ This is a stable bugfix and feature release. Major new features and changes inc - New styles: named file descriptors, `RC_QUOTES`, and unclosed quotes (e.g., `echo "foo`) [38c794a978cd, 25ae1c01216c, 967335dfc5fd] +- The 'brackets' highlighting no longer treats quotes specially. + [ecdda36ef56f] + Selected bugfixes include: @@ -54,6 +57,12 @@ Selected bugfixes include: - Handle some non-default options being set in zshrc [b07ada1255b7, a2a899b41b8, 972ad197c13d, b3f66fc8748f] +- Fix off-by-one highlighting in vi "visual" mode (vicmd keymap) + [be3882aeb054] + +- The 'yank-pop' widget is not wrapped + [#183] + # Changes in version 0.6.0 From 71dc090d02f891a65fee153041dd4332c76c21bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 23:34:58 +0000 Subject: [PATCH 093/297] Tag version 0.7.0-beta1. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index e1bde80..874ff7c 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.0-dev +0.7.0-beta1 From eb277cdcc6b475b35a311374fc2cb6e325630d2e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 094/297] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 874ff7c..a1bbfb9 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.0-beta1 +0.7.0-beta2-dev From 3ee5aa0e06702ae116085e47c7e7f7dc977158c8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 23:43:23 +0000 Subject: [PATCH 095/297] release.md: Add missing argument. --- release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.md b/release.md index b9398c8..4b6adf2 100644 --- a/release.md +++ b/release.md @@ -9,7 +9,7 @@ `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; Commit that using `git commit -m "Tag version $(<.version)." .version`; - Tag it using `git tag -s -m "Tag version $(<.version)"`; + Tag it using `git tag -s -m "Tag version $(<.version)" $(<.version)`; Increment `./.version` and restore the `-dev` suffix; Commit that using `git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5 .version`. - Push with `git push && git push --tags` From ae5ad09cf5b8c7b7825ba014660ee511620c6b2b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 14:58:56 +0000 Subject: [PATCH 096/297] Bump copyright years. --- COPYING.md | 2 +- highlighters/main/main-highlighter.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/COPYING.md b/COPYING.md index 22eea4f..95db0c1 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2018 zsh-syntax-highlighting contributors +Copyright (c) 2010-2019 zsh-syntax-highlighting contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c0ca575..80f9c0d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2018 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2019 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From 27fa4a6546dd17e03e56a7b4e7c7b42c4ab4779e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 15:46:22 +0000 Subject: [PATCH 097/297] noop: Quote the bitflag values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now every instance of «:foo:» is ''-quoted. This enables $EDITOR to highlight them consistently throughout the file. --- highlighters/main/main-highlighter.zsh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 80f9c0d..e05139b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -434,12 +434,12 @@ _zsh_highlight_main_highlighter_highlight_list() # # When the kind of a word is not yet known, $this_word / $next_word may contain # multiple states. For example, after "sudo -i", the next word may be either - # another --flag or a command name, hence the state would include both :start: - # and :sudo_opt:. + # another --flag or a command name, hence the state would include both ':start:' + # and ':sudo_opt:'. # # The tokens are always added with both leading and trailing colons to serve as - # word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/} - # will DTRT regardless of how many elements or repetitions $x has.. + # word delimiters (an improvised array); [[ $x == *':foo:'* ]] and x=${x//:foo:/} + # will DTRT regardless of how many elements or repetitions $x has. # # Handling of redirections: upon seeing a redirection token, we must stall # the current state --- that is, the value of $this_word --- for two iterations @@ -544,7 +544,7 @@ _zsh_highlight_main_highlighter_highlight_list() continue fi - if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then + if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then # Expand aliases. _zsh_highlight_main__type "$arg" local res="$REPLY" @@ -660,12 +660,12 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]# ]]; then # Flag that requires no argument - this_word=:sudo_opt: + this_word=':sudo_opt:' next_word+=':start:' next_word+=':sudo_opt:' elif [[ $arg == '-'* ]]; then # Unknown flag - this_word=:sudo_opt: + this_word=':sudo_opt:' next_word+=':start:' next_word+=':sudo_opt:' _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token From 2d0dddf58bab0bd9220f29919065ff85db66390e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 15:27:55 +0000 Subject: [PATCH 098/297] 'main': Don't dequote the word in command position before analyzing it. Fixes #656. Fixes #660. Regression from commit e1ecf950e23471b235e318ba7b85e77395a6b146, "main: Do path expanstion after alias expansion" (sic). --- highlighters/main/main-highlighter.zsh | 3 +- .../main/test-data/assign-value-quote1.zsh | 37 +++++++++++++++++++ .../main/test-data/assign-value-quote2.zsh | 37 +++++++++++++++++++ .../main/test-data/assignment-quoted.zsh | 37 +++++++++++++++++++ .../quoted-redirection-in-command-word.zsh | 37 +++++++++++++++++++ 5 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/assign-value-quote1.zsh create mode 100644 highlighters/main/test-data/assign-value-quote2.zsh create mode 100644 highlighters/main/test-data/assignment-quoted.zsh create mode 100644 highlighters/main/test-data/quoted-redirection-in-command-word.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e05139b..b15246c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -580,8 +580,7 @@ _zsh_highlight_main_highlighter_highlight_list() continue else _zsh_highlight_main_highlighter_expand_path $arg - arg=$REPLY - _zsh_highlight_main__type "$arg" 0 + _zsh_highlight_main__type "$REPLY" 0 res="$REPLY" fi fi diff --git a/highlighters/main/test-data/assign-value-quote1.zsh b/highlighters/main/test-data/assign-value-quote1.zsh new file mode 100644 index 0000000..b6d04fe --- /dev/null +++ b/highlighters/main/test-data/assign-value-quote1.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'s="foo\'bar"' + +expected_region_highlight=( + '1 11 assign' # s="foo'bar" + '3 11 default' # "foo'bar" + '3 11 double-quoted-argument' # "foo'bar" +) diff --git a/highlighters/main/test-data/assign-value-quote2.zsh b/highlighters/main/test-data/assign-value-quote2.zsh new file mode 100644 index 0000000..3c5f93b --- /dev/null +++ b/highlighters/main/test-data/assign-value-quote2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'s="foo \'\' bar"' + +expected_region_highlight=( + '1 14 assign' # s="foo '' bar" + '3 14 default' # "foo '' bar" + '3 14 double-quoted-argument' # "foo '' bar" +) diff --git a/highlighters/main/test-data/assignment-quoted.zsh b/highlighters/main/test-data/assignment-quoted.zsh new file mode 100644 index 0000000..18638ad --- /dev/null +++ b/highlighters/main/test-data/assignment-quoted.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'1="foo"' + +expected_region_highlight=( + '1 7 assign' # 1="foo" + '3 7 default' # "foo" + '3 7 double-quoted-argument' # "foo" +) diff --git a/highlighters/main/test-data/quoted-redirection-in-command-word.zsh b/highlighters/main/test-data/quoted-redirection-in-command-word.zsh new file mode 100644 index 0000000..b1a79e1 --- /dev/null +++ b/highlighters/main/test-data/quoted-redirection-in-command-word.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'">" foo ls' + +expected_region_highlight=( + '1 3 unknown-token' # ">" - not "redirection" + '5 7 default' # foo + '9 10 default' # ls - not "command" +) From 533bfa011622f2eb829e1310db0860ae8d3d75f3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 17:10:34 +0000 Subject: [PATCH 099/297] 'main': Fix the new 'backslash' test on zsh-5.0.2 and older. (The bug occurred on zsh-5.0.7 and older but I don't have zsh-5.0.7 handy to test on.) Evidently, the issue was due to elision. This addresses #665.0 and #665.5. --- highlighters/main/main-highlighter.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b15246c..8dd861f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -188,7 +188,7 @@ _zsh_highlight_main__type() { elif { [[ $1 != */* ]] || is-at-least 5.3 } && # Add a subshell to avoid a zsh upstream bug; see issue #606. # ### Remove the subshell when we stop supporting zsh 5.7.1 (I assume 5.8 will have the bugfix). - ! (builtin type -w -- $1) >/dev/null 2>&1; then + ! (builtin type -w -- "$1") >/dev/null 2>&1; then REPLY=none fi fi @@ -203,7 +203,7 @@ _zsh_highlight_main__type() { # starts with an arithmetic expression [«((…))» as the first thing inside # «$(…)»], which is area that has had some parsing bugs before 5.6 # (approximately). - REPLY="${$(:; (( aliases_allowed )) || unalias -- $1 2>/dev/null; LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" + REPLY="${$(:; (( aliases_allowed )) || unalias -- "$1" 2>/dev/null; LC_ALL=C builtin type -w -- "$1" 2>/dev/null)##*: }" if [[ $REPLY == 'alias' ]]; then may_cache=0 fi From 86fe05400587d27949bfbdacb99ae433a6c53a00 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Jan 2020 21:12:21 +0000 Subject: [PATCH 100/297] 'main': precommands += ssh-agent --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8dd861f..028d51a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -321,6 +321,8 @@ _zsh_highlight_highlighter_main_paint() 'catchsegv' '' 'nohup' '' 'setsid' :wc + # As of OpenSSH 8.1p1; -k is deliberately left out since it may not be followed by a command + 'ssh-agent' aEPt:csDd ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From f32d1704b1e97f3a82f96ffd8ed828db7d84c56d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Dec 2019 09:20:18 +0000 Subject: [PATCH 101/297] 'main': Fix issue #652. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/alias-eponymous2.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 028d51a..b7858f1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -548,7 +548,7 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then # Expand aliases. - _zsh_highlight_main__type "$arg" + _zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" local res="$REPLY" if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' diff --git a/highlighters/main/test-data/alias-eponymous2.zsh b/highlighters/main/test-data/alias-eponymous2.zsh index dfc7404..dcd8565 100644 --- a/highlighters/main/test-data/alias-eponymous2.zsh +++ b/highlighters/main/test-data/alias-eponymous2.zsh @@ -32,5 +32,5 @@ alias ls=tmp tmp='command ls' BUFFER='ls' expected_region_highlight=( - "1 2 alias 'issue #652'" # ls + "1 2 alias" # ls ) From 21cdd6bc5e436f03c474a413b5f30b8fdf95593f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Dec 2019 09:24:01 +0000 Subject: [PATCH 102/297] 'main': Simplify alias handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $last_alias isn't needed; there's no reason to treat loops of length 2 (alias a=b b=a) differently to loops of length 1 (alias a=a), length 3 (alias a=b b=c c=a), or length N. The «(( $+seen_alias[$arg] ))» check is redundant as of the last commit: the enclosing condition ensures that $res is "alias", which implies that «(( $+seen_alias[$arg] ))» is false. --- highlighters/main/main-highlighter.zsh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b7858f1..b881c21 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -394,9 +394,7 @@ _zsh_highlight_main_highlighter_highlight_list() # alias_style is the style to apply to an alias once in_alias=0 # Usually 'alias' but set to 'unknown-token' if any word expanded from # the alias would be highlighted as unknown-token - # last_alias is the last alias arg (lhs) expanded (if in an alias). - # This allows for expanding alias ls='ls -l' while avoiding loops. - local alias_style arg buf=$4 highlight_glob=true last_alias style + local alias_style arg buf=$4 highlight_glob=true style local in_array_assignment=false # true between 'a=(' and the matching ')' # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. @@ -474,7 +472,7 @@ _zsh_highlight_main_highlighter_highlight_list() if (( in_alias )); then (( in_alias-- )) if (( in_alias == 0 )); then - last_alias= seen_alias=() + seen_alias=() # start_pos and end_pos are of the alias (previous $arg) here _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style fi @@ -550,16 +548,15 @@ _zsh_highlight_main_highlighter_highlight_list() # Expand aliases. _zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" local res="$REPLY" - if [[ $res == "alias" ]] && [[ $last_alias != $arg ]]; then + if [[ $res == "alias" ]]; then # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' # Also mark insane aliases as unknown-token (cf. #263). - if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then + if [[ $arg == ?*=* ]]; then (( in_alias == 0 )) && in_alias=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi seen_alias[$arg]=1 - last_alias=$arg _zsh_highlight_main__resolve_alias $arg local -a alias_args # Elision is desired in case alias x='' From c3293ba0d8d6c2c11fed3c866c411fdc82e2e6fb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 18:16:31 +0000 Subject: [PATCH 103/297] 'main': Update comments after last commit. No functional change. --- highlighters/main/main-highlighter.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b881c21..e97b8b8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -546,11 +546,11 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *':start:'* ]] && ! (( in_redirection )); then # Expand aliases. + # An alias is ineligible for expansion while it's being expanded (see #652/#653). _zsh_highlight_main__type "$arg" "$(( ! ${+seen_alias[$arg]} ))" local res="$REPLY" if [[ $res == "alias" ]]; then - # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' - # Also mark insane aliases as unknown-token (cf. #263). + # Mark insane aliases as unknown-token (cf. #263). if [[ $arg == ?*=* ]]; then (( in_alias == 0 )) && in_alias=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token From 1618848df6d3b66d8d3110f313bbc1fb7d388b2c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:17:52 +0000 Subject: [PATCH 104/297] 'main': Add some tests for complete and partial absolute paths in command position. --- .../abspath-in-command-position1.zsh | 35 +++++++++++++++++++ .../abspath-in-command-position2.zsh | 35 +++++++++++++++++++ .../abspath-in-command-position3.zsh | 35 +++++++++++++++++++ .../abspath-in-command-position4.zsh | 35 +++++++++++++++++++ .../abspath-in-command-position5.zsh | 35 +++++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 highlighters/main/test-data/abspath-in-command-position1.zsh create mode 100644 highlighters/main/test-data/abspath-in-command-position2.zsh create mode 100644 highlighters/main/test-data/abspath-in-command-position3.zsh create mode 100644 highlighters/main/test-data/abspath-in-command-position4.zsh create mode 100644 highlighters/main/test-data/abspath-in-command-position5.zsh diff --git a/highlighters/main/test-data/abspath-in-command-position1.zsh b/highlighters/main/test-data/abspath-in-command-position1.zsh new file mode 100644 index 0000000..75140d2 --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position1.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'/' + +expected_region_highlight=( + '1 1 path' # / +) diff --git a/highlighters/main/test-data/abspath-in-command-position2.zsh b/highlighters/main/test-data/abspath-in-command-position2.zsh new file mode 100644 index 0000000..5033d2c --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position2.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'/bi' + +expected_region_highlight=( + '1 3 path_prefix' # /bi +) diff --git a/highlighters/main/test-data/abspath-in-command-position3.zsh b/highlighters/main/test-data/abspath-in-command-position3.zsh new file mode 100644 index 0000000..9323ed7 --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position3.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'/bin' + +expected_region_highlight=( + '1 4 path' # /bin +) diff --git a/highlighters/main/test-data/abspath-in-command-position4.zsh b/highlighters/main/test-data/abspath-in-command-position4.zsh new file mode 100644 index 0000000..9e935bf --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position4.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'/bin/s' + +expected_region_highlight=( + '1 6 path_prefix' # /bin/s +) diff --git a/highlighters/main/test-data/abspath-in-command-position5.zsh b/highlighters/main/test-data/abspath-in-command-position5.zsh new file mode 100644 index 0000000..e428b1a --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position5.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'/bin/sh' + +expected_region_highlight=( + '1 7 command' # /bin/sh +) From 521fedfdf5facbe0f45e331253c924758624e864 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:32:44 +0000 Subject: [PATCH 105/297] 'main': Change the issue a test is associated with. Issue #202 is too overloaded. --- highlighters/main/test-data/alias-to-dir.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh index 767d3c7..bfa6e07 100644 --- a/highlighters/main/test-data/alias-to-dir.zsh +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -32,5 +32,5 @@ alias x=/ BUFFER=$'x' expected_region_highlight=( - '1 1 unknown-token "issue #202"' # x (/) + '1 1 unknown-token "issue #668"' # x (/) ) From 6629a1f432b8b8bfec92c98ce3fa03fcf5ac79ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:37:30 +0000 Subject: [PATCH 106/297] 'main': Add a test for a $CDPATH bug. --- .../main/test-data/cdpath-abspath.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/cdpath-abspath.zsh diff --git a/highlighters/main/test-data/cdpath-abspath.zsh b/highlighters/main/test-data/cdpath-abspath.zsh new file mode 100644 index 0000000..1913e46 --- /dev/null +++ b/highlighters/main/test-data/cdpath-abspath.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +cdpath=( $PWD ) +mkdir foo foo/bar + +BUFFER="/foo" + +expected_region_highlight=( + '1 4 unknown-token "fixed in the next commit"' # x (/) +) From 08edf8db7f187d2ff5324516ffff099249d9f858 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:37:53 +0000 Subject: [PATCH 107/297] 'main': Fix the $CDPATH from the previous commit. --- highlighters/main/main-highlighter.zsh | 10 ++++++---- highlighters/main/test-data/cdpath-abspath.zsh | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e97b8b8..2f4c925 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -986,10 +986,12 @@ _zsh_highlight_main_highlighter_check_path() [[ -e $expanded_path ]] && return 0 # Search the path in CDPATH - local cdpath_dir - for cdpath_dir in $cdpath ; do - [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 - done + if [[ $expanded_path != /* ]]; then + local cdpath_dir + for cdpath_dir in $cdpath ; do + [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 + done + fi # If dirname($1) doesn't exist, neither does $1. [[ ! -d ${expanded_path:h} ]] && return 1 diff --git a/highlighters/main/test-data/cdpath-abspath.zsh b/highlighters/main/test-data/cdpath-abspath.zsh index 1913e46..64707b2 100644 --- a/highlighters/main/test-data/cdpath-abspath.zsh +++ b/highlighters/main/test-data/cdpath-abspath.zsh @@ -34,5 +34,5 @@ mkdir foo foo/bar BUFFER="/foo" expected_region_highlight=( - '1 4 unknown-token "fixed in the next commit"' # x (/) + '1 4 unknown-token' # x (/) ) From b1f36d9c5f45b879fbd2f64195167a60d9f3cb9e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:48:49 +0000 Subject: [PATCH 108/297] 'main': Add a comment. --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2f4c925..fbb149f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -988,6 +988,7 @@ _zsh_highlight_main_highlighter_check_path() # Search the path in CDPATH if [[ $expanded_path != /* ]]; then local cdpath_dir + # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. for cdpath_dir in $cdpath ; do [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 done From 3a6f7e7bfec2be8992944171cffde045b96c977b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 15:49:04 +0000 Subject: [PATCH 109/297] 'main': Add an XFail test for #641 and #658. --- highlighters/main/test-data/sudo-longopt.zsh | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/sudo-longopt.zsh diff --git a/highlighters/main/test-data/sudo-longopt.zsh b/highlighters/main/test-data/sudo-longopt.zsh new file mode 100644 index 0000000..8c39142 --- /dev/null +++ b/highlighters/main/test-data/sudo-longopt.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='sudo --askpass ls' + +expected_region_highlight=( + '1 4 precommand' # sudo + '6 14 double-hyphen-option "issues #641 and #658"' # --askpass + '16 17 default "issues #641 and #658"' # ls (we don't know whether --askpass takes an argument) +) From 5012d771f3f491cd2927d314a9cb55216172f28c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 15:53:59 +0000 Subject: [PATCH 110/297] 'main': Don't highlight unknown precommand flags as errors. We cannot now for sure whether the flag is misspelled or simply unknown to us, so err on the side of caution. This fixes an unreleased regression. Fixes #658. Issue #641 was originally filed about this problem, but is left open to track further enhancements. --- highlighters/main/main-highlighter.zsh | 7 ++----- highlighters/main/test-data/precommand-unknown-option.zsh | 4 ++-- highlighters/main/test-data/sudo-longopt.zsh | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e97b8b8..9ac15e9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -662,12 +662,9 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':start:' next_word+=':sudo_opt:' elif [[ $arg == '-'* ]]; then - # Unknown flag + # Unknown flag. We don't know whether it takes an argument or not, + # so we don't modify $next_word. this_word=':sudo_opt:' - next_word+=':start:' - next_word+=':sudo_opt:' - _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token - continue else # Not an option flag; nothing to do. (If the command line is # syntactically valid, ${this_word//:sudo_opt:/} should be diff --git a/highlighters/main/test-data/precommand-unknown-option.zsh b/highlighters/main/test-data/precommand-unknown-option.zsh index 1fba1b9..cd94233 100644 --- a/highlighters/main/test-data/precommand-unknown-option.zsh +++ b/highlighters/main/test-data/precommand-unknown-option.zsh @@ -38,6 +38,6 @@ expected_region_highlight=( '10 11 command' # ls '12 12 commandseparator' # ; '14 17 precommand' # sudo - '19 20 unknown-token' # -x - '22 23 command' # ls + '19 20 single-hyphen-option' # -x + '22 23 default' # ls ) diff --git a/highlighters/main/test-data/sudo-longopt.zsh b/highlighters/main/test-data/sudo-longopt.zsh index 8c39142..7a2ea9d 100644 --- a/highlighters/main/test-data/sudo-longopt.zsh +++ b/highlighters/main/test-data/sudo-longopt.zsh @@ -32,6 +32,6 @@ BUFFER='sudo --askpass ls' expected_region_highlight=( '1 4 precommand' # sudo - '6 14 double-hyphen-option "issues #641 and #658"' # --askpass - '16 17 default "issues #641 and #658"' # ls (we don't know whether --askpass takes an argument) + '6 14 double-hyphen-option' # --askpass + '16 17 default' # ls (we don't know whether --askpass takes an argument) ) From cb166dcc773f932918cedfa88789370940179b74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jan 2020 23:06:51 +0000 Subject: [PATCH 111/297] 'main': Restore 0.6.0's behaviour for unknown options. See discussion on #664. --- highlighters/main/main-highlighter.zsh | 9 ++++++++- .../main/test-data/precommand-unknown-option.zsh | 2 +- highlighters/main/test-data/sudo-longopt.zsh | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9ac15e9..038215d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -663,8 +663,15 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':sudo_opt:' elif [[ $arg == '-'* ]]; then # Unknown flag. We don't know whether it takes an argument or not, - # so we don't modify $next_word. + # so modify $next_word as we do for flags that require no argument. + # With that behaviour, if the flag in fact takes no argument we'll + # highlight the inner command word correctly, and if it does take an + # argument we'll highlight the command word correctly if the argument + # was given in the same shell word as the flag (as in '-uphy1729' or + # '--user=phy1729' without spaces). this_word=':sudo_opt:' + next_word+=':start:' + next_word+=':sudo_opt:' else # Not an option flag; nothing to do. (If the command line is # syntactically valid, ${this_word//:sudo_opt:/} should be diff --git a/highlighters/main/test-data/precommand-unknown-option.zsh b/highlighters/main/test-data/precommand-unknown-option.zsh index cd94233..6baf9ff 100644 --- a/highlighters/main/test-data/precommand-unknown-option.zsh +++ b/highlighters/main/test-data/precommand-unknown-option.zsh @@ -39,5 +39,5 @@ expected_region_highlight=( '12 12 commandseparator' # ; '14 17 precommand' # sudo '19 20 single-hyphen-option' # -x - '22 23 default' # ls + '22 23 command' # ls ) diff --git a/highlighters/main/test-data/sudo-longopt.zsh b/highlighters/main/test-data/sudo-longopt.zsh index 7a2ea9d..697f555 100644 --- a/highlighters/main/test-data/sudo-longopt.zsh +++ b/highlighters/main/test-data/sudo-longopt.zsh @@ -33,5 +33,5 @@ BUFFER='sudo --askpass ls' expected_region_highlight=( '1 4 precommand' # sudo '6 14 double-hyphen-option' # --askpass - '16 17 default' # ls (we don't know whether --askpass takes an argument) + '16 17 command' # ls (we don't know whether --askpass takes an argument) ) From 9cb7e9a837c37b098db4aaaacc5923d3ae14240a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 16 Jan 2020 15:49:27 +0000 Subject: [PATCH 112/297] tests: Make sudo-longopt pass when sudo isn't installed. Fixes #673. --- highlighters/main/test-data/sudo-longopt.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/sudo-longopt.zsh b/highlighters/main/test-data/sudo-longopt.zsh index 697f555..ef768bf 100644 --- a/highlighters/main/test-data/sudo-longopt.zsh +++ b/highlighters/main/test-data/sudo-longopt.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +hash sudo='false' BUFFER='sudo --askpass ls' expected_region_highlight=( From b3b6d7129fa5e41ff1741922422aded759dac760 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 16 Jan 2020 16:12:14 +0000 Subject: [PATCH 113/297] tests: Add failing tests for issue #674. --- .../alias-precommand-option-argument1.zsh | 1 + .../alias-precommand-option-argument3.zsh | 1 + .../param-precommand-option-argument1.zsh | 42 +++++++++++++++++++ .../param-precommand-option-argument3.zsh | 42 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 highlighters/main/test-data/param-precommand-option-argument1.zsh create mode 100644 highlighters/main/test-data/param-precommand-option-argument3.zsh diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index 30398a3..2d1f35c 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +# See also param-precommand-option-argument1.zsh alias sudo_u='sudo -u' sudo(){} diff --git a/highlighters/main/test-data/alias-precommand-option-argument3.zsh b/highlighters/main/test-data/alias-precommand-option-argument3.zsh index 2c78121..373f12b 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument3.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument3.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +# See also param-precommand-option-argument3.zsh alias sudo_u='sudo -u' sudo(){} diff --git a/highlighters/main/test-data/param-precommand-option-argument1.zsh b/highlighters/main/test-data/param-precommand-option-argument1.zsh new file mode 100644 index 0000000..fb2ed71 --- /dev/null +++ b/highlighters/main/test-data/param-precommand-option-argument1.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +# See also alias-precommand-option-argument1.zsh +local -a sudo_u=(sudo -u) +sudo(){} + +BUFFER='$sudo_u phy1729 echo foo' + +expected_region_highlight=( + '1 7 precommand' # $sudo_u + '9 15 default "issue #674"' # phy1729 + '18 20 command "issue #540"' # echo (not builtin) + '22 24 default' # foo +) diff --git a/highlighters/main/test-data/param-precommand-option-argument3.zsh b/highlighters/main/test-data/param-precommand-option-argument3.zsh new file mode 100644 index 0000000..4bcfa8a --- /dev/null +++ b/highlighters/main/test-data/param-precommand-option-argument3.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +# See also alias-precommand-option-argument3.zsh +local -a sudo_u=(sudo -u) +sudo(){} + +BUFFER='$sudo_u phy1729 ls foo' + +expected_region_highlight=( + '1 7 precommand' # sudo_u + '9 15 default "issue #674"' # phy1729 + '17 18 command "issue #674"' # ls + '20 22 default' # foo +) From 6b0671b63ebf58ff9a5f3678e5894e3bf49132b1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jan 2020 16:21:15 +0000 Subject: [PATCH 114/297] Add .editorconfig file. Vim doesn't honour the modelines by default because they're too far from the start/end of the file [the default value of the 'modelines' (sic) option is too small]. --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0f7ae82 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# Top-most editorconfig file + +root = true + +[*] +end_of_line = lf +tab_width = 2 +indent_size = 2 +indent_style = space From 1c6a6d92b00eaaa0881f7fec9bde3b9e2be9d309 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jan 2020 18:50:21 +0000 Subject: [PATCH 115/297] dev tools: Allow specifying preamble code when generating test cases. --- tests/generate.zsh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 259ea75..8b16073 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -32,16 +32,17 @@ emulate -LR zsh setopt localoptions extendedglob # Argument parsing. -if (( $# != 3 )) || [[ $1 == -* ]]; then - print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" +if (( $# * $# - 7 * $# + 12 )) || [[ $1 == -* ]]; then + print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME [PREAMBLE]" print -r -- >&2 "" print -r -- >&2 "Generate highlighters/HIGHLIGHTER/test-data/BASENAME.zsh based on the" - print -r -- >&2 "current highlighting of BUFFER." + print -r -- >&2 "current highlighting of BUFFER, using the setup code PREAMBLE." exit 1 fi buffer=$1 ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh +preamble=${4:-""} # Load the main script. . ${0:A:h:h}/zsh-syntax-highlighting.zsh @@ -61,9 +62,14 @@ fi <$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" > $fname # Assumes stdout is line-buffered git add -- $fname +exec > >(tee -a $fname) + +# Preamble +if [[ -n $preamble ]]; then + print -rl -- "$preamble" "" +fi # Buffer -exec > >(tee -a $fname) print -n 'BUFFER=' if [[ $buffer != (#s)[$'\t -~']#(#e) ]]; then print -r -- ${(qqqq)buffer} @@ -82,8 +88,17 @@ print 'expected_region_highlight=(' PREBUFFER="" BUFFER="$buffer" region_highlight=() - # TODO: use run_test() from tests/test-highlighting.zsh (to get a tempdir) - _zsh_highlight + eval $( + exec 3>&1 >/dev/null + typeset -r __tests_tmpdir="$(mktemp -d)" + { + # Use a subshell to ensure $__tests_tmpdir, which is to be rm -rf'd, won't be modified. + (cd -- "$__tests_tmpdir" && eval $preamble && _zsh_highlight && typeset -p region_highlight >&3) + : # workaround zsh bug workers/45305 with respect to the $(…) subshell we're in + } always { + rm -rf -- ${__tests_tmpdir} + } + ) for ((i=1; i<=${#region_highlight}; i++)); do local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) From 9ed2a46ed2a59297d3811ca13dcea26e0884824e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jan 2020 23:47:45 +0000 Subject: [PATCH 116/297] dev tools: New script to ease opening $EDITOR on failing tests. Has room for improvement; for now, I use it with CTRL-W_f. --- tests/edit-failed-tests | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 tests/edit-failed-tests diff --git a/tests/edit-failed-tests b/tests/edit-failed-tests new file mode 100755 index 0000000..9112c2a --- /dev/null +++ b/tests/edit-failed-tests @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +type perl sponge >/dev/null || { print -ru2 -- "$0: This script requires perl(1) and sponge(1) [from moreutils]"; exit 1; } + +local editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) +() { + > "$2" perl -nE '$highlighter = $1 if /^Running test (\S*)/; say "highlighters/${highlighter}/test-data/$1.zsh" if /^# (\S*)/' "$1" + >>"$2" echo "" + >>"$2" cat <"$1" + "${editor[@]}" -- "$2" +} =(${MAKE:-make} quiet-test) =(:) +# TODO: tee(1) the quiet-test output to /dev/tty as it's happening, with colors. From dfb917020cd0c281bc6444dcc5b2b1bcef977b1a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jan 2020 14:07:23 +0000 Subject: [PATCH 117/297] Bump copyright years. --- COPYING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COPYING.md b/COPYING.md index 95db0c1..cacbcbe 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2019 zsh-syntax-highlighting contributors +Copyright (c) 2010-2020 zsh-syntax-highlighting contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted From 9bf06c5c2a2dd8e2afaa59f1d77acffeab48e98a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 20 Jan 2020 03:49:00 +0000 Subject: [PATCH 118/297] tests: Add a regression test for issue #676. --- highlighters/main/test-data/null-exec.zsh | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/null-exec.zsh diff --git a/highlighters/main/test-data/null-exec.zsh b/highlighters/main/test-data/null-exec.zsh new file mode 100644 index 0000000..ab73717 --- /dev/null +++ b/highlighters/main/test-data/null-exec.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'exec >/dev/null;' + +expected_region_highlight=( + '1 4 precommand' # exec + '6 6 redirection' # > + '7 15 path' # /dev/null + '16 16 commandseparator "issue #676"' # ; +) From e2e97dde9c92bf27d8222482a08e2b77d66ac334 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 22 Jan 2020 04:44:27 +0000 Subject: [PATCH 119/297] 'main': Support tabbed(1) from suckless-tools --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 038215d..0ae5a16 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -323,6 +323,8 @@ _zsh_highlight_highlighter_main_paint() 'setsid' :wc # As of OpenSSH 8.1p1; -k is deliberately left out since it may not be followed by a command 'ssh-agent' aEPt:csDd + # suckless-tools v44 + 'tabbed' gnprtTuU:cdfhsv ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From 27e4789439a7e95a2d40b6270070923a41730ffd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 23 Jan 2020 22:09:33 +0000 Subject: [PATCH 120/297] docs: Track FreeBSD port rename See https://svnweb.freebsd.org/ports?revision=501751&view=revision --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 1c2a523..23acdf5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -6,7 +6,7 @@ How to install * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] * Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] (or in [OBS repository][obs-repository]) * Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ (or in [OBS repository][obs-repository]) -* FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`textproc/zsh-syntax-highlighting`][freebsd-port]) +* FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] * Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) From 77c6bf2019366a8c4cabd5788f7e0da796cec533 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 24 Jan 2020 00:37:56 +0000 Subject: [PATCH 121/297] 'main': precommands: Remove argumentless options that can't be followed by a command word. Suggested-by: Matthew Martin (in https://github.com/zsh-users/zsh-syntax-highlighting/commit/e2e97dde9c92bf27d8222482a08e2b77d66ac334#r36941988) --- highlighters/main/main-highlighter.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0ae5a16..6af3f9d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -315,7 +315,8 @@ _zsh_highlight_highlighter_main_paint() 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags - 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 + # Argumentless flags that can't be followed by a command: -e -h -K -k -V -v + 'sudo' Cgprtu:AEHPSbilns # as of sudo 1.8.21p2 'stdbuf' ioe: 'eatmydata' '' 'catchsegv' '' @@ -324,7 +325,8 @@ _zsh_highlight_highlighter_main_paint() # As of OpenSSH 8.1p1; -k is deliberately left out since it may not be followed by a command 'ssh-agent' aEPt:csDd # suckless-tools v44 - 'tabbed' gnprtTuU:cdfhsv + # Argumentless flags that can't be followed by a command: -v + 'tabbed' gnprtTuU:cdfhs ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From deee22ed42cdc8d6f5d6dd413cc350d05978c94d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 24 Jan 2020 00:49:51 +0000 Subject: [PATCH 122/297] tests: Don't filter out tests that aborted. Useful in piping Travis CI output through tap-filter manually. --- tests/tap-filter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tap-filter b/tests/tap-filter index 6587808..feb22d2 100755 --- a/tests/tap-filter +++ b/tests/tap-filter @@ -40,6 +40,6 @@ use strict; undef $/; # slurp mode print for - grep { /^ok.*# TODO/m or /^not ok(?!.*# TODO)/m } + grep { /^ok.*# TODO/m or /^not ok(?!.*# TODO)/m or /^Bail out!/m } split /^(?=#)/m, ; From 9d380805d7efd5325c9080e550d0fe1cffaece0b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 24 Jan 2020 00:51:27 +0000 Subject: [PATCH 123/297] tests: Unbreak the build on zsh 5.0.8 and older. --- .../main/test-data/param-precommand-option-argument1.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/param-precommand-option-argument1.zsh b/highlighters/main/test-data/param-precommand-option-argument1.zsh index fb2ed71..58e51ef 100644 --- a/highlighters/main/test-data/param-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/param-precommand-option-argument1.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- # See also alias-precommand-option-argument1.zsh -local -a sudo_u=(sudo -u) +local -a sudo_u; sudo_u=(sudo -u) sudo(){} BUFFER='$sudo_u phy1729 echo foo' From 454675650047135eb8ce15ed725eb64d2d57db9c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 24 Jan 2020 01:22:03 +0000 Subject: [PATCH 124/297] tests: Fix another instance of issue from the last commit. --- .../main/test-data/param-precommand-option-argument3.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/param-precommand-option-argument3.zsh b/highlighters/main/test-data/param-precommand-option-argument3.zsh index 4bcfa8a..ea5035e 100644 --- a/highlighters/main/test-data/param-precommand-option-argument3.zsh +++ b/highlighters/main/test-data/param-precommand-option-argument3.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- # See also alias-precommand-option-argument3.zsh -local -a sudo_u=(sudo -u) +local -a sudo_u; sudo_u=(sudo -u) sudo(){} BUFFER='$sudo_u phy1729 ls foo' From b73853dd9680676555f24d057b4e9abcfb0f806d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 24 Jan 2020 18:40:51 +0000 Subject: [PATCH 125/297] changelog: Document #677 as a known issue. --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 43842ad..1d90e55 100644 --- a/changelog.md +++ b/changelog.md @@ -64,6 +64,14 @@ Selected bugfixes include: [#183] +Known issues include: + +- A multiline alias that uses a simple command terminator (such as `;`, `|`, `&&`) + before a newline will incorrectly be highlighted as an error. See issue #677 + for examples and workarounds. + [#677] + + # Changes in version 0.6.0 This is a stable release, featuring bugfixes and minor improvements. From 4e92449752de0de5f02988696e1a8317f19feae8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 25 Jan 2020 21:00:40 +0000 Subject: [PATCH 126/297] changelog: Document #670 as a known issue. --- changelog.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog.md b/changelog.md index 1d90e55..7a9fefa 100644 --- a/changelog.md +++ b/changelog.md @@ -71,6 +71,13 @@ Known issues include: for examples and workarounds. [#677] +- Use of a simple parameter expansion (`${foo}` with nothing but a parameter + name inside the braces) in command position, when the value of the parameter + looks like an assignment (such as after `foo='bar=$(ls)'`), may result in + incorrect highlighting and "BUG" messages. As a workaround, the expansion + may be nested (`${${foo}}`). + [#670] + # Changes in version 0.6.0 From 0e51046b19b4f01d57c7953c8053d707b51a54d1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 25 Jan 2020 12:32:11 -0600 Subject: [PATCH 127/297] main: Add tests for issue #678 --- .../main/test-data/precommand-killing1.zsh | 39 +++++++++++++++++++ .../main/test-data/precommand-killing2.zsh | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 highlighters/main/test-data/precommand-killing1.zsh create mode 100644 highlighters/main/test-data/precommand-killing2.zsh diff --git a/highlighters/main/test-data/precommand-killing1.zsh b/highlighters/main/test-data/precommand-killing1.zsh new file mode 100644 index 0000000..80d279b --- /dev/null +++ b/highlighters/main/test-data/precommand-killing1.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +hash sudo=false + +BUFFER='sudo -e /etc/passwd' + +expected_region_highlight=( + '1 4 precommand' # sudo + '6 7 single-hyphen-option' # -e + '9 19 path' # /etc/passwd +) diff --git a/highlighters/main/test-data/precommand-killing2.zsh b/highlighters/main/test-data/precommand-killing2.zsh new file mode 100644 index 0000000..2e332ae --- /dev/null +++ b/highlighters/main/test-data/precommand-killing2.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +hash sudo=false + +BUFFER='sudo -e /does/not/exist' + +expected_region_highlight=( + '1 4 precommand' # sudo + '6 7 single-hyphen-option' # -e + '9 23 normal "issue #678"' # /does/not/exist +) From dde84e1b25f059a298ce3189cddfd0778f998df3 Mon Sep 17 00:00:00 2001 From: Manaswini Das Date: Mon, 27 Jan 2020 17:04:26 +0530 Subject: [PATCH 128/297] docs: Fix typo Fixes #679 --- docs/highlighters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index f6eba7f..d0c9332 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -104,7 +104,7 @@ To create your own `acme` highlighter: `_zsh_highlight_highlighter_acme_paint` respectively. These names are still supported for backwards compatibility; - however, support for them will be removed in a a future major or minor release (v0.x.0 or v1.0.0). + however, support for them will be removed in a future major or minor release (v0.x.0 or v1.0.0). * Activate your highlighter in `~/.zshrc`: From 52ea5c686aab9b37d88347e64d0fc4d12443d5d4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Feb 2020 10:20:13 +0000 Subject: [PATCH 129/297] 'main': precommands += chronic, ifne (from moreutils) Fixes #681. --- highlighters/main/main-highlighter.zsh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6af3f9d..a4ff7a1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -327,7 +327,15 @@ _zsh_highlight_highlighter_main_paint() # suckless-tools v44 # Argumentless flags that can't be followed by a command: -v 'tabbed' gnprtTuU:cdfhs + + # moreutils 0.62-1 + 'chronic' :ev + 'ifne' :n + ) + # Commands that would need to skip one positional argument: + # flock + # ssh if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false From 1a55dc8fc28cf1049ba8ff33694d3e56678cad17 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 16 Jan 2020 17:39:12 +0000 Subject: [PATCH 130/297] 'main': Pass parameters through the multi-word machinery, as we already do for aliases. Fixes #674. --- highlighters/main/main-highlighter.zsh | 36 +++++++++++++++---- .../param-precommand-option-argument1.zsh | 2 +- .../param-precommand-option-argument3.zsh | 4 +-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a4ff7a1..7f5495e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -77,6 +77,16 @@ _zsh_highlight_main_add_region_highlight() { [[ $1 == unknown-token ]] && alias_style=unknown-token return fi + if (( in_param )); then + if [[ $1 == unknown-token ]]; then + param_style=unknown-token + fi + if [[ -n $param_style ]]; then + return + fi + param_style=$1 + return + fi # The calculation was relative to $buf but region_highlight is relative to $BUFFER. (( start += buf_offset )) @@ -406,11 +416,13 @@ _zsh_highlight_main_highlighter_highlight_list() # alias_style is the style to apply to an alias once in_alias=0 # Usually 'alias' but set to 'unknown-token' if any word expanded from # the alias would be highlighted as unknown-token - local alias_style arg buf=$4 highlight_glob=true style + # param_style is analogous for parameter expansions + local alias_style param_style arg buf=$4 highlight_glob=true style local in_array_assignment=false # true between 'a=(' and the matching ')' # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. - integer in_alias=0 len=$#buf + # in_param is analogous for parameter expansions + integer in_alias=0 in_param=0 len=$#buf local -a match mbegin mend list_highlights # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a local -A seen_alias @@ -489,6 +501,14 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style fi fi + if (( in_param )); then + (( in_param-- )) + if (( in_param == 0 )); then + # start_pos and end_pos are of the '$foo' word (previous $arg) here + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style + param_style="" + fi + fi # Initialize this_word and next_word. if (( in_redirection == 0 )); then @@ -513,7 +533,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi - if (( in_alias == 0 )); then + if (( in_alias == 0 && in_param == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. [[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]] # The first, outer parenthesis @@ -626,6 +646,7 @@ _zsh_highlight_main_highlighter_highlight_list() local -a match mbegin mend local MATCH; integer MBEGIN MEND local parameter_name + local -a words if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then parameter_name=${${arg:2}%?} elif [[ $arg[1] == '$' ]]; then @@ -638,14 +659,16 @@ _zsh_highlight_main_highlighter_highlight_list() # Set $arg. case ${(tP)MATCH} in (*array*|*assoc*) - local -a words; words=( ${(P)MATCH} ) - arg=${words[1]} + words=( ${(P)MATCH} ) ;; (*) # scalar, presumably - arg=${(P)MATCH} + words=( ${(P)MATCH} ) ;; esac + (( in_param = 1 + $#words )) + args=( $words $args ) + arg=$args[1] _zsh_highlight_main__type "$arg" 0 res=$REPLY fi @@ -946,6 +969,7 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style done (( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style + (( in_param == 1 )) && in_param=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $param_style [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] REPLY=$(( end_pos + ${#match[1]} - 1 )) reply=($list_highlights) diff --git a/highlighters/main/test-data/param-precommand-option-argument1.zsh b/highlighters/main/test-data/param-precommand-option-argument1.zsh index 58e51ef..84cf03a 100644 --- a/highlighters/main/test-data/param-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/param-precommand-option-argument1.zsh @@ -36,7 +36,7 @@ BUFFER='$sudo_u phy1729 echo foo' expected_region_highlight=( '1 7 precommand' # $sudo_u - '9 15 default "issue #674"' # phy1729 + '9 15 default' # phy1729 '18 20 command "issue #540"' # echo (not builtin) '22 24 default' # foo ) diff --git a/highlighters/main/test-data/param-precommand-option-argument3.zsh b/highlighters/main/test-data/param-precommand-option-argument3.zsh index ea5035e..9a8dde2 100644 --- a/highlighters/main/test-data/param-precommand-option-argument3.zsh +++ b/highlighters/main/test-data/param-precommand-option-argument3.zsh @@ -36,7 +36,7 @@ BUFFER='$sudo_u phy1729 ls foo' expected_region_highlight=( '1 7 precommand' # sudo_u - '9 15 default "issue #674"' # phy1729 - '17 18 command "issue #674"' # ls + '9 15 default' # phy1729 + '17 18 command' # ls '20 22 default' # foo ) From 35583061497dd54321e58cbdb2380aa41229ba26 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 16 Jan 2020 19:02:39 +0000 Subject: [PATCH 131/297] tests: Add tests for issue #670. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before the parent commit, they behaved as follows: ZSH_PATCHLEVEL=debian/5.7.1-1 # parameter-value-contains-command-position1 1..2 ok 1 - [1,7] «$foobar» - # TODO "issue #670" not ok 2 - have 1 expectations and 6 region_highlight entries: «expected_region_highlight=( '1 7 assign "issue ♯670"' )» «region_highlight=( '0 7 assign' '2 7 default' '2 7 command-substitution-unquoted' zsh-syntax-highlighting: BUG: _zsh_highlight_highlighter_main_paint: start(2) >= end(2) Bail out! On './highlighters/main/test-data/parameter-value-contains-command-position2.zsh': output on stderr # parameter-value-contains-command-position2 1..2 ok 1 - [1,2] «$y» - # TODO "issue #670" ok 2 - cardinality check Due to the the "BUG:" and "Bail out!" on the first one, they could not be added as XFAIL tests before the parent commit. --- ...meter-value-contains-command-position1.zsh | 38 +++++++++++++++++++ ...meter-value-contains-command-position2.zsh | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 highlighters/main/test-data/parameter-value-contains-command-position1.zsh create mode 100644 highlighters/main/test-data/parameter-value-contains-command-position2.zsh diff --git a/highlighters/main/test-data/parameter-value-contains-command-position1.zsh b/highlighters/main/test-data/parameter-value-contains-command-position1.zsh new file mode 100644 index 0000000..b4a8a55 --- /dev/null +++ b/highlighters/main/test-data/parameter-value-contains-command-position1.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +local foobar='x=$(ls)' + +BUFFER=$'$foobar' + +expected_region_highlight=( + # Used to highlight the "ba" as 'command' because the 'ls' showed through; issues #670 and #674 + '1 7 assign' # $foobar +) diff --git a/highlighters/main/test-data/parameter-value-contains-command-position2.zsh b/highlighters/main/test-data/parameter-value-contains-command-position2.zsh new file mode 100644 index 0000000..eca36d4 --- /dev/null +++ b/highlighters/main/test-data/parameter-value-contains-command-position2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +local y='x=$(ls)' + +BUFFER=$'$y' + +expected_region_highlight=( + # Used to trigger a "BUG" message on stderr - issues #670 and #674 + '1 2 assign' # $y +) From 2f4f81cab7033c4e5c40c8e434dd700accafe24b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 20 Feb 2020 11:37:23 +0000 Subject: [PATCH 132/297] 'main': Parameter expansions may not contain assignments. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In «a="b=c"; $a», the '=' sign in the expansion of $a is not active. Therefore, prevent the expansion of $a from being considered an assignment. Update test expectations accordingly. --- highlighters/main/main-highlighter.zsh | 2 +- .../test-data/parameter-value-contains-command-position1.zsh | 2 +- .../test-data/parameter-value-contains-command-position2.zsh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7f5495e..64b3ad7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -840,7 +840,7 @@ _zsh_highlight_main_highlighter_highlight_list() function) style=function;; command) style=command;; hashed) style=hashed-command;; - none) if _zsh_highlight_main_highlighter_check_assign; then + none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign local i=$(( arg[(i)=] + 1 )) if [[ $arg[i] == '(' ]]; then diff --git a/highlighters/main/test-data/parameter-value-contains-command-position1.zsh b/highlighters/main/test-data/parameter-value-contains-command-position1.zsh index b4a8a55..05ea1bf 100644 --- a/highlighters/main/test-data/parameter-value-contains-command-position1.zsh +++ b/highlighters/main/test-data/parameter-value-contains-command-position1.zsh @@ -34,5 +34,5 @@ BUFFER=$'$foobar' expected_region_highlight=( # Used to highlight the "ba" as 'command' because the 'ls' showed through; issues #670 and #674 - '1 7 assign' # $foobar + '1 7 unknown-token' # $foobar (not an assignment) ) diff --git a/highlighters/main/test-data/parameter-value-contains-command-position2.zsh b/highlighters/main/test-data/parameter-value-contains-command-position2.zsh index eca36d4..5042e89 100644 --- a/highlighters/main/test-data/parameter-value-contains-command-position2.zsh +++ b/highlighters/main/test-data/parameter-value-contains-command-position2.zsh @@ -34,5 +34,5 @@ BUFFER=$'$y' expected_region_highlight=( # Used to trigger a "BUG" message on stderr - issues #670 and #674 - '1 2 assign' # $y + '1 2 unknown-token' # $y (not an assignment) ) From f490b7cb950b1999785fcd7b82ef5a3e968b3802 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 21 Feb 2020 10:17:55 +0000 Subject: [PATCH 133/297] 'main': Add two tests for metacharacters in parameter expansions. Suggested-by: @QBobWatson (in https://github.com/zsh-users/zsh-syntax-highlighting/pull/682#issuecomment-588361771) --- .../parameter-expansion-untokenized1.zsh | 38 +++++++++++++++++++ .../parameter-expansion-untokenized2.zsh | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 highlighters/main/test-data/parameter-expansion-untokenized1.zsh create mode 100644 highlighters/main/test-data/parameter-expansion-untokenized2.zsh diff --git a/highlighters/main/test-data/parameter-expansion-untokenized1.zsh b/highlighters/main/test-data/parameter-expansion-untokenized1.zsh new file mode 100644 index 0000000..f3c9a5e --- /dev/null +++ b/highlighters/main/test-data/parameter-expansion-untokenized1.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +local x="()" + +BUFFER=$'$x ls' + +expected_region_highlight=( + '1 2 unknown-token "fixed in the next commit"' # $x + '4 5 command' # ls +) diff --git a/highlighters/main/test-data/parameter-expansion-untokenized2.zsh b/highlighters/main/test-data/parameter-expansion-untokenized2.zsh new file mode 100644 index 0000000..6389171 --- /dev/null +++ b/highlighters/main/test-data/parameter-expansion-untokenized2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +local x="^foo^bar" + +BUFFER=$'$x ls' + +expected_region_highlight=( + '1 2 unknown-token "fixed in the next commit"' # $x + '4 5 default' # ls +) From f72972630080e358cf584b0ff56bcd7485d9a584 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 21 Feb 2020 10:19:51 +0000 Subject: [PATCH 134/297] 'main': Do not look for metacharacters in parameter expansions. Fixes the bug the previous commit added a test for. --- highlighters/main/main-highlighter.zsh | 18 ++++++++++++------ .../parameter-expansion-untokenized1.zsh | 2 +- .../parameter-expansion-untokenized2.zsh | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 64b3ad7..25dfa8a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -861,11 +861,14 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi continue - elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then + elif (( ! in_param )) && + [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion - elif [[ $arg[0,1] == $histchars[2,2] ]]; then + elif (( ! in_param )) && + [[ $arg[0,1] == $histchars[2,2] ]]; then style=history-expansion - elif [[ $arg[1,2] == '((' ]]; then + elif (( ! in_param )) && + [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...} @@ -880,14 +883,17 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos reserved-word fi continue - elif [[ $arg == '()' ]]; then + elif (( ! in_param )) && + [[ $arg == '()' ]]; then # anonymous function style=reserved-word - elif [[ $arg == $'\x28' ]]; then + elif (( ! in_param )) && + [[ $arg == $'\x28' ]]; then # subshell style=reserved-word braces_stack='R'"$braces_stack" - elif [[ $arg == $'\x29' ]]; then + elif (( ! in_param )) && + [[ $arg == $'\x29' ]]; then # end of subshell or command substitution if _zsh_highlight_main__stack_pop 'S'; then REPLY=$start_pos diff --git a/highlighters/main/test-data/parameter-expansion-untokenized1.zsh b/highlighters/main/test-data/parameter-expansion-untokenized1.zsh index f3c9a5e..8b8b5e4 100644 --- a/highlighters/main/test-data/parameter-expansion-untokenized1.zsh +++ b/highlighters/main/test-data/parameter-expansion-untokenized1.zsh @@ -33,6 +33,6 @@ local x="()" BUFFER=$'$x ls' expected_region_highlight=( - '1 2 unknown-token "fixed in the next commit"' # $x + '1 2 unknown-token' # $x '4 5 command' # ls ) diff --git a/highlighters/main/test-data/parameter-expansion-untokenized2.zsh b/highlighters/main/test-data/parameter-expansion-untokenized2.zsh index 6389171..d23a1f2 100644 --- a/highlighters/main/test-data/parameter-expansion-untokenized2.zsh +++ b/highlighters/main/test-data/parameter-expansion-untokenized2.zsh @@ -33,6 +33,6 @@ local x="^foo^bar" BUFFER=$'$x ls' expected_region_highlight=( - '1 2 unknown-token "fixed in the next commit"' # $x + '1 2 unknown-token' # $x '4 5 default' # ls ) From dc70e89bfdbed86a0a4c8b2a24416107b948e261 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Feb 2020 14:29:55 +0000 Subject: [PATCH 135/297] tests: Support non-arrays in typeset_p(). --- tests/test-highlighting.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b2a6db5..f335293 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -93,9 +93,13 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # In zsh<5.3, 'typeset -p arrayvar' emits two lines, so we use this wrapper instead. typeset_p() { - for 1 ; do - print -r -- "$1=( ${(@q-P)1} )" - done + for 1 ; do + if [[ ${(tP)1} == *array* ]]; then + print -r -- "$1=( ${(@q-P)1} )" + else + print -r -- "$1=${(q-P)1}" + fi + done } # Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output From 4a043b4d155ab68ca63e73dce04263257cb227f3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Feb 2020 14:31:18 +0000 Subject: [PATCH 136/297] noop: Whitespace changes only. ./.editorconfig is already set correctly. --- tests/test-highlighting.zsh | 2 +- zsh-syntax-highlighting.zsh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index f335293..91534ef 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -206,7 +206,7 @@ run_test() { local ret=$pipestatus[1] stderr=$pipestatus[2] if (( ! stderr )); then # stdout will become stderr - echo "Bail out! On ${(qq)1}: output on stderr"; return 1 + echo "Bail out! On ${(qq)1}: output on stderr"; return 1 else return $ret fi diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 5c6b478..fd2a7c6 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -161,12 +161,12 @@ _zsh_highlight() (( REGION_ACTIVE )) || return integer min max if (( MARK > CURSOR )) ; then - min=$CURSOR max=$MARK + min=$CURSOR max=$MARK else - min=$MARK max=$CURSOR + min=$MARK max=$CURSOR fi if (( REGION_ACTIVE == 1 )); then - [[ $KEYMAP = vicmd ]] && (( max++ )) + [[ $KEYMAP = vicmd ]] && (( max++ )) elif (( REGION_ACTIVE == 2 )); then local needle=$'\n' # CURSOR and MARK are 0 indexed between letters like region_highlight From 3414c7c0d29963075b99a6946efb0e2304ad881b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Feb 2020 14:33:39 +0000 Subject: [PATCH 137/297] test harness: Include $PREBUFFER and $BUFFER in the output. For human readers' benefit. --- tests/test-highlighting.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 91534ef..6583d2d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -117,12 +117,15 @@ run_test_internal() { local srcdir="$PWD" builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! On ${(qq)1}: cd failed: $?"; return 1 } - echo "# ${1:t:r}" - # Load the data and prepare checking it. local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0 local expected_mismatch local -a expected_region_highlight region_highlight + + echo "# ${1:t:r}" + [[ -n $PREBUFFER ]] && printf '# %s\n' "$(typeset_p PREBUFFER)" + [[ -n $BUFFER ]] && printf '# %s\n' "$(typeset_p BUFFER)" + . "$srcdir"/"$1" (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } From 2b3638a211cca4790c5b3b4f607edc0b0b2b6c73 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Feb 2020 14:37:14 +0000 Subject: [PATCH 138/297] test harness: Tweak quiet-test output - Print the test name and data after the plan line - Split on the plan line rather than on comments + That makes tap-filter more suitable to filter TAP output generated by other TAP producers. + However, the filtered output deletes the plan line and adds a blank line in its stead. This suits our use-case of interactive test runs. --- tests/tap-filter | 4 +++- tests/test-highlighting.zsh | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/tap-filter b/tests/tap-filter index feb22d2..f9aa604 100755 --- a/tests/tap-filter +++ b/tests/tap-filter @@ -41,5 +41,7 @@ use strict; undef $/; # slurp mode print for grep { /^ok.*# TODO/m or /^not ok(?!.*# TODO)/m or /^Bail out!/m } - split /^(?=#)/m, + # Split on plan lines and remove them from the output. (To keep them, + # use the lookahead syntax, «(?=…)», to make the match zero-length.) + split /^\d+\.\.\d+$/m, ; diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6583d2d..ab5f2d5 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -122,10 +122,6 @@ run_test_internal() { local expected_mismatch local -a expected_region_highlight region_highlight - echo "# ${1:t:r}" - [[ -n $PREBUFFER ]] && printf '# %s\n' "$(typeset_p PREBUFFER)" - [[ -n $BUFFER ]] && printf '# %s\n' "$(typeset_p BUFFER)" - . "$srcdir"/"$1" (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } @@ -146,7 +142,12 @@ run_test_internal() { expected_region_highlight=("${(@n)expected_region_highlight}") fi + # Print the plan line, and some comments for human readers echo "1..$(( $#expected_region_highlight + 1))" + echo "## ${1:t:r}" + [[ -n $PREBUFFER ]] && printf '# %s\n' "$(typeset_p PREBUFFER)" + [[ -n $BUFFER ]] && printf '# %s\n' "$(typeset_p BUFFER)" + local i for ((i=1; i<=$#expected_region_highlight; i++)); do local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} ) From ab88dfad272bcc4ae2e65d25d1d59c3ab240906e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 25 Feb 2020 07:21:40 -0600 Subject: [PATCH 139/297] tests: Add main test for alias of a parameter like string --- .../main/test-data/alias-parameter.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/alias-parameter.zsh diff --git a/highlighters/main/test-data/alias-parameter.zsh b/highlighters/main/test-data/alias-parameter.zsh new file mode 100644 index 0000000..6119c3d --- /dev/null +++ b/highlighters/main/test-data/alias-parameter.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +alias '$foo'='echo alias' +foo=(echo param) + +BUFFER='$foo' + +expected_region_highlight=( + '1 4 alias' # $foo +) From 7fd44bc429aaa33e4bafc35a6e942b8d2fdba642 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 25 Feb 2020 07:30:05 -0600 Subject: [PATCH 140/297] tests: Fix previous --- highlighters/main/test-data/alias-parameter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias-parameter.zsh b/highlighters/main/test-data/alias-parameter.zsh index 6119c3d..21bc6b3 100644 --- a/highlighters/main/test-data/alias-parameter.zsh +++ b/highlighters/main/test-data/alias-parameter.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- alias '$foo'='echo alias' -foo=(echo param) +local foo; foo=(echo param) BUFFER='$foo' From 73c89c69a2cae7eeb9562319b52b390706286c44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 25 Feb 2020 17:22:55 +0000 Subject: [PATCH 141/297] tests: Add a test for partial elisions of parameter expansions in command position See https://github.com/zsh-users/zsh-syntax-highlighting/commit/1a55dc8fc28cf1049ba8ff33694d3e56678cad17#commitcomment-37476021 --- .../main/test-data/cmdpos-elision-partial.zsh | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 highlighters/main/test-data/cmdpos-elision-partial.zsh diff --git a/highlighters/main/test-data/cmdpos-elision-partial.zsh b/highlighters/main/test-data/cmdpos-elision-partial.zsh new file mode 100644 index 0000000..f5a2740 --- /dev/null +++ b/highlighters/main/test-data/cmdpos-elision-partial.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +# Test elision of some, but not all of the words +# See issue #667 for the case of eliding all words +local -a x; x=(sudo "") + +BUFFER=$'$x -u phy1729 ls' + +expected_region_highlight=( + '1 2 precommand' # $x + # The "" is elided. If it weren't elided, the «ls» would be highlighted as an ordinary argument. + '4 5 single-hyphen-option' # -u + '7 13 default' # phy1729 + '15 16 command' # ls +) From 3cea1434aeaf1b8ed08542d47fe53e25678b4f47 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 25 Feb 2020 17:34:35 +0000 Subject: [PATCH 142/297] Bump copyright years. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 25dfa8a..9a48222 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2019 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2020 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From e07c901dfd5f0f1282cb027ea015c7b96aa576ed Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 15:22:43 +0000 Subject: [PATCH 143/297] tests: Fix the last added test to pass when sudo(8) isn't installed. --- highlighters/main/test-data/cmdpos-elision-partial.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/cmdpos-elision-partial.zsh b/highlighters/main/test-data/cmdpos-elision-partial.zsh index f5a2740..6eda0d7 100644 --- a/highlighters/main/test-data/cmdpos-elision-partial.zsh +++ b/highlighters/main/test-data/cmdpos-elision-partial.zsh @@ -32,6 +32,7 @@ # See issue #667 for the case of eliding all words local -a x; x=(sudo "") +sudo(){} BUFFER=$'$x -u phy1729 ls' expected_region_highlight=( From d65f4f8a351a86355920ad095768d3ce3c44efa0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 15:36:25 +0000 Subject: [PATCH 144/297] release.md: Add details about a step. --- release.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release.md b/release.md index 4b6adf2..943eb58 100644 --- a/release.md +++ b/release.md @@ -5,6 +5,7 @@ - Check open issues and outstanding pull requests - Confirm `make test` passes - check with multiple zsh versions + (easiest to check travis: https://travis-ci.org/zsh-users/zsh-syntax-highlighting/) - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; From 36a3c0f82c23934fbfa924c79453266c4edda5fd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 15:36:43 +0000 Subject: [PATCH 145/297] Tag version 0.7.0. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index a1bbfb9..faef31a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.0-beta2-dev +0.7.0 From 4eb8a19133c4f346af35436cf38a27d43fb458e7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 146/297] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index faef31a..c0ab427 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.0 +0.7.1-dev From 04dd78cb00a0dc98586ceace7f5dd0dd0f437d49 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 21:29:59 +0000 Subject: [PATCH 147/297] Update changelog for the 0.7.0 release. (Yes, this should have been committed earlier today.) --- changelog.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/changelog.md b/changelog.md index 7a9fefa..f83f32f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,5 @@ # Changes in version 0.7.0 -**Version 0.7.0 has not been released. This changelog is a work in progress.** - This is a stable bugfix and feature release. Major new features and changes include: - Add `ZSH_HIGHLIGHT_DIRS_BLACKLIST` to disable "path" and "path prefix" @@ -71,13 +69,6 @@ Known issues include: for examples and workarounds. [#677] -- Use of a simple parameter expansion (`${foo}` with nothing but a parameter - name inside the braces) in command position, when the value of the parameter - looks like an assignment (such as after `foo='bar=$(ls)'`), may result in - incorrect highlighting and "BUG" messages. As a workaround, the expansion - may be nested (`${${foo}}`). - [#670] - # Changes in version 0.6.0 From cb8d68d00a951968fe8e0d35bcac47e7ea7b7867 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 21:30:39 +0000 Subject: [PATCH 148/297] Update changelog for the 0.7.1 release. --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index f83f32f..9779223 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# Changes in version 0.7.1 + +- Remove out-of-date information from the 0.7.0 changelog. + # Changes in version 0.7.0 This is a stable bugfix and feature release. Major new features and changes include: From ec04a20681e584a698e9c0dee32a8f29f53b6684 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 21:33:51 +0000 Subject: [PATCH 149/297] release.md: Update with the step that was missed in 0.7.0. --- release.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/release.md b/release.md index 943eb58..8df4b9c 100644 --- a/release.md +++ b/release.md @@ -8,7 +8,8 @@ (easiest to check travis: https://travis-ci.org/zsh-users/zsh-syntax-highlighting/) - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` -- Remove `-dev` suffix from `./.version`; +- Make sure there are no local commits and that `git status` is clean; + Remove `-dev` suffix from `./.version`; Commit that using `git commit -m "Tag version $(<.version)." .version`; Tag it using `git tag -s -m "Tag version $(<.version)" $(<.version)`; Increment `./.version` and restore the `-dev` suffix; From 932e29a0c75411cb618f02995b66c0a4a25699bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 21:34:10 +0000 Subject: [PATCH 150/297] Tag version 0.7.1. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index c0ab427..39e898a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.1-dev +0.7.1 From 619fcad067c134382319e68be5f11deb51cc1ef6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 151/297] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 39e898a..c7d2522 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.1 +0.7.2-dev From 027f5223007cc233266a8c79c9ed9525fea2c1f9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 22:31:36 +0000 Subject: [PATCH 152/297] test harness: Honour $expected_mismatch when there are more expected than observed highlights. Required for the next commit. --- tests/test-highlighting.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index ab5f2d5..be95b51 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -155,7 +155,8 @@ run_test_internal() { local todo= (( $+expected_highlight_zone[4] )) && todo="# TODO $expected_highlight_zone[4]" if ! (( $+region_highlight[i] )); then - print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" + print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \ + "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" continue fi local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} ) From 9880276756971e4519045965ae3a1080c39d0609 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 22:22:27 +0000 Subject: [PATCH 153/297] 'main': Fix the currently-failing test for issue #577. It is fixed in the next commit. --- highlighters/main/test-data/noglob-always.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/highlighters/main/test-data/noglob-always.zsh b/highlighters/main/test-data/noglob-always.zsh index 481722f..f59e562 100644 --- a/highlighters/main/test-data/noglob-always.zsh +++ b/highlighters/main/test-data/noglob-always.zsh @@ -39,6 +39,9 @@ expected_region_highlight=( '19 24 reserved-word' # always '26 26 reserved-word' # { '28 31 builtin' # echo + '33 33 default' # * '33 33 globbing "issue #577"' # * '35 35 reserved-word' # } ) + +expected_mismatch="expected default+globbing, observed default" From edfc7dfd9baf1b38dcb8dad931a958669c34250d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 22:22:35 +0000 Subject: [PATCH 154/297] 'main': Fix issue #577. --- highlighters/main/main-highlighter.zsh | 3 ++- highlighters/main/test-data/noglob-always.zsh | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9a48222..590be77 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -744,7 +744,8 @@ _zsh_highlight_main_highlighter_highlight_list() elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then # try-always construct style=reserved-word # de facto a reserved word, although not de jure - next_word=':start:' # only left brace is allowed, apparently + highlight_glob=true + next_word=':start::start_of_pipeline:' # only left brace is allowed, apparently elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then style=precommand diff --git a/highlighters/main/test-data/noglob-always.zsh b/highlighters/main/test-data/noglob-always.zsh index f59e562..6d55048 100644 --- a/highlighters/main/test-data/noglob-always.zsh +++ b/highlighters/main/test-data/noglob-always.zsh @@ -40,8 +40,6 @@ expected_region_highlight=( '26 26 reserved-word' # { '28 31 builtin' # echo '33 33 default' # * - '33 33 globbing "issue #577"' # * + '33 33 globbing' # * '35 35 reserved-word' # } ) - -expected_mismatch="expected default+globbing, observed default" From 8e3578240cf6d6bbe7d904475ae6d46acc520fdd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Feb 2020 22:26:49 +0000 Subject: [PATCH 155/297] tests harness docs: Add paragraph breaks. --- tests/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/README.md b/tests/README.md index 89aef14..9f9d894 100644 --- a/tests/README.md +++ b/tests/README.md @@ -7,6 +7,9 @@ The tests harness expects the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. +Tests should set the following variables: + +1. Each test should define the string `$BUFFER` that is to be highlighted and the array parameter `$expected_region_highlight`. The value of that parameter is a list of strings of the form `"$i $j $style"`. @@ -16,11 +19,16 @@ that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. `$style` is a key of `$ZSH_HIGHLIGHT_STYLES`. If `$todo` exists, the test point is marked as TODO (the failure of that test point will not fail the test), and `$todo` is used as the explanation. + +2. If a test sets `$skip_test` to a non-empty string, the test will be skipped with the provided string as the reason. + +3. If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight` need not match the order in `$region_highlight`. +4. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` have different numbers of elements. Tests may set `$expected_mismatch` to an explanation string (like `$todo`) to avoid this and mark the cardinality check From 1a752da1c2f58bd96e1e09a83f53556060674f3f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jan 2020 20:46:46 +0000 Subject: [PATCH 156/297] Highlight redirections by default, and add that to the examples in README. Fixes #646. --- README.md | 5 +++++ highlighters/main/main-highlighter.zsh | 2 +- images/after4-smaller.png | Bin 0 -> 3224 bytes images/before4-smaller.png | Bin 0 -> 2987 bytes 4 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 images/after4-smaller.png create mode 100644 images/before4-smaller.png diff --git a/README.md b/README.md index 08af2b6..4951dba 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,11 @@ Before: [![Screenshot #3.1](images/before3-smaller.png)](images/before3.png)
After:  [![Screenshot #3.2](images/after3-smaller.png)](images/after3.png) +Before: [![Screenshot #4.1](images/before4-smaller.png)](images/before4-smaller.png) +
+After:  [![Screenshot #4.2](images/after4-smaller.png)](images/after4-smaller.png) + + How to install -------------- diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 590be77..d01c129 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -56,7 +56,7 @@ : ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} -: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} +: ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} : ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none} : ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green} diff --git a/images/after4-smaller.png b/images/after4-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..fc946cf038822083111f753f7bdb814ba8a22304 GIT binary patch literal 3224 zcmV;J3}^F+P)mIs-@(M5Rka5H*4g5RE28Q4=*jjRX}FYmDe4wwG9lAt9(>d0>eOb`urB z5*3LN3!u_F3?otn6a-}6k6|dnWd=ix-wW&CJ!j9_d#`iOy?fs~KredHi(d4i7rp33 zFWP|orPLDu{l7ayy6CirxH;*u-+I426(=1J(HiOFH_eju#)WuoP{!kztoqQrhax80 z?g2N_aV64x63vz77~YK*_S(kRUod zwFlGvYy9?9oU}X)^VPR|g(Oj-F!f5ox~8*MY@% zUcJuldRR=k2}v| zPsJ&h=S|-Y-VQJUFj-7VQ&UrI?F$x%Z?R~-+YNuG#Co|ufmH08p`oV53Agenu%kXc-*LX z`jp9><>Ma)+25@P0H*dpJFUv3%z7h-VV1n2_}Bz-b3kkz3tRQF#Pn)St6@(4nfZU* zxF@QWC8cZQ=wQkg-~at?eofoWrKD|cH`q*2_9#9vr?R07zuk+lA{*xe zUjl)^QXm*u46tNH(R3gHSOJ6s@3i3w1pEMhAh->WJPj;|%4}0vGfcgEP zAwL1Bu!2mqe#XGc>ClFlEEyp&p;efINrc+FJm!&aWo5G7wear9Jdc1g;C*#nhm z{dPA_%GmdE*`a2|{Hc?>_s13I1dmao_e*pp z1t;bwo(|cu|Kh#aGZ)kHca3FtJ70R;=$Ef^eTatJ_PaR`q7H`cK72JpbbHGfb<%}B z%OxnM=-9^1(TO+D9KV)RnX+qww$xt9cHzkf4=?WC_TApgnFTQ`Wb48mv@9y~(Zzk+ z147T-%g;Qw)SlNaE{ZGQGx^Sei8uYM<+dCYun8C;yBrIA4G@3;-oR2c*X(Ryy6hP2 z1pEOG0KgOQ2ME9dwgT=l9#3F1=|vdMX5?gVO7ZLdMCCf#Uhn z>qeIltv*D>#7svzO7-!+P!hAyfTFi&xdi1klwDeG%LBl$@QbgGS)fM%hQ-R*tcZ`A zZ()Y>&lO$vHKqWtMhE8=hPp|Yf}!vJ(O6+8Ez-*CNkO9(xJBs!`+z_eZ)UlcK2t3?Q+{pp43-&dN+wu!(iqCDq^ku2%9c%B_JirbEWH99z7wA-y^ zf2(*!l->W@h5^+X$II{eTQd~&+ub+;sJy>ll)S}}1rV)|kEb8_KouamJ{QH|6FFcy zY<`&f-7pq7lMj|$TVhPn@UVt&PfOY6B-5WW`9OJ_W1x7x^t#cYYkde?y|1-{)9_Kg zkp;ESI3%vV)VG17eTgD^6HHhzZ7kRkxnTZJ#wo3a`Zn(#n7SKnVcRopK=e zS;5tvE4&=_xore(d3F&UuMP8xx9w{D{LJ0tgbV)}C!}8{0niAT00V#lfHn{fGy!~o z0aVlcs-+xlsngVenl_j9z%xMJ_LVf?kq8$O@lzqD_HTW75H>~*!gr&f^#p4!<65;G z9)ar;Z{ESc)1|G|p#+fB*Eh%p>cmAAd{sfS4vi`IAGEJ{Il6t+%Zp1|T9I0DQH8p; zCPk^~2wA1YrA>bP#*sPS8JzLhU{K9+u040i|y0Ql(bf9v(tXEC3PoqsMXf5oY`?W$ z6y%lYTU)7-`=t^9M8(8ZLmVq=YAVUjd2ThrQFYJRN{K>#yBjA^cQgD*^|?v9g z(O1^)OjA--t}ZEk{^W5vSD;LLoJ)WdV3w?&5dxM{oq#A{w(LupCNQbXH*gt19`F&s z04Tre#k6F9l$rlf<8EZ1MBZAb_M{B!=l9le);}T-m7cH zw4AZPO@{$6b=^0v9h1EO@I%@cPYt(1f|8uqeDj_@6JY4LtzR`XZcjwkOFWMb3@-X0 zAZV5ap8y;~_hl>I>qF7`Xdpb1b9ouum!GGHnBMty?Ox(R(bSVHV%jJi{d>n-w0QIH0d1ZB#6;-Vd zN8$7%Nr$Hi3BWL$f9k=#-)<+K|H8V<_wZ`KS3n4`6$onc=7$N)1bzng0O7#<(k~P3 zKcCskdIJEOz&aol*afTuH03O(z7aM}Lii-?^TZ}QNDDWL+1z_83ZgmfsOa_@t5=Fm zqBZY)^}T&tjz22M&U#$)^kMiX=F+;8GG21M>g;T_4oob=37fAJR)|tl^2-XYZuT&c zQL_6^-g>35wzi_Utfn&cmh6Ah_25?ao9w*v^NNFYV8f^d3ZLT9ZjpQDG`fvV>bBynDiukBB$H= z((6W#&h-(F5BTHB)4cc_@#(2oLw@=-H)Y#UCcS<8&u47ckb=aGc1!@EbjSSrY(`1p z!}zGU(} zquenf!d5pjX){6Rm#e9zOab6%Xsa*)u++5GSoHQSU??f`SY6)0DT*TUc!-i#A8p<% zlikUeMmMUD=eA>~UO~ia=hnXaReb<}a5Rki8EbGl3$`=+uD}%N8SATdXw@0Yx_ym> z{I)dz%#VhhgJ{nEHD_Lot;-L&O@E&4p94DGcqUFG2B@|_O)ra+t|o}(7IAMH%s)@@ ze*?*j%qtNWQ=Ywz{~~#tL8sgEoLezDe|K=b=tVDj(TiRvivIx)y5Gev0C-*i0000< KMNUMnLSTZgCmW#v literal 0 HcmV?d00001 diff --git a/images/before4-smaller.png b/images/before4-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..2dbd0588b767e802d3ff640de6319e5fdca4de24 GIT binary patch literal 2987 zcmV;c3sm%pP)=B#=M?2_%p}0tr3> z`s+etTJt=1e4|VHyGz6=TxqhknF{%{&pTQ?@!}xGS#F+A6F$=}@x$o)3MtumC*_wE z{dw7W3;_VK9WNxFnJ+(j^MYjIQ&Qz;H408c(i4{*3rS4ROp6cLX{A0I0+5UkWL5=# zJBsE0HF-yiCvF^q?yl6*^K(D_dNA@*M$K0k072(pKbgln=-P(q?sqpONty53Z~QnQ zp^^J{S2-L=euj%>Pt3lRj&A2)&kv0BoJ0Zun%$Am!!Cw$*hnHWZMV1*uAGkf#N~>c zceHp4jq|BjgUAzLQ*sNQMR^^K zRkO9yCIEE)dFvr_ef0D6t2^iGNQqaz_NuM(Uih5P=mG#BDvh74r%Wcv=}fn?|JqoE z`e7VdS#Po~i-ghG26GpGWBrvHO$7e9ItiA*l8%MDsFp2~Z8Rfiuu8lUwf`o^P@=G~0d{J>~^!4z^#Z}R(RFDAv z{B^*|D=tq=%l%$M;s%ZWF3CEDmWMjYBDPz6YgziuOa6)FwJCQZBmA$V)Rg$nrQ+vB z$_st7%Cn;U&RvOnnj9UMU;e8lS?qf8braA&zWN|}>ysHJ&ttD%@DF}aP?dIUZr@}V z*H?J{q#13AEqobw`K0%S=%?j{w|_JlY&eX@kRnQ%pU!&XsW0@6o1nKnxhQmLpG7p* z+^)Xou7v?0rj1`=S;%*qya+V?^*^tl$fH~Kz9Dg|Asqk+dYBgA=>) zOELfe&CoNsK5e%FQAl!3&HhkG?4M<2cRdV;`-nbv-nRdy7U#xno+NZCAl9-7PUbueXvE30sugsu5Y&la8C&B^;r82|uCUPnhk0Dn9kaPo@F6Ohu1 z$htpv>GCcx76!b!xm*z;wp)Db{f+7v$;|szL&P#gL|qcxaNk`W!;2$r^=nbiX>*>6 zj5$89x~l!Y?w$a@@NA!f5O*M%@v|2%+k7(iRYCYl?V*F|ItzXZ ze_omquu|v&0#ScYdUdF?;s+s+()V}Ue&4RsACuu2+E{XC7Kvwzx5YlQX@dgb^2gHw zC$G3X0YGNam8zU$Q%C?v@w*$Zf)>jHAhuf^CvZLmh^9wh$qdo0?6Z?H*Q&q1O>#;K7(kBzS8!YN zA4cUrjJlE9l^*Od{rZnd?|H1`jKACCeZZM<@5s6-OMkEJ2Ekxhd90;hb&0AUD3S}n z?dp2pf8iacx=D)3=u@jZ_u2DzgCgMZ$6E1q;G0)mo&c?J0THJHU1uN6C|AxkBS08CgbWWk>(--nP~@F7bmmM6VY(f^-`WjEScYMaTI>;88njQEp{R z`y0wQDpraK8qeQXc>V<7zP`Eot3rnjo7Nn>d&s}`me+DupNux{z%-!G+__67U|G8D zxy{*Yr|z`6b8Vx6nO8PnFZH~xszKGUM|WHu(#pExlD89QOp(19(=1AlJ1ffS)buAZ z(X)Ck03aFdvGSbcs$LOp1%R%~@;XH;bt=Gnvg)jL2Tpj}bl%+WWE_;y&?EeAOmq2` zg$2G-(>e!<%Ee@uGX4FdtEn?NIaLEH_YAHIkAJTK9r))JmnXoxCxO@7ZhyZds%$mo znoG*Nk;LicRMx6Z&}E>kCN2O_6clB!mXF#jYP~{q8wNamFpbsceU0x}8Xd`Q2LQ79 z*_;c4#^V9kp8yE;HfDt#UK4iMUBmX5-@>o$PBHLI?*`rjlQ4e6&vWkYIiF9Jm2Ru6 ze_Q*yk;cG1xalnmznEmY_qc;51pt7eZR2Rc#sJ`L{Au6n#oj*4^`sC0MZ;#xwgsyA zd!_fOem>deyALl=BLWbVt-W?kO}Q9aB*4TpqfMvw%uyx*5LIkEHyETPq`m=QI-k9~ zsQK(X1B=Z8BFzB+is{B5#{G8cTG`NE5hu8;w^k+q5ZN{d_sq??68r-9v4YDVUk849 z=@VV{daX8LQgrM+4{V&NL{zuhdSI)SIzbRmc%K<`wZ!gJpi7y5V4l#L`Nrvf8FszM z+H;>JivT2+`M*7Eqy)aG3F?)F9hECfK%SrhsE>BF?FJDc?dZ80(S+@E3!>MCEP zXXKR^Bpk8r|B^)>WB<$j%8rhvnuhk~yoepQE7RL#gPv-3nyv+vo2KaI42J1rd+uG|m zoYI5??q{=W1Lsr3t`}c7eDK$YHP8Ex+Lp5Pr1V#L5B&aft2FocRN_c{#owO<1=F>D zPpaBmD)S3!+8Z*1)*9lTOd^_+y0Vl=pQ4Bi6)iQ{;aed@mebT$l@|3R1fwf|p(FZm zM3Gn5P^69IV_APfw#5${EQjq;k;3ZRtw}$Q!4OS(>{!;I3<$$;6XNn8ssmnLnu4M< z1^^U!B^d$$keEtL68`uPAW)_0B!LS6hG9rp97I)ART{dEh*K|)ZkXzl Date: Wed, 11 Mar 2020 16:52:08 +0000 Subject: [PATCH 157/297] 'main': Add a test for issue #687, concerning the SH_WORD_SPLIT option. --- .../main/test-data/opt-shwordsplit1.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/opt-shwordsplit1.zsh diff --git a/highlighters/main/test-data/opt-shwordsplit1.zsh b/highlighters/main/test-data/opt-shwordsplit1.zsh new file mode 100644 index 0000000..0b5bd60 --- /dev/null +++ b/highlighters/main/test-data/opt-shwordsplit1.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +setopt shwordsplit +EDITOR='ed -s' + +ed() { command ed "$@" } + +BUFFER=$'$EDITOR' + +expected_region_highlight=( + '1 7 function "issue #687"' # $EDITOR +) From 41d90cb5ed7cae3978b314a7277eaf5a65acf205 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 12 Mar 2020 20:48:46 -0500 Subject: [PATCH 158/297] make test: Run tests under env -i This makes the tests more reproducable. In particular it avoids hiding a WARN_CREATE_GLOBAL error when the dev happens to have defined that variable in the environment (cf. next commit). --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6cc2648..42081ed 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ test: for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ - $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ + env -i QUIET=$$QUIET $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ done; \ From b85e313bc9fdf992bde28d4dd4ebb39748df744b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 12 Mar 2020 20:51:19 -0500 Subject: [PATCH 159/297] main: Declare variable local to fix WARN_CREATE_GLOBAL error --- highlighters/main/test-data/opt-shwordsplit1.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/opt-shwordsplit1.zsh b/highlighters/main/test-data/opt-shwordsplit1.zsh index 0b5bd60..7455785 100644 --- a/highlighters/main/test-data/opt-shwordsplit1.zsh +++ b/highlighters/main/test-data/opt-shwordsplit1.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- setopt shwordsplit -EDITOR='ed -s' +local EDITOR='ed -s' ed() { command ed "$@" } From b00be5f741e2b4f01abd0258a4b1ed662a4d158d Mon Sep 17 00:00:00 2001 From: Austin Traver Date: Fri, 13 Mar 2020 01:16:40 -0700 Subject: [PATCH 160/297] driver: Be resilient to KSH_ARRAYS being set in the calling scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The «emulate» call isn't sufficient, since these lines are parsed before it takes effect. Fixes #689 (née #622). See also #688 for preventing these gymnastics from being needed in the first place. See also https://github.com/junegunn/fzf/pull/1924 for an inter-plugin interaction that this probably fixes. --- zsh-syntax-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index fd2a7c6..ff75108 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -86,12 +86,12 @@ _zsh_highlight() # Before we 'emulate -L', save the user's options local -A zsyh_user_options if zmodload -e zsh/parameter; then - zsyh_user_options=("${(@kv)options}") + zsyh_user_options=("${(kv)options[@]}") else local canonical_options onoff option raw_options raw_options=(${(f)"$(emulate -R zsh; set -o)"}) canonical_options=(${${${(M)raw_options:#*off}%% *}#no} ${${(M)raw_options:#*on}%% *}) - for option in $canonical_options; do + for option in "${canonical_options[@]}"; do [[ -o $option ]] # This variable cannot be eliminated c.f. workers/42101. onoff=${${=:-off on}[2-$?]} From a3c1757e479fdb96ddfdd09a258b33638f3d5474 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 13 Mar 2020 23:13:01 +0000 Subject: [PATCH 161/297] changelog: Update through HEAD. --- changelog.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/changelog.md b/changelog.md index 9779223..48f59a5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,14 @@ +# Changes in HEAD + +- Redirection operators (e.g., `<` and `>`) are now highlighted by default + [#646] + +- Propertly terminate `noglob` scope in try/always blocks + [#577] + +- Don't error out when `KSH_ARRAYS` is set in the calling scope + [#622, #689] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From 37b6f5052f5c45f525e4d46f70be6fb8a1052dc1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 13:33:09 +0000 Subject: [PATCH 162/297] test harness: Update tests/edit-failed-tests for harness output changes in commit 2b3638a211cca4790c5b3b4f607edc0b0b2b6c73, "test harness: Tweak quiet-test output". --- tests/edit-failed-tests | 2 +- tests/test-highlighting.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/edit-failed-tests b/tests/edit-failed-tests index 9112c2a..e3a7668 100755 --- a/tests/edit-failed-tests +++ b/tests/edit-failed-tests @@ -32,7 +32,7 @@ type perl sponge >/dev/null || { print -ru2 -- "$0: This script requires perl(1) local editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" ) () { - > "$2" perl -nE '$highlighter = $1 if /^Running test (\S*)/; say "highlighters/${highlighter}/test-data/$1.zsh" if /^# (\S*)/' "$1" + > "$2" perl -nE '$highlighter = $1 if /^Running test (\S*)/; say "highlighters/${highlighter}/test-data/$1.zsh" if /^## (\S*)/' "$1" >>"$2" echo "" >>"$2" cat <"$1" "${editor[@]}" -- "$2" diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index be95b51..c75c844 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -144,7 +144,7 @@ run_test_internal() { # Print the plan line, and some comments for human readers echo "1..$(( $#expected_region_highlight + 1))" - echo "## ${1:t:r}" + echo "## ${1:t:r}" # note: tests/edit-failed-tests looks for the "##" emitted by this line [[ -n $PREBUFFER ]] && printf '# %s\n' "$(typeset_p PREBUFFER)" [[ -n $BUFFER ]] && printf '# %s\n' "$(typeset_p BUFFER)" From e58e45273fb54396e2f66a038c1b43d2b4dd9ab4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 13:56:15 +0000 Subject: [PATCH 163/297] tests: Add some tests for unusual or invalid elements in array assignments: - pipes (issue #651) - semicolons - literal newlines (also discussed on #651) --- highlighters/main/test-data/array-cmdsep1.zsh | 39 +++++++++++++++++++ highlighters/main/test-data/array-cmdsep2.zsh | 39 +++++++++++++++++++ highlighters/main/test-data/array-cmdsep3.zsh | 39 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 highlighters/main/test-data/array-cmdsep1.zsh create mode 100644 highlighters/main/test-data/array-cmdsep2.zsh create mode 100644 highlighters/main/test-data/array-cmdsep3.zsh diff --git a/highlighters/main/test-data/array-cmdsep1.zsh b/highlighters/main/test-data/array-cmdsep1.zsh new file mode 100644 index 0000000..38ff6d9 --- /dev/null +++ b/highlighters/main/test-data/array-cmdsep1.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'a=( foo | bar )' + +expected_region_highlight=( + '1 3 assign' # a=( + '5 7 default' # foo + '9 9 unknown-token "issue #651"' # | + '11 13 unknown-token' # bar + '15 15 unknown-token' # ) +) diff --git a/highlighters/main/test-data/array-cmdsep2.zsh b/highlighters/main/test-data/array-cmdsep2.zsh new file mode 100644 index 0000000..8b4a2eb --- /dev/null +++ b/highlighters/main/test-data/array-cmdsep2.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'a=( foo ; bar )' + +expected_region_highlight=( + '1 3 assign' # a=( + '5 7 default' # foo + '9 9 unknown-token "fixed in the after-next (grandchild) commit"' # ; + '11 13 default' # bar + '15 15 assign' # ) +) diff --git a/highlighters/main/test-data/array-cmdsep3.zsh b/highlighters/main/test-data/array-cmdsep3.zsh new file mode 100644 index 0000000..def01b0 --- /dev/null +++ b/highlighters/main/test-data/array-cmdsep3.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'a=( foo \n bar )' + +expected_region_highlight=( + '1 3 assign' # a=( + '5 7 default' # foo + '9 9 commandseparator' # \n + '11 13 default' # bar + '15 15 assign' # ) +) From a4525a0826a3e1b0fc3def19a0a4a527c7045f3d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:17:51 +0000 Subject: [PATCH 164/297] 'main': Add infrastructure for treating literal newlines differently to semicolons. Used by the next commit. --- highlighters/main/main-highlighter.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d01c129..7b9fbd3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -359,6 +359,7 @@ _zsh_highlight_highlighter_main_paint() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' + $'\n' # ${(z)} returns ';' but we convert it to $'\n' '|&' '&!' '&|' # ### 'case' syntax, but followed by a pattern, not by a command @@ -535,12 +536,17 @@ _zsh_highlight_main_highlighter_highlight_list() if (( in_alias == 0 && in_param == 0 )); then # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. - [[ "$proc_buf" = (#b)(#s)(([ $'\t']|\\$'\n')#)* ]] + [[ "$proc_buf" = (#b)(#s)(([ $'\t']|[\\]$'\n')#)(?|)* ]] # The first, outer parenthesis integer offset="${#match[1]}" (( start_pos = end_pos + offset )) (( end_pos = start_pos + $#arg )) + # The zsh lexer considers ';' and newline to be the same token, so + # ${(z)} converts all newlines to semicolons. Convert them back here to + # make later processing simplier. + [[ $arg == ';' && ${match[3]} == $'\n' ]] && arg=$'\n' + # Compute the new $proc_buf. We advance it # (chop off characters from the beginning) # beyond what end_pos points to, by skipping @@ -731,7 +737,7 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi - if [[ $arg == ';' ]] && $in_array_assignment; then + if [[ $arg == (';'|$'\n') ]] && $in_array_assignment; then # literal newline inside an array assignment next_word=':regular:' else From 3ca93f864fb61b32db74f1249b3a8e47806b6ed8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:19:23 +0000 Subject: [PATCH 165/297] 'main': Highlight literal semicolons in array assignments as errors. Fixes the test added in the penultimate (grandparent) commit. --- highlighters/main/main-highlighter.zsh | 10 +++++++++- highlighters/main/test-data/array-cmdsep2.zsh | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7b9fbd3..04b6ece 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -737,9 +737,17 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi - if [[ $arg == (';'|$'\n') ]] && $in_array_assignment; then + if [[ $arg == $'\n' ]] && $in_array_assignment; then # literal newline inside an array assignment next_word=':regular:' + elif [[ $arg == ';' ]] && $in_array_assignment; then + # literal semicolon inside an array assignment + # + # This is parsed the same way as a literal newline. Nevertheless, + # highlight it as an error since it's probably unintended. Compare + # issue #691. + next_word=':regular:' + style=unknown-token else next_word=':start:' highlight_glob=true diff --git a/highlighters/main/test-data/array-cmdsep2.zsh b/highlighters/main/test-data/array-cmdsep2.zsh index 8b4a2eb..2d2c865 100644 --- a/highlighters/main/test-data/array-cmdsep2.zsh +++ b/highlighters/main/test-data/array-cmdsep2.zsh @@ -33,7 +33,7 @@ BUFFER=$'a=( foo ; bar )' expected_region_highlight=( '1 3 assign' # a=( '5 7 default' # foo - '9 9 unknown-token "fixed in the after-next (grandchild) commit"' # ; + '9 9 unknown-token' # ; (not commandseparator; see highlighter source code) '11 13 default' # bar '15 15 assign' # ) ) From bfd44f5c3f82c92bc309c80776a58f40f0a05438 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:22:05 +0000 Subject: [PATCH 166/297] noop: Add comments. --- highlighters/main/main-highlighter.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 04b6ece..3986e56 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -727,6 +727,8 @@ _zsh_highlight_main_highlighter_highlight_list() # The Great Fork: is this a command word? Is this a non-command word? if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + + # First, determine the style of the command separator itself. if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then # Missing closing square bracket(s) style=unknown-token @@ -737,6 +739,8 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi + + # Second, determine the style of next_word. if [[ $arg == $'\n' ]] && $in_array_assignment; then # literal newline inside an array assignment next_word=':regular:' @@ -755,6 +759,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':start_of_pipeline:' fi fi + elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then # try-always construct style=reserved-word # de facto a reserved word, although not de jure From 81267ca3130c420f65164730f0585630ac5bbe40 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:25:49 +0000 Subject: [PATCH 167/297] 'main': Highlight pipes inside array assignments as errors Fixes #651. --- highlighters/main/main-highlighter.zsh | 16 +++++++++++----- highlighters/main/test-data/array-cmdsep1.zsh | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 3986e56..1402669 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -732,6 +732,17 @@ _zsh_highlight_main_highlighter_highlight_list() if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then # Missing closing square bracket(s) style=unknown-token + elif $in_array_assignment; then + case $arg in + # Literal newlines are just fine. + ($'\n') style=commandseparator;; + # Semicolons are parsed the same way as literal newlines. Nevertheless, + # highlight them as errors since they're probably unintended. Compare + # issue #691. + (';') style=unknown-token;; + # Other command separators aren't allowed. + (*) style=unknown-token;; + esac elif [[ $this_word == *':regular:'* ]]; then # This highlights empty commands (semicolon follows nothing) as an error. # Zsh accepts them, though. @@ -746,12 +757,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':regular:' elif [[ $arg == ';' ]] && $in_array_assignment; then # literal semicolon inside an array assignment - # - # This is parsed the same way as a literal newline. Nevertheless, - # highlight it as an error since it's probably unintended. Compare - # issue #691. next_word=':regular:' - style=unknown-token else next_word=':start:' highlight_glob=true diff --git a/highlighters/main/test-data/array-cmdsep1.zsh b/highlighters/main/test-data/array-cmdsep1.zsh index 38ff6d9..3ffe43d 100644 --- a/highlighters/main/test-data/array-cmdsep1.zsh +++ b/highlighters/main/test-data/array-cmdsep1.zsh @@ -33,7 +33,7 @@ BUFFER=$'a=( foo | bar )' expected_region_highlight=( '1 3 assign' # a=( '5 7 default' # foo - '9 9 unknown-token "issue #651"' # | + '9 9 unknown-token' # | '11 13 unknown-token' # bar '15 15 unknown-token' # ) ) From 498cc7641f360bc84b9ae92630b0609ae1976ee2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:34:25 +0000 Subject: [PATCH 168/297] tests: Extend and document the after-a-parse-error aspects of the issue #651 test. --- highlighters/main/test-data/array-cmdsep1.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/array-cmdsep1.zsh b/highlighters/main/test-data/array-cmdsep1.zsh index 3ffe43d..790c030 100644 --- a/highlighters/main/test-data/array-cmdsep1.zsh +++ b/highlighters/main/test-data/array-cmdsep1.zsh @@ -29,11 +29,16 @@ # ------------------------------------------------------------------------------------------------- BUFFER=$'a=( foo | bar )' +bar(){} expected_region_highlight=( '1 3 assign' # a=( '5 7 default' # foo '9 9 unknown-token' # | - '11 13 unknown-token' # bar + # zsh reports a parse error at this point. Nevertheless, we test how we + # highlight the remainder of $BUFFER. Currently we recover by treating the pipe + # as a command separator. That's not the only reasonable behaviour, though; if + # we change the behaviour, we should adjust the following expectations accordingly. + '11 13 function' # bar '15 15 unknown-token' # ) ) From c5878ae632b141470215f7190793889e8ce356ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:37:04 +0000 Subject: [PATCH 169/297] changelog: Update through HEAD. --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 48f59a5..ead1b45 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,14 @@ - Don't error out when `KSH_ARRAYS` is set in the calling scope [#622, #689] +- Literal semicolons in array assignments (`foo=( bar ; baz )`) are now + highlighted as errors. + [3ca93f864fb6] + +- Command separators in array assignments (`foo=( bar | baz )`) are now + highlighted as errors. + [#651, 81267ca3130c] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From 54e1828d5c515730f3d9fb026a8bf9e8eb2cc970 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:56:43 +0000 Subject: [PATCH 170/297] 'main': Clarify documentation of the :sudo_opt: and :sudo_arg: states. --- highlighters/main/main-highlighter.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1402669..66ebff5 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -453,6 +453,9 @@ _zsh_highlight_main_highlighter_highlight_list() # - :sudo_arg: The argument to a precommand's leading-dash option, # when given as a separate word; i.e., "foo" in "-u foo" (two # words) but not in "-ufoo" (one word). + # Note: :sudo_opt: and :sudo_arg: are used for any precommand + # declared in ${precommand_options}, not just for sudo(8). + # The naming is historical. # - :regular: "Not a command word", and command delimiters are permitted. # Mainly used to detect premature termination of commands. # - :always: The word 'always' in the «{ foo } always { bar }» syntax. From f996d839751329677b7f85081185317d5a748e6d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 15:06:50 +0000 Subject: [PATCH 171/297] tests: Add cross-references. --- highlighters/main/test-data/alias-comment1.zsh | 2 +- highlighters/main/test-data/comment-followed.zsh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index dd5068f..7810c4a 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -# see alias-comment2.zsh +# see alias-comment2.zsh and comment-followed.zsh setopt interactivecomments alias x=$'# foo\npwd' BUFFER='x' diff --git a/highlighters/main/test-data/comment-followed.zsh b/highlighters/main/test-data/comment-followed.zsh index 8c7e42c..6f5a4f5 100644 --- a/highlighters/main/test-data/comment-followed.zsh +++ b/highlighters/main/test-data/comment-followed.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +# see alias-comment1.zsh setopt interactivecomments BUFFER=$'# foo\ntrue' From e94dc89606a8931ae4231d586eaa31a2daadac94 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 15:35:27 +0000 Subject: [PATCH 172/297] tests: Distinguish issues #616 and #677. See https://github.com/zsh-users/zsh-syntax-highlighting/issues/677#issuecomment-599225740 for details. (In particular, there's already another test that calls itself #616.) --- highlighters/main/test-data/alias-comment1.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index 7810c4a..8618575 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -33,5 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias "issue #616"' # x + '1 1 alias "issue #677"' # x ) From 9134cdf8d6a87500ccd5b01df0bd46e22d6744c3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 14:59:07 +0000 Subject: [PATCH 173/297] 'main': Allow newlines in command position. Fixes #501. Fixes #616 (the original form; not the form in test-data/alias-comment1.zsh which is now considered o be #677 (see previous commit for details)). Fixes a latent bug in test-data/always2.zsh. No user-visible effect, and therefore, no changelog entry. --- highlighters/main/main-highlighter.zsh | 6 ++++-- highlighters/main/test-data/always2.zsh | 2 +- highlighters/main/test-data/comment-followed.zsh | 2 +- highlighters/main/test-data/empty-command-newline.zsh | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 66ebff5..6f09f09 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -747,10 +747,12 @@ _zsh_highlight_main_highlighter_highlight_list() (*) style=unknown-token;; esac elif [[ $this_word == *':regular:'* ]]; then - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. + style=commandseparator + elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then style=commandseparator else + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. style=unknown-token fi diff --git a/highlighters/main/test-data/always2.zsh b/highlighters/main/test-data/always2.zsh index f5852c6..991137c 100644 --- a/highlighters/main/test-data/always2.zsh +++ b/highlighters/main/test-data/always2.zsh @@ -32,7 +32,7 @@ BUFFER=$'{\nls\n} always { pwd }' expected_region_highlight=( '1 1 reserved-word' # { - '2 2 unknown-token' # \n + '2 2 commandseparator' # \n '3 4 command' # ls '5 5 commandseparator' # \n '6 6 reserved-word' # } diff --git a/highlighters/main/test-data/comment-followed.zsh b/highlighters/main/test-data/comment-followed.zsh index 6f5a4f5..044f283 100644 --- a/highlighters/main/test-data/comment-followed.zsh +++ b/highlighters/main/test-data/comment-followed.zsh @@ -34,6 +34,6 @@ BUFFER=$'# foo\ntrue' expected_region_highlight=( '1 5 comment' # # foo - '6 6 commandseparator "issue #501"' # \n + '6 6 commandseparator' # \n '7 10 builtin' # true ) diff --git a/highlighters/main/test-data/empty-command-newline.zsh b/highlighters/main/test-data/empty-command-newline.zsh index 783f4b6..4b7b35c 100644 --- a/highlighters/main/test-data/empty-command-newline.zsh +++ b/highlighters/main/test-data/empty-command-newline.zsh @@ -34,6 +34,6 @@ BUFFER=$':;\n:' expected_region_highlight=( '1 1 builtin' # : '2 2 commandseparator' # ; - '3 3 commandseparator "issue #616"' # \n + '3 3 commandseparator' # \n '4 4 builtin' # : ) From 525ba909327b71584d160cf648548270dd516192 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 16:06:35 +0000 Subject: [PATCH 174/297] tests: Add an XFail test for issue #694. --- .../main/test-data/fd-target-not-filename.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/fd-target-not-filename.zsh diff --git a/highlighters/main/test-data/fd-target-not-filename.zsh b/highlighters/main/test-data/fd-target-not-filename.zsh new file mode 100644 index 0000000..15de3db --- /dev/null +++ b/highlighters/main/test-data/fd-target-not-filename.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +touch 2 + +BUFFER=$'echo foo>&2' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 8 default' # foo + '9 10 redirection' # >& + '11 11 file-descriptor "issue #694"' # 2 (not path) +) From 9931990b92a276c6ec69cdf6af9f9f3b65603cd1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 17:07:27 +0000 Subject: [PATCH 175/297] tests: Fix the test for alias loops. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the command word was highlighted as "unknown-token" not because alias loops are invalid, as a comment incorrectly claimed, but because the command word «a» resolved to a «b» that was ineligible for being expanded as an alias, and there was no function/builtin/etc. called "b". Add a function "b" to demonstrate that alias loops are valid. I've also filed issue #695 about the overloading of "unknown-token". --- highlighters/main/test-data/alias-loop.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias-loop.zsh b/highlighters/main/test-data/alias-loop.zsh index baa122b..83992db 100644 --- a/highlighters/main/test-data/alias-loop.zsh +++ b/highlighters/main/test-data/alias-loop.zsh @@ -28,12 +28,16 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +function b() {} # beware of ALIAS_FUNC_DEF alias a=b b=c c=b BUFFER='a foo; :' expected_region_highlight=( - '1 1 unknown-token' # a (invalid alias loop) + # An alias is ineligible for expansion whilst it's being expanded. + # Therefore, the "b" in the expansion of the alias "c" is not considered + # as an alias. + '1 1 alias' # a '3 5 default' # foo '6 6 commandseparator' # ; '8 8 builtin' # : From 8072651b6c37f8eed2ca9c5b95934f551aeb4dda Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 18:10:03 +0000 Subject: [PATCH 176/297] editorconfig += Makefile --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index 0f7ae82..1d2e96e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,8 @@ end_of_line = lf tab_width = 2 indent_size = 2 indent_style = space + +[Makefile] +tab_width = 8 +indent_style = tab + From f564d11a4192cff97d92f0e64a2c9c093c3c7338 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 18:10:18 +0000 Subject: [PATCH 177/297] make test: Re-enable syntax highlighting of TAP output in interactive runs Fixes #692. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 42081ed..bbc1d43 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ test: for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ - env -i QUIET=$$QUIET $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ + env -i QUIET=$$QUIET $${TERM:+"TERM=$$TERM"} $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ done; \ From fdf682a2f92fc593d0447ddbb85d560e5dc4c202 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 18:14:39 +0000 Subject: [PATCH 178/297] 'main': Expand comment. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6f09f09..36a46f4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -665,7 +665,7 @@ _zsh_highlight_main_highlighter_highlight_list() [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then - # Set $arg. + # Set $arg and update $res. case ${(tP)MATCH} in (*array*|*assoc*) words=( ${(P)MATCH} ) From 8feb06a0222ef7f710a3404a58de22c83494867b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 18:57:57 +0000 Subject: [PATCH 179/297] 'main': Support parameter elision in command position. --- highlighters/main/main-highlighter.zsh | 26 ++++++++++---- .../parameter-elision-command-word.zsh | 36 +++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 highlighters/main/test-data/parameter-elision-command-word.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 36a46f4..114fd41 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -656,6 +656,7 @@ _zsh_highlight_main_highlighter_highlight_list() local MATCH; integer MBEGIN MEND local parameter_name local -a words + integer elision_is_happening if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then parameter_name=${${arg:2}%?} elif [[ $arg[1] == '$' ]]; then @@ -663,23 +664,36 @@ _zsh_highlight_main_highlighter_highlight_list() fi if [[ $res == none ]] && zmodload -e zsh/parameter && [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && - (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] + [[ ${parameters[(e)$MATCH]} != *special* ]] then # Set $arg and update $res. case ${(tP)MATCH} in (*array*|*assoc*) words=( ${(P)MATCH} ) + elision_is_happening=$(( $#words == 0 )) + ;; + ("") + # not set + words=( ) + elision_is_happening=1 ;; (*) # scalar, presumably words=( ${(P)MATCH} ) + elision_is_happening=$(( $#words == 0 )) ;; esac - (( in_param = 1 + $#words )) - args=( $words $args ) - arg=$args[1] - _zsh_highlight_main__type "$arg" 0 - res=$REPLY + if (( elision_is_happening )); then + (( ++in_redirection )) + _zsh_highlight_main_add_region_highlight $start_pos $end_pos comment + continue + else + (( in_param = 1 + $#words )) + args=( $words $args ) + arg=$args[1] + _zsh_highlight_main__type "$arg" 0 + res=$REPLY + fi fi } diff --git a/highlighters/main/test-data/parameter-elision-command-word.zsh b/highlighters/main/test-data/parameter-elision-command-word.zsh new file mode 100644 index 0000000..25f649a --- /dev/null +++ b/highlighters/main/test-data/parameter-elision-command-word.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='$x ls' + +expected_region_highlight=( + '1 2 comment' # $x + '4 5 command' # ls +) From 74c7ffc9b53d395d04bdbf737cb420065ac35bfe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:04:57 +0000 Subject: [PATCH 180/297] 'main': Factor out common logic to after the case/esac. --- highlighters/main/main-highlighter.zsh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 114fd41..a2802cc 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -656,7 +656,6 @@ _zsh_highlight_main_highlighter_highlight_list() local MATCH; integer MBEGIN MEND local parameter_name local -a words - integer elision_is_happening if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then parameter_name=${${arg:2}%?} elif [[ $arg[1] == '$' ]]; then @@ -670,20 +669,18 @@ _zsh_highlight_main_highlighter_highlight_list() case ${(tP)MATCH} in (*array*|*assoc*) words=( ${(P)MATCH} ) - elision_is_happening=$(( $#words == 0 )) ;; ("") # not set words=( ) - elision_is_happening=1 ;; (*) # scalar, presumably words=( ${(P)MATCH} ) - elision_is_happening=$(( $#words == 0 )) ;; esac - if (( elision_is_happening )); then + if (( $#words == 0 )); then + # Parameter elision is happening (( ++in_redirection )) _zsh_highlight_main_add_region_highlight $start_pos $end_pos comment continue From 9e036e0b0c3f8017613e3ce81f7d7441043b5585 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 25 Feb 2020 17:37:46 +0000 Subject: [PATCH 181/297] 'main': Document the second meaning of the 'comment' style. --- docs/highlighters/main.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 43f6082..1566fa4 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -58,6 +58,7 @@ This highlighter defines the following styles: * `assign` - parameter assignments (`x=foo` and `x=( )`) * `redirection` - redirection operators (`<`, `>`, etc) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `comment` - elided parameters in command position (`$x ls` when `$x` is unset or empty) * `named-fd` - named file descriptor (`echo foo {fd}>&2`) * `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command). * `default` - everything else From 2331072c065d5aa94ac0dccc278946779b11cd1b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 18:29:10 +0000 Subject: [PATCH 182/297] changelog: Update through HEAD. --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index ead1b45..08887ea 100644 --- a/changelog.md +++ b/changelog.md @@ -17,6 +17,9 @@ highlighted as errors. [#651, 81267ca3130c] +- Support parameter elision in command position (e.g., `$foo ls` where `$foo` is unset or empty) + [#667] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From 8f7e9b2af445ae22bc17918b5e93142799c0a861 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 19:55:42 +0000 Subject: [PATCH 183/297] tests: Add a test for uninstalled precommands. --- .../main/test-data/precommand-uninstalled.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/precommand-uninstalled.zsh diff --git a/highlighters/main/test-data/precommand-uninstalled.zsh b/highlighters/main/test-data/precommand-uninstalled.zsh new file mode 100644 index 0000000..e249304 --- /dev/null +++ b/highlighters/main/test-data/precommand-uninstalled.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +unhash sudo +local PATH + +BUFFER=$'sudo ls' + +expected_region_highlight=( + '1 4 unknown-token' # sudo + '6 7 default' # ls - not 'command', since sudo isn't installed +) From 6243c99f41fb50fd4f9ee2e739f4084e24487555 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 18:57:28 +0000 Subject: [PATCH 184/297] tests: Fixup last commit. --- highlighters/main/test-data/precommand-uninstalled.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/precommand-uninstalled.zsh b/highlighters/main/test-data/precommand-uninstalled.zsh index e249304..03c8a75 100644 --- a/highlighters/main/test-data/precommand-uninstalled.zsh +++ b/highlighters/main/test-data/precommand-uninstalled.zsh @@ -28,7 +28,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -unhash sudo +# Simulate sudo not being installed. +# +# The 'hash' step is because, if sudo _really_ isn't installed, 'unhash sudo' +# would error out and break the test. +hash sudo=/usr/bin/env && unhash sudo + local PATH BUFFER=$'sudo ls' From 241d3a92e89d34ae934b09d3eff19e5a3a12d99d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:04:12 +0000 Subject: [PATCH 185/297] tests: Fix an XFail test expectation. Before this commit, the test was unable to XPass, since there is no highlighting style called "normal". --- highlighters/main/test-data/precommand-killing2.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/precommand-killing2.zsh b/highlighters/main/test-data/precommand-killing2.zsh index 2e332ae..71591f1 100644 --- a/highlighters/main/test-data/precommand-killing2.zsh +++ b/highlighters/main/test-data/precommand-killing2.zsh @@ -35,5 +35,5 @@ BUFFER='sudo -e /does/not/exist' expected_region_highlight=( '1 4 precommand' # sudo '6 7 single-hyphen-option' # -e - '9 23 normal "issue #678"' # /does/not/exist + '9 23 default "issue #678"' # /does/not/exist ) From 4bbd2a3bc6f8e70f2d88dfa197ae8a7d6b32f319 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:07:52 +0000 Subject: [PATCH 186/297] 'main': Prepare to add additional fields to $precommand_options values. No functional change. --- highlighters/main/main-highlighter.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a2802cc..0a899d8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -790,8 +790,11 @@ _zsh_highlight_main_highlighter_highlight_list() elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then style=precommand - flags_with_argument=${precommand_options[$arg]%:*} - flags_sans_argument=${precommand_options[$arg]#*:} + () { + set -- "${(@s.:.)precommand_options[$arg]}" + flags_with_argument=$1 + flags_sans_argument=$2 + } next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' From 63bcd85dfaf5d4139f9edce69293807a1a3ee43e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:13:12 +0000 Subject: [PATCH 187/297] =?UTF-8?q?'main':=20Don't=20use=20=C2=ABfoo=20&&?= =?UTF-8?q?=20bar=20||=20baz=C2=BB=20where=20a=20trenary=20is=20more=20app?= =?UTF-8?q?ropriate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents the baz pattern match from being attempted whenever the bar pattern match was tried and failed. --- highlighters/main/main-highlighter.zsh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0a899d8..0b40b08 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -698,14 +698,24 @@ _zsh_highlight_main_highlighter_highlight_list() if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then if [[ -n $flags_with_argument ]] && - { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]] || - [[ $arg == '-'[$flags_with_argument] ]] }; then + { + # Trenary + if [[ -n $flags_sans_argument ]] + then [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]] + else [[ $arg == '-'[$flags_with_argument] ]] + fi + } then # Flag that requires an argument this_word=${this_word//:start:/} next_word=':sudo_arg:' elif [[ -n $flags_with_argument ]] && - { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]] || - [[ $arg == '-'[$flags_with_argument]* ]] }; then + { + # Trenary + if [[ -n $flags_sans_argument ]] + then [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]] + else [[ $arg == '-'[$flags_with_argument]* ]] + fi + } then # Argument attached in the same word this_word=${this_word//:start:/} next_word+=':start:' From c73153c6e848eae00918ba27da51fb2d862278a2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:20:31 +0000 Subject: [PATCH 188/297] 'main': Add infrastructure for precommand options that are not to be followed by a command word (issue #678). --- highlighters/main/main-highlighter.zsh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0b40b08..ac34f23 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -306,9 +306,13 @@ _zsh_highlight_highlighter_main_paint() # $flags_sans_argument is a set of letters, corresponding to the option letters # that wouldn't be followed by a colon in a getopts specification. local flags_sans_argument - # $precommand_options maps precommand name to values of $flags_with_argument and - # $flags_sans_argument for that precommand, joined by a colon. (The value is NOT - # a getopt(3) spec, although it resembles one.) + # $flags_solo is a set of letters, corresponding to option letters that, if + # present, mean the precommand will now be acting as a precommand, i.e., will + # not be followed by a :start: word. + local flags_solo + # $precommand_options maps precommand name to values of $flags_with_argument, + # $flags_sans_argument, and flags_solo for that precommand, joined by a + # colon. (The value is NOT a getopt(3) spec, although it resembles one.) # # Currently, setting $flags_sans_argument is only important for commands that # have a non-empty $flags_with_argument; see test-data/precommand4.zsh. @@ -726,6 +730,17 @@ _zsh_highlight_main_highlighter_highlight_list() this_word=':sudo_opt:' next_word+=':start:' next_word+=':sudo_opt:' + elif [[ -n $flags_solo ]] && + { + # Trenary + if [[ -n $flags_sans_argument ]] + then [[ $arg == '-'[$flags_sans_argument]#[$flags_solo]* ]] + else [[ $arg == '-'[$flags_solo]* ]] + fi + } then + # Solo flags + this_word=':sudo_opt:' + next_word=':regular:' # no :start:, nor :sudo_opt: since we don't know whether the solo flag takes an argument or not elif [[ $arg == '-'* ]]; then # Unknown flag. We don't know whether it takes an argument or not, # so modify $next_word as we do for flags that require no argument. @@ -804,6 +819,7 @@ _zsh_highlight_main_highlighter_highlight_list() set -- "${(@s.:.)precommand_options[$arg]}" flags_with_argument=$1 flags_sans_argument=$2 + flags_solo=$3 } next_word=${next_word//:regular:/} next_word+=':sudo_opt:' From 20d250d6186c0147afc68930ab5887bc056549a9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:21:31 +0000 Subject: [PATCH 189/297] 'main': Support the non-precommand flags of sudo(8) and ssh-agent(1). Uses the infrastructure added in the previous commit. Fixes #678. --- highlighters/main/main-highlighter.zsh | 8 ++++---- highlighters/main/test-data/precommand-killing2.zsh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ac34f23..b60db29 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -329,15 +329,15 @@ _zsh_highlight_highlighter_main_paint() 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'nice' n: # as of current POSIX spec 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags - # Argumentless flags that can't be followed by a command: -e -h -K -k -V -v - 'sudo' Cgprtu:AEHPSbilns # as of sudo 1.8.21p2 + # Not listed: -h, which has two different meanings. + 'sudo' Cgprtu:AEHPSbilns:eKkVv # as of sudo 1.8.21p2 'stdbuf' ioe: 'eatmydata' '' 'catchsegv' '' 'nohup' '' 'setsid' :wc - # As of OpenSSH 8.1p1; -k is deliberately left out since it may not be followed by a command - 'ssh-agent' aEPt:csDd + # As of OpenSSH 8.1p1 + 'ssh-agent' aEPt:csDd:k # suckless-tools v44 # Argumentless flags that can't be followed by a command: -v 'tabbed' gnprtTuU:cdfhs diff --git a/highlighters/main/test-data/precommand-killing2.zsh b/highlighters/main/test-data/precommand-killing2.zsh index 71591f1..bc6fc86 100644 --- a/highlighters/main/test-data/precommand-killing2.zsh +++ b/highlighters/main/test-data/precommand-killing2.zsh @@ -35,5 +35,5 @@ BUFFER='sudo -e /does/not/exist' expected_region_highlight=( '1 4 precommand' # sudo '6 7 single-hyphen-option' # -e - '9 23 default "issue #678"' # /does/not/exist + '9 23 default' # /does/not/exist ) From e15781c900e41470da5e8c662a2e37efdac1208e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:26:28 +0000 Subject: [PATCH 190/297] changelog: Update through HEAD. --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 08887ea..41328cc 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,9 @@ - Support parameter elision in command position (e.g., `$foo ls` where `$foo` is unset or empty) [#667] +- Don't consider the filename in «sudo -e /path/to/file» to be a command position + [#678] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From 62e2d05f916f1c3731bc12fc33ce03327d7a0811 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:34:48 +0000 Subject: [PATCH 191/297] changelog: Update through HEAD. --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 41328cc..6526092 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,9 @@ - Don't consider the filename in «sudo -e /path/to/file» to be a command position [#678] +- Don't look up absolute directory names in $cdpath + [2cc2583f8f12, part of #669] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From f56e3fad23e8f20bf278b69120dffb0a850a3214 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 20:45:56 +0000 Subject: [PATCH 192/297] 'main': Optimize the path_prefix check. Computing ${#array} is O(N), whereas checking 0 is O(1). --- highlighters/main/main-highlighter.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index dd3af08..fcc0c96 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1117,9 +1117,10 @@ _zsh_highlight_main_highlighter_check_path() # If this word ends the buffer, check if it's the prefix of a valid path. if (( has_end && (len == end_pos) )) && [[ $WIDGET != zle-line-finish ]]; then + # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local -a tmp tmp=( ${expanded_path}*(N) ) - (( $#tmp > 0 )) && REPLY=path_prefix && return 0 + (( ${+tmp[1]} )) && REPLY=path_prefix && return 0 fi # It's not a path. From 3174e375f4d74e66fe032f5aa21c030c9f0d5ba8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 21:50:04 +0000 Subject: [PATCH 193/297] 'main': Fix highlighting of null execs. Fixes #676. --- changelog.md | 3 +++ highlighters/main/main-highlighter.zsh | 4 ++++ highlighters/main/test-data/null-exec.zsh | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6526092..d1a01ab 100644 --- a/changelog.md +++ b/changelog.md @@ -26,6 +26,9 @@ - Don't look up absolute directory names in $cdpath [2cc2583f8f12, part of #669] +- Fix "exec 2>&1;" being highlighted as an error. + [#676] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index fcc0c96..1234ac7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -824,6 +824,10 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' + if [[ $arg == 'exec' ]]; then + # To allow "exec 2>&1;" where there's no command word + next_word+=':regular:' + fi else case $res in reserved) # reserved word diff --git a/highlighters/main/test-data/null-exec.zsh b/highlighters/main/test-data/null-exec.zsh index ab73717..be1e306 100644 --- a/highlighters/main/test-data/null-exec.zsh +++ b/highlighters/main/test-data/null-exec.zsh @@ -34,5 +34,5 @@ expected_region_highlight=( '1 4 precommand' # exec '6 6 redirection' # > '7 15 path' # /dev/null - '16 16 commandseparator "issue #676"' # ; + '16 16 commandseparator' # ; ) From e815d4579bef0c0d3ee5a505cc9c74c0f2e2dfc1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 22:26:49 +0000 Subject: [PATCH 194/297] tests: Add a test for a bug fixed in 2d0dddf58bab0bd9220f29919065ff85db66390e "'main': Don't dequote the word in command position before analyzing it.". Fixes #630. --- .../main/test-data/alias-in-cmdsubst.zsh | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 highlighters/main/test-data/alias-in-cmdsubst.zsh diff --git a/highlighters/main/test-data/alias-in-cmdsubst.zsh b/highlighters/main/test-data/alias-in-cmdsubst.zsh new file mode 100644 index 0000000..b3cf777 --- /dev/null +++ b/highlighters/main/test-data/alias-in-cmdsubst.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +alias p='print -r --' + +BUFFER=$'s=$(p foo)' + +expected_region_highlight=( + '1 10 assign' # s=$(p foo) + '3 10 default' # $(p foo) + '3 10 command-substitution-unquoted' # $(p foo) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 alias' # p + '7 9 default' # foo + '10 10 command-substitution-delimiter-unquoted' # ) +) From b454b596edc661813bee4eef24282a5aa729eaa0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 00:48:16 +0000 Subject: [PATCH 195/297] Fix historical instances of one-space indentation. No functional change. --- highlighters/main/main-highlighter.zsh | 285 +++++++++++++------------ 1 file changed, 145 insertions(+), 140 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1234ac7..5f20434 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -762,75 +762,75 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':sudo_opt:' next_word+=':start:' fi - fi + fi - # The Great Fork: is this a command word? Is this a non-command word? - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + # The Great Fork: is this a command word? Is this a non-command word? + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - # First, determine the style of the command separator itself. - if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then - # Missing closing square bracket(s) - style=unknown-token - elif $in_array_assignment; then - case $arg in - # Literal newlines are just fine. - ($'\n') style=commandseparator;; - # Semicolons are parsed the same way as literal newlines. Nevertheless, - # highlight them as errors since they're probably unintended. Compare - # issue #691. - (';') style=unknown-token;; - # Other command separators aren't allowed. - (*) style=unknown-token;; - esac - elif [[ $this_word == *':regular:'* ]]; then - style=commandseparator - elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then - style=commandseparator - else - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. - style=unknown-token - fi - - # Second, determine the style of next_word. - if [[ $arg == $'\n' ]] && $in_array_assignment; then - # literal newline inside an array assignment - next_word=':regular:' - elif [[ $arg == ';' ]] && $in_array_assignment; then - # literal semicolon inside an array assignment - next_word=':regular:' - else - next_word=':start:' - highlight_glob=true - if [[ $arg != '|' && $arg != '|&' ]]; then - next_word+=':start_of_pipeline:' - fi - fi - - elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then - # try-always construct - style=reserved-word # de facto a reserved word, although not de jure - highlight_glob=true - next_word=':start::start_of_pipeline:' # only left brace is allowed, apparently - elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word - if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then - style=precommand - () { - set -- "${(@s.:.)precommand_options[$arg]}" - flags_with_argument=$1 - flags_sans_argument=$2 - flags_solo=$3 - } - next_word=${next_word//:regular:/} - next_word+=':sudo_opt:' - next_word+=':start:' - if [[ $arg == 'exec' ]]; then - # To allow "exec 2>&1;" where there's no command word - next_word+=':regular:' + # First, determine the style of the command separator itself. + if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then + # Missing closing square bracket(s) + style=unknown-token + elif $in_array_assignment; then + case $arg in + # Literal newlines are just fine. + ($'\n') style=commandseparator;; + # Semicolons are parsed the same way as literal newlines. Nevertheless, + # highlight them as errors since they're probably unintended. Compare + # issue #691. + (';') style=unknown-token;; + # Other command separators aren't allowed. + (*) style=unknown-token;; + esac + elif [[ $this_word == *':regular:'* ]]; then + style=commandseparator + elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then + style=commandseparator + else + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. + style=unknown-token fi - else - case $res in - reserved) # reserved word + + # Second, determine the style of next_word. + if [[ $arg == $'\n' ]] && $in_array_assignment; then + # literal newline inside an array assignment + next_word=':regular:' + elif [[ $arg == ';' ]] && $in_array_assignment; then + # literal semicolon inside an array assignment + next_word=':regular:' + else + next_word=':start:' + highlight_glob=true + if [[ $arg != '|' && $arg != '|&' ]]; then + next_word+=':start_of_pipeline:' + fi + fi + + elif ! (( in_redirection)) && [[ $this_word == *':always:'* && $arg == 'always' ]]; then + # try-always construct + style=reserved-word # de facto a reserved word, although not de jure + highlight_glob=true + next_word=':start::start_of_pipeline:' # only left brace is allowed, apparently + elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word + if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then + style=precommand + () { + set -- "${(@s.:.)precommand_options[$arg]}" + flags_with_argument=$1 + flags_sans_argument=$2 + flags_solo=$3 + } + next_word=${next_word//:regular:/} + next_word+=':sudo_opt:' + next_word+=':start:' + if [[ $arg == 'exec' ]]; then + # To allow "exec 2>&1;" where there's no command word + next_word+=':regular:' + fi + else + case $res in + (reserved) # reserved word style=reserved-word # Match braces and handle special cases. case $arg in @@ -907,15 +907,17 @@ _zsh_highlight_main_highlighter_highlight_list() ;; esac ;; - 'suffix alias') style=suffix-alias;; - alias) :;; - builtin) style=builtin + ('suffix alias') + style=suffix-alias + ;; + (alias) :;; + (builtin) style=builtin [[ $arg == $'\x5b' ]] && braces_stack='Q'"$braces_stack" ;; - function) style=function;; - command) style=command;; - hashed) style=hashed-command;; - none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then + (function) style=function;; + (command) style=command;; + (hashed) style=hashed-command;; + (none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign local i=$(( arg[(i)=] + 1 )) if [[ $arg[i] == '(' ]]; then @@ -984,67 +986,70 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi ;; - *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res + (*) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res continue ;; - esac - fi - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then - next_word=':start::start_of_pipeline:' - fi - else # $arg is a non-command word + esac + fi + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then + next_word=':start::start_of_pipeline:' + fi + else # $arg is a non-command word case $arg in - $'\x29') # subshell or end of array assignment - if $in_array_assignment; then - style=assign - in_array_assignment=false - next_word+=':start:' - elif (( in_redirection )); then - style=unknown-token - else - if _zsh_highlight_main__stack_pop 'S'; then - REPLY=$start_pos - reply=($list_highlights) - return 0 - fi - _zsh_highlight_main__stack_pop 'R' reserved-word - fi;; - $'\x28\x29') # possibly a function definition - if (( in_redirection )) || $in_array_assignment; then - style=unknown-token - else - if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word - then - next_word+=':start::start_of_pipeline:' - fi - style=reserved-word - fi - ;; - *) if false; then - elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then - # Parsing rule: { - # - # Additionally, `tt(})' is recognized in any position if neither the - # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. - if (( in_redirection )) || $in_array_assignment; then - style=unknown-token - else - _zsh_highlight_main__stack_pop 'Y' reserved-word - if [[ $style == reserved-word ]]; then - next_word+=':always:' - fi - fi - elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then - style=history-expansion - elif [[ $arg == $'\x5d\x5d' ]] && _zsh_highlight_main__stack_pop 'T' reserved-word; then - : - elif [[ $arg == $'\x5d' ]] && _zsh_highlight_main__stack_pop 'Q' builtin; then - : - else - _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection )) - continue - fi - ;; + ($'\x29') + # subshell or end of array assignment + if $in_array_assignment; then + style=assign + in_array_assignment=false + next_word+=':start:' + elif (( in_redirection )); then + style=unknown-token + else + if _zsh_highlight_main__stack_pop 'S'; then + REPLY=$start_pos + reply=($list_highlights) + return 0 + fi + _zsh_highlight_main__stack_pop 'R' reserved-word + fi + ;; + ($'\x28\x29') + # possibly a function definition + if (( in_redirection )) || $in_array_assignment; then + style=unknown-token + else + if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word + then + next_word+=':start::start_of_pipeline:' + fi + style=reserved-word + fi + ;; + (*) if false; then + elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then + # Parsing rule: { + # + # Additionally, `tt(})' is recognized in any position if neither the + # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. + if (( in_redirection )) || $in_array_assignment; then + style=unknown-token + else + _zsh_highlight_main__stack_pop 'Y' reserved-word + if [[ $style == reserved-word ]]; then + next_word+=':always:' + fi + fi + elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then + style=history-expansion + elif [[ $arg == $'\x5d\x5d' ]] && _zsh_highlight_main__stack_pop 'T' reserved-word; then + : + elif [[ $arg == $'\x5d' ]] && _zsh_highlight_main__stack_pop 'Q' builtin; then + : + else + _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 != in_redirection )) + continue + fi + ;; esac fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style @@ -1202,7 +1207,7 @@ _zsh_highlight_main_highlighter_highlight_argument() (( i = REPLY )) highlights+=($reply) continue - elif [[ $arg[i+1] == $'\x28' ]]; then + elif [[ $arg[i+1] == $'\x28' ]]; then start=$i (( i += 2 )) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] @@ -1310,14 +1315,14 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in - '"') break;; - '`') saved_reply=($reply) - _zsh_highlight_main_highlighter_highlight_backtick $i - (( i = REPLY )) - reply=($saved_reply $reply) - continue - ;; - '$' ) style=dollar-double-quoted-argument + ('"') break;; + ('`') saved_reply=($reply) + _zsh_highlight_main_highlighter_highlight_backtick $i + (( i = REPLY )) + reply=($saved_reply $reply) + continue + ;; + ('$') style=dollar-double-quoted-argument # Look for an alphanumeric parameter name. if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then (( k += $#MATCH )) # highlight the parameter name From 9ceb7c6e7c75183c20ac1ed51eb86c673fe3c808 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 01:51:32 +0000 Subject: [PATCH 196/297] changelog.md (0.7.0): Fix typo --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d1a01ab..21c6b2a 100644 --- a/changelog.md +++ b/changelog.md @@ -65,7 +65,7 @@ This is a stable bugfix and feature release. Major new features and changes inc - Highlight numeric globs (e.g., `echo /lib<->`) -- Assorted improvement to aliases highlighting +- Assorted improvements to aliases highlighting (e.g., `alias sudo_u='sudo -u'; sudo_u jrandom ls`, `alias x=y y=z z=nosuchcommand; x`, From 6e1a2216994927bfebd2aab3bda5138331dff28e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 02:57:55 +0000 Subject: [PATCH 197/297] tests: Add a test for issue #571. --- .../main/test-data/assign-quoted-cmdsubst.zsh | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 highlighters/main/test-data/assign-quoted-cmdsubst.zsh diff --git a/highlighters/main/test-data/assign-quoted-cmdsubst.zsh b/highlighters/main/test-data/assign-quoted-cmdsubst.zsh new file mode 100644 index 0000000..d4a62df --- /dev/null +++ b/highlighters/main/test-data/assign-quoted-cmdsubst.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'x="$(ls x y z)"' + +expected_region_highlight=( + '1 15 assign' # x="$(ls x y z)" + '3 15 default' # "$(ls x y z)" + '3 3 double-quoted-argument' # " + '15 15 double-quoted-argument' # " + '4 14 command-substitution-quoted' # $(ls x y z) + '4 5 command-substitution-delimiter-quoted' # $( + '6 7 command' # ls + '9 9 default' # x + '11 11 default' # y + '13 13 default' # z + '14 14 command-substitution-delimiter-quoted' # ) +) From c699ce9a26554ef1dd79a0a5d92fe5c10faef9fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:09:25 +0000 Subject: [PATCH 198/297] changelog: Fix markup. --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 21c6b2a..544c92a 100644 --- a/changelog.md +++ b/changelog.md @@ -20,13 +20,13 @@ - Support parameter elision in command position (e.g., `$foo ls` where `$foo` is unset or empty) [#667] -- Don't consider the filename in «sudo -e /path/to/file» to be a command position +- Don't consider the filename in `sudo -e /path/to/file` to be a command position [#678] - Don't look up absolute directory names in $cdpath [2cc2583f8f12, part of #669] -- Fix "exec 2>&1;" being highlighted as an error. +- Fix `exec 2>&1;` being highlighted as an error. [#676] # Changes in version 0.7.1 From 936bc251a82b4bc54647013c35e8f5bc3759bc7a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:08:48 +0000 Subject: [PATCH 199/297] 'main': The optimized cmdsubst input syntax doesn't glob. Fixes #582. --- changelog.md | 3 ++ highlighters/main/main-highlighter.zsh | 7 +++ .../test-data/optimized-cmdsubst-input.zsh | 43 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 highlighters/main/test-data/optimized-cmdsubst-input.zsh diff --git a/changelog.md b/changelog.md index 544c92a..870b576 100644 --- a/changelog.md +++ b/changelog.md @@ -29,6 +29,9 @@ - Fix `exec 2>&1;` being highlighted as an error. [#676] +- Fix `: $(<*)` being highlighted as globbing. + [#582] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1234ac7..680b247 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -498,6 +498,13 @@ _zsh_highlight_main_highlighter_highlight_list() else args=(${(z)buf}) fi + + # Special case: $(<*) isn't globbing. + if [[ $braces_stack == 'S' ]] && (( $+args[3] && ! $+args[4] )) && [[ $args[3] == $'\x29' ]] && + [[ $args[1] == *'<'* ]] && _zsh_highlight_main__is_redirection $args[1]; then + highlight_glob=false + fi + while (( $#args )); do arg=$args[1] shift args diff --git a/highlighters/main/test-data/optimized-cmdsubst-input.zsh b/highlighters/main/test-data/optimized-cmdsubst-input.zsh new file mode 100644 index 0000000..ca55ef8 --- /dev/null +++ b/highlighters/main/test-data/optimized-cmdsubst-input.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +# See getoutput() and getoutputfile() in zsh's C source code. + +BUFFER=$': $(<*)' + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 default' # $(<*) + '3 7 command-substitution-unquoted' # $(<*) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 redirection' # < + '6 6 default' # * - not globbing! + '7 7 command-substitution-delimiter-unquoted' # ) +) From 61945185ffb31c09f89f7f40c6e682e777d267be Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:18:27 +0000 Subject: [PATCH 200/297] 'main': Document what $in_redirection is currently used for. --- highlighters/main/main-highlighter.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 680b247..676f98d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -488,6 +488,13 @@ _zsh_highlight_main_highlighter_highlight_list() # $in_redirection. The value of $next_word from the iteration that processed # the operator is discarded. # + # $in_redirection is currently used for: + # - comments + # - aliases + # - redirections + # - parameter elision in command position + # - 'repeat' loops + # local this_word next_word=':start::start_of_pipeline:' integer in_redirection # Processing buffer From 2339ee33b98bb7651da5cbe07cf184208e7f3f44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:31:32 +0000 Subject: [PATCH 201/297] 'main': Honour the MULTIOS option when applying the 'globbing' style. Fixes #583. --- changelog.md | 3 ++ highlighters/main/main-highlighter.zsh | 4 +- .../test-data/multios-negates-globbing.zsh | 39 +++++++++++++++++++ .../test-data/multios-negates-globbing2.zsh | 38 ++++++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/multios-negates-globbing.zsh create mode 100644 highlighters/main/test-data/multios-negates-globbing2.zsh diff --git a/changelog.md b/changelog.md index 870b576..7978a82 100644 --- a/changelog.md +++ b/changelog.md @@ -32,6 +32,9 @@ - Fix `: $(<*)` being highlighted as globbing. [#582] +- Fix `cat < *` being highlighting as globbing when the `MULTIOS` option is unset. + [#583] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 676f98d..0048147 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1257,7 +1257,9 @@ _zsh_highlight_main_highlighter_highlight_argument() fi ;| *) - if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then + if $highlight_glob && + [[ $zsyh_user_options[multios] == on || $in_redirection -eq 0 ]] && + [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing) (( i += $#MATCH - 1 )) path_eligible=0 diff --git a/highlighters/main/test-data/multios-negates-globbing.zsh b/highlighters/main/test-data/multios-negates-globbing.zsh new file mode 100644 index 0000000..7ece670 --- /dev/null +++ b/highlighters/main/test-data/multios-negates-globbing.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +unsetopt multios + +BUFFER=$'cat < *' + +expected_region_highlight=( + '1 3 command' # cat + '5 5 redirection' # < + '7 7 default' # * - not globbing +) diff --git a/highlighters/main/test-data/multios-negates-globbing2.zsh b/highlighters/main/test-data/multios-negates-globbing2.zsh new file mode 100644 index 0000000..b6db983 --- /dev/null +++ b/highlighters/main/test-data/multios-negates-globbing2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'cat < *' + +expected_region_highlight=( + '1 3 command' # cat + '5 5 redirection' # < + '7 7 default' # * + '7 7 globbing' # * +) From 5720d8705290723cbc2b1cef09605554c44fbdab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:48:40 +0000 Subject: [PATCH 202/297] noop: Clarify comment. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0048147..f204838 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -646,7 +646,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then if (( in_redirection == 1 )); then - # The condition excludes the case that BUFFER='{foo}>&2' and we're on the '>&'. + # Two consecuive redirection operators is an error. _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token else in_redirection=2 From 1024ae81772c66e4d7f5522bb939a098b3fbb542 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:58:15 +0000 Subject: [PATCH 203/297] 'main': Add $last_arg for "lookbehind". --- highlighters/main/main-highlighter.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f204838..8829ceb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -422,7 +422,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Usually 'alias' but set to 'unknown-token' if any word expanded from # the alias would be highlighted as unknown-token # param_style is analogous for parameter expansions - local alias_style param_style arg buf=$4 highlight_glob=true style + local alias_style param_style last_arg arg buf=$4 highlight_glob=true style local in_array_assignment=false # true between 'a=(' and the matching ')' # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. @@ -513,6 +513,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi while (( $#args )); do + last_arg=$arg arg=$args[1] shift args if (( in_alias )); then From fb69f4ca81ee0d161a0885693239f8dfa396dda2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 03:59:30 +0000 Subject: [PATCH 204/297] 'main': When the redirection operator '>&' or '<&' is followed by a positive integer, do not consider that as a filename; it's always a file descriptor. Fixes #694. --- changelog.md | 3 +++ docs/highlighters/main.md | 3 ++- highlighters/main/main-highlighter.zsh | 17 +++++++++++++---- .../main/test-data/fd-target-not-filename.zsh | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 7978a82..952a33c 100644 --- a/changelog.md +++ b/changelog.md @@ -35,6 +35,9 @@ - Fix `cat < *` being highlighting as globbing when the `MULTIOS` option is unset. [#583] +- Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist + [#694] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 1566fa4..8f4ef4b 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -59,7 +59,8 @@ This highlighter defines the following styles: * `redirection` - redirection operators (`<`, `>`, etc) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) * `comment` - elided parameters in command position (`$x ls` when `$x` is unset or empty) -* `named-fd` - named file descriptor (`echo foo {fd}>&2`) +* `named-fd` - named file descriptor (the `fd` in `echo foo {fd}>&2`) +* `numeric-fd` - numeric file descriptor (the `2` in `echo foo {fd}>&2`) * `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command). * `default` - everything else diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8829ceb..e43efa7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -59,6 +59,7 @@ : ${ZSH_HIGHLIGHT_STYLES[redirection]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} : ${ZSH_HIGHLIGHT_STYLES[named-fd]:=none} +: ${ZSH_HIGHLIGHT_STYLES[numeric-fd]:=none} : ${ZSH_HIGHLIGHT_STYLES[arg0]:=fg=green} # Whether the highlighter should be called or not. @@ -112,6 +113,10 @@ _zsh_highlight_main_calculate_fallback() { hashed-command arg0 arg0_\* arg0 + # TODO: Maybe these? — + # named-fd file-descriptor + # numeric-fd file-descriptor + path_prefix path # The path separator fallback won't ever be used, due to the optimisation # in _zsh_highlight_main_highlighter_highlight_path_separators(). @@ -1271,10 +1276,14 @@ _zsh_highlight_main_highlighter_highlight_argument() esac done - if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then - base_style=$REPLY - _zsh_highlight_main_highlighter_highlight_path_separators $base_style - highlights+=($reply) + if (( path_eligible )); then + if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == <0-> ]]; then + base_style=numeric-fd + elif _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then + base_style=$REPLY + _zsh_highlight_main_highlighter_highlight_path_separators $base_style + highlights+=($reply) + fi fi highlights=($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights) diff --git a/highlighters/main/test-data/fd-target-not-filename.zsh b/highlighters/main/test-data/fd-target-not-filename.zsh index 15de3db..5c3cd08 100644 --- a/highlighters/main/test-data/fd-target-not-filename.zsh +++ b/highlighters/main/test-data/fd-target-not-filename.zsh @@ -36,5 +36,5 @@ expected_region_highlight=( '1 4 builtin' # echo '6 8 default' # foo '9 10 redirection' # >& - '11 11 file-descriptor "issue #694"' # 2 (not path) + '11 11 numeric-fd' # 2 (not path) ) From e79ce6afd0209297374dfe811a3cff9643a61aac Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 14:12:00 +0000 Subject: [PATCH 205/297] 'main': Document additional meanings of the 'S' $braces_stack flag. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e43efa7..5bab812 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -444,7 +444,7 @@ _zsh_highlight_main_highlighter_highlight_list() # "Q" for square # "Y" for curly # "T" for [[ ]] - # "S" for $( ) + # "S" for $( ), =( ), <( ), >( ) # "D" for do/done # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) # "?" for 'if'/'fi'; also checked by 'elif'/'else' From ea2f1060f6138f3cb97ec5662cecf423cc888aec Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 14:53:09 +0000 Subject: [PATCH 206/297] test harness: No-op change to minimize the next diff. --- tests/test-highlighting.zsh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6b8547b..ba508ac 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -186,14 +186,16 @@ run_test_internal() { if [[ -n $expected_mismatch ]]; then tap_escape $expected_mismatch; expected_mismatch=$REPLY print "ok $i - cardinality check" "# SKIP $expected_mismatch" - elif (( $#expected_region_highlight == $#region_highlight )); then - print -r -- "ok $i - cardinality check" else - local details - details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " - details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" - tap_escape $details; details=$REPLY - print -r -- "not ok $i - cardinality check - $details" + if (( $#expected_region_highlight == $#region_highlight )); then + print -r -- "ok $i - cardinality check" + else + local details + details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " + details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" + tap_escape $details; details=$REPLY + print -r -- "not ok $i - cardinality check - $details" + fi fi } From 61c1cfe99f92b630ab335aa298ce1fc3eeb01b6c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 14:58:00 +0000 Subject: [PATCH 207/297] test harness: Change cardinality check semantics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cardinality check shall — - if the test sets \$expected_mismatch, be XFail; - elif any test points is XFail, be skipped; - else, be expected to pass. To test this, change «6 * 9» to «6 + 9» in test-data/arith1.zsh that will be added in the after-next (grandchild) commit. --- tests/README.md | 8 +++++--- tests/test-highlighting.zsh | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/README.md b/tests/README.md index b2baafb..55fff8a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -30,9 +30,11 @@ need not match the order in `$region_highlight`. 4. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` -have different numbers of elements. Tests may set `$expected_mismatch` to an -explanation string (like `$todo`) to avoid this and skip the cardinality check. -`$expected_mismatch` is set implicitly if the `$todo` component is present. +have different numbers of elements. To mark this check as expected to fail, +tests may set `$expected_mismatch` to an explanation string (like `$todo`); +this is useful when the only difference between actual and expected is that actual +has some additional, superfluous elements. This check is skipped if the +`$todo` component is present in any regular test point. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index ba508ac..9742612 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -120,6 +120,7 @@ run_test_internal() { # Load the data and prepare checking it. local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0 local expected_mismatch + local skip_mismatch local -a expected_region_highlight region_highlight . "$srcdir"/"$1" @@ -155,11 +156,11 @@ run_test_internal() { local todo= if (( $+expected_highlight_zone[4] )); then todo="# TODO $expected_highlight_zone[4]" - : ${expected_mismatch:="cardinality check disabled whilst regular test points are expected to fail"} + skip_mismatch="cardinality check disabled whilst regular test points are expected to fail" fi if ! (( $+region_highlight[i] )); then print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \ - "${expected_mismatch:+"# TODO ${(qqq)expected_mismatch}"}" + "${skip_mismatch:+"# TODO ${(qqq)skip_mismatch}"}" continue fi local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} ) @@ -183,18 +184,27 @@ run_test_internal() { unset desc done - if [[ -n $expected_mismatch ]]; then - tap_escape $expected_mismatch; expected_mismatch=$REPLY - print "ok $i - cardinality check" "# SKIP $expected_mismatch" + # If both $skip_mismatch and $expected_mismatch are set, that means the test + # has some XFail test points, _and_ explicitly sets $expected_mismatch as + # well. Explicit settings should have priority, so we ignore $skip_mismatch + # if $expected_mismatch is set. + if [[ -n $skip_mismatch && -z $expected_mismatch ]]; then + tap_escape $skip_mismatch; skip_mismatch=$REPLY + print "ok $i - cardinality check" "# SKIP $skip_mismatch" else + local todo + if [[ -n $expected_mismatch ]]; then + tap_escape $expected_mismatch; expected_mismatch=$REPLY + todo="# TODO $expected_mismatch" + fi if (( $#expected_region_highlight == $#region_highlight )); then - print -r -- "ok $i - cardinality check" + print -r -- "ok $i - cardinality check${todo:+ - }$todo" else local details details+="have $#expected_region_highlight expectations and $#region_highlight region_highlight entries: " details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY - print -r -- "not ok $i - cardinality check - $details" + print -r -- "not ok $i - cardinality check - $details${todo:+ - }$todo" fi fi } From 2e65bb6d7d90271ac0628254641a89adf109f064 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 14:35:46 +0000 Subject: [PATCH 208/297] tests: Add a test documenting the current state, prior to introducing #704. --- .../main/test-data/arith-cmdsubst-mess.zsh | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 highlighters/main/test-data/arith-cmdsubst-mess.zsh diff --git a/highlighters/main/test-data/arith-cmdsubst-mess.zsh b/highlighters/main/test-data/arith-cmdsubst-mess.zsh new file mode 100644 index 0000000..82268ac --- /dev/null +++ b/highlighters/main/test-data/arith-cmdsubst-mess.zsh @@ -0,0 +1,46 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $((ls); (ls))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # $((ls); (ls)) + '3 15 command-substitution-unquoted' # $((ls); (ls)) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 reserved-word' # ( + '6 7 command' # ls + '8 8 reserved-word' # ) + '9 9 commandseparator' # ; + '11 11 reserved-word' # ( + '12 13 command' # ls + '14 14 reserved-word' # ) + '15 15 command-substitution-delimiter-unquoted' # ) +) From d237a60c9b9a7af636b6a08e051acffd8a14179a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 14:22:06 +0000 Subject: [PATCH 209/297] 'main': Don't highlight arithmetic expansions as command substitutions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not perfect: we don't try to detect cases such as «$((ls); (ls))», which look like arithmetic expansions but are in fact command substitutions. Fixes part of #607. Introduces #704. --- changelog.md | 7 ++++ highlighters/main/main-highlighter.zsh | 10 ++++- .../main/test-data/arith-cmdsubst-mess.zsh | 20 +++++----- highlighters/main/test-data/arith1.zsh | 37 +++++++++++++++++++ highlighters/main/test-data/arith2.zsh | 37 +++++++++++++++++++ 5 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 highlighters/main/test-data/arith1.zsh create mode 100644 highlighters/main/test-data/arith2.zsh diff --git a/changelog.md b/changelog.md index 952a33c..ab5c445 100644 --- a/changelog.md +++ b/changelog.md @@ -38,6 +38,13 @@ - Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist [#694] +- Fix `: $((42))` being highlighted as a subshell. + [part of #607] + +- Regress highlighting of `: $((ls); (ls))`: is a subshell, but will now be + incorrectly highlighted as an arithmetic expansion. + [#704] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5bab812..a6498bf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1222,7 +1222,8 @@ _zsh_highlight_main_highlighter_highlight_argument() (( i = REPLY )) highlights+=($reply) continue - elif [[ $arg[i+1] == $'\x28' ]]; then + elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then + # command substitution that doesn't look like an arithmetic expansion start=$i (( i += 2 )) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] @@ -1237,6 +1238,10 @@ _zsh_highlight_main_highlighter_highlight_argument() highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted) fi continue + else + # TODO: if it's an arithmetic expansion, skip past it, to prevent + # multiplications from being highlighted as globbing (issue #607, + # test-data/arith1.zsh) fi while [[ $arg[i+1] == [\^=~#+] ]]; do (( i += 1 )) @@ -1359,7 +1364,8 @@ _zsh_highlight_main_highlighter_highlight_double_quote() # $#, $*, $@, $?, $- - like $$ above (( k += 1 )) # highlight both dollar signs (( i += 1 )) # don't consider the second one as introducing another parameter expansion - elif [[ $arg[i+1] == $'\x28' ]]; then + elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then + # command substitution that doesn't look like an arithmetic expansion breaks+=( $last_break $(( start_pos + i - 1 )) ) (( i += 2 )) saved_reply=($reply) diff --git a/highlighters/main/test-data/arith-cmdsubst-mess.zsh b/highlighters/main/test-data/arith-cmdsubst-mess.zsh index 82268ac..6f60469 100644 --- a/highlighters/main/test-data/arith-cmdsubst-mess.zsh +++ b/highlighters/main/test-data/arith-cmdsubst-mess.zsh @@ -33,14 +33,14 @@ BUFFER=$': $((ls); (ls))' expected_region_highlight=( '1 1 builtin' # : '3 15 default' # $((ls); (ls)) - '3 15 command-substitution-unquoted' # $((ls); (ls)) - '3 4 command-substitution-delimiter-unquoted' # $( - '5 5 reserved-word' # ( - '6 7 command' # ls - '8 8 reserved-word' # ) - '9 9 commandseparator' # ; - '11 11 reserved-word' # ( - '12 13 command' # ls - '14 14 reserved-word' # ) - '15 15 command-substitution-delimiter-unquoted' # ) + '3 15 command-substitution-unquoted "issue #704"' # $((ls); (ls)) + '3 4 command-substitution-delimiter-unquoted "issue #704"' # $( + '5 5 reserved-word "issue #704"' # ( + '6 7 command "issue #704"' # ls + '8 8 reserved-word "issue #704"' # ) + '9 9 commandseparator "issue #704"' # ; + '11 11 reserved-word "issue #704"' # ( + '12 13 command "issue #704"' # ls + '14 14 reserved-word "issue #704"' # ) + '15 15 command-substitution-delimiter-unquoted "issue #704"' # ) ) diff --git a/highlighters/main/test-data/arith1.zsh b/highlighters/main/test-data/arith1.zsh new file mode 100644 index 0000000..92fa3da --- /dev/null +++ b/highlighters/main/test-data/arith1.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( 6 * 9 ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 14 default' # $(( 6 * 9 )) +) +expected_mismatch="currently the actual highlighting has one superfluous group that highlights the asterisk is highlighted as 'globbing'" diff --git a/highlighters/main/test-data/arith2.zsh b/highlighters/main/test-data/arith2.zsh new file mode 100644 index 0000000..7e98476 --- /dev/null +++ b/highlighters/main/test-data/arith2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': "$(( 6 * 9 ))"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 16 default' # "$(( 6 * 9 ))" + '3 16 double-quoted-argument' # "$(( 6 * 9 ))" +) From e165f18c758e92e57d8e5008c71889ea72f41227 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 16:13:32 +0000 Subject: [PATCH 210/297] 'main': Fix a bug manifesting under zsh 5.2 and older. The escaped caret was taken for a negated character class. This caused test-data/arith1.zsh to XPass: the arithmetic expansion was consumed by the 'while' loop. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a6498bf..57875f3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1243,7 +1243,7 @@ _zsh_highlight_main_highlighter_highlight_argument() # multiplications from being highlighted as globbing (issue #607, # test-data/arith1.zsh) fi - while [[ $arg[i+1] == [\^=~#+] ]]; do + while [[ $arg[i+1] == [=~#+'^'] ]]; do (( i += 1 )) done if [[ $arg[i+1] == [*@#?$!-] ]]; then From 99389327aef8ea5621c8aef82034e31ee2087e62 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 16:22:56 +0000 Subject: [PATCH 211/297] test harness: Fix test failures under zsh 5.0.8 and older. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The output of test-data/opt-shwordsplit1.zsh on zsh 5.7 is: . 1..2 ## opt-shwordsplit1 # BUFFER=vim not ok 1 - [1,7] «$EDITOR» - expected (1 7 "function"), observed (1 7 "unknown-token"). # TODO "issue ok 2 - cardinality check # SKIP cardinality check disabled whilst regular test points are expected to fail On zsh 5.0.8, tap_escape() choked when called on the arguments argv=('[1,7]' '«vim»'). This patch fixes that. As you may have noticed, under zsh 5.7 the diagnostic message of test point 1 is truncated. That'll be fixed in the next commit. --- tests/test-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 9742612..524a765 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -105,7 +105,7 @@ typeset_p() { # Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output # The string to escape is «"$@"»; the result is returned in $REPLY. tap_escape() { - local s="$@" + local s="${(j. .)@}" REPLY="${${s//'#'/♯}//$'\n'/↵}" } From e6eea1f9b7e67136911536a2450c7130f44c0b04 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 16:35:14 +0000 Subject: [PATCH 212/297] test harness: Don't leak options from test files to the test harness. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an issue whereby the '# TODO "issue #687"' directive in the output of opt-shwordsplit1.zsh was truncated, because the test itself had set the SH_WORD_SPLIT option and that affected the evaluation of «${(z)expected_region_highlight[i]}» in the test harness. Furthermore, this patch also independently fixes the error under zsh-5.0.8 and earlier that was fixed by the previous commit. --- tests/test-highlighting.zsh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 524a765..7d7ebb7 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -123,20 +123,27 @@ run_test_internal() { local skip_mismatch local -a expected_region_highlight region_highlight - . "$srcdir"/"$1" + local ARG="$1" + () { + setopt localoptions + . "$srcdir"/"$ARG" - (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } + # WARNING: The remainder of this anonymous function will run with the test's options in effect - # Check the data declares $PREBUFFER or $BUFFER. - [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; } - # Check the data declares $expected_region_highlight. - (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return 1; } + (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } - # Set sane defaults for ZLE variables - : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} + # Check the data declares $PREBUFFER or $BUFFER. + [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; } + # Check the data declares $expected_region_highlight. + (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return 1; } - # Process the data. - _zsh_highlight + # Set sane defaults for ZLE variables + : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} + + # Process the data. + _zsh_highlight + } + unset ARG if (( unsorted )); then region_highlight=("${(@n)region_highlight}") From bdb4e8b70e784e5149d7de9323074696653798cd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 17:06:32 +0000 Subject: [PATCH 213/297] test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight. --- tests/test-highlighting.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7d7ebb7..e8c36f5 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -212,6 +212,11 @@ run_test_internal() { details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY print -r -- "not ok $i - cardinality check - $details${todo:+ - }$todo" + paste \ + =(print -rC1 -- "expected_region_highlight" "${(qq)expected_region_highlight[@]}") \ + =(print -rC1 -- "region_highlight" "${(qq)region_highlight[@]}") \ + | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ + | sed 's/^/# /' fi fi } From 66021cf0f7fde00b3a4e29d514549fea5ea51b18 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 17:17:51 +0000 Subject: [PATCH 214/297] travis: Install bsdmainutils to provide column(1). See the last commit, bdb4e8b70e784e5149d7de9323074696653798cd test harness: When the cardinality check fails, pretty-print \$expected_region_highlight and \$region_highlight. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 39040f8..39dd445 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ env: - ZSH=4.3.12 - ZSH=4.3.11 -script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps && make test' +script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps bsdmainutils && make test' notifications: webhooks: From 63852df98339a3dd14f122ded3131c41d2fc1b05 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 18 Mar 2020 23:55:10 +0000 Subject: [PATCH 215/297] test harness: Fix $skip_test support, broken yesterday. It was broken by commit e6eea1f9b7e67136911536a2450c7130f44c0b04, "test harness: Don't leak options from test files to the test harness.". --- tests/test-highlighting.zsh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index e8c36f5..334c447 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -124,25 +124,26 @@ run_test_internal() { local -a expected_region_highlight region_highlight local ARG="$1" + local RETURN="" () { setopt localoptions . "$srcdir"/"$ARG" # WARNING: The remainder of this anonymous function will run with the test's options in effect - (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } + (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return ${RETURN:=0}; } # Check the data declares $PREBUFFER or $BUFFER. - [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; } + [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } # Check the data declares $expected_region_highlight. - (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return 1; } + (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return ${RETURN:=1}; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} # Process the data. _zsh_highlight - } + }; [[ -z $RETURN ]] || return $RETURN unset ARG if (( unsorted )); then From 9bdeb4aa4aa17cd5ad09557b5c1e3d3c75ebe6f0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 00:03:24 +0000 Subject: [PATCH 216/297] test harness: Remove a bogus check. We already declare $expected_region_highlight in run_test_internal(). Therefore, it will always be declared. --- tests/test-highlighting.zsh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 334c447..6f00378 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -135,8 +135,6 @@ run_test_internal() { # Check the data declares $PREBUFFER or $BUFFER. [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } - # Check the data declares $expected_region_highlight. - (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return ${RETURN:=1}; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} From c4bb260a3083f2cdb7dcf4a22147aeef8d801ae1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 00:16:09 +0000 Subject: [PATCH 217/297] test harness: Print the test name when $skip_test is set. --- tests/test-highlighting.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6f00378..a92d422 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -131,7 +131,11 @@ run_test_internal() { # WARNING: The remainder of this anonymous function will run with the test's options in effect - (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return ${RETURN:=0}; } + (( $#skip_test )) && { + print -r -- "1..0 # SKIP $skip_test" + print -r -- "## ${ARG:t:r}" + return ${RETURN:=0} + } # Check the data declares $PREBUFFER or $BUFFER. [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } From 3ff5bec82ebe6796d18dfda4f4e28d59ba5f394d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 00:37:21 +0000 Subject: [PATCH 218/297] test harness: Let tests fail early by exiting non-zero or by setting a flag. Fixes #609. --- tests/README.md | 8 ++++++-- tests/test-highlighting.zsh | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/README.md b/tests/README.md index 55fff8a..cb3d943 100644 --- a/tests/README.md +++ b/tests/README.md @@ -24,11 +24,15 @@ point will not fail the test), and `$todo` is used as the explanation. If a test sets `$skip_test` to a non-empty string, the test will be skipped with the provided string as the reason. -3. +3. +If a test sets `$fail_test` to a non-empty string, the test will be skipped +with the provided string as the reason. + +4. If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight` need not match the order in `$region_highlight`. -4. +5. Normally, tests fail if `$expected_region_highlight` and `$region_highlight` have different numbers of elements. To mark this check as expected to fail, tests may set `$expected_mismatch` to an explanation string (like `$todo`); diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a92d422..a707a32 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -118,7 +118,7 @@ run_test_internal() { builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! On ${(qq)1}: cd failed: $?"; return 1 } # Load the data and prepare checking it. - local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test unsorted=0 + local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET REPLY skip_test fail_test unsorted=0 local expected_mismatch local skip_mismatch local -a expected_region_highlight region_highlight @@ -127,9 +127,15 @@ run_test_internal() { local RETURN="" () { setopt localoptions - . "$srcdir"/"$ARG" # WARNING: The remainder of this anonymous function will run with the test's options in effect + if { ! . "$srcdir"/"$ARG" } || (( $#fail_test )); then + print -r -- "1..1" + print -r -- "## ${ARG:t:r}" + tap_escape $fail_test; fail_test=$REPLY + print -r -- "not ok 1 - failed setup: $fail_test" + return ${RETURN:=0} + fi (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test" From d6defe715afa04498b0dda4b1d8d5cad38bb9067 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 01:39:07 +0000 Subject: [PATCH 219/297] tests: Add a test for issue #705, concerning continuation lines. --- .../test-data/backslash-continuation2.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/backslash-continuation2.zsh diff --git a/highlighters/main/test-data/backslash-continuation2.zsh b/highlighters/main/test-data/backslash-continuation2.zsh new file mode 100644 index 0000000..2d8b509 --- /dev/null +++ b/highlighters/main/test-data/backslash-continuation2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'echo foo\\\nbar"baz"' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 18 default' # foo\\\nbar"baz" + '14 18 double-quoted-argument "issue #705"' # "baz" +) From dfc41123d757543f81971a694c787e10aa2e56a9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 02:30:58 +0000 Subject: [PATCH 220/297] tests: Fix the test added in the last commit. --- highlighters/main/test-data/backslash-continuation2.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/backslash-continuation2.zsh b/highlighters/main/test-data/backslash-continuation2.zsh index 2d8b509..9e2ca62 100644 --- a/highlighters/main/test-data/backslash-continuation2.zsh +++ b/highlighters/main/test-data/backslash-continuation2.zsh @@ -32,6 +32,6 @@ BUFFER=$'echo foo\\\nbar"baz"' expected_region_highlight=( '1 4 builtin' # echo - '6 18 default' # foo\\\nbar"baz" + '6 18 default "issue #705"' # foo\\\nbar"baz" '14 18 double-quoted-argument "issue #705"' # "baz" ) From 10171731f3d28e5de22f932ea212bb8cb4083dc1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 03:13:36 +0000 Subject: [PATCH 221/297] tests: Add a test for the "close file descriptor" and "coproc" redirection syntaxes Part of issue #645. --- .../test-data/redirection-special-cases.zsh | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 highlighters/main/test-data/redirection-special-cases.zsh diff --git a/highlighters/main/test-data/redirection-special-cases.zsh b/highlighters/main/test-data/redirection-special-cases.zsh new file mode 100644 index 0000000..d1348d5 --- /dev/null +++ b/highlighters/main/test-data/redirection-special-cases.zsh @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 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 +# ------------------------------------------------------------------------------------------------- + +# See xpandredir() in the zsh source. + +BUFFER=$'cat <&p; exec {myfd}>&-' + +expected_region_highlight=( + '1 3 command' # cat + '5 6 redirection' # <& + '7 7 redirection "issue #645 (in part)"' # p + '8 8 commandseparator' # ; + '10 13 precommand' # exec + '15 20 named-fd' # {myfd} + '21 22 redirection' # >& + '23 23 redirection "issue #645 (in part)"' # - +) From fdf23e06c754b791850a2a55a7f8dc6df964407a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 03:13:36 +0000 Subject: [PATCH 222/297] 'main': Support the "close file descriptor" and "coproc" redirection syntaxes Part of issue #645. --- highlighters/main/main-highlighter.zsh | 8 ++++++-- highlighters/main/test-data/redirection-special-cases.zsh | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5d4637b..45d13e2 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1287,8 +1287,12 @@ _zsh_highlight_main_highlighter_highlight_argument() done if (( path_eligible )); then - if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == <0-> ]]; then - base_style=numeric-fd + if (( in_redirection )) && [[ $last_arg == *['<>']['&'] && $arg[$1,-1] == (<0->|p|-) ]]; then + if [[ $arg[$1,-1] == (p|-) ]]; then + base_style=redirection + else + base_style=numeric-fd + fi elif _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then base_style=$REPLY _zsh_highlight_main_highlighter_highlight_path_separators $base_style diff --git a/highlighters/main/test-data/redirection-special-cases.zsh b/highlighters/main/test-data/redirection-special-cases.zsh index d1348d5..733cf6b 100644 --- a/highlighters/main/test-data/redirection-special-cases.zsh +++ b/highlighters/main/test-data/redirection-special-cases.zsh @@ -35,10 +35,10 @@ BUFFER=$'cat <&p; exec {myfd}>&-' expected_region_highlight=( '1 3 command' # cat '5 6 redirection' # <& - '7 7 redirection "issue #645 (in part)"' # p + '7 7 redirection' # p '8 8 commandseparator' # ; '10 13 precommand' # exec '15 20 named-fd' # {myfd} '21 22 redirection' # >& - '23 23 redirection "issue #645 (in part)"' # - + '23 23 redirection' # - ) From 90a92b2bb89b146217c6d29b784d9e840da7cd97 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:00:22 +0000 Subject: [PATCH 223/297] test harness: Fix an issue with the pretty-printed $expected_region_highlight/$region_highlight diffing. If the right column was longer, the excess entries were printed on the left column. --- tests/test-highlighting.zsh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a707a32..b20fcaa 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -221,11 +221,21 @@ run_test_internal() { details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY print -r -- "not ok $i - cardinality check - $details${todo:+ - }$todo" - paste \ - =(print -rC1 -- "expected_region_highlight" "${(qq)expected_region_highlight[@]}") \ - =(print -rC1 -- "region_highlight" "${(qq)region_highlight[@]}") \ - | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ - | sed 's/^/# /' + + () { + local -a left_column right_column + left_column=( "expected_region_highlight" "${(qq)expected_region_highlight[@]}" ) + right_column=( "region_highlight" "${(qq)region_highlight[@]}" ) + integer difference=$(( $#right_column - $#left_column )) + if (( difference > 0 )); then + left_column+=( ${(r:2*difference::. :):-} ) + fi + paste \ + =(print -rC1 -- $left_column) \ + =(print -rC1 -- $right_column) \ + | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ + | sed 's/^/# /' + } fi fi } From ea7c165b592f4a8b93a372113c600b3cfa36601e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:01:37 +0000 Subject: [PATCH 224/297] test harness: Rewrite the columnar pretty-printer without external tools. --- tests/test-highlighting.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b20fcaa..6b83dbf 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -230,10 +230,7 @@ run_test_internal() { if (( difference > 0 )); then left_column+=( ${(r:2*difference::. :):-} ) fi - paste \ - =(print -rC1 -- $left_column) \ - =(print -rC1 -- $right_column) \ - | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ + print -rC2 -- "${left_column[@]}" "${right_column[@]}" \ | sed 's/^/# /' } fi From 5a44d9f32a92eb3038632fc09aee72701c310c47 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 01:00:42 +0000 Subject: [PATCH 225/297] tests: Record current behaviour on global aliases. --- highlighters/main/test-data/global-alias1.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/global-alias1.zsh diff --git a/highlighters/main/test-data/global-alias1.zsh b/highlighters/main/test-data/global-alias1.zsh new file mode 100644 index 0000000..8a66776 --- /dev/null +++ b/highlighters/main/test-data/global-alias1.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +alias -g foo=bar + +BUFFER=$'foo foo' + +expected_region_highlight=( + '1 3 arg0_global' # foo + '5 7 default' # foo +) From 3c5f63d9592df3c544f96950d5b45ee3d96c7fc9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 01:06:00 +0000 Subject: [PATCH 226/297] 'main': Highlight global aliases --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 11 ++++++++++- highlighters/main/test-data/global-alias1.zsh | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 8f4ef4b..37e7d13 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -20,6 +20,7 @@ This highlighter defines the following styles: * `reserved-word` - shell reserved words (`if`, `for`) * `alias` - aliases * `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) +* `global-alias` - global aliases * `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`) * `function` - function names * `command` - command names diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 45d13e2..d3a0fb3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -33,6 +33,7 @@ : ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} : ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline} +: ${ZSH_HIGHLIGHT_STYLES[global-alias]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} @@ -106,6 +107,7 @@ _zsh_highlight_main_calculate_fallback() { local -A fallback_of; fallback_of=( alias arg0 suffix-alias arg0 + global-alias dollar-double-quoted-argument builtin arg0 function arg0 command arg0 @@ -178,7 +180,9 @@ _zsh_highlight_main__type() { if (( $+aliases[(e)$1] )); then may_cache=0 fi - if (( $+aliases[(e)$1] )) && (( aliases_allowed )); then + if false && (( ${+galiases[(e)$1]} )); then + REPLY='global alias' + elif (( $+aliases[(e)$1] )) && (( aliases_allowed )); then REPLY=alias elif [[ $1 == *.* && -n ${1%.*} ]] && (( $+saliases[(e)${1##*.}] )); then REPLY='suffix alias' @@ -930,6 +934,9 @@ _zsh_highlight_main_highlighter_highlight_list() ('suffix alias') style=suffix-alias ;; + ('global alias') + style=global-alias + ;; (alias) :;; (builtin) style=builtin [[ $arg == $'\x5b' ]] && braces_stack='Q'"$braces_stack" @@ -1014,6 +1021,8 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then next_word=':start::start_of_pipeline:' fi + elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position + style=global-alias else # $arg is a non-command word case $arg in ($'\x29') diff --git a/highlighters/main/test-data/global-alias1.zsh b/highlighters/main/test-data/global-alias1.zsh index 8a66776..0022de3 100644 --- a/highlighters/main/test-data/global-alias1.zsh +++ b/highlighters/main/test-data/global-alias1.zsh @@ -33,6 +33,6 @@ alias -g foo=bar BUFFER=$'foo foo' expected_region_highlight=( - '1 3 arg0_global' # foo - '5 7 default' # foo + '1 3 global-alias' # foo + '5 7 global-alias' # foo ) From 3d81c83132e8798e72590ee8d7e956558113e9c3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:11:21 +0000 Subject: [PATCH 227/297] travis: Remove bsdmainutils since column(1) has been removed, three commits ago. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 39dd445..39040f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ env: - ZSH=4.3.12 - ZSH=4.3.11 -script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps bsdmainutils && make test' +script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps && make test' notifications: webhooks: From 48dd47931a39558f40a49c05d6ee7d1d32b5358d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:13:17 +0000 Subject: [PATCH 228/297] changelog: Update through HEAD. --- changelog.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index ab5c445..9e7c5a4 100644 --- a/changelog.md +++ b/changelog.md @@ -36,7 +36,13 @@ [#583] - Fix `echo >&2` highlighting the `2` as a filename if a file by that name happened to exist - [#694] + [#694, part of #645] + +- Fix `echo >&-` highlighting the `-` as a filename if a file by that name happened to exist + [part of #645] + +- Fix `echo >&p` highlighting the `p` as a filename if a file by that name happened to exist + [part of #645] - Fix `: $((42))` being highlighted as a subshell. [part of #607] @@ -45,6 +51,12 @@ incorrectly highlighted as an arithmetic expansion. [#704] +- Fix wrong highlighting of unquoted parameter expansions under zsh 5.2 and older + [e165f18c758e] + +- Highlight global aliases + [#700] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From cfef4f3ae0d68d9b673d49816cc9c79597f21bfc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:13:46 +0000 Subject: [PATCH 229/297] 'main': Enable the zsh/parameter codepath of global aliases highlighting. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d3a0fb3..9454a2e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -180,7 +180,7 @@ _zsh_highlight_main__type() { if (( $+aliases[(e)$1] )); then may_cache=0 fi - if false && (( ${+galiases[(e)$1]} )); then + if (( ${+galiases[(e)$1]} )); then REPLY='global alias' elif (( $+aliases[(e)$1] )) && (( aliases_allowed )); then REPLY=alias From e2dddb91c6353e2f627f68b221673b6227d99ce6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:25:38 +0000 Subject: [PATCH 230/297] 'main': Add a regression test for parameters that expand to global aliases. Will be fixed in the next commit. --- .../test-data/parameter-to-global-alias.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/parameter-to-global-alias.zsh diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh new file mode 100644 index 0000000..665b881 --- /dev/null +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +alias -g x=y +local s=x + +BUFFER=$'$s' + +expected_region_highlight=( + '1 2 unknown-token "fixed in the next commit"' # $s +) From 08839bbd878becde3929b03ab37b34f730003eb4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 05:28:17 +0000 Subject: [PATCH 231/297] 'main': Let the type determination ignore global aliases when it ignores regular ones. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/parameter-to-global-alias.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9454a2e..dbb0df9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -180,7 +180,7 @@ _zsh_highlight_main__type() { if (( $+aliases[(e)$1] )); then may_cache=0 fi - if (( ${+galiases[(e)$1]} )); then + if (( ${+galiases[(e)$1]} )) && (( aliases_allowed )); then REPLY='global alias' elif (( $+aliases[(e)$1] )) && (( aliases_allowed )); then REPLY=alias diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh index 665b881..2c4b9bb 100644 --- a/highlighters/main/test-data/parameter-to-global-alias.zsh +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -34,5 +34,5 @@ local s=x BUFFER=$'$s' expected_region_highlight=( - '1 2 unknown-token "fixed in the next commit"' # $s + '1 2 unknown-token' # $s ) From 29ca0bc6c8016e94987392244bb607fb9d291c41 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Mar 2020 04:13:50 +0000 Subject: [PATCH 232/297] 'main': Highlight errors from the EQUALS option. Fixes #430. --- changelog.md | 3 ++ highlighters/main/main-highlighter.zsh | 5 ++++ highlighters/main/test-data/equals1.zsh | 36 +++++++++++++++++++++++ highlighters/main/test-data/equals2.zsh | 38 +++++++++++++++++++++++++ highlighters/main/test-data/equals3.zsh | 36 +++++++++++++++++++++++ highlighters/main/test-data/equals4.zsh | 36 +++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 highlighters/main/test-data/equals1.zsh create mode 100644 highlighters/main/test-data/equals2.zsh create mode 100644 highlighters/main/test-data/equals3.zsh create mode 100644 highlighters/main/test-data/equals4.zsh diff --git a/changelog.md b/changelog.md index 9e7c5a4..c75edb9 100644 --- a/changelog.md +++ b/changelog.md @@ -57,6 +57,9 @@ - Highlight global aliases [#700] +- Highlight `: =nosuchcommand' as an error (when the `EQUALS` option hasn't been unset). + [#430] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index dbb0df9..c44b1c3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1122,6 +1122,11 @@ _zsh_highlight_main_highlighter_check_path() REPLY=path + if [[ ${1[1]} == '=' && $1 == ??* && ${1[2]} != $'\x28' && $zsyh_user_options[equals] == 'on' && $expanded_path[1] != '/' ]]; then + REPLY=unknown-token # will error out if executed + return 0 + fi + [[ -z $expanded_path ]] && return 1 # Check if this is a blacklisted path diff --git a/highlighters/main/test-data/equals1.zsh b/highlighters/main/test-data/equals1.zsh new file mode 100644 index 0000000..77f46e8 --- /dev/null +++ b/highlighters/main/test-data/equals1.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': =ls' + +expected_region_highlight=( + '1 1 builtin' # : + '3 5 path' # =ls +) diff --git a/highlighters/main/test-data/equals2.zsh b/highlighters/main/test-data/equals2.zsh new file mode 100644 index 0000000..bd59ff7 --- /dev/null +++ b/highlighters/main/test-data/equals2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +unsetopt equals + +BUFFER=$': =nosuchcommand' + +expected_region_highlight=( + '1 1 builtin' # : + '3 16 default' # =nosuchcommand +) diff --git a/highlighters/main/test-data/equals3.zsh b/highlighters/main/test-data/equals3.zsh new file mode 100644 index 0000000..8c10789 --- /dev/null +++ b/highlighters/main/test-data/equals3.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': =nosuchcommand' + +expected_region_highlight=( + '1 1 builtin' # : + '3 16 unknown-token' # =nosuchcommand +) diff --git a/highlighters/main/test-data/equals4.zsh b/highlighters/main/test-data/equals4.zsh new file mode 100644 index 0000000..28bc214 --- /dev/null +++ b/highlighters/main/test-data/equals4.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': =' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 default' # = +) From c67372e96ca477bf87f36cdb501ffd4ca0897971 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 20:04:02 +0000 Subject: [PATCH 233/297] 'main': Add an XFail test for issue #202. --- .../plain-file-in-command-position.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/plain-file-in-command-position.zsh diff --git a/highlighters/main/test-data/plain-file-in-command-position.zsh b/highlighters/main/test-data/plain-file-in-command-position.zsh new file mode 100644 index 0000000..b16e43c --- /dev/null +++ b/highlighters/main/test-data/plain-file-in-command-position.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +touch foo +chmod -x foo +BUFFER=$'./foo; ./foo' + +expected_region_highlight=( + '1 5 unknown-token "issue #202"' # ./foo (in middle) + '6 6 commandseparator' # ; + '8 12 unknown-token "issue #202"' # ./foo (at end) +) From a6eb966d96f51fc611c2a5a04b4253033da492e0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 20:17:31 +0000 Subject: [PATCH 234/297] 'main': Extend tests to capture the current behaviour. The next commits will change this behaviour. --- .../abspath-in-command-position3.zsh | 6 ++- .../abspath-in-command-position3b.zsh | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/abspath-in-command-position3b.zsh diff --git a/highlighters/main/test-data/abspath-in-command-position3.zsh b/highlighters/main/test-data/abspath-in-command-position3.zsh index 9323ed7..6c89ddc 100644 --- a/highlighters/main/test-data/abspath-in-command-position3.zsh +++ b/highlighters/main/test-data/abspath-in-command-position3.zsh @@ -28,8 +28,10 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=$'/bin' +BUFFER=$'/bin; /bin' expected_region_highlight=( - '1 4 path' # /bin + '1 4 path' # /bin (in middle) + '5 5 commandseparator' # ; + '7 10 path' # /bin (at end) ) diff --git a/highlighters/main/test-data/abspath-in-command-position3b.zsh b/highlighters/main/test-data/abspath-in-command-position3b.zsh new file mode 100644 index 0000000..f75ad9e --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position3b.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +setopt autocd +BUFFER=$'/bin; /bin' + +expected_region_highlight=( + '1 4 path' # /bin (in middle) + '5 5 commandseparator' # ; + '7 10 path' # /bin (at end) +) From 5545fb9ab26bec2bfd861912c6abccf90e68fa07 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 20:06:13 +0000 Subject: [PATCH 235/297] 'main': In command position, do not highlight directories (unless AUTO_CD is set) and non-executable files. Fixes #202. Test expectations are updated. For example, BUFFER='/bin' is now highlighted as path_prefix because it's a prefix of '/bin/sh' which would be valid. However, BUFFER='/bin;' is now properly highlighted as an error (unless AUTO_CD is set). --- highlighters/main/main-highlighter.zsh | 43 +++++++++++++++---- .../abspath-in-command-position1.zsh | 2 +- .../abspath-in-command-position1b.zsh | 36 ++++++++++++++++ .../abspath-in-command-position3.zsh | 4 +- .../abspath-in-command-position3b.zsh | 4 +- .../main/test-data/path-dollared-word3.zsh | 4 +- .../main/test-data/path-dollared-word3b.zsh | 39 +++++++++++++++++ .../plain-file-in-command-position.zsh | 4 +- 8 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 highlighters/main/test-data/abspath-in-command-position1b.zsh create mode 100644 highlighters/main/test-data/path-dollared-word3b.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c44b1c3..b7c1bf0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1006,7 +1006,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main__stack_pop 'R' reserved-word else - if _zsh_highlight_main_highlighter_check_path $arg; then + if _zsh_highlight_main_highlighter_check_path $arg 1; then style=$REPLY else style=unknown-token @@ -1115,12 +1115,19 @@ _zsh_highlight_main_highlighter_highlight_path_separators() # Check if $1 is a path. # If yes, return 0 and in $REPLY the style to use. # Else, return non-zero (and the contents of $REPLY is undefined). +# +# $2 should be non-zero iff we're in command position. _zsh_highlight_main_highlighter_check_path() { _zsh_highlight_main_highlighter_expand_path "$1" local expanded_path="$REPLY" tmp_path + integer in_command_position=$2 - REPLY=path + if (( in_command_position )); then + REPLY=arg0 + else + REPLY=path + fi if [[ ${1[1]} == '=' && $1 == ??* && ${1[2]} != $'\x28' && $zsyh_user_options[equals] == 'on' && $expanded_path[1] != '/' ]]; then REPLY=unknown-token # will error out if executed @@ -1142,15 +1149,23 @@ _zsh_highlight_main_highlighter_check_path() tmp_path=$tmp_path:h done - [[ -L $expanded_path ]] && return 0 - [[ -e $expanded_path ]] && return 0 + if (( in_command_position )); then + if [[ -x $expanded_path ]] && [[ $zsyh_user_options[autocd] == on || ! -d $expanded_path ]]; then + return 0 + fi + else + if [[ -L $expanded_path || -e $expanded_path ]]; then + return 0 + fi + fi # Search the path in CDPATH - if [[ $expanded_path != /* ]]; then - local cdpath_dir + if [[ $expanded_path != /* ]] && + { (( ! in_command_position )) || [[ $zsyh_user_options[autocd] == on ]] }; then # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. + local cdpath_dir for cdpath_dir in $cdpath ; do - [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 + [[ -d "$cdpath_dir/$expanded_path" && -x "$cdpath_dir/$expanded_path" ]] && return 0 done fi @@ -1162,7 +1177,14 @@ _zsh_highlight_main_highlighter_check_path() [[ $WIDGET != zle-line-finish ]]; then # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local -a tmp - tmp=( ${expanded_path}*(N) ) + if (( in_command_position )); then + # We include directories even when autocd is enabled, because those + # directories might contain executable files: e.g., BUFFER="/bi" en route + # to typing "/bin/sh". + tmp=( ${expanded_path}*(N-*,N-/) ) + else + tmp=( ${expanded_path}*(N) ) + fi (( ${+tmp[1]} )) && REPLY=path_prefix && return 0 fi @@ -1173,6 +1195,8 @@ _zsh_highlight_main_highlighter_check_path() # Highlight an argument and possibly special chars in quotes starting at $1 in $arg # This command will at least highlight $1 to end_pos with the default style # If $2 is set to 0, the argument cannot be highlighted as an option. +# +# This function currently assumes it's never called for the command word. _zsh_highlight_main_highlighter_highlight_argument() { local base_style=default i=$1 option_eligible=${2:-1} path_eligible=1 ret start style @@ -1307,7 +1331,8 @@ _zsh_highlight_main_highlighter_highlight_argument() else base_style=numeric-fd fi - elif _zsh_highlight_main_highlighter_check_path $arg[$1,-1]; then + # This function is currently never called for the command word, so $2 is hard-coded as 0. + elif _zsh_highlight_main_highlighter_check_path $arg[$1,-1] 0; then base_style=$REPLY _zsh_highlight_main_highlighter_highlight_path_separators $base_style highlights+=($reply) diff --git a/highlighters/main/test-data/abspath-in-command-position1.zsh b/highlighters/main/test-data/abspath-in-command-position1.zsh index 75140d2..cfc12a5 100644 --- a/highlighters/main/test-data/abspath-in-command-position1.zsh +++ b/highlighters/main/test-data/abspath-in-command-position1.zsh @@ -31,5 +31,5 @@ BUFFER=$'/' expected_region_highlight=( - '1 1 path' # / + '1 1 path_prefix' # / ) diff --git a/highlighters/main/test-data/abspath-in-command-position1b.zsh b/highlighters/main/test-data/abspath-in-command-position1b.zsh new file mode 100644 index 0000000..82292ed --- /dev/null +++ b/highlighters/main/test-data/abspath-in-command-position1b.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +setopt autocd +BUFFER=$'/' + +expected_region_highlight=( + '1 1 arg0' # / +) diff --git a/highlighters/main/test-data/abspath-in-command-position3.zsh b/highlighters/main/test-data/abspath-in-command-position3.zsh index 6c89ddc..415e316 100644 --- a/highlighters/main/test-data/abspath-in-command-position3.zsh +++ b/highlighters/main/test-data/abspath-in-command-position3.zsh @@ -31,7 +31,7 @@ BUFFER=$'/bin; /bin' expected_region_highlight=( - '1 4 path' # /bin (in middle) + '1 4 unknown-token' # /bin (in middle) '5 5 commandseparator' # ; - '7 10 path' # /bin (at end) + '7 10 path_prefix' # /bin (at end) ) diff --git a/highlighters/main/test-data/abspath-in-command-position3b.zsh b/highlighters/main/test-data/abspath-in-command-position3b.zsh index f75ad9e..e43b7fb 100644 --- a/highlighters/main/test-data/abspath-in-command-position3b.zsh +++ b/highlighters/main/test-data/abspath-in-command-position3b.zsh @@ -32,7 +32,7 @@ setopt autocd BUFFER=$'/bin; /bin' expected_region_highlight=( - '1 4 path' # /bin (in middle) + '1 4 arg0' # /bin (in middle) '5 5 commandseparator' # ; - '7 10 path' # /bin (at end) + '7 10 arg0' # /bin (at end) ) diff --git a/highlighters/main/test-data/path-dollared-word3.zsh b/highlighters/main/test-data/path-dollared-word3.zsh index 6921cba..ec981b1 100644 --- a/highlighters/main/test-data/path-dollared-word3.zsh +++ b/highlighters/main/test-data/path-dollared-word3.zsh @@ -34,7 +34,7 @@ BUFFER='$PWD; ${PWD}' expected_region_highlight=( - "1 4 path" # $PWD + "1 4 unknown-token" # $PWD (without AUTO_CD) "5 5 commandseparator" # ; - "7 12 path" # ${PWD} + "7 12 path_prefix" # ${PWD} ) diff --git a/highlighters/main/test-data/path-dollared-word3b.zsh b/highlighters/main/test-data/path-dollared-word3b.zsh new file mode 100644 index 0000000..7c904f3 --- /dev/null +++ b/highlighters/main/test-data/path-dollared-word3b.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +setopt autocd + +BUFFER=$'$PWD; ${PWD}' + +expected_region_highlight=( + '1 4 arg0' # $PWD + '5 5 commandseparator' # ; + '7 12 arg0' # ${PWD} +) diff --git a/highlighters/main/test-data/plain-file-in-command-position.zsh b/highlighters/main/test-data/plain-file-in-command-position.zsh index b16e43c..141ffac 100644 --- a/highlighters/main/test-data/plain-file-in-command-position.zsh +++ b/highlighters/main/test-data/plain-file-in-command-position.zsh @@ -33,7 +33,7 @@ chmod -x foo BUFFER=$'./foo; ./foo' expected_region_highlight=( - '1 5 unknown-token "issue #202"' # ./foo (in middle) + '1 5 unknown-token' # ./foo (in middle) '6 6 commandseparator' # ; - '8 12 unknown-token "issue #202"' # ./foo (at end) + '8 12 unknown-token' # ./foo (at end) ) From 3f930fb0c171785155a3353c50a9e937799e48a2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 20:28:14 +0000 Subject: [PATCH 236/297] 'main': Add an auxiliary variable for readability. --- highlighters/main/main-highlighter.zsh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b7c1bf0..05ff2ff 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1123,6 +1123,12 @@ _zsh_highlight_main_highlighter_check_path() local expanded_path="$REPLY" tmp_path integer in_command_position=$2 + if [[ $zsyh_user_options[autocd] == on ]]; then + integer autocd=1 + else + integer autocd=0 + fi + if (( in_command_position )); then REPLY=arg0 else @@ -1150,7 +1156,7 @@ _zsh_highlight_main_highlighter_check_path() done if (( in_command_position )); then - if [[ -x $expanded_path ]] && [[ $zsyh_user_options[autocd] == on || ! -d $expanded_path ]]; then + if [[ -x $expanded_path ]] && { (( autocd )) || [[ ! -d $expanded_path ]] }; then return 0 fi else @@ -1160,8 +1166,7 @@ _zsh_highlight_main_highlighter_check_path() fi # Search the path in CDPATH - if [[ $expanded_path != /* ]] && - { (( ! in_command_position )) || [[ $zsyh_user_options[autocd] == on ]] }; then + if [[ $expanded_path != /* ]] && (( autocd || ! in_command_position )); then # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local cdpath_dir for cdpath_dir in $cdpath ; do From 83ac855cebd1b781ba75ea306a251672d49697fc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 20:17:59 +0000 Subject: [PATCH 237/297] 'main': Let AUTO_CD directories be highlighted with their own style. --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 23 ++++++++++++++++--- .../abspath-in-command-position1b.zsh | 2 +- .../abspath-in-command-position3b.zsh | 4 ++-- .../main/test-data/path-dollared-word3b.zsh | 5 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 37e7d13..5eec335 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -27,6 +27,7 @@ This highlighter defines the following styles: * `precommand` - precommand modifiers (e.g., `noglob`, `builtin`) * `commandseparator` - command separation tokens (`;`, `&&`) * `hashed-command` - hashed commands +* `autodirectory` - a directory name in command position when the `AUTO_CD` option is set * `path` - existing filenames * `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default) * `path_prefix` - prefixes of existing filenames diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 05ff2ff..0222160 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -36,6 +36,7 @@ : ${ZSH_HIGHLIGHT_STYLES[global-alias]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} +: ${ZSH_HIGHLIGHT_STYLES[autodirectory]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=} @@ -113,6 +114,7 @@ _zsh_highlight_main_calculate_fallback() { command arg0 precommand arg0 hashed-command arg0 + autodirectory arg0 arg0_\* arg0 # TODO: Maybe these? — @@ -1130,6 +1132,8 @@ _zsh_highlight_main_highlighter_check_path() fi if (( in_command_position )); then + # ### Currently, this value is never returned: either it's overwritten + # ### below, or the return code is non-zero REPLY=arg0 else REPLY=path @@ -1156,8 +1160,16 @@ _zsh_highlight_main_highlighter_check_path() done if (( in_command_position )); then - if [[ -x $expanded_path ]] && { (( autocd )) || [[ ! -d $expanded_path ]] }; then - return 0 + if [[ -x $expanded_path ]]; then + if (( autocd )); then + if [[ -d $expanded_path ]]; then + REPLY=autodirectory + fi + return 0 + elif [[ ! -d $expanded_path ]]; then + # ### This seems unreachable for the current callers + return 0 + fi fi else if [[ -L $expanded_path || -e $expanded_path ]]; then @@ -1170,7 +1182,12 @@ _zsh_highlight_main_highlighter_check_path() # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local cdpath_dir for cdpath_dir in $cdpath ; do - [[ -d "$cdpath_dir/$expanded_path" && -x "$cdpath_dir/$expanded_path" ]] && return 0 + if [[ -d "$cdpath_dir/$expanded_path" && -x "$cdpath_dir/$expanded_path" ]]; then + if (( in_command_position && autocd )); then + REPLY=autodirectory + fi + return 0 + fi done fi diff --git a/highlighters/main/test-data/abspath-in-command-position1b.zsh b/highlighters/main/test-data/abspath-in-command-position1b.zsh index 82292ed..88fe60c 100644 --- a/highlighters/main/test-data/abspath-in-command-position1b.zsh +++ b/highlighters/main/test-data/abspath-in-command-position1b.zsh @@ -32,5 +32,5 @@ setopt autocd BUFFER=$'/' expected_region_highlight=( - '1 1 arg0' # / + '1 1 autodirectory' # / ) diff --git a/highlighters/main/test-data/abspath-in-command-position3b.zsh b/highlighters/main/test-data/abspath-in-command-position3b.zsh index e43b7fb..0e65c98 100644 --- a/highlighters/main/test-data/abspath-in-command-position3b.zsh +++ b/highlighters/main/test-data/abspath-in-command-position3b.zsh @@ -32,7 +32,7 @@ setopt autocd BUFFER=$'/bin; /bin' expected_region_highlight=( - '1 4 arg0' # /bin (in middle) + '1 4 autodirectory' # /bin (in middle) '5 5 commandseparator' # ; - '7 10 arg0' # /bin (at end) + '7 10 autodirectory' # /bin (at end) ) diff --git a/highlighters/main/test-data/path-dollared-word3b.zsh b/highlighters/main/test-data/path-dollared-word3b.zsh index 7c904f3..72a2f7c 100644 --- a/highlighters/main/test-data/path-dollared-word3b.zsh +++ b/highlighters/main/test-data/path-dollared-word3b.zsh @@ -29,11 +29,10 @@ # ------------------------------------------------------------------------------------------------- setopt autocd - BUFFER=$'$PWD; ${PWD}' expected_region_highlight=( - '1 4 arg0' # $PWD + '1 4 autodirectory' # $PWD '5 5 commandseparator' # ; - '7 12 arg0' # ${PWD} + '7 12 autodirectory' # ${PWD} ) From 81842663388e6dfb18e8e85c24c0ff532706513b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 21:44:31 +0000 Subject: [PATCH 238/297] 'main': Add a test for aliases to AUTO_CD directories. --- .../main/test-data/alias-to-dir1b.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/alias-to-dir1b.zsh diff --git a/highlighters/main/test-data/alias-to-dir1b.zsh b/highlighters/main/test-data/alias-to-dir1b.zsh new file mode 100644 index 0000000..62ec521 --- /dev/null +++ b/highlighters/main/test-data/alias-to-dir1b.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +setopt autocd +alias x=/ +BUFFER=$'x' + +expected_region_highlight=( + '1 1 alias' # x +) From f2726d0464a554a874d8e257c9d97a0a0db2a2a2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 21:45:50 +0000 Subject: [PATCH 239/297] 'main': Don't consider path_prefix in alias expansions. --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/alias-to-dir.zsh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0222160..d6c3f23 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1196,6 +1196,7 @@ _zsh_highlight_main_highlighter_check_path() # If this word ends the buffer, check if it's the prefix of a valid path. if (( has_end && (len == end_pos) )) && + (( ! in_alias )) && [[ $WIDGET != zle-line-finish ]]; then # TODO: When we've dropped support for pre-5.0.6 zsh, use the *(Y1) glob qualifier here. local -a tmp diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh index bfa6e07..30390d4 100644 --- a/highlighters/main/test-data/alias-to-dir.zsh +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -32,5 +32,5 @@ alias x=/ BUFFER=$'x' expected_region_highlight=( - '1 1 unknown-token "issue #668"' # x (/) + '1 1 unknown-token' # x (/) ) From c7229a000a2ecfd7fedf845390f1fa41a3a5fd0c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 06:41:38 +0000 Subject: [PATCH 240/297] tests: Test that global qualifiers and command substitutions aren't evaluated. Fixes #504. --- highlighters/main/test-data/meta-no-eval1.zsh | 49 +++++++++++++++++++ highlighters/main/test-data/meta-no-eval2.zsh | 40 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 highlighters/main/test-data/meta-no-eval1.zsh create mode 100644 highlighters/main/test-data/meta-no-eval2.zsh diff --git a/highlighters/main/test-data/meta-no-eval1.zsh b/highlighters/main/test-data/meta-no-eval1.zsh new file mode 100644 index 0000000..bb04077 --- /dev/null +++ b/highlighters/main/test-data/meta-no-eval1.zsh @@ -0,0 +1,49 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(kill -9 $$) ${:-$(kill -9 $$)}' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # $(kill -9 $$) + '3 15 command-substitution-unquoted' # $(kill -9 $$) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 8 builtin' # kill + '10 11 single-hyphen-option' # -9 + '13 14 default' # $$ + '15 15 command-substitution-delimiter-unquoted' # ) + '17 34 default' # ${:-$(kill -9 $$)} + '21 33 command-substitution-unquoted' # $(kill -9 $$) + '21 22 command-substitution-delimiter-unquoted' # $( + '23 26 builtin' # kill + '28 29 single-hyphen-option' # -9 + '31 32 default' # $$ + '33 33 command-substitution-delimiter-unquoted' # ) +) diff --git a/highlighters/main/test-data/meta-no-eval2.zsh b/highlighters/main/test-data/meta-no-eval2.zsh new file mode 100644 index 0000000..61ef089 --- /dev/null +++ b/highlighters/main/test-data/meta-no-eval2.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +# We aren't testing how this is highlighted; we're testing that it's not +# evaluated. If it gets evaluated, the test suite will die. +BUFFER=$': /(e*exit 42*)' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # /(e*exit 42*) + '6 6 globbing' # * + '14 14 globbing' # * +) From bd9094cc6132ce4d56ad4dd587cf3970eba59a95 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 06:44:12 +0000 Subject: [PATCH 241/297] tests: Add a test for issue #498, which has already been fixed. --- .../main/test-data/assign-invalid-command.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/assign-invalid-command.zsh diff --git a/highlighters/main/test-data/assign-invalid-command.zsh b/highlighters/main/test-data/assign-invalid-command.zsh new file mode 100644 index 0000000..557327e --- /dev/null +++ b/highlighters/main/test-data/assign-invalid-command.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'x=y nosuchcommand' + +expected_region_highlight=( + '1 3 assign' # x=y + '3 3 default' # y + '5 17 unknown-token' # nosuchcommand +) From b0af27f25fff69a7d27798453d8a4cdd910bad03 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 06:49:40 +0000 Subject: [PATCH 242/297] tests: Add a unit test for a path specified with mixed quoting. Fixes #475. --- .../main/test-data/path-mixed-quoting.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/path-mixed-quoting.zsh diff --git a/highlighters/main/test-data/path-mixed-quoting.zsh b/highlighters/main/test-data/path-mixed-quoting.zsh new file mode 100644 index 0000000..cbd0b38 --- /dev/null +++ b/highlighters/main/test-data/path-mixed-quoting.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +touch foo + +BUFFER=$': \'f\'oo' + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 path' # \'f\'oo + '3 5 single-quoted-argument' # \'f\' +) From 3e7745ef30fb5d51b0f6fc81814e9c10beb3b73e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 19:15:21 +0000 Subject: [PATCH 243/297] test harness: Stringify values in a more readable manner. (q-) passes through newlines and NUL bytes verbatim. Using (qqqq) ensures the escaped string will be on a single line (as required by the TAP format) and be readable even if it contains control characters. --- tests/test-highlighting.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6b83dbf..e03287f 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -95,9 +95,9 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) typeset_p() { for 1 ; do if [[ ${(tP)1} == *array* ]]; then - print -r -- "$1=( ${(@q-P)1} )" + print -r -- "$1=( ${(@qqqqP)1} )" else - print -r -- "$1=${(q-P)1}" + print -r -- "$1=${(qqqqP)1}" fi done } From 9e9885253adce1e7a4c77d56d6cc4f3fc24986b9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 19:17:41 +0000 Subject: [PATCH 244/297] test harness: Output the time information to the same place the test name was printed to. --- tests/test-perfs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index a032978..2b003fc 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -73,7 +73,7 @@ run_test_internal() { # Measure the time taken by _zsh_highlight. TIMEFMT="%*Es" - time (BUFFER="$BUFFER" && _zsh_highlight) + { time (BUFFER="$BUFFER" && _zsh_highlight) } 2>&1 } run_test() { From f54d829f03998ba38adbb2255bbee82d424638d4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 19:43:12 +0000 Subject: [PATCH 245/297] tests: Add tests for issue #461. --- .../test-data/assignment-before-resword1.zsh | 40 +++++++++++++++++++ .../test-data/assignment-before-resword2.zsh | 40 +++++++++++++++++++ .../test-data/assignment-before-resword3.zsh | 38 ++++++++++++++++++ .../test-data/assignment-before-resword4.zsh | 40 +++++++++++++++++++ .../test-data/assignment-before-resword5.zsh | 38 ++++++++++++++++++ 5 files changed, 196 insertions(+) create mode 100644 highlighters/main/test-data/assignment-before-resword1.zsh create mode 100644 highlighters/main/test-data/assignment-before-resword2.zsh create mode 100644 highlighters/main/test-data/assignment-before-resword3.zsh create mode 100644 highlighters/main/test-data/assignment-before-resword4.zsh create mode 100644 highlighters/main/test-data/assignment-before-resword5.zsh diff --git a/highlighters/main/test-data/assignment-before-resword1.zsh b/highlighters/main/test-data/assignment-before-resword1.zsh new file mode 100644 index 0000000..eb4a0c6 --- /dev/null +++ b/highlighters/main/test-data/assignment-before-resword1.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar { :; }' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 9 unknown-token "issue #461"' # { + '11 11 builtin' # : + '12 12 commandseparator' # ; + '14 14 reserved-word' # } +) diff --git a/highlighters/main/test-data/assignment-before-resword2.zsh b/highlighters/main/test-data/assignment-before-resword2.zsh new file mode 100644 index 0000000..5324a66 --- /dev/null +++ b/highlighters/main/test-data/assignment-before-resword2.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar ( :; )' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 9 unknown-token "issue #461"' # ( + '11 11 builtin' # : + '12 12 commandseparator' # ; + '14 14 reserved-word' # ) +) diff --git a/highlighters/main/test-data/assignment-before-resword3.zsh b/highlighters/main/test-data/assignment-before-resword3.zsh new file mode 100644 index 0000000..09a8f04 --- /dev/null +++ b/highlighters/main/test-data/assignment-before-resword3.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar (( foo ))' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 10 unknown-token "issue #461"' # (( + '16 17 reserved-word' # )) +) diff --git a/highlighters/main/test-data/assignment-before-resword4.zsh b/highlighters/main/test-data/assignment-before-resword4.zsh new file mode 100644 index 0000000..c0083cb --- /dev/null +++ b/highlighters/main/test-data/assignment-before-resword4.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar [[ -n foo ]]' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 10 unknown-token "issue #461"' # [[ + '12 13 single-hyphen-option' # -n + '15 17 default' # foo + '19 20 reserved-word' # ]] +) diff --git a/highlighters/main/test-data/assignment-before-resword5.zsh b/highlighters/main/test-data/assignment-before-resword5.zsh new file mode 100644 index 0000000..33f1ed1 --- /dev/null +++ b/highlighters/main/test-data/assignment-before-resword5.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2017 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'foo=bar \! :' + +expected_region_highlight=( + '1 7 assign' # foo=bar + '5 7 default' # bar + '9 9 unknown-token' # \! + '11 11 builtin' # : +) From b44964c5453324ec1aa71344572853147e995629 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 19:45:02 +0000 Subject: [PATCH 246/297] 'main': Highlight reserved words following assignments as errors. Fixes #461. --- changelog.md | 3 +++ highlighters/main/main-highlighter.zsh | 11 ++++++++++- .../main/test-data/assignment-before-resword1.zsh | 2 +- .../main/test-data/assignment-before-resword2.zsh | 4 ++-- .../main/test-data/assignment-before-resword3.zsh | 3 +-- .../main/test-data/assignment-before-resword4.zsh | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index c75edb9..c89e362 100644 --- a/changelog.md +++ b/changelog.md @@ -60,6 +60,9 @@ - Highlight `: =nosuchcommand' as an error (when the `EQUALS` option hasn't been unset). [#430] +- Highlight reserved word after assignments as errors (e.g., `foo=bar (ls;)`) + [#461] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c44b1c3..8f0f24b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -431,7 +431,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Usually 'alias' but set to 'unknown-token' if any word expanded from # the alias would be highlighted as unknown-token # param_style is analogous for parameter expansions - local alias_style param_style last_arg arg buf=$4 highlight_glob=true style + local alias_style param_style last_arg arg buf=$4 highlight_glob=true saw_assignment=false style local in_array_assignment=false # true between 'a=(' and the matching ')' # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. @@ -556,6 +556,7 @@ _zsh_highlight_main_highlighter_highlight_list() # $style how to highlight $arg # $in_array_assignment boolean flag for "between '(' and ')' of array assignment" # $highlight_glob boolean flag for "'noglob' is in effect" + # $saw_assignment boolean flag for "was preceded by an assignment" # style=unknown-token if [[ $this_word == *':start:'* ]]; then @@ -826,6 +827,7 @@ _zsh_highlight_main_highlighter_highlight_list() else next_word=':start:' highlight_glob=true + saw_assignment=false if [[ $arg != '|' && $arg != '|&' ]]; then next_word+=':start_of_pipeline:' fi @@ -835,6 +837,7 @@ _zsh_highlight_main_highlighter_highlight_list() # try-always construct style=reserved-word # de facto a reserved word, although not de jure highlight_glob=true + saw_assignment=false next_word=':start::start_of_pipeline:' # only left brace is allowed, apparently elif ! (( in_redirection)) && [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then @@ -930,6 +933,9 @@ _zsh_highlight_main_highlighter_highlight_list() fi ;; esac + if $saw_assignment && [[ $style != unknown-token ]]; then + style=unknown-token + fi ;; ('suffix alias') style=suffix-alias @@ -947,6 +953,7 @@ _zsh_highlight_main_highlighter_highlight_list() (none) if (( ! in_param )) && _zsh_highlight_main_highlighter_check_assign; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign local i=$(( arg[(i)=] + 1 )) + saw_assignment=true if [[ $arg[i] == '(' ]]; then in_array_assignment=true else @@ -972,6 +979,7 @@ _zsh_highlight_main_highlighter_highlight_list() [[ $arg[0,1] == $histchars[2,2] ]]; then style=history-expansion elif (( ! in_param )) && + ! $saw_assignment && [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # @@ -992,6 +1000,7 @@ _zsh_highlight_main_highlighter_highlight_list() # anonymous function style=reserved-word elif (( ! in_param )) && + ! $saw_assignment && [[ $arg == $'\x28' ]]; then # subshell style=reserved-word diff --git a/highlighters/main/test-data/assignment-before-resword1.zsh b/highlighters/main/test-data/assignment-before-resword1.zsh index eb4a0c6..b271d4a 100644 --- a/highlighters/main/test-data/assignment-before-resword1.zsh +++ b/highlighters/main/test-data/assignment-before-resword1.zsh @@ -33,7 +33,7 @@ BUFFER=$'foo=bar { :; }' expected_region_highlight=( '1 7 assign' # foo=bar '5 7 default' # bar - '9 9 unknown-token "issue #461"' # { + '9 9 unknown-token' # { '11 11 builtin' # : '12 12 commandseparator' # ; '14 14 reserved-word' # } diff --git a/highlighters/main/test-data/assignment-before-resword2.zsh b/highlighters/main/test-data/assignment-before-resword2.zsh index 5324a66..247e41e 100644 --- a/highlighters/main/test-data/assignment-before-resword2.zsh +++ b/highlighters/main/test-data/assignment-before-resword2.zsh @@ -33,8 +33,8 @@ BUFFER=$'foo=bar ( :; )' expected_region_highlight=( '1 7 assign' # foo=bar '5 7 default' # bar - '9 9 unknown-token "issue #461"' # ( + '9 9 unknown-token' # ( '11 11 builtin' # : '12 12 commandseparator' # ; - '14 14 reserved-word' # ) + '14 14 unknown-token' # ) ) diff --git a/highlighters/main/test-data/assignment-before-resword3.zsh b/highlighters/main/test-data/assignment-before-resword3.zsh index 09a8f04..5204189 100644 --- a/highlighters/main/test-data/assignment-before-resword3.zsh +++ b/highlighters/main/test-data/assignment-before-resword3.zsh @@ -33,6 +33,5 @@ BUFFER=$'foo=bar (( foo ))' expected_region_highlight=( '1 7 assign' # foo=bar '5 7 default' # bar - '9 10 unknown-token "issue #461"' # (( - '16 17 reserved-word' # )) + '9 17 unknown-token' # (( foo )) ) diff --git a/highlighters/main/test-data/assignment-before-resword4.zsh b/highlighters/main/test-data/assignment-before-resword4.zsh index c0083cb..cc3d523 100644 --- a/highlighters/main/test-data/assignment-before-resword4.zsh +++ b/highlighters/main/test-data/assignment-before-resword4.zsh @@ -33,7 +33,7 @@ BUFFER=$'foo=bar [[ -n foo ]]' expected_region_highlight=( '1 7 assign' # foo=bar '5 7 default' # bar - '9 10 unknown-token "issue #461"' # [[ + '9 10 unknown-token' # [[ '12 13 single-hyphen-option' # -n '15 17 default' # foo '19 20 reserved-word' # ]] From 1000da306a1e7e4852573ff6268860d9bde814d9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 20:16:43 +0000 Subject: [PATCH 247/297] =?UTF-8?q?'main':=20Correctly=20highlight=20'&&'?= =?UTF-8?q?=20and=20'||'=20inside=20'[[=20=E2=80=A6=20]]'=20conditions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 2 ++ highlighters/main/main-highlighter.zsh | 3 +- highlighters/main/test-data/dinbrack1.zsh | 41 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/dinbrack1.zsh diff --git a/changelog.md b/changelog.md index c89e362..3ccc449 100644 --- a/changelog.md +++ b/changelog.md @@ -63,6 +63,8 @@ - Highlight reserved word after assignments as errors (e.g., `foo=bar (ls;)`) [#461] +- Correctly highlight `[[ foo && bar || baz ]]`. + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8f0f24b..deee67e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -790,7 +790,8 @@ _zsh_highlight_main_highlighter_highlight_list() fi # The Great Fork: is this a command word? Is this a non-command word? - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && + [[ $braces_stack != *T* || $arg != ('||'|'&&') ]]; then # First, determine the style of the command separator itself. if _zsh_highlight_main__stack_pop T || _zsh_highlight_main__stack_pop Q; then diff --git a/highlighters/main/test-data/dinbrack1.zsh b/highlighters/main/test-data/dinbrack1.zsh new file mode 100644 index 0000000..e2279d6 --- /dev/null +++ b/highlighters/main/test-data/dinbrack1.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'[[ foo && bar || baz ]]' + +expected_region_highlight=( + '1 2 reserved-word' # [[ + '4 6 default' # foo + '8 9 default' # && + '11 13 default' # bar + '15 16 default' # || + '18 20 default' # baz + '22 23 reserved-word' # ]] +) From 8eaa41431d6fe4def9905a3029a456fad4177c18 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 21:25:49 +0000 Subject: [PATCH 248/297] changelog: Update through HEAD. --- changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index 3ccc449..d975a76 100644 --- a/changelog.md +++ b/changelog.md @@ -65,6 +65,12 @@ - Correctly highlight `[[ foo && bar || baz ]]`. +- Highlight non-executable files in command position correctly (e.g., `% /etc/passwd`) + [#202, #669] + +- Highlight directories in command position correctly, including `AUTO_CD` support + [#669] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From d5d2f22013e673b3395373aa8a5df59ed0d94972 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 22:39:30 +0000 Subject: [PATCH 249/297] Revert "test harness: Rewrite the columnar pretty-printer without external tools." and "travis: Remove bsdmainutils since column(1) has been removed, three commits ago." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commits ea7c165b592f4a8b93a372113c600b3cfa36601e and 3d81c83132e8798e72590ee8d7e956558113e9c3. When "have 6 expectations and 4 region_highlight entries", the pure-zsh implementation printed them as follows: not ok 7 - cardinality check - have 6 expectations and 4 region_highlight entries: «expected_region_highlight=( $'1 1 builtin' $'3 6 comment' $'8 13 comment' $'15 15 default' $'16 21 comment' $'22 22 default' )» «region_highlight=( $'0 1 builtin' $'2 6 comment' $'7 13 comment' $'14 22 default' )» # expected_region_highlight '22 22 default' # '1 1 builtin' region_highlight # '3 6 comment' '0 1 builtin' # '8 13 comment' '2 6 comment' # '15 15 default' '7 13 comment' # '16 21 comment' '14 22 default' Whereas the column(1)-based implementation prints them as follows: not ok 7 - cardinality check - have 6 expectations and 4 region_highlight entries: «expected_region_highlight=( $'1 1 builtin' $'3 6 comment' $'8 13 comment' $'15 15 default' $'16 21 comment' $'22 22 default' )» «region_highlight=( $'0 1 builtin' $'2 6 comment' $'7 13 comment' $'14 22 default' )» # expected_region_highlight region_highlight # '1 1 builtin' '0 1 builtin' # '3 6 comment' '2 6 comment' # '8 13 comment' '7 13 comment' # '15 15 default' '14 22 default' # '16 21 comment' # '22 22 default' Ultimately, this difference is down to the pure-zsh implementation getting the arguments as a single list, whereas paste(1) gets two separate lists. --- .travis.yml | 2 +- tests/test-highlighting.zsh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39040f8..39dd445 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ env: - ZSH=4.3.12 - ZSH=4.3.11 -script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps && make test' +script: docker run -v $PWD:/work -w /work zshusers/zsh:${ZSH} /bin/sh -c 'install_packages make procps bsdmainutils && make test' notifications: webhooks: diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index e03287f..d12b44c 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -230,7 +230,10 @@ run_test_internal() { if (( difference > 0 )); then left_column+=( ${(r:2*difference::. :):-} ) fi - print -rC2 -- "${left_column[@]}" "${right_column[@]}" \ + paste \ + =(print -rC1 -- $left_column) \ + =(print -rC1 -- $right_column) \ + | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ | sed 's/^/# /' } fi From 2904e0f986b1e33f4ddc58a2cd630d48533ccede Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 22:45:37 +0000 Subject: [PATCH 250/297] test harness: Fix the pretty-printer's padding implementation. The new implementation is less efficient but definitely correct. --- tests/test-highlighting.zsh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index d12b44c..e79462b 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -227,9 +227,7 @@ run_test_internal() { left_column=( "expected_region_highlight" "${(qq)expected_region_highlight[@]}" ) right_column=( "region_highlight" "${(qq)region_highlight[@]}" ) integer difference=$(( $#right_column - $#left_column )) - if (( difference > 0 )); then - left_column+=( ${(r:2*difference::. :):-} ) - fi + repeat $difference do left_column+=(.); done paste \ =(print -rC1 -- $left_column) \ =(print -rC1 -- $right_column) \ From aecfd61bbda9b8739c48e7a2818438cb0f134791 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 21 Mar 2020 01:45:34 +0000 Subject: [PATCH 251/297] 'main': Support the 'env' precommand. --- changelog.md | 2 ++ highlighters/main/main-highlighter.zsh | 2 ++ highlighters/main/test-data/multiline-array-assignment1.zsh | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d975a76..496b4a8 100644 --- a/changelog.md +++ b/changelog.md @@ -71,6 +71,8 @@ - Highlight directories in command position correctly, including `AUTO_CD` support [#669] +- Recognize `env` as a precommand (e.g., `env FOO=bar ls`) + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 263b0be..456e3e7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -347,6 +347,8 @@ _zsh_highlight_highlighter_main_paint() 'catchsegv' '' 'nohup' '' 'setsid' :wc + 'env' u:i + # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k # suckless-tools v44 diff --git a/highlighters/main/test-data/multiline-array-assignment1.zsh b/highlighters/main/test-data/multiline-array-assignment1.zsh index 3734c7a..2926d93 100644 --- a/highlighters/main/test-data/multiline-array-assignment1.zsh +++ b/highlighters/main/test-data/multiline-array-assignment1.zsh @@ -35,5 +35,5 @@ expected_region_highlight=( '6 6 commandseparator' # \n '7 9 default' # bar '10 10 assign' # ) - '12 14 command' # env + '12 14 precommand' # env ) From d1802e388e94aca25380a3a9aeb4a2b7ba661b41 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 22 Mar 2020 15:01:10 -0500 Subject: [PATCH 252/297] main: Add test for issue #713 --- .../history-double-quoted-followed.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/history-double-quoted-followed.zsh diff --git a/highlighters/main/test-data/history-double-quoted-followed.zsh b/highlighters/main/test-data/history-double-quoted-followed.zsh new file mode 100644 index 0000000..6421ced --- /dev/null +++ b/highlighters/main/test-data/history-double-quoted-followed.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=': !!= "!!="' + +expected_region_highlight=( + '1 1 builtin' # : + '3 4 history-expansion "issue #713"' # !! + '7 11 default' # "!!=" + '7 11 double-quoted-argument' # "!!=" + '8 9 history-expansion "issue #713' # !! +) From 5d139fcd946212071b698942cf679916caf9c459 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Mar 2020 01:27:37 +0000 Subject: [PATCH 253/297] Fix typos in comments. --- highlighters/main/main-highlighter.zsh | 2 +- zsh-syntax-highlighting.zsh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 456e3e7..5a5244e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -318,7 +318,7 @@ _zsh_highlight_highlighter_main_paint() # that wouldn't be followed by a colon in a getopts specification. local flags_sans_argument # $flags_solo is a set of letters, corresponding to option letters that, if - # present, mean the precommand will now be acting as a precommand, i.e., will + # present, mean the precommand will not be acting as a precommand, i.e., will # not be followed by a :start: word. local flags_solo # $precommand_options maps precommand name to values of $flags_with_argument, diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index ff75108..f5fb700 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -29,8 +29,8 @@ # First of all, ensure predictable parsing. typeset zsh_highlight__aliases="$(builtin alias -Lm '[^+]*')" -# In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42') -# them without a '--' guard, so they don't round trip. +# In zsh <= 5.2, aliases that begin with a plus sign ('alias -- +foo=42') +# are emitted by `alias -L` without a '--' guard, so they don't round trip. # # Hence, we exclude them from unaliasing: builtin unalias -m '[^+]*' From 7678a8a22780141617f809002eeccf054bf8f448 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 21:37:50 +0000 Subject: [PATCH 254/297] 'main': Break out an anonymous function into a named function. This is in order to allow it to be reused. No functional change. --- highlighters/main/main-highlighter.zsh | 89 ++++++++++++++++---------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5a5244e..5812af0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -420,6 +420,56 @@ _zsh_highlight_highlighter_main_paint() done } +# Try to expand $1, if it's possible to do so safely. +# +# Uses two parameters from the caller: $parameter_name_pattern and $res. +# +# If expansion was done, set $reply to the expansion and return true. +# Otherwise, return false. +_zsh_highlight_main_highlighter__try_expand_parameter() +{ + local arg="$1" + unset reply + { + # ### For now, expand just '$foo' or '${foo}', possibly with braces, but with + # ### no other features of the parameter expansion syntax. (No ${(x)foo}, + # ### no ${foo[x]}, no ${foo:-x}.) + { + local -a match mbegin mend + local MATCH; integer MBEGIN MEND + local parameter_name + local -a words + if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then + parameter_name=${${arg:2}%?} + elif [[ $arg[1] == '$' ]]; then + parameter_name=${arg:1} + fi + if [[ $res == none ]] && zmodload -e zsh/parameter && + [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && + [[ ${parameters[(e)$MATCH]} != *special* ]] + then + # Set $arg and update $res. + case ${(tP)MATCH} in + (*array*|*assoc*) + words=( ${(P)MATCH} ) + ;; + ("") + # not set + words=( ) + ;; + (*) + # scalar, presumably + words=( ${(P)MATCH} ) + ;; + esac + reply=( "${words[@]}" ) + else + return 1 + fi + } + } +} + # $1 is the offset of $4 from the parent buffer. Added to the returned highlights. # $2 is the initial braces_stack (for a closing paren). # $3 is 1 if $4 contains the end of $BUFFER, else 0. @@ -676,42 +726,13 @@ _zsh_highlight_main_highlighter_highlight_list() fi # Expand parameters. - # - # ### For now, expand just '$foo' or '${foo}', possibly with braces, but with - # ### no other features of the parameter expansion syntax. (No ${(x)foo}, - # ### no ${foo[x]}, no ${foo:-x}.) - () { + if _zsh_highlight_main_highlighter__try_expand_parameter "$arg"; then # That's not entirely correct --- if the parameter's value happens to be a reserved # word, the parameter expansion will be highlighted as a reserved word --- but that # incorrectness is outweighed by the usability improvement of permitting the use of # parameters that refer to commands, functions, and builtins. - local -a match mbegin mend - local MATCH; integer MBEGIN MEND - local parameter_name - local -a words - if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then - parameter_name=${${arg:2}%?} - elif [[ $arg[1] == '$' ]]; then - parameter_name=${arg:1} - fi - if [[ $res == none ]] && zmodload -e zsh/parameter && - [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && - [[ ${parameters[(e)$MATCH]} != *special* ]] - then - # Set $arg and update $res. - case ${(tP)MATCH} in - (*array*|*assoc*) - words=( ${(P)MATCH} ) - ;; - ("") - # not set - words=( ) - ;; - (*) - # scalar, presumably - words=( ${(P)MATCH} ) - ;; - esac + () { + local -a words; words=( "${reply[@]}" ) if (( $#words == 0 )); then # Parameter elision is happening (( ++in_redirection )) @@ -724,8 +745,8 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main__type "$arg" 0 res=$REPLY fi - fi - } + } + fi # Parse the sudo command line if (( ! in_redirection )); then From 2aca4e2c02ae13753a0667b266d73afde7545f20 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 22:16:04 +0000 Subject: [PATCH 255/297] 'main': Make logic more robust. No functional change. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, if the value didn't begin with a dollar sign, _zsh_highlight_main_highlighter__try_expand_parameter() would return 1 by accident.¹ Tweak the input validation to make this behaviour explicit. No functional change. ¹ Specifically, it would return 1 because ${parameter_name}'s value would be the empty string and ${parameter_name_pattern} wouldn't match that. --- highlighters/main/main-highlighter.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5812af0..10abbb9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -439,9 +439,12 @@ _zsh_highlight_main_highlighter__try_expand_parameter() local MATCH; integer MBEGIN MEND local parameter_name local -a words - if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then + if [[ $arg[1] != '$' ]]; then + return 1 + fi + if [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then parameter_name=${${arg:2}%?} - elif [[ $arg[1] == '$' ]]; then + else parameter_name=${arg:1} fi if [[ $res == none ]] && zmodload -e zsh/parameter && From b8c93afd3438f98602bbb7caec4c1c349ef64acb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Mar 2020 20:45:46 +0000 Subject: [PATCH 256/297] driver: Make sure we don't change the return value in a called function. --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f5fb700..73a92c6 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -72,7 +72,7 @@ typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS _zsh_highlight() { # Store the previous command return code to restore it whatever happens. - local ret=$? + readonly ret=$? # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains. # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'. From f563780236eb989fd0d53552870ca479074f521b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Mar 2020 20:52:14 +0000 Subject: [PATCH 257/297] driver: Simplify initialization of $zsyh_user_options in the fallback codepath. --- zsh-syntax-highlighting.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 73a92c6..a87a63c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -93,9 +93,13 @@ _zsh_highlight() canonical_options=(${${${(M)raw_options:#*off}%% *}#no} ${${(M)raw_options:#*on}%% *}) for option in "${canonical_options[@]}"; do [[ -o $option ]] - # This variable cannot be eliminated c.f. workers/42101. - onoff=${${=:-off on}[2-$?]} - zsyh_user_options+=($option $onoff) + case $? in + (0) zsyh_user_options+=($option on);; + (1) zsyh_user_options+=($option off);; + (*) # Can't happen, surely? + echo "zsh-syntax-highlighting: warning: '[[ -o $option ]]' returned $?" + ;; + esac done fi typeset -r zsyh_user_options From 90fec4d65862da6d1ed5dfe2447f680a1387e57c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 1 Apr 2020 06:38:41 +0000 Subject: [PATCH 258/297] 'main': precommands += ionice(1) (from util-linux) --- highlighters/main/main-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 10abbb9..6c9bc25 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -348,6 +348,7 @@ _zsh_highlight_highlighter_main_paint() 'nohup' '' 'setsid' :wc 'env' u:i + 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k From 2a30d4fb5aeb8489c4c70eb694c5f6d5827dfc1d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 2 Apr 2020 23:32:28 +0000 Subject: [PATCH 259/297] 'main': Fix an infinite loop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the test case, the behaviour was as follows: +highlighters/main/main-highlighter.zsh:733> _zsh_highlight_main_highlighter__try_expand_parameter '$1' +highlighters/main/main-highlighter.zsh:432> local arg='$1' +highlighters/main/main-highlighter.zsh:433> unset reply +highlighters/main/main-highlighter.zsh:439> local -a match mbegin mend +highlighters/main/main-highlighter.zsh:440> local MATCH +highlighters/main/main-highlighter.zsh:440> integer MBEGIN MEND +highlighters/main/main-highlighter.zsh:441> local parameter_name +highlighters/main/main-highlighter.zsh:442> local -a words +highlighters/main/main-highlighter.zsh:443> [[ '$' != \$ ]] +highlighters/main/main-highlighter.zsh:446> [[ 1 == { ]] +highlighters/main/main-highlighter.zsh:449> parameter_name=1 +highlighters/main/main-highlighter.zsh:451> [[ none == none ]] +highlighters/main/main-highlighter.zsh:451> zmodload -e zsh/parameter +highlighters/main/main-highlighter.zsh:452> [[ ${parameter_name} -regex-match ^${~parameter_name_pattern}$ ]] +highlighters/main/main-highlighter.zsh:453> [[ '' != *special* ]] +highlighters/main/main-highlighter.zsh:456> case array-special (*array*|*assoc*) +highlighters/main/main-highlighter.zsh:458> words=( '$1' ) +highlighters/main/main-highlighter.zsh:469> reply=( '$1' ) There are two problems here: - In terms of _zsh_highlight_main_highlighter__try_expand_parameter's pre- and postconditions, the expansion of the word «$1» (line 733) included that same word (line 469). That happened because word-to-be-expanded is passed to _zsh_highlight_main_highlighter__try_expand_parameter as its first positional parameter, and in this case the word happened to be «$1». - Furthermore, the exclusion of special parameters (line 453) false negatived. That happened because $parameter_name_pattern explicitly allows positional parameters, but ${parameters[(e)1]} expands to nothing. This will be fixed in the next commit. Not a regression from 0.7.1. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6c9bc25..a190a5f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -730,7 +730,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi # Expand parameters. - if _zsh_highlight_main_highlighter__try_expand_parameter "$arg"; then + if (( ! in_param )) && _zsh_highlight_main_highlighter__try_expand_parameter "$arg"; then # That's not entirely correct --- if the parameter's value happens to be a reserved # word, the parameter expansion will be highlighted as a reserved word --- but that # incorrectness is outweighed by the usability improvement of permitting the use of From 96e6cbe22ff87e36d0505c417b9638ce9b2bbc2c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 2 Apr 2020 23:40:52 +0000 Subject: [PATCH 260/297] 'main': Fix expansion of positional parameters in `_zsh_highlight_main_highlighter__try_expand_parameter`. As described in the last commit's log message, ${parameter_name_pattern] explicitly matches positional parameters but ${parameters[$MATCH]} expands to nothing in that case (when, e.g., [[ $MATCH == '1' ]]; note this is equality of strings, not integers). As a side effect, this removes the dependency on the zsh/parameter module for expanding parameters. --- highlighters/main/main-highlighter.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a190a5f..4f44882 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -448,9 +448,9 @@ _zsh_highlight_main_highlighter__try_expand_parameter() else parameter_name=${arg:1} fi - if [[ $res == none ]] && zmodload -e zsh/parameter && + if [[ $res == none ]] && [[ ${parameter_name} =~ ^${~parameter_name_pattern}$ ]] && - [[ ${parameters[(e)$MATCH]} != *special* ]] + [[ ${(tP)MATCH} != *special* ]] then # Set $arg and update $res. case ${(tP)MATCH} in From 291634ecfe32f24ac997e53ab2f146c1f6bd8c55 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Apr 2020 01:03:57 +0000 Subject: [PATCH 261/297] tests: Add a test for the infinite loop fixed by each of the last two commits. Accidentally lost during a rebase. --- .../param-positional-in-array-append.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/param-positional-in-array-append.zsh diff --git a/highlighters/main/test-data/param-positional-in-array-append.zsh b/highlighters/main/test-data/param-positional-in-array-append.zsh new file mode 100644 index 0000000..2af7f38 --- /dev/null +++ b/highlighters/main/test-data/param-positional-in-array-append.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +# This used to be an infinite loop. + +BUFFER=$'l+=( $1' + +expected_region_highlight=( + '1 4 assign' # l+=( + '6 7 default' # $1 +) From 96eb2e31a192968c376ce74ca5ab09c094d1d082 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Apr 2020 01:19:38 +0000 Subject: [PATCH 262/297] driver: Fix "_zsh_highlight:3: read-only variable: ret" warnings when POSIX_BUILTINS is set. Fixes #719. Cf. #688. --- zsh-syntax-highlighting.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index a87a63c..7944b0f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -72,7 +72,9 @@ typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS _zsh_highlight() { # Store the previous command return code to restore it whatever happens. - readonly ret=$? + local ret=$? + # Make it read-only. Can't combine this with the previous line when POSIX_BUILTINS may be set. + typeset -r ret # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains. # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'. From ccb1da4ae8935f5b40ac7dbcdd6eeb694403c97f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Apr 2020 01:48:47 +0000 Subject: [PATCH 263/297] Bump copyright years. --- zsh-syntax-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 7944b0f..6c95e8c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2020 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From 415e762ab21da7e0ebfe6dab09b8cc62df99bfcc Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Wed, 8 Apr 2020 21:04:48 +0300 Subject: [PATCH 264/297] Fix typo --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4f44882..0e69d86 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -634,7 +634,7 @@ _zsh_highlight_main_highlighter_highlight_list() # The zsh lexer considers ';' and newline to be the same token, so # ${(z)} converts all newlines to semicolons. Convert them back here to - # make later processing simplier. + # make later processing simpler. [[ $arg == ';' && ${match[3]} == $'\n' ]] && arg=$'\n' # Compute the new $proc_buf. We advance it From f5d1be7ec2436cfa9d45dfc2bb72fb060eae650f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Apr 2020 02:59:39 +0000 Subject: [PATCH 265/297] editorconfig: Fix Makefile settings --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 1d2e96e..cda541d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,5 +10,6 @@ indent_style = space [Makefile] tab_width = 8 +indent_size = 8 indent_style = tab From 8d32609a7b19198fd8ce01821b2423e7a35a40e1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 20 Apr 2020 11:09:24 +0000 Subject: [PATCH 266/297] 'main': precommands += strace --- changelog.md | 2 ++ highlighters/main/main-highlighter.zsh | 1 + 2 files changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 496b4a8..bea26f1 100644 --- a/changelog.md +++ b/changelog.md @@ -73,6 +73,8 @@ - Recognize `env` as a precommand (e.g., `env FOO=bar ls`) +- Recognize `strace` as a precommand + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0e69d86..d7cce99 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -349,6 +349,7 @@ _zsh_highlight_highlighter_main_paint() 'setsid' :wc 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 + 'strace' IbeaosXPpEuOS:ACdffhikqrtttTvVxxyDc # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k From f1b9fbbaf0123fb7b14b4a11bc18c86fd4b2305b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 20 Apr 2020 11:11:29 +0000 Subject: [PATCH 267/297] 'main': Follow-up to previous: Document the version number, and deduplicate some option letters. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d7cce99..7ebc971 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -349,7 +349,7 @@ _zsh_highlight_highlighter_main_paint() 'setsid' :wc 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 - 'strace' IbeaosXPpEuOS:ACdffhikqrtttTvVxxyDc + 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k From 16d818a21f886ec61a9bdafd1722920863c65b1b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 13:27:33 +0000 Subject: [PATCH 268/297] 'main': Don't trip WARN_NESTED_VAR. Fixes #727. --- highlighters/main/main-highlighter.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7ebc971..4010648 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1677,6 +1677,8 @@ _zsh_highlight_main_highlighter_expand_path() # ------------------------------------------------------------------------------------------------- _zsh_highlight_main__precmd_hook() { + setopt localoptions + unsetopt warnnestedvar _zsh_highlight_main__command_type_cache=() } From 343ec1061fda6ecbc9782e33a8e4539525899594 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 17:34:59 +0000 Subject: [PATCH 269/297] 'make perf': Show only a cumulative datum per highligher, rather than per test file. The overall per-highlighter duration should be less prone to random noise than the multitude of per-test-file figures. --- tests/test-perfs.zsh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 2b003fc..a84e147 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -62,8 +62,6 @@ run_test_internal() { local srcdir="$PWD" builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! cd failed: $?"; return 1 } - echo -n "# ${1:t:r}: " - # Load the data and prepare checking it. PREBUFFER= BUFFER= ; . "$srcdir"/"$1" @@ -71,9 +69,8 @@ run_test_internal() { # Check the data declares $PREBUFFER or $BUFFER. [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; } - # Measure the time taken by _zsh_highlight. - TIMEFMT="%*Es" - { time (BUFFER="$BUFFER" && _zsh_highlight) } 2>&1 + # Set $? for _zsh_highlight + true && _zsh_highlight } run_test() { @@ -93,9 +90,10 @@ run_test() { # Process each test data file in test data directory. local data_file -for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do +TIMEFMT="%*Es" +{ time (for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do run_test "$data_file" (( $pipestatus[1] )) && exit 2 -done +done) } 2>&1 || exit $? exit 0 From 06710f37807ad9095e7e159e2215b1710368ca96 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 18:35:15 +0000 Subject: [PATCH 270/297] 'main': Don't run `_zsh_highlight_main__type` on every non-command word. Fixes #728, the performance regression from 0.7.1. --- highlighters/main/main-highlighter.zsh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4010648..66a3d2a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -273,6 +273,18 @@ _zsh_highlight_main__resolve_alias() { fi } +# Return true iff $1 is a global alias +_zsh_highlight_main__is_global_alias() { + if zmodload -e zsh/parameter; then + (( ${+galiases[$arg]} )) + elif [[ $arg == '='* ]]; then + # avoid running into «alias -L '=foo'» erroring out with 'bad assignment' + return 1 + else + alias -L -g -- "$1" >/dev/null + fi +} + # Check that the top of $braces_stack has the expected value. If it does, set # the style according to $2; otherwise, set style=unknown-token. # @@ -1061,7 +1073,7 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then next_word=':start::start_of_pipeline:' fi - elif _zsh_highlight_main__type "$arg"; [[ $REPLY == 'global alias' ]]; then # $arg is a global alias that isn't in command position + elif _zsh_highlight_main__is_global_alias "$arg"; then # $arg is a global alias that isn't in command position style=global-alias else # $arg is a non-command word case $arg in From e65ebf04663ed49c395b6747d74a163850c0221b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 5 May 2020 14:31:42 +0000 Subject: [PATCH 271/297] 'main': Fix a regression caused by the great-grandparent commit's WARN_NESTED_VAR fix. An error message was emitted on versions of zsh that don't have the WARN_NESTED_VAR option. Fixes #731. --- highlighters/main/main-highlighter.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 66a3d2a..e4a17e0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1689,8 +1689,13 @@ _zsh_highlight_main_highlighter_expand_path() # ------------------------------------------------------------------------------------------------- _zsh_highlight_main__precmd_hook() { + # Unset the WARN_NESTED_VAR option, taking care not to error if the option + # doesn't exist (zsh older than zsh-5.3.1-test-2). setopt localoptions - unsetopt warnnestedvar + if [[ -o warnnestedvar ]] 2>/dev/null; then + unsetopt warnnestedvar + fi + _zsh_highlight_main__command_type_cache=() } From 0582ea19102064084149a31418ab38bd1eeaef1a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 5 May 2020 17:59:51 +0000 Subject: [PATCH 272/297] changelog += WARN_NESTED_VAR fixes (#727, #731) --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index bea26f1..6c75259 100644 --- a/changelog.md +++ b/changelog.md @@ -75,6 +75,10 @@ - Recognize `strace` as a precommand +- Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set: + `_zsh_highlight_main__precmd_hook:1: array parameter _zsh_highlight_main__command_type_cache set in enclosing scope in function _zsh_highlight_main__precmd_hook` + [#727, #731] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. From 3a4b212c7d8263a12bef176b10737748b752a579 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 6 May 2020 20:25:03 +0000 Subject: [PATCH 273/297] 'main': Fix regression in zsh 5.3.1 and older: all precmd hooks later than z-sy-h would be aborted. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In those versions of zsh, «[[ -o nosuchoption ]]» is regarded as a syntax error. In newer zsh versions, it merely returns non-zero (specifically, it returns 3, unlike «[[ -o unsetoption ]]» which returns 1). Fixes #732. Fixes #733. --- changelog.md | 2 +- highlighters/main/main-highlighter.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 6c75259..120750c 100644 --- a/changelog.md +++ b/changelog.md @@ -77,7 +77,7 @@ - Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set: `_zsh_highlight_main__precmd_hook:1: array parameter _zsh_highlight_main__command_type_cache set in enclosing scope in function _zsh_highlight_main__precmd_hook` - [#727, #731] + [#727, #731, #732, #733] # Changes in version 0.7.1 diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e4a17e0..59d4036 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1692,7 +1692,7 @@ _zsh_highlight_main__precmd_hook() { # Unset the WARN_NESTED_VAR option, taking care not to error if the option # doesn't exist (zsh older than zsh-5.3.1-test-2). setopt localoptions - if [[ -o warnnestedvar ]] 2>/dev/null; then + if eval '[[ -o warnnestedvar ]]' 2>/dev/null; then unsetopt warnnestedvar fi From 41b8a74692f64e29399c571d62f0fd68283df09e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 13 May 2020 12:51:40 +0000 Subject: [PATCH 274/297] 'main': Add a test for parameter elision not happening in redirects in command position. Will be fixed in the next commit. --- .../redirection-inhibits-elision.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/redirection-inhibits-elision.zsh diff --git a/highlighters/main/test-data/redirection-inhibits-elision.zsh b/highlighters/main/test-data/redirection-inhibits-elision.zsh new file mode 100644 index 0000000..be5e431 --- /dev/null +++ b/highlighters/main/test-data/redirection-inhibits-elision.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'<$foo cat cat' + +expected_region_highlight=( + '1 1 redirection' # < + '2 5 default "fixed in the next commit"' # $foo + '7 9 command "fixed in the next commit"' # cat + '11 13 default "fixed in the next commit"' # cat +) From ea3ae74164bdc1f38b23f6b4c339ac637bfb923b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 13 May 2020 12:51:52 +0000 Subject: [PATCH 275/297] 'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position. --- highlighters/main/main-highlighter.zsh | 2 +- .../main/test-data/redirection-inhibits-elision.zsh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 59d4036..6053337 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -750,7 +750,7 @@ _zsh_highlight_main_highlighter_highlight_list() # parameters that refer to commands, functions, and builtins. () { local -a words; words=( "${reply[@]}" ) - if (( $#words == 0 )); then + if (( $#words == 0 )) && (( ! in_redirection )); then # Parameter elision is happening (( ++in_redirection )) _zsh_highlight_main_add_region_highlight $start_pos $end_pos comment diff --git a/highlighters/main/test-data/redirection-inhibits-elision.zsh b/highlighters/main/test-data/redirection-inhibits-elision.zsh index be5e431..c0ca267 100644 --- a/highlighters/main/test-data/redirection-inhibits-elision.zsh +++ b/highlighters/main/test-data/redirection-inhibits-elision.zsh @@ -32,7 +32,7 @@ BUFFER=$'<$foo cat cat' expected_region_highlight=( '1 1 redirection' # < - '2 5 default "fixed in the next commit"' # $foo - '7 9 command "fixed in the next commit"' # cat - '11 13 default "fixed in the next commit"' # cat + '2 5 default' # $foo + '7 9 command' # cat + '11 13 default' # cat ) From 5171ec524ffab6a27e4d68018ab6872beba4f093 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 May 2020 02:23:18 +0000 Subject: [PATCH 276/297] Document ZSH_HIGHLIGHT_MAXLENGTH. Fixes #698. --- docs/highlighters.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/highlighters.md b/docs/highlighters.md index d0c9332..bb72e54 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -18,6 +18,23 @@ Syntax highlighting is done by pluggable highlighters: [6]: highlighters/line.md +Highlighter-independent settings +-------------------------------- + +By default, all command lines are highlighted. However, it is possible to +prevent command lines longer than a fixed number of characters from being +highlighted by setting the variable `${ZSH_HIGHLIGHT_MAXLENGTH}` to the maximum +length (in characters) of command lines to be highlighter. This is useful when +editing very long comand lines (for example, with the [`fned`][fned] utility +function). Example: + +[fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed + +```zsh +ZSH_HIGHLIGHT_MAXLENGTH=512 +``` + + How to activate highlighters ---------------------------- From 4dd4797ae012f236e14daf82773b3dbe72134a0b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 May 2020 03:27:48 +0000 Subject: [PATCH 277/297] test harness: Print the expected-v.-actual on every failure, not just upon cardinality failures. I was looking into something and wanted to see how a the second word in the array was highlighted, even though the failure was on the third word. --- tests/test-highlighting.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index e79462b..74ccc95 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -154,6 +154,8 @@ run_test_internal() { }; [[ -z $RETURN ]] || return $RETURN unset ARG + integer print_expected_and_actual=0 + if (( unsorted )); then region_highlight=("${(@n)region_highlight}") expected_region_highlight=("${(@n)expected_region_highlight}") @@ -177,6 +179,7 @@ run_test_internal() { if ! (( $+region_highlight[i] )); then print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])" \ "${skip_mismatch:+"# TODO ${(qqq)skip_mismatch}"}" + if [[ -z $skip_mismatch ]]; then (( ++print_expected_and_actual )); fi continue fi local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} ) @@ -189,6 +192,7 @@ run_test_internal() { [[ $highlight_zone[3] != $expected_highlight_zone[3] ]] then print -r -- "not ok $i - $desc - expected ($exp_start $exp_end ${(qqq)expected_highlight_zone[3]}), observed ($start $end ${(qqq)highlight_zone[3]}). $todo" + if [[ -z $todo ]]; then (( ++print_expected_and_actual )); fi else print -r -- "ok $i - $desc${todo:+ - }$todo" fi @@ -221,7 +225,10 @@ run_test_internal() { details+="«$(typeset_p expected_region_highlight)» «$(typeset_p region_highlight)»" tap_escape $details; details=$REPLY print -r -- "not ok $i - cardinality check - $details${todo:+ - }$todo" - + if [[ -z $todo ]]; then (( ++print_expected_and_actual )); fi + fi + fi + if (( print_expected_and_actual )); then () { local -a left_column right_column left_column=( "expected_region_highlight" "${(qq)expected_region_highlight[@]}" ) @@ -234,7 +241,6 @@ run_test_internal() { | if type column >/dev/null; then column -t -s $'\t'; else cat; fi \ | sed 's/^/# /' } - fi fi } From b253a8b86acfe4555b8703654c77d393e70858c2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 May 2020 03:30:11 +0000 Subject: [PATCH 278/297] changelog: Update through HEAD. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The great-grandparent commit, "a3ae74 'main': Fix the last commit's bug concerning parameter elision not happening in redirects in command position.", is not added because it's not a change with respect to 0.7.1. --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 120750c..428472f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changes in HEAD +- Document `$ZSH_HIGHLIGHT_MAXLENGTH`. + [#698] + - Redirection operators (e.g., `<` and `>`) are now highlighted by default [#646] From a50647e77b0029aef2cba28a56bfb72a9f7cb6bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 19:42:31 +0000 Subject: [PATCH 279/297] tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit % git co HEAD^ && repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 } HEAD is now at f1948df tests: Add a performance testing script, for measuring the performance of the 'main' highlighter on a large file. 19) 1 34378.97 34378.97 100.00% 5.43 5.43 0.02% _zsh_highlight 19) 1 34058.34 34058.34 100.00% 5.50 5.50 0.02% _zsh_highlight 19) 1 34364.80 34364.80 100.00% 5.36 5.36 0.02% _zsh_highlight --- tests/test-zprof.zsh | 77 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 tests/test-zprof.zsh diff --git a/tests/test-zprof.zsh b/tests/test-zprof.zsh new file mode 100755 index 0000000..2538f7d --- /dev/null +++ b/tests/test-zprof.zsh @@ -0,0 +1,77 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2015 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 +# ------------------------------------------------------------------------------------------------- + +# Load the main script. +. ${0:h:h}/zsh-syntax-highlighting.zsh + +# Activate the highlighter. +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) + +source_file=0.7.1:highlighters/$1/$1-highlighter.zsh + +# Runs a highlighting test +# $1: data file +run_test_internal() { + setopt interactivecomments + + local -a highlight_zone + + local tests_tempdir="$1"; shift + local srcdir="$PWD" + builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! cd failed: $?"; return 1 } + + # Load the data and prepare checking it. + PREBUFFER= + BUFFER=$(cd -- "$srcdir" && git cat-file blob $source_file) + expected_region_highlight=() + + zmodload zsh/zprof + zprof -c + # Set $? for _zsh_highlight + true && _zsh_highlight + zprof +} + +run_test() { + # Do not combine the declaration and initialization: «local x="$(false)"» does not set $?. + local __tests_tempdir + __tests_tempdir="$(mktemp -d)" && [[ -d $__tests_tempdir ]] || { + echo >&2 "Bail out! mktemp failed"; return 1 + } + typeset -r __tests_tempdir # don't allow tests to override the variable that we will 'rm -rf' later on + + { + (run_test_internal "$__tests_tempdir" "$@") + } always { + rm -rf -- "$__tests_tempdir" + } +} + +run_test From 700c0e18fea594b16358726d00ec06445b7ead37 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 20:00:01 +0000 Subject: [PATCH 280/297] 'main': Optimize a hot path. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit % git co HEAD^ && repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 } HEAD is now at 64e3651 'main': Optimize a hot path. 19) 1 28765.13 28765.13 100.00% 5.57 5.57 0.02% _zsh_highlight 19) 1 28566.46 28566.46 100.00% 5.91 5.91 0.02% _zsh_highlight 19) 1 28248.12 28248.12 100.00% 5.57 5.57 0.02% _zsh_highlight ---- This commit has been rebased. The above statistics were measured after the rebase. The below statistics had been measured before the rebase. Before this patch: num calls time self name ----------------------------------------------------------------------------------- 1) 3 33410.81 11136.94 98.51% 19277.07 6425.69 56.84% _zsh_highlight_main_highlighter_highlight_list 19) 1 33916.21 33916.21 100.00% 5.27 5.27 0.02% _zsh_highlight With this patch: num calls time self name ----------------------------------------------------------------------------------- 1) 3 27167.49 9055.83 98.17% 18754.77 6251.59 67.77% _zsh_highlight_main_highlighter_highlight_list 19) 1 27674.40 27674.40 100.00% 5.39 5.39 0.02% _zsh_highlight And if test-zprof.zsh is changed to not set interactivecomments: num calls time self name ----------------------------------------------------------------------------------- 1) 13360 36029.12 2.70 83.56% 30304.23 2.27 70.28% _zsh_highlight_main_highlighter_highlight_argument 21) 1 43117.76 43117.76 100.00% 4.52 4.52 0.01% _zsh_highlight num calls time self name ----------------------------------------------------------------------------------- 1) 13360 14782.89 1.11 68.12% 9163.42 0.69 42.23% _zsh_highlight_main_highlighter_highlight_argument 21) 1 21699.93 21699.93 100.00% 4.17 4.17 0.02% _zsh_highlight --- highlighters/main/main-highlighter.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 66a3d2a..903c9f5 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1311,7 +1311,12 @@ _zsh_highlight_main_highlighter_highlight_argument() fi esac + # This loop is a hot path. Keep it fast! for (( ; i <= $#arg ; i += 1 )); do + if [[ $arg[$i] != [\\\'\"\`\$\<\>\*\?] ]]; then + continue + fi + case "$arg[$i]" in "\\") (( i += 1 )); continue;; "'") From 8f5d74d2190c124110cde3e240eb703b2594dca4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 20:08:49 +0000 Subject: [PATCH 281/297] 'main': Further optimize argument parsing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit % repeat 3 { zsh -f tests/test-zprof.zsh main | tee … | grep -w _zsh_highlight | head -n1 } 18) 1 26895.86 26895.86 100.00% 6.35 6.35 0.02% _zsh_highlight 19) 1 27399.11 27399.11 100.00% 5.52 5.52 0.02% _zsh_highlight 19) 1 27027.58 27027.58 100.00% 5.66 5.66 0.02% _zsh_highlight ---- This commit has been rebased. The above statistics were measured after the rebase. The below statistics had been measured before the rebase. num calls time self name ----------------------------------------------------------------------------------- 1) 3 25689.17 8563.06 98.15% 18422.01 6140.67 70.38% _zsh_highlight_main_highlighter_highlight_list 2) 32390 5706.13 0.18 21.80% 2315.68 0.07 8.85% _zsh_highlight_main_highlighter_highlight_argument 19) 1 26173.33 26173.33 100.00% 5.27 5.27 0.02% _zsh_highlight Interestingly, if I make the change in this diff to _zsh_highlight_main_highlighter_highlight_double_quote — > diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh > index da6ab2b..bb17618 100644 > --- a/highlighters/main/main-highlighter.zsh > +++ b/highlighters/main/main-highlighter.zsh > @@ -1462,10 +1462,13 @@ _zsh_highlight_main_highlighter_highlight_double_quote() > local i j k ret style > reply=() > > - for (( i = $1 + 1 ; i <= $#arg ; i += 1 )) ; do > + (( i = $1 )) > + while (( ++i <= $#arg )); do > + i=${arg[(ib.i.)[\"\`\$\\\\${histchars[1]}]]} > (( j = i + start_pos - 1 )) > (( k = j + 1 )) > case "$arg[$i]" in > + ("") break;; > ('"') break;; > ('`') saved_reply=($reply) > _zsh_highlight_main_highlighter_highlight_backtick $i — it actually makes things measurably slower (!), even on input that has a large number of pasted double-quoted strings: on «BUFFER=": ${(r.8*1500..foo"bar".):-}"» the slowdown is (1123.24ms / 1091.06ms = 1.0295). Therefore, I won't be committing that change. --- highlighters/main/main-highlighter.zsh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 903c9f5..da6ab2b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1312,12 +1312,11 @@ _zsh_highlight_main_highlighter_highlight_argument() esac # This loop is a hot path. Keep it fast! - for (( ; i <= $#arg ; i += 1 )); do - if [[ $arg[$i] != [\\\'\"\`\$\<\>\*\?] ]]; then - continue - fi - + (( --i )) + while (( ++i <= $#arg )); do + i=${arg[(ib.i.)[\\\'\"\`\$\<\>\*\?]]} case "$arg[$i]" in + "") break;; "\\") (( i += 1 )); continue;; "'") _zsh_highlight_main_highlighter_highlight_single_quote $i From 8211a95421735c22cbc8a9bd7f19e02d29a60e5b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 May 2020 04:44:49 +0000 Subject: [PATCH 282/297] changelog: Update through HEAD. --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 428472f..947cdb5 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,9 @@ - Document `$ZSH_HIGHLIGHT_MAXLENGTH`. [#698] +- Optimize highlighting unquoted words (words that are not in single quotes, double quotes, backticks, or dollar-single-quotes) + [#730] + - Redirection operators (e.g., `<` and `>`) are now highlighted by default [#646] From ade4b28d2df365387f86a2f5824822e4a430d382 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 15 Mar 2020 17:42:25 +0000 Subject: [PATCH 283/297] 'main': Fix issue #677, concerning multiline aliases. The fix is to exempt such aliases from the empty commands sanity check. --- changelog.md | 5 +++++ highlighters/main/main-highlighter.zsh | 12 ++++++++++-- highlighters/main/test-data/alias-comment1.zsh | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 947cdb5..72de00d 100644 --- a/changelog.md +++ b/changelog.md @@ -85,6 +85,10 @@ `_zsh_highlight_main__precmd_hook:1: array parameter _zsh_highlight_main__command_type_cache set in enclosing scope in function _zsh_highlight_main__precmd_hook` [#727, #731, #732, #733] +- Fix highlighting of alias whose definitions use a simple command terminator + (such as `;`, `|`, `&&`) before a newline + [#677; had regressed in 0.7.0] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. @@ -159,6 +163,7 @@ Known issues include: before a newline will incorrectly be highlighted as an error. See issue #677 for examples and workarounds. [#677] + [UPDATE: Fixed in 0.8.0] # Changes in version 0.6.0 diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5d108ac..9bf0e3a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -854,9 +854,17 @@ _zsh_highlight_main_highlighter_highlight_list() style=commandseparator elif [[ $this_word == *':start:'* ]] && [[ $arg == $'\n' ]]; then style=commandseparator + elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( in_alias )); then + style=commandseparator else - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. + # Empty commands (semicolon follows nothing) are valid syntax. + # However, in interactive use they are likely to be erroneous; + # therefore, we highlight them as errors. + # + # Alias definitions are exempted from this check to allow multiline aliases + # with explicit (redundant) semicolons: «alias foo=$'bar;\nbaz'» (issue #677). + # + # See also #691 about possibly changing the style used here. style=unknown-token fi diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index 8618575..bae7ef6 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -33,5 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias "issue #677"' # x + '1 1 alias' # x ) From f8b1470314be9fd25df90fa40d45c727c193ba96 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 May 2020 04:55:17 +0000 Subject: [PATCH 284/297] changelog.md: Restore vertical whitespace before section headers. --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 72de00d..d62ad15 100644 --- a/changelog.md +++ b/changelog.md @@ -89,10 +89,12 @@ (such as `;`, `|`, `&&`) before a newline [#677; had regressed in 0.7.0] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. + # Changes in version 0.7.0 This is a stable bugfix and feature release. Major new features and changes include: From a238647df9a51d33f55585f8ceebe8d839fcdcb3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 18 Mar 2020 23:31:11 -0500 Subject: [PATCH 285/297] main: Add arithmetic substitution highlighting Closes #607 #649 #704 --- changelog.md | 9 +- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 115 ++++++++++++++++-- .../main/test-data/arith-cmdsubst-mess.zsh | 20 +-- highlighters/main/test-data/arith1.zsh | 2 +- highlighters/main/test-data/arith2.zsh | 1 + 6 files changed, 121 insertions(+), 27 deletions(-) diff --git a/changelog.md b/changelog.md index d62ad15..1dd1c1d 100644 --- a/changelog.md +++ b/changelog.md @@ -50,13 +50,6 @@ - Fix `echo >&p` highlighting the `p` as a filename if a file by that name happened to exist [part of #645] -- Fix `: $((42))` being highlighted as a subshell. - [part of #607] - -- Regress highlighting of `: $((ls); (ls))`: is a subshell, but will now be - incorrectly highlighted as an arithmetic expansion. - [#704] - - Fix wrong highlighting of unquoted parameter expansions under zsh 5.2 and older [e165f18c758e] @@ -89,6 +82,8 @@ (such as `;`, `|`, `&&`) before a newline [#677; had regressed in 0.7.0] +- Highlight arithmetic expansions (e.g., `$(( 42 ))`) + [#607 #649 #704] # Changes in version 0.7.1 diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 5eec335..cc6186b 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -42,6 +42,7 @@ This highlighter defines the following styles: * `command-substitution-delimiter-quoted` - a quoted command substitution delimiters (`"$(` and `)"`) * `process-substitution` - process substitutions (`<(echo foo)`) * `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`) +* `arithmetic-expansion` - arithmetic expansion `$(( 42 ))`) * `single-hyphen-option` - single-hyphen options (`-o`) * `double-hyphen-option` - double-hyphen options (`--option`) * `back-quoted-argument` - backtick command substitution (`` `foo` ``) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9bf0e3a..6b3610c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1350,8 +1350,13 @@ _zsh_highlight_main_highlighter_highlight_argument() (( i = REPLY )) highlights+=($reply) continue - elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then - # command substitution that doesn't look like an arithmetic expansion + elif [[ $arg[i+1] == $'\x28' ]]; then + if [[ $arg[i+2] == $'\x28' ]] && _zsh_highlight_main_highlighter_highlight_arithmetic $i; then + # Arithmetic expansion + (( i = REPLY )) + highlights+=($reply) + continue + fi start=$i (( i += 2 )) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] @@ -1366,10 +1371,6 @@ _zsh_highlight_main_highlighter_highlight_argument() highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter-unquoted) fi continue - else - # TODO: if it's an arithmetic expansion, skip past it, to prevent - # multiplications from being highlighted as globbing (issue #607, - # test-data/arith1.zsh) fi while [[ $arg[i+1] == [=~#+'^'] ]]; do (( i += 1 )) @@ -1497,11 +1498,17 @@ _zsh_highlight_main_highlighter_highlight_double_quote() # $#, $*, $@, $?, $- - like $$ above (( k += 1 )) # highlight both dollar signs (( i += 1 )) # don't consider the second one as introducing another parameter expansion - elif [[ $arg[i+1] == $'\x28' && ${arg:$i} != $'\x28\x28'*$'\x29\x29'* ]]; then - # command substitution that doesn't look like an arithmetic expansion + elif [[ $arg[i+1] == $'\x28' ]]; then + saved_reply=($reply) + if [[ $arg[i+2] == $'\x28' ]] && _zsh_highlight_main_highlighter_highlight_arithmetic $i; then + # Arithmetic expansion + (( i = REPLY )) + reply=($saved_reply $reply) + continue + fi + breaks+=( $last_break $(( start_pos + i - 1 )) ) (( i += 2 )) - saved_reply=($reply) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,-1] ret=$? (( i += REPLY )) @@ -1682,6 +1689,96 @@ _zsh_highlight_main_highlighter_highlight_backtick() REPLY=$i } +# Highlight special chars inside arithmetic expansions +_zsh_highlight_main_highlighter_highlight_arithmetic() +{ + local -a saved_reply + local style + integer i j k paren_depth ret + reply=() + + for (( i = $1 + 3 ; i <= end_pos - start_pos ; i += 1 )) ; do + (( j = i + start_pos - 1 )) + (( k = j + 1 )) + case "$arg[$i]" in + [\'\"\\@{}]) + style=unknown-token + ;; + '(') + (( paren_depth++ )) + continue + ;; + ')') + if (( paren_depth )); then + (( paren_depth-- )) + continue + fi + [[ $arg[i+1] == ')' ]] && { (( i++ )); break; } + # Special case ) at the end of the buffer to avoid flashing command substitution for a character + (( has_end && (len == k) )) && break + # This is a single paren and there are no open parens, so this isn't an arithmetic expansion + return 1 + ;; + '`') + saved_reply=($reply) + _zsh_highlight_main_highlighter_highlight_backtick $i + (( i = REPLY )) + reply=($saved_reply $reply) + continue + ;; + '$' ) + if [[ $arg[i+1] == $'\x28' ]]; then + saved_reply=($reply) + if [[ $arg[i+2] == $'\x28' ]] && _zsh_highlight_main_highlighter_highlight_arithmetic $i; then + # Arithmetic expansion + (( i = REPLY )) + reply=($saved_reply $reply) + continue + fi + + (( i += 2 )) + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + ret=$? + (( i += REPLY )) + reply=( + $saved_reply + $j $(( start_pos + i )) command-substitution-quoted + $j $(( j + 2 )) command-substitution-delimiter-quoted + $reply + ) + if (( ret == 0 )); then + reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter) + fi + continue + else + continue + fi + ;; + ($histchars[1]) # ! - may be a history expansion + if [[ $arg[i+1] != ('='|$'\x28'|$'\x7b'|[[:blank:]]) ]]; then + style=history-expansion + else + continue + fi + ;; + *) + continue + ;; + + esac + reply+=($j $k $style) + done + + if [[ $arg[i] != ')' ]]; then + # If unclosed, i points past the end + (( i-- )) + fi + style=arithmetic-expansion + reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) arithmetic-expansion $reply) + REPLY=$i +} + + # Called with a single positional argument. # Perform filename expansion (tilde expansion) on the argument and set $REPLY to the expanded value. # diff --git a/highlighters/main/test-data/arith-cmdsubst-mess.zsh b/highlighters/main/test-data/arith-cmdsubst-mess.zsh index 6f60469..82268ac 100644 --- a/highlighters/main/test-data/arith-cmdsubst-mess.zsh +++ b/highlighters/main/test-data/arith-cmdsubst-mess.zsh @@ -33,14 +33,14 @@ BUFFER=$': $((ls); (ls))' expected_region_highlight=( '1 1 builtin' # : '3 15 default' # $((ls); (ls)) - '3 15 command-substitution-unquoted "issue #704"' # $((ls); (ls)) - '3 4 command-substitution-delimiter-unquoted "issue #704"' # $( - '5 5 reserved-word "issue #704"' # ( - '6 7 command "issue #704"' # ls - '8 8 reserved-word "issue #704"' # ) - '9 9 commandseparator "issue #704"' # ; - '11 11 reserved-word "issue #704"' # ( - '12 13 command "issue #704"' # ls - '14 14 reserved-word "issue #704"' # ) - '15 15 command-substitution-delimiter-unquoted "issue #704"' # ) + '3 15 command-substitution-unquoted' # $((ls); (ls)) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 reserved-word' # ( + '6 7 command' # ls + '8 8 reserved-word' # ) + '9 9 commandseparator' # ; + '11 11 reserved-word' # ( + '12 13 command' # ls + '14 14 reserved-word' # ) + '15 15 command-substitution-delimiter-unquoted' # ) ) diff --git a/highlighters/main/test-data/arith1.zsh b/highlighters/main/test-data/arith1.zsh index 92fa3da..0462f73 100644 --- a/highlighters/main/test-data/arith1.zsh +++ b/highlighters/main/test-data/arith1.zsh @@ -33,5 +33,5 @@ BUFFER=$': $(( 6 * 9 ))' expected_region_highlight=( '1 1 builtin' # : '3 14 default' # $(( 6 * 9 )) + '3 14 arithmetic-expansion' # $(( 6 * 9 )) ) -expected_mismatch="currently the actual highlighting has one superfluous group that highlights the asterisk is highlighted as 'globbing'" diff --git a/highlighters/main/test-data/arith2.zsh b/highlighters/main/test-data/arith2.zsh index 7e98476..af981d7 100644 --- a/highlighters/main/test-data/arith2.zsh +++ b/highlighters/main/test-data/arith2.zsh @@ -34,4 +34,5 @@ expected_region_highlight=( '1 1 builtin' # : '3 16 default' # "$(( 6 * 9 ))" '3 16 double-quoted-argument' # "$(( 6 * 9 ))" + '4 15 arithmetic-expansion' # $(( 6 * 9 )) ) From 870bccf8ffdcce7e01319438f96475a6329c9363 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 22 Mar 2020 14:47:03 -0500 Subject: [PATCH 286/297] main: Add tests for arithmetic expansion --- .../arithmetic-command-substitution.zsh | 42 +++++++++++++++++++ .../test-data/arithmetic-doubled-parens.zsh | 37 ++++++++++++++++ .../main/test-data/arithmetic-empty.zsh | 39 +++++++++++++++++ .../main/test-data/arithmetic-hist-expn.zsh | 38 +++++++++++++++++ .../test-data/arithmetic-invalid-chars.zsh | 39 +++++++++++++++++ .../test-data/arithmetic-multiplication.zsh | 39 +++++++++++++++++ .../main/test-data/arithmetic-nested.zsh | 38 +++++++++++++++++ .../main/test-data/arithmetic-quoted.zsh | 38 +++++++++++++++++ .../main/test-data/arithmetic-unclosed.zsh | 37 ++++++++++++++++ .../main/test-data/arithmetic-unfinished.zsh | 41 ++++++++++++++++++ 10 files changed, 388 insertions(+) create mode 100644 highlighters/main/test-data/arithmetic-command-substitution.zsh create mode 100644 highlighters/main/test-data/arithmetic-doubled-parens.zsh create mode 100644 highlighters/main/test-data/arithmetic-empty.zsh create mode 100644 highlighters/main/test-data/arithmetic-hist-expn.zsh create mode 100644 highlighters/main/test-data/arithmetic-invalid-chars.zsh create mode 100644 highlighters/main/test-data/arithmetic-multiplication.zsh create mode 100644 highlighters/main/test-data/arithmetic-nested.zsh create mode 100644 highlighters/main/test-data/arithmetic-quoted.zsh create mode 100644 highlighters/main/test-data/arithmetic-unclosed.zsh create mode 100644 highlighters/main/test-data/arithmetic-unfinished.zsh diff --git a/highlighters/main/test-data/arithmetic-command-substitution.zsh b/highlighters/main/test-data/arithmetic-command-substitution.zsh new file mode 100644 index 0000000..07db0fb --- /dev/null +++ b/highlighters/main/test-data/arithmetic-command-substitution.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( $(echo 2) + 2 ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 22 default' # $(( $(echo 2) + 2 )) + '3 22 arithmetic-expansion' # $(( $(echo 2) + 2 )) + '7 15 command-substitution-quoted' # $(echo 2) + '7 8 command-substitution-delimiter-quoted' # $( + '9 12 builtin' # echo + '14 14 default' # 2 + '15 15 command-substitution-delimiter' # ) +) diff --git a/highlighters/main/test-data/arithmetic-doubled-parens.zsh b/highlighters/main/test-data/arithmetic-doubled-parens.zsh new file mode 100644 index 0000000..d582d67 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-doubled-parens.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( ((42)) ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # $(( ((42)) )) + '3 15 arithmetic-expansion' # $(( ((42)) )) +) diff --git a/highlighters/main/test-data/arithmetic-empty.zsh b/highlighters/main/test-data/arithmetic-empty.zsh new file mode 100644 index 0000000..bd75996 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-empty.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': "foo"$(())"bar"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 17 default' # "foo"$(())"bar" + '3 7 double-quoted-argument' # "foo" + '8 12 arithmetic-expansion' # $(()) + '13 17 double-quoted-argument' # "bar" +) diff --git a/highlighters/main/test-data/arithmetic-hist-expn.zsh b/highlighters/main/test-data/arithmetic-hist-expn.zsh new file mode 100644 index 0000000..79af723 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-hist-expn.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( \!\! ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 11 default' # $(( !! )) + '3 11 arithmetic-expansion' # $(( !! )) + '7 8 history-expansion "issue #713"' # !! +) diff --git a/highlighters/main/test-data/arithmetic-invalid-chars.zsh b/highlighters/main/test-data/arithmetic-invalid-chars.zsh new file mode 100644 index 0000000..9ace438 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-invalid-chars.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( 0 * 1\'\'000 ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 19 default' # $(( 0 * 1\'\'000 )) + '3 19 arithmetic-expansion' # $(( 0 * 1\'\'000 )) + '12 12 unknown-token' # \' + '13 13 unknown-token' # \' +) diff --git a/highlighters/main/test-data/arithmetic-multiplication.zsh b/highlighters/main/test-data/arithmetic-multiplication.zsh new file mode 100644 index 0000000..65df0c9 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-multiplication.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': foo*$(( 42 * 1729 ))*bar' + +expected_region_highlight=( + '1 1 builtin' # : + '3 26 default' # foo*$(( 42 * 1729 ))*bar + '6 6 globbing' # * + '7 22 arithmetic-expansion' # $(( 42 * 1729 )) + '23 23 globbing' # * +) diff --git a/highlighters/main/test-data/arithmetic-nested.zsh b/highlighters/main/test-data/arithmetic-nested.zsh new file mode 100644 index 0000000..d734cd3 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-nested.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( $(( 1 + 2 )) * 3 ))' + +expected_region_highlight=( + '1 1 builtin' # : + '3 25 default' # $(( $(( 1 + 2 )) * 3 )) + '3 25 arithmetic-expansion' # $(( $(( 1 + 2 )) * 3 )) + '7 18 arithmetic-expansion' # $(( 1 + 2 )) +) diff --git a/highlighters/main/test-data/arithmetic-quoted.zsh b/highlighters/main/test-data/arithmetic-quoted.zsh new file mode 100644 index 0000000..917ddf7 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-quoted.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': "$(( 1 + 1 ))"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 16 default' # "$(( 1 + 1 ))" + '3 16 double-quoted-argument' # "$(( 1 + 1 ))" + '4 15 arithmetic-expansion' # $(( 1 + 1 )) +) diff --git a/highlighters/main/test-data/arithmetic-unclosed.zsh b/highlighters/main/test-data/arithmetic-unclosed.zsh new file mode 100644 index 0000000..aa4eac7 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-unclosed.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( 1' + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 default' # $(( 1 + '3 7 arithmetic-expansion' # $(( 1 +) diff --git a/highlighters/main/test-data/arithmetic-unfinished.zsh b/highlighters/main/test-data/arithmetic-unfinished.zsh new file mode 100644 index 0000000..916c3da --- /dev/null +++ b/highlighters/main/test-data/arithmetic-unfinished.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': $(( 1729 )' + +expected_region_highlight=( + '1 1 builtin' # : + '3 12 default' # $(( 1729 ) + '3 12 arithmetic-expansion' # $(( 1729 ) +) + +if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug + expected_region_highlight[2]='3 13 default' # $(( 1729 ) +fi From 00c0c765509538de207173fc787d364eedd48d6b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 26 May 2020 17:52:17 +0000 Subject: [PATCH 287/297] CI += zsh-5.8 Fixes #740. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 39dd445..4ee2765 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: required env: - ZSH=master + - ZSH=5.8 - ZSH=5.7.1 - ZSH=5.7 - ZSH=5.6.2 From 0f11d80968e89071c0c978a6c7b50d11bcc744c5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jun 2020 14:23:43 +0000 Subject: [PATCH 288/297] 'main': Highlight the parentheses of array assignments as reserved words. Fixes #585. --- changelog.md | 4 ++++ highlighters/main/main-highlighter.zsh | 5 ++++- highlighters/main/test-data/array-cmdsep1.zsh | 1 + highlighters/main/test-data/array-cmdsep2.zsh | 2 ++ highlighters/main/test-data/array-cmdsep3.zsh | 2 ++ highlighters/main/test-data/assign-append.zsh | 2 ++ highlighters/main/test-data/assign-array.zsh | 2 ++ highlighters/main/test-data/assign-array2.zsh | 2 ++ highlighters/main/test-data/assign-array3.zsh | 2 ++ highlighters/main/test-data/assign.zsh | 2 ++ highlighters/main/test-data/bang-assign-array.zsh | 2 ++ highlighters/main/test-data/multiline-array-assignment1.zsh | 2 ++ .../main/test-data/param-positional-in-array-append.zsh | 1 + 13 files changed, 28 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 1dd1c1d..d68d15c 100644 --- a/changelog.md +++ b/changelog.md @@ -85,6 +85,10 @@ - Highlight arithmetic expansions (e.g., `$(( 42 ))`) [#607 #649 #704] +- Highlight the parentheses of array assignments as reserved words (`foo=( bar )`). + The `assign` style remains supported and has precedence. + [#585] + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6b3610c..25cbb0d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1007,6 +1007,7 @@ _zsh_highlight_main_highlighter_highlight_list() saw_assignment=true if [[ $arg[i] == '(' ]]; then in_array_assignment=true + _zsh_highlight_main_add_region_highlight start_pos+i-1 start_pos+i reserved-word else # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) @@ -1088,9 +1089,11 @@ _zsh_highlight_main_highlighter_highlight_list() ($'\x29') # subshell or end of array assignment if $in_array_assignment; then - style=assign + _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign + _zsh_highlight_main_add_region_highlight $start_pos $end_pos reserved-word in_array_assignment=false next_word+=':start:' + continue elif (( in_redirection )); then style=unknown-token else diff --git a/highlighters/main/test-data/array-cmdsep1.zsh b/highlighters/main/test-data/array-cmdsep1.zsh index 790c030..2fd55c0 100644 --- a/highlighters/main/test-data/array-cmdsep1.zsh +++ b/highlighters/main/test-data/array-cmdsep1.zsh @@ -33,6 +33,7 @@ bar(){} expected_region_highlight=( '1 3 assign' # a=( + '3 3 reserved-word' # ( '5 7 default' # foo '9 9 unknown-token' # | # zsh reports a parse error at this point. Nevertheless, we test how we diff --git a/highlighters/main/test-data/array-cmdsep2.zsh b/highlighters/main/test-data/array-cmdsep2.zsh index 2d2c865..0bda676 100644 --- a/highlighters/main/test-data/array-cmdsep2.zsh +++ b/highlighters/main/test-data/array-cmdsep2.zsh @@ -32,8 +32,10 @@ BUFFER=$'a=( foo ; bar )' expected_region_highlight=( '1 3 assign' # a=( + '3 3 reserved-word' # ( '5 7 default' # foo '9 9 unknown-token' # ; (not commandseparator; see highlighter source code) '11 13 default' # bar '15 15 assign' # ) + '15 15 reserved-word' # ) ) diff --git a/highlighters/main/test-data/array-cmdsep3.zsh b/highlighters/main/test-data/array-cmdsep3.zsh index def01b0..b4b3687 100644 --- a/highlighters/main/test-data/array-cmdsep3.zsh +++ b/highlighters/main/test-data/array-cmdsep3.zsh @@ -32,8 +32,10 @@ BUFFER=$'a=( foo \n bar )' expected_region_highlight=( '1 3 assign' # a=( + '3 3 reserved-word' # ( '5 7 default' # foo '9 9 commandseparator' # \n '11 13 default' # bar '15 15 assign' # ) + '15 15 reserved-word' # ) ) diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index eb9fbbd..feb68e5 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -31,7 +31,9 @@ BUFFER='a+=(lorem ipsum)' expected_region_highlight=( "1 4 assign" # a+=( + "4 4 reserved-word" # ( "5 9 default" # lorem "11 15 default" # ipsum "16 16 assign" # ) + "16 16 reserved-word" # ) ) diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh index 0624f9b..ef0a666 100644 --- a/highlighters/main/test-data/assign-array.zsh +++ b/highlighters/main/test-data/assign-array.zsh @@ -32,8 +32,10 @@ BUFFER='(A=(hello world))' expected_region_highlight=( "1 1 reserved-word" # ( "2 4 assign" # A=( + "4 4 reserved-word" # ( "5 9 default" # hello "11 15 default" # world "16 16 assign" # ) + "16 16 reserved-word" # ) "17 17 reserved-word" # ) ) diff --git a/highlighters/main/test-data/assign-array2.zsh b/highlighters/main/test-data/assign-array2.zsh index cdc9e63..2d48721 100644 --- a/highlighters/main/test-data/assign-array2.zsh +++ b/highlighters/main/test-data/assign-array2.zsh @@ -31,8 +31,10 @@ BUFFER='A=(hello world) ls' expected_region_highlight=( "1 3 assign" # A=( + "3 3 reserved-word" # ( "4 8 default" # hello "10 14 default" # world "15 15 assign" # ) + "15 15 reserved-word" # ) "17 18 command" # ls ) diff --git a/highlighters/main/test-data/assign-array3.zsh b/highlighters/main/test-data/assign-array3.zsh index 986d71f..5eb645e 100644 --- a/highlighters/main/test-data/assign-array3.zsh +++ b/highlighters/main/test-data/assign-array3.zsh @@ -31,9 +31,11 @@ BUFFER='A=(hello world) b=42' expected_region_highlight=( "1 3 assign" # A=( + "3 3 reserved-word" # ( "4 8 default" # hello "10 14 default" # world "15 15 assign" # ) + "15 15 reserved-word" # ) "17 20 assign" # b=42 "19 20 default" # 42 ) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 6e797ac..c6e8532 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -33,8 +33,10 @@ expected_region_highlight=( "1 3 assign" # A=1 "3 3 default" # 1 "5 7 assign" # b=( + "7 7 reserved-word" # ( "8 12 default" # "foo" "8 12 double-quoted-argument" # "foo" "14 16 default" # bar "17 17 assign" # ) + "17 17 reserved-word" # ) ) diff --git a/highlighters/main/test-data/bang-assign-array.zsh b/highlighters/main/test-data/bang-assign-array.zsh index 77b57e6..a54cf2d 100644 --- a/highlighters/main/test-data/bang-assign-array.zsh +++ b/highlighters/main/test-data/bang-assign-array.zsh @@ -32,9 +32,11 @@ BUFFER=$'foo=(bar abaz) \! ls' expected_region_highlight=( '1 5 assign' # foo=( + '5 5 reserved-word' # ( '6 8 default' # bar '10 13 default' # abaz '14 14 assign' # ) + '14 14 reserved-word' # ) '16 16 unknown-token' # \! '18 19 command' # ls ) diff --git a/highlighters/main/test-data/multiline-array-assignment1.zsh b/highlighters/main/test-data/multiline-array-assignment1.zsh index 2926d93..8906cfd 100644 --- a/highlighters/main/test-data/multiline-array-assignment1.zsh +++ b/highlighters/main/test-data/multiline-array-assignment1.zsh @@ -32,8 +32,10 @@ BUFFER=$'foo=(\nbar) env' expected_region_highlight=( '1 5 assign' # foo=( + '5 5 reserved-word' # ( '6 6 commandseparator' # \n '7 9 default' # bar '10 10 assign' # ) + '10 10 reserved-word' # ) '12 14 precommand' # env ) diff --git a/highlighters/main/test-data/param-positional-in-array-append.zsh b/highlighters/main/test-data/param-positional-in-array-append.zsh index 2af7f38..bd39e02 100644 --- a/highlighters/main/test-data/param-positional-in-array-append.zsh +++ b/highlighters/main/test-data/param-positional-in-array-append.zsh @@ -34,5 +34,6 @@ BUFFER=$'l+=( $1' expected_region_highlight=( '1 4 assign' # l+=( + '4 4 reserved-word' # ( '6 7 default' # $1 ) From 792c065acb003022160099fef303efafa161f735 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jun 2020 14:28:25 +0000 Subject: [PATCH 289/297] tests: Add an XFail test for issue #712. The second test point passes on 0.7.1, but the third does not. --- .../main/test-data/redirection-from-param.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/redirection-from-param.zsh diff --git a/highlighters/main/test-data/redirection-from-param.zsh b/highlighters/main/test-data/redirection-from-param.zsh new file mode 100644 index 0000000..86d2f6c --- /dev/null +++ b/highlighters/main/test-data/redirection-from-param.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2020 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 +# ------------------------------------------------------------------------------------------------- + +touch file +local fn=$PWD/file + +BUFFER=$'<$fn cat' + +expected_region_highlight=( + '1 1 redirection' # < + '2 4 path "issue #712"' # $fn + '6 8 command "issue #712"' # cat +) From 6fd92e1bbd927119e8fbb2d8f50d4cd9a6bcb6d9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jun 2020 14:38:14 +0000 Subject: [PATCH 290/297] 'main': Don't progress the $in_redirection staller while $in_param. Fixes #712. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/redirection-from-param.zsh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 25cbb0d..e59c61c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -617,7 +617,7 @@ _zsh_highlight_main_highlighter_highlight_list() if (( in_redirection == 0 )); then this_word=$next_word next_word=':regular:' - else + elif (( !in_param )); then # Stall $next_word. (( --in_redirection )) fi diff --git a/highlighters/main/test-data/redirection-from-param.zsh b/highlighters/main/test-data/redirection-from-param.zsh index 86d2f6c..42ae638 100644 --- a/highlighters/main/test-data/redirection-from-param.zsh +++ b/highlighters/main/test-data/redirection-from-param.zsh @@ -35,6 +35,6 @@ BUFFER=$'<$fn cat' expected_region_highlight=( '1 1 redirection' # < - '2 4 path "issue #712"' # $fn - '6 8 command "issue #712"' # cat + '2 4 path' # $fn + '6 8 command' # cat ) From f6f7a918187900bb3d84cc260951ed43f234317f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 11 Jun 2020 08:09:45 +0000 Subject: [PATCH 291/297] test harness: Fix use of an undefined variable in an error message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error message uses «$1», but it is always unset at that point. Furthermore, the NO_UNSET (-u) option is in effect. Therefore, when the error message was to be printed, zsh's NO_UNSET error message was printed instead: . (anon):20: 1: parameter not set That error message was printed to stderr, and was caught by the caller within the test harness: . Bail out! On './highlighters/main/test-data/path_prefix3.zsh': output on stderr Thus, the bug being fixed would not caused false positive or false negative test results, but only wrong error messages. Follow-up to 0.7.1-71-ge6eea1f, "test harness: Don't leak options from test files to the test harness". --- tests/test-highlighting.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 74ccc95..c30d571 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -144,7 +144,7 @@ run_test_internal() { } # Check the data declares $PREBUFFER or $BUFFER. - [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } + [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)ARG}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} From f6471dbec33e60d452abbb27ecdb36c59b4db05a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 11 Jun 2020 08:14:07 +0000 Subject: [PATCH 292/297] tests: Fix a wrong value of $PREBUFFER in a test, and add checks to prevent this from recurring. Discussed: https://github.com/zsh-users/zsh-syntax-highlighting/pull/706#issuecomment-642072978 --- highlighters/main/test-data/path_prefix3.zsh | 2 +- tests/test-highlighting.zsh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/path_prefix3.zsh b/highlighters/main/test-data/path_prefix3.zsh index f4a0189..9f34f94 100644 --- a/highlighters/main/test-data/path_prefix3.zsh +++ b/highlighters/main/test-data/path_prefix3.zsh @@ -30,7 +30,7 @@ # Assumes that '/bin/sh' exists and '/bin/s' does not exist. # Related to path_prefix.zsh -PREBUFFER='ls \' +PREBUFFER=$'ls \\\n' BUFFER='/bin/s' expected_region_highlight=( diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index c30d571..0e8e03e 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -145,6 +145,7 @@ run_test_internal() { # Check the data declares $PREBUFFER or $BUFFER. [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)ARG}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return ${RETURN:=1}; } + [[ $PREBUFFER == (''|*$'\n') ]] || { echo >&2 "Bail out! On ${(qq)ARG}: PREBUFFER=${(qqqq)PREBUFFER} doesn't end with a newline"; return ${RETURN:=1}; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} From 91d2eeaf23c47341e8dc7ad66dbf85e38c2674de Mon Sep 17 00:00:00 2001 From: Il Harper Date: Mon, 15 Jun 2020 13:11:30 +0800 Subject: [PATCH 293/297] docs: Fix obs-repository link --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 23acdf5..fc0f752 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -23,7 +23,7 @@ How to install [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting -[obs-repository]: https://software.opensuse.org//download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting +[obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) From fb929edc30192407a9298aad64f55ca1b19a464e Mon Sep 17 00:00:00 2001 From: Nuri Jung Date: Wed, 1 Jul 2020 21:38:38 +0900 Subject: [PATCH 294/297] docs: regexp highlighter: Fix a wrong associative array name in the example. Factored out from #747. --- docs/highlighters/regexp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 06b21ac..5c8a89e 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -11,7 +11,7 @@ To use this highlighter, associate regular expressions with styles in the `ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`: ```zsh -typeset -A ZSH_HIGHLIGHT_PATTERNS +typeset -A ZSH_HIGHLIGHT_REGEXP ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) ``` From 075c8529245c5cb4b51d5e86e4c20388dd1d76b5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 00:23:40 +0000 Subject: [PATCH 295/297] driver: Stop re-declaring $region_highlight. It's unneeded. --- zsh-syntax-highlighting.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 6c95e8c..d27d2cb 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -76,6 +76,13 @@ _zsh_highlight() # Make it read-only. Can't combine this with the previous line when POSIX_BUILTINS may be set. typeset -r ret + # $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array. + (( ${+region_highlight} )) || { + echo >&2 'zsh-syntax-highlighting: error: $region_highlight is not defined' + echo >&2 'zsh-syntax-highlighting: (Check whether zsh-syntax-highlighting was installed according to the instructions.)' + return $ret + } + # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains. # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'. # This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough @@ -118,7 +125,6 @@ _zsh_highlight() [[ $PENDING -gt 0 ]] && return $ret # Reset region highlight to build it from scratch - typeset -ga region_highlight region_highlight=(); { From 810c2dcedebcfef5458c0bbd5e2e01d63adc7059 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 00:24:04 +0000 Subject: [PATCH 296/297] Use the new, unreleased zsh 'memo=' feature to remove only our own entries from $region_highlight. Fixes #418 (interoperability issue with other plugins). --- HACKING.md | 16 ++++++ changelog.md | 24 ++++++++ highlighters/pattern/pattern-highlighter.zsh | 2 +- highlighters/regexp/regexp-highlighter.zsh | 2 +- tests/test-highlighting.zsh | 2 +- zsh-syntax-highlighting.zsh | 60 ++++++++++++++++++-- 6 files changed, 97 insertions(+), 9 deletions(-) diff --git a/HACKING.md b/HACKING.md index 71d8a2e..6fd195c 100644 --- a/HACKING.md +++ b/HACKING.md @@ -67,6 +67,22 @@ expected_region_highlight=( ) ``` +Memos and commas +---------------- + +We append to `region_highlight` as follows: + + +```zsh +region_highlight+=("$start $end $spec, memo=zsh-syntax-highlighting") +``` + +That comma is required to cause zsh 5.8 and older to ignore the memo without +ignoring the `$spec`. It's a hack, but given that no further 5.8.x patch +releases are planned, it's been deemed acceptable. See issue #418 and the +cross-referenced issues. + + Miscellany ---------- diff --git a/changelog.md b/changelog.md index d68d15c..daeda05 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,23 @@ # Changes in HEAD +## Notice about an improbable-but-not-impossible forward incompatibility + +Everyone can probably skip this section. + +The `master` branch of zsh-syntax-highlighting uses a zsh feature that has not +yet appeared in a zsh release: the `memo=` feature, added to zsh in commit +zsh-5.8-172-gdd6e702ee (after zsh 5.8, before zsh 5.9). In the unlikely event +that this zsh feature should change in an incompatible way before the next +stable zsh release, set `zsh_highlight__memo_feature=0` in your .zshrc files to +disable use of the new feature. + +z-sy-h dogfoods the new, unreleased zsh feature because that feature was +added to zsh at z-sy-h's initiative. The new feature is used in the fix +to issue #418. + + +## Other changes: + - Document `$ZSH_HIGHLIGHT_MAXLENGTH`. [#698] @@ -89,6 +107,12 @@ The `assign` style remains supported and has precedence. [#585] +- Fix interoperability issue with other plugins that use highlighting. The fix + requires zsh 5.8.0.3 or newer. (zsh 5.8.0.2-dev from the `master` branch, + revision zsh-5.8-172-gdd6e702ee or newer is also fine.) + [#418, https://github.com/okapia/zsh-viexchange/issues/1] + + # Changes in version 0.7.1 - Remove out-of-date information from the 0.7.0 changelog. diff --git a/highlighters/pattern/pattern-highlighter.zsh b/highlighters/pattern/pattern-highlighter.zsh index 054eff7..e0422d0 100644 --- a/highlighters/pattern/pattern-highlighter.zsh +++ b/highlighters/pattern/pattern-highlighter.zsh @@ -54,7 +54,7 @@ _zsh_highlight_pattern_highlighter_loop() local -a match mbegin mend local MATCH; integer MBEGIN MEND if [[ "$buf" == (#b)(*)(${~pat})* ]]; then - region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat]") + region_highlight+=("$((mbegin[2] - 1)) $mend[2] $ZSH_HIGHLIGHT_PATTERNS[$pat], memo=zsh-syntax-highlighting") "$0" "$match[1]" "$pat"; return $? fi } diff --git a/highlighters/regexp/regexp-highlighter.zsh b/highlighters/regexp/regexp-highlighter.zsh index 26f9da3..0d43aac 100644 --- a/highlighters/regexp/regexp-highlighter.zsh +++ b/highlighters/regexp/regexp-highlighter.zsh @@ -55,7 +55,7 @@ _zsh_highlight_regexp_highlighter_loop() local -a match mbegin mend while true; do [[ "$buf" =~ "$pat" ]] || return; - region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat]") + region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat], memo=zsh-syntax-highlighting") buf="$buf[$(($MEND+1)),-1]" OFFSET=$((MEND+OFFSET)); done diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 0e8e03e..30e93b1 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -190,7 +190,7 @@ run_test_internal() { if [[ $start != $exp_start ]] || [[ $end != $exp_end ]] || - [[ $highlight_zone[3] != $expected_highlight_zone[3] ]] + [[ ${highlight_zone[3]%,} != ${expected_highlight_zone[3]} ]] # remove the comma that's before the memo field then print -r -- "not ok $i - $desc - expected ($exp_start $exp_end ${(qqq)expected_highlight_zone[3]}), observed ($start $end ${(qqq)highlight_zone[3]}). $todo" if [[ -z $todo ]]; then (( ++print_expected_and_actual )); fi diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index d27d2cb..f98dc4b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -83,12 +83,63 @@ _zsh_highlight() return $ret } + # Probe the memo= feature, once. + (( ${+zsh_highlight__memo_feature} )) || { + region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" ) + case ${region_highlight[-1]} in + ("0 0 fg=red") + # zsh 5.8 or earlier + integer -gr zsh_highlight__memo_feature=0 + ;; + ("0 0 fg=red memo=zsh-syntax-highlighting") + # zsh 5.9 or later + integer -gr zsh_highlight__memo_feature=1 + ;; + (" 0 0 fg=red, memo=zsh-syntax-highlighting") ;& + (*) + # We can get here in two ways: + # + # 1. When not running as a widget. In that case, $region_highlight is + # not a special variable (= one with custom getter/setter functions + # written in C) but an ordinary one, so the third case pattern matches + # and we fall through to this block. (The test suite uses this codepath.) + # + # 2. When running under a future version of zsh that will have changed + # the serialization of $region_highlight elements from their underlying + # C structs, so that none of the previous case patterns will match. + # + # In either case, fall back to a version check. + # + # The memo= feature was added to zsh in commit zsh-5.8-172-gdd6e702ee. + # The version number at the time was 5.8.0.2-dev (see Config/version.mk). + # Therefore, on 5.8.0.3 and newer the memo= feature is available. + # + # On zsh version 5.8.0.2 between the aforementioned commit and the + # first Config/version.mk bump after it (which, at the time of writing, + # is yet to come), this condition will false negative. + if is-at-least 5.8.0.3; then + integer -gr zsh_highlight__memo_feature=1 + else + integer -gr zsh_highlight__memo_feature=0 + fi + ;; + esac + region_highlight[-1]=() + } + + # Reset region_highlight to build it from scratch + if (( zsh_highlight__memo_feature )); then + region_highlight=( "${(@)region_highlight:#*memo=zsh-syntax-highlighting*}" ) + else + # Legacy codepath. Not very interoperable with other plugins (issue #418). + region_highlight=() + fi + # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains. # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'. # This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough # and doesn't have the pattern matching bug if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) }; then - region_highlight=() return $ret fi @@ -124,9 +175,6 @@ _zsh_highlight() # Do not highlight if there are pending inputs (copy/paste). [[ $PENDING -gt 0 ]] && return $ret - # Reset region highlight to build it from scratch - region_highlight=(); - { local cache_place local -a region_highlight_copy @@ -245,7 +293,7 @@ _zsh_highlight_apply_zle_highlight() { else start=$second end=$first fi - region_highlight+=("$start $end $region") + region_highlight+=("$start $end $region, memo=zsh-syntax-highlighting") } @@ -285,7 +333,7 @@ _zsh_highlight_add_highlight() shift 2 for highlight; do if (( $+ZSH_HIGHLIGHT_STYLES[$highlight] )); then - region_highlight+=("$start $end $ZSH_HIGHLIGHT_STYLES[$highlight]") + region_highlight+=("$start $end $ZSH_HIGHLIGHT_STYLES[$highlight], memo=zsh-syntax-highlighting") break fi done From d9a7963970d6ae8b80d2a4db6af490d33869e812 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 01:56:21 +0000 Subject: [PATCH 297/297] driver: Follow-up to grandparent: Have all test suite entry points declare the mock $region_highlight. tests/generate.zsh already does this. --- tests/test-perfs.zsh | 1 + tests/test-zprof.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index a84e147..ff083de 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -48,6 +48,7 @@ } # Load the main script. +typeset -a region_highlight . ${0:h:h}/zsh-syntax-highlighting.zsh # Activate the highlighter. diff --git a/tests/test-zprof.zsh b/tests/test-zprof.zsh index 2538f7d..ada1618 100755 --- a/tests/test-zprof.zsh +++ b/tests/test-zprof.zsh @@ -29,6 +29,7 @@ # ------------------------------------------------------------------------------------------------- # Load the main script. +typeset -a region_highlight . ${0:h:h}/zsh-syntax-highlighting.zsh # Activate the highlighter.