From 56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b Mon Sep 17 00:00:00 2001 From: NAKAMURA Yoshitaka Date: Tue, 1 Nov 2011 20:02:03 +0900 Subject: [PATCH 0001/1080] fix "_zsh_highlight_widget_XXX:zle: unknown option: X" error --- 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 686daa4..2dcc6a7 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -142,16 +142,16 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget \"\$@\" && _zsh_highlight }; \ + _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Completion widget: override and rebind old one with prefix "orig-". completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget \"\$@\" && _zsh_highlight }; \ + _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget \"\$@\" && _zsh_highlight }; \ + builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Default: unhandled case. From d82eee521253c0bd5fa1090a332d892028685ffe Mon Sep 17 00:00:00 2001 From: Jud Porter Date: Fri, 2 Dec 2011 16:44:33 -0500 Subject: [PATCH 0002/1080] add emulate -L zsh to _zsh_highlight_main_highlighter. resolves issue #83 --- 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 7aede14..2032b81 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -61,6 +61,7 @@ _zsh_highlight_main_highlighter_predicate() # Main syntax highlighting function. _zsh_highlight_main_highlighter() { + emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true new_expression=true arg style typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR From 2c5c38144dac58fb3e48e8ffbba2e7233cfeea43 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Sat, 3 Dec 2011 19:26:46 +0100 Subject: [PATCH 0003/1080] close #84 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 233870c..9e98980 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ How to install * Download the script or clone this repository in [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh) plugins directory: - cd ~/.oh-my-zsh/plugins/ + cd ~/.oh-my-zsh/custom/plugins git clone git://github.com/zsh-users/zsh-syntax-highlighting.git * Activate the plugin in `~/.zshrc` (in **last** position): From 30c365e030d87f506c116698bf94a30c2b4acf30 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Sat, 3 Dec 2011 19:36:21 +0100 Subject: [PATCH 0004/1080] Add links to Arch Linux and Gentoo packages (Anyone knowing packages for other systems or wanting to create it, please get in touch!) --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 9e98980..9f47020 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ zsh-syntax-highlighting How to install -------------- +### Using packages + +* Arch Linux: [AUR/zsh-syntax-highlighting](https://aur.archlinux.org/packages.php?ID=54171) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages.php?ID=50867) +* Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting) + ### In your ~/.zshrc * Download the script or clone this repository: From 966eb851cac069301755c7124716e6cf0fffc2a9 Mon Sep 17 00:00:00 2001 From: "Jan M. Binder" Date: Sat, 7 Apr 2012 11:48:11 +0200 Subject: [PATCH 0005/1080] Added quotes to suppress error --- 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 2dcc6a7..cbd63e9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -107,7 +107,7 @@ typeset -gA ZSH_HIGHLIGHT_STYLES # Returns 0 if the buffer has changed since _zsh_highlight was last called. _zsh_highlight_buffer_modified() { - [[ ${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-} != $BUFFER ]] + [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] } # Whether the cursor has moved or not. From 732b7d6e65c0349ee1d89b698bf9cd8a30c1015d Mon Sep 17 00:00:00 2001 From: "Jan M. Binder" Date: Sat, 7 Apr 2012 17:09:15 +0200 Subject: [PATCH 0006/1080] Fix bracket highlighter --- highlighters/brackets/brackets-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 5166122..8e635dd 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -52,18 +52,18 @@ _zsh_highlight_brackets_highlighter() # Find all brackets and remember which one is matching for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do - local char=$BUFFER[pos+1] + local char="$BUFFER[pos+1]" case $char in ["([{"]) levelpos[$pos]=$((++level)) lastoflevel[$level]=$pos - _zsh_highlight_brackets_highlighter_brackettype $char + _zsh_highlight_brackets_highlighter_brackettype "$char" ;; [")]}"]) matching[$lastoflevel[$level]]=$pos matching[$pos]=$lastoflevel[$level] levelpos[$pos]=$((level--)) - _zsh_highlight_brackets_highlighter_brackettype $char + _zsh_highlight_brackets_highlighter_brackettype "$char" ;; ['"'\']) # Skip everything inside quotes From 19981ef9eae354ee004cd6b9a54bf07c0a94965c Mon Sep 17 00:00:00 2001 From: evan Date: Fri, 17 Aug 2012 15:52:09 -0400 Subject: [PATCH 0007/1080] added sudo as a precommand --- 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 2032b81..be1d0a9 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -73,7 +73,7 @@ _zsh_highlight_main_highlighter() '|' '||' ';' '&' '&&' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( - 'builtin' 'command' 'exec' 'nocorrect' 'noglob' + 'builtin' 'command' 'exec' 'nocorrect' 'noglob' 'sudo' ) # Tokens that are always immediately followed by a command. ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=( From b4e667795c6dc98a7807f9b0f43af39d249f662f Mon Sep 17 00:00:00 2001 From: Takeshi Banse Date: Sun, 9 Dec 2012 10:43:00 +0900 Subject: [PATCH 0008/1080] make $pattern local to _zsh_highlight_pattern_highlighter #97 Signed-off-by: Takeshi Banse --- highlighters/pattern/pattern-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/pattern/pattern-highlighter.zsh b/highlighters/pattern/pattern-highlighter.zsh index 93041a3..1cf6ef1 100644 --- a/highlighters/pattern/pattern-highlighter.zsh +++ b/highlighters/pattern/pattern-highlighter.zsh @@ -42,6 +42,7 @@ _zsh_highlight_pattern_highlighter_predicate() _zsh_highlight_pattern_highlighter() { setopt localoptions extendedglob + local pattern for pattern in ${(k)ZSH_HIGHLIGHT_PATTERNS}; do _zsh_highlight_pattern_highlighter_loop "$BUFFER" "$pattern" done From 408b100295b2531845aec1b2b65c5459e3fb6a11 Mon Sep 17 00:00:00 2001 From: Chris Knadler Date: Tue, 26 Feb 2013 17:59:53 -0800 Subject: [PATCH 0009/1080] Fix relative link in main readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f47020..a34d64c 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,12 @@ How to install plugins=( [plugins...] zsh-syntax-highlighting) * Source `~/.zshrc` to take changes into account: - + source ~/.zshrc How to tweak ------------ -Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](zsh-syntax-highlighting/tree/master/highlighters) +Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](highlighters) for documentation and configuration settings. From 612e493cba51bade9d4b0ea125deda09065feb64 Mon Sep 17 00:00:00 2001 From: Chris Knadler Date: Tue, 26 Feb 2013 18:03:35 -0800 Subject: [PATCH 0010/1080] Fix relative links in highlighters readme --- highlighters/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/README.md b/highlighters/README.md index 1b07564..0ea64c2 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -3,11 +3,11 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* [***main***](highlighters/main) - the base highlighter, and the only one active by default. -* [***brackets***](highlighters/brackets) - matches brackets and parenthesis. -* [***pattern***](highlighters/pattern) - matches user-defined patterns. -* [***cursor***](highlighters/cursor) - matches the cursor position. -* [***root***](highlighters/root) - triggered if the current user is root. +* [***main***](main) - the base highlighter, and the only one active by default. +* [***brackets***](brackets) - matches brackets and parenthesis. +* [***pattern***](pattern) - matches user-defined patterns. +* [***cursor***](cursor) - matches the cursor position. +* [***root***](root) - triggered if the current user is root. How to activate highlighters From 0fcc2629d220258fb3ab6a70c30fae6be2898fd1 Mon Sep 17 00:00:00 2001 From: Evan Pitstick Date: Fri, 8 Mar 2013 00:57:16 -0500 Subject: [PATCH 0011/1080] Finds highlighters dir a little better --- 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 cbd63e9..967287b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -198,7 +198,7 @@ _zsh_highlight_bind_widgets || { } # Resolve highlighters directory location. -_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${0:h}/highlighters}" || { +_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-$(dirname "$(readlink -f $0)")/highlighters}" || { echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2 return 1 } From 228f5a6aad0e2604a2e3a202026fd0fdb1c9c7f0 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 25 Jul 2013 04:41:09 +0200 Subject: [PATCH 0012/1080] add separate path_prefix and path_approx hilights --- highlighters/main/main-highlighter.zsh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index be1d0a9..2516e83 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,6 +41,8 @@ : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} @@ -82,6 +84,7 @@ _zsh_highlight_main_highlighter() for arg in ${(z)BUFFER}; do local substr_color=0 + local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}})) ((end_pos=$start_pos+${#arg})) @@ -138,6 +141,8 @@ _zsh_highlight_main_highlighter() ;; esac fi + # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it + [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] [[ $substr_color = 0 ]] && region_highlight+=("$start_pos $end_pos $style") [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true start_pos=$end_pos @@ -159,7 +164,15 @@ _zsh_highlight_main_highlighter_check_path() [[ -z $expanded_path ]] && return 1 [[ -e $expanded_path ]] && return 0 [[ ! -e ${expanded_path:h} ]] && return 1 - [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print ${expanded_path}*(N)) ]] && return 0 + if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]]; then + local -a tmp + # got a path prefix? + tmp=( ${expanded_path}*(N) ) + (( $#tmp > 0 )) && style_override=path_prefix && return 0 + # or maybe an approximate path? + tmp=( (#a1)${expanded_path}*(N) ) + (( $#tmp > 0 )) && style_override=path_approx && return 0 + fi return 1 } From 93827ed84dc1928b31c0678555c6d0fff125ccaa Mon Sep 17 00:00:00 2001 From: James Kyle Date: Thu, 25 Jul 2013 11:39:21 -0700 Subject: [PATCH 0013/1080] Issue #92 Eliminates system bell errors on osx. Prepended an 'if' to remove error bell on osx systems. --- highlighters/root/root-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/root/root-highlighter.zsh b/highlighters/root/root-highlighter.zsh index 4ef8762..294fda1 100644 --- a/highlighters/root/root-highlighter.zsh +++ b/highlighters/root/root-highlighter.zsh @@ -41,5 +41,5 @@ _zsh_highlight_root_highlighter_predicate() # root highlighting function. _zsh_highlight_root_highlighter() { - [[ $(command id -u) -eq 0 ]] && region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") + if [[ $(command id -u) -eq 0 ]] { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") } } From 8abcf187f6f3ac6a0d915daefe6f580784e739b3 Mon Sep 17 00:00:00 2001 From: Shura Date: Mon, 29 Jul 2013 17:33:34 +0400 Subject: [PATCH 0014/1080] dollar variable and backslash codes highlighting --- highlighters/main/main-highlighter.zsh | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index be1d0a9..d7f04d2 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -167,18 +167,35 @@ _zsh_highlight_main_highlighter_check_path() _zsh_highlight_main_highlighter_highlight_string() { setopt localoptions noksharrays - local i j k style + local i j k style varflag # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in - '$') style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument];; - "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] - (( k += 1 )) # Color following char too. - (( i += 1 )) # Skip parsing the escaped char. + '$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] + (( varflag = 1)) ;; - *) continue;; + "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] + for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do + [[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break + done + AA=$arg[$i+1,$c-1] + if [[ "$AA" =~ "^(0*(x|X)[0-9,a-f,A-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then + (( k += $#MATCH )) + (( i += $#MATCH )) + else + (( k += 1 )) # Color following char too. + (( i += 1 )) # Skip parsing the escaped char. + fi + (( varflag = 0 )) + ;; + ([^a-zA-Z0-9_])) + (( varflag = 0 )) + continue + ;; + *) [[ $varflag -eq 0 ]] && continue ;; + esac region_highlight+=("$j $k $style") done From 57c01d19deff8a9f4240af7e3cd67ace90947394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80?= Date: Wed, 7 Aug 2013 03:21:15 +0300 Subject: [PATCH 0015/1080] Update main-highlighter.zsh Add support of CDPATH --- highlighters/main/main-highlighter.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index be1d0a9..e8cf782 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -158,6 +158,10 @@ _zsh_highlight_main_highlighter_check_path() local expanded_path; : ${expanded_path:=${(Q)~arg}} [[ -z $expanded_path ]] && return 1 [[ -e $expanded_path ]] && return 0 + # Search the path in CDPATH + for cdpath_dir in $cdpath ; do + [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 + done [[ ! -e ${expanded_path:h} ]] && return 1 [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos && -n $(print ${expanded_path}*(N)) ]] && return 0 return 1 From a7ee0597ef696ef8f79af31f36ff8997b80e2368 Mon Sep 17 00:00:00 2001 From: Shura Date: Fri, 9 Aug 2013 10:24:14 +0400 Subject: [PATCH 0016/1080] Update main-highlighter.zsh Comments added --- 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 d7f04d2..dbe48da 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -181,6 +181,7 @@ _zsh_highlight_main_highlighter_highlight_string() [[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break done AA=$arg[$i+1,$c-1] + # Matching for HEX and OCT values like \0xA6, \xA6 or \012 if [[ "$AA" =~ "^(0*(x|X)[0-9,a-f,A-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then (( k += $#MATCH )) (( i += $#MATCH )) @@ -188,10 +189,10 @@ _zsh_highlight_main_highlighter_highlight_string() (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. fi - (( varflag = 0 )) + (( varflag = 0 )) # End of variable ;; ([^a-zA-Z0-9_])) - (( varflag = 0 )) + (( varflag = 0 )) # End of variable continue ;; *) [[ $varflag -eq 0 ]] && continue ;; From dbd27cb30a710809dd070669c331574fdc15b397 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Fri, 9 Aug 2013 09:56:28 +0200 Subject: [PATCH 0017/1080] #155: document path_prefix/path_approx --- highlighters/main/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 6900bfb..df0c195 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -32,6 +32,8 @@ This highlighter defines the following styles: * `commandseparator` - command separation tokens * `hashed-command` - hashed commands * `path` - paths +* `path_prefix` - path prefixes +* `path_approx` - approximated paths * `globbing` - globbing expressions * `history-expansion` - history expansion expressions * `single-hyphen-option` - single hyphen options From 3b3a58be9114687d21f03840ebc4c53365d5e604 Mon Sep 17 00:00:00 2001 From: Antoine Catton Date: Sat, 28 Sep 2013 19:33:34 -0600 Subject: [PATCH 0018/1080] Fix #121: sudo syntax highlighting incorrectly Parse sudo command line in order to highlight the options correctly --- highlighters/main/main-highlighter.zsh | 23 +++++++++++- highlighters/main/test-data/sudo-command.zsh | 39 ++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/sudo-command.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f70a286..4cb4a33 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -65,7 +65,7 @@ _zsh_highlight_main_highlighter() { emulate -L zsh setopt localoptions extendedglob bareglobqual - local start_pos=0 end_pos highlight_glob=true new_expression=true arg style + local start_pos=0 end_pos highlight_glob=true new_expression=true arg style sudo=false sudo_arg=false typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS @@ -75,7 +75,7 @@ _zsh_highlight_main_highlighter() '|' '||' ';' '&' '&&' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( - 'builtin' 'command' 'exec' 'nocorrect' 'noglob' 'sudo' + 'builtin' 'command' 'exec' 'nocorrect' 'noglob' ) # Tokens that are always immediately followed by a command. ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=( @@ -88,10 +88,29 @@ _zsh_highlight_main_highlighter() [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}})) ((end_pos=$start_pos+${#arg})) + # Parse the sudo command line + if $sudo; then + case "$arg" in + # Flag that requires an argument + '-'[Cgprtu]) sudo_arg=true;; + # This prevents misbehavior with sudo -u -otherargument + '-'*) sudo_arg=false;; + *) if $sudo_arg; then + sudo_arg=false + else + sudo=false + new_expression=true + fi + ;; + esac + fi if $new_expression; then new_expression=false if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] + elif [[ "$arg" = "sudo" ]]; then + style=$ZSH_HIGHLIGHT_STYLES[precommand] + sudo=true else res=$(LC_ALL=C builtin type -w $arg 2>/dev/null) case $res in diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh new file mode 100644 index 0000000..ce19f0c --- /dev/null +++ b/highlighters/main/test-data/sudo-command.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-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='sudo -u otheruser ls /' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "9 17 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "19 20 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "22 22 $ZSH_HIGHLIGHT_STYLES[path]" # / +) From dffbab0c9223818ff7f93dd6f1a3a550abcefda5 Mon Sep 17 00:00:00 2001 From: Evan Pitstick Date: Wed, 9 Oct 2013 12:02:34 -0400 Subject: [PATCH 0019/1080] a more simple and universal way (for zsh projects) to find highlight dir path --- 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 967287b..cdbe4c4 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -198,7 +198,7 @@ _zsh_highlight_bind_widgets || { } # Resolve highlighters directory location. -_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-$(dirname "$(readlink -f $0)")/highlighters}" || { +_zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2 return 1 } From 0fc6b0750985b56e7410f0ea67fc27b3fea25cd7 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Mon, 21 Oct 2013 21:18:38 +0900 Subject: [PATCH 0020/1080] Do not leak a variable: cdpath_dir. Leaking a variable that holds a path in CDPATH could easily end up appearing on your prompt like `~cdpath_dir/subdir`. --- 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 f70a286..21a40ea 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -164,6 +164,7 @@ _zsh_highlight_main_highlighter_check_path() [[ -z $expanded_path ]] && return 1 [[ -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 From c62cb54e9db82a64aa0975f84c2ab46a056e965e Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Wed, 30 Oct 2013 00:00:16 -0400 Subject: [PATCH 0021/1080] do not remove quotes when checking assignments Zsh does not allow the variable name or the equals sign to be quoted or escaped. The previous code incorrectly highlighted the following examples as assignments: $ 'x=y' zsh: command not found: x=y $ x\=y zsh: command not found: x=y $ "x"=y zsh: command not found: x=y $ \x=y zsh: command not found: x=y --- 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 f70a286..e2abcc1 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -153,7 +153,7 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_check_assign() { setopt localoptions extended_glob - [[ ${(Q)arg} == [[:alpha:]_]([[:alnum:]_])#=* ]] + [[ $arg == [[:alpha:]_]([[:alnum:]_])#=* ]] } # Check if the argument is a path. From 441f1a8aad75b6f3e80cdd05e2307896e162dd82 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Wed, 30 Oct 2013 00:46:17 -0400 Subject: [PATCH 0022/1080] highlight array assignments of the form x[y]=... This code is more lenient than bash. Examples: $ x[y[]= zsh: no matches found: x[y[]= $ x[][]= zsh: no matches found: x[][]= The proper solution is to look inside the [...] and make sure that all unescaped/unquoted square brackes are matched, but that is a heck of a lot more complicated than this simple 8-character patch. --- 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 e2abcc1..f69e656 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -153,7 +153,7 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_check_assign() { setopt localoptions extended_glob - [[ $arg == [[:alpha:]_]([[:alnum:]_])#=* ]] + [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])=* ]] } # Check if the argument is a path. From 784a5dc35b38aa23f651da70adcf4e72f31e4c30 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Tue, 5 Nov 2013 00:50:20 +0100 Subject: [PATCH 0023/1080] protect alias expansion from interpreting aliases as options If one defines aliases like `++` the alias builtin tries to interprete these as options so they have to be protected like this alias -- ++=true The same goes for a call to `alias` in order to expand the alias again. --- 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 f70a286..b2e942b 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -63,7 +63,7 @@ _zsh_highlight_main_highlighter_predicate() # Main syntax highlighting function. _zsh_highlight_main_highlighter() { - emulate -L zsh + emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true new_expression=true arg style typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR @@ -97,7 +97,7 @@ _zsh_highlight_main_highlighter() case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] - local aliased_command="${"$(alias $arg)"#*=}" + local aliased_command="${"$(alias -- $arg)"#*=}" [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg) ;; *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; From 04f9c8884fbb24dfaf79db56700d08946d39c126 Mon Sep 17 00:00:00 2001 From: sonnym Date: Sat, 7 Dec 2013 05:11:19 -0500 Subject: [PATCH 0024/1080] highlight ^old^new pattern by extending the already in place mechanism of checking for the first histchar to check for the second as well --- 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 72b48f0..5b038b4 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -128,7 +128,7 @@ _zsh_highlight_main_highlighter() new_expression=true elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] - elif [[ $arg[0,1] = $histchars[0,1] ]]; then + elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] From c83e266888b9ea4db05dbdc8d1df57ca34818eea Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 24 Dec 2013 12:40:35 +0100 Subject: [PATCH 0025/1080] #110: Now using :A modifier, bump zsh version requirement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a34d64c..0a9f19a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ zsh-syntax-highlighting **[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** -*Requirements: zsh 4.3.9+.* +*Requirements: zsh 4.3.17+.* How to install From dcb5da9457028e394e3fa66a373392cce6d8c947 Mon Sep 17 00:00:00 2001 From: Evgeniy Alexeev Date: Thu, 9 Jan 2014 04:21:35 +0300 Subject: [PATCH 0026/1080] Update README.md Edited links to Archlinux packages (the link to `zsh-syntax-highlighting-git` is out-of-date, and `zsh-syntax-highlighting` is now available in [community]) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a9f19a..7546395 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ How to install ### Using packages -* Arch Linux: [AUR/zsh-syntax-highlighting](https://aur.archlinux.org/packages.php?ID=54171) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages.php?ID=50867) +* Arch Linux: [community/zsh-syntax-highlighting](https://www.archlinux.org/packages/zsh-syntax-highlighting) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages/zsh-syntax-highlighting-git) * Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting) ### In your ~/.zshrc From e8cc271314612cf2aad1fe8e9e28d1a9c24ae0c8 Mon Sep 17 00:00:00 2001 From: Randy Date: Mon, 24 Mar 2014 08:45:34 +0200 Subject: [PATCH 0027/1080] Resolves slow performance in brackets highlighter --- highlighters/brackets/brackets-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 8e635dd..ee4a83b 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -49,6 +49,7 @@ _zsh_highlight_brackets_highlighter() { local level=0 pos local -A levelpos lastoflevel matching typepos + region_highlight=() # Find all brackets and remember which one is matching for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do From 7edd08156e98b8be451bd5a034714746894b2a3d Mon Sep 17 00:00:00 2001 From: Randy Date: Sat, 29 Mar 2014 22:52:10 +0200 Subject: [PATCH 0028/1080] Chaned main highlighter alorithm to resolve issue #77 --- zsh-syntax-highlighting.zsh | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index cdbe4c4..65f1938 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -54,37 +54,42 @@ _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 -a selected_highlighters local cache_place + local -a region_highlight_copy # Select which highlighters in ZSH_HIGHLIGHT_HIGHLIGHTERS need to be invoked. local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do + # eval cache place for current highlighter and prepare it + cache_place="_zsh_highlight_${highlighter}_highlighter_cache" + typeset -ga ${cache_place} + # If highlighter needs to be invoked if "_zsh_highlight_${highlighter}_highlighter_predicate"; then - # Mark the highlighter as selected for update. - selected_highlighters+=($highlighter) + # save a copy, and cleanup region_highlight + region_highlight_copy=("${region_highlight[@]}") + region_highlight=() - # Remove what was stored in its cache from region_highlight. - cache_place="_zsh_highlight_${highlighter}_highlighter_cache" - typeset -ga ${cache_place} - [[ ${#${(P)cache_place}} -gt 0 ]] && [[ ! -z ${region_highlight-} ]] && region_highlight=(${region_highlight:#(${(P~j.|.)cache_place})}) + # Execute highlighter and save result + { + "_zsh_highlight_${highlighter}_highlighter" + } always { + eval "${cache_place}=(\"\${region_highlight[@]}\")" + } + + # Restore saved region_highlight + region_highlight=("${region_highlight_copy[@]}") fi - done - # Invoke each selected highlighter and store the result in its cache. - local -a region_highlight_copy - for highlighter in $selected_highlighters; do - cache_place="_zsh_highlight_${highlighter}_highlighter_cache" - region_highlight_copy=($region_highlight) - { - "_zsh_highlight_${highlighter}_highlighter" - } always { - [[ ! -z ${region_highlight-} ]] && : ${(PA)cache_place::=${region_highlight:#(${(~j.|.)region_highlight_copy})}} - } + # Use value form cache if any cached + eval "region_highlight+=(\"\${${cache_place}[@]}\")" + done } always { From d7d4dff1c8bc95a462156e131f4d48b02962c5cd Mon Sep 17 00:00:00 2001 From: Joost Cassee Date: Sun, 8 Jun 2014 00:04:00 +0200 Subject: [PATCH 0029/1080] Add 'line' highlighter for the whole buffer --- highlighters/README.md | 1 + highlighters/line/README.md | 24 ++++++++++++++ highlighters/line/line-highlighter.zsh | 45 ++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 highlighters/line/README.md create mode 100644 highlighters/line/line-highlighter.zsh diff --git a/highlighters/README.md b/highlighters/README.md index 0ea64c2..987cc83 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -8,6 +8,7 @@ Syntax highlighting is done by pluggable highlighters: * [***pattern***](pattern) - matches user-defined patterns. * [***cursor***](cursor) - matches the cursor position. * [***root***](root) - triggered if the current user is root. +* [***line***](line) - applied to the whole command line How to activate highlighters diff --git a/highlighters/line/README.md b/highlighters/line/README.md new file mode 100644 index 0000000..2be32a2 --- /dev/null +++ b/highlighters/line/README.md @@ -0,0 +1,24 @@ +zsh-syntax-highlighting / highlighters / line +================================================= + +This is the ***line*** highlighter, that highlights the whole line. + + +How to activate it +------------------ +To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line) + + +How to tweak it +--------------- +This highlighter defines the following styles: + +* `line` - the style for the whole line + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[line]='bold' + +The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/line/line-highlighter.zsh b/highlighters/line/line-highlighter.zsh new file mode 100644 index 0000000..230c587 --- /dev/null +++ b/highlighters/line/line-highlighter.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 default styles. +: ${ZSH_HIGHLIGHT_STYLES[line]:=} + +# Whether the root highlighter should be called or not. +_zsh_highlight_line_highlighter_predicate() +{ + _zsh_highlight_buffer_modified +} + +# root highlighting function. +_zsh_highlight_line_highlighter() +{ + region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[line]") +} From 74a183447d88a10ba55273a7b5a794f62d72ef2d Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 29 Jun 2014 11:52:32 +0200 Subject: [PATCH 0030/1080] zle: don't override yank/yank-pop `yank-pop` relies on the fact that the last zle command is `yank` or `yank-pop` to work correctly. Rewriting them prevents this check to work correctly breaking `yank-pop`. This fix just disallow overriding of those two zle commands. As a side-effect, syntax highlighting will not happen when using. This fixes #99. --- 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 cdbe4c4..7d780d2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -134,7 +134,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From a723f504a51552ed5ac98f8d30ddf32b188ade3b Mon Sep 17 00:00:00 2001 From: George Angelopoulos Date: Tue, 5 Aug 2014 17:04:52 +0300 Subject: [PATCH 0031/1080] README: make installation step 1 more accurate You cannot download just the "script". You need the entire directory/repo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7546395..d2b9d0e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ How to install ### In your ~/.zshrc -* Download the script or clone this repository: +* [Download](https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz) or clone this repository: git clone git://github.com/zsh-users/zsh-syntax-highlighting.git From 0c8c4b73f81d1b9918ab47e9f0528d49eba2915e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Jan 2015 09:08:31 +0000 Subject: [PATCH 0032/1080] README: give the rationale for the at-end-of-.zshrc requirement --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 7546395..aff1c8a 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,14 @@ How to install source ~/.zshrc +FAQ +--- + +### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file? + +`zsh-syntax-highlighting.zsh` wraps ZLE widgets. It must be sourced after all +custom widgets have been created (`zle -N`). + How to tweak ------------ From 2c5acaefa930600acdcec3d8a7322193ae032aeb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Jan 2015 12:49:19 +0000 Subject: [PATCH 0033/1080] Refactoring, no functional change The new function will be used in the next commit. --- highlighters/main/main-highlighter.zsh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5b038b4..18d5bc4 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -60,6 +60,13 @@ _zsh_highlight_main_highlighter_predicate() _zsh_highlight_buffer_modified } +# Helper to deal with tokens crossing line boundaries. +_zsh_highlight_main_add_region_highlight() { + integer start=$1 end=$2 + local style=$3 + region_highlight+=("$start $end $style") +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -142,7 +149,7 @@ _zsh_highlight_main_highlighter() '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; "'"*"'") style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; '"'*'"') style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] - region_highlight+=("$start_pos $end_pos $style") + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_string substr_color=1 ;; @@ -162,7 +169,7 @@ _zsh_highlight_main_highlighter() fi # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] - [[ $substr_color = 0 ]] && region_highlight+=("$start_pos $end_pos $style") + [[ $substr_color = 0 ]] && _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true start_pos=$end_pos done @@ -235,6 +242,6 @@ _zsh_highlight_main_highlighter_highlight_string() *) [[ $varflag -eq 0 ]] && continue ;; esac - region_highlight+=("$j $k $style") + _zsh_highlight_main_add_region_highlight $j $k $style done } From 667495bfb7f7b27fb95d4773554bedef0042b95e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Jan 2015 14:03:08 +0000 Subject: [PATCH 0034/1080] Support multiline strings --- highlighters/main/main-highlighter.zsh | 13 ++++++- .../main/test-data/multiline-string.zsh | 37 +++++++++++++++++++ tests/test-highlighting.zsh | 8 ++-- 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 highlighters/main/test-data/multiline-string.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 18d5bc4..516600f 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -64,6 +64,14 @@ _zsh_highlight_main_highlighter_predicate() _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 local style=$3 + + # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is + # relative to $BUFFER. + (( start -= $#PREBUFFER )) + (( end -= $#PREBUFFER )) + + (( end < 0 )) && return # bug + (( start < 0 )) && start=0 # normal with e.g. multiline strings region_highlight+=("$start $end $style") } @@ -76,6 +84,7 @@ _zsh_highlight_main_highlighter() typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS + local buf="$PREBUFFER$BUFFER" region_highlight=() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( @@ -89,11 +98,11 @@ _zsh_highlight_main_highlighter() $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS ) - for arg in ${(z)BUFFER}; do + for arg in ${(z)buf}; do local substr_color=0 local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false - ((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]##[[:space:]]#}})) + ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##[[:space:]]#}})) ((end_pos=$start_pos+${#arg})) # Parse the sudo command line if $sudo; then diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh new file mode 100644 index 0000000..f2eb13e --- /dev/null +++ b/highlighters/main/test-data/multiline-string.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo "foo1\n' +BUFFER='foo2" ./' + +expected_region_highlight=( + "0 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' + "7 8 $ZSH_HIGHLIGHT_STYLES[path]" # './' +) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 2e72b2b..fdca16f 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -60,13 +60,13 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) for data_file in ${0:h:h}/highlighters/$1/test-data/*; do # Load the data and prepare checking it. - BUFFER= ; expected_region_highlight=(); errors=() + PREBUFFER= BUFFER= ; expected_region_highlight=(); errors=() echo -n "* ${data_file:t:r}: " . $data_file - # Check the data declares $BUFFER. - if [[ ${#BUFFER} -eq 0 ]]; then - errors+=("'BUFFER' is not declared or blank.") + # Check the data declares $PREBUFFER or $BUFFER. + if [[ ${#PREBUFFER} -eq 0 && ${#BUFFER} -eq 0 ]]; then + errors+=("Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank") else # Check the data declares $expected_region_highlight. From 23cacb12fe9a3580fa9ec45d625218a05a146779 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Jan 2015 15:17:49 +0000 Subject: [PATCH 0035/1080] Support backslash continuations --- highlighters/main/main-highlighter.zsh | 2 +- .../main/test-data/backslash-continuation.zsh | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/backslash-continuation.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 516600f..fa495c7 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -102,7 +102,7 @@ _zsh_highlight_main_highlighter() local substr_color=0 local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false - ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##[[:space:]]#}})) + ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) # Parse the sudo command line if $sudo; then diff --git a/highlighters/main/test-data/backslash-continuation.zsh b/highlighters/main/test-data/backslash-continuation.zsh new file mode 100644 index 0000000..f0b22f7 --- /dev/null +++ b/highlighters/main/test-data/backslash-continuation.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo \\\n' +BUFFER='noglob' + +expected_region_highlight=( + "0 6 none" # 'noglob' highlighted as a string, not as a precomand +) From 384be15b130a54d19e3d0183b645edd440645ccb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Jan 2015 15:39:42 +0000 Subject: [PATCH 0036/1080] Support literal newlines --- highlighters/main/main-highlighter.zsh | 21 ++++++++++ .../main/test-data/vanilla-newline.zsh | 40 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 highlighters/main/test-data/vanilla-newline.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index fa495c7..657fcd3 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -104,6 +104,27 @@ _zsh_highlight_main_highlighter() [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) + + # Deal with faked colons. + # + # 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). + if [[ $arg == ';' ]] ; then + if [[ $buf[start_pos+1] == ';' ]] ; then + # Literally-input colon. That's the normal case. + elif [[ $buf[start_pos] == $'\n' ]] ; then + # Newline token rendered as a colon. Empirically we're off-by-one. + (( start_pos -= 1 )) + (( end_pos -= 1 )) + else + # Currently, there aren't any other sources of ";" (SEPER) tokens + # besides literally-input semicolons and (Z+n+)-converted newlines, + # If that ever changes, handle them here. + fi + fi + # Parse the sudo command line if $sudo; then case "$arg" in diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh new file mode 100644 index 0000000..b876928 --- /dev/null +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +PREBUFFER=$'echo foo; echo bar\n\n\n' +BUFFER='echo baz; echo qux' + +expected_region_highlight=( + "0 4 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "5 7 $ZSH_HIGHLIGHT_STYLES[default]" # baz + "8 9 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon + "11 14 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "16 18 $ZSH_HIGHLIGHT_STYLES[default]" # qux +) From ff4d402e9a587e0e8f8400a3aeac40a8f73215e5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Jan 2015 13:28:09 +0000 Subject: [PATCH 0037/1080] Highlight the first part of multiline strings correctly Given the following input: PREBUFFER=$'echo "foo\n' BUFFER='bar"' This patch causes the '"foo' part to be highlighted as a string. There is no test because the tests only check highlighting of BUFFER, and 'bar"' is already highlighted correctly. --- highlighters/main/main-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 657fcd3..2c9120a 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -177,13 +177,13 @@ _zsh_highlight_main_highlighter() case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; - "'"*"'") style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; - '"'*'"') style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] + "'"*) style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; + '"'*) style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_string substr_color=1 ;; - '`'*'`') style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; + '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] From 359d48bf78f510081bf0413f65ee41968648d543 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Jan 2015 14:02:35 +0000 Subject: [PATCH 0038/1080] Don't highlight prefix redirections as error Fixes zsh-users/zsh-syntax-highlighting#146 --- highlighters/main/main-highlighter.zsh | 12 +++++- .../main/test-data/prefix-redirection.zsh | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/prefix-redirection.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5b038b4..639aaa3 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -66,6 +66,7 @@ _zsh_highlight_main_highlighter() emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true new_expression=true arg style sudo=false sudo_arg=false + local redirection=false # true when we've seen a redirection operator before seeing the command word typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS @@ -104,7 +105,7 @@ _zsh_highlight_main_highlighter() ;; esac fi - if $new_expression; then + if $new_expression && ! $redirection; then # $arg is the command word new_expression=false if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] @@ -130,13 +131,20 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + style=$ZSH_HIGHLIGHT_STYLE[redirection] + redirection=true else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi ;; esac fi - else + else # $arg is the file target of a prefix redirection, or a non-command word + if $redirection; then + redirection=false + new_expression=true + fi case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh new file mode 100644 index 0000000..c1152fb --- /dev/null +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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='>/tmp >/tmp sudo echo foo' + +expected_region_highlight=( + "2 5 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "7 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "13 16 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "18 21 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "23 25 $ZSH_HIGHLIGHT_STYLES[default]" # foo +) From b9b67b9f78baade6faa43d1675986d0640566698 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Aug 2015 09:44:14 +0000 Subject: [PATCH 0039/1080] Don't parse first word of array assignment as command Fixes zsh-users/zsh-syntax-highlighting#178 --- highlighters/main/main-highlighter.zsh | 6 +++++- highlighters/main/test-data/assign.zsh | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5b038b4..1bd1809 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -125,7 +125,11 @@ _zsh_highlight_main_highlighter() *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; *) if _zsh_highlight_main_highlighter_check_assign; then style=$ZSH_HIGHLIGHT_STYLES[assign] - new_expression=true + if [[ $arg[-1] != '(' ]]; then + # assignment to a scalar parameter. + # (For array assignments, the command doesn't start until the ")" token.) + new_expression=true + fi elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 0401bf4..61edd6d 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -28,8 +28,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='A=1' +BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 + "8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" ) From 52ece975c393f5f7e1d2bbfecb19124fc696f918 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 2 Sep 2015 02:37:43 +0000 Subject: [PATCH 0040/1080] Update comments. No functional change. --- 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 2c9120a..f5711c9 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -70,8 +70,8 @@ _zsh_highlight_main_add_region_highlight() { (( start -= $#PREBUFFER )) (( end -= $#PREBUFFER )) - (( end < 0 )) && return # bug - (( start < 0 )) && start=0 # normal with e.g. multiline strings + (( end < 0 )) && return # having end<0 would be a bug + (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings region_highlight+=("$start $end $style") } @@ -102,6 +102,7 @@ _zsh_highlight_main_highlighter() local substr_color=0 local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false + # advance $start_pos, skipping over whitespace in $buf. ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) From c2b9327b0763f3457fb09db17e22ee9e1e024792 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 2 Sep 2015 08:28:03 +0000 Subject: [PATCH 0041/1080] Support literal newlines, part 2 --- highlighters/main/main-highlighter.zsh | 36 +++++++++---------- .../main/test-data/vanilla-newline.zsh | 12 +++---- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f5711c9..ad31b4c 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -102,28 +102,24 @@ _zsh_highlight_main_highlighter() local substr_color=0 local style_override="" [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false - # advance $start_pos, skipping over whitespace in $buf. - ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) - ((end_pos=$start_pos+${#arg})) - # Deal with faked colons. - # - # 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). + # advance $start_pos, skipping over whitespace in $buf. if [[ $arg == ';' ]] ; then - if [[ $buf[start_pos+1] == ';' ]] ; then - # Literally-input colon. That's the normal case. - elif [[ $buf[start_pos] == $'\n' ]] ; then - # Newline token rendered as a colon. Empirically we're off-by-one. - (( start_pos -= 1 )) - (( end_pos -= 1 )) - else - # Currently, there aren't any other sources of ";" (SEPER) tokens - # besides literally-input semicolons and (Z+n+)-converted newlines, - # If that ever changes, handle them here. - fi + # 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=${${buf[start_pos+1,-1]}[(i)$needle]} + (( start_pos += offset )) + (( end_pos += offset )) + else + ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) + ((end_pos=$start_pos+${#arg})) fi # Parse the sudo command line diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index b876928..f0c8eac 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -29,12 +29,12 @@ # ------------------------------------------------------------------------------------------------- PREBUFFER=$'echo foo; echo bar\n\n\n' -BUFFER='echo baz; echo qux' +BUFFER=' echo baz; echo qux' expected_region_highlight=( - "0 4 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "5 7 $ZSH_HIGHLIGHT_STYLES[default]" # baz - "8 9 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon - "11 14 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "16 18 $ZSH_HIGHLIGHT_STYLES[default]" # qux + "1 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # baz + "9 10 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon + "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux ) From 13a8db1d71aa78a517cc2b4896e69f59870ce7b3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 09:27:51 +0000 Subject: [PATCH 0042/1080] tests: exit non-zero upon failure --- tests/test-highlighting.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index fdca16f..64655ee 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -49,6 +49,7 @@ local -a errors highlight_zone local -A observed_result +integer something_failed=0 # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh @@ -107,9 +108,12 @@ for data_file in ${0:h:h}/highlighters/$1/test-data/*; do echo "OK" else echo "KO" + (( something_failed=1 )) for error in $errors; do echo " - $error" done fi done + +exit $something_failed From 7f41967a17d0620dfd10617c3bc0dfb48e4cbb34 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 09:38:02 +0000 Subject: [PATCH 0043/1080] Highlight array appends: foo+=(bar baz). Fixes zsh-users/zsh-syntax-highlighting#181. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/assign-append.zsh | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/assign-append.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 975df35..540442c 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -218,7 +218,7 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_check_assign() { setopt localoptions extended_glob - [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])=* ]] + [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] } # Check if the argument is a path. diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh new file mode 100644 index 0000000..29e759a --- /dev/null +++ b/highlighters/main/test-data/assign-append.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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+=(lorem ipsum)' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[assign]" # a+=( +) From 8e7c26f489f952213bbb269a0570384184c0f6fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 12:50:32 +0000 Subject: [PATCH 0044/1080] Do wrap the 'yank' widget, because that works. Partly reverts eb9870f4db1cf347456af0867e1c1ae47252b209 which was PR #143 to fix issue #99. --- 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 937e426..e418187 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -139,7 +139,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank-pop)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From 546a5288e243c3fabd98fc1a4d60165fa2a257a9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 15:08:08 +0000 Subject: [PATCH 0045/1080] multiline strings: Add a second test for commit ff4d402e9a587e0e8f8400a3aeac40a8f73215e5 --- .../main/test-data/multiline-string2.zsh | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 highlighters/main/test-data/multiline-string2.zsh diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh new file mode 100644 index 0000000..03626af --- /dev/null +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'echo "foo1\n' + +expected_region_highlight=( + "6 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' +) From eaffd88793e82e27b65017e669b545a3f97d33f5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 19:21:52 +0000 Subject: [PATCH 0046/1080] docs: Document homebrew package name. Fixes zsh-users/zsh-syntax-highlighting#156. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 794c14d..fac07e2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ How to install * Arch Linux: [community/zsh-syntax-highlighting](https://www.archlinux.org/packages/zsh-syntax-highlighting) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages/zsh-syntax-highlighting-git) * Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting) +* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting](https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb) ### In your ~/.zshrc From f78919d941d3418681622e74731d76b1e944d2a1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 5 Sep 2015 21:44:11 +0000 Subject: [PATCH 0047/1080] Preserve $? of wrapped widgets. --- 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 e418187..ef62139 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -42,11 +42,11 @@ typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS # This function is supposed to be called whenever the ZLE state changes. _zsh_highlight() { - setopt localoptions nowarncreateglobal - # Store the previous command return code to restore it whatever happens. local ret=$? + setopt localoptions nowarncreateglobal + # Do not highlight if there are more than 300 chars in the buffer. It's most # likely a pasted command or a huge list of files in that case.. [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret From d330b49b33bed50e295dee6850ac46136ff29372 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 6 Sep 2015 19:20:49 +0000 Subject: [PATCH 0048/1080] Fix variable leakage into global namespace. Similar to zsh-users/zsh-syntax-highlighting#97. --- 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 540442c..d1d75de 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -147,7 +147,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] sudo=true else - res=$(LC_ALL=C builtin type -w $arg 2>/dev/null) + local res=$(LC_ALL=C builtin type -w $arg 2>/dev/null) case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] From a0b5bc6c71a80b97a0826c7b2fc30eec7e80b442 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 7 Sep 2015 01:26:11 +0000 Subject: [PATCH 0049/1080] Fix bug in previous commit (d330b49b33bed50e295dee6850ac46136ff29372) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'local' is a reserved word in zsh 5.1 but not in earlier versions [1]. Therefore, under zsh older than 5.1, quoting is required. This manifested as random «builtin=''» in emitted to the terminal, and commands (such as 'echo') highlighted as errors (in red). [1] https://github.com/zsh-users/zsh/blob/master/README#L46 (the section "Incompatibilites between 5.0.8 and 5.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 d1d75de..0841989 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -147,7 +147,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] sudo=true else - local res=$(LC_ALL=C builtin type -w $arg 2>/dev/null) + local res="$(LC_ALL=C builtin type -w $arg 2>/dev/null)" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] From b3ceea85113d4dddf8f765708d5e271d62529685 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 7 Sep 2015 09:08:58 +0000 Subject: [PATCH 0050/1080] Highlight 'noglob' correctly in more cases. Fixes zsh-users/zsh-syntax-highlighting#189. --- highlighters/main/main-highlighter.zsh | 11 +++++--- highlighters/main/test-data/noglob1.zsh | 35 ++++++++++++++++++++++++ highlighters/main/test-data/noglob2.zsh | 36 +++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 highlighters/main/test-data/noglob1.zsh create mode 100644 highlighters/main/test-data/noglob2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0841989..8d1d134 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -102,7 +102,9 @@ _zsh_highlight_main_highlighter() for arg in ${(z)buf}; do local substr_color=0 local style_override="" - [[ $start_pos -eq 0 && $arg = 'noglob' ]] && highlight_glob=false + if $new_expression && [[ $arg = 'noglob' ]]; then + highlight_glob=false + fi # advance $start_pos, skipping over whitespace in $buf. if [[ $arg == ';' ]] ; then @@ -134,7 +136,7 @@ _zsh_highlight_main_highlighter() sudo_arg=false else sudo=false - new_expression=true + new_expression=true; highlight_glob=true fi ;; esac @@ -163,7 +165,7 @@ _zsh_highlight_main_highlighter() if [[ $arg[-1] != '(' ]]; then # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) - new_expression=true + new_expression=true; highlight_glob=true fi elif _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] @@ -181,7 +183,7 @@ _zsh_highlight_main_highlighter() else # $arg is the file target of a prefix redirection, or a non-command word if $redirection; then redirection=false - new_expression=true + new_expression=true; highlight_glob=true fi case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; @@ -210,6 +212,7 @@ _zsh_highlight_main_highlighter() [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] [[ $substr_color = 0 ]] && _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos done } diff --git a/highlighters/main/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh new file mode 100644 index 0000000..fe17e07 --- /dev/null +++ b/highlighters/main/test-data/noglob1.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 *' + +expected_region_highlight=( + "16 16 $ZSH_HIGHLIGHT_STYLES[default]" # * +) diff --git a/highlighters/main/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh new file mode 100644 index 0000000..9b1e4ed --- /dev/null +++ b/highlighters/main/test-data/noglob2.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 *; echo *' + +expected_region_highlight=( + "13 13 $ZSH_HIGHLIGHT_STYLES[default]" # * + "21 21 $ZSH_HIGHLIGHT_STYLES[globbing]" # * +) From 9310d8ae7119f557a7ca0e180463cccaef9f593b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 4 Sep 2015 18:19:26 +0000 Subject: [PATCH 0051/1080] Support suffix aliases Fixes zsh-users/zsh-syntax-highlighting#126. --- highlighters/main/README.md | 1 + highlighters/main/main-highlighter.zsh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index df0c195..4de2c15 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -25,6 +25,7 @@ This highlighter defines the following styles: * `unknown-token` - unknown tokens / errors * `reserved-word` - shell reserved words * `alias` - aliases +* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) * `builtin` - shell builtin commands * `function` - functions * `command` - commands diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0841989..6e7cbe5 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -34,6 +34,7 @@ : ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} : ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green} @@ -150,6 +151,9 @@ _zsh_highlight_main_highlighter() local res="$(LC_ALL=C builtin type -w $arg 2>/dev/null)" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; + *': suffix alias') + style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] + ;; *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] local aliased_command="${"$(alias -- $arg)"#*=}" [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg) From dc701501e5ff940f36f4aa34acc36c921ad7fe8d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 6 Sep 2015 19:07:32 +0000 Subject: [PATCH 0052/1080] Highlight ? as globbing. Fixes zsh-users/zsh-syntax-highlighting#94. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/glob.zsh | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/glob.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0841989..890e012 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -193,7 +193,7 @@ _zsh_highlight_main_highlighter() substr_color=1 ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; - *"*"*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; + *[*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] = $histchars[0,1] ]]; then diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh new file mode 100644 index 0000000..bf8e3be --- /dev/null +++ b/highlighters/main/test-data/glob.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 $ZSH_HIGHLIGHT_STYLES[builtin]" # : + "3 6 $ZSH_HIGHLIGHT_STYLES[globbing]" # foo* + "8 11 $ZSH_HIGHLIGHT_STYLES[globbing]" # bar? +) From 555e142e66ec7eb2c2a18489ef615b394bc62609 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 8 Sep 2015 10:13:16 +0000 Subject: [PATCH 0053/1080] suffix aliases: Highlight differently. Add an underline, since they are at command word position but will be executed by something else. Suggested-by: Daniel Hahler --- 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 f665f45..c0b2816 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -34,7 +34,7 @@ : ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} : ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green} -: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green} +: ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green} From 0e31d6e1a298adfce9596b7048f207c9940d495d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 8 Sep 2015 20:22:22 +0000 Subject: [PATCH 0054/1080] Highlight the region on top of syntax highlighting. Let $zle_highlight[region] override $region_highlight. --- zsh-syntax-highlighting.zsh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index ef62139..e105a9f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -92,6 +92,22 @@ _zsh_highlight() done + # Re-apply zle_highlight settings + () { + if (( REGION_ACTIVE )) ; then + # zle_highlight[region] defaults to 'standout' if unspecified + local region="${${zle_highlight[(r)region:*]#region:}:-standout}" + integer start end + if (( MARK > CURSOR )) ; then + start=$CURSOR end=$MARK + else + start=$MARK end=$CURSOR + fi + region_highlight+=("$start $end $region") + fi + } + + } always { _ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR From e5c2a88db023600d7aeacbb2b7d640e0c8671a83 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 8 Sep 2015 20:22:22 +0000 Subject: [PATCH 0055/1080] Highlight yanks/pastes on top of syntax highlighting. Let $zle_highlight[paste] override $region_highlight. --- zsh-syntax-highlighting.zsh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index e105a9f..012ea0b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -106,6 +106,21 @@ _zsh_highlight() region_highlight+=("$start $end $region") fi } + # YANK_ACTIVE is only available in zsh-5.1.1 and newer + (( $+YANK_ACTIVE )) && () { + if (( YANK_ACTIVE )) ; then + # zle_highlight[paste] defaults to 'standout' if unspecified + local paste="${${zle_highlight[(r)paste:*]#paste:}:-standout}" + integer start end + if (( YANK_END > YANK_START )) ; then + start=$YANK_START end=$YANK_END + else + start=$YANK_END end=$YANK_START + fi + region_highlight+=("$start $end $paste") + fi + } + } always { From 4f5a0fe60b96976caf714db502d893a982ec3bd1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 10 Sep 2015 19:44:19 +0000 Subject: [PATCH 0056/1080] main highlighter docs: Give examples of styles. --- highlighters/main/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 4de2c15..7934769 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -35,15 +35,15 @@ This highlighter defines the following styles: * `path` - paths * `path_prefix` - path prefixes * `path_approx` - approximated paths -* `globbing` - globbing expressions -* `history-expansion` - history expansion expressions -* `single-hyphen-option` - single hyphen options -* `double-hyphen-option` - double hyphen options -* `back-quoted-argument` - backquoted expressions -* `single-quoted-argument` - single quoted arguments -* `double-quoted-argument` - double quoted arguments -* `dollar-double-quoted-argument` - dollar double quoted arguments -* `back-double-quoted-argument` - back double quoted arguments +* `globbing` - globbing expressions (`*.txt`) +* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) +* `single-hyphen-option` - single hyphen options (-o) +* `double-hyphen-option` - double hyphen options (--option) +* `back-quoted-argument` - backquoted expressions (`` `foo` ``) +* `single-quoted-argument` - single quoted arguments (`` 'foo' ``) +* `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") +* `back-double-quoted-argument` - back double quoted arguments (\x inside "") * `assign` - variable assignments * `default` - parts of the buffer that do not match anything From 6d93ea07fd61503793cede3f5589feebc1483a1c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 10 Sep 2015 19:44:19 +0000 Subject: [PATCH 0057/1080] main highlighter docs: README: Tweak. --- highlighters/main/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 7934769..0c69335 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -49,6 +49,9 @@ 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 + # To differentiate aliases from other command types ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold' @@ -58,4 +61,5 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for # To disable highlighting of globbing expressions ZSH_HIGHLIGHT_STYLES[globbing]='none' -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). From a8afbdf2f548b6782d2a33d40c6d72464e23beee Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 10 Sep 2015 19:58:02 +0000 Subject: [PATCH 0058/1080] Support $''-quoted strings. This does not yet highlight backslash escapes within them. --- highlighters/main/README.md | 1 + highlighters/main/main-highlighter.zsh | 3 ++ highlighters/main/test-data/dollar-quoted.zsh | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/dollar-quoted.zsh diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 0c69335..5bdc017 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -42,6 +42,7 @@ This highlighter defines the following styles: * `back-quoted-argument` - backquoted expressions (`` `foo` ``) * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) * `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") * `back-double-quoted-argument` - back double quoted arguments (\x inside "") * `assign` - variable assignments diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c0b2816..6eb37d8 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -51,6 +51,7 @@ : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} : ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} @@ -198,6 +199,8 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_highlight_string substr_color=1 ;; + \$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] + ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *[*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if _zsh_highlight_main_highlighter_check_path; then diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh new file mode 100644 index 0000000..7906d3e --- /dev/null +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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=( + "3 6 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'*' - not a glob +) From c46b8d169e567ea465d4c1b06b14f950140ac023 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 12 Sep 2015 20:29:04 +0000 Subject: [PATCH 0059/1080] test harness: Fix off-by-one discrepancy between observed and expected. Fixes issue #195. --- .../brackets/test-data/mismatch-patentheses.zsh | 8 ++++---- .../brackets/test-data/nested-parentheses.zsh | 12 ++++++------ .../brackets/test-data/quoted-patentheses.zsh | 2 +- .../brackets/test-data/simple-parentheses.zsh | 8 ++++---- .../brackets/test-data/unclosed-patentheses.zsh | 6 +++--- .../brackets/test-data/unclosed-patentheses2.zsh | 6 +++--- .../main/test-data/backslash-continuation.zsh | 2 +- highlighters/main/test-data/multiline-string.zsh | 2 +- highlighters/main/test-data/prefix-redirection.zsh | 2 +- highlighters/main/test-data/simple-redirection.zsh | 4 ++-- highlighters/main/test-data/vanilla-newline.zsh | 6 +++--- tests/README.md | 7 +++++++ tests/test-highlighting.zsh | 5 ++++- 13 files changed, 40 insertions(+), 30 deletions(-) diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index ad72f75..3e75292 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -31,8 +31,8 @@ BUFFER='echo ({x}]' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) ) diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 68683e5..1de6b3f 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -31,10 +31,10 @@ BUFFER='echo $(echo ${(z)array})' expected_region_highlight=( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( - "13 13 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ( - "16 16 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ) - "22 22 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( + "14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "15 15 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ( + "17 17 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ) + "23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "24 24 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) ) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 2589010..60010b4 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -31,5 +31,5 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 15 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing +"1 16 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing ) diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index cd9a759..9ee1737 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -31,8 +31,8 @@ BUFFER='echo ({x})' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index 879c618..b815541 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -31,7 +31,7 @@ BUFFER='echo ({x}' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( + "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index c6534ef..7f2f324 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -31,7 +31,7 @@ BUFFER='echo {x})' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # { - "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # } - "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) + "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # { + "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # } + "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) ) diff --git a/highlighters/main/test-data/backslash-continuation.zsh b/highlighters/main/test-data/backslash-continuation.zsh index f0b22f7..e9d6d20 100644 --- a/highlighters/main/test-data/backslash-continuation.zsh +++ b/highlighters/main/test-data/backslash-continuation.zsh @@ -32,5 +32,5 @@ PREBUFFER=$'echo \\\n' BUFFER='noglob' expected_region_highlight=( - "0 6 none" # 'noglob' highlighted as a string, not as a precomand + "1 6 none" # 'noglob' highlighted as a string, not as a precomand ) diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh index f2eb13e..450458c 100644 --- a/highlighters/main/test-data/multiline-string.zsh +++ b/highlighters/main/test-data/multiline-string.zsh @@ -32,6 +32,6 @@ PREBUFFER=$'echo "foo1\n' BUFFER='foo2" ./' expected_region_highlight=( - "0 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' + "1 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' "7 8 $ZSH_HIGHLIGHT_STYLES[path]" # './' ) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index c1152fb..29d91e2 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -32,7 +32,7 @@ BUFFER='>/tmp >/tmp sudo echo foo' expected_region_highlight=( "2 5 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "7 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "8 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "13 16 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo "18 21 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "23 25 $ZSH_HIGHLIGHT_STYLES[default]" # foo diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index 055b1cb..b569c27 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -34,6 +34,6 @@ expected_region_highlight=( "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps "4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux "8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | - "9 12 $ZSH_HIGHLIGHT_STYLES[command]" # grep - "14 17 $ZSH_HIGHLIGHT_STYLES[default]" # java + "10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep + "15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java ) diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index f0c8eac..1aa3cc4 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -32,9 +32,9 @@ PREBUFFER=$'echo foo; echo bar\n\n\n' BUFFER=' echo baz; echo qux' expected_region_highlight=( - "1 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # baz - "9 10 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon + "2 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo + "7 9 $ZSH_HIGHLIGHT_STYLES[default]" # baz + "10 10 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux ) diff --git a/tests/README.md b/tests/README.md index f8cac48..676dd64 100644 --- a/tests/README.md +++ b/tests/README.md @@ -5,6 +5,13 @@ Utility scripts for testing zsh-syntax-highlighting highlighters. The tests expect the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. +Each test should define the array parameter `$expected_region_highlight`. +The value of that parameter is a list of `"$i $j $style"` strings. +Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; +that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. + +_Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. + highlighting test ----------------- diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 64655ee..83ce6a0 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -84,7 +84,10 @@ for data_file in ${0:h:h}/highlighters/$1/test-data/*; do observed_result=() for i in {1..${#region_highlight}}; do highlight_zone=${(z)region_highlight[$i]} - for j in {$highlight_zone[1]..$highlight_zone[2]}; do + integer start=$highlight_zone[1] end=$highlight_zone[2] + (( --end )) # region_highlight ranges are half-open + (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed + for j in {$start..$end}; do observed_result[$j]=$highlight_zone[3] done done From 80587e5419c1c0c80f58723989245bac734c98ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 12 Sep 2015 20:31:33 +0000 Subject: [PATCH 0060/1080] New test for dollar-double-quoted-argument. This exercises the previous patch. --- highlighters/main/test-data/double-quoted.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/double-quoted.zsh diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh new file mode 100644 index 0000000..b200af0 --- /dev/null +++ b/highlighters/main/test-data/double-quoted.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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=( + "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo + "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar + "11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " +) From 186536705b1880ef32467a07ceec36a6f35d5403 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 19:05:20 +0000 Subject: [PATCH 0061/1080] tests: path-tilde-named.zsh: Fix expectations The path string ends at offset 26, not 23. --- highlighters/main/test-data/path-tilde-named.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index 38b2bb5..1bc3de7 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -34,5 +34,5 @@ BUFFER='ls ~D/path-tilde-named.zsh' expected_region_highlight=( "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 23 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.zsh + "4 26 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.zsh ) From 0d3a5dadea25961e625c75d59b983cb740f4413b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 20:01:46 +0000 Subject: [PATCH 0062/1080] tests: Add test for escape sequences in double-quoted strings --- highlighters/main/test-data/double-quoted.zsh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index b200af0..936efa3 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -28,10 +28,19 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=': "foo$bar"' +BUFFER=': "foo$bar:\`:\":\$:' +BUFFER+=\\\':\" expected_region_highlight=( "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar - "11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " + "11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "12 13 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \` + "14 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "15 16 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \$ + "17 17 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "18 19 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \" + "20 20 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : + "21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \' + "23 24 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # :" ) From 05ab9f7342ca2a9c2ae7e5d27109bef647ad5a2a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 20:11:05 +0000 Subject: [PATCH 0063/1080] tests: Run only *.zsh files. Otherwise, *.rej patch files would be run by zsh, with unpredictable results. --- 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 83ce6a0..1290bb8 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -58,7 +58,7 @@ integer something_failed=0 ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # Process each test data file in test data directory. -for data_file in ${0:h:h}/highlighters/$1/test-data/*; do +for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do # Load the data and prepare checking it. PREBUFFER= BUFFER= ; expected_region_highlight=(); errors=() From 404d498e1d80f2a6e3d0a1a06a6497f3c0b7ccd4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 23:23:38 +0000 Subject: [PATCH 0064/1080] tests: vanilla-newline.zsh: Fix expectations --- highlighters/main/test-data/vanilla-newline.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index 1aa3cc4..ccf3588 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -34,7 +34,7 @@ BUFFER=' echo baz; echo qux' expected_region_highlight=( "2 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "7 9 $ZSH_HIGHLIGHT_STYLES[default]" # baz - "10 10 $ZSH_HIGHLIGHT_STYLES[default]" # semicolon + "10 10 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # semicolon "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux ) From 4068413dfe3920d39a0e0942f53b8404404a3d3a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 22:44:51 +0000 Subject: [PATCH 0065/1080] tests: Let each test change the highlight styles. This way, each test can set custom styles to specific highlight contexts (to differentiate those contexts) without affecting later tests. --- tests/test-highlighting.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 1290bb8..2e5a20c 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -49,7 +49,9 @@ local -a errors highlight_zone local -A observed_result +local -A save_ZSH_HIGHLIGHT_STYLES integer something_failed=0 +local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh @@ -57,12 +59,16 @@ integer something_failed=0 # Activate the highlighter. ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) +# Cache a pristine set of styles. +save_ZSH_HIGHLIGHT_STYLES=( "${(@kv)ZSH_HIGHLIGHT_STYLES}" ) + # Process each test data file in test data directory. for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do # Load the data and prepare checking it. PREBUFFER= BUFFER= ; expected_region_highlight=(); errors=() echo -n "* ${data_file:t:r}: " + ZSH_HIGHLIGHT_STYLES=( "${(@kv)save_ZSH_HIGHLIGHT_STYLES}" ) . $data_file # Check the data declares $PREBUFFER or $BUFFER. From aab1b8f50f9d068e9f9662bd490039af89629339 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 23:17:22 +0000 Subject: [PATCH 0066/1080] Follow-up to 547b8be30461: Fix $observed_result calculation. In region_highlight, a spec of the form 'i j foo' with i >= j should have no effect. Before this commit, however, the {$i..$j} range would happily expand to (5 4 3) if i > j were the case (e.g., i=5 and j=3). This breaks vanilla-newline.zsh; the next commit will fix that. --- tests/test-highlighting.zsh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 2e5a20c..0cbf793 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -91,11 +91,16 @@ for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do for i in {1..${#region_highlight}}; do highlight_zone=${(z)region_highlight[$i]} integer start=$highlight_zone[1] end=$highlight_zone[2] - (( --end )) # region_highlight ranges are half-open - (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed - for j in {$start..$end}; do - observed_result[$j]=$highlight_zone[3] - done + if (( start < end )) # region_highlight ranges are half-open + then + (( --end )) # convert to closed range, like expected_region_highlight + (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed + for j in {$start..$end}; do + observed_result[$j]=$highlight_zone[3] + done + else + # noop range; ignore. + fi done # Then we compare the observed result with the expected one. From 00862cf4fa6a3613e71f3aba4edc079796440205 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 12:19:18 +0000 Subject: [PATCH 0067/1080] Followup to e5c2a88db023 (merged in 51102bf83fdf): Have widgets return EXIT_SUCCESS. --- 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 012ea0b..b9c5c70 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -121,12 +121,12 @@ _zsh_highlight() fi } + return $ret } always { _ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR - return $ret } } From 627eb719406c3e1a96f12072413115d53207f1b0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 18:44:18 +0000 Subject: [PATCH 0068/1080] tests: Use $unused_highlight in more places. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notably, the 'single-hyphen-option' and 'assign' contexts both default to the 'none' style, so before this patch, the tests would not have detected a failure to apply those two contexts. For other contexts, using $unused_highlight only helps detect the case where the right highlight style (e.g., 'fg=yellow') is used as a result of applying the wrong context — which should be a theoretical failure mode. This is part of zsh-users/zsh-syntax-highlighting#198. --- highlighters/main/test-data/assign-append.zsh | 1 + highlighters/main/test-data/assign.zsh | 1 + highlighters/main/test-data/dollar-quoted.zsh | 1 + highlighters/main/test-data/multiline-string2.zsh | 1 + highlighters/main/test-data/sudo-command.zsh | 1 + 5 files changed, 5 insertions(+) diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 29e759a..973e74c 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='a+=(lorem ipsum)' expected_region_highlight=( diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 61edd6d..7351fa9 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index 7906d3e..31f8f5a 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight BUFFER=": \$'*'" expected_region_highlight=( diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 03626af..d460d6e 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight BUFFER=$'echo "foo1\n' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index ce19f0c..cf229c9 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight BUFFER='sudo -u otheruser ls /' expected_region_highlight=( From 416934202edf95101b709b6fe70b0bb1b57e77eb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0069/1080] tests: Cover 'single-quoted-argument', 'double-hyphen-option', and 'function'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- highlighters/main/test-data/dollar-quoted.zsh | 3 +- .../main/test-data/double-hyphen-option.zsh | 36 ++++++++++++++ highlighters/main/test-data/function.zsh | 48 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/double-hyphen-option.zsh create mode 100644 highlighters/main/test-data/function.zsh diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index 31f8f5a..b90d709 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -29,8 +29,9 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight -BUFFER=": \$'*'" +BUFFER=": \$'*' 'foo'" expected_region_highlight=( "3 6 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'*' - not a glob + "8 12 $ZSH_HIGHLIGHT_STYLES[single-quoted-argument]" # 'foo' ) diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh new file mode 100644 index 0000000..8fad394 --- /dev/null +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight +BUFFER='hello --world' + +expected_region_highlight=( + "7 13 $ZSH_HIGHLIGHT_STYLES[double-hyphen-option]" # --world +) diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh new file mode 100644 index 0000000..ecf5572 --- /dev/null +++ b/highlighters/main/test-data/function.zsh @@ -0,0 +1,48 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[function]=$unused_highlight +cd() { + builtin cd "$@" +} +ls() { + command ls "$@" +} +BUFFER='cd;ls' + +# Use $unused_highlight to see that function highlighting has precedence over command and builtin + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[function]" # cd + "4 5 $ZSH_HIGHLIGHT_STYLES[function]" # ls +) + +# don't 'unfunction cd ls', since cd() and ls() should still be a functions +# when _zsh_highlight runs. Leaving the wrapper functions is harmless. From e0a7ddb6ecfb5627916a1a55da373762ebb2abc4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0070/1080] tests: Cover 'history-expansion'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- .../main/test-data/history-expansion.zsh | 37 +++++++++++++++++++ .../main/test-data/history-expansion2.zsh | 35 ++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 highlighters/main/test-data/history-expansion.zsh create mode 100644 highlighters/main/test-data/history-expansion2.zsh diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh new file mode 100644 index 0000000..2e7d994 --- /dev/null +++ b/highlighters/main/test-data/history-expansion.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo + "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar + "10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz +) diff --git a/highlighters/main/test-data/history-expansion2.zsh b/highlighters/main/test-data/history-expansion2.zsh new file mode 100644 index 0000000..14bf693 --- /dev/null +++ b/highlighters/main/test-data/history-expansion2.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 8 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # ^foo^bar +) From b056f592f2a0876f436ba87d5788f0d1b3a061d1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0071/1080] tests: Cover 'path_prefix'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- highlighters/main/test-data/path_prefix.zsh | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/path_prefix.zsh diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh new file mode 100644 index 0000000..45b99dc --- /dev/null +++ b/highlighters/main/test-data/path_prefix.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + +# Assumes that [[ -e /bin/sh ]]. + +ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight +BUFFER='ls /bin/s' + +expected_region_highlight=( + "4 9 $ZSH_HIGHLIGHT_STYLES[path_prefix]" # /bin/s +) From 8767e0ef66b641578758c80ad63c7228be31ee91 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0072/1080] tests: Cover 'reserved-word'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- highlighters/main/test-data/reserved-word.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/reserved-word.zsh diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh new file mode 100644 index 0000000..aae3eff --- /dev/null +++ b/highlighters/main/test-data/reserved-word.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[reserved-word]=$unused_highlight +BUFFER='repeat "1" do done' + +expected_region_highlight=( + "1 6 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat + "8 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "1" +) From 81c8d78d1250192de8ad76a0c0c2627ef2752b47 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0073/1080] tests: Cover 'alias' and 'suffix-alias'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- highlighters/main/test-data/alias.zsh | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 highlighters/main/test-data/alias.zsh diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh new file mode 100644 index 0000000..7ff5f35 --- /dev/null +++ b/highlighters/main/test-data/alias.zsh @@ -0,0 +1,51 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 alias1="unused expansion" +alias -s alias2="echo" + +ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight +BUFFER='x.alias2; alias1' + +# Set expected_region_highlight as a function of zsh version. +# +# Highlight of suffix alias requires zsh-5.1.1 or newer; see issue #126, +# and commit 36403 to zsh itself. Therefore, check if the requisite zsh +# functionality is present, and skip verifying suffix-alias highlighting +# if it isn't. +expected_region_highlight=() +if [[ "$(type -w x.alias2)" == *suffix* ]]; then + expected_region_highlight+=( + "1 8 $ZSH_HIGHLIGHT_STYLES[suffix-alias]" # x.alias2 + ) +fi +expected_region_highlight+=( + "11 16 $ZSH_HIGHLIGHT_STYLES[alias]" # alias1 +) From f7cb4741d60f4f7d901a8c72db5d57b2510f5835 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 22:04:07 +0000 Subject: [PATCH 0074/1080] Followup to previous: Extend the 'alias' test. --- highlighters/main/test-data/alias.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 7ff5f35..3397d06 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -30,6 +30,7 @@ alias alias1="unused expansion" alias -s alias2="echo" +alias1() {} # to check that it's highlighted as an alias, not as a function ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x.alias2; alias1' From 5fb4cb2f72ff3bf2cde7d6c8eb5593e1c1a19539 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 22:45:22 +0000 Subject: [PATCH 0075/1080] Fix regression: Highlight ';' as commandseparator. This was broken by c2b9327b0763f3457fb09db17e22ee9e1e024792 and tracked as zsh-users/zsh-syntax-highlighting#199. This fixes the vanilla-newline.zsh test, which was was (consciously) broken by the previous commit. --- highlighters/main/main-highlighter.zsh | 4 +- .../main/test-data/commandseparator.zsh | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/commandseparator.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6eb37d8..30bbba5 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -120,8 +120,8 @@ _zsh_highlight_main_highlighter() # words for arguments). local needle=$'[;\n]' integer offset=${${buf[start_pos+1,-1]}[(i)$needle]} - (( start_pos += offset )) - (( end_pos += offset )) + (( start_pos += offset - 1 )) + (( end_pos = start_pos + $#arg )) else ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh new file mode 100644 index 0000000..9325d84 --- /dev/null +++ b/highlighters/main/test-data/commandseparator.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight + +BUFFER=':; pwd' + +expected_region_highlight=( + "2 2 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "4 6 $ZSH_HIGHLIGHT_STYLES[builtin]" # pwd +) From 845361ef3de012fd17f2f22adde556a3d61129f0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0076/1080] tests: Cover 'hashed-command'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- .../main/test-data/hashed-command.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/hashed-command.zsh diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh new file mode 100644 index 0000000..13e0e67 --- /dev/null +++ b/highlighters/main/test-data/hashed-command.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +hash zsh_syntax_highlighting_hash=/doesnotexist +ZSH_HIGHLIGHT_STYLES[hashed]=$unused_highlight +BUFFER='zsh_syntax_highlighting_hash' + +expected_region_highlight=( + "1 28 $ZSH_HIGHLIGHT_STYLES[hashed-command]" +) From 22fa215e052853946635274b0423a9338f98c7fa Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Sep 2015 15:39:53 +0000 Subject: [PATCH 0077/1080] Fixup last commit. * highlighters/main/test-data/hashed-command.zsh: Set the right region key. This makes the test more specific. (Issue #184 would have caught this bug.) --- highlighters/main/test-data/hashed-command.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index 13e0e67..9b74990 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- hash zsh_syntax_highlighting_hash=/doesnotexist -ZSH_HIGHLIGHT_STYLES[hashed]=$unused_highlight +ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight BUFFER='zsh_syntax_highlighting_hash' expected_region_highlight=( From 001e6cb404e861c1684ff573be0d0c53f4994025 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Sep 2015 19:21:21 +0000 Subject: [PATCH 0078/1080] tests: Cover 'back-quoted-argument'. This is part of issue zsh-users/zsh-syntax-highlighting#198. --- .../main/test-data/back-quoted-argument.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/back-quoted-argument.zsh diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh new file mode 100644 index 0000000..ae01b0a --- /dev/null +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight +BUFFER='echo `echo 42`' + +expected_region_highlight=( + "6 14 $ZSH_HIGHLIGHT_STYLES[back-quoted-argument]" +) From 9e80fe8f02f29fe1c952dcd0fa0404e73b920625 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 16:46:28 +0000 Subject: [PATCH 0079/1080] Bump copyright years. --- highlighters/brackets/test-data/mismatch-patentheses.zsh | 2 +- highlighters/brackets/test-data/nested-parentheses.zsh | 2 +- highlighters/brackets/test-data/quoted-patentheses.zsh | 2 +- highlighters/brackets/test-data/simple-parentheses.zsh | 2 +- highlighters/brackets/test-data/unclosed-patentheses.zsh | 2 +- highlighters/brackets/test-data/unclosed-patentheses2.zsh | 2 +- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/alias.zsh | 2 +- highlighters/main/test-data/assign-append.zsh | 2 +- highlighters/main/test-data/assign.zsh | 2 +- highlighters/main/test-data/dollar-quoted.zsh | 2 +- highlighters/main/test-data/double-hyphen-option.zsh | 2 +- highlighters/main/test-data/double-quoted.zsh | 2 +- highlighters/main/test-data/function.zsh | 2 +- highlighters/main/test-data/glob.zsh | 2 +- highlighters/main/test-data/history-expansion.zsh | 2 +- highlighters/main/test-data/history-expansion2.zsh | 2 +- highlighters/main/test-data/noglob1.zsh | 2 +- highlighters/main/test-data/noglob2.zsh | 2 +- highlighters/main/test-data/path-tilde-named.zsh | 2 +- highlighters/main/test-data/path_prefix.zsh | 2 +- highlighters/main/test-data/prefix-redirection.zsh | 2 +- highlighters/main/test-data/reserved-word.zsh | 2 +- highlighters/main/test-data/simple-redirection.zsh | 2 +- highlighters/main/test-data/sudo-command.zsh | 2 +- tests/test-highlighting.zsh | 2 +- zsh-syntax-highlighting.zsh | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index 3e75292..f538273 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 1de6b3f..49262e4 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 60010b4..e21ae0a 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index 9ee1737..b4e6967 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index b815541..33ee42d 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 7f2f324..3aa4a7b 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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 30bbba5..7f0f3de 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# 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 diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 3397d06..74bda73 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 973e74c..6319826 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 7351fa9..231d16c 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index b90d709..5024e48 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index 8fad394..009e36b 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index 936efa3..0847dca 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/function.zsh b/highlighters/main/test-data/function.zsh index ecf5572..9ed2cc7 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index bf8e3be..ddae33d 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 2e7d994..b56e77a 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/history-expansion2.zsh b/highlighters/main/test-data/history-expansion2.zsh index 14bf693..0d93397 100644 --- a/highlighters/main/test-data/history-expansion2.zsh +++ b/highlighters/main/test-data/history-expansion2.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh index fe17e07..2a76589 100644 --- a/highlighters/main/test-data/noglob1.zsh +++ b/highlighters/main/test-data/noglob1.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh index 9b1e4ed..0892787 100644 --- a/highlighters/main/test-data/noglob2.zsh +++ b/highlighters/main/test-data/noglob2.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index 1bc3de7..74824db 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index 45b99dc..bd54454 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 29d91e2..c7d92bf 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index aae3eff..619ec28 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index b569c27..98860ea 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index cf229c9..6059711 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2013 zsh-syntax-highlighting contributors +# Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 0cbf793..83fde94 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# 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 diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index b9c5c70..721d257 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# 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 From 1467eae86d0790a940c1f3e0d550eee66c430e97 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 16:48:27 +0000 Subject: [PATCH 0080/1080] Bump copyright years, part 2. --- COPYING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COPYING.md b/COPYING.md index 2aa6438..5512a0a 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +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 From 908c4fe150c4023662462c96f634f6f710000cef Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 17:57:59 +0000 Subject: [PATCH 0081/1080] Stop leaking variables into global namespace. Set WARN_CREATE_GLOBAL to prevent recurrence. Fixes zsh-users/zsh-syntax-highlighting#192. --- highlighters/main/main-highlighter.zsh | 1 + zsh-syntax-highlighting.zsh | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7f0f3de..dec467a 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -261,6 +261,7 @@ _zsh_highlight_main_highlighter_highlight_string() { setopt localoptions noksharrays local i j k style varflag + local AA # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 721d257..a80512c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -45,7 +45,7 @@ _zsh_highlight() # Store the previous command return code to restore it whatever happens. local ret=$? - setopt localoptions nowarncreateglobal + setopt localoptions warncreateglobal # Do not highlight if there are more than 300 chars in the buffer. It's most # likely a pasted command or a huge list of files in that case.. @@ -125,8 +125,8 @@ _zsh_highlight() } always { - _ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER - _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR + typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER + typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR } } From 4ec0c6d7a7874dfca32a17251130203fe61eb7cb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 18:45:35 +0000 Subject: [PATCH 0082/1080] README: Expand the at-end-of-.zshrc FAQ answer. Fixes zsh-users/zsh-syntax-highlighting#185. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fac07e2..f7fc896 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,9 @@ FAQ ### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file? `zsh-syntax-highlighting.zsh` wraps ZLE widgets. It must be sourced after all -custom widgets have been created (i.e., after all `zle -N` calls). +custom widgets have been created (i.e., after all `zle -N` calls and after +running `compinit`). Widgets created later will work, but will not update the +syntax highlighting. How to tweak ------------ From b0cc02ed86e3586ab92cc1082fb97b94cd5f584f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 17 Sep 2015 20:07:37 +0000 Subject: [PATCH 0083/1080] dollar-double-quoted-argument: Highlight "$foo" better. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now, «"$42foo"» doesn't highlight the «foo», and «"$bar» highlights the «r». --- highlighters/main/main-highlighter.zsh | 15 ++++---- .../main/test-data/double-quoted2.zsh | 37 +++++++++++++++++++ .../main/test-data/double-quoted3.zsh | 37 +++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 highlighters/main/test-data/double-quoted2.zsh create mode 100644 highlighters/main/test-data/double-quoted3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index dec467a..4aca3a9 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -260,7 +260,7 @@ _zsh_highlight_main_highlighter_check_path() _zsh_highlight_main_highlighter_highlight_string() { setopt localoptions noksharrays - local i j k style varflag + local i j k style local AA # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do @@ -268,7 +268,11 @@ _zsh_highlight_main_highlighter_highlight_string() (( k = j + 1 )) case "$arg[$i]" in '$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] - (( varflag = 1)) + # 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 + (( i += $#MATCH )) # skip past it + fi ;; "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do @@ -283,13 +287,8 @@ _zsh_highlight_main_highlighter_highlight_string() (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. fi - (( varflag = 0 )) # End of variable ;; - ([^a-zA-Z0-9_])) - (( varflag = 0 )) # End of variable - continue - ;; - *) [[ $varflag -eq 0 ]] && continue ;; + *) continue ;; esac _zsh_highlight_main_add_region_highlight $j $k $style diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh new file mode 100644 index 0000000..e596c6d --- /dev/null +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 test checks that the 'r' gets highlighted correctly. Do not append to the BUFFER. +BUFFER=': "foo$bar' + +expected_region_highlight=( + "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo + "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar +) diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh new file mode 100644 index 0000000..919bf08 --- /dev/null +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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=': "$42foo"' + +expected_region_highlight=( + "3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " + "4 6 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 + "7 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" +) From 66eb801358b1a38cb268856b7ddfbddf8b71ba6c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 18:57:56 +0000 Subject: [PATCH 0084/1080] =?UTF-8?q?dollar-double-quoted-argument:=20Hand?= =?UTF-8?q?le=20=C2=AB"foo$"=C2=BB=20correctly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/main-highlighter.zsh | 2 ++ highlighters/main/test-data/double-quoted3.zsh | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4aca3a9..da27158 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -272,6 +272,8 @@ _zsh_highlight_main_highlighter_highlight_string() if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then (( k += $#MATCH )) # highlight the parameter name (( i += $#MATCH )) # skip past it + else + continue fi ;; "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 919bf08..4a91c85 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -28,10 +28,11 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=': "$42foo"' +BUFFER=': "$" "$42foo"' expected_region_highlight=( - "3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " - "4 6 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 - "7 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" + "3 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "$" + "7 7 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " + "8 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 + "11 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" ) From 86cd337446a3f7392f9a5ef1bfe23e224653ec74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 22:58:22 +0000 Subject: [PATCH 0085/1080] README: Document release announcements. Thanks to tibbs@fedora for setting up anitya. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index f7fc896..cb22c37 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,13 @@ custom widgets have been created (i.e., after all `zle -N` calls and after running `compinit`). Widgets created later will work, but will not update the syntax highlighting. +### How are new releases announced? + +There is currently no "push" announcements channel. However, the following alternatives exist: + +- GitHub's RSS feed of releases: https://github.com/zsh-users/zsh-syntax-highlighting/releases.atom +- An anitya entry: https://release-monitoring.org/project/7552/ + How to tweak ------------ From 040df93c01354a73ad9ceded41aed1bab8fa6776 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 12:39:06 +0000 Subject: [PATCH 0086/1080] Highlight redirections. Fixes zsh-users/zsh-syntax-highlighting#23. --- highlighters/main/README.md | 1 + highlighters/main/main-highlighter.zsh | 5 ++- highlighters/main/test-data/redirection.zsh | 38 +++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/redirection.zsh diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 5bdc017..ca10867 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -46,6 +46,7 @@ This highlighter defines the following styles: * `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") * `back-double-quoted-argument` - back double quoted arguments (\x inside "") * `assign` - variable assignments +* `redirection` - redirection operators (`<`, `>`, etc) * `default` - parts of the buffer that do not match anything To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index da27158..e4abcaa 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -55,6 +55,7 @@ : ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} +: ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() @@ -177,7 +178,7 @@ _zsh_highlight_main_highlighter() elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then - style=$ZSH_HIGHLIGHT_STYLE[redirection] + style=$ZSH_HIGHLIGHT_STYLES[redirection] redirection=true else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] @@ -209,6 +210,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + style=$ZSH_HIGHLIGHT_STYLES[redirection] else style=$ZSH_HIGHLIGHT_STYLES[default] fi diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh new file mode 100644 index 0000000..0a01d55 --- /dev/null +++ b/highlighters/main/test-data/redirection.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Redirection before and after the command word are implemented differently; test both. +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight +BUFFER='<<>&!bar' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[redirection]" # <<< + "13 16 $ZSH_HIGHLIGHT_STYLES[redirection]" # >>&! +) From 35c4bb7bdc57e52a6948b73a9d4a1b430a6b8b8a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 12:41:30 +0000 Subject: [PATCH 0087/1080] More WARN_CREATE_GLOBAL cleanups. Followup to 908c4fe150c4023662462c96f634f6f710000cef. Found by test-perfs.zsh. --- zsh-syntax-highlighting.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index a80512c..287ed49 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -55,6 +55,7 @@ _zsh_highlight() [[ $PENDING -gt 0 ]] && return $ret # Reset region highlight to build it from scratch + typeset -ga region_highlight region_highlight=(); { From cb5589db739ca6b835e05537f9a35a0cbc168379 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 15:35:03 +0000 Subject: [PATCH 0088/1080] Don't wrap set-local-history. See issue #137. A reproduction recipe for testing this change: $ zsh -f % bindkey -e % source % source zsh-syntax-highlighting.zsh % echo foo % echo bar % <^R>echo<^R> This finds the 'echo foo' with this change but not without it. --- 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 287ed49..c207f7a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -171,7 +171,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank-pop)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank-pop|set-local-history)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From dd12dde93a83b2863a4ff05440ec1fb7e82af9a6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 17:53:22 +0000 Subject: [PATCH 0089/1080] Fix errors with non-reserved-word typeset. Follow-up to 908c4fe150c4023662462c96f634f6f710000cef. Intended to fix fix zsh-users/zsh-syntax-highlighting#206. --- 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 c207f7a..13b573c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -126,7 +126,7 @@ _zsh_highlight() } always { - typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=$BUFFER + typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER" typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR } } From 9c7a1109c842bb64297dd495752ff2a900a44a6f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 20:57:51 +0000 Subject: [PATCH 0090/1080] WARN_CREATE_GLOBAL: don't leak the arithmetic for loop's index variable. Found by code inspection; WARN_CREATE_GLOBAL missed this. --- 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 da27158..3e8a967 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -262,6 +262,7 @@ _zsh_highlight_main_highlighter_highlight_string() setopt localoptions noksharrays local i j k style local AA + integer c # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) From f4164ac86cb30c28c89a10ed6ee23871efd0b052 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:15:34 +0000 Subject: [PATCH 0091/1080] internal: Document a function-local variable. --- highlighters/main/main-highlighter.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 3e8a967..b576c46 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -102,7 +102,11 @@ _zsh_highlight_main_highlighter() ) for arg in ${(z)buf}; do - local substr_color=0 + # substr_color is set to 1 to disable adding an entry to region_highlight + # for this iteration. Currently, that is done for "" strings, + # which add the entry early so escape sequences within the string override + # the string's color. + integer substr_color=0 local style_override="" if $new_expression && [[ $arg = 'noglob' ]]; then highlight_glob=false From 69fcb40275dc7dbc51f46097483cb1328db16686 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:18:37 +0000 Subject: [PATCH 0092/1080] Highlight backslash escapes within $'' strings. Correct highlighting of backslash escapes within "" strings: highlight only the four specific escape sequences defined there. Fixes zsh-users/zsh-syntax-highlighting#196. --- highlighters/main/README.md | 1 + highlighters/main/main-highlighter.zsh | 35 +++++++++++++++-- .../main/test-data/dollar-quoted2.zsh | 38 +++++++++++++++++++ highlighters/main/test-data/double-quoted.zsh | 4 +- .../main/test-data/double-quoted3.zsh | 2 + 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 highlighters/main/test-data/dollar-quoted2.zsh diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 5bdc017..fff62de 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -45,6 +45,7 @@ This highlighter defines the following styles: * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) * `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") * `back-double-quoted-argument` - back double quoted arguments (\x inside "") +* `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'') * `assign` - variable assignments * `default` - parts of the buffer that do not match anything diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b576c46..0284a3b 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -54,6 +54,7 @@ : ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} +: ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} # Whether the highlighter should be called or not. @@ -103,7 +104,7 @@ _zsh_highlight_main_highlighter() for arg in ${(z)buf}; do # substr_color is set to 1 to disable adding an entry to region_highlight - # for this iteration. Currently, that is done for "" strings, + # for this iteration. Currently, that is done for "" and $'' strings, # which add the entry early so escape sequences within the string override # the string's color. integer substr_color=0 @@ -204,6 +205,9 @@ _zsh_highlight_main_highlighter() substr_color=1 ;; \$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + _zsh_highlight_main_highlighter_highlight_dollar_string + substr_color=1 ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *[*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; @@ -265,8 +269,6 @@ _zsh_highlight_main_highlighter_highlight_string() { setopt localoptions noksharrays local i j k style - local AA - integer c # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) @@ -282,6 +284,33 @@ _zsh_highlight_main_highlighter_highlight_string() fi ;; "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] + if [[ \\\`\"\$ == *$arg[$i+1]* ]]; then + (( k += 1 )) # Color following char too. + (( i += 1 )) # Skip parsing the escaped char. + else + continue + fi + ;; + *) continue ;; + + esac + _zsh_highlight_main_add_region_highlight $j $k $style + done +} + +# Highlight special chars inside dollar-quoted strings +_zsh_highlight_main_highlighter_highlight_dollar_string() +{ + setopt localoptions noksharrays + local i j k style + local AA + integer c + # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string. + for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do + (( j = i + start_pos - 1 )) + (( k = j + 1 )) + case "$arg[$i]" in + "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do [[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break done diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh new file mode 100644 index 0000000..21df3c8 --- /dev/null +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight +BUFFER=": \$'foo\xbar'" + +expected_region_highlight=( + "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo + "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba + "12 13 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r' +) diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index 0847dca..35178a2 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- BUFFER=': "foo$bar:\`:\":\$:' -BUFFER+=\\\':\" +BUFFER+=\\\\:\" expected_region_highlight=( "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo @@ -41,6 +41,6 @@ expected_region_highlight=( "17 17 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : "18 19 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \" "20 20 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : - "21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \' + "21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \\ "23 24 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # :" ) diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 4a91c85..2d861cb 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -29,10 +29,12 @@ # ------------------------------------------------------------------------------------------------- BUFFER=': "$" "$42foo"' +BUFFER+=\ \"\\\'\\x\" expected_region_highlight=( "3 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "$" "7 7 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " "8 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 "11 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" + "16 21 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "\'\x" - \' and \x are not escape sequences ) From 78ad649d479f677bf9ff555ea42cb3ef7b56b1ba Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0093/1080] back-dollar-quoted-argument: Don't consider comma a hex character. Character class syntax does not ignore commas between ranges. --- 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 0284a3b..2222943 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -312,11 +312,11 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() case "$arg[$i]" in "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do - [[ "$arg[$c]" != ([0-9,xX,a-f,A-F]) ]] && break + [[ "$arg[$c]" != ([0-9xXa-fA-F]) ]] && break done AA=$arg[$i+1,$c-1] # Matching for HEX and OCT values like \0xA6, \xA6 or \012 - if [[ "$AA" =~ "^(0*(x|X)[0-9,a-f,A-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then + if [[ "$AA" =~ "^(0*(x|X)[0-9a-fA-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then (( k += $#MATCH )) (( i += $#MATCH )) else From 98366ade118e16e2a831602493a38fd40ec31cc9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0094/1080] back-dollar-quoted-argument: Don't consider \0xHH a hex escape sequence. A leading zero is not permitted in the '\xHH' syntax. --- 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 2222943..77d7785 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -316,7 +316,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() done AA=$arg[$i+1,$c-1] # Matching for HEX and OCT values like \0xA6, \xA6 or \012 - if [[ "$AA" =~ "^(0*(x|X)[0-9a-fA-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then + if [[ "$AA" =~ "^((x|X)[0-9a-fA-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then (( k += $#MATCH )) (( i += $#MATCH )) else From 8a43bd2cd98033a7951f43ecf730c8e9498900df Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0095/1080] back-dollar-quoted-argument: Highlight \uHHHH and \UHHHHHHHH escapes. --- highlighters/main/main-highlighter.zsh | 8 ++++++-- highlighters/main/test-data/dollar-quoted2.zsh | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 77d7785..bf76e98 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -312,11 +312,15 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() case "$arg[$i]" in "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do - [[ "$arg[$c]" != ([0-9xXa-fA-F]) ]] && break + [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break done AA=$arg[$i+1,$c-1] # Matching for HEX and OCT values like \0xA6, \xA6 or \012 - if [[ "$AA" =~ "^((x|X)[0-9a-fA-F]{1,2})" || "$AA" =~ "^(0[0-7]{1,3})" ]];then + if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}" + || "$AA" =~ "^0[0-7]{1,3}" + || "$AA" =~ "^u[0-9a-fA-F]{1,4}" + || "$AA" =~ "^U[0-9a-fA-F]{1,8}" + ]]; then (( k += $#MATCH )) (( i += $#MATCH )) else diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index 21df3c8..ecaaa39 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -29,10 +29,12 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight -BUFFER=": \$'foo\xbar'" +BUFFER=": \$'foo\xbar\udeadbeef'" expected_region_highlight=( "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba - "12 13 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r' + "12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r + "13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead + "19 23 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef' ) From 0788514cbd3e6165a498cf64ddfae50fd0834b54 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0096/1080] back-dollar-quoted-argument: Correct octal escape syntax. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A leading zero, as in '\0NNN', is permitted by 'echo' but not by 'print', and «$''» follows 'print'. --- 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 bf76e98..483d285 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -317,7 +317,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() AA=$arg[$i+1,$c-1] # Matching for HEX and OCT values like \0xA6, \xA6 or \012 if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}" - || "$AA" =~ "^0[0-7]{1,3}" + || "$AA" =~ "^[0-7]{1,3}" || "$AA" =~ "^u[0-9a-fA-F]{1,4}" || "$AA" =~ "^U[0-9a-fA-F]{1,8}" ]]; then From 6732783d46baa15e0b48a1e24922ec79640af243 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0097/1080] back-dollar-quoted-argument: Correct an off-by-one. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Highlight the last character of a «\xHH» escape when it is the last thing in LBUFFER. This is similar to what b0cc02ed86e3586ab92cc1082fb97b94cd5f584f did for issue #186. --- highlighters/main/main-highlighter.zsh | 2 +- .../main/test-data/dollar-quoted3.zsh | 39 +++++++++++++++++++ .../main/test-data/double-quoted2.zsh | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/dollar-quoted3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 483d285..ef42709 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -311,7 +311,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() (( k = j + 1 )) case "$arg[$i]" in "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] - for (( c = i + 1 ; c < end_pos - start_pos ; c += 1 )); do + for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break done AA=$arg[$i+1,$c-1] diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh new file mode 100644 index 0000000..2632ff9 --- /dev/null +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Similar to double-quoted2.zsh +ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight +# This test checks that the '1' gets highlighted correctly. Do not append to the BUFFER. +BUFFER=": \$'\xa1" + +expected_region_highlight=( + "3 4 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $' + "5 8 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xa1 +) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index e596c6d..fd202fe 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -28,6 +28,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +# Similar to dollar-quoted3.zsh # This test checks that the 'r' gets highlighted correctly. Do not append to the BUFFER. BUFFER=': "foo$bar' From 3fdaec3d4a2221d8af2d60019f7bc50e0384cb09 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 26 Sep 2015 16:27:08 +0000 Subject: [PATCH 0098/1080] WARN_CREATE_GLOBAL: Plug yet another instance. --- 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 13b573c..ce9db28 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -243,8 +243,8 @@ _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/ # Reset scratch variables when commandline is done. _zsh_highlight_preexec_hook() { - _ZSH_HIGHLIGHT_PRIOR_BUFFER= - _ZSH_HIGHLIGHT_PRIOR_CURSOR= + typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= + typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR= } autoload -U add-zsh-hook add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { From 79e8c2dd48eca06161051f5fb4b4993365966a7d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 12:50:39 +0000 Subject: [PATCH 0099/1080] Don't highlight syntax elements as paths. Without this, redirections, history expansions, and command separators would be matched by path_approx. A test case is simply LBUFFER="<" RBUFFER="" (highlighted as redirection with this fix and as path_approx without it). Fixes zsh-users/zsh-syntax-highlighting#204. --- highlighters/main/main-highlighter.zsh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a71c94f..27f35a3 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -178,15 +178,17 @@ _zsh_highlight_main_highlighter() # (For array assignments, the command doesn't start until the ")" token.) new_expression=true; highlight_glob=true fi - elif _zsh_highlight_main_highlighter_check_path; then - style=$ZSH_HIGHLIGHT_STYLES[path] elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] redirection=true else - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + if _zsh_highlight_main_highlighter_check_path; then + style=$ZSH_HIGHLIGHT_STYLES[path] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi fi ;; esac @@ -212,8 +214,7 @@ _zsh_highlight_main_highlighter() ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; *[*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; - *) if _zsh_highlight_main_highlighter_check_path; then - style=$ZSH_HIGHLIGHT_STYLES[path] + *) if false; then elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then @@ -221,7 +222,11 @@ _zsh_highlight_main_highlighter() elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] else - style=$ZSH_HIGHLIGHT_STYLES[default] + if _zsh_highlight_main_highlighter_check_path; then + style=$ZSH_HIGHLIGHT_STYLES[path] + else + style=$ZSH_HIGHLIGHT_STYLES[default] + fi fi ;; esac From 8b728522de2c8ca5745e92857dac38e1d633c6d8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 26 Sep 2015 03:11:58 +0000 Subject: [PATCH 0100/1080] Add test for empty commands. Related to issue #205. --- highlighters/main/test-data/empty-command.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/empty-command.zsh diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh new file mode 100644 index 0000000..b63ecb5 --- /dev/null +++ b/highlighters/main/test-data/empty-command.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo; ; ' # without the trailing space, it's highlighted as path_approx + +expected_region_highlight=( + "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; +) From f6574061598e622d4f2fcc435340acdf489be933 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 26 Sep 2015 18:59:16 +0000 Subject: [PATCH 0101/1080] minor: Fix comment in last ocmmit. --- highlighters/main/test-data/empty-command.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index b63ecb5..6b20e91 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -28,7 +28,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='echo; ; ' # without the trailing space, it's highlighted as path_approx +# without the trailing space, it's highlighted as path_approx (issue #187, issue #204) +BUFFER='echo; ; ' expected_region_highlight=( "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; From 64882848149385856435d18497c2f5aa82741fc4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 25 Sep 2015 21:36:20 +0000 Subject: [PATCH 0102/1080] back-dollar-quoted-argument: Highlight incomplete escape sequences as unknown-token Followup to 219184f046d40cc723606797666dab18f8a6aea7, which fixed issue #196. --- highlighters/main/main-highlighter.zsh | 4 ++++ highlighters/main/test-data/dollar-quoted2.zsh | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 27f35a3..b53dcee 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -332,6 +332,10 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() (( k += $#MATCH )) (( i += $#MATCH )) else + if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then + # \x not followed by hex digits is probably an error + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. fi diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index ecaaa39..0eb482d 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -29,12 +29,14 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight -BUFFER=": \$'foo\xbar\udeadbeef'" +BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba "12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r "13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead - "19 23 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef' + "19 22 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef + "23 24 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # \u + "25 29 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # zzzz' ) From 52a2ef644b652b18d543da768b42ba080263ad7f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 27 Sep 2015 16:28:32 +0000 Subject: [PATCH 0103/1080] Don't highlight escaped globbing. Fixes zsh-users/zsh-syntax-highlighting#193. --- highlighters/main/main-highlighter.zsh | 3 ++- highlighters/main/test-data/glob.zsh | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b53dcee..79f1324 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -213,7 +213,8 @@ _zsh_highlight_main_highlighter() substr_color=1 ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; - *[*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; + [*?]*|*[^\\][*?]*) + $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if false; then elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index ddae33d..502283e 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -28,10 +28,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=': foo* bar?' +BUFFER=': foo* bar? *baz qux\?' expected_region_highlight=( "1 1 $ZSH_HIGHLIGHT_STYLES[builtin]" # : "3 6 $ZSH_HIGHLIGHT_STYLES[globbing]" # foo* "8 11 $ZSH_HIGHLIGHT_STYLES[globbing]" # bar? + "13 16 $ZSH_HIGHLIGHT_STYLES[globbing]" # *baz + "18 22 $ZSH_HIGHLIGHT_STYLES[default]" # qux\? ) From 7b4598a76495af2e2140be2d7c289a77c654ee8c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 24 Sep 2015 18:24:07 +0000 Subject: [PATCH 0104/1080] Highlight arithmetic expansions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes zsh-users/zsh-syntax-highlighting#188 in the case that both the opening '((' and closing '))' have been typed, The case that only the opening '((' have been typed is also fixed, but requires a zsh development build (zsh-5.1.1-52-g4bed2cf or newer); see comments within. --- highlighters/main/main-highlighter.zsh | 13 ++++++ .../main/test-data/arithmetic-evaluation.zsh | 40 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 highlighters/main/test-data/arithmetic-evaluation.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b53dcee..c4e77d9 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -183,6 +183,19 @@ _zsh_highlight_main_highlighter() elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] redirection=true + elif [[ $arg[1,2] == '((' ]]; then + # Arithmetic evaluation. + # + # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...} + # splitter would only output the '((' token if the matching '))' had + # been typed. Therefore, under those versions of zsh, BUFFER="(( 42" + # would be highlighted as an error until the matching "))" are typed. + # + # We highlight just the opening parentheses, as a reserved word; this + # is how [[ ... ]] is highlighted, too. + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style + substr_color=1 else if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] diff --git a/highlighters/main/test-data/arithmetic-evaluation.zsh b/highlighters/main/test-data/arithmetic-evaluation.zsh new file mode 100644 index 0000000..6d470a6 --- /dev/null +++ b/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Must be at command word, since the word following 'if' isn't currently considered +# a command word (issue #207). +# +# An opening '((' without matching '))' is highlighted correctly under zsh-5.1.1-52-g4bed2cf +# or newer, only (issue #188). +BUFFER='(( x == 42 ))' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # (( +) From 800158745a2a51a330dc193237784526e5462c9b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 28 Sep 2015 19:49:39 +0000 Subject: [PATCH 0105/1080] Highlight quoted command words correctly. Fixes zsh-users/zsh-syntax-highlighting#147. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/unbackslash.zsh | 36 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/unbackslash.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c4e77d9..3f9b7a9 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -157,7 +157,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] sudo=true else - local res="$(LC_ALL=C builtin type -w $arg 2>/dev/null)" + local res="$(LC_ALL=C builtin type -w ${(Q)arg} 2>/dev/null)" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') diff --git a/highlighters/main/test-data/unbackslash.zsh b/highlighters/main/test-data/unbackslash.zsh new file mode 100644 index 0000000..1a8bc45 --- /dev/null +++ b/highlighters/main/test-data/unbackslash.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[command]=$unused_highlight +BUFFER='\sh' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # \sh (runs 'sh', bypassing aliases) +) From faed2fa49e46f52957a31b6c4bac29a949a8c813 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 29 Sep 2015 01:20:54 +0000 Subject: [PATCH 0106/1080] internal: Fix docstrings. --- 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 c317c73..ba02b82 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -254,14 +254,14 @@ _zsh_highlight_main_highlighter() done } -# Check if the argument is variable assignment +# Check if $arg is variable assignment _zsh_highlight_main_highlighter_check_assign() { setopt localoptions extended_glob [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] } -# Check if the argument is a path. +# Check if $arg is a path. _zsh_highlight_main_highlighter_check_path() { setopt localoptions nonomatch From 5cd1fb26c017f2aa7008d38d1a36992bebd4d420 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 29 Sep 2015 01:49:19 +0000 Subject: [PATCH 0107/1080] Resolve tilde expansions in command word. This causes '~/bin/foo' to highlight as a command, rather than as a file. Part of issue #201. --- highlighters/main/main-highlighter.zsh | 23 +++++++++-- .../main/test-data/tilde-command-word.zsh | 38 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 highlighters/main/test-data/tilde-command-word.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ba02b82..030652d 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -157,7 +157,9 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] sudo=true else - local res="$(LC_ALL=C builtin type -w ${(Q)arg} 2>/dev/null)" + _zsh_highlight_main_highlighter_expand_path $arg + local expanded_arg="$REPLY" + local res="$(LC_ALL=C builtin type -w ${expanded_arg} 2>/dev/null)" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') @@ -264,8 +266,9 @@ _zsh_highlight_main_highlighter_check_assign() # Check if $arg is a path. _zsh_highlight_main_highlighter_check_path() { - setopt localoptions nonomatch - local expanded_path; : ${expanded_path:=${(Q)~arg}} + _zsh_highlight_main_highlighter_expand_path $arg; + local expanded_path="$REPLY" + [[ -z $expanded_path ]] && return 1 [[ -e $expanded_path ]] && return 0 # Search the path in CDPATH @@ -360,3 +363,17 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() _zsh_highlight_main_add_region_highlight $j $k $style done } + +# Called with a single positional argument. +# Perform filename expansion (tilde expansion) on the argument and set $REPLY to the expanded value. +# +# Does not perform filename generation (globbing). +_zsh_highlight_main_highlighter_expand_path() +{ + (( $# == 1 )) || echo "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument" >&2 + + # The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}. + setopt localoptions nonomatch + unset REPLY + : ${REPLY:=${(Q)~1}} +} diff --git a/highlighters/main/test-data/tilde-command-word.zsh b/highlighters/main/test-data/tilde-command-word.zsh new file mode 100644 index 0000000..ff10836 --- /dev/null +++ b/highlighters/main/test-data/tilde-command-word.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +hash -d D=/usr/bin + +BUFFER='~D/env foo' + +expected_region_highlight=( + "1 6 $ZSH_HIGHLIGHT_STYLES[command]" # ~D/env [= /usr/bin/env] + "8 10 $ZSH_HIGHLIGHT_STYLES[default]" # foo +) From 07fd773d7e619d685514784567f4f904f2f1d945 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 30 Sep 2015 01:26:27 +0000 Subject: [PATCH 0108/1080] noop: Add comments. --- highlighters/main/main-highlighter.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 030652d..6fa2754 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -271,21 +271,27 @@ _zsh_highlight_main_highlighter_check_path() [[ -z $expanded_path ]] && return 1 [[ -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 dirname($arg) doesn't exist, neither does $arg. [[ ! -e ${expanded_path:h} ]] && return 1 + + # If this word ends the buffer, check if it's the prefix of a valid path. if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]]; then local -a tmp - # got a path prefix? tmp=( ${expanded_path}*(N) ) (( $#tmp > 0 )) && style_override=path_prefix && return 0 # or maybe an approximate path? tmp=( (#a1)${expanded_path}*(N) ) (( $#tmp > 0 )) && style_override=path_approx && return 0 fi + + # It's not a path. return 1 } From e138cfd76526614b954f4c45c80e03b5c4a5e7be Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Oct 2015 13:27:21 +0000 Subject: [PATCH 0109/1080] command word: Protect against the case that the command word starts with a minus. --- 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 6fa2754..f7a9f12 100755 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -159,7 +159,7 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$(LC_ALL=C builtin type -w ${expanded_arg} 2>/dev/null)" + local res="$(LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null)" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') From 56c793d96abef15bbac787dfcc93ff68169c1b1f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 18 Oct 2015 12:46:20 +0000 Subject: [PATCH 0110/1080] docs: Clarify oh-my-zsh installation instructions Suggested-by: Ory Band (on issue #169) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cb22c37..c14c9df 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ How to install cd ~/.oh-my-zsh/custom/plugins git clone git://github.com/zsh-users/zsh-syntax-highlighting.git -* Activate the plugin in `~/.zshrc` (in **last** position): +* Activate the plugin in `~/.zshrc`: plugins=( [plugins...] zsh-syntax-highlighting) @@ -47,6 +47,8 @@ How to install source ~/.zshrc +Note that `zsh-syntax-highlighting` must be the last plugin sourced, +so make it the last element of the `$plugins` array. FAQ --- From 7aeadfe01bcab87d2506b34d865644b3bb5f05a5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 25 Sep 2015 08:28:27 -0500 Subject: [PATCH 0111/1080] Add Makefile --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..34b3610 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +NAME=zsh-syntax-highlighting + +PREFIX?=/usr/local +SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) + +install: + $(INSTALL) -d $(SHARE_DIR) + cp -r zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) From 83c3f96109d353ffc6b808e46229f6416b6f116b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 25 Sep 2015 21:29:51 -0500 Subject: [PATCH 0112/1080] Makefile: Add test target --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 34b3610..3677977 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,11 @@ SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) install: $(INSTALL) -d $(SHARE_DIR) cp -r zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) + +test: + @for test in highlighters/*; do \ + if [ -d $$test/test-data ]; then \ + echo "Running test $${test##*/}"; \ + zsh tests/test-highlighting.zsh "$${test##*/}"; \ + fi \ + done From 2883c9582dc35e0f70e49b79622e09015bc972fb Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 19 Oct 2015 01:36:42 -0500 Subject: [PATCH 0113/1080] Makefile: exit non-zero for a failed test --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 3677977..680c116 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,12 @@ install: cp -r zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) test: + @result=0 @for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ zsh tests/test-highlighting.zsh "$${test##*/}"; \ + : $$(( result |= $$? )); \ fi \ done + @exit $$result From 94191f0731c6285dc9b8bd71a07933782c370c33 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 19 Oct 2015 01:44:02 -0500 Subject: [PATCH 0114/1080] Makefile: Add default for INSTALL --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 680c116..68fbf0d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ NAME=zsh-syntax-highlighting +INSTALL?=install -c PREFIX?=/usr/local SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) From 984b4acd7818bf513850a31415f9a5a5b040191c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 07:08:21 +0000 Subject: [PATCH 0115/1080] Makefile: have the default invocation safer. Don't modify $(PREFIX) from 'make', only from 'make install'. --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 68fbf0d..5088d6a 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ INSTALL?=install -c PREFIX?=/usr/local SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) +# Have the default target do nothing. +all: + @ : + install: $(INSTALL) -d $(SHARE_DIR) cp -r zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) From 43386376d8f861fe46ad59c616569c26fed631a9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Oct 2015 16:18:56 +0000 Subject: [PATCH 0116/1080] Set the version number. Store it in a separate file so OS packages and 'make install' (issue #177) can reuse it. --- .version | 1 + zsh-syntax-highlighting.zsh | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 .version diff --git a/.version b/.version new file mode 100644 index 0000000..0ba2319 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +0.3.0-dev \ No newline at end of file diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index ce9db28..3c3163d 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -29,6 +29,8 @@ # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_VERSION=$(<"$0:h"/.version) + # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- From 9c56c624e98134e565c0b16da77a5d7bd71236f6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Oct 2015 16:26:43 +0000 Subject: [PATCH 0117/1080] versionstamp: Handle NO_FUNCTION_ARGZERO. Sourcing zsh-syntax-highlighting.zsh without FUNCTION_ARGZERO doesn't work (for reasons unrelated to this branch), but now errors out gracefully. The failure mode before this branch was: zsh-syntax-highlighting: highlighters directory '/usr/local/bin/highlighters' not found. where /usr/local/bin is dirname() of the zsh binary. --- zsh-syntax-highlighting.zsh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 3c3163d..a65b29f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -29,7 +29,16 @@ # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_VERSION=$(<"$0:h"/.version) +if [[ -o function_argzero ]]; then + # $0 is reliable + ZSH_HIGHLIGHT_VERSION=$(<"$0:h"/.version) +else + # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. + # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? + # TODO: also check POSIX_ARGZERO, but not it's not available in older zsh + echo "zsh-syntax-highlighting: error: not compatible with FUNCTION_ARGZERO" >&2 + return 1 +fi # ------------------------------------------------------------------------------------------------- # Core highlighting update system From c538d6b35750df11c3750658bf0b23d4efdf0da8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Oct 2015 18:12:07 +0000 Subject: [PATCH 0118/1080] versionstamp: Set up '.revision-hash' file. --- .gitattributes | 1 + .revision-hash | 1 + 2 files changed, 2 insertions(+) create mode 100644 .gitattributes create mode 100644 .revision-hash diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..715e624 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.revision-hash export-subst diff --git a/.revision-hash b/.revision-hash new file mode 100644 index 0000000..6828f88 --- /dev/null +++ b/.revision-hash @@ -0,0 +1 @@ +$Format:%H$ From 728784649f837b130ee88ccb88e319f1103640aa Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 07:35:12 +0000 Subject: [PATCH 0119/1080] 'make install': Install .version and .revision-hash. --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5088d6a..7eaae66 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,12 @@ all: install: $(INSTALL) -d $(SHARE_DIR) - cp -r zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) + cp -r .version zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) + if [ x"true" = x"`git rev-parse --is-inside-work-tree 2>/dev/null`" ]; then \ + git rev-parse HEAD; \ + else \ + cat .revision-hash; \ + fi > $(SHARE_DIR)/.revision-hash test: @result=0 From e0bb30a1532714e707d8bd66e51256639e20c8d4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 08:02:27 +0000 Subject: [PATCH 0120/1080] changelog: Add changelog for 0.2.1..HEAD (0.3.0-dev). --- changelog.md | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 changelog.md diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..1b69c89 --- /dev/null +++ b/changelog.md @@ -0,0 +1,95 @@ +up to 9a3c7d19609ca8c426a54b252b8509faf63b0bd5 + + +# Changes in version 0.3.0 + + +## Added highlighting of: + +- suffix aliases: + + alias -s png=display + foo.png + +- prefix redirections: + + foo.txt + +- arithmetic evaluations: + + (( 42 )) + +- $'' strings, including \x/\octal/\u/\U escapes + + : $'foo\u0040bar' + +- multiline strings: + + % echo "line 1 + line 2" + +- string literals that haven't been finished: + + % echo "Hello, world + +- command words that involve tilde expansion: + + % ~/bin/foo + + +## Fixed highlighting of: + +- quoted command words: + + % \ls + +- backslash escapes in "" strings: + + % echo "\x41" + +- noglob after command separator: + + % :; noglob echo * + +- glob after command separator, when the first command starts with 'noglob': + + % 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 <‸ + + (where `‸` represents the cursor location) + +- escaped globbing (outside quotes) + + % echo \* + + +## Other changes: + +- implemented compatibility with zsh's paste highlighting (issue #175) + +- `$?` propagated correctly to wrapped widgets + + +## Developer-visible changes: + +- added makefile with `install` and `test` targets + +- set `warn_create_global` internally + + + + +# Version 0.2.1 + +(Start of changelog.) + From fe4e893ce5142e1947d064ef0674ff3f5ebe947f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 08:05:58 +0000 Subject: [PATCH 0121/1080] changelog: Extend 'suffix aliases' entry. --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 1b69c89..5e2cc8e 100644 --- a/changelog.md +++ b/changelog.md @@ -6,7 +6,7 @@ up to 9a3c7d19609ca8c426a54b252b8509faf63b0bd5 ## Added highlighting of: -- suffix aliases: +- suffix aliases (requires zsh 5.1.1 or newer): alias -s png=display foo.png From 766b350a7d346374e8945a0644825953fc202181 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 08:30:11 +0000 Subject: [PATCH 0122/1080] Wrap yank-pop. As explained in #143 (which was a PR for #99), 'yank-pop' only works when the previous widget has the ZLE_YANK flag, which means wrapping the 'yank' widget breaks the 'yank-pop' widget (makes it a no-op). However, that is a reason against wrapping the 'yank' widget, but not against wrapping the 'yank-pop' widget. Indeed, if 'yank-pop' is wrapped but 'yank' isn't, then yank-pop functions correctly and updates highlighting properly. To unbreak yank-pop, either 'yank' should be excluded from wrapping, or one of the fixes mentioned on issue #183 should be applied. --- 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 a65b29f..810bb54 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -182,7 +182,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank-pop|set-local-history)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|set-local-history)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From f48f5400c1faa875fed810f70fb57dfa506b977b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 13:38:12 +0000 Subject: [PATCH 0123/1080] Revert "Do wrap the 'yank' widget, because that works." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8e7c26f489f952213bbb269a0570384184c0f6fe. Currently, after a 'yank', paste highlighting (via $YANK_ACTIVE in zsh 5.1.1) is applied but other highlighting (e.g., string highlighting when the yanked text is «"foo» as a new word) is not. See issue #183 for context. Conflicts: zsh-syntax-highlighting.zsh --- 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 810bb54..1441695 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -182,7 +182,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|set-local-history)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From 4604deb652a2ce4de24ea0608c30092cb91c3a4a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 13:59:30 +0000 Subject: [PATCH 0124/1080] dev: Document the release process (first draft). --- release.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 release.md diff --git a/release.md b/release.md new file mode 100644 index 0000000..ae0a82e --- /dev/null +++ b/release.md @@ -0,0 +1,11 @@ +# Release procedure (for developers): + +- Check open issues and outstanding pull requests +- Confirm `make test` passes + - check with multiple zsh versions +- Update changelog.md +- Update ./.version +- `git tag -am "Release $(<.version)" zsh-syntax-highlighting-"$(<.version)" && git push --tags` +- `perl -pi -e 's/$/-dev/' ./.version` +- Notify downstreams (OS packages) + - anitya should autodetect the tag From bde1c83af1d082320a6e73fab2492f96415ad238 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Oct 2015 14:26:01 +0000 Subject: [PATCH 0125/1080] 'make test': Pass -f to zsh to minimize environmental variation. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7eaae66..8425eca 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ test: @for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ - zsh tests/test-highlighting.zsh "$${test##*/}"; \ + zsh -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ done From 3576df29aa06892f7f754fe2ac32456cf29be9ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 00:21:11 +0000 Subject: [PATCH 0126/1080] Don't leak $REPLY into global scope. Fixes issue #213. --- zsh-syntax-highlighting.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 1441695..54d52a1 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -57,6 +57,7 @@ _zsh_highlight() local ret=$? setopt localoptions warncreateglobal + 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 # likely a pasted command or a huge list of files in that case.. From 72b1abd17d1ef5e5385beb5b1b7ea22c5a123669 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 20 Oct 2015 00:26:43 +0000 Subject: [PATCH 0127/1080] Makefile: declare PHONY targets --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 8425eca..44d4923 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,5 @@ test: fi \ done @exit $$result + +.PHONY: all install test From 6f7bf8c0f46592bf5d864cce4457d81e902fe2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Galv=C3=A3o?= Date: Mon, 19 Oct 2015 23:10:24 +0100 Subject: [PATCH 0128/1080] README.md: install with oh-my-zsh in a single command --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index c14c9df..c754179 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,7 @@ How to install * Download the script or clone this repository in [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh) plugins directory: - cd ~/.oh-my-zsh/custom/plugins - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting * Activate the plugin in `~/.zshrc`: From bb9c407c958664daef60117c6673345761c34c70 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 00:31:40 +0000 Subject: [PATCH 0129/1080] 'make install': Tweak to work with one-shell-per-logical-line 'make' implementations, Tested with 'bmake -B'. Found-by: Carsten Hey --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 44d4923..d77c229 100644 --- a/Makefile +++ b/Makefile @@ -18,14 +18,14 @@ install: fi > $(SHARE_DIR)/.revision-hash test: - @result=0 - @for test in highlighters/*; do \ + @result=0; \ + for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ zsh -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ - done - @exit $$result + done; \ + exit $$result .PHONY: all install test From 0a7035170ac4927c90a614fa7287f7697b86be96 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 03:07:04 +0000 Subject: [PATCH 0130/1080] versioning: Expose .revision-hash as $ZSH_HIGHLIGHT_REVISION. Currently, this only works in installed trees and exported tarballs; the parameter is left unset when running directly from a git worktree. --- zsh-syntax-highlighting.zsh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 54d52a1..bed6e64 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -32,6 +32,13 @@ if [[ -o function_argzero ]]; then # $0 is reliable ZSH_HIGHLIGHT_VERSION=$(<"$0:h"/.version) + ZSH_HIGHLIGHT_REVISION=$(<"$0:h"/.revision-hash) + if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then + # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION + # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining + # the valid value (via `git rev-parse HEAD`, as Makefile does) might be costly, so: + unset ZSH_HIGHLIGHT_REVISION + fi else # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? From c30301d4745c536aee55a43aea57e5987339d492 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 11:49:51 +0000 Subject: [PATCH 0131/1080] Drop unnecessary shebang lines. All these files should be sourced, not executed; and Debian's lintian complains: W: zsh-syntax-highlighting: script-not-executable usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh --- highlighters/brackets/brackets-highlighter.zsh | 1 - highlighters/brackets/test-data/mismatch-patentheses.zsh | 1 - highlighters/brackets/test-data/nested-parentheses.zsh | 1 - highlighters/brackets/test-data/quoted-patentheses.zsh | 1 - highlighters/brackets/test-data/simple-parentheses.zsh | 1 - highlighters/brackets/test-data/unclosed-patentheses.zsh | 1 - highlighters/brackets/test-data/unclosed-patentheses2.zsh | 1 - highlighters/cursor/cursor-highlighter.zsh | 1 - highlighters/line/line-highlighter.zsh | 1 - highlighters/main/test-data/alias.zsh | 1 - highlighters/main/test-data/arithmetic-evaluation.zsh | 1 - highlighters/main/test-data/assign-append.zsh | 1 - highlighters/main/test-data/assign.zsh | 1 - highlighters/main/test-data/back-quoted-argument.zsh | 1 - highlighters/main/test-data/backslash-continuation.zsh | 1 - highlighters/main/test-data/commandseparator.zsh | 1 - highlighters/main/test-data/dollar-quoted.zsh | 1 - highlighters/main/test-data/dollar-quoted2.zsh | 1 - highlighters/main/test-data/dollar-quoted3.zsh | 1 - highlighters/main/test-data/double-hyphen-option.zsh | 1 - highlighters/main/test-data/double-quoted.zsh | 1 - highlighters/main/test-data/double-quoted2.zsh | 1 - highlighters/main/test-data/double-quoted3.zsh | 1 - highlighters/main/test-data/empty-command.zsh | 1 - highlighters/main/test-data/function.zsh | 1 - highlighters/main/test-data/glob.zsh | 1 - highlighters/main/test-data/hashed-command.zsh | 1 - highlighters/main/test-data/history-expansion.zsh | 1 - highlighters/main/test-data/history-expansion2.zsh | 1 - highlighters/main/test-data/multiline-string.zsh | 1 - highlighters/main/test-data/multiline-string2.zsh | 1 - highlighters/main/test-data/multiple-redirections.zsh | 1 - highlighters/main/test-data/noglob1.zsh | 1 - highlighters/main/test-data/noglob2.zsh | 1 - highlighters/main/test-data/path-space- .zsh | 1 - highlighters/main/test-data/path-tilde-home.zsh | 1 - highlighters/main/test-data/path-tilde-named.zsh | 1 - highlighters/main/test-data/path.zsh | 1 - highlighters/main/test-data/path_prefix.zsh | 1 - highlighters/main/test-data/prefix-redirection.zsh | 1 - highlighters/main/test-data/redirection.zsh | 1 - highlighters/main/test-data/reserved-word.zsh | 1 - highlighters/main/test-data/simple-command.zsh | 1 - highlighters/main/test-data/simple-redirection.zsh | 1 - highlighters/main/test-data/sudo-command.zsh | 1 - highlighters/main/test-data/tilde-command-word.zsh | 1 - highlighters/main/test-data/unbackslash.zsh | 1 - highlighters/main/test-data/unknown-command.zsh | 1 - highlighters/main/test-data/vanilla-newline.zsh | 1 - highlighters/pattern/pattern-highlighter.zsh | 1 - highlighters/root/root-highlighter.zsh | 1 - zsh-syntax-highlighting.zsh | 1 - 52 files changed, 52 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index ee4a83b..2b87a3e 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index f538273..5671079 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 49262e4..291f8f4 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index e21ae0a..a2c52c4 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index b4e6967..893145f 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index 33ee42d..c36ba36 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 3aa4a7b..04c246b 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index b5868a4..d315c62 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/line/line-highlighter.zsh b/highlighters/line/line-highlighter.zsh index 230c587..68308cc 100644 --- a/highlighters/line/line-highlighter.zsh +++ b/highlighters/line/line-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 74bda73..aa84a58 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/arithmetic-evaluation.zsh b/highlighters/main/test-data/arithmetic-evaluation.zsh index 6d470a6..dc26472 100644 --- a/highlighters/main/test-data/arithmetic-evaluation.zsh +++ b/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 6319826..a38cd86 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 231d16c..ef38668 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index ae01b0a..6dfba71 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/backslash-continuation.zsh b/highlighters/main/test-data/backslash-continuation.zsh index e9d6d20..9fbd916 100644 --- a/highlighters/main/test-data/backslash-continuation.zsh +++ b/highlighters/main/test-data/backslash-continuation.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index 9325d84..383bd47 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index 5024e48..ea12f9f 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index 0eb482d..1ce9bb4 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index 2632ff9..53ee171 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index 009e36b..b87ebe8 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index 35178a2..3f80f9e 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index fd202fe..d3facb2 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 2d861cb..6b9001c 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index 6b20e91..26265a7 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index 9ed2cc7..3e579ab 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index 502283e..d808e2b 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index 9b74990..ce41b45 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index b56e77a..c670312 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/history-expansion2.zsh b/highlighters/main/test-data/history-expansion2.zsh index 0d93397..45af624 100644 --- a/highlighters/main/test-data/history-expansion2.zsh +++ b/highlighters/main/test-data/history-expansion2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh index 450458c..987dd20 100644 --- a/highlighters/main/test-data/multiline-string.zsh +++ b/highlighters/main/test-data/multiline-string.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index d460d6e..9753e5d 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index ac0606c..374de8a 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh index 2a76589..d9bc69b 100644 --- a/highlighters/main/test-data/noglob1.zsh +++ b/highlighters/main/test-data/noglob1.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh index 0892787..2c19250 100644 --- a/highlighters/main/test-data/noglob2.zsh +++ b/highlighters/main/test-data/noglob2.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/path-space- .zsh b/highlighters/main/test-data/path-space- .zsh index 91c3833..f6b889e 100644 --- a/highlighters/main/test-data/path-space- .zsh +++ b/highlighters/main/test-data/path-space- .zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/path-tilde-home.zsh b/highlighters/main/test-data/path-tilde-home.zsh index 14f8e18..28b0f50 100644 --- a/highlighters/main/test-data/path-tilde-home.zsh +++ b/highlighters/main/test-data/path-tilde-home.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index 74824db..be5bb5a 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/path.zsh b/highlighters/main/test-data/path.zsh index 52e3af1..3688b9b 100644 --- a/highlighters/main/test-data/path.zsh +++ b/highlighters/main/test-data/path.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index bd54454..5b7c8b4 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index c7d92bf..c029509 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh index 0a01d55..7515352 100644 --- a/highlighters/main/test-data/redirection.zsh +++ b/highlighters/main/test-data/redirection.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index 619ec28..3cd9cd2 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/simple-command.zsh b/highlighters/main/test-data/simple-command.zsh index 4227c80..51dd9a9 100644 --- a/highlighters/main/test-data/simple-command.zsh +++ b/highlighters/main/test-data/simple-command.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index 98860ea..191c67e 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 6059711..6e84179 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/tilde-command-word.zsh b/highlighters/main/test-data/tilde-command-word.zsh index ff10836..e66db8e 100644 --- a/highlighters/main/test-data/tilde-command-word.zsh +++ b/highlighters/main/test-data/tilde-command-word.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/unbackslash.zsh b/highlighters/main/test-data/unbackslash.zsh index 1a8bc45..b96c055 100644 --- a/highlighters/main/test-data/unbackslash.zsh +++ b/highlighters/main/test-data/unbackslash.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/unknown-command.zsh b/highlighters/main/test-data/unknown-command.zsh index 74854d4..9b9e8d3 100644 --- a/highlighters/main/test-data/unknown-command.zsh +++ b/highlighters/main/test-data/unknown-command.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index ccf3588..7fa9ba2 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/pattern/pattern-highlighter.zsh b/highlighters/pattern/pattern-highlighter.zsh index 1cf6ef1..c77d53b 100644 --- a/highlighters/pattern/pattern-highlighter.zsh +++ b/highlighters/pattern/pattern-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/root/root-highlighter.zsh b/highlighters/root/root-highlighter.zsh index 294fda1..4362379 100644 --- a/highlighters/root/root-highlighter.zsh +++ b/highlighters/root/root-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index bed6e64..a60d0bb 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2015 zsh-syntax-highlighting contributors # All rights reserved. From c687bddea311a8adc964fd91496e07150368bbfd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 11:49:51 +0000 Subject: [PATCH 0132/1080] Drop unnecessary shebang lines, part 2. Follow-up to the last commit. E: zsh-syntax-highlighting: missing-dep-for-interpreter zsh => zsh | zsh-beta (usr/share/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh) W: zsh-syntax-highlighting: executable-not-elf-or-script usr/share/zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh --- highlighters/main/main-highlighter.zsh | 1 - 1 file changed, 1 deletion(-) mode change 100755 => 100644 highlighters/main/main-highlighter.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh old mode 100755 new mode 100644 index f7a9f12..0dbbc21 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2010-2015 zsh-syntax-highlighting contributors # All rights reserved. From a73b33fc13273fc65d29e7cfc075ee12e607fe45 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:32:34 +0000 Subject: [PATCH 0133/1080] release.md: Create tags the way they've always been created. --- release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.md b/release.md index ae0a82e..bab8432 100644 --- a/release.md +++ b/release.md @@ -5,7 +5,7 @@ - check with multiple zsh versions - Update changelog.md - Update ./.version -- `git tag -am "Release $(<.version)" zsh-syntax-highlighting-"$(<.version)" && git push --tags` +- `git tag $(<.version) && git push --tags` - `perl -pi -e 's/$/-dev/' ./.version` - Notify downstreams (OS packages) - anitya should autodetect the tag From 58b0047c8135950447272a7d64ca7c71bada8415 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:29:33 +0000 Subject: [PATCH 0134/1080] changelog: Update through HEAD --- changelog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 5e2cc8e..f17bf86 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to 9a3c7d19609ca8c426a54b252b8509faf63b0bd5 +up to c687bddea311a8adc964fd91496e07150368bbfd # Changes in version 0.3.0 @@ -79,6 +79,8 @@ up to 9a3c7d19609ca8c426a54b252b8509faf63b0bd5 - `$?` propagated correctly to wrapped widgets +- don't leak $REPLY into global scope + ## Developer-visible changes: @@ -86,6 +88,8 @@ up to 9a3c7d19609ca8c426a54b252b8509faf63b0bd5 - set `warn_create_global` internally +- document release process + From fee52920ae0b29e30bf5413151263faed20f5123 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:34:59 +0000 Subject: [PATCH 0135/1080] Tag version 0.3.0. --- .version | 2 +- changelog.md | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.version b/.version index 0ba2319..0d91a54 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.3.0-dev \ No newline at end of file +0.3.0 diff --git a/changelog.md b/changelog.md index f17bf86..aedd0eb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,3 @@ -up to c687bddea311a8adc964fd91496e07150368bbfd - - # Changes in version 0.3.0 From b5c30ae52638e81a38fe5329081c5613d7bd6ca5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 0136/1080] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 0d91a54..746bd19 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.3.0 +0.3.1-dev From cac3d95269dcd6ae4641264e5cfc35f63b913f57 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:37:14 +0000 Subject: [PATCH 0137/1080] release.md: Document tag process more clearly. --- release.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/release.md b/release.md index bab8432..87fae5f 100644 --- a/release.md +++ b/release.md @@ -4,8 +4,11 @@ - Confirm `make test` passes - check with multiple zsh versions - Update changelog.md -- Update ./.version -- `git tag $(<.version) && git push --tags` -- `perl -pi -e 's/$/-dev/' ./.version` +- Remove `-dev` suffix from `./.version`; + Commit that; + Tag it using `git tag $(<.version)`; + Increment `./.version` and restore the `-dev` suffix; + Commit that. +- Push with `git push --tags` - Notify downstreams (OS packages) - anitya should autodetect the tag From cae87016c6c67d5b33050965a0149c02220bb71f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:41:55 +0000 Subject: [PATCH 0138/1080] release.md: Add an IRC task. --- release.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release.md b/release.md index 87fae5f..a38d677 100644 --- a/release.md +++ b/release.md @@ -12,3 +12,4 @@ - Push with `git push --tags` - Notify downstreams (OS packages) - anitya should autodetect the tag +- Update /topic on IRC From 8631cc1061058c020755a95960dea042c7ffdd71 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:56:10 +0000 Subject: [PATCH 0139/1080] README.md += overview description paragraph Based on text by Carsten Hey . --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index c754179..7c4211a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ zsh-syntax-highlighting *Requirements: zsh 4.3.17+.* +This package provides syntax highlighing for the shell zsh. It enables +highlighing of commands whilst they are typed at a zsh prompt into an +interactive terminal. This helps in reviewing commands before running +them, particularly in catching syntax errors. + How to install -------------- From 30f2f1f144a4a8bd9cbf801deeff12101e252891 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 21 Oct 2015 02:48:34 +0000 Subject: [PATCH 0140/1080] .gitignore: Add .pc (quilt dir) for the benefit of downstreams --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 13b9215..fb2e708 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.zwc* +.pc/ From 083c47b00707f87f0f9f7ec08d91abbbcec64d7b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 21 Oct 2015 06:55:00 +0000 Subject: [PATCH 0141/1080] regerssion: Look for .version and .revision-hash in the correct place. Fixes zsh-users/zsh-syntax-highlighting#215. --- 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 a60d0bb..f622c0e 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -30,8 +30,8 @@ if [[ -o function_argzero ]]; then # $0 is reliable - ZSH_HIGHLIGHT_VERSION=$(<"$0:h"/.version) - ZSH_HIGHLIGHT_REVISION=$(<"$0:h"/.revision-hash) + ZSH_HIGHLIGHT_VERSION=$(<"$0:A:h"/.version) + ZSH_HIGHLIGHT_REVISION=$(<"$0:A:h"/.revision-hash) if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining From d99aa58aaaef6d9f416f338333277eeaec44ffdc Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 23 Oct 2015 03:27:05 +0000 Subject: [PATCH 0142/1080] test harness: Run each test as a single subshell. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That allows tests to be completely independent of each other, so tests that change global state — such as modify environment variables, define functions or aliases, or hash commands — will not affect other tests, without needing an explicit cleanup step. This enables testing path-tilde-home with and without $HOME set, which is part of issue #216. While at it, convert the test harness to TAP. This fixes issue #180 by adding support for "not ok 42 # TODO" output. This commit assumes that 'grep' supports POSIX-compliant -q and -v flags. Patch-by: Matthew Martin --- tests/README.md | 9 ++- tests/test-highlighting.zsh | 114 ++++++++++++++++-------------------- 2 files changed, 57 insertions(+), 66 deletions(-) diff --git a/tests/README.md b/tests/README.md index 676dd64..15aacd8 100644 --- a/tests/README.md +++ b/tests/README.md @@ -6,9 +6,10 @@ Utility scripts for testing zsh-syntax-highlighting highlighters. The tests expect the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. Each test should define the array parameter `$expected_region_highlight`. -The value of that parameter is a list of `"$i $j $style"` strings. +The value of that parameter is a list of `"$i $j $style [$todo]"` strings. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. +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. _Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. @@ -19,6 +20,12 @@ highlighting test zsh test-highlighting.zsh +All tests may be run with + + make test + +which will run all highlighting tests and report results in [TAP](http://testanything.org/) format. + performance test ---------------- diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 83fde94..d855e2e 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -47,87 +47,71 @@ exit 1 } -local -a errors highlight_zone -local -A observed_result -local -A save_ZSH_HIGHLIGHT_STYLES -integer something_failed=0 -local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use - # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh # Activate the highlighter. ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) -# Cache a pristine set of styles. -save_ZSH_HIGHLIGHT_STYLES=( "${(@kv)ZSH_HIGHLIGHT_STYLES}" ) - -# Process each test data file in test data directory. -for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do +# Runs a highlighting test +# $1: data file +run_test() { + local -a highlight_zone + local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use # Load the data and prepare checking it. - PREBUFFER= BUFFER= ; expected_region_highlight=(); errors=() - echo -n "* ${data_file:t:r}: " - ZSH_HIGHLIGHT_STYLES=( "${(@kv)save_ZSH_HIGHLIGHT_STYLES}" ) - . $data_file + PREBUFFER= BUFFER= ; + . "$1" # Check the data declares $PREBUFFER or $BUFFER. - if [[ ${#PREBUFFER} -eq 0 && ${#BUFFER} -eq 0 ]]; then - errors+=("Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank") - else + [[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! 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! 'expected_region_highlight' is not declared or empty."; return 1; } - # Check the data declares $expected_region_highlight. - if [[ ${#expected_region_highlight} -eq 0 ]]; then - errors+=("'expected_region_highlight' is not declared or empty.") + # Process the data. + region_highlight=() + _zsh_highlight + + # Overlapping regions can be declared in region_highlight, so we first build an array of the + # observed highlighting. + local -A observed_result + for i in {1..${#region_highlight}}; do + highlight_zone=${(z)region_highlight[$i]} + integer start=$highlight_zone[1] end=$highlight_zone[2] + if (( start < end )) # region_highlight ranges are half-open + then + (( --end )) # convert to closed range, like expected_region_highlight + (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed + for j in {$start..$end}; do + observed_result[$j]=$highlight_zone[3] + done else - - # Process the data. - region_highlight=() - _zsh_highlight - - # Overlapping regions can be declared in region_highlight, so we first build an array of the - # observed highlighting. - observed_result=() - for i in {1..${#region_highlight}}; do - highlight_zone=${(z)region_highlight[$i]} - integer start=$highlight_zone[1] end=$highlight_zone[2] - if (( start < end )) # region_highlight ranges are half-open - then - (( --end )) # convert to closed range, like expected_region_highlight - (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed - for j in {$start..$end}; do - observed_result[$j]=$highlight_zone[3] - done - else - # noop range; ignore. - fi - done - - # Then we compare the observed result with the expected one. - for i in {1..${#expected_region_highlight}}; do - highlight_zone=${(z)expected_region_highlight[$i]} - for j in {$highlight_zone[1]..$highlight_zone[2]}; do - if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - errors+=("'$BUFFER[$highlight_zone[1],$highlight_zone[2]]' [$highlight_zone[1],$highlight_zone[2]]: expected '$highlight_zone[3]', observed '$observed_result[$j]'.") - break - fi - done - done - + # noop range; ignore. fi - fi + done - # Format result/errors. - if [[ ${#errors} -eq 0 ]]; then - echo "OK" - else - echo "KO" - (( something_failed=1 )) - for error in $errors; do - echo " - $error" + # Then we compare the observed result with the expected one. + local todo + echo "1..${#expected_region_highlight}" + for i in {1..${#expected_region_highlight}}; do + highlight_zone=${(z)expected_region_highlight[$i]} + [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" + for j in {$highlight_zone[1]..$highlight_zone[2]}; do + if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then + echo "not ok $i '$BUFFER[$highlight_zone[1],$highlight_zone[2]]' [$highlight_zone[1],$highlight_zone[2]]: expected '$highlight_zone[3]', observed '$observed_result[$j]'.$todo" + continue 2 + fi done - fi + echo "ok $i$todo" + done +} +# Process each test data file in test data directory. +integer something_failed=0 +for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do + echo "# ${data_file:t:r}" + (run_test "$data_file") | tee >(cat) | grep '^not ok' | grep -qv ' # TODO' && (( something_failed=1 )) + (( $pipestatus[1] )) && exit 2 done exit $something_failed From 22c8736e2bd048331e2233fb3ac86bf0ab099383 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 23 Oct 2015 03:13:47 +0000 Subject: [PATCH 0143/1080] Add XFAIL test for issue #160, "subshells highlighted incorrectly". --- highlighters/main/test-data/subshell.zsh | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/subshell.zsh diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh new file mode 100644 index 0000000..378e083 --- /dev/null +++ b/highlighters/main/test-data/subshell.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='tar cf - * | (cd /target; tar xfp -)' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # tar + "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # cd + "27 29 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # tar +) From b2ac98b98150b097e9a3dbea8a7b02b4a5cfd0bd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 03:51:06 +0000 Subject: [PATCH 0144/1080] Fix issue #216: test failure with HOME=/nonexistent. Make the test pass by setting explicitly the global state (existing $HOME) it depends on. Test another value of the global state (a non-existing $HOME). --- .../main/test-data/path-tilde-home.zsh | 1 + .../main/test-data/path-tilde-home2.zsh | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/path-tilde-home2.zsh diff --git a/highlighters/main/test-data/path-tilde-home.zsh b/highlighters/main/test-data/path-tilde-home.zsh index 28b0f50..31ad1e9 100644 --- a/highlighters/main/test-data/path-tilde-home.zsh +++ b/highlighters/main/test-data/path-tilde-home.zsh @@ -27,6 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +HOME="." BUFFER='ls ~' expected_region_highlight=( diff --git a/highlighters/main/test-data/path-tilde-home2.zsh b/highlighters/main/test-data/path-tilde-home2.zsh new file mode 100644 index 0000000..b091082 --- /dev/null +++ b/highlighters/main/test-data/path-tilde-home2.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 +# ------------------------------------------------------------------------------------------------- + +HOME="/nonexistent" +BUFFER='ls ~' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 4 $ZSH_HIGHLIGHT_STYLES[default]" # ~ +) + From 11c060ab765a2e08b829f90ae81e53fe5a203492 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:26:51 +0000 Subject: [PATCH 0145/1080] test harness: Fix a bug whereby 'todo' state would propagate to all subsequent test points. Update expectations on the subshell test (which triggered this bug, since it has a passing test point following a 'todo' test point). --- highlighters/main/test-data/subshell.zsh | 4 ++-- tests/test-highlighting.zsh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 378e083..f013eb1 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -30,7 +30,7 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # tar + "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # cd - "27 29 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # tar + "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar ) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index d855e2e..c77b3ca 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -91,9 +91,9 @@ run_test() { done # Then we compare the observed result with the expected one. - local todo echo "1..${#expected_region_highlight}" for i in {1..${#expected_region_highlight}}; do + local todo= highlight_zone=${(z)expected_region_highlight[$i]} [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do From c4a9fe93792b11d26f20028cba6f97b0ede8beb7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:30:00 +0000 Subject: [PATCH 0146/1080] test harness: Exit 1 if a 'todo' test passed. --- 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 c77b3ca..4ecee08 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -110,7 +110,7 @@ run_test() { integer something_failed=0 for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do echo "# ${data_file:t:r}" - (run_test "$data_file") | tee >(cat) | grep '^not ok' | grep -qv ' # TODO' && (( something_failed=1 )) + (run_test "$data_file") | tee >(cat) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 done From 187371a459b00d8330d866f2b68cf29b43b00de4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:44:39 +0000 Subject: [PATCH 0147/1080] chamgelog: Update through HEAD --- changelog.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/changelog.md b/changelog.md index aedd0eb..6d5a5c8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,23 @@ +up to c4a9fe93792b11d26f20028cba6f97b0ede8beb7 + +# Changes in version 0.3.1 + +## Other changes: + +- Fix initialization when sourcing `zsh-syntax-highlighting.zsh` via a symlink + (083c47b00707) + + +## Developer-visible changes: + +- Run each test in a separate subprocess, isolating them from each other + (d99aa58aaaef, et seq) + +- Fix test failure with nonexisting $HOME + (#216, b2ac98b98150) + + + # Changes in version 0.3.0 From a18a7427fd2c5caf551848ba1602ebd5e09009fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:45:18 +0000 Subject: [PATCH 0148/1080] README: Document 'make install'. Fixes zsh-users/zsh-syntax-highlighting#218. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 7c4211a..2845a34 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,15 @@ How to install Note that `zsh-syntax-highlighting` must be the last plugin sourced, so make it the last element of the `$plugins` array. +### System-wide installation + +Either 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` and directing your users to +add `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +in their `.zshrc`s. + + FAQ --- From 8b8b19d91f2f945402488c5025c132a93a2a50c8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:48:16 +0000 Subject: [PATCH 0149/1080] test harness: Fix a bug with empty actual or expected results. Fixes zsh-users/zsh-syntax-highlighting#217. --- 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 4ecee08..dece1d9 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -75,7 +75,7 @@ run_test() { # Overlapping regions can be declared in region_highlight, so we first build an array of the # observed highlighting. local -A observed_result - for i in {1..${#region_highlight}}; do + for ((i=1; i<=${#region_highlight}; i++)); do highlight_zone=${(z)region_highlight[$i]} integer start=$highlight_zone[1] end=$highlight_zone[2] if (( start < end )) # region_highlight ranges are half-open @@ -92,7 +92,7 @@ run_test() { # Then we compare the observed result with the expected one. echo "1..${#expected_region_highlight}" - for i in {1..${#expected_region_highlight}}; do + for ((i=1; i<=${#expected_region_highlight}; i++)); do local todo= highlight_zone=${(z)expected_region_highlight[$i]} [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" From 728ed66ff9b4f3b59f35f8d3f8072246e6e22264 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:53:06 +0000 Subject: [PATCH 0150/1080] Fix copyright year. Followup to b2ac98b98150b097e9a3dbea8a7b02b4a5cfd0bd. --- highlighters/main/test-data/path-tilde-home2.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/path-tilde-home2.zsh b/highlighters/main/test-data/path-tilde-home2.zsh index b091082..18dd17b 100644 --- a/highlighters/main/test-data/path-tilde-home2.zsh +++ b/highlighters/main/test-data/path-tilde-home2.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From d66113c1ed0af7a9c4cb72fd1b8b572fe4171135 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:56:02 +0000 Subject: [PATCH 0151/1080] Add XFAIL test for issue #205, "';' highlighted as unknown-token". --- .../main/test-data/assign-semicolon.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/assign-semicolon.zsh diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh new file mode 100644 index 0000000..c47bf28 --- /dev/null +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight +BUFFER='A=1; echo hello world' + +expected_region_highlight=( + "4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator] 'issue #205'" # ; + "6 9 $ZSH_HIGHLIGHT_STYLES[command]" # echo +) From 20d106bd4d6223931ccd82a80c9cbfffeaad6650 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 04:57:05 +0000 Subject: [PATCH 0152/1080] noop: Associate an XFAIL test with its issue. --- highlighters/main/test-data/subshell.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index f013eb1..31f8507 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'not yet implemented'" # cd + "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'issue #166'" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar ) From 663c760cc9e8d4a17546be8ab0726271b8d310ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Oct 2015 05:34:01 +0000 Subject: [PATCH 0153/1080] minor: test harness: Convert some global failure modes to TAP "Bail out" mode. --- tests/test-highlighting.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index dece1d9..a67229a 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -31,20 +31,20 @@ # Check an highlighter was given as argument. [[ -n "$1" ]] || { - echo "You must provide the name of a valid highlighter as argument." >&2 - exit 1 + echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." + exit 2 } # Check the highlighter is valid. [[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { - echo "Could not find highlighter '$1'." >&2 - exit 1 + echo >&2 "Bail out! Could not find highlighter '$1'." + exit 2 } # Check the highlighter has test data. [[ -d ${0:h:h}/highlighters/$1/test-data ]] || { - echo "Highlighter '$1' has no test data." >&2 - exit 1 + echo >&2 "Bail out! Highlighter '$1' has no test data." + exit 2 } # Load the main script. From 57624bb9f64b88c633c03df986f73a45512eb60b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Oct 2015 09:43:25 +0000 Subject: [PATCH 0154/1080] Add screenshot. preview-smaller.png is derived from preview.png by 50% downscaling. Prior art: https://github.com/zsh-readable/zsh-readable/commit/66c18e6b71d5ed1a95bea481e2d6982fd1a3e560 --- README.md | 2 ++ images/preview-smaller.png | Bin 0 -> 5982 bytes images/preview.png | Bin 0 -> 14650 bytes 3 files changed, 2 insertions(+) create mode 100644 images/preview-smaller.png create mode 100644 images/preview.png diff --git a/README.md b/README.md index 2845a34..d7fc4ad 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ highlighing of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors. +[![Screenshot](images/preview-smaller.png)](images/preview.png) + How to install -------------- diff --git a/images/preview-smaller.png b/images/preview-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..6fb84d18e545b56beef047eea45d7b03f9e50c05 GIT binary patch literal 5982 zcmeAS@N?(olHy`uVBq!ia0y~yV3^Ioz!1d2#K6FC=855Q1_lPs0*}aI1_o|n5N2eU zHAjMhfq}im)7O>#K9>Ziy4F8F6J{Irm7U|^um(KSBW>!ZqEM@@^IIrUrd!ZTjHTlT!0HETs_?E1A)SzQ`k zOI>#~7;WO=IrHBcYXfbeBI`J<-X^Z&uiutpDVYH|G>?0%&%T?(p%>Q z_bYy7E^kxZulQ~EJ!QT2fcPKZ`^WqX?%FM>@3XW@J2T_UmoJ%@mxYSy#P73FP z>&fNI{z?4L`Tb(1ak`rCES8cN7Zi1MbI;AO++F_u-@|tKSI>C;1eo*+1pRKDczsEx zJX&qvv8mfOX57)#KDu6<&35T^%gvh?nUq*e_b>RFa&&3BMjqpwdu7?j*xFxA(~X{2 z`z=z@B`xjQBG>K`tJu|HYhNw(%i%HK+@^4 zSW0arw;OwURGItJo`oXw{S*Q#ezF-HIKxy|2x{J8D?mzl>$hZHuSUcPqq+RKl7?wxFL{xZk!&F&t*#}}E8>`BT^jw(w(b#qpCTg{;b z{fxhK6At_~GcXHq*}Hddt3a=m=_+HF`z@&#_*8C3FDrWV@NLikdB@C7U0|%O_!OaA zYWC>l;xCnxm-j8ca^t`a2VI_(D_3q#KOd$ca^C*`p9cqsc{l9SVGVfggm*qjHa|_Sbh2DvrHf0;GU262M_!I4xw`JzW zgNjveZfxunR^OI?KW_PD#*G^{nypx}Rq<6`zH{I&< zu0l<2rK_yeiOKehLq7l5e#iJG+cCEGjQw?gxwyC(Cl%PMkga_O{&H(Vy*ktrOUD8s2VTel}|= zUu%B?cTV$Cf!Ol5@4o2>_dlriKfCn%{-eU}m7gS(&F(bl*0DMV<=b3-%qnLc5t_Do z;zq}8{jy))CwG-?QqEGhUIe3D-hR3695QLiGT+%+B3-ALwnpXF{S05!Cu{xg_V)Mv z_Wx#>W>0HwZmtYm?l)J>XGXx&pC>1)XK%gr=g*%-ix%m{?lR%2H8D00UVSxdYt&<3 zadB})m${Xm`A&TgLf8M5HP4$Pko4-x%D})t`@dfaqL}e|~;GHuKgZSMK`y|A~j&G^d{W<*>ytW}k1E=cKA{Z+6!I|JT&i zwEyqh{IDWROUv5tcgv?vXXlTyh(2}d)TYgwU*{goxV1&|!|V0?uc%;q#)=gyJeFVXl`uTyCFbw%A08gA=yHEw?cP0m_UzG__M6}ChXaRVi$UETv$Gci z7rRZJHjPU$C^&d^&Y7)&)AeF|)*DOk9FrH#_HESy<9G<3nd7b+B`1snyJsbPK zy}Yb$ZC!n5N1<)i7lU7MISc$B2zNAv83^w)_?)w!XT5WDK}-FCV_K`3_i%eIU|71f zX#4c(*MEL~{H|ia;HSD4Lg497?+}oXVB`a&*nS5zP7eip!U}n#$Dy_ z^;!x_OSiUtWLq?K%FLNRZzT8MH1O*`ls>Jz>gvA_SsfeqOy=44W6h*VlUf8mKRdho zZL1&0#g)O!Z+SgGH#b{&(Z!1woj8h@D%jia-?b%1`smT4SIz2|`OnYO(bCbGV^zB9 zYmeAxB}K)9XV2!|+?2X0XY0IM!rP+mSq8l2%_?AFjbWOewJC2SZ$-_om&@JzWM-P> zMmae(sd#Q@U&Xt3x9HL1$LHHr8rj&`Sb@N<;^*gP&YT$-7? z)eHx!+_*ogtE#5HxUkT0jW z<2xSSWi!pX;;}aDdf2Yo-`|wo`*h;>)%^YSHT1)7&d0r9(;psceSEC9yQ^zg)z?*V z>+f$)_phk&}r>WFxgqsk}JT( zmBIGEY3nq`n{M2P-72K+HRNu$yq1`l=x_UV%GU!|GERQ}{+*wn-{05Qw)|a8K|w)4 zz=WNpYD!9rvahdm>M%?`=HlYQ!p0UBSbeYd``rr{E=U@uaVS=O-6X(w`O>8p0n;w; zckkXgbD|Z_=sBrHz-{T(i~@_=Utj+G z{G2NpQXxJqL^x*lq17McdRQO$R&3Z6%Qx-dld4Zr9EwWH%B%0kZ_S!|t>@d@+u@NW z`S)zrsxDo+G&Hd9`}_O#KR-P+&At{gJ#tt1`?`mRSbN=qXD7{_IdkU3i60Lz^WTZs z$;BOC^YQ4Z({+D;aVq}#`#1k2hesXb!RMQeeypDCwRBVD`MdxX&q;wZ0zU0`T)K2A zTk}KxJC2dldOv;p&$Vd#+C64A85<|d23p?~+zO)ZDlVEgZ{Eq1C!b0AuaDciXYbzs zJ-&6k|LSJ1;b;3)spL@Yzs=TV^Q&j?rs@9tayjbf{i^P**^&F_mA+o#xpM2&Ybpkt zY!BRF|Ka|9m-CgQN1t9=>aFfK=ftT~Mp9ekYCas?TmAjnlP3|;XKM}CE7t56@>;yt z$7xbPSmeT6TOZH=f8=1}&(9yftT|>}HU}Vw`?y_xHKm-4z#3>Rn`^<$71q zs_M&&^Y;I1PEJzwo~|cro+mS5)~sJAl>2W4_*S3DXXwxpowFmvaLO*DO=s8MKiqCy ztR`)~=yKr)1^Id((c~N-p4H*Z5it zQn{%9of{i{X0-@-2)({u{KsOsf3(eliv?G8&YqUNtz8qVp{xGa$RWZw?pOI;#aWXk zZOXa1>GX7cY3H)jr%&e=@b6_y3}7-k(!`Z^pnqAAdIV3eBb%&F+uvo2z9(Ae7{$6B z{+uxHccNNLBeTQ;hGjFBp4Ds@G++{0(B3&AJv7-rF7f?(hW&AmUu(T{Rm`~B6<@b< z#~FjoJ^Mbg>FH%`^_krk*B{imGx@;D&ZFI#cO)X+mM4Eq`u2W*pjDMgVPS^Ji?2_f z7-R;ecJ78o}1u$d@`|M>8(Z*$cY|7TN zug5Q6(sHzWrfGN7oh#F7dA3H(Z(Qtd=*MYqAEM7M+waW?zjd$!wWTwL(~ zZn=tjvaia9AkV3n9gjV|9--oLHK>&-a-F)1{htqqS-Hi2{P=O?$dN6Xm(!k{n5e)1 z&n8~eP=0YM=EP~`Op2$!M6*BRstev6S;3XUu{Qqfu_qtaFL;#H)s=U)^chd$w7EPy zD%#vDeq`@^Syizhta!Tf-IQQsCifnRk7ta}TUc95KmPye^XJ?T4o_#bzC1R&)3tZO zryfuD7rA0Be>bPTc~`J`X1Q43;qJ84FB4vrn71!tekZyM@Rtd3j^vy}dUxUOjns*5(t3oSf+N%gc*jUAgPFMXBxKfkx)}_5XGnZuDe9sps=d`q+ zIif9jugz?kmF&a!A9i~h?czC^rgYWh_Msiw%N8iaRr5~m+GI3m&J5%B|9_URN--%+ zI(laF1?}3%JrZlDT?*Q>$HOmedE}+@>GPL{>lYOl7A@K_gHw3N?Zj@kNOKdDEkPoa zQg`~!Hk)_#Y=XJEcn06PtGcldIPWbh*rZjxT)m=^>x!xBjAGXOj4aIql@a@nUJTOO z=gh^Ea&=Xd4%5CBS)DGS8XvwKxh?H}e3siW*8KO<##`rYo&LWxNNaW83f|r~_e{LC zv>%@mMYO~>g$ZR8=)QaM?Afv)+3Q*QuS&}P{NpPAviHP^_3!qUzma`X$oW}i(X-Vo%k+FH^)F+2px!>N}x_Q$y&Bn&`U*G-L zbzhhr9kf$`V`444@Rx^uHgVmor+g2;{(db+GbDs9zCj>z4B>!L5J%8 zmN`vXZcH=He}DL>kkWZxcxIgL_XC^n-l*!bWRECsn)uox#$7UWi|UCY-nToIU3Qnf z-BtcRZm!?<;^*g9tk7U*Zx@fRDLga7@Y;vtKY#S_b99uHx=yN*kyYQ8X>4h5!Q$g> zD{K3!%Y65|=MBDaRF;3$>A$6cQD;ZpxA) z({!zO@4R{I`LlC>mPgr5x&B`DwN`L>K+LffycJd#Pj3ord{^^3`e=UhgVk$xF&;SG zc}J=4^0k#IB|knq43DoBeQ|&P|35!J+y8jb9J)H}>NJ*RTzdsXt{lEBtSFE)>7xFM zAYHrSV+t!uff&$CB6D|Nry(+S+LO+Ao2RZ)NkIJ$Itw z#qIp!604M-XTN-L-}k@nkNJIxyGcw25@)8nKNic_Q+MKgzT@+Albk+=RsGt%+;3rk zjl9sO7EOW17=W3fl7AnrnVNFYPNQS$#}}t8 zCLb@pTk*S&+cNuR0vr3s&#qCX591GWte6ZY>xRqf+j2DBdMqmL*G?_}*U>H9**P&U&*9^Rg-K6NSOlNi*8baT`NO=I=4yet!96>H(W(UX5ap#C;tRRRD^`CmAx)&fBfLxiLQz; z{^y$$O*Zm$8MJ+UC*y3*A5!Gnl6&-pY2xt=C!c8vy^~6nC32)L&NMt@$Xt=bk}doy zyqc4r|NZs#_qp}=BxLIzt6jHY&6!irZ(CVsU&&I*T&57kvi^p}^r-Ay8B%T`PXs zyPIB|nyRhtKkv=^_xsD=-&6IT77^dQIH*%aG+Or1tA`I71lUgNFW9q1L~+)N5Z@53 z7L6S*zb`c3>&?-qa`o!R3q9H*uU>xF7?I4=&+kdc}2)R>j^Wt8rwJHMClMR7B{{$jCDMUiE7zi{5s6fKRT zmxUDh-PcWL5Sga5U}b8iu*Me5D15x9@^jwYGbdcG zdwCm5{Hm;G=2lWlYinb&fAUoE^u%}X+ydISXDH6TaP`&K`>}gGA|q#Mu08SW-QA0? zzo(@$XIffX?Tu4C{lBl%@ROamNQi*^`hBwv!-aJ}`;>in)FT>r_x@kE8S1`gu56rf z?avJ63AJ;zUB8%f|LOk3`s1VCa<;V_UaP69#_lf5y}Zm`I z=l%NoU7d+Ztn}TU71`mZPOpFcb@Qdm_1b#>emy$+PEKw*JMS+`d;43Lg_{{$4_Pc_ zld&kM{O~}dynNz}4gm=skDx>5_a(I7Y)wDUzj5Pt)9kPmo)g;o?knHCe!KVUyCq&< z3!dy_aGF)9!yfr)=esYTlK)(bHhyP!{6N{6_s1tW$7rSaxX-ejnDpy@_Gi9NW$|67 zZ_M+wE>|l_{Q6P)(U({ySK;l;eul4?u`E(CGc&Wc-o0eWlRG<$cbC28;^dUHsn{@e zrpETaAKkUpmwSX?SK3>5^5*8h{4xgbicg=P`#E6sVq2R%rn6d?`?FhETW6cxkKg&} z^49F5PoHud8Sgcn^-WJtXwA-oh2Q7d?p(H{^rls;SJ<@qlY=Kro~&}@+M73yzrWW{ zp3UvU#gp^y(Wj&D_y4c>swMF7nc0>5|C16QZnEw;p{1An*YgxFi}})>#_{u?zg@pG zEi=7l5qGrT#PG8^+dk`@%R1I(Y%wGLQ)MMT>#{S|;@m&KnZM(IaFOHB-N?cg->(y< z9+R7zbyn*2Pg!?AWyNi+ znewmZiT3GDE~jTd`}%Ez&)a3&^JayA>}>O|;qKI!prpX@sc!Cl`F2UR8ItWEd3Z|q z$=lVWoqJPzZC-KO+`Zp#Wv@S~>^#rO&FxrNpjioXN=k~4;_4MWJ-*5$l8f_RupO{| z5cK+i|Ay6!x0IBVv#*3){P*{Fzl`Ojn>Q`3tg3#0d)uUNMdQM9fB9aw$unnGetP1W zIqL!Mx~+WI!lEQ++N=G_`||nudGRkl{{4P0Dw8^mdUwJ5 zw>i(YLtzriH(%E0-?04qPxaJ`#laW%)&Ayc3J3`?$-cJ6bFx}$YAR>bhi9|%Uy1+w zb~~Td(W3ZSPf+Gu&m8SY*WL#=rU?Fj&}z$5`@dW}@R)*?=-+p{-?KPYyx;r%$oAl6 zK7uTY*4EJr13KKRzQ5D`wyxjq*NUxC%Bxox+E{-&E+&(E)0T%Rp$ZPeG>`TI>{f_X0r+cg>raFi9Wi#*_U zejq!8%Xi7-t7RPPbXUu2o?$z2eudSdkc-RgHI__Vu_41lA!I|nVyf#3S&1Disb81o zw@&I{UGe6m_v0T?nJT9uME{lsnwxL;oo$wynkp(P>gw(e3W$o=YqzsFdieX77Z)4X zNp-H6?7Cexr)}*AzLE>CTBWKE7`?4j^S)xRRk_~sM0~$-g5oT*sqFKAHHG^v;$#Rg zU-((#*uVC0zeksSl@{`a9zOl=v)0?y@9NTct*vciBkjIS%{so@F1~V4>5L;nscW3K zy65EOy=&nVp5nDMYOS88CZmn5?a`$dUAx7eK6_^7Bi(B#@n(U@G>67-36gW#Hh)mE z;rc((V_Lq%w{r|{=P&rnvF`2DGiqF$8BTS-w41mtx$wgZojY|bnT0|ey4s7@c>H#| zZG3;XtLw|ZujBs7{b&5~ZRzpTOJr34GBxa$-@A-K<&VQF!%o#x5$w!%yF^7r7u7L+ zes;FFxY*mn$uDue%d%k6m7H8biybY7_b(mkZS4N}?)(&SVMF;+VXk)t zZ=AI~rflR|cIO2%6Vo!EnM`M98oO_oNOr!{#8A*O{o(w8n7_e{ejZwS=2Jh%7yrwi zwd3LS{sj-WykicSakR5kMPBLpEaB3v%nqIh|DJjoIN{(#QJ%QI-SV}|ip@FazhiI@ z3&=UvaDu7RDD1$L%7mMnQp?K9-1}s1?krBTZ>yGmyxrTG~i_V)gWLNLpcfU(0b;+?6U2Sb`eX`bK zGc1dj?YMvR^y%yq6BPgb`)4)%0Gk@?G$$#Bbp{g84zX28HmPi0CFSJ!|Nr6T(kqW! zY+~A~JaIM88bdGdrH8KU^|#*C)a1jkRQBjj)9}bOih*uHJgZlnyPN;|+S-j9H-7u} zEif?f<;$1V-`;q7dEMHYJ$?K3^1s_Ib98>NTGQOEkT<)yZQ%xAHwH-k%E#9?83v5wFO3IT3j?G@) z-p|j?Ufp6kzU*08=FM)s^Gq>+XTD}Xxy$Q~R72X^mzF2Bgi_Zy z_=?W8DqXdHeST3`t+&&pAXF@pJu<_d-Z1L-33$ceT>-=zIRc^+FUm8 zhfH%COf(q%Uoh@VM^{VrYoS%juU>q%(z9c5zqj_5xq3)Jg5cuq3GYue9IY|GHih3gR`paw zdzO|}`Ma22x8i4KX0G4=FRI+Y)U@>5o159!)(9pu@yS?RxO}rg)RzUW z{ihzM9*y}Cb$+85!+!S{KU5roOs=nLKXGFB*@xv4dt|0R`%*o*_H&P2;VYHEV_7Ty z+$#0jS;m@ich}crz0!>zA0Ln3UFN(0!pFzQ{pVVVN=R5F9B8<5o`%yZwHbdCC2KwU3YWN?Q~>@Ydg3^5a9| z#|NjTYWH5P{r~rSseN0!T-Av!3mzVB@4xivR`z;RJ<-xa!+96?98`T3vL*liz9t0` zQPH!rOtUX7@r;a&Y*Of$$z9rE{`<^K<84CEe=!!ew{BoeGcECEFu1rd^308m$*#FS zA2joSX?Nvnb*fSN{_5)Kh`al0e~XEWcbDI}cduv1yeO-(H#amwuH3$DZDsZA+uPgs z>;Lb4>vd)2i}L%m>Ksio)R|@&rFJQB+`M^n*Y8`q%kw|(vj6pBanSZXjT{%!xazhw zN~lYR9hWc!x= zy{@j+UtTC~3+D03o-MT6>hOdK0t#wsZZ*{}E+{%IzWC$k&xO;Urhb2SxBB}#(}HEk zI`Y!zxEv)$W^ZELiotx6mO6BLjzjP_c@XY>}6<4#u!^0oEy1M$(yr172 zf81Us7kY)MGqhW8x_&$#KmYqHD=+)o|7BreWo2wqICA{>>rH!dZf)_Lbz{!5zy@ZK ztA+_{x!#;zk;=czMD^?z{jSyQ+w_^W)mfy?a&B~qYP(4LxVj#Fc6PS7Zd8c!heyqe zjSq{7i_g|u>AW=PYMiyEp5DIl_wx>ZnzT4XYwp~+pFe#%GG*qZ$1h&2*sZf~Uy@HU z7Z;a}t!-&)R(<^4R83vovnLH@wqLw^_wKoKegZ79-@hpct-f&9HNO6DsiVN8$&+ty z$$b3mnV77sF2|vFcXu~-3afK91q1|KSQV;$IDKMEm;qzhVe<{5W{15hq`sx>u&k|(sy@mdTlb1>eX1< zcJn;T+UV`;_LhCRnLhuj=Q`HnKz{!IpP!%4w=7<^W{r%EYOdU~CuVKf^QTYG&M-WD@?_@6M@J8=3SIqfcU`Wc)(>NwINSX7vRfL>44BL^ zCeMBOn5({BDx2|}0E?r6$i3z%QCp?XiQHWoygc>vG~2HsPmMo5pI<-EJpbOx;N>df zTS{MFb8Kc~+;#tZ6DxPxxj8GfC(NFGd)wN|pBG=XDmu62+}z|kXL)Ey$dji}ckbT( z{q^R(kLl;uuyB(8bu^X2|ToS-j=$bvFs-g#rwT29nzjg#8fvb!F9$ z9p4sb3h?C~ce|vv*)K1+me7l+!ABo>s`uf`Z+HW&&*mE=$ zytuIN!-s;-)E678zvo>(|7Lgjd#Tl{!&d*@`r=G~*jrb2UMZEhnLmE~SU#`n)WL&} zD?`d&UD4Fi^0GO(G5L7b?8UmrPM$m&eEQed*RFz&j*j!HI)s1R+VktxYPS8?zr4JB z^zp=r6SrpDcDNXbyoy>G@=ENWjje5QQ4x#d44cZL*mcga6=AE@^ChJ&Z)^75urw^6 zQ{zFtK+20bceg&5NebHH=eqV8`^_zxm#1oncR4FK3i!>lvCO$)kj;7d(z@8)d3Se} zzP_ewV-qt)T2%C^Z~wa3-Ls12{Qdp2SFc#TI=iZBmjVYTC+DJrLGwK)t93q~X;GLo zS1LhG+AK%leEzdl>zx+f*qS|Efg?3FmEZo)h6)1>jTH+PI0&@(&NlPZ6MQG$`|mKn zy@-6iklnFW7ej78u1%`>Cc(%2x+02oP2<{xD&It{oYwWe(<%+Vy}PS@ZxXk-p3UDc zm&2x{aBx3c^y^A<*SUGN(K?#zeqME088XkR)Jve{#*G_RrU!iX{d%SCC~#)`QbyhA zZ6bTCgoK3V%$+;c>*+%0b{5ASrLV(sjc2O}`JO$)#Kd&u&z<6DXIAcArN%3$@ao_5 zgf%za6Y6FCwHtPvdXTwk#*csv%RYvgOZ#|vS(U$=BdTiZcdSQ}d5(4Yxd%sAu2}Ko zef@v#FK=#cE|dTLphHix)F|x!p2}dEKsHv^z5oCHUcdL-EQ|D+HkCzX-~LYKh*Y?E zg(Dxi1GM~S`Woq7?#nyl*Qaj#F7%*ovsa+&+L@2D|NQv4I&7_!ZPk|!LFG0+*uY~kJDkl3Ibz0Kz5 zlga08zu#HnIoZq0t0DLHwwW(4s4qqCFez{}OrIXUJ@0Pa->=uD&GR^d)<$-6x*E$Z z&@OIWcY$$_BXd?j^W3ti?1c4wa*s+5%-Wmb<#lR?VKN)P+@7?vv;5{-otzP$YW{5+`1a;#T+xz9|a+*@0e-TNY9 zxA88%ylcslC2Q9Fwn)78fqeo?VB)9G@25xa6^o3FwEy?xas2;Z;SUbAazA_Bq$L0xgT(`@J?V(~&CO*SJeh*7Bgy zTH7*4p2l|q3}+9r*CaHRi5_Q>KNJ>`So!(2*Xe1x`~UsQzWeC-G~H+y@eJ+6$Ili$ zc#yDhhUj%}pQ4wSR4<;1yWUm%`7Zy4gJ08-Crk;oP}%^XvcZ3|i^q?Y+C;A=8GUr(VXfM|37+IJh3~ zl@=EgnlyRx=8~5|3-a&p)0+C~&CSi~esdV|?(Na6s%~#>ovD9Jqwtn^>80{&f$xWp z9&%Jpoh50xu0JElXxoisQ$9JH8;jlhC5_XbJb7YaWu+IfLBY=M-_Pgs*S{|_F)4p{ zN3i~pzunK2<~I&{Iyx@aKTPJA->XzNFc6qwl6mR#dHeXFphpiLY^ePFOwIS*fA38W zNoQX_dhkHuT}t%6nw=KE_>ud0@}G}NJQe8pJ?GHD8_6fOP7|xlWIuMjH>9vpF3m&# z%Dl5J(i=)Ow6%Y~Sln+_^5Vl$@pz7=3%g2RpPg;q&COGe@Sx%+j(d zeH9WPfB(sol-Q6JOO~jt(q1xsx_H6QPpQVKGnC}_UEDX1ci~npmV-t!;%Ya|Vtjhb zKl?F{G0)C_SKaRLFKMuUd9yCmfG5s$^-um2Z*Olu-YeQJpUCQc3K6KsFn_T`NvZKZD!?te^ z(lWyLUc0|VzW37QxWdP$qxNo|X(rD4dTI}ldrD|TDi<;rqa({^I4xM znVWC#i#l}Z(2-ZSx94A%HTm&l`}XbcR~-NF@bJ;D?Ca~U+ONB^K;`?YG(BBu-7Y)KRL|9Pr!b=r6CA7?fmi3O`G9vo4=-`;DtxB9!E zkB>>j(mi`@w6sob`Tz35Lg&(__5XgR8}DCvV)^{KsOStw$Ah1qp3dH}?e#qC+uQTk z*Uo!BuiEd=m)ZII3?-~CGj&dV5dvyRSz21Uy1G8HTPD>bVVLy)-(N{dNkce&NDuKm0BdU|f$xN)>we0#>lMQ(=W<=?ZfuM-s&y}PS)b>-)0Z2n)5ipO`vf1a5>ud<*s zbVk|Y=@TbrM%0OKG)qmX+kb*nxh|aJTIYA=;PWrer#+1eaXYqbV)e!QqRVnSjd}%l zicg)mF*8M!MDo4TYhxBSrVsCTwO_3_kjp!JdG3wbC;o5g^xivX#+}(~n6AxTa%PUj zK0CV~zm+*6CTu!*fBuI8CZ-D+Cr&GCb{=luI5XvlP|TdFh0D6Wy}w`oQabO~GV3W*oNHIH!yM9**REK^cg^?F2X;rscfJfEUN*AY^{wx2 zy_jI9_iV1~ncm32MlaXOos~_ZJ~Nvn6h0kd{q|m6yZhN$NrQ$y+0G6H^XdBg*W8{y zQ7RK;<Q(P~Q@ON8d%m;W<3CIt7iGds9BK0TQNk`L)!`^?t=; zUIi_!tf!}@Hh3+K+FkZ`j%D$^+V8Q2J8thT&o_K@cunNyHIw?6Xm$vG$VuzDc;lr0 z!NZNw-!(4uX%}x1Jg|P|iAPr#G6ydYQob^Eu59eC3ro43+l541JHPNg`e9~2|LpA5 znwu3qysuvzG;v18$>|fNxb^+^2B%&W6}CBsG!13AxKZ!)>34T`e}8v3d+N3qZsOlh zzEeyV<6@0F$FP4%m~75Fo(a?3z4|6*ot^dZ+3bqy$&(JX%Wuk+KCpiOrYzC@f0!<; z6z&#FR9aK)z~B%wr?GLP!iLh-sqyYnI(sa59jA76{gf`PbSaI@J93~4dCuxuR=3`- znO}aE{_8L)U)IU>V8*@m7vh-(W@p(bKZ*a>wAuLN$vr>Sj`t}(`=F)!bb5Tm)~>6o zHFclfvFuUZ7`n2cgyn)-^9Em-H49f;m%dWj$IHdV#Nyb|-+w)|^5&Mz$uoLfjNTj! z{k^<JH%;YNA6Ti*rfM<17H+O`>6@{{EvD4~Kuq){HOP6c+XUK4TXn3{% zbe4ul$xEgU>HUd|vwe8}|6u?BYkJ_yUH7gg&0g!&xL8^2jqiGIS8qK(=0H>NyBm|; zD=L0$$-KNR|NgwWbN3cJbV@is&-UlfpTg>XJbZk5Iyx~M5*m+uQeIegVqQEu`XMwU#)6Pk155o@mvv$$cqqDqWs==~{bj`)cWriwlCxKvu|}EW z&E3;00$ErLiq+=VB&{=0SI=?@+P?jGoWA+yQx!}%F9f8WTl0pY{N0mBu0_S1JWoCz z|M+=vvb&gW(z_V0?7JS_+EHbNQXN_AxOeW{DXiubpfxpX>#ikBSU!CDB2vt&6Sc*| z=aq`#(KeyRG>LF;**F8ykOKCw1H5lPKJn!~#=s!)473(Nq@!_qBEyy@@dF-4(%uq_ zubwyl&>1H_m*x0_^dI&GCjSB?*pF@yS(njK@Jr;H*`-K2FZ#Wv?k&$Yh1&vxO$ zHL=|@A1^y^w|a|^rPZfzw;6VqZHzyE_u`Em*H3q^3=UkmqqtpEd&k1P6E!uD9Qp9+ zG>?SC>aaZ@m`pbbMaFF0n3%92GB8l_mAXOxJsWfL?JX@WywYY7dvzZfZ$HEHm&L7l z#^S=o^Xj^$99TYq<$%M7Nh>OSx31eZbHk|%0#<_mIOiXVR8C*f&|39Na}%@6;VzfR zHF8rf1x?d;j|nd>Q85rWaDDo5`QvBLW~{xveP`X=*VjF-^~rADtlfXbBCh%3V!_F| zd3Pd~rYWha*8I}+^kiUWfAmz<_vo>+Lpf zoVs`ZYVF6zKfhe=Gt=qvvPqmpB}?k-8-7&yN$#5X^y!;BoC|_3?%vKKDy_IIq~s=i z)=;x9I$L?w3d?&t58jILncg!ax6$IQdzz|+d9%Pf&qHckDRT|K+oOWXwjvq!3qUXXoR6 zvfO9pSO%9ceEIZA$|$8{|Ni}3A8B?o#}-!w#-^>BeeASI#@;DQs$O*OjXB1AWBxly zOFh1Tp4-7vLKjz5f7Po0Eq%Y%z0z{sx;_7@d>>CpeG$}i*Q8FFo9o0Wrd40>iG}C1 zNQ4E>-F^Ss+UVruw2FrH(Y1jC~j)jcE$a<){OL3 zB8!Z-gjiZ1UHQH_=io-u;<~vf&ON)GU->exNrIQCaz(8R2g+Et32HP$kB-t7%psF%#yBs;hu;5WAmVe z2QCY*%3gd_R9cbkiqG?R-#;FgS65TpmU}zQM2c6+B;(8s!-WeM{`~nfF)?wmTkoVD zx@A@WeHR!1&&k}=F@20jx4!0SIX|_qFgsdDd(+k4o2*HV)2%HrM&Mp*Y$DB?!<_4{rTHC>$S|Z!iP>z zW44#)%kkJv|v~e0mIZ zoJ|f_gqFWB4ht#~DQ#Eh70qBe<dSe0BYj=xIC$8EkuB|51F)V0~xD)Eig#xc8iW z^!oIdmp=1yuDEZH-+#*Y-g19$g>@S?TzY){?p$@=yC>9qE8bZ)JWA@5pS}QWz297` ztJklaTUuIz1_&ojnc`B~`sLFnr`^VGUPolvxPDB&rxC(>_`%hv*6o?1X(BdZwO3xT z)L(x$`{%}K{Rb`ImXt)S&416QFO?r>SF^a*Hu`ni5`O`m=9j&do2+Uq%F0|^Hk4?_ z?hbqHH+N3OE6rs-j26{mD-S)&xgBP?QO30ExZG;ZkMHZ3M;bTC*ROe*n_YPHn42m4 zfn~n4yS^=~{QT^tlbEbU!GaANHdKFq7rVR6w*KFq-MfEpNIZP%^y&H^57|3!7jdvL z8Swmhpj6?wq0Ifnv{$F5F|JM&Tan20rO9Fk@4pN2uLDa2w_Tr9#9r5;zChNey>|jL z*9)fgP1-3Ecc1`4pt3ERv*2f(=TKL=S-@h;K<6laY zd{nv(t~kuhR;_$-XJ@gg)Y+NF>H9!~HV3aN6kmadKYFLHcu zYwMePXRoa-y}_8wmws+T3TN>0M=v8Kt6k?iw@2*1x51@b+e~X!UFX{9?f+iK|Bs4^ zu_=CbMrvUvXc5ofUti7dRV06TagmdgQ-9x&N7KW)9&BT*Ydv^@OY4EzoL1Xo+Z$rq zG7T7hIcOKO>@JX8bnwW!)}W52#Re=j2bql$_}?_jaI^;nG#d>+}t#<^ILLOyc5LSOnzG9p*27E%y3)@z+%s6S#kM z>|0cNOTX%;(dA`^2@JKrF02ym>$|h}^wZNW?&0e`dcb zwaAtCZlAqg(IF1W$tmf=^7$q6yL@aFzArK|+SYTY`xF^-o^0kNCp=C%OZn>a^M5Q& z^E}CS^7Eq;f7VS5z4FTD+2hZC*H;C6K3n$gjMmD%oBiC58EophroI2!Q`3$*t5ub2 z&C9f|$*EtTW3VEsCg#I+1&$-v_P+mqUErO21G^OaCohjv&kBsfbM;ww9~EC-w_@d@ zzrVlBTNW+Zym|AE#^@DWckc6_Zzt8OW^DX%$oOw?Ch~E9dC@XNQlxQ%Sq(>-sjdr@lk+>i6B{U!H7K z;JcUbSJNvubMaQNmCF`^R`3OPGEG+Vy|pp<_>GOp-CycL8yg$j`Q^h_UwwSMe|n5- zw3S7SoSDz}vQQ_doM~@ui{yKXRzB*yB3Pb##zbCx^3$w^K@1@rD@3NuzFx-a^U`&O z{(;t#Z}IA@CpZ8ed3$BYJQ(kUG5XXF5aMP4qCGo*PcmxGCTC1t3MGupWIfIq0&_dU4yix|xTvW-mO$)o)fT z@OAByIhQlPYu-H5Y5x1+TOThz`G1GDbu;Ww+xSXi{}QH>Pbn7}W=U)}W~*R0vNSO6 z^=_^WUl%RCe=uuCeW6s#D($rwGZkS=v00N8ZjxNy$l|<>uyeZ;iSQ z+rLNH+kY&r-kTE5c<$W%uWwey7rp!W`DN9{wP{=O<=33`*!_6>{klD+tB=k6%AMow z``7a9ho|35i>mgxb~B`>yHC~Hx*#FG>etIRImK00tR;oz@-N=ry>;=T<5Dk8jU5vv zZ#K8xdu54G*WMLOzbdP~<=xuSyZQ6lLx*Z#zC6Cx=5^js=incPhsq8`s&2KJnm=-!&2MHLkl%l+oo z{d%dcprOGbz@lhp7dQQB>g8p=mySK-xtI~h#j&DxPxtO>@$XrVFT-PYE?U26;@R2m zS&Q@I&!1nvcF`}^b$51$N4qk|#)P%C^kiLKb?oDg-R1H2)n)ZnyEd9>CxomH^WI(Z zGDbW5>)S<(LOD6*Ra7LTFHGY+^g&EFto*gui=eY6AB&@I%}-8#ACaE3KIp<$%L5yK z`!b1MI4YgszX;TUHS+p#bVq6U_1)8=tYQK*3IYN{!k*g{O$#;o|HwonRBKoA@xBiq zK4e~AmV1Ant+jRa!$YkH=Gj(%`uthlZ;phFOiVX@_n0i( zJy*2!ih;Z7VWyXlyXQ-5sV;pQb1vn7Y2UIt$E{KeT?Ieu`#A?LU6g%&oveLbjfaOv zP*6~1<<6+J=T4uVZJ69PdGh2PLYuR$uDZXZEH2o49^*wGw(9ElHBSVWeq7$nbg%x! z!ZVX5onIe+-F{t&#=e)Ak1yzZ`MG2HbN+rCqaP0rHboUqi@oCZyg)W4R-B!Ef8Dn? zfA>4c?woqO?eYz6&3*T?QsOi#Rd?LDe7=AFI;j~xQps)+soz)cp1aukb4#4w`$Iu- zzfWd-U3c%#--oM?@*nVX^(c0lC494wzi(3Vk;Mldby=O+Z^7$&Re#x%B`P*HHD6y{ z^|$-EWb)+84-dDi`_HR+dTQ$SdsVALSBFVTN-o;z5oPD)5mEnk){m;(@9)n4`qi~Q z{Qs}lmtI*WFDXj?kaOwD?F|NV>z+-Urnjf!V?f$6uZ0y?ZdW@#KgV}#U1@B;T=k_( zc`tRj&vS5Hx_XJPq!v1!xUcklG&<9W04>(RG2w`7KwmnXm8r79}=T1dEl zPwDBy=icp|AW)y%cT4=%mYJ3BVp^|+-QVr{=lmXqpG^nuW%s=DXka(~{ploUv8%<( z!nNB{+V*l)?_C#>TC+vuR@2P>1wjE(=gw8=Et?$ew1B;T`|@?wFpZ2I&mUv6#J58TaAt)%^W|MtA2d~!NjD;IlxO*`Iq`H|LSv8o%l z|HnUH)sta=cbBP|nOS&tto6L9Uyt@m&#wAfwa{1k!PCj=y)V<_B5$6UA#pe6`=`Ct z&)fM#8;*7XT~oBE!J|bh{6`>TU%^3EsreuP{hyn#LwRK6l>zMo0~0{F74KfTVv>S?fLnQ8-HzE z!EI?7{_gJOy>Az!U&|BlIvrUzWAAkanX4>jtRG6BfBd#X^8D!v>;Bi}JL{&WtX-8N z9wxW4a1YyJ>&GeV8$S9>oz*#I%IBAwlio4$@EkbpIjgIeFF5#MLj!}M{r5SR#a`ZP z=M^oP)fIIxi^=BFnwh&}L!~~{O9d^dR|)H_u91-`X?uD+I^-$ay-9OwPEXjLTUA)N z{r}(mk4wFeNfm6~@S%OS>02Sms>iJ1k0)QPTD)M&*X1+heRHx>-#^bf|D*j!2}^L* zkI_y6E&Y-OZafTNgb!ac-{l>xG(M z7cBa9TBY2}i|1VaWNt36FW1a&TZG!R+Vqykf*?FkzuYI+=|?SJD$(4} z)10mKYqf&z*DG7u)>Snp-gQb{7k6Cl!JC-P=ibkK2b)UM*c+(aB}&v9ItAdZp_7H}1;Ey2pE!_HJCU zcj2@hHzju%|FT`4K3Pr5Id#s}S7KGSW-ohd5PY=eDg(>)Pujnl1*W?ll5OY<>M7;k z@|j0?_W_XyFIgrmH`m;_BPsdFf&OSBI_KLoe;FV6?RWBv`s#bWS$(^%aJlmGTTg73 zl>C)ndV0ez9+Bb=%mFchgupkP;78JTH1kxV-A`(p0A5fTt!c(ME6(j`k6?4s05SMFG8&Q+_a@ZjMxU)j)A z1^(yre|`C>X;ZUi{``HmWgur>dylY_+K*4*N~dg%JZCJ3;_AP4D2VSqLqYk2 zlYDGkCV?Mg!W$kH^)2@b*k~B^S`sa_tcj_|SH(_3N3ty9>+Tmt9_U`PRF;yR%IUXU=q7w{G(7t;UA8 z?o|K&c5I2t-EXtLty`xqS8K9+$&0ht1-! z-nsMdjrH;Y0dec@FV+(6S}#{;@nHY|t(VS;zBaVsuoe~k_oMp5(MY`zTeiYY%0?5? zn;FmDd$z>I@A+-LOS?t=%6eY8cvX-Ue{FBL#OYdo>_4F`>{XewEJwSWrh2A*bPVdKMcK@V){eJkA zr@*lJ?bbPtI_qw{SYdWyu66l3x5bvl&(2(ruU~6DW7aII>Tfx%PJ*(sd-Lw@x^W}I z-~YU*c9_TRLXi{t+R~!J#n&fD2bX!C?AfuSgPHvc|Gb^mk^ z{JmVawwBw`BRaclb{@I#?KPKUMD^EK7o6LKLyF-UO8%6he@^0VEq7s}aNo^3yLs6KYTUPJrdTH&Qeo0mLsDf@Oje7&DV zx3{&IG+SGx*TtUJ(JR}!xj10ur&FiSJ$+I$X~vIBCnx8Xl`WK$d)gGB$8q+}Tl;ID z_poXySlRwv{p87<+d37Tzn?m_&(rhg&u?%4 zY%*e>>a{dLBs?VM?CIa%^Y@>%D$hH))Z28PRN~oLU%!76ik=h`uwmu2>kl{A)#c8a zdz5MSrAvNhB>^*{D_ztJA6QK{4%Ezedu(m>8mnW^(^too^(3x;^zmB=M~sL1zrK}| zex-`&vw%X%kgDDCd};j{R6NXo0mw)^3V$)}Gj6S{puTvy7vNMB1i`SJ-Z!sH+O1ws#3 V=WLr>#=yY9;OXk;vd$@?2>^ Date: Mon, 26 Oct 2015 14:18:54 +0000 Subject: [PATCH 0155/1080] 'make test': Allow specifying the zsh binary to use. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d77c229..d58f8cb 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ NAME=zsh-syntax-highlighting INSTALL?=install -c PREFIX?=/usr/local SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) +ZSH?=zsh # zsh binary to run tests with # Have the default target do nothing. all: @@ -22,7 +23,7 @@ test: for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ echo "Running test $${test##*/}"; \ - zsh -f tests/test-highlighting.zsh "$${test##*/}"; \ + $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ done; \ From 4d3da30f8b726c6e0eeb3adda06adc9eaa329b3b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 14:24:45 +0000 Subject: [PATCH 0156/1080] 'make test': Colorize output. Color is only added when "make test"'s stdout is a tty. --- Makefile | 2 +- tests/tap-colorizer.zsh | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/tap-colorizer.zsh diff --git a/Makefile b/Makefile index d58f8cb..8a14bd2 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ test: $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ - done; \ + done | $(ZSH) -f tests/tap-colorizer.zsh; \ exit $$result .PHONY: all install test diff --git a/tests/tap-colorizer.zsh b/tests/tap-colorizer.zsh new file mode 100644 index 0000000..cb645c6 --- /dev/null +++ b/tests/tap-colorizer.zsh @@ -0,0 +1,67 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# This is a stdin-to-stdout filter that takes TAP output (such as 'make test') +# on stdin and passes it, colorized, to stdout. + +emulate -LR zsh + +if [[ ! -t 1 ]] ; then + exec cat +fi + +while read -r line; +do + case $line in + # comment (filename header) or plan + (#* | <->..<->) + print -nP %F{blue} + ;; + # XPASS + (ok*# TODO*) + print -nP %F{red} + ;; + # XFAIL + (not ok*# TODO*) + print -nP %F{yellow} + ;; + # FAIL + (not ok*) + print -nP %F{red} + ;; + # PASS + (ok*) + print -nP %F{green} + ;; + esac + print -nr - "$line" + print -nP %f + echo "" # newline +done From 98aee7f8b9a34c639352034087ac31193256b898 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 06:30:14 +0000 Subject: [PATCH 0157/1080] Remove path_approx. Fixes zsh-users/zsh-syntax-highlighting#187. Adds a test for zsh-users/zsh-syntax-highlighting#204. --- highlighters/main/README.md | 1 - highlighters/main/main-highlighter.zsh | 4 ---- highlighters/main/test-data/empty-command.zsh | 3 +-- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 3a65af3..c903b26 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -34,7 +34,6 @@ This highlighter defines the following styles: * `hashed-command` - hashed commands * `path` - paths * `path_prefix` - path prefixes -* `path_approx` - approximated paths * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `single-hyphen-option` - single hyphen options (-o) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0dbbc21..59fdd84 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -42,7 +42,6 @@ : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} -: ${ZSH_HIGHLIGHT_STYLES[path_approx]:=fg=yellow,underline} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} @@ -285,9 +284,6 @@ _zsh_highlight_main_highlighter_check_path() local -a tmp tmp=( ${expanded_path}*(N) ) (( $#tmp > 0 )) && style_override=path_prefix && return 0 - # or maybe an approximate path? - tmp=( (#a1)${expanded_path}*(N) ) - (( $#tmp > 0 )) && style_override=path_approx && return 0 fi # It's not a path. diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index 26265a7..9e4b13f 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -27,8 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -# without the trailing space, it's highlighted as path_approx (issue #187, issue #204) -BUFFER='echo; ; ' +BUFFER='echo; ;' expected_region_highlight=( "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; From 7d45f3e3ecbc49c8d1a8fc18c72fe37d8c71ef36 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 07:00:39 +0200 Subject: [PATCH 0158/1080] changelog: Update through HEAD (98aee7f8b9a3). --- changelog.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6d5a5c8..9f64503 100644 --- a/changelog.md +++ b/changelog.md @@ -1,12 +1,24 @@ -up to c4a9fe93792b11d26f20028cba6f97b0ede8beb7 +up to 98aee7f8b9a34c639352034087ac31193256b898 + + + # Changes in version 0.3.1 +## Removed features: + +- Removed highlighting of approximate paths (`path_approx`). + (#187, 98aee7f8b9a3) + + ## Other changes: - Fix initialization when sourcing `zsh-syntax-highlighting.zsh` via a symlink (083c47b00707) +- docs: Add screenshot. + (57624bb9f64b) + ## Developer-visible changes: @@ -16,6 +28,13 @@ up to c4a9fe93792b11d26f20028cba6f97b0ede8beb7 - Fix test failure with nonexisting $HOME (#216, b2ac98b98150) +- Document `make install` + (a18a7427fd2c) + +- tests: Allow specifying the zsh binary to use. + (557bb7e0c6a0) + + # Changes in version 0.3.0 From 871af6808284b09d4df0dbda1befd579829bade7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 05:09:13 +0000 Subject: [PATCH 0159/1080] sudo: Extend test to cover all codepaths. --- highlighters/main/test-data/sudo-command.zsh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 6e84179..437d5eb 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -28,12 +28,18 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight -BUFFER='sudo -u otheruser ls /' +# Tests three codepaths: +# * -i (no argument) +# * -C3 (pasted argument) +# * -u otheruser (non-pasted argument) +BUFFER='sudo -C3 -u otheruser -i ls /' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "9 17 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "19 20 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "22 22 $ZSH_HIGHLIGHT_STYLES[path]" # / + "6 8 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -C3 + "10 11 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "13 21 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "23 24 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i + "26 27 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "29 29 $ZSH_HIGHLIGHT_STYLES[path]" # / ) From 9816fcf05586bcd24f2299649acc1fc46c72581e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 05:09:13 +0000 Subject: [PATCH 0160/1080] redirections: Test an infix redirection. --- highlighters/main/test-data/prefix-redirection.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index c029509..0eddf0f 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -27,12 +27,13 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='>/tmp >/tmp sudo echo foo' +BUFFER='>/tmp >/tmp sudo echo >/tmp foo' expected_region_highlight=( "2 5 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "8 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "13 16 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo "18 21 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "23 25 $ZSH_HIGHLIGHT_STYLES[default]" # foo + "24 27 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "29 31 $ZSH_HIGHLIGHT_STYLES[default]" # foo ) From 4513eaea71d7fde16a91be86a134d50411cbfa86 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 09:46:51 +0200 Subject: [PATCH 0161/1080] 'make perf': New target. --- Makefile | 11 +++++++++++ tests/README.md | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/Makefile b/Makefile index 8a14bd2..cc4e57b 100644 --- a/Makefile +++ b/Makefile @@ -29,4 +29,15 @@ test: done | $(ZSH) -f tests/tap-colorizer.zsh; \ exit $$result +perf: + @result=0; \ + for test in highlighters/*; do \ + if [ -d $$test/test-data ]; then \ + echo "Running test $${test##*/}"; \ + $(ZSH) -f tests/test-perfs.zsh "$${test##*/}"; \ + : $$(( result |= $$? )); \ + fi \ + done; \ + exit $$result + .PHONY: all install test diff --git a/tests/README.md b/tests/README.md index 15aacd8..e82a64b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -32,3 +32,7 @@ performance test [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: zsh test-perfs.zsh + +All tests may be run with + + make perf From 6fe07c096109d5f3832e83ad0b6ec8241fd2e967 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 11:55:36 +0200 Subject: [PATCH 0162/1080] 'make test': Fix breakage introduced by 4d3da30f8b726c6e0eeb3adda06adc9eaa329b3b: test failure would not be reflected by the exit code of 'make'. Setting a shell parameter in the left-hand side of a pipe is not visible to commands after the pipe, because the left-hand side forks. (That's true both in 'sh' used by 'make' and in 'zsh' that runs tests/test-highlighting.zsh, at least on my system.) Therefore, move the colorizing hook to where it doesn't interfere with setting the $something_failed (in tests/test-highlighting.zsh) and $result (in Makefile) parameters. --- Makefile | 2 +- tests/tap-colorizer.zsh | 0 tests/test-highlighting.zsh | 5 +++-- 3 files changed, 4 insertions(+), 3 deletions(-) mode change 100644 => 100755 tests/tap-colorizer.zsh diff --git a/Makefile b/Makefile index cc4e57b..e4fa163 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ test: $(ZSH) -f tests/test-highlighting.zsh "$${test##*/}"; \ : $$(( result |= $$? )); \ fi \ - done | $(ZSH) -f tests/tap-colorizer.zsh; \ + done; \ exit $$result perf: diff --git a/tests/tap-colorizer.zsh b/tests/tap-colorizer.zsh old mode 100644 new mode 100755 diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a67229a..1eed974 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -59,6 +59,8 @@ run_test() { local -a highlight_zone local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use + echo "# ${1:t:r}" + # Load the data and prepare checking it. PREBUFFER= BUFFER= ; . "$1" @@ -109,8 +111,7 @@ run_test() { # Process each test data file in test data directory. integer something_failed=0 for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do - echo "# ${data_file:t:r}" - (run_test "$data_file") | tee >(cat) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) + (run_test "$data_file") | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 done From fb5ce437998dd6dbf7b603012c239b5f2e43fc0b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 11:25:09 +0200 Subject: [PATCH 0163/1080] noop: Rename a local variable for clarity. --- highlighters/main/main-highlighter.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 59fdd84..42d19cc 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -102,11 +102,11 @@ _zsh_highlight_main_highlighter() ) for arg in ${(z)buf}; do - # substr_color is set to 1 to disable adding an entry to region_highlight + # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, # which add the entry early so escape sequences within the string override # the string's color. - integer substr_color=0 + integer already_added=0 local style_override="" if $new_expression && [[ $arg = 'noglob' ]]; then highlight_glob=false @@ -195,7 +195,7 @@ _zsh_highlight_main_highlighter() # is how [[ ... ]] is highlighted, too. style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style - substr_color=1 + already_added=1 else if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] @@ -218,12 +218,12 @@ _zsh_highlight_main_highlighter() '"'*) style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_string - substr_color=1 + already_added=1 ;; \$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_dollar_string - substr_color=1 + already_added=1 ;; '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; [*?]*|*[^\\][*?]*) @@ -247,7 +247,7 @@ _zsh_highlight_main_highlighter() fi # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] - [[ $substr_color = 0 ]] && _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos From ed6d229b1cdf3feaf234223dcf10ab320408fbb5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 12:33:11 +0200 Subject: [PATCH 0164/1080] Add XFail test for issue #208, 'precommand modifiers at non-command-word position'. --- highlighters/main/test-data/precommand.zsh | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/precommand.zsh diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh new file mode 100644 index 0000000..6878538 --- /dev/null +++ b/highlighters/main/test-data/precommand.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER=': command zzzzzz' + +expected_region_highlight=( + "1 1 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "3 9 $ZSH_HIGHLIGHT_STYLES[default]" # not precommand + "11 16 $ZSH_HIGHLIGHT_STYLES[default] 'issue #208'" # not unknown-token (since 'zzzzzz' is not a command) +) From feec9f58c9e4541291aba3ed6ee749329186ad09 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 13:38:40 +0200 Subject: [PATCH 0165/1080] Followup to last: Fix issue number in comment. --- highlighters/main/test-data/precommand.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index 6878538..0f15684 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -33,5 +33,5 @@ BUFFER=': command zzzzzz' expected_region_highlight=( "1 1 $ZSH_HIGHLIGHT_STYLES[command]" # ls "3 9 $ZSH_HIGHLIGHT_STYLES[default]" # not precommand - "11 16 $ZSH_HIGHLIGHT_STYLES[default] 'issue #208'" # not unknown-token (since 'zzzzzz' is not a command) + "11 16 $ZSH_HIGHLIGHT_STYLES[default] 'issue #209'" # not unknown-token (since 'zzzzzz' is not a command) ) From 7e6d960a08dfc7f48d8f3d658db208b0fdee7aad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 08:09:08 +0000 Subject: [PATCH 0166/1080] noop: Break out a helper function. --- zsh-syntax-highlighting.zsh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f622c0e..e81f1e8 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -178,6 +178,14 @@ _zsh_highlight_cursor_moved() # Setup functions # ------------------------------------------------------------------------------------------------- +# Helper for _zsh_highlight_bind_widgets +# $1 is name of widget to call +_zsh_highlight_call_widget() +{ + builtin zle "$@" && + _zsh_highlight +} + # Rebind all ZLE widgets to make them invoke _zsh_highlights. _zsh_highlight_bind_widgets() { @@ -197,16 +205,16 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Completion widget: override and rebind old one with prefix "orig-". completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \ + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Default: unhandled case. From c808d2187a7331dff4d493a945482d718e63bc7a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 08:20:28 +0000 Subject: [PATCH 0167/1080] wrapping: Don't add '--' when invoking widgets. It's the widget's caller's responsibility, not ours, to add '--' where due. If we do it, two instances of '--' might result. (I haven't been able to provoke this problem.) If this commit causes problems, the cause would be widget-callers that don't pass '--' although they should. --- 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 e81f1e8..1d63dbf 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -205,16 +205,16 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Completion widget: override and rebind old one with prefix "orig-". completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }; \ + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Default: unhandled case. From 7723edf4f58fd23d1316b971b137dadfbbfdd03f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 12:32:53 +0000 Subject: [PATCH 0168/1080] Add an XFail test for accept-line semantics. --- highlighters/main/test-data/path_prefix.zsh | 3 +- highlighters/main/test-data/path_prefix2.zsh | 39 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/path_prefix2.zsh diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index 5b7c8b4..17cd26c 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -27,7 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -# Assumes that [[ -e /bin/sh ]]. +# Assumes that '/bin/sh' exists and '/bin/s' does not exist. +# Related to path_prefix2.zsh ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh new file mode 100644 index 0000000..13d8c9e --- /dev/null +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Assumes that '/bin/sh' exists and '/bin/s' does not exist. +# Related to path_prefix.zsh + +ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight +BUFFER='ls /bin/s' +WIDGET=accept-line + +expected_region_highlight=( + "4 9 $ZSH_HIGHLIGHT_STYLES[default] 'implemented by next commit'" # /bin/s +) From 59fbdda64c21dd9e911329f31fbbedc69123865b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 26 Oct 2015 08:26:35 +0000 Subject: [PATCH 0169/1080] main: Refresh highlighting upon accept-* widgets (accept-line et al). Use this to remove [path_prefix] highlighting during accept-* widgets. This causes ": file.tx" to remove the underline from "file.tx", like ": file.tx" already does. (Assume 'file.txt' exists.) --- highlighters/main/main-highlighter.zsh | 7 +++++-- highlighters/main/test-data/path_prefix2.zsh | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 42d19cc..166ae57 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -59,7 +59,9 @@ # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() { - _zsh_highlight_buffer_modified + # accept-* may trigger removal of path_prefix highlighting + [[ $WIDGET == accept-* ]] || + _zsh_highlight_buffer_modified } # Helper to deal with tokens crossing line boundaries. @@ -280,7 +282,8 @@ _zsh_highlight_main_highlighter_check_path() [[ ! -e ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. - if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]]; then + if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && + [[ $WIDGET != accept-* ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) (( $#tmp > 0 )) && style_override=path_prefix && return 0 diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index 13d8c9e..a1974eb 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -35,5 +35,5 @@ BUFFER='ls /bin/s' WIDGET=accept-line expected_region_highlight=( - "4 9 $ZSH_HIGHLIGHT_STYLES[default] 'implemented by next commit'" # /bin/s + "4 9 $ZSH_HIGHLIGHT_STYLES[default]" # /bin/s ) From 2080a441ac496e26a8068e50ee54349e3b9641fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 13:00:19 +0200 Subject: [PATCH 0170/1080] minor: Remove redundant setting of $highlight_glob. --- highlighters/main/main-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 166ae57..83f6800 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -144,7 +144,7 @@ _zsh_highlight_main_highlighter() sudo_arg=false else sudo=false - new_expression=true; highlight_glob=true + new_expression=true fi ;; esac @@ -178,7 +178,7 @@ _zsh_highlight_main_highlighter() if [[ $arg[-1] != '(' ]]; then # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) - new_expression=true; highlight_glob=true + new_expression=true fi elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] @@ -211,7 +211,7 @@ _zsh_highlight_main_highlighter() else # $arg is the file target of a prefix redirection, or a non-command word if $redirection; then redirection=false - new_expression=true; highlight_glob=true + new_expression=true fi case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; From e49251b6fa1632eb6a8b774c3717823e5207c98d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 12:25:58 +0200 Subject: [PATCH 0171/1080] sudo/redirections: Add two XFail tests for issue #221, "sudo and redirection don't mix". --- .../main/test-data/sudo-redirection.zsh | 39 +++++++++++++++++++ .../main/test-data/sudo-redirection2.zsh | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 highlighters/main/test-data/sudo-redirection.zsh create mode 100644 highlighters/main/test-data/sudo-redirection2.zsh diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh new file mode 100644 index 0000000..bf5a3e7 --- /dev/null +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='sudo -u >/tmp otheruser ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "9 9 $ZSH_HIGHLIGHT_STYLES[redirection]" # > + "10 13 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #221'" # ls +) diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh new file mode 100644 index 0000000..dcdb8d6 --- /dev/null +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='sudo >/tmp -u otheruser ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 6 $ZSH_HIGHLIGHT_STYLES[redirection]" # > + "7 10 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option] 'issue #221'" # -u + "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #221'" # ls +) From 80d692c400a7c70d51079638c09e25cc2a0dcc6d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 12:25:58 +0200 Subject: [PATCH 0172/1080] command word: Add an XFail test for issue #194, "Highlight anonymous functions". --- .../main/test-data/anonymous-function.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/anonymous-function.zsh diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh new file mode 100644 index 0000000..9e3e279 --- /dev/null +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +BUFFER='() echo hello; () { echo world }' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () + "4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo + "9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello + "14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # { + "21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo +) From 10b1da64e61de7b22d02f51ec37f40e0c86ae710 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 12:19:51 +0200 Subject: [PATCH 0173/1080] states work: Convert sudo parsing. --- highlighters/main/main-highlighter.zsh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 83f6800..1fa07f4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -84,7 +84,7 @@ _zsh_highlight_main_highlighter() { emulate -L zsh setopt localoptions extendedglob bareglobqual - local start_pos=0 end_pos highlight_glob=true new_expression=true arg style sudo=false sudo_arg=false + local start_pos=0 end_pos highlight_glob=true new_expression=true arg style local redirection=false # true when we've seen a redirection operator before seeing the command word typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS @@ -103,7 +103,9 @@ _zsh_highlight_main_highlighter() $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS ) + local this_word=':start:' next_word for arg in ${(z)buf}; do + next_word=':regular:' # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, # which add the entry early so escape sequences within the string override @@ -134,20 +136,16 @@ _zsh_highlight_main_highlighter() fi # Parse the sudo command line - if $sudo; then + if [[ $this_word == *':sudo_opt:'* ]]; then case "$arg" in # Flag that requires an argument - '-'[Cgprtu]) sudo_arg=true;; + '-'[Cgprtu]) next_word=':sudo_arg:';; # This prevents misbehavior with sudo -u -otherargument - '-'*) sudo_arg=false;; - *) if $sudo_arg; then - sudo_arg=false - else - sudo=false - new_expression=true - fi - ;; + '-'*) next_word+=':sudo_opt:';; + *) this_word+=':start:'; new_expression=true;; esac + elif [[ $this_word == *':sudo_arg:'* ]]; then + next_word+=':sudo_opt:' fi if $new_expression && ! $redirection; then # $arg is the command word new_expression=false @@ -155,7 +153,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] elif [[ "$arg" = "sudo" ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] - sudo=true + next_word+=':sudo_opt:' else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" @@ -253,6 +251,7 @@ _zsh_highlight_main_highlighter() [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos + this_word=$next_word done } From 0aa6a5db78ba232dcfcf8d681dde7c890c5913a4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 12:19:51 +0200 Subject: [PATCH 0174/1080] states work: Convert $new_expression parsing. --- highlighters/main/main-highlighter.zsh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1fa07f4..2803eb3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -84,7 +84,7 @@ _zsh_highlight_main_highlighter() { emulate -L zsh setopt localoptions extendedglob bareglobqual - local start_pos=0 end_pos highlight_glob=true new_expression=true arg style + local start_pos=0 end_pos highlight_glob=true arg style local redirection=false # true when we've seen a redirection operator before seeing the command word typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS @@ -112,7 +112,7 @@ _zsh_highlight_main_highlighter() # the string's color. integer already_added=0 local style_override="" - if $new_expression && [[ $arg = 'noglob' ]]; then + if [[ $this_word == *':start:'* ]] && [[ $arg = 'noglob' ]]; then highlight_glob=false fi @@ -142,13 +142,12 @@ _zsh_highlight_main_highlighter() '-'[Cgprtu]) next_word=':sudo_arg:';; # This prevents misbehavior with sudo -u -otherargument '-'*) next_word+=':sudo_opt:';; - *) this_word+=':start:'; new_expression=true;; + *) this_word+=':start:';; esac elif [[ $this_word == *':sudo_arg:'* ]]; then next_word+=':sudo_opt:' fi - if $new_expression && ! $redirection; then # $arg is the command word - new_expression=false + if [[ $this_word == *':start:'* ]] && ! $redirection; then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] elif [[ "$arg" = "sudo" ]]; then @@ -176,7 +175,7 @@ _zsh_highlight_main_highlighter() if [[ $arg[-1] != '(' ]]; then # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) - new_expression=true + next_word+=':start:' fi elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] @@ -209,7 +208,7 @@ _zsh_highlight_main_highlighter() else # $arg is the file target of a prefix redirection, or a non-command word if $redirection; then redirection=false - new_expression=true + next_word+=':start:' fi case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; @@ -248,7 +247,7 @@ _zsh_highlight_main_highlighter() # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && new_expression=true + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && next_word+=':start:' [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos this_word=$next_word From 88cf98d9c45b00be04a4e92738b02c11ccf2d0ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 15:52:03 +0200 Subject: [PATCH 0175/1080] states work: Documents the various states. --- highlighters/main/main-highlighter.zsh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2803eb3..2cc35f8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -103,6 +103,20 @@ _zsh_highlight_main_highlighter() $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS ) + # State machine + # + # The states are: + # - :start: Command word + # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i") + # - :sudo_arg: The argument to a sudo leading-dash option that takes one, + # when given as a separate word; i.e., "foo" in "-u foo" (two + # words) but not in "-ufoo" (one word). + # - :regular: "Not a command word". + # Mainly used to detect premature termination of commands. + # + # 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.. local this_word=':start:' next_word for arg in ${(z)buf}; do next_word=':regular:' From 2c9f8c8c95fa4f5675e510e0e4a3b4cdb0d40314 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 13:35:04 +0200 Subject: [PATCH 0176/1080] Fix issue #209, "precommand modifiers at non-command-word position". --- highlighters/main/main-highlighter.zsh | 5 ++++- highlighters/main/test-data/precommand.zsh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2cc35f8..5090aef 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -261,7 +261,10 @@ _zsh_highlight_main_highlighter() # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && next_word+=':start:' + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] || + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then + next_word+=':start:' + fi [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos this_word=$next_word diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index 0f15684..156b72d 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -33,5 +33,5 @@ BUFFER=': command zzzzzz' expected_region_highlight=( "1 1 $ZSH_HIGHLIGHT_STYLES[command]" # ls "3 9 $ZSH_HIGHLIGHT_STYLES[default]" # not precommand - "11 16 $ZSH_HIGHLIGHT_STYLES[default] 'issue #209'" # not unknown-token (since 'zzzzzz' is not a command) + "11 16 $ZSH_HIGHLIGHT_STYLES[default]" # not unknown-token (since 'zzzzzz' is not a command) ) From 018bc45f2159720d530221ff86380ec9e3e3a09f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 16:22:03 +0200 Subject: [PATCH 0177/1080] Followup to last: tighten the fix and ask a question. --- highlighters/main/main-highlighter.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5090aef..069c352 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -261,8 +261,12 @@ _zsh_highlight_main_highlighter() # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] || + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + # TODO maybe check *':regular:'* here? + next_word=':start:' + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then + # TODO should this be '=' or '+=' ? $next_word is probably :regular: and nothing looks for that value. next_word+=':start:' fi [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true From c6355a31b7ceb63a58e7cc5ebb857ab0e752d195 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 21:00:25 +0200 Subject: [PATCH 0178/1080] Followup to last: re-fix issue #9 and add test for it. The fix for issue #9 was accidentally broken by the penultimate commit. Note that we don't care about aliases to ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR entries, since the code deals with aliases at command position. --- highlighters/main/main-highlighter.zsh | 7 +--- highlighters/main/test-data/noglob-alias.zsh | 35 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 highlighters/main/test-data/noglob-alias.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 069c352..708f997 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -88,7 +88,6 @@ _zsh_highlight_main_highlighter() local redirection=false # true when we've seen a redirection operator before seeing the command word typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS - typeset -a ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS local buf="$PREBUFFER$BUFFER" region_highlight=() @@ -98,10 +97,6 @@ _zsh_highlight_main_highlighter() ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( 'builtin' 'command' 'exec' 'nocorrect' 'noglob' ) - # Tokens that are always immediately followed by a command. - ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS=( - $ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS - ) # State machine # @@ -178,7 +173,7 @@ _zsh_highlight_main_highlighter() ;; *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] local aliased_command="${"$(alias -- $arg)"#*=}" - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_FOLLOWED_BY_COMMANDS+=($arg) + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) ;; *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; *': function') style=$ZSH_HIGHLIGHT_STYLES[function];; diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh new file mode 100644 index 0000000..44d253a --- /dev/null +++ b/highlighters/main/test-data/noglob-alias.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 x=command +BUFFER='x ls' + +expected_region_highlight=( + "3 4 $ZSH_HIGHLIGHT_STYLES[command]" # ls +) From be006aded59014d15c2b11b2a858e9d3852a9393 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 13:46:10 +0200 Subject: [PATCH 0179/1080] sudo/redirections: Fix part of issue #221, "sudo and redirection don't mix". --- highlighters/main/main-highlighter.zsh | 51 +++++++++++-------- .../main/test-data/sudo-redirection.zsh | 2 +- .../main/test-data/sudo-redirection2.zsh | 2 +- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 708f997..4840897 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -85,7 +85,6 @@ _zsh_highlight_main_highlighter() emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true arg style - local redirection=false # true when we've seen a redirection operator before seeing the command word typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS local buf="$PREBUFFER$BUFFER" @@ -112,9 +111,21 @@ _zsh_highlight_main_highlighter() # 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.. + # + # Handling of redirections: upon seeing a redirection token, we must stall + # the current state --- both $this_word and $next_word --- for two iterations + # (one for the redirection operator, one for the word following it representing + # the redirection target). Therefore, we set $in_redirection to 2 upon seeing a + # redirection operator, decrement it each iteration, and stall the current state + # when it is non-zero. local this_word=':start:' next_word + integer in_redirection for arg in ${(z)buf}; do - next_word=':regular:' + if (( in_redirection == 0 )); then + next_word=':regular:' + else + (( --in_redirection )) + fi # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, # which add the entry early so escape sequences within the string override @@ -145,18 +156,21 @@ _zsh_highlight_main_highlighter() fi # Parse the sudo command line - if [[ $this_word == *':sudo_opt:'* ]]; then - case "$arg" in - # Flag that requires an argument - '-'[Cgprtu]) next_word=':sudo_arg:';; - # This prevents misbehavior with sudo -u -otherargument - '-'*) next_word+=':sudo_opt:';; - *) this_word+=':start:';; - esac - elif [[ $this_word == *':sudo_arg:'* ]]; then - next_word+=':sudo_opt:' + if (( ! in_redirection )); then + if [[ $this_word == *':sudo_opt:'* ]]; then + case "$arg" in + # Flag that requires an argument + '-'[Cgprtu]) next_word=':sudo_arg:';; + # This prevents misbehavior with sudo -u -otherargument + '-'*) next_word+=':sudo_opt:';; + *) this_word+=':start:';; + esac + elif [[ $this_word == *':sudo_arg:'* ]]; then + next_word+=':sudo_opt:' + fi fi - if [[ $this_word == *':start:'* ]] && ! $redirection; then # $arg is the command word + + if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] elif [[ "$arg" = "sudo" ]]; then @@ -190,7 +204,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] - redirection=true + (( in_redirection=2 )) elif [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # @@ -214,11 +228,7 @@ _zsh_highlight_main_highlighter() ;; esac fi - else # $arg is the file target of a prefix redirection, or a non-command word - if $redirection; then - redirection=false - next_word+=':start:' - fi + else # $arg is a non-command word case $arg in '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; @@ -243,6 +253,7 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[commandseparator] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] + (( in_redirection=2 )) else if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] @@ -266,7 +277,7 @@ _zsh_highlight_main_highlighter() fi [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos - this_word=$next_word + (( in_redirection == 0 )) && this_word=$next_word done } diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index bf5a3e7..e782996 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -35,5 +35,5 @@ expected_region_highlight=( "9 9 $ZSH_HIGHLIGHT_STYLES[redirection]" # > "10 13 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #221'" # ls + "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index dcdb8d6..c74058f 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -35,5 +35,5 @@ expected_region_highlight=( "7 10 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option] 'issue #221'" # -u "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #221'" # ls + "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) From 6d6fb8b03e85d30ddd3cd262bc14f5503c508c12 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 16:09:07 +0200 Subject: [PATCH 0180/1080] redirections: Document handling of redirections and possibly fix a latent bug. The change of behaviour is triggered by test-data/sudo-redirection.zsh: the iteration on "otheruser" sets $next_word to ":regular::sudo_opt::start::sudo_opt::start:" before this patch, but to ":regular::sudo_opt::start:" after it (note the deduplication). --- 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 4840897..87f358a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -113,18 +113,28 @@ _zsh_highlight_main_highlighter() # 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 --- both $this_word and $next_word --- for two iterations + # the current state --- that is, the value of $this_word --- for two iterations # (one for the redirection operator, one for the word following it representing # the redirection target). Therefore, we set $in_redirection to 2 upon seeing a # redirection operator, decrement it each iteration, and stall the current state - # when it is non-zero. + # when it is non-zero. Thus, upon reaching the next word (the one that follows + # the redirection operator and target), $this_word will still contain values + # appropriate for the word immediately following the word that preceded the + # redirection operator. + # + # The "the previous word was a redirection operator" state is not communicated + # to the next iteration via $next_word/$this_word as usual, but via + # $in_redirection. The value of $next_word from the iteration that processed + # the operator is discarded. + # local this_word=':start:' next_word integer in_redirection for arg in ${(z)buf}; do + if (( in_redirection )); then + (( --in_redirection )) + fi if (( in_redirection == 0 )); then next_word=':regular:' - else - (( --in_redirection )) fi # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, From 01d7eeb3c7134cd75dc1e8a0ca831bcc4122e1fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 15:01:37 +0200 Subject: [PATCH 0181/1080] Fix issue #205, "';' after assignment is highlighted as unknown-token". --- highlighters/main/main-highlighter.zsh | 6 ++++-- highlighters/main/test-data/assign-semicolon.zsh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 87f358a..c86fb46 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -212,6 +212,9 @@ _zsh_highlight_main_highlighter() fi elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && + [[ $this_word == *':regular:'* ]]; then + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] (( in_redirection=2 )) @@ -282,8 +285,7 @@ _zsh_highlight_main_highlighter() next_word=':start:' elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then - # TODO should this be '=' or '+=' ? $next_word is probably :regular: and nothing looks for that value. - next_word+=':start:' + next_word=':start:' fi [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index c47bf28..c3692d4 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -31,6 +31,6 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER='A=1; echo hello world' expected_region_highlight=( - "4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator] 'issue #205'" # ; + "4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "6 9 $ZSH_HIGHLIGHT_STYLES[command]" # echo ) From 87deac3062335a208d71342dabbe8c70c342b5d9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 05:58:48 +0000 Subject: [PATCH 0182/1080] command word: Add an XFail test for issue #207. --- highlighters/main/test-data/control-flow.zsh | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 highlighters/main/test-data/control-flow.zsh diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh new file mode 100644 index 0000000..95059e4 --- /dev/null +++ b/highlighters/main/test-data/control-flow.zsh @@ -0,0 +1,46 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight +BUFFER='while if echo Hello; then ls /; fi; do stat "x"; done' + +expected_region_highlight+=( + "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while + "7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #207'" # if + "10 13 $ZSH_HIGHLIGHT_STYLES[builtin] 'issue #207'" # echo + "15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello + "22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then + "27 28 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # ls + "30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / + "33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi + "37 38 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do + "40 43 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # stat + "45 47 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" + "50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done +) From b397b12ac1397a7afb6c13b94e1dc867a7b6a087 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 08:04:43 +0200 Subject: [PATCH 0183/1080] command word: Start fixing issue #207, "Word following certain reserved words should be a command word". --- highlighters/main/main-highlighter.zsh | 11 +++++++++++ highlighters/main/test-data/control-flow.zsh | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c86fb46..4a00995 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -87,6 +87,7 @@ _zsh_highlight_main_highlighter() local start_pos=0 end_pos highlight_glob=true arg style typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS + typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW local buf="$PREBUFFER$BUFFER" region_highlight=() @@ -97,6 +98,15 @@ _zsh_highlight_main_highlighter() 'builtin' 'command' 'exec' 'nocorrect' 'noglob' ) + # Tokens that, at (naively-determined) "command position", are followed by + # a de jure command position. + ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=( + 'while' + 'if' + 'then' + 'do' + ) + # State machine # # The states are: @@ -284,6 +294,7 @@ _zsh_highlight_main_highlighter() # TODO maybe check *':regular:'* here? next_word=':start:' elif + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then next_word=':start:' fi diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 95059e4..2a85d5e 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -32,15 +32,15 @@ BUFFER='while if echo Hello; then ls /; fi; do stat "x"; done' expected_region_highlight+=( "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while - "7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #207'" # if - "10 13 $ZSH_HIGHLIGHT_STYLES[builtin] 'issue #207'" # echo + "7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if + "10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo "15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello "22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then - "27 28 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # ls + "27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls "30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / "33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi "37 38 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do - "40 43 $ZSH_HIGHLIGHT_STYLES[command] 'issue #207'" # stat + "40 43 $ZSH_HIGHLIGHT_STYLES[command]" # stat "45 47 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" "50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done ) From 2218e26bf89e347103fff139c31d66ae68282ce1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 17:32:23 +0000 Subject: [PATCH 0184/1080] command word: Highlight 'else' correctly. Part of issue #207. --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/control-flow.zsh | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4a00995..45f24e6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -104,6 +104,7 @@ _zsh_highlight_main_highlighter() 'while' 'if' 'then' + 'else' 'do' ) diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 2a85d5e..c2887c2 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -28,7 +28,7 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight -BUFFER='while if echo Hello; then ls /; fi; do stat "x"; done' +BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done' expected_region_highlight+=( "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while @@ -38,9 +38,12 @@ expected_region_highlight+=( "22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then "27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls "30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / - "33 34 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi - "37 38 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do - "40 43 $ZSH_HIGHLIGHT_STYLES[command]" # stat - "45 47 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" - "50 53 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done + "31 31 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "33 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # else + "38 39 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "42 43 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi + "46 47 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do + "49 52 $ZSH_HIGHLIGHT_STYLES[command]" # stat + "54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" + "59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done ) From c216242b462eb3a71b7f4b2fea2fc9750914cd45 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 20:44:49 +0200 Subject: [PATCH 0185/1080] command word: Highlight more reserved words. Part of issue #207. --- 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 45f24e6..f222877 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -99,13 +99,18 @@ _zsh_highlight_main_highlighter() ) # Tokens that, at (naively-determined) "command position", are followed by - # a de jure command position. + # a de jure command position. All of these are reserved words. ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=( 'while' + 'until' 'if' 'then' + 'elif' 'else' 'do' + 'time' + 'coproc' + '!' # reserved word; unrelated to $histchars[1] ) # State machine From 0d1bfbcbfa675ca1de7a78513688990b813c1992 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 15:10:01 +0200 Subject: [PATCH 0186/1080] Highlight subshells and anonymous functions correctly. Fixes zsh-users/zsh-syntax-highlighting#166. Fixes zsh-users/zsh-syntax-highlighting#194. Builds upon the issue #207 work. --- highlighters/main/main-highlighter.zsh | 6 ++++++ highlighters/main/test-data/anonymous-function.zsh | 10 +++++----- highlighters/main/test-data/subshell.zsh | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f222877..61596d0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -101,6 +101,9 @@ _zsh_highlight_main_highlighter() # Tokens that, at (naively-determined) "command position", are followed by # a de jure command position. All of these are reserved words. ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW=( + $'\x7b' # block + $'\x28' # subshell + '()' # anonymous function 'while' 'until' 'if' @@ -247,6 +250,9 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style already_added=1 + elif [[ $arg == '()' ]]; then + # anonymous function + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] else if _zsh_highlight_main_highlighter_check_path; then style=$ZSH_HIGHLIGHT_STYLES[path] diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index 9e3e279..62714ed 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -30,11 +30,11 @@ BUFFER='() echo hello; () { echo world }' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () - "4 7 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo + "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo "9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello "14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # () - "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #194'" # { - "21 24 $ZSH_HIGHLIGHT_STYLES[command] 'issue #194'" # echo + "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { + "21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo ) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 31f8507..f8d61a0 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,6 +31,6 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "15 16 $ZSH_HIGHLIGHT_STYLES[command] 'issue #166'" # cd + "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar ) From 86e92497091197a7a281ac90dce05d0ed8146096 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 13:06:30 +0200 Subject: [PATCH 0187/1080] sudo/redirections: Fix remaining part of issue #221, "sudo and redirection don't mix". --- highlighters/main/main-highlighter.zsh | 3 ++- highlighters/main/test-data/sudo-redirection2.zsh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 61596d0..569fbe4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -189,7 +189,8 @@ _zsh_highlight_main_highlighter() if [[ $this_word == *':sudo_opt:'* ]]; then case "$arg" in # Flag that requires an argument - '-'[Cgprtu]) next_word=':sudo_arg:';; + '-'[Cgprtu]) this_word=${this_word//:start:/}; + next_word=':sudo_arg:';; # This prevents misbehavior with sudo -u -otherargument '-'*) next_word+=':sudo_opt:';; *) this_word+=':start:';; diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index c74058f..f806178 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -33,7 +33,7 @@ expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo "6 6 $ZSH_HIGHLIGHT_STYLES[redirection]" # > "7 10 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option] 'issue #221'" # -u + "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) From a3047a9121005b5d522aa2b6dfbd70577a254406 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 13:22:48 +0200 Subject: [PATCH 0188/1080] sudo: Highlight an empty `sudo;` as an error. The word following 'sudo' was considered :regular:, although it isn't. --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/sudo-command.zsh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 569fbe4..f8d6ffa 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -206,6 +206,7 @@ _zsh_highlight_main_highlighter() elif [[ "$arg" = "sudo" ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] next_word+=':sudo_opt:' + next_word=${next_word//:regular:/} else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 437d5eb..1cf9423 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -32,7 +32,7 @@ ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight # * -i (no argument) # * -C3 (pasted argument) # * -u otheruser (non-pasted argument) -BUFFER='sudo -C3 -u otheruser -i ls /' +BUFFER='sudo -C3 -u otheruser -i ls /; sudo ;' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo @@ -42,4 +42,5 @@ expected_region_highlight=( "23 24 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i "26 27 $ZSH_HIGHLIGHT_STYLES[command]" # ls "29 29 $ZSH_HIGHLIGHT_STYLES[path]" # / + "37 37 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because empty command ) From f49f3bf0c088e7dfaff708909ce7d00b6576b839 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 13:35:16 +0200 Subject: [PATCH 0189/1080] sudo: Extend tests. --- highlighters/main/test-data/sudo-redirection.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index e782996..e31ce6e 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='sudo -u >/tmp otheruser ls' +BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo @@ -36,4 +36,11 @@ expected_region_highlight=( "10 13 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "27 27 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "29 32 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "34 35 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "36 36 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "38 41 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "43 44 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i + "46 47 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) From 9cb87473cca68568c5285634a151617d1e7ccc9e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 13:37:45 +0200 Subject: [PATCH 0190/1080] sudo: Tweak state computations. This causes the ':start:' state to be set in $next_word in iteration N-1, rather than to only be added to $this_word in iteration N. --- highlighters/main/main-highlighter.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f8d6ffa..382618f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -192,11 +192,14 @@ _zsh_highlight_main_highlighter() '-'[Cgprtu]) this_word=${this_word//:start:/}; next_word=':sudo_arg:';; # This prevents misbehavior with sudo -u -otherargument - '-'*) next_word+=':sudo_opt:';; - *) this_word+=':start:';; + '-'*) this_word=${this_word//:start:/}; + next_word+=':start:'; + next_word+=':sudo_opt:';; + *) ;; esac elif [[ $this_word == *':sudo_arg:'* ]]; then next_word+=':sudo_opt:' + next_word+=':start:' fi fi @@ -205,8 +208,9 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[precommand] elif [[ "$arg" = "sudo" ]]; then style=$ZSH_HIGHLIGHT_STYLES[precommand] - next_word+=':sudo_opt:' next_word=${next_word//:regular:/} + next_word+=':sudo_opt:' + next_word+=':start:' else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" From 2f05620b19aec6a79d90c6ca8db71e2cc981c3c0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 14:14:45 +0200 Subject: [PATCH 0191/1080] sudo: Flag an error when a required argument is missing. --- highlighters/main/main-highlighter.zsh | 9 +++++++-- highlighters/main/test-data/sudo-command.zsh | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 382618f..37173b1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -239,6 +239,8 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && [[ $this_word == *':regular:'* ]]; then + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. style=$ZSH_HIGHLIGHT_STYLES[commandseparator] elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] @@ -291,7 +293,11 @@ _zsh_highlight_main_highlighter() elif [[ $arg[0,1] = $histchars[0,1] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + if [[ $this_word == *':regular:'* ]]; then + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] (( in_redirection=2 )) @@ -309,7 +315,6 @@ _zsh_highlight_main_highlighter() [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - # TODO maybe check *':regular:'* here? next_word=':start:' elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 1cf9423..ec1ccff 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -32,7 +32,7 @@ ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight # * -i (no argument) # * -C3 (pasted argument) # * -u otheruser (non-pasted argument) -BUFFER='sudo -C3 -u otheruser -i ls /; sudo ;' +BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo @@ -43,4 +43,5 @@ expected_region_highlight=( "26 27 $ZSH_HIGHLIGHT_STYLES[command]" # ls "29 29 $ZSH_HIGHLIGHT_STYLES[path]" # / "37 37 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because empty command + "47 47 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because incomplete command ) From e9ceb2017ef8c30434bccc9d0433d4f81db75caa Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 16:44:02 +0000 Subject: [PATCH 0192/1080] comments: Add XFail tests from issues #163 and #167. These tests are based on the patches contributed in those issues: commit 9d9df4fe80c878e460b38b5d8be76926a9e02286 (upstream/pr/167) Author: Miciah Masters AuthorDate: Thu Apr 23 20:28:24 2015 -0400 Commit: Miciah Dashiel Butler Masters CommitDate: Thu Apr 23 20:28:24 2015 -0400 Highlight comments M highlighters/main/main-highlighter.zsh A highlighters/main/test-data/comments.zsh commit d94f1a037f9829792b2faaf94efe4d86300369b7 (upstream/pr/163) Author: sonnym AuthorDate: Fri Mar 6 18:27:57 2015 -0500 Commit: sonnym CommitDate: Fri Mar 6 21:16:27 2015 -0500 highlight comments when interactive_comments is on M highlighters/main/main-highlighter.zsh A highlighters/main/test-data/comment-embedded.zsh A highlighters/main/test-data/comment-leading.zsh Patch-by: sonnym Patch-by: Miciah Masters (corrected and refreshed for harness changes by me) --- .../main/test-data/comment-leading.zsh | 38 ++++++++++++++++++ highlighters/main/test-data/comments.zsh | 39 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 highlighters/main/test-data/comment-leading.zsh create mode 100644 highlighters/main/test-data/comments.zsh diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh new file mode 100644 index 0000000..78013e8 --- /dev/null +++ b/highlighters/main/test-data/comment-leading.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 interactive_comments + +BUFFER='# echo foo' + +expected_region_highlight=( + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # # + "2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # " echo foo" +) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh new file mode 100644 index 0000000..b08c29c --- /dev/null +++ b/highlighters/main/test-data/comments.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 interactive_comments + +BUFFER='echo "foo #bar" #baz # quux' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[command]" # echo + "6 15 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo #bar" + "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # #baz # quux +) From e76f208cf84770b56b3436d45d348cb191fc3da2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 08:34:12 +0200 Subject: [PATCH 0193/1080] comments: Add a PASSing test for the NO_INTERACTIVE_COMMENTS case. --- highlighters/main/test-data/comment-off.zsh | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/comment-off.zsh diff --git a/highlighters/main/test-data/comment-off.zsh b/highlighters/main/test-data/comment-off.zsh new file mode 100644 index 0000000..5aa16af --- /dev/null +++ b/highlighters/main/test-data/comment-off.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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 interactive_comments + +BUFFER='# echo foo' + +expected_region_highlight=( + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # # + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" +) From 693de99a9030db2fa0abafcdd5860791a97dd743 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 19:29:06 +0200 Subject: [PATCH 0194/1080] comments: Fix issue #163 and #167: Highlight comments. --- highlighters/main/README.md | 1 + highlighters/main/main-highlighter.zsh | 15 ++++++++++++++- highlighters/main/test-data/comment-leading.zsh | 4 ++-- highlighters/main/test-data/comments.zsh | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index c903b26..c748248 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -47,6 +47,7 @@ This highlighter defines the following styles: * `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'') * `assign` - variable assignments * `redirection` - redirection operators (`<`, `>`, etc) +* `comment` - interactive comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) * `default` - parts of the buffer that do not match anything To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 37173b1..16052de 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -55,6 +55,7 @@ : ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[assign]:=none} : ${ZSH_HIGHLIGHT_STYLES[redirection]:=none} +: ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() @@ -82,6 +83,9 @@ _zsh_highlight_main_add_region_highlight() { # Main syntax highlighting function. _zsh_highlight_main_highlighter() { + if [[ -o interactive_comments ]]; then + local interactive_comments= # set to empty + fi emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true arg style @@ -148,7 +152,8 @@ _zsh_highlight_main_highlighter() # local this_word=':start:' next_word integer in_redirection - for arg in ${(z)buf}; do + for arg in ${interactive_comments-${(z)buf}} \ + ${interactive_comments+${(zZ+c+)buf}}; do if (( in_redirection )); then (( --in_redirection )) fi @@ -184,6 +189,14 @@ _zsh_highlight_main_highlighter() ((end_pos=$start_pos+${#arg})) fi + if [[ ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then + # TODO: check $this_word + style=$ZSH_HIGHLIGHT_STYLES[comment] + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + already_added=1 + continue + fi + # Parse the sudo command line if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh index 78013e8..a30af8b 100644 --- a/highlighters/main/test-data/comment-leading.zsh +++ b/highlighters/main/test-data/comment-leading.zsh @@ -33,6 +33,6 @@ setopt interactive_comments BUFFER='# echo foo' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # # - "2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # " echo foo" + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # # + "2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # " echo foo" ) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index b08c29c..4b9c974 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -35,5 +35,5 @@ BUFFER='echo "foo #bar" #baz # quux' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[command]" # echo "6 15 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo #bar" - "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]} 'issue #163'" # #baz # quux + "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux ) From 1ac39b0af1ff7e50e11c21f0c0d1e71734d129f6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 15:48:55 +0200 Subject: [PATCH 0195/1080] comments: Mark prematurely-terminated command as an error. This is already done for commands prematurely terminated by ";". --- highlighters/main/main-highlighter.zsh | 7 ++-- highlighters/main/test-data/sudo-comment.zsh | 38 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/sudo-comment.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 16052de..8fa7dda 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -190,8 +190,11 @@ _zsh_highlight_main_highlighter() fi if [[ ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then - # TODO: check $this_word - style=$ZSH_HIGHLIGHT_STYLES[comment] + if [[ $this_word == *(':regular:'|':start:')* ]]; then + style=$ZSH_HIGHLIGHT_STYLES[comment] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] # prematurely terminated + fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style already_added=1 continue diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh new file mode 100644 index 0000000..8a70ae3 --- /dev/null +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight +setopt interactive_comments +BUFFER='sudo -u # comment' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "9 17 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # "# comment" - error because argument missed +) From afa6bb3882e8a8e153241a70794f5942c85543a7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 29 Oct 2015 19:58:23 +0200 Subject: [PATCH 0196/1080] states work: Extend state machine documentation. --- 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 8fa7dda..db28998 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -131,6 +131,11 @@ _zsh_highlight_main_highlighter() # - :regular: "Not a command word". # Mainly used to detect premature termination of commands. # + # 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:. + # # 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.. From 8ab8c815eccf0b18119c56679d584eca07dd6ec4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 09:34:16 +0200 Subject: [PATCH 0197/1080] Fix syntax error with zsh-5.0.5-dev-1 and older. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zsh prior to workers/32609 (commit 9d47e8398d299e53ffe4e7ddf3731d2fedae9948) does not support the (-n)-less «[[ $var ]]» syntax. Fixes zsh-users/zsh-syntax-highlighting#225. --- 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 db28998..ce48ce7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -194,7 +194,7 @@ _zsh_highlight_main_highlighter() ((end_pos=$start_pos+${#arg})) fi - if [[ ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then + if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then style=$ZSH_HIGHLIGHT_STYLES[comment] else From d3deffbf46a45250a399bea86a66cbdd14e12edc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 07:09:46 +0000 Subject: [PATCH 0198/1080] minor: Fix WARN_CREATE_GLOBAL warnings issued by zsh 5.1.1-dev-0. The following warnings are issued by zsh as of zsh-workers/37018 (commit de9effbce601 to zsh itself): _zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter match created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter mbegin created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string:17: array parameter mend created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string:17: numeric parameter parameter MBEGIN created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string:17: numeric parameter parameter MEND created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_dollar_string:17: scalar parameter MATCH created globally in function _zsh_highlight_main_highlighter_highlight_dollar_string _zsh_highlight_main_highlighter_highlight_string:11: array parameter match created globally in function _zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string:11: array parameter mbegin created globally in function _zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string:11: array parameter mend created globally in function _zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string:11: numeric parameter parameter MBEGIN created globally in function _zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string:11: numeric parameter parameter MEND created globally in function _zsh_highlight_main_highlighter_highlight_string _zsh_highlight_main_highlighter_highlight_string:11: scalar parameter MATCH created globally in function _zsh_highlight_main_highlighter_highlight_string --- highlighters/main/main-highlighter.zsh | 4 ++++ highlighters/pattern/pattern-highlighter.zsh | 1 + 2 files changed, 5 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ce48ce7..f5fd41e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -389,6 +389,8 @@ _zsh_highlight_main_highlighter_check_path() _zsh_highlight_main_highlighter_highlight_string() { setopt localoptions noksharrays + local -a match mbegin mend + local MATCH; integer MBEGIN MEND local i j k style # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do @@ -423,6 +425,8 @@ _zsh_highlight_main_highlighter_highlight_string() _zsh_highlight_main_highlighter_highlight_dollar_string() { setopt localoptions noksharrays + local -a match mbegin mend + local MATCH; integer MBEGIN MEND local i j k style local AA integer c diff --git a/highlighters/pattern/pattern-highlighter.zsh b/highlighters/pattern/pattern-highlighter.zsh index c77d53b..4e2eabd 100644 --- a/highlighters/pattern/pattern-highlighter.zsh +++ b/highlighters/pattern/pattern-highlighter.zsh @@ -52,6 +52,7 @@ _zsh_highlight_pattern_highlighter_loop() # This does *not* do its job syntactically, sorry. local buf="$1" pat="$2" 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]") "$0" "$match[1]" "$pat"; return $? From 5a3871056439afc15a4c8ad26c9665f9c67d3d85 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 09:34:01 +0000 Subject: [PATCH 0199/1080] subshells: Add an XFail test demonstrating that #166 is not yet fixed. Reported-by: Antony Lee --- highlighters/main/test-data/subshell.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index f8d61a0..aee6c49 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,6 +31,8 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar + "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #166'" # ( "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar + #"36 36 $ZSH_HIGHLIGHT_STYLES[?]" # ) ) From 9e178f9f394823932887ecdcd1fa2834e54d21b1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 11:38:32 +0200 Subject: [PATCH 0200/1080] subshells: Highlight the opening parenthesis correctly. (Issue #166.) Followup to 0d1bfbcbfa675ca1de7a78513688990b813c1992. --- highlighters/main/main-highlighter.zsh | 3 ++- highlighters/main/test-data/subshell.zsh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f5fd41e..7d4410d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -279,8 +279,9 @@ _zsh_highlight_main_highlighter() style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style already_added=1 - elif [[ $arg == '()' ]]; then + elif [[ $arg == '()' || $arg == $'\x28' ]]; then # anonymous function + # subshell style=$ZSH_HIGHLIGHT_STYLES[reserved-word] else if _zsh_highlight_main_highlighter_check_path; then diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index aee6c49..18d2a23 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,7 +31,7 @@ BUFFER='tar cf - * | (cd /target; tar xfp -)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #166'" # ( + "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar #"36 36 $ZSH_HIGHLIGHT_STYLES[?]" # ) From 6fbd2aa9579b46a277db9833b225da0c7fbf0ba1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 14:57:26 +0200 Subject: [PATCH 0201/1080] Add an XFail test for issue #222, "command word after repeat". --- highlighters/main/test-data/control-flow.zsh | 4 +++- highlighters/main/test-data/reserved-word.zsh | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index c2887c2..7e61372 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -28,7 +28,7 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight -BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done' +BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' expected_region_highlight+=( "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while @@ -46,4 +46,6 @@ expected_region_highlight+=( "49 52 $ZSH_HIGHLIGHT_STYLES[command]" # stat "54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" "59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done + "65 70 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat + "75 76 $ZSH_HIGHLIGHT_STYLES[command] 'issue #222'" # ls ) diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index 3cd9cd2..b19af50 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -33,4 +33,6 @@ BUFFER='repeat "1" do done' expected_region_highlight=( "1 6 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat "8 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "1" + "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #222'" # do + "15 18 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'fallout of previous test point'" # done ) From 8b4adbd991b0329edda7a8a40fef859b56192f70 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 28 Oct 2015 14:57:26 +0200 Subject: [PATCH 0202/1080] Fix issue #222, "command word after repeat". --- highlighters/main/main-highlighter.zsh | 8 ++++++++ highlighters/main/test-data/control-flow.zsh | 2 +- highlighters/main/test-data/reserved-word.zsh | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7d4410d..5079f50 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -342,6 +342,14 @@ _zsh_highlight_main_highlighter() [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then next_word=':start:' + elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then + # skip the repeat-count word + in_redirection=2 + # The redirection mechanism assumes $this_word describes the word + # following the redirection. Make it so. + # + # The repeat-count word will be handled like a redirection target. + this_word=':start:' fi [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 7e61372..3107f50 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -47,5 +47,5 @@ expected_region_highlight+=( "54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" "59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done "65 70 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat - "75 76 $ZSH_HIGHLIGHT_STYLES[command] 'issue #222'" # ls + "75 76 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index b19af50..2f62103 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -33,6 +33,6 @@ BUFFER='repeat "1" do done' expected_region_highlight=( "1 6 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat "8 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "1" - "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #222'" # do - "15 18 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'fallout of previous test point'" # done + "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do + "15 18 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done ) From a59f442d2d3436a645100259d2396521461e1729 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 17:28:48 +0000 Subject: [PATCH 0203/1080] brackets: Highlight the closing brackets of arithmetic expansion. (Issue #226.) --- highlighters/main/main-highlighter.zsh | 3 +++ highlighters/main/test-data/arithmetic-evaluation.zsh | 1 + 2 files changed, 4 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5079f50..2867dcf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -278,6 +278,9 @@ _zsh_highlight_main_highlighter() # is how [[ ... ]] is highlighted, too. style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style + if [[ $arg[-2,-1] == '))' ]]; then + _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style + fi already_added=1 elif [[ $arg == '()' || $arg == $'\x28' ]]; then # anonymous function diff --git a/highlighters/main/test-data/arithmetic-evaluation.zsh b/highlighters/main/test-data/arithmetic-evaluation.zsh index dc26472..9287e91 100644 --- a/highlighters/main/test-data/arithmetic-evaluation.zsh +++ b/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -36,4 +36,5 @@ BUFFER='(( x == 42 ))' expected_region_highlight=( "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # (( + "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # )) ) From 28abb960de02cdaeb88633b8dd08a982cf21aa19 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 20:14:03 +0200 Subject: [PATCH 0204/1080] noop: Follow-up to last: improve readability. --- 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 2867dcf..69589ce 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -278,10 +278,11 @@ _zsh_highlight_main_highlighter() # is how [[ ... ]] is highlighted, too. style=$ZSH_HIGHLIGHT_STYLES[reserved-word] _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style + already_added=1 if [[ $arg[-2,-1] == '))' ]]; then _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style + already_added=1 fi - already_added=1 elif [[ $arg == '()' || $arg == $'\x28' ]]; then # anonymous function # subshell From c0dafd1d850e582291b41d693369794d1ea31343 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 20:20:30 +0200 Subject: [PATCH 0205/1080] brackets: Highlight the closing brackets of subshells and blocks. (Issue #226.) --- highlighters/main/main-highlighter.zsh | 2 ++ highlighters/main/test-data/subshell.zsh | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 69589ce..64a2032 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -299,6 +299,8 @@ _zsh_highlight_main_highlighter() fi else # $arg is a non-command word case $arg in + $'\x29') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # subshell + $'\x7d') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # block '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; "'"*) style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 18d2a23..3e98476 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -27,12 +27,15 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='tar cf - * | (cd /target; tar xfp -)' +BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar - #"36 36 $ZSH_HIGHLIGHT_STYLES[?]" # ) + "36 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) + "40 40 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { + "42 44 $ZSH_HIGHLIGHT_STYLES[command]" # cat + "46 46 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # } ) From 44e5323b53edd221a79a585869cf4833d555ba58 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 07:00:39 +0200 Subject: [PATCH 0206/1080] changelog: Update through HEAD (c0dafd1d850e). --- changelog.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9f64503..dbffcde 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,66 @@ -up to 98aee7f8b9a34c639352034087ac31193256b898 +up to c0dafd1d850e582291b41d693369794d1ea31343 # Changes in version 0.3.1 + +## Added highlighting of: + +- incomplete sudo commands + (a3047a912100, 2f05620b19ae) + + 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 + + (The `ls` are now highlighted as a command.) + +- comments (when `INTERACTIVE_COMMENTS` is set) + (#163, #167, 693de99a9030) + + echo Hello # comment + +- closing brackets of arithmetic expansion, subshells, and blocks + (#226, a59f442d2d34, et seq) + + (( foo )) + ( foo ) + { foo } + + +## Fixed highlighting of: + +- precommand modifiers at non-command-word position + (#209, 2c9f8c8c95fa) + + ls command foo + +- sudo commands with infix redirections + (#221, be006aded590, 86e924970911) + + sudo -u >/tmp/foo.out user ls + +- subshells; anonymous functions + (#166, #194, 0d1bfbcbfa67, 9e178f9f3948) + + (true) + () { true } + +- parameter assignment statements with no command + (#205, 01d7eeb3c713) + + A=1; + + (The semicolon used to be highlighted as a mistake) + + ## Removed features: - Removed highlighting of approximate paths (`path_approx`). @@ -13,27 +69,48 @@ up to 98aee7f8b9a34c639352034087ac31193256b898 ## Other changes: +- main highlighter refactored to use states rather than booleans. + (2080a441ac49, et seq) + - Fix initialization when sourcing `zsh-syntax-highlighting.zsh` via a symlink (083c47b00707) - docs: Add screenshot. (57624bb9f64b) +- widgets wrapping: Don't add '--' when invoking widgets. + (c808d2187a73) + +- Refresh highlighting upon `accept-*` widgets (`accept-line` et al). + (59fbdda64c21) + +- Stop leaking match/mbegin/mend to global scope (thanks to upstream + `WARN_CREATE_GLOBAL` improvements). + (d3deffbf46a4) + ## Developer-visible changes: +- Test harness converted to [TAP](http://testanything.org/tap-specification.html) format + (d99aa58aaaef, et seq) + - Run each test in a separate subprocess, isolating them from each other (d99aa58aaaef, et seq) - Fix test failure with nonexisting $HOME (#216, b2ac98b98150) +- Test output is now colorized. + (4d3da30f8b72, 6fe07c096109) + - Document `make install` (a18a7427fd2c) - tests: Allow specifying the zsh binary to use. (557bb7e0c6a0) +- tests: Add 'make perf' target + (4513eaea71d7) From b285c7b821729bb658aa707b2b1bd120285fb29b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 18:44:44 +0000 Subject: [PATCH 0207/1080] brackets: Highlight closing ')' of array assignments correctly. (Issue #226.) Followup to c0dafd1d850e582291b41d693369794d1ea31343, which changed the highlight of those ')'s from to [reserved-word]. --- highlighters/main/main-highlighter.zsh | 20 ++++++++--- highlighters/main/test-data/assign-array.zsh | 38 ++++++++++++++++++++ highlighters/main/test-data/assign.zsh | 2 ++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 highlighters/main/test-data/assign-array.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 64a2032..ad622b8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -89,6 +89,7 @@ _zsh_highlight_main_highlighter() emulate -L zsh setopt localoptions extendedglob bareglobqual local start_pos=0 end_pos highlight_glob=true arg style + local in_array_assignment=false # true between 'a=(' and the matching ')' typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW @@ -171,8 +172,11 @@ _zsh_highlight_main_highlighter() # the string's color. integer already_added=0 local style_override="" - if [[ $this_word == *':start:'* ]] && [[ $arg = 'noglob' ]]; then - highlight_glob=false + if [[ $this_word == *':start:'* ]]; then + in_array_assignment=false + if [[ $arg == 'noglob' ]]; then + highlight_glob=false + fi fi # advance $start_pos, skipping over whitespace in $buf. @@ -251,7 +255,9 @@ _zsh_highlight_main_highlighter() *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; *) if _zsh_highlight_main_highlighter_check_assign; then style=$ZSH_HIGHLIGHT_STYLES[assign] - if [[ $arg[-1] != '(' ]]; then + if [[ $arg[-1] == '(' ]]; then + in_array_assignment=true + else # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) next_word+=':start:' @@ -299,7 +305,13 @@ _zsh_highlight_main_highlighter() fi else # $arg is a non-command word case $arg in - $'\x29') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # subshell + $'\x29') # subshell or end of array assignment + if $in_array_assignment; then + style=$ZSH_HIGHLIGHT_STYLES[assign] + in_array_assignment=false + else + style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + fi;; $'\x7d') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # block '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh new file mode 100644 index 0000000..c530fda --- /dev/null +++ b/highlighters/main/test-data/assign-array.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER='(A=(hello world))' + +expected_region_highlight=( + "1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( + "2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=( + "16 16 $ZSH_HIGHLIGHT_STYLES[assign]" # ) + "17 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) +) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index ef38668..7510aba 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -32,5 +32,7 @@ BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( "1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 + "5 7 $ZSH_HIGHLIGHT_STYLES[assign]" # b=( "8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" + "17 17 $ZSH_HIGHLIGHT_STYLES[assign]" # ) ) From 3620ad951f4f2a593909d008d96bcf720f1a5d16 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 19:04:37 +0000 Subject: [PATCH 0208/1080] Add an XFail test for issue #231, "Assignment terminating subshell flags closing parenthesis as an error". --- .../main/test-data/assign-subshell.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/assign-subshell.zsh diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh new file mode 100644 index 0000000..871936f --- /dev/null +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight +BUFFER='(A=1)' + +expected_region_highlight=( + "1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( + "2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 + "5 5 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #231'" # ) +) From e1078a8b4cf19167b0a3d33c303e903c1ef733c0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 19:14:19 +0000 Subject: [PATCH 0209/1080] 'make install': Allow setting $(SHARE_DIR). --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e4fa163..a911378 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NAME=zsh-syntax-highlighting INSTALL?=install -c PREFIX?=/usr/local -SHARE_DIR=$(DESTDIR)$(PREFIX)/share/$(NAME) +SHARE_DIR?=$(DESTDIR)$(PREFIX)/share/$(NAME) ZSH?=zsh # zsh binary to run tests with # Have the default target do nothing. From b5d02a2f49e465d83f32d8cd74fde600dbe3563a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 22:31:18 +0000 Subject: [PATCH 0210/1080] tests: Document test isolation, implemented some time ago. --- tests/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index e82a64b..80525ac 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,7 +3,9 @@ zsh-syntax-highlighting / tests Utility scripts for testing zsh-syntax-highlighting highlighters. -The tests expect the highlighter directory to contain a `test-data` directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. +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. Each test should define the array parameter `$expected_region_highlight`. The value of that parameter is a list of `"$i $j $style [$todo]"` strings. @@ -13,6 +15,10 @@ If `$todo` exists, the test point is marked as TODO (the failure of that test po _Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. +**Isolation**: Each test is run in a separate subshell, so any variables, aliases, functions, etc., +it defines will be visible to the tested code (that computes `$region_highlight`), but will not affect +subsequent tests. + highlighting test ----------------- From c01533920245599e4fbc4a1825520737b2c1a6ce Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 22:54:52 +0000 Subject: [PATCH 0211/1080] tests: Provide an independent, auto-cleaned working directory to each test. Fixes zsh-users/zsh-syntax-highlighting#182. Prerequisite for testing issue #228. * tests/test-highlighting.zsh (run_test): Move functionality to run_test_internal; make run_test be a wrapper that handles creating and cleaning up the tempdir. * tests/README.md: Document the new feature. * "highlighters/main/test-data/path-space- .zsh" * highlighters/main/test-data/path-tilde-named.zsh * highlighters/main/test-data/path.zsh Change test data to not depend on being run from the source directory. --- highlighters/main/test-data/path-space- .zsh | 6 +++-- .../main/test-data/path-tilde-named.zsh | 8 ++++--- highlighters/main/test-data/path.zsh | 8 ++++--- tests/README.md | 3 ++- tests/test-highlighting.zsh | 23 +++++++++++++++++-- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/highlighters/main/test-data/path-space- .zsh b/highlighters/main/test-data/path-space- .zsh index f6b889e..7d473a7 100644 --- a/highlighters/main/test-data/path-space- .zsh +++ b/highlighters/main/test-data/path-space- .zsh @@ -27,9 +27,11 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ls highlighters/main/test-data/path-space-\ .zsh' +mkdir A +touch "A/mu with spaces" +BUFFER='ls A/mu\ with\ spaces' expected_region_highlight=( "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 48 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path-space-\ .zsh + "4 19 $ZSH_HIGHLIGHT_STYLES[path]" # A/mu\ with\ spaces ) diff --git a/highlighters/main/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index be5bb5a..235cc1c 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -27,11 +27,13 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -hash -d D=highlighters/main/test-data +mkdir mydir +touch mydir/path-tilde-named.test +hash -d D=mydir -BUFFER='ls ~D/path-tilde-named.zsh' +BUFFER='ls ~D/path-tilde-named.test' expected_region_highlight=( "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 26 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.zsh + "4 27 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.test ) diff --git a/highlighters/main/test-data/path.zsh b/highlighters/main/test-data/path.zsh index 3688b9b..29384c2 100644 --- a/highlighters/main/test-data/path.zsh +++ b/highlighters/main/test-data/path.zsh @@ -27,9 +27,11 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ls highlighters/main/test-data/path.zsh' +mkdir A +touch A/mu +BUFFER='ls A/mu' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 39 $ZSH_HIGHLIGHT_STYLES[path]" # highlighters/main/test-data/path.zsh + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "4 7 $ZSH_HIGHLIGHT_STYLES[path]" # A/mu ) diff --git a/tests/README.md b/tests/README.md index 80525ac..7b17914 100644 --- a/tests/README.md +++ b/tests/README.md @@ -17,7 +17,8 @@ _Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets **Isolation**: Each test is run in a separate subshell, so any variables, aliases, functions, etc., it defines will be visible to the tested code (that computes `$region_highlight`), but will not affect -subsequent tests. +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. highlighting test diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 1eed974..b31db05 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -55,15 +55,19 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # Runs a highlighting test # $1: data file -run_test() { +run_test_internal() { local -a highlight_zone local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use + local tests_tempdir="$1"; shift + local srcdir="$PWD" + builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! cd failed: $?"; return 1 } + echo "# ${1:t:r}" # Load the data and prepare checking it. PREBUFFER= BUFFER= ; - . "$1" + . "$srcdir"/"$1" # 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; } @@ -108,6 +112,21 @@ run_test() { done } +run_test() { + # Do not combine the declaration and initialization: «local x="$(false)"» does not set $?. + local __tests_tempdir; __tests_tempdir="$(mktemp -d)" + if [[ $? -ne 0 ]] || [[ -z $__tests_tempdir ]] || [[ ! -d $__tests_tempdir ]]; then + echo >&2 "Bail out! mktemp failed"; return 1 + fi + 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" + } +} + # Process each test data file in test data directory. integer something_failed=0 for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do From 2b35ff1c154f3d802abe2f20748e091229eee269 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 22:57:47 +0000 Subject: [PATCH 0212/1080] minor: Rename a test file to a not-escape-needing name. There's simply no reason to use such names, now that the filename is no longer itself test data. --- highlighters/main/test-data/{path-space- .zsh => path-space.zsh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename highlighters/main/test-data/{path-space- .zsh => path-space.zsh} (100%) diff --git a/highlighters/main/test-data/path-space- .zsh b/highlighters/main/test-data/path-space.zsh similarity index 100% rename from highlighters/main/test-data/path-space- .zsh rename to highlighters/main/test-data/path-space.zsh From a636527f703d0e85a6d383bdc52a41e408b2a0c8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 23:04:11 +0000 Subject: [PATCH 0213/1080] tests: Add an XFail test for issue #228, "Support the PATH_DIRS option". This builds upon the test harness auto-cleaned-up directories work (c01533920). --- .../main/test-data/option-path_dirs.zsh | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 highlighters/main/test-data/option-path_dirs.zsh diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh new file mode 100644 index 0000000..4d8ab72 --- /dev/null +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -0,0 +1,41 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +## setup +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' + +expected_region_highlight=( + "1 21 $ZSH_HIGHLIGHT_STYLES[command] 'issue #228'" # bar/testing-issue-228 +) From 96ee5116b18241216ba34369073f078a24892238 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 23:14:48 +0000 Subject: [PATCH 0214/1080] Fix issue #228, "Support the PATH_DIRS option". --- highlighters/main/main-highlighter.zsh | 21 ++++++++++++++++++- .../main/test-data/option-path_dirs.zsh | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ad622b8..571ebb6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -83,19 +83,33 @@ _zsh_highlight_main_add_region_highlight() { # Main syntax highlighting function. _zsh_highlight_main_highlighter() { + ## Before we even 'emulate -L', we must test a few options that would reset. if [[ -o interactive_comments ]]; then local interactive_comments= # set to empty fi + if [[ -o path_dirs ]]; then + integer path_dirs_was_set=1 + else + integer path_dirs_was_set=0 + fi emulate -L zsh setopt localoptions extendedglob bareglobqual + + ## Variable declarations and initializations local start_pos=0 end_pos highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW + local -a options_to_set local buf="$PREBUFFER$BUFFER" region_highlight=() + if (( path_dirs_was_set )); then + options_to_set+=( PATH_DIRS ) + fi + unset path_dirs_was_set + ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' ) @@ -239,7 +253,12 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$(LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null)" + local res="$( + if (( $#options_to_set )); then + setopt $options_to_set; + fi + LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null + )" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh index 4d8ab72..21434c4 100644 --- a/highlighters/main/test-data/option-path_dirs.zsh +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -37,5 +37,5 @@ path+=( "$PWD"/foo ) BUFFER='bar/testing-issue-228' expected_region_highlight=( - "1 21 $ZSH_HIGHLIGHT_STYLES[command] 'issue #228'" # bar/testing-issue-228 + "1 21 $ZSH_HIGHLIGHT_STYLES[command]" # bar/testing-issue-228 ) From 4f0c293fdef047cda6bb7574187f952c38643fc9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 00:05:06 +0000 Subject: [PATCH 0215/1080] cursor: Remove cursor highlighting when accepting a line. Fixes zsh-users/zsh-syntax-highlighting#109. Similar to 59fbdda64c21dd9e911329f31fbbedc69123865b in the 'main' highlighter. --- highlighters/cursor/cursor-highlighter.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index d315c62..5685c40 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -34,11 +34,15 @@ # Whether the cursor highlighter should be called or not. _zsh_highlight_cursor_highlighter_predicate() { - _zsh_highlight_cursor_moved + # accept-* may trigger removal of cursor highlighting + [[ $WIDGET == accept-* ]] || + _zsh_highlight_cursor_moved } # Cursor highlighting function. _zsh_highlight_cursor_highlighter() { + [[ $WIDGET == accept-* ]] && return + region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]") } From 28776371a0ca23a1f1c8ca45e77bff3a908b611d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 00:37:58 +0000 Subject: [PATCH 0216/1080] =?UTF-8?q?tests:=20Add=20an=20XFail=20test=20fo?= =?UTF-8?q?r=20highlighting=20=C2=AB"${foo}"=C2=BB.=20=20(Issue=20#186.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/test-data/double-quoted4.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/double-quoted4.zsh diff --git a/highlighters/main/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh new file mode 100644 index 0000000..3568321 --- /dev/null +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2011 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=( + "3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " + "4 9 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] 'issue #186'" # ${foo} + "10 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # bar" +) From 6e3720f39d84f1dca76003dd22012ecadd21d6f7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 00:37:58 +0000 Subject: [PATCH 0217/1080] =?UTF-8?q?dollar-double-quoted-argument:=20Supp?= =?UTF-8?q?ort=20the=20syntax=20=C2=AB"${foo}"=C2=BB.=20=20(Issue=20#186.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/main-highlighter.zsh | 3 +++ highlighters/main/test-data/double-quoted4.zsh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 571ebb6..861ed0f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -448,6 +448,9 @@ _zsh_highlight_main_highlighter_highlight_string() if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then (( k += $#MATCH )) # highlight the parameter name (( i += $#MATCH )) # skip past it + elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then + (( k += $#MATCH )) # highlight the parameter name and braces + (( i += $#MATCH )) # skip past it else continue fi diff --git a/highlighters/main/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh index 3568321..bec056e 100644 --- a/highlighters/main/test-data/double-quoted4.zsh +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -31,6 +31,6 @@ BUFFER=': "${foo}bar"' expected_region_highlight=( "3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " - "4 9 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] 'issue #186'" # ${foo} + "4 9 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # ${foo} "10 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # bar" ) From 8f19af6b319db6130f376f3f2a27b5b74acd0562 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 00:48:22 +0000 Subject: [PATCH 0218/1080] driver: Tolerate KSH_ARRAYS being set in the calling context. Fixes zsh-users/zsh-syntax-highlighting#162. --- zsh-syntax-highlighting.zsh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 1d63dbf..ab099bd 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -30,8 +30,8 @@ if [[ -o function_argzero ]]; then # $0 is reliable - ZSH_HIGHLIGHT_VERSION=$(<"$0:A:h"/.version) - ZSH_HIGHLIGHT_REVISION=$(<"$0:A:h"/.revision-hash) + ZSH_HIGHLIGHT_VERSION=$(<"${0:A:h}"/.version) + ZSH_HIGHLIGHT_REVISION=$(<"${0:A:h}"/.revision-hash) if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining @@ -63,6 +63,7 @@ _zsh_highlight() local ret=$? setopt localoptions warncreateglobal + setopt localoptions noksharrays 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 @@ -189,6 +190,8 @@ _zsh_highlight_call_widget() # Rebind all ZLE widgets to make them invoke _zsh_highlights. _zsh_highlight_bind_widgets() { + setopt localoptions noksharrays + # Load ZSH module zsh/zleparameter, needed to override user defined widgets. zmodload zsh/zleparameter 2>/dev/null || { echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 @@ -229,6 +232,8 @@ _zsh_highlight_bind_widgets() # 1) Path to the highlighters directory. _zsh_highlight_load_highlighters() { + setopt localoptions noksharrays + # Check the directory exists. [[ -d "$1" ]] || { echo "zsh-syntax-highlighting: highlighters directory '$1' not found." >&2 From 1397f1bae16be8848c31b1345217703384c2dae2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 01:05:05 +0000 Subject: [PATCH 0219/1080] tests: Tweak the isolation wrapper for style and robustness. Followup to c01533920245599e4fbc4a1825520737b2c1a6ce. Suggested-by: Matthew Martin --- tests/test-highlighting.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b31db05..0abf34b 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -114,14 +114,14 @@ run_test_internal() { run_test() { # Do not combine the declaration and initialization: «local x="$(false)"» does not set $?. - local __tests_tempdir; __tests_tempdir="$(mktemp -d)" - if [[ $? -ne 0 ]] || [[ -z $__tests_tempdir ]] || [[ ! -d $__tests_tempdir ]]; then + local __tests_tempdir + __tests_tempdir="$(mktemp -d)" && [[ -d $__tests_tempdir ]] || { echo >&2 "Bail out! mktemp failed"; return 1 - fi + } typeset -r __tests_tempdir # don't allow tests to override the variable that we will 'rm -rf' later on { - run_test_internal "$__tests_tempdir" "$@" + (run_test_internal "$__tests_tempdir" "$@") } always { rm -rf -- "$__tests_tempdir" } @@ -130,7 +130,7 @@ run_test() { # Process each test data file in test data directory. integer something_failed=0 for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do - (run_test "$data_file") | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) + run_test "$data_file" | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 done From bdc14497332fb3b0ab2c13987fe07fd50e3c3f1e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 01:27:38 +0000 Subject: [PATCH 0220/1080] noop: Break out a helper function. --- highlighters/main/main-highlighter.zsh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 861ed0f..d12d9bf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -80,6 +80,19 @@ _zsh_highlight_main_add_region_highlight() { region_highlight+=("$start $end $style") } +# Wrapper around 'type -w'. +# +# Takes a single argument and outputs the output of 'type -w $1'. +# +# NOTE: This runs 'setopt', but that should be safe since it'll only ever be +# called inside a $(...) subshell, so the effects will be local. +_zsh_highlight_main__type() { + if (( $#options_to_set )); then + setopt $options_to_set; + fi + LC_ALL=C builtin type -w -- $1 2>/dev/null +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -101,7 +114,7 @@ _zsh_highlight_main_highlighter() typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW - local -a options_to_set + local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" region_highlight=() @@ -253,12 +266,7 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$( - if (( $#options_to_set )); then - setopt $options_to_set; - fi - LC_ALL=C builtin type -w -- ${expanded_arg} 2>/dev/null - )" + local res="$(_zsh_highlight_main__type ${expanded_arg})" case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') From 4fcfb15913a20c955d5b22299f715be06f4c79db Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 01:33:30 +0000 Subject: [PATCH 0221/1080] Highlight parameter expansions that are a command word. Fixes zsh-users/zsh-syntax-highlighting#101. --- highlighters/main/main-highlighter.zsh | 14 ++++++++ .../main/test-data/commmand-parameter.zsh | 36 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 highlighters/main/test-data/commmand-parameter.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d12d9bf..9e8f650 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -267,6 +267,20 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" local res="$(_zsh_highlight_main__type ${expanded_arg})" + () { + # Special-case: command word is '$foo', like that, without braces or anything. + # + # 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 + if [[ $res == *': none' ]] && (( ${+parameters} )) && + [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]]; then + res="$(_zsh_highlight_main__type ${(P)MATCH})" + fi + } case $res in *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; *': suffix alias') diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh new file mode 100644 index 0000000..a2b756c --- /dev/null +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +x=/usr/bin/env +BUFFER='$x "argument"' + +expected_region_highlight=( + "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # $x + "4 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "argument" +) From 3669d69226020bd656eb71a68adb2db9428a938e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 02:02:42 +0000 Subject: [PATCH 0222/1080] Fix copyright year. --- highlighters/main/test-data/comment-leading.zsh | 2 +- highlighters/main/test-data/comment-off.zsh | 2 +- highlighters/main/test-data/comments.zsh | 2 +- highlighters/main/test-data/double-quoted2.zsh | 2 +- highlighters/main/test-data/double-quoted3.zsh | 2 +- highlighters/main/test-data/double-quoted4.zsh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh index a30af8b..d880451 100644 --- a/highlighters/main/test-data/comment-leading.zsh +++ b/highlighters/main/test-data/comment-leading.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/comment-off.zsh b/highlighters/main/test-data/comment-off.zsh index 5aa16af..9027542 100644 --- a/highlighters/main/test-data/comment-off.zsh +++ b/highlighters/main/test-data/comment-off.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index 4b9c974..e76645c 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index d3facb2..b29c884 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 6b9001c..96408fa 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 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/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh index bec056e..3355fc2 100644 --- a/highlighters/main/test-data/double-quoted4.zsh +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From 79b95c629e08ba21161621f1f710f96b420d99ba Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 02:04:23 +0000 Subject: [PATCH 0223/1080] Drop unnecessary shebang lines. Done in c30301d4745c536aee55a43aea57e5987339d492 and c687bddea311a8adc964fd91496e07150368bbfd for other tests. --- highlighters/main/test-data/comment-leading.zsh | 1 - highlighters/main/test-data/comment-off.zsh | 1 - highlighters/main/test-data/comments.zsh | 1 - 3 files changed, 3 deletions(-) diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh index d880451..d5ccdfd 100644 --- a/highlighters/main/test-data/comment-leading.zsh +++ b/highlighters/main/test-data/comment-leading.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/comment-off.zsh b/highlighters/main/test-data/comment-off.zsh index 9027542..a9a346e 100644 --- a/highlighters/main/test-data/comment-off.zsh +++ b/highlighters/main/test-data/comment-off.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index e76645c..f1b8108 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -1,4 +1,3 @@ -#!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- # Copyright (c) 2015 zsh-syntax-highlighting contributors # All rights reserved. From b1619c001390f853aff8a35efb764a11b640819d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Nov 2015 19:49:36 +0000 Subject: [PATCH 0224/1080] Fix issue #219: install documentation fully and properly. - Install the top-level README.md, which wasn't installed before. - Install docs to /usr/local/share/doc rather than /usr/local/share. --- Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a911378..29f2ce7 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ NAME=zsh-syntax-highlighting INSTALL?=install -c PREFIX?=/usr/local SHARE_DIR?=$(DESTDIR)$(PREFIX)/share/$(NAME) +DOC_DIR?=$(DESTDIR)$(PREFIX)/share/doc/$(NAME) ZSH?=zsh # zsh binary to run tests with # Have the default target do nothing. @@ -11,12 +12,23 @@ all: install: $(INSTALL) -d $(SHARE_DIR) - cp -r .version zsh-syntax-highlighting.zsh highlighters $(SHARE_DIR) + $(INSTALL) -d $(DOC_DIR) + $(INSTALL) .version zsh-syntax-highlighting.zsh $(SHARE_DIR) + $(INSTALL) COPYING.md README.md changelog.md $(DOC_DIR) if [ x"true" = x"`git rev-parse --is-inside-work-tree 2>/dev/null`" ]; then \ git rev-parse HEAD; \ else \ cat .revision-hash; \ fi > $(SHARE_DIR)/.revision-hash + : +# The [ -e ] check below is to because sh evaluates this with (the moral +# equivalent of) NONOMATCH in effect, and highlighters/*.zsh has no matches. + for dirname in highlighters highlighters/*/ ; do \ + $(INSTALL) -d "$(SHARE_DIR)/$$dirname"; \ + $(INSTALL) -d "$(DOC_DIR)/$$dirname"; \ + for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" "$(SHARE_DIR)/$$dirname"; done; \ + for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" "$(DOC_DIR)/$$dirname"; done; \ + done test: @result=0; \ From 21e5e2692344d0346e49e48e4b09a70462aab64f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:22:14 +0000 Subject: [PATCH 0225/1080] docs: Clarify 'create a new highlighter' documentation. --- highlighters/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/README.md b/highlighters/README.md index 987cc83..833b840 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -31,7 +31,7 @@ How to implement a new highlighter To create your own ***myhighlighter*** highlighter: * Create your script at **highlighters/*myhighlighter*/*myhighlighter*-highlighter.zsh**. -* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called, for example: +* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: _zsh_highlight_myhighlighter_highlighter_predicate() { # Call this highlighter in SVN repositories From 7d4252f5f59619e29ede41251184219dc560ac5d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:55:00 +0000 Subject: [PATCH 0226/1080] minor: docs: Improve dollar-double-quoted-argument documentation. --- highlighters/main/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index c748248..3b6f524 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -42,7 +42,7 @@ This highlighter defines the following styles: * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) -* `dollar-double-quoted-argument` - dollar double quoted arguments ($foo inside "") +* `dollar-double-quoted-argument` - parameter expansion inside double quotes ($foo inside "") * `back-double-quoted-argument` - back double quoted arguments (\x inside "") * `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'') * `assign` - variable assignments From 3bfd250cce8944fa3321aa715c24ac8b2e80057f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 17:50:14 +0000 Subject: [PATCH 0227/1080] 'make perf': Designate this target as '.PHONY'. Patch-by: Matthew Martin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29f2ce7..8008240 100644 --- a/Makefile +++ b/Makefile @@ -52,4 +52,4 @@ perf: done; \ exit $$result -.PHONY: all install test +.PHONY: all install test perf From 00de155063f5700dce5dafc85ecbf4e734138f4e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 18:41:14 +0000 Subject: [PATCH 0228/1080] docs: 'main': Improve styles documentation. --- highlighters/main/README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 3b6f524..9e54669 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -23,32 +23,32 @@ How to tweak it This highlighter defines the following styles: * `unknown-token` - unknown tokens / errors -* `reserved-word` - shell reserved words +* `reserved-word` - shell reserved words (`if`, `for`) * `alias` - aliases * `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) -* `builtin` - shell builtin commands -* `function` - functions -* `command` - commands -* `precommand` - precommands (i.e. exec, builtin, ...) -* `commandseparator` - command separation tokens +* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`) +* `function` - function names +* `command` - command names +* `precommand` - precommand modifiers (e.g., `noglob`, `builtin`) +* `commandseparator` - command separation tokens (`;`, `&&`) * `hashed-command` - hashed commands -* `path` - paths -* `path_prefix` - path prefixes +* `path` - existing filenames +* `path_prefix` - prefixes of existing filenames * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) -* `single-hyphen-option` - single hyphen options (-o) -* `double-hyphen-option` - double hyphen options (--option) +* `single-hyphen-option` - single hyphen options (`-o`) +* `double-hyphen-option` - double hyphen options (`--option`) * `back-quoted-argument` - backquoted expressions (`` `foo` ``) * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) -* `dollar-double-quoted-argument` - parameter expansion inside double quotes ($foo inside "") -* `back-double-quoted-argument` - back double quoted arguments (\x inside "") -* `back-dollar-quoted-argument` - back dollar quoted arguments (\x inside $'') -* `assign` - variable assignments +* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) +* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) +* `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`) +* `assign` - parameter assignments * `redirection` - redirection operators (`<`, `>`, etc) -* `comment` - interactive comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) -* `default` - parts of the buffer that do not match anything +* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `default` - everything else To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: From 2dbcb575e5a5c7ba3fecbc59831b0d20cc7c397d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 19:40:58 +0000 Subject: [PATCH 0229/1080] internal: Document the ':regular' state. --- highlighters/main/main-highlighter.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9e8f650..9192f90 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -156,7 +156,7 @@ _zsh_highlight_main_highlighter() # - :sudo_arg: The argument to a sudo leading-dash option that takes one, # when given as a separate word; i.e., "foo" in "-u foo" (two # words) but not in "-ufoo" (one word). - # - :regular: "Not a command word". + # - :regular: "Not a command word", and command delimiters are permitted. # Mainly used to detect premature termination of commands. # # When the kind of a word is not yet known, $this_word / $next_word may contain @@ -191,7 +191,10 @@ _zsh_highlight_main_highlighter() (( --in_redirection )) fi if (( in_redirection == 0 )); then + # Initialize $next_word to its default value. next_word=':regular:' + else + # Stall $next_word. fi # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, From 3ed0f7f8238ee1dc91e569e1383d245578b99b9c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 20:06:43 +0000 Subject: [PATCH 0230/1080] noop: Consolidate two identical conditionals. --- 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 9192f90..21d2ae1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -400,6 +400,7 @@ _zsh_highlight_main_highlighter() (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then next_word=':start:' + highlight_glob=true elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then @@ -413,7 +414,6 @@ _zsh_highlight_main_highlighter() # The repeat-count word will be handled like a redirection target. this_word=':start:' fi - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && highlight_glob=true start_pos=$end_pos (( in_redirection == 0 )) && this_word=$next_word done From 29fd6ec1de4ddb159915d505bb68ac491ba8e1e9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 20:19:19 +0000 Subject: [PATCH 0231/1080] Support the '|&', '&!', '&|' command separators. --- highlighters/main/main-highlighter.zsh | 4 ++++ highlighters/main/test-data/commandseparator.zsh | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 21d2ae1..c341599 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -125,6 +125,10 @@ _zsh_highlight_main_highlighter() ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' + '|&' + '&!' '&|' + # ### 'case' syntax, but followed by a pattern, not by a command + # ';;' ';&' ';|' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( 'builtin' 'command' 'exec' 'nocorrect' 'noglob' diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index 383bd47..7c152ff 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -29,9 +29,11 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight -BUFFER=':; pwd' +BUFFER=':; pwd &! ls' expected_region_highlight=( "2 2 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; "4 6 $ZSH_HIGHLIGHT_STYLES[builtin]" # pwd + "8 9 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # &! + "11 12 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) From e2096f5c4ea5a29db5b8ab50eaf0bb5317b7c76d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 18 Nov 2015 01:48:53 +0000 Subject: [PATCH 0232/1080] 'make install': Unbreak PREFIX=~/foo usage. Change quoting to only quote the shell variable, not the make variable. This allows the leading '~' to be unescaped for make's sh to expand. Followup to b1619c001390f853aff8a35efb764a11b640819d. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8008240..d9d9d11 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,10 @@ install: # The [ -e ] check below is to because sh evaluates this with (the moral # equivalent of) NONOMATCH in effect, and highlighters/*.zsh has no matches. for dirname in highlighters highlighters/*/ ; do \ - $(INSTALL) -d "$(SHARE_DIR)/$$dirname"; \ - $(INSTALL) -d "$(DOC_DIR)/$$dirname"; \ - for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" "$(SHARE_DIR)/$$dirname"; done; \ - for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" "$(DOC_DIR)/$$dirname"; done; \ + $(INSTALL) -d $(SHARE_DIR)/"$$dirname"; \ + $(INSTALL) -d $(DOC_DIR)/"$$dirname"; \ + for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" $(SHARE_DIR)"/$$dirname"; done; \ + for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" $(DOC_DIR)"/$$dirname"; done; \ done test: From 1933de83be0bbfb41c44d182fe581ad85012b71a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 18 Nov 2015 02:14:03 +0000 Subject: [PATCH 0233/1080] 'make install': Remove +x permission from installed library and documntation files. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d9d9d11..a11cce5 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ all: install: $(INSTALL) -d $(SHARE_DIR) $(INSTALL) -d $(DOC_DIR) - $(INSTALL) .version zsh-syntax-highlighting.zsh $(SHARE_DIR) - $(INSTALL) COPYING.md README.md changelog.md $(DOC_DIR) + cp .version zsh-syntax-highlighting.zsh $(SHARE_DIR) + cp COPYING.md README.md changelog.md $(DOC_DIR) if [ x"true" = x"`git rev-parse --is-inside-work-tree 2>/dev/null`" ]; then \ git rev-parse HEAD; \ else \ @@ -26,8 +26,8 @@ install: for dirname in highlighters highlighters/*/ ; do \ $(INSTALL) -d $(SHARE_DIR)/"$$dirname"; \ $(INSTALL) -d $(DOC_DIR)/"$$dirname"; \ - for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" $(SHARE_DIR)"/$$dirname"; done; \ - for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && $(INSTALL) "$$fname" $(DOC_DIR)"/$$dirname"; done; \ + for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && cp "$$fname" $(SHARE_DIR)"/$$dirname"; done; \ + for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && cp "$$fname" $(DOC_DIR)"/$$dirname"; done; \ done test: From ea5186543d02da45ea3253cf43429b7edfa6add3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 07:00:39 +0200 Subject: [PATCH 0234/1080] changelog: Update through HEAD (1933de83be0b). --- changelog.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index dbffcde..8d8855c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to c0dafd1d850e582291b41d693369794d1ea31343 +up to 1933de83be0bbfb41c44d182fe581ad85012b71a @@ -34,6 +34,28 @@ up to c0dafd1d850e582291b41d693369794d1ea31343 ( 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 + +- parameter expansions with braces inside double quotes + (#186, 6e3720f39d84) + + echo "${foo}" + +- parameter expansions in command word + (#101, 4fcfb15913a2) + + x=/bin/ls + $x -l + +- the command separators '|&', '&!', '&|' + + view file.pdf &! ls + ## Fixed highlighting of: @@ -60,6 +82,9 @@ up to c0dafd1d850e582291b41d693369794d1ea31343 (The semicolon used to be highlighted as a mistake) +- cursor highlighter: Remove the cursor highlighting when accepting a line. + (#109, 4f0c293fdef0) + ## Removed features: @@ -88,6 +113,18 @@ up to c0dafd1d850e582291b41d693369794d1ea31343 `WARN_CREATE_GLOBAL` improvements). (d3deffbf46a4) +- 'make install': Permit setting `$(SHARE_DIR)` from the environment. + (e1078a8b4cf1) + +- driver: Tolerate KSH_ARRAYS being set in the calling context. + (#162, 8f19af6b319d) + +- 'make install': Install documentation fully and properly. + (#219, b1619c001390, et seq) + +- docs: Improve 'main' highlighter's documentation. + (00de155063f5, 7d4252f5f596) + ## Developer-visible changes: @@ -112,6 +149,8 @@ up to c0dafd1d850e582291b41d693369794d1ea31343 - tests: Add 'make perf' target (4513eaea71d7) +- tests: Run each test in a sandbox directory + (c01533920245) # Changes in version 0.3.0 From 17fbcad8ac21925eae106c3d3bfcb96a4be4c8d3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Oct 2015 13:38:04 +0000 Subject: [PATCH 0235/1080] 'main': Fix state check. At this time, no user-visible consequences are known. --- 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 c341599..f9ba70b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -406,8 +406,8 @@ _zsh_highlight_main_highlighter() next_word=':start:' highlight_glob=true elif - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:' ]] || - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:' ]]; then + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] || + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then next_word=':start:' elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then # skip the repeat-count word From e60737d3208f11403a637f44c1667742ce21460b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 18 Nov 2015 17:52:46 +0000 Subject: [PATCH 0236/1080] 'make perf': Unbreak by porting over 'make test' harness changes. In particular, tests were relying on the harness to provide a sandbox working directory, but the perf harness wasn't providing that. --- tests/test-perfs.zsh | 66 ++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 0d4adc3..45a800b 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# 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 @@ -31,20 +31,20 @@ # Check an highlighter was given as argument. [[ -n "$1" ]] || { - echo "You must provide the name of a valid highlighter as argument." >&2 - exit 1 + echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." + exit 2 } # Check the highlighter is valid. [[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { - echo "Could not find highlighter '$1'." >&2 - exit 1 + echo >&2 "Bail out! Could not find highlighter '$1'." + exit 2 } # Check the highlighter has test data. [[ -d ${0:h:h}/highlighters/$1/test-data ]] || { - echo "Highlighter '$1' has no test data." >&2 - exit 1 + echo >&2 "Bail out! Highlighter '$1' has no test data." + exit 2 } # Load the main script. @@ -53,23 +53,49 @@ # Activate the highlighter. ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) -# Process each test data file in test data directory. -for data_file in ${0:h:h}/highlighters/$1/test-data/*; do +# Runs a highlighting test +# $1: data file +run_test_internal() { + local -a highlight_zone + local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use + + local tests_tempdir="$1"; shift + 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. - BUFFER= - echo -n "* ${data_file:t:r}: " - . $data_file + PREBUFFER= BUFFER= ; + . "$srcdir"/"$1" - # Check the data declares $BUFFER. - if [[ ${#BUFFER} -eq 0 ]]; then - echo "KO\n - 'BUFFER' is not declared or blank." - else + # 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) + # Measure the time taken by _zsh_highlight. + TIMEFMT="%*Es" + time (BUFFER="$BUFFER" && _zsh_highlight) +} - fi +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" + } +} + +# Process each test data file in test data directory. +for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do + run_test "$data_file" + (( $pipestatus[1] )) && exit 2 done + +exit 0 From 6c033e62e902907bfdf0560f0a321beda19df45f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 02:54:53 +0000 Subject: [PATCH 0237/1080] docs copyedit: Whitespace. --- changelog.md | 2 +- highlighters/brackets/README.md | 2 ++ highlighters/cursor/README.md | 2 ++ highlighters/line/README.md | 2 ++ highlighters/main/README.md | 2 ++ highlighters/pattern/README.md | 2 ++ highlighters/root/README.md | 2 ++ tests/README.md | 2 ++ 8 files changed, 15 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 8d8855c..ad0a0f5 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,7 @@ up to 1933de83be0bbfb41c44d182fe581ad85012b71a -# Changes in version 0.3.1 +# Changes in version 0.3.1 ## Added highlighting of: diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 9fd4f96..1df11c1 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -6,6 +6,7 @@ This is the ***brackets*** highlighter, that highlights brackets, parenthesis an How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] brackets) @@ -13,6 +14,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- + This highlighter defines the following styles: * `bracket-error` - unmatched brackets diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index d28ac19..1cd530f 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -6,6 +6,7 @@ This is the ***cursor*** highlighter, that highlights the cursor. How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] cursor) @@ -13,6 +14,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- + This highlighter defines the following styles: * `cursor` - the style for the current cursor position diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 2be32a2..3a7956f 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -6,6 +6,7 @@ This is the ***line*** highlighter, that highlights the whole line. How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line) @@ -13,6 +14,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- + This highlighter defines the following styles: * `line` - the style for the whole line diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 9e54669..76826aa 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -11,6 +11,7 @@ This is the ***main*** highlighter, that highlights: How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] main) @@ -20,6 +21,7 @@ This highlighter is active by default. How to tweak it --------------- + This highlighter defines the following styles: * `unknown-token` - unknown tokens / errors diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 82a7c65..4e820b3 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -6,6 +6,7 @@ This is the ***pattern*** highlighter, that highlights user defined patterns. How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] pattern) @@ -13,6 +14,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- + To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: # To have commands starting with `rm -rf` in red: diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 53c871b..870f205 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -6,6 +6,7 @@ This is the ***root*** highlighter, that highlights the whole line if the curren How to activate it ------------------ + To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] root) @@ -13,6 +14,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- + This highlighter defines the following styles: * `root` - the style for the whole line if the current user is root. diff --git a/tests/README.md b/tests/README.md index 7b17914..afdf0c0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,6 +23,7 @@ which is automatically cleaned up after the test exits. highlighting test ----------------- + [`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage: zsh test-highlighting.zsh @@ -36,6 +37,7 @@ which will run all highlighting tests and report results in [TAP](http://testany performance test ---------------- + [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: zsh test-perfs.zsh From 91e4a576fbe064aceb12dee8cc96349dd92cf867 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 02:56:39 +0000 Subject: [PATCH 0238/1080] docs copyedit: Port 6d93ea07fd61 to the other highlighters' README's. --- highlighters/brackets/README.md | 3 ++- highlighters/cursor/README.md | 3 ++- highlighters/line/README.md | 3 ++- highlighters/pattern/README.md | 3 ++- highlighters/root/README.md | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 1df11c1..440e187 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -29,4 +29,5 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold' ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold' -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index 1cd530f..8e00286 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -23,4 +23,5 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 3a7956f..cc942f2 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -23,4 +23,5 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for ZSH_HIGHLIGHT_STYLES[line]='bold' -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 4e820b3..5f9cac1 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -20,4 +20,5 @@ To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PA # To have commands starting with `rm -rf` in red: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 870f205..3bfb6cf 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -23,4 +23,5 @@ To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for ZSH_HIGHLIGHT_STYLES[root]='bg=red' -The syntax for declaring styles is [documented here](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). From 8ea392e3611c193d8c2a9ed6a976ff07ce513ac1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:00:50 +0000 Subject: [PATCH 0239/1080] docs copyedit: Restyle bold-italic to fixed-width. --- highlighters/README.md | 16 ++++++++-------- highlighters/brackets/README.md | 2 +- highlighters/cursor/README.md | 2 +- highlighters/line/README.md | 2 +- highlighters/main/README.md | 2 +- highlighters/pattern/README.md | 2 +- highlighters/root/README.md | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/highlighters/README.md b/highlighters/README.md index 833b840..00eb2bd 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -3,12 +3,12 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* [***main***](main) - the base highlighter, and the only one active by default. -* [***brackets***](brackets) - matches brackets and parenthesis. -* [***pattern***](pattern) - matches user-defined patterns. -* [***cursor***](cursor) - matches the cursor position. -* [***root***](root) - triggered if the current user is root. -* [***line***](line) - applied to the whole command line +* [`main`](main) - the base highlighter, and the only one active by default. +* [`brackets`](brackets) - matches brackets and parenthesis. +* [`pattern`](pattern) - matches user-defined patterns. +* [`cursor`](cursor) - matches the cursor position. +* [`root`](root) - triggered if the current user is root. +* [`line`](line) - applied to the whole command line How to activate highlighters @@ -28,9 +28,9 @@ Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. Navigate into How to implement a new highlighter ---------------------------------- -To create your own ***myhighlighter*** highlighter: +To create your own `myhighlighter` highlighter: -* Create your script at **highlighters/*myhighlighter*/*myhighlighter*-highlighter.zsh**. +* Create your script at `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. * Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: _zsh_highlight_myhighlighter_highlighter_predicate() { diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 440e187..d08097e 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / brackets ================================================= -This is the ***brackets*** highlighter, that highlights brackets, parenthesis and matches them. +This is the `brackets` highlighter, that highlights brackets, parenthesis and matches them. How to activate it diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index 8e00286..35fa8bd 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / cursor ================================================= -This is the ***cursor*** highlighter, that highlights the cursor. +This is the `cursor` highlighter, that highlights the cursor. How to activate it diff --git a/highlighters/line/README.md b/highlighters/line/README.md index cc942f2..6cdda00 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / line ================================================= -This is the ***line*** highlighter, that highlights the whole line. +This is the `line` highlighter, that highlights the whole line. How to activate it diff --git a/highlighters/main/README.md b/highlighters/main/README.md index 76826aa..b128a7a 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / main ============================================= -This is the ***main*** highlighter, that highlights: +This is the `main` highlighter, that highlights: * Commands * Options diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 5f9cac1..8bdf929 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / pattern ================================================ -This is the ***pattern*** highlighter, that highlights user defined patterns. +This is the `pattern` highlighter, that highlights user defined patterns. How to activate it diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 3bfb6cf..d9fb17a 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / root ================================================= -This is the ***root*** highlighter, that highlights the whole line if the current user is root. +This is the `root` highlighter, that highlights the whole line if the current user is root. How to activate it From 12097d55d13c056657f9e0b6f4e3a4ff5d5f5fa8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0240/1080] docs copyedit: Rewrap to 80 columns. --- highlighters/README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/highlighters/README.md b/highlighters/README.md index 00eb2bd..42de77e 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -22,7 +22,9 @@ To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in How to tweak highlighters ------------------------- -Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. Navigate into each highlighter directory to see what styles it defines and how to configure it. +Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. +Navigate into each highlighter directory to see what styles it defines +and how to configure it. How to implement a new highlighter @@ -31,14 +33,19 @@ How to implement a new highlighter To create your own `myhighlighter` highlighter: * Create your script at `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. -* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: + +* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. + This function must return 0 when the highlighter needs to be called and + non-zero otherwise, for example: _zsh_highlight_myhighlighter_highlighter_predicate() { # Call this highlighter in SVN repositories [[ -d .svn ]] } -* Implement the `_zsh_highlight_myhighlighter_highlighter` function. This function does the actual syntax highlighting, by modifying `region_highlight`, for example: +* Implement the `_zsh_highlight_myhighlighter_highlighter` function. + This function does the actual syntax highlighting, by modifying + `region_highlight`, for example: _zsh_highlight_myhighlighter_highlighter() { # Colorize the whole buffer with blue background From 49f7beecb5b78f0ba8b7cb045d0986312a69d533 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0241/1080] docs copyedit: Review toplevel and tests README.md files. --- README.md | 37 +++++++++++++++++++++++++++---------- tests/README.md | 8 +++++--- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d7fc4ad..35e6f4c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting ======================= -**[Fish shell](http://www.fishshell.com) like syntax highlighting for [Zsh](http://www.zsh.org).** +**[Fish shell](http://www.fishshell.com) like syntax highlighting for Zsh.** *Requirements: zsh 4.3.17+.* @@ -18,9 +18,15 @@ How to install ### Using packages -* Arch Linux: [community/zsh-syntax-highlighting](https://www.archlinux.org/packages/zsh-syntax-highlighting) / [AUR/zsh-syntax-highlighting-git](https://aur.archlinux.org/packages/zsh-syntax-highlighting-git) -* Gentoo: [mv overlay](http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting) -* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting](https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb) +* Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] +* Gentoo: [mv overlay][gentoo-overlay] +* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] + +[arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting +[AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git +[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting +[brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb + ### In your ~/.zshrc @@ -28,7 +34,10 @@ How to install git clone git://github.com/zsh-users/zsh-syntax-highlighting.git - (or [download a snapshot](https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz)) + If `git` is not installed, you could download a snapshot of the latest + development tree from: + + https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz * Source the script **at the end** of `~/.zshrc`: @@ -41,21 +50,27 @@ How to install ### With oh-my-zsh -* Download the script or clone this repository in [oh-my-zsh](http://github.com/robbyrussell/oh-my-zsh) plugins directory: +Oh-my-zsh is a zsh configuration framework. It lives at +. + +To install zsh-syntax-highlighting under oh-my-zsh: + +1. Download the script or clone this repository in oh-my-zsh's plugins directory: git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting -* Activate the plugin in `~/.zshrc`: +2. Activate the plugin in `~/.zshrc`: plugins=( [plugins...] zsh-syntax-highlighting) -* Source `~/.zshrc` to take changes into account: +3. Source `~/.zshrc` to take changes into account: source ~/.zshrc Note that `zsh-syntax-highlighting` must be the last plugin sourced, so make it the last element of the `$plugins` array. + ### System-wide installation Either of the above methods is suitable for a single-user installation, which requires @@ -82,8 +97,10 @@ There is currently no "push" announcements channel. However, the following alte - GitHub's RSS feed of releases: https://github.com/zsh-users/zsh-syntax-highlighting/releases.atom - An anitya entry: https://release-monitoring.org/project/7552/ + How to tweak ------------ -Syntax highlighting is done by pluggable highlighter scripts, see the [highlighters directory](highlighters) -for documentation and configuration settings. +Syntax highlighting is done by pluggable highlighter scripts. See the +[`highlighters` directory](./highlighters) for documentation and configuration +settings. diff --git a/tests/README.md b/tests/README.md index afdf0c0..324d9ad 100644 --- a/tests/README.md +++ b/tests/README.md @@ -8,12 +8,14 @@ directory with test data files. See the [main highlighter](../highlighters/main/test-data) for examples. Each test should define the array parameter `$expected_region_highlight`. -The value of that parameter is a list of `"$i $j $style [$todo]"` strings. +The value of that parameter is a list of strings of the form `"$i $j $style"`. +or `"$i $j $style $todo"`. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. -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 `$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. -_Note_: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. +**Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. **Isolation**: Each test is run in a separate subshell, so any variables, aliases, functions, etc., it defines will be visible to the tested code (that computes `$region_highlight`), but will not affect From 9ce97cd64d4133cc36ff56259d8db374056e30c5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:25:03 +0000 Subject: [PATCH 0242/1080] docs copyedit: minor. --- highlighters/cursor/README.md | 2 +- highlighters/line/README.md | 2 +- highlighters/root/README.md | 2 +- tests/README.md | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index 35fa8bd..eb65d6f 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -1,5 +1,5 @@ zsh-syntax-highlighting / highlighters / cursor -================================================= +=============================================== This is the `cursor` highlighter, that highlights the cursor. diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 6cdda00..88d418b 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -1,5 +1,5 @@ zsh-syntax-highlighting / highlighters / line -================================================= +============================================= This is the `line` highlighter, that highlights the whole line. diff --git a/highlighters/root/README.md b/highlighters/root/README.md index d9fb17a..4f2535a 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -1,5 +1,5 @@ zsh-syntax-highlighting / highlighters / root -================================================= +============================================= This is the `root` highlighter, that highlights the whole line if the current user is root. diff --git a/tests/README.md b/tests/README.md index 324d9ad..6212c59 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,7 +23,7 @@ subsequent tests. The current working directory of tests is set to a newly-crea which is automatically cleaned up after the test exits. -highlighting test +Highlighting test ----------------- [`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage: @@ -37,7 +37,7 @@ All tests may be run with which will run all highlighting tests and report results in [TAP](http://testanything.org/) format. -performance test +Performance test ---------------- [`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: From 3bedd8571ed7bd013b2765af74f9b317a40b5b10 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:47:11 +0000 Subject: [PATCH 0243/1080] docs copyedit: Clarify tagline. Restore zsh URL removed a few commits ago. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 35e6f4c..5ffa82c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ zsh-syntax-highlighting ======================= -**[Fish shell](http://www.fishshell.com) like syntax highlighting for Zsh.** +**[Fish shell][fish]-like like syntax highlighting for [Zsh][zsh].** *Requirements: zsh 4.3.17+.* +[fish]: http://www.fishshell.com/ +[zsh]: http://www.zsh.org/ + This package provides syntax highlighing for the shell zsh. It enables highlighing of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running From 3f163a2fd4a7c9598a48f08e577a42a82f3ad9b0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0244/1080] docs copyedit: Rewrap to 80 columns, part 2. --- README.md | 12 +++++++----- highlighters/README.md | 6 ++++-- highlighters/brackets/README.md | 6 ++++-- highlighters/cursor/README.md | 3 ++- highlighters/line/README.md | 3 ++- highlighters/main/README.md | 3 ++- highlighters/pattern/README.md | 3 ++- highlighters/root/README.md | 6 ++++-- tests/README.md | 16 ++++++++++------ 9 files changed, 37 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5ffa82c..679c2ed 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,11 @@ so make it the last element of the `$plugins` array. ### System-wide installation -Either 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` and directing your users to -add `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +Either 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` +and directing your users to add + `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` in their `.zshrc`s. @@ -95,7 +96,8 @@ syntax highlighting. ### How are new releases announced? -There is currently no "push" announcements channel. However, the following alternatives exist: +There is currently no "push" announcements channel. However, the following +alternatives exist: - GitHub's RSS feed of releases: https://github.com/zsh-users/zsh-syntax-highlighting/releases.atom - An anitya entry: https://release-monitoring.org/project/7552/ diff --git a/highlighters/README.md b/highlighters/README.md index 42de77e..0d104cd 100644 --- a/highlighters/README.md +++ b/highlighters/README.md @@ -14,7 +14,8 @@ Syntax highlighting is done by pluggable highlighters: How to activate highlighters ---------------------------- -To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in `~/.zshrc`, for example: +To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in +`~/.zshrc`, for example: ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) @@ -32,7 +33,8 @@ How to implement a new highlighter To create your own `myhighlighter` highlighter: -* Create your script at `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. +* Create your script at + `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. * Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index d08097e..860bc5b 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -1,7 +1,8 @@ zsh-syntax-highlighting / highlighters / brackets ================================================= -This is the `brackets` highlighter, that highlights brackets, parenthesis and matches them. +This is the `brackets` highlighter, that highlights brackets, parenthesis and +matches them. How to activate it @@ -21,7 +22,8 @@ This highlighter defines the following styles: * `bracket-level-N` - brackets with nest level N * `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: +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' diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index eb65d6f..470dd0d 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -19,7 +19,8 @@ This highlighter defines the following styles: * `cursor` - the style for the current cursor position -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 88d418b..781cf26 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -19,7 +19,8 @@ This highlighter defines the following styles: * `line` - the style for the whole line -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[line]='bold' diff --git a/highlighters/main/README.md b/highlighters/main/README.md index b128a7a..d450ed9 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -52,7 +52,8 @@ This highlighter defines the following styles: * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) * `default` - everything else -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: +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 diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 8bdf929..75290f4 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -15,7 +15,8 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: How to tweak it --------------- -To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: +To use this highlighter, associate patterns with styles in the +`ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: # To have commands starting with `rm -rf` in red: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 4f2535a..8592ef7 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -1,7 +1,8 @@ zsh-syntax-highlighting / highlighters / root ============================================= -This is the `root` highlighter, that highlights the whole line if the current user is root. +This is the `root` highlighter, that highlights the whole line if the current +user is root. How to activate it @@ -19,7 +20,8 @@ This highlighter defines the following styles: * `root` - the style for the whole line if the current user is root. -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, for example in `~/.zshrc`: +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[root]='bg=red' diff --git a/tests/README.md b/tests/README.md index 6212c59..ea3717a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,18 +15,21 @@ that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. 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. -**Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. +**Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but +interprets the indexes differently. -**Isolation**: Each test is run in a separate subshell, so any variables, aliases, functions, etc., -it defines will be visible to the tested code (that computes `$region_highlight`), but will not affect -subsequent tests. The current working directory of tests is set to a newly-created empty directory, +**Isolation**: Each test is run in a separate subshell, so any variables, +aliases, functions, etc., it defines will be visible to the tested code (that +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. Highlighting test ----------------- -[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of the highlighting. Usage: +[`test-highlighting.zsh`](tests/test-highlighting.zsh) tests the correctness of +the highlighting. Usage: zsh test-highlighting.zsh @@ -40,7 +43,8 @@ which will run all highlighting tests and report results in [TAP](http://testany Performance test ---------------- -[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the highlighting. Usage: +[`test-perfs.zsh`](tests/test-perfs.zsh) measures the time spent doing the +highlighting. Usage: zsh test-perfs.zsh From b989ae23d02e24867f059c7c74c86ce27e12b274 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0245/1080] docs copyedit: Rewrap to 80 columns, part 3. --- tests/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index ea3717a..faaed1e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -37,7 +37,9 @@ All tests may be run with make test -which will run all highlighting tests and report results in [TAP](http://testanything.org/) format. +which will run all highlighting tests and report results in [TAP format][TAP]. + +[TAP]: http://testanything.org/ Performance test From bcc9db27840f3354b807eb26b5a865c1258e7e41 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0246/1080] docs copyedit: Rewrap to 80 columns, part 4. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 679c2ed..59919f6 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Oh-my-zsh is a zsh configuration framework. It lives at To install zsh-syntax-highlighting under oh-my-zsh: -1. Download the script or clone this repository in oh-my-zsh's plugins directory: +1. Clone this repository in oh-my-zsh's plugins directory: git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting From 6e99128987ee3a2629fda6302e27f2eaac43ab5f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 17 Nov 2015 03:02:39 +0000 Subject: [PATCH 0247/1080] docs copyedit: minor: Spelling/punctuation fix. --- highlighters/brackets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 860bc5b..4bb37f4 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / brackets ================================================= -This is the `brackets` highlighter, that highlights brackets, parenthesis and +This is the `brackets` highlighter, that highlights brackets and parentheses, and matches them. From 2dd6923c30aee2e5984a01d08d22382791280dcf Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 16 Nov 2015 23:44:47 -0600 Subject: [PATCH 0248/1080] docs: Move highlighter headers down one level --- highlighters/brackets/README.md | 8 +++----- highlighters/cursor/README.md | 8 +++----- highlighters/line/README.md | 8 +++----- highlighters/main/README.md | 8 +++----- highlighters/pattern/README.md | 8 +++----- highlighters/root/README.md | 8 +++----- 6 files changed, 18 insertions(+), 30 deletions(-) diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 4bb37f4..2865905 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -1,20 +1,18 @@ zsh-syntax-highlighting / highlighters / brackets -================================================= +------------------------------------------------- This is the `brackets` highlighter, that highlights brackets and parentheses, and matches them. -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] brackets) -How to tweak it ---------------- +### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index 470dd0d..fcfb6f6 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -1,19 +1,17 @@ zsh-syntax-highlighting / highlighters / cursor -=============================================== +----------------------------------------------- This is the `cursor` highlighter, that highlights the cursor. -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] cursor) -How to tweak it ---------------- +### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 781cf26..dc6c35f 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -1,19 +1,17 @@ zsh-syntax-highlighting / highlighters / line -============================================= +--------------------------------------------- This is the `line` highlighter, that highlights the whole line. -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line) -How to tweak it ---------------- +### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/main/README.md b/highlighters/main/README.md index d450ed9..e28f5f3 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -1,5 +1,5 @@ zsh-syntax-highlighting / highlighters / main -============================================= +--------------------------------------------- This is the `main` highlighter, that highlights: @@ -9,8 +9,7 @@ This is the `main` highlighter, that highlights: * Paths * Strings -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: @@ -19,8 +18,7 @@ To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: This highlighter is active by default. -How to tweak it ---------------- +### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 75290f4..0b7e099 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -1,19 +1,17 @@ zsh-syntax-highlighting / highlighters / pattern -================================================ +------------------------------------------------ This is the `pattern` highlighter, that highlights user defined patterns. -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] pattern) -How to tweak it ---------------- +### How to tweak it To use this highlighter, associate patterns with styles in the `ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 8592ef7..c1906be 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -1,20 +1,18 @@ zsh-syntax-highlighting / highlighters / root -============================================= +--------------------------------------------- This is the `root` highlighter, that highlights the whole line if the current user is root. -How to activate it ------------------- +### How to activate it To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] root) -How to tweak it ---------------- +### How to tweak it This highlighter defines the following styles: From 35e0b0ca69cc734d5108baff5fa88e25284f6b84 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 16 Nov 2015 23:48:17 -0600 Subject: [PATCH 0249/1080] docs: Remove duplicate 'How to activate it' sections --- highlighters/brackets/README.md | 7 ------- highlighters/cursor/README.md | 7 ------- highlighters/line/README.md | 7 ------- highlighters/main/README.md | 6 ------ highlighters/pattern/README.md | 7 ------- highlighters/root/README.md | 7 ------- 6 files changed, 41 deletions(-) diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index 2865905..df47d8c 100644 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -5,13 +5,6 @@ This is the `brackets` highlighter, that highlights brackets and parentheses, an matches them. -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] brackets) - - ### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index fcfb6f6..3ff6c8e 100644 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -4,13 +4,6 @@ zsh-syntax-highlighting / highlighters / cursor This is the `cursor` highlighter, that highlights the cursor. -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] cursor) - - ### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/line/README.md b/highlighters/line/README.md index dc6c35f..ac69f68 100644 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -4,13 +4,6 @@ zsh-syntax-highlighting / highlighters / line This is the `line` highlighter, that highlights the whole line. -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] line) - - ### How to tweak it This highlighter defines the following styles: diff --git a/highlighters/main/README.md b/highlighters/main/README.md index e28f5f3..bbf87ce 100644 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -9,12 +9,6 @@ This is the `main` highlighter, that highlights: * Paths * Strings -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] main) - This highlighter is active by default. diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index 0b7e099..b0b2b90 100644 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -4,13 +4,6 @@ zsh-syntax-highlighting / highlighters / pattern This is the `pattern` highlighter, that highlights user defined patterns. -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] pattern) - - ### How to tweak it To use this highlighter, associate patterns with styles in the diff --git a/highlighters/root/README.md b/highlighters/root/README.md index c1906be..0b1f217 100644 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -5,13 +5,6 @@ This is the `root` highlighter, that highlights the whole line if the current user is root. -### How to activate it - -To activate it, add it to `ZSH_HIGHLIGHT_HIGHLIGHTERS`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS=( [...] root) - - ### How to tweak it This highlighter defines the following styles: From 0ab450ae47ef01d9f6d27318f253edddc3899ca1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 17 Nov 2015 21:11:09 -0600 Subject: [PATCH 0250/1080] docs: Move docs into docs/ --- docs/highlighters.md | 59 ++++++++++++++++++++++++++++++ docs/highlighters/brackets.md | 26 ++++++++++++++ docs/highlighters/cursor.md | 19 ++++++++++ docs/highlighters/line.md | 19 ++++++++++ docs/highlighters/main.md | 63 ++++++++++++++++++++++++++++++++ docs/highlighters/pattern.md | 16 +++++++++ docs/highlighters/root.md | 20 +++++++++++ highlighters/README.md | 60 +------------------------------ highlighters/brackets/README.md | 27 +------------- highlighters/cursor/README.md | 20 +---------- highlighters/line/README.md | 20 +---------- highlighters/main/README.md | 64 +-------------------------------- highlighters/pattern/README.md | 17 +-------- highlighters/root/README.md | 21 +---------- 14 files changed, 229 insertions(+), 222 deletions(-) create mode 100644 docs/highlighters.md create mode 100644 docs/highlighters/brackets.md create mode 100644 docs/highlighters/cursor.md create mode 100644 docs/highlighters/line.md create mode 100644 docs/highlighters/main.md create mode 100644 docs/highlighters/pattern.md create mode 100644 docs/highlighters/root.md mode change 100644 => 120000 highlighters/README.md mode change 100644 => 120000 highlighters/brackets/README.md mode change 100644 => 120000 highlighters/cursor/README.md mode change 100644 => 120000 highlighters/line/README.md mode change 100644 => 120000 highlighters/main/README.md mode change 100644 => 120000 highlighters/pattern/README.md mode change 100644 => 120000 highlighters/root/README.md diff --git a/docs/highlighters.md b/docs/highlighters.md new file mode 100644 index 0000000..cc56f4e --- /dev/null +++ b/docs/highlighters.md @@ -0,0 +1,59 @@ +zsh-syntax-highlighting / highlighters +====================================== + +Syntax highlighting is done by pluggable highlighters: + +* [`main`](highlighters/main.md) - the base highlighter, and the only one active by default. +* [`brackets`](highlighters/brackets.md) - matches brackets and parenthesis. +* [`pattern`](highlighters/pattern.md) - matches user-defined patterns. +* [`cursor`](highlighters/cursor.md) - matches the cursor position. +* [`root`](highlighters/root.md) - triggered if the current user is root. +* [`line`](highlighters/line.md) - applied to the whole command line + + +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) + + +How to tweak highlighters +------------------------- + +Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. +Navigate into each highlighter directory to see what styles it defines +and how to configure it. + + +How to implement a new highlighter +---------------------------------- + +To create your own `myhighlighter` highlighter: + +* Create your script at + `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. + +* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. + This function must return 0 when the highlighter needs to be called and + non-zero otherwise, for example: + + _zsh_highlight_myhighlighter_highlighter_predicate() { + # Call this highlighter in SVN repositories + [[ -d .svn ]] + } + +* Implement the `_zsh_highlight_myhighlighter_highlighter` function. + This function does the actual syntax highlighting, by modifying + `region_highlight`, for example: + + _zsh_highlight_myhighlighter_highlighter() { + # Colorize the whole buffer with blue background + region_highlight+=(0 $#BUFFER bg=blue) + } + +* Activate your highlighter in `~/.zshrc`: + + ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) diff --git a/docs/highlighters/brackets.md b/docs/highlighters/brackets.md new file mode 100644 index 0000000..df47d8c --- /dev/null +++ b/docs/highlighters/brackets.md @@ -0,0 +1,26 @@ +zsh-syntax-highlighting / highlighters / brackets +------------------------------------------------- + +This is the `brackets` highlighter, that highlights brackets and parentheses, and +matches them. + + +### How to tweak it + +This highlighter defines the following styles: + +* `bracket-error` - unmatched brackets +* `bracket-level-N` - brackets with nest level N +* `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket + +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' + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/docs/highlighters/cursor.md b/docs/highlighters/cursor.md new file mode 100644 index 0000000..3ff6c8e --- /dev/null +++ b/docs/highlighters/cursor.md @@ -0,0 +1,19 @@ +zsh-syntax-highlighting / highlighters / cursor +----------------------------------------------- + +This is the `cursor` highlighter, that highlights the cursor. + + +### How to tweak it + +This highlighter defines the following styles: + +* `cursor` - the style for the current cursor position + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/docs/highlighters/line.md b/docs/highlighters/line.md new file mode 100644 index 0000000..ac69f68 --- /dev/null +++ b/docs/highlighters/line.md @@ -0,0 +1,19 @@ +zsh-syntax-highlighting / highlighters / line +--------------------------------------------- + +This is the `line` highlighter, that highlights the whole line. + + +### How to tweak it + +This highlighter defines the following styles: + +* `line` - the style for the whole line + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[line]='bold' + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md new file mode 100644 index 0000000..bbf87ce --- /dev/null +++ b/docs/highlighters/main.md @@ -0,0 +1,63 @@ +zsh-syntax-highlighting / highlighters / main +--------------------------------------------- + +This is the `main` highlighter, that highlights: + +* Commands +* Options +* Arguments +* Paths +* Strings + +This highlighter is active by default. + + +### How to tweak it + +This highlighter defines the following styles: + +* `unknown-token` - unknown tokens / errors +* `reserved-word` - shell reserved words (`if`, `for`) +* `alias` - aliases +* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) +* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`) +* `function` - function names +* `command` - command names +* `precommand` - precommand modifiers (e.g., `noglob`, `builtin`) +* `commandseparator` - command separation tokens (`;`, `&&`) +* `hashed-command` - hashed commands +* `path` - existing filenames +* `path_prefix` - prefixes of existing filenames +* `globbing` - globbing expressions (`*.txt`) +* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) +* `single-hyphen-option` - single hyphen options (`-o`) +* `double-hyphen-option` - double hyphen options (`--option`) +* `back-quoted-argument` - backquoted expressions (`` `foo` ``) +* `single-quoted-argument` - single quoted arguments (`` 'foo' ``) +* `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) +* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) +* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) +* `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`) +* `assign` - parameter assignments +* `redirection` - redirection operators (`<`, `>`, etc) +* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `default` - everything else + +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 + + # 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 declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md new file mode 100644 index 0000000..b0b2b90 --- /dev/null +++ b/docs/highlighters/pattern.md @@ -0,0 +1,16 @@ +zsh-syntax-highlighting / highlighters / pattern +------------------------------------------------ + +This is the `pattern` highlighter, that highlights user defined patterns. + + +### How to tweak it + +To use this highlighter, associate patterns with styles in the +`ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: + + # To have commands starting with `rm -rf` in red: + ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/docs/highlighters/root.md b/docs/highlighters/root.md new file mode 100644 index 0000000..0b1f217 --- /dev/null +++ b/docs/highlighters/root.md @@ -0,0 +1,20 @@ +zsh-syntax-highlighting / highlighters / root +--------------------------------------------- + +This is the `root` highlighter, that highlights the whole line if the current +user is root. + + +### How to tweak it + +This highlighter defines the following styles: + +* `root` - the style for the whole line if the current user is root. + +To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, +for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_STYLES[root]='bg=red' + +The syntax for declaring styles is documented in [the `zshzle(1)` manual +page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/README.md b/highlighters/README.md deleted file mode 100644 index 0d104cd..0000000 --- a/highlighters/README.md +++ /dev/null @@ -1,59 +0,0 @@ -zsh-syntax-highlighting / highlighters -====================================== - -Syntax highlighting is done by pluggable highlighters: - -* [`main`](main) - the base highlighter, and the only one active by default. -* [`brackets`](brackets) - matches brackets and parenthesis. -* [`pattern`](pattern) - matches user-defined patterns. -* [`cursor`](cursor) - matches the cursor position. -* [`root`](root) - triggered if the current user is root. -* [`line`](line) - applied to the whole command line - - -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) - - -How to tweak highlighters -------------------------- - -Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. -Navigate into each highlighter directory to see what styles it defines -and how to configure it. - - -How to implement a new highlighter ----------------------------------- - -To create your own `myhighlighter` highlighter: - -* Create your script at - `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. - -* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. - This function must return 0 when the highlighter needs to be called and - non-zero otherwise, for example: - - _zsh_highlight_myhighlighter_highlighter_predicate() { - # Call this highlighter in SVN repositories - [[ -d .svn ]] - } - -* Implement the `_zsh_highlight_myhighlighter_highlighter` function. - This function does the actual syntax highlighting, by modifying - `region_highlight`, for example: - - _zsh_highlight_myhighlighter_highlighter() { - # Colorize the whole buffer with blue background - region_highlight+=(0 $#BUFFER bg=blue) - } - -* Activate your highlighter in `~/.zshrc`: - - ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) diff --git a/highlighters/README.md b/highlighters/README.md new file mode 120000 index 0000000..7b048c0 --- /dev/null +++ b/highlighters/README.md @@ -0,0 +1 @@ +../docs/highlighters.md \ No newline at end of file diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md deleted file mode 100644 index df47d8c..0000000 --- a/highlighters/brackets/README.md +++ /dev/null @@ -1,26 +0,0 @@ -zsh-syntax-highlighting / highlighters / brackets -------------------------------------------------- - -This is the `brackets` highlighter, that highlights brackets and parentheses, and -matches them. - - -### How to tweak it - -This highlighter defines the following styles: - -* `bracket-error` - unmatched brackets -* `bracket-level-N` - brackets with nest level N -* `cursor-matchingbracket` - the matching bracket, if cursor is on a bracket - -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' - -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md new file mode 120000 index 0000000..d8f3a5a --- /dev/null +++ b/highlighters/brackets/README.md @@ -0,0 +1 @@ +../docs/highlighters/brackets.md \ No newline at end of file diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md deleted file mode 100644 index 3ff6c8e..0000000 --- a/highlighters/cursor/README.md +++ /dev/null @@ -1,19 +0,0 @@ -zsh-syntax-highlighting / highlighters / cursor ------------------------------------------------ - -This is the `cursor` highlighter, that highlights the cursor. - - -### How to tweak it - -This highlighter defines the following styles: - -* `cursor` - the style for the current cursor position - -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, -for example in `~/.zshrc`: - - ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' - -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md new file mode 120000 index 0000000..13f58ef --- /dev/null +++ b/highlighters/cursor/README.md @@ -0,0 +1 @@ +../docs/highlighters/cursor.md \ No newline at end of file diff --git a/highlighters/line/README.md b/highlighters/line/README.md deleted file mode 100644 index ac69f68..0000000 --- a/highlighters/line/README.md +++ /dev/null @@ -1,19 +0,0 @@ -zsh-syntax-highlighting / highlighters / line ---------------------------------------------- - -This is the `line` highlighter, that highlights the whole line. - - -### How to tweak it - -This highlighter defines the following styles: - -* `line` - the style for the whole line - -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, -for example in `~/.zshrc`: - - ZSH_HIGHLIGHT_STYLES[line]='bold' - -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/line/README.md b/highlighters/line/README.md new file mode 120000 index 0000000..80edd29 --- /dev/null +++ b/highlighters/line/README.md @@ -0,0 +1 @@ +../docs/highlighters/line.md \ No newline at end of file diff --git a/highlighters/main/README.md b/highlighters/main/README.md deleted file mode 100644 index bbf87ce..0000000 --- a/highlighters/main/README.md +++ /dev/null @@ -1,63 +0,0 @@ -zsh-syntax-highlighting / highlighters / main ---------------------------------------------- - -This is the `main` highlighter, that highlights: - -* Commands -* Options -* Arguments -* Paths -* Strings - -This highlighter is active by default. - - -### How to tweak it - -This highlighter defines the following styles: - -* `unknown-token` - unknown tokens / errors -* `reserved-word` - shell reserved words (`if`, `for`) -* `alias` - aliases -* `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer) -* `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`) -* `function` - function names -* `command` - command names -* `precommand` - precommand modifiers (e.g., `noglob`, `builtin`) -* `commandseparator` - command separation tokens (`;`, `&&`) -* `hashed-command` - hashed commands -* `path` - existing filenames -* `path_prefix` - prefixes of existing filenames -* `globbing` - globbing expressions (`*.txt`) -* `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) -* `single-hyphen-option` - single hyphen options (`-o`) -* `double-hyphen-option` - double hyphen options (`--option`) -* `back-quoted-argument` - backquoted expressions (`` `foo` ``) -* `single-quoted-argument` - single quoted arguments (`` 'foo' ``) -* `double-quoted-argument` - double quoted arguments (`` "foo" ``) -* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) -* `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) -* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) -* `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`) -* `assign` - parameter assignments -* `redirection` - redirection operators (`<`, `>`, etc) -* `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) -* `default` - everything else - -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 - - # 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 declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/main/README.md b/highlighters/main/README.md new file mode 120000 index 0000000..e99df2e --- /dev/null +++ b/highlighters/main/README.md @@ -0,0 +1 @@ +../docs/highlighters/main.md \ No newline at end of file diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md deleted file mode 100644 index b0b2b90..0000000 --- a/highlighters/pattern/README.md +++ /dev/null @@ -1,16 +0,0 @@ -zsh-syntax-highlighting / highlighters / pattern ------------------------------------------------- - -This is the `pattern` highlighter, that highlights user defined patterns. - - -### How to tweak it - -To use this highlighter, associate patterns with styles in the -`ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: - - # To have commands starting with `rm -rf` in red: - ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') - -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md new file mode 120000 index 0000000..edaff5a --- /dev/null +++ b/highlighters/pattern/README.md @@ -0,0 +1 @@ +../docs/highlighters/pattern.md \ No newline at end of file diff --git a/highlighters/root/README.md b/highlighters/root/README.md deleted file mode 100644 index 0b1f217..0000000 --- a/highlighters/root/README.md +++ /dev/null @@ -1,20 +0,0 @@ -zsh-syntax-highlighting / highlighters / root ---------------------------------------------- - -This is the `root` highlighter, that highlights the whole line if the current -user is root. - - -### How to tweak it - -This highlighter defines the following styles: - -* `root` - the style for the whole line if the current user is root. - -To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, -for example in `~/.zshrc`: - - ZSH_HIGHLIGHT_STYLES[root]='bg=red' - -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). diff --git a/highlighters/root/README.md b/highlighters/root/README.md new file mode 120000 index 0000000..2f69e4a --- /dev/null +++ b/highlighters/root/README.md @@ -0,0 +1 @@ +../docs/highlighters/root.md \ No newline at end of file From 51f66ae851d597a4ae8d53078087a32e67fe0445 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 16 Nov 2015 23:58:42 -0600 Subject: [PATCH 0251/1080] docs: Create all.md --- .gitignore | 1 + Makefile | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index fb2e708..18fa5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.zwc* .pc/ +docs/all.md diff --git a/Makefile b/Makefile index a11cce5..0d01896 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,13 @@ SHARE_DIR?=$(DESTDIR)$(PREFIX)/share/$(NAME) DOC_DIR?=$(DESTDIR)$(PREFIX)/share/doc/$(NAME) ZSH?=zsh # zsh binary to run tests with -# Have the default target do nothing. all: - @ : + cd docs && \ + cp highlighters.md all.md && \ + printf '\n\nIndividual highlighters documentation\n=====================================' >> all.md && \ + for doc in highlighters/*.md; do printf '\n\n'; cat "$$doc"; done >> all.md -install: +install: all $(INSTALL) -d $(SHARE_DIR) $(INSTALL) -d $(DOC_DIR) cp .version zsh-syntax-highlighting.zsh $(SHARE_DIR) @@ -25,10 +27,12 @@ install: # equivalent of) NONOMATCH in effect, and highlighters/*.zsh has no matches. for dirname in highlighters highlighters/*/ ; do \ $(INSTALL) -d $(SHARE_DIR)/"$$dirname"; \ - $(INSTALL) -d $(DOC_DIR)/"$$dirname"; \ for fname in "$$dirname"/*.zsh ; do [ -e "$$fname" ] && cp "$$fname" $(SHARE_DIR)"/$$dirname"; done; \ - for fname in "$$dirname"/*.md ; do [ -e "$$fname" ] && cp "$$fname" $(DOC_DIR)"/$$dirname"; done; \ done + cp -R docs/* $(DOC_DIR) + +clean: + rm -f docs/all.md test: @result=0; \ @@ -52,4 +56,4 @@ perf: done; \ exit $$result -.PHONY: all install test perf +.PHONY: all install clean test perf From f5ca4b891b69478c98e2f04200aeae7c726fc05b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 24 Nov 2015 00:27:21 -0600 Subject: [PATCH 0252/1080] Remove broken links --- docs/highlighters.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index cc56f4e..4c6b950 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -3,12 +3,12 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* [`main`](highlighters/main.md) - the base highlighter, and the only one active by default. -* [`brackets`](highlighters/brackets.md) - matches brackets and parenthesis. -* [`pattern`](highlighters/pattern.md) - matches user-defined patterns. -* [`cursor`](highlighters/cursor.md) - matches the cursor position. -* [`root`](highlighters/root.md) - triggered if the current user is root. -* [`line`](highlighters/line.md) - applied to the whole command line +* `main` - the base highlighter, and the only one active by default. +* `brackets` - matches brackets and parenthesis. +* `pattern` - matches user-defined patterns. +* `cursor` - matches the cursor position. +* `root` - triggered if the current user is root. +* `line` - applied to the whole command line How to activate highlighters From 8e115052e9e01d38c2f4660d7a00d5f5a528fe68 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 24 Nov 2015 00:38:27 -0600 Subject: [PATCH 0253/1080] docs: Fix broken symlinks --- highlighters/brackets/README.md | 2 +- highlighters/cursor/README.md | 2 +- highlighters/line/README.md | 2 +- highlighters/main/README.md | 2 +- highlighters/pattern/README.md | 2 +- highlighters/root/README.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/highlighters/brackets/README.md b/highlighters/brackets/README.md index d8f3a5a..6997bd6 120000 --- a/highlighters/brackets/README.md +++ b/highlighters/brackets/README.md @@ -1 +1 @@ -../docs/highlighters/brackets.md \ No newline at end of file +../../docs/highlighters/brackets.md \ No newline at end of file diff --git a/highlighters/cursor/README.md b/highlighters/cursor/README.md index 13f58ef..70e0c8c 120000 --- a/highlighters/cursor/README.md +++ b/highlighters/cursor/README.md @@ -1 +1 @@ -../docs/highlighters/cursor.md \ No newline at end of file +../../docs/highlighters/cursor.md \ No newline at end of file diff --git a/highlighters/line/README.md b/highlighters/line/README.md index 80edd29..052fe20 120000 --- a/highlighters/line/README.md +++ b/highlighters/line/README.md @@ -1 +1 @@ -../docs/highlighters/line.md \ No newline at end of file +../../docs/highlighters/line.md \ No newline at end of file diff --git a/highlighters/main/README.md b/highlighters/main/README.md index e99df2e..0354731 120000 --- a/highlighters/main/README.md +++ b/highlighters/main/README.md @@ -1 +1 @@ -../docs/highlighters/main.md \ No newline at end of file +../../docs/highlighters/main.md \ No newline at end of file diff --git a/highlighters/pattern/README.md b/highlighters/pattern/README.md index edaff5a..5ff00e6 120000 --- a/highlighters/pattern/README.md +++ b/highlighters/pattern/README.md @@ -1 +1 @@ -../docs/highlighters/pattern.md \ No newline at end of file +../../docs/highlighters/pattern.md \ No newline at end of file diff --git a/highlighters/root/README.md b/highlighters/root/README.md index 2f69e4a..ca6799d 120000 --- a/highlighters/root/README.md +++ b/highlighters/root/README.md @@ -1 +1 @@ -../docs/highlighters/root.md \ No newline at end of file +../../docs/highlighters/root.md \ No newline at end of file From 0b3183f6cb9a597ed358f6c7165f580f2245f8b7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Nov 2015 07:05:41 +0000 Subject: [PATCH 0254/1080] docs: Split README.md into INSTALL.md. Fixes zsh-users/zsh-syntax-highlighting#235. --- INSTALL.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 64 +------------------------------------------------- 2 files changed, 70 insertions(+), 63 deletions(-) create mode 100644 INSTALL.md diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..b7051bc --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,69 @@ +How to install +-------------- + +### Using packages + +* Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] +* Gentoo: [mv overlay][gentoo-overlay] +* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] + +[arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting +[AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git +[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting +[brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb + + +### In your ~/.zshrc + +* Clone this repository: + + git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + + If `git` is not installed, you could download a snapshot of the latest + development tree from: + + https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz + +* Source the script **at the end** of `~/.zshrc`: + + source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + +* Source `~/.zshrc` to take changes into account: + + source ~/.zshrc + + +### With oh-my-zsh + +Oh-my-zsh is a zsh configuration framework. It lives at +. + +To install zsh-syntax-highlighting under oh-my-zsh: + +1. Clone this repository in oh-my-zsh's plugins directory: + + git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting + +2. Activate the plugin in `~/.zshrc`: + + plugins=( [plugins...] zsh-syntax-highlighting) + +3. Source `~/.zshrc` to take changes into account: + + source ~/.zshrc + +Note that `zsh-syntax-highlighting` must be the last plugin sourced, +so make it the last element of the `$plugins` array. + + +### System-wide installation + +Either 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` +and directing your users to add + `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +in their `.zshrc`s. + + + diff --git a/README.md b/README.md index 59919f6..464ffb7 100644 --- a/README.md +++ b/README.md @@ -19,69 +19,7 @@ them, particularly in catching syntax errors. How to install -------------- -### Using packages - -* Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] -* Gentoo: [mv overlay][gentoo-overlay] -* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] - -[arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting -[AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git -[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting -[brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb - - -### In your ~/.zshrc - -* Clone this repository: - - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git - - If `git` is not installed, you could download a snapshot of the latest - development tree from: - - https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz - -* Source the script **at the end** of `~/.zshrc`: - - source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - -* Source `~/.zshrc` to take changes into account: - - source ~/.zshrc - - -### With oh-my-zsh - -Oh-my-zsh is a zsh configuration framework. It lives at -. - -To install zsh-syntax-highlighting under oh-my-zsh: - -1. Clone this repository in oh-my-zsh's plugins directory: - - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting - -2. Activate the plugin in `~/.zshrc`: - - plugins=( [plugins...] zsh-syntax-highlighting) - -3. Source `~/.zshrc` to take changes into account: - - source ~/.zshrc - -Note that `zsh-syntax-highlighting` must be the last plugin sourced, -so make it the last element of the `$plugins` array. - - -### System-wide installation - -Either 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` -and directing your users to add - `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` -in their `.zshrc`s. +See [INSTALL.md](INSTALL.md). FAQ From ded1c8789b07155c833fc49abbb422b93233e81c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Nov 2015 07:27:29 +0000 Subject: [PATCH 0255/1080] docs: Clarify highlighters documentation. --- docs/highlighters.md | 13 ++++++++++--- docs/highlighters/pattern.md | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 4c6b950..a614b1c 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -23,9 +23,16 @@ To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in How to tweak highlighters ------------------------- -Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` array. -Navigate into each highlighter directory to see what styles it defines -and how to configure it. +Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` associative array. +Navigate into each highlighter directory to see what styles (keys) it defines; +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighters]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting + +Some highlighters support additional configuration parameters; see each +highlighter's documentation for details. How to implement a new highlighter diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index b0b2b90..b64746b 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -7,7 +7,7 @@ This is the `pattern` highlighter, that highlights user defined patterns. ### How to tweak it To use this highlighter, associate patterns with styles in the -`ZSH_HIGHLIGHT_PATTERNS` array, for example in `~/.zshrc`: +`ZSH_HIGHLIGHT_PATTERNS` associative array, for example in `~/.zshrc`: # To have commands starting with `rm -rf` in red: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') From 22123ab622b8b979c3159550f2e7e100648d047f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Nov 2015 07:36:10 +0000 Subject: [PATCH 0256/1080] docs: Follow-up to last: Fix markup. --- docs/highlighters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index a614b1c..6e61a83 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -29,7 +29,7 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighters]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting Some highlighters support additional configuration parameters; see each highlighter's documentation for details. From 7ee350efcd125c7b6595bf5f59b55c74eae01ad4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Nov 2015 07:39:44 +0000 Subject: [PATCH 0257/1080] docs: Port new text to individual highlighters' documentation. The new text is from the preceding two commits, 22123ab622b8 + ded1c8789b07. Fixes a broken link. --- docs/highlighters/brackets.md | 7 +++++-- docs/highlighters/cursor.md | 7 +++++-- docs/highlighters/line.md | 7 +++++-- docs/highlighters/main.md | 7 +++++-- docs/highlighters/pattern.md | 7 +++++-- docs/highlighters/root.md | 7 +++++-- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/highlighters/brackets.md b/docs/highlighters/brackets.md index df47d8c..9001074 100644 --- a/docs/highlighters/brackets.md +++ b/docs/highlighters/brackets.md @@ -22,5 +22,8 @@ for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=yellow,bold' ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta,bold' -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/cursor.md b/docs/highlighters/cursor.md index 3ff6c8e..7295fd1 100644 --- a/docs/highlighters/cursor.md +++ b/docs/highlighters/cursor.md @@ -15,5 +15,8 @@ for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[cursor]='bg=blue' -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/line.md b/docs/highlighters/line.md index ac69f68..4ba14e9 100644 --- a/docs/highlighters/line.md +++ b/docs/highlighters/line.md @@ -15,5 +15,8 @@ for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[line]='bold' -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index bbf87ce..c3228ba 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -59,5 +59,8 @@ for example in `~/.zshrc`: # To disable highlighting of globbing expressions ZSH_HIGHLIGHT_STYLES[globbing]='none' -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index b64746b..d1b99e9 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -12,5 +12,8 @@ To use this highlighter, associate patterns with styles in the # To have commands starting with `rm -rf` in red: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/root.md b/docs/highlighters/root.md index 0b1f217..0b0d41f 100644 --- a/docs/highlighters/root.md +++ b/docs/highlighters/root.md @@ -16,5 +16,8 @@ for example in `~/.zshrc`: ZSH_HIGHLIGHT_STYLES[root]='bg=red' -The syntax for declaring styles is documented in [the `zshzle(1)` manual -page](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC135). +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)` +manual page][zshzle-Character-Highlighting]. + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting From 438a94496f51357038117a1838355f7dedc088b7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Nov 2015 07:43:03 +0000 Subject: [PATCH 0258/1080] docs: Grammar fix. --- docs/highlighters/pattern.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index d1b99e9..3ad5f24 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting / highlighters / pattern ------------------------------------------------ -This is the `pattern` highlighter, that highlights user defined patterns. +This is the `pattern` highlighter, that highlights user-defined patterns. ### How to tweak it From 635a68f7b4238a9995c95fe35f223873e20aff03 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 25 Nov 2015 03:54:33 +0000 Subject: [PATCH 0259/1080] driver: Fix error message wording --- 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 ab099bd..8b1296b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -42,7 +42,7 @@ else # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? # TODO: also check POSIX_ARGZERO, but not it's not available in older zsh - echo "zsh-syntax-highlighting: error: not compatible with FUNCTION_ARGZERO" >&2 + echo "zsh-syntax-highlighting: error: not compatible with NO_FUNCTION_ARGZERO" >&2 return 1 fi From 84734ba9502673f83f8c1d4b1b930ef28d742e8f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 25 Nov 2015 03:55:20 +0000 Subject: [PATCH 0260/1080] versionstamp: Better $ZSH_HIGHLIGHT_REVISION reporting when running from git. --- 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 8b1296b..3e243d2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -36,7 +36,7 @@ if [[ -o function_argzero ]]; then # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining # the valid value (via `git rev-parse HEAD`, as Makefile does) might be costly, so: - unset ZSH_HIGHLIGHT_REVISION + ZSH_HIGHLIGHT_REVISION=HEAD fi else # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. From b8ced86853592d7af6f578428a0494da93242d77 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 17:15:48 +0000 Subject: [PATCH 0261/1080] docs: Minor clarifications. --- docs/highlighters.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 6e61a83..cb13d50 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -19,6 +19,9 @@ To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) +By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main` +highlighter is active. + How to tweak highlighters ------------------------- @@ -48,7 +51,7 @@ To create your own `myhighlighter` highlighter: non-zero otherwise, for example: _zsh_highlight_myhighlighter_highlighter_predicate() { - # Call this highlighter in SVN repositories + # Call this highlighter in SVN working copies [[ -d .svn ]] } From 2ed2f1e3c4dd521255980d4c4617713e80dd7411 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 18:07:41 +0000 Subject: [PATCH 0262/1080] docs: INSTALL.md: Streamling .zshrc installation instructions. --- INSTALL.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index b7051bc..6bdcd87 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -15,22 +15,18 @@ How to install ### In your ~/.zshrc -* Clone this repository: +Simply clone this repository and source the script: git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc + source ~/.zshrc - If `git` is not installed, you could download a snapshot of the latest + 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 -* Source the script **at the end** of `~/.zshrc`: - - source /path/to/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - -* Source `~/.zshrc` to take changes into account: - - source ~/.zshrc + Note the `source` command must be **at the end** of `~/.zshrc`. ### With oh-my-zsh From 2e5481ab9ad448ea8264a6ab1fe137689c1e9abe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 18:09:43 +0000 Subject: [PATCH 0263/1080] docs; INSTALL.md: Make 'system-wide' section easier to read. --- INSTALL.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 6bdcd87..b8dd3bb 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -56,10 +56,15 @@ so make it the last element of the `$plugins` array. Either 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-syntax-highlighting system-wide, you may do so by running + + make install + and directing your users to add - `source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` -in their `.zshrc`s. + + source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh + +to their `.zshrc`s. From 371f8183d6f98e7db6afc6459cba75ba0dc6b89a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 17:15:48 +0000 Subject: [PATCH 0264/1080] docs: Minor clarification. --- docs/highlighters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index cb13d50..3fabc8c 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -35,7 +35,7 @@ manual page][zshzle-Character-Highlighting]. [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting Some highlighters support additional configuration parameters; see each -highlighter's documentation for details. +highlighter's documentation for details and examples. How to implement a new highlighter From 95330c691bae3c82e7e56ebf122f1bbf28a02de6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Nov 2015 03:36:36 +0000 Subject: [PATCH 0265/1080] docs: Clarify tagline summary of 'root' highlighter --- docs/highlighters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 3fabc8c..9443011 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -7,7 +7,7 @@ Syntax highlighting is done by pluggable highlighters: * `brackets` - matches brackets and parenthesis. * `pattern` - matches user-defined patterns. * `cursor` - matches the cursor position. -* `root` - triggered if the current user is root. +* `root` - highlights the whole command line if the current user is root. * `line` - applied to the whole command line From eb3715a56a88f2eb2a7c4de5978840e22b6f125f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 17:33:21 +0000 Subject: [PATCH 0266/1080] docs: Followup to the recent docs branch: clean up some internal cross-references. --- README.md | 4 ++-- docs/highlighters.md | 9 +++++---- highlighters/README.md | 9 ++++++++- 3 files changed, 15 insertions(+), 7 deletions(-) mode change 120000 => 100644 highlighters/README.md diff --git a/README.md b/README.md index 464ffb7..ac8beaf 100644 --- a/README.md +++ b/README.md @@ -45,5 +45,5 @@ How to tweak ------------ Syntax highlighting is done by pluggable highlighter scripts. See the -[`highlighters` directory](./highlighters) for documentation and configuration -settings. +[documentation on highlighters](docs/highlighters.md) for details and +configuration settings. diff --git a/docs/highlighters.md b/docs/highlighters.md index 9443011..91b7f26 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -27,10 +27,11 @@ How to tweak highlighters ------------------------- Highlighters look up styles from the `ZSH_HIGHLIGHT_STYLES` associative array. -Navigate into each highlighter directory to see what styles (keys) it defines; -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)` -manual page][zshzle-Character-Highlighting]. +Navigate into the [individual highlighters' documentation](highlighters/) to +see what styles (keys) each highlighter defines; 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)` manual +page][zshzle-Character-Highlighting]. [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/highlighters/README.md b/highlighters/README.md deleted file mode 120000 index 7b048c0..0000000 --- a/highlighters/README.md +++ /dev/null @@ -1 +0,0 @@ -../docs/highlighters.md \ No newline at end of file diff --git a/highlighters/README.md b/highlighters/README.md new file mode 100644 index 0000000..8490ddf --- /dev/null +++ b/highlighters/README.md @@ -0,0 +1,8 @@ +zsh-syntax-highlighting / highlighters +====================================== + +Navigate into the individual highlighters' documentation to see +what styles (`$ZSH_HIGHLIGHT_STYLES` keys) each highlighter defines. + +Refer to the [documentation on highlighters](../docs/highlighters.md) for further +information. From 1f1ad09e38aa06f72dee0676eb49d9a0f3481fdb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 26 Nov 2015 17:39:51 +0000 Subject: [PATCH 0267/1080] docs: Restore (with changes) links removed in f5ca4b891b69478c98e2f04200aeae7c726fc05b. The preceding commit, which made docs/highlighters.md and highlighters/README.md distinct, allows reverting their removal. --- docs/highlighters.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 91b7f26..266abe1 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -3,12 +3,19 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* `main` - the base highlighter, and the only one active by default. -* `brackets` - matches brackets and parenthesis. -* `pattern` - matches user-defined patterns. -* `cursor` - matches the cursor position. -* `root` - highlights the whole command line if the current user is root. -* `line` - applied to the whole command line +* `main` - the base highlighter, and the only one [active by default][1]. +* `brackets` - [matches brackets][2] and parenthesis. +* `pattern` - matches [user-defined patterns][3]. +* `cursor` - matches [the cursor position][4]. +* `root` - highlights the whole command line [if the current user is root][5]. +* `line` - applied to [the whole command line][6]. + +[1]: highlighters/main.md +[2]: highlighters/brackets.md +[3]: highlighters/pattern.md +[4]: highlighters/cursor.md +[5]: highlighters/root.md +[6]: highlighters/line.md How to activate highlighters From eee130f81dd652095616413ef46c7eb3ca56639a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 27 Oct 2015 07:00:39 +0200 Subject: [PATCH 0268/1080] changelog: Update through HEAD (952a97dbc99a). --- changelog.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index ad0a0f5..56e3536 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to 1933de83be0bbfb41c44d182fe581ad85012b71a +up to 952a97dbc99a54bd86141b7a57625e748941a937 @@ -125,6 +125,15 @@ up to 1933de83be0bbfb41c44d182fe581ad85012b71a - docs: Improve 'main' highlighter's documentation. (00de155063f5, 7d4252f5f596) +- docs: Moved to a new docs/ tree; assorted minor updates + (c575f8f37567, 5b34c23cfad5, et seq) + +- docs: Split README.md into INSTALL.md + (0b3183f6cb9a) + +- driver: Report `$ZSH_HIGHLIGHT_REVISION` when running from git + (84734ba95026) + ## Developer-visible changes: From 2d792b03bb715b1cd4c550aba48e2ca10be6a447 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Nov 2015 23:19:23 +0000 Subject: [PATCH 0269/1080] Tag version 0.4.0. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 746bd19..1d0ba9e 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.3.1-dev +0.4.0 From 7338c54a252d21183185f9a6da202e8e4e2bdd5f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 0270/1080] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 1d0ba9e..1351681 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.4.0 +0.4.1-dev From 69b6c4e450188f98d5f4f660f00f2e92f2fb701c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Nov 2015 23:24:22 +0000 Subject: [PATCH 0271/1080] release.md: Clarify release procedure. --- release.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.md b/release.md index a38d677..3d044a3 100644 --- a/release.md +++ b/release.md @@ -5,10 +5,10 @@ - check with multiple zsh versions - Update changelog.md - Remove `-dev` suffix from `./.version`; - Commit that; + Commit that using 'git commit -m "Tag version $(<.version)."; Tag it using `git tag $(<.version)`; Increment `./.version` and restore the `-dev` suffix; - Commit that. + Commit that using 'git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5'. - Push with `git push --tags` - Notify downstreams (OS packages) - anitya should autodetect the tag From cf685a3a27d1a6745b1871e7e5280b917cae3fec Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Nov 2015 02:00:51 +0000 Subject: [PATCH 0272/1080] changelog: Start 0.4.1 section. Also fix an error in the title of the 0.4.0 section. --- changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 56e3536..edcd93b 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,10 @@ up to 952a97dbc99a54bd86141b7a57625e748941a937 -# Changes in version 0.3.1 +# Changes in version 0.4.1 + + +# Changes in version 0.4.0 ## Added highlighting of: From 09c4114eb980c86a76f276425e00d7a4aad152b0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 Nov 2015 08:43:23 +0000 Subject: [PATCH 0273/1080] command word: Do not attempt to interpret command separator tokens as anything else. The important part of this change is removing the second conjunct from the condition; the remainder of the change gives one example of when that matters. --- highlighters/main/main-highlighter.zsh | 13 ++++--- .../main/test-data/empty-command2.zsh | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 highlighters/main/test-data/empty-command2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f9ba70b..addad0d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -312,11 +312,14 @@ _zsh_highlight_main_highlighter() fi elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] - elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]] && - [[ $this_word == *':regular:'* ]]; then - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. - style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + if [[ $this_word == *':regular:'* ]]; then + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. + style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + else + style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + fi elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] (( in_redirection=2 )) diff --git a/highlighters/main/test-data/empty-command2.zsh b/highlighters/main/test-data/empty-command2.zsh new file mode 100644 index 0000000..a888ffe --- /dev/null +++ b/highlighters/main/test-data/empty-command2.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Same test data and expectations as empty-command.zsh; the only difference is: +touch ';' + +BUFFER='echo; ;' + +expected_region_highlight=( + "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; + "7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; +) From 46cd970bc462484174e6e9c24dcafedf6719b616 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Nov 2015 02:53:58 +0000 Subject: [PATCH 0274/1080] tests: Improve tests by using $unused_highlight. The default for [redirection] is 'none', so it wasn't actually being tested. --- highlighters/main/test-data/sudo-redirection.zsh | 1 + highlighters/main/test-data/sudo-redirection2.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index e31ce6e..c99e174 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -27,6 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index f806178..7242f3b 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -27,6 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo >/tmp -u otheruser ls' expected_region_highlight=( From 430cf55368bb40db5328029f3b11510cf3b65b59 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Nov 2015 02:56:07 +0000 Subject: [PATCH 0275/1080] tests: Cover [default]. --- highlighters/main/test-data/history-expansion.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index c670312..0e1c4a6 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -27,6 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight BUFFER='!foo bar !baz' expected_region_highlight=( From 48ecd2918005c14ab51239a6130a6a11413b15ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Nov 2015 03:10:11 +0000 Subject: [PATCH 0276/1080] tests: Add two XFail tests for issue #238, "fd redirections at command word". --- .../main/test-data/exec-redirection1.zsh | 39 ++++++++++++++++++ .../main/test-data/sudo-redirection3.zsh | 40 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 highlighters/main/test-data/exec-redirection1.zsh create mode 100644 highlighters/main/test-data/sudo-redirection3.zsh diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh new file mode 100644 index 0000000..880cfea --- /dev/null +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight +BUFFER='exec {foo}>&/tmp ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # exec + # TODO: "6 10 $ZSH_HIGHLIGHT_STYLES[redirection] 'issue #238'" # {foo} + "11 12 $ZSH_HIGHLIGHT_STYLES[redirection]" # >& + "13 16 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp + "18 19 $ZSH_HIGHLIGHT_STYLES[command] 'issue #238'" # ls +) diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh new file mode 100644 index 0000000..f885d9f --- /dev/null +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight +BUFFER='sudo 2>./. -u otheruser ls' + +expected_region_highlight=( + "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo + "6 7 $ZSH_HIGHLIGHT_STYLES[redirection] 'issue #238'" # 2> + "8 10 $ZSH_HIGHLIGHT_STYLES[path]" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh + "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u + "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser + "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #238'" # ls +) From 73ee7c1f6c4a2bbb77029a93c79e0289e0ffef57 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 29 Nov 2015 03:11:50 +0000 Subject: [PATCH 0277/1080] Fix part of issue #238, "fd redirections at command word". This fixes fd's specified by a (single) digit. The named fd syntax remains an XFail. --- highlighters/main/main-highlighter.zsh | 5 +++-- highlighters/main/test-data/sudo-redirection3.zsh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index addad0d..196a065 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -320,7 +320,8 @@ _zsh_highlight_main_highlighter() else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi - elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then + # A '<' or '>', possibly followed by a digit style=$ZSH_HIGHLIGHT_STYLES[redirection] (( in_redirection=2 )) elif [[ $arg[1,2] == '((' ]]; then @@ -389,7 +390,7 @@ _zsh_highlight_main_highlighter() else style=$ZSH_HIGHLIGHT_STYLES[unknown-token] fi - elif [[ $arg[1] == '<' || $arg[1] == '>' ]]; then + elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then style=$ZSH_HIGHLIGHT_STYLES[redirection] (( in_redirection=2 )) else diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index f885d9f..1e9b215 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -32,9 +32,9 @@ BUFFER='sudo 2>./. -u otheruser ls' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 7 $ZSH_HIGHLIGHT_STYLES[redirection] 'issue #238'" # 2> + "6 7 $ZSH_HIGHLIGHT_STYLES[redirection]" # 2> "8 10 $ZSH_HIGHLIGHT_STYLES[path]" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command] 'issue #238'" # ls + "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls ) From 4f3910cbbaa5b77d2abda65cd19b25b86554e552 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 4 Dec 2015 23:40:30 +0000 Subject: [PATCH 0278/1080] Fix issue #248: Highlight 'pkexec' as a precommand. --- 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 196a065..bc6e2bb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -132,6 +132,7 @@ _zsh_highlight_main_highlighter() ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( 'builtin' 'command' 'exec' 'nocorrect' 'noglob' + 'pkexec' # immune to #121 because it's usually not passed --option flags ) # Tokens that, at (naively-determined) "command position", are followed by From 82f5eb17ecee1f18b3ce3d8a93761a51235cab78 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 12 Dec 2015 11:04:38 +0000 Subject: [PATCH 0279/1080] docs: Note Debian package name. The Debian package should propagate to the "testing" suite (stretch) in a few days. --- INSTALL.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index b8dd3bb..32817a1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,12 +4,16 @@ How to install ### Using packages * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] +* Debian: [in "unstable"][debian-package] * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* Ubuntu: [in Xenial][ubuntu-package] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git +[debian-package]: https://packages.debian.org/zsh-syntax-highlighting [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting +[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb From 38c3ac8831159187bac26dc22ac60c92d680064f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 16 Dec 2015 22:21:11 +0000 Subject: [PATCH 0280/1080] docs: Note that Debian package has migrated to (been added to) Debian stretch. --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 32817a1..95d2151 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,10 +4,10 @@ How to install ### Using packages * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] -* Debian: [in "unstable"][debian-package] +* Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] -* Ubuntu: [in Xenial][ubuntu-package] +* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git From 268656d52bbf971f59883b729b465362ce8f410a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 1 Jan 2016 16:35:00 +0000 Subject: [PATCH 0281/1080] tests: Add a comment. No functional change. --- tests/test-highlighting.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 0abf34b..d80cc46 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -121,6 +121,8 @@ run_test() { typeset -r __tests_tempdir # don't allow tests to override the variable that we will 'rm -rf' later on { + # Use a subshell to isolate tests from each other. + # (So tests can alter global shell state using 'cd', 'hash', etc) (run_test_internal "$__tests_tempdir" "$@") } always { rm -rf -- "$__tests_tempdir" From ed33d2cb13884b298a996ceadfc94ae6ffd78825 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 2 Jan 2016 14:28:56 +0100 Subject: [PATCH 0282/1080] widget binding: don't exclude widgets starting with '_' Just because a widget starts with _ does not mean it should be skipped when rebinding. The only reason widgets need to be skipped is when their function name start with _zsh_highlight_widget*, which is checked later. Example: _expand_alias (^Xa) needs to be wrapped. The exclusion of _* was introduced in 186d80054a40262b9db967aeaf483a28027de19f to fix #65, but it is not needed. The relevant exclusion of _zsh_highlight_widget* is already enough due to the case statement. --- 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 3e243d2..6b27722 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -200,7 +200,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do + for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From 936e2e93142543b685365e7ea615a5b77a88ec35 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 1 Jan 2016 16:35:00 +0000 Subject: [PATCH 0283/1080] tests: Add another comment. No functional change. --- tests/test-highlighting.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index d80cc46..5d35452 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -112,6 +112,9 @@ run_test_internal() { done } +# Run a single test file. The exit status is 1 if the test harness had +# an error and 0 otherwise. The exit status does not depend on whether +# test points succeeded or failed. run_test() { # Do not combine the declaration and initialization: «local x="$(false)"» does not set $?. local __tests_tempdir From 9b64ad750f356f828c3cfa96bc42489b2f081d8a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 2 Jan 2016 21:22:01 +0000 Subject: [PATCH 0284/1080] tests: Add a 'print failures only' mode to 'make test', called 'make quiet-test'. Fixes zsh-users/zsh-syntax-highlighting#262. Currently, 'make quiet-test' uses Perl. However, since it is considered a development tool rather than a user-facing tool, users and downstream packages needn't install Perl. Furthermore, even this dev-only dependency may be dropped in the future. The only difference between tests/tap-filter here and the one in the issue is using a `cat` subshell v. using 'undef $/; '. --- Makefile | 3 +++ tests/README.md | 3 +++ tests/tap-filter | 45 +++++++++++++++++++++++++++++++++++++ tests/test-highlighting.zsh | 15 ++++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 tests/tap-filter diff --git a/Makefile b/Makefile index 0d01896..f454324 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ test: done; \ exit $$result +quiet-test: + $(MAKE) test QUIET=y + perf: @result=0; \ for test in highlighters/*; do \ diff --git a/tests/README.md b/tests/README.md index faaed1e..2674aa7 100644 --- a/tests/README.md +++ b/tests/README.md @@ -38,6 +38,9 @@ All tests may be run with 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" +results (tests that failed but were expected to succeed, or vice-versa), run +`make quiet-test` (or `make test QUIET=y`). [TAP]: http://testanything.org/ diff --git a/tests/tap-filter b/tests/tap-filter new file mode 100755 index 0000000..6587808 --- /dev/null +++ b/tests/tap-filter @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +# ------------------------------------------------------------------------------------------------- +# 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. +# ------------------------------------------------------------------------------------------------- +# vim: ft=perl sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# This is a stdin-to-stdout filter that takes TAP output (such as 'make test') +# on stdin and deletes lines pertaining to expected results. +# +# More specifically, if any of the test points in a test file either failed but +# was expected to pass, or passed but was expected to fail, then emit that test +# file's output; else, elide that test file's output. + +use v5.10.0; +use warnings; +use strict; + +undef $/; # slurp mode +print for + grep { /^ok.*# TODO/m or /^not ok(?!.*# TODO)/m } + split /^(?=#)/m, + ; diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 5d35452..dc47989 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -132,10 +132,23 @@ run_test() { } } +# Set up results_filter +local results_filter +if [[ $QUIET == y ]]; then + if type -w perl >/dev/null; then + results_filter=${0:A:h}/tap-filter + else + echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 + fi +else + results_filter=cat +fi +[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } + # Process each test data file in test data directory. integer something_failed=0 for data_file in ${0:h:h}/highlighters/$1/test-data/*.zsh; do - run_test "$data_file" | tee >(${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) + run_test "$data_file" | tee >($results_filter | ${0:A:h}/tap-colorizer.zsh) | grep -v '^not ok.*# TODO' | grep -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) (( $pipestatus[1] )) && exit 2 done From 5e4b446dee770a811ffb6c19ee41f624895e56da Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 11 Jan 2016 15:07:18 +0000 Subject: [PATCH 0285/1080] aliases: Add a test for one variant of issue #263. --- .../main/test-data/alias-assignment1.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/alias-assignment1.zsh diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh new file mode 100644 index 0000000..19fb485 --- /dev/null +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# Issue #263 (more-pathological case): aliases[x=y]=z works; the ${(z)} splitter considers +# that a single word; but it's not looked up as an alias. Hence, highlight it as an error. +aliases[x=y]='lorem ipsum dolor sit amet' +ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight +BUFFER='x=y ls' + +expected_region_highlight=( + "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token] 'issue #263, #issuecomment-170579803'" # x=y +) From 28932316cca6004253ec57f5d87981c72be64e86 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 11 Jan 2016 15:07:18 +0000 Subject: [PATCH 0286/1080] aliases: Highlight aliases with '=' in their LHS as error. (Part of issue #263.) --- highlighters/main/main-highlighter.zsh | 25 ++++++++++++++++--- .../main/test-data/alias-assignment1.zsh | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index bc6e2bb..ca080c7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -294,9 +294,28 @@ _zsh_highlight_main_highlighter() *': suffix alias') style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] ;; - *': alias') style=$ZSH_HIGHLIGHT_STYLES[alias] - local aliased_command="${"$(alias -- $arg)"#*=}" - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) + *': alias') () { + integer insane_alias + case $arg 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=$ZSH_HIGHLIGHT_STYLES[unknown-token] + else + style=$ZSH_HIGHLIGHT_STYLES[alias] + local aliased_command="${"$(alias -- $arg)"#*=}" + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) + fi + } ;; *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; *': function') style=$ZSH_HIGHLIGHT_STYLES[function];; diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh index 19fb485..9ecbead 100644 --- a/highlighters/main/test-data/alias-assignment1.zsh +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x=y ls' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token] 'issue #263, #issuecomment-170579803'" # x=y + "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # x=y ) From 282c7134e8acdf241397c207300a65ad9be12e16 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 17 Jan 2016 19:35:07 +0000 Subject: [PATCH 0287/1080] Revert "wrapping: Don't add '--' when invoking widgets." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The '--' guard was correct; it was there to guard against arguments belonging to the syntax «zle widget [ -n num ] [ -Nw ] [ -K keymap ] args». For example, this affected using over BUFFER="-w " CURSOR=3 after autoload -Uz select-word-style select-word-style default zstyle ':zle:backward-kill-word' word-style shell . This reverts commit c808d2187a7331dff4d493a945482d718e63bc7a. --- 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 3e243d2..905672f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -208,16 +208,16 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Completion widget: override and rebind old one with prefix "orig-". completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget \"\$@\" }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget \"\$@\" }; \ + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; # Default: unhandled case. From 30d8f92df2258c263185ede09925fef3fa47019c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 20 Jan 2016 22:01:45 +0000 Subject: [PATCH 0288/1080] test harness: Properly quote error message interpolations. No functional change, except that error messages are now more readable. --- tests/test-highlighting.zsh | 6 +++--- tests/test-perfs.zsh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index dc47989..5c2741d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -37,13 +37,13 @@ # Check the highlighter is valid. [[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { - echo >&2 "Bail out! Could not find highlighter '$1'." + 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 ]] || { - echo >&2 "Bail out! Highlighter '$1' has no test data." + echo >&2 "Bail out! Highlighter ${(qq)1} has no test data." exit 2 } @@ -104,7 +104,7 @@ run_test_internal() { [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - echo "not ok $i '$BUFFER[$highlight_zone[1],$highlight_zone[2]]' [$highlight_zone[1],$highlight_zone[2]]: expected '$highlight_zone[3]', observed '$observed_result[$j]'.$todo" + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 45a800b..5d94b37 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -37,13 +37,13 @@ # Check the highlighter is valid. [[ -f ${0:h:h}/highlighters/$1/$1-highlighter.zsh ]] || { - echo >&2 "Bail out! Could not find highlighter '$1'." + 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 ]] || { - echo >&2 "Bail out! Highlighter '$1' has no test data." + echo >&2 "Bail out! Highlighter ${(qq)1} has no test data." exit 2 } From 451665cb2a8ba80626aab295c88d23d0f341ea6c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 20 Jan 2016 22:10:45 +0000 Subject: [PATCH 0289/1080] 'main': Don't highlight at the $PS3 prompt. The input to the $PS3 prompt is not commands, so the 'main' highlighter is not applicable to it. Fixes zsh-users/zsh-syntax-highlighting#268. --- highlighters/main/main-highlighter.zsh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ca080c7..6312521 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -108,6 +108,15 @@ _zsh_highlight_main_highlighter() emulate -L zsh setopt localoptions extendedglob bareglobqual + # At the PS3 prompt, highlight nothing. + # + # (We can't check this in _zsh_highlight_main_highlighter_predicate because + # if the predicate returns false, the previous value of region_highlight + # would be reused.) + if [[ $CONTEXT == 'select' ]]; then + return + fi + ## Variable declarations and initializations local start_pos=0 end_pos highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' From 62a6be3d636493596c83a1c88b6ab533bd5baa44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 27 Jan 2016 20:38:38 +0000 Subject: [PATCH 0290/1080] Version number bump. Have master self-describe as 0.5.0-dev, since an 0.4.1 release is upcoming on another branch. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 1351681..4259c64 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.4.1-dev +0.5.0-dev From 683f4837a037e35e6a5236020e855fcd262ed48d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 27 Jan 2016 20:48:56 +0000 Subject: [PATCH 0291/1080] changelog: Update for upcoming 0.4.1 release. --- changelog.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index edcd93b..94cb929 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,16 @@ -up to 952a97dbc99a54bd86141b7a57625e748941a937 +up to 952a97dbc99a54bd86141b7a57625e748941a937 + 0.4.1 # Changes in version 0.4.1 +## Fixes: + +- Arguments to widgets were not properly dash-escaped. Only matters for widgets + that take arguments (i.e., that are invoked as `zle ${widget} -- ${args}`). + (282c7134e8ac, reverts c808d2187a73) + # Changes in version 0.4.0 @@ -107,7 +113,7 @@ up to 952a97dbc99a54bd86141b7a57625e748941a937 (57624bb9f64b) - widgets wrapping: Don't add '--' when invoking widgets. - (c808d2187a73) + (c808d2187a73) [_reverted in 0.4.1_] - Refresh highlighting upon `accept-*` widgets (`accept-line` et al). (59fbdda64c21) From 3cb58fd7d7b9e42067ffcf24892114dc2c9b26e4 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 11 Feb 2016 16:48:53 +0100 Subject: [PATCH 0292/1080] Optimization: -1 is extra computation of string length internally ./parse.zsh "zplugin.zsh" > out_norm.txt 106,17s user 7,84s system 98% cpu 1:55,85 total ./parse.zsh "zplugin.zsh" > out_opt.txt 51,91s user 7,44s system 99% cpu 59,912 total % wc -l zplugin.zsh 3188 zplugin.zsh --- 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 6312521..43163a7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -125,6 +125,7 @@ _zsh_highlight_main_highlighter() typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" + integer len="${#buf}" region_highlight=() if (( path_dirs_was_set )); then @@ -234,11 +235,13 @@ _zsh_highlight_main_highlighter() # indistinguishable from 'echo foo echo bar' (one command with three # words for arguments). local needle=$'[;\n]' - integer offset=${${buf[start_pos+1,-1]}[(i)$needle]} + # Len-start_pos drops one character, but it should do it, as start_pos + # starts from next, not from "start_pos", character + integer offset=${${buf: start_pos: len-start_pos}[(i)$needle]} (( start_pos += offset - 1 )) (( end_pos = start_pos + $#arg )) else - ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}})) + ((start_pos+=(len-start_pos)-${#${${buf: start_pos: len-start_pos}##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) fi From e500ca246286e15789869de98dfa70d78574cdb0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 14 Feb 2016 17:34:53 +0200 Subject: [PATCH 0293/1080] 'main': Don't highlight in vared This is a continuation of 451665cb2a8ba80626aab295c88d23d0f341ea6c which did the same for the $PS3 prompt. Reported-by: Sebastian Gniazdowski --- 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 43163a7..981d3bd 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -108,12 +108,12 @@ _zsh_highlight_main_highlighter() emulate -L zsh setopt localoptions extendedglob bareglobqual - # At the PS3 prompt, highlight nothing. + # At the PS3 prompt and in vared, highlight nothing. # # (We can't check this in _zsh_highlight_main_highlighter_predicate because # if the predicate returns false, the previous value of region_highlight # would be reused.) - if [[ $CONTEXT == 'select' ]]; then + if [[ $CONTEXT == (select|vared) ]]; then return fi From bdb23d137854611f1b83286876f354ee5bcb72eb Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Wed, 17 Feb 2016 23:52:54 +0530 Subject: [PATCH 0294/1080] use https instead of git for url --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 95d2151..72fba04 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -21,7 +21,7 @@ How to install Simply clone this repository and source the script: - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc source ~/.zshrc @@ -42,7 +42,7 @@ To install zsh-syntax-highlighting under oh-my-zsh: 1. Clone this repository in oh-my-zsh's plugins directory: - git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting 2. Activate the plugin in `~/.zshrc`: From 487b122c480d00befc3f80a8cc2e53ad99593b2c Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 2 Jan 2016 14:31:35 +0100 Subject: [PATCH 0295/1080] widget binding: don't exclude widgets with identical function name Skipping when $cur_widgets == user:$cur_widget was introduced with 776453cb5b6922a61c01fb51f1c0bdbaf73b79d3. However there are cases where this is not just an 'already rebound' event, but simply a normal widget whose function name happens to be identical to its widget name. Example: expand-absolute-path is a widget whose function name is also expand-absolute-path. No reason why this should be ignored. Another example: edit-command-line --- 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 6b27722..540d8e5 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -204,7 +204,7 @@ _zsh_highlight_bind_widgets() case $widgets[$cur_widget] in # Already rebound event: do nothing. - user:$cur_widget|user:_zsh_highlight_widget_*);; + user:_zsh_highlight_widget_*);; # User defined widget: override and rebind old one with prefix "orig-". user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ From e635f766bef9ffe1c0d646d8fd256e9134e94468 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 12 Mar 2016 18:35:00 +0000 Subject: [PATCH 0296/1080] docs: Clarify oh-my-zsh installation instructions. Thanks to Andrew Janke. Fixes zsh-users/zsh-syntax-highlighting#270. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 72fba04..f021c49 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -42,7 +42,7 @@ To install zsh-syntax-highlighting under oh-my-zsh: 1. Clone this repository in oh-my-zsh's plugins directory: - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.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`: From 4c23a2fd1b90db08551d909ab7323bb82ea5de49 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Mar 2016 02:47:25 +0000 Subject: [PATCH 0297/1080] 'main': Highlight lone '!' correctly: it's not a history expansion. While here, also add a test for the '!' reserved word (which is highlighted since c216242b). --- highlighters/main/main-highlighter.zsh | 6 ++++-- highlighters/main/test-data/history-expansion.zsh | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 981d3bd..a6465a6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -342,7 +342,9 @@ _zsh_highlight_main_highlighter() # (For array assignments, the command doesn't start until the ")" token.) next_word+=':start:' fi - elif [[ $arg[0,1] == $histchars[0,1] || $arg[0,1] == $histchars[2,2] ]]; then + elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then + style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + elif [[ $arg[0,1] == $histchars[2,2] ]]; then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then @@ -414,7 +416,7 @@ _zsh_highlight_main_highlighter() [*?]*|*[^\\][*?]*) $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; *) if false; then - elif [[ $arg[0,1] = $histchars[0,1] ]]; then + elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=$ZSH_HIGHLIGHT_STYLES[history-expansion] elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 0e1c4a6..0e818b8 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -28,10 +28,12 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight -BUFFER='!foo bar !baz' +BUFFER='!foo bar !baz ! ; !' expected_region_highlight=( "1 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar "10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz + "15 15 $ZSH_HIGHLIGHT_STYLES[default]" # ! (before the semicolon) + "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ! (after the semicolon) ) From 4849ef3307f37155b7d02294647d2ae011363392 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Dec 2015 21:15:48 +0100 Subject: [PATCH 0298/1080] Refactor the application of zle_highlight settings - Extract duplicated code into a new function. This makes it easier to add support for other entries in the future, that cannot be accessed in the current version of zsh (isearch, suffix). - Make decision logic more comprehensible. - Respect deliberately empty entries in zle_highlight. Don't force the default value when the user deliberately sets an entry in zle_highlight to the empty string. For example zle_highligh(paste:) to disable paste highlighting completely. --- zsh-syntax-highlighting.zsh | 70 +++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 227cf8e..26c01fc 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -113,33 +113,13 @@ _zsh_highlight() done # Re-apply zle_highlight settings - () { - if (( REGION_ACTIVE )) ; then - # zle_highlight[region] defaults to 'standout' if unspecified - local region="${${zle_highlight[(r)region:*]#region:}:-standout}" - integer start end - if (( MARK > CURSOR )) ; then - start=$CURSOR end=$MARK - else - start=$MARK end=$CURSOR - fi - region_highlight+=("$start $end $region") - fi - } - # YANK_ACTIVE is only available in zsh-5.1.1 and newer - (( $+YANK_ACTIVE )) && () { - if (( YANK_ACTIVE )) ; then - # zle_highlight[paste] defaults to 'standout' if unspecified - local paste="${${zle_highlight[(r)paste:*]#paste:}:-standout}" - integer start end - if (( YANK_END > YANK_START )) ; then - start=$YANK_START end=$YANK_END - else - start=$YANK_END end=$YANK_START - fi - region_highlight+=("$start $end $paste") - fi - } + + # region + (( REGION_ACTIVE )) && _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" + + # yank / paste (zsh-5.1.1 and newer) + (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" + return $ret @@ -150,6 +130,42 @@ _zsh_highlight() } } +# Apply highlighting based on entries in the zle_highligh array. +# This function takes four arguments: +# 1. The exact entry (no patterns) in the zle_highlight array: +# region, paste, isearch, or suffix +# 2. The default highlighting that should be applied if the entry is unset +# 3. and 4. Two integer values describing the beginning and end of the +# range. The order does not matter. +_zsh_highlight_apply_zle_highlight() { + local entry="$1" default="$2" + integer first="$3" second="$4" + + # read the relevant entry from zle_highlight + local region="${zle_highlight[(r)$entry:*]}" + + if [[ -z "$region" ]]; then + # entry not specified at all, use default value + region=$default + else + # strip prefix + region="${region#$entry:}" + + # no highlighting when set to the empty string or to 'none' + if [[ -z "$region" ]] || [[ "$region" == none ]]; then + return + fi + fi + + integer start end + if (( first < second )); then + start=$first end=$second + else + start=$second end=$first + fi + region_highlight+=("$start $end $region") +} + # ------------------------------------------------------------------------------------------------- # API/utility functions for highlighters From 7e7e291b2047e89419ab77fffe2f310b8c7d79e0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 13:58:55 +0000 Subject: [PATCH 0299/1080] widget binding: Remove an unnecessary layer of indirection. The 'eval' was never needed, and the lack of proper quoting of the interpolated variables caused issues, such as #278. Fixes zsh-users/zsh-syntax-highlighting#278. --- zsh-syntax-highlighting.zsh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 26c01fc..2fe3713 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -223,18 +223,18 @@ _zsh_highlight_bind_widgets() user:_zsh_highlight_widget_*);; # User defined widget: override and rebind old one with prefix "orig-". - user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + user:*) zle -N orig-$cur_widget ${widgets[$cur_widget]#*:} + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- "$@" }; + zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". - completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ + _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- "$@" }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }; \ - zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; + builtin) _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- "$@" }; \ + zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Default: unhandled case. *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; From 261c180a36659fb01d68e2356a17837bd9ad4b3a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 14:41:18 +0000 Subject: [PATCH 0300/1080] widget binding: Unbreak the build. The last commit inadvertently broke interactive use, although the test suite passed. See issue #278. --- zsh-syntax-highlighting.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 2fe3713..a30ab41 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -222,18 +222,21 @@ _zsh_highlight_bind_widgets() # Already rebound event: do nothing. user:_zsh_highlight_widget_*);; + # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function + # definition time is used. + # User defined widget: override and rebind old one with prefix "orig-". user:*) zle -N orig-$cur_widget ${widgets[$cur_widget]#*:} - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- "$@" }; + eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }"; zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- "$@" }; \ + eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }"; \ zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". - builtin) _zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- "$@" }; \ + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }"; zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Default: unhandled case. From 47a664447c2dd497995e404f30d98e8f03f7ebbb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 14:47:53 +0000 Subject: [PATCH 0301/1080] noop: Remove stray statement terminators and line joiners. --- zsh-syntax-highlighting.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index a30ab41..78c2c91 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -227,16 +227,16 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) zle -N orig-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }"; + eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \ - eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }"; \ + completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ } + eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }"; + builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Default: unhandled case. From 6a634fac9fb9044a620e64d71d10af4964ce5a9c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 13:58:55 +0000 Subject: [PATCH 0302/1080] widget binding: Properly escape widget names at definition. Re-Fixes zsh-users/zsh-syntax-highlighting#278. --- zsh-syntax-highlighting.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 78c2c91..63e1d2c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -224,19 +224,22 @@ _zsh_highlight_bind_widgets() # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function # definition time is used. + # + # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with + # NO_function_argzero, regardless of the option's setting here. # User defined widget: override and rebind old one with prefix "orig-". user:*) zle -N orig-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }" + eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ } - eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget orig-$cur_widget -- \"\$@\" }" + eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_$cur_widget() { _zsh_highlight_call_widget .$cur_widget -- \"\$@\" }" + builtin) eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Default: unhandled case. From 11d378332e875f5c215f62de82f68deeba912d76 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 15:12:04 +0000 Subject: [PATCH 0303/1080] widget binding: Further unbreak the build. 7e7e291b2047 broke 'zle -C' completions, as reported in #278 just now. --- 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 63e1d2c..3d05dd4 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -234,7 +234,7 @@ _zsh_highlight_bind_widgets() zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ } + completion:*) zle -C orig-$cur_widget ${${(s.:.)widgets[complete-word]}[2,3]} eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; From cb02451a4e08d7c0157595db52769ed994aea3b5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 15:14:09 +0000 Subject: [PATCH 0304/1080] widget binding: Fix crucial typo in last commit. --- 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 3d05dd4..899d67c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -234,7 +234,7 @@ _zsh_highlight_bind_widgets() zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C orig-$cur_widget ${${(s.:.)widgets[complete-word]}[2,3]} + completion:*) zle -C orig-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; From bc7f8ea433adf3efd71a3e950e9a8dec846a1171 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Mar 2016 01:32:44 +0000 Subject: [PATCH 0305/1080] 'main': Restore support for zsh-4.3.10 and older. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zsh older than workers/28418 (zsh revision 23bdfc7fd2a012d5205ed22d18eb39e41c8fbc95) doesn't support the «${name:offset:length}» syntax. Therefore, use the older «$name[start,end]» syntax instead. Followup to 3cb58fd7d7b9e42067ffcf24892114dc2c9b26e4, "Optimization: -1 is extra computation of string length internally". Fixes zsh-users/zsh-syntax-highlighting#279. --- highlighters/main/main-highlighter.zsh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a6465a6..2f43255 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -235,13 +235,11 @@ _zsh_highlight_main_highlighter() # indistinguishable from 'echo foo echo bar' (one command with three # words for arguments). local needle=$'[;\n]' - # Len-start_pos drops one character, but it should do it, as start_pos - # starts from next, not from "start_pos", character - integer offset=${${buf: start_pos: len-start_pos}[(i)$needle]} + integer offset=${${buf[start_pos+1,len]}[(i)$needle]} (( start_pos += offset - 1 )) (( end_pos = start_pos + $#arg )) else - ((start_pos+=(len-start_pos)-${#${${buf: start_pos: len-start_pos}##([[:space:]]|\\[[:space:]])#}})) + ((start_pos+=(len-start_pos)-${#${${buf[start_pos+1,len]}##([[:space:]]|\\[[:space:]])#}})) ((end_pos=$start_pos+${#arg})) fi From 79e4d3d1240599ab00a5e9aae54dfbd5c18fb270 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Wed, 13 Jan 2016 21:44:59 +0100 Subject: [PATCH 0306/1080] apply suffix and isearch zle_highlights on top --- zsh-syntax-highlighting.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 899d67c..9ff3a7f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -120,6 +120,12 @@ _zsh_highlight() # yank / paste (zsh-5.1.1 and newer) (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" + # isearch + (( $+ISEARCH_ACTIVE )) && (( ISEARCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCH_START" "$ISEARCH_END" + + # suffix + (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" + return $ret From bb8d325c0cbdc830ed638a1220c723f82c029b00 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 1 Apr 2016 00:52:27 -0500 Subject: [PATCH 0307/1080] tests: Fix grep syntax In basic regular expressions | is not a special character that spearates branches, so use an extended regular expression. --- 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 5c2741d..b59997d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -148,7 +148,7 @@ fi # Process each test data file in test data directory. integer something_failed=0 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 -q '^not ok\|^ok.*# TODO' && (( something_failed=1 )) + 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 done From 31ac2b36a9156ef424e8ccee560ec31f97bd3eef Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 20 Jan 2016 00:12:55 -0600 Subject: [PATCH 0308/1080] tests: Quote style in expected_region_highlight --- .../test-data/mismatch-patentheses.zsh | 8 ++--- .../brackets/test-data/nested-parentheses.zsh | 12 +++---- .../brackets/test-data/quoted-patentheses.zsh | 2 +- .../brackets/test-data/simple-parentheses.zsh | 8 ++--- .../test-data/unclosed-patentheses.zsh | 6 ++-- .../test-data/unclosed-patentheses2.zsh | 6 ++-- .../main/test-data/alias-assignment1.zsh | 2 +- highlighters/main/test-data/alias.zsh | 4 +-- .../main/test-data/anonymous-function.zsh | 14 ++++---- .../main/test-data/arithmetic-evaluation.zsh | 4 +-- highlighters/main/test-data/assign-append.zsh | 2 +- highlighters/main/test-data/assign-array.zsh | 8 ++--- .../main/test-data/assign-semicolon.zsh | 4 +-- .../main/test-data/assign-subshell.zsh | 6 ++-- highlighters/main/test-data/assign.zsh | 8 ++--- .../main/test-data/back-quoted-argument.zsh | 2 +- .../main/test-data/commandseparator.zsh | 8 ++--- highlighters/main/test-data/comments.zsh | 4 +-- .../main/test-data/commmand-parameter.zsh | 4 +-- highlighters/main/test-data/control-flow.zsh | 34 +++++++++---------- highlighters/main/test-data/dollar-quoted.zsh | 4 +-- .../main/test-data/dollar-quoted2.zsh | 14 ++++---- .../main/test-data/dollar-quoted3.zsh | 4 +-- .../main/test-data/double-hyphen-option.zsh | 2 +- highlighters/main/test-data/double-quoted.zsh | 22 ++++++------ .../main/test-data/double-quoted2.zsh | 4 +-- .../main/test-data/double-quoted3.zsh | 10 +++--- .../main/test-data/double-quoted4.zsh | 6 ++-- highlighters/main/test-data/empty-command.zsh | 4 +-- .../main/test-data/empty-command2.zsh | 4 +-- .../main/test-data/exec-redirection1.zsh | 10 +++--- highlighters/main/test-data/function.zsh | 4 +-- highlighters/main/test-data/glob.zsh | 10 +++--- .../main/test-data/hashed-command.zsh | 2 +- .../main/test-data/history-expansion.zsh | 10 +++--- .../main/test-data/history-expansion2.zsh | 2 +- .../main/test-data/multiline-string.zsh | 4 +-- .../main/test-data/multiline-string2.zsh | 2 +- .../main/test-data/multiple-redirections.zsh | 26 +++++++------- highlighters/main/test-data/noglob-alias.zsh | 2 +- highlighters/main/test-data/noglob1.zsh | 2 +- highlighters/main/test-data/noglob2.zsh | 4 +-- .../main/test-data/option-path_dirs.zsh | 2 +- highlighters/main/test-data/path-space.zsh | 4 +-- .../main/test-data/path-tilde-home.zsh | 4 +-- .../main/test-data/path-tilde-home2.zsh | 4 +-- .../main/test-data/path-tilde-named.zsh | 4 +-- highlighters/main/test-data/path.zsh | 4 +-- highlighters/main/test-data/path_prefix.zsh | 2 +- highlighters/main/test-data/path_prefix2.zsh | 2 +- highlighters/main/test-data/precommand.zsh | 6 ++-- .../main/test-data/prefix-redirection.zsh | 12 +++---- highlighters/main/test-data/redirection.zsh | 4 +-- highlighters/main/test-data/reserved-word.zsh | 8 ++--- .../main/test-data/simple-command.zsh | 2 +- .../main/test-data/simple-redirection.zsh | 10 +++--- highlighters/main/test-data/subshell.zsh | 16 ++++----- highlighters/main/test-data/sudo-command.zsh | 18 +++++----- highlighters/main/test-data/sudo-comment.zsh | 6 ++-- .../main/test-data/sudo-redirection.zsh | 26 +++++++------- .../main/test-data/sudo-redirection2.zsh | 12 +++---- .../main/test-data/sudo-redirection3.zsh | 12 +++---- .../main/test-data/tilde-command-word.zsh | 4 +-- highlighters/main/test-data/unbackslash.zsh | 2 +- .../main/test-data/unknown-command.zsh | 2 +- .../main/test-data/vanilla-newline.zsh | 10 +++--- tests/test-highlighting.zsh | 4 +-- 67 files changed, 239 insertions(+), 239 deletions(-) diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index 5671079..b45b868 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -30,8 +30,8 @@ BUFFER='echo ({x}]' expected_region_highlight=( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( - "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) + "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ( + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { + "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } + "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ) ) diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 291f8f4..028aed1 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -30,10 +30,10 @@ BUFFER='echo $(echo ${(z)array})' expected_region_highlight=( - "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( - "14 14 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "15 15 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ( - "17 17 $ZSH_HIGHLIGHT_STYLES[bracket-level-3]" # ) - "23 23 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "24 24 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ( + "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { + "15 15 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-3]}" # ( + "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-3]}" # ) + "23 23 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } + "24 24 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ) ) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index a2c52c4..5819180 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -30,5 +30,5 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 16 $ZSH_HIGHLIGHT_STYLES[none]" # We expect the brackets highlighter to do nothing +"1 16 ${(q-)ZSH_HIGHLIGHT_STYLES[none]}" # We expect the brackets highlighter to do nothing ) diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index 893145f..8e0c1a3 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -30,8 +30,8 @@ BUFFER='echo ({x})' expected_region_highlight=( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ( - "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } - "10 10 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # ) + "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ( + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { + "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } + "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ) ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index c36ba36..4edfc46 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -30,7 +30,7 @@ BUFFER='echo ({x}' expected_region_highlight=( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ( - "7 7 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # { - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-level-2]" # } + "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ( + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { + "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 04c246b..15c7fbe 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -30,7 +30,7 @@ BUFFER='echo {x})' expected_region_highlight=( - "6 6 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # { - "8 8 $ZSH_HIGHLIGHT_STYLES[bracket-level-1]" # } - "9 9 $ZSH_HIGHLIGHT_STYLES[bracket-error]" # ) + "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # { + "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # } + "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ) ) diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh index 9ecbead..435b72d 100644 --- a/highlighters/main/test-data/alias-assignment1.zsh +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x=y ls' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # x=y + "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # x=y ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index aa84a58..ea804fa 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -43,9 +43,9 @@ BUFFER='x.alias2; alias1' expected_region_highlight=() if [[ "$(type -w x.alias2)" == *suffix* ]]; then expected_region_highlight+=( - "1 8 $ZSH_HIGHLIGHT_STYLES[suffix-alias]" # x.alias2 + "1 8 ${(q-)ZSH_HIGHLIGHT_STYLES[suffix-alias]}" # x.alias2 ) fi expected_region_highlight+=( - "11 16 $ZSH_HIGHLIGHT_STYLES[alias]" # alias1 + "11 16 ${(q-)ZSH_HIGHLIGHT_STYLES[alias]}" # alias1 ) diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index 62714ed..57ab884 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -30,11 +30,11 @@ BUFFER='() echo hello; () { echo world }' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () - "4 7 $ZSH_HIGHLIGHT_STYLES[command]" # echo - "9 13 $ZSH_HIGHLIGHT_STYLES[default]" # hello - "14 14 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "16 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # () - "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { - "21 24 $ZSH_HIGHLIGHT_STYLES[command]" # echo + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () + "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "9 13 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # hello + "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "16 17 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () + "19 19 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { + "21 24 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo ) diff --git a/highlighters/main/test-data/arithmetic-evaluation.zsh b/highlighters/main/test-data/arithmetic-evaluation.zsh index 9287e91..e5caaa8 100644 --- a/highlighters/main/test-data/arithmetic-evaluation.zsh +++ b/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -35,6 +35,6 @@ BUFFER='(( x == 42 ))' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # (( - "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # )) + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # (( + "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # )) ) diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index a38cd86..094ea3f 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='a+=(lorem ipsum)' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[assign]" # a+=( + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # a+=( ) diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh index c530fda..377a4cc 100644 --- a/highlighters/main/test-data/assign-array.zsh +++ b/highlighters/main/test-data/assign-array.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=(hello world))' expected_region_highlight=( - "1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( - "2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=( - "16 16 $ZSH_HIGHLIGHT_STYLES[assign]" # ) - "17 17 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( + "2 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=( + "16 16 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # ) + "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ) ) diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index c3692d4..e76d260 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -31,6 +31,6 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER='A=1; echo hello world' expected_region_highlight=( - "4 4 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "6 9 $ZSH_HIGHLIGHT_STYLES[command]" # echo + "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "6 9 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo ) diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh index 871936f..784c968 100644 --- a/highlighters/main/test-data/assign-subshell.zsh +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -31,7 +31,7 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=1)' expected_region_highlight=( - "1 1 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( - "2 4 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 - "5 5 $ZSH_HIGHLIGHT_STYLES[reserved-word] 'issue #231'" # ) + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( + "2 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=1 + "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]} 'issue #231'" # ) ) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 7510aba..443fff8 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[assign]" # A=1 - "5 7 $ZSH_HIGHLIGHT_STYLES[assign]" # b=( - "8 12 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo" - "17 17 $ZSH_HIGHLIGHT_STYLES[assign]" # ) + "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=1 + "5 7 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # b=( + "8 12 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo" + "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # ) ) diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index 6dfba71..cb182b5 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight BUFFER='echo `echo 42`' expected_region_highlight=( - "6 14 $ZSH_HIGHLIGHT_STYLES[back-quoted-argument]" + "6 14 ${(q-)ZSH_HIGHLIGHT_STYLES[back-quoted-argument]}" ) diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index 7c152ff..1f66f3f 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -32,8 +32,8 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER=':; pwd &! ls' expected_region_highlight=( - "2 2 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "4 6 $ZSH_HIGHLIGHT_STYLES[builtin]" # pwd - "8 9 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # &! - "11 12 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "2 2 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # pwd + "8 9 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # &! + "11 12 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index f1b8108..24ed51c 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -32,7 +32,7 @@ setopt interactive_comments BUFFER='echo "foo #bar" #baz # quux' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[command]" # echo - "6 15 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo #bar" + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "6 15 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo #bar" "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux ) diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index a2b756c..4cffde7 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -31,6 +31,6 @@ x=/usr/bin/env BUFFER='$x "argument"' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # $x - "4 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "argument" + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # $x + "4 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "argument" ) diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 3107f50..1de787b 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -31,21 +31,21 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' expected_region_highlight+=( - "1 5 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # while - "7 8 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # if - "10 13 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "15 19 $ZSH_HIGHLIGHT_STYLES[default]" # Hello - "22 25 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # then - "27 28 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "30 30 $ZSH_HIGHLIGHT_STYLES[path]" # / - "31 31 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "33 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # else - "38 39 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "42 43 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # fi - "46 47 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do - "49 52 $ZSH_HIGHLIGHT_STYLES[command]" # stat - "54 56 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "x" - "59 62 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done - "65 70 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat - "75 76 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "1 5 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # while + "7 8 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # if + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "15 19 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # Hello + "22 25 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # then + "27 28 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "30 30 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # / + "31 31 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "33 36 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # else + "38 39 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "42 43 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # fi + "46 47 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # do + "49 52 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # stat + "54 56 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "x" + "59 62 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # done + "65 70 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # repeat + "75 76 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index ea12f9f..f8ffefa 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -31,6 +31,6 @@ ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight BUFFER=": \$'*' 'foo'" expected_region_highlight=( - "3 6 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'*' - not a glob - "8 12 $ZSH_HIGHLIGHT_STYLES[single-quoted-argument]" # 'foo' + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $'*' - not a glob + "8 12 ${(q-)ZSH_HIGHLIGHT_STYLES[single-quoted-argument]}" # 'foo' ) diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index 1ce9bb4..a29edbb 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -31,11 +31,11 @@ ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( - "3 7 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $'foo - "8 11 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xba - "12 12 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # r - "13 18 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \dead - "19 22 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # beef - "23 24 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # \u - "25 29 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # zzzz' + "3 7 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $'foo + "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \xba + "12 12 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # r + "13 18 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \dead + "19 22 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # beef + "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # \u + "25 29 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # zzzz' ) diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index 53ee171..eb1ee82 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -33,6 +33,6 @@ ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight BUFFER=": \$'\xa1" expected_region_highlight=( - "3 4 $ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]" # $' - "5 8 $ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]" # \xa1 + "3 4 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $' + "5 8 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \xa1 ) diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index b87ebe8..eb7514f 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight BUFFER='hello --world' expected_region_highlight=( - "7 13 $ZSH_HIGHLIGHT_STYLES[double-hyphen-option]" # --world + "7 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-hyphen-option]}" # --world ) diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index 3f80f9e..ececcca 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -31,15 +31,15 @@ BUFFER=': "foo$bar:\`:\":\$:' BUFFER+=\\\\:\" expected_region_highlight=( - "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo - "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar - "11 11 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : - "12 13 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \` - "14 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : - "15 16 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \$ - "17 17 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : - "18 19 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \" - "20 20 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # : - "21 22 $ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]" # \\ - "23 24 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # :" + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo + "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $bar + "11 11 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : + "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \` + "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : + "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \$ + "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : + "18 19 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \" + "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : + "21 22 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \\ + "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # :" ) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index b29c884..dcae235 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -32,6 +32,6 @@ BUFFER=': "foo$bar' expected_region_highlight=( - "3 6 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "foo - "7 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $bar + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo + "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $bar ) diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 96408fa..efbcd63 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -31,9 +31,9 @@ BUFFER=': "$" "$42foo"' BUFFER+=\ \"\\\'\\x\" expected_region_highlight=( - "3 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "$" - "7 7 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " - "8 10 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # $42 - "11 14 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # foo" - "16 21 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "\'\x" - \' and \x are not escape sequences + "3 5 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "$" + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # " + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $42 + "11 14 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # foo" + "16 21 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "\'\x" - \' and \x are not escape sequences ) diff --git a/highlighters/main/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh index 3355fc2..4a1e205 100644 --- a/highlighters/main/test-data/double-quoted4.zsh +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -30,7 +30,7 @@ BUFFER=': "${foo}bar"' expected_region_highlight=( - "3 3 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # " - "4 9 $ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]" # ${foo} - "10 13 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # bar" + "3 3 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # " + "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # ${foo} + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # bar" ) diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index 9e4b13f..4da62ba 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -30,6 +30,6 @@ BUFFER='echo; ;' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; + "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ; ) diff --git a/highlighters/main/test-data/empty-command2.zsh b/highlighters/main/test-data/empty-command2.zsh index a888ffe..a4d5538 100644 --- a/highlighters/main/test-data/empty-command2.zsh +++ b/highlighters/main/test-data/empty-command2.zsh @@ -33,6 +33,6 @@ touch ';' BUFFER='echo; ;' expected_region_highlight=( - "5 5 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "7 7 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ; + "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ; ) diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh index 880cfea..9d74587 100644 --- a/highlighters/main/test-data/exec-redirection1.zsh +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -31,9 +31,9 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='exec {foo}>&/tmp ls' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # exec - # TODO: "6 10 $ZSH_HIGHLIGHT_STYLES[redirection] 'issue #238'" # {foo} - "11 12 $ZSH_HIGHLIGHT_STYLES[redirection]" # >& - "13 16 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "18 19 $ZSH_HIGHLIGHT_STYLES[command] 'issue #238'" # ls + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # exec + # TODO: "6 10 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]} 'issue #238'" # {foo} + "11 12 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # >& + "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "18 19 ${(q-)ZSH_HIGHLIGHT_STYLES[command]} 'issue #238'" # ls ) diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index 3e579ab..fa19b91 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -39,8 +39,8 @@ BUFFER='cd;ls' # Use $unused_highlight to see that function highlighting has precedence over command and builtin expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[function]" # cd - "4 5 $ZSH_HIGHLIGHT_STYLES[function]" # ls + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[function]}" # cd + "4 5 ${(q-)ZSH_HIGHLIGHT_STYLES[function]}" # ls ) # don't 'unfunction cd ls', since cd() and ls() should still be a functions diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index d808e2b..6d4609e 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -30,9 +30,9 @@ BUFFER=': foo* bar? *baz qux\?' expected_region_highlight=( - "1 1 $ZSH_HIGHLIGHT_STYLES[builtin]" # : - "3 6 $ZSH_HIGHLIGHT_STYLES[globbing]" # foo* - "8 11 $ZSH_HIGHLIGHT_STYLES[globbing]" # bar? - "13 16 $ZSH_HIGHLIGHT_STYLES[globbing]" # *baz - "18 22 $ZSH_HIGHLIGHT_STYLES[default]" # qux\? + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # : + "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # foo* + "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # bar? + "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # *baz + "18 22 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # qux\? ) diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index ce41b45..121f0b8 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -32,5 +32,5 @@ ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight BUFFER='zsh_syntax_highlighting_hash' expected_region_highlight=( - "1 28 $ZSH_HIGHLIGHT_STYLES[hashed-command]" + "1 28 ${(q-)ZSH_HIGHLIGHT_STYLES[hashed-command]}" ) diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 0e818b8..6980b8d 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -31,9 +31,9 @@ ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight BUFFER='!foo bar !baz ! ; !' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !foo - "6 8 $ZSH_HIGHLIGHT_STYLES[default]" # bar - "10 13 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # !baz - "15 15 $ZSH_HIGHLIGHT_STYLES[default]" # ! (before the semicolon) - "19 19 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ! (after the semicolon) + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # !foo + "6 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # bar + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # !baz + "15 15 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # ! (before the semicolon) + "19 19 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ! (after the semicolon) ) diff --git a/highlighters/main/test-data/history-expansion2.zsh b/highlighters/main/test-data/history-expansion2.zsh index 45af624..3840b55 100644 --- a/highlighters/main/test-data/history-expansion2.zsh +++ b/highlighters/main/test-data/history-expansion2.zsh @@ -30,5 +30,5 @@ BUFFER='^foo^bar' expected_region_highlight=( - "1 8 $ZSH_HIGHLIGHT_STYLES[history-expansion]" # ^foo^bar + "1 8 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # ^foo^bar ) diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh index 987dd20..c393812 100644 --- a/highlighters/main/test-data/multiline-string.zsh +++ b/highlighters/main/test-data/multiline-string.zsh @@ -31,6 +31,6 @@ PREBUFFER=$'echo "foo1\n' BUFFER='foo2" ./' expected_region_highlight=( - "1 5 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' - "7 8 $ZSH_HIGHLIGHT_STYLES[path]" # './' + "1 5 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # 'foo2"' + "7 8 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # './' ) diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 9753e5d..eafb17b 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight BUFFER=$'echo "foo1\n' expected_region_highlight=( - "6 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # 'foo2"' + "6 10 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # 'foo2"' ) diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index 374de8a..e842239 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -30,17 +30,17 @@ BUFFER='ps aux | grep java | sort | uniq | tail | head' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps - "4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux - "8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | - "10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep - "15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java - "20 20 $ZSH_HIGHLIGHT_STYLES[default]" # | - "22 25 $ZSH_HIGHLIGHT_STYLES[command]" # sort - "27 27 $ZSH_HIGHLIGHT_STYLES[default]" # | - "29 32 $ZSH_HIGHLIGHT_STYLES[command]" # uniq - "34 34 $ZSH_HIGHLIGHT_STYLES[default]" # | - "36 39 $ZSH_HIGHLIGHT_STYLES[command]" # tail - "41 41 $ZSH_HIGHLIGHT_STYLES[default]" # | - "43 46 $ZSH_HIGHLIGHT_STYLES[command]" # head + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps + "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux + "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep + "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java + "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "22 25 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # sort + "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "29 32 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # uniq + "34 34 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "36 39 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tail + "41 41 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "43 46 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # head ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 44d253a..df8ad23 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -31,5 +31,5 @@ alias x=command BUFFER='x ls' expected_region_highlight=( - "3 4 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "3 4 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh index d9bc69b..52e8f57 100644 --- a/highlighters/main/test-data/noglob1.zsh +++ b/highlighters/main/test-data/noglob1.zsh @@ -30,5 +30,5 @@ BUFFER=':; noglob echo *' expected_region_highlight=( - "16 16 $ZSH_HIGHLIGHT_STYLES[default]" # * + "16 16 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # * ) diff --git a/highlighters/main/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh index 2c19250..c51ca8d 100644 --- a/highlighters/main/test-data/noglob2.zsh +++ b/highlighters/main/test-data/noglob2.zsh @@ -30,6 +30,6 @@ BUFFER='noglob echo *; echo *' expected_region_highlight=( - "13 13 $ZSH_HIGHLIGHT_STYLES[default]" # * - "21 21 $ZSH_HIGHLIGHT_STYLES[globbing]" # * + "13 13 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # * + "21 21 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # * ) diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh index 21434c4..e1de805 100644 --- a/highlighters/main/test-data/option-path_dirs.zsh +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -37,5 +37,5 @@ path+=( "$PWD"/foo ) BUFFER='bar/testing-issue-228' expected_region_highlight=( - "1 21 $ZSH_HIGHLIGHT_STYLES[command]" # bar/testing-issue-228 + "1 21 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # bar/testing-issue-228 ) diff --git a/highlighters/main/test-data/path-space.zsh b/highlighters/main/test-data/path-space.zsh index 7d473a7..d4c9fa6 100644 --- a/highlighters/main/test-data/path-space.zsh +++ b/highlighters/main/test-data/path-space.zsh @@ -32,6 +32,6 @@ touch "A/mu with spaces" BUFFER='ls A/mu\ with\ spaces' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 19 $ZSH_HIGHLIGHT_STYLES[path]" # A/mu\ with\ spaces + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "4 19 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # A/mu\ with\ spaces ) diff --git a/highlighters/main/test-data/path-tilde-home.zsh b/highlighters/main/test-data/path-tilde-home.zsh index 31ad1e9..c5ed284 100644 --- a/highlighters/main/test-data/path-tilde-home.zsh +++ b/highlighters/main/test-data/path-tilde-home.zsh @@ -31,6 +31,6 @@ HOME="." BUFFER='ls ~' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 4 $ZSH_HIGHLIGHT_STYLES[path]" # ~ + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ~ ) diff --git a/highlighters/main/test-data/path-tilde-home2.zsh b/highlighters/main/test-data/path-tilde-home2.zsh index 18dd17b..0726a85 100644 --- a/highlighters/main/test-data/path-tilde-home2.zsh +++ b/highlighters/main/test-data/path-tilde-home2.zsh @@ -31,7 +31,7 @@ HOME="/nonexistent" BUFFER='ls ~' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 4 $ZSH_HIGHLIGHT_STYLES[default]" # ~ + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # ~ ) diff --git a/highlighters/main/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index 235cc1c..3e396bd 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -34,6 +34,6 @@ hash -d D=mydir BUFFER='ls ~D/path-tilde-named.test' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 27 $ZSH_HIGHLIGHT_STYLES[path]" # ~D/path-tilde-named.test + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "4 27 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ~D/path-tilde-named.test ) diff --git a/highlighters/main/test-data/path.zsh b/highlighters/main/test-data/path.zsh index 29384c2..028b4e3 100644 --- a/highlighters/main/test-data/path.zsh +++ b/highlighters/main/test-data/path.zsh @@ -32,6 +32,6 @@ touch A/mu BUFFER='ls A/mu' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "4 7 $ZSH_HIGHLIGHT_STYLES[path]" # A/mu + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # A/mu ) diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index 17cd26c..daa0c4b 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' expected_region_highlight=( - "4 9 $ZSH_HIGHLIGHT_STYLES[path_prefix]" # /bin/s + "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[path_prefix]}" # /bin/s ) diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index a1974eb..bd6990c 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -35,5 +35,5 @@ BUFFER='ls /bin/s' WIDGET=accept-line expected_region_highlight=( - "4 9 $ZSH_HIGHLIGHT_STYLES[default]" # /bin/s + "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # /bin/s ) diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index 156b72d..3ec941a 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -31,7 +31,7 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER=': command zzzzzz' expected_region_highlight=( - "1 1 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "3 9 $ZSH_HIGHLIGHT_STYLES[default]" # not precommand - "11 16 $ZSH_HIGHLIGHT_STYLES[default]" # not unknown-token (since 'zzzzzz' is not a command) + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "3 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not precommand + "11 16 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not unknown-token (since 'zzzzzz' is not a command) ) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 0eddf0f..4681584 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -30,10 +30,10 @@ BUFFER='>/tmp >/tmp sudo echo >/tmp foo' expected_region_highlight=( - "2 5 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "8 11 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "13 16 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "18 21 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "24 27 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "29 31 $ZSH_HIGHLIGHT_STYLES[default]" # foo + "2 5 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "18 21 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "24 27 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "29 31 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # foo ) diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh index 7515352..c1a2049 100644 --- a/highlighters/main/test-data/redirection.zsh +++ b/highlighters/main/test-data/redirection.zsh @@ -32,6 +32,6 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='<<>&!bar' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[redirection]" # <<< - "13 16 $ZSH_HIGHLIGHT_STYLES[redirection]" # >>&! + "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # <<< + "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # >>&! ) diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index 2f62103..50cd72b 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[reserved-word]=$unused_highlight BUFFER='repeat "1" do done' expected_region_highlight=( - "1 6 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # repeat - "8 10 $ZSH_HIGHLIGHT_STYLES[double-quoted-argument]" # "1" - "12 13 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # do - "15 18 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # done + "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # repeat + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "1" + "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # do + "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # done ) diff --git a/highlighters/main/test-data/simple-command.zsh b/highlighters/main/test-data/simple-command.zsh index 51dd9a9..e7a5378 100644 --- a/highlighters/main/test-data/simple-command.zsh +++ b/highlighters/main/test-data/simple-command.zsh @@ -30,5 +30,5 @@ BUFFER='ls' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index 191c67e..11e5ec7 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -30,9 +30,9 @@ BUFFER='ps aux | grep java' expected_region_highlight=( - "1 2 $ZSH_HIGHLIGHT_STYLES[command]" # ps - "4 6 $ZSH_HIGHLIGHT_STYLES[default]" # aux - "8 8 $ZSH_HIGHLIGHT_STYLES[default]" # | - "10 13 $ZSH_HIGHLIGHT_STYLES[command]" # grep - "15 18 $ZSH_HIGHLIGHT_STYLES[default]" # java + "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps + "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux + "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep + "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java ) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 3e98476..c02de9d 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -30,12 +30,12 @@ BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "14 14 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ( - "15 16 $ZSH_HIGHLIGHT_STYLES[command]" # cd - "27 29 $ZSH_HIGHLIGHT_STYLES[command]" # tar - "36 36 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # ) - "40 40 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # { - "42 44 $ZSH_HIGHLIGHT_STYLES[command]" # cat - "46 46 $ZSH_HIGHLIGHT_STYLES[reserved-word]" # } + "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar + "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( + "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # cd + "27 29 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar + "36 36 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ) + "40 40 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { + "42 44 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # cat + "46 46 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # } ) diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index ec1ccff..0fbbb6f 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -35,13 +35,13 @@ ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 8 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -C3 - "10 11 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "13 21 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "23 24 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i - "26 27 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "29 29 $ZSH_HIGHLIGHT_STYLES[path]" # / - "37 37 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because empty command - "47 47 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # ;, error because incomplete command + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "6 8 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -C3 + "10 11 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u + "13 21 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser + "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -i + "26 27 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "29 29 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # / + "37 37 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ;, error because empty command + "47 47 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ;, error because incomplete command ) diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh index 8a70ae3..bb26fe7 100644 --- a/highlighters/main/test-data/sudo-comment.zsh +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -32,7 +32,7 @@ setopt interactive_comments BUFFER='sudo -u # comment' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "9 17 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # "# comment" - error because argument missed + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u + "9 17 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # "# comment" - error because argument missed ) diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index c99e174..8ef5f9f 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -31,17 +31,17 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 7 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "9 9 $ZSH_HIGHLIGHT_STYLES[redirection]" # > - "10 13 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "27 27 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "29 32 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "34 35 $ZSH_HIGHLIGHT_STYLES[command]" # ls - "36 36 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # ; - "38 41 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "43 44 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -i - "46 47 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u + "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # > + "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser + "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "29 32 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "34 35 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "36 36 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; + "38 41 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "43 44 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -i + "46 47 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index 7242f3b..810ff42 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -31,10 +31,10 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo >/tmp -u otheruser ls' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 6 $ZSH_HIGHLIGHT_STYLES[redirection]" # > - "7 10 $ZSH_HIGHLIGHT_STYLES[path]" # /tmp - "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # > + "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp + "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u + "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser + "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index 1e9b215..2ac24e3 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -31,10 +31,10 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo 2>./. -u otheruser ls' expected_region_highlight=( - "1 4 $ZSH_HIGHLIGHT_STYLES[precommand]" # sudo - "6 7 $ZSH_HIGHLIGHT_STYLES[redirection]" # 2> - "8 10 $ZSH_HIGHLIGHT_STYLES[path]" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh - "12 13 $ZSH_HIGHLIGHT_STYLES[single-hyphen-option]" # -u - "15 23 $ZSH_HIGHLIGHT_STYLES[default]" # otheruser - "25 26 $ZSH_HIGHLIGHT_STYLES[command]" # ls + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo + "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # 2> + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh + "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u + "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser + "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls ) diff --git a/highlighters/main/test-data/tilde-command-word.zsh b/highlighters/main/test-data/tilde-command-word.zsh index e66db8e..cb9c87b 100644 --- a/highlighters/main/test-data/tilde-command-word.zsh +++ b/highlighters/main/test-data/tilde-command-word.zsh @@ -32,6 +32,6 @@ hash -d D=/usr/bin BUFFER='~D/env foo' expected_region_highlight=( - "1 6 $ZSH_HIGHLIGHT_STYLES[command]" # ~D/env [= /usr/bin/env] - "8 10 $ZSH_HIGHLIGHT_STYLES[default]" # foo + "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ~D/env [= /usr/bin/env]} + "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # foo ) diff --git a/highlighters/main/test-data/unbackslash.zsh b/highlighters/main/test-data/unbackslash.zsh index b96c055..fcdaf44 100644 --- a/highlighters/main/test-data/unbackslash.zsh +++ b/highlighters/main/test-data/unbackslash.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[command]=$unused_highlight BUFFER='\sh' expected_region_highlight=( - "1 3 $ZSH_HIGHLIGHT_STYLES[command]" # \sh (runs 'sh', bypassing aliases) + "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # \sh (runs 'sh', bypassing aliases) ) diff --git a/highlighters/main/test-data/unknown-command.zsh b/highlighters/main/test-data/unknown-command.zsh index 9b9e8d3..4fd8663 100644 --- a/highlighters/main/test-data/unknown-command.zsh +++ b/highlighters/main/test-data/unknown-command.zsh @@ -30,5 +30,5 @@ BUFFER='azertyuiop' expected_region_highlight=( - "1 10 $ZSH_HIGHLIGHT_STYLES[unknown-token]" # azertyuiop + "1 10 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # azertyuiop ) diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index 7fa9ba2..4f270a8 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -31,9 +31,9 @@ PREBUFFER=$'echo foo; echo bar\n\n\n' BUFFER=' echo baz; echo qux' expected_region_highlight=( - "2 5 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "7 9 $ZSH_HIGHLIGHT_STYLES[default]" # baz - "10 10 $ZSH_HIGHLIGHT_STYLES[commandseparator]" # semicolon - "12 15 $ZSH_HIGHLIGHT_STYLES[builtin]" # echo - "17 19 $ZSH_HIGHLIGHT_STYLES[default]" # qux + "2 5 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "7 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # baz + "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # semicolon + "12 15 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "17 19 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # qux ) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index b59997d..9254ba4 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -103,8 +103,8 @@ run_test_internal() { highlight_zone=${(z)expected_region_highlight[$i]} [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do - if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + if [[ "$observed_result[$j]" != "${(Q)highlight_zone[3]}" ]]; then + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(Q)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done From 78290e043bc51122378d6559054a47f23e143e8b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 2 Apr 2016 20:40:54 -0500 Subject: [PATCH 0309/1080] tests: Expect the correct style --- highlighters/main/test-data/anonymous-function.zsh | 4 ++-- highlighters/main/test-data/assign-semicolon.zsh | 2 +- highlighters/main/test-data/backslash-continuation.zsh | 2 +- highlighters/main/test-data/comments.zsh | 2 +- highlighters/main/test-data/multiple-redirections.zsh | 10 +++++----- highlighters/main/test-data/precommand.zsh | 2 +- highlighters/main/test-data/simple-redirection.zsh | 2 +- highlighters/main/test-data/subshell.zsh | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index 57ab884..e301a66 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -31,10 +31,10 @@ BUFFER='() echo hello; () { echo world }' expected_region_highlight=( "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () - "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo "9 13 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # hello "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; "16 17 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () "19 19 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { - "21 24 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "21 24 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo ) diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index e76d260..9b81195 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -32,5 +32,5 @@ BUFFER='A=1; echo hello world' expected_region_highlight=( "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "6 9 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "6 9 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo ) diff --git a/highlighters/main/test-data/backslash-continuation.zsh b/highlighters/main/test-data/backslash-continuation.zsh index 9fbd916..e1fd1d3 100644 --- a/highlighters/main/test-data/backslash-continuation.zsh +++ b/highlighters/main/test-data/backslash-continuation.zsh @@ -31,5 +31,5 @@ PREBUFFER=$'echo \\\n' BUFFER='noglob' expected_region_highlight=( - "1 6 none" # 'noglob' highlighted as a string, not as a precomand + "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # 'noglob' highlighted as a string, not as a precomand ) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index 24ed51c..0ef4956 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -32,7 +32,7 @@ setopt interactive_comments BUFFER='echo "foo #bar" #baz # quux' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # echo + "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo "6 15 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo #bar" "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux ) diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index e842239..5dc8931 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -32,15 +32,15 @@ BUFFER='ps aux | grep java | sort | uniq | tail | head' expected_region_highlight=( "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux - "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java - "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "22 25 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # sort - "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "29 32 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # uniq - "34 34 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "34 34 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "36 39 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tail - "41 41 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "41 41 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "43 46 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # head ) diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index 3ec941a..e2fc541 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -31,7 +31,7 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER=': command zzzzzz' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # : "3 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not precommand "11 16 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not unknown-token (since 'zzzzzz' is not a command) ) diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index 11e5ec7..f4bd696 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -32,7 +32,7 @@ BUFFER='ps aux | grep java' expected_region_highlight=( "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux - "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # | + "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java ) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index c02de9d..17110ed 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -32,7 +32,7 @@ BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }' expected_region_highlight=( "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( - "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # cd + "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # cd "27 29 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar "36 36 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ) "40 40 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { From 367929502fc1e6cb5a1bacc5ff8cc8a317cb998a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 5 Apr 2016 05:49:18 +0000 Subject: [PATCH 0310/1080] release.md: Add a release checklist line item. --- release.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release.md b/release.md index 3d044a3..4a1ba5c 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,7 @@ # Release procedure (for developers): +- For minor (A.B.0) releases: + - Check whether the release uses any not-yet-released zsh features - Check open issues and outstanding pull requests - Confirm `make test` passes - check with multiple zsh versions From d4f8edc9f3ad334398f1ffc1f7ef93b2d83c1ecd Mon Sep 17 00:00:00 2001 From: Adam Kruszewski Date: Sun, 17 Apr 2016 04:48:30 +0000 Subject: [PATCH 0311/1080] plugin.zsh: Convert from symlink to plain file Fixes zsh-users/zsh-syntax-highlighting#292 (compatibility with zsh-5.1.1/msys2 on windows). --- zsh-syntax-highlighting.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 120000 => 100644 zsh-syntax-highlighting.plugin.zsh diff --git a/zsh-syntax-highlighting.plugin.zsh b/zsh-syntax-highlighting.plugin.zsh deleted file mode 120000 index cc95cd4..0000000 --- a/zsh-syntax-highlighting.plugin.zsh +++ /dev/null @@ -1 +0,0 @@ -zsh-syntax-highlighting.zsh \ No newline at end of file diff --git a/zsh-syntax-highlighting.plugin.zsh b/zsh-syntax-highlighting.plugin.zsh new file mode 100644 index 0000000..2fa8b3b --- /dev/null +++ b/zsh-syntax-highlighting.plugin.zsh @@ -0,0 +1 @@ +source ${0:A:h}/zsh-syntax-highlighting.zsh From b52a485c5c8d161a1abeea7db9a1a8a44e527985 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 Apr 2016 14:12:49 +0000 Subject: [PATCH 0312/1080] brackets: Optimize a tiny bit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compute «${#BUFFER}» just once. I haven't measured the effect of this, but it might just avoid a strlen() every time around the loop, which could add up for large ${BUFFER}s. See issue #295. --- highlighters/brackets/brackets-highlighter.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 2b87a3e..2571b58 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -48,10 +48,11 @@ _zsh_highlight_brackets_highlighter() { local level=0 pos local -A levelpos lastoflevel matching typepos + integer buflen=${#BUFFER} region_highlight=() # Find all brackets and remember which one is matching - for (( pos = 0; $pos < ${#BUFFER}; pos++ )) ; do + for (( pos = 0; pos < buflen; pos++ )) ; do local char="$BUFFER[pos+1]" case $char in ["([{"]) @@ -68,9 +69,9 @@ _zsh_highlight_brackets_highlighter() ['"'\']) # Skip everything inside quotes local quotetype=$char - while (( $pos < ${#BUFFER} )) ; do + while (( pos < buflen )) ; do (( pos++ )) - [[ $BUFFER[$pos+1] == $quotetype ]] && break + [[ $BUFFER[pos+1] == $quotetype ]] && break done ;; esac From 38c8fbea2dd22b32a5fa3793f7fa34133c5b2e07 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Mon, 28 Mar 2016 14:55:56 +0200 Subject: [PATCH 0313/1080] root-highlighter: use EUID instead of id -u command No need to fork every time. --- highlighters/root/root-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/root/root-highlighter.zsh b/highlighters/root/root-highlighter.zsh index 4362379..a9039d6 100644 --- a/highlighters/root/root-highlighter.zsh +++ b/highlighters/root/root-highlighter.zsh @@ -40,5 +40,5 @@ _zsh_highlight_root_highlighter_predicate() # root highlighting function. _zsh_highlight_root_highlighter() { - if [[ $(command id -u) -eq 0 ]] { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") } + if (( EUID == 0 )) { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") } } From c54c076cfa4501f9ef36652395011b8e661feb90 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 24 Apr 2016 17:08:08 +0000 Subject: [PATCH 0314/1080] cleanup: Avoid colon after parameter expansion to avoid risking introducing a colon modifier. --- 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 9ff3a7f..e171339 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -148,14 +148,14 @@ _zsh_highlight_apply_zle_highlight() { integer first="$3" second="$4" # read the relevant entry from zle_highlight - local region="${zle_highlight[(r)$entry:*]}" + local region="${zle_highlight[(r)${entry}:*]}" if [[ -z "$region" ]]; then # entry not specified at all, use default value region=$default else # strip prefix - region="${region#$entry:}" + region="${region#${entry}:}" # no highlighting when set to the empty string or to 'none' if [[ -z "$region" ]] || [[ "$region" == none ]]; then From a830613467af83971270299186a866ef6fa9f58f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 14:22:24 -0500 Subject: [PATCH 0315/1080] tests: Specify the style key instead of the style itself --- .../test-data/mismatch-patentheses.zsh | 8 ++--- .../brackets/test-data/nested-parentheses.zsh | 12 +++---- .../brackets/test-data/quoted-patentheses.zsh | 2 +- .../brackets/test-data/simple-parentheses.zsh | 8 ++--- .../test-data/unclosed-patentheses.zsh | 6 ++-- .../test-data/unclosed-patentheses2.zsh | 6 ++-- .../main/test-data/alias-assignment1.zsh | 2 +- highlighters/main/test-data/alias.zsh | 4 +-- .../main/test-data/anonymous-function.zsh | 14 ++++---- .../main/test-data/arithmetic-evaluation.zsh | 4 +-- highlighters/main/test-data/assign-append.zsh | 2 +- highlighters/main/test-data/assign-array.zsh | 8 ++--- .../main/test-data/assign-semicolon.zsh | 4 +-- .../main/test-data/assign-subshell.zsh | 6 ++-- highlighters/main/test-data/assign.zsh | 8 ++--- .../main/test-data/back-quoted-argument.zsh | 2 +- .../main/test-data/backslash-continuation.zsh | 2 +- .../main/test-data/commandseparator.zsh | 8 ++--- .../main/test-data/comment-leading.zsh | 4 +-- highlighters/main/test-data/comment-off.zsh | 6 ++-- highlighters/main/test-data/comments.zsh | 6 ++-- .../main/test-data/commmand-parameter.zsh | 4 +-- highlighters/main/test-data/control-flow.zsh | 34 +++++++++---------- highlighters/main/test-data/dollar-quoted.zsh | 4 +-- .../main/test-data/dollar-quoted2.zsh | 14 ++++---- .../main/test-data/dollar-quoted3.zsh | 4 +-- .../main/test-data/double-hyphen-option.zsh | 2 +- highlighters/main/test-data/double-quoted.zsh | 22 ++++++------ .../main/test-data/double-quoted2.zsh | 4 +-- .../main/test-data/double-quoted3.zsh | 10 +++--- .../main/test-data/double-quoted4.zsh | 6 ++-- highlighters/main/test-data/empty-command.zsh | 4 +-- .../main/test-data/empty-command2.zsh | 4 +-- .../main/test-data/exec-redirection1.zsh | 10 +++--- highlighters/main/test-data/function.zsh | 4 +-- highlighters/main/test-data/glob.zsh | 10 +++--- .../main/test-data/hashed-command.zsh | 2 +- .../main/test-data/history-expansion.zsh | 10 +++--- .../main/test-data/history-expansion2.zsh | 2 +- .../main/test-data/multiline-string.zsh | 4 +-- .../main/test-data/multiline-string2.zsh | 2 +- .../main/test-data/multiple-redirections.zsh | 26 +++++++------- highlighters/main/test-data/noglob-alias.zsh | 2 +- highlighters/main/test-data/noglob1.zsh | 2 +- highlighters/main/test-data/noglob2.zsh | 4 +-- .../main/test-data/option-path_dirs.zsh | 2 +- highlighters/main/test-data/path-space.zsh | 4 +-- .../main/test-data/path-tilde-home.zsh | 4 +-- .../main/test-data/path-tilde-home2.zsh | 4 +-- .../main/test-data/path-tilde-named.zsh | 4 +-- highlighters/main/test-data/path.zsh | 4 +-- highlighters/main/test-data/path_prefix.zsh | 2 +- highlighters/main/test-data/path_prefix2.zsh | 2 +- highlighters/main/test-data/precommand.zsh | 6 ++-- .../main/test-data/prefix-redirection.zsh | 12 +++---- highlighters/main/test-data/redirection.zsh | 4 +-- highlighters/main/test-data/reserved-word.zsh | 8 ++--- .../main/test-data/simple-command.zsh | 2 +- .../main/test-data/simple-redirection.zsh | 10 +++--- highlighters/main/test-data/subshell.zsh | 16 ++++----- highlighters/main/test-data/sudo-command.zsh | 18 +++++----- highlighters/main/test-data/sudo-comment.zsh | 6 ++-- .../main/test-data/sudo-redirection.zsh | 26 +++++++------- .../main/test-data/sudo-redirection2.zsh | 12 +++---- .../main/test-data/sudo-redirection3.zsh | 12 +++---- .../main/test-data/tilde-command-word.zsh | 4 +-- highlighters/main/test-data/unbackslash.zsh | 2 +- .../main/test-data/unknown-command.zsh | 2 +- .../main/test-data/vanilla-newline.zsh | 10 +++--- tests/test-highlighting.zsh | 4 +-- 70 files changed, 246 insertions(+), 246 deletions(-) diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index b45b868..f0991b0 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -30,8 +30,8 @@ BUFFER='echo ({x}]' expected_region_highlight=( - "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ( - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { - "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } - "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ) + "6 6 bracket-error" # ( + "7 7 bracket-level-2" # { + "9 9 bracket-level-2" # } + "10 10 bracket-error" # ) ) diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 028aed1..b3f531b 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -30,10 +30,10 @@ BUFFER='echo $(echo ${(z)array})' expected_region_highlight=( - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ( - "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { - "15 15 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-3]}" # ( - "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-3]}" # ) - "23 23 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } - "24 24 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ) + "7 7 bracket-level-1" # ( + "14 14 bracket-level-2" # { + "15 15 bracket-level-3" # ( + "17 17 bracket-level-3" # ) + "23 23 bracket-level-2" # } + "24 24 bracket-level-1" # ) ) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 5819180..954445e 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -30,5 +30,5 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 16 ${(q-)ZSH_HIGHLIGHT_STYLES[none]}" # We expect the brackets highlighter to do nothing +"1 16 none" # We expect the brackets highlighter to do nothing ) diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index 8e0c1a3..3fc66df 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -30,8 +30,8 @@ BUFFER='echo ({x})' expected_region_highlight=( - "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ( - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { - "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } - "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # ) + "6 6 bracket-level-1" # ( + "7 7 bracket-level-2" # { + "9 9 bracket-level-2" # } + "10 10 bracket-level-1" # ) ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index 4edfc46..e1a634a 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -30,7 +30,7 @@ BUFFER='echo ({x}' expected_region_highlight=( - "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ( - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # { - "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-2]}" # } + "6 6 bracket-error" # ( + "7 7 bracket-level-2" # { + "9 9 bracket-level-2" # } ) diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 15c7fbe..1a1937f 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -30,7 +30,7 @@ BUFFER='echo {x})' expected_region_highlight=( - "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # { - "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-level-1]}" # } - "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[bracket-error]}" # ) + "6 6 bracket-level-1" # { + "8 8 bracket-level-1" # } + "9 9 bracket-error" # ) ) diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh index 435b72d..3cdf4e6 100644 --- a/highlighters/main/test-data/alias-assignment1.zsh +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x=y ls' expected_region_highlight=( - "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # x=y + "1 3 unknown-token" # x=y ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index ea804fa..344f0de 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -43,9 +43,9 @@ BUFFER='x.alias2; alias1' expected_region_highlight=() if [[ "$(type -w x.alias2)" == *suffix* ]]; then expected_region_highlight+=( - "1 8 ${(q-)ZSH_HIGHLIGHT_STYLES[suffix-alias]}" # x.alias2 + "1 8 suffix-alias" # x.alias2 ) fi expected_region_highlight+=( - "11 16 ${(q-)ZSH_HIGHLIGHT_STYLES[alias]}" # alias1 + "11 16 alias" # alias1 ) diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index e301a66..a6fbcf0 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -30,11 +30,11 @@ BUFFER='() echo hello; () { echo world }' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () - "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "9 13 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # hello - "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "16 17 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # () - "19 19 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { - "21 24 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "1 2 reserved-word" # () + "4 7 builtin" # echo + "9 13 default" # hello + "14 14 commandseparator" # ; + "16 17 reserved-word" # () + "19 19 reserved-word" # { + "21 24 builtin" # echo ) diff --git a/highlighters/main/test-data/arithmetic-evaluation.zsh b/highlighters/main/test-data/arithmetic-evaluation.zsh index e5caaa8..e0eb6e7 100644 --- a/highlighters/main/test-data/arithmetic-evaluation.zsh +++ b/highlighters/main/test-data/arithmetic-evaluation.zsh @@ -35,6 +35,6 @@ BUFFER='(( x == 42 ))' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # (( - "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # )) + "1 2 reserved-word" # (( + "12 13 reserved-word" # )) ) diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 094ea3f..82b48f9 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='a+=(lorem ipsum)' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # a+=( + "1 4 assign" # a+=( ) diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh index 377a4cc..be3f13b 100644 --- a/highlighters/main/test-data/assign-array.zsh +++ b/highlighters/main/test-data/assign-array.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=(hello world))' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( - "2 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=( - "16 16 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # ) - "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ) + "1 1 reserved-word" # ( + "2 4 assign" # A=( + "16 16 assign" # ) + "17 17 reserved-word" # ) ) diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index 9b81195..8fe2964 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -31,6 +31,6 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER='A=1; echo hello world' expected_region_highlight=( - "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "6 9 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo + "4 4 commandseparator" # ; + "6 9 builtin" # echo ) diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh index 784c968..f9639fe 100644 --- a/highlighters/main/test-data/assign-subshell.zsh +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -31,7 +31,7 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=1)' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( - "2 4 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=1 - "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]} 'issue #231'" # ) + "1 1 reserved-word" # ( + "2 4 assign" # A=1 + "5 5 reserved-word 'issue #231'" # ) ) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 443fff8..9148d52 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( - "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # A=1 - "5 7 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # b=( - "8 12 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo" - "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[assign]}" # ) + "1 3 assign" # A=1 + "5 7 assign" # b=( + "8 12 double-quoted-argument" # "foo" + "17 17 assign" # ) ) diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index cb182b5..cd73212 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight BUFFER='echo `echo 42`' expected_region_highlight=( - "6 14 ${(q-)ZSH_HIGHLIGHT_STYLES[back-quoted-argument]}" + "6 14 back-quoted-argument" ) diff --git a/highlighters/main/test-data/backslash-continuation.zsh b/highlighters/main/test-data/backslash-continuation.zsh index e1fd1d3..ebcf2e1 100644 --- a/highlighters/main/test-data/backslash-continuation.zsh +++ b/highlighters/main/test-data/backslash-continuation.zsh @@ -31,5 +31,5 @@ PREBUFFER=$'echo \\\n' BUFFER='noglob' expected_region_highlight=( - "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # 'noglob' highlighted as a string, not as a precomand + "1 6 default" # 'noglob' highlighted as a string, not as a precomand ) diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index 1f66f3f..e478318 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -32,8 +32,8 @@ ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER=':; pwd &! ls' expected_region_highlight=( - "2 2 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # pwd - "8 9 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # &! - "11 12 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "2 2 commandseparator" # ; + "4 6 builtin" # pwd + "8 9 commandseparator" # &! + "11 12 command" # ls ) diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh index d5ccdfd..f750cc4 100644 --- a/highlighters/main/test-data/comment-leading.zsh +++ b/highlighters/main/test-data/comment-leading.zsh @@ -32,6 +32,6 @@ setopt interactive_comments BUFFER='# echo foo' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # # - "2 10 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # " echo foo" + "1 1 comment" # # + "2 10 comment" # " echo foo" ) diff --git a/highlighters/main/test-data/comment-off.zsh b/highlighters/main/test-data/comment-off.zsh index a9a346e..0381bdb 100644 --- a/highlighters/main/test-data/comment-off.zsh +++ b/highlighters/main/test-data/comment-off.zsh @@ -32,7 +32,7 @@ unsetopt interactive_comments BUFFER='# echo foo' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # # - "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" - "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # " echo foo" + "1 1 unknown-token" # # + "3 6 default" # " echo foo" + "8 10 default" # " echo foo" ) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index 0ef4956..3bb008e 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -32,7 +32,7 @@ setopt interactive_comments BUFFER='echo "foo #bar" #baz # quux' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "6 15 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo #bar" - "17 27 ${(q-)ZSH_HIGHLIGHT_STYLES[comment]}" # #baz # quux + "1 4 builtin" # echo + "6 15 double-quoted-argument" # "foo #bar" + "17 27 comment" # #baz # quux ) diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index 4cffde7..fb43e9e 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -31,6 +31,6 @@ x=/usr/bin/env BUFFER='$x "argument"' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # $x - "4 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "argument" + "1 2 command" # $x + "4 13 double-quoted-argument" # "argument" ) diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 1de787b..58a696b 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -31,21 +31,21 @@ ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' expected_region_highlight+=( - "1 5 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # while - "7 8 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # if - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "15 19 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # Hello - "22 25 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # then - "27 28 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "30 30 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # / - "31 31 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "33 36 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # else - "38 39 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "42 43 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # fi - "46 47 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # do - "49 52 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # stat - "54 56 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "x" - "59 62 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # done - "65 70 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # repeat - "75 76 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 5 reserved-word" # while + "7 8 reserved-word" # if + "10 13 builtin" # echo + "15 19 default" # Hello + "22 25 reserved-word" # then + "27 28 command" # ls + "30 30 path" # / + "31 31 commandseparator" # ; + "33 36 reserved-word" # else + "38 39 command" # ls + "42 43 reserved-word" # fi + "46 47 reserved-word" # do + "49 52 command" # stat + "54 56 double-quoted-argument" # "x" + "59 62 reserved-word" # done + "65 70 reserved-word" # repeat + "75 76 command" # ls ) diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index f8ffefa..cfeb6d3 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -31,6 +31,6 @@ ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight BUFFER=": \$'*' 'foo'" expected_region_highlight=( - "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $'*' - not a glob - "8 12 ${(q-)ZSH_HIGHLIGHT_STYLES[single-quoted-argument]}" # 'foo' + "3 6 dollar-quoted-argument" # $'*' - not a glob + "8 12 single-quoted-argument" # 'foo' ) diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index a29edbb..03afc66 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -31,11 +31,11 @@ ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( - "3 7 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $'foo - "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \xba - "12 12 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # r - "13 18 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \dead - "19 22 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # beef - "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # \u - "25 29 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # zzzz' + "3 7 dollar-quoted-argument" # $'foo + "8 11 back-dollar-quoted-argument" # \xba + "12 12 dollar-quoted-argument" # r + "13 18 back-dollar-quoted-argument" # \dead + "19 22 dollar-quoted-argument" # beef + "23 24 unknown-token" # \u + "25 29 dollar-quoted-argument" # zzzz' ) diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index eb1ee82..cb5bd77 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -33,6 +33,6 @@ ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight BUFFER=": \$'\xa1" expected_region_highlight=( - "3 4 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]}" # $' - "5 8 ${(q-)ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]}" # \xa1 + "3 4 dollar-quoted-argument" # $' + "5 8 back-dollar-quoted-argument" # \xa1 ) diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index eb7514f..3339d89 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight BUFFER='hello --world' expected_region_highlight=( - "7 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-hyphen-option]}" # --world + "7 13 double-hyphen-option" # --world ) diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index ececcca..7e379f8 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -31,15 +31,15 @@ BUFFER=': "foo$bar:\`:\":\$:' BUFFER+=\\\\:\" expected_region_highlight=( - "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo - "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $bar - "11 11 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : - "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \` - "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : - "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \$ - "17 17 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : - "18 19 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \" - "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # : - "21 22 ${(q-)ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]}" # \\ - "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # :" + "3 6 double-quoted-argument" # "foo + "7 10 dollar-double-quoted-argument" # $bar + "11 11 double-quoted-argument" # : + "12 13 back-double-quoted-argument" # \` + "14 14 double-quoted-argument" # : + "15 16 back-double-quoted-argument" # \$ + "17 17 double-quoted-argument" # : + "18 19 back-double-quoted-argument" # \" + "20 20 double-quoted-argument" # : + "21 22 back-double-quoted-argument" # \\ + "23 24 double-quoted-argument" # :" ) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index dcae235..1538423 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -32,6 +32,6 @@ BUFFER=': "foo$bar' expected_region_highlight=( - "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "foo - "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $bar + "3 6 double-quoted-argument" # "foo + "7 10 dollar-double-quoted-argument" # $bar ) diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index efbcd63..39514e0 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -31,9 +31,9 @@ BUFFER=': "$" "$42foo"' BUFFER+=\ \"\\\'\\x\" expected_region_highlight=( - "3 5 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "$" - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # " - "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # $42 - "11 14 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # foo" - "16 21 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "\'\x" - \' and \x are not escape sequences + "3 5 double-quoted-argument" # "$" + "7 7 double-quoted-argument" # " + "8 10 dollar-double-quoted-argument" # $42 + "11 14 double-quoted-argument" # foo" + "16 21 double-quoted-argument" # "\'\x" - \' and \x are not escape sequences ) diff --git a/highlighters/main/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh index 4a1e205..51bb25e 100644 --- a/highlighters/main/test-data/double-quoted4.zsh +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -30,7 +30,7 @@ BUFFER=': "${foo}bar"' expected_region_highlight=( - "3 3 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # " - "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]}" # ${foo} - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # bar" + "3 3 double-quoted-argument" # " + "4 9 dollar-double-quoted-argument" # ${foo} + "10 13 double-quoted-argument" # bar" ) diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index 4da62ba..6e68184 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -30,6 +30,6 @@ BUFFER='echo; ;' expected_region_highlight=( - "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ; + "5 5 commandseparator" # ; + "7 7 unknown-token" # ; ) diff --git a/highlighters/main/test-data/empty-command2.zsh b/highlighters/main/test-data/empty-command2.zsh index a4d5538..698b3a7 100644 --- a/highlighters/main/test-data/empty-command2.zsh +++ b/highlighters/main/test-data/empty-command2.zsh @@ -33,6 +33,6 @@ touch ';' BUFFER='echo; ;' expected_region_highlight=( - "5 5 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "7 7 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ; + "5 5 commandseparator" # ; + "7 7 unknown-token" # ; ) diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh index 9d74587..47fd9f6 100644 --- a/highlighters/main/test-data/exec-redirection1.zsh +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -31,9 +31,9 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='exec {foo}>&/tmp ls' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # exec - # TODO: "6 10 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]} 'issue #238'" # {foo} - "11 12 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # >& - "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "18 19 ${(q-)ZSH_HIGHLIGHT_STYLES[command]} 'issue #238'" # ls + "1 4 precommand" # exec + # TODO: "6 10 redirection 'issue #238'" # {foo} + "11 12 redirection" # >& + "13 16 path" # /tmp + "18 19 command 'issue #238'" # ls ) diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index fa19b91..27c60a1 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -39,8 +39,8 @@ BUFFER='cd;ls' # Use $unused_highlight to see that function highlighting has precedence over command and builtin expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[function]}" # cd - "4 5 ${(q-)ZSH_HIGHLIGHT_STYLES[function]}" # ls + "1 2 function" # cd + "4 5 function" # ls ) # don't 'unfunction cd ls', since cd() and ls() should still be a functions diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index 6d4609e..2fd9c6f 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -30,9 +30,9 @@ BUFFER=': foo* bar? *baz qux\?' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # : - "3 6 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # foo* - "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # bar? - "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # *baz - "18 22 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # qux\? + "1 1 builtin" # : + "3 6 globbing" # foo* + "8 11 globbing" # bar? + "13 16 globbing" # *baz + "18 22 default" # qux\? ) diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index 121f0b8..1cc24b0 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -32,5 +32,5 @@ ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight BUFFER='zsh_syntax_highlighting_hash' expected_region_highlight=( - "1 28 ${(q-)ZSH_HIGHLIGHT_STYLES[hashed-command]}" + "1 28 hashed-command" ) diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 6980b8d..be511b0 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -31,9 +31,9 @@ ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight BUFFER='!foo bar !baz ! ; !' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # !foo - "6 8 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # bar - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # !baz - "15 15 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # ! (before the semicolon) - "19 19 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ! (after the semicolon) + "1 4 history-expansion" # !foo + "6 8 default" # bar + "10 13 history-expansion" # !baz + "15 15 default" # ! (before the semicolon) + "19 19 reserved-word" # ! (after the semicolon) ) diff --git a/highlighters/main/test-data/history-expansion2.zsh b/highlighters/main/test-data/history-expansion2.zsh index 3840b55..386d0df 100644 --- a/highlighters/main/test-data/history-expansion2.zsh +++ b/highlighters/main/test-data/history-expansion2.zsh @@ -30,5 +30,5 @@ BUFFER='^foo^bar' expected_region_highlight=( - "1 8 ${(q-)ZSH_HIGHLIGHT_STYLES[history-expansion]}" # ^foo^bar + "1 8 history-expansion" # ^foo^bar ) diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh index c393812..484c951 100644 --- a/highlighters/main/test-data/multiline-string.zsh +++ b/highlighters/main/test-data/multiline-string.zsh @@ -31,6 +31,6 @@ PREBUFFER=$'echo "foo1\n' BUFFER='foo2" ./' expected_region_highlight=( - "1 5 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # 'foo2"' - "7 8 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # './' + "1 5 double-quoted-argument" # 'foo2"' + "7 8 path" # './' ) diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index eafb17b..3d45002 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight BUFFER=$'echo "foo1\n' expected_region_highlight=( - "6 10 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # 'foo2"' + "6 10 double-quoted-argument" # 'foo2"' ) diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index 5dc8931..778e712 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -30,17 +30,17 @@ BUFFER='ps aux | grep java | sort | uniq | tail | head' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps - "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux - "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep - "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java - "20 20 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "22 25 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # sort - "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "29 32 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # uniq - "34 34 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "36 39 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tail - "41 41 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "43 46 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # head + "1 2 command" # ps + "4 6 default" # aux + "8 8 commandseparator" # | + "10 13 command" # grep + "15 18 default" # java + "20 20 commandseparator" # | + "22 25 command" # sort + "27 27 commandseparator" # | + "29 32 command" # uniq + "34 34 commandseparator" # | + "36 39 command" # tail + "41 41 commandseparator" # | + "43 46 command" # head ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index df8ad23..6f3a7f7 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -31,5 +31,5 @@ alias x=command BUFFER='x ls' expected_region_highlight=( - "3 4 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "3 4 command" # ls ) diff --git a/highlighters/main/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh index 52e8f57..ea70a83 100644 --- a/highlighters/main/test-data/noglob1.zsh +++ b/highlighters/main/test-data/noglob1.zsh @@ -30,5 +30,5 @@ BUFFER=':; noglob echo *' expected_region_highlight=( - "16 16 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # * + "16 16 default" # * ) diff --git a/highlighters/main/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh index c51ca8d..6d7a940 100644 --- a/highlighters/main/test-data/noglob2.zsh +++ b/highlighters/main/test-data/noglob2.zsh @@ -30,6 +30,6 @@ BUFFER='noglob echo *; echo *' expected_region_highlight=( - "13 13 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # * - "21 21 ${(q-)ZSH_HIGHLIGHT_STYLES[globbing]}" # * + "13 13 default" # * + "21 21 globbing" # * ) diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh index e1de805..1f3002a 100644 --- a/highlighters/main/test-data/option-path_dirs.zsh +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -37,5 +37,5 @@ path+=( "$PWD"/foo ) BUFFER='bar/testing-issue-228' expected_region_highlight=( - "1 21 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # bar/testing-issue-228 + "1 21 command" # bar/testing-issue-228 ) diff --git a/highlighters/main/test-data/path-space.zsh b/highlighters/main/test-data/path-space.zsh index d4c9fa6..67a26fd 100644 --- a/highlighters/main/test-data/path-space.zsh +++ b/highlighters/main/test-data/path-space.zsh @@ -32,6 +32,6 @@ touch "A/mu with spaces" BUFFER='ls A/mu\ with\ spaces' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "4 19 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # A/mu\ with\ spaces + "1 2 command" # ls + "4 19 path" # A/mu\ with\ spaces ) diff --git a/highlighters/main/test-data/path-tilde-home.zsh b/highlighters/main/test-data/path-tilde-home.zsh index c5ed284..8b1c680 100644 --- a/highlighters/main/test-data/path-tilde-home.zsh +++ b/highlighters/main/test-data/path-tilde-home.zsh @@ -31,6 +31,6 @@ HOME="." BUFFER='ls ~' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ~ + "1 2 command" # ls + "4 4 path" # ~ ) diff --git a/highlighters/main/test-data/path-tilde-home2.zsh b/highlighters/main/test-data/path-tilde-home2.zsh index 0726a85..3f7b820 100644 --- a/highlighters/main/test-data/path-tilde-home2.zsh +++ b/highlighters/main/test-data/path-tilde-home2.zsh @@ -31,7 +31,7 @@ HOME="/nonexistent" BUFFER='ls ~' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "4 4 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # ~ + "1 2 command" # ls + "4 4 default" # ~ ) diff --git a/highlighters/main/test-data/path-tilde-named.zsh b/highlighters/main/test-data/path-tilde-named.zsh index 3e396bd..335b3fd 100644 --- a/highlighters/main/test-data/path-tilde-named.zsh +++ b/highlighters/main/test-data/path-tilde-named.zsh @@ -34,6 +34,6 @@ hash -d D=mydir BUFFER='ls ~D/path-tilde-named.test' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "4 27 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ~D/path-tilde-named.test + "1 2 command" # ls + "4 27 path" # ~D/path-tilde-named.test ) diff --git a/highlighters/main/test-data/path.zsh b/highlighters/main/test-data/path.zsh index 028b4e3..d387eff 100644 --- a/highlighters/main/test-data/path.zsh +++ b/highlighters/main/test-data/path.zsh @@ -32,6 +32,6 @@ touch A/mu BUFFER='ls A/mu' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "4 7 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # A/mu + "1 2 command" # ls + "4 7 path" # A/mu ) diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index daa0c4b..e945fe2 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -34,5 +34,5 @@ ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' expected_region_highlight=( - "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[path_prefix]}" # /bin/s + "4 9 path_prefix" # /bin/s ) diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index bd6990c..761c004 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -35,5 +35,5 @@ BUFFER='ls /bin/s' WIDGET=accept-line expected_region_highlight=( - "4 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # /bin/s + "4 9 default" # /bin/s ) diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index e2fc541..04697cf 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -31,7 +31,7 @@ ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER=': command zzzzzz' expected_region_highlight=( - "1 1 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # : - "3 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not precommand - "11 16 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # not unknown-token (since 'zzzzzz' is not a command) + "1 1 builtin" # : + "3 9 default" # not precommand + "11 16 default" # not unknown-token (since 'zzzzzz' is not a command) ) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 4681584..5a5c0e2 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -30,10 +30,10 @@ BUFFER='>/tmp >/tmp sudo echo >/tmp foo' expected_region_highlight=( - "2 5 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "8 11 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "18 21 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "24 27 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "29 31 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # foo + "2 5 path" # /tmp + "8 11 path" # /tmp + "13 16 precommand" # sudo + "18 21 builtin" # echo + "24 27 path" # /tmp + "29 31 default" # foo ) diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh index c1a2049..e26fb7d 100644 --- a/highlighters/main/test-data/redirection.zsh +++ b/highlighters/main/test-data/redirection.zsh @@ -32,6 +32,6 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='<<>&!bar' expected_region_highlight=( - "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # <<< - "13 16 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # >>&! + "1 3 redirection" # <<< + "13 16 redirection" # >>&! ) diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index 50cd72b..8442a4c 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -31,8 +31,8 @@ ZSH_HIGHLIGHT_STYLES[reserved-word]=$unused_highlight BUFFER='repeat "1" do done' expected_region_highlight=( - "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # repeat - "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[double-quoted-argument]}" # "1" - "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # do - "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # done + "1 6 reserved-word" # repeat + "8 10 double-quoted-argument" # "1" + "12 13 reserved-word" # do + "15 18 reserved-word" # done ) diff --git a/highlighters/main/test-data/simple-command.zsh b/highlighters/main/test-data/simple-command.zsh index e7a5378..8bb41fd 100644 --- a/highlighters/main/test-data/simple-command.zsh +++ b/highlighters/main/test-data/simple-command.zsh @@ -30,5 +30,5 @@ BUFFER='ls' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 2 command" # ls ) diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index f4bd696..e8c25e5 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -30,9 +30,9 @@ BUFFER='ps aux | grep java' expected_region_highlight=( - "1 2 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ps - "4 6 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # aux - "8 8 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # | - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # grep - "15 18 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # java + "1 2 command" # ps + "4 6 default" # aux + "8 8 commandseparator" # | + "10 13 command" # grep + "15 18 default" # java ) diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 17110ed..0080ad2 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -30,12 +30,12 @@ BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }' expected_region_highlight=( - "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar - "14 14 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ( - "15 16 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # cd - "27 29 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # tar - "36 36 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # ) - "40 40 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # { - "42 44 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # cat - "46 46 ${(q-)ZSH_HIGHLIGHT_STYLES[reserved-word]}" # } + "1 3 command" # tar + "14 14 reserved-word" # ( + "15 16 builtin" # cd + "27 29 command" # tar + "36 36 reserved-word" # ) + "40 40 reserved-word" # { + "42 44 command" # cat + "46 46 reserved-word" # } ) diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 0fbbb6f..49fc6a6 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -35,13 +35,13 @@ ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "6 8 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -C3 - "10 11 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u - "13 21 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser - "23 24 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -i - "26 27 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "29 29 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # / - "37 37 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ;, error because empty command - "47 47 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # ;, error because incomplete command + "1 4 precommand" # sudo + "6 8 single-hyphen-option" # -C3 + "10 11 single-hyphen-option" # -u + "13 21 default" # otheruser + "23 24 single-hyphen-option" # -i + "26 27 command" # ls + "29 29 path" # / + "37 37 unknown-token" # ;, error because empty command + "47 47 unknown-token" # ;, error because incomplete command ) diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh index bb26fe7..e66f13d 100644 --- a/highlighters/main/test-data/sudo-comment.zsh +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -32,7 +32,7 @@ setopt interactive_comments BUFFER='sudo -u # comment' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u - "9 17 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # "# comment" - error because argument missed + "1 4 precommand" # sudo + "6 7 single-hyphen-option" # -u + "9 17 unknown-token" # "# comment" - error because argument missed ) diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index 8ef5f9f..5581c1b 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -31,17 +31,17 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u - "9 9 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # > - "10 13 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser - "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "27 27 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "29 32 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "34 35 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls - "36 36 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # ; - "38 41 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "43 44 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -i - "46 47 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 4 precommand" # sudo + "6 7 single-hyphen-option" # -u + "9 9 redirection" # > + "10 13 path" # /tmp + "15 23 default" # otheruser + "25 26 command" # ls + "27 27 commandseparator" # ; + "29 32 precommand" # sudo + "34 35 command" # ls + "36 36 commandseparator" # ; + "38 41 precommand" # sudo + "43 44 single-hyphen-option" # -i + "46 47 command" # ls ) diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index 810ff42..4a2d9d0 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -31,10 +31,10 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo >/tmp -u otheruser ls' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "6 6 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # > - "7 10 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # /tmp - "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u - "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser - "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 4 precommand" # sudo + "6 6 redirection" # > + "7 10 path" # /tmp + "12 13 single-hyphen-option" # -u + "15 23 default" # otheruser + "25 26 command" # ls ) diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index 2ac24e3..91d456d 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -31,10 +31,10 @@ ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo 2>./. -u otheruser ls' expected_region_highlight=( - "1 4 ${(q-)ZSH_HIGHLIGHT_STYLES[precommand]}" # sudo - "6 7 ${(q-)ZSH_HIGHLIGHT_STYLES[redirection]}" # 2> - "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[path]}" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh - "12 13 ${(q-)ZSH_HIGHLIGHT_STYLES[single-hyphen-option]}" # -u - "15 23 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # otheruser - "25 26 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ls + "1 4 precommand" # sudo + "6 7 redirection" # 2> + "8 10 path" # ./. # a 3-character path, for alignment with sudo-redirection2.zsh + "12 13 single-hyphen-option" # -u + "15 23 default" # otheruser + "25 26 command" # ls ) diff --git a/highlighters/main/test-data/tilde-command-word.zsh b/highlighters/main/test-data/tilde-command-word.zsh index cb9c87b..67c996c 100644 --- a/highlighters/main/test-data/tilde-command-word.zsh +++ b/highlighters/main/test-data/tilde-command-word.zsh @@ -32,6 +32,6 @@ hash -d D=/usr/bin BUFFER='~D/env foo' expected_region_highlight=( - "1 6 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # ~D/env [= /usr/bin/env]} - "8 10 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # foo + "1 6 command" # ~D/env [= /usr/bin/env + "8 10 default" # foo ) diff --git a/highlighters/main/test-data/unbackslash.zsh b/highlighters/main/test-data/unbackslash.zsh index fcdaf44..9731df5 100644 --- a/highlighters/main/test-data/unbackslash.zsh +++ b/highlighters/main/test-data/unbackslash.zsh @@ -31,5 +31,5 @@ ZSH_HIGHLIGHT_STYLES[command]=$unused_highlight BUFFER='\sh' expected_region_highlight=( - "1 3 ${(q-)ZSH_HIGHLIGHT_STYLES[command]}" # \sh (runs 'sh', bypassing aliases) + "1 3 command" # \sh (runs 'sh', bypassing aliases) ) diff --git a/highlighters/main/test-data/unknown-command.zsh b/highlighters/main/test-data/unknown-command.zsh index 4fd8663..e71faec 100644 --- a/highlighters/main/test-data/unknown-command.zsh +++ b/highlighters/main/test-data/unknown-command.zsh @@ -30,5 +30,5 @@ BUFFER='azertyuiop' expected_region_highlight=( - "1 10 ${(q-)ZSH_HIGHLIGHT_STYLES[unknown-token]}" # azertyuiop + "1 10 unknown-token" # azertyuiop ) diff --git a/highlighters/main/test-data/vanilla-newline.zsh b/highlighters/main/test-data/vanilla-newline.zsh index 4f270a8..bd60ad4 100644 --- a/highlighters/main/test-data/vanilla-newline.zsh +++ b/highlighters/main/test-data/vanilla-newline.zsh @@ -31,9 +31,9 @@ PREBUFFER=$'echo foo; echo bar\n\n\n' BUFFER=' echo baz; echo qux' expected_region_highlight=( - "2 5 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "7 9 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # baz - "10 10 ${(q-)ZSH_HIGHLIGHT_STYLES[commandseparator]}" # semicolon - "12 15 ${(q-)ZSH_HIGHLIGHT_STYLES[builtin]}" # echo - "17 19 ${(q-)ZSH_HIGHLIGHT_STYLES[default]}" # qux + "2 5 builtin" # echo + "7 9 default" # baz + "10 10 commandseparator" # semicolon + "12 15 builtin" # echo + "17 19 default" # qux ) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 9254ba4..2886f73 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -103,8 +103,8 @@ run_test_internal() { highlight_zone=${(z)expected_region_highlight[$i]} [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do - if [[ "$observed_result[$j]" != "${(Q)highlight_zone[3]}" ]]; then - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(Q)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + if [[ "$observed_result[$j]" != "$ZSH_HIGHLIGHT_STYLES[$highlight_zone[3]]" ]]; then + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)ZSH_HIGHLIGHT_STYLES[$highlight_zone[3]]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done From 089329660bb3930915e98d9ce289978e61a04c45 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 16:04:32 -0500 Subject: [PATCH 0316/1080] highlighters: Pass around the style key instead of the style itself --- .../brackets/brackets-highlighter.zsh | 12 +-- highlighters/main/main-highlighter.zsh | 88 +++++++++---------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 2571b58..cc756e8 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -82,11 +82,11 @@ _zsh_highlight_brackets_highlighter() if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) - local style=$ZSH_HIGHLIGHT_STYLES[$bracket_color_level] - region_highlight+=("$pos $((pos + 1)) $style") + local style=$bracket_color_level + region_highlight+=("$pos $((pos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") else - local style=$ZSH_HIGHLIGHT_STYLES[bracket-error] - region_highlight+=("$pos $((pos + 1)) $style") + local style=bracket-error + region_highlight+=("$pos $((pos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") fi done @@ -94,8 +94,8 @@ _zsh_highlight_brackets_highlighter() pos=$CURSOR if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then local otherpos=$matching[$pos] - local style=$ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket] - region_highlight+=("$otherpos $((otherpos + 1)) $style") + local style=cursor-matchingbracket + region_highlight+=("$otherpos $((otherpos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") fi } diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2f43255..9260ebe 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -68,7 +68,7 @@ _zsh_highlight_main_highlighter_predicate() # Helper to deal with tokens crossing line boundaries. _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 - local style=$3 + local style=$ZSH_HIGHLIGHT_STYLES[$3] # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # relative to $BUFFER. @@ -245,9 +245,9 @@ _zsh_highlight_main_highlighter() if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then - style=$ZSH_HIGHLIGHT_STYLES[comment] + style=comment else - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] # prematurely terminated + style=unknown-token # prematurely terminated fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style already_added=1 @@ -275,9 +275,9 @@ _zsh_highlight_main_highlighter() if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then - style=$ZSH_HIGHLIGHT_STYLES[precommand] + style=precommand elif [[ "$arg" = "sudo" ]]; then - style=$ZSH_HIGHLIGHT_STYLES[precommand] + style=precommand next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' @@ -300,9 +300,9 @@ _zsh_highlight_main_highlighter() fi } case $res in - *': reserved') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; + *': reserved') style=reserved-word;; *': suffix alias') - style=$ZSH_HIGHLIGHT_STYLES[suffix-alias] + style=suffix-alias ;; *': alias') () { integer insane_alias @@ -319,20 +319,20 @@ _zsh_highlight_main_highlighter() (*) :;; esac if (( insane_alias )); then - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + style=unknown-token else - style=$ZSH_HIGHLIGHT_STYLES[alias] + style=alias local aliased_command="${"$(alias -- $arg)"#*=}" [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) fi } ;; - *': builtin') style=$ZSH_HIGHLIGHT_STYLES[builtin];; - *': function') style=$ZSH_HIGHLIGHT_STYLES[function];; - *': command') style=$ZSH_HIGHLIGHT_STYLES[command];; - *': hashed') style=$ZSH_HIGHLIGHT_STYLES[hashed-command];; + *': builtin') style=builtin;; + *': function') style=function;; + *': command') style=command;; + *': hashed') style=hashed-command;; *) if _zsh_highlight_main_highlighter_check_assign; then - style=$ZSH_HIGHLIGHT_STYLES[assign] + style=assign if [[ $arg[-1] == '(' ]]; then in_array_assignment=true else @@ -341,20 +341,20 @@ _zsh_highlight_main_highlighter() next_word+=':start:' fi elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then - style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + style=history-expansion elif [[ $arg[0,1] == $histchars[2,2] ]]; then - style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + style=history-expansion elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then # This highlights empty commands (semicolon follows nothing) as an error. # Zsh accepts them, though. - style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + style=commandseparator else - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + style=unknown-token fi elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then # A '<' or '>', possibly followed by a digit - style=$ZSH_HIGHLIGHT_STYLES[redirection] + style=redirection (( in_redirection=2 )) elif [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. @@ -366,7 +366,7 @@ _zsh_highlight_main_highlighter() # # We highlight just the opening parentheses, as a reserved word; this # is how [[ ... ]] is highlighted, too. - style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + style=reserved-word _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style already_added=1 if [[ $arg[-2,-1] == '))' ]]; then @@ -376,12 +376,12 @@ _zsh_highlight_main_highlighter() elif [[ $arg == '()' || $arg == $'\x28' ]]; then # anonymous function # subshell - style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + style=reserved-word else if _zsh_highlight_main_highlighter_check_path; then - style=$ZSH_HIGHLIGHT_STYLES[path] + style=path else - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + style=unknown-token fi fi ;; @@ -391,52 +391,52 @@ _zsh_highlight_main_highlighter() case $arg in $'\x29') # subshell or end of array assignment if $in_array_assignment; then - style=$ZSH_HIGHLIGHT_STYLES[assign] + style=assign in_array_assignment=false else - style=$ZSH_HIGHLIGHT_STYLES[reserved-word] + style=reserved-word fi;; - $'\x7d') style=$ZSH_HIGHLIGHT_STYLES[reserved-word];; # block - '--'*) style=$ZSH_HIGHLIGHT_STYLES[double-hyphen-option];; - '-'*) style=$ZSH_HIGHLIGHT_STYLES[single-hyphen-option];; - "'"*) style=$ZSH_HIGHLIGHT_STYLES[single-quoted-argument];; - '"'*) style=$ZSH_HIGHLIGHT_STYLES[double-quoted-argument] + $'\x7d') style=reserved-word;; # block + '--'*) style=double-hyphen-option;; + '-'*) style=single-hyphen-option;; + "'"*) style=single-quoted-argument;; + '"'*) style=double-quoted-argument _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_string already_added=1 ;; - \$\'*) style=$ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument] + \$\'*) style=dollar-quoted-argument _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style _zsh_highlight_main_highlighter_highlight_dollar_string already_added=1 ;; - '`'*) style=$ZSH_HIGHLIGHT_STYLES[back-quoted-argument];; + '`'*) style=back-quoted-argument;; [*?]*|*[^\\][*?]*) - $highlight_glob && style=$ZSH_HIGHLIGHT_STYLES[globbing] || style=$ZSH_HIGHLIGHT_STYLES[default];; + $highlight_glob && style=globbing || style=default;; *) if false; then elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then - style=$ZSH_HIGHLIGHT_STYLES[history-expansion] + style=history-expansion elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $this_word == *':regular:'* ]]; then - style=$ZSH_HIGHLIGHT_STYLES[commandseparator] + style=commandseparator else - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + style=unknown-token fi elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then - style=$ZSH_HIGHLIGHT_STYLES[redirection] + style=redirection (( in_redirection=2 )) else if _zsh_highlight_main_highlighter_check_path; then - style=$ZSH_HIGHLIGHT_STYLES[path] + style=path else - style=$ZSH_HIGHLIGHT_STYLES[default] + style=default fi fi ;; esac fi # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it - [[ -n $style_override ]] && style=$ZSH_HIGHLIGHT_STYLES[$style_override] + [[ -n $style_override ]] && style=$style_override (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then next_word=':start:' @@ -508,7 +508,7 @@ _zsh_highlight_main_highlighter_highlight_string() (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in - '$' ) style=$ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument] + '$' ) 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 @@ -520,7 +520,7 @@ _zsh_highlight_main_highlighter_highlight_string() continue fi ;; - "\\") style=$ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument] + "\\") style=back-double-quoted-argument if [[ \\\`\"\$ == *$arg[$i+1]* ]]; then (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. @@ -549,7 +549,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in - "\\") style=$ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument] + "\\") style=back-dollar-quoted-argument for (( c = i + 1 ; c <= end_pos - start_pos ; c += 1 )); do [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break done @@ -565,7 +565,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() else if (( $#arg > $i+1 )) && [[ $arg[$i+1] == [xXuU] ]]; then # \x not followed by hex digits is probably an error - style=$ZSH_HIGHLIGHT_STYLES[unknown-token] + style=unknown-token fi (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. From 341a3ae1f015fc366edfa7d31d0f96c693c9343c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 29 Apr 2016 09:48:39 -0500 Subject: [PATCH 0317/1080] highlighters: Use _zsh_highlight_add_highlight _zsh_highlight_add_highlight appends to region_highlight $1 $2 and the next non-null parameter. If there is no non-null parameter, do nothing, This is so that highlighters can add a style with fallbacks if the most specific style is not defined. If none of the applicable styles are defined, do the right thing and don't add an invalid entry to region_highlight. The pattern highlighter doesn't use this function as it'd need too large of an API change. --- highlighters/brackets/brackets-highlighter.zsh | 6 +++--- highlighters/cursor/cursor-highlighter.zsh | 2 +- highlighters/line/line-highlighter.zsh | 2 +- highlighters/main/main-highlighter.zsh | 5 ++--- highlighters/root/root-highlighter.zsh | 2 +- zsh-syntax-highlighting.zsh | 17 +++++++++++++++++ 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index cc756e8..3875b99 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -83,10 +83,10 @@ _zsh_highlight_brackets_highlighter() local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) local style=$bracket_color_level - region_highlight+=("$pos $((pos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") + _zsh_highlight_add_highlight $pos $((pos + 1)) $style else local style=bracket-error - region_highlight+=("$pos $((pos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") + _zsh_highlight_add_highlight $pos $((pos + 1)) $style fi done @@ -95,7 +95,7 @@ _zsh_highlight_brackets_highlighter() if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then local otherpos=$matching[$pos] local style=cursor-matchingbracket - region_highlight+=("$otherpos $((otherpos + 1)) $ZSH_HIGHLIGHT_STYLES[$style]") + _zsh_highlight_add_highlight $otherpos $((otherpos + 1)) $style fi } diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index 5685c40..aa70f55 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -44,5 +44,5 @@ _zsh_highlight_cursor_highlighter() { [[ $WIDGET == accept-* ]] && return - region_highlight+=("$CURSOR $(( $CURSOR + 1 )) $ZSH_HIGHLIGHT_STYLES[cursor]") + _zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor } diff --git a/highlighters/line/line-highlighter.zsh b/highlighters/line/line-highlighter.zsh index 68308cc..2da55ea 100644 --- a/highlighters/line/line-highlighter.zsh +++ b/highlighters/line/line-highlighter.zsh @@ -40,5 +40,5 @@ _zsh_highlight_line_highlighter_predicate() # root highlighting function. _zsh_highlight_line_highlighter() { - region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[line]") + _zsh_highlight_add_highlight 0 $#BUFFER line } diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 9260ebe..a0f8dba 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -68,7 +68,7 @@ _zsh_highlight_main_highlighter_predicate() # Helper to deal with tokens crossing line boundaries. _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 - local style=$ZSH_HIGHLIGHT_STYLES[$3] + local style=$3 # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # relative to $BUFFER. @@ -77,7 +77,7 @@ _zsh_highlight_main_add_region_highlight() { (( end < 0 )) && return # having end<0 would be a bug (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings - region_highlight+=("$start $end $style") + _zsh_highlight_add_highlight $start $end $style } # Wrapper around 'type -w'. @@ -126,7 +126,6 @@ _zsh_highlight_main_highlighter() local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" integer len="${#buf}" - region_highlight=() if (( path_dirs_was_set )); then options_to_set+=( PATH_DIRS ) diff --git a/highlighters/root/root-highlighter.zsh b/highlighters/root/root-highlighter.zsh index a9039d6..ede9769 100644 --- a/highlighters/root/root-highlighter.zsh +++ b/highlighters/root/root-highlighter.zsh @@ -40,5 +40,5 @@ _zsh_highlight_root_highlighter_predicate() # root highlighting function. _zsh_highlight_root_highlighter() { - if (( EUID == 0 )) { region_highlight+=("0 $#BUFFER $ZSH_HIGHLIGHT_STYLES[root]") } + if (( EUID == 0 )) { _zsh_highlight_add_highlight 0 $#BUFFER root } } diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index e171339..8d3e42a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -196,6 +196,23 @@ _zsh_highlight_cursor_moved() [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) } +# Add a highlight defined by ZSH_HIGHLIGHT_STYLES +# +# Should be used by all highlighters aside from 'pattern' (cf. ZSH_HIGHLIGHT_PATTERN) +_zsh_highlight_add_highlight() +{ + local -i start end + local highlight + start=$1 + end=$2 + shift 2 + for highlight; do + if (( $+ZSH_HIGHLIGHT_STYLES[$highlight] )); then + region_highlight+=("$start $end $ZSH_HIGHLIGHT_STYLES[$highlight]") + break + fi + done +} # ------------------------------------------------------------------------------------------------- # Setup functions From f34714b8ee6a956efe51d4de645df55f822daa60 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 30 Apr 2016 02:11:17 +0000 Subject: [PATCH 0318/1080] Bump copyright years. --- COPYING.md | 2 +- tests/test-highlighting.zsh | 2 +- zsh-syntax-highlighting.zsh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/COPYING.md b/COPYING.md index 5512a0a..3d6b811 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2015 zsh-syntax-highlighting contributors +Copyright (c) 2010-2016 zsh-syntax-highlighting contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 2886f73..e3c7415 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2015 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 8d3e42a..4f70fff 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2015 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From c346f6eb6fb601a03ee333685d195c16a3c411e3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 29 Apr 2016 21:23:09 -0500 Subject: [PATCH 0319/1080] docs: highlighters should use _zsh_highlight_add_highlight --- docs/highlighters.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 266abe1..3309fb9 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -64,12 +64,17 @@ To create your own `myhighlighter` highlighter: } * Implement the `_zsh_highlight_myhighlighter_highlighter` function. - This function does the actual syntax highlighting, by modifying - `region_highlight`, for example: + This function does the actual syntax highlighting, by calling + `_zsh_highlight_add_highlight` with the start and end of the region to + be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default + style for that key in the highlighter script outside of any function with `: + ${ZSH_HIGHLIGHT_STYLES[key]:=value}`. For example: + + : ${ZSH_HIGHLIGHT_STYLES[aurora]:=fg=green} _zsh_highlight_myhighlighter_highlighter() { - # Colorize the whole buffer with blue background - region_highlight+=(0 $#BUFFER bg=blue) + # Colorize the whole buffer with the 'aurora' style + _zsh_highlight_add_highlight 0 $#BUFFER aurora } * Activate your highlighter in `~/.zshrc`: From 4da9889d154509a8ee30605618d2256cf511cae4 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 30 Apr 2016 12:35:41 -0500 Subject: [PATCH 0320/1080] tests: Use 'NONE' to denote no highlighting 'none' is a valid highlighting type. Since by convention styles are all lowercase, 'NONE' shouldn't conflict with anything. Closes #289. --- highlighters/brackets/test-data/quoted-patentheses.zsh | 2 +- tests/test-highlighting.zsh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 954445e..5c3dcea 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -30,5 +30,5 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 16 none" # We expect the brackets highlighter to do nothing +"1 16 NONE" # We expect the brackets highlighter to do nothing ) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index e3c7415..73dc098 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -101,6 +101,7 @@ run_test_internal() { for ((i=1; i<=${#expected_region_highlight}; i++)); do local todo= highlight_zone=${(z)expected_region_highlight[$i]} + [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do if [[ "$observed_result[$j]" != "$ZSH_HIGHLIGHT_STYLES[$highlight_zone[3]]" ]]; then From e8af14fe1f6f1b60062b67d8a70daabd9df6a8be Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 3 May 2016 15:00:48 +0000 Subject: [PATCH 0321/1080] minor: Rewrap docs for uncompiled readability. --- docs/highlighters.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 3309fb9..9b43430 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -67,8 +67,8 @@ To create your own `myhighlighter` highlighter: This function does the actual syntax highlighting, by calling `_zsh_highlight_add_highlight` with the start and end of the region to be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default - style for that key in the highlighter script outside of any function with `: - ${ZSH_HIGHLIGHT_STYLES[key]:=value}`. For example: + style for that key in the highlighter script outside of any function with + `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`. For example: : ${ZSH_HIGHLIGHT_STYLES[aurora]:=fg=green} From cef49752fd0ec9935544d23be878bf3c19c50d89 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 01:20:32 +0000 Subject: [PATCH 0322/1080] dev docs: Create HACKING.md. Review-by: Matthew Martin --- HACKING.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 HACKING.md diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..5ce72d8 --- /dev/null +++ b/HACKING.md @@ -0,0 +1,32 @@ +Hacking on zsh-syntax-highlighting itself +========================================= + +This document includes information for people working on z-sy-h itself: on the +core driver (`zsh-syntax-highlighting.zsh`), on the highlighters in the +distribution, and on the test suite. It does not target third-party +highlighter authors (although they may find it an interesting read). + +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 + } + +It prints, for each argument, its token breakdown, similar to how the main +loop of the `main` highlighter sees it. + +IRC channel +----------- + +We're on #zsh-syntax-highlighting on freenode. + From fd840102527126044b1fae9e2b6bead33e7e1c58 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 21:02:20 -0500 Subject: [PATCH 0323/1080] 'brackets': Lift local declarations from inside loops --- .../brackets/brackets-highlighter.zsh | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 3875b99..9e94c83 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -46,14 +46,13 @@ _zsh_highlight_brackets_highlighter_predicate() # Brackets highlighting function. _zsh_highlight_brackets_highlighter() { - local level=0 pos + local char quotetype style + local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 pos local -A levelpos lastoflevel matching typepos - integer buflen=${#BUFFER} - region_highlight=() # Find all brackets and remember which one is matching for (( pos = 0; pos < buflen; pos++ )) ; do - local char="$BUFFER[pos+1]" + char="$BUFFER[pos+1]" case $char in ["([{"]) levelpos[$pos]=$((++level)) @@ -68,7 +67,7 @@ _zsh_highlight_brackets_highlighter() ;; ['"'\']) # Skip everything inside quotes - local quotetype=$char + quotetype=$char while (( pos < buflen )) ; do (( pos++ )) [[ $BUFFER[pos+1] == $quotetype ]] && break @@ -80,12 +79,10 @@ _zsh_highlight_brackets_highlighter() # Now highlight all found brackets for pos in ${(k)levelpos}; do if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then - local bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} - local bracket_color_level=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) - local style=$bracket_color_level + style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) _zsh_highlight_add_highlight $pos $((pos + 1)) $style else - local style=bracket-error + style=bracket-error _zsh_highlight_add_highlight $pos $((pos + 1)) $style fi done @@ -93,9 +90,8 @@ _zsh_highlight_brackets_highlighter() # If cursor is on a bracket, then highlight corresponding bracket, if any pos=$CURSOR if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then - local otherpos=$matching[$pos] - local style=cursor-matchingbracket - _zsh_highlight_add_highlight $otherpos $((otherpos + 1)) $style + local -i otherpos=$matching[$pos] + _zsh_highlight_add_highlight $otherpos $((otherpos + 1)) cursor-matchingbracket fi } From f4d3dcb42f58da709e8784ade7e4169c8d4a5bcd Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 21:06:43 -0500 Subject: [PATCH 0324/1080] 'brackets': Move highlight call outside conditional --- highlighters/brackets/brackets-highlighter.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 9e94c83..5a2d939 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -80,11 +80,10 @@ _zsh_highlight_brackets_highlighter() for pos in ${(k)levelpos}; do if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) - _zsh_highlight_add_highlight $pos $((pos + 1)) $style else style=bracket-error - _zsh_highlight_add_highlight $pos $((pos + 1)) $style fi + _zsh_highlight_add_highlight $pos $((pos + 1)) $style done # If cursor is on a bracket, then highlight corresponding bracket, if any From 95d82568d8f9d4ba34eb293b6ce792854a14f110 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 21:07:37 -0500 Subject: [PATCH 0325/1080] 'brackets': Use one-based indexing zsh arrays start at one, and this will make the next commit easier. --- highlighters/brackets/brackets-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 5a2d939..0252fa1 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -51,8 +51,8 @@ _zsh_highlight_brackets_highlighter() local -A levelpos lastoflevel matching typepos # Find all brackets and remember which one is matching - for (( pos = 0; pos < buflen; pos++ )) ; do - char="$BUFFER[pos+1]" + for (( pos = 1; pos <= buflen; pos++ )) ; do + char=$BUFFER[pos] case $char in ["([{"]) levelpos[$pos]=$((++level)) @@ -83,7 +83,7 @@ _zsh_highlight_brackets_highlighter() else style=bracket-error fi - _zsh_highlight_add_highlight $pos $((pos + 1)) $style + _zsh_highlight_add_highlight $((pos - 1)) $pos $style done # If cursor is on a bracket, then highlight corresponding bracket, if any From e05b8e88adc6f399f546f8900038289febda6a18 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 21:09:53 -0500 Subject: [PATCH 0326/1080] 'brackets': Check if brackets match on first pass This removes the need for the typepos array. --- .../brackets/brackets-highlighter.zsh | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 0252fa1..8709223 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -47,8 +47,8 @@ _zsh_highlight_brackets_highlighter_predicate() _zsh_highlight_brackets_highlighter() { local char quotetype style - local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 pos - local -A levelpos lastoflevel matching typepos + local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos + local -A levelpos lastoflevel matching # Find all brackets and remember which one is matching for (( pos = 1; pos <= buflen; pos++ )) ; do @@ -57,13 +57,14 @@ _zsh_highlight_brackets_highlighter() ["([{"]) levelpos[$pos]=$((++level)) lastoflevel[$level]=$pos - _zsh_highlight_brackets_highlighter_brackettype "$char" ;; [")]}"]) - matching[$lastoflevel[$level]]=$pos - matching[$pos]=$lastoflevel[$level] + matchingpos=$lastoflevel[$level] levelpos[$pos]=$((level--)) - _zsh_highlight_brackets_highlighter_brackettype "$char" + if _zsh_highlight_brackets_match $matchingpos $pos; then + matching[$matchingpos]=$pos + matching[$pos]=$matchingpos + fi ;; ['"'\']) # Skip everything inside quotes @@ -78,7 +79,7 @@ _zsh_highlight_brackets_highlighter() # Now highlight all found brackets for pos in ${(k)levelpos}; do - if [[ -n $matching[$pos] ]] && [[ $typepos[$pos] == $typepos[$matching[$pos]] ]]; then + if (( $+matching[$pos] )); then style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) else style=bracket-error @@ -95,12 +96,12 @@ _zsh_highlight_brackets_highlighter() } # Helper function to differentiate type -_zsh_highlight_brackets_highlighter_brackettype() +_zsh_highlight_brackets_match() { - case $1 in - ["()"]) typepos[$pos]=round;; - ["[]"]) typepos[$pos]=bracket;; - ["{}"]) typepos[$pos]=curly;; - *) ;; + case $BUFFER[$1] in + \() [[ $BUFFER[$2] == \) ]];; + \[) [[ $BUFFER[$2] == \] ]];; + \{) [[ $BUFFER[$2] == \} ]];; + *) false;; esac } From ccaf6f48a10e7653c2e4b80571e59d07c0de442f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 4 May 2016 23:50:45 -0500 Subject: [PATCH 0327/1080] brackets: Fix bug introduced in 95d8256 --- highlighters/brackets/brackets-highlighter.zsh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 8709223..f8db178 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -46,7 +46,7 @@ _zsh_highlight_brackets_highlighter_predicate() # Brackets highlighting function. _zsh_highlight_brackets_highlighter() { - local char quotetype style + local char style local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos local -A levelpos lastoflevel matching @@ -68,11 +68,7 @@ _zsh_highlight_brackets_highlighter() ;; ['"'\']) # Skip everything inside quotes - quotetype=$char - while (( pos < buflen )) ; do - (( pos++ )) - [[ $BUFFER[pos+1] == $quotetype ]] && break - done + pos=$BUFFER[(ib:pos+1:)$char] ;; esac done From fd061b5730bfbeec29167b48631805b56e191334 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 2 Apr 2016 20:27:10 -0500 Subject: [PATCH 0328/1080] tests: Test ZSH_HIGHLIGHT_STYLES keys directly Closes #287. Testing the keys directly removes the need for unused_highlight which will be removed next. --- tests/test-highlighting.zsh | 10 ++++++++-- zsh-syntax-highlighting.zsh | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 73dc098..83b4b3c 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -50,6 +50,12 @@ # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh +# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style +_zsh_highlight_add_highlight() +{ + region_highlight+=("$1 $2 $3") +} + # Activate the highlighter. ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) @@ -104,8 +110,8 @@ run_test_internal() { [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do - if [[ "$observed_result[$j]" != "$ZSH_HIGHLIGHT_STYLES[$highlight_zone[3]]" ]]; then - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)ZSH_HIGHLIGHT_STYLES[$highlight_zone[3]]}, observed ${(qqq)observed_result[$j]}.$todo" + if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected $highlight_zone[3], observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4f70fff..ca06fb0 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -196,9 +196,10 @@ _zsh_highlight_cursor_moved() [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR)) } -# Add a highlight defined by ZSH_HIGHLIGHT_STYLES +# Add a highlight defined by ZSH_HIGHLIGHT_STYLES. # -# Should be used by all highlighters aside from 'pattern' (cf. ZSH_HIGHLIGHT_PATTERN) +# Should be used by all highlighters aside from 'pattern' (cf. ZSH_HIGHLIGHT_PATTERN). +# Overwritten in tests/test-highlighting.zsh when testing. _zsh_highlight_add_highlight() { local -i start end From d3678ec7a89ea90a464580940f6929b3e165e772 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 21:55:47 -0500 Subject: [PATCH 0329/1080] tests: Remove unused_highlight --- highlighters/main/test-data/alias-assignment1.zsh | 1 - highlighters/main/test-data/alias.zsh | 1 - highlighters/main/test-data/assign-append.zsh | 1 - highlighters/main/test-data/assign-array.zsh | 1 - highlighters/main/test-data/assign-semicolon.zsh | 1 - highlighters/main/test-data/assign-subshell.zsh | 1 - highlighters/main/test-data/assign.zsh | 1 - highlighters/main/test-data/back-quoted-argument.zsh | 1 - highlighters/main/test-data/commandseparator.zsh | 2 -- highlighters/main/test-data/control-flow.zsh | 1 - highlighters/main/test-data/dollar-quoted.zsh | 1 - highlighters/main/test-data/dollar-quoted2.zsh | 1 - highlighters/main/test-data/dollar-quoted3.zsh | 1 - highlighters/main/test-data/double-hyphen-option.zsh | 1 - highlighters/main/test-data/exec-redirection1.zsh | 1 - highlighters/main/test-data/function.zsh | 3 --- highlighters/main/test-data/hashed-command.zsh | 1 - highlighters/main/test-data/history-expansion.zsh | 1 - highlighters/main/test-data/multiline-string2.zsh | 1 - highlighters/main/test-data/path_prefix.zsh | 1 - highlighters/main/test-data/path_prefix2.zsh | 1 - highlighters/main/test-data/precommand.zsh | 1 - highlighters/main/test-data/redirection.zsh | 1 - highlighters/main/test-data/reserved-word.zsh | 1 - highlighters/main/test-data/sudo-command.zsh | 1 - highlighters/main/test-data/sudo-comment.zsh | 1 - highlighters/main/test-data/sudo-redirection.zsh | 1 - highlighters/main/test-data/sudo-redirection2.zsh | 1 - highlighters/main/test-data/sudo-redirection3.zsh | 1 - highlighters/main/test-data/unbackslash.zsh | 1 - tests/test-highlighting.zsh | 1 - tests/test-perfs.zsh | 1 - 32 files changed, 35 deletions(-) diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh index 3cdf4e6..cf5be75 100644 --- a/highlighters/main/test-data/alias-assignment1.zsh +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -30,7 +30,6 @@ # Issue #263 (more-pathological case): aliases[x=y]=z works; the ${(z)} splitter considers # that a single word; but it's not looked up as an alias. Hence, highlight it as an error. aliases[x=y]='lorem ipsum dolor sit amet' -ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x=y ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 344f0de..5129614 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -31,7 +31,6 @@ alias alias1="unused expansion" alias -s alias2="echo" alias1() {} # to check that it's highlighted as an alias, not as a function -ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='x.alias2; alias1' # Set expected_region_highlight as a function of zsh version. diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 82b48f9..6485f0e 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='a+=(lorem ipsum)' expected_region_highlight=( diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh index be3f13b..8995162 100644 --- a/highlighters/main/test-data/assign-array.zsh +++ b/highlighters/main/test-data/assign-array.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=(hello world))' expected_region_highlight=( diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index 8fe2964..c2618b0 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight BUFFER='A=1; echo hello world' expected_region_highlight=( diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh index f9639fe..77cdd65 100644 --- a/highlighters/main/test-data/assign-subshell.zsh +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='(A=1)' expected_region_highlight=( diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 9148d52..7e18731 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index cd73212..f8329ea 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=$unused_highlight BUFFER='echo `echo 42`' expected_region_highlight=( diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index e478318..e8d93a6 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -27,8 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[commandseparator]=$unused_highlight - BUFFER=':; pwd &! ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 58a696b..2f6a160 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[alias]=$unused_highlight BUFFER='while if echo Hello; then ls /; else ls; fi; do stat "x"; done; repeat 10 ls' expected_region_highlight+=( diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index cfeb6d3..8c4c16f 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=$unused_highlight BUFFER=": \$'*' 'foo'" expected_region_highlight=( diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index 03afc66..a69373f 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index cb5bd77..320cd94 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -28,7 +28,6 @@ # ------------------------------------------------------------------------------------------------- # Similar to double-quoted2.zsh -ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=$unused_highlight # This test checks that the '1' gets highlighted correctly. Do not append to the BUFFER. BUFFER=": \$'\xa1" diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index 3339d89..9728cd8 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=$unused_highlight BUFFER='hello --world' expected_region_highlight=( diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh index 47fd9f6..784ec47 100644 --- a/highlighters/main/test-data/exec-redirection1.zsh +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='exec {foo}>&/tmp ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index 27c60a1..6876391 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[function]=$unused_highlight cd() { builtin cd "$@" } @@ -36,8 +35,6 @@ ls() { } BUFFER='cd;ls' -# Use $unused_highlight to see that function highlighting has precedence over command and builtin - expected_region_highlight=( "1 2 function" # cd "4 5 function" # ls diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index 1cc24b0..83b0ed6 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -28,7 +28,6 @@ # ------------------------------------------------------------------------------------------------- hash zsh_syntax_highlighting_hash=/doesnotexist -ZSH_HIGHLIGHT_STYLES[hashed-command]=$unused_highlight BUFFER='zsh_syntax_highlighting_hash' expected_region_highlight=( diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index be511b0..3e23711 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[default]=$unused_highlight BUFFER='!foo bar !baz ! ; !' expected_region_highlight=( diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 3d45002..8ecce5b 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=$unused_highlight BUFFER=$'echo "foo1\n' expected_region_highlight=( diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index e945fe2..12fb30b 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -30,7 +30,6 @@ # Assumes that '/bin/sh' exists and '/bin/s' does not exist. # Related to path_prefix2.zsh -ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' expected_region_highlight=( diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index 761c004..ffe50cd 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -30,7 +30,6 @@ # Assumes that '/bin/sh' exists and '/bin/s' does not exist. # Related to path_prefix.zsh -ZSH_HIGHLIGHT_STYLES[path_prefix]=$unused_highlight BUFFER='ls /bin/s' WIDGET=accept-line diff --git a/highlighters/main/test-data/precommand.zsh b/highlighters/main/test-data/precommand.zsh index 04697cf..a03b331 100644 --- a/highlighters/main/test-data/precommand.zsh +++ b/highlighters/main/test-data/precommand.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[assign]=$unused_highlight BUFFER=': command zzzzzz' expected_region_highlight=( diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh index e26fb7d..5086082 100644 --- a/highlighters/main/test-data/redirection.zsh +++ b/highlighters/main/test-data/redirection.zsh @@ -28,7 +28,6 @@ # ------------------------------------------------------------------------------------------------- # Redirection before and after the command word are implemented differently; test both. -ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='<<>&!bar' expected_region_highlight=( diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index 8442a4c..e71fe0a 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[reserved-word]=$unused_highlight BUFFER='repeat "1" do done' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 49fc6a6..4f8909e 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight # Tests three codepaths: # * -i (no argument) # * -C3 (pasted argument) diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh index e66f13d..856567b 100644 --- a/highlighters/main/test-data/sudo-comment.zsh +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=$unused_highlight setopt interactive_comments BUFFER='sudo -u # comment' diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index 5581c1b..f507899 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index 4a2d9d0..30f6ff8 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo >/tmp -u otheruser ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index 91d456d..fdd426d 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[redirection]=$unused_highlight BUFFER='sudo 2>./. -u otheruser ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/unbackslash.zsh b/highlighters/main/test-data/unbackslash.zsh index 9731df5..c8dfbd4 100644 --- a/highlighters/main/test-data/unbackslash.zsh +++ b/highlighters/main/test-data/unbackslash.zsh @@ -27,7 +27,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ZSH_HIGHLIGHT_STYLES[command]=$unused_highlight BUFFER='\sh' expected_region_highlight=( diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 83b4b3c..d08237f 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -63,7 +63,6 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # $1: data file run_test_internal() { local -a highlight_zone - local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use local tests_tempdir="$1"; shift local srcdir="$PWD" diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 5d94b37..3411754 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -57,7 +57,6 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # $1: data file run_test_internal() { local -a highlight_zone - local unused_highlight='bg=red,underline' # a style unused by anything else, for tests to use local tests_tempdir="$1"; shift local srcdir="$PWD" From eaa4335c34416ebec1cdca525101c8b0edb5aba4 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 24 Apr 2016 23:22:14 -0500 Subject: [PATCH 0330/1080] tests: Set ZSH_HIGHLIGHT_STYLES=() during tests Since the _zsh_highlight_add_highlight that the tests use ignores ZSH_HIGHLIGHT_STYLES, we can test both an injective mapping and an empty mapping at once. --- HACKING.md | 21 ++++++++++++++++++- .../test-data/mismatch-patentheses.zsh | 3 +++ .../brackets/test-data/nested-parentheses.zsh | 4 ++++ .../brackets/test-data/simple-parentheses.zsh | 3 +++ .../test-data/unclosed-patentheses.zsh | 3 +++ .../test-data/unclosed-patentheses2.zsh | 2 ++ tests/test-highlighting.zsh | 1 + 7 files changed, 36 insertions(+), 1 deletion(-) diff --git a/HACKING.md b/HACKING.md index 5ce72d8..8626305 100644 --- a/HACKING.md +++ b/HACKING.md @@ -6,7 +6,7 @@ core driver (`zsh-syntax-highlighting.zsh`), on the highlighters in the distribution, and on the test suite. It does not target third-party highlighter authors (although they may find it an interesting read). -The 'main' highlighter +The `main` highlighter ---------------------- The following function `pz` is useful when working on the `main` highlighting: @@ -25,6 +25,25 @@ The following function `pz` is useful when working on the `main` highlighting: It prints, for each argument, its token breakdown, similar to how the main loop of the `main` highlighter sees it. +Testing the `brackets` highlighter +---------------------------------- + +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]= + + 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" # ) + ) + IRC channel ----------- diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index f0991b0..f40226f 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -27,6 +27,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= + BUFFER='echo ({x}]' expected_region_highlight=( diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index b3f531b..413394f 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -27,6 +27,10 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= +ZSH_HIGHLIGHT_STYLES[bracket-level-3]= + BUFFER='echo $(echo ${(z)array})' expected_region_highlight=( diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index 3fc66df..186d0b9 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -27,6 +27,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= + BUFFER='echo ({x})' expected_region_highlight=( diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index e1a634a..941d092 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -27,6 +27,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= + BUFFER='echo ({x}' expected_region_highlight=( diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 1a1937f..41b6836 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= + BUFFER='echo {x})' expected_region_highlight=( diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index d08237f..08912c1 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -153,6 +153,7 @@ fi # Process each test data file in test data directory. integer something_failed=0 +ZSH_HIGHLIGHT_STYLES=() 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 From f73f3d53d3a6cc27e63e7008f7437d0f41f5b484 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 20 Jan 2016 00:38:44 -0600 Subject: [PATCH 0331/1080] 'brackets': Allow unset ZSH_HIGHLIGHT_STYLES Without this when bracket_color_size is 0, $(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) errors with division by zero. --- highlighters/brackets/brackets-highlighter.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index f8db178..cd5e7cc 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -76,7 +76,9 @@ _zsh_highlight_brackets_highlighter() # Now highlight all found brackets for pos in ${(k)levelpos}; do if (( $+matching[$pos] )); then - style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) + if (( bracket_color_size )); then + style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) + fi else style=bracket-error fi From 56a867076c60a1d998c492b2c078525552db45ac Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 19:10:06 +0000 Subject: [PATCH 0332/1080] tests: Followup to fd061b5730bf: quote both expected and actual 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 08912c1..e232b3f 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -110,7 +110,7 @@ run_test_internal() { [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected $highlight_zone[3], observed ${(qqq)observed_result[$j]}.$todo" + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done From 21207c336a538658e13f2a14f297ff2393adc906 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 18:40:13 +0000 Subject: [PATCH 0333/1080] tests: TAP compliance: Do not emit literal '#' in the 'description' part --- 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 e232b3f..9c771ad 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -110,7 +110,8 @@ run_test_internal() { [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + # Escape # as ♯ since the former is illegal in the 'description' part of TAP output + echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]//'#'/♯} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done From 70b5687d66944e473103d16d9683b2bd935f92c2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 18:44:54 +0000 Subject: [PATCH 0334/1080] minor: tests: Tighten up local variable scope. --- tests/test-highlighting.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 9c771ad..a2f1520 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -62,7 +62,6 @@ ZSH_HIGHLIGHT_HIGHLIGHTERS=($1) # Runs a highlighting test # $1: data file run_test_internal() { - local -a highlight_zone local tests_tempdir="$1"; shift local srcdir="$PWD" @@ -87,7 +86,7 @@ run_test_internal() { # observed highlighting. local -A observed_result for ((i=1; i<=${#region_highlight}; i++)); do - highlight_zone=${(z)region_highlight[$i]} + local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) integer start=$highlight_zone[1] end=$highlight_zone[2] if (( start < end )) # region_highlight ranges are half-open then @@ -99,13 +98,15 @@ run_test_internal() { else # noop range; ignore. fi + unset start end + unset highlight_zone done # Then we compare the observed result with the expected one. echo "1..${#expected_region_highlight}" for ((i=1; i<=${#expected_region_highlight}; i++)); do + local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} ) local todo= - highlight_zone=${(z)expected_region_highlight[$i]} [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$highlight_zone[1]..$highlight_zone[2]}; do @@ -116,6 +117,8 @@ run_test_internal() { fi done echo "ok $i$todo" + unset todo + unset highlight_zone done } From f83bca0847a66a1a8ca308fab10cd0f1090ff32e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 18:48:59 +0000 Subject: [PATCH 0335/1080] minor: tests: Introduce a local variable. No functional change. --- tests/test-highlighting.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a2f1520..3286b6f 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -107,16 +107,18 @@ run_test_internal() { for ((i=1; i<=${#expected_region_highlight}; i++)); do local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} ) local todo= + integer start=$highlight_zone[1] end=$highlight_zone[2] [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" - for j in {$highlight_zone[1]..$highlight_zone[2]}; do + for j in {$start..$end}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then # Escape # as ♯ since the former is illegal in the 'description' part of TAP output - echo "not ok $i ${(qqq)BUFFER[$highlight_zone[1],$highlight_zone[2]]//'#'/♯} [$highlight_zone[1],$highlight_zone[2]]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + echo "not ok $i ${(qqq)BUFFER[$start,$end]//'#'/♯} [$start,$end]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done echo "ok $i$todo" + unset start end unset todo unset highlight_zone done From 6aa57d60aa6479f39f86e2cf4c4fdd45a594ab43 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 18:40:13 +0000 Subject: [PATCH 0336/1080] tests: TAP support: Emit a 'description' for all test points --- tests/test-highlighting.zsh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 3286b6f..4594202 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -108,16 +108,18 @@ run_test_internal() { local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} ) local todo= integer start=$highlight_zone[1] end=$highlight_zone[2] + # Escape # as ♯ since the former is illegal in the 'description' part of TAP output + local desc="[$start,$end] ${(qqq)BUFFER[$start,$end]//'#'/♯}" [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$start..$end}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - # Escape # as ♯ since the former is illegal in the 'description' part of TAP output - echo "not ok $i ${(qqq)BUFFER[$start,$end]//'#'/♯} [$start,$end]: expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + echo "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done - echo "ok $i$todo" + echo "ok $i - $desc${todo:+' - '}$todo" + unset desc unset start end unset todo unset highlight_zone From 3176b9567c4b5779a399df7fb65778c677763f6b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 19:17:43 +0000 Subject: [PATCH 0337/1080] minor: tests: Quote $BUFFER differently on output. The new output improves readability of the 'main' highlighter's test 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 4594202..4b41d54 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -109,7 +109,7 @@ run_test_internal() { local todo= integer start=$highlight_zone[1] end=$highlight_zone[2] # Escape # as ♯ since the former is illegal in the 'description' part of TAP output - local desc="[$start,$end] ${(qqq)BUFFER[$start,$end]//'#'/♯}" + local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$start..$end}; do From f0bae44b76dd60fa14f76e3a27e3a9a6490b63c3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 5 May 2016 20:34:27 +0000 Subject: [PATCH 0338/1080] tests: Followup to last: echo(1) is evil. Use 'print -r --' instead, so literal backslashes in $BUFFER aren't expanded. Found-by: Matthew Martin --- 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 4b41d54..7b547bd 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -114,11 +114,11 @@ run_test_internal() { [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$start..$end}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - echo "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" continue 2 fi done - echo "ok $i - $desc${todo:+' - '}$todo" + print -r -- "ok $i - $desc${todo:+' - '}$todo" unset desc unset start end unset todo From b5955213b9bd830b1dd237c14f4aff883eab7da5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 5 May 2016 00:19:19 -0500 Subject: [PATCH 0339/1080] tests: Add tests for 'brackets' and 'pattern' --- .../brackets/test-data/empty-styles.zsh | 34 +++++++++++++ .../brackets/test-data/loop-styles.zsh | 51 +++++++++++++++++++ .../brackets/test-data/near-quotes.zsh | 38 ++++++++++++++ .../brackets/test-data/nested-quote.zsh | 36 +++++++++++++ highlighters/pattern/test-data/rm-rf.zsh | 36 +++++++++++++ 5 files changed, 195 insertions(+) create mode 100644 highlighters/brackets/test-data/empty-styles.zsh create mode 100644 highlighters/brackets/test-data/loop-styles.zsh create mode 100644 highlighters/brackets/test-data/near-quotes.zsh create mode 100644 highlighters/brackets/test-data/nested-quote.zsh create mode 100644 highlighters/pattern/test-data/rm-rf.zsh diff --git a/highlighters/brackets/test-data/empty-styles.zsh b/highlighters/brackets/test-data/empty-styles.zsh new file mode 100644 index 0000000..2de1b20 --- /dev/null +++ b/highlighters/brackets/test-data/empty-styles.zsh @@ -0,0 +1,34 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=': (x)' + +expected_region_highlight=( + "1 5 NONE" +) diff --git a/highlighters/brackets/test-data/loop-styles.zsh b/highlighters/brackets/test-data/loop-styles.zsh new file mode 100644 index 0000000..a5be21d --- /dev/null +++ b/highlighters/brackets/test-data/loop-styles.zsh @@ -0,0 +1,51 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= +ZSH_HIGHLIGHT_STYLES[bracket-level-3]= + +BUFFER=': ({[({[(x)]})]})' + +expected_region_highlight=( + "3 3 bracket-level-1" + "4 4 bracket-level-2" + "5 5 bracket-level-3" + "6 6 bracket-level-1" + "7 7 bracket-level-2" + "8 8 bracket-level-3" + "9 9 bracket-level-1" + "11 11 bracket-level-1" + "12 12 bracket-level-3" + "13 13 bracket-level-2" + "14 14 bracket-level-1" + "15 15 bracket-level-3" + "16 16 bracket-level-2" + "17 17 bracket-level-1" +) diff --git a/highlighters/brackets/test-data/near-quotes.zsh b/highlighters/brackets/test-data/near-quotes.zsh new file mode 100644 index 0000000..b7cc2cb --- /dev/null +++ b/highlighters/brackets/test-data/near-quotes.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= + +BUFFER=': {"{x}"}' + +expected_region_highlight=( + "3 3 bracket-level-1" + "4 8 NONE" + "9 9 bracket-level-1" +) diff --git a/highlighters/brackets/test-data/nested-quote.zsh b/highlighters/brackets/test-data/nested-quote.zsh new file mode 100644 index 0000000..8febae8 --- /dev/null +++ b/highlighters/brackets/test-data/nested-quote.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= + +BUFFER=': "\"{x"' + +expected_region_highlight=( + "3 9 NONE 'issue #303'" +) diff --git a/highlighters/pattern/test-data/rm-rf.zsh b/highlighters/pattern/test-data/rm-rf.zsh new file mode 100644 index 0000000..2f76929 --- /dev/null +++ b/highlighters/pattern/test-data/rm-rf.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red') + +BUFFER='rm -rf /' + +expected_region_highlight=( + "1 8 fg=white,bold,bg=red" # rm -rf / +) From bb341f186c8b6089e678cb71dc340dfd4a9b46be Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 5 May 2016 00:12:18 -0500 Subject: [PATCH 0340/1080] dev docs: Document testing quirks --- HACKING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/HACKING.md b/HACKING.md index 8626305..633cea0 100644 --- a/HACKING.md +++ b/HACKING.md @@ -44,6 +44,23 @@ tests must set the `bracket-level-#` keys themselves. For example: "10 10 bracket-level-1" # ) ) +Testing the `pattern` highlighter +--------------------------------- + +Because the `pattern` highlighter modifies `region_highlight` directly instead +of using `_zsh_highlight_add_highlight`, the test harness 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') + + BUFFER='rm -rf /' + + expected_region_highlight=( + "1 8 fg=white,bold,bg=red" # rm -rf / + ) + IRC channel ----------- From 9cab566f539b65a22e5bf7e486122fef53e19ea4 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 5 May 2016 18:02:51 -0500 Subject: [PATCH 0341/1080] docs: Document installation with other plugin managers Closes #297. --- INSTALL.md | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index f021c49..0cf3b5b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -13,8 +13,8 @@ How to install [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git [debian-package]: https://packages.debian.org/zsh-syntax-highlighting [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting -[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb +[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting ### In your ~/.zshrc @@ -33,12 +33,23 @@ Simply clone this repository and source the script: Note the `source` command must be **at the end** of `~/.zshrc`. -### With oh-my-zsh +### With a plugin manager -Oh-my-zsh is a zsh configuration framework. It lives at -. +Note that `zsh-syntax-highlighting` must be the last plugin sourced. -To install zsh-syntax-highlighting under oh-my-zsh: +The zsh-syntax-highlighting authors recommend manual installation over the use +of a framework or plugin manager. + +This list is incomplete as there are too many [frameworks / plugin managers] +(https://github.com/unixorn/awesome-zsh-plugins#frameworks) to list them all +here. + +#### [Antigen](https://github.com/zsh-users/antigen) + +Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in +your `.zshrc`. + +#### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) 1. Clone this repository in oh-my-zsh's plugins directory: @@ -52,13 +63,29 @@ To install zsh-syntax-highlighting under oh-my-zsh: source ~/.zshrc -Note that `zsh-syntax-highlighting` must be the last plugin sourced, -so make it the last element of the `$plugins` array. +#### [Prezto](https://github.com/sorin-ionescu/prezto) + +Zsh-syntax-highlighting is included with Prezto. See the [Prezto documentation] +(https://github.com/sorin-ionescu/prezto/tree/master/modules/syntax-highlighting) +to enable and configure highlighters. + +#### [zgen](https://github.com/tarjoilija/zgen) + +Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`. + +#### [zplug](https://github.com/zplug/zplug) + +Add `zplug "zsh-users/zsh-syntax-highlighting", nice:10` to your `.zshrc`. + +#### [zplugin](https://github.com/psprint/zplugin) + +Add `zplugin load zsh-users/zsh-syntax-highlighting` to the end of your +`.zshrc`. ### System-wide installation -Either of the above methods is suitable for a single-user installation, +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 @@ -69,6 +96,3 @@ and directing your users to add source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh to their `.zshrc`s. - - - From 6889ff6bd2ad9fa8ec48e89ccabaf097d47ea5b0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 03:26:06 +0000 Subject: [PATCH 0342/1080] 'main': Add a regression test for issue #302, "Process substitution misparsed as redirection". --- highlighters/main/test-data/redirection2.zsh | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/redirection2.zsh diff --git a/highlighters/main/test-data/redirection2.zsh b/highlighters/main/test-data/redirection2.zsh new file mode 100644 index 0000000..bf5cb5a --- /dev/null +++ b/highlighters/main/test-data/redirection2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='ls >(wc) | nl' + +expected_region_highlight=( + "1 2 command" # ls + "10 10 commandseparator" # | + "12 13 command 'issue #302'" # nl +) From bfabffbf975cd846a6e3098cac2a70b3ac3f8d33 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 03:26:29 +0000 Subject: [PATCH 0343/1080] 'main': Factor out common code. No functional change. --- 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 a0f8dba..bfcd882 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -93,6 +93,12 @@ _zsh_highlight_main__type() { LC_ALL=C builtin type -w -- $1 2>/dev/null } +# Check whether the first argument is a redirection operator token. +# Report result via the exit code. +_zsh_highlight_main__is_redirection() { + [[ $1 == (<0-9>|)(\<|\>)* ]] +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -351,7 +357,7 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then + elif _zsh_highlight_main__is_redirection $arg; then # A '<' or '>', possibly followed by a digit style=redirection (( in_redirection=2 )) @@ -421,7 +427,7 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif [[ $arg == (<0-9>|)(\<|\>)* ]]; then + elif _zsh_highlight_main__is_redirection $arg; then style=redirection (( in_redirection=2 )) else From fc9c892a3f1548c7c49c73e4a7d110dbb13fdfd4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 03:26:06 +0000 Subject: [PATCH 0344/1080] 'main': Fix issue #302, "Process substitution misparsed as redirection". --- highlighters/main/main-highlighter.zsh | 6 +++++- highlighters/main/test-data/redirection2.zsh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index bfcd882..e0de002 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -96,7 +96,11 @@ _zsh_highlight_main__type() { # Check whether the first argument is a redirection operator token. # Report result via the exit code. _zsh_highlight_main__is_redirection() { - [[ $1 == (<0-9>|)(\<|\>)* ]] + # A redirection operator token: + # - starts with an optional single-digit number; + # - then, has a '<' or '>' character; + # - is not a process substitution [<(...) or >(...)]. + [[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] } # Main syntax highlighting function. diff --git a/highlighters/main/test-data/redirection2.zsh b/highlighters/main/test-data/redirection2.zsh index bf5cb5a..83f7c08 100644 --- a/highlighters/main/test-data/redirection2.zsh +++ b/highlighters/main/test-data/redirection2.zsh @@ -32,5 +32,5 @@ BUFFER='ls >(wc) | nl' expected_region_highlight=( "1 2 command" # ls "10 10 commandseparator" # | - "12 13 command 'issue #302'" # nl + "12 13 command" # nl ) From 15db71abd0cced43513d61b9d9a6b5ca21fee14b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 03:38:27 +0000 Subject: [PATCH 0345/1080] driver: Track rename of an unreleased upstream API. ISEARCH_ACTIVE was renamed ISEARCHMATCH_ACTIVE in workers/38921 (commit f06be0ffcf2c to zsh itself). Fixes #299. --- 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 ca06fb0..f07851d 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -121,7 +121,7 @@ _zsh_highlight() (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" # isearch - (( $+ISEARCH_ACTIVE )) && (( ISEARCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCH_START" "$ISEARCH_END" + (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END" # suffix (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END" From a7a7f8b42280ccc93df07127d6ae379a0b755cbc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 9 May 2016 04:06:44 +0000 Subject: [PATCH 0346/1080] Support linewise region. Fixes #267. --- zsh-syntax-highlighting.zsh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f07851d..b806fae 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -115,7 +115,22 @@ _zsh_highlight() # Re-apply zle_highlight settings # region - (( REGION_ACTIVE )) && _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" + if (( REGION_ACTIVE == 1 )); then + _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR" + 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 + (( min = ${${BUFFER[1,$min]}[(I)$needle]} )) + (( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 )) + _zsh_highlight_apply_zle_highlight region standout "$min" "$max" + } + fi # yank / paste (zsh-5.1.1 and newer) (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END" From 217669270418fbc6ae98836b09357b5ba8f85b7d Mon Sep 17 00:00:00 2001 From: Nils Luxton Date: Mon, 9 May 2016 17:35:21 +0100 Subject: [PATCH 0347/1080] docs: Added style key prefix convention Part of #306 --- docs/highlighters.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 9b43430..24fc6da 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -68,13 +68,14 @@ To create your own `myhighlighter` highlighter: `_zsh_highlight_add_highlight` with the start and end of the region to be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default style for that key in the highlighter script outside of any function with - `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`. For example: + `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix + the key with your highlighter name. For example: - : ${ZSH_HIGHLIGHT_STYLES[aurora]:=fg=green} + : ${ZSH_HIGHLIGHT_STYLES[myhighlighter-aurora]:=fg=green} _zsh_highlight_myhighlighter_highlighter() { # Colorize the whole buffer with the 'aurora' style - _zsh_highlight_add_highlight 0 $#BUFFER aurora + _zsh_highlight_add_highlight 0 $#BUFFER myhighlighter-aurora } * Activate your highlighter in `~/.zshrc`: From 5fe8fd8bdcffd6db88f0a80619625d7baaf3e1c9 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Wed, 11 May 2016 00:31:39 +0200 Subject: [PATCH 0348/1080] 'brackets': Fix for one-based indexing Use correct indexing also for cursor-matchingbracket. Fixup for 95d82568d8f9d4ba34eb293b6ce792854a14f110 --- .../brackets/brackets-highlighter.zsh | 4 +- .../test-data/cursor-matchingbracket.zsh | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 highlighters/brackets/test-data/cursor-matchingbracket.zsh diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index cd5e7cc..d882afa 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -86,10 +86,10 @@ _zsh_highlight_brackets_highlighter() done # If cursor is on a bracket, then highlight corresponding bracket, if any - pos=$CURSOR + pos=$((CURSOR + 1)) if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then local -i otherpos=$matching[$pos] - _zsh_highlight_add_highlight $otherpos $((otherpos + 1)) cursor-matchingbracket + _zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket fi } diff --git a/highlighters/brackets/test-data/cursor-matchingbracket.zsh b/highlighters/brackets/test-data/cursor-matchingbracket.zsh new file mode 100644 index 0000000..5e9cf62 --- /dev/null +++ b/highlighters/brackets/test-data/cursor-matchingbracket.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= +ZSH_HIGHLIGHT_STYLES[bracket-level-3]= + +BUFFER=': ((( )))' +CURSOR=2 # cursor is zero-based + +expected_region_highlight=( + "9 9 cursor-matchingbracket" +) From 62f1c108f313f68029c4a860b6326d55cebe0b1b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 11 May 2016 20:36:18 +0000 Subject: [PATCH 0349/1080] tests: New test to capture off-by-ones. Inspired by #312. --- highlighters/main/test-data/off-by-one.zsh | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/off-by-one.zsh diff --git a/highlighters/main/test-data/off-by-one.zsh b/highlighters/main/test-data/off-by-one.zsh new file mode 100644 index 0000000..550c09f --- /dev/null +++ b/highlighters/main/test-data/off-by-one.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=A +f() {} + +BUFFER='a;f;' + +expected_region_highlight=( + "1 1 alias" # f + "2 2 commandseparator" # ; + "3 3 function" # g + "4 4 commandseparator" # ; +) From a00ed24ba34c9d9c1e06f16517411e22532b57d2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 May 2016 13:25:59 +0000 Subject: [PATCH 0350/1080] docs: Simplify/clarify installation instructions. This also removes an implicit assumption that ~/.zshrc is idempotent. --- INSTALL.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 0cf3b5b..94d4fca 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -23,7 +23,10 @@ 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" >> ~/.zshrc - source ~/.zshrc + + Then, enable syntax highlighting in the current interactive shell: + + source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh If `git` is not installed, download and extract a snapshot of the latest development tree from: From 162c8264525f7479b58f3ada7d4ac2b26e0bbcd0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 May 2016 13:29:10 +0000 Subject: [PATCH 0351/1080] docs: Honour $ZDOTDIR in code examples. Keep references in prose as '~/.zshrc': using $ZDOTDIR in that context would be confusing, and people who set $ZDOTDIR understand these references. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 94d4fca..8f322e1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -22,7 +22,7 @@ How to install 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" >> ~/.zshrc + echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc Then, enable syntax highlighting in the current interactive shell: From 02229ebd63284d420d9b214bfab9197ed940723f Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 12 May 2016 17:22:57 +0200 Subject: [PATCH 0352/1080] 'main': optimization that in my tests shows 2.7s -> 2.2s Consider indexing long buffers (say 300 chars). E.g. following line: integer offset=${${buf[start_pos+1,len]}[(i)$needle]} will gradually go into large indices for first index [a,] and be kept at large index for second index [,b]. Instead, we can remove already processed characters from buf: proc_buf="${proc_buf[offset + $#arg + 1,-1]}" $offset and $#arg are small, first index will not be large. $proc_buf will be smaller and smaller and the second index [,-1] will run shorter and shorter. --- highlighters/main/main-highlighter.zsh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a0f8dba..983ab35 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -199,6 +199,8 @@ _zsh_highlight_main_highlighter() # local this_word=':start:' next_word integer in_redirection + # Processing buffer + local proc_buf="$buf" for arg in ${interactive_comments-${(z)buf}} \ ${interactive_comments+${(zZ+c+)buf}}; do if (( in_redirection )); then @@ -234,14 +236,26 @@ _zsh_highlight_main_highlighter() # indistinguishable from 'echo foo echo bar' (one command with three # words for arguments). local needle=$'[;\n]' - integer offset=${${buf[start_pos+1,len]}[(i)$needle]} - (( start_pos += offset - 1 )) + integer offset=$(( ${proc_buf[(i)$needle]} - 1 )) + (( start_pos += offset )) (( end_pos = start_pos + $#arg )) else - ((start_pos+=(len-start_pos)-${#${${buf[start_pos+1,len]}##([[:space:]]|\\[[:space:]])#}})) + integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}})) + ((start_pos+=offset)) ((end_pos=$start_pos+${#arg})) fi + # Above `if` computes new start_pos and end_pos. + # Here we compute 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. + proc_buf="${proc_buf[offset + $#arg + 1,-1]}" + if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then style=comment From ef4bfe5bcc141b711ba1ac048ef975b69b16d727 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 12 May 2016 20:43:45 +0200 Subject: [PATCH 0353/1080] 'main': 2nd optimization that in my tests shows 2.2s -> 2.0s --- highlighters/main/main-highlighter.zsh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 983ab35..0456739 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -254,7 +254,16 @@ _zsh_highlight_main_highlighter() # end_pos was advanced by $offset (via start_pos) # and by $#arg. Note the `start_pos=$end_pos` # below. - proc_buf="${proc_buf[offset + $#arg + 1,-1]}" + # + # 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]}" if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then From 7b82b88a7166cf3b04e452dfb4bda8706631aa46 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 May 2016 19:24:00 +0000 Subject: [PATCH 0354/1080] 'main': Don't leak the PATH_DIRS options. Found-by: m0viefreak (in #298) --- 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 0456739..eaba198 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -88,7 +88,7 @@ _zsh_highlight_main_add_region_highlight() { # called inside a $(...) subshell, so the effects will be local. _zsh_highlight_main__type() { if (( $#options_to_set )); then - setopt $options_to_set; + setopt localoptions $options_to_set; fi LC_ALL=C builtin type -w -- $1 2>/dev/null } From 0ff354b44b6e6e47c8d64086ec926317edbf6e23 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 12 May 2016 19:28:17 +0000 Subject: [PATCH 0355/1080] docs: Namespace highlighters' styles. Follow-up to 217669270418fbc6ae98836b09357b5ba8f85b7d. Part of #306. --- docs/highlighters.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 24fc6da..fa8e8e5 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -69,13 +69,13 @@ To create your own `myhighlighter` highlighter: be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default style for that key in the highlighter script outside of any function with `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix - the key with your highlighter name. For example: + the key with your highlighter name and a colon. For example: - : ${ZSH_HIGHLIGHT_STYLES[myhighlighter-aurora]:=fg=green} + : ${ZSH_HIGHLIGHT_STYLES[myhighlighter:aurora]:=fg=green} _zsh_highlight_myhighlighter_highlighter() { # Colorize the whole buffer with the 'aurora' style - _zsh_highlight_add_highlight 0 $#BUFFER myhighlighter-aurora + _zsh_highlight_add_highlight 0 $#BUFFER myhighlighter:aurora } * Activate your highlighter in `~/.zshrc`: From def8c0da83afcb69b13ce129aa3d9ed8a24d2479 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 30 Apr 2016 02:11:17 +0000 Subject: [PATCH 0356/1080] Bump copyright years. --- highlighters/brackets/brackets-highlighter.zsh | 2 +- highlighters/main/main-highlighter.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index d882afa..ce52309 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2011 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2016 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 fb03b6e..78539c7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2015 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From 3ce01076b521d9ab37dce90f2e73bdf1d44ec3d7 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Mon, 28 Mar 2016 23:45:02 +0200 Subject: [PATCH 0357/1080] driver: load zsh/parameter if available --- zsh-syntax-highlighting.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f07851d..676b278 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -328,5 +328,8 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { echo 'zsh-syntax-highlighting: failed loading add-zsh-hook.' >&2 } +# Load zsh/parameter module if available +zmodload zsh/parameter 2>/dev/null || true + # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true From 2f18ba64e397f11b04e685eeaee802b7285510cc Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Mon, 28 Mar 2016 23:38:51 +0200 Subject: [PATCH 0358/1080] 'main': use zsh/parameter to resolve alias If possible, use zsh/parameter to avoid forks. Fixes #263. --- highlighters/main/main-highlighter.zsh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index eaba198..6cd0cdb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -93,6 +93,19 @@ _zsh_highlight_main__type() { LC_ALL=C builtin type -w -- $1 2>/dev/null } +# Resolve alias. +# +# Takes a single argument. +# +# The result will be stored in REPLY. +_zsh_highlight_main__resolve_alias() { + if zmodload -e zsh/parameter; then + REPLY=${aliases[$arg]} + else + REPLY="${"$(alias -- $arg)"#*=}" + fi +} + # Main syntax highlighting function. _zsh_highlight_main_highlighter() { @@ -344,8 +357,9 @@ _zsh_highlight_main_highlighter() style=unknown-token else style=alias - local aliased_command="${"$(alias -- $arg)"#*=}" - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$aliased_command"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) + _zsh_highlight_main__resolve_alias $arg + local alias_target="$REPLY" + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$alias_target"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) fi } ;; From 4832f18c50a53b6e008253847a5e70c42e51afb9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 13 May 2016 02:50:17 +0000 Subject: [PATCH 0359/1080] =?UTF-8?q?tests:=20New=20test=20for=20issue=20#?= =?UTF-8?q?290,=20=C2=ABMishighlights=20"longloops"=20'repeat'=C2=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/test-data/control-flow2.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/control-flow2.zsh diff --git a/highlighters/main/test-data/control-flow2.zsh b/highlighters/main/test-data/control-flow2.zsh new file mode 100644 index 0000000..3871adb --- /dev/null +++ b/highlighters/main/test-data/control-flow2.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='repeat 42; do ls; done' + +expected_region_highlight+=( + "1 6 reserved-word" # repeat + "8 9 default" # 42 + "10 10 commandseparator 'issue #290'" # ; + "12 13 reserved-word" # do + "15 16 command" # ls + "17 17 commandseparator" # ; + "19 22 reserved-word" # done +) From ef68f50c048fd7d7ce54b76774a86f6719f4ed21 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 13 May 2016 02:50:17 +0000 Subject: [PATCH 0360/1080] =?UTF-8?q?'main':=20Fix=20issue=20#290,=20?= =?UTF-8?q?=C2=ABMishighlights=20"longloops"=20'repeat'=C2=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/main-highlighter.zsh | 5 ++++- highlighters/main/test-data/control-flow2.zsh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index cb7e55c..92ddda1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -497,8 +497,11 @@ _zsh_highlight_main_highlighter() # 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:' + this_word=':start::regular:' fi start_pos=$end_pos (( in_redirection == 0 )) && this_word=$next_word diff --git a/highlighters/main/test-data/control-flow2.zsh b/highlighters/main/test-data/control-flow2.zsh index 3871adb..acf99e1 100644 --- a/highlighters/main/test-data/control-flow2.zsh +++ b/highlighters/main/test-data/control-flow2.zsh @@ -32,7 +32,7 @@ BUFFER='repeat 42; do ls; done' expected_region_highlight+=( "1 6 reserved-word" # repeat "8 9 default" # 42 - "10 10 commandseparator 'issue #290'" # ; + "10 10 commandseparator" # ; "12 13 reserved-word" # do "15 16 command" # ls "17 17 commandseparator" # ; From 1082067f931558d3fc17688df15ab8fd2d3b50f1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 12 May 2016 21:39:11 -0500 Subject: [PATCH 0361/1080] tests: Fail on stderr output Closes #291. --- tests/test-highlighting.zsh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7b547bd..383e92d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -140,7 +140,17 @@ run_test() { { # Use a subshell to isolate tests from each other. # (So tests can alter global shell state using 'cd', 'hash', etc) - (run_test_internal "$__tests_tempdir" "$@") + { + # These braces are so multios don't come into play. + { (run_test_internal "$__tests_tempdir" "$@") 3>&1 >&2 2>&3 } | grep \^ + local ret=$pipestatus[1] stderr=$pipestatus[2] + if (( ! stderr )); then + # stdout will become stderr + echo "Bail out! output on stderr"; return 1 + else + return $ret + fi + } 3>&1 >&2 2>&3 } always { rm -rf -- "$__tests_tempdir" } From 0f43026bf0e7cc4dd138d4b531993616afd92aad Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 4 May 2016 20:38:16 -0500 Subject: [PATCH 0362/1080] docs: Document writing tests --- docs/highlighters.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/highlighters.md b/docs/highlighters.md index fa8e8e5..00738ba 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -81,3 +81,5 @@ To create your own `myhighlighter` highlighter: * Activate your highlighter in `~/.zshrc`: ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) + +* [Write tests](../tests/README.md). From 13018f3dd735a1651fd10988981db65723560ef4 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 5 May 2016 23:31:31 -0500 Subject: [PATCH 0363/1080] docs: Document use of NONE in expected_region_highlight --- tests/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/README.md b/tests/README.md index 2674aa7..06307c2 100644 --- a/tests/README.md +++ b/tests/README.md @@ -12,6 +12,8 @@ The value of that parameter is a list of strings of the form `"$i $j $style"`. or `"$i $j $style $todo"`. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. +`$style` is either a key of `$ZSH_HIGHLIGHT_STYLES` or `NONE` to specify no +highlighting should be observed. 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. From 19acd8e844e6a8edd4f3dc49a4b71292d3a6c316 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 12 May 2016 22:09:45 -0500 Subject: [PATCH 0364/1080] docs: Mention `$BUFFER` --- tests/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 06307c2..6461708 100644 --- a/tests/README.md +++ b/tests/README.md @@ -7,7 +7,8 @@ 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. -Each test should define the array parameter `$expected_region_highlight`. +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"`. or `"$i $j $style $todo"`. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; From 364f206a547f350ddf2cee2d122859cfb03b4a4d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 5 May 2016 23:31:58 -0500 Subject: [PATCH 0365/1080] docs: Give example of test that modifies its environment --- tests/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 6461708..d55945f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -25,8 +25,19 @@ interprets the indexes differently. aliases, functions, etc., it defines will be visible to the tested code (that 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. +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 ) + + BUFFER='bar/testing-issue-228' + + expected_region_highlight=( + "1 21 command" # bar/testing-issue-228 + ) Highlighting test ----------------- From d37c55c788cd422a38625fda8e7f5a33151945e9 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 12 May 2016 22:59:06 -0500 Subject: [PATCH 0366/1080] minor: tests: Add comment for NONE in expected_region_highlight --- tests/test-highlighting.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 383e92d..7705476 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -110,6 +110,7 @@ run_test_internal() { integer start=$highlight_zone[1] end=$highlight_zone[2] # Escape # as ♯ since the former is illegal in the 'description' part of TAP output local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" + # Match the emptiness of observed_result if no highlighting is expected [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" for j in {$start..$end}; do From 6362c757b6f769215e17f60b83d4894146ae6d0e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 13 May 2016 04:28:30 +0000 Subject: [PATCH 0367/1080] tests: Extend issue #290 test with another variant. The test being extended is highlighters/main/test-data/control-flow2.zsh. --- highlighters/main/test-data/control-flow3.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/control-flow3.zsh diff --git a/highlighters/main/test-data/control-flow3.zsh b/highlighters/main/test-data/control-flow3.zsh new file mode 100644 index 0000000..58f507f --- /dev/null +++ b/highlighters/main/test-data/control-flow3.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='repeat 42; ls; pwd' + +expected_region_highlight+=( + "1 6 reserved-word" # repeat + "8 9 default" # 42 + "10 10 commandseparator" # ; + "12 13 command" # ls + "14 14 commandseparator" # ; + "16 18 builtin" # pwd +) From 61f43255abed0495e5145a3494e7fd7a524cee8c Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Thu, 12 May 2016 21:04:35 +0200 Subject: [PATCH 0368/1080] 'main': Support multiple styles in _zsh_highlight_main_add_region_highlight --- 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 cb7e55c..225866a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -68,7 +68,7 @@ _zsh_highlight_main_highlighter_predicate() # Helper to deal with tokens crossing line boundaries. _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 - local style=$3 + shift 2 # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # relative to $BUFFER. @@ -77,7 +77,7 @@ _zsh_highlight_main_add_region_highlight() { (( end < 0 )) && return # having end<0 would be a bug (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings - _zsh_highlight_add_highlight $start $end $style + _zsh_highlight_add_highlight $start $end "$@" } # Wrapper around 'type -w'. From 12b879caf7a6f96921d1c03ab9b839a7f6c8eb1e Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Mon, 28 Mar 2016 23:42:31 +0200 Subject: [PATCH 0369/1080] 'main': Use zsh/parameter instead of type -w If possible, try to use the zsh/parameter module to get information about a shell words. This avoids subshells and is a huge speed improvement on systems such as cygwin. Note 1: $commands does not know about PATH_DIRS. So in case PATH_DIRS is set, 'type -w' is still used if nothing else matches. Note 2: zsh/parameter can't distinguish between 'command' and 'hashed'. Adjusted the test for that case to XFAIL. The ideal solution would be if whence had an option to put the result in REPLY instead of printing it to stdout. --- highlighters/main/main-highlighter.zsh | 61 +++++++++++++------ .../main/test-data/hashed-command.zsh | 2 +- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 225866a..47d3b6e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -80,17 +80,39 @@ _zsh_highlight_main_add_region_highlight() { _zsh_highlight_add_highlight $start $end "$@" } -# Wrapper around 'type -w'. +# Get the type of a command. # -# Takes a single argument and outputs the output of 'type -w $1'. +# Uses the zsh/parameter module if available to avoid forks, and a +# wrapper around 'type -w' as fallback. # -# NOTE: This runs 'setopt', but that should be safe since it'll only ever be -# called inside a $(...) subshell, so the effects will be local. +# Takes a single argument. +# +# The result will be stored in REPLY. _zsh_highlight_main__type() { if (( $#options_to_set )); then setopt localoptions $options_to_set; fi - LC_ALL=C builtin type -w -- $1 2>/dev/null + unset REPLY + if zmodload -e zsh/parameter; then + if (( $+aliases[(e)$1] )); then + REPLY=alias + elif (( $+saliases[(e)${1##*.}] )); then + REPLY='suffix alias' + elif (( $reswords[(Ie)$1] )); then + REPLY=reserved + elif (( $+functions[(e)$1] )); then + REPLY=function + elif (( $+builtins[(e)$1] )); then + REPLY=builtin + elif (( $+commands[(e)$1] )); then + REPLY=command + elif ! builtin type -w -- $1 >/dev/null 2>&1; then + REPLY=none + fi + fi + if ! (( $+REPLY )); then + REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }" + fi } # Check whether the first argument is a redirection operator token. @@ -329,7 +351,8 @@ _zsh_highlight_main_highlighter() else _zsh_highlight_main_highlighter_expand_path $arg local expanded_arg="$REPLY" - local res="$(_zsh_highlight_main__type ${expanded_arg})" + _zsh_highlight_main__type ${expanded_arg} + local res="$REPLY" () { # Special-case: command word is '$foo', like that, without braces or anything. # @@ -339,17 +362,16 @@ _zsh_highlight_main_highlighter() # parameters that refer to commands, functions, and builtins. local -a match mbegin mend local MATCH; integer MBEGIN MEND - if [[ $res == *': none' ]] && (( ${+parameters} )) && + if [[ $res == none ]] && (( ${+parameters} )) && [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]]; then - res="$(_zsh_highlight_main__type ${(P)MATCH})" + _zsh_highlight_main__type ${(P)MATCH} + res=$REPLY fi } case $res in - *': reserved') style=reserved-word;; - *': suffix alias') - style=suffix-alias - ;; - *': alias') () { + reserved) style=reserved-word;; + 'suffix alias') style=suffix-alias;; + alias) () { integer insane_alias case $arg in # Issue #263: aliases with '=' on their LHS. @@ -373,11 +395,11 @@ _zsh_highlight_main_highlighter() fi } ;; - *': builtin') style=builtin;; - *': function') style=function;; - *': command') style=command;; - *': hashed') style=hashed-command;; - *) if _zsh_highlight_main_highlighter_check_assign; then + builtin) style=builtin;; + function) style=function;; + command) style=command;; + hashed) style=hashed-command;; + none) if _zsh_highlight_main_highlighter_check_assign; then style=assign if [[ $arg[-1] == '(' ]]; then in_array_assignment=true @@ -431,6 +453,9 @@ _zsh_highlight_main_highlighter() fi fi ;; + *) _zsh_highlight_main_add_region_highlight commandtypefromthefuture-$res + already_added=1 + ;; esac fi else # $arg is a non-command word diff --git a/highlighters/main/test-data/hashed-command.zsh b/highlighters/main/test-data/hashed-command.zsh index 83b0ed6..2983ef8 100644 --- a/highlighters/main/test-data/hashed-command.zsh +++ b/highlighters/main/test-data/hashed-command.zsh @@ -31,5 +31,5 @@ hash zsh_syntax_highlighting_hash=/doesnotexist BUFFER='zsh_syntax_highlighting_hash' expected_region_highlight=( - "1 28 hashed-command" + "1 28 hashed-command 'zsh/parameter cannot distinguish between hashed and command'" ) From 3b67e656bff5b8543e16d44fbb56ad9c98afe43f Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 01:33:00 +0200 Subject: [PATCH 0370/1080] 'main': Implement simple command type cache --- highlighters/main/main-highlighter.zsh | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 47d3b6e..742c2b7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -89,6 +89,12 @@ _zsh_highlight_main_add_region_highlight() { # # The result will be stored in REPLY. _zsh_highlight_main__type() { + if (( $+_zsh_highlight_main__command_type_cache )); then + REPLY=$_zsh_highlight_main__command_type_cache[(e)$1] + if [[ -n "$REPLY" ]]; then + return + fi + fi if (( $#options_to_set )); then setopt localoptions $options_to_set; fi @@ -113,6 +119,9 @@ _zsh_highlight_main__type() { if ! (( $+REPLY )); then REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }" fi + if (( $+_zsh_highlight_main__command_type_cache )); then + _zsh_highlight_main__command_type_cache[(e)$1]=$REPLY + fi } # Check whether the first argument is a redirection operator token. @@ -662,3 +671,21 @@ _zsh_highlight_main_highlighter_expand_path() unset REPLY : ${REPLY:=${(Q)~1}} } + +# ------------------------------------------------------------------------------------------------- +# Main highlighter initialization +# ------------------------------------------------------------------------------------------------- + +_zsh_highlight_main__precmd_hook() { + _zsh_highlight_main__command_type_cache=() +} + +autoload -U add-zsh-hook +if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2>/dev/null; then + # Initialize command type cache + typeset -gA _zsh_highlight_main__command_type_cache +else + echo 'zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.' >&2 + # Make sure the cache is unset + unset _zsh_highlight_main__command_type_cache +fi From a5b8bc0ef05988506d9f20026ded7e52519b5dda Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 27 May 2016 10:21:28 +0000 Subject: [PATCH 0371/1080] 'main': Internal cleanup: drop $style_override. Changes the interface of _zsh_highlight_main_highlighter_check_path(). Suggested-by: m0viefreak --- highlighters/main/main-highlighter.zsh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 742c2b7..9cc2b19 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -271,7 +271,6 @@ _zsh_highlight_main_highlighter() # which add the entry early so escape sequences within the string override # the string's color. integer already_added=0 - local style_override="" if [[ $this_word == *':start:'* ]]; then in_array_assignment=false if [[ $arg == 'noglob' ]]; then @@ -456,7 +455,7 @@ _zsh_highlight_main_highlighter() style=reserved-word else if _zsh_highlight_main_highlighter_check_path; then - style=path + style=$REPLY else style=unknown-token fi @@ -507,7 +506,7 @@ _zsh_highlight_main_highlighter() (( in_redirection=2 )) else if _zsh_highlight_main_highlighter_check_path; then - style=path + style=$REPLY else style=default fi @@ -515,8 +514,6 @@ _zsh_highlight_main_highlighter() ;; esac fi - # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it - [[ -n $style_override ]] && style=$style_override (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then next_word=':start:' @@ -547,11 +544,15 @@ _zsh_highlight_main_highlighter_check_assign() } # Check if $arg 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). _zsh_highlight_main_highlighter_check_path() { _zsh_highlight_main_highlighter_expand_path $arg; local expanded_path="$REPLY" + REPLY=path + [[ -z $expanded_path ]] && return 1 [[ -e $expanded_path ]] && return 0 @@ -569,7 +570,7 @@ _zsh_highlight_main_highlighter_check_path() [[ $WIDGET != accept-* ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) - (( $#tmp > 0 )) && style_override=path_prefix && return 0 + (( $#tmp > 0 )) && REPLY=path_prefix && return 0 fi # It's not a path. From 6cd39e7c70d32592070de8c6fd598583052fb32b Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 22 Nov 2015 16:50:26 +0100 Subject: [PATCH 0372/1080] 'main': Highlight path separators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is based on the work done by Jorge Israel Peña (blaenk) in #136. Changes: * Adjusted to changes on the latest master branch. * Use regular path highlighter colors by default. * Break out early if the separator color is the same to improve performance. * Tests. --- highlighters/main/main-highlighter.zsh | 19 ++++++- .../main/test-data/path-separators.zsh | 53 +++++++++++++++++++ .../main/test-data/path-separators2.zsh | 39 ++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/path-separators.zsh create mode 100644 highlighters/main/test-data/path-separators2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 742c2b7..50945ab 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,7 +41,9 @@ : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=${ZSH_HIGHLIGHT_STYLES[path]}} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} +: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=${ZSH_HIGHLIGHT_STYLES[path_prefix]}} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} @@ -517,7 +519,10 @@ _zsh_highlight_main_highlighter() fi # if a style_override was set (eg in _zsh_highlight_main_highlighter_check_path), use it [[ -n $style_override ]] && style=$style_override - (( already_added )) || _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + if ! (( already_added )); then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + [[ $style == path || $style == path_prefix ]] && _zsh_highlight_main_highlighter_highlight_path_separators + fi if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then next_word=':start:' highlight_glob=true @@ -546,6 +551,18 @@ _zsh_highlight_main_highlighter_check_assign() [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] } +_zsh_highlight_main_highlighter_highlight_path_separators() +{ + local pos style_pathsep + style_pathsep=${style}_pathseparator + [[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$style]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0 + for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do + if [[ $BUFFER[pos] == / ]]; then + _zsh_highlight_main_add_region_highlight $((pos - 1)) $pos $style_pathsep + fi + done +} + # Check if $arg is a path. _zsh_highlight_main_highlighter_check_path() { diff --git a/highlighters/main/test-data/path-separators.zsh b/highlighters/main/test-data/path-separators.zsh new file mode 100644 index 0000000..cf13dad --- /dev/null +++ b/highlighters/main/test-data/path-separators.zsh @@ -0,0 +1,53 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# ZSH_HIGHLIGHT_STYLES is empty in tests. The path-separator code however compares its values. +# Make sure the relevant ones are set to something. +ZSH_HIGHLIGHT_STYLES[path_pathseparator]=set +ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]=set + +mkdir A +touch A/mu +BUFFER='ls /bin/ / A/mu A/m' + +expected_region_highlight=( + "4 4 path_pathseparator" # / + "5 7 path" # bin + "8 8 path_pathseparator" # / + + "10 10 path_pathseparator" # / + + "12 12 path" # A + "13 13 path_pathseparator" # / + "14 15 path" # mu + + "17 17 path_prefix" # A + "18 18 path_prefix_pathseparator" # / + "19 19 path_prefix" # m +) diff --git a/highlighters/main/test-data/path-separators2.zsh b/highlighters/main/test-data/path-separators2.zsh new file mode 100644 index 0000000..db4e706 --- /dev/null +++ b/highlighters/main/test-data/path-separators2.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# ZSH_HIGHLIGHT_STYLES is empty in tests. The path-separator code however compares its values. +# For this test, make sure both these styles are set and identical: +ZSH_HIGHLIGHT_STYLES[path]=value +ZSH_HIGHLIGHT_STYLES[path_pathseparator]=value + +BUFFER='ls /bin/' + +expected_region_highlight=( + "4 8 path" # /bin/ +) From 91fa057a39922983a37d729598fca87bf0d3ff3c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 1 Jun 2016 00:54:30 -0500 Subject: [PATCH 0373/1080] minor: 'main': Only search for prefixes if :h is a directory --- 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 7267f7a..8cff27e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -580,7 +580,7 @@ _zsh_highlight_main_highlighter_check_path() done # If dirname($arg) doesn't exist, neither does $arg. - [[ ! -e ${expanded_path:h} ]] && return 1 + [[ ! -d ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && From 14711a51f3356a35ae212bdc00f0616e2eb83db7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 02:41:10 +0000 Subject: [PATCH 0374/1080] tests: Explicitly test 'default' style inside an array assignment. --- highlighters/main/test-data/assign.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 7e18731..713a5f2 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -33,5 +33,6 @@ expected_region_highlight=( "1 3 assign" # A=1 "5 7 assign" # b=( "8 12 double-quoted-argument" # "foo" + "14 16 default" # bar "17 17 assign" # ) ) From f4036a09cee330cae56e33e4fa617d68d0f43e88 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 02:44:38 +0000 Subject: [PATCH 0375/1080] 'main': Highlight scalar assignments to argv Assignments to positional parameters using scalar assignment syntax is a feature: it is covered by upstream's test suite ("append to positional parameter" in Test/A06assign.ztst). --- highlighters/main/main-highlighter.zsh | 3 +- highlighters/main/test-data/assign-argv.zsh | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/assign-argv.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8cff27e..263917b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -545,7 +545,8 @@ _zsh_highlight_main_highlighter() _zsh_highlight_main_highlighter_check_assign() { setopt localoptions extended_glob - [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] + [[ $arg == [[:alpha:]_][[:alnum:]_]#(|\[*\])(|[+])=* ]] || + [[ $arg == [0-9]##(|[+])=* ]] } _zsh_highlight_main_highlighter_highlight_path_separators() diff --git a/highlighters/main/test-data/assign-argv.zsh b/highlighters/main/test-data/assign-argv.zsh new file mode 100644 index 0000000..fdf30aa --- /dev/null +++ b/highlighters/main/test-data/assign-argv.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='42=foo 43+=bar' + +expected_region_highlight=( + "1 6 assign" # 42=foo + "8 14 assign" # 43+=bar +) From 29b30e0ca7a40b4166946e32919e999745b45ddd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 03:42:12 +0000 Subject: [PATCH 0376/1080] 'main': Add XFail test for issue #330, concerning command word after array assignment. --- highlighters/main/test-data/assign-array2.zsh | 36 +++++++++++++++++++ highlighters/main/test-data/assign-array3.zsh | 36 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 highlighters/main/test-data/assign-array2.zsh create mode 100644 highlighters/main/test-data/assign-array3.zsh diff --git a/highlighters/main/test-data/assign-array2.zsh b/highlighters/main/test-data/assign-array2.zsh new file mode 100644 index 0000000..330ae5f --- /dev/null +++ b/highlighters/main/test-data/assign-array2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='A=(hello world) ls' + +expected_region_highlight=( + "1 3 assign" # A=( + "15 15 assign" # ) + "17 18 command 'issue #330'" # ls +) diff --git a/highlighters/main/test-data/assign-array3.zsh b/highlighters/main/test-data/assign-array3.zsh new file mode 100644 index 0000000..2241d55 --- /dev/null +++ b/highlighters/main/test-data/assign-array3.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='A=(hello world) b=42' + +expected_region_highlight=( + "1 3 assign" # A=( + "15 15 assign" # ) + "17 20 assign 'issue #330'" # b=42 +) From fccf92402b0426421ccb9d558003552771831d62 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 03:57:45 +0000 Subject: [PATCH 0377/1080] minor: tests: Formatting tweak to XPASS output. Remove superfluous single quotes around the second hyphen. --- tests/test-highlighting.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 7705476..1d169d6 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -112,14 +112,14 @@ run_test_internal() { local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" # Match the emptiness of observed_result if no highlighting is expected [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= - [[ -n "$highlight_zone[4]" ]] && todo=" # TODO $highlight_zone[4]" + [[ -n "$highlight_zone[4]" ]] && todo="# TODO $highlight_zone[4]" for j in {$start..$end}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}.$todo" + print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}. $todo" continue 2 fi done - print -r -- "ok $i - $desc${todo:+' - '}$todo" + print -r -- "ok $i - $desc${todo:+ - }$todo" unset desc unset start end unset todo From 7fb6f9979121f35436a80ee90185b95984159f93 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 04:16:13 +0000 Subject: [PATCH 0378/1080] 'main': Try the "non-command word" codepath when a word may be either a command word or a non-command word. Fixes #231. Fixes #330. --- highlighters/main/main-highlighter.zsh | 7 ++++++- highlighters/main/test-data/assign-array2.zsh | 2 +- highlighters/main/test-data/assign-array3.zsh | 2 +- highlighters/main/test-data/assign-subshell.zsh | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 263917b..4df9ca1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -273,6 +273,7 @@ _zsh_highlight_main_highlighter() # which add the entry early so escape sequences within the string override # the string's color. integer already_added=0 + style=unknown-token if [[ $this_word == *':start:'* ]]; then in_array_assignment=false if [[ $arg == 'noglob' ]]; then @@ -468,12 +469,16 @@ _zsh_highlight_main_highlighter() ;; esac fi - else # $arg is a non-command word + fi + if (( ! already_added )) && [[ $style == unknown-token ]] && # not handled by the 'command word' codepath + { (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] } + then # $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:' else style=reserved-word fi;; diff --git a/highlighters/main/test-data/assign-array2.zsh b/highlighters/main/test-data/assign-array2.zsh index 330ae5f..37ba372 100644 --- a/highlighters/main/test-data/assign-array2.zsh +++ b/highlighters/main/test-data/assign-array2.zsh @@ -32,5 +32,5 @@ BUFFER='A=(hello world) ls' expected_region_highlight=( "1 3 assign" # A=( "15 15 assign" # ) - "17 18 command 'issue #330'" # ls + "17 18 command" # ls ) diff --git a/highlighters/main/test-data/assign-array3.zsh b/highlighters/main/test-data/assign-array3.zsh index 2241d55..26c42e9 100644 --- a/highlighters/main/test-data/assign-array3.zsh +++ b/highlighters/main/test-data/assign-array3.zsh @@ -32,5 +32,5 @@ BUFFER='A=(hello world) b=42' expected_region_highlight=( "1 3 assign" # A=( "15 15 assign" # ) - "17 20 assign 'issue #330'" # b=42 + "17 20 assign" # b=42 ) diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh index 77cdd65..fc04f6b 100644 --- a/highlighters/main/test-data/assign-subshell.zsh +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -32,5 +32,5 @@ BUFFER='(A=1)' expected_region_highlight=( "1 1 reserved-word" # ( "2 4 assign" # A=1 - "5 5 reserved-word 'issue #231'" # ) + "5 5 reserved-word" # ) ) From 4b77af73fb5e7919ac11dd48505a55f6968ff95b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 08:41:45 +0000 Subject: [PATCH 0379/1080] minor: Fix typo in comment. Two instances. --- 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 676b278..5ba8695 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -41,7 +41,7 @@ if [[ -o function_argzero ]]; then else # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? - # TODO: also check POSIX_ARGZERO, but not it's not available in older zsh + # TODO: also check POSIX_ARGZERO, but note it's not available in older zsh echo "zsh-syntax-highlighting: error: not compatible with NO_FUNCTION_ARGZERO" >&2 return 1 fi @@ -136,7 +136,7 @@ _zsh_highlight() } } -# Apply highlighting based on entries in the zle_highligh array. +# Apply highlighting based on entries in the zle_highlight array. # This function takes four arguments: # 1. The exact entry (no patterns) in the zle_highlight array: # region, paste, isearch, or suffix From 10a596f9fdbca1980903812182cc61da1f16a610 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 08:46:30 +0000 Subject: [PATCH 0380/1080] dev docs: Document a useful tab completion setting. --- HACKING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HACKING.md b/HACKING.md index 633cea0..39d82fa 100644 --- a/HACKING.md +++ b/HACKING.md @@ -61,6 +61,13 @@ itself as third word (cf. the [documentation for `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 + IRC channel ----------- From da91264122cbb54b264e7704efd50c8ce0da1796 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 10 Jun 2016 14:17:47 +0000 Subject: [PATCH 0381/1080] 'main': Add missing arguments. Part of #337. --- 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 fe83535..5fdb63c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -464,7 +464,7 @@ _zsh_highlight_main_highlighter() fi fi ;; - *) _zsh_highlight_main_add_region_highlight commandtypefromthefuture-$res + *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos commandtypefromthefuture-$res already_added=1 ;; esac From d9e07b50827cf4051c6f3ddcd4402f6c429569c2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 10 Jun 2016 14:25:00 +0000 Subject: [PATCH 0382/1080] 'main': simple parameter expansions at command word: Don't use an undefined value. Causes such expansions to be highlighted as [unknown-token] rather than as default (absent from $region_highlight). Fixes #337. --- 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 5fdb63c..f9c4f0b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -374,7 +374,9 @@ _zsh_highlight_main_highlighter() local -a match mbegin mend local MATCH; integer MBEGIN MEND if [[ $res == none ]] && (( ${+parameters} )) && - [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]]; then + [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && + (( ${+parameters[${MATCH}]} )) + then _zsh_highlight_main__type ${(P)MATCH} res=$REPLY fi From 750aebc553f2f4149055ef4cb9d7641f5df6d3ea Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 10 Jun 2016 15:09:45 +0000 Subject: [PATCH 0383/1080] driver: Stop requiring function_argzero. Instead, use the %N prompt expando, as suggested by Bart in users/21637. Avoid the `print -P %N` syntax to save a fork on Cygwin, at the expense of not supporting zsh's from 2001 through c. 2004 vintages. Fixes #338. --- zsh-syntax-highlighting.plugin.zsh | 1 + zsh-syntax-highlighting.zsh | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/zsh-syntax-highlighting.plugin.zsh b/zsh-syntax-highlighting.plugin.zsh index 2fa8b3b..f2456ae 100644 --- a/zsh-syntax-highlighting.plugin.zsh +++ b/zsh-syntax-highlighting.plugin.zsh @@ -1 +1,2 @@ +0=${(%):-%N} source ${0:A:h}/zsh-syntax-highlighting.zsh diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 5ba8695..87967b6 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -28,7 +28,9 @@ # ------------------------------------------------------------------------------------------------- -if [[ -o function_argzero ]]; then +# Set $0 to the expected value, regardless of functionargzero. +0=${(%):-%N} +if true; then # $0 is reliable ZSH_HIGHLIGHT_VERSION=$(<"${0:A:h}"/.version) ZSH_HIGHLIGHT_REVISION=$(<"${0:A:h}"/.revision-hash) @@ -38,12 +40,6 @@ if [[ -o function_argzero ]]; then # the valid value (via `git rev-parse HEAD`, as Makefile does) might be costly, so: ZSH_HIGHLIGHT_REVISION=HEAD fi -else - # $0 is unreliable, so the call to _zsh_highlight_load_highlighters will fail. - # TODO: If 'zmodload zsh/parameter' is available, ${funcsourcetrace[1]%:*} might serve as a substitute? - # TODO: also check POSIX_ARGZERO, but note it's not available in older zsh - echo "zsh-syntax-highlighting: error: not compatible with NO_FUNCTION_ARGZERO" >&2 - return 1 fi # ------------------------------------------------------------------------------------------------- From 9a934d291e7c0f2477d26595d4ac15123c91b4eb Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 11 Jun 2016 14:15:57 +0200 Subject: [PATCH 0384/1080] 'main': Path separators: Leave styles empty by default If the separator feature is disabled, this makes it possible to change the main 'path' styles in a running session without the need to touch the '_pathseparator' styles, too. --- 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 f9c4f0b..540e05b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,9 +41,9 @@ : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} : ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} -: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=${ZSH_HIGHLIGHT_STYLES[path]}} +: ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} -: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=${ZSH_HIGHLIGHT_STYLES[path_prefix]}} +: ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} From f3d3aaa00cc49ccf512164afa2e13290ff934ed7 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 11 Jun 2016 14:14:06 +0200 Subject: [PATCH 0385/1080] 'main': Document _pathseparator styles --- docs/highlighters/main.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index c3228ba..4793fed 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -27,7 +27,9 @@ This highlighter defines the following styles: * `commandseparator` - command separation tokens (`;`, `&&`) * `hashed-command` - hashed commands * `path` - existing filenames +* `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default) * `path_prefix` - prefixes of existing filenames +* `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default) * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `single-hyphen-option` - single hyphen options (`-o`) From b9112aec798a41035d044d4f93d7cfa50c9ca580 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 11 Jun 2016 16:38:03 +0200 Subject: [PATCH 0386/1080] driver: Widget binding: Use ${(k)widgets} instead of $(zle -la) Avoids a fork. --- 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 87967b6..e49e5a8 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -236,7 +236,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local cur_widget - for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do + for cur_widget in ${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do case $widgets[$cur_widget] in # Already rebound event: do nothing. From ee07588cfd9bb07a5176bc6eb74e25da6db39129 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 1 Jul 2016 01:59:37 +0000 Subject: [PATCH 0387/1080] tests: Add a regression test for issue #267, concerning highlighting a vi linewise region. --- .../main/test-data/vi-linewise-mode.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/vi-linewise-mode.zsh diff --git a/highlighters/main/test-data/vi-linewise-mode.zsh b/highlighters/main/test-data/vi-linewise-mode.zsh new file mode 100644 index 0000000..4b77766 --- /dev/null +++ b/highlighters/main/test-data/vi-linewise-mode.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# See issue #267 for the magic numbers +BUFFER=$'foo foo\nbar bar' +REGION_ACTIVE=2 +CURSOR=4 +MARK=12 + +expected_region_highlight=( + "1 3 standout" # foo +) From 3e59ab41b6b85a7b3113f3f3e7a97befd3e16491 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 12 Jul 2016 06:50:49 +0000 Subject: [PATCH 0388/1080] driver: Change a variable name to avoid squatting the highlighters' namespace. Part of issue #329. --- 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 610add0..25b9453 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -81,7 +81,7 @@ _zsh_highlight() local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do # eval cache place for current highlighter and prepare it - cache_place="_zsh_highlight_${highlighter}_highlighter_cache" + cache_place="_zsh_highlight_highlighter_${highlighter}_cache" typeset -ga ${cache_place} # If highlighter needs to be invoked From ba16cf2fb2f2071499a2a19c264be942d2a3a5b6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 12 Jul 2016 07:03:18 +0000 Subject: [PATCH 0389/1080] docs: s/myhighlighter/acme/g Makes the text easier to read ("_zsh_highlight_myhighlighter_highlighter" is a mouthful). --- docs/highlighters.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 00738ba..d09da3e 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -49,21 +49,21 @@ highlighter's documentation for details and examples. How to implement a new highlighter ---------------------------------- -To create your own `myhighlighter` highlighter: +To create your own `acme` highlighter: * Create your script at - `highlighters/${myhighlighter}/${myhighlighter}-highlighter.zsh`. + `highlighters/${acme}/${acme}-highlighter.zsh`. -* Implement the `_zsh_highlight_myhighlighter_highlighter_predicate` function. +* Implement the `_zsh_highlight_acme_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: - _zsh_highlight_myhighlighter_highlighter_predicate() { + _zsh_highlight_acme_highlighter_predicate() { # Call this highlighter in SVN working copies [[ -d .svn ]] } -* Implement the `_zsh_highlight_myhighlighter_highlighter` function. +* Implement the `_zsh_highlight_acme_highlighter` function. This function does the actual syntax highlighting, by calling `_zsh_highlight_add_highlight` with the start and end of the region to be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default @@ -71,15 +71,15 @@ To create your own `myhighlighter` highlighter: `: ${ZSH_HIGHLIGHT_STYLES[key]:=value}`, being sure to prefix the key with your highlighter name and a colon. For example: - : ${ZSH_HIGHLIGHT_STYLES[myhighlighter:aurora]:=fg=green} + : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green} - _zsh_highlight_myhighlighter_highlighter() { + _zsh_highlight_acme_highlighter() { # Colorize the whole buffer with the 'aurora' style - _zsh_highlight_add_highlight 0 $#BUFFER myhighlighter:aurora + _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora } * Activate your highlighter in `~/.zshrc`: - ZSH_HIGHLIGHT_HIGHLIGHTERS+=(myhighlighter) + ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme) * [Write tests](../tests/README.md). From 80148f6c840299f0980f4359ec5307ca63837dff Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 12 Jul 2016 07:05:37 +0000 Subject: [PATCH 0390/1080] docs: State highlighters' designated namespace. --- docs/highlighters.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/highlighters.md b/docs/highlighters.md index d09da3e..1df2388 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -78,6 +78,8 @@ To create your own `acme` highlighter: _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora } +* Name your own functions and global variables `_zsh_highlight_acme_*`. + * Activate your highlighter in `~/.zshrc`: ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme) From fffe13a8fb85c3c05c20293ed58f5e79c1b848ce Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 18 Jul 2016 04:27:54 +0000 Subject: [PATCH 0391/1080] docs: Minor tweak. Suggested-by: Matthew Martin --- docs/highlighters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 1df2388..2659645 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -52,7 +52,7 @@ How to implement a new highlighter To create your own `acme` highlighter: * Create your script at - `highlighters/${acme}/${acme}-highlighter.zsh`. + `highlighters/acme/acme-highlighter.zsh`. * Implement the `_zsh_highlight_acme_highlighter_predicate` function. This function must return 0 when the highlighter needs to be called and From 95f7206a93738f8bc4fc7dc98dd0c8fcafba3976 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 20 Jul 2016 02:00:28 +0000 Subject: [PATCH 0392/1080] tests: Add an XFail test for issue #342. --- .../main/test-data/path-broken-symlink.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/path-broken-symlink.zsh diff --git a/highlighters/main/test-data/path-broken-symlink.zsh b/highlighters/main/test-data/path-broken-symlink.zsh new file mode 100644 index 0000000..79a790e --- /dev/null +++ b/highlighters/main/test-data/path-broken-symlink.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ln -s /nonexistent broken-symlink +BUFFER=': broken-symlink' +CURSOR=5 # to make path_prefix ineligible + +expected_region_highlight=( + "3 16 path 'issue #342'" # broken-symlink +) From 53083da8215e3a32a3d515ce06439a2609cd209b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 20 Jul 2016 02:00:56 +0000 Subject: [PATCH 0393/1080] 'main': Highlight a broken symlink as a file. Fixes #342. --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/path-broken-symlink.zsh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 540e05b..e1ff409 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -582,6 +582,7 @@ _zsh_highlight_main_highlighter_check_path() REPLY=path [[ -z $expanded_path ]] && return 1 + [[ -L $expanded_path ]] && return 0 [[ -e $expanded_path ]] && return 0 # Search the path in CDPATH diff --git a/highlighters/main/test-data/path-broken-symlink.zsh b/highlighters/main/test-data/path-broken-symlink.zsh index 79a790e..84c7d59 100644 --- a/highlighters/main/test-data/path-broken-symlink.zsh +++ b/highlighters/main/test-data/path-broken-symlink.zsh @@ -32,5 +32,5 @@ BUFFER=': broken-symlink' CURSOR=5 # to make path_prefix ineligible expected_region_highlight=( - "3 16 path 'issue #342'" # broken-symlink + "3 16 path" # broken-symlink ) From 3409a2e4d27386e3404e331553194c3e0f0163ac Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 21 Jul 2016 04:01:50 +0000 Subject: [PATCH 0394/1080] *: s/echo/print/ Just in case one of the interpolated variables contains a backslash. --- highlighters/main/main-highlighter.zsh | 4 ++-- zsh-syntax-highlighting.zsh | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 540e05b..abe4d38 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -693,7 +693,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() # Does not perform filename generation (globbing). _zsh_highlight_main_highlighter_expand_path() { - (( $# == 1 )) || echo "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument" >&2 + (( $# == 1 )) || print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_highlighter_expand_path: called without argument" # The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}. setopt localoptions nonomatch @@ -714,7 +714,7 @@ if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2>/dev/null; then # Initialize command type cache typeset -gA _zsh_highlight_main__command_type_cache else - echo 'zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.' >&2 + print -r -- >&2 'zsh-syntax-highlighting: Failed to load add-zsh-hook. Some speed optimizations will not be used.' # Make sure the cache is unset unset _zsh_highlight_main__command_type_cache fi diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 25b9453..e401956 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -245,7 +245,7 @@ _zsh_highlight_bind_widgets() # Load ZSH module zsh/zleparameter, needed to override user defined widgets. zmodload zsh/zleparameter 2>/dev/null || { - echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 + print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' return 1 } @@ -278,7 +278,7 @@ _zsh_highlight_bind_widgets() zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Default: unhandled case. - *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; + *) print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" ;; esac done } @@ -293,7 +293,7 @@ _zsh_highlight_load_highlighters() # Check the directory exists. [[ -d "$1" ]] || { - echo "zsh-syntax-highlighting: highlighters directory '$1' not found." >&2 + print -r -- >&2 "zsh-syntax-highlighting: highlighters directory '$1' not found." return 1 } @@ -305,7 +305,7 @@ _zsh_highlight_load_highlighters() . "$highlighter_dir/${highlighter}-highlighter.zsh" type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null && type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null || { - echo "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_${highlighter}_highlighter' and '_zsh_highlight_${highlighter}_highlighter_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." >&2 + print -r -- >&2 "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_${highlighter}_highlighter' and '_zsh_highlight_${highlighter}_highlighter_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." } } done @@ -318,13 +318,13 @@ _zsh_highlight_load_highlighters() # Try binding widgets. _zsh_highlight_bind_widgets || { - echo 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' >&2 + print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.' return 1 } # Resolve highlighters directory location. _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { - echo 'zsh-syntax-highlighting: failed loading highlighters, exiting.' >&2 + print -r -- >&@ 'zsh-syntax-highlighting: failed loading highlighters, exiting.' return 1 } @@ -336,7 +336,7 @@ _zsh_highlight_preexec_hook() } autoload -U add-zsh-hook add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { - echo 'zsh-syntax-highlighting: failed loading add-zsh-hook.' >&2 + print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.' } # Load zsh/parameter module if available From 6b69389bd9ea20f09af8550c2045cc76a9053e68 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 Jul 2016 15:52:43 +0000 Subject: [PATCH 0395/1080] 'main': New test, related to issue #328. The test passes so I'm adding it directly to master. --- .../main/test-data/path-dollared-word2.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/path-dollared-word2.zsh diff --git a/highlighters/main/test-data/path-dollared-word2.zsh b/highlighters/main/test-data/path-dollared-word2.zsh new file mode 100644 index 0000000..3485b45 --- /dev/null +++ b/highlighters/main/test-data/path-dollared-word2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +lambda="''" +touch \$lambda +BUFFER=': \$lambda' + +expected_region_highlight=( + "3 8 path" # \$lambda +) From 0d41933c61d16d8c2d68df01f41ead98b0330127 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 07:50:38 +0000 Subject: [PATCH 0396/1080] 'main': Add test for issue #343, concerning the 'command' precommand. --- highlighters/main/test-data/precommand2.zsh | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/precommand2.zsh diff --git a/highlighters/main/test-data/precommand2.zsh b/highlighters/main/test-data/precommand2.zsh new file mode 100644 index 0000000..3d8f332 --- /dev/null +++ b/highlighters/main/test-data/precommand2.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='command -v ls' + +expected_region_highlight=( + "1 7 precommand" # command + "9 10 single-hyphen-option 'issue #343'" # -v + "12 13 command 'issue #343'" # ls +) From fa57633d81526451248919210ae4aad731a76a0e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 08:13:51 +0000 Subject: [PATCH 0397/1080] 'main': Enable test for issue #238. --- highlighters/main/test-data/exec-redirection1.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/exec-redirection1.zsh b/highlighters/main/test-data/exec-redirection1.zsh index 784ec47..caec2f1 100644 --- a/highlighters/main/test-data/exec-redirection1.zsh +++ b/highlighters/main/test-data/exec-redirection1.zsh @@ -31,7 +31,7 @@ BUFFER='exec {foo}>&/tmp ls' expected_region_highlight=( "1 4 precommand" # exec - # TODO: "6 10 redirection 'issue #238'" # {foo} + "6 10 redirection 'issue #238'" # {foo} "11 12 redirection" # >& "13 16 path" # /tmp "18 19 command 'issue #238'" # ls From 8013dc3b8db6726fd2cc4bccacaaab9fb31055ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 23:15:32 +0000 Subject: [PATCH 0398/1080] dev tools: Add a script that generates a test-data file. --- tests/README.md | 19 +++++++++++ tests/generate.zsh | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100755 tests/generate.zsh diff --git a/tests/README.md b/tests/README.md index d55945f..b7e3450 100644 --- a/tests/README.md +++ b/tests/README.md @@ -39,6 +39,25 @@ which is automatically cleaned up after the test exits. For example: "1 21 command" # bar/testing-issue-228 ) + +Writing new tests +----------------- + +An experimental tool is available to generate test files: + + zsh -f tests/generate.zsh 'ls -x' \ + | sed s/YYYY/$(date +%Y)/ \ + > highlighters/main/test-data/foo.zsh + git add -N $_ + +This generates a test file based on the current highlighting of the given `$BUFFER` +(in this case, `ls -x`). + +_This tool is experimental._ Its interface may change. In particular it may +grow ways to set `$PREBUFFER` and/or `$ZSH_HIGHLIGHT_HIGHLIGHTERS` or to +inject free-form code into the generated file. + + Highlighting test ----------------- diff --git a/tests/generate.zsh b/tests/generate.zsh new file mode 100755 index 0000000..3fc0ebc --- /dev/null +++ b/tests/generate.zsh @@ -0,0 +1,83 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +emulate -LR zsh + +# Argument parsing. +if (( $# != 1 )) || [[ $1 == -* ]]; then + print -r -- >&2 "$0: usage: $0 BUFFER" + print -r -- >&2 "" + print -r -- >&2 "This tool generates a test file, suitable for highlighters/*/test-data/." + exit 1 +fi +buffer=$1 + +# Load the main script. +. ${0:A:h:h}/zsh-syntax-highlighting.zsh + +# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style +_zsh_highlight_add_highlight() +{ + region_highlight+=("$1 $2 $3") +} + +# Copyright block +<$0 sed -n -e '1,/^$/p' | sed -e 's/2[0-9][0-9][0-9]/YYYY/' +echo "" + +# Buffer +print -n 'BUFFER=' +print -r -- ${(qq)buffer} +echo "" + +# Expectations +print 'expected_region_highlight=(' +() { + local i + local PREBUFFER + local BUFFER + + PREBUFFER="" + BUFFER="$buffer" + region_highlight=() + _zsh_highlight + + for ((i=1; i<=${#region_highlight}; i++)); do + local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) + integer start=$highlight_zone[1] end=$highlight_zone[2] + if (( start < end )) # region_highlight ranges are half-open + then + (( --end )) # convert to closed range, like expected_region_highlight + (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed + fi + printf " %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} $BUFFER[start,end] + done +} +print ')' From add6825898e101ccab12d3ffd93091fc2284e637 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 29 Jul 2016 19:02:40 +0000 Subject: [PATCH 0399/1080] dev tools: Extend tests/generate.zsh. --- tests/README.md | 12 ++++-------- tests/generate.zsh | 10 +++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/README.md b/tests/README.md index b7e3450..5526612 100644 --- a/tests/README.md +++ b/tests/README.md @@ -45,17 +45,13 @@ Writing new tests An experimental tool is available to generate test files: - zsh -f tests/generate.zsh 'ls -x' \ - | sed s/YYYY/$(date +%Y)/ \ - > highlighters/main/test-data/foo.zsh - git add -N $_ + zsh -f tests/generate.zsh 'ls -x' acme newfile -This generates a test file based on the current highlighting of the given `$BUFFER` -(in this case, `ls -x`). +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`). _This tool is experimental._ Its interface may change. In particular it may -grow ways to set `$PREBUFFER` and/or `$ZSH_HIGHLIGHT_HIGHLIGHTERS` or to -inject free-form code into the generated file. +grow ways to set `$PREBUFFER` to inject free-form code into the generated file. Highlighting test diff --git a/tests/generate.zsh b/tests/generate.zsh index 3fc0ebc..5bd0b60 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -31,13 +31,17 @@ emulate -LR zsh # Argument parsing. -if (( $# != 1 )) || [[ $1 == -* ]]; then - print -r -- >&2 "$0: usage: $0 BUFFER" +if (( $# != 3 )) || [[ $1 == -* ]]; then + print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" print -r -- >&2 "" - print -r -- >&2 "This tool generates a test file, suitable for highlighters/*/test-data/." + print -r -- >&2 "Generate highlighters/HIGHILGHTER/test-data/BASENAME.zsh based on the" + print -r -- >&2 "current highlighting of BUFFER." exit 1 fi buffer=$1 +ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) +exec >${0:A:h:h}/highlighters/$2/test-data/$3.zsh +git add -N ${0:A:h:h}/highlighters/$2/test-data/$3.zsh # Load the main script. . ${0:A:h:h}/zsh-syntax-highlighting.zsh From 9e569bb0fe04211d3ddb04ff73a88b03e390cf35 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 21:50:46 +0200 Subject: [PATCH 0400/1080] driver: Widget binding: Support binding incomplete/nonexistent widgets --- zsh-syntax-highlighting.zsh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index e401956..84fe126 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -250,8 +250,10 @@ _zsh_highlight_bind_widgets() } # Override ZLE widgets to make them invoke _zsh_highlight. + local -U widgets_to_bind + widgets_to_bind=(${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}) local cur_widget - for cur_widget in ${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}; do + for cur_widget in $widgets_to_bind; do case $widgets[$cur_widget] in # Already rebound event: do nothing. @@ -277,8 +279,15 @@ _zsh_highlight_bind_widgets() builtin) eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; + # Incomplete or nonexistent widget: Bind to z-sy-h directly. + *) + if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then + _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } + zle -N $cur_widget _zsh_highlight_widget_$cur_widget + else # Default: unhandled case. - *) print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" ;; + print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" + fi esac done } From 5bae6219008b2a8671c0de60476f50f6e0ff34ce Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 21:56:57 +0200 Subject: [PATCH 0401/1080] driver: Always bind zle-line-finish and use it instead of accept-* Special handling for cursor imprint or partial path highlighting is needed in more cases than accept-*. For example when accepting a line from isearch, no accept-* widget is invoked. The proper way is to use zle-line-finish. Trumps #259. Fixes #284. --- highlighters/cursor/cursor-highlighter.zsh | 7 +++---- highlighters/main/main-highlighter.zsh | 7 +++---- highlighters/main/test-data/path_prefix2.zsh | 2 +- zsh-syntax-highlighting.zsh | 6 ++++++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index aa70f55..13479b9 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -34,15 +34,14 @@ # Whether the cursor highlighter should be called or not. _zsh_highlight_cursor_highlighter_predicate() { - # accept-* may trigger removal of cursor highlighting - [[ $WIDGET == accept-* ]] || - _zsh_highlight_cursor_moved + # remove cursor highlighting when the line is finished + [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved } # Cursor highlighting function. _zsh_highlight_cursor_highlighter() { - [[ $WIDGET == accept-* ]] && return + [[ $WIDGET == zle-line-finish ]] && return _zsh_highlight_add_highlight $CURSOR $(( $CURSOR + 1 )) cursor } diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7e62b90..701d0cc 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -62,9 +62,8 @@ # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() { - # accept-* may trigger removal of path_prefix highlighting - [[ $WIDGET == accept-* ]] || - _zsh_highlight_buffer_modified + # may need to remove path_prefix highlighting when the line ends + [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified } # Helper to deal with tokens crossing line boundaries. @@ -596,7 +595,7 @@ _zsh_highlight_main_highlighter_check_path() # If this word ends the buffer, check if it's the prefix of a valid path. if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && - [[ $WIDGET != accept-* ]]; then + [[ $WIDGET != zle-line-finish ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) (( $#tmp > 0 )) && REPLY=path_prefix && return 0 diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index ffe50cd..501928a 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -31,7 +31,7 @@ # Related to path_prefix.zsh BUFFER='ls /bin/s' -WIDGET=accept-line +WIDGET=zle-line-finish expected_region_highlight=( "4 9 default" # /bin/s diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 84fe126..80f5a4e 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -252,6 +252,12 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local -U widgets_to_bind widgets_to_bind=(${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}) + + # Always wrap special zle-line-finish widget. This is needed to decide if the + # current line ends and special highlighting logic needs to be applied. + # E.g. remove cursor imprint, don't highlight partial paths, ... + widgets_to_bind+=(zle-line-finish) + local cur_widget for cur_widget in $widgets_to_bind; do case $widgets[$cur_widget] in From a8fe22d422515a46a4c2e968ff37762c577059bc Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 29 Mar 2016 22:13:46 +0200 Subject: [PATCH 0402/1080] driver: Don't highlight in isearch zsh version 5.2 and lower don't support ISEARCHMATCH_ACTIVE and we are unable to re-apply zle_highlight on top. Therefore it is impossible to see the underlined matched area. Since that information is more important, completely disable highlighting in isearch in that case. To do that, we need to make sure we are actually called when something changes in isearch. Trumps #257. The FAQ entry presupposes #245 will be fixed (in time for the release) too. --- README.md | 18 ++++++++++++++++++ zsh-syntax-highlighting.zsh | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index ac8beaf..7f0fe28 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,24 @@ custom widgets have been created (i.e., after all `zle -N` calls and after running `compinit`). Widgets created later will work, but will not update the syntax highlighting. +### Why does syntax highlighting not work while searching history? + +_This problem is fixed in zsh 5.3 and newer._ + +Highlighting the command line during an incremental history search +(with the `history-incremental-search-backward` widget, which is +bound by default to Ctrl+R in zsh's emacs keymap) requires zsh 5.3 +or newer. + +Under zsh 5.2 and older, the zsh-default underlining of the matched portion +of the buffer remains available, but zsh-syntax-highlighting's additional +highlighting is unavailable. (Those versions of zsh do not provide enough +information to allow computing the highlighting correctly.) + +See [issue #288][i288] for details. + +[i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 + ### How are new releases announced? There is currently no "push" announcements channel. However, the following diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 80f5a4e..de3fea9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -58,6 +58,13 @@ _zsh_highlight() # Store the previous command return code to restore it whatever happens. local 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?'. + if [[ $WIDGET == zle-isearch-update ]]; then + region_highlight=() + return $ret + fi + setopt localoptions warncreateglobal setopt localoptions noksharrays local REPLY # don't leak $REPLY into global scope @@ -258,6 +265,10 @@ _zsh_highlight_bind_widgets() # E.g. remove cursor imprint, don't highlight partial paths, ... widgets_to_bind+=(zle-line-finish) + # Always wrap special zle-isearch-update widget to be notified of updates in isearch. + # This is needed because we need to disable highlighting in that case. + widgets_to_bind+=(zle-isearch-update) + local cur_widget for cur_widget in $widgets_to_bind; do case $widgets[$cur_widget] in From 4ad311ec0a6837b7c83bcfd1a1bf12cceb03f363 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sat, 30 Jul 2016 20:08:12 +0000 Subject: [PATCH 0403/1080] =?UTF-8?q?driver:=20Enable=20highlighting=20dur?= =?UTF-8?q?ing=20isearch=20under=20zsh=E2=89=A55.3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch causes a behaviour difference in the [i257] scenario: - Before this change, the zle_highlight[isearch] is applied and z-sy-h's highlighting isn't. - With this change, both zle_highlight[isearch] and z-sy-h's highlighting are applied, so «echo foo» renders the first word in green underline (fg=green from ZSH_HIGHLIGHT_STYLES[builtin], underline from zle_highlight[isearch]). This patch causes the presuppositional FAQ entry added in a8fe22d422515a46a4c2e968ff37762c577059bc to be correct. This is part of #261, of which #288 was a spin-off. [i257] https://github.com/zsh-users/zsh-syntax-highlighting/pull/257#issuecomment-168394665 --- 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 de3fea9..7879216 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -60,7 +60,7 @@ _zsh_highlight() # 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?'. - if [[ $WIDGET == zle-isearch-update ]]; then + if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then region_highlight=() return $ret fi From e2f863c151c395023dd2b0f3a6f8d3bd1a6d8470 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 11 Aug 2016 19:37:37 +0000 Subject: [PATCH 0404/1080] minor: Fix typo in development usage message. --- tests/generate.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 5bd0b60..3eee487 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -34,7 +34,7 @@ emulate -LR zsh if (( $# != 3 )) || [[ $1 == -* ]]; then print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" print -r -- >&2 "" - print -r -- >&2 "Generate highlighters/HIGHILGHTER/test-data/BASENAME.zsh based on the" + print -r -- >&2 "Generate highlighters/HIGHLIGHTER/test-data/BASENAME.zsh based on the" print -r -- >&2 "current highlighting of BUFFER." exit 1 fi From d711563fe1bf8fa6810bc34ac92a2fd3150290ed Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Aug 2016 09:17:59 +0000 Subject: [PATCH 0405/1080] driver: Make it reentrant. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an infinite recursion in zsh without zle-line-pre-redraw [≤5.2] in the following situation: % source zsh-syntax-highlighting.zsh % eval "my-self-insert() { zle -M 'foobar'; ${(q)widgets[self-insert]#*:} \"\$@\" }" % zle -N self-insert my-self-insert % source zsh-syntax-highlighting.zsh Fixes #305. --- zsh-syntax-highlighting.zsh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 7879216..27da031 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -249,6 +249,7 @@ _zsh_highlight_call_widget() _zsh_highlight_bind_widgets() { setopt localoptions noksharrays + local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once # Load ZSH module zsh/zleparameter, needed to override user defined widgets. zmodload zsh/zleparameter 2>/dev/null || { @@ -258,7 +259,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local -U widgets_to_bind - widgets_to_bind=(${${(k)widgets}:#(.*|orig-*|run-help|which-command|beep|set-local-history|yank)}) + widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)}) # Always wrap special zle-line-finish widget. This is needed to decide if the # current line ends and special highlighting logic needs to be applied. @@ -283,13 +284,13 @@ _zsh_highlight_bind_widgets() # NO_function_argzero, regardless of the option's setting here. # User defined widget: override and rebind old one with prefix "orig-". - user:*) zle -N orig-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" + user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} + eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C orig-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} - eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget orig-${(q)cur_widget} -- \"\$@\" }" + completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} + eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". From 295d62ec888d0d43579abad4e4245aede8f2cc85 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Aug 2016 09:43:54 +0000 Subject: [PATCH 0406/1080] driver: Followup to last: make the value more unique. Part of issue #305. --- zsh-syntax-highlighting.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 27da031..5e13253 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -249,6 +249,7 @@ _zsh_highlight_call_widget() _zsh_highlight_bind_widgets() { setopt localoptions noksharrays + typeset -F SECONDS local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once # Load ZSH module zsh/zleparameter, needed to override user defined widgets. From d1c773faa7e86b76657cd39bbb1dcb5db8f5c017 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 13:00:55 +0000 Subject: [PATCH 0407/1080] noop: Fix indentation. --- 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 701d0cc..7d652eb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -348,9 +348,9 @@ _zsh_highlight_main_highlighter() next_word+=':sudo_opt:' next_word+=':start:' fi - fi + fi - if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word + if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=precommand elif [[ "$arg" = "sudo" ]]; then From 6e2ef574c89fa7e0f0e3ddc8934020be722e1d59 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 13:25:43 +0000 Subject: [PATCH 0408/1080] noop: Restructure code for clarity. The structure now mirrors the stall construct at the top of the loop. --- 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 7d652eb..47e43e7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -546,7 +546,12 @@ _zsh_highlight_main_highlighter() this_word=':start::regular:' fi start_pos=$end_pos - (( in_redirection == 0 )) && this_word=$next_word + if (( in_redirection == 0 )); then + # This is the default/common codepath. + this_word=$next_word + else + # Stall $this_word. + fi done } From 179b8e753fa572f2d42003954b04c23cdc63d646 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 13:27:36 +0000 Subject: [PATCH 0409/1080] 'main': Test for redirection earlier. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a prerequisite for the next commit. The incumbent code was wrong: the test of $in_redirection in the first hunk would never have seen «(( in_redirection == 2 ))». That had no visible effect since options to sudo don't look like redirection operators. --- highlighters/main/main-highlighter.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 47e43e7..ade7907 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -331,6 +331,11 @@ _zsh_highlight_main_highlighter() continue fi + if _zsh_highlight_main__is_redirection $arg ; then + # A '<' or '>', possibly followed by a digit + in_redirection=2 + fi + # Parse the sudo command line if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then @@ -432,10 +437,8 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif _zsh_highlight_main__is_redirection $arg; then - # A '<' or '>', possibly followed by a digit + elif (( in_redirection == 2 )); then style=redirection - (( in_redirection=2 )) elif [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # @@ -509,9 +512,8 @@ _zsh_highlight_main_highlighter() else style=unknown-token fi - elif _zsh_highlight_main__is_redirection $arg; then + elif (( in_redirection == 2 )); then style=redirection - (( in_redirection=2 )) else if _zsh_highlight_main_highlighter_check_path; then style=$REPLY From 757d047f09cda75a74ce62e198504893335f9ad5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 13:31:05 +0000 Subject: [PATCH 0410/1080] 'main': The word after 'sudo' is only a non-command word if it is an option. --- highlighters/main/main-highlighter.zsh | 3 +++ highlighters/main/test-data/sudo-command.zsh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ade7907..02d7225 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -338,6 +338,9 @@ _zsh_highlight_main_highlighter() # Parse the sudo command line if (( ! in_redirection )); then + if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then + this_word=${this_word//:sudo_opt:/} + fi if [[ $this_word == *':sudo_opt:'* ]]; then case "$arg" in # Flag that requires an argument diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 4f8909e..3183a23 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -31,7 +31,7 @@ # * -i (no argument) # * -C3 (pasted argument) # * -u otheruser (non-pasted argument) -BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ;' +BUFFER='sudo -C3 -u otheruser -i ls /; sudo ; sudo -u ; sudo notacommand' expected_region_highlight=( "1 4 precommand" # sudo @@ -43,4 +43,5 @@ expected_region_highlight=( "29 29 path" # / "37 37 unknown-token" # ;, error because empty command "47 47 unknown-token" # ;, error because incomplete command + "54 64 unknown-token" # notacommand - doesn't falls back to "not a command word" codepath ) From 2c002f9f89bd3b127577ee1247b89b1a02af6234 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 13:40:31 +0000 Subject: [PATCH 0411/1080] noop: Add comments. --- highlighters/main/main-highlighter.zsh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 02d7225..a810eff 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -258,6 +258,7 @@ _zsh_highlight_main_highlighter() local proc_buf="$buf" for arg in ${interactive_comments-${(z)buf}} \ ${interactive_comments+${(zZ+c+)buf}}; do + # Initialize $next_word. if (( in_redirection )); then (( --in_redirection )) fi @@ -267,6 +268,14 @@ _zsh_highlight_main_highlighter() else # Stall $next_word. fi + + # Initialize per-"simple command" [zshmisc(1)] variables: + # + # $already_added (see next paragraph) + # $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" + # # $already_added is set to 1 to disable adding an entry to region_highlight # for this iteration. Currently, that is done for "" and $'' strings, # which add the entry early so escape sequences within the string override @@ -280,7 +289,7 @@ _zsh_highlight_main_highlighter() fi fi - # advance $start_pos, skipping over whitespace in $buf. + # Compute the new $start_pos and $end_pos, skipping over whitespace in $buf. 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)..} @@ -300,8 +309,7 @@ _zsh_highlight_main_highlighter() ((end_pos=$start_pos+${#arg})) fi - # Above `if` computes new start_pos and end_pos. - # Here we compute new proc_buf. We advance it + # 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. @@ -320,6 +328,9 @@ _zsh_highlight_main_highlighter() # Why [,-1] is slower than [,length] isn't clear. proc_buf="${proc_buf[offset + $#arg + 1,len]}" + # Handle the INTERACTIVE_COMMENTS option. + # + # We use the (Z+c+) flag so the entire comment is presented as one token in $arg. if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then style=comment @@ -331,16 +342,21 @@ _zsh_highlight_main_highlighter() continue fi + # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then # A '<' or '>', possibly followed by a digit in_redirection=2 fi - # Parse the sudo command line + # Special-case the first word after 'sudo'. if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then this_word=${this_word//:sudo_opt:/} fi + fi + + # Parse the sudo command line + if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then case "$arg" in # Flag that requires an argument @@ -358,6 +374,7 @@ _zsh_highlight_main_highlighter() fi fi + # The Great Fork: is this a command word? Is this a non-command word? if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=precommand From b7bb4f86575496918602ace125a9718fedae7b68 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:08:47 +0000 Subject: [PATCH 0412/1080] README: Rephrase a question non-negatively^W neutrally. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 7f0fe28..f5521c6 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,7 @@ custom widgets have been created (i.e., after all `zle -N` calls and after running `compinit`). Widgets created later will work, but will not update the syntax highlighting. -### Why does syntax highlighting not work while searching history? - -_This problem is fixed in zsh 5.3 and newer._ +### Does syntax highlighting work during incremental history search? Highlighting the command line during an incremental history search (with the `history-incremental-search-backward` widget, which is From d1e0defceb2330b18d794ad5cc24c87984cbdb95 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:09:04 +0000 Subject: [PATCH 0413/1080] README: Add a reference to upstream's documentation. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5521c6..9e045a8 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,14 @@ Highlighting the command line during an incremental history search bound by default to Ctrl+R in zsh's emacs keymap) requires zsh 5.3 or newer. -Under zsh 5.2 and older, the zsh-default underlining of the matched portion +Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting] of the matched portion of the buffer remains available, but zsh-syntax-highlighting's additional highlighting is unavailable. (Those versions of zsh do not provide enough information to allow computing the highlighting correctly.) See [issue #288][i288] for details. +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 ### How are new releases announced? From b2ba91f12f7e88170adc549e978c400c9c7d6a3e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:09:42 +0000 Subject: [PATCH 0414/1080] noop: Rewrap. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9e045a8..4558463 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,10 @@ Highlighting the command line during an incremental history search bound by default to Ctrl+R in zsh's emacs keymap) requires zsh 5.3 or newer. -Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting] of the matched portion -of the buffer remains available, but zsh-syntax-highlighting's additional -highlighting is unavailable. (Those versions of zsh do not provide enough -information to allow computing the highlighting correctly.) +Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting] +of the matched portion of the buffer remains available, but zsh-syntax-highlighting's +additional highlighting is unavailable. (Those versions of zsh do not provide +enough information to allow computing the highlighting correctly.) See [issue #288][i288] for details. From f3242cbd6aba306d4423991ac738fd430c4723ec Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:22:39 +0000 Subject: [PATCH 0415/1080] driver: Followup to d711563fe1bf8fa6810bc34ac92a2fd3150290ed: actually make the driver reentrant. Re-fixes #305. --- zsh-syntax-highlighting.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 5e13253..98e640e 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -286,17 +286,17 @@ _zsh_highlight_bind_widgets() # User defined widget: override and rebind old one with prefix "orig-". user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; # Completion widget: override and rebind old one with prefix "orig-". completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} - eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$cur_widget;; + builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; # Incomplete or nonexistent widget: Bind to z-sy-h directly. *) From f91a7b885e7ddbf3c27d48c300cb0de83ae5cab6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:49:18 +0000 Subject: [PATCH 0416/1080] driver: Followup to 80148f6c840299f0980f4359ec5307ca63837dff: don't squat on the highlighters' namespace. --- 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 98e640e..66a42f8 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -88,7 +88,7 @@ _zsh_highlight() local highlighter; for highlighter in $ZSH_HIGHLIGHT_HIGHLIGHTERS; do # eval cache place for current highlighter and prepare it - cache_place="_zsh_highlight_highlighter_${highlighter}_cache" + cache_place="_zsh_highlight__highlighter_${highlighter}_cache" typeset -ga ${cache_place} # If highlighter needs to be invoked From a3d5dfcbdae9cea58aa703efe79192927a34e713 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 12 Jul 2016 07:15:04 +0000 Subject: [PATCH 0417/1080] driver: Rename highlighter entry points This updates the docs and the driver, in a manner backwards compatible with existing highlighters. (None of the highlighters are touched by this change, yet tests continue to pass.) Part of issue #329. --- docs/highlighters.md | 18 ++++++++++++++---- zsh-syntax-highlighting.zsh | 29 +++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 2659645..c0f79bc 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -54,16 +54,16 @@ To create your own `acme` highlighter: * Create your script at `highlighters/acme/acme-highlighter.zsh`. -* Implement the `_zsh_highlight_acme_highlighter_predicate` function. +* Implement the `_zsh_highlight_highlighter_acme_predicate` function. This function must return 0 when the highlighter needs to be called and non-zero otherwise, for example: - _zsh_highlight_acme_highlighter_predicate() { + _zsh_highlight_highlighter_acme_predicate() { # Call this highlighter in SVN working copies [[ -d .svn ]] } -* Implement the `_zsh_highlight_acme_highlighter` function. +* Implement the `_zsh_highlight_highlighter_acme_paint` function. This function does the actual syntax highlighting, by calling `_zsh_highlight_add_highlight` with the start and end of the region to be highlighted and the `ZSH_HIGHLIGHT_STYLES` key to use. Define the default @@ -73,13 +73,23 @@ To create your own `acme` highlighter: : ${ZSH_HIGHLIGHT_STYLES[acme:aurora]:=fg=green} - _zsh_highlight_acme_highlighter() { + _zsh_highlight_highlighter_acme_paint() { # Colorize the whole buffer with the 'aurora' style _zsh_highlight_add_highlight 0 $#BUFFER acme:aurora } * Name your own functions and global variables `_zsh_highlight_acme_*`. + - In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints + `_zsh_highlight_highlighter_acme_predicate` and + `_zsh_highlight_highlighter_acme_paint` + were named + `_zsh_highlight_acme_highlighter_predicate` and + `_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). + * Activate your highlighter in `~/.zshrc`: ZSH_HIGHLIGHT_HIGHLIGHTERS+=(acme) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index e401956..9462c2a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -85,7 +85,7 @@ _zsh_highlight() typeset -ga ${cache_place} # If highlighter needs to be invoked - if "_zsh_highlight_${highlighter}_highlighter_predicate"; then + if "_zsh_highlight_highlighter_${highlighter}_predicate"; then # save a copy, and cleanup region_highlight region_highlight_copy=("${region_highlight[@]}") @@ -93,7 +93,7 @@ _zsh_highlight() # Execute highlighter and save result { - "_zsh_highlight_${highlighter}_highlighter" + "_zsh_highlight_highlighter_${highlighter}_paint" } always { eval "${cache_place}=(\"\${region_highlight[@]}\")" } @@ -301,13 +301,26 @@ _zsh_highlight_load_highlighters() local highlighter highlighter_dir for highlighter_dir ($1/*/); do highlighter="${highlighter_dir:t}" - [[ -f "$highlighter_dir/${highlighter}-highlighter.zsh" ]] && { + [[ -f "$highlighter_dir/${highlighter}-highlighter.zsh" ]] && . "$highlighter_dir/${highlighter}-highlighter.zsh" - type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null && - type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null || { - print -r -- >&2 "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_${highlighter}_highlighter' and '_zsh_highlight_${highlighter}_highlighter_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." - } - } + if type "_zsh_highlight_highlighter_${highlighter}_paint" &> /dev/null && + type "_zsh_highlight_highlighter_${highlighter}_predicate" &> /dev/null; + then + # New (0.5.0) function names + elif type "_zsh_highlight_${highlighter}_highlighter" &> /dev/null && + type "_zsh_highlight_${highlighter}_highlighter_predicate" &> /dev/null; + then + # Old (0.4.x) function names + if false; then + # TODO: only show this warning for plugin authors/maintainers, not for end users + print -r -- >&2 "zsh-syntax-highlighting: warning: ${(qq)highlighter} highlighter uses deprecated entry point names; please ask its maintainer to update it: https://github.com/zsh-users/zsh-syntax-highlighting/issues/329" + fi + # Make it work. + eval "_zsh_highlight_highlighter_${(q)highlighter}_paint() { _zsh_highlight_${(q)highlighter}_highlighter \"\$@\" }" + eval "_zsh_highlight_highlighter_${(q)highlighter}_predicate() { _zsh_highlight_${(q)highlighter}_highlighter_predicate \"\$@\" }" + else + print -r -- >&2 "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." + fi done } From c793e0dceab1571ff02078ed764d294326922a4f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 21 Jul 2016 03:33:28 +0000 Subject: [PATCH 0418/1080] highlighters: Rename entry points. This tracks the API change made in the previous commit, as suggested in the (#if 0'd) deprecation warning. --- highlighters/brackets/brackets-highlighter.zsh | 4 ++-- highlighters/cursor/cursor-highlighter.zsh | 4 ++-- highlighters/line/line-highlighter.zsh | 4 ++-- highlighters/main/main-highlighter.zsh | 6 +++--- highlighters/pattern/pattern-highlighter.zsh | 4 ++-- highlighters/root/root-highlighter.zsh | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index ce52309..2a5f396 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -38,13 +38,13 @@ : ${ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]:=standout} # Whether the brackets highlighter should be called or not. -_zsh_highlight_brackets_highlighter_predicate() +_zsh_highlight_highlighter_brackets_predicate() { _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified } # Brackets highlighting function. -_zsh_highlight_brackets_highlighter() +_zsh_highlight_highlighter_brackets_paint() { local char style local -i bracket_color_size=${#ZSH_HIGHLIGHT_STYLES[(I)bracket-level-*]} buflen=${#BUFFER} level=0 matchingpos pos diff --git a/highlighters/cursor/cursor-highlighter.zsh b/highlighters/cursor/cursor-highlighter.zsh index aa70f55..6806aa2 100644 --- a/highlighters/cursor/cursor-highlighter.zsh +++ b/highlighters/cursor/cursor-highlighter.zsh @@ -32,7 +32,7 @@ : ${ZSH_HIGHLIGHT_STYLES[cursor]:=standout} # Whether the cursor highlighter should be called or not. -_zsh_highlight_cursor_highlighter_predicate() +_zsh_highlight_highlighter_cursor_predicate() { # accept-* may trigger removal of cursor highlighting [[ $WIDGET == accept-* ]] || @@ -40,7 +40,7 @@ _zsh_highlight_cursor_highlighter_predicate() } # Cursor highlighting function. -_zsh_highlight_cursor_highlighter() +_zsh_highlight_highlighter_cursor_paint() { [[ $WIDGET == accept-* ]] && return diff --git a/highlighters/line/line-highlighter.zsh b/highlighters/line/line-highlighter.zsh index 2da55ea..f922dc9 100644 --- a/highlighters/line/line-highlighter.zsh +++ b/highlighters/line/line-highlighter.zsh @@ -32,13 +32,13 @@ : ${ZSH_HIGHLIGHT_STYLES[line]:=} # Whether the root highlighter should be called or not. -_zsh_highlight_line_highlighter_predicate() +_zsh_highlight_highlighter_line_predicate() { _zsh_highlight_buffer_modified } # root highlighting function. -_zsh_highlight_line_highlighter() +_zsh_highlight_highlighter_line_paint() { _zsh_highlight_add_highlight 0 $#BUFFER line } diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index abe4d38..f790a2a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -60,7 +60,7 @@ : ${ZSH_HIGHLIGHT_STYLES[comment]:=fg=black,bold} # Whether the highlighter should be called or not. -_zsh_highlight_main_highlighter_predicate() +_zsh_highlight_highlighter_main_predicate() { # accept-* may trigger removal of path_prefix highlighting [[ $WIDGET == accept-* ]] || @@ -150,7 +150,7 @@ _zsh_highlight_main__resolve_alias() { } # Main syntax highlighting function. -_zsh_highlight_main_highlighter() +_zsh_highlight_highlighter_main_paint() { ## Before we even 'emulate -L', we must test a few options that would reset. if [[ -o interactive_comments ]]; then @@ -166,7 +166,7 @@ _zsh_highlight_main_highlighter() # At the PS3 prompt and in vared, highlight nothing. # - # (We can't check this in _zsh_highlight_main_highlighter_predicate because + # (We can't check this in _zsh_highlight_highlighter_main_predicate because # if the predicate returns false, the previous value of region_highlight # would be reused.) if [[ $CONTEXT == (select|vared) ]]; then diff --git a/highlighters/pattern/pattern-highlighter.zsh b/highlighters/pattern/pattern-highlighter.zsh index 4e2eabd..054eff7 100644 --- a/highlighters/pattern/pattern-highlighter.zsh +++ b/highlighters/pattern/pattern-highlighter.zsh @@ -32,13 +32,13 @@ typeset -gA ZSH_HIGHLIGHT_PATTERNS # Whether the pattern highlighter should be called or not. -_zsh_highlight_pattern_highlighter_predicate() +_zsh_highlight_highlighter_pattern_predicate() { _zsh_highlight_buffer_modified } # Pattern syntax highlighting function. -_zsh_highlight_pattern_highlighter() +_zsh_highlight_highlighter_pattern_paint() { setopt localoptions extendedglob local pattern diff --git a/highlighters/root/root-highlighter.zsh b/highlighters/root/root-highlighter.zsh index ede9769..3718c44 100644 --- a/highlighters/root/root-highlighter.zsh +++ b/highlighters/root/root-highlighter.zsh @@ -32,13 +32,13 @@ : ${ZSH_HIGHLIGHT_STYLES[root]:=standout} # Whether the root highlighter should be called or not. -_zsh_highlight_root_highlighter_predicate() +_zsh_highlight_highlighter_root_predicate() { _zsh_highlight_buffer_modified } # root highlighting function. -_zsh_highlight_root_highlighter() +_zsh_highlight_highlighter_root_paint() { if (( EUID == 0 )) { _zsh_highlight_add_highlight 0 $#BUFFER root } } From 11c908196700c00c4662295f44747a5826615c4b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 19:01:25 +0000 Subject: [PATCH 0419/1080] *: error messages: Fix quoting. --- 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 dad3800..9de8d61 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -305,7 +305,7 @@ _zsh_highlight_bind_widgets() zle -N $cur_widget _zsh_highlight_widget_$cur_widget else # Default: unhandled case. - print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" + print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" fi esac done @@ -321,7 +321,7 @@ _zsh_highlight_load_highlighters() # Check the directory exists. [[ -d "$1" ]] || { - print -r -- >&2 "zsh-syntax-highlighting: highlighters directory '$1' not found." + print -r -- >&2 "zsh-syntax-highlighting: highlighters directory ${(qq)1} not found." return 1 } @@ -347,7 +347,7 @@ _zsh_highlight_load_highlighters() eval "_zsh_highlight_highlighter_${(q)highlighter}_paint() { _zsh_highlight_${(q)highlighter}_highlighter \"\$@\" }" eval "_zsh_highlight_highlighter_${(q)highlighter}_predicate() { _zsh_highlight_${(q)highlighter}_highlighter_predicate \"\$@\" }" else - print -r -- >&2 "zsh-syntax-highlighting: '${highlighter}' highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in '${highlighter_dir}/${highlighter}-highlighter.zsh'." + print -r -- >&2 "zsh-syntax-highlighting: ${(qq)highlighter} highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in ${(qq):-"$highlighter_dir/${highlighter}-highlighter.zsh"}." fi done } From 51614ca2c994486dc0a41ec0737a97f0af16a505 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 30 Aug 2016 02:56:23 +0000 Subject: [PATCH 0420/1080] 'main': Avoid triggering a zsh bug related to hashed commands. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This manifested in completion of the form «./foo» where there happened to be a program called 'foo' in $PATH. Fixes #354. Closes #355. --- highlighters/main/main-highlighter.zsh | 9 ++++++++- zsh-syntax-highlighting.zsh | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b120bf2..f6194cf 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -113,7 +113,14 @@ _zsh_highlight_main__type() { REPLY=builtin elif (( $+commands[(e)$1] )); then REPLY=command - elif ! builtin type -w -- $1 >/dev/null 2>&1; then + # 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 + # falling through to the $() below, incurring a fork. (Issue #354.) + # + # The second disjunct mimics the isrelative() C call from the zsh bug. + elif { is-at-least 5.3 || [[ $1 != */* ]] } && + ! builtin type -w -- $1 >/dev/null 2>&1; then REPLY=none fi fi diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 9de8d61..c20751b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -383,5 +383,7 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { # Load zsh/parameter module if available zmodload zsh/parameter 2>/dev/null || true +autoload -U is-at-least + # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true From da60234fb236ccd2b199ffa8a157014dacf4e591 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 31 Aug 2016 14:08:16 +0000 Subject: [PATCH 0421/1080] driver: Declare global variables This caused warnings with `setopt warn_create_global`. --- 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 c20751b..f9d82de 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -32,8 +32,8 @@ 0=${(%):-%N} if true; then # $0 is reliable - ZSH_HIGHLIGHT_VERSION=$(<"${0:A:h}"/.version) - ZSH_HIGHLIGHT_REVISION=$(<"${0:A:h}"/.revision-hash) + typeset -g ZSH_HIGHLIGHT_VERSION=$(<"${0:A:h}"/.version) + typeset -g ZSH_HIGHLIGHT_REVISION=$(<"${0:A:h}"/.revision-hash) if [[ $ZSH_HIGHLIGHT_REVISION == \$Format:* ]]; then # When running from a source tree without 'make install', $ZSH_HIGHLIGHT_REVISION # would be set to '$Format:%H$' literally. That's an invalid value, and obtaining From 4c4baede519a20805482161d175188ddf34975dc Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Thu, 8 Sep 2016 14:56:24 +0200 Subject: [PATCH 0422/1080] 'brackets': Don't highlight corresponding bracket on accept-line --- .../brackets/brackets-highlighter.zsh | 14 ++++--- .../cursor-matchingbracket-line-finish.zsh | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 2a5f396..1bdd1f9 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -40,7 +40,7 @@ # Whether the brackets highlighter should be called or not. _zsh_highlight_highlighter_brackets_predicate() { - _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified + [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_cursor_moved || _zsh_highlight_buffer_modified } # Brackets highlighting function. @@ -85,11 +85,13 @@ _zsh_highlight_highlighter_brackets_paint() _zsh_highlight_add_highlight $((pos - 1)) $pos $style done - # If cursor is on a bracket, then highlight corresponding bracket, if any - pos=$((CURSOR + 1)) - if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then - local -i otherpos=$matching[$pos] - _zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket + # If cursor is on a bracket, then highlight corresponding bracket, if any. + if [[ $WIDGET != zle-line-finish ]]; then + pos=$((CURSOR + 1)) + if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then + local -i otherpos=$matching[$pos] + _zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket + fi fi } diff --git a/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh b/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh new file mode 100644 index 0000000..23b317b --- /dev/null +++ b/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +WIDGET=zle-line-finish + +BUFFER=': $foo[bar]' +CURSOR=6 # cursor is zero-based + +expected_region_highlight=( + "11 11 NONE" +) From fdaeec45146b5fe6b2c2b01da6f97681d89f8094 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 8 Sep 2016 19:09:29 +0000 Subject: [PATCH 0423/1080] 'main': Followup to 51614ca2c994: Run cheaper conditions first. This was suggested on #355. --- 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 f6194cf..6df671e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -119,7 +119,7 @@ _zsh_highlight_main__type() { # falling through to the $() below, incurring a fork. (Issue #354.) # # The second disjunct mimics the isrelative() C call from the zsh bug. - elif { is-at-least 5.3 || [[ $1 != */* ]] } && + elif { [[ $1 != */* ]] || is-at-least 5.3 } && ! builtin type -w -- $1 >/dev/null 2>&1; then REPLY=none fi From a8a6384356af7f3ad718acaccbc77128d166eacf Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 03:27:32 +0000 Subject: [PATCH 0424/1080] 'main': Add tests for the IGNORE_BRACES option. Also adds an XFail test for balanced braces for issue #344. --- highlighters/main/test-data/braces1.zsh | 42 +++++++++++++++++++++++++ highlighters/main/test-data/braces2.zsh | 42 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 highlighters/main/test-data/braces1.zsh create mode 100644 highlighters/main/test-data/braces2.zsh diff --git a/highlighters/main/test-data/braces1.zsh b/highlighters/main/test-data/braces1.zsh new file mode 100644 index 0000000..858ade5 --- /dev/null +++ b/highlighters/main/test-data/braces1.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER=$'() { echo }\n}' +# no special setopts + +expected_region_highlight=( + '1 2 reserved-word' # () + '4 4 reserved-word' # { + '6 9 builtin' # echo + '11 11 reserved-word' # } + '12 12 commandseparator' # \n + '13 13 unknown-token "issue #344 (balanced parentheses/braces)"' # } +) diff --git a/highlighters/main/test-data/braces2.zsh b/highlighters/main/test-data/braces2.zsh new file mode 100644 index 0000000..89ba15a --- /dev/null +++ b/highlighters/main/test-data/braces2.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER=$'() { echo }\n}' +setopt ignorebraces + +expected_region_highlight=( + '1 2 reserved-word' # () + '4 4 reserved-word' # { + '6 9 builtin' # echo + '11 11 default "ignore_braces; fixed by next commit"' # } + '12 12 commandseparator' # \n + '13 13 reserved-word' # } +) From 02807f1826a512672764a8658de3b8a67f074c44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 03:38:34 +0000 Subject: [PATCH 0425/1080] 'main': Support the IGNORE_BRACES option. This is related to a future "unbalanced { ( ) }" check for issue #344. --- highlighters/main/main-highlighter.zsh | 20 +++++++++++++++++++- highlighters/main/test-data/braces2.zsh | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6df671e..a010b22 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -162,6 +162,11 @@ _zsh_highlight_highlighter_main_paint() if [[ -o interactive_comments ]]; then local interactive_comments= # set to empty fi + if [[ -o ignore_braces ]] || [[ -o ignore_close_braces ]]; then + local right_brace_is_recognised_everywhere=false + else + local right_brace_is_recognised_everywhere=true + fi if [[ -o path_dirs ]]; then integer path_dirs_was_set=1 else @@ -513,7 +518,18 @@ _zsh_highlight_highlighter_main_paint() else style=reserved-word fi;; - $'\x7d') style=reserved-word;; # block + $'\x7d') # right brace + # + # 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 $right_brace_is_recognised_everywhere; then + style=reserved-word + else + # Fall through to the catchall case at the end. + fi + ;| '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; "'"*) style=single-quoted-argument;; @@ -531,6 +547,8 @@ _zsh_highlight_highlighter_main_paint() [*?]*|*[^\\][*?]*) $highlight_glob && style=globbing || style=default;; *) if false; then + elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then + # was handled by the $'\x7d' case above elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then diff --git a/highlighters/main/test-data/braces2.zsh b/highlighters/main/test-data/braces2.zsh index 89ba15a..adee00b 100644 --- a/highlighters/main/test-data/braces2.zsh +++ b/highlighters/main/test-data/braces2.zsh @@ -36,7 +36,7 @@ expected_region_highlight=( '1 2 reserved-word' # () '4 4 reserved-word' # { '6 9 builtin' # echo - '11 11 default "ignore_braces; fixed by next commit"' # } + '11 11 default' # } '12 12 commandseparator' # \n '13 13 reserved-word' # } ) From 0a9b347483ae653e95ed7ccb147a0db3644b6384 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 04:10:28 +0000 Subject: [PATCH 0426/1080] driver: Warn just once when a highlighter is missing. The heretofore code warned once per keypress. --- zsh-syntax-highlighting.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f9d82de..ec01306 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -92,7 +92,11 @@ _zsh_highlight() typeset -ga ${cache_place} # If highlighter needs to be invoked - if "_zsh_highlight_highlighter_${highlighter}_predicate"; then + if ! type "_zsh_highlight_highlighter_${highlighter}_predicate" >&/dev/null; then + echo "zsh-syntax-highlighting: warning: disabling the ${(qq)highlighter} highlighter as it has not been loaded" >&2 + # TODO: use ${(b)} rather than ${(q)} if supported + ZSH_HIGHLIGHT_HIGHLIGHTERS=( ${ZSH_HIGHLIGHT_HIGHLIGHTERS:#${highlighter}} ) + elif "_zsh_highlight_highlighter_${highlighter}_predicate"; then # save a copy, and cleanup region_highlight region_highlight_copy=("${region_highlight[@]}") From 51b9d79c3bb61d3233a67b440f6ef7899d04b8c9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 04:52:32 +0000 Subject: [PATCH 0427/1080] 'main': Highlight mismatched parentheses and braces. --- highlighters/main/main-highlighter.zsh | 35 ++++++++++++++-- highlighters/main/test-data/braces1.zsh | 2 +- .../main/test-data/brackets-mismatch1.zsh | 40 +++++++++++++++++++ .../main/test-data/brackets-mismatch2.zsh | 40 +++++++++++++++++++ 4 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 highlighters/main/test-data/brackets-mismatch1.zsh create mode 100644 highlighters/main/test-data/brackets-mismatch2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a010b22..99ebe6a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -155,6 +155,20 @@ _zsh_highlight_main__resolve_alias() { 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. +# +# $1: character expected to be at the top of $braces_stack +# $2: assignment to execute it if matches +_zsh_highlight_main__stack_pop() { + if [[ $braces_stack[1] == $1 ]]; then + braces_stack=${braces_stack:1} + eval "$2" + else + style=unknown-token + fi +} + # Main syntax highlighting function. _zsh_highlight_highlighter_main_paint() { @@ -194,6 +208,8 @@ _zsh_highlight_highlighter_main_paint() local buf="$PREBUFFER$BUFFER" integer len="${#buf}" + local braces_stack # "R" for round, "Q" for square, "Y" for curly + if (( path_dirs_was_set )); then options_to_set+=( PATH_DIRS ) fi @@ -418,7 +434,15 @@ _zsh_highlight_highlighter_main_paint() fi } case $res in - reserved) style=reserved-word;; + reserved) # reserved word + style=reserved-word + if [[ $arg == $'\x7b' ]]; then + braces_stack='Y'"$braces_stack" + elif [[ $arg == $'\x7d' ]]; then + # We're at command word, so no need to check $right_brace_is_recognised_everywhere + _zsh_highlight_main__stack_pop 'Y' style=reserved-word + fi + ;; 'suffix alias') style=suffix-alias;; alias) () { integer insane_alias @@ -488,10 +512,13 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style already_added=1 fi - elif [[ $arg == '()' || $arg == $'\x28' ]]; then + elif [[ $arg == '()' ]]; then # anonymous function + style=reserved-word + elif [[ $arg == $'\x28' ]]; then # subshell style=reserved-word + braces_stack='R'"$braces_stack" else if _zsh_highlight_main_highlighter_check_path; then style=$REPLY @@ -516,7 +543,7 @@ _zsh_highlight_highlighter_main_paint() in_array_assignment=false next_word+=':start:' else - style=reserved-word + _zsh_highlight_main__stack_pop 'R' style=reserved-word fi;; $'\x7d') # right brace # @@ -525,7 +552,7 @@ _zsh_highlight_highlighter_main_paint() # Additionally, `tt(})' is recognized in any position if neither the # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.""" if $right_brace_is_recognised_everywhere; then - style=reserved-word + _zsh_highlight_main__stack_pop 'Y' style=reserved-word else # Fall through to the catchall case at the end. fi diff --git a/highlighters/main/test-data/braces1.zsh b/highlighters/main/test-data/braces1.zsh index 858ade5..4b8064b 100644 --- a/highlighters/main/test-data/braces1.zsh +++ b/highlighters/main/test-data/braces1.zsh @@ -38,5 +38,5 @@ expected_region_highlight=( '6 9 builtin' # echo '11 11 reserved-word' # } '12 12 commandseparator' # \n - '13 13 unknown-token "issue #344 (balanced parentheses/braces)"' # } + '13 13 unknown-token' # } ) diff --git a/highlighters/main/test-data/brackets-mismatch1.zsh b/highlighters/main/test-data/brackets-mismatch1.zsh new file mode 100644 index 0000000..b9fd02a --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch1.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='() { echo foo )' + +expected_region_highlight=( + '1 2 reserved-word' # () + '4 4 reserved-word' # { + '6 9 builtin' # echo + '11 13 default' # foo + '15 15 unknown-token' # ) +) diff --git a/highlighters/main/test-data/brackets-mismatch2.zsh b/highlighters/main/test-data/brackets-mismatch2.zsh new file mode 100644 index 0000000..ae74a3b --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch2.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='() ( echo foo }' + +expected_region_highlight=( + '1 2 reserved-word' # () + '4 4 reserved-word' # ( + '6 9 builtin' # echo + '11 13 default' # foo + '15 15 unknown-token' # } +) From 2fabf7ca64b77ddcbbcb1aba76c9d52ccfc7ef41 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 05:58:08 +0000 Subject: [PATCH 0428/1080] 'main': More tests for mismstached parentheses and braces. --- .../main/test-data/brackets-mismatch3.zsh | 37 +++++++++++++++++++ .../main/test-data/brackets-mismatch4.zsh | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 highlighters/main/test-data/brackets-mismatch3.zsh create mode 100644 highlighters/main/test-data/brackets-mismatch4.zsh diff --git a/highlighters/main/test-data/brackets-mismatch3.zsh b/highlighters/main/test-data/brackets-mismatch3.zsh new file mode 100644 index 0000000..497e435 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch3.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='echo )' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 6 unknown-token' # ) +) diff --git a/highlighters/main/test-data/brackets-mismatch4.zsh b/highlighters/main/test-data/brackets-mismatch4.zsh new file mode 100644 index 0000000..d3a99b0 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch4.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='echo }' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 6 unknown-token' # } +) From 6f91850a01e17c3215ca0873582b3b726efe6abd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 17:56:00 +0000 Subject: [PATCH 0429/1080] 'main': Highlight first command word in named functions defined in the sh syntax when MULTI_FUNC_DEF is set. Fixes a subset of issue #237. --- highlighters/main/main-highlighter.zsh | 12 +++++ .../main/test-data/function-named1.zsh | 45 +++++++++++++++++++ .../main/test-data/function-named2.zsh | 40 +++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 highlighters/main/test-data/function-named1.zsh create mode 100644 highlighters/main/test-data/function-named2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 99ebe6a..50408a0 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -186,6 +186,11 @@ _zsh_highlight_highlighter_main_paint() else integer path_dirs_was_set=0 fi + if [[ -o multi_func_def ]]; then + integer multi_func_def=1 + else + integer multi_func_def=0 + fi emulate -L zsh setopt localoptions extendedglob bareglobqual @@ -545,6 +550,13 @@ _zsh_highlight_highlighter_main_paint() else _zsh_highlight_main__stack_pop 'R' style=reserved-word fi;; + $'\x28\x29') # possibly a function definition + if (( multi_func_def )) || false # TODO: or if the previous word was a command word + then + next_word+=':start:' + fi + style=reserved-word + ;; $'\x7d') # right brace # # Parsing rule: # { diff --git a/highlighters/main/test-data/function-named1.zsh b/highlighters/main/test-data/function-named1.zsh new file mode 100644 index 0000000..30a0e23 --- /dev/null +++ b/highlighters/main/test-data/function-named1.zsh @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='f() pwd; f() { balanced braces }' + +expected_region_highlight=( + '1 1 TBD "issue #223"' # f + '2 3 reserved-word' # () + '5 7 builtin' # pwd + '8 8 commandseparator' # ; + '10 10 TBD "issue #223"' # f + '11 12 reserved-word' # () + '14 14 reserved-word' # { + '16 23 unknown-token' # balanced + '25 30 default' # braces + '32 32 reserved-word' # } +) diff --git a/highlighters/main/test-data/function-named2.zsh b/highlighters/main/test-data/function-named2.zsh new file mode 100644 index 0000000..4a29587 --- /dev/null +++ b/highlighters/main/test-data/function-named2.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER='f g h () pwd' + +expected_region_highlight=( + '1 1 TBD "issue #223"' # f + '3 3 TBD "issue #223"' # g + '5 5 TBD "issue #223"' # h + '7 8 reserved-word' # () + '10 12 builtin' # pwd +) From e15a09840ea537b3b41efaae940ad022662db75d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 22 Sep 2016 21:22:57 +0000 Subject: [PATCH 0430/1080] dev tools: Automate a recurring step: Set year correctly for new tests. --- tests/generate.zsh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 3eee487..4b21587 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -40,8 +40,10 @@ if (( $# != 3 )) || [[ $1 == -* ]]; then fi buffer=$1 ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) -exec >${0:A:h:h}/highlighters/$2/test-data/$3.zsh -git add -N ${0:A:h:h}/highlighters/$2/test-data/$3.zsh +fname=${0:A:h:h}/highlighters/$2/test-data/$3.zsh +exec 3>&1 +exec >$fname +git add -N $fname # Load the main script. . ${0:A:h:h}/zsh-syntax-highlighting.zsh @@ -85,3 +87,10 @@ print 'expected_region_highlight=(' done } print ')' + +exec >&3 +year="`LC_ALL=C date +%Y`" +if read -q "?Set copyright year to $year? "; then + <$fname >$fname.t sed s/YYYY/$year/ && + mv $fname.t $fname +fi From a4196eda5e6fea29bf3cc70a17bf3bd2dd2eea95 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 23 Sep 2016 15:55:06 +0000 Subject: [PATCH 0431/1080] 'main': Restore compatibility with zsh-4.3.14 and older (after e3182c18de8f). Fixes #368. --- 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 50408a0..af0ee67 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -176,7 +176,7 @@ _zsh_highlight_highlighter_main_paint() if [[ -o interactive_comments ]]; then local interactive_comments= # set to empty fi - if [[ -o ignore_braces ]] || [[ -o ignore_close_braces ]]; then + if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then local right_brace_is_recognised_everywhere=false else local right_brace_is_recognised_everywhere=true From 987c13348693db2e33184d688b6e732532147f8d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Sep 2016 17:06:21 +0000 Subject: [PATCH 0432/1080] dev tools: Tolerate invalid input. --- tests/generate.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 4b21587..e0a06da 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -40,7 +40,7 @@ if (( $# != 3 )) || [[ $1 == -* ]]; then fi buffer=$1 ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) -fname=${0:A:h:h}/highlighters/$2/test-data/$3.zsh +fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh exec 3>&1 exec >$fname git add -N $fname From 5627fd2045c773a61d672151b489612539d4eab1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Sep 2016 17:07:01 +0000 Subject: [PATCH 0433/1080] dev tools: Stage the copyright block to make diffs smaller. --- tests/generate.zsh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index e0a06da..f6c32d6 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -41,9 +41,6 @@ fi buffer=$1 ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 ) fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh -exec 3>&1 -exec >$fname -git add -N $fname # Load the main script. . ${0:A:h:h}/zsh-syntax-highlighting.zsh @@ -54,9 +51,17 @@ _zsh_highlight_add_highlight() region_highlight+=("$1 $2 $3") } + # Copyright block -<$0 sed -n -e '1,/^$/p' | sed -e 's/2[0-9][0-9][0-9]/YYYY/' +year="`LC_ALL=C date +%Y`" +if ! read -q "?Set copyright year to $year? "; then + year="YYYY" +fi +exec >$fname +<$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" echo "" +# Assumes stdout is line-buffered +git add -- $fname # Buffer print -n 'BUFFER=' @@ -87,10 +92,3 @@ print 'expected_region_highlight=(' done } print ')' - -exec >&3 -year="`LC_ALL=C date +%Y`" -if read -q "?Set copyright year to $year? "; then - <$fname >$fname.t sed s/YYYY/$year/ && - mv $fname.t $fname -fi From 8bf423d16d463fa5fe6fe69cecd2297a8fdbeed7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 24 Sep 2016 17:55:18 +0000 Subject: [PATCH 0434/1080] 'main': Don't find command positions within multiline array literals. Fixes #333. --- highlighters/main/main-highlighter.zsh | 9 ++++- .../test-data/multiline-array-assignment1.zsh | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/multiline-array-assignment1.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index af0ee67..993a716 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -613,8 +613,13 @@ _zsh_highlight_highlighter_main_paint() [[ $style == path || $style == path_prefix ]] && _zsh_highlight_main_highlighter_highlight_path_separators fi if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - next_word=':start:' - highlight_glob=true + if [[ $arg == ';' ]] && $in_array_assignment; then + # literal newline inside an array assignment + next_word=':regular:' + else + next_word=':start:' + highlight_glob=true + fi elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] || [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then diff --git a/highlighters/main/test-data/multiline-array-assignment1.zsh b/highlighters/main/test-data/multiline-array-assignment1.zsh new file mode 100644 index 0000000..662e0f3 --- /dev/null +++ b/highlighters/main/test-data/multiline-array-assignment1.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +BUFFER=$'foo=(\nbar) env' + +expected_region_highlight=( + '1 5 assign' # foo=( + '6 6 commandseparator' # \n + '7 9 default' # bar + '10 10 assign' # ) + '12 14 command' # env +) From e5782e4ddfb6dbf5d5b12cb7352b3d955260e9b3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 07:56:28 +0000 Subject: [PATCH 0435/1080] 'main': Highlight 'always' blocks. Fixes #335. --- highlighters/main/main-highlighter.zsh | 13 +++++++- highlighters/main/test-data/always1.zsh | 41 +++++++++++++++++++++++ highlighters/main/test-data/always2.zsh | 43 +++++++++++++++++++++++++ highlighters/main/test-data/always3.zsh | 43 +++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/always1.zsh create mode 100644 highlighters/main/test-data/always2.zsh create mode 100644 highlighters/main/test-data/always3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 993a716..07049a9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -260,6 +260,7 @@ _zsh_highlight_highlighter_main_paint() # words) but not in "-ufoo" (one word). # - :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. # # 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 @@ -408,7 +409,11 @@ _zsh_highlight_highlighter_main_paint() fi # The Great Fork: is this a command word? Is this a non-command word? - if [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word + if [[ $this_word == *':always:'* && $arg == 'always' ]]; then + # try-always construct + style=reserved-word # de facto a reserved word, although not de jure + next_word=':start:' + elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=precommand elif [[ "$arg" = "sudo" ]]; then @@ -446,6 +451,9 @@ _zsh_highlight_highlighter_main_paint() elif [[ $arg == $'\x7d' ]]; then # We're at command word, so no need to check $right_brace_is_recognised_everywhere _zsh_highlight_main__stack_pop 'Y' style=reserved-word + if [[ $style == reserved-word ]]; then + next_word+=':always:' + fi fi ;; 'suffix alias') style=suffix-alias;; @@ -565,6 +573,9 @@ _zsh_highlight_highlighter_main_paint() # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.""" if $right_brace_is_recognised_everywhere; then _zsh_highlight_main__stack_pop 'Y' style=reserved-word + if [[ $style == reserved-word ]]; then + next_word+=':always:' + fi else # Fall through to the catchall case at the end. fi diff --git a/highlighters/main/test-data/always1.zsh b/highlighters/main/test-data/always1.zsh new file mode 100644 index 0000000..ae40a72 --- /dev/null +++ b/highlighters/main/test-data/always1.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='{ ls } always { pwd }' + +expected_region_highlight=( + '1 1 reserved-word' # { + '3 4 command' # ls + '6 6 reserved-word' # } + '8 13 reserved-word' # always + '15 15 reserved-word' # { + '17 19 builtin' # pwd + '21 21 reserved-word' # } +) diff --git a/highlighters/main/test-data/always2.zsh b/highlighters/main/test-data/always2.zsh new file mode 100644 index 0000000..f5852c6 --- /dev/null +++ b/highlighters/main/test-data/always2.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=$'{\nls\n} always { pwd }' + +expected_region_highlight=( + '1 1 reserved-word' # { + '2 2 unknown-token' # \n + '3 4 command' # ls + '5 5 commandseparator' # \n + '6 6 reserved-word' # } + '8 13 reserved-word' # always + '15 15 reserved-word' # { + '17 19 builtin' # pwd + '21 21 reserved-word' # } +) diff --git a/highlighters/main/test-data/always3.zsh b/highlighters/main/test-data/always3.zsh new file mode 100644 index 0000000..d41beeb --- /dev/null +++ b/highlighters/main/test-data/always3.zsh @@ -0,0 +1,43 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +setopt ignorebraces +BUFFER='echo { foo } always { bar }' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 6 default' # { + '8 10 default' # foo + '12 12 default' # } + '14 19 default' # always + '21 21 default' # { + '23 25 default' # bar + '27 27 default' # } +) From a053768627fd2b552a96c38505e3e30a8cb93792 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 08:08:45 +0000 Subject: [PATCH 0436/1080] dev tools: Remove a superfluous empty line. --- highlighters/main/test-data/braces1.zsh | 1 - highlighters/main/test-data/braces2.zsh | 1 - highlighters/main/test-data/brackets-mismatch1.zsh | 1 - highlighters/main/test-data/brackets-mismatch2.zsh | 1 - highlighters/main/test-data/brackets-mismatch3.zsh | 1 - highlighters/main/test-data/brackets-mismatch4.zsh | 1 - highlighters/main/test-data/function-named1.zsh | 1 - highlighters/main/test-data/function-named2.zsh | 1 - highlighters/main/test-data/multiline-array-assignment1.zsh | 1 - tests/generate.zsh | 1 - 10 files changed, 10 deletions(-) diff --git a/highlighters/main/test-data/braces1.zsh b/highlighters/main/test-data/braces1.zsh index 4b8064b..3c5b1f0 100644 --- a/highlighters/main/test-data/braces1.zsh +++ b/highlighters/main/test-data/braces1.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER=$'() { echo }\n}' # no special setopts diff --git a/highlighters/main/test-data/braces2.zsh b/highlighters/main/test-data/braces2.zsh index adee00b..a3ea7c9 100644 --- a/highlighters/main/test-data/braces2.zsh +++ b/highlighters/main/test-data/braces2.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER=$'() { echo }\n}' setopt ignorebraces diff --git a/highlighters/main/test-data/brackets-mismatch1.zsh b/highlighters/main/test-data/brackets-mismatch1.zsh index b9fd02a..5e6e80f 100644 --- a/highlighters/main/test-data/brackets-mismatch1.zsh +++ b/highlighters/main/test-data/brackets-mismatch1.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='() { echo foo )' expected_region_highlight=( diff --git a/highlighters/main/test-data/brackets-mismatch2.zsh b/highlighters/main/test-data/brackets-mismatch2.zsh index ae74a3b..2d98ac2 100644 --- a/highlighters/main/test-data/brackets-mismatch2.zsh +++ b/highlighters/main/test-data/brackets-mismatch2.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='() ( echo foo }' expected_region_highlight=( diff --git a/highlighters/main/test-data/brackets-mismatch3.zsh b/highlighters/main/test-data/brackets-mismatch3.zsh index 497e435..e33040a 100644 --- a/highlighters/main/test-data/brackets-mismatch3.zsh +++ b/highlighters/main/test-data/brackets-mismatch3.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='echo )' expected_region_highlight=( diff --git a/highlighters/main/test-data/brackets-mismatch4.zsh b/highlighters/main/test-data/brackets-mismatch4.zsh index d3a99b0..a9b15dc 100644 --- a/highlighters/main/test-data/brackets-mismatch4.zsh +++ b/highlighters/main/test-data/brackets-mismatch4.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='echo }' expected_region_highlight=( diff --git a/highlighters/main/test-data/function-named1.zsh b/highlighters/main/test-data/function-named1.zsh index 30a0e23..c962ddb 100644 --- a/highlighters/main/test-data/function-named1.zsh +++ b/highlighters/main/test-data/function-named1.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='f() pwd; f() { balanced braces }' expected_region_highlight=( diff --git a/highlighters/main/test-data/function-named2.zsh b/highlighters/main/test-data/function-named2.zsh index 4a29587..e12fce6 100644 --- a/highlighters/main/test-data/function-named2.zsh +++ b/highlighters/main/test-data/function-named2.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER='f g h () pwd' expected_region_highlight=( diff --git a/highlighters/main/test-data/multiline-array-assignment1.zsh b/highlighters/main/test-data/multiline-array-assignment1.zsh index 662e0f3..3734c7a 100644 --- a/highlighters/main/test-data/multiline-array-assignment1.zsh +++ b/highlighters/main/test-data/multiline-array-assignment1.zsh @@ -28,7 +28,6 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- - BUFFER=$'foo=(\nbar) env' expected_region_highlight=( diff --git a/tests/generate.zsh b/tests/generate.zsh index f6c32d6..e3f8f9d 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -59,7 +59,6 @@ if ! read -q "?Set copyright year to $year? "; then fi exec >$fname <$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/" -echo "" # Assumes stdout is line-buffered git add -- $fname From c6b6513ac0d61602a3fec196d26579070454b31c Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sun, 25 Sep 2016 12:24:40 +0200 Subject: [PATCH 0437/1080] 'main' / *_check_path: Precompute $#BUFFER and use it for speed gain Running main highlighter on itself (both runs are on the optimized version): - clean (8 runs, last 3 noted): 1.7007670000 1.7330720000 1.7038810000 - optimized (8 runs, last 3 noted): 1.5007230000 1.5142960000 1.4973320000 Average difference: 0.208456 When parsing main-highlighter with itself, the *_check_path function is called 426 times. Note that there are 686 region_highlight resulting entries. --- 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 07049a9..e842128 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -212,6 +212,7 @@ _zsh_highlight_highlighter_main_paint() local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" integer len="${#buf}" + integer pure_buf_len=$(( len - ${#PREBUFFER} )) # == $#BUFFER, used e.g. in *_check_path local braces_stack # "R" for round, "Q" for square, "Y" for curly @@ -701,7 +702,7 @@ _zsh_highlight_main_highlighter_check_path() [[ ! -d ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. - if [[ ${BUFFER[1]} != "-" && ${#BUFFER} == $end_pos ]] && + if [[ ${BUFFER[1]} != "-" && $pure_buf_len == $end_pos ]] && [[ $WIDGET != zle-line-finish ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) From 2755438e80bbe5572db7ef8062163bcda6eb80fc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 09:20:40 +0000 Subject: [PATCH 0438/1080] 'main': Yet another test for mismatched braces. --- .../main/test-data/brackets-mismatch5.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/brackets-mismatch5.zsh diff --git a/highlighters/main/test-data/brackets-mismatch5.zsh b/highlighters/main/test-data/brackets-mismatch5.zsh new file mode 100644 index 0000000..21e8bb2 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch5.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo { }' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 6 default' # { + '8 8 unknown-token' # } +) From b2733a64da9388d8f9254f205c664a9872006856 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 09:20:40 +0000 Subject: [PATCH 0439/1080] 'main': Highlight mismatched do/done. --- highlighters/main/main-highlighter.zsh | 33 ++++++++++----- .../main/test-data/brackets-mismatch6.zsh | 40 +++++++++++++++++++ 2 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 highlighters/main/test-data/brackets-mismatch6.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e842128..e08bce1 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -214,7 +214,11 @@ _zsh_highlight_highlighter_main_paint() integer len="${#buf}" integer pure_buf_len=$(( len - ${#PREBUFFER} )) # == $#BUFFER, used e.g. in *_check_path - local braces_stack # "R" for round, "Q" for square, "Y" for curly + # "R" for round + # "Q" for square + # "Y" for curly + # "D" for do/done + local braces_stack if (( path_dirs_was_set )); then options_to_set+=( PATH_DIRS ) @@ -447,15 +451,24 @@ _zsh_highlight_highlighter_main_paint() case $res in reserved) # reserved word style=reserved-word - if [[ $arg == $'\x7b' ]]; then - braces_stack='Y'"$braces_stack" - elif [[ $arg == $'\x7d' ]]; then - # We're at command word, so no need to check $right_brace_is_recognised_everywhere - _zsh_highlight_main__stack_pop 'Y' style=reserved-word - if [[ $style == reserved-word ]]; then - next_word+=':always:' - fi - fi + case $arg in + ($'\x7b') + braces_stack='Y'"$braces_stack" + ;; + ($'\x7d') + # We're at command word, so no need to check $right_brace_is_recognised_everywhere + _zsh_highlight_main__stack_pop 'Y' style=reserved-word + if [[ $style == reserved-word ]]; then + next_word+=':always:' + fi + ;; + ('do') + braces_stack='D'"$braces_stack" + ;; + ('done') + _zsh_highlight_main__stack_pop 'D' style=reserved-word + ;; + esac ;; 'suffix alias') style=suffix-alias;; alias) () { diff --git a/highlighters/main/test-data/brackets-mismatch6.zsh b/highlighters/main/test-data/brackets-mismatch6.zsh new file mode 100644 index 0000000..9df8388 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch6.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='(repeat 1; do)' + +expected_region_highlight=( + '1 1 reserved-word' # ( + '2 7 reserved-word' # repeat + '9 9 default' # 1 + '10 10 commandseparator' # ; + '12 13 reserved-word' # do + '14 14 unknown-token' # ) +) From a2876fb57dfdd53930667736300bd00eb5bd9b89 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 11:38:43 +0000 Subject: [PATCH 0440/1080] dev tools: Add a TODO to introduce code reuse. --- tests/generate.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/generate.zsh b/tests/generate.zsh index e3f8f9d..0f515d8 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -77,6 +77,7 @@ print 'expected_region_highlight=(' PREBUFFER="" BUFFER="$buffer" region_highlight=() + # TODO: use run_test() from tests/test-highlighting.zsh (to get a tempdir) _zsh_highlight for ((i=1; i<=${#region_highlight}; i++)); do From 2bb8f0703d8f3f976177493979f8e8efdf9aae58 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 09:20:40 +0000 Subject: [PATCH 0441/1080] 'main': Highlight mismatched foreach/end. Fixes #96. --- highlighters/main/main-highlighter.zsh | 7 +++ .../main/test-data/brackets-mismatch7.zsh | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 highlighters/main/test-data/brackets-mismatch7.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e08bce1..1bcac2a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -218,6 +218,7 @@ _zsh_highlight_highlighter_main_paint() # "Q" for square # "Y" for curly # "D" for do/done + # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) local braces_stack if (( path_dirs_was_set )); then @@ -468,6 +469,12 @@ _zsh_highlight_highlighter_main_paint() ('done') _zsh_highlight_main__stack_pop 'D' style=reserved-word ;; + ('foreach') + braces_stack='$'"$braces_stack" + ;; + ('end') + _zsh_highlight_main__stack_pop '$' style=reserved-word + ;; esac ;; 'suffix alias') style=suffix-alias;; diff --git a/highlighters/main/test-data/brackets-mismatch7.zsh b/highlighters/main/test-data/brackets-mismatch7.zsh new file mode 100644 index 0000000..27d5920 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch7.zsh @@ -0,0 +1,44 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2012 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 n in *; do echo $n; end' + +expected_region_highlight=( + '1 3 reserved-word' # for + '5 5 default' # n + '7 8 default' # in + '10 10 globbing' # * + '11 11 commandseparator' # ; + '13 14 reserved-word' # do + '16 19 builtin' # echo + '21 22 default' # $n + '23 23 commandseparator' # ; + '25 27 unknown-token' # end +) From 4fc35362ee5a48b587184efd265d2df4b3dbbcaf Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 12:06:39 +0000 Subject: [PATCH 0442/1080] 'main': Permit subshells to end at command position. Fixes #344. --- highlighters/main/main-highlighter.zsh | 3 ++ .../main/test-data/brackets-mismatch8.zsh | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 highlighters/main/test-data/brackets-mismatch8.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1bcac2a..92767a6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -553,6 +553,9 @@ _zsh_highlight_highlighter_main_paint() # subshell style=reserved-word braces_stack='R'"$braces_stack" + elif [[ $arg == $'\x29' ]]; then + # end of subshell + _zsh_highlight_main__stack_pop 'R' style=reserved-word else if _zsh_highlight_main_highlighter_check_path; then style=$REPLY diff --git a/highlighters/main/test-data/brackets-mismatch8.zsh b/highlighters/main/test-data/brackets-mismatch8.zsh new file mode 100644 index 0000000..07a42e3 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch8.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='(ls&)' + +expected_region_highlight=( + '1 1 reserved-word' # ( + '2 3 command' # ls + '4 4 commandseparator' # & + '5 5 reserved-word' # ) +) From c3913e0d8eadfa85e9cb1b4138d4fee7c7b486ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 14:31:31 +0000 Subject: [PATCH 0443/1080] 'main': Highlight command substitutions inside double quotes. Part of issue #139. --- highlighters/main/main-highlighter.zsh | 2 ++ highlighters/main/test-data/dollar-paren.zsh | 38 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/dollar-paren.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 92767a6..544550b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -756,6 +756,8 @@ _zsh_highlight_main_highlighter_highlight_string() elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then (( k += $#MATCH )) # highlight the parameter name and braces (( i += $#MATCH )) # skip past it + elif [[ $arg[i+1] == $'\x28' ]]; then + # Highlight just the '$'. else continue fi diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh new file mode 100644 index 0000000..354daa0 --- /dev/null +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=': "$(:)"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 double-quoted-argument' # " + '4 4 dollar-double-quoted-argument' # $ + '5 8 double-quoted-argument' # (:)" +) From 4afe670f7a1b9f38e417eaeeefdf2ea4021c6728 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 14:35:16 +0000 Subject: [PATCH 0444/1080] 'main': Highlight shell's PID ($$) inside double quotes. --- highlighters/main/main-highlighter.zsh | 4 ++ highlighters/main/test-data/dollar-dollar.zsh | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 highlighters/main/test-data/dollar-dollar.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 544550b..c08a6d9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -756,6 +756,10 @@ _zsh_highlight_main_highlighter_highlight_string() elif [[ ${arg:$i} =~ ^[{]([A-Za-z_][A-Za-z0-9_]*|[0-9]+)[}] ]] ; then (( k += $#MATCH )) # highlight the parameter name and braces (( i += $#MATCH )) # skip past it + elif [[ $arg[i+1] == '$' ]]; then + # $$ - pid + (( 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 # Highlight just the '$'. else diff --git a/highlighters/main/test-data/dollar-dollar.zsh b/highlighters/main/test-data/dollar-dollar.zsh new file mode 100644 index 0000000..79d7f7d --- /dev/null +++ b/highlighters/main/test-data/dollar-dollar.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=': "$$ $$foo"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 double-quoted-argument' # " + '4 5 dollar-double-quoted-argument' # $$ + '7 8 dollar-double-quoted-argument' # $$ + '9 12 double-quoted-argument' # foo" +) From 44ef6e38e5a7f99defdbd3e65c5ffb79fd9eaf3e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 14:51:02 +0000 Subject: [PATCH 0445/1080] 'main': Highlight several more special (non-alphabetic) parameters. --- highlighters/main/main-highlighter.zsh | 4 ++ highlighters/main/test-data/dollar-noise.zsh | 46 ++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 highlighters/main/test-data/dollar-noise.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c08a6d9..7cdfa76 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -760,6 +760,10 @@ _zsh_highlight_main_highlighter_highlight_string() # $$ - pid (( k += 1 )) # highlight both dollar signs (( i += 1 )) # don't consider the second one as introducing another parameter expansion + elif [[ $arg[i+1] == [-#*@?] ]]; then + # $#, $*, $@, $?, $- - 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 # Highlight just the '$'. else diff --git a/highlighters/main/test-data/dollar-noise.zsh b/highlighters/main/test-data/dollar-noise.zsh new file mode 100644 index 0000000..e900b02 --- /dev/null +++ b/highlighters/main/test-data/dollar-noise.zsh @@ -0,0 +1,46 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=': "$- $# $* $@ $?"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 double-quoted-argument' # " + '4 5 dollar-double-quoted-argument' # $- + '6 6 double-quoted-argument' # + '7 8 dollar-double-quoted-argument' # $# + '9 9 double-quoted-argument' # + '10 11 dollar-double-quoted-argument' # $* + '12 12 double-quoted-argument' # + '13 14 dollar-double-quoted-argument' # $@ + '15 15 double-quoted-argument' # + '16 17 dollar-double-quoted-argument' # $? + '18 18 double-quoted-argument' # " +) From 15461e7d21c3b868e1aff89521fbd20732ec157f Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sun, 25 Sep 2016 17:26:37 +0200 Subject: [PATCH 0446/1080] 'main': Directly count spaces to skip, don't leverage proc_buf length Main highlighter run on itself, on the optimized version: - optimized (8 runs, 3 last noted): 1.1201650000 1.1074430000 1.1263810000 - unoptimized (8 runs, 3 last noted): 1.5746400000 1.5115250000 1.5155440000 Average difference: 0.415907 --- highlighters/main/main-highlighter.zsh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e842128..f599a0b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -251,6 +251,8 @@ _zsh_highlight_highlighter_main_paint() '!' # reserved word; unrelated to $histchars[1] ) + local -a match mbegin mend + # State machine # # The states are: @@ -339,7 +341,22 @@ _zsh_highlight_highlighter_main_paint() (( start_pos += offset )) (( end_pos = start_pos + $#arg )) else - integer offset=$(((len-start_pos)-${#${proc_buf##([[:space:]]|\\[[:space:]])#}})) + # 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:]]|\\[[:space:]])##)* ]]; then + # The first, outer parenthesis + integer offset="${#match[1]}" + else + integer offset=0 + fi ((start_pos+=offset)) ((end_pos=$start_pos+${#arg})) fi From 79198759b3121b5f69beb81fbffe264a19420105 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 18:08:36 +0000 Subject: [PATCH 0447/1080] tests: Also test arguments to an anonymous function. --- highlighters/main/test-data/anonymous-function.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index a6fbcf0..5b8e0b6 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='() echo hello; () { echo world }' +BUFFER='() echo hello; () { echo world } "argument"' expected_region_highlight=( "1 2 reserved-word" # () @@ -37,4 +37,5 @@ expected_region_highlight=( "16 17 reserved-word" # () "19 19 reserved-word" # { "21 24 builtin" # echo + "34 43 double-quoted-argument" # "argument" ) From 2b303f01b696c4538e9a7fc862c6340400bc3273 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 25 Sep 2016 08:01:54 +0000 Subject: [PATCH 0448/1080] dev tools: Automagically handle newlines (\n) in $BUFFER. --- tests/generate.zsh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/generate.zsh b/tests/generate.zsh index 0f515d8..64a1ede 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -29,6 +29,7 @@ # ------------------------------------------------------------------------------------------------- emulate -LR zsh +setopt localoptions extendedglob # Argument parsing. if (( $# != 3 )) || [[ $1 == -* ]]; then @@ -64,7 +65,11 @@ git add -- $fname # Buffer print -n 'BUFFER=' -print -r -- ${(qq)buffer} +if [[ $buffer != (#s)[$'\t -~']#(#e) ]]; then + print -r -- ${(qqqq)buffer} +else + print -r -- ${(qq)buffer} +fi echo "" # Expectations @@ -88,7 +93,7 @@ print 'expected_region_highlight=(' (( --end )) # convert to closed range, like expected_region_highlight (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed fi - printf " %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} $BUFFER[start,end] + printf " %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} ${${(qqqq)BUFFER[start,end]}[3,-2]} done } print ')' From b4537a972eedb920fc61cabb359afd3ec7ea4b34 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 17:24:58 +0000 Subject: [PATCH 0449/1080] 'main': Set fallback style for the 'arg0' style. The fallback style name uses '_' in anticipation of a future auto-fallback feature keyed on style names. 'arg0' was previously known as 'commandtypefromthefuture'. --- docs/highlighters/main.md | 23 +++++++++++++++++++++++ highlighters/main/main-highlighter.zsh | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 4793fed..bf83820 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -44,6 +44,7 @@ This highlighter defines the following styles: * `assign` - parameter assignments * `redirection` - redirection operators (`<`, `>`, etc) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) +* `arg0` - a command word other than one of those enumrated above (other than a command, precommand, alias, function, or shell builtin command). * `default` - everything else To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, @@ -65,4 +66,26 @@ 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)` manual page][zshzle-Character-Highlighting]. +### Useless trivia + +#### Forward compatibility. + +zsh-syntax-highlighting attempts to be forward-compatible with zsh. +Specifically, we attempt to facilitate highlighting _command word_ types that +had not yet been invented when this version of zsh-syntax-highlighting was +released. + +A _command word_ is something like a function name, external command name, et +cetera. (See +[Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines] +for a formal definition.) + +If a new _kind_ of command word is ever added to zsh — something conceptually +different than "function" and "alias" and "external command" — then command words +of that (new) kind will be highlighted by the style `arg0_$kind`, +where `$kind` is the output of `type -w` on the new kind of command word. If that +style is not defined, then the style `arg0` will be used instead. + +[zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines + [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a810eff..095a8fd 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[arg0]:=fg=green} # Whether the highlighter should be called or not. _zsh_highlight_main_highlighter_predicate() @@ -488,7 +489,7 @@ _zsh_highlight_main_highlighter() fi fi ;; - *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos commandtypefromthefuture-$res + *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res arg0 already_added=1 ;; esac From bccc3dc26943949e5b2f9525e6827440507b03ac Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 20 Aug 2016 09:31:13 +0000 Subject: [PATCH 0450/1080] 'main': Enable fallback to the 'arg0' style. --- highlighters/main/main-highlighter.zsh | 33 +++++++++++++---- highlighters/main/test-data/inheritance.zsh | 40 +++++++++++++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 highlighters/main/test-data/inheritance.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 095a8fd..9c7fb12 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -32,17 +32,11 @@ : ${ZSH_HIGHLIGHT_STYLES[default]:=none} : ${ZSH_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold} : ${ZSH_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow} -: ${ZSH_HIGHLIGHT_STYLES[alias]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[suffix-alias]:=fg=green,underline} -: ${ZSH_HIGHLIGHT_STYLES[builtin]:=fg=green} -: ${ZSH_HIGHLIGHT_STYLES[function]:=fg=green} -: ${ZSH_HIGHLIGHT_STYLES[command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[precommand]:=fg=green,underline} : ${ZSH_HIGHLIGHT_STYLES[commandseparator]:=none} -: ${ZSH_HIGHLIGHT_STYLES[hashed-command]:=fg=green} : ${ZSH_HIGHLIGHT_STYLES[path]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_pathseparator]:=} -: ${ZSH_HIGHLIGHT_STYLES[path_prefix]:=underline} : ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} @@ -72,6 +66,33 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 + if (( $+argv[2] )); then + # Caller specified inheritance explicitly. + else + # Automate inheritance. + typeset -A fallback_of; fallback_of=( + alias arg0 + suffix-alias arg0 + builtin arg0 + function arg0 + command arg0 + precommand arg0 + hashed-command arg0 + + path_prefix path + # The path separator fallback won't ever be used, due to the optimisation + # in _zsh_highlight_main_highlighter_highlight_path_separators(). + path_pathseparator path + path_prefix_pathseparator path_prefix + ) + local needle=$1 value + while [[ -n ${value::=$fallback_of[$needle]} ]]; do + unset "fallback_of[$needle]" # paranoia against infinite loops + argv+=($value) + needle=$value + done + fi + # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # relative to $BUFFER. (( start -= $#PREBUFFER )) diff --git a/highlighters/main/test-data/inheritance.zsh b/highlighters/main/test-data/inheritance.zsh new file mode 100644 index 0000000..e851ca3 --- /dev/null +++ b/highlighters/main/test-data/inheritance.zsh @@ -0,0 +1,40 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +_zsh_highlight_add_highlight() +{ + region_highlight+=("$1 $2 ${(j.,.)argv[3,-1]}") +} + +BUFFER='type' + +expected_region_highlight=( + '1 4 builtin,arg0' # type +) From 7d38d07255e4fc6330456047823eb180ec60fff6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 20:46:46 +0000 Subject: [PATCH 0451/1080] 'main': Followup to fdaeec45146b: Update comment. That revision was itself a followup to 51614ca2c994. --- 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 f7aa2a9..1bbc3cb 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -140,7 +140,7 @@ _zsh_highlight_main__type() { # exists and is in $PATH). Avoid triggering the bug, at the expense of # falling through to the $() below, incurring a fork. (Issue #354.) # - # The second disjunct mimics the isrelative() C call from the zsh bug. + # 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 REPLY=none From 56e4c38ab46f5b541636a5f08f8c6eb2b63beb7c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 23:41:59 +0000 Subject: [PATCH 0452/1080] changelog: Start 0.5.0 section. Update through bc7f8ea433ad. --- changelog.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 94cb929..8cbf797 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,63 @@ -up to 952a97dbc99a54bd86141b7a57625e748941a937 + 0.4.1 +up to bc7f8ea433ad +# Changes in version 0.5.0 + + +## Added highlighting of: + +- 'pkexec' (a precommand). + (#248, 4f3910cbbaa5) + +- Aliases that cannot be defined normally nor invoked normally (highlighted as an error) + (#263 (in part), 28932316cca6) + + +## Fixed highlighting of: + +- Command separator tokens in syntactically-invalid positions. + (09c4114eb980) + +- Redirections with a file descriptor number at command word. + (#238 (in part), 73ee7c1f6c4a) + +- The `select` prompt, `$PS3`. + (#268, 451665cb2a8b) + +- Values of variables in `vared`. + (e500ca246286) + +- `!` as an argument (neither a history expansion nor a reserved word). + (4c23a2fd1b90) + + +## API changes (for highlighter authors): + +## Developer-visible changes: + +- Add `make quiet-test`. + (9b64ad750f35) + +- test harness: Better quote replaceables in error messages. + (30d8f92df225) + + +## Other changes: + +- Under zsh≤5.2, widgets whose names start with a `_` are no longer excluded + from highlighting. + (ed33d2cb1388; reverts part of 186d80054a40 which was for #65) + +- Under zsh≤5.2, widgets implemented by a function named after the widget are + no longer excluded from highlighting. + (487b122c480d; reverts part of 776453cb5b692) + +- Under zsh≤5.2, shell-unsafe widget names can now be wrapped. + (#278, 6a634fac9fb9, et seq) + + # Changes in version 0.4.1 ## Fixes: From 0020f592c108766c9adc6cc1558f7253658db07d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 23:41:59 +0000 Subject: [PATCH 0453/1080] changelog: Update through cef49752fd0e. --- changelog.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 8cbf797..97ccd16 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to bc7f8ea433ad +up to cef49752fd0e @@ -14,6 +14,11 @@ up to bc7f8ea433ad - Aliases that cannot be defined normally nor invoked normally (highlighted as an error) (#263 (in part), 28932316cca6) +- The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. + (79e4d3d12405; requires zsh 5.3 for `$ISEARCH_ACTIVE` / `$SUFFIX_ACTIVE` support) + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting + ## Fixed highlighting of: @@ -35,6 +40,10 @@ up to bc7f8ea433ad ## API changes (for highlighter authors): +- New interface `_zsh_highlight_add_highlight`. + (341a3ae1f015, c346f6eb6fb6) + + ## Developer-visible changes: - Add `make quiet-test`. @@ -43,6 +52,17 @@ up to bc7f8ea433ad - test harness: Better quote replaceables in error messages. (30d8f92df225) +- test harness: Fix exit code for XPASS. + (bb8d325c0cbd) + +- tests: Specify the style key, not its value, in test expectations. + (a830613467af; see also its successor 089329660bb3) + +- tests: Add the "NONE" expectation. + (4da9889d1545) + +- Create [HACKING.md](HACKING.md). + ## Other changes: @@ -57,6 +77,13 @@ up to bc7f8ea433ad - Under zsh≤5.2, shell-unsafe widget names can now be wrapped. (#278, 6a634fac9fb9, et seq) +- Correct some test expectations. + (78290e043bc5) + +- `zsh-syntax-highlighting.plugin.zsh`: Convert from symlink to plain file + for msys2 compatibility. + (#292, d4f8edc9f3ad) + # Changes in version 0.4.1 From 2dff6e54ed14c0b29221252480d10bd0c6257693 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 23:41:59 +0000 Subject: [PATCH 0454/1080] changelog: Copyedit. - Move an entry to another section. - Fix commit hash width. - Add missing punctuation. --- changelog.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 97ccd16..c37856d 100644 --- a/changelog.md +++ b/changelog.md @@ -11,7 +11,7 @@ up to cef49752fd0e - 'pkexec' (a precommand). (#248, 4f3910cbbaa5) -- Aliases that cannot be defined normally nor invoked normally (highlighted as an error) +- Aliases that cannot be defined normally nor invoked normally (highlighted as an error). (#263 (in part), 28932316cca6) - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. @@ -43,6 +43,8 @@ up to cef49752fd0e - New interface `_zsh_highlight_add_highlight`. (341a3ae1f015, c346f6eb6fb6) +- tests: Specify the style key, not its value, in test expectations. + (a830613467af, fd061b5730bf, eaa4335c3441, among others) ## Developer-visible changes: @@ -55,9 +57,6 @@ up to cef49752fd0e - test harness: Fix exit code for XPASS. (bb8d325c0cbd) -- tests: Specify the style key, not its value, in test expectations. - (a830613467af; see also its successor 089329660bb3) - - tests: Add the "NONE" expectation. (4da9889d1545) @@ -72,7 +71,7 @@ up to cef49752fd0e - Under zsh≤5.2, widgets implemented by a function named after the widget are no longer excluded from highlighting. - (487b122c480d; reverts part of 776453cb5b692) + (487b122c480d; reverts part of 776453cb5b69) - Under zsh≤5.2, shell-unsafe widget names can now be wrapped. (#278, 6a634fac9fb9, et seq) From 773d60c833ed0346f74af9faa8d662fd83d71aed Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 23:41:59 +0000 Subject: [PATCH 0455/1080] changelog: Update through d37c55c788cd. --- changelog.md | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index c37856d..c563ad7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to cef49752fd0e +up to d37c55c788cd @@ -15,7 +15,7 @@ up to cef49752fd0e (#263 (in part), 28932316cca6) - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. - (79e4d3d12405; requires zsh 5.3 for `$ISEARCH_ACTIVE` / `$SUFFIX_ACTIVE` support) + (79e4d3d12405; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting @@ -37,6 +37,12 @@ up to cef49752fd0e - `!` as an argument (neither a history expansion nor a reserved word). (4c23a2fd1b90) +- "division by zero" error under the `brackets` highlighter when `$ZSH_HIGHLIGHT_STYLES` is empty. + (f73f3d53d3a6) + +- Process substitutions, `<(pwd)` and `>(wc -l)`. + (#302, 6889ff6bd2ad, bfabffbf975c, fc9c892a3f15) + ## API changes (for highlighter authors): @@ -46,6 +52,10 @@ up to cef49752fd0e - tests: Specify the style key, not its value, in test expectations. (a830613467af, fd061b5730bf, eaa4335c3441, among others) +- Module author documentation improvements. + (#306 (in part), 217669270418, 0ff354b44b6e, and others) + + ## Developer-visible changes: - Add `make quiet-test`. @@ -58,10 +68,16 @@ up to cef49752fd0e (bb8d325c0cbd) - tests: Add the "NONE" expectation. - (4da9889d1545) + (4da9889d1545, 13018f3dd735, d37c55c788cd) - Create [HACKING.md](HACKING.md). +- tests: Emit a description for PASS test points. + (6aa57d60aa64, f0bae44b76dd) + +- tests: consider a test that writes to stderr to have failed. + (#291, 1082067f9315) + ## Other changes: @@ -83,6 +99,12 @@ up to cef49752fd0e for msys2 compatibility. (#292, d4f8edc9f3ad) +- Document installation under some plugin managers. + (e635f766bef9, 9cab566f539b) + +- Don't leak the `PATH_DIRS` option. + (7b82b88a7166) + # Changes in version 0.4.1 From 3c90a673f6cc4d6b56c1e79da32c00e2bbe1456c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 23:41:59 +0000 Subject: [PATCH 0456/1080] changelog: Update through 0020f592c108. --- changelog.md | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index c563ad7..28b1883 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to d37c55c788cd +up to 0020f592c108 @@ -19,6 +19,45 @@ up to d37c55c788cd [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +- Path separators (`/`) — the default behaviour remains to highlight path separators + and path components the same way. + (#136, #260, 6cd39e7c70d3, 9a934d291e7c, f3d3aaa00cc4) + +- Assignments to individual positional arguments (`42=foo` to assign to `$42`). + (f4036a09cee3) + +- Linewise region (the `visual-line-mode` widget, bound to `V` in zsh's `vi` keymap). + (#267, a7a7f8b42280, ee07588cfd9b) + +- Command-lines recalled by `isearch` mode; requires zsh≥5.3. + (#261 (in part); #257; 4ad311ec0a68) + +- Command-lines whilst the `IGNORE_BRACES` or `IGNORE_CLOSE_BRACES` option is in effect. + (a8a6384356af, 02807f1826a5) + +- Mismatched parentheses and braces (in the `main` highlighter). + (51b9d79c3bb6, 2fabf7ca64b7, a4196eda5e6f, and others) + +- Mismatched `do`/`done` keywords. + (b2733a64da93) + +- Mismatched `foreach`/`end` keywords. + (#96, 2bb8f0703d8f) + +- In Bourne-style function definitions, when the `MULTI_FUNC_DEF` option is set + (which is the default), highlight the first word in the function body as + a command word: `f() { g "$@" }`. + (6f91850a01e1) + +- `always` blocks. + (#335, e5782e4ddfb6) + +- Command substitutions inside double quotes, `"$(echo foo)"`. + (#139 (in part), c3913e0d8ead) + +- Non-alphabetic parameters inside double quotes (`"$$"`, `"$#"`, `"$*"`, `"$@"`, `"$?"`, `"$-"`). + (44ef6e38e5a7) + ## Fixed highlighting of: @@ -43,6 +82,34 @@ up to d37c55c788cd - Process substitutions, `<(pwd)` and `>(wc -l)`. (#302, 6889ff6bd2ad, bfabffbf975c, fc9c892a3f15) +- The non-`SHORT_LOOPS` form of `repeat` loops: `repeat 42; do true; done`. + (#290, 4832f18c50a5, ef68f50c048f, 6362c757b6f7) + +- Broken symlinks (are now highlighted as files). + (#342, 95f7206a9373, 53083da8215e) + +- Lines accepted from `isearch` mode. + (#284; #257, #259, #288; 5bae6219008b, a8fe22d42251) + +- Work around upstream bug that triggered when the command word was a relative + path, that when interpreted relative to a $PATH directory denoted a command; + the effect of that upstream bug was that the relative path was cached as + a "valid external command name". + (#354, #355, 51614ca2c994, fdaeec45146b, 7d38d07255e4; + upstream fix slated to be released in 5.3 (workers/39104)) + +- After accepting a line with the cursor on a bracket, the matching bracket + of the bracket under the cursor no longer remains highlighted (with the + `brackets` highlighter). + (4c4baede519a) + +- The first word on a new line within an array assignment or initialization is no + longer considered a command position. + (8bf423d16d46) + +- Subshells that end at command position, `(true;)`. + (#344, 4fc35362ee5a) + ## API changes (for highlighter authors): @@ -53,7 +120,15 @@ up to d37c55c788cd (a830613467af, fd061b5730bf, eaa4335c3441, among others) - Module author documentation improvements. - (#306 (in part), 217669270418, 0ff354b44b6e, and others) + (#306 (in part), 217669270418, 0ff354b44b6e, 80148f6c8402, and others) + +- The driver no longer defines a `_zsh_highlight_${highlighter}_highlighter_cache` + variable, which is in the highlighters' namespace. + (3e59ab41b6b8, 80148f6c8402, f91a7b885e7d) + +- Rename highlighter entry points. The old names remain supported for + backwards compatibility. + (a3d5dfcbdae9, c793e0dceab1) ## Developer-visible changes: @@ -78,6 +153,9 @@ up to d37c55c788cd - tests: consider a test that writes to stderr to have failed. (#291, 1082067f9315) +- tests: Create a script that generates a test file. + (8013dc3b8db6, et seq; `tests/generate.zsh`) + ## Other changes: @@ -105,6 +183,23 @@ up to d37c55c788cd - Don't leak the `PATH_DIRS` option. (7b82b88a7166) +- Don't require the `FUNCTION_ARGZERO` option to be set. + (#338, 750aebc553f2) + +- Under zsh≤5.2, support binding incomplete/nonexistent widgets. + (9e569bb0fe04, part of #288) + +- Make the driver reentrant, fixing possibility of infinite recursion + under zsh≤5.2 under interaction with theoretical third-party code. + (#305, d711563fe1bf, 295d62ec888d, f3242cbd6aba) + +- Fix warnings when `WARN_CREATE_GLOBAL` is set prior to sourcing zsh-syntax-highlighting. + (z-sy-h already sets `WARN_CREATE_GLOBAL` internally.) + (da60234fb236) + +- Warn only once, rather than once per keypress, when a highlighter is unavailable. + (0a9b347483ae) + # Changes in version 0.4.1 From f3d0e141fd9d2bfaa823eba98ab48200bb0045e4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 18 Oct 2016 22:18:51 +0000 Subject: [PATCH 0457/1080] changelog: Review. --- changelog.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index 28b1883..f088a6e 100644 --- a/changelog.md +++ b/changelog.md @@ -15,7 +15,7 @@ up to 0020f592c108 (#263 (in part), 28932316cca6) - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. - (79e4d3d12405; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) + (79e4d3d12405, 15db71abd0cc; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting @@ -56,7 +56,7 @@ up to 0020f592c108 (#139 (in part), c3913e0d8ead) - Non-alphabetic parameters inside double quotes (`"$$"`, `"$#"`, `"$*"`, `"$@"`, `"$?"`, `"$-"`). - (44ef6e38e5a7) + (4afe670f7a1b, 44ef6e38e5a7) ## Fixed highlighting of: @@ -120,7 +120,7 @@ up to 0020f592c108 (a830613467af, fd061b5730bf, eaa4335c3441, among others) - Module author documentation improvements. - (#306 (in part), 217669270418, 0ff354b44b6e, 80148f6c8402, and others) + (#306 (in part), 217669270418, 0ff354b44b6e, 80148f6c8402, 364f206a547f, and others) - The driver no longer defines a `_zsh_highlight_${highlighter}_highlighter_cache` variable, which is in the highlighters' namespace. @@ -130,6 +130,12 @@ up to 0020f592c108 backwards compatibility. (a3d5dfcbdae9, c793e0dceab1) +- tests: Add the "NONE" expectation. + (4da9889d1545, 13018f3dd735, d37c55c788cd) + +- tests: consider a test that writes to stderr to have failed. + (#291, 1082067f9315) + ## Developer-visible changes: @@ -142,17 +148,12 @@ up to 0020f592c108 - test harness: Fix exit code for XPASS. (bb8d325c0cbd) -- tests: Add the "NONE" expectation. - (4da9889d1545, 13018f3dd735, d37c55c788cd) - - Create [HACKING.md](HACKING.md). + (cef49752fd0e) - tests: Emit a description for PASS test points. (6aa57d60aa64, f0bae44b76dd) -- tests: consider a test that writes to stderr to have failed. - (#291, 1082067f9315) - - tests: Create a script that generates a test file. (8013dc3b8db6, et seq; `tests/generate.zsh`) From e060a0a1c8520e4b4cde8b9bcb93af8814438fb5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 18 Oct 2016 22:43:36 +0000 Subject: [PATCH 0458/1080] release.md: Record the specific command I used. --- release.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release.md b/release.md index 4a1ba5c..08bcfa6 100644 --- a/release.md +++ b/release.md @@ -6,6 +6,7 @@ - Confirm `make test` passes - check with multiple zsh versions - Update changelog.md + `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; Commit that using 'git commit -m "Tag version $(<.version)."; Tag it using `git tag $(<.version)`; From 2335986a394823942b5cf1991a56ee64cc92958a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 18 Oct 2016 23:54:52 +0000 Subject: [PATCH 0459/1080] changelog: Add the last few entries. One remains as a TODO. --- changelog.md | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index f088a6e..32a7b8a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,30 @@ up to 0020f592c108 - - - # Changes in version 0.5.0 +## TBW: + +- `arg0` style, inheritance, forward compatibility + (12b879caf7a6, da91264122cb, b4537a972eed, bccc3dc26943) + + +## Performance improvements: + +We thank Sebastian Gniazdowski and "m0viefreak" for significant contributions +in this area. + +- Optimize string operations in the `main` (default) highlighter. + (#372/3cb58fd7d7b9, 02229ebd6328, ef4bfe5bcc14, #372/c6b6513ac0d6, #374/15461e7d21c3) + +- Command word highlighting: Use the `zsh/parameter` module to avoid forks. + Memoize (cache) the results. + (#298, 3ce01076b521, 2f18ba64e397, 12b879caf7a6; #320, 3b67e656bff5) + +- Avoid forks in the driver and in the `root` highlighter. + (b9112aec798a, 38c8fbea2dd2) + + ## Added highlighting of: - 'pkexec' (a precommand). @@ -107,8 +126,11 @@ up to 0020f592c108 longer considered a command position. (8bf423d16d46) -- Subshells that end at command position, `(true;)`. - (#344, 4fc35362ee5a) +- Subshells that end at command position, `(A=42)`, `(true;)`. + (#231, 7fb6f9979121; #344, 4fc35362ee5a) + +- Command word after array assignment, `a=(lorem ipsum) pwd`. + (#330, 7fb6f9979121) ## API changes (for highlighter authors): From f5c44ed7a2d8de454668687cc126252e676ddf37 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 18 Oct 2016 23:59:32 +0000 Subject: [PATCH 0460/1080] changelog: Markup tweak. --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 32a7b8a..20782b3 100644 --- a/changelog.md +++ b/changelog.md @@ -27,7 +27,7 @@ in this area. ## Added highlighting of: -- 'pkexec' (a precommand). +- `pkexec` (a precommand). (#248, 4f3910cbbaa5) - Aliases that cannot be defined normally nor invoked normally (highlighted as an error). From d464d3857fe83d2ce2a3a78338dc928d2ba578c1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 19 Oct 2016 09:10:24 +0000 Subject: [PATCH 0461/1080] changelog: Write `arg0` entry. --- changelog.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 20782b3..1c94856 100644 --- a/changelog.md +++ b/changelog.md @@ -3,12 +3,6 @@ up to 0020f592c108 # Changes in version 0.5.0 -## TBW: - -- `arg0` style, inheritance, forward compatibility - (12b879caf7a6, da91264122cb, b4537a972eed, bccc3dc26943) - - ## Performance improvements: We thank Sebastian Gniazdowski and "m0viefreak" for significant contributions @@ -77,6 +71,10 @@ in this area. - Non-alphabetic parameters inside double quotes (`"$$"`, `"$#"`, `"$*"`, `"$@"`, `"$?"`, `"$-"`). (4afe670f7a1b, 44ef6e38e5a7) +- Command words from future versions of zsh (forward compatibly). + This also adds an `arg0` style that all other command word styles fall back to. + (b4537a972eed, bccc3dc26943) + ## Fixed highlighting of: From 1bdb88aee14c59cf5fd8309e1ef3e5c65199a320 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 19 Oct 2016 23:08:18 +0000 Subject: [PATCH 0462/1080] Post-branch version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 4259c64..fb0b754 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.5.0-dev +0.6.0-dev From 28d7056a7a0652fafe84e38b58ac5366326531d9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 19 Oct 2016 23:27:54 +0000 Subject: [PATCH 0463/1080] 'main': Escape '!' within double-quoted strings. --- highlighters/main/main-highlighter.zsh | 2 +- .../history-double-quoted-escaped.zsh | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/history-double-quoted-escaped.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1bbc3cb..d7d292d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -810,7 +810,7 @@ _zsh_highlight_main_highlighter_highlight_string() fi ;; "\\") style=back-double-quoted-argument - if [[ \\\`\"\$ == *$arg[$i+1]* ]]; then + if [[ \\\`\"\$${histchars[1]} == *$arg[$i+1]* ]]; then (( k += 1 )) # Color following char too. (( i += 1 )) # Skip parsing the escaped char. else diff --git a/highlighters/main/test-data/history-double-quoted-escaped.zsh b/highlighters/main/test-data/history-double-quoted-escaped.zsh new file mode 100644 index 0000000..cd08cbf --- /dev/null +++ b/highlighters/main/test-data/history-double-quoted-escaped.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "Hello\!"' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 14 double-quoted-argument' # "Hello\\\!" + '12 13 back-double-quoted-argument' # \\\! +) From 24096c2e4f2dfce55c05ad9d40bec8f83d3eac50 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 19 Oct 2016 23:59:02 +0000 Subject: [PATCH 0464/1080] changelog: Update through 28d7056a7a06. --- changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 1c94856..35cbb06 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to 0020f592c108 +up to 28d7056a7a06 # Changes in version 0.5.0 @@ -75,6 +75,9 @@ in this area. This also adds an `arg0` style that all other command word styles fall back to. (b4537a972eed, bccc3dc26943) +- Escaped history expansions inside double quotes: `: "\!"` + (28d7056a7a06) + ## Fixed highlighting of: From cd9ec14a65ec3d5d09e1a53114050abb14bebec6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 20 Oct 2016 00:03:09 +0000 Subject: [PATCH 0465/1080] README: Add before/after images --- README.md | 4 ++++ images/after1-smaller.png | Bin 0 -> 3826 bytes images/after1.png | Bin 0 -> 8753 bytes images/before1-smaller.png | Bin 0 -> 3807 bytes images/before1.png | Bin 0 -> 4537 bytes 5 files changed, 4 insertions(+) create mode 100644 images/after1-smaller.png create mode 100644 images/after1.png create mode 100644 images/before1-smaller.png create mode 100644 images/before1.png diff --git a/README.md b/README.md index 4558463..515147c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ highlighing of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors. +Before: [![Screenshot](images/before1-smaller.png)](images/before1.png) +
+After: [![Screenshot](images/after1-smaller.png)](images/after1.png) + [![Screenshot](images/preview-smaller.png)](images/preview.png) diff --git a/images/after1-smaller.png b/images/after1-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..46c664839f55377c64ba8ba6f670bbe0fea1249f GIT binary patch literal 3826 zcmeAS@N?(olHy`uVBq!ia0y~yU`%FUU=ZS9V_;zDJH6kKfq{V~-O<;Pfnj4m_n$;o z1_lO&WRD&6 zh2cL4F4((#G6Mqxdx@v7EBga3VR2LLe{BCP85nrKdAc};RNQ(yr@CND=(Gd%cjuN^ z$xfOeUg;#qED_@N|LD*GLNb?UqKb>Ht5 z@2`IM^PKJTFq4KRc78dViURGZa_$EQn?amoH$YULwJ;NNrHa+8g64EXO5~?43`$gtbYCa^=WVYy)L=Ax;Jm$ zbk@thQ_vw*Rz2T;ehc&C_IfL+aSe2G@ze=+LVHU8YVW^Ym|Da4E7QQikMGCNoq9*^?A%bQz30E(ni$T+#J;Ch zwrA$^@BeS>^R7Cn`f|VZ#IngJAL=)REx)|6=4VmbnHdN7)&8#d^>TS6>_qAMddtq{LhCs&qrb%u)61OWf)h4DWm~3%88hZO{ zVB@BzE3?`*F1&D!Ra~lCZ^OP#FV-Js7xaMS;kIESi&V!%K^7k`dPI6(~zk5ku zj@snT$jxbt0TB@vDZ(a33{E|@+QBOVk44<)dK&)w`ZgPf1eFU6Azy;>7~Ghx7I0*| z_4QETu;4Daf2xgXaYNODn7t8!{|q#l=Kbf2o68&jN2BWUm3I~MxAP@2DeS+s_4#X` zdbU#y&zFn0y-dvE__K9c`pqRA7WGHPf_8-d&$_nUIB(_r-Q|bZ*RjUevc}#OQP$(z zvv=W&6J@!FSay_fzIuK1K;55>Yu|i6|8V2+Bhv5Quxyr$tM)x*misDrU*oIey2tZO zKCSokOlfVuoM`qrGgUR4i#zk(t4BLqSnhdxKJ0##mDKAd^!M*i?__1~PoH-d{Iy~T zZfdGXe&iC=+_WMyfBB-bLhYNYH&$qN9a3*l_ks=zZPB!bF@%^k@8@$&r%)6}2%zL`t)0ye> z7A|!B`}(Fgx4uvN3WiEf+u2IotF~M$JHJR}h9%dz*oj9YOI+uzeRcGU$ONW2Y{wX< z9WPdzXzDT3t;%elx`VvPCB=5xBQ)iMA1 zlBBX`is{!q{;M1B&nwc6tJeN2$-`!2U;AKbYyCX7|36y)#LeNUx6zIJzsV$G;_`L% z>8~%(|cvV2{GcDRBvGoMUB&Vtq6Juh!<4G2_h`!Rigi>P+hdjn-=FYluQ-9cpA|kJwvf zDl04dH*C&J!ws(*By0rySybALExk@z38v(p)1^&jV|jtOU-NGaIn} z5bIznYOHs(iEF5y5V3J;#RKmLD_pa;DINQ(GNDuAv*-cS1J^J8JKvx`r~CQ^w)f9Y z|9P<`N$2!>r|Bm@+PyB@Wqv6+<$1E|t^3auEicb+Gn-Qx23*>CRga*H22*!<{h)XG&&bFGgS$8GoH`MCSNQ}lM7w@s`Q zW^(@fw;|1U|NN_Kzc9zd&p)rKB9Lve>BAAuvd~b*4{=#q-AT!ksasUdzg@dx@c)M4 znJ%ZS0)v+e7yfuvq9bqI#*m-?Oy2fXxT)!njIDF(UnsWkN+{pr8z{1A^JYT{o;SC) zuD;LD^kDz_n`%-i6C00Y>TmT}R#T>P$2!R7-p4Y-UysYK|UNh)ewrsug>jj^XQ@6w%@V65=jF2+nF|0ZIV3Tctn7C z3*+yJ(;K|_raQiioB8~VMa6GL_s6e#KJzZBzt+EZVZdU0=EMV^AGb_$^Wc~?J*2dI zkBd{y!gX8g|9;*Nqz)RBov1e$L7^)ZTP;Rc^jJ^N&|0 zK5}+44b7#c3?(zpikO%(?yWe+5EmDhb7#lIIdf#n-rP8NW~TAaH=EB#>?~TEwNQIj z_5OG3r||>7Ylv{h}?0Ww!%1Sk4;j(=frRVuiT^nB7edOq&KS!Lm9d}nxb@mJo z|Ns5M;XShAoHxY892WH3@K;OSR-LzktNwI+_2XhOjjh`IpDpRl`xxzWBkpNqM`5{u zz>DXZ6JF0XdS^dR?C@p{&TH~v;oJ9JHDpY!&vNVi$J@eqzF*i&_t*`0_48>LT{;!R zw|`mxf8Vv`#&cdi_dS#L5{eaQ9lzZFE%gZZ-^KQG&m91Tgf4=zKFKw5WsXxx*;pFf8cYgo$ zfTQcb-%g3JTRXjd(N@VH)}6n?Jo|14XH0NW>9}rhCGqLaGDS0itT~ba+NB*2|7_|1 zeX-ScSy*WFPqO-^O@J?pGA+nzTCR04-zUKaeAJ6`sBpRZnxcU zyTh`%b2YkZuJd2Iozw8d+-#GAR@b8J>p%Frb$bjXI4-_knUPx>wSU3N&Y24r-Vv8O zw|wfhRB>PU|NdNMz*Y9ZNB~c;`;fqgOn)Htu(s#QjqF zsP6UG3HKy!M+ULpH1g|bY@VKT_*sAJf6cJ)``4wTtaDG9*{%7moWr~JlG_ITC2o#I z7R_E&RaUdjau40m6?@XN{`8ZawV@ByT^*7%%)cA#t{2&9{5a*!$%h{vWZWo@d&{D5 za%+kA?5YI0qF;c;$UIW?u{)IZOClyu8SZQJr?n^G^S@TH^}RL#hd zu5Qr`TN81xUB1pEGE#Et)TuT?ig?!Q?~bh#HIr*@6;ANv zDw*~0w$|~rp>?J{JktvfUoHFbVT=I%^^+G$tSNo=gzvfr*hAaN8NL5Dku5d{d6gvUB9}~es0_JOR9S1|F~o{H@8N1 zNk2Hd_`?yG6Ek_HulGLm`ghb+*(uD@jjbm-JN;A&(|L8bFlSE`7MIq!zK?z1#+vXK zlI}*y*47a`dpKfdp; z#xL*AHPGJhlQHxC+Q*CB&z-t@&fjZ^%GECE2NkTVGT#YA`d`2G<>|xf2aiI({wiGk z^<_@Yxi6d9e}6x$+<#z2U_cz-_q*!PJMLF`pR)hKV3yPHCdZQN`UM76)uL%P&hwv} zH}%s!zu*~X^>+VQx9o0n~vVAgGGpxJe}KE^n5 z9pj%Hmku?%_ieDWocUZx$l~&yGYfZFrM0&i9eN-k6maKnr55MY`O9|2_chk-*|TTL z>FN5~D_5?}oBlNKuZ=OM>Z$vGi+GN@uXg--o>jx1vuMAL^S_g4LOS}&_RExC{Iy5Y zxJ-rorcIkH>i$^#{Q2{p*wb}S|GvMYd+@?U8O7%f-comUPv$;&z5cGQBmcWE zUn|`u9&cJbNoB|F&febCkB^SN6FYoZ)@z2~zqeC%Fa7cV^xS=Rrho1i`q)-{c<^xD z(|X2x<RYz@Wmx#=yYPRsBblfq{V~-O<;Pfnj4m_n$;o z1_lO&WRD&6 zh2cL4F4((#G6Mqxdx@v7EBga3VR2KIyq%9$Ffb^Zdb&7COZ7lWP^N zorRp7BA62m-z3JfoYqp(3tt;0enC4*-!;Q^jmWC4i?(Rxeccu|A?s_C64NHmpqrcm zWn7%m3Mx9BH=T`U{ytvqmv-_@%A}bolZxuj7tix~mUG`Sec$)$^S}3Y^BF8!2m^)P zkDtC|%YXwDR+FO<&M?62Yk2Jf3^1U`Fv$CxJHXUAFIMFI`t|ADDN|nkH-Gx<)6Jd5 zrrR!yB=h!KJ$TKlY53{q71I;?pG&%D37m8=2;h_XRFXW4?_**>#Jw-|+7B5oXrB7E zOL=EN)Wr?Ivn!?@tEk(0>ii0g6Q`S3Y5CvpQ*$n!D1WxqU08Uv{d`@`jXQmLk6P&I z^*wo#!Y6Nc=IQC_wza%cQodaY@iS~a?9NBLetFHrP>#up@%E4Yz@GYRf@)<=rOOlF zuH5zB-hy$SJVWKu4|l9~WPbP}dULsR%ggP#XV>r+Jajw!ZvDeZsmDJpr_ArS<4Qh$ z=yv|$b+PmI$@(@uQ?Z}Lyp-*@$lvAD;bAMUSI1K)eZ{?3p+MR)!XK-%=X}-%a?UC z7EP(%#rSS(jhOR294OZ@_?sqtJaBtin`#o$!%_^OZeA~GB4RWVnxwQBCtYDti z|8t|v=4amdYii@2Y`A}Y12_KVwJQ0rA!jX1{!Pt9o z@R8$(*F_HGeJ?^mVP$;yHH9yF4ViXMWWy&9rlKPM(`<{qs?`e#N(& z>6I^+PCs$t#DmHHb}R2CURvVWBWFA7@^b&rACJpd|FSZDvw%76OZ$(28)bagt{lD< z8gEth=ER?$pDRBcWWT7%bndwO=UW#uF|3_|>uZ`ueQgr{Vj5iLx~}Y6dTxFnRLfdwZ*IZcJt`es*SMSWj(j zZRO)$bA}nV)n?}TS!$b?b?xWp$=05~-|Cvha~>|PNB;G{g#B$kvfR6OFC;WHFe=I` zAYj7seD}i-92d8_9lmggzs~Z&5&>zE$4&eBORk*kV}6kF(HnAc3S7RwzrEdA@Q}&U(vo4x(xri+p{~!* z&E@3bVM(~PB~wLJbz|;rv#_;MPhY;iT;R|#|K;bcZm$ATQ&YdZyxcCT9rodba=(DA z?AcdWSKHQVo0!aTVz;^MKjqOEnHgK<{`ps~{PWwf;%$7v8?G143Fj0zRaW(0JN4!H zIqrbpEc4oq>GrJ(U$UfQ>NdlbYg(?yw^x2X^7r8x$rURa=E(ev-zsvye*fFQ`S)7B zy>-ou+r%=jM(EO|n5;=^_ILVs&fj>h?{pu(gR3j+)TvWjTCS8Ntz5Ha$)-({E?fwB zc78tpfi;nv4Xhq6U--~6YKHbP)vxw`u`5=sT9ki(-@JWa+?REs&>=fAe^oxb2ur-Q^*_k!oF{_%6$+%6wl_UFur24(jJ)#W=r z`&E3udn`Ak&~VPC$K^W`n>CIW77B>4T$AMOar<#L|IV#B&$R3xH8)l4s;xfe;yzhI z#-}hd5iAakwuhT6#&~hW-Vp_-8yx8_ovmDBY!EF3(T7$|J9ZK%$qwi?Z3Qe zoIf*u>%IH)k32|lb9evjwLS07=4AHW>!agB7Hl^^*wyX)`$57#+dP?#jErKpkFc^C z8JbPI-Y5Tjsj_?49Q#Y>`=2ti8JMXZdsMx5zx`fir62SC=4u#T$-B6sY|9Mmay|P$ zADFYRuS@;??JbYI-JV~+TUuDs&du@6%+%E1`z5IP-i>=}RTFg9izG!K*!(y5d6>@X zmi_PA<<}M&SHFC4FJ*`E%4Z?ZneQ$w{#QA@B&_()-o%WintN4ZYU&3)R6iW(c=>kQ z3$>alY`Zt-Y~R1{d3dHcqyJaI*HcZus~p}by&+}$pRLQn*Knw0x2Z(@tN)bsIiP3q zbg4yIeo}x|v_zmK6#=QtLmenm%8rSMW#c&-=Q|<=b@R;;d#|3T3miU;Vs3 z-h89gzWv)7i-W2dzcZCH?F)M?=P>25J+mucpCG#pW6Ac7@9Y$~e=rn?T#)3jVU1W` zzl%MB=}p0ff10NrrEh&__dwx;-Gul5qQh5d?4G+w;llO0dtvEQk{TG~Z`3gwtvA1C zvSRh8ja!{nPJ#g%>o1%p&)`*je>=UEln5k5>I*d2m6| zqTDY=Q_ZJg|Np(;gyVO!rKTFB@u;XCd~-7(>#6gNZMr`5^`T z*4B4>3(X2b>nf7|%(=f-dcUt<*$&^?2OP|Jq}}fO&bA0msaD8}?2i9-XI<>g`SZ_r z=}cADXR~`GjoXCP{S30N>1@lp zdumha=?~w(ryp!$O-W6?D8cgkVADhaDTdenhueI1#AxI%5Vkt}VVmjVO{FJHobh*X7He@oAkQR`AN|&8ent)_?##%{lMh=scfqE>pL8#h&|7ymw@t~%`3_B4IrZb?shJy}@ANUjO z16WJkL>|vO(0za@XL+bM(=(;6T*D8{1#AWiVoz>2njNTlV0s{|rbqsR(FM7anKcp{ z8T^@)8YE8{ZqD8EzcNAL6t9cU6;Y3m6Xr8&9$4)qeRqy{`F+)yyj-7JGVIJMdaSwe^m+I_-Gs7#B77_Mj^d2{_DiD*LqD*TCP9yCF{FA|9oLE6>~D+Jo1xyX!6GhGH~;+bPtKzD?2;|3dNS0ToibVfly(2v5K`2YI-#O=%O1!6y!4re&iv^; zb3R&V*6ip|zLe8HpYc!syZn2rbG9zKc=$Q~MLqksvkM(c2ws*t+b_PoRy^^bMus%o z_U-NZYo`c(W_gpl)IK2QVa%7BU}ZzYjk|)Gmn>OgQgOU)$8wIZbCiCZP17)|{wLsh`_kd03?)yDGkNXOXtDz|tKeKXeN&=EU+X zQrX`p@=$_z&Bj~yEESA_UH!__Qa`V}J@x{brG3Ze%vu{4pIZcXOZYQLflHKKXhc>+)USkC`&eld!M9zBc;n^JG@mo;$myIvt&FzI#ni^Ut3# zdfJcuy*!_FZrr$qlSgIsm2c9wj?Ix#%fBBdtMh&O86P<>kAxX<%aq%;kN*5M%U|a7G4)>AQ?C0ldroZJn5=6QbYru`ZJ%|^wT@cN?K8h$BivB= z`B`AdlZ<~?_r7QdRoAuN+9ent|NA_D51X`cuK(OAVTZ(2Uslb(*7tt?ek0!JIs2|IbE~Sdir2PF zkd&0viQcxx@x1u6e6RfP`+w`U?mE@RqaClmIZpJEdhh~<)&94>EkC^@uWIJY>$kpq zdL&kIAmr)i=Mh>*wT{l1a&e*Awfmhv)TRdoYldmE-eVO@zJLEZ_YdZ2UWTVWUb)Gg zZQd(zq?Recbes0`REBu1`M(v#a?FcA8132NIdAHG^DTij-j@Xi`;vAy+yzN&DwpSG*5G#AVY1E@BQBuo(reFQJOrb{QKAIrGH99 z!=I+}^01xE<}t{V`SJ6i$a24#Q(nBhyfD@KWVcOfSHzj>g0 z_@H2tP&3s!^UX(ND}{!KRg?dpQBOY~lxQOK;BD^4Kl7&^KX@W+ZI0ae1d~rk_SKqd zUCrH{RdnL}=TAyOKVx|=zvldG8p#`HS+ylfGwh_6?$gVg)93DzYd?8M&3D$34nbuP zfB)x~{q1uvNN1n*Wv;2d^z-fQ7RS{IKlj{j+;Ip=0Nsd%TbH>%oKv?{>dev$2`e)Wo!E)v6f#70gvG z-KopBT&kPUAs9Hv%I#Xrb@Ovijy-x&zFU#`-Fr2$#rxLg{_eWoZRRmSra@VpVe72W zY8TG1^Xr-0H0EDVj@As@xlHGqMIXzHn@(GUTBGheIP`A*aqZwnbB6ECj;HMMzD;D= zxa#a(o|9``1mDW2I&S!0D*UvuR0Wv~A<~*7|X7R^9!GPs9wlV-i#!nHOoi)pIDiF<<693$C3 zea@9LKYVJ(YlGO?x@Wp8&&)FAZWf+c^DgDRtM~jhw*v0Z(_W<_zVhyCBkl~252n04 z&+^arP4QGVDtOhLx}oIy&$SmBCpJ!yU=(CbO8xM45~DyCTUx~8s2=axE00E~-ap5G z=kAKs3Vl(lZA)g@>wnf;%4Qp+42n##G0j-(#TT_JXW>wzTu?V0{Z*%N|# z4o^HIm=HAYb@$>I#iiHI{5tA4mvwhr#J0DI4r?CHozNrA+ah?9saPR;-rH%L7wzEb zXx=Eh)aT1<`^aCDcXhAtzdiruMfTfaJ$H5MrKJ16%Zmr<9+N$D?0Jgqoc)SkpF3Pm z3Kf0fIP41eH#>cd(TQ>i=73lLewQob%`>T7SXR^MQZ2W9C zC96UE>A6y_-CY}_&Ln?*bv5VSo|zv$6o~1^ooV3|*3i;Q`uXXpPRx!Cx85GQ`{bJ8 z_q>jx_?o>(EfW)QG6`I8^KS9=pI;pd$~W;G(48~Kc9ZMYqdR75 zAM0(65?H!z&Uy1UKd!EN`Ei}a$K7Z3CN-`#TU~!w&*A6mZkAP+PH#6o+pk~D{Vp`- z@I;Rd*LPlVyf-r>?`B7m%&Q~Y@*aIDy)i@a;x~QXsSmDQG4oa5zryvn_kY>-DdHywqBE%76Eoc>T~1ixw}euYdlx zdh_Pg`_}KL{10DWcCPi1Tx#m1;GcKP74715F0u2O99f$)?MLL)J?mDiIwUFmmDl`b z|GhM>ZG0TxzNy`Bn|kNw=bIrtSCiz}nj0;PpFMc|`0zB{Xb(@%#PjoPx8&TMG(Em< z=8qp0a>2@`ch8))(kjW?^!JTZ#lPQGb1vi@__i|j07t+Yy=SFoV(siFh_Dv7do`SW zs`Qb0caYA?N-drSzm``f>P!+L-5bMN4q0Bw{OBNm{Ps-$!rAw47p4B!P;ZKBp6YmH z?X{Y%`_q+Y%D(EV{Nv2i7rfDwZbkvhWcLzx^KrO-)Um*j-buTnX7# z{{Gy{%gcWr)vt3j-|XSyzi64>W%k)?mVQ;;A?Cf-O0?`|j@Fs0pMO^#KGV2JExze|v>a02)=dFHAe)*r$;*hy< zzoXH|xV-Dhw4|B#g|18&|JC}Yc;|3OYOQ{-Xy(x!JLC7S{&ZO}`v&cFBp;(j})DEec&-CAYF}$^8u_+uqA( z-kxZyYIA4hLk&k?xuF^H4&%oYPjbD{Wbg97P9ZABR0^ zSroC2XH#s9>(XNH+xM4iTCOcUaNg?1{r%1@nOdfM`KEr!+Rt$0|26g%{?pgEXq{&4 zIcRx$t+i+HzgH7#j(&U55V3{v(%suF9S%DdJHNeM8k|xW%=w4u`zd?>2Os}EW;?L}WUdkFC`na!;%e$g_wo%BO?1mNh)6TqHq;%=5&X)bJ?#!H*xNYtO`OMqX&a?5X zcv$z4E4sK?*C=AojiucG!jAKQ{rYs{5tr`wbGAwB|MhD1kKeyH7d&)Yr?t|sY3hlC zLdNaSoKzo{IlEh1d1tcbSZmLhf1${j{jFpB!`T^jmd1P5P6^q1>^S!_?Vn56Pxo?U zD4%QZ!P#XLa2esJ>MhXDVX zY}?&Jqu7pk{`<6c9h>GZK~UQ{v*X|6_qy*g9ru}VtxCFM=_OWt^lQVVYga4+<<_SE zv(dAUITHFaQhRmS$@{nSgimj@O-gz&(f!Hi=kpIA?SAxc!L<6iKZO~&>ep9p-_CON z>#Nl2zp>?=Pj4nP2&+qdXS?2fOvawEuKG$ygyNCo?YYYCn>JLJv$?rmR8?vD{rK@u zCDWn?}GRBI~*sR|y=O@=p*{Yz)qx+2*8f$x#3IUPGJ zzPM|>KFjoveX@7+?jHgg4qQEd7*}o*@6>p8cS`oFmWX5aOv@Kp&pFZ|V$1Myw!BZn z|99MPr`}u~XZT_F#GnNSGFtrkuC1|onR!R`zfG(4@BaPUWs)CiRHV zi(L9~2;Yv{2=kvE_8=2g3VoM+7bZhw4{Bs)uo{l^~3Pjjo*%u!2Ox7{(he?G(g zxLrrAm-`&lOx(Bc%=i&SGU&Z9mWzGc#g6EzsFKhbg-XAq(hTNr1 zs=wX(mt~w1DeIFu${_ttbnCM0%P&jze7zRUaAu})dy#SaGk*I&6Vm5Zwt+fEVPS4Q zK0Lzeeor3v+dup9@v({Mr_%`s`#&5~2vnH=QeEtx_R%E9FkN=bqZ87mwq1xh_UCPb z%9r|c$EIw#$Wd>vF}3DS<-csz4c1=RKaPl`{PC9Up1*sT6c2RJlpC?Yo<)U^7`wUdA76F=htjfwT${W3=cHxYhD__G9f-fQ^cEdC22WlS#7ESTnys?)tf-~mO-Wb+6 z#x!NI$ICYqGB<7)ye?>-WOC@!;Y-i!?g>AdI^ARHzOIRy%Q@_PCWqwt@`gX*Kd{5k z;NF|1ckX1_m1~5|I-9cge8c;HZ}0uRd$V5Xknhn*r@s%+sRY_cPkJ=FD1Y(PNhhAI zGjn^8u0guElPF zXE`m3Ub)|n6jZ*}Th|bLJ<(q*$2NQa6D<$+d3ystwen>tGYal>6^h-X7<})a^rJua zb0!x1_)Yq|>&3&W&Lz(yt2|cS+uGeQCBj=Vm0LOJ-nS6-m6NWh`LLZR{<+9td3;&^ zQ|0QAkdT15IKR}?yN8y1e}Dh{#l`Nco2_qK&ax|3&i42GdeGXc!#>_=$DQr^{U>&H zI9%SG{VV-Sbc}|Dd^K z%crn6%R`KnmM;3vP|mPj@mi7q>u-S#g0~yksFr zMvv7qluE5%UrE^J6})?w{f_nj=bUWjW?d#}w)KanbMdQLciuNo&sOulF`w6YO3mZv zpQWGuij}m#`|(fA)cJgtg-%+xOJA`}Ry%nAUs{y7y#6{qQPB-GmNDBNrWgG*`txXrlnurDcGKOpSm+{8c1d6;r*zD@a$Je$<$?|>q{gd~1B^Y?jmb&@$O7P?KsTWVI zKHk6i%^k~mS@-8%ym(QCja~S`)1yx}8P)BontJ}+{B-ZUvy4yDLPejRs@;|OyiT&` z*sI(H%Q$SpgPi93&Yp2?pDn+d$^}!Emf4}9b2M~PT*JiX&$T~)v{U$Fkj~Lq=QsYU zl3Q7mBN&e9zn{9)earLPi*+TOot=Br&(AZJ>UDd}E?@KDtrlkvx^hXIb{^$Ajt~GMA%I%gm zXOICVhkK?=ZRgrs{e4;d{<<~M+xud7msRevl-jP~zW&6bi+?i28D*7@+CIBtdcA-7 zMHU08hfcyPS6x1G@!0uaiz9nPO_~cYJFUOIx#+3ar%#_|nB__xOADAD=j^;VQ{a`p zW5-c*)#he3Ta!H1EgvtNnsje;o1F6N%gZB2ju@n!k7|F@E^kWas6z>~Z)*x0%bMOR^t7ed_xC-CfI)7ZYByU%qf* z$I=Tg6%@B*hN@q=kf8&%19>UJ+2cs-5*q%qe~{*Rc_^Y!j)8$ewZt`|BqgyV)hf9t zHL)a>!N|bSOxMsr*U&P=$k@un(#ph8+rYrez<@QK?<0za-29Zxv`X9>O02f|GB7YO Nc)I$ztaD0e0svKPFPs1X literal 0 HcmV?d00001 diff --git a/images/before1-smaller.png b/images/before1-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..78fac4f5c45ef4488daa11755a9cb1710867bfa0 GIT binary patch literal 3807 zcmeAS@N?(olHy`uVBq!ia0y~yU`%FUU=ZS9V_;zDJH6kKfq{V~-O<;Pfnj4m_n$;o z1_lO&WRD&6 zh2cL4F4((#G6Mqxdx@v7EBga3VR2JI<`gz(1_s{8o-U3d6}R5TRQiO3i~m1pz;k;; zS4bq&;t=21Bxb$PmM}+=-7L4*&L%LGI<7wEwMdiq?Q)4VQd^cK&EnX~wl!dFl6KU} zEk}=Oxdh8HF6ChAGvHIuh!VMQ|9iWD%}8vMe3q8eCYd(lqmx6%F|Jl7IXOA!+KBF@ZyEVm1PVJ-`?D8z8+WocIWGlU%t46goMoh^YCzc^6hQ88@9;Yc`vv+e7##( znAoOGn*_wg(@p-*=S%+kdft5Pur&uhJUrZftM~ad`R3lZ*SFKJSX5P2ZCbLVMXI;0 zv$K=sK;q%HkJr{lfBE!DsiB^C<<(b=zrVa%z23;&e0pnZ>-oEW?Ck85mh|?Xop79o zVQZAGxK6}}n9?1)cNc$tc2-AMH`T?3CDkahzxvskna-0+ii?Ghg=mRdTUo6L(c*n{ z{o+MOetv$>UFv>wPHfme0*9~HqwDr`T#2rYW;*cbX!pdaQ(Gf9rzsj53Qn6g?Z=nP{u}H6*JW&t z`V*aypWlDxj88;lq@?cZu+-F%u zJu6;B-Jiw)GD>5rS44F5;=Oxi|NZ+{@qBLihSJwzCnv88(Q0XFVPH`6nbA=B`Psqa z$B#dd%g)YbVPjJ=F%j`v8YD6O^wW->o|d_DWsmjAc7OO#&?8~EsJ(CB6YGaBUUXO% zKTCLbXJFX zPIp=w^i|^f$BzfMWL{QzIX!58(hGfi{g@pMj~*rIL~dHrKF4XHLrTh$gUUZU1eFEk zQBZeognP>sYw|PiIF5C>1|^^r-2>hk`wS zKAmN?AcU5Kfd7L z;L6|Ma{FYhr!o9ErM-T`nl(M_{BlqB)&7o%jz0bJ@^WDYSy@@nN$mV`DN#{UiE+3b9-Ke@NJeSC3o@tYSf5~`}K zE?>TES^UgrvAq7h+V8P(dnz`D&x_G}zRSXy-1}r6uHXOf)cgJa=c#0- zr@J%A*w@*BQo3>axev?d*CjbSGe18wQ@OHk;}1(qOG9(>=~JgpwW;}GaQgJ=$bbNc z^z`(^*-4+Do!wLPl*@mP#ldUW!j2s|!trU@t?lXO<>ai(dKNBRXjAyeW&U?o7M2UQ zZ{JSvSsFA^W$oIv)i!KpxAdRYtJi)!D*o4Q+4rO7SO5Qev3mW!N4K_Sb2c12c(CUE z-tQa@A3uKd@%Em)Bz}$E(Lchc{TX^XIuc4tO`jH3^8c*;{mszW`18%jJC>@}|9mRG zE^_m-@cP)8n24B|JFmAz)Ps^fk6Ufm(|*6@kEh4io&58s=G~p0lX-c0*}f{O)_ssP z_1m#w!-j-_00C1e-}S#slg`diG0(Z7&{J7e#Z@1_uV!XpVd0_DloXZ!e?I#+r|qfu znAG_H*X#A0*RJ)QvDp6Sxiq7qCms*2w6way*TuTr@7D8IuTK5>^XH!W z|8}NQyvKVal`ZS$p8auUWw1@C%I?a&mGy8X5`3#m3w7?q-$z?Y!vlI@s&qixR76&z^C~yKLOJktsgw zPnF5zLx-H&T3aP^-<+DN9T^^e{q^!iUP~WMR`-_>7kA$p<-0ZN?2jK6la?%AtUT3A z)wAfzia@ra?Rj?}EpqL4dAj>lkBsG{#>U2;zP>bX?`}qY6_u8&SFfI5E6KcI>Qqr( z9i5(8#jmcc%*o0!l9+9n+_oX&;K746UtS2VU9*Pg+NzBkCw_i*cJh@qzq;o;Eqt)p zz2Bnr)fKzv7qYhY^!16YV`gGvneDrEz4p;#$2P57*Jm}iZ+H3oX(Ff3rO8N1otiK~ zpsl5);9wK0ld+jvJ=>)o_RIh8Wqf*a@{oA<=jZ1)uUgfmr>A%3#EA!getuSc`F=e( zg`Qvc*wD~$PtjAa^{>r}pZS=XnFX!CUi{_7McW_Ou3ZCVvgG9C$mrHtW)08V zw{LBa-Mw=MRG9b3SYAr7(bVMhpJyY;m$~abznPiYp=;N|LgW}0Em|~T(xj$UtF&Hx zt-5jJ#+Mr}wr}6=o}Il~C7!LTua9qW>YTZA1LNcK4a&a1i)A=(_QTf3=E9vjIR@sQ zFG{R-?A+OTPG8J^X%J_tlj4gv-28Gj1|K#X?^|~3x~QnA=#G+?LRYd(O{94D{rwg_ z$GY5aQjVh|k_T4s2Cy&uA}?El_{J9bFa)zy9Y_RY=Nnb|~&_t4?PhE-oOV)oa` zGBPqw`tm(=ev-iH^XpEWI(6vT+1Y|}a(%(e{Ukqhb#-01bEjw8G_jD-(61LRU%S@! z=uwi0xVZDe00l)wMpjly!H3C%r?(wV#vwO zT^O{o;P0=}z{>LSav6&PhTvsB2d}OUXJq*I?_Wnphry2Xr%rKg+qR84^6>MnS+k^m z{P^LpGGx)xrK}7*_ipYfdn;vQWAotkYi*T{K`UG4&zC=S`n2nF@$UHSZ0!;&*|hWX zbTjw8Gq`HU@Zs}k;cIdXvu4j;cs1+clP4)fHAnxLi-PiLMt;7#rzdCF+Nf6J^m7YV zt>SvW|G%A$jZMMlXTCRX-}b(AKfJcfQOADw?Onys{no_q-{)?8Z%3iBmbUi75Ur0l z)8{K{YI;66nPSv@?Ao6zN+k0Vv#)V6lnySCQYg}^j z+>5VODe39T%F50a-bsgAI6M0L*%=(&gMx(i?A`nD>C@IPUrMG-pZ@sI&(DiKZQHhO z!s(|Od3j>%f`fvpZWO-0rdv^6o&4|5PYK&96T6>JCOg)a`lwA-R8>9tU`hnny7>Kl zr>E;D|Ni!N!pW2k+qWM-E?>{{;HLWXtEE(5^z|Lvka$=?M5M*Jo$uhebABat!EZNj*x=yj$7f_@Bp@Kb z5FQ?$bAO+#pP%1}^XJVgV~_kX7Y+I=pHatf;Apq_#+;i*Po6$iw6~XExNzZx*IyMf zi~bx{m^T0J#`5=ZK65MtgO~XT9!onjqw(qK>B@R~eBENYhgOBI7LbwA`4Ai&yfN>t zmBv&r7B)5|O-;^retEemUky$FEqm7gHYov_Ye2!MsM4&Z{NK7zhA{CPoC`h{lczb zQ0rTNuC=xG=Y!4cI=Z^1Rr;q-pYB%oo0H(`%KHDuWByfFv&u?JE*w4T`l0^%y4XF% z&-rH0nl)qQ%*-p@Z<9VUAK0C3AAY4>h;B_P<{IGHczu+1T33s>SlipYtbAE{t3M zyqTT<$A^c`ufA6O`*4_l($Anj=BoBd$;pwSp{j4npFMqAczs>$q_5pqm(QqA`gwD% zS?;YP%IcXyTUefRcT zczsfe*Po-G+*e;M`u67Lp|4+FUXF~8&W`!BOYQ-$=*`==C#!^NU7c_{No#H7=4JQ8 zH=ns;?>oz+bAJ85pA&8;p5woK;_ltKoSdA_dB^Rw{yj^xsZg1I`seNZ{e}hx1t)S1 zFL%2?`(to?zx^c3oxA=&j|*mQ6Ph+{nuKv0PoKPfUpv1%-%8zO2X5b%uG%ZN+<(4Y zR`8h$#>8{|3y*fo)pLKgpKgAb$M}py)gN)D2{R7FWNZs!U|>)!ag8WRNi0dVN-j!G zEJ43=9mO Lu6{1-oD!M;Ip literal 0 HcmV?d00001 diff --git a/images/before1.png b/images/before1.png new file mode 100644 index 0000000000000000000000000000000000000000..871ce80810561b80bfd06eb5ff3503ec53162d8b GIT binary patch literal 4537 zcmeAS@N?(olHy`uVBq!ia0y~yU^>RYz@Wmx%)r2~cPWoL0|Ns~x}&cn1H;CC?mvmF z3=9kk$sR$z3=CCj3=9n|3=F>*7#JE}Fff!FFfhDIU|_JC!N4G1FlSew4Fdx+Lx4|+ ztF>z&0|NsG2S-3afP{pEy}iAwtE-NV4j&(%tgI|EGqbd`^#A|=6%-UsoH(&)(W30^ z>^pbvSsi~=1TU%>sY4!B<%$_}a=FFL=PMuOwQMr2c z>ihTaFJ8R3aN$A&1B0xrtYgQH<>lqwx^*itG11S@@AmE6Y;0_2&z>zPC|I&&$-jU9 zf`fyXEnD{P-Mi19KOa1JFefL6hli)Gu1-oy%EiS+RaMo&!Qs!JKlSzX;^N|#mX_DA zUuR`yy>a6P7Z=yxzkk1e{VFIZC?q7bef##`zkfe?@W8^t;_>6ht5>f+a^y&7XQz>o z5j#7(va)heP|*GR_vPi~&zw24a^=d{*jNz}krgXeY}~kU=gytAwY44|9tRE_c=6)J z)TvW@dwWexO!V~h%+1Z;ym|BU=g(KKUWtl|?%lhWpP&Eu@#A)OcJ1x$9UUDB2?=6i zVhs%qvu4ezs;V+IHC0zvFE1}|Yip~lteif5dShcF3k%DxUAvYpU20`zgwvu%*-7-c5riZ-@SX+%gZYwB0^41&e75F%a^7` zTwGjJQ`7hF-{;Pq`}XbILx&Ct3kz##XoQD{$Hc^Z`0znfQ*-(9<;BItr%#`Dc6PS4 zwY_lR!h{JE?%liR?d^T-+BHv4&&7)u7Zw&ODJeaC_|V_q-^|SH<;#~vMMbMttqKeb z{P^)>R8&-GXz0n4CqI4qv|+;rV`JlI&z_~Hr}OgirlqAVSg=4+QnId-m)}PEOvud9$LT;<_qv#ZA-}9h$_;z`(oB)5S5Q;?~=k${G<@sjUptS>z5XTy$u2GgQ!cI4OZe zD9uHI(MUm&lf#jZ)10GAz~NoCrILWCDhFqvrD}(Si=)VdU{^--L#uW?YVCTxYsaoP zH$(4Uz8o8S*SN*=2k*Jx>AQCIy zj|J8-wxq}$GHsa9v*S)7ik3<<=IJe1Y?@VdQnW>Wt=QCK8-!yvno8ba~(UV{4na_m`9AXbO zMIGxo&;GF?_WqGZ$!0eG%8Uup&XJK4_WJUT&0_hH$6l_>xjDI~N24pQOSaD`uakJ+eburzW>kaDS z?3md1_FP`19xVBMNvrR{BV9>v%Mw=Ab{n1AkJJi@(Wy^*O(= z`1#rR1v1}Dt;8p_*5_(O)8EPu~_eDdaF&ANu$r(JhkUiohBr#YX$PFox! zkt%90EC27nf%8hwi;rB~k$2~jY1qF&$@Q)WBRE%PFF8~y)-3k$=ex@{_4Zxn-V*cn z=+`x0Sfo>AFXS@6xK{9ZuUB=ltzvV#w&vX3Q=%{5{gANWtBZxyyEhwe?aHl4H@mfL z)q%9M`WQv)j}5MJ6TkQ8%v|>4@}#5g(+Y27M4hSh%+0sI7bepFab{Ppe*SlvS*baj z-a8-L_bmB9)*h$&N97v9m7y2r_p9gkKc8&jwc&F1L$f`{iq7=AroUM4VkG@N;+X&O z_V*PR;edf8*RZ!TQz(YiBvWyv0lHelCdI{K_G>>}JTUzS`AizHailmu^1gad~F= zDRzkm%2IApY^TNVC#_y4uQciHm)j0AuO&U%aJ_&#>fwwPw(sw+;CyjrlH>8?;uoaz zS?(M)esW(}x^U7DL%GTw@?6okPF7TlxBcwu@%Qh5VBrrFLn!w;RkckX+5_{Ihf0+MV~hqb%0Sl`i14i^UhcY_lsE0Q%;z2m+&!CQQd=ai_bR^!oURsfFMAPp=&QrWS*&??rzuT6 z_ja1_w2zMy#r=itRZoPxQ}X_>@`kXiRb6@7Z1Bg|~w=JnY((-hVkg$w2hD`?SK~ zrO%{AI{$t?v4eM?D(|_sr|S)UO$r1{EM=;)Cz)JHH`)=G{AbV3c@q)~rLR`6azAEm zc2Y!FIosgQb;AwBVvE*+lf5zG)vjaQi&zSD% zIr~Q-TJm@L{qDd|#&IDfm*t;4cz=);7KU7A=~B%Wyoe6t_jn^Z05{>k?B1VPuf>YMC8E(TOHeW@@N9s76lx}r4q^(0sM@BL5S@6dP^pK@>Zi#H!@R^8}S$$u7J_sg~Z@^@|a2epC$ zWsLcgWiRUk+ z!~_=~<@$H|0%P^n#oKbCydQqLk-y%*JnHBChy#1opQgOYwqf--7W-kr&bH}>`S*iU zRg?d}dHsPu=7r+Y$?q@hjq{teV*lQrO1n^=;_B~n`{F;I((HK(=a;kZHoR8+!)}T0_1z|GmuTB(-u$ta=i_HddB0;!|3xI< zA1kYRAL+gQ{AO0>;>-6M7+)<`iQcuEA-L*N^N}hIUz6+c4hugOOo&@jeWduZO!&L+ z(m`QE|y4@xMOO+v!`*lr1zm_ojZ~sm{aG7u2jgezo0QxpCgRx?8_HwljNp?VS-GVm&?LfQNIH zw@+lo)h}uf=Ipr_|7Pw=pX{?DGJnIrez_v_r8?@$ywCmXqBU|Q_CJ$VzjpcMXQOY1 zac6WM+?Vc4JX3z+hi5?kq>U%-HcsDoV4tph?UVGE6+h4YmlJv9`}b{X&ZEoC@mE>g zxBgF9P-D47)=}uU&0m#8{$`$W9~3uS(yFt``TP7QD1r8$x?w2yCAuT@r@OFN;=GKQ zx?8?o4RhqX8~<2y*8c9?^G%0;;>Y+v+n*;}^S9^A3*LRj?R%_`+3Q)-|` zZ1azr6m+_^dG6$xzuQ;MPs@MF`>pr*!PrON=F}g#sOVm(ZZ$3L*`A)-zVF9WmsUTC z3S8@XY|r186DLmWJ;3lYeg6ub4f*HY?Y><+bDb@rZG*kI|76>F{-VYY(%$L2C363| zy=d~L**yM1%ijNTo&J2&^o@J}%h>PfISXp+OtVYNE;&DI>E1A|@Z*<-zCSW}yZ!%E zu_=AE^&GF+OQKEpFA2Rg>3!?hPoL>09|co0`Liuf^NGHTxsz zv&hD9w$JCL;`r@W^3^p9)f=bY_;8u?sA{S1euoEtCeM#&n|pu9$1iK4Lc z{twf6%KIKx=&aVC=bP*qlxpKMsg3i^@v6_>#jdH1wbgdhJl{kgT{!8A!;Sgf%Wuk^ zUv71pW6sq2RdQ3WJblHQS)2ST`t32pZk_rw`gYd`djX?)!GcC=XAA3pO7CP^ za;CcaI-@dmbJXb#OFFyMJVcnMd znodT152X(LXDnh?O54BCSe$`@LAAs+q9i4;B-JXpC^fMpmBGls&`j6RK-bVR#K_pn u#L~*dMBBi?%D^BzUNH Date: Thu, 20 Oct 2016 00:15:31 +0000 Subject: [PATCH 0466/1080] README: Use a more minimal example iamge. --- images/after1-smaller.png | Bin 3826 -> 2517 bytes images/after1.png | Bin 8753 -> 5842 bytes images/before1-smaller.png | Bin 3807 -> 1589 bytes images/before1.png | Bin 4537 -> 2636 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/images/after1-smaller.png b/images/after1-smaller.png index 46c664839f55377c64ba8ba6f670bbe0fea1249f..768294c3b3cdee1b8bb60849faad86aaa05b4ab9 100644 GIT binary patch delta 2455 zcmew)dsSGmGr-TCmrII^fq{Y7)59f*fq~%?0|SE)2O9$egI;07w~308^&$*>mVI~6 zoMm9(xasNQ7?N@C?d)owE8$|t?Rl7aID!P;@bDiMUlAC`rkmAz^=_E=?rSOk12ymJ znrsWoHSgw}u}q~auQRQ8+w8Svsh8L0UG@lGc~wa9T6k{l8?8-t9~wUeg;#25mOB7ko)m`ak{Clh@PpF^X#wx;(ME-zdzV-&fb^az;>_4 zG&cXI`IfSq_x~?BJoD#X3!y7oKR$9TxO!+uVZnkTtAGh13)Cr+Gr@YU7T@}DQ! zTj}^VunIdoWwWx6ux5W$QhWTR=*I}L?k8-vd%cYE@-8gi-e2x+KILwMvH9HB^_L!g z`E!S7e)xJPSJpjWCKWUN_<3+s>W8n_H>7aBxzB&|rhtILUoFv^ABrt)O^Z%EyVYR& zmm%Qg*Qzg7wsv;)b`@1smu}wljEj?#Hp^MCZ{Iz`M&?Edg*$Hh**G63F-Xfb7AQ!4 z*l=G#NZKaWd4%yBz*JVP;SMoU_sLVeAO4`04+xfB_~ z^7&a~yXeu5jtLje%S={t446=ppV=s?y@c!crk0hR?~KST`X-Rg9(DmYr8 zFQmcHlek`bgNOtlk7-XNr$q3!`j7;*fW(S#N*g#|yo=xREl=VR=i|1S??Ugsv-W$+ zHeaS#&%RPQ$|mNg?+gK!t!F>HG_*X(#+bh7=01ItJ6+A;THNm+`o0a#p#sZWC!0U{ko9(w;kOeXj*Ba#XvAbTZGTk1 zVBgm3j^)pIOiUbtCP_3|?%H)kps0A^GPj-=cgq#EPn$fuXL~xmre?v`s|&YQO{iPJ zxGnFlm!l(N*P?)^C@()hK3Q4WZ^bjZD!OtOFc+|2V+w9~?7%UBa}DD;$$6blMas%< zjJq2Sv#m5!YO56SaN{xL-oafV{bE1Yn>X=$>W`V-s9`EfYufE4viBEX$=8TJ<2HqB z2DUzr%9Ne{`lw&N641fl_$FxK!*!D`6n63TS--q{W}*yZXX2tO<<|MXiKGWvd?S1ho{_p=V~V*8kkmiJmdXKU&w3p=&G+Y&ItR4A>**}GlD zoQ=s-aKrm94MT@$@hLIe=6$hhKJ9B@<-j*1TepaT=W|>1+P;tf*Bwf6QDC28+i~^a z!>r(QH*cuPt>^EPHP)$cy1(yHQbtx&>FWh+c>LyXJEvnP7!;iNx9Y_<&o z4VyfFzJFMl7%MAleaxPUiGTjo{9f@x@p$-#NNe^vX0P|(=I{L$cilGa(of~K%s#aP z;_U_NgQq;qS5Nrfx^L6vW)#2WKCJj6CJzl(gQc*zPmA9e_I{1_LX$n6_aSSOZ?5zYd^)kn!S12+b6y4 z%XtH?GbJ-u``(vd_r2WWX6Gq4!zJ|w^*_#=zIY>;Z1im6w@=}7&al6ZUV0&cufBI> zMtUPN`;rcWjn{uqI^Ynog=62}Ft4Y_y59s#cut-_-#=%LOxU`Z zPPfGickY}yZ=T$&*|P)RM9vjjB48jpbFcabuAo$A&W9oimJ6Jnw%upczonTvv9WAZ zV_7|qf%uKw`;UX26!Oi^$gxWC&#;lX*VX#Sn|X7G>U34X`Eq$P_F3;SI`?h2mV01H zT!y+k$J-gt6W>LAT=lF&iY?Rd!P5uTD^B|w=mqR)ikrxs@J(Y!)osIn=aTBD?zwF& z6}(357<=N~NxOC>oR{-n|Ku6l`#sF;{D;Eh51zMou1{OGvS)4B;p+DXr|AYnXIJ^H zOuVh@JgHFoNM`FzXthW-pzXJ*IM_paW@{L}v6A~pIu;?lX=7d0guEx8%Km#Mxo^2J(vrsuDJ zzu$j_Ltehkb+V$eT;9FOk38RBF!WPrZSd|bSaPgRHRGK?3sDp?B4g7KRlhj zp-gwlk^|rGJLl-|$n(k9BzQh=mruC8ElzrM`K_&5=YxLN>UeeBe{lMv#;jAkPv7r% zl@vDkvB~Dsv^i@8q^y1vNz9U7w?ELvwBz!@_3npv&1Z|Al+M2{zTV!I<6Gl?Iq4kD zdA>VrCUNWWF#O|BxX%>ea5*=DA(w$cwZt`|BqgyV)hf9tHL)a>!N|bSOxMsr*T^8m yz`)AT$jZb(+rYrez~IND^(PsSHRR@}WTsW(*3h|Myp(}~fx*+&&t;ucLK6U`BYJ26 delta 3751 zcmcaA{7F`^Gr-TCmrII^fq{Y7)59f*fq^lZfq_AYgN=cKq3`s5!-hI1iv67uMLA=sQj#(nYgG0qeX+ncvh|z**t80ri z)}mf3 zQvdt-%VoPiFW6rqBvtl1{OZ(q@9XNn-z(l<{qE;E+vi~>4NdI)ayAtO+EL})4-Phi zILB^)s61<7Cgw^Nt62rj51*OpznAWR^BvhDY)*cwz8$|{t9R|syM5Y^i!Yq7@8FOy zX6utF{2tKeV&B$OFJU>!^zkvn#}6E{Zr^6?PTy1ZHtO4(o6e4oj1wnLWLOiuy>D&w z_Fd7>9969tE-i{#{rdIm)86`fU2=1EZ{ED=te1VKphK#xdcObs7Usw8`(}Sk{E#AK zV<6?!yZ64aI^Qxk>$vD?Y~7P&*6VsTsn$=v`t^1dGhb}WdKGbgr zTYh*ey!&Q3*j_4e!W^>^P+oO$)@ z-3~_9=?~gZubX=R?G78e)pc=uIG&$#44anClwp!oW1io()cfHf){2L$(L2Mq*Y9Dv zcyWP7QN8?^W%A`pYsHjv?1l6<-|V@Wb1cJT(e>9a-@HlrTmS28&dp7&zkXF+?e*_# zx#af33HVz5(Di;_+z69klxG`HT;K+FE>!HA5!Ci9yR2$RchN=ZIdm{q> z8E7)i`_C0OmpA^8M%Cpj?<(eR=SyNz*ney5^VdH0Y^NHYFBflnnV7@zXX~=`n@cz> z>W_*A?Fjv!b#1wE-pcvA%MY)wV~ww6jlC?q-U^}7D(fx15% z*S`6D{^7>sN2K4qVc9GhSM7VsEcaFLzQ$L_b&uznd|L16nbO*RInnHMW~yp77kB2n zSC4kKu-x-SlIo=!=319enmzmUrTV4bzg6FCGO>tZ(-i!$-Fwr4sNE0VP7eAP zGO5C9x&GlD0V{Ia%Kc8x&heWg@o-sLq>8XxLmc~h`L=0%&%c@;SQRPsTPwS1hQp3~ zoYMVH(<4PRRGn&aXw>EgMVVHMWnVI)=y{9wN=Pg|5`1kcqZ*F~`_7x13oVK%- zxL0kdzgTvDk;)89u5+;yk4Bcb&RhHH=ogU*OmoT-LUl^PXcGb!J=H94a^(b z7)=itC9nu2?0lYjU{+ED%Ndq)k*~xU^O?=(bYH7u{_`bCWz7`RuY3GgH{PFDq#IYQ z{a2EQ&Bng=!P3_Hd2IiGwEl^k!&7gg8~1;cNyNnE>+0*%UtgZdbMDJz`ML(}a0O*% zKAD1?1*^S#Uf$Xo5UAMpWBUFUQSGYt2FlD{-bV$#GpGN0`0AI;ySHa2S{8F$d;N38 zo;e2c@w zMT$2*EZn&8M}Zs%e?9xI%3}<-x96uH?~~Q&I@HL_9kYN1 zXMZPpiOgBiBLDj7<|;LjD~Ikas^j++_4M?-Q~&>OOH0d_>`nEv7##Q2Z`$CKR+$$q zw?(r$P3BC;#826CAH3Fm{QqXeN2R$&qMirVGFb_nFK0Gj{UO%DRMc4SXcN~^Jt1P_ z)QSh*4_3HlZ&NzHOvt$(`3 z<@2-O+~egIKXkD9(b=e#tD5FoA1#jC?#J_S_j{-4?K*FpSSQTn{P%A|n(zMkSJ!@F zj)|XtUR6aP+ho&+Bb;TSp^P8mvb4IBk|k5OsG5JfcE#ZT4Z|~CPFV#8FBdNS@v1~e z-nhPvAwU0_yzQxQQ_~+ATj$ijP;B3oP`<@CP-N5Q&4v;@Z*FZ}eV?D{!T$3%)ud7; zHXg~;-|DffrcCFKb&$=yk7b6x9Z^^YDrV2#XBNSyOm^{+?B62|Eb znFn$n#4TWr4tf{&fXB?4=g~vCZNFoCC6Wa4w=-?1+9Y|v@rVHP7RKKbr#E=@i=D{&(dPr&a9v7#Yh3mG~|NXwz zZtg=L`~0F;Q=T@~FaN4@dpp0B^h5LgjZI8H{{5c!UB;5>_O^pFjX!k9^PD@p`S8`R zmbxw?e;2>J{Icpx;4Zn^DXtqgGN{~8)%~26ZK%EJ>Z;s)cjh0jN_^z(WEz@FOBqUL zoE0%KW!zhFj3F*AF6YjUiF4-2l)bre@XSo(pKmswkJwqXG;5*utm^&s@77P>|Lxev z9NQ_k_RiV${#lfjYRJN6`z}h)^PjplytMns(L;ZZIBz@duAb`b86N)s`-Q`MWW_me zh>1BY=(pjomb$GvZv|KV>G+U=pD#tddTlyucIJ$*V1MV5%M$vLn_8Nhm}+WjIyyTQ z4eJdjZcabHDfhOSmzP%v=iPRlD_gq~|9tVeU)nA$Q-7Sr!^z+G@BIGh0Y}$=znv0c zw|08_qOFoYtUG^&dG_59&Y0k$(sAA1O5)R-Wr}73S#u-+Y*t_L4K zPMWa!*ww4w*6)yzFJCsFujVta%|DACd40KcQy(N$JmT~`_w>n$m)&l=-*$&(bLVPw z)m-PlbUUZviMiP(1+A_{+1G#YckA{TNN`+yy)q-WG;05Xm7OyeF1#ZycW(LAsTG+f zKAc>y3g?R*xPO0s{ngdspFf?}Pd1Rq$jdvHVs!D&ot{Upcy4Xn?=p$|rSehT>#q~; zN!*SMV!dhP*U#8IJ?HSV{?`ARVd3|$OGjDfo-(sr^IbWIckLy&4f;#m9E&WPy{f9L zW}D?6x}hufq-Xu@^vKNtIR*v!?D%d6MOY%!d6VRqz1mOFPUcHFqK|6lCUnRQkduCi8t z?<&u6UEKJ5e*59}hl~3koUd=Y6H|ZNv*|-Y#n;e|&WW2(af>&dGg z{cWw|YeVZyeR!r99KKri6cXX%Kvf6Xl`ze?2>+P zcJYTJE+=O4OkeMP==JZYsj^d;r5jsMbawiw6sGgm>uzDro+vCXt#f@J`@W4e;V&fJ zjgqacBY5_3+Auz0nBG{fo4evc%2Jj1wBt@s3?g5=uU-CcOZQIkyPNG*ANth4<7|yz z-kocpz2PTg=KHme7rCE1b@iOT*AkVhUD6LKSXX7f6NvP`e(THAht&@rg?{~2xcckM zoSJiAHnac!eptD_|GZf~t!86Y4?f$WD-T7aAeD7>aI?UDmo-BX(@Ws}szN^YM9cp&(+hA!q^SO|a#pOF^7Vff2Yi~0;^gu!=;LhJlEzYO&m+h*L?`y2vvuDqg z)6?~}SFT){H~neeUmIgi)l>KX7V#W)U+wtwJgbI1XVHEg=YJ>9gmm|Xlg|LM8=>`edMFZ8jk`0(K2 zx~KJw_sXL;Ree|LV_;xVEpd$~Nl7e8wMs5ZO)N=eFfuSS(={~EHM9&dGPW|Yv@$W& lHZZUmVI~6 zoMm7Tz2@oS7*cWT?cBKcR!}~w`-q(G9!t?u0t>3%2>iV^Nuiauh(9{P8{hS|4SxdmcLEOU%1nQdfCV&P0 zFvTjoeDUJNiyy4J94=kFc=6&#?xvbp#{EjN9L%d44)0sn^MAq(u2ZWQylGpX{b})q-yhD zGGun`U8UnoTn?UL{MMhE+qOB}rh0E*{>Nj#xs9XVf4p;yjlKROcf|+CipRV+ww}J; ze^@^w>wjUe0xKKari_b9%lzx-*L{A_#L7LxJYTNV?9#migAJ9R)7bdse8R%S^7nq7 zw*K}S+t7XM8p>Lv7y4RUF)2PUO-%QGpyC7p#^tBp%)kDZZ-!~aw)C8~Lq)%zZ_VS( zw^g}q8GqUkv-JO%|@^vS+WL~cL`EqW8uf-~Qvz-?j1lhufXKxRxwGY<|Duzv7lmX8pY^bEQmd ztfZ>GHdViGwf`rmXC=vb?D*lu{f8Dfemcy?kuh&~) zE?fwhG`u((Mn)OaJj(syfV!3K`Ln1<)S58abraEzCo^(xz*&ui94FJJsPUgFJLlbQ7{ z0wwSH9v?e6JHKkZ)BRfZ{XcoHTyyG`o$fT5bKftnHon%py9u|q{W`8IwlmIo)~)(G zA|92Ml__ayMkyx*ii(RRZL3Te85u#L6&&pB=f_uAShyx;=cL---zxt-+{Uzv!PCK{ zfbnCEvFXAdJ_r5>d`p)uJrMZ7;vN5YYo_|WjS>r3et7*Xb8RV#bytws!6B28^mn#L z*QZbCV+-G$O0%GVg%>ov)VjI#D%ainmT^^R*Aa)H?2bH6@pXqECK*)j zlsl`c6v4(W8{N6{%cD|@0FGs+_pOUeewWGJJZVYa>b@Q2XIu0x>=Vr~yIJm&nfJTC zOx&ft{?J0D6Sm58|INKvP`>An{j~6d{7-|fiSk>@OEzqg*qQI760^E3-|NZ$^Sam8 z3OAY*DAfE=oU-F$;*lc<{Oh%D|NkXEr{IB*b>GC+YzQ}d)T z|M_j6XJ6Rool`tJ&vy3O=|GOBf<)miH=G4>oSnrOY8-s3h!tqFp%9GX4b}=y9%;I}&Wp1YF z_eyW>q4{N=>JR%_Bmp*Uj~GTcynto_M^tBbjziq&fEUxp(53#dB)1FWdCgR@TPy!}JJdhn&2co@B&G7=8>0eq z#DXhDsC}M_N*k9Bz7O@SFR5?}yo^JYBOh z>%|pwH*7uT|5A0?gXPz|%N7Z(`XXb0gNJ8pPJIOT2}!nzx{1MzId+_`PZw>pnZowH z?7}^7V*t+%=q52i$E>TkG<9Ot&Y@TA(n)%=gZz>+3{6M+X~9JXp88KIQil&s_O=va>GNU*Yb#yCIQT z+AQZlhDp%k8w%B5UmbniZ||3wsMsy0`zeRJP3h1Ip&9IRwp)hva4f$*@xfKW18r>A z-5HDp5=(e4F3Is_v2H9qu)a~`z(tMH4MlH4m�)Js_kYBf<1%^TE=`f{7ukuUt0U zQO2M2ZZ`7~#>w@Jz4Ga)y&3%bgiiAeao{YFqQYr zZMFXww2q1@&54s&RDLEnH^JGMsn+)7k8_tYuUmV*_WhE3#v{0V(#gH4 z^UllfC}Q?n-(7aWEXF5^LD4a($WX#%LQU%8-WDyXAEC4FPnh<0fBpK&JOTeU2$$XL zY4o3daFcC7fYwd%El)b-lzO_>AI#t8(Aq1u@3&3OY^MFMUZy4PF6-pf)8l)$KfYy> z_NrA!W+wcrDYOFB*kL|~!s=aZCGTWvz65@jy0KlqRYYTf2N+bGyElP|&co3ZVThO4K_J8InXT%6ztatJW zWq93xdw#w_Y}3^)w|mQFOER9mj=Fut_vcy__sH){k9KkLEeMZ({ciySXMx_HG}EIQ zck7rpysM~9T$03SHgk)q@^-E^#Z&*U#DBXk?xr={m-m?yj~|!GY*jtZgew{u7n!zO z6duyrqvqdsBcd~VmVu+m`tA2Nz2ESlYl=wy46D#>_WvYKoieGZy7kcHR_2=<8+l}{ zrZ~6ref+-v|J}`|nf(^>3>Lm&NA|E7WSP| zl791^cT31N`_iCqX%BXtHI;i%B6;Q>)A~Bj`~mvczHO_6%XQsL8ozd~0vV=a$9wUAuGD?N&(S>l>8^n|OZQNxN-kc-7Ud z%eZOxnn>j)O_PwMwq?GPD;Jl(o|V4J+pleBv7(Ag%&zO}>c8G=&Q;=@y!sZ~!L-!W zM6+s(&Y4z^)-o=$vOIt7$z`F}Ha^)$g!$Gut=?%-91{5U8n5+Xlc&2yEuU)P)iYkZ{Pyl`RI$G@At;A6NT#OVwdLxCzDHkw z_;Mc6zNonEvwPI``u9J76^G4Rw)WPtqUW=wzx_X(Q9LB{VETN|UvmwURdV~S|E{>H zvut-Ow`v;4to&84uXwfuW~?|O^7rTYecqW**!WCUOgYN_{`#78b5rZJwb7sJ-|c=M z6cf{PGDS&Uoqh4e8&j$+-FX|0l=v9>>{fPMShaAU`0TaEidO%;I4AQ+-@T>39v2-~ zjVW#GD0v*ytFeQn{*Go;@K(upo$Y77-P^riTS0bvP;I*D~{auQ8unu zuX(N8ZMQw(XLdoi#6+XzTT?tgpQ(*I zvaW3j+re39(>871%*n--bbDKFN=nLx^z(8_$;mUV%k?@tJ8gbGnSAStORZmP$MUG) zjbC?k)*s*LyYkC?Q5Tq!TbGyK^O;SSP+3F_mfb_P|td&{0b4p{fJQUP+>qaMh$&j#*V`;XQ@~RJ+vgAWxgf~b&p+=}pQoU#+&on~eA3LBp5Ncy z)zr{kN?a;Tk8**;uD)t=ca|miqSRb>~$+=c8 z-p32_TK{xU;xN;2c(yao{8Qb8eC7`glglRvrJ7dC7MXv#?|q}{R%x$r;*u;o_9=|v z=gWfrZw^nfdvW~IzZ&W1^3nCj``VTqHCy~)lF*HXKX&v>KmYYdQ2D{U>LYu$m8@JM zzbRrtef`Nz4|)zbR6JzmY_P47xL0|6{qr8FOCAck5gQsFJVFE zi{CC4aeAu5daJczZflOb3bN(obSQOM)ckk8Lb1)k112hQC*=MLY|qv;Of3C6kE8y^ zX9XiBf6d#^FNP?vN~oOve%bb6y6qadz-=q$y6$J;)Vf=@`kcH}P$cut<*C(|Vg;^V z`na<*ZccTv_~q2q<=2jsWCwXh_cT6w$gwC^rs&~DQ5lZ8$tur|N9QsW26%L@)Hk?N zx#SGX%Ps!XEBF1q_vA_H>SNzO?|wV`agtMFNBvsmNzrE3tfntt-7PndlR7l*N5zky z=Tob%YFX6F?fZLemfDMz%Ts!l-FsxU`vj)zoiq~O-kG)}X#MS=<^=zFHYYDF_0E46 zUVQ!Q%gf8}?PSPhYhyR*o#%m+^VqBSu>)TUWJKR`O%$NGE>`?o`H>uG{S;u38!hyqc zAHHpWU|;3DY0~|7^C~JzXRv&W)cJ7FarMkI@e!pVuSA5I*7J&=U+3`DJ>S8GdH$IO zRelfYzr9a?KggPT#`#Yk3y*)>3jsl$yN@1h{e499a86_Sx0CgIdX$@(m-hVpesI3~ z&G!$sx|!ZwdaNV3dF}7dGmUoCFk2n(y82>^?Axf*->Rj%S^q^#Dl9vGaC7ae^XjTw zn|3eVRHxTQuz-r>*8;W3Km}ro*UUZ9RLH*6RAlpPrtcX;rFK{OrubW4+QxjvqHp zJ0lUcCgR}6Ej+yu4EIhpvI}#RW&)iGGD`e|-^QQ5MFd8kL{wZ%m_Q{=Lz;*thy7H2dsKdln8D0#}3 z_xnGo>=lh@Zo8ZIHp=km*Z2JLH5V*izB+B>dMN@#*=Vy zk!wnNdVO$Q+_^cH#XtVOuU}u=%hi~pa$>9fqPs528*SAmh}hgNd^0Q8F^KCe<2&|u zZd;TE4wgy$konEWy47pvxi-hrh`ZZRQCn}a7FDmwA6K4z2u_k8`6wu_xrwmm(f zdSmgLitP7s3mqqE-V*z|r%mtJw;+kTuf8gz&6k|L^s(H9xRx%%fR?N{#hS81dvB}^ zp8oJn=<3QKUa4;;>RwMP<#n=bzHZnrz^3`J>HhS}Wq-GJdDj#lo#RtcWJNo3d%JK7;-(S1?nye=w4&hz`1ou2m=p3C*Szt133>xiE}Xx>dZ~X-zSon*#lJ6VdWpr_1gI=CnJdpI z)~(kw=Yjjl@RE{}5T)j$I~OmCvbj{Ud)K-D>?Ms$7C&z9@tCG6C-&|_ouZYjY`trF z)`g27oq5k+QOy=LQ*Ht+%Rc%-eJsGMxI4U!-eguwQ;!0RsbrYKdz^NlIc# zs#S7PYGO$$gOP!unXaLMu8~2Afq|8wk(G&owt<0_fx(YQ>rbL+$jwj5OsmALp>w}@ SDFXuogQu$>tIIm4geCyYJPxM- delta 8740 zcmcblyU|6lGr-TCmrII^fq{Y7)59f*fr0550|SE!2O9$eLs#`5(TR$Y^}^z&EO|R0 ztzckKH1%|G45_&Fc5Y=w$kUw%>L=GKT009lIYlrh8oo)4XF08l%?&TNiE7%KN%4Y(m!8CMBj#oIy7^14F6o{n zaMHmbfKR6WQ%UkHzK@9k5%<2-Yd>VXpn2-sF6Es8Q5QG-&aRkttfFq~sq-r|PMmID zrR9IWPtCb_qWsxbcVXex_VaZ$H}3T1J!+w+*Z1T}3ZJ~)nWv|x+t%_*N%?jq#Luwx zusa{|`sFnfLpdfZ#@j#o1AFSP396Mfl`ciidke;S^7RarOF!JP+L8I;i|Ebe z&Mhyu=bl}|Tkz2B@VoU7Bc&eyw45@(-;OK!_@UeRhu6i<+b8SW^i0Km7V}cJ)6x~& zcHDSYcGd3Ky?gg`;`Yo~vqr}(=Y~UBnc4pTf8T%nw5i1T+RKuhJ3A(B+GLb=X2!#p zudierDtUdaS5!MJAS~?IB-MIvo4YdGgNrU-*3DQnrFs|RyTz^gF54Trs-!kpxu3e< z;n2aoaewUhunjeV^O#1OeIARM&+8G98@5RAKjvrnVxuM3==A+BrS&!EIxlmuw z*R@KE=h!Xp@{s7B`Bkqp)6UH~d2X)t&qv+*72j^ASH4_2{ltkA4<`HDt-P0bX^Cf# zob9a3%l$upJT71T%gXf40_L9Nn$}#uuUVXJE?jKwdG^}p&uVVd^o&l z!D<$E=iA#1N;K9)FvizD{UKp!Snz(YK}v_`!SAc$=P{>0ZEyQLMS`bA<5$Pt>+7>} zpN8-MCCb*^Sg#qpY{KNphwtsJzPT}(z4+Ogm0>-#wY8Oxd(9bU*jAgF=Vz&HUe>jr zpC?;;{(h@#7SDOOxE}e}{}T4M`N(qb-o22}(7>oDuYiCF%k$k2KX6>!=63kPA^tkc z14{&?MIJZp=P$W>+DMc0-yZK8mF&e4A5ZTIu>z$M=(Hjt_cmKMu zZ{3dhLB>aK$i*pe`TqX)c4xsuCQD08h9ygv28M>ZK0h~?lZS^T;ntQ+6;;)Zxwp;2 z)()R*VyxC4H(%xgQQ+qWuw$&!w# z+YDE(X}KQXUitaR--l-;SFC85Bl9zUtH}NO{cr!~-)s5y)-^M36U)3Bp-Y!yvg#+P z+285kIe+81zSDjD4z8}OQ>RXCX}MC8v~tawC7U))x^N-j+4=eW2i8PxHn4iQeBndO zs2SSFRKME$#jaSjYEl0Eee?ExadS47_@92!j_KF7Y2qhcZ>wHdx?ky;*6IfjQZ43i zpa0svclv@uoemOL-3y+x`p3_0bGv+K*`G5f8kFnZ7gU$;`0Q8l{qC{ckV3;bn;w_% zNNm#;-HBA+k{JDM1KY#8iekCF;%Dhgu=W~W#tyraaezSbIHq~Z*Om3PcZ+oP)mCF=3(q5JuSDB6tp}pO^eZL zVZK>#xbeJi1Vc$@Q%gYyPs1G{iz&>K*K_mlAL5sLtvWwkW^#S;7QV*1LIGKweRk=e zo=B+rEm^zr_0P5PImb0#tZSdvCoEWY+3!nr`J=8snOqfn{$FW~+i0NTcD`}JUyl5xU@kCkiu_ks_A_tp%(VaVqH+Gr_^tQu&p+}Y z!Oh+Mv)A^#JDZc)cdw6*3t6z;{9sqN^X~@<|7`PQHZn4b-9Ey~W@KnK?Rua5^QFq} zS##_!o$r6j%w}MwcI;90-u?D_m6d+X_nWIxZ+Io|;)=2@Gpx(??EidV&c41b_4l{8 zJo0vXe*JD~VM#kT$1^iiQ-AN5pyqow?yXf#&{;2%6n$Xx-`wY6I;&guziXFYTV!1Q z^1;279mXr4g*<1zyR`UU<@A!U;y-&6Gn#7dRf(yoAM{ZDaG>Mm+ifq@YNoL5-kh_2 z|Gwwpnc|G~{$B-OPc{9na(JiohLr7pwk``_!=aMhrV{b5{!`ZHfS$>dC-3}zulnZh za{cVPt^cTM`h1;U!5^(Z@9Qp?Z_|;Bvzl=!l+Dh5_4E38^Nm*f_HSn_ z4yt1O&Q#8{FYL9P!<5JN%&vTWg6uYoCEGW?vs2*y!B8M_L9(91hBab&{Vw(hrZ)u_ z{%M|il)m+y-2;UWb`#$Jiw<9KJzDjL<-r9-i*mmhO*Nl} z{r~rV6OP}_mYQmi#-pNIfAG!CfUKv^H@4~e%-5T?Y-jQ7y256*&Y(GSd0SiG?JYDb z2(7C~`ZMSLTIv11eq}p+XCH7dpNfG^JW0E3!NO+nsf>H|Nhk-=#BIN$kPf zv*pfh1_oNE-qqE`#ffoMuRT~Ey)7s4(UHzQKcCI+ku+`-R`)Z=zNWJ+?{596O{u3p zeE*()u!%J#HT9wd%kP6t69uFgUi%+z^Vt!jk-tFL>hOncri(X~o-ld-fMw%{e~&rd zoSzo+aBlRe0~d^?;$)b(x80O~uNl_LJ(G$X^42~$`0j$4Od9W$mDl!8zf)b8 zFMGzPb%t2ME2}rBnz~s70`xTJynCbbe15&TOx@;<%ie!*&%88~q3URdQfwF}_x8xV z@M}CmZ{6M8HYFeDJ2YkG)Q^vkZ_c~Bi_JEDg}si1;>8>0rxLGnT1?j0+|8zX;DFhO zEzJIcbNS}^Pkr0tv1_ri<)l~Ik@}W}!ATFU-cEeCjBUe>7Y)xF4mv1);7_m*U@dVI zc|7kxcl`mToaLe3OwW|Mat%K)7qA&9h&{R8Xm+6Hf$4#;njZNNMi=BxX4Xh-WbkKF zYLGl-xH)&r|H=e~Q@k!ZS42HNPMFWAd0@4d^xZk)<@Z%*@^XD@jpuLMUcS3*PdDp_ zGUa8-rPKd>7Lj{z|5YV;REle!Wz0 zKYpk1t(5+f<@Lo|7Bu|t>VLl2u6EUR+sg}^Ta#?8HBUNe`kgK*&@(q|qz^QZUB z`Dme8v!g@#QcnMT#y|b<^6#zA*}ClF;pg}l_3YoyE_5g%cvNX@E zuwR?6ut+3a>#d2t&?ff6!!y`lG`?(@eKat$H6pm))>Zx z&ZHX#9Nf))vPZdMlG@`cwcrr@+$cD(-PIMGMy!SxFmR{P)jw*2&tysDWm zuiyIe>5*8;fsm)4pGRmN)jB$3%Eg6d*Y0=zP@5hUtQn@sdXH5s`TqUu+&`G7c^RJi zc;zN{wt26>ky@q%({0+%QyJp5=Kod{%P}whV62IGlzT5V_aQUClEcJ5l?e!M@`ZsI$fzmw9b%G4FNxt`gS9mU*_C{&)obvBq zub2KQ5e&!PFjja?K9#&2Me?~q1d{Cl^(1W+R8~@Codi>ytu(dgI_2&~z zJ{{RtYpQiMcXw9NiSM63DFywE<+=Qt^RsCrZ=7Y-mMG1zlUlk@FKeb$$`rux#)x3^myS10`3bGvc-@tHM0Z`(OpZC?9w#hIGl zztf)`oSIZ={7#NH`rNMnfBFJ+BNlF5;`SxHeqK&-!R!sK2NNE=+x=e6#%4}a6Vs|y zt77a|Fju*Br!L=escu4tVBj1pw`(!i&CfkK_UJ|VZbjyI@72T>?^~PuyX$(lna2c~ z24!)Et+PU_T{y$euV-%4n14MvS~G0tGM#T0eJn3-I&BSVjk@pP(7XA^wSybY8NM?+ zp0dmPHj$-%bT*1sqoVZXSSNM6%S8suB&xg)3%M{TkFTUS#|d# zJ}qDPq2hnx#4|Q8Mcuw1cOkd86!7pD(ZNBY#ca)xEy|_WYL@*>8vS+|{j@lJ5U5FCM6SO!myN z=P9;x_A7dQ?r=FNRP=@G$cjzJa(c?(Ic2%;sndyft#-V(n_(enmMi34lqX2 z@2~ESp2_-JvhlOol&l8rr{_w!c6V)zI+OhM)zzGPduD$4P#~rsccz6?SVK!I>F1}X zIx#yo+gC6E79V$?)tl6~)@*hCT|I}Nue(`R zSvtMl^lZO=G55RBn8Oo2HeBC%#qr+Eki456NiwgFY|DG}rS!%O#f#tcd8a>=m!qzy9%3YuzdT z-D~3YLq9B9ys*Ch`QPfzn^W&wzn}6ye0|xu)ff!dl$!)o}Ky(nsdqK{_idwRjr*T3(r`Gf9MWZwzZWWO*g?ql5hM+cW(O zXWzeFl=@#oy(zAFs^gKh*J`%zPgkBP`>Lz*k26nS@J3UXSKT#Jgm16fT%RweF|q0o z*PjBnHOEf=TDDkXxAVUWAy8`5)G^ZiyCJ<_ku%u73VqdH77@B9Z?UVrlE9JIs_n=V9{mVT{EbU5m9`Yrk8e@cr( z_HJGg$$n_ogrk?{emXB)vFHDeMjzwyt|!xyX4)6JGF|*v>zm@8!yT!$`oW@^M|bRu z-@p3PWyS1k9_J30y;YHo&V5nx;mhSm@^dCCTK0Xdui`v*d1r=J(DEP6Qi@#LB_~cx zmz-j>D0Fp|+{(Ho_cxSmdoQ1Pd!ntX&7GBxuLgjUlX>2qgo9123_Nl+5)JzM{|GI< z=#iPJdB09u(1@9hC*z8A0{>Q}IsMajDDG%l{Gj1Q!esfIiN^6>;pgu!p87*Xx@XeQ zLka0}PFu~c)VF0daugkueH`|vWl_X7o=veau1kx(Z{J_8X}PxazdwiFy|kp@2BkjAAJ1xnC*;laLLu~pf#r+GN0;>e}C=LKW=lK`qY}@{dM6_mpiYE zX?*LIXLZ%|kl=k;-qtTv`}?y#5WO?oM7ce)sibFv#&+)q36a*@)d zvpQS$zq&JXUgEa759Bj%Pdm@Xv*KahL$2uJVqK$%JvWwe{|h_L|MlzBjYnL%-_O}5 zvH#br)jxj!-dym|X`R+e!=|Yx>JJJTw?A`IeOTt~Zf)hA$(m!WJzxHXB4hTqj_nU; zXV_U9?^!z~Wb3ix+{?6oE?qy}%aNgcuDu6mmr=;g{<81i+fK&L*)8wd^>uyh4xS&+ zDqb%M@Ca7d(CBb%W{Z51oTFj%*+*=Sd*0@|iHn*NW>g-Se$!2|a#_Zkl_w{?xi3{8 zpYOSowP@X!(|LOuf_zq9kaOV5yrF#W-1m58*@N;GVkgaWx*0uonUqgz)O5Waav;pg zDgHs>)6cGVR!LO9d@!B)!O43c0{myPZFdWeVmspb@6+0KY?`|SK`rXcj(?Be>%Pl$ z+-JhID(Q};mss)9uML;3U9kw1TbusRM$bN`{z&N0NbS{OC-2|R6F$AsHYw@BME573 zpU*#hwENM&1=H&5{uE~9s$XBZeLKt5udh<8|HhVgKE0XHAgnI+o$Y$_F&TTty6P(- z5sF8Sx92LmZ`x2@&gSNNQB|eo_v6Pul}xAl|Nj1bVGGMXNt+o8=2Nffty%MA@tHHP z{tGuZ-!!SIx2RQ8;`sJa(NwF8_i&rw+ms0lT7QIhSEi(;ZAv*g>DBx1nmd30`uaM3 zqwaxsclD;V7b(w|pQw3sg+s;LGR}$*VOI0`I#ud*SnvIsIi+S>`~Lnn_9l*>eBD?) z9(}d%o3_P-VZO|YnL#I~ewN>@<+X9X`JIa!(`F|{dld4gvzykNR_>n8S7$7->!oT} zWr}shW4;;IN3LvJ<`EDeQ2qTKXfSAwRcY6fB`VkXUok8evU|8Y1&^N^6F26KtI?H)6)rZgV69~tw1$nKhYUT}Js#uBZ&91c^h ztrVmxcr-T|-aPg%ondSJieU2xzDKI&bnLMB;;!}jEYm;s$==Poe+XzeaP|CQT)9cS zQ{&a$DcP@DB97TJEnj3k=SYW$EyK&%@;(j!-*La4dUJ7{;fLK5gBBdfXz}N}w#MdV z<{j1lHm%mb`}c2`Nq(qNkv=Ea_43^n>qO=*a_O7BT-SO!e`V@~D?w?W&)=$_k^5oC zp90466aMXU?DIdp+?sCs?NgJa@sU^6pHyZ{cl`HC+oCq=n(hBRA%`|Un^*1fah@^z zyZ!M+lI$!U_8)sBKh3RLGe<3D-FC<1{`m~|<8~dfUhZ>HGjZR(Gp}z=m0j#sSo0=g zpNH?$e-)EMmpK<02%dYkysYV`dwtB{}N~Ek$>L`QsJJGGnvM;|Z z+4J>UG{c#h#_dJM>CgD>|4c}qSJ?*YGlhk@`S|b%tNT59+;9Kv$H&JeqMuGD9PIya zNFh*R{!4YSd)h~n7{hegEsst}o7#3E=GdRN4Ju#i&mEhxJ zt5~(Zo+r*W`k>*_^1aDRo}ADz_K=!a=cl3KUX++VP2sC^JvG{tZ8#$Lt<&X_}cV_4%D)0D*?FW*qe+_+uvx}bTI$)Qh& zFFmijC;VvYbdRa~x+ZEa=dkmc9FphD8~%j_!NE6om1=8;uiJ8C#f}{_9GlrT zW?WQyc4nq?Vxr>bXJ;Sx*Z*03J3l9NDvR!w@3|Jc1)k-!D0=07J5o^jT5nxL@byH0 zu^ij%{ZF(!*yrsH{M5>qrOYU}(^V*Tk79lBy?@e={@Bl%SnT6B>F=%=534$tJddpM zSaok}cf*tjZ^cw@<)C}tLey7Ix}xU8cB1&_B7^1eW%*B)t3yIU0^;KQQd939TJrt< z{qq+WyRUAxzHK?nu2?zS-}CE1YpV|Xc&8nAw(Iww*wx{1d2{x|Y%Z(7oe>=RITIKQ z0;DD9)YtBPDv^0}!@CgX=Y40{o+%u)VpF49+y68JYIm33v zYe@pEzXdi3-fqmFda6)%X6vdcxo_tFS6XzVpM_1a)w^bD@p8u322bPi82DnQDY4`p zK5Aud5vP-2KX>|{Ly@e!m-BnvjvJlavhZe^nbf1MKb)WH8$DLfP%5>4eI;R=SMcs# z_B+=9pL4RAn{}C_+14MP&c&~0-Fe?UJzLHH#(ZAqDK(Fuf0lmsD^}9}?#DkdQ|I$p z7CLF&E`7x^S?%Ece`!(T^7`xeL`65$SjKF7m|pbL=+D>nLM`THYa$l(%NVZRU&b3( z6DacjV6&?uA79%dCCmEv<@ZnC-<4qCFl?O zwSBhyYAP2@Ra$0;hR)H@NpTGmn?Kk7{LxO~k3l*|W1Zjlt4eNVO^#qVreFVl>QeVD z&u=f*m2h@;?oB^G&s3_{?J>K2&4Z8MGET4E?(G7MX7jv!Z{heYA2>()eX?~C1CR=LYkYP*8_`V)&T{>cz$lvO%v`|OJ8_5S4-Sq!8eIti~_b@|A} zW9NS@j_eUNX)e6%wEp_$qNiS;K7E>DmMe8EEns?_v-9FifmiyD9Y@Voo14{aP4ZN? ze5}80YSO*YZF0)5FE5WAIbx7@MnW%c&x>D-rY0tNl5X3lhs@spKd|UrcE%mAjK|Bf zUtEY=#`xiDlbx5>vd7^M-DWP2F3EoU^r`FjcXusIUQBq+e)+MtJ&st|P{rKvpZ$Y0&&xv*eR2#845}rr5hW>!C8<`)MX8A;sSHL2 zhGx2k2D*lpAx6elCYDwvhS~-ORt5&F>3kniH00)|WTsW()=*-#&6k0Jfx*+&&t;uc GLK6U0m^|13 diff --git a/images/before1-smaller.png b/images/before1-smaller.png index 78fac4f5c45ef4488daa11755a9cb1710867bfa0..b29551eaf020276e65ae29976892d2e3de3e8453 100644 GIT binary patch delta 1536 zcmcaFyOl?=Gr-TCmrII^fq{Y7)59f*fq~%?0|SE)2MYrOLraB6?LmRnVRIG zhJ9C@#QoAe7j=GCNb=S=Z7LF6{F(pq8|LuhwMu6fGtON1Y?+10;?~Wk_EO&xBYk+Z zL)^SNCq+GEPnfjyz*YHuvgfO7?$;N8m^>%$y!@T-#rD^0ZQuVbnD^WEfy12x|7Ff? zyLW(>Q&<OH~T=dHQwrr`mF?nI1r;0d6G@3L80rV zGdJJmRmEQ!(z$g@6k0B)Ogo4)?VRra$7aU*I)xvXzw1V>nm#=zCMm5>%l1W2H_Pp90>?FWH3nvw8}H2$ zJpZ?CstZp+PlercmD4wlax9qXGVj?8&G|d!{0!TRetl+kj>y^E+M1&_HFS@^0K?-I zYTc0`(%aWhu9-HW{&d+P2KGF!6DiED)A&m#<=HSC@XPAmsi0PHXxoH+zy1k&-0vw{ zbByuHCB6vH4p#g5;y2s6r=Qqs26CusIA^Si`m!XTW7X7pJrmEXue7ds zPCd2hjD_RZtSdQNxA%y>NYB0EmV3qSY2*v#D@T{BSNv}LdiL>xB++$ZywijCM}NvL zb$IBcamgvaZJTCb;&&281xVwK~|0BK>4PsK1|>H?vT5d+kEeOxZhX-G^I>u zK$Xxed}02oqWza;?@~T9^ST{U zUm7piT+MD#-CrN(Tx)T!N^@24oPe%#84It^vb?omvuyq3qLyhZBK#HxgjQB%zpfH` z5xQ4VWC@dK<*8&j{+H6S7uQ$0%eDqg;R;>;_*a0TQ*cPun&{P$P8yy|vqD3MZTAkTKCt?!5_|iHIP=fd zzxX>9>KPaqR7+eVN>UO_Qmv9F*YoiO85x8a7+4t^S(zAX8yHv_7@XwV8iJxOH$Npa ht&+jWz|c(B&_EYM!;Wy?7Yqyx44$rjF6*2UngE#9)T;mh delta 3758 zcmdnWb6-}mGr-TCmrII^fq{Y7)59f*fq^lZfq_AYgN=cKq3`s5!-3Noj#IWsWuKK68R45_&FHm1@iBwYOeK?9!K8@fUw znHGom#wIcAg|>t_itJ{&#dbDC2R&F_Z zOv@!$mT@TuQ=b8!f<~0ch5Pm2+vW9nZdV_E(4PBj`ka>X^VZ*WzRxlK{I0gS_56y$ zH7j?p8J{sY%wycfH_bV>K{9PdVw>c%w464{v>6|r95Rk^wKB=c$vNltOa5=}?d9FH zY14xjFD$MsV_^99=4SKtxazk%Uw{1a#U&&pWd5Irhuf2HZ_C}VMdr?X!PVjG-Ri@_ z#5Qf(Bp@!HZt{OVU-IAA^X6-ZtvT@F;oqN=KD(~>1EQoU`R zot-QP5)Ze1ytX#_%coCD4fVV$ufAgZ{pHo_^+x9A(_33x&)@Z9XJ?lZIN^7He1?o#)gb7I2=13BBODb?TJ7|#0duMT$O@jlt)qM}a?U#lxCKc1MVyr=xV zT>hOM2l?&)6gYgn9$mMm<4SaGG}D1cN4qCZo!T0?IZe^fP;lC`X+OSP_TO0lzb<2I z)Su{t`uzO27dP%(a4}=T^y%%hX3b*! z`2VHEiu$=fcb2{mTNATWh>wqt`O^EBFFWto|ChaY?_S04xAog6PMFZ}^Ye4=nw4L# zhu7^{@gnN}GzO4a8dJR@qN5k@-7EX=-@l6IbIUiBz79J%c~yv3OG^s_gPPBbhRV;+ z4jw;#{DE9{b~Xzeo05r%h}Y5}iRq`GcJ%bL%$+NHtWUQ4!-s+%3ByJ0efyqRKYa0` z!?O5U!n->=3knMjAGFrDwDI zXJ!~SXWjqx_4UMAv%0oyF_|)Ts-lI3#L1H&NV9c=RYqCvwx0_Bl=q9a2)398~_< zA*d`MC#M%9E+&?AeO>I1`u}!bUS1RC&h3rdoW@zR@@u+RUB|-xe>yulKuP)Gqeo32 zJ{0Wv^XatPQT_v)bGg#f)8|>2_g$^OdbOv!`|-ua?mJ6f1})xKwmxR(q}JBfGiT4H z`uXt%2M1UF{+8P(YdwwO$0_ag8`iApVds~7vaj}cM0E7&mzS3dGsw!ydQM{JmrIF? zk}7|H@9eT=YR8Tr=l=X%z5l=MygU19XCLpAecZ^*zT)!BAJ1mzbN$J^z3tdnww9bI(4c|%@2dq zr%y))1URIprzg%%`uyzdo}#B*{&Or2Ub_}{?8p(0`cKPlZBIWhCud#OvvA=;o5Dvf z^S`sQuw1x(`*woQ(x8bdYuB!=wqYx~rT?s6z4qf#@xOMe&=ZT`0=BUxA){F@oVgk{t-Uy&(PD+kx*J{`n0H$|7Y#*Z-&OkpKm_i zu~fDG=Tq@@k(-x=*Vo6!#6-lz+^?D?&P08HSg~1oXpG1 z%l1`KweEwYso#zb8#W{a1PGW)`L6$6nsj!Cih0frg`Uc)Dz5tYeKj)+3kwgGrlhF+ z|MS_uIc-nH$E3#pzh1B3ymqbcjK%gp&!rg^J@I&GrKQyszCO-$Lw(_?DVlq#zpwLb zy%=w#G1cqZ_3OsAws%)pu3ft}GCVx}!^4TQW@+h6i_uH3thBWM^+LIEf62?BYuB$| zK6ub^65qxjZ}0D)Z~yOyvM3iTV}ROZLseDR8|_!Kw(98Uh|IdZDfM*4(^H~~Cw;e` zzj}4*&!0c{)c?0LmEt|#BdKgzS3mdck1H#KZ7M&h_|LOBd3m|Nv`Mnzf8Wew%@6DA zx1^jDs{4G_oaMmX-Q}AXENEbuF=NJwt=ZSTF6oEO|NB#Y+Wgqx?QV+~My-8kxPI|s zWo>Qkodpk_*2V3em41HS(xpq69<-H{lhe`ANGL8g-kx_itK@IzMTghHUjJT{SUr38 zte#8WW#h(;Oz~NNs!SdqI^@*W+A5j*=G0W}$nfy%ua__KTKZ_Ry1#_Dxck;9->p$+ zfBdMJv}EyO<*8n(o<&zy1hN%v&%66*k!!ch)7__fWGp8&Ha7P3^`&`xcQfj%sI*+Y zdiDHTN#+Gpr;6(8==97gesyJKPF9wY#B9Ulwha;W2M->s`SL<=?V2?_*H&%ZIPvqd zvy-o^`PDt&Y2ky#?)?^}uddiVzmT=Hr>{?J9WxUX%WU7R>$Q&_JGN=vx<0G9eY?xw zPZK$PE=@*C>ePe@0&OiV1qYj0os7-Y>e(*!uwVXvFXPjblZV8+KR-XedDW^eJw3fM zCr&*0^YgRn%lGT;>OtxB{JO`6hK75Jo_ei+ZC3ou$IQ$uX#Mr#FE1|I{LWYpEw)zH&(tFE>d z(~WA$zP{wI)A}`Qc;3E!YkTbOojag%y+_9KQi6@9Ca3>A8^L%TAGS6&7w+82F);UhQDU`Y=g!V^`eOD=gE(8A6kojI=9jZE_^{b{-?CfRMMXtL zca*#ox{_sTBE`G!@3-hV*7fCnlX4s#8E@UX)iT5D>-`X(W&igs+_6KVuCDIGw{LFF z&derKyoU}SHmv%R5wpKemXVQh(wFa{^OFQlpI>+4)Tu+y&dwH;lj{p!?kD-7tE=n6 zojX0#riq1whJL+p`P#L%M~{+3#KoN#1}G>hGP1I=svTdi%@#C2==1XI{Fk?`*DpEd zpK;90%*?~j?^tyH-qtN!OmyP+$<)==dHDFa`1tgwEZ%K?*)JqK+<9TZgV*c#yXEHQ z^4C32`{Av>w`I0@J`+PuZtlXMl?8u)l?GOpmzT>}6fguY^Er5RbvPr#zkmNaIyww? zoIiDnYumPM%#nwmcg>n5_2b76hm|3VmM*PlW#GAYb5Ge@DH|J`2d`git85Hf*)o5= z{HfEYU7w40$7g42msrWBou8+hx$m99RXc_cpFaya`t_oe&cwOx)n_PcNIDt_*_ zCVv0EdUxY{I|`Mxw6zz8XnnkyK3`E&)APZ}6r<*2*REarcIe8gl|PkD>kd^rgIa5G zadKYX-U|aXE?m0QRQ>&3g0caeoEL@nb`e& zGTE`V)JJWyqN?iA2U8-r*2VAdJ3U=L`S-WC6HcaV*uMSvart_l2RGH9UtJwu_~%Dq zN?O{X>(|Be^73x%F4xzK-PN*ak<#SH|G&HpR#8_^K0Qshqp$DShQz}HA|fr$?R*E% zo%1WH3x2zK!v+UGzj{6+BO?I;0fzAK@SOYmWc~d7PMkk)UKxAjkGW{jU-^tWh66{t z#W&{MGONAOtMnHh~wPfu6Y z)8p$F(>=5*bhUttjLwJP;NXpUcdaz0da#{cs!d5T!TmHC} zTfF7+y>pY_^V|Jskm_yo_4T!>`?KR9qjUYI1Dl=u7A;b$`+m3l%*m69Nl8lY@9)2V zxKB5F+lGDn=GFiGDn5DgWY_N(b_IvjhlI@6pKEPx{rO-syN<4|X_fxz)2F-D{pKXN zy0ZTN@tA+r)vU6Tk_$(Vx_+p?zAko8@pHb}vu4ehIWzN0_uHh8%m;Stu$VS&+NbyX z|EGC+a!%KcR{OAO)hY==LB$yVStchR7+eYY9TOY7v+%K-n5gK-b91flY{{Hl@I%dQ zuKln27r)F}H*Yq!wz6umJo4xK$&(A?)<17%=l}8Hq4TS+RsTL5=AZO4=#ROoeNu9A zWN4`BoAPH*pB7$U7dz=|_toVy>XUxnoNJbQ>xi;@p8&(#w{IiE!qN&D#Ds+p&oz9|8Bcr3U zWB%-td%!Dt^Y-n@Dxq3eC)`fbS{u1}+5Pa%XRg@$&NAtoU;pptgxiVd_%ENhdv`7; zC#Q4XaeJ+Q&(drvRHmQ)c{_iP0f!nvGtMKT}lyxm&pIsON4>X;^(bD(F_cnA)YRdAsP4HMpcK1T$h~}8xaz+sHs1r zVo8UG!Zeo^{VHr%uB=$=`Z*){$|~Dj0o{GK=B@BBP+TPU=wj9_4ZAL(=2=gU967Qg z)N$=YIxtTH*q%E%u1?REWJ>&@1iHFMofa zP_E)ZBRiB>aO5)Q`9I=rov$9}owwr@sf&7A&Fj0bkCU@Rs4?#Q0r|i43U52=h$Kb7 z?oFG1wp3$(OZMD5CVwS07Hv88U20ZMZG*t1HT!=5DOV5tc{tlN(Z_t!oQDea_Pco> zi$0orO?s)q#f5vsDtylLKKaRbX-VZj&bF7zGiT0>Jl}l!P z`@ZT`f4Zhv%oFxMRlM~9Di2*gsh&~T$+_dr<+k>`y&i4P%WArB|192hB6OugyrH?& zi=_D_9mhBnwbWa;EcTdHGsz<{?8r`&dOlm_bw`^NRxYaV6V*~b^>2a3<}c6M7EXEW zBR=86H1@o$9=6{Y&nlb`wY(BHy+`Zi^YZxaE3qEs$@8_N|8vPmzZAE6Z`OBd>yzCF zo2Ic%6;7?cpm&X{?{jA6OP6UO`_37qF5apn`7NRTNsx;D?Dp5Pxl{8W>uQ$&?-pU^ zDN3xjese9(>g|lQGa^BcU(O9?E(-OV@>lUd$#-eTC2Eu7d6RB^Ij~k#lPz@a3+t0p zeoxxFiNkrxom$->{#lkSGU3M-HYV)~6)aroI_a-tV1r-`lV5@4iEA?3zAxF*+np>b z+Wc=rUGl5RZnKsvxh_xB<=ke@ekNwOW~le4$R9CWGWAxsUo!>fMIY6fIOj*HOVP>q z9fg*spB`E?M_uBZcG0q;HpP{Zl9#JD{^U9QJokh|@|JEBHnE%Hjh2>|*4Y`SZ#*TK zzSSk@N3)XL*WZ;#SU>jiXP!Cy`m6O9*YXAJA%-6&{CH+<9wKy7KU~A?Z_um#TPB*l zPj>$nobWB!y2-vF%3c`zO>f*T~F`{N{OjTPF9qMtjtR;iUxA+E&Y?JR?8ulU`T66#qCUTWSflU4A4bqh9|v|FQ2z%Si20 z^__OE&x%z|XWX=q;%YGfC4uJqjPgmFK8QK46R@9~c5^y|cBmWIzBt_o8$F8YS+Rvb;9nj4MORU+GmLr?(0GOiI(!D?G$M zU+yJ`Puh|V$4!pRSKx}cwlS}%!{hX2jcWlD>#zK&QrdZV{ShI>8@0k|n>(dDWOaTE znXs+s5viFRsJ?c6>L!nU|J^3txxHJ!{ru`ZW;c4i_pTM{oRjRHxz(5L|IQ8@g(;7J zG3l>xxs_GyZ~Aj~>*{UOnBH8GGG&b}i~KP2;!f8(_11uiV2h6HC-;1iw*L1t>`0-# zyVU7@^)46uf|r;Weo~mh`(;b1hwIMmcWl=%t~&c}WAu+D&5Pc&d3gSq@p{`+x1X=o zo||oYQE9DY`R@3EfOfub#g|I7F3HJk-kNhbF?XWSPQl)az<3qY{qsEDeLT&fFwuGW z?wR^ZlV|r&kNl<@vCb^$!`j2`LGLPCJ^u0X6-TpHeM~!EzhL%_w*{=r^(V#mrY`s% zIY(#vT29rv_HMqX?TS9G(M!GuBxe6)sgCJ%dG>wVK98)rt&^{$e*Yo5!lAlC+DX!ojnV>pG@ZKTp4iF*Q|ey#S z)@@1fV+)hguxYigWb^8E=D0+$tzP>-^=V>|_pJERI>7}AxCp%H%&%WmY!s|@`zk6aL;QMXK`o@%Hd$T9D z)a!4J-X#>MXJXNDq*jZyHSYg`LZxjlRk||PT-Y9G6(N}QyXlhP$qDVxJudCsqgQEZ zwyBCoVfoHw-DwN{2wqHzn_O{a&+Mdxjw8H#9B!>~cw1ri_(px#v(%4k!qg{T`ExQg zH8s3JYm!dFRLMWio=4Su`KLT?`_OiSrzhdoYL}w=N3*kCbL%ED<@Mjgu7|&`KPq>FeZ5Wf z=VvoT`7a*|ygmK?%9@=sK6={J+>M#DuCh3-!|%-D-4oxe4_B^?6VjaVyjk*(W|7Oh zV_L>PYCF!fo7mQW(DQ%)U;Sf^`Le%~brU!3HjaNYO+SCG?@K8?dBGPt+#CB;0!#nA zKiZY~XYNFmn|ilDmrdNZ+HU@Tg$1<-tNb5?ckbWzTSk4`Q~Q!Sj}Gtup1VKIJ+z^0 z{$j&VyZb->Z#n)ka`r#d1I^!@&!5WwU3>rhgGRn-AN*_Y_djTq>&X+U3IB9}ng8GR zkMciN+uCyeswhwP7L*Y+G6*p+urf5VGBMURFt9Q(ILWm&WO9w5j3S22j&R-=pcb8{ LtDnm{r-UW|PBz{U delta 4472 zcmX>jvQt^HGr-TCmrII^fq{Y7)59f*fr0550|SE!2Qvc$!``Jl>Jt_1>X{h=d_r8U zT>}{y7&tgM0s;agBqZ$Z?Ok16b#!$2`1oXHWto|orKP3+|NpO`pm5^EiA9SRWoKvK zxpOB!KR+@u^6As3oSd9KK0bYYeZPMF3JD2mX=!0%Vq#=u+`W7Ej~_p@wYAr-T{~sU z6afK&88c?o)YN2TWK5hm(a_M)sou#+O-;?(+FDCXtEZ=D_Uzd+XU;rz>XeF#%GIk^ z-@ku<@#4jW3l|y~7-VH-9Xoa`FE8)bty_tSiGF^5w{PEOV`Dpe_H02x!IC9Q{{8zG z92~rC*|K-<-hKZ3`QX8WIXO8zJUn%Eby8ANE-o&rs;UkS4uAgqsjsgW7Zx~;XxVX6f{{8#)>sLWRK_MZb?c2Bi{{8#Gg9jEC7LOl4UcGwtkt0VsJ3Ebx zjM&-Pm6er)f`abfzb`K@f9A}Yl`B`q#>R?>h^$z#V&le*J9qA^t*!O&@HlYbz>60z zrcRyO+uLhmVxp&~XKrr(=FOX*KYzY@^-5G!bno81_5A$&$B!Skv$Jb&Z|~^nNJvN! z6BBD_XqYu?R#jD%si~>Dx_Wted0SgsWo6~`>C+n<8(CObcJ11=bm>wnD=T+*_oSqx zIdkTel$6-m*i=_nXJ%&Z*s+6~oBQtFyIx*i5fKq`a&nH2j$gif`S$IbjEu~cD_6R@ zy5i#Enwpxv*MI*$ckbM`Z{Hp|bVyiOSVKc2JUl!mCg#J351N{q%a<=NE-pTO`n0pN zv#qV|g$oxZOqg)*-aT(`?`zktd3t&-Uc9)luuw@!>EXkN{{H@EW@ay6zAP##TD59b zU|`_Kj~}C=qC!JMPo6ya>C>kT8#Wjl8$WyYEImD)mzOs!Ep5Sq`UR4blFiM{j~+d$ zsHo`g?|<^-$^QNO&z(EBZrwUJH@DW-)_wc-`TF`!o;>;W>(|}g-Rsw{pEqyb{Q2{@ zZQFL~(xuYU(oLH-oj-s6@ZrPy`ubsEVbRgiH*enDvu96oa`NWQn-vumr%juttE)R{ z(xf$O)@NN^NDB&LVeE;i5yEo1ucn z!$}D<N4vj7AEIoE(mPoaP)|0uJx8EtLdBRXI2VEmb=tTpUFv1iLbtA6m8JQGILI z>s>o`y}22B_wwb~*t^CpovhVCEdp70P6A=Ihk|0u6zye!caYdWt78?CGbr zrMCR@A70g(!oPpv(ddbVU+r1$9l7cty1B+~EO(uoD!r4(?oXRozSiR`^V7vEq?M=3d|e`aYPPX`;D51~*EadAc4WwL zf3WTJdy($8wj$*RWlvXZR51c__@{W+>@B;|8%qDEbBM!85dWi zuHGGW{PnpR^^cxERW7*j$T#&4Ten-wYS{i=O;S z&wMUq;1GMLDe73ydG?PDvG(R#U$8xwyo)rv`c!j;^IN&9euy-(HQYY!y5sW7 zcXL0@`TTX-;uwikQF~eWe+LenS9)H2r2gWLygQFf!~O+Iu6I2c!MQSf$)QrQX0eAq z-(9|`x9>9dmYBCkzpnYhBAp_8A(#2ZwSvccy{eOK6`R|&HRtZ05`FpZhlB-RT`Z*D zz1etcS8heR*{x-(4y2{k$0%BVY;cvE_`N@8=CU7`CmnU4R(K;L>P)3)Zod7!Fp>6; zGrMy2>+`?M%u3DK^xpZ{zGuk?vi3ODKPuMjRso&XSaPmgV{2QllOs`e0dZe*;rOEjP z+K*qq(0pUo$V>oR)ai_RYSz5lu6z4qNv<+7SAu;>NMb&zG|tSNkq^ zYk8Kf#!TB)xc1>8~f4`-~f zeSd!i=ZiCw9FHFtzaX8@a_6Y=ll#Kbg_C|5%2n===Zd~{vZ7kN?Pphy?;n9`$=_S@ zk7(*lS^nr)*v}o`9NQPzi~HY`JHNc=PEOC~s2NY%_UO%X@qXL5?U#GKR0oqS^Eaby zz3S)t_t>}vG%lU4^~>=0^1VG}H9a=oi(TsvDCD2~D78z&z1?7rf#hmV=bxS1*6zI5 z9c8gru5gk6tGL2{YSc`Im@e9Hd^sX zca5d?yOiB>@sCe-EdRb|ujb*FsdpDR^K#eaq`YabWj^;n;O^NZliDJAy;u1?;Iy@n zds+R9xIbbYmgr|LcoG9)uY_EDEEtV`ZlH~rmapFe% zZ(k!kgQMp!*kRF|*v|2i>#gc}@f#`Y(i7vp-(-*7 zHve$S)`#jdo+(TGt54T@rgh%LC@&#%kHwr%A-=~simMy{xAXEUeOOvFp*`qPwGHb= zi}C}#>sbzdeAk<8Aldz6$k}2BOE^rxgY-eI_l^`S5VPN9$5Q_`j&}5I`I3u?S#~f z1y6g^jU|6e`7_oYnH|_6f5voA&)Gi$(UQN@?{^1&GL8!=xh((W!TW=(uu$YOOP6}~ z&E~ef)I=M`dtaPyrsmW?TF$b0%Bh7tx zZ)S^T_dB-lSnvTO(e#fUJKLsj?3CYn%Iny_o7WYkxvwX=%75>F@_vWLtN8kqd$V7> z`B<~+MyE>tv+%lKuJxC{YqLM76$~hooc-frip~fBsULm*INe&bRe6=Ii>1NiE#b=P zQ}=~U+xXn7w)NM!>+Vw@Ij2rMe<>vks@fFBF$fet%(aoZqY!`}g)#+J*8I zSAU<|7yt2;X3vB844un@k#N^c{3x}uLZnh?H%Dd2jP(Y7)@$V5US+3BuCAVL?)cfF z=CALI@)%30l_!6g<<=*&{?CkH*t1&Z=*CQ6mVJSzK220OdG5EnoQva*eP>SIxL#ke zLbOMWy0TmpEmhnhDUw;za62cXT(XIzt;NU>w=qgpIG|z zmOS;ke9?PK-NQf1&9Og1D&tM2?A`Y;B^r`<*p4^?)WG%W257Z`*FwA>_TI%?32g~Z1~%9#Z^su+7r9gdrnHUzc63>==kAt z_4B~ap3zf(-}Rq>)3(R+OFnP$HPADEtHoT9Ri;;HbETtfq0zZF^$SmR9-h9SX65m# z?e5Br^WN3n`rWae*~4q^jPMZa=@AD!oU6QjA~UXjQF}0F&%O9Jb65IgpB0h$8~*jn z6`?QHQCH@D?q3(Jkt?zPnXLM?%P&70eKU+Zqx0atbYJ3`@)PwxJOlD4Z9HkWar(vs z`*h`NpQOL6_<8QXoX8{Jzi(4>9$jvZzslmi^?$;G8p|cJjzYg}{;DkUH}j19pt#|Z zR-H}G-{(I;skHyp4MVvv(H)^b-G#*x=Vipy-SX{fm?Pia_{W;F_IKx=Z#w)FKgI{z z{yf>5zdc`G@a`*a-(!9C%wEruCO<9DbCcTiWSf7~q@dHS&2uNm{N284ep>!Z-fz9f z55_+FHmCl`MMd{Qb*pJ{&-V1x_I*F5y0rR9RNz|AV|)I#oH%h}?*WFN>HAmcY{)-6WFrf=L^|6j&_ zPtRFU^Jkh}T6W3#SxfhZafKhhEcE@6!Q1Wsr;1JKtF7mF&0Z31x_?RNrAhBwzkVv+ z{5xp1ce>D|bdRmJx=G*4=h@U8K71|S_O00;L7zo7hO>P>HxL~LwwvbpCi>{YNmm?h%(rmox4S;r3mDA{7Bo^jTUh^7dMDG8Yqh(b-p2CUCB2IODe?4C{e=@1 z2K!d6u;0MN#bPbr_!Xo+iqUA^t^fO8J$cq2bTZ=Odnk3_KVuQIQriB7#^RIj zamt7qT80=ITbWo|nV4uB7+4t?gvTp}P3Gs4QN)l@W19Jjfq{X+)78&qol`;+0APv8 A-v9sr From 50cbdbaebcb11349aac510a389e445b2b2670f03 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 20 Oct 2016 00:39:32 +0000 Subject: [PATCH 0467/1080] README: Add another image. --- README.md | 8 +++++++- images/after2-smaller.png | Bin 0 -> 4386 bytes images/after2.png | Bin 0 -> 10228 bytes images/before2-smaller.png | Bin 0 -> 2605 bytes images/before2.png | Bin 0 -> 2614 bytes 5 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 images/after2-smaller.png create mode 100644 images/after2.png create mode 100644 images/before2-smaller.png create mode 100644 images/before2.png diff --git a/README.md b/README.md index 515147c..0c0c25b 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,15 @@ highlighing of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors. +Some examples: + Before: [![Screenshot](images/before1-smaller.png)](images/before1.png)
-After: [![Screenshot](images/after1-smaller.png)](images/after1.png) +After:  [![Screenshot](images/after1-smaller.png)](images/after1.png) + +Before: [![Screenshot](images/before2-smaller.png)](images/before2.png) +
+After:  [![Screenshot](images/after2-smaller.png)](images/after2.png) [![Screenshot](images/preview-smaller.png)](images/preview.png) diff --git a/images/after2-smaller.png b/images/after2-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..8b5b1f8f21d923c80a7d4c787e66774f4d9a170f GIT binary patch literal 4386 zcmeAS@N?(olHy`uVBq!ia0y~yVA#ySz@W^*#=yXEzsPz60|Ns~x}&cn1H;CC?mvmF z3=9kk$sR$z3=CCj3=9n|3=F>*7#JE}Fff!FFfhDIU|_JC!N4G1FlSew4FdxMTavfC z3&Vd9T(EcfWCjKX_7YEDSM~>7A`B`jO&fA-7#IZ9JY5_^DsH`$Mtb+{|U#ImiWH6pnuGDod7xkKH+S?x^1@?~l{k_Ysd0<$DE_&e1<@f=AG zG|u6>aig>G5TCaJTQW=1Wi}%rBPXE+qEV-3+xvOn)%AXLJxW3C*Q&U$)$i}wm0Q=o z+xfh1yJ^EA2DT3@2c8y&ConL-(B{$j%rH-4i*|8Afk9qgUjK5j#SO0g%T{<^G|+nS z(Il8R=&-_t&xO|?>5Jd(ozItWcUS424~Mv4e62DvHrCYFe}2~d{*mj~r(ch&Ui&}W zg2ki4Wv(Er`8&tB)~|P0dm1Ray%S~4k~=itD5{0m z)1IE5E-WPE6c#4dEvB3F{M=lf$W1JZFW#_UTi25jx?sbte{y;b2k$xcq&Pmd^-g~HcJqhOolAc2IBZ|XbG7%{dkw#T7t~xk=llzL z7C&#o`LmZF))y&$pS@3i@#c@&&EDDB+H2RYeet#G&Ye33v(M(-*wCmOy)7Uz@@0%C zV*{teE!SP_kAh|})QVTOF}WSsI(f^%0~rd7(q$j65`A5^ZSujKtkyQQ73R)$Q#C%$ z2>5LyxNm|GS76x%A2-er58Skkd&v;6~)x(4+bO^F%eFYorsH~0mLgsqG5 z%*)eDO-+4sb8~y@>1i8FUIsnS+9lw@rpKh*5R@Q&AJ#1 zSb^ii#wU@yGjw0BXUIHYdb*suVS7W`*U*xS2kL7Sy?*PKTK6{rnUbB3gzkuC zU+(p^I!j1uFFm1t&Q_ zNMh}g;8|+A;Vt*ii>svUXD5c3NcA#lxcA8fK07~u{g%DqrM=FH++6RbrR#DTi zXvsQ_<9#9X9+$&L?NK8(ld*>v?!^;3VfO z*AtUePQ8D&V2?Tf)1MY1;cHEEH^@ExALsP*qr{ZV!+~K-7ytQPBH|zZ{MJq_-lscn z!s@g+WiozZCv&UC(ytk0X*m&6sOUmr8WX7}qSk*}L3nTn?7tSElE&D~hU zHSyV*nH3ck8_M6uJ+CWEZp?28Nl^O06VP26_?@Rfa!1nVx!DH{XFrc_IQo2%L}Cr>A(`th)z~%PQ5Tc2!^CvA5@%o+Boiy7j>;rQjzY7&aEL>3gm= zK74YvLFx{h_MZ*&*<%V0rQ3utowjSs&r($8y7z0|4pxRx-Ve9rAK0Hib;#g#OT?Bl z8P9LMSl4{aZ_UrmfdyZ7m8xasG#z#|y8VS!=A^u|+FL)~=FW*9&IGKe)!#1KP9>e3q?&Vo-`p)*OzzeHuMJxh@i3xm`_s$YK4?2^^sSo9EXi+Wvps=V=9iK^ zU-TVTwy(bF%rUE5{{LI`*<`QwpNgIz+qP#Nyrb0hCh4(-yjIJ6dv0s}14lSI+bpCx zSDK%0cpful+YYNivs=^-LUdF9sKsQ$lcaYQ5&@~ zCw}Noe)aTqOiJ2@-jF+M8kgsaU5Z<`i6O^%fqIC^3Vr4SM_KP|nOl;tdxWLqYX1AU zc#ZOuhFuN!uHIW;s`B5jS)#3WdUaS_^>2nfd-q0e%@SQ5zW&(Z!_Bj1Nkv6PtysCz zF;MuwWslCed2V&n@(vVxd|^B?H=yCE1IHt~JuFLBuX)PY{f4JIN7#V*$BOdaaBlzb z41;J<%YzER$?h^*P1Ab=?kb4I=mt3@IxpM7E4OZf1dF{_lf9T%Rm_4TGu_!bOMSZ= zE-oxsbYy2)i1`VAl>@;_rppwkz1yqx-guGAOcKqN@+}F~zwZDiS>) z_h3qK?^~|*YMwWq&(*i~|NgyUY4VY#Ycr3&lGyX$QSNVxEwjbythw)<7L~s!slwX5 z-@=MzU09dWZ8vG7#jc4wRU1ow>y^tcdd1~jn|L#VDdF=>)2y{P;{2wVI=b4v z*{LEZ99mTS!2P6vu*T-g^>ZhGSf(p;(x0P=b#Y4Y@jG1UrxKpKR=jZ8!u3l*%Anw6 z>IbKrcG5?KuNOO7Y$!PV67< zHZA^mndx-|!Pw@ij|xOya$7XZGJ)u=`_nGxvded#f#Lei(3z>!n;<6PaNmwQ2L_m1|3t zKHZQ0vi5=%c-0sQd5|`laBdyE%r^}vNHtpW&9C!1_*V*R! zEmyX(npOMzTcXiS4^Pj7r%!k9+GWKjXLF-oxBiI48u3Nd-AYqV6w7Wq^m+AzyD_gn z-(P;>3rH@YZ7j6%RMvO{QS;KO#=U1 zRRVb59QQI|Dqv4jvTle{;J>+S+e2l6#+>5c$~HZZ%`({%+xckkcoZ+cyeKQecp|8tOCe!`R~E`EM|ot>Rmu3nuu zckbGK%l;j3YiZsnee+NpUk#s0gjZzuhUaC>@rqy0Ry^=dkZ@9#Wvl5B==jHI!Fxra zYtO|`dzn2-Y9tHfb}V1lHT`|WPod-cw=H*4Yxn5c^!EC@r)=w0xQbsVwJzCf60|M; ze*{Ol^uwtzi_z0KuZBs#H<`W_Ff}zuWLmPs!GU3pW%7ID>gvO9 zZca*n7c;|iI3z%HCw(sO6N~cHq;;4?lgi6IX(guUN$W8#hjzoUFdH{JorY z*_(ueO{`b0S~||0)f-?^uDquw=*X#GihsIH5_mT7JxmHwzSFBc?a$!}j{~v=;)*#Z zbVR&OYPlT9x~E&CoN>_uwO=jsC(0-VKkkvJc&J&Z&-MOLwfKUgNiyf}OggtFf71CK z426;0tDio|tXfi1bF%hf#-G@(0uiYzKCio&)cp=jP)soDtY!>|(aBu5?!jyB{QbPU z%N!FG_x!Vp*~JnX%6D}87OwV+q$O9(*B`1Y+^GUwP@b_#O}UR zZ#@3JsW9Z)t`b*k3Zvkx3_5Yve`@bB+$O}(&Mw|NktCzt5NNTfF~{p3W=^0hwGf0`Zp958Xh=l>x}+P|8zeqX-I_whlaMpn(9A15Ux7aiDL z<`^sc=b8DnJwJa=O8--_W7)qWx#3U#+;FI_QtMEibKhP4ne55_FQRD=u1Q`i$uFPU zc7W~eDH&<$)1S}VpTDv)_~(k10ta5)iKkb3SqvK_5?G1~Ax$n9f zpYhPSC6*U)p8Xr+tf(VdC2daxB4#N~`*nV4LS7qd=eNqf=_l^9xcum1{Sz{m{emSI z*Mn!iKOXYC&a`%}-CMiGnf1=rl3VAWiDmO_-&?&~;nV6yzvO%#nUnc>t<66lsefmC zJ6kO>GICA)e!0aLPpk}Heq&p%bZTnqk)uZ~r%h`A(3|^q&+fB-C0hYThZxBk8i z`7C28*M*FK{w7}2$)2@ZTSc`~`Vq^lC>5a#*IMPKeYC3f-f`@m*rR=J%r6BWU0&6= zzWwW!j_IqX1m+1}Emg5!@3iBL)ofjx?{XX3N*G?geCguiGGX#$XBQWi*Vosp+uF+7 z+uN^OIrCVblHEtOCo=QpEPLm+&Jogd`17*fRjf4ai2J=}f#0$Zom=$xaz+{)Q=azo z`#JL+>K5O5_gFa9*s?12Nn0uQ$!j&8y__=fMM%%qWo~9JYW{5Hs^GKJXrWF8#rm42nF%5<^geKlX?mYYg4KmB<8c~vxSdwa$T$GwvlFDFYU}&amXrOCk5Mp3pWo&9? rWTtIkU}a$N{H@^`6b-rgDVb@NxHU}M&{@F1z`)??>gTe~DWM4f*7#JE}Fff!FFfhDIU|_JC!N4G1FlSew4FdxMTavfC z3&Vd9T(EcfWCjKX_7YEDSM~>7A`B`jO&fA-7#P%kc)B=-RNQ(yx4J^)>(1l$ldX3O zFmZCKum~wAC^X$+l2~wOjY62#t;4~#aZwBVw_cSv+ScvvyfR6{y+7l2dsWDlEZeN^ zjh&TUXUai90X#fuj&Zgdk*1Boy==D&A^=H@HEyH~Gx%c-Ei;OEbuDe39kYjiXlaYrlx@`PsU^U$0^RLb-#1vYCbql(~Wk^%+y@J=abiMw$IPbCOKJ`#np`_Ny=JF#Q(m#3(1BzNlseSCL&?d1zqu*Ww>{ z_dk45>Cw@mI{8S`W>?{7ztRLt-Sy*lHzgf9bNcFB0T$W!kIwyNUu7W8!xj}4)zR6R zx!uXzn_E{`x8(i3x$5(4gc|0|k?~pfzH{=&=)PxW_Fp7>Pm{8RMv&Wy~~^XCtpn!91SOq?wXTk`MPj6-)`q?`M1S!!VZW4rGC z^gFx$2gFLUH8(C=q-11lJkuzZ%ewqs%DFj~EUc`7At5aX6BP9I`&(LA%yMoVXk=!u zsdw3UAV5L%1?L=QKIWx!Z@Aa1d|A7_YRT0Df)6a#+3#axNN$WfQ2F5gt7`WnD{k{L z9BSk~aL{ktedj7yrzn|_tIj7~uWv6d%j#JhP$s#~yXi;Xx9fooj(Zban2xx2*?$dE zuBqhf(w}jcd0Nc$ly_DC_ez|~mf8OBSmOji{`7SRejndczK?B{d7vw=iS*m`$vLg| zG6M0-_dd=OPP6}EpTC>!*Q&iUZWMg}|6Vfn@9eN^v#Oc;Iyk4dUulRa?2gH3Xr3BS zweofUX<3`x`WzOXx2!8|7o@Yy$(|6GoT>g!x%|ETh7X4NvAd?cy}kYOMR)m))!*}$ z`OUrc?f;c4A)7XD&dkY4xw$EIpY3AD18)!LI;=RG&MjD2$G4(*Q-8{X^aC8$^Y1c- zFw`^5;q5447Gs{A^KU;x1pAx9OaFep(mwNSvvtGy#_0{G_u2L`2r6#aE#nvSCdT~K z&0Sp2X8-S+tJt>1BErUPjeoQlPjj&8hP?HAqJsjJo3p!^*!LCcoZ&Kxy00yC&*IJ9 z&r3UBK8Q2A@$$s0+#-ctf(r%KtoR+YotLxefx_|I6_YR4Dl88F{r~=itiRtsa`&}b zdNlsLe&El-w}*GXlhE7SHvL=oZf${&TmCw7-Ld1zle}~gX4JpgsHG`UKWZ#)_I!`}T3n5A%>-XW}?tVuvd8ukQ^{gCCkludSVbwRgjR zX^Htf#+PKu|Nc7KrO_Po<=&G6=0cf5l3e}%ZO^}#d`pa2XlasZ zu8p28U;KyVN`lM{7d<~I?75}%PTYH)RmB4hE}JQuZ_OBQ`yHC7#VIN?O~LT);ze^c##-im!*k2;d8VeS{`~oKpY7($0)crf^BB%W)P%Kmd@(+d zkf65VX4-Fw2Z1hA`W2^bO})NU;0A{c9}kO+?bpp$&d&?_zIdbb4_kp=AE%$I&z5ah zT6Aa8w#%0m-EQCEIE|U}fYO2E%P+^idAVuPiKBlHSp3}mhpQ$qb#LEA7X5e4S0a8q zY57{`rFW>&c!Ig?uj7Y$N-B;&Tlk}JCCBFzE}gRLHeJ@1y6b+gfA05v@3&l3xOU;O z`H7AD3WVpZF0ZZjong9q-&K~>=|{5s-sv5ma+CjGiG$O-J-w;=i|g0yxi0<2z5mAJ zYl=!)x@$k2(c8#p`fYAw{rtA4!A}nE$yoE_Av34{ZF^l`mz@_G{6#u8WQAPq_OLe& zt_m@}TqE6-VLmHJIMp>UVsjcV!|Cbz%h#__gK871DTQ#z$Fuh-K`mq4F9Ydu> zu%5%)srKC0&Nu&`r6vA#sv76i&Ek;-d!)9_+o1ohS2v&_Xxi}`k`^{ad|Fq%bJAx0 z-PRkv{rC6G`!c_urz?IJ{;1l<>fH5e+f4fqoq)C56Zm~+%id7YkGg13ajK2=7MXjA^AC% z1O=}JG)P~0+P_i%l+@J|4s(?I6q#GTSuEdoyREC2b<58W@)kG0i!C^qG@C(X>FysL zTf_g$U9gS$QxxrgU~%+A) zJ@KVkr|Y#lrXMFhT3nOJcgOtJzc05IKTr6o_v7vUBfqwb9OdTy@J7$_Ujl2L(VgOC!;3U;B`Gobt`D@LJ^=;2pHC(;j zV)5%hk&&mLAD`Rei%;k7YW>Dy#K3P6dA`WOfNAsmZR|ppjA*tn3-#7F5dWf7n=p`ATtua};-pS}s!Gs;E^KPcr+V!YutSZ@a zUTrbYE?Wb>b-pEb2VQ8-I{GH7q{A#D;%>q`kwpIF)e)1Mt2<9?1$@}@ch=XO4Ab4O z-y~WpNC>{Nw%_fXcuj3`&aEw-xwp4nTCao=JEGm zbXws&vC$|!BR*5|YeMG1xDOk2&+(m{Xpm{YNqb?*)D8po7c9M>zZNXJwl`N;>EZFi zE(aDJw%T7?yZOnZ8S~gSUpjke4MXr1_M6`}t+Q8G6;I4wdFD^_G}Y$pnVNI^{jch* zOJM!w_FM1InzKn|fip~Bzu&`M_xqHU;I?;mTO_Qzm%r@~obKG55Rw1%U+wRX{{Hl%U7}xJU+=GezxTSe?!_Y;ggSFx z=uF!@ds2ZM*K_VI>goF8*LpWye)gWhx$590osBH#uX&dLtJ%B5fyd23u>8p1>(=+r zPYV)!Cb)N@|CXO_UOi&r2Li+8>g*ofsJu}ZwB}hN=Unk;-D3MIQ!<`!d&@KH=$ain z>L%Y(e0O#2F@m_ zboA)aJEhlSd!$Uec%{uI%$#|$Lr_^mQ}f}x>UW7h3iK^cZ<+X*<<@S_n1@Pfg+9f} z)&3WEZTP6S#Xhpu{&;!YhJ+LIG#33?Z*<~c1e@2k`BN^w(Ld)Y(yqNQNnOu#hwOnf zC6(9J=8H_(`Ofd7==~LYIm>H$Y8Rb7z17agbaCmcqKz9T^4m=i zT*oP_RA&rZ8=E$YsHJb=W#VhdQ=D|*SWCyg^&PL-HnW%QxmU1tb@eGfnX0TcrSrPVZmXTB z-h8pPe4=)SSjv*_cS{!KKZ$ir3$sc}nDeE|;ZtXcXy>c)dF3ArK5Y4WtLMrDg~G!> zXO|t?lXX?=(BZ?8JBw7s^*T12X?gv+$IF|>?w7kZCUn})S+>PBas;WYzH@$k`}{tW^0~Sf^L}xjG}@Waepcc0nv#mD zHkW*jvKo$$6Q503w^#IAac)Jo)zd&%1rirsao7|GxzYBljS;`ywf^F zCbXYgxcOdgao8$Lzq^wjaw;ubtM=o}!SbqG|J<10=uCdvdi_+xR^?qvmEi_P?0geW zs=U6o_VJNU;XAe8@8(XFU}ob<`1aBZhsdmtCwAvgCPdjdCIVc&e{W;yi_^tCTJ>{_PTRmRHiaolQ;i~gd@IZg#e}-eqiIvmBPV;=- z?XNI7@{J*b;8(W?&a=<=t-3GC>l6Atc5&VR00nl=&&Eo^p?_XzZ&kJ8$qQOtl4H#{ z-OBRmwtEcbypy{3Z`)a$*I;*Xg7s0GUw3m#DSMca7z31O#DCF$EY~xn?vNk&j-Kld-wYHi6=80ZByl^OFexkB&#NzUZmDpzd3I1 ziJc*<@qj+^p(yDe}**TkPp z{vW%iredFjdCPewf4-hGWkzlMzdE%ECskNkS$*bOO=aa4`*5%N{noW2qM}D19&Y#a z@JRUi>8XmU>crWzPyhP*I&w?K#PaAX>@)W+k36c|(QuS0s-RwUgVf2&#P=P~6jB$- z{OsyEu=~L8i1?YSCuDT4ZCEVDaCt((zU~A1Z))cCOj*8Z%Z#n@VlEfvAK&=lcjuCf zAMKMyr<26mM)vp=Noc+iGumbMZWvC z8aXb~eJ7(Cy#H-rD0{umqyVdEk%YXqh?u@fPp`+cnpW3T2WRJ2RxCQxvibN%ZY96) zoI`sjB|q4B@|xK4t535htb8@!l9RineS!jK@a}_-94}9L8}aVi$Gm^f^0)7Wnfv{W zqL1pX{WPJY*Wf$X>Q}09ckf2jg=Yvqvn+o0;otA~!4VNBzP!AAd+ApnA0HKa`}r>~ zFAt86J}sTU=isZWt1~k{9=woaU=*36l(f(-aofD_jMfEmm)MLtETnhvNlsuE{BgMB z!!7BGYA%VEC)X=(9;{ogaI#lVsnYh1Ak!a)jlY5g#E(@T;s48DGf(-jtd6($+8cVz z1@9(EaobBNS(;Y49XiU^x$4KKJ!gJ-cTdjTSn9js$Kk&3+mlxPSZ}Y_IGw+2&pz{j z3G4nnh%?wZ-zENy6>q(@nt8H&a{u1NPZUk9JlPhn+t%^4bWfDiyBN=g$5S5%B)m(Q z`E;6)HdFDdO*=aI=9bpTC^`l$O$+M!BIVSadV7)A#!a;|m6J<^&d6{yKT^0R-{(#-qrry;{kKI}7JEOFOsrQ0Hgn9U%+WvZ_ zu;B3G+om5T3vT#lEEp;~cin;GQ;(OF+)2-C>nOUJ>dE$mzf0faTzb8YNXfqaEDlHJ z_4TEEwW_^ov%`GD@}70fH9w~Q-&GnvZ~F8;zwkxeoBQr}ay0(m!>8o@;6dca-oCfW z`}R49?mMlre6jF~7l+n7E^iXGs0nkLV{}!cDQvQeRsGim|I>fHd{JWh>%n}#0|L^F zEAOgyJuK<1{5Gra+;`sC8Kos9B}_cFTF&n7?&=3Fv_|5fZ%#_|c(wyH{PjG8HAI(_ zf8wo-bzxgCT)bGw@BiL@^_KYzCr_SCNlUwQ;etbK?A-nR>$58*W-Qlx|G7N*PP&`a zleB{^BAS;|j7~1;-D-YF*ZD!w%f2TfI*r%zv z`Q-WY>ekk~-yRNK9rp2vuz!T=;c$^w-RNx-rcQPB^W)Rs_hZri^UdEsCVpG9&SAC0 z90}IF%Bs7gOJ?jWI^1#Zt?;LawCS6d9@Wsa_Fk3vUh?FYYrkqaH}&+j9dRkx`r?Cr z9b;sq?E3E)-9J2={m*V!!_#jM3$oc=Ma$;5P5<_L_tLk8&;M;+>N`VRKhCGD%&fJw zb#_d!Gd>cgUjNFk#}*vs4T#{d zE;|s)K9waYS@BA%)@sLnUzM~xoW9rHO?<9-7>XYBKYiHV9>AhR}7k8H$w-zTZ~VJ|QO~wH zF7a_;Wv0y>%~02Ea~iHQ?@^h({JZ>$=K6^fCoWmOJUA}SFLbKNIV~-%MO(K{?djp! zRXTZ5;`jUY_ReiQiO7QYz*y z$5q~fZGNv-?%g4O@0ZiHnKLe#Zau$C#I=!KP9V^(grlhF!QJwwo5SN<@BiiNlWT2Z ziP&^xU+Nmp;@Z6(yB1I1o|S5KV3Wd{Fvh6m*&n|AV-B6c%f_s$t9#_gmh}lYE?oi* zl-=E3{`{o+e3m8m=6jyk5#EsUWlH&JZs*U{vX<$0uWss|JpWts`Xx3(9)EYd7kT;8 zpiCzu+_}zfO7xrq)5L!KDUR4F^zDt{!fnsXueI#FxIarGSM!XWR>JCJ`TqCzA>nNY z6Bevk(Q)RC&oZBxhtAElo@t!U=jiAtA}X3_AaUaKX=O#lMqX*Nf(Hi}@5{&P1RXFD zebG6k$*L!0aoN;=9xtNvzj~~0RQ3=I51+5i+_2GO;bKvs)g~{=ySY;8^`WIvo@L=d8CKS&$HF{g>SKkDlyBbO$HenW)z#s#^3l0fD+6CW z$xMBeyHoGvov;6@H%>_^I?~Ims4RCbW}?csxa0*<-}fzIlG*vP$L+^q`2{D>aco@l zBXkCIge;;vU~RQqZDf7d&sK;pJI+mWv5Cr->VYf9FOEwTTww>{-s((ziJA)Q(2?u1))*hk1F zbltO4Fp0?8byJMnHdve0;``i}74qj=A`jMlj^DUAHnVU;1<#V>TmR=AG}xJN{q59p zZ>_8)PMa1TXv~-4-rUr4?R!^?IbZe9Cz(lB6$T}*pGCyXmT7tG;^I)S;p;vprziEk z`}n^~-aVc(Gcqaq!IvMb#}COYIq)Yt;a>m;_qKm;`W}Ax8QIyg)Z z!6$B~phRoPuBlCp| z3==1Q`0@C|pU-n|$8DbGtG45B*$fN8s_)a5`-X~6nR4J*Z$Q|yr)}KzT9XzrE4ccK z^GrU`I@NmZ_1&)&X1N7ESm+~ZZ=m>dLw|_p!;6WW1&-T#mpE~9B>GS8>>a^vGi|%mPFhcthfcL)-=L=Dfb0eQ1qF!Rxg}?$f7sUY#>X=i`N$Ge0c1_dGFo z`o=e@U;3whuVSu=eS7QMc0R$t?9A5mvd+>K8{hYo9G>n!k^S?cjY39}9u>F#Wo9a! z>Se1~-iYeo8<1tMWs9@Y6;6E~$hy?)6kVzB=(W=kG`NZZNT`r&jjN zZ9J^}Tt!0u$)WAXD@v{BPo4eiPw|Pft(Ss0xSK_`E;;q*=Z1tvmlO*p;b+U#Dt@N! zcrGXSbB;{K2ge_exC^s&;&Q&F|L!Q*D*Y~NO}@{J9SjU+vfIT>doOiAYk#?8U)o20 z7MtAtO+Q{R-m^;5Jtg(^?1$^ho8~-yTzx%r%I`gupJ$lmO11OJKH7Rc?sKkp&;&=T zhP{5*f^iR+UEtBU9k6kuL(8r|jgxEh8Krc#aXJL;>h6!I&iwpOKVI}=Z3%ZsOkw{0 z=dZ3_7Qgq;crxdfiUNZ_Pt@&f7_bbQ73aLW!O(T; z@C_iFnU*BkMz&p>H!<3W!jo(!9|UDy?!W77FF^zxHm zdpKBM+~j3D;uzD?k&`ju4#S1I1h?elnh_OiW4=6|w6^x_tf`+eUB%B>naq4}TL0k# z#}g+SnwTW-%r;=G`{7*ZZS%S3E2p8uI9chN*>38S>3Do>>IW&=H|0+A0%{JtVAR=irco6QjE~~tWktUpdtS}r;A`7gdo=YC^DUh;@z%)A|IY1x zuzmd+;l$VPoVzz}uDJD2qSVraqwQIHzwkvB5ETc5-#$Hb1t{=dO2i zA4y;lDRjS6zxVUs98J+gxr@@jTxRDlIg(M>DpUIO;dAXi+2*&mk7mi4t@(VY=Ax2- znbD>6vsZM|!h`o@wdPlszOJ~d@wM^wD${qoO`(D&Rx=DoDL!w@BX4)dTKA$` zpK!)|wSv~}8AlDz_P(`s<(}JJzVL6>2Ftk;ANWfSH7Qmv>iD$(l)~?1NsXIzL2jG( zTc`)hq)xZKcfHeFD39I1IQHJwlj^LgcK*f}4ezfg&Pu-f;`H~I$#LsSH%C8Wikg0V z;^`C9ytZn73{1}FG?L%!I$$aVKzigmR-_H0sS zQxdavXi!gn$#eai*!)cwS^igF*qC}*{npmMTaky+&UbV--`s2+=Wp!hH#h5lWR}(q z&)f@nx1Xh1JbskJY<@xKgopTD&!~TFtTQ8Db~F|~`!cnCmDQcK*F8e^f8NvF-njhj z^|U2zEHl$z{+x_w9Bu8dE%{%=jHbDrS(w2+u~Vk+#q$UM>z&`-D|q0ja_@$m@Pq=> z{GcvNmv?3d?sb%E6wKdM)AoLff%~fFO~=AA$_)Hua*j>9Jlt) zqqPUaE9IM-KqG1OeD;4=Rlochy8SH|k~U9Iy$9OO=F5ieHfLU)zyB6G@CiLjcTrpQ<8pYGbBV+qlZa{C=QeoH zol_K@-!Pl)KH$FNJw`2A^4c|E$~dL|?bb9iJvte17rsw)>jT{1tPbq)1qW z#2Kf1@f0U5`g1=;C~%%_^tAtf(mDG#Kl$}K@rj3oiO09XmqJ&rde(gY@loi!jHv3& z=ku!l?$x$5Ey)NKIT;xgshzj%^>43v&m=QH^sirgd{h6t=_jVYFu1vGTcl9f)>#P| zHuwhAjQ&(L#e`R%ntObG^{s!Cx(zf#|6G~;>!fLHT(YA5#e(Aomi1@dI&Xe|`aYd$ zrcY2nz=10(gCjR2FuvdWJ?^$wU|^t(UCoS^7M5xH@qR%;LOXZvTob>4o@=*Q<#yNF z2{)@}h2Cl6h|pQkJ2ixH^~5>i-}*B6J_O4gpCi#&-uQjvKBI8Oi$c+i?xqaO6d%@z zH^$%iX(L&|lieNpJJpfpZ>0?P{`nqVZU1+APAj%A)Q>#-#pLAWH43rbxfAjN{AXS) zzsli${^Z%P+dTHK6^e5f-BM%S=_!_L#DD2W&&9{QLd>@(mj%yu7@8yZ7svGiG?y)!AKM?!SE7wrS?~Dw?mZ4!?ZqQS-u^ z2`QUSxEyinJ(Oenp1JIS%@W=efkLwaStA8@r4Q|b54W0s_$Fe&adQ2~P0fG(94AS~ zx_qj-q0I7wG3o1a1-+in9rC~Af2g>(EsvNsEo$T4zq1-vZv3!VaZ>Q&bd{K#2`jqv z&!1kie~ZOTvFPh8-S%%P>a~}3{r~k?sN!eB@z>R?u8sfxs?NOl|6(B6OLb{)& zL+(RESy}!WvlSP`lu4fYGnIYE4vBm9_iYSa+?R86G<4X?%AR~x`fF2VL4Jb2WGwrS z58C!+ulN1Aw9h`${dhZg;7rNsf&KdC69N_$VKs}Be|M~ZA25~Q_~gqMEE>BEUjLYz zz{)p&s=#s|)2;e1_oBfrdCE~+6D$z1_saH8lFMX dkei>9nO2Eg!?X>Z1q=)f44$rjF6*2UngB{T(jfo< literal 0 HcmV?d00001 diff --git a/images/before2-smaller.png b/images/before2-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..991a716d54186b242ea0a09c13b5533f5719d6bf GIT binary patch literal 2605 zcmeAS@N?(olHy`uVBq!ia0y~yVA#ySz@W^*!oa{#TK(CYfq{V~-O<;Pfnj4m_n$;o z1_lO&WRD zmbgK;wrPfG-@#?({ajia&lUQGrBVWFE9Q6}k;r5hU3T}uqI%6{rcLub4WG&+2Mc^; ztZ@FJYg^eI=wjSB)3Hs`;@pOM>!`=Z{@VDA$o_I4_uAObkkS5c`&Sc(#!L9a>^5P7?do%RHuem zp9Jr9##vrLR(J-}DY*)s9e(l?2g>N1*M3uWUcIT>aj(63*8IQ;&(e%pPU4Nob5 znU*Kkm%HJUh@!|U8D62R^^;%ewp3-dTwn>!+7U2=YpR-wTWglu6_3hU&yqG*{hodA z;@e%$#ic&AtpR%kxGuI!X^E_y{7R!`oA%L*hdg8hS1wyIPoV3fr0wd?Q&;p%iz1DK z%Oh*+|K45c;$CZQ?{~I(+DpbO$*rf?o3}7sk~nCv?^#rWg!E5-hDaU81at4kqB23| zo-{$#1BGG}o?X|y(ZpgE=%s&;QDJ_8)#YBLq{gJUXJrq9qBfo@{KtJH@PGu@4jzjG zsy+#f=0WEwri)4!+R9xaLW=nK$oBq{zc+$`bd1bZM_Ulag)u$IM>QwJ9`F11Zo8X}}S)cTl3Hr@kZCzRNJd+uGP9+uhO{}18-_wiz@wo_r!{p=&_@}D2y9;!OWsxP9bW9_#a zpN`syO{m{@x5Rbsa?6(G5$E^rIs5nd?Wx5M8(dr7^UB$&%{;1ObH8s+vPkKltbc_M zmREiL-jv_?Y*~!ZhdF5u9KPquzucF6^Re~NQJ+-nmmPW~50*Cg@;$vCBX^-^-Or|2P}+Yyu$B`$X95eNM&oToFAzc5r1T3gU+<#)``k94(?7d zyd7gZ;Xu*7=|Oq1N1wRy60Hp8z?O*vsjvJCwO$N&6STYV}} zR=k)ox?%l{6WR_My_R98{Yp8kCC(X?ZMf!N|8~Rc+dnrRXJ7Da*0Pkpe%&!~B8y7` z9*eA8_{%A`Mejm&)Y`aL>v(hpW-T~e6{3~#m1eN)`-eB^}g68 z#P}mRG=JOc+dm6eW-459Vn4HJU+%JhnN|NUlq|fxCH$e2M$AMf;Sv|$mJ4jYB3{?K z-Tq7dJ*_{>yVRq-)X6*7w6Q*W(*$>G6R#Efysq53=;VC%O5oGXO?#XsMy-)pIL~V3 z>ey>B%R9sF$JejU09%yxO!6c9rOb08x2*0c#lG;j`}xFpg2n>&_cNcwr5W9k3s$o6 zV!3eH>i=C2@%?#+c!XZK6t@Luh1E&iQ%Kkc4qTUQT37%tq)D&KW_aR;MlMZA`s@iItIM5&HsPzMexI2odvo4VL8+ZD+(JIz zjIY;!u)ptDSzS!#yu*i8Hq2DF^sttn`t?qh-E_;}!fTeuhcjQ8B*v!}Za9nM!0Ce5 ziozUjn>(i8IJrC~$E|O33;T<6TJC@4Y!c2L5dO)rV?y;uhOZuG>UZ~9_+}q)cDDbM z>sq`(^WvMbp7ZDWjju%C{G=7O^VQmZk%yDR4{dRie`R+ztkIHZZ~XEtA>5@AlEOpC1F!gVFyGitHY>NWQRFHP3_T)*(_uMpQ;i*;N%k7jK* zd%^iMYqDj_*IeV081AWycmMrRzUo`nx}vo_IoH2GJ-+dtO^cHqi_ng~&^N_DRBdAX z!}}(kOix?FY|fDX$?(F|(~&F(&b~?KexN$jPh``n{>K#_N?UI62|w_v3O>ZPE8s{P z!yXx>R{ogWEyKx`vR<2>S@-^Q|NE-a zeNN);iseRqd0VqeQ~TeZ?%360*g@OvNUO_QmvAUQWHy38H@}J&2$Y7bd3x`3=FJ{O|6W~ pwG9lc3=AA+SyiBD$jwj5OsmAL!Qgn)5e5bZ22WQ%mvv4FO#p=IsK)>R literal 0 HcmV?d00001 diff --git a/images/before2.png b/images/before2.png new file mode 100644 index 0000000000000000000000000000000000000000..48cfc327a65b527fd73a8eaf144298e753e64357 GIT binary patch literal 2614 zcmeAS@N?(olHy`uVBq!ia0y~yU`%6RU~uDLU|?XlH7(JDfq{V~-O<;Pfnj4m_n$;o z1_lO&WRDI~ z{R&rBaE1szQg-z3Yi*vlV#yU1UtxI_w`kQP%^{amxQYx8uFAZ$_~H_|z{MT?4-7A= zEVoM%@zGXeJ-T?BMnZ>t-+69di(Y=(ee;g& zVaA(oIPI`)ZZ19k>4%VXOn+TXn8fZ_G~NPxz<-+_^%RD@%et*k*~}qUFTT2Q+b^6Wp(4Uk@0d12 zTaf8&9s7=)*PEOEzDnEoYsD`s!<70>Gg317lr>{5FYSEY!gT4+(T_2D3uO0;zsi4b zo-0?^p?UsaufzN=&Q^R4efxWjiSxhU&HMRGPQRV|qp-u@#b@JN`^__KBNkuUmnWa~ z|H}hr?tRX7A8WIeU)`Vg-N()J%tV{ByZ3KOv)#W)=$T>6Ry+1>XP(cyli~PNf5y3k zmu%)Oxv}t%MYZ9S2Y0j$`*k#&O#eTyKg1a%&(#xgwxpt5==%^jlF~j6=Cp_mx%ak|jOQIy08v zY;a5TlrZRin0YM3Zudm_*6(+ZMFq{(*t>l0g_@-c7A#o7w&Leh=d(p~p8wp>w(0DN z<3dl>4((5y`B%?(hV-(>?JVD>a@ug7PMK;qc?atnhPD5?Ai>)hA+mC<;c>>p9$G93 z?w#wHUd!;D>(swl6qCH8y_-=bKgVH}+APk0yFy5ddTcYmT%;*<<@@a9o#fP4rXZ$Yh zzHjo?@;Xd^{s<60yPunnPtGh`BtB0)WCdRid!%CKR6uB1L7_W_tnJm!an5(`)(0$34uzFW; zfM0nSp3G|&b09o5z(OjrX*J)^i3e)JP2L~ho^*D3*~N_IGh$6x(!ZlRFT8rM_%K>?`}EI?`${XOR|@Vfy{F2x`|iz* z(un01rYFBmG@5n&fZDC;35$Q5RL|bf&9jPQV%oOu{YLMTw|0kB%$ojiLG4YE6>oQK z{;+e(wO8*AmuTEN{WH*Y!Ony8WoH=jeC|6`b@+UfMSD|oMp4ARQyKGE3WX0YOWW=L zS$M-2<&_ql&z^tWUst-#;VE0&ew9l#9X6d8etR7CGWj03FID@W?$WKlqLp}(cJ39n z&$`i^lBeTRxcQ9J^H;Jf1eOJTTIIjtp~%hmHeaJzXU!De@l~Mw?d1L>UiA}2vz{-W z`DRnCp0`Q$^~C))3)V2+^^TTJ@omRts9E6gPdoG)j$7y z$NiAigeRc%9AY4tx>r(7a($8fY=P&$7K-lJc;Ubcx7_Bg6h^utq#$v{2J5Len@XS$7XUYBjIKxS4_@f^^+&%w_UBj z%a`ql3hTMb?d6)vB$#-&92j7q#|sOdAAq{6g<=l`nSs%~p#J}R_x?;Ls8GiLLj zec$H1$>*pho2&3+?)fuk`5d4AO^mzAEM~=O>;3cg=%k-{64TphJe_mi(fO;gG)`S8 zT6FNgr|HFwDkbNa{_>Vr{pDvI?v<+Ede}Pk+M&nA8_U;}sF@ip-mvY@=FsLV?=P%B zv0C?rVes;k_aoc2Uvp1-J8#pSd!6&EMfc{H74hZ&k5_12ULh+U^MAAO%#R-Bzbo>S z^{ngt|2aNh)OpDH$Gse@iWR)azn0$BDTpy!UFUDLY>6W>2OQrMjM z^uH8DAIC0dx4Nl|jl+KMZ)HDqLiUmHg|9}R+6yNBz1u48GV5?_mz<8c~vxSdwa$T$GwvlFDFYU}&amXrOCk5Mp3pWo&9?WUg&s lU}a$7ILoR6MMG|WN@iLmZVd*=OV0 literal 0 HcmV?d00001 From 1495195eb53fbe0db8712c6290198d4e2079e442 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 20 Oct 2016 01:01:20 +0000 Subject: [PATCH 0468/1080] README: Add a third image. Also remove the existing image, thereby removing the filename expansion example and the file-existence highlighting example. --- README.md | 4 +++- images/after3-smaller.png | Bin 0 -> 1673 bytes images/after3.png | Bin 0 -> 3427 bytes images/before3-smaller.png | Bin 0 -> 763 bytes images/before3.png | Bin 0 -> 1461 bytes 5 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 images/after3-smaller.png create mode 100644 images/after3.png create mode 100644 images/before3-smaller.png create mode 100644 images/before3.png diff --git a/README.md b/README.md index 0c0c25b..69159ff 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@ Before: [![Screenshot](images/before2-smaller.png)](images/before2.png)
After:  [![Screenshot](images/after2-smaller.png)](images/after2.png) -[![Screenshot](images/preview-smaller.png)](images/preview.png) +Before: [![Screenshot](images/before3-smaller.png)](images/before3.png) +
+After:  [![Screenshot](images/after3-smaller.png)](images/after3.png) How to install diff --git a/images/after3-smaller.png b/images/after3-smaller.png new file mode 100644 index 0000000000000000000000000000000000000000..d6aaa7bdf30aea607d98d8fa23f715534cb3bea7 GIT binary patch literal 1673 zcmeAS@N?(olHy`uVBq!ia0y~yU`SzLU=ZS9V_;xdJF~ijfq{V~-O<;Pfnj4m_n$;o z1_lO&WRD&6 zh2cL4F4((#G6Mqxdx@v7EBga35e93E=+|~{85mf5JzX3_A`ZWe$o2_Nm#Fjdj^1Dz zGfQ;I#TL&U8O`D=IbkHg7*$v*GWDPEKdC#Eg$9G^Q+k#nPzhwS*AE&GUc?rkdTmpp<(0CpFc~*d;3_t%9!eTnBKeUb-22^YUt~; zGsNsHV(pi=|99nj#@&vdjsp&!oX=|Pb}UH>c zecIB`&s(@_mzBc2>C@R)U+p@1(lcUh*pnwuI##{@Q1$Wp7n6Nm-G}$?v01X}>OtY9 zL7KL5{7;K4&!!pox+#}h$==N~HrBeXQ7! zeqPR|=7&Jsdhy)c+!t@(x;i>GzK}bfp3cY+|0nrf|G`tIy!v{2E@W-}bYY=$&BsTq zqFk*S&sBvstmU~gTjSq4o7!I{zkmJOv0;P5^2;ap?X#O_U;l6MEumRHYJGiupKfi< zF4-BAlb^plMvvd~{fie1uD^~wcAmWfnfZ|}wp8zxBg zwrNd0wLUx~&qTyS8>mMZ%5qtHr*Z~w!j z6_ZX{RDRK5=a)}g=XUtUR8u=1FK_RgH*dZ)cjx&UwP9&V?d$Eg-=>9yUF-U>*uB5v z-JP8c5uu@?yLat!x^z9Ms>-Ums%k}u)^!sX0hYer-oW+O+wVT-U%7IL!h|M=W68fn+A!|^PyYF^% zcXNB1&pzwn=@}V#{bk9bRjas4OG^V*hU}>RuE*f8{(AEFcXw}W%Z)ye_xi@h)uUyq8KKMOFr049pN6Y`!{joF@T%rGe#hNuOXVaRU7B=`TcaDmZdQ)b7 z>(;FYC05txWSrqX;>sNT+iy>tJGb}RwXk{}V`E{yc4d{nudc4Xv8(iT z*RJ>X_A+nS^0vRT^W$+}HQ^jHX&td{`?3!Y9Jg%Sretp~&&OxxSrcP1a_n>J<2hhJY`vmAJSe!j7#rR5X%jVoDf_7p#!zUIxFoO5T+ zY*@6YDKIclM^EqB?d|!IF)=ce^rmgkzt0!3Nra14mXEz(#!_g4_&IA8ZL?`2EZg4P z-u}yb@3w8z#P#D;7`&DSMd^rb+rEACzI}05QjW&!)wa8M9X3Alw5ag^zrT)K|NN;b zD=jU|%If<2_pi2@T=vVPir3e4!@|RVA5Tq9jfshQ^5#trgRk1;7q_aDlRO+BEDinT zvO`_ACx|m5o}q3!tC!h^cmG>Ib#PpJcgvNFsouw*f0lA&S?Xee#VlF-*xb|_x8)^N zB`UA}Z!V}f@xk7M59IsLpH+PQueRshnKdWw7C1L7wHN1=bohN>nc{&*7#JE}Fff!FFfhDIU|_JC!N4G1FlSew4FdxMTavfC z3&Vd9T(EcfWCjKX_7YEDSM~>7A`I3R(XZ{^GBEI@d%8G=RNQ(yr`ji^Tl_~NELmvDQ#=6$A*JSX`ptE*7+9W3IdU zvS8U((dE%m2@BqGMl&*B+H-lC@8La_p9{Xe3f;10%Z^=V#aezdYxXlZawVMBbXZ(o zGn12(^Ty_MekEmP-EZ-GDgl^L@aCsaSG?Nt z_MDdA#w9_TpFVvmczldkL`>|_wYAYVwq}c~2%V0cp}?V`rPUO+`sg&>=sA}P7!RB( zNO&HUuucBLLRKd=%YAozXPYhDut8wr#ECnKo^su*`<=Vz<1y(K>(;eJtv$B0__=_* z{QD_(1*WH`={AS0c1=!xY+Gt;Yy0s|@%e>2c1WB(dv-_RW43*NK6x)$y3|o?>aHdK z0w=3IoPD%g@WIQ>&AN;RwzhLsD*yedOiM}GuxweI%Fe{YY~NloJUBH~+jG*^ty{l* z_^`p^8HXUlx_AaTZzJzxix(_EvoV$F!J5d;83qy_lO!c2MOYkd)TVk>J~+Vms>I4~ zzTMr2rG;BHrh1u~nod-Sj*4=-!pq6|aQpqb(+_tPJY;HaZk7%5=kILMZ)y9~dLbZ> zllQ5;e9Z(`?`ab}Jr}*{?AY*i&$Hgw*VkW8Feo@RMU&;gjT;e@QbI$guF#o&Ix;ra zcT&xxPW3rOh11%uwy@dRA^20YHMjJcztc{n^&)tJf}^Y7Nj-RYUw*6#{|!qIWH7S zwZm?_Q?RqMGnwhLX8rp2-`)86rFz|@dflq3tA$_m8$CZack_*PTy*4leJwEU@QtYq4RPz+4<C>-nGdl1_ zVd~VW0jsY@Y)awu^7h`Cbd<|OMJOaJ%xV4g$5+GST@w-%_~h++y1Ka9&0j54NT^#- z`TIbsLw-?IJrl!|B1?wPypQTQI5-ZRnyUTr!(o2sg#imzuH=lb{W|q(ZTjlH{r&tl zHa0n{lJoQRO{C6lI38d9)|7>v{qfE8`K>-_ccmM5?b;>SKYjXiWlKv*ZZVx5>+AN) z*RWl=oAUVVT!tMbFM}qfl$V?P&$shk8|FQ!r@K43puk{jl&+~%?`1i!{~uRWW^L8J zXPFqGHTBbri;EX+*}8S2inf-P&Nq46sws+!ipulSkN3%5$uM!YTT=J;>-CxkjqGpo z{=eJ({!-Yd&!5}Z9)H|#?>EV&^pyy!V?t5UrcnNu-zU9!lQSvB(Xr8cS%i<*qW!ri zm;S345*CgO4RxJ-@`!x>pNXfZ>#H-=eYxnaa&oS9xz$p~BF!Hcr8YO~%zZn@Z_3G( zF#a_!Uc6ZNe6eL*oX$%IoDn|}Erv3VHXMS@B zbBLb!_Qi`9c}%kZ|HoL}XU2mmY^}cU&c|pzIrq}VQD8;TN|&8wZ>2nqtgUY+?e|(L zG+B&U)!2Bl%F4?xXH1x2@S?)Ur$=I@-yDm?^6F~Oc#~T@3K#DsDdv$Okig>wE`o72x**}mSObL5Rodzj_&JqwpCTGXVnv+{G=>Mwu) z{yl1vmY4T#LzSeYWRgnP4sCV&sOoCZ`&U-2SaCur*fNT}v$HeN-JRXj$k_Pu%IiT4 z6^eFoB?4z>nf|%n#QNv<9LpYgrAg6m6>9Za_y7M_z5MA~MuW_KHyyvJ^~ke(dU^`7 zubV&r{)Vceopav4eXDYE%^IEEH*Y)F)Yjg-apT0hcX{V#nVx=hBSS_-OUrA`=Z}w% zYfki-Q)ip5Et2Eqv!z4D$Lmqx)+(3XiQ%75JuP~3cei+h<=Si$sfRiu&sc=&_P^bt z~NN6ZygR5HlmT%t{=x2ZZbXtG$!i5L*p7-?hxD*x| zs`<_7Xli0w6Te?hZSv&cNep%G-@0Drklg)H!mNDytXW+jJ`~KcsT4{-H>Yv_eECnG zK24Z0qvPGXJQ>R(7E4RZ3$NeqPYS3%E}r^0!>}$OK!71)YuL(d+r+ZAN;Nh%mTivT zl*0M!?CkX5xvN*N4h#xnI`Ahh>GCq)7cXBn?%!{}Y11a168Xv}f(!>*IE9ZSFI~D+ zLswV!+aEzeK@B~DJ2iPsZUzPY$O*x1nUZ(Dik!pOx3rwZn| z)$(v@do7)`cI{dd37(LZAyZDK{CT(gy~m{Kda+5dv9g|@E-ZBB<7{6Y@;JZi>&xZy zCoMUe)$;JklarHGPU`RbaVYQGV&Bhs_xIgR`~Bw4o5a@^_5W(NZQC|U#s1F+=Tj+0 z(__8ucg~q*ntdem>Tg5CF#Sj=qo$O!G$jKAf#2WXyO)-ln&sSRXyq1v^x@%Q4?n-Q z>C?sQemrDXQCCmCzpr*j+1pvQcmD8g-*u*bxi;fU76U7LrQ1HfzPt>d%ayrWnQU!s z55HO!qQ&4)Tf6t}o9^!Ji+Atl2G2cx`t;Gan>HDxq^0q#ULCf2W7buzFJHbS+}~Hr zpx`#Y@yrZE=Ja!O91{{0?0!68&bhPWqUz;Uc5<^U1n-rvRjS*+Pj1V>dxw&L#c^%h zzTH?sp@Ct>{Q3Tqe0+RFzQ)!6Ep1QT&Q$a3@}6Sm1StWudVW!elkTzS69_jOiV0lk5R!?8{^_-N1J~(@7ou4n{U?B=g*!Ux_nvK z($ezB+wJ!m7`R%Q7<8tomXyxS|J=93_>VjDojt;?a`SV)U$$=P>f#a+6=h^7dvl}l z!-o%!R&jB0H}==tGkpH@|I5qEWt-)-bMEhx?H1QRc6PS;$0w8ht)56;4O6=tX?CSu zw||@1uE4;+if1#^KV0^=e>k`Np5XWIYyWq4c5b}D+TcB1@8(`dmV$jJ_pF`A_~X{L zBPUXA{{Q*>e?R}DM~@0VK5|`gHA{krZOO7_e5ZK& zuHC!pGuJA#rorFS(=j^w_J&=P)qI7n@3xdW+fesuV^M6RJj)q6#p!FGf9EcEaqiHC zt;LND^6jFgDtq_tz3{Tc?Ecc#t5*vO3N~)pVlv0JT5SKHPuy14)`d?`i9UJuOi4$F zXSv_pq8WP^8%XtDcv*7cWy#@JKJ#pT&a*22zJBuuX@Qluax|(h^qcjliWDW>pU+sI zzu=X5!gb5%`qkye|12d$Td!CaANgNv|6k^ASluy$W${P9zG!5A+R%C64uitq{)Ui( z(zSPb*q1alIQaYL@Nyq+yZLwKyw`W{hFP;4@YRXG&eHzyo=ZWOts;l*fhzO8eH?f8 z?SDVx&L4hdVU`!y*GdOIUwbQR_BqRC${zCR(r4mDrF!N|bSOxMsr*T^8mz`)AX(#qIE+rYre lz@YPE!XXq5x%nxXX_dG&{8)3Nj)8%J!PC{xWt~$(69B%14Ba#1H&%{28MmEry73tF%YYuWfzcPQX-pLClf{}4Q&nY>o0e#Je$ceNp9ZkuNrA{coP!@jz53VWv|M^bBKRV<)wSxO5N%28-Kpq zdf>_-)}<$kdVkLdI8%|tw(#km(uo;md;$sVo3{AnGe;d#U^vpAG{H2=u4&^WdAZ^p zhx=5HemTP(nR;&O{qprD46&ELrd(ZYnp5!Wg1CSM6VIB(%cQ*)bm{+4%HG-^nBcKP|HOgny)u4>9V^+H&rI5JTcgwC7q|VKx3w*Tk*A(A zMoqA1K7Rk7l)}V%A-}^7&sh0ps4mnm2`o*U*U`KwVqL_U{dYSj6jrocos>OOAvy2x z%YV8G1``wC&aM3&cmE|b7n_~i=H|qMLe(1DwJZPTJ&Qh7AUU(X>4r|EwYVJ@rvMYV@aJrg6hM}O3O@P1*F>fT&IACcKkHVh1T zXEw|$)-8O?z`&qd;u=wsl30>zm0XmXSdz+MWMF8fYiOWrWDsItU}b7)Wo)W#U|?ln i@IsA|2}MJ0eoAIqC2kEft9R}LrD{)CKbLh*2~7a_*exXh literal 0 HcmV?d00001 diff --git a/images/before3.png b/images/before3.png new file mode 100644 index 0000000000000000000000000000000000000000..40c360151a09b90ea2b449b4e8f07c9a16d5837d GIT binary patch literal 1461 zcmeAS@N?(olHy`uVBq!ia0y~yU^v0Rz@Wmxz`(%pa;w&E1_lO}bVpxD28NCO+21sKj0E!u(pVPZTFUefn~3!i(^Q{;kV(nKB1`+_59!C_Fa)~ zS;@TT=8wg<@8s~t1a~!t=Nx+GzN;vV%|vX%#MzP-oEvpwwb^n_gSr^KPewWGuWgyq z#Fp)xx^|b2ic6>9w3@p&93T9vI{)|4z2bAfosKuH{rLOwyyunozL(#7{=LrT`<@n^ z1V-+N1OLSs`9DOx_uaH+&U2QuS%ey;w#*GD*`+bx8kMrF6{I&O9@lC6*ecekni>GL- znX>Ed+^;Y7dSpEIk z9`gq7s>naDo)m53GuxFSd*hglx_E_W!Zxu-lf2*Mt+hJAS<&KBvbeI@Fzvp^tdcYD zzVjw7uUENp(bv__xAnr(pVMZ(YJRNoEajtU-1RjFT2p!|TGmLf;hr|HQ20cGu-$?7 ze~gFU+N&r&W_!%=C_-nU;PfVo%q@?OT3=3lvvaEb-mQ18u4f9(IaX()G08*W_64WD zg_BNhV#uzj+@g53b$V5`}SCWdNt$ohPs_jXZ4%;PsQ4rJ>quMT*6VBqu72yi+|}Y z8T)*-s}_e;SpOfrx%St~EiuJ%1#EqjcW;~S^Wc_|=>N5K@;mtEZA`bArP0E1cFvR& zjy219q&PZV?u zyDzSs<*U5jDdn-)!$rK2an?y9`8(FcJU=<!}BS3_gi}x}dOTPm}-08yXwD#ZDiz6#91Yee8P45Y6L(_SK5%7vC7J zE(m<7p7K*+;slo)+}s*=?Rys}9K2h6cK#2O3HE6f+`sfxejV>&o}BhqwB~**SE%1T z`+2uIlae9qr<0F=(DQU(DsZXuYSx^$66OW* zue6_V$js|M?Kef^@7(;~4>+TQKF6+T-Miw1>0#~Pfd_5nMJ@*SRX;JDY_Vm^6y>QC z%CBTk=k$26?`pV*Ou>Qdr5d$joA#u;+;6G+cO)?9SbkT8={Ij{1y3#i%q*3IZLcD^ z6~9XCjIUzberQ?n$8?cN{r5i1EV&?kq5o5W&aS2<{TsrU_^zp&ZOdcW^gYa8aT#Mz zid(DNw&X{GruAxy6U%anjvuidCr-)a?^RuH5;;&moZ;c{XBQC zINLAAUp;Plw{lC4XFvJ3`oh(y^Y>X^ndDFS;b&uYUrEIxzvwz&dq%zUhigBtJ!lb- zt^6*#BI3ZE2l)%uA3S2|tTl~+fkCyzHKHUXu_V Date: Thu, 20 Oct 2016 01:01:45 +0000 Subject: [PATCH 0469/1080] README: Set alt="" attributes. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 69159ff..2c2b6d6 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,17 @@ them, particularly in catching syntax errors. Some examples: -Before: [![Screenshot](images/before1-smaller.png)](images/before1.png) +Before: [![Screenshot #1.1](images/before1-smaller.png)](images/before1.png)
-After:  [![Screenshot](images/after1-smaller.png)](images/after1.png) +After:  [![Screenshot #1.2](images/after1-smaller.png)](images/after1.png) -Before: [![Screenshot](images/before2-smaller.png)](images/before2.png) +Before: [![Screenshot #2.1](images/before2-smaller.png)](images/before2.png)
-After:  [![Screenshot](images/after2-smaller.png)](images/after2.png) +After:  [![Screenshot #2.2](images/after2-smaller.png)](images/after2.png) -Before: [![Screenshot](images/before3-smaller.png)](images/before3.png) +Before: [![Screenshot #3.1](images/before3-smaller.png)](images/before3.png)
-After:  [![Screenshot](images/after3-smaller.png)](images/after3.png) +After:  [![Screenshot #3.2](images/after3-smaller.png)](images/after3.png) How to install From 035d3eb095a4396843bffbbeb640fe97e9a0dff2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Oct 2016 17:46:42 +0000 Subject: [PATCH 0470/1080] Follow-up to 28d7056a7a06: Fix test expectations. --- changelog.md | 2 +- .../main/test-data/history-double-quoted-escaped.zsh | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 35cbb06..4af6af7 100644 --- a/changelog.md +++ b/changelog.md @@ -76,7 +76,7 @@ in this area. (b4537a972eed, bccc3dc26943) - Escaped history expansions inside double quotes: `: "\!"` - (28d7056a7a06) + (28d7056a7a06, et seq) ## Fixed highlighting of: diff --git a/highlighters/main/test-data/history-double-quoted-escaped.zsh b/highlighters/main/test-data/history-double-quoted-escaped.zsh index cd08cbf..c447a78 100644 --- a/highlighters/main/test-data/history-double-quoted-escaped.zsh +++ b/highlighters/main/test-data/history-double-quoted-escaped.zsh @@ -32,6 +32,7 @@ BUFFER='echo "Hello\!"' expected_region_highlight=( '1 4 builtin' # echo - '6 14 double-quoted-argument' # "Hello\\\!" - '12 13 back-double-quoted-argument' # \\\! + '6 11 double-quoted-argument' # "Hello + '12 13 back-double-quoted-argument' # \! + '14 14 double-quoted-argument' # "Hello\!" ) From 5398949cb36ca10acfc28286604fd1b69f2ac7a4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 24 Oct 2016 11:33:40 +0000 Subject: [PATCH 0471/1080] changelog: Update for changes pulled out of 0.5.x. --- changelog.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 4af6af7..26b93d8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,16 @@ up to 28d7056a7a06 +# Changes in version 0.6.0 + + +## Added highlighting of: + +- The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. + (79e4d3d12405, 15db71abd0cc; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting + + # Changes in version 0.5.0 @@ -27,11 +38,6 @@ in this area. - Aliases that cannot be defined normally nor invoked normally (highlighted as an error). (#263 (in part), 28932316cca6) -- The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. - (79e4d3d12405, 15db71abd0cc; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) - -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting - - Path separators (`/`) — the default behaviour remains to highlight path separators and path components the same way. (#136, #260, 6cd39e7c70d3, 9a934d291e7c, f3d3aaa00cc4) From 3d74aa47e4a75c205b10690c45c02de44e84cd13 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Thu, 27 Oct 2016 21:29:55 +0200 Subject: [PATCH 0472/1080] Add Fedora package --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 8f322e1..d6d91dd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,6 +5,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] +* Fedora: [zsh-syntax-highlighting package][fedora-package] in Fedora 24+ * 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] @@ -15,6 +16,7 @@ How to install [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting +[fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting ### In your ~/.zshrc From 626c034c68d703d71eeebe539edb55888bb26ae1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 29 Oct 2016 16:55:32 +0000 Subject: [PATCH 0473/1080] Add FreeBSD port --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index d6d91dd..e2a9394 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -6,6 +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] * Fedora: [zsh-syntax-highlighting package][fedora-package] in Fedora 24+ +* FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`textproc/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] @@ -13,6 +14,7 @@ How to install [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git [debian-package]: https://packages.debian.org/zsh-syntax-highlighting +[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting From fed37a90ac0ebcc59fe7090dcbf8d2d6c8acf197 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 2 Nov 2016 03:14:53 +0000 Subject: [PATCH 0474/1080] 'main': Fix a bug concerning command word with embedded colon-space sequences. Such a command word would, if not valid, fall through to the `type -w` case, where the output would be misparsed, consequently the forward-compatible [arg0] style would be used. --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/arg0-colon.zsh | 35 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/arg0-colon.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d7d292d..1311c74 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -147,7 +147,7 @@ _zsh_highlight_main__type() { fi fi if ! (( $+REPLY )); then - REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)#*: }" + REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" fi if (( $+_zsh_highlight_main__command_type_cache )); then _zsh_highlight_main__command_type_cache[(e)$1]=$REPLY diff --git a/highlighters/main/test-data/arg0-colon.zsh b/highlighters/main/test-data/arg0-colon.zsh new file mode 100644 index 0000000..8955bd2 --- /dev/null +++ b/highlighters/main/test-data/arg0-colon.zsh @@ -0,0 +1,35 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER=''\''x: /' + +expected_region_highlight=( + '1 5 unknown-token' # \'x: / +) From 5625e30b8779f95e9c90744773be653aec48fbc7 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Wed, 2 Nov 2016 10:58:15 +0100 Subject: [PATCH 0475/1080] 'main': Fix bug: no start_pos=$end_pos in comment short path --- 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 07049a9..5cc712b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -373,6 +373,7 @@ _zsh_highlight_highlighter_main_paint() fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style already_added=1 + start_pos=$end_pos continue fi From 347cf0eb06a9705e16f7806486fe23b80665fbd0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 2 Nov 2016 15:54:02 +0000 Subject: [PATCH 0476/1080] 'main': Add regression test for previous commit. --- .../main/test-data/comment-followed.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/comment-followed.zsh diff --git a/highlighters/main/test-data/comment-followed.zsh b/highlighters/main/test-data/comment-followed.zsh new file mode 100644 index 0000000..af4e9b5 --- /dev/null +++ b/highlighters/main/test-data/comment-followed.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +setopt interactivecomments +BUFFER=$'# foo\ntrue' + +expected_region_highlight=( + '1 5 comment' # # + #'6 6 '"' # \n + + '7 10 builtin' # true +) From 2dce602727d715f142b5067be4f85de84d98a8b7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 11 Nov 2016 08:34:46 +0000 Subject: [PATCH 0477/1080] driver: Be immune to weird aliases in the calling scope. Fixes #390. --- zsh-syntax-highlighting.zsh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index ec01306..b1e3fbb 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -27,6 +27,9 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +# First of all, ensure predictable parsing. +zsh_highlight__aliases=`alias -L` +builtin unalias -m '*' # Set $0 to the expected value, regardless of functionargzero. 0=${(%):-%N} @@ -390,4 +393,11 @@ zmodload zsh/parameter 2>/dev/null || true autoload -U is-at-least # Initialize the array of active highlighters if needed. -[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) || true +[[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) + +# Restore the aliases we unned +eval "$zsh_highlight__aliases" +builtin unset zsh_highlight__aliases + +# Set $?. +true From 50fbb5f76e895f895aa44ea59c71860fa2c99b69 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 20 Nov 2016 05:39:17 +0000 Subject: [PATCH 0478/1080] docs: Update Homebrew link. The upstream repository has been split and renamed. Fixes #391. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index e2a9394..5080b29 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -16,7 +16,7 @@ How to install [debian-package]: https://packages.debian.org/zsh-syntax-highlighting [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting -[brew-package]: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/zsh-syntax-highlighting.rb +[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [fedora-package]: https://apps.fedoraproject.org/packages/zsh-syntax-highlighting From 76ea9e1df3166209d5f937f57a0833f26b1a01bd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 22 Nov 2016 07:09:29 +0000 Subject: [PATCH 0479/1080] 'main': Highlight possible history expansions in double-quoted strings. --- highlighters/main/main-highlighter.zsh | 7 ++++ .../test-data/history-double-quoted-no.zsh | 36 ++++++++++++++++++ .../history-double-quoted-unescaped.zsh | 38 +++++++++++++++++++ .../test-data/history-double-quoted-yes.zsh | 38 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 highlighters/main/test-data/history-double-quoted-no.zsh create mode 100644 highlighters/main/test-data/history-double-quoted-unescaped.zsh create mode 100644 highlighters/main/test-data/history-double-quoted-yes.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 617f820..267cdee 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -818,6 +818,13 @@ _zsh_highlight_main_highlighter_highlight_string() 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 diff --git a/highlighters/main/test-data/history-double-quoted-no.zsh b/highlighters/main/test-data/history-double-quoted-no.zsh new file mode 100644 index 0000000..7867e83 --- /dev/null +++ b/highlighters/main/test-data/history-double-quoted-no.zsh @@ -0,0 +1,36 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "foo != bar !{baz}"' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 24 double-quoted-argument' # "foo != bar !{baz}" - no history expansions +) diff --git a/highlighters/main/test-data/history-double-quoted-unescaped.zsh b/highlighters/main/test-data/history-double-quoted-unescaped.zsh new file mode 100644 index 0000000..c828b44 --- /dev/null +++ b/highlighters/main/test-data/history-double-quoted-unescaped.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "Hello!"' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 11 double-quoted-argument' # "Hello + '12 12 history-expansion' # ! + '13 13 double-quoted-argument' # " +) diff --git a/highlighters/main/test-data/history-double-quoted-yes.zsh b/highlighters/main/test-data/history-double-quoted-yes.zsh new file mode 100644 index 0000000..88c300e --- /dev/null +++ b/highlighters/main/test-data/history-double-quoted-yes.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='echo "foo !bar"' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 10 double-quoted-argument' # "foo + '11 11 history-expansion' # ! + '12 15 double-quoted-argument' # bar" +) From 8d5afe47f774edf7f71b68b63acddedc5cf5e946 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Dec 2016 09:06:32 +0000 Subject: [PATCH 0480/1080] driver: Be immune to 'alias' having been redefined. --- 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 b1e3fbb..fff47d1 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -28,7 +28,7 @@ # ------------------------------------------------------------------------------------------------- # First of all, ensure predictable parsing. -zsh_highlight__aliases=`alias -L` +zsh_highlight__aliases=`builtin alias -L` builtin unalias -m '*' # Set $0 to the expected value, regardless of functionargzero. From 74949c2d9198dc8be9d1f3c6bc74c16a35098218 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 1 Dec 2016 09:07:37 +0000 Subject: [PATCH 0481/1080] driver: Don't undefine aliases that begin with a '+', to workaround an upstream bug. Fixes #392. --- zsh-syntax-highlighting.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index fff47d1..52d35f2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -28,8 +28,12 @@ # ------------------------------------------------------------------------------------------------- # First of all, ensure predictable parsing. -zsh_highlight__aliases=`builtin alias -L` -builtin unalias -m '*' +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. +# +# Hence, we exclude them from unaliasing: +builtin unalias -m '[^+]*' # Set $0 to the expected value, regardless of functionargzero. 0=${(%):-%N} From 67be62107be0882f7ca09a191ffbafcb1ee9097a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Dec 2016 09:50:55 +0000 Subject: [PATCH 0482/1080] tests: Move some code in preparation for next commit. No functional change. --- tests/test-highlighting.zsh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 1d169d6..6f7fa96 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -47,6 +47,19 @@ exit 2 } +# Set up results_filter +local results_filter +if [[ $QUIET == y ]]; then + if type -w perl >/dev/null; then + results_filter=${0:A:h}/tap-filter + else + echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 + fi +else + results_filter=cat +fi +[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } + # Load the main script. . ${0:h:h}/zsh-syntax-highlighting.zsh @@ -157,19 +170,6 @@ run_test() { } } -# Set up results_filter -local results_filter -if [[ $QUIET == y ]]; then - if type -w perl >/dev/null; then - results_filter=${0:A:h}/tap-filter - else - echo >&2 "Bail out! quiet mode not supported: perl not found"; exit 2 - fi -else - results_filter=cat -fi -[[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } - # Process each test data file in test data directory. integer something_failed=0 ZSH_HIGHLIGHT_STYLES=() From 5efd062a4d2c8fe37864a0108059a33e37656682 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 2 Dec 2016 09:35:29 +0000 Subject: [PATCH 0483/1080] tests: Add a regression test for issue #392 (aliases beginning with a '+' are lost). --- tests/test-highlighting.zsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 6f7fa96..94c4152 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -61,7 +61,19 @@ fi [[ -n $results_filter ]] || { echo >&2 "Bail out! BUG setting \$results_filter"; exit 2 } # 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" +alias -- +plus=plus +alias -- _other=other +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" +else + print -r -- "not ok 1 # 'alias -- +foo=bar' is preserved" + exit 1 +fi > >($results_filter | ${0:A:h}/tap-colorizer.zsh) # Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style _zsh_highlight_add_highlight() From 4f49c4a35f1766da6261414764a8f78fb3b59240 Mon Sep 17 00:00:00 2001 From: Giridaran Manivannan Date: Thu, 15 Dec 2016 12:42:27 +0530 Subject: [PATCH 0484/1080] docs: Update zplug install instruction The latest version of zplug has deprecated the `nice` tag. The `defer` tag is the preferred method now. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 5080b29..8532560 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -82,7 +82,7 @@ Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`. #### [zplug](https://github.com/zplug/zplug) -Add `zplug "zsh-users/zsh-syntax-highlighting", nice:10` to your `.zshrc`. +Add `zplug "zsh-users/zsh-syntax-highlighting", defer:2` to your `.zshrc`. #### [zplugin](https://github.com/psprint/zplugin) From aac4a4423898fccbd1ab72c369ac09995a9139f1 Mon Sep 17 00:00:00 2001 From: vinter Date: Thu, 15 Dec 2016 21:41:35 +0900 Subject: [PATCH 0485/1080] driver: Fix duplicated slash in error message Fixes #400. --- 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 52d35f2..0251d1e 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -340,8 +340,8 @@ _zsh_highlight_load_highlighters() local highlighter highlighter_dir for highlighter_dir ($1/*/); do highlighter="${highlighter_dir:t}" - [[ -f "$highlighter_dir/${highlighter}-highlighter.zsh" ]] && - . "$highlighter_dir/${highlighter}-highlighter.zsh" + [[ -f "$highlighter_dir${highlighter}-highlighter.zsh" ]] && + . "$highlighter_dir${highlighter}-highlighter.zsh" if type "_zsh_highlight_highlighter_${highlighter}_paint" &> /dev/null && type "_zsh_highlight_highlighter_${highlighter}_predicate" &> /dev/null; then @@ -358,7 +358,7 @@ _zsh_highlight_load_highlighters() eval "_zsh_highlight_highlighter_${(q)highlighter}_paint() { _zsh_highlight_${(q)highlighter}_highlighter \"\$@\" }" eval "_zsh_highlight_highlighter_${(q)highlighter}_predicate() { _zsh_highlight_${(q)highlighter}_highlighter_predicate \"\$@\" }" else - print -r -- >&2 "zsh-syntax-highlighting: ${(qq)highlighter} highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in ${(qq):-"$highlighter_dir/${highlighter}-highlighter.zsh"}." + print -r -- >&2 "zsh-syntax-highlighting: ${(qq)highlighter} highlighter should define both required functions '_zsh_highlight_highlighter_${highlighter}_paint' and '_zsh_highlight_highlighter_${highlighter}_predicate' in ${(qq):-"$highlighter_dir${highlighter}-highlighter.zsh"}." fi done } From 9523d6d49cb3d4db5bd84c3cec6168a2057fe3ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 25 Jan 2017 19:35:34 +0000 Subject: [PATCH 0486/1080] tests: zsh 5.4-to-be compatibility: Set a new "I am shooting myself in the foot" option. --- highlighters/main/test-data/alias.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 5129614..2977343 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -29,6 +29,9 @@ 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 BUFFER='x.alias2; alias1' From 835fec7f3c61ebce2268c202644ad59e174bb240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Tue, 7 Feb 2017 12:19:18 -0500 Subject: [PATCH 0487/1080] workaround for PAT_STATIC bug in zsh ZSH versions less than 5.3.2 (or 5.4) have a bug that prevents `history-incremental-pattern-search-backward` for working correctly (the history stops searching after the first found item). Closes #407 --- README.md | 11 +++++++---- zsh-syntax-highlighting.zsh | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2c2b6d6..b09f21f 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,13 @@ syntax highlighting. ### Does syntax highlighting work during incremental history search? -Highlighting the command line during an incremental history search -(with the `history-incremental-search-backward` widget, which is -bound by default to Ctrl+R in zsh's emacs keymap) requires zsh 5.3 -or newer. +Yes! + +If you're using `history-incremental-search-backward` (by default bound to Ctrl+R +in zsh's emacs keymap) then it works with _zsh version 5.3 and newer_. + +If you're using `history-incremental-pattern-search-backward`, then syntax highlighting works +in _zsh 5.3.2 and newer_ due to [a bug in zsh](http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=40285). Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting] of the matched portion of the buffer remains available, but zsh-syntax-highlighting's diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 0251d1e..e224c96 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -53,6 +53,15 @@ fi # Core highlighting update system # ------------------------------------------------------------------------------------------------- +# Use workaround for bug in ZSH? +# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html +autoload -U is-at-least +if is-at-least 5.3.2; then + zsh_highlight__pat_static_bug=false +else + zsh_highlight__pat_static_bug=true +fi + # Array declaring active highlighters names. typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS @@ -67,7 +76,9 @@ _zsh_highlight() # 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?'. - if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then + # This disables highlighting during isearch (for reasons explained in README.md) unless zsh is new enough + # and doesn't have the 5.3.1 bug + if [[ $WIDGET == zle-isearch-update ]] && { $zsh_highlight__pat_static_bug || ! (( $+ISEARCHMATCH_ACTIVE )) }; then region_highlight=() return $ret fi @@ -394,8 +405,6 @@ add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { # Load zsh/parameter module if available zmodload zsh/parameter 2>/dev/null || true -autoload -U is-at-least - # Initialize the array of active highlighters if needed. [[ $#ZSH_HIGHLIGHT_HIGHLIGHTERS -eq 0 ]] && ZSH_HIGHLIGHT_HIGHLIGHTERS=(main) From 237f89ad629fc255ef7ea0b645dfd86cbbc4868e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 11 Feb 2017 23:49:13 +0000 Subject: [PATCH 0488/1080] =?UTF-8?q?'main':=20Don't=20consider=20=C2=AB$*?= =?UTF-8?q?=C2=BB=20a=20glob.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/main-highlighter.zsh | 1 + .../main/test-data/parameter-star.zsh | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/parameter-star.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 267cdee..c8fb82f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -658,6 +658,7 @@ _zsh_highlight_highlighter_main_paint() already_added=1 ;; '`'*) style=back-quoted-argument;; + [$][*]) style=default;; [*?]*|*[^\\][*?]*) $highlight_glob && style=globbing || style=default;; *) if false; then diff --git a/highlighters/main/test-data/parameter-star.zsh b/highlighters/main/test-data/parameter-star.zsh new file mode 100644 index 0000000..1797e58 --- /dev/null +++ b/highlighters/main/test-data/parameter-star.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# 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='() { : $* }' + +# This tests that $* isn't highlighted as a glob. +# If we ever add a "unquoted parameter" style, the expectation may change. +expected_region_highlight=( + "8 9 default" # $* +) From be083d7f37107e5b27207255ae1a64bf56f9f112 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 5 Mar 2017 14:36:41 +0000 Subject: [PATCH 0489/1080] =?UTF-8?q?driver:=20Improve=20=C2=ABunhandled?= =?UTF-8?q?=20ZLE=20widget=20'foo'=C2=BB=20error=20message.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #409. --- zsh-syntax-highlighting.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 0251d1e..008970b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -317,6 +317,7 @@ _zsh_highlight_bind_widgets() else # Default: unhandled case. print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" + print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)" fi esac done From 73cb83270262bbb6bf110a8a6a99f36db8f56cef Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 5 Mar 2017 17:33:36 +0000 Subject: [PATCH 0490/1080] 'main': Highlight mismatched 'if'/'fi'. Also 'then'/'elif'/'else'. --- highlighters/main/main-highlighter.zsh | 25 +++++++++ .../brackets-mismatch10-if-negative.zsh | 42 +++++++++++++++ .../brackets-mismatch8-if-positive.zsh | 53 +++++++++++++++++++ .../brackets-mismatch9-if-positive.zsh | 42 +++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 highlighters/main/test-data/brackets-mismatch10-if-negative.zsh create mode 100644 highlighters/main/test-data/brackets-mismatch8-if-positive.zsh create mode 100644 highlighters/main/test-data/brackets-mismatch9-if-positive.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c8fb82f..d4a396a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -241,6 +241,8 @@ _zsh_highlight_highlighter_main_paint() # "Y" for curly # "D" for do/done # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) + # "?" for 'if'/'fi'; also checked by 'elif'/'else' + # ":" for 'then' local braces_stack if (( path_dirs_was_set )); then @@ -509,6 +511,29 @@ _zsh_highlight_highlighter_main_paint() ('done') _zsh_highlight_main__stack_pop 'D' style=reserved-word ;; + ('if') + braces_stack=':?'"$braces_stack" + ;; + ('then') + _zsh_highlight_main__stack_pop ':' style=reserved-word + ;; + ('elif') + if [[ ${braces_stack[1]} == '?' ]]; then + braces_stack=':'"$braces_stack" + else + style=unknown-token + fi + ;; + ('else') + if [[ ${braces_stack[1]} == '?' ]]; then + : + else + style=unknown-token + fi + ;; + ('fi') + _zsh_highlight_main__stack_pop '?' "" + ;; ('foreach') braces_stack='$'"$braces_stack" ;; diff --git a/highlighters/main/test-data/brackets-mismatch10-if-negative.zsh b/highlighters/main/test-data/brackets-mismatch10-if-negative.zsh new file mode 100644 index 0000000..9d0b53c --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch10-if-negative.zsh @@ -0,0 +1,42 @@ +#!/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='elif true; then echo two; fi' + +expected_region_highlight=( + '1 4 unknown-token' # elif + '6 9 builtin' # true + '10 10 commandseparator' # ; + '12 15 unknown-token' # then + '17 20 builtin' # echo + '22 24 default' # two + '25 25 commandseparator' # ; + '27 28 unknown-token' # fi +) diff --git a/highlighters/main/test-data/brackets-mismatch8-if-positive.zsh b/highlighters/main/test-data/brackets-mismatch8-if-positive.zsh new file mode 100644 index 0000000..d6838f0 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch8-if-positive.zsh @@ -0,0 +1,53 @@ +#!/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='if false; then echo one; elif true; then echo two; else echo three; fi' + +expected_region_highlight=( + '1 2 reserved-word' # if + '4 8 builtin' # false + '9 9 commandseparator' # ; + '11 14 reserved-word' # then + '16 19 builtin' # echo + '21 23 default' # one + '24 24 commandseparator' # ; + '26 29 reserved-word' # elif + '31 34 builtin' # true + '35 35 commandseparator' # ; + '37 40 reserved-word' # then + '42 45 builtin' # echo + '47 49 default' # two + '50 50 commandseparator' # ; + '52 55 reserved-word' # else + '57 60 builtin' # echo + '62 66 default' # three + '67 67 commandseparator' # ; + '69 70 reserved-word' # fi +) diff --git a/highlighters/main/test-data/brackets-mismatch9-if-positive.zsh b/highlighters/main/test-data/brackets-mismatch9-if-positive.zsh new file mode 100644 index 0000000..87c1ba7 --- /dev/null +++ b/highlighters/main/test-data/brackets-mismatch9-if-positive.zsh @@ -0,0 +1,42 @@ +#!/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='if false; then echo one; fi' + +expected_region_highlight=( + '1 2 reserved-word' # if + '4 8 builtin' # false + '9 9 commandseparator' # ; + '11 14 reserved-word' # then + '16 19 builtin' # echo + '21 23 default' # one + '24 24 commandseparator' # ; + '26 27 reserved-word' # fi +) From ad522a091429ba180c930f84b2a023b40de4dbcc Mon Sep 17 00:00:00 2001 From: jsoizo Date: Mon, 10 Apr 2017 00:44:30 +0900 Subject: [PATCH 0491/1080] driver: Fix printing error message to file when cannot resolve highlighters directory location Fixes #426. Review-by: Matthew Martin, me --- 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 e70e689..2c376e7 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -388,7 +388,7 @@ _zsh_highlight_bind_widgets || { # Resolve highlighters directory location. _zsh_highlight_load_highlighters "${ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR:-${${0:A}:h}/highlighters}" || { - print -r -- >&@ 'zsh-syntax-highlighting: failed loading highlighters, exiting.' + print -r -- >&2 'zsh-syntax-highlighting: failed loading highlighters, exiting.' return 1 } From 5feed23962df4dd6b8ef7fb1946617140d4078aa Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Jul 2017 11:30:31 +0000 Subject: [PATCH 0492/1080] docs: Unbreak Fedora link. Fixes #439. --- INSTALL.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 8532560..e19dfe4 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,7 +5,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] -* Fedora: [zsh-syntax-highlighting package][fedora-package] in Fedora 24+ +* Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`textproc/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [mv overlay][gentoo-overlay] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] @@ -19,6 +19,7 @@ How to install [brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb [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 ### In your ~/.zshrc From 39a6c476ddbd47692bbcf0f5311bf049d4faa3ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 30 Jul 2017 16:38:30 +0000 Subject: [PATCH 0493/1080] changelog: Update through 5feed23962df. --- changelog.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 26b93d8..4157b33 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,14 @@ -up to 28d7056a7a06 +up to 5feed23962df # Changes in version 0.6.0 +This is a stable release, featuring bugfixes and minor improvements. + + +## Performance improvements: + +(none) + ## Added highlighting of: @@ -10,6 +17,58 @@ up to 28d7056a7a06 [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +- Possible history expansions in double-quoted strings. + (76ea9e1df316) + +- Mismatched `if`/`then`/`elif`/`else`/`fi`. + (73cb83270262) + + +## Fixed highlighting of: + +- A comment line followed by a non-comment line. + (#385, 9396ad5c5f9c) + +- An unquoted `$*` (expands to the positional parameters). + (237f89ad629f) + +- history-incremental-pattern-search-backward under zsh 5.3.1. + (#407, #415, 462779629a0c) + +## API changes (for highlighter authors): + +(none) + + +## Developer-visible changes: + +- tests: Set the `ALIAS_FUNC_DEF` option for zsh 5.4 compatibility. + (9523d6d49cb3) + + +## Other changes: + +- docs: Added before/after screenshots. + (cd9ec14a65ec..b7e277106b49) + +- docs: Link Fedora package. + (3d74aa47e4a7, 5feed23962df) + +- docs: Link FreeBSD port. + (626c034c68d7) + +- Prevent user-defined aliases from taking effect in z-sy-h's own code. + (#390, 2dce602727d7, 8d5afe47f774; and #392, #395, b8fa1b9dc954) + +- docs: Update zplug installation instructions. + (#399, 4f49c4a35f17) + +- Improve "unhandled ZLE widget 'foo'" error message. + (#409, be083d7f3710) + +- Fix printing of "failed loading highlighters" error message. + (#426, ad522a091429) + # Changes in version 0.5.0 From 28e661bbc86a558700ed9782edd42a6c212e7e4c Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 30 Jul 2017 19:06:14 +0200 Subject: [PATCH 0494/1080] README: Fix FAQ entry about isearch highlighting Fixes #423 --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b09f21f..b867b8b 100644 --- a/README.md +++ b/README.md @@ -46,23 +46,19 @@ syntax highlighting. ### Does syntax highlighting work during incremental history search? -Yes! +Highlighting the command line during an incremental history search (by default bound to +to Ctrl+R in zsh's emacs keymap) requires zsh 5.4 or newer. -If you're using `history-incremental-search-backward` (by default bound to Ctrl+R -in zsh's emacs keymap) then it works with _zsh version 5.3 and newer_. - -If you're using `history-incremental-pattern-search-backward`, then syntax highlighting works -in _zsh 5.3.2 and newer_ due to [a bug in zsh](http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=40285). - -Under zsh 5.2 and older, the zsh-default [underlining][zshzle-Character-Highlighting] +Under zsh versions older than 5.4, the zsh-default [underlining][zshzle-Character-Highlighting] of the matched portion of the buffer remains available, but zsh-syntax-highlighting's additional highlighting is unavailable. (Those versions of zsh do not provide enough information to allow computing the highlighting correctly.) -See [issue #288][i288] for details. +See issues [#288][i288] and [#415][i415] for details. [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 +[i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415 ### How are new releases announced? From f2ba507bbc9edfa841f599cd0694bcafafbcd482 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 30 Jul 2017 19:06:21 +0200 Subject: [PATCH 0495/1080] driver: Adjust zsh version for probing for pattern match bug --- 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 2c376e7..6ff39b6 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -56,7 +56,7 @@ fi # Use workaround for bug in ZSH? # zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html autoload -U is-at-least -if is-at-least 5.3.2; then +if is-at-least 5.4; then zsh_highlight__pat_static_bug=false else zsh_highlight__pat_static_bug=true From 3c43da5ffefcb5fc5b86a3c50caa07af22fa209d Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 30 Jul 2017 19:07:29 +0200 Subject: [PATCH 0496/1080] driver: Improve comment about ^r pattern match bug The bug is not specific to 5.3.1. --- 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 6ff39b6..e36c3c3 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -77,7 +77,7 @@ _zsh_highlight() # 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 5.3.1 bug + # 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 From dea1fedc735822aa3c43074bdaf7966881d93529 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Mon, 31 Jul 2017 19:12:40 +0200 Subject: [PATCH 0497/1080] #419: Add links to OpenSUSE build service deb/rpm repositories --- INSTALL.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index e19dfe4..e210e9b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,12 +4,14 @@ How to install ### Using packages * Arch Linux: [community/zsh-syntax-highlighting][arch-package] / [AUR/zsh-syntax-highlighting-git][AUR-package] -* Debian: `zsh-syntax-highlighting` package [in `stretch`][debian-package] -* Fedora: [zsh-syntax-highlighting package][fedora-package-alt] in Fedora 24+ +* 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]) * 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] +* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) +* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git @@ -20,6 +22,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 ### In your ~/.zshrc From d1666463a74f52bcab93f65813beed912cee8d54 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 17:22:41 +0000 Subject: [PATCH 0498/1080] changelog: Update through dea1fedc7358. --- changelog.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 4157b33..4b811ac 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -up to 5feed23962df +up to dea1fedc7358 # Changes in version 0.6.0 @@ -13,7 +13,7 @@ This is a stable release, featuring bugfixes and minor improvements. ## Added highlighting of: - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. - (79e4d3d12405, 15db71abd0cc; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) + (79e4d3d12405, 15db71abd0cc, b56ee542d619; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting @@ -35,6 +35,7 @@ This is a stable release, featuring bugfixes and minor improvements. - history-incremental-pattern-search-backward under zsh 5.3.1. (#407, #415, 462779629a0c) + ## API changes (for highlighter authors): (none) @@ -57,6 +58,9 @@ This is a stable release, featuring bugfixes and minor improvements. - docs: Link FreeBSD port. (626c034c68d7) +- docs: Link OpenSUSE Build Service packages + (#419, dea1fedc7358) + - Prevent user-defined aliases from taking effect in z-sy-h's own code. (#390, 2dce602727d7, 8d5afe47f774; and #392, #395, b8fa1b9dc954) From 411864d35ba045cf66e2c5f7bc10d380116506d3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 17:30:59 +0000 Subject: [PATCH 0499/1080] release.md: Create annotated tags, fix markup. --- release.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.md b/release.md index 08bcfa6..e1b852b 100644 --- a/release.md +++ b/release.md @@ -8,8 +8,8 @@ - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; - Commit that using 'git commit -m "Tag version $(<.version)."; - Tag it using `git tag $(<.version)`; + Commit that using `git commit -m "Tag version $(<.version)."`; + Tag it using `git tag -m "Tag version $(<.version)"`; Increment `./.version` and restore the `-dev` suffix; Commit that using 'git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5'. - Push with `git push --tags` From dc2673155594f1de815802ca674bc7741ccda60f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 17:31:25 +0000 Subject: [PATCH 0500/1080] Tag version 0.6.0-rc1. --- .version | 2 +- changelog.md | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.version b/.version index fb0b754..e54f099 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.6.0-dev +0.6.0-rc1 diff --git a/changelog.md b/changelog.md index 4b811ac..f20e69d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,3 @@ -up to dea1fedc7358 - # Changes in version 0.6.0 This is a stable release, featuring bugfixes and minor improvements. From 30a29a9e3183f9fb49ee31a165cbafbd178c3424 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 0501/1080] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index e54f099..72f3d0d 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.6.0-rc1 +0.6.0-rc2-dev From e4ed76b87dc9508866e56f5402d5b291132984d8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 17:42:28 +0000 Subject: [PATCH 0502/1080] release.md: Correct 'git push' instructions. --- release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.md b/release.md index e1b852b..288ead2 100644 --- a/release.md +++ b/release.md @@ -12,7 +12,7 @@ Tag it using `git tag -m "Tag version $(<.version)"`; Increment `./.version` and restore the `-dev` suffix; Commit that using 'git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5'. -- Push with `git push --tags` +- Push with `git push && git push --tags` - Notify downstreams (OS packages) - anitya should autodetect the tag - Update /topic on IRC From 176a019434cb09b510866fc985a5b944280d49e3 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 00:23:38 +0200 Subject: [PATCH 0503/1080] #440: Add Travis-CI configuration --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..00bf207 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: false + +env: + - ZSH=4.3.11 + - ZSH=4.3.17 + - ZSH=5.0.0 + - ZSH=5.1.1 + - ZSH=5.2 + - ZSH=5.3 + - ZSH=5.3.1 + +script: docker run -v $PWD:/work -w /work desyncr/zsh-docker-zsh-${ZSH} /bin/sh -c 'make test' From 7e840ff2db3b445d6f2f8ac166e627d350d712ac Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 00:28:37 +0200 Subject: [PATCH 0504/1080] #440: Fix Travis-CI configuration --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 00bf207..62d2ce7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ -sudo: false +language: generic +sudo: required env: - ZSH=4.3.11 From 46441b1c0dec1016dd0ce5fb19a81a9f75eaea83 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 00:37:28 +0200 Subject: [PATCH 0505/1080] #440: Print zsh version before tests --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index f454324..14475a5 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ clean: rm -f docs/all.md test: + @$(ZSH) --version @result=0; \ for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ From 47ac611c896db3163161176a3b9fb14768663e6d Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 00:38:03 +0200 Subject: [PATCH 0506/1080] #440: Add build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b867b8b..2e51869 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -zsh-syntax-highlighting +zsh-syntax-highlighting [![Build Status](https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master)](https://travis-ci.org/zsh-users/zsh-syntax-highlighting) ======================= **[Fish shell][fish]-like like syntax highlighting for [Zsh][zsh].** From d43fe3ab709fca8c3008d845d77b28b7a97a4105 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 00:47:43 +0200 Subject: [PATCH 0507/1080] #440: Setup IRC/gitter notifications --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.travis.yml b/.travis.yml index 62d2ce7..87fc3ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,18 @@ env: - ZSH=5.3.1 script: docker run -v $PWD:/work -w /work desyncr/zsh-docker-zsh-${ZSH} /bin/sh -c 'make test' + +notifications: + webhooks: + urls: + - https://webhooks.gitter.im/e/367e241cdea60cb2070b + on_success: change + on_failure: always + on_start: never + irc: + channels: + - "chat.freenode.net#zsh-syntax-highlighting" + on_success: change + on_failure: always + on_start: never + use_notice: true From f60d9b8c36fc4bb2644c5cf1195032574cce2158 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 23:10:53 +0000 Subject: [PATCH 0508/1080] #440: Make README more readable in source form. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e51869..702d980 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -zsh-syntax-highlighting [![Build Status](https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master)](https://travis-ci.org/zsh-users/zsh-syntax-highlighting) +zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis] ======================= **[Fish shell][fish]-like like syntax highlighting for [Zsh][zsh].** @@ -75,3 +75,10 @@ How to tweak Syntax highlighting is done by pluggable highlighter scripts. See the [documentation on highlighters](docs/highlighters.md) for details and configuration settings. + + + + +[build-status-image]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master +[build-status-travis]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting + From d0251488589a77d8e6b15ee68ac48c910610bdce Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jul 2017 23:16:37 +0000 Subject: [PATCH 0509/1080] #440: docs: Remove the travis links from README during 'make install'. --- Makefile | 1 + README.md | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 14475a5..692dabd 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ install: all $(INSTALL) -d $(DOC_DIR) cp .version zsh-syntax-highlighting.zsh $(SHARE_DIR) cp COPYING.md README.md changelog.md $(DOC_DIR) + sed -e '1s/ .*//' -e '/^\[build-status-[a-z]*\]: /d' < README.md > $(DOC_DIR)/README.md if [ x"true" = x"`git rev-parse --is-inside-work-tree 2>/dev/null`" ]; then \ git rev-parse HEAD; \ else \ diff --git a/README.md b/README.md index 702d980..04c7882 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,5 @@ Syntax highlighting is done by pluggable highlighter scripts. See the [documentation on highlighters](docs/highlighters.md) for details and configuration settings. - - - [build-status-image]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master [build-status-travis]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting - From bbaae63f2e31723166628ee1056373718a2e4354 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 17:53:42 +0200 Subject: [PATCH 0510/1080] #440: Test on Zsh master and intermediate releases since 4.3.11 --- .travis.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 87fc3ec..4d051ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,29 @@ sudo: required env: - ZSH=4.3.11 + - ZSH=4.3.12 + - ZSH=4.3.13 + - ZSH=4.3.14 + - ZSH=4.3.15 + - ZSH=4.3.16 - ZSH=4.3.17 - ZSH=5.0.0 + - ZSH=5.0.1 + - ZSH=5.0.2 + - ZSH=5.0.3 + - ZSH=5.0.4 + - ZSH=5.0.5 + - ZSH=5.0.6 + - ZSH=5.0.7 + - ZSH=5.0.8 + - ZSH=5.1 - ZSH=5.1.1 - ZSH=5.2 - ZSH=5.3 - ZSH=5.3.1 + - ZSH=master -script: docker run -v $PWD:/work -w /work desyncr/zsh-docker-zsh-${ZSH} /bin/sh -c 'make test' +script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c 'make test' notifications: webhooks: From ed90f0d2c98af5ae1b6bc79ed231070fbfce0102 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 17:55:04 +0200 Subject: [PATCH 0511/1080] #440: Fix minimum required Zsh version (4.3.11 instead of 4.3.17) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 04c7882..855be9e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travi **[Fish shell][fish]-like like syntax highlighting for [Zsh][zsh].** -*Requirements: zsh 4.3.17+.* +*Requirements: zsh 4.3.11+.* [fish]: http://www.fishshell.com/ [zsh]: http://www.zsh.org/ From 871041a939f01e32d884151872e7245681f50940 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 1 Aug 2017 18:31:11 +0200 Subject: [PATCH 0512/1080] #440: Make sure zsh's git hash is printed when testing against zsh master branch Context: zsh-users/zsh-docker#2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 692dabd..8754db1 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ clean: rm -f docs/all.md test: - @$(ZSH) --version + @$(ZSH) -fc 'echo $$ZSH_PATCHLEVEL' @result=0; \ for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ From e58800158a392d6403de4d5a1ba5d4cf24e516e8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 9 Aug 2017 18:42:35 +0000 Subject: [PATCH 0513/1080] #440: Identify the output. Useful when using, e.g., Debian's package, which outputs just "Debian" here. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8754db1..6cc2648 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ clean: rm -f docs/all.md test: - @$(ZSH) -fc 'echo $$ZSH_PATCHLEVEL' + @$(ZSH) -fc 'echo ZSH_PATCHLEVEL=$$ZSH_PATCHLEVEL' @result=0; \ for test in highlighters/*; do \ if [ -d $$test/test-data ]; then \ From 6f149dfc5eab32bfb0cc1163b4ae5e001e48f9a1 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Thu, 10 Aug 2017 20:25:53 +0200 Subject: [PATCH 0514/1080] Tests: add zsh 5.4 and 5.4.1 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4d051ef..c881a27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ env: - ZSH=5.2 - ZSH=5.3 - ZSH=5.3.1 + - ZSH=5.4 + - ZSH=5.4.1 - ZSH=master script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c 'make test' From 434af7b11dd33641231f1b48b8432e68eb472e46 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 29 Aug 2017 06:04:59 +0000 Subject: [PATCH 0515/1080] Tag version 0.6.0. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 72f3d0d..a918a2a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.6.0-rc2-dev +0.6.0 From 9ff91eb8f04f318d569b1706c0174a14b8ad0868 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 0516/1080] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index a918a2a..e1bde80 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.6.0 +0.7.0-dev From 4cde79ef0026f9b543d2beffc90d6199239dbfa0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 30 Aug 2017 07:32:56 +0000 Subject: [PATCH 0517/1080] release.md: Make a little more copy-pasteable. --- release.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.md b/release.md index 288ead2..55a70f5 100644 --- a/release.md +++ b/release.md @@ -8,10 +8,10 @@ - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Remove `-dev` suffix from `./.version`; - Commit that using `git commit -m "Tag version $(<.version)."`; + Commit that using `git commit -m "Tag version $(<.version)." .version`; Tag it using `git tag -m "Tag version $(<.version)"`; Increment `./.version` and restore the `-dev` suffix; - Commit that using 'git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5'. + Commit that using `git commit -C b5c30ae52638e81a38fe5329081c5613d7bd6ca5 .version`. - Push with `git push && git push --tags` - Notify downstreams (OS packages) - anitya should autodetect the tag From 873b9955c76b02b0582ed9fac9e704dbfcd6dc79 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Mon, 11 Sep 2017 19:27:52 +0200 Subject: [PATCH 0518/1080] tests: add zsh 5.4.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c881a27..2bdf718 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ env: - ZSH=5.3.1 - ZSH=5.4 - ZSH=5.4.1 + - ZSH=5.4.2 - ZSH=master script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c 'make test' From 3d26cb81465a85251640c144dae26c5ff8bb2b76 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Mon, 11 Sep 2017 19:29:58 +0200 Subject: [PATCH 0519/1080] tests: run the most recent versions first --- .travis.yml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2bdf718..2fbac21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,31 +2,31 @@ language: generic sudo: required env: - - ZSH=4.3.11 - - ZSH=4.3.12 - - ZSH=4.3.13 - - ZSH=4.3.14 - - ZSH=4.3.15 - - ZSH=4.3.16 - - ZSH=4.3.17 - - ZSH=5.0.0 - - ZSH=5.0.1 - - ZSH=5.0.2 - - ZSH=5.0.3 - - ZSH=5.0.4 - - ZSH=5.0.5 - - ZSH=5.0.6 - - ZSH=5.0.7 - - ZSH=5.0.8 - - ZSH=5.1 - - ZSH=5.1.1 - - ZSH=5.2 - - ZSH=5.3 - - ZSH=5.3.1 - - ZSH=5.4 - - ZSH=5.4.1 - - ZSH=5.4.2 - ZSH=master + - ZSH=5.4.2 + - ZSH=5.4.1 + - ZSH=5.4 + - ZSH=5.3.1 + - ZSH=5.3 + - ZSH=5.2 + - ZSH=5.1.1 + - ZSH=5.1 + - ZSH=5.0.8 + - ZSH=5.0.7 + - ZSH=5.0.6 + - ZSH=5.0.5 + - ZSH=5.0.4 + - ZSH=5.0.3 + - ZSH=5.0.2 + - ZSH=5.0.1 + - ZSH=5.0.0 + - ZSH=4.3.17 + - ZSH=4.3.16 + - ZSH=4.3.15 + - ZSH=4.3.14 + - ZSH=4.3.13 + - ZSH=4.3.12 + - ZSH=4.3.11 script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c 'make test' From 5436d3e5fc1ea86203ea4c6b48575809836930b3 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 11 Sep 2017 18:45:35 +0000 Subject: [PATCH 0520/1080] tests: Remove superfluous comment. The functions can remain defined because, nowadays, the test harness runs each test in a subshell; but that's a well-known property of the test harness so need not be mentioned explicitly. Inspired by discussion on issue #443. --- highlighters/main/test-data/function.zsh | 3 --- 1 file changed, 3 deletions(-) diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index 6876391..426ee76 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -39,6 +39,3 @@ expected_region_highlight=( "1 2 function" # cd "4 5 function" # ls ) - -# don't 'unfunction cd ls', since cd() and ls() should still be a functions -# when _zsh_highlight runs. Leaving the wrapper functions is harmless. From 8146d58bb2c77e6b9ff7424ba09508071a3fcf12 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Thu, 28 Sep 2017 19:07:24 +0200 Subject: [PATCH 0521/1080] CI: customize IRC notifcation message --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2fbac21..db5dbc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,3 +44,5 @@ notifications: on_failure: always on_start: never use_notice: true + template: + - "%{repository}/%{branch}#%{build_number}: %{message} Changes : %{compare_url} | Build : %{build_url}" From c41356c3f62328122c091b6624cdfc22c62214a4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 18 Oct 2017 00:17:06 +0000 Subject: [PATCH 0522/1080] docs: Add Void Linux link. --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index e210e9b..ca1bfa7 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -12,6 +12,7 @@ How to install * Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) * RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* Void Linux: `zsh-syntax-highlighting package` [in XBPS][void-package] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git @@ -23,6 +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 ### In your ~/.zshrc From a2a899b41b8b467b6c46b3f56c829a58657e671e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 2 Nov 2017 17:07:10 +0000 Subject: [PATCH 0523/1080] driver: _zsh_highlight_bind_widgets: Be resilient to NO_UNSET being set in the calling scope. Fixes #449. --- 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 e36c3c3..47288c5 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -295,7 +295,7 @@ _zsh_highlight_bind_widgets() local cur_widget for cur_widget in $widgets_to_bind; do - case $widgets[$cur_widget] in + case ${widgets[$cur_widget]:-""} in # Already rebound event: do nothing. user:_zsh_highlight_widget_*);; @@ -322,7 +322,7 @@ _zsh_highlight_bind_widgets() # Incomplete or nonexistent widget: Bind to z-sy-h directly. *) - if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then + if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } zle -N $cur_widget _zsh_highlight_widget_$cur_widget else From f547f7768cc05a44a8bb0c65d6b0272fc8beec8f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:12:37 -0500 Subject: [PATCH 0524/1080] brackets: Add test for highlighting errors with no styles --- .../brackets/test-data/only-error.zsh | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 highlighters/brackets/test-data/only-error.zsh diff --git a/highlighters/brackets/test-data/only-error.zsh b/highlighters/brackets/test-data/only-error.zsh new file mode 100644 index 0000000..1c3a159 --- /dev/null +++ b/highlighters/brackets/test-data/only-error.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# 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=': x)' + +expected_region_highlight=( + "1 3 NONE" + "4 4 bracket-error" # ) +) From ac90970edcfe8c6c0f1804fb0f32f5aa8b9f9137 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:11:00 -0500 Subject: [PATCH 0525/1080] brackets: Don't call _zsh_highlight_add_highlight with empty style --- highlighters/brackets/brackets-highlighter.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 1bdd1f9..d04ab38 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -77,12 +77,11 @@ _zsh_highlight_highlighter_brackets_paint() for pos in ${(k)levelpos}; do if (( $+matching[$pos] )); then if (( bracket_color_size )); then - style=bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) + _zsh_highlight_add_highlight $((pos - 1)) $pos bracket-level-$(( (levelpos[$pos] - 1) % bracket_color_size + 1 )) fi else - style=bracket-error + _zsh_highlight_add_highlight $((pos - 1)) $pos bracket-error fi - _zsh_highlight_add_highlight $((pos - 1)) $pos $style done # If cursor is on a bracket, then highlight corresponding bracket, if any. From 9dcfacc4a5229c2b368043c9ff10dc7936c4b886 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:23:18 -0500 Subject: [PATCH 0526/1080] brackets: Disallow negative nesting level --- highlighters/brackets/brackets-highlighter.zsh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index d04ab38..e4d854f 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -59,11 +59,15 @@ _zsh_highlight_highlighter_brackets_paint() lastoflevel[$level]=$pos ;; [")]}"]) - matchingpos=$lastoflevel[$level] - levelpos[$pos]=$((level--)) - if _zsh_highlight_brackets_match $matchingpos $pos; then - matching[$matchingpos]=$pos - matching[$pos]=$matchingpos + if (( level > 0 )); then + matchingpos=$lastoflevel[$level] + levelpos[$pos]=$((level--)) + if _zsh_highlight_brackets_match $matchingpos $pos; then + matching[$matchingpos]=$pos + matching[$pos]=$matchingpos + fi + else + levelpos[$pos]=-1 fi ;; ['"'\']) From 1f77ed8369ed26bdc92b746280b6f7822ccde06c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:11:34 -0500 Subject: [PATCH 0527/1080] brackets: Use idiomatic set check --- highlighters/brackets/brackets-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index e4d854f..cb09b40 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -91,7 +91,7 @@ _zsh_highlight_highlighter_brackets_paint() # If cursor is on a bracket, then highlight corresponding bracket, if any. if [[ $WIDGET != zle-line-finish ]]; then pos=$((CURSOR + 1)) - if [[ -n $levelpos[$pos] ]] && [[ -n $matching[$pos] ]]; then + if (( $+levelpos[$pos] )) && (( $+matching[$pos] )); then local -i otherpos=$matching[$pos] _zsh_highlight_add_highlight $((otherpos - 1)) $otherpos cursor-matchingbracket fi From a33c72e8389b3d984d25fd556d86878777c76571 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:12:16 -0500 Subject: [PATCH 0528/1080] tests: Use idiomatic set check --- 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 94c4152..d29880d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -137,7 +137,7 @@ run_test_internal() { local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" # Match the emptiness of observed_result if no highlighting is expected [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= - [[ -n "$highlight_zone[4]" ]] && todo="# TODO $highlight_zone[4]" + (( $+highlight_zone[4] )) && todo="# TODO $highlight_zone[4]" for j in {$start..$end}; do if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}. $todo" From a9ce93143927173ec29cf08994467bea32b95e28 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:24:56 -0500 Subject: [PATCH 0529/1080] Default possibly unset variables to empty --- tests/test-highlighting.zsh | 2 +- zsh-syntax-highlighting.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index d29880d..ed7dff9 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -49,7 +49,7 @@ # Set up results_filter local results_filter -if [[ $QUIET == y ]]; then +if [[ ${QUIET-} == y ]]; then if type -w perl >/dev/null; then results_filter=${0:A:h}/tap-filter else diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 47288c5..b708a7c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -188,7 +188,7 @@ _zsh_highlight_apply_zle_highlight() { integer first="$3" second="$4" # read the relevant entry from zle_highlight - local region="${zle_highlight[(r)${entry}:*]}" + local region="${zle_highlight[(r)${entry}:*]-}" if [[ -z "$region" ]]; then # entry not specified at all, use default value From 079ea39f74c29fdee5a209f387d50e19880ffcf8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 4 Nov 2017 20:22:59 -0500 Subject: [PATCH 0530/1080] tests: Ensure region highlight is unset if NONE is expected --- tests/test-highlighting.zsh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index ed7dff9..0c1d843 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -135,12 +135,16 @@ run_test_internal() { integer start=$highlight_zone[1] end=$highlight_zone[2] # Escape # as ♯ since the former is illegal in the 'description' part of TAP output local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" - # Match the emptiness of observed_result if no highlighting is expected - [[ $highlight_zone[3] == NONE ]] && highlight_zone[3]= (( $+highlight_zone[4] )) && todo="# TODO $highlight_zone[4]" for j in {$start..$end}; do - if [[ "$observed_result[$j]" != "$highlight_zone[3]" ]]; then - print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]}. $todo" + if + if [[ $highlight_zone[3] == NONE ]]; then + (( $+observed_result[$j] )) + else + [[ "$observed_result[$j]" != "$highlight_zone[3]" ]] + fi + then + print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]-NONE}. $todo" continue 2 fi done From 459c128f43d454981838be1c0ff4bec13970b555 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:09:32 -0500 Subject: [PATCH 0531/1080] tests: Set ZLE variables to sane defaults --- tests/test-highlighting.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 0c1d843..f6ebff4 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -103,6 +103,9 @@ run_test_internal() { # Check the data declares $expected_region_highlight. (( ${#expected_region_highlight} == 0 )) && { echo >&2 "Bail out! 'expected_region_highlight' is not declared or empty."; return 1; } + # Set sane defaults for ZLE variables + : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} + # Process the data. region_highlight=() _zsh_highlight From 18517cc98ee21ef940fd641ee94f0a0cd9b30c28 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 2 Nov 2017 19:25:23 -0500 Subject: [PATCH 0532/1080] tests: Run tests with NOUNSET --- tests/test-highlighting.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index f6ebff4..743b3bb 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -29,6 +29,8 @@ # ------------------------------------------------------------------------------------------------- +setopt NOUNSET + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." From 9d9e9662cf0b8ab6e171ac5171d202837a64eeb7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 5 Nov 2017 14:38:05 +0000 Subject: [PATCH 0533/1080] driver: Correctly escape assoc key pattern --- 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 b708a7c..d1470b8 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -188,7 +188,7 @@ _zsh_highlight_apply_zle_highlight() { integer first="$3" second="$4" # read the relevant entry from zle_highlight - local region="${zle_highlight[(r)${entry}:*]-}" + local region="${zle_highlight[(r)${(b)entry}:*]-}" if [[ -z "$region" ]]; then # entry not specified at all, use default value From e4352f98bb41c80b5a5c9892faf3998f53863868 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 5 Nov 2017 15:58:58 +0000 Subject: [PATCH 0534/1080] driver: Revert previous commit, unbreaking the build on zsh<5.0.8. --- zsh-syntax-highlighting.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index d1470b8..e4e44fa 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -188,7 +188,11 @@ _zsh_highlight_apply_zle_highlight() { integer first="$3" second="$4" # read the relevant entry from zle_highlight - local region="${zle_highlight[(r)${(b)entry}:*]-}" + # + # ### In zsh≥5.0.8 we'd use ${(b)entry}, but we support older zsh's, so we don't + # ### add (b). The only effect is on the failure mode for callers that violate + # ### the precondition. + local region="${zle_highlight[(r)${entry}:*]-}" if [[ -z "$region" ]]; then # entry not specified at all, use default value From c948a3caa0daa201c58dd9e24f2d1de9b6666f45 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 4 Nov 2017 11:18:31 -0500 Subject: [PATCH 0535/1080] tests: Declare local variables --- tests/test-highlighting.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 743b3bb..a9210ae 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -97,7 +97,8 @@ run_test_internal() { echo "# ${1:t:r}" # Load the data and prepare checking it. - PREBUFFER= BUFFER= ; + local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET + local -a expected_region_highlight region_highlight . "$srcdir"/"$1" # Check the data declares $PREBUFFER or $BUFFER. @@ -109,11 +110,11 @@ run_test_internal() { : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} # Process the data. - region_highlight=() _zsh_highlight # Overlapping regions can be declared in region_highlight, so we first build an array of the # observed highlighting. + local i j local -A observed_result for ((i=1; i<=${#region_highlight}; i++)); do local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) From 038409c10d553d363263f585f14888c06e9d1add Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 4 Nov 2017 11:19:00 -0500 Subject: [PATCH 0536/1080] tests: Run tests with WARN_CREATE_GLOBAL --- highlighters/main/test-data/commmand-parameter.zsh | 2 +- highlighters/main/test-data/path-dollared-word2.zsh | 2 +- tests/README.md | 3 +++ tests/test-highlighting.zsh | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index fb43e9e..355f890 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -x=/usr/bin/env +local x=/usr/bin/env BUFFER='$x "argument"' expected_region_highlight=( diff --git a/highlighters/main/test-data/path-dollared-word2.zsh b/highlighters/main/test-data/path-dollared-word2.zsh index 3485b45..d1c34af 100644 --- a/highlighters/main/test-data/path-dollared-word2.zsh +++ b/highlighters/main/test-data/path-dollared-word2.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -lambda="''" +local lambda="''" touch \$lambda BUFFER=': \$lambda' diff --git a/tests/README.md b/tests/README.md index 5526612..11c35fc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -21,6 +21,9 @@ point will not fail the test), and `$todo` is used as the explanation. **Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but interprets the indexes differently. +**Note**: Tests are run with `setopt NOUNSET WARN_CREATE_GLOBAL`, so any +variables the test creates must be declared local. + **Isolation**: Each test is run in a separate subshell, so any variables, aliases, functions, etc., it defines will be visible to the tested code (that computes `$region_highlight`), but will not affect subsequent tests. The diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a9210ae..9731d8d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -29,7 +29,7 @@ # ------------------------------------------------------------------------------------------------- -setopt NOUNSET +setopt NO_UNSET WARN_CREATE_GLOBAL # Check an highlighter was given as argument. [[ -n "$1" ]] || { From 4bd30737dc9d7af10d2e985c7f2fea229028341c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 6 Nov 2017 07:08:21 -0600 Subject: [PATCH 0537/1080] tests: Support SKIP directive in tap-colorizer --- tests/tap-colorizer.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tap-colorizer.zsh b/tests/tap-colorizer.zsh index cb645c6..eb24934 100755 --- a/tests/tap-colorizer.zsh +++ b/tests/tap-colorizer.zsh @@ -44,6 +44,10 @@ do (#* | <->..<->) print -nP %F{blue} ;; + # SKIP + (*# SKIP*) + print -nP %F{yellow} + ;; # XPASS (ok*# TODO*) print -nP %F{red} From f4d37b74ccc6c840ff11de41be28088846dd2ed5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 6 Nov 2017 07:08:53 -0600 Subject: [PATCH 0538/1080] tests: Add ability to skip tests --- tests/README.md | 2 ++ tests/test-highlighting.zsh | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 11c35fc..78433c3 100644 --- a/tests/README.md +++ b/tests/README.md @@ -17,6 +17,8 @@ that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. highlighting should be observed. 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. **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 9731d8d..a7b98a5 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -97,10 +97,12 @@ run_test_internal() { echo "# ${1:t:r}" # Load the data and prepare checking it. - local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET + local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test local -a expected_region_highlight region_highlight . "$srcdir"/"$1" + (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } + # 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; } # Check the data declares $expected_region_highlight. From 749b30221d04842539aeda79ae890e90d464a4da Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 6 Nov 2017 07:09:16 -0600 Subject: [PATCH 0539/1080] 'main': Skip tests that break on msys2 Closes #382. --- .../main/test-data/option-path_dirs.zsh | 23 +++++++++++-------- .../main/test-data/path-broken-symlink.zsh | 16 ++++++++----- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/highlighters/main/test-data/option-path_dirs.zsh b/highlighters/main/test-data/option-path_dirs.zsh index 1f3002a..0300c7e 100644 --- a/highlighters/main/test-data/option-path_dirs.zsh +++ b/highlighters/main/test-data/option-path_dirs.zsh @@ -27,15 +27,18 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -## setup -setopt PATH_DIRS -mkdir -p foo/bar -touch foo/bar/testing-issue-228 -chmod +x foo/bar/testing-issue-228 -path+=( "$PWD"/foo ) +if [[ $OSTYPE == msys ]]; then + skip_test='Cannot chmod +x in msys2' +else + 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 + ) +fi diff --git a/highlighters/main/test-data/path-broken-symlink.zsh b/highlighters/main/test-data/path-broken-symlink.zsh index 84c7d59..c99f872 100644 --- a/highlighters/main/test-data/path-broken-symlink.zsh +++ b/highlighters/main/test-data/path-broken-symlink.zsh @@ -27,10 +27,14 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -ln -s /nonexistent broken-symlink -BUFFER=': broken-symlink' -CURSOR=5 # to make path_prefix ineligible +if [[ $OSTYPE == msys ]]; then + skip_test='Cannot create symlinks in msys2' +else + ln -s /nonexistent broken-symlink + BUFFER=': broken-symlink' + CURSOR=5 # to make path_prefix ineligible -expected_region_highlight=( - "3 16 path" # broken-symlink -) + expected_region_highlight=( + "3 16 path" # broken-symlink + ) +fi From 2a506145790b144b561326341a098fbc0bc780da Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 24 Nov 2017 10:05:13 -0600 Subject: [PATCH 0540/1080] main: Save user options in a single variable --- highlighters/main/main-highlighter.zsh | 43 +++++++++++--------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d4a396a..cd4661d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -194,25 +194,8 @@ _zsh_highlight_main__stack_pop() { # Main syntax highlighting function. _zsh_highlight_highlighter_main_paint() { - ## Before we even 'emulate -L', we must test a few options that would reset. - if [[ -o interactive_comments ]]; then - local interactive_comments= # set to empty - fi - if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then - local right_brace_is_recognised_everywhere=false - else - local right_brace_is_recognised_everywhere=true - fi - if [[ -o path_dirs ]]; then - integer path_dirs_was_set=1 - else - integer path_dirs_was_set=0 - fi - if [[ -o multi_func_def ]]; then - integer multi_func_def=1 - else - integer multi_func_def=0 - fi + # Before we even 'emulate -L', save the user's options + local -A useroptions=("${(@kv)options}") emulate -L zsh setopt localoptions extendedglob bareglobqual @@ -245,10 +228,15 @@ _zsh_highlight_highlighter_main_paint() # ":" for 'then' local braces_stack - if (( path_dirs_was_set )); then + if [[ $useroptions[ignorebraces] == on || ${useroptions[ignoreclosebraces]:-off} == on ]]; then + local right_brace_is_recognised_everywhere=false + else + local right_brace_is_recognised_everywhere=true + fi + + if [[ $useroptions[pathdirs] == on ]]; then options_to_set+=( PATH_DIRS ) fi - unset path_dirs_was_set ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR=( '|' '||' ';' '&' '&&' @@ -322,8 +310,13 @@ _zsh_highlight_highlighter_main_paint() integer in_redirection # Processing buffer local proc_buf="$buf" - for arg in ${interactive_comments-${(z)buf}} \ - ${interactive_comments+${(zZ+c+)buf}}; do + local -a args + if [[ $useroptions[interactivecomments] == on ]]; then + args=(${(zZ+c+)buf}) + else + args=(${(z)buf}) + fi + for arg in $args; do # Initialize $next_word. if (( in_redirection )); then (( --in_redirection )) @@ -412,7 +405,7 @@ _zsh_highlight_highlighter_main_paint() # Handle the INTERACTIVE_COMMENTS option. # # We use the (Z+c+) flag so the entire comment is presented as one token in $arg. - if [[ -n ${interactive_comments+'set'} && $arg[1] == $histchars[3] ]]; then + if [[ $useroptions[interactivecomments] == on && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then style=comment else @@ -648,7 +641,7 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main__stack_pop 'R' style=reserved-word fi;; $'\x28\x29') # possibly a function definition - if (( multi_func_def )) || false # TODO: or if the previous word was a command word + if [[ $useroptions[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word then next_word+=':start:' fi From 7177ba005fde5c4d12440b8b3ae33bbcf4e9200c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 24 Nov 2017 16:34:34 -0600 Subject: [PATCH 0541/1080] main: Split declaration and assignment Unbreak build for 5.0.8 and earlier. --- 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 cd4661d..7850ddc 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -195,7 +195,7 @@ _zsh_highlight_main__stack_pop() { _zsh_highlight_highlighter_main_paint() { # Before we even 'emulate -L', save the user's options - local -A useroptions=("${(@kv)options}") + local -A useroptions; useroptions=("${(@kv)options}") emulate -L zsh setopt localoptions extendedglob bareglobqual From ecdda36ef56f09c4d6dc2011e475c50b2d6fcd32 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Nov 2017 21:14:28 -0600 Subject: [PATCH 0542/1080] brackets: Ignore quotes Closes #112. Closes #138. --- .../brackets/brackets-highlighter.zsh | 4 --- .../brackets/test-data/near-quotes.zsh | 7 +++- .../brackets/test-data/nested-quote.zsh | 36 ------------------- .../brackets/test-data/quoted-patentheses.zsh | 4 ++- 4 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 highlighters/brackets/test-data/nested-quote.zsh diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index cb09b40..2ef2386 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -70,10 +70,6 @@ _zsh_highlight_highlighter_brackets_paint() levelpos[$pos]=-1 fi ;; - ['"'\']) - # Skip everything inside quotes - pos=$BUFFER[(ib:pos+1:)$char] - ;; esac done diff --git a/highlighters/brackets/test-data/near-quotes.zsh b/highlighters/brackets/test-data/near-quotes.zsh index b7cc2cb..d3965d2 100644 --- a/highlighters/brackets/test-data/near-quotes.zsh +++ b/highlighters/brackets/test-data/near-quotes.zsh @@ -28,11 +28,16 @@ # ------------------------------------------------------------------------------------------------- ZSH_HIGHLIGHT_STYLES[bracket-level-1]= +ZSH_HIGHLIGHT_STYLES[bracket-level-2]= BUFFER=': {"{x}"}' expected_region_highlight=( "3 3 bracket-level-1" - "4 8 NONE" + "4 4 NONE" + "5 5 bracket-level-2" + "6 6 NONE" + "7 7 bracket-level-2" + "8 8 NONE" "9 9 bracket-level-1" ) diff --git a/highlighters/brackets/test-data/nested-quote.zsh b/highlighters/brackets/test-data/nested-quote.zsh deleted file mode 100644 index 8febae8..0000000 --- a/highlighters/brackets/test-data/nested-quote.zsh +++ /dev/null @@ -1,36 +0,0 @@ -# ------------------------------------------------------------------------------------------------- -# Copyright (c) 2016 zsh-syntax-highlighting contributors -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, are permitted -# provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of conditions -# and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, this list of -# conditions and the following disclaimer in the documentation and/or other materials provided -# with the distribution. -# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors -# may be used to endorse or promote products derived from this software without specific prior -# written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# ------------------------------------------------------------------------------------------------- -# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- -# vim: ft=zsh sw=2 ts=2 et -# ------------------------------------------------------------------------------------------------- - -ZSH_HIGHLIGHT_STYLES[bracket-level-1]= - -BUFFER=': "\"{x"' - -expected_region_highlight=( - "3 9 NONE 'issue #303'" -) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 5c3dcea..8d1e26d 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -30,5 +30,7 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 16 NONE" # We expect the brackets highlighter to do nothing +"1 10 NONE" +"11 11 bracket-error" +"12 16 NONE" ) From f6d45cc1919a88b4a04a387cae445a8b16c3d4a5 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Wed, 29 Nov 2017 17:53:23 +0100 Subject: [PATCH 0543/1080] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 855be9e..decb30b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis] ======================= -**[Fish shell][fish]-like like syntax highlighting for [Zsh][zsh].** +**[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].** *Requirements: zsh 4.3.11+.* From c13ee4cf88a6c16a14d40f4830a4b10f8099081e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 6 Dec 2017 22:32:31 +0000 Subject: [PATCH 0544/1080] docs: Point to repology for finding packages. --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index ca1bfa7..92046b6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -26,6 +26,8 @@ How to install [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 +See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) + ### In your ~/.zshrc From 26a82113b08b131446193d8b52f30a8946814c6a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 25 Nov 2017 01:25:07 +0000 Subject: [PATCH 0545/1080] 'main': Highlight 'sudo' correctly when it's not installed. No test because _zsh_highlight_main__type() falls back to 'type -w' which runs 'rehash' implicitly, so on systems where 'sudo' is installed it's not possible to simulate its being absent. Test by forcing _zsh_highlight_main__type() to return 'none' when the argument is [[ $1 == 'sudo' ]], and: (1) Run 'make test' and confirm that all tests either pass, or fail and the first test point that fails is one that expects "sudo" at command position to be highlighted as 'command'; (2) In an interactive zsh, 'sudo' at command position is highlighted as an error. --- 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 7850ddc..346b754 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -147,6 +147,7 @@ _zsh_highlight_main__type() { fi fi if ! (( $+REPLY )); then + # Note that 'type -w' will run 'rehash' implicitly. REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }" fi if (( $+_zsh_highlight_main__command_type_cache )); then @@ -457,7 +458,7 @@ _zsh_highlight_highlighter_main_paint() elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=precommand - elif [[ "$arg" = "sudo" ]]; then + elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand next_word=${next_word//:regular:/} next_word+=':sudo_opt:' From d04c62a2240bf3d4b29ce9e122737140b1e17a8a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 6 Dec 2017 18:34:56 -0600 Subject: [PATCH 0546/1080] tests: Add skips for tests that require sudo --- highlighters/main/test-data/prefix-redirection.zsh | 2 ++ highlighters/main/test-data/sudo-command.zsh | 2 ++ highlighters/main/test-data/sudo-comment.zsh | 2 ++ highlighters/main/test-data/sudo-redirection.zsh | 2 ++ highlighters/main/test-data/sudo-redirection2.zsh | 2 ++ highlighters/main/test-data/sudo-redirection3.zsh | 2 ++ 6 files changed, 12 insertions(+) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 5a5c0e2..53c699f 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + BUFFER='>/tmp >/tmp sudo echo >/tmp foo' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 3183a23..e825e83 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + # Tests three codepaths: # * -i (no argument) # * -C3 (pasted argument) diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh index 856567b..c750b01 100644 --- a/highlighters/main/test-data/sudo-comment.zsh +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + setopt interactive_comments BUFFER='sudo -u # comment' diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index f507899..419caf2 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index 30f6ff8..715fed2 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + BUFFER='sudo >/tmp -u otheruser ls' expected_region_highlight=( diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index fdd426d..f8ea581 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +type sudo >/dev/null || skip_test='sudo must be present' + BUFFER='sudo 2>./. -u otheruser ls' expected_region_highlight=( From 8d37377644b17ca3bde9d9af67110412018d86bf Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 7 Dec 2017 01:04:13 +0000 Subject: [PATCH 0547/1080] Followup to last: Don't require 'sudo' to test prefix redirections. --- highlighters/main/test-data/prefix-redirection.zsh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 53c699f..6a13aa6 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -27,15 +27,13 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' - -BUFFER='>/tmp >/tmp sudo echo >/tmp foo' +BUFFER='>/tmp >/tmp command echo >/tmp foo' expected_region_highlight=( "2 5 path" # /tmp "8 11 path" # /tmp - "13 16 precommand" # sudo - "18 21 builtin" # echo - "24 27 path" # /tmp - "29 31 default" # foo + "13 19 precommand" # command + "21 24 builtin" # echo + "27 30 path" # /tmp + "32 34 default" # foo ) From 1ad5c1f40fc66fd41402d55da134a8ea8313e654 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 7 Dec 2017 01:16:02 +0000 Subject: [PATCH 0548/1080] Followup to parents: Restore sudo-* tests on platforms that don't have sudo. Travis (as currently configured) is one such platform. --- highlighters/main/test-data/sudo-command.zsh | 2 +- highlighters/main/test-data/sudo-comment.zsh | 2 +- highlighters/main/test-data/sudo-redirection.zsh | 2 +- highlighters/main/test-data/sudo-redirection2.zsh | 2 +- highlighters/main/test-data/sudo-redirection3.zsh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index e825e83..266ace2 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' +sudo(){} # Tests three codepaths: # * -i (no argument) diff --git a/highlighters/main/test-data/sudo-comment.zsh b/highlighters/main/test-data/sudo-comment.zsh index c750b01..74cd905 100644 --- a/highlighters/main/test-data/sudo-comment.zsh +++ b/highlighters/main/test-data/sudo-comment.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' +sudo(){} setopt interactive_comments BUFFER='sudo -u # comment' diff --git a/highlighters/main/test-data/sudo-redirection.zsh b/highlighters/main/test-data/sudo-redirection.zsh index 419caf2..c675d7d 100644 --- a/highlighters/main/test-data/sudo-redirection.zsh +++ b/highlighters/main/test-data/sudo-redirection.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' +sudo(){} BUFFER='sudo -u >/tmp otheruser ls; sudo ls; sudo -i ls' diff --git a/highlighters/main/test-data/sudo-redirection2.zsh b/highlighters/main/test-data/sudo-redirection2.zsh index 715fed2..23ada53 100644 --- a/highlighters/main/test-data/sudo-redirection2.zsh +++ b/highlighters/main/test-data/sudo-redirection2.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' +sudo(){} BUFFER='sudo >/tmp -u otheruser ls' diff --git a/highlighters/main/test-data/sudo-redirection3.zsh b/highlighters/main/test-data/sudo-redirection3.zsh index f8ea581..80e55b5 100644 --- a/highlighters/main/test-data/sudo-redirection3.zsh +++ b/highlighters/main/test-data/sudo-redirection3.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -type sudo >/dev/null || skip_test='sudo must be present' +sudo(){} BUFFER='sudo 2>./. -u otheruser ls' From fb948f5331202a55f333d6190d071f2d670846ea Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 7 Dec 2017 03:06:56 +0000 Subject: [PATCH 0549/1080] noop: Add comments. --- 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 346b754..1343d6a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -488,6 +488,8 @@ _zsh_highlight_highlighter_main_paint() case $res in reserved) # reserved word style=reserved-word + # + # Match braces. case $arg in ($'\x7b') braces_stack='Y'"$braces_stack" @@ -554,6 +556,7 @@ _zsh_highlight_highlighter_main_paint() if (( insane_alias )); then style=unknown-token else + # The common case. style=alias _zsh_highlight_main__resolve_alias $arg local alias_target="$REPLY" From 4e6f60063f1cda63b744f702f0cae71c529026eb Mon Sep 17 00:00:00 2001 From: disarmer mk Date: Fri, 14 Oct 2016 23:38:21 +0300 Subject: [PATCH 0550/1080] Add regexp highlighter --- HACKING.md | 14 ++--- docs/highlighters/regexp.md | 27 ++++++++ highlighters/regexp/README.md | 1 + highlighters/regexp/regexp-highlighter.zsh | 61 +++++++++++++++++++ highlighters/regexp/test-data/complex.zsh | 37 +++++++++++ .../regexp/test-data/word-boundary.zsh | 38 ++++++++++++ 6 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 docs/highlighters/regexp.md create mode 120000 highlighters/regexp/README.md create mode 100644 highlighters/regexp/regexp-highlighter.zsh create mode 100644 highlighters/regexp/test-data/complex.zsh create mode 100644 highlighters/regexp/test-data/word-boundary.zsh diff --git a/HACKING.md b/HACKING.md index 39d82fa..5266a33 100644 --- a/HACKING.md +++ b/HACKING.md @@ -44,14 +44,14 @@ tests must set the `bracket-level-#` keys themselves. For example: "10 10 bracket-level-1" # ) ) -Testing the `pattern` highlighter ---------------------------------- +Testing the `pattern` and `regexp` highlighters +----------------------------------------------- -Because the `pattern` highlighter modifies `region_highlight` directly instead -of using `_zsh_highlight_add_highlight`, the test harness 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: +Because the `pattern` and `regexp` highlighters modifies `region_highlight` +directly instead of using `_zsh_highlight_add_highlight`, the test harness +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') diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md new file mode 100644 index 0000000..25f1b6c --- /dev/null +++ b/docs/highlighters/regexp.md @@ -0,0 +1,27 @@ +zsh-syntax-highlighting / highlighters / regexp +------------------------------------------------ + +This is the `regexp` highlighter, that highlights user-defined regular +expressions. It's similar to the `pattern` highlighter, but allows more complex +patterns. + +### How to tweak it + +To use this highlighter, associate regular expressions with styles in the +`ZSH_HIGHLIGHT_REGEXP` associative array, for example in `~/.zshrc`: + + ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) + +This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not +"sudoedit" + +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)` +manual page][zshzle-Character-Highlighting]. + +See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` +in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] + +[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[perlretut]: http://perldoc.perl.org/perlretut.html +[zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions diff --git a/highlighters/regexp/README.md b/highlighters/regexp/README.md new file mode 120000 index 0000000..9f2522d --- /dev/null +++ b/highlighters/regexp/README.md @@ -0,0 +1 @@ +../../docs/highlighters/regexp.md \ No newline at end of file diff --git a/highlighters/regexp/regexp-highlighter.zsh b/highlighters/regexp/regexp-highlighter.zsh new file mode 100644 index 0000000..0edc461 --- /dev/null +++ b/highlighters/regexp/regexp-highlighter.zsh @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + + +# List of keyword and color pairs. +typeset -gA ZSH_HIGHLIGHT_REGEXP + +# Whether the pattern highlighter should be called or not. +_zsh_highlight_highlighter_regexp_predicate() +{ + _zsh_highlight_buffer_modified +} + +# Pattern syntax highlighting function. +_zsh_highlight_highlighter_regexp_paint() +{ + setopt localoptions extendedglob + local pattern + for pattern in ${(k)ZSH_HIGHLIGHT_REGEXP}; do + _zsh_highlight_regexp_highlighter_loop "$BUFFER" "$pattern" + done +} + +_zsh_highlight_regexp_highlighter_loop() +{ + local buf="$1" pat="$2" + integer OFFSET=0 + local MATCH; integer MBEGIN MEND + while true; do + [[ "$buf" =~ "$pat" ]] || return; + region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat]") + buf="$buf[$(($MEND+1)),-1]" + OFFSET=$((MEND+OFFSET)); + done +} diff --git a/highlighters/regexp/test-data/complex.zsh b/highlighters/regexp/test-data/complex.zsh new file mode 100644 index 0000000..4e0089b --- /dev/null +++ b/highlighters/regexp/test-data/complex.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +ZSH_HIGHLIGHT_REGEXP+=('[0-9\+\-]+' 'fg=white,bold,bg=red') + +BUFFER='echo 1+9-3 7+2' + +expected_region_highlight=( + "6 10 fg=white,bold,bg=red" + "12 14 fg=white,bold,bg=red" +) diff --git a/highlighters/regexp/test-data/word-boundary.zsh b/highlighters/regexp/test-data/word-boundary.zsh new file mode 100644 index 0000000..d1f89d9 --- /dev/null +++ b/highlighters/regexp/test-data/word-boundary.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +setopt RE_MATCH_PCRE + +ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' 'fg=white,bold,bg=red') + +BUFFER='sudo ls' + +expected_region_highlight=( + "1 4 fg=white,bold,bg=red" +) From 6a6d40208cd96024e5d23eb7452804f6bf696304 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 25 Nov 2017 15:16:20 -0600 Subject: [PATCH 0551/1080] main: Add fallback for useroptions if zsh/parameter is absent --- highlighters/main/main-highlighter.zsh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1343d6a..50415d8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -196,7 +196,21 @@ _zsh_highlight_main__stack_pop() { _zsh_highlight_highlighter_main_paint() { # Before we even 'emulate -L', save the user's options - local -A useroptions; useroptions=("${(@kv)options}") + local -A useroptions + if zmodload -e zsh/parameter; then + useroptions=("${(@kv)options}") + else + local canonicaloptions onoff option rawoptions + rawoptions=(${(f)"$(emulate -R zsh; set -o)"}) + canonicaloptions=(${${${(M)rawoptions:#*off}%% *}#no} ${${(M)rawoptions:#*on}%% *}) + for option in $canonicaloptions; do + [[ -o $option ]] + # This variable cannot be eliminated c.f. workers/42101. + onoff=${${=:-off on}[2-$?]} + useroptions+=($option $onoff) + done + fi + emulate -L zsh setopt localoptions extendedglob bareglobqual From 2411195c2092d64917cff3d8f904d63b78b195bf Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 12 Dec 2017 07:58:35 -0600 Subject: [PATCH 0552/1080] main: Expand paths before removing quoting Fixes highlighting of `ls \~`. Closes #328. --- 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 50415d8..3171c20 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -923,7 +923,7 @@ _zsh_highlight_main_highlighter_expand_path() # The $~1 syntax normally performs filename generation, but not when it's on the right-hand side of ${x:=y}. setopt localoptions nonomatch unset REPLY - : ${REPLY:=${(Q)~1}} + : ${REPLY:=${(Q)${~1}}} } # ------------------------------------------------------------------------------------------------- From ce1be4153de4bdb849a26614963027ec2449e5b5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 15 Dec 2017 02:35:10 +0000 Subject: [PATCH 0553/1080] =?UTF-8?q?'main':=20Add=20tests=20for=20=C2=ABl?= =?UTF-8?q?s=20\~=C2=BB=20and=20for=20not=20performing=20parameter=20expan?= =?UTF-8?q?sion=20on=20the=20command=20word.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a followup to the last commit, which was about issue #328. These tests are taken from the original #328 pull request, with updated expectations where applicable. Review-by: Matthew Martin --- .../main/test-data/path-dollared-word.zsh | 45 +++++++++++++++++++ .../main/test-data/path-dollared-word3.zsh | 37 +++++++++++++++ .../main/test-data/path-dollared-word4.zsh | 36 +++++++++++++++ .../main/test-data/path-tilde-home3.zsh | 36 +++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 highlighters/main/test-data/path-dollared-word.zsh create mode 100644 highlighters/main/test-data/path-dollared-word3.zsh create mode 100644 highlighters/main/test-data/path-dollared-word4.zsh create mode 100644 highlighters/main/test-data/path-tilde-home3.zsh diff --git a/highlighters/main/test-data/path-dollared-word.zsh b/highlighters/main/test-data/path-dollared-word.zsh new file mode 100644 index 0000000..99055da --- /dev/null +++ b/highlighters/main/test-data/path-dollared-word.zsh @@ -0,0 +1,45 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +if [[ $OSTYPE == msys ]]; then + skip_test='Cannot chmod +x in msys2' # cargo culted from option-path_dirs.zsh +else + mkdir kappa + touch kappa.exe + chmod +x kappa.exe + cd kappa + + BUFFER='$PWD.exe; ${PWD}.exe' + + expected_region_highlight=( + "1 8 unknown-token" # $PWD.exe - not eval'd; issue #328 + "9 9 commandseparator" # ; + "11 20 unknown-token" # ${PWD}.exe + ) +fi diff --git a/highlighters/main/test-data/path-dollared-word3.zsh b/highlighters/main/test-data/path-dollared-word3.zsh new file mode 100644 index 0000000..fc3324e --- /dev/null +++ b/highlighters/main/test-data/path-dollared-word3.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# «/usr» at this point would be highlighted as path_prefix; so should +# a parameter that expands to an equivalent string be highlighted. +BUFFER='$PWD; ${PWD}' + +expected_region_highlight=( + "1 4 unknown-token" # $PWD - not eval'd; issue #328 + "7 12 unknown-token" # ${PWD} +) diff --git a/highlighters/main/test-data/path-dollared-word4.zsh b/highlighters/main/test-data/path-dollared-word4.zsh new file mode 100644 index 0000000..e29182c --- /dev/null +++ b/highlighters/main/test-data/path-dollared-word4.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# This tests for a regression during development of issue #328: an interim version +# of that branch failed that test with "Bail out! output on stderr". +BUFFER='${' + +expected_region_highlight=( + "1 2 unknown-token" # ${ +) diff --git a/highlighters/main/test-data/path-tilde-home3.zsh b/highlighters/main/test-data/path-tilde-home3.zsh new file mode 100644 index 0000000..5c076e8 --- /dev/null +++ b/highlighters/main/test-data/path-tilde-home3.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +HOME="." +BUFFER='ls \~' + +expected_region_highlight=( + "1 2 command" # ls + "4 5 default" # \~ +) From 2919679ee89dfaf34a336050c4013215ee2e2677 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 14 Dec 2017 20:44:20 -0600 Subject: [PATCH 0554/1080] tests: Skip when zsh/pcre is not available --- highlighters/regexp/test-data/word-boundary.zsh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/highlighters/regexp/test-data/word-boundary.zsh b/highlighters/regexp/test-data/word-boundary.zsh index d1f89d9..e852b8a 100644 --- a/highlighters/regexp/test-data/word-boundary.zsh +++ b/highlighters/regexp/test-data/word-boundary.zsh @@ -27,12 +27,16 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -setopt RE_MATCH_PCRE +if zmodload -s zsh/pcre; then + setopt RE_MATCH_PCRE -ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' 'fg=white,bold,bg=red') + ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' 'fg=white,bold,bg=red') -BUFFER='sudo ls' + BUFFER='sudo ls' -expected_region_highlight=( - "1 4 fg=white,bold,bg=red" -) + expected_region_highlight=( + "1 4 fg=white,bold,bg=red" + ) +else + skip_test='Test requires zsh/pcre' +fi From 3e5629454358821a4cebc059a988e7f1cdbbbf51 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 14 Dec 2017 20:58:32 -0600 Subject: [PATCH 0555/1080] tests: Avoid using new zmodload flags Unbreaks build on pre-5.4. --- highlighters/regexp/test-data/word-boundary.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/regexp/test-data/word-boundary.zsh b/highlighters/regexp/test-data/word-boundary.zsh index e852b8a..1f4f666 100644 --- a/highlighters/regexp/test-data/word-boundary.zsh +++ b/highlighters/regexp/test-data/word-boundary.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -if zmodload -s zsh/pcre; then +if zmodload zsh/pcre 2>/dev/null; then setopt RE_MATCH_PCRE ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' 'fg=white,bold,bg=red') From b07ada1255b74c25fbc96901f2b77dc4bd81de1a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 15 Dec 2017 20:09:39 -0600 Subject: [PATCH 0556/1080] driver: Run under emulate -L zsh and add zsyh_user_options --- docs/highlighters.md | 8 +++++++ highlighters/main/main-highlighter.zsh | 31 +++++--------------------- zsh-syntax-highlighting.zsh | 19 +++++++++++++++- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index c0f79bc..642d2bd 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -78,6 +78,14 @@ To create your own `acme` highlighter: _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 ]] + + The option name must be all lowercase with no underscores and not an alias. + * Name your own functions and global variables `_zsh_highlight_acme_*`. - In zsh-syntax-highlighting 0.4.0 and earlier, the entrypoints diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 3171c20..f7abee8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -195,24 +195,7 @@ _zsh_highlight_main__stack_pop() { # Main syntax highlighting function. _zsh_highlight_highlighter_main_paint() { - # Before we even 'emulate -L', save the user's options - local -A useroptions - if zmodload -e zsh/parameter; then - useroptions=("${(@kv)options}") - else - local canonicaloptions onoff option rawoptions - rawoptions=(${(f)"$(emulate -R zsh; set -o)"}) - canonicaloptions=(${${${(M)rawoptions:#*off}%% *}#no} ${${(M)rawoptions:#*on}%% *}) - for option in $canonicaloptions; do - [[ -o $option ]] - # This variable cannot be eliminated c.f. workers/42101. - onoff=${${=:-off on}[2-$?]} - useroptions+=($option $onoff) - done - fi - - emulate -L zsh - setopt localoptions extendedglob bareglobqual + setopt localoptions extendedglob # At the PS3 prompt and in vared, highlight nothing. # @@ -243,13 +226,13 @@ _zsh_highlight_highlighter_main_paint() # ":" for 'then' local braces_stack - if [[ $useroptions[ignorebraces] == on || ${useroptions[ignoreclosebraces]:-off} == on ]]; then + if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false else local right_brace_is_recognised_everywhere=true fi - if [[ $useroptions[pathdirs] == on ]]; then + if [[ $zsyh_user_options[pathdirs] == on ]]; then options_to_set+=( PATH_DIRS ) fi @@ -326,7 +309,7 @@ _zsh_highlight_highlighter_main_paint() # Processing buffer local proc_buf="$buf" local -a args - if [[ $useroptions[interactivecomments] == on ]]; then + if [[ $zsyh_user_options[interactivecomments] == on ]]; then args=(${(zZ+c+)buf}) else args=(${(z)buf}) @@ -420,7 +403,7 @@ _zsh_highlight_highlighter_main_paint() # Handle the INTERACTIVE_COMMENTS option. # # We use the (Z+c+) flag so the entire comment is presented as one token in $arg. - if [[ $useroptions[interactivecomments] == on && $arg[1] == $histchars[3] ]]; then + if [[ $zsyh_user_options[interactivecomments] == on && $arg[1] == $histchars[3] ]]; then if [[ $this_word == *(':regular:'|':start:')* ]]; then style=comment else @@ -659,7 +642,7 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main__stack_pop 'R' style=reserved-word fi;; $'\x28\x29') # possibly a function definition - if [[ $useroptions[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word + if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word then next_word+=':start:' fi @@ -816,7 +799,6 @@ _zsh_highlight_main_highlighter_check_path() # Highlight special chars inside double-quoted strings _zsh_highlight_main_highlighter_highlight_string() { - setopt localoptions noksharrays local -a match mbegin mend local MATCH; integer MBEGIN MEND local i j k style @@ -872,7 +854,6 @@ _zsh_highlight_main_highlighter_highlight_string() # Highlight special chars inside dollar-quoted strings _zsh_highlight_main_highlighter_highlight_dollar_string() { - setopt localoptions noksharrays local -a match mbegin mend local MATCH; integer MBEGIN MEND local i j k style diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index e4e44fa..d100edb 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -83,8 +83,25 @@ _zsh_highlight() return $ret fi + # 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}") + 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 + [[ -o $option ]] + # This variable cannot be eliminated c.f. workers/42101. + onoff=${${=:-off on}[2-$?]} + zsyh_user_options+=($option $onoff) + done + fi + typeset -r zsyh_user_options + + emulate -L zsh setopt localoptions warncreateglobal - setopt localoptions noksharrays 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 eeb2eadcdd945f7ad713bd85d9fabfa0fcf43e26 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 19 Dec 2017 16:02:29 -0600 Subject: [PATCH 0557/1080] docs: Fix links; thanks @dukex for noticing Closes #441. --- INSTALL.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 92046b6..1f0d923 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -55,9 +55,10 @@ Note that `zsh-syntax-highlighting` must be the last plugin sourced. The zsh-syntax-highlighting authors recommend manual installation over the use of a framework or plugin manager. -This list is incomplete as there are too many [frameworks / plugin managers] -(https://github.com/unixorn/awesome-zsh-plugins#frameworks) to list them all -here. +This list is incomplete as there are too many +[frameworks / plugin managers][framework-list] to list them all here. + +[framework-list]: https://github.com/unixorn/awesome-zsh-plugins#frameworks #### [Antigen](https://github.com/zsh-users/antigen) @@ -80,9 +81,10 @@ your `.zshrc`. #### [Prezto](https://github.com/sorin-ionescu/prezto) -Zsh-syntax-highlighting is included with Prezto. See the [Prezto documentation] -(https://github.com/sorin-ionescu/prezto/tree/master/modules/syntax-highlighting) -to enable and configure highlighters. +Zsh-syntax-highlighting is included with Prezto. See the +[Prezto documentation][prezto-docs] to enable and configure highlighters. + +[prezto-docs]: https://github.com/sorin-ionescu/prezto/tree/master/modules/syntax-highlighting #### [zgen](https://github.com/tarjoilija/zgen) From ab1013ae0d8c94a38141d4b75f5ff88ea59bc80e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 19 Dec 2017 22:51:39 -0600 Subject: [PATCH 0558/1080] main: A redirection token is an invalid redirection target Closes #466. --- highlighters/main/main-highlighter.zsh | 8 +++- .../main/test-data/redirection-comment.zsh | 38 +++++++++++++++++ highlighters/main/test-data/redirection3.zsh | 42 +++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/redirection-comment.zsh create mode 100644 highlighters/main/test-data/redirection3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f7abee8..0a83092 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -417,8 +417,12 @@ _zsh_highlight_highlighter_main_paint() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then - # A '<' or '>', possibly followed by a digit - in_redirection=2 + if (( in_redirection )); then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token + already_added=1 + else + in_redirection=2 + fi fi # Special-case the first word after 'sudo'. diff --git a/highlighters/main/test-data/redirection-comment.zsh b/highlighters/main/test-data/redirection-comment.zsh new file mode 100644 index 0000000..a019100 --- /dev/null +++ b/highlighters/main/test-data/redirection-comment.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +setopt interactive_comments + +BUFFER=': <<#foo' + +expected_region_highlight=( + "1 1 builtin" # : + "3 4 redirection" # << + "5 8 comment" # #foo +) diff --git a/highlighters/main/test-data/redirection3.zsh b/highlighters/main/test-data/redirection3.zsh new file mode 100644 index 0000000..bf062cf --- /dev/null +++ b/highlighters/main/test-data/redirection3.zsh @@ -0,0 +1,42 @@ +# ------------------------------------------------------------------------------------------------- +# 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=': >>>; : <>\<<<> + "5 5 unknown-token" # > + "6 6 commandseparator" # ; + "8 8 builtin" # : + "10 11 redirection" # <> + "12 13 default" # \< + "14 16 redirection" # <<< + "17 19 default" # EOF +) From f623b07fb0e9ed6a37427d1ae109816bc3a0b79f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 12 Nov 2017 23:12:22 -0600 Subject: [PATCH 0559/1080] main: Remove trailing whitespace --- highlighters/main/main-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0a83092..bfd2137 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -78,7 +78,7 @@ _zsh_highlight_main_add_region_highlight() { command arg0 precommand arg0 hashed-command arg0 - + path_prefix path # The path separator fallback won't ever be used, due to the optimisation # in _zsh_highlight_main_highlighter_highlight_path_separators(). @@ -286,7 +286,7 @@ _zsh_highlight_highlighter_main_paint() # 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:/} + # 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 @@ -542,7 +542,7 @@ _zsh_highlight_highlighter_main_paint() 'suffix alias') style=suffix-alias;; alias) () { integer insane_alias - case $arg in + case $arg in # Issue #263: aliases with '=' on their LHS. # # There are three cases: From dcb115c74c353a29e4916d3d4fa9161eaf4f967e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Nov 2017 22:41:27 -0600 Subject: [PATCH 0560/1080] main: Make " and $' helper functions responsible for highlighting quote --- highlighters/main/main-highlighter.zsh | 34 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index bfd2137..5a26311 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -103,6 +103,12 @@ _zsh_highlight_main_add_region_highlight() { _zsh_highlight_add_highlight $start $end "$@" } +_zsh_highlight_main_add_many_region_highlights() { + for 1 2 3; do + _zsh_highlight_main_add_region_highlight $1 $2 $3 + done +} + # Get the type of a command. # # Uses the zsh/parameter module if available to avoid forks, and a @@ -670,14 +676,10 @@ _zsh_highlight_highlighter_main_paint() '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; "'"*) style=single-quoted-argument;; - '"'*) style=double-quoted-argument - _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - _zsh_highlight_main_highlighter_highlight_string + '"'*) _zsh_highlight_main_highlighter_highlight_double_quote already_added=1 ;; - \$\'*) style=dollar-quoted-argument - _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - _zsh_highlight_main_highlighter_highlight_dollar_string + \$\'*) _zsh_highlight_main_highlighter_highlight_dollar_quote already_added=1 ;; '`'*) style=back-quoted-argument;; @@ -801,11 +803,12 @@ _zsh_highlight_main_highlighter_check_path() } # Highlight special chars inside double-quoted strings -_zsh_highlight_main_highlighter_highlight_string() +_zsh_highlight_main_highlighter_highlight_double_quote() { - local -a match mbegin mend + local -a highlights match mbegin mend local MATCH; integer MBEGIN MEND local i j k style + # Starting quote is at 1, so start parsing at offset 2 in the string. for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) @@ -851,18 +854,22 @@ _zsh_highlight_main_highlighter_highlight_string() *) continue ;; esac - _zsh_highlight_main_add_region_highlight $j $k $style + highlights+=($j $k $style) done + + highlights=($start_pos $end_pos double-quoted-argument $highlights) + _zsh_highlight_main_add_many_region_highlights $highlights } # Highlight special chars inside dollar-quoted strings -_zsh_highlight_main_highlighter_highlight_dollar_string() +_zsh_highlight_main_highlighter_highlight_dollar_quote() { - local -a match mbegin mend + local -a highlights match mbegin mend local MATCH; integer MBEGIN MEND local i j k style local AA integer c + # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string. for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) @@ -893,8 +900,11 @@ _zsh_highlight_main_highlighter_highlight_dollar_string() *) continue ;; esac - _zsh_highlight_main_add_region_highlight $j $k $style + highlights+=($j $k $style) done + + highlights=($start_pos $end_pos dollar-quoted-argument $highlights) + _zsh_highlight_main_add_many_region_highlights $highlights } # Called with a single positional argument. From 25ae1c01216c967335dfc5fd419848aaa8507b53 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Nov 2017 22:43:40 -0600 Subject: [PATCH 0561/1080] main: Add ' helper function --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index bf83820..19912ab 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -38,6 +38,7 @@ This highlighter defines the following styles: * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) +* `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``) * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) * `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) * `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5a26311..5afa146 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -46,6 +46,7 @@ : ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} +: ${ZSH_HIGHLIGHT_STYLES[rc-quote]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]:=fg=cyan} : ${ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan} @@ -675,7 +676,9 @@ _zsh_highlight_highlighter_main_paint() ;| '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; - "'"*) style=single-quoted-argument;; + "'"*) _zsh_highlight_main_highlighter_highlight_single_quote 1 + already_added=1 + ;; '"'*) _zsh_highlight_main_highlighter_highlight_double_quote already_added=1 ;; @@ -802,6 +805,26 @@ _zsh_highlight_main_highlighter_check_path() return 1 } +# Highlight single-quoted strings +_zsh_highlight_main_highlighter_highlight_single_quote() +{ + local arg1=$1 i q=\' + local -a highlights + i=$arg[(ib:arg1+1:)$q] + + if [[ $zsyh_user_options[rcquotes] == on ]]; then + while [[ $arg[i+1] == "'" ]]; do + highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + 1 )) rc-quote) + (( i++ )) + i=$arg[(ib:i+1:)$q] + done + fi + + highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights) + _zsh_highlight_main_add_many_region_highlights $highlights + REPLY=$i +} + # Highlight special chars inside double-quoted strings _zsh_highlight_main_highlighter_highlight_double_quote() { From dc1b2f6fa4bb477e7b9712ebdb4e82beb50258c6 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Nov 2017 22:45:07 -0600 Subject: [PATCH 0562/1080] main: Highlight partially quoted arguments correctly Closes #130 --- highlighters/main/main-highlighter.zsh | 72 +++++++++++++++++++------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5afa146..a0cd600 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -676,19 +676,7 @@ _zsh_highlight_highlighter_main_paint() ;| '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; - "'"*) _zsh_highlight_main_highlighter_highlight_single_quote 1 - already_added=1 - ;; - '"'*) _zsh_highlight_main_highlighter_highlight_double_quote - already_added=1 - ;; - \$\'*) _zsh_highlight_main_highlighter_highlight_dollar_quote - already_added=1 - ;; '`'*) style=back-quoted-argument;; - [$][*]) style=default;; - [*?]*|*[^\\][*?]*) - $highlight_glob && style=globbing || style=default;; *) if false; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then # was handled by the $'\x7d' case above @@ -706,7 +694,8 @@ _zsh_highlight_highlighter_main_paint() if _zsh_highlight_main_highlighter_check_path; then style=$REPLY else - style=default + _zsh_highlight_main_highlighter_highlight_argument + already_added=1 fi fi ;; @@ -805,6 +794,49 @@ _zsh_highlight_main_highlighter_check_path() return 1 } +# Highlight an argument and possibly special chars in quotes +# This command will at least highlight start_pos to end_pos with the default style +_zsh_highlight_main_highlighter_highlight_argument() +{ + local i + + _zsh_highlight_main_add_region_highlight $start_pos $end_pos default + for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do + case "$arg[$i]" in + "\\") (( i += 1 )); continue;; + "'") _zsh_highlight_main_highlighter_highlight_single_quote $i; (( i = REPLY ));; + '"') _zsh_highlight_main_highlighter_highlight_double_quote $i; (( i = REPLY ));; + '$') + if [[ $arg[i+1] == "'" ]]; then + _zsh_highlight_main_highlighter_highlight_dollar_quote $i + (( i = REPLY )) + elif [[ $arg[i+1] == [\^=~#+] ]]; then + while [[ $arg[i+1] == [\^=~#+] ]]; do + (( i += 1 )) + done + if [[ $arg[i+1] == [*@#?-$!] ]]; then + (( i += 1 )) + fi + elif [[ $arg[i+1] == [*@#?-$!] ]]; then + (( i += 1 )) + fi;; + [*?]) + if $highlight_glob; then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing + break + fi;; + *) continue;; + esac + done +} + +# Quote Helper Functions +# +# $arg is expected to be set to the current argument +# $start_pos is expected to be set to the start of $arg in $BUFFER +# $1 is the index in $arg which starts the quote +# $REPLY is returned as the end of quote index in $arg + # Highlight single-quoted strings _zsh_highlight_main_highlighter_highlight_single_quote() { @@ -832,11 +864,11 @@ _zsh_highlight_main_highlighter_highlight_double_quote() local MATCH; integer MBEGIN MEND local i j k style - # Starting quote is at 1, so start parsing at offset 2 in the string. - for (( i = 2 ; i < end_pos - start_pos ; i += 1 )) ; do + for (( i = $1 + 1 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in + '"') break;; '$' ) style=dollar-double-quoted-argument # Look for an alphanumeric parameter name. if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then @@ -880,8 +912,9 @@ _zsh_highlight_main_highlighter_highlight_double_quote() highlights+=($j $k $style) done - highlights=($start_pos $end_pos double-quoted-argument $highlights) + highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights) _zsh_highlight_main_add_many_region_highlights $highlights + REPLY=$i } # Highlight special chars inside dollar-quoted strings @@ -893,11 +926,11 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() local AA integer c - # Starting dollar-quote is at 1:2, so start parsing at offset 3 in the string. - for (( i = 3 ; i < end_pos - start_pos ; i += 1 )) ; do + for (( i = $1 + 2 ; i < end_pos - start_pos ; 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 [[ "$arg[$c]" != ([0-9xXuUa-fA-F]) ]] && break @@ -926,8 +959,9 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() highlights+=($j $k $style) done - highlights=($start_pos $end_pos dollar-quoted-argument $highlights) + highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights) _zsh_highlight_main_add_many_region_highlights $highlights + REPLY=$i } # Called with a single positional argument. From 572ca51b1f6b5dc8f7313fc02a999df76e6a524e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Nov 2017 23:03:21 -0600 Subject: [PATCH 0563/1080] main: Add tests --- .../main/test-data/multiple-quotes.zsh | 47 +++++++++++++++++++ highlighters/main/test-data/rc-quotes.zsh | 39 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 highlighters/main/test-data/multiple-quotes.zsh create mode 100644 highlighters/main/test-data/rc-quotes.zsh diff --git a/highlighters/main/test-data/multiple-quotes.zsh b/highlighters/main/test-data/multiple-quotes.zsh new file mode 100644 index 0000000..10b8d14 --- /dev/null +++ b/highlighters/main/test-data/multiple-quotes.zsh @@ -0,0 +1,47 @@ +# ------------------------------------------------------------------------------------------------- +# 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"baz$quux/foo\\\\bar"baz$\'quux\\nfoo\\001bar\'baz' + +expected_region_highlight=( + "3 7 single-quoted-argument" # 'foo' + "8 10 default" # bar + "11 14 double-quoted-argument" #"baz + "15 19 dollar-double-quoted-argument" # $quux + "20 23 double-quoted-argument" # /foo + "24 25 back-double-quoted-argument" # \\ + "26 29 double-quoted-argument" # bar" + "30 32 default" # baz + "33 38 dollar-quoted-argument" # $'quux + "39 40 back-dollar-quoted-argument" # \n + "41 43 dollar-quoted-argument" # foo + "44 47 back-dollar-quoted-argument" # \001 + "48 51 dollar-quoted-argument" # bar' + "52 54 default" # baz +) diff --git a/highlighters/main/test-data/rc-quotes.zsh b/highlighters/main/test-data/rc-quotes.zsh new file mode 100644 index 0000000..6d1d6ed --- /dev/null +++ b/highlighters/main/test-data/rc-quotes.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +setopt RC_QUOTES + +BUFFER=": 'foo''bar'baz" + +expected_region_highlight=( + "3 6 single-quoted-argument" # 'foo + "7 8 rc-quote" # '' + "9 12 single-quoted-argument" # bar' + "13 15 default" # baz +) From ff61a496b5ea5f17eb0621314edb09219d421e44 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 23 Dec 2017 23:04:32 +0000 Subject: [PATCH 0564/1080] 'main': Add a regression test for issue #468. --- .../test-data/order-path-before-globbing.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/order-path-before-globbing.zsh diff --git a/highlighters/main/test-data/order-path-before-globbing.zsh b/highlighters/main/test-data/order-path-before-globbing.zsh new file mode 100644 index 0000000..00e730b --- /dev/null +++ b/highlighters/main/test-data/order-path-before-globbing.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 +# ------------------------------------------------------------------------------------------------- + +touch '*' +BUFFER=': * \*' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 globbing "issue #468"' # * + '5 6 path' # \* +) From bdbe214453c40908006f1bc53bf0562e93fe957d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Nov 2017 22:38:19 -0600 Subject: [PATCH 0565/1080] main: Add *-quoted-argument-unclosed styles Closes #277. --- docs/highlighters/main.md | 3 +++ highlighters/main/main-highlighter.zsh | 27 ++++++++++++++++--- .../main/test-data/dollar-quoted3.zsh | 2 +- .../main/test-data/double-quoted2.zsh | 2 +- .../main/test-data/multiline-string2.zsh | 4 +-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 19912ab..7fddebc 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -36,8 +36,11 @@ This highlighter defines the following styles: * `double-hyphen-option` - double hyphen options (`--option`) * `back-quoted-argument` - backquoted expressions (`` `foo` ``) * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) +* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) +* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``) * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) +* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``) * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``) * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) * `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index a0cd600..3d5d9f3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -85,6 +85,10 @@ _zsh_highlight_main_add_region_highlight() { # in _zsh_highlight_main_highlighter_highlight_path_separators(). path_pathseparator path path_prefix_pathseparator path_prefix + + single-quoted-argument{-unclosed,} + double-quoted-argument{-unclosed,} + dollar-single-quoted-argument{-unclosed,} ) local needle=$1 value while [[ -n ${value::=$fallback_of[$needle]} ]]; do @@ -840,7 +844,7 @@ _zsh_highlight_main_highlighter_highlight_argument() # Highlight single-quoted strings _zsh_highlight_main_highlighter_highlight_single_quote() { - local arg1=$1 i q=\' + local arg1=$1 i q=\' style local -a highlights i=$arg[(ib:arg1+1:)$q] @@ -852,7 +856,12 @@ _zsh_highlight_main_highlighter_highlight_single_quote() done fi - highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) single-quoted-argument $highlights) + if [[ $arg[i] == "'" ]]; then + style=single-quoted-argument + else + style=single-quoted-argument-unclosed + fi + highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } @@ -912,7 +921,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote() highlights+=($j $k $style) done - highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) double-quoted-argument $highlights) + if [[ $arg[i] == '"' ]]; then + style=double-quoted-argument + else + style=double-quoted-argument-unclosed + fi + highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } @@ -959,7 +973,12 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() highlights+=($j $k $style) done - highlights=($(( start_pos + $1 - 1 )) $(( start_pos + i )) dollar-quoted-argument $highlights) + if [[ $arg[i] == "'" ]]; then + style=dollar-quoted-argument + else + style=dollar-quoted-argument-unclosed + fi + highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index 320cd94..2872f7f 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -32,6 +32,6 @@ BUFFER=": \$'\xa1" expected_region_highlight=( - "3 4 dollar-quoted-argument" # $' + "3 4 dollar-quoted-argument-unclosed" # $' "5 8 back-dollar-quoted-argument" # \xa1 ) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index 1538423..ecd79ea 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -32,6 +32,6 @@ BUFFER=': "foo$bar' expected_region_highlight=( - "3 6 double-quoted-argument" # "foo + "3 6 double-quoted-argument-unclosed" # "foo "7 10 dollar-double-quoted-argument" # $bar ) diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 8ecce5b..7c5845e 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -27,8 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER=$'echo "foo1\n' +BUFFER=$'echo \'foo1\n' expected_region_highlight=( - "6 10 double-quoted-argument" # 'foo2"' + "6 10 single-quoted-argument-unclosed" # 'foo1 ) From 8652a8f4e4c1a2d8fd36b4ee46515b42ad09c97f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 25 Dec 2017 08:41:53 +0000 Subject: [PATCH 0566/1080] Bump copyright years. --- highlighters/brackets/brackets-highlighter.zsh | 2 +- highlighters/main/main-highlighter.zsh | 2 +- tests/tap-colorizer.zsh | 2 +- tests/test-highlighting.zsh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index 2ef2386..fc71f2a 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2017 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 3d5d9f3..687364f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2017 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/tests/tap-colorizer.zsh b/tests/tap-colorizer.zsh index eb24934..f3dc84e 100755 --- a/tests/tap-colorizer.zsh +++ b/tests/tap-colorizer.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2015 zsh-syntax-highlighting contributors +# Copyright (c) 2015, 2017 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index a7b98a5..2f4d3c3 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2017 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From 0bf9ce7ab506dda7249de534524472b9c60a8a3d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 1 Jan 2018 04:15:28 +0000 Subject: [PATCH 0567/1080] Happy New Year 2017. --- COPYING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/COPYING.md b/COPYING.md index 3d6b811..b9ea233 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2016 zsh-syntax-highlighting contributors +Copyright (c) 2010-2017 zsh-syntax-highlighting contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted From 2181247ae1889a0b3f50fc42cf71651b732e7282 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 1 Jan 2018 05:04:53 +0000 Subject: [PATCH 0568/1080] 'main': Add a regression test for issue #474. --- COPYING.md | 2 +- .../test-data/order-path-after-dollar.zsh | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/order-path-after-dollar.zsh diff --git a/COPYING.md b/COPYING.md index b9ea233..22eea4f 100644 --- a/COPYING.md +++ b/COPYING.md @@ -1,4 +1,4 @@ -Copyright (c) 2010-2017 zsh-syntax-highlighting contributors +Copyright (c) 2010-2018 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/test-data/order-path-after-dollar.zsh b/highlighters/main/test-data/order-path-after-dollar.zsh new file mode 100644 index 0000000..c260c53 --- /dev/null +++ b/highlighters/main/test-data/order-path-after-dollar.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 +# ------------------------------------------------------------------------------------------------- + +touch '$foo' +BUFFER=': $foo \$foo' + +expected_region_highlight=( + '1 1 builtin' # : + '3 6 default "issue #474"' # $foo - if we add a "unquoted parameter expansion" style then this expectation should change + '8 12 path' # \$foo +) From df0f44858634c454fbbabc182fc5ffe43b8907b5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 25 Dec 2017 00:03:51 -0600 Subject: [PATCH 0569/1080] main: Highlight path after globbing checks Closes #468. --- highlighters/main/main-highlighter.zsh | 19 +++++----- highlighters/main/test-data/noglob3.zsh | 36 +++++++++++++++++++ .../test-data/order-path-before-globbing.zsh | 2 +- 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 highlighters/main/test-data/noglob3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 687364f..b8ed6f4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -695,19 +695,14 @@ _zsh_highlight_highlighter_main_paint() elif (( in_redirection == 2 )); then style=redirection else - if _zsh_highlight_main_highlighter_check_path; then - style=$REPLY - else - _zsh_highlight_main_highlighter_highlight_argument - already_added=1 - fi + _zsh_highlight_main_highlighter_highlight_argument + already_added=1 fi ;; esac fi if ! (( already_added )); then _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - [[ $style == path || $style == path_prefix ]] && _zsh_highlight_main_highlighter_highlight_path_separators fi if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $arg == ';' ]] && $in_array_assignment; then @@ -802,7 +797,8 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight start_pos to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local i + local i path_eligible style + path_eligible=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos default for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do @@ -827,11 +823,18 @@ _zsh_highlight_main_highlighter_highlight_argument() [*?]) if $highlight_glob; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing + path_eligible=0 break fi;; *) continue;; esac done + + if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then + style=$REPLY + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + _zsh_highlight_main_highlighter_highlight_path_separators + fi } # Quote Helper Functions diff --git a/highlighters/main/test-data/noglob3.zsh b/highlighters/main/test-data/noglob3.zsh new file mode 100644 index 0000000..361ea8c --- /dev/null +++ b/highlighters/main/test-data/noglob3.zsh @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +touch \* + +BUFFER='noglob echo *' + +expected_region_highlight=( + "13 13 path" # * +) diff --git a/highlighters/main/test-data/order-path-before-globbing.zsh b/highlighters/main/test-data/order-path-before-globbing.zsh index 00e730b..b1695fc 100644 --- a/highlighters/main/test-data/order-path-before-globbing.zsh +++ b/highlighters/main/test-data/order-path-before-globbing.zsh @@ -33,6 +33,6 @@ BUFFER=': * \*' expected_region_highlight=( '1 1 builtin' # : - '3 3 globbing "issue #468"' # * + '3 3 globbing' # * '5 6 path' # \* ) From 987b743646c3e71a160de0ac2177bfe914bde39a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 23 Dec 2017 03:59:53 +0000 Subject: [PATCH 0570/1080] =?UTF-8?q?'main':=20Fix=20highlighting=20of=20?= =?UTF-8?q?=C2=AB<->=C2=BB-style=20numeric=20globs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found-by: Matthew Martin --- highlighters/main/main-highlighter.zsh | 6 ++- .../main/test-data/number_range-glob.zsh | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/number_range-glob.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b8ed6f4..3bffa73 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -173,7 +173,8 @@ _zsh_highlight_main__is_redirection() { # - starts with an optional single-digit number; # - then, has a '<' or '>' character; # - is not a process substitution [<(...) or >(...)]. - [[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] + # - is not a numeric glob <-> + [[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]] } # Resolve alias. @@ -820,7 +821,8 @@ _zsh_highlight_main_highlighter_highlight_argument() elif [[ $arg[i+1] == [*@#?-$!] ]]; then (( i += 1 )) fi;; - [*?]) + [*?]|\<) + # The '<' is for the <-> globbing syntax. (This function doesn't get called on redirection tokens.) if $highlight_glob; then _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing path_eligible=0 diff --git a/highlighters/main/test-data/number_range-glob.zsh b/highlighters/main/test-data/number_range-glob.zsh new file mode 100644 index 0000000..f8b51c9 --- /dev/null +++ b/highlighters/main/test-data/number_range-glob.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='print <-> x<-> ' + +expected_region_highlight=( + '1 5 builtin' # print + '7 9 globbing' # <-> + '11 14 globbing' # x<-> + '16 16 redirection' # < + '17 22 default' # foo2-3 (the filename) + '23 23 redirection' # > +) From d17417ec1bd37ace6222175810878c97a47a2b91 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 7 Jan 2018 22:06:39 -0600 Subject: [PATCH 0571/1080] main: Highlight unclosed backtick subshells --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 20 +++++++++++++++++-- .../main/test-data/back-quoted-argument.zsh | 6 ++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 7fddebc..cec79fa 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -35,6 +35,7 @@ This highlighter defines the following styles: * `single-hyphen-option` - single hyphen options (`-o`) * `double-hyphen-option` - double hyphen options (`--option`) * `back-quoted-argument` - backquoted expressions (`` `foo` ``) +* `back-quoted-argument-unclosed` - unclosed backquoted expressions (`` `foo ``) * `single-quoted-argument` - single quoted arguments (`` 'foo' ``) * `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``) * `double-quoted-argument` - double quoted arguments (`` "foo" ``) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 3bffa73..6981b0f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -89,6 +89,7 @@ _zsh_highlight_main_add_region_highlight() { single-quoted-argument{-unclosed,} double-quoted-argument{-unclosed,} dollar-single-quoted-argument{-unclosed,} + back-quoted-argument{-unclosed,} ) local needle=$1 value while [[ -n ${value::=$fallback_of[$needle]} ]]; do @@ -681,7 +682,6 @@ _zsh_highlight_highlighter_main_paint() ;| '--'*) style=double-hyphen-option;; '-'*) style=single-hyphen-option;; - '`'*) style=back-quoted-argument;; *) if false; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then # was handled by the $'\x7d' case above @@ -807,6 +807,7 @@ _zsh_highlight_main_highlighter_highlight_argument() "\\") (( i += 1 )); continue;; "'") _zsh_highlight_main_highlighter_highlight_single_quote $i; (( i = REPLY ));; '"') _zsh_highlight_main_highlighter_highlight_double_quote $i; (( i = REPLY ));; + '`') _zsh_highlight_main_highlighter_highlight_backtick $i; (( i = REPLY ));; '$') if [[ $arg[i+1] == "'" ]]; then _zsh_highlight_main_highlighter_highlight_dollar_quote $i @@ -866,7 +867,7 @@ _zsh_highlight_main_highlighter_highlight_single_quote() else style=single-quoted-argument-unclosed fi - highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) + highlights+=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights REPLY=$i } @@ -988,6 +989,21 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() REPLY=$i } +# Highlight backtick subshells +_zsh_highlight_main_highlighter_highlight_backtick() +{ + local arg1=$1 i=$1 q=\` style + while i=$arg[(ib:i+1:)$q]; [[ $arg[i-1] == '\' && $i -lt $(( end_pos - start_pos )) ]]; do done + + if [[ $arg[i] == '`' ]]; then + style=back-quoted-argument + else + style=back-quoted-argument-unclosed + fi + _zsh_highlight_main_add_region_highlight $(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style + 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/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index f8329ea..663ba6d 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -27,8 +27,10 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='echo `echo 42`' +# 42 is in the command position in a nested subshell. +BUFFER='echo `echo \`42\`` `echo 6 times 9' expected_region_highlight=( - "6 14 back-quoted-argument" + "6 18 back-quoted-argument" + "20 34 back-quoted-argument-unclosed" ) From c969a1f26a7ade7f30ae2ca3ffdf52d3beaeb099 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 14:28:08 +0000 Subject: [PATCH 0572/1080] tests: Include the filename in error messages. The new failure mode is: . Running test main Bail out! On './highlighters/main/test-data/glob.zsh': Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank Bail out! On './highlighters/main/test-data/glob.zsh': output on stderr Running test pattern Fixes #478. --- tests/test-highlighting.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 2f4d3c3..11fb66d 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -92,7 +92,7 @@ run_test_internal() { local tests_tempdir="$1"; shift local srcdir="$PWD" - builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! cd failed: $?"; return 1 } + builtin cd -q -- "$tests_tempdir" || { echo >&2 "Bail out! On ${(qq)1}: cd failed: $?"; return 1 } echo "# ${1:t:r}" @@ -104,9 +104,9 @@ run_test_internal() { (( $#skip_test )) && { print -r -- "1..0 # SKIP $skip_test"; return; } # 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; } + [[ -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! 'expected_region_highlight' is not declared or empty."; return 1; } + (( ${#expected_region_highlight} == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared or empty."; return 1; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} @@ -184,7 +184,7 @@ run_test() { local ret=$pipestatus[1] stderr=$pipestatus[2] if (( ! stderr )); then # stdout will become stderr - echo "Bail out! output on stderr"; return 1 + echo "Bail out! On ${(qq)1}: output on stderr"; return 1 else return $ret fi From d39f83509e9374ea16256e471de5df3298f46044 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 13 Jan 2018 14:43:02 +0000 Subject: [PATCH 0573/1080] docs: main: Add missing hyphens. --- docs/highlighters/main.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index cec79fa..02198cb 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -32,16 +32,16 @@ This highlighter defines the following styles: * `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default) * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) -* `single-hyphen-option` - single hyphen options (`-o`) -* `double-hyphen-option` - double hyphen options (`--option`) +* `single-hyphen-option` - single-hyphen options (`-o`) +* `double-hyphen-option` - double-hyphen options (`--option`) * `back-quoted-argument` - backquoted expressions (`` `foo` ``) * `back-quoted-argument-unclosed` - unclosed backquoted expressions (`` `foo ``) -* `single-quoted-argument` - single quoted arguments (`` 'foo' ``) -* `single-quoted-argument-unclosed` - unclosed single quoted arguments (`` 'foo ``) -* `double-quoted-argument` - double quoted arguments (`` "foo" ``) -* `double-quoted-argument-unclosed` - unclosed double quoted arguments (`` "foo ``) -* `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``) -* `dollar-quoted-argument-unclosed` - unclosed dollar quoted arguments (`` $'foo ``) +* `single-quoted-argument` - single-quoted arguments (`` 'foo' ``) +* `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``) +* `double-quoted-argument` - double-quoted arguments (`` "foo" ``) +* `double-quoted-argument-unclosed` - unclosed double-quoted arguments (`` "foo ``) +* `dollar-quoted-argument` - dollar-quoted arguments (`` $'foo' ``) +* `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``) * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``) * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) * `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) From 4724837df059950851f7f5049b556f36677cdc78 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 13 Jan 2018 14:43:37 +0000 Subject: [PATCH 0574/1080] docs: main: Clarify back-quoted-argument, back-double-quoted-argument, back-dollar-quoted-argument, and assign. Fixes #480. --- docs/highlighters/main.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 02198cb..3459e90 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -34,8 +34,8 @@ This highlighter defines the following styles: * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) * `single-hyphen-option` - single-hyphen options (`-o`) * `double-hyphen-option` - double-hyphen options (`--option`) -* `back-quoted-argument` - backquoted expressions (`` `foo` ``) -* `back-quoted-argument-unclosed` - unclosed backquoted expressions (`` `foo ``) +* `back-quoted-argument` - backtick command substitution (`` `foo` ``) +* `back-quoted-argument-unclosed` - unclosed backtick command substitution (`` `foo ``) * `single-quoted-argument` - single-quoted arguments (`` 'foo' ``) * `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``) * `double-quoted-argument` - double-quoted arguments (`` "foo" ``) @@ -44,9 +44,9 @@ This highlighter defines the following styles: * `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``) * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``) * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`) -* `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`) -* `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`) -* `assign` - parameter assignments +* `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`) +* `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`) +* `assign` - parameter assignments (`x=foo` and `x=( )`) * `redirection` - redirection operators (`<`, `>`, etc) * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`) * `arg0` - a command word other than one of those enumrated above (other than a command, precommand, alias, function, or shell builtin command). From f064b17d25ed04f6d5ce7c996dadae51b5fc73bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 13 Jan 2018 15:45:41 +0000 Subject: [PATCH 0575/1080] =?UTF-8?q?'main':=20Add=20an=20explicit=20test?= =?UTF-8?q?=20for=20escaped=20single=20quotes=20within=20single=20quotes,?= =?UTF-8?q?=20=C2=AB'foo'\''bar'=C2=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/test-data/escaped-single-quote.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/escaped-single-quote.zsh diff --git a/highlighters/main/test-data/escaped-single-quote.zsh b/highlighters/main/test-data/escaped-single-quote.zsh new file mode 100644 index 0000000..77a01b4 --- /dev/null +++ b/highlighters/main/test-data/escaped-single-quote.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\'' # <<<: 'foo'\''bar'>>> + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 single-quoted-argument' # 'foo' + '8 9 default' # \' + '10 14 single-quoted-argument' # 'bar' +) From 901063aa0fe768d0766754925a03cbe22a37f56d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 15 Jan 2018 22:31:59 +0000 Subject: [PATCH 0576/1080] =?UTF-8?q?'main':=20Add=20a=20regression=20test?= =?UTF-8?q?=20for=20issue=20#483,=20concerning=20=C2=AB:=20$( Date: Thu, 18 Jan 2018 23:25:42 +0000 Subject: [PATCH 0577/1080] 'main': Don't match redirection operators in command substitutions as <-> number range globs. Fixes #483. --- highlighters/main/main-highlighter.zsh | 15 ++++++++++----- highlighters/main/test-data/number_range-glob.zsh | 10 +++++----- .../main/test-data/redirection-in-cmdsubst.zsh | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6981b0f..dccf63c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -801,6 +801,9 @@ _zsh_highlight_main_highlighter_highlight_argument() local i path_eligible style path_eligible=1 + local -a match mbegin mend + local MATCH; integer MBEGIN MEND + _zsh_highlight_main_add_region_highlight $start_pos $end_pos default for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in @@ -822,14 +825,16 @@ _zsh_highlight_main_highlighter_highlight_argument() elif [[ $arg[i+1] == [*@#?-$!] ]]; then (( i += 1 )) fi;; - [*?]|\<) - # The '<' is for the <-> globbing syntax. (This function doesn't get called on redirection tokens.) - if $highlight_glob; then + *) + if $highlight_glob && [[ ${arg[$i]} == [*?] || ${arg:$i-1} == \<[0-9]#-[0-9]#\>* ]]; then + (( i += $#MATCH - 1 )) _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing path_eligible=0 break - fi;; - *) continue;; + else + continue + fi + ;; esac done diff --git a/highlighters/main/test-data/number_range-glob.zsh b/highlighters/main/test-data/number_range-glob.zsh index f8b51c9..1808492 100644 --- a/highlighters/main/test-data/number_range-glob.zsh +++ b/highlighters/main/test-data/number_range-glob.zsh @@ -28,13 +28,13 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='print <-> x<-> ' +BUFFER='print <-> x<->y ' expected_region_highlight=( '1 5 builtin' # print '7 9 globbing' # <-> - '11 14 globbing' # x<-> - '16 16 redirection' # < - '17 22 default' # foo2-3 (the filename) - '23 23 redirection' # > + '11 15 globbing' # x<-> + '17 17 redirection' # < + '18 23 default' # foo2-3 (the filename) + '24 24 redirection' # > ) diff --git a/highlighters/main/test-data/redirection-in-cmdsubst.zsh b/highlighters/main/test-data/redirection-in-cmdsubst.zsh index ea1155d..ac7a365 100644 --- a/highlighters/main/test-data/redirection-in-cmdsubst.zsh +++ b/highlighters/main/test-data/redirection-in-cmdsubst.zsh @@ -32,5 +32,5 @@ BUFFER=$': $( Date: Thu, 18 Jan 2018 14:52:31 -0600 Subject: [PATCH 0578/1080] main: Explicitly pass $style to _highlight_path_separators --- highlighters/main/main-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index dccf63c..74192b4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -750,8 +750,8 @@ _zsh_highlight_main_highlighter_check_assign() _zsh_highlight_main_highlighter_highlight_path_separators() { local pos style_pathsep - style_pathsep=${style}_pathseparator - [[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$style]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0 + style_pathsep=$1_pathseparator + [[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$1]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0 for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do if [[ $BUFFER[pos] == / ]]; then _zsh_highlight_main_add_region_highlight $((pos - 1)) $pos $style_pathsep @@ -841,7 +841,7 @@ _zsh_highlight_main_highlighter_highlight_argument() if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then style=$REPLY _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - _zsh_highlight_main_highlighter_highlight_path_separators + _zsh_highlight_main_highlighter_highlight_path_separators $style fi } From 6835121eafa49899b396f5f85207fb1fe229bc1c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Jan 2018 14:59:24 -0600 Subject: [PATCH 0579/1080] main: Have helper functions return highlights in reply This allows _highlight_arguments to put things in region_highlight prior to the highlights decided by the helper functions, but decide on what that prior highlight should be after the helpers have run. --- highlighters/main/main-highlighter.zsh | 54 +++++++++++++++++--------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 74192b4..18e3099 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -751,10 +751,11 @@ _zsh_highlight_main_highlighter_highlight_path_separators() { local pos style_pathsep style_pathsep=$1_pathseparator + reply=() [[ -z "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" || "$ZSH_HIGHLIGHT_STYLES[$1]" == "$ZSH_HIGHLIGHT_STYLES[$style_pathsep]" ]] && return 0 for (( pos = start_pos; $pos <= end_pos; pos++ )) ; do if [[ $BUFFER[pos] == / ]]; then - _zsh_highlight_main_add_region_highlight $((pos - 1)) $pos $style_pathsep + reply+=($((pos - 1)) $pos $style_pathsep) fi done } @@ -799,6 +800,7 @@ _zsh_highlight_main_highlighter_check_path() _zsh_highlight_main_highlighter_highlight_argument() { local i path_eligible style + local -a highlights reply path_eligible=1 local -a match mbegin mend @@ -808,13 +810,26 @@ _zsh_highlight_main_highlighter_highlight_argument() for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in "\\") (( i += 1 )); continue;; - "'") _zsh_highlight_main_highlighter_highlight_single_quote $i; (( i = REPLY ));; - '"') _zsh_highlight_main_highlighter_highlight_double_quote $i; (( i = REPLY ));; - '`') _zsh_highlight_main_highlighter_highlight_backtick $i; (( i = REPLY ));; + "'") + _zsh_highlight_main_highlighter_highlight_single_quote $i + (( i = REPLY )) + highlights+=($reply) + ;; + '"') + _zsh_highlight_main_highlighter_highlight_double_quote $i + (( i = REPLY )) + highlights+=($reply) + ;; + '`') + _zsh_highlight_main_highlighter_highlight_backtick $i + (( i = REPLY )) + highlights+=($reply) + ;; '$') if [[ $arg[i+1] == "'" ]]; then _zsh_highlight_main_highlighter_highlight_dollar_quote $i (( i = REPLY )) + highlights+=($reply) elif [[ $arg[i+1] == [\^=~#+] ]]; then while [[ $arg[i+1] == [\^=~#+] ]]; do (( i += 1 )) @@ -841,8 +856,10 @@ _zsh_highlight_main_highlighter_highlight_argument() if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then style=$REPLY _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - _zsh_highlight_main_highlighter_highlight_path_separators $style + highlights+=($reply) fi + + _zsh_highlight_main_add_many_region_highlights $highlights } # Quote Helper Functions @@ -851,17 +868,18 @@ _zsh_highlight_main_highlighter_highlight_argument() # $start_pos is expected to be set to the start of $arg in $BUFFER # $1 is the index in $arg which starts the quote # $REPLY is returned as the end of quote index in $arg +# $reply is returned as an array of region_highlight additions # Highlight single-quoted strings _zsh_highlight_main_highlighter_highlight_single_quote() { local arg1=$1 i q=\' style - local -a highlights i=$arg[(ib:arg1+1:)$q] + reply=() if [[ $zsyh_user_options[rcquotes] == on ]]; then while [[ $arg[i+1] == "'" ]]; do - highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + 1 )) rc-quote) + reply+=($(( start_pos + i - 1 )) $(( start_pos + i + 1 )) rc-quote) (( i++ )) i=$arg[(ib:i+1:)$q] done @@ -872,17 +890,17 @@ _zsh_highlight_main_highlighter_highlight_single_quote() else style=single-quoted-argument-unclosed fi - highlights+=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $highlights) - _zsh_highlight_main_add_many_region_highlights $highlights + reply+=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply) REPLY=$i } # Highlight special chars inside double-quoted strings _zsh_highlight_main_highlighter_highlight_double_quote() { - local -a highlights match mbegin mend + local -a match mbegin mend local MATCH; integer MBEGIN MEND local i j k style + reply=() for (( i = $1 + 1 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) @@ -929,7 +947,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() *) continue ;; esac - highlights+=($j $k $style) + reply+=($j $k $style) done if [[ $arg[i] == '"' ]]; then @@ -937,19 +955,19 @@ _zsh_highlight_main_highlighter_highlight_double_quote() else style=double-quoted-argument-unclosed fi - highlights=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $highlights) - _zsh_highlight_main_add_many_region_highlights $highlights + reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $reply) REPLY=$i } # Highlight special chars inside dollar-quoted strings _zsh_highlight_main_highlighter_highlight_dollar_quote() { - local -a highlights match mbegin mend + local -a match mbegin mend local MATCH; integer MBEGIN MEND local i j k style local AA integer c + reply=() for (( i = $1 + 2 ; i < end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) @@ -981,7 +999,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() *) continue ;; esac - highlights+=($j $k $style) + reply+=($j $k $style) done if [[ $arg[i] == "'" ]]; then @@ -989,8 +1007,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() else style=dollar-quoted-argument-unclosed fi - highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $highlights) - _zsh_highlight_main_add_many_region_highlights $highlights + reply+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply) REPLY=$i } @@ -998,6 +1015,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() _zsh_highlight_main_highlighter_highlight_backtick() { local arg1=$1 i=$1 q=\` style + reply=() while i=$arg[(ib:i+1:)$q]; [[ $arg[i-1] == '\' && $i -lt $(( end_pos - start_pos )) ]]; do done if [[ $arg[i] == '`' ]]; then @@ -1005,7 +1023,7 @@ _zsh_highlight_main_highlighter_highlight_backtick() else style=back-quoted-argument-unclosed fi - _zsh_highlight_main_add_region_highlight $(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style + reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style) REPLY=$i } From c1a048a0846dffaf5e3fe4099370bc5f217b9d8b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Jan 2018 15:01:06 -0600 Subject: [PATCH 0580/1080] main: Only highlight one base_style in _highlight_arguments Closes #481 --- highlighters/main/main-highlighter.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 18e3099..44cfa60 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -799,14 +799,13 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight start_pos to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local i path_eligible style + local base_style=default i path_eligible style local -a highlights reply path_eligible=1 local -a match mbegin mend local MATCH; integer MBEGIN MEND - _zsh_highlight_main_add_region_highlight $start_pos $end_pos default for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in "\\") (( i += 1 )); continue;; @@ -843,7 +842,7 @@ _zsh_highlight_main_highlighter_highlight_argument() *) if $highlight_glob && [[ ${arg[$i]} == [*?] || ${arg:$i-1} == \<[0-9]#-[0-9]#\>* ]]; then (( i += $#MATCH - 1 )) - _zsh_highlight_main_add_region_highlight $start_pos $end_pos globbing + base_style=globbing path_eligible=0 break else @@ -854,11 +853,12 @@ _zsh_highlight_main_highlighter_highlight_argument() done if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then - style=$REPLY - _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + base_style=$REPLY + _zsh_highlight_main_highlighter_highlight_path_separators $base_style highlights+=($reply) fi + highlights=($start_pos $end_pos $base_style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights } From 604075aa90a7c6cccd043cbe99dea0f549ceb16a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Jan 2018 20:08:14 -0600 Subject: [PATCH 0581/1080] main: Use =~ for globbing test This will set MATCH as needed for the next commit --- 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 44cfa60..4b83f60 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -840,7 +840,7 @@ _zsh_highlight_main_highlighter_highlight_argument() (( i += 1 )) fi;; *) - if $highlight_glob && [[ ${arg[$i]} == [*?] || ${arg:$i-1} == \<[0-9]#-[0-9]#\>* ]]; then + if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then (( i += $#MATCH - 1 )) base_style=globbing path_eligible=0 From e48af357532c24e24666441205cda24968bf93c6 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Jan 2018 20:10:25 -0600 Subject: [PATCH 0582/1080] main: Only highlight characters special to globbing as globbing --- highlighters/main/main-highlighter.zsh | 8 ++-- highlighters/main/test-data/glob.zsh | 9 ++-- .../main/test-data/globs-with-quoting.zsh | 42 +++++++++++++++++++ .../main/test-data/number_range-glob.zsh | 4 +- 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 highlighters/main/test-data/globs-with-quoting.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4b83f60..5058bc8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -799,9 +799,8 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight start_pos to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i path_eligible style + local base_style=default i path_eligible=1 style local -a highlights reply - path_eligible=1 local -a match mbegin mend local MATCH; integer MBEGIN MEND @@ -841,10 +840,9 @@ _zsh_highlight_main_highlighter_highlight_argument() fi;; *) if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then - (( i += $#MATCH - 1 )) - base_style=globbing + highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing) + (( i += $#MATCH - 1 )) path_eligible=0 - break else continue fi diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index 2fd9c6f..b8b542b 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -31,8 +31,11 @@ BUFFER=': foo* bar? *baz qux\?' expected_region_highlight=( "1 1 builtin" # : - "3 6 globbing" # foo* - "8 11 globbing" # bar? - "13 16 globbing" # *baz + "3 5 default" # foo + "6 6 globbing" # * + "8 10 default" # bar + "11 11 globbing" # ? + "13 13 globbing" # * + "14 16 default" # baz "18 22 default" # qux\? ) diff --git a/highlighters/main/test-data/globs-with-quoting.zsh b/highlighters/main/test-data/globs-with-quoting.zsh new file mode 100644 index 0000000..b1ef63e --- /dev/null +++ b/highlighters/main/test-data/globs-with-quoting.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 +# ------------------------------------------------------------------------------------------------- + +BUFFER=$': "foo"*\'bar\'?"baz?"<17-29>"qu*ux"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 7 double-quoted-argument' # "foo" + '8 8 globbing' # * + '9 13 single-quoted-argument' # 'bar' + '14 14 globbing' # ? + '15 20 double-quoted-argument' # "baz?" + '21 27 globbing' # <17-29> + '28 34 double-quoted-argument' # "qu*ux" +) diff --git a/highlighters/main/test-data/number_range-glob.zsh b/highlighters/main/test-data/number_range-glob.zsh index 1808492..c13c6b7 100644 --- a/highlighters/main/test-data/number_range-glob.zsh +++ b/highlighters/main/test-data/number_range-glob.zsh @@ -33,7 +33,9 @@ BUFFER='print <-> x<->y ' expected_region_highlight=( '1 5 builtin' # print '7 9 globbing' # <-> - '11 15 globbing' # x<-> + '11 11 default' # x + '12 14 globbing' # <-> + '15 15 default' # y '17 17 redirection' # < '18 23 default' # foo2-3 (the filename) '24 24 redirection' # > From a65a07fae4e916f49b84afd8f6d9b2ef258b52fb Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 19 Jan 2018 08:00:25 -0600 Subject: [PATCH 0583/1080] main: Correct typos --- 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 5058bc8..43a97da 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -888,7 +888,7 @@ _zsh_highlight_main_highlighter_highlight_single_quote() else style=single-quoted-argument-unclosed fi - reply+=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply) + reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply) REPLY=$i } @@ -1005,7 +1005,7 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() else style=dollar-quoted-argument-unclosed fi - reply+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply) + reply=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply) REPLY=$i } From 6d133a0eb0c2abaa4a97c584c100f460a405b273 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 14 Jan 2018 21:24:44 -0600 Subject: [PATCH 0584/1080] main: Highlight options as base_style This means --foo="bar" will have quotes highlighted. --- highlighters/main/main-highlighter.zsh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 43a97da..b132c2a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -680,8 +680,6 @@ _zsh_highlight_highlighter_main_paint() # Fall through to the catchall case at the end. fi ;| - '--'*) style=double-hyphen-option;; - '-'*) style=single-hyphen-option;; *) if false; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then # was handled by the $'\x7d' case above @@ -805,6 +803,15 @@ _zsh_highlight_main_highlighter_highlight_argument() local -a match mbegin mend local MATCH; integer MBEGIN MEND + if [[ $arg[1] == - ]]; then + if [[ $arg[2] == - ]]; then + base_style=double-hyphen-option + else + base_style=single-hyphen-option + fi + path_eligible=0 + fi + for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in "\\") (( i += 1 )); continue;; From 18e214ee5b0ff53e443d6257eddfa42af1cf9bd8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 18 Jan 2018 21:55:05 -0600 Subject: [PATCH 0585/1080] main: Add test for quotes in options --- .../main/test-data/option-with-quotes.zsh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 highlighters/main/test-data/option-with-quotes.zsh diff --git a/highlighters/main/test-data/option-with-quotes.zsh b/highlighters/main/test-data/option-with-quotes.zsh new file mode 100644 index 0000000..b87fb77 --- /dev/null +++ b/highlighters/main/test-data/option-with-quotes.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=$': --user="phy1729"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 9 double-hyphen-option' # --user= + '10 18 double-quoted-argument' # "phy1729" +) From 8d2955f51a6e396210a61ee6753a4a99904d03ce Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 14 Jan 2018 21:27:07 -0600 Subject: [PATCH 0586/1080] main: Consolidate } handling No functional change. --- highlighters/main/main-highlighter.zsh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b132c2a..6796a39 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -665,24 +665,16 @@ _zsh_highlight_highlighter_main_paint() fi style=reserved-word ;; - $'\x7d') # right brace - # - # 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 $right_brace_is_recognised_everywhere; then + *) 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. _zsh_highlight_main__stack_pop 'Y' style=reserved-word if [[ $style == reserved-word ]]; then next_word+=':always:' fi - else - # Fall through to the catchall case at the end. - fi - ;| - *) if false; then - elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then - # was handled by the $'\x7d' case above elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then From f16e858f0c839c5170a6647d6e4aadd00bdc24f1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 14 Jan 2018 21:28:42 -0600 Subject: [PATCH 0587/1080] main: Highlight backticks in double quotes --- highlighters/main/main-highlighter.zsh | 8 +++++++- highlighters/main/test-data/back-quoted-argument.zsh | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6796a39..b8ed1a5 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -894,7 +894,7 @@ _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 + local -a match mbegin mend saved_reply local MATCH; integer MBEGIN MEND local i j k style reply=() @@ -904,6 +904,12 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( 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 # Look for an alphanumeric parameter name. if [[ ${arg:$i} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+) ]] ; then diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index 663ba6d..9355b28 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -28,9 +28,12 @@ # ------------------------------------------------------------------------------------------------- # 42 is in the command position in a nested subshell. -BUFFER='echo `echo \`42\`` `echo 6 times 9' +BUFFER='echo `echo \`42\`` "is `echo equal` to" `echo 6 times 9' expected_region_highlight=( - "6 18 back-quoted-argument" - "20 34 back-quoted-argument-unclosed" + "6 18 back-quoted-argument" # `echo \`42\`` + "20 23 double-quoted-argument" # "is + "24 35 back-quoted-argument" # `echo equal` + "36 39 double-quoted-argument" # to" + "41 55 back-quoted-argument-unclosed" # `echo 6 times 9 ) From 8046c33b540436286e47e23e828c982ab567097b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 20 Jan 2018 00:36:16 +0000 Subject: [PATCH 0588/1080] 'main': Do not expand special parameters. Fixes #489. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding «(e)» to the first subscript is a no-op: the subscript is known to be safe due to the previous line. --- 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 b8ed1a5..5e03d1a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -493,7 +493,7 @@ _zsh_highlight_highlighter_main_paint() local MATCH; integer MBEGIN MEND if [[ $res == none ]] && (( ${+parameters} )) && [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && - (( ${+parameters[${MATCH}]} )) + (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then _zsh_highlight_main__type ${(P)MATCH} res=$REPLY From 382be9096dfbb3b00ea92f3d61c68667a7a026ef Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Jan 2018 20:30:13 -0600 Subject: [PATCH 0589/1080] main: Add XFAIL to redirections2 for process-substitution #494 --- highlighters/main/test-data/redirection2.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/main/test-data/redirection2.zsh b/highlighters/main/test-data/redirection2.zsh index 83f7c08..1a1588d 100644 --- a/highlighters/main/test-data/redirection2.zsh +++ b/highlighters/main/test-data/redirection2.zsh @@ -31,6 +31,7 @@ BUFFER='ls >(wc) | nl' expected_region_highlight=( "1 2 command" # ls + "4 8 process-substitution 'issue #494'" # >(wc) "10 10 commandseparator" # | "12 13 command" # nl ) From 03692831ad465b79447e56bc20e2294558944479 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 20 Jan 2018 15:40:11 +0000 Subject: [PATCH 0590/1080] 'main': Don't highlight bare '$foo' as a filename, as it's a parameter expansion. Fixes #474. --- highlighters/main/main-highlighter.zsh | 2 ++ highlighters/main/test-data/order-path-after-dollar.zsh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5e03d1a..a08da66 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -823,7 +823,9 @@ _zsh_highlight_main_highlighter_highlight_argument() highlights+=($reply) ;; '$') + path_eligible=0 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/order-path-after-dollar.zsh b/highlighters/main/test-data/order-path-after-dollar.zsh index c260c53..773c183 100644 --- a/highlighters/main/test-data/order-path-after-dollar.zsh +++ b/highlighters/main/test-data/order-path-after-dollar.zsh @@ -33,6 +33,6 @@ BUFFER=': $foo \$foo' expected_region_highlight=( '1 1 builtin' # : - '3 6 default "issue #474"' # $foo - if we add a "unquoted parameter expansion" style then this expectation should change + '3 6 default' # $foo - if we add a "unquoted parameter expansion" style then this expectation should change '8 12 path' # \$foo ) From 1f1e629290773bd6f9673f364303219d6da11129 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Jan 2018 21:41:49 -0600 Subject: [PATCH 0591/1080] regexp: Add missing local for arrays match mbegin mend See #497. --- highlighters/regexp/regexp-highlighter.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/highlighters/regexp/regexp-highlighter.zsh b/highlighters/regexp/regexp-highlighter.zsh index 0edc461..26f9da3 100644 --- a/highlighters/regexp/regexp-highlighter.zsh +++ b/highlighters/regexp/regexp-highlighter.zsh @@ -52,6 +52,7 @@ _zsh_highlight_regexp_highlighter_loop() local buf="$1" pat="$2" integer OFFSET=0 local MATCH; integer MBEGIN MEND + local -a match mbegin mend while true; do [[ "$buf" =~ "$pat" ]] || return; region_highlight+=("$((MBEGIN - 1 + OFFSET)) $((MEND + OFFSET)) $ZSH_HIGHLIGHT_REGEXP[$pat]") From 7b417be1ce29c549052e989ef2b628a0de0d0a79 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Feb 2018 13:23:08 -0600 Subject: [PATCH 0592/1080] tests: Escape newlines in TAP description --- 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 11fb66d..9c6b145 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -141,8 +141,8 @@ run_test_internal() { local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} ) local todo= integer start=$highlight_zone[1] end=$highlight_zone[2] - # Escape # as ♯ since the former is illegal in the 'description' part of TAP output - local desc="[$start,$end] «${BUFFER[$start,$end]//'#'/♯}»" + # Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output + local desc="[$start,$end] «${${BUFFER[$start,$end]//'#'/♯}//$'\n'/↵}»" (( $+highlight_zone[4] )) && todo="# TODO $highlight_zone[4]" for j in {$start..$end}; do if From cc662371b18d2bac2300a5d5e85075b6d1b8da3e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Feb 2018 13:23:42 -0600 Subject: [PATCH 0593/1080] main: Update test for issue #501 XFAIL --- highlighters/main/test-data/comment-followed.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/highlighters/main/test-data/comment-followed.zsh b/highlighters/main/test-data/comment-followed.zsh index af4e9b5..8c7e42c 100644 --- a/highlighters/main/test-data/comment-followed.zsh +++ b/highlighters/main/test-data/comment-followed.zsh @@ -32,8 +32,7 @@ setopt interactivecomments BUFFER=$'# foo\ntrue' expected_region_highlight=( - '1 5 comment' # # - #'6 6 '"' # \n - + '1 5 comment' # # foo + '6 6 commandseparator "issue #501"' # \n '7 10 builtin' # true ) From 84f0507cf6b6dbf34aeb6872eb648a09a7f44ade Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 18:47:36 -0600 Subject: [PATCH 0594/1080] driver: Replace eval with ${(P) --- 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 d100edb..f933f70 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -141,7 +141,7 @@ _zsh_highlight() { "_zsh_highlight_highlighter_${highlighter}_paint" } always { - eval "${cache_place}=(\"\${region_highlight[@]}\")" + : ${(AP)cache_place::="${region_highlight[@]}"} } # Restore saved region_highlight @@ -150,7 +150,7 @@ _zsh_highlight() fi # Use value form cache if any cached - eval "region_highlight+=(\"\${${cache_place}[@]}\")" + region_highlight+=("${(@P)cache_place}") done From ff85c7e01b0a7e5d9f92fc0195685edbea2b8dbc Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 18:48:46 -0600 Subject: [PATCH 0595/1080] driver: Do not highlight newlines or past BUFFER for zle standout --- zsh-syntax-highlighting.zsh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f933f70..eee0284 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -168,8 +168,10 @@ _zsh_highlight() else min=$MARK max=$CURSOR fi - (( min = ${${BUFFER[1,$min]}[(I)$needle]} )) - (( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 )) + # 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 From e13074528fab7720980a23ce862327fb97c105e3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 18:52:30 -0600 Subject: [PATCH 0596/1080] main: Do not highlight for regions that end before the start of BUFFER --- 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 a08da66..2a46b7a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -104,7 +104,8 @@ _zsh_highlight_main_add_region_highlight() { (( start -= $#PREBUFFER )) (( end -= $#PREBUFFER )) - (( end < 0 )) && return # having end<0 would be a bug + (( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return } + (( end <= 0 )) && return (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings _zsh_highlight_add_highlight $start $end "$@" } From fdca2ef714a190a7044d904e7311e5f792b184c8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 18:54:48 -0600 Subject: [PATCH 0597/1080] main: Fix off by one errors in quote helper functions --- highlighters/main/main-highlighter.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2a46b7a..26fcb4b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -888,6 +888,8 @@ _zsh_highlight_main_highlighter_highlight_single_quote() if [[ $arg[i] == "'" ]]; then style=single-quoted-argument else + # If unclosed, i points past the end + (( i-- )) style=single-quoted-argument-unclosed fi reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $reply) @@ -902,7 +904,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() local i j k style reply=() - for (( i = $1 + 1 ; i < end_pos - start_pos ; i += 1 )) ; do + for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in @@ -959,6 +961,8 @@ _zsh_highlight_main_highlighter_highlight_double_quote() if [[ $arg[i] == '"' ]]; then style=double-quoted-argument else + # If unclosed, i points past the end + (( i-- )) style=double-quoted-argument-unclosed fi reply=($(( start_pos + $1 - 1)) $(( start_pos + i )) $style $reply) @@ -975,7 +979,7 @@ _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 <= end_pos - start_pos ; i += 1 )) ; do (( j = i + start_pos - 1 )) (( k = j + 1 )) case "$arg[$i]" in @@ -1011,6 +1015,8 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() if [[ $arg[i] == "'" ]]; then style=dollar-quoted-argument else + # If unclosed, i points past the end + (( i-- )) style=dollar-quoted-argument-unclosed fi reply=($(( start_pos + $1 - 1 )) $(( start_pos + i )) $style $reply) @@ -1027,6 +1033,8 @@ _zsh_highlight_main_highlighter_highlight_backtick() if [[ $arg[i] == '`' ]]; then style=back-quoted-argument else + # If unclosed, i points past the end + (( i-- )) style=back-quoted-argument-unclosed fi reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style) From 622358f32d4395e58859f7fa38bad84509eb3e32 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 19:12:08 -0600 Subject: [PATCH 0598/1080] main: Test suffix aliases if zsh/parameter is available --- highlighters/main/test-data/alias.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 2977343..5ec2a2d 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -43,7 +43,7 @@ BUFFER='x.alias2; alias1' # functionality is present, and skip verifying suffix-alias highlighting # if it isn't. expected_region_highlight=() -if [[ "$(type -w x.alias2)" == *suffix* ]]; then +if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then expected_region_highlight+=( "1 8 suffix-alias" # x.alias2 ) From a9be0975c80332a8297780570b9b6b7f02d3f17c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Feb 2018 19:14:26 -0600 Subject: [PATCH 0599/1080] tests: Directly diff expected_region_highlight against region_highlight --- .../cursor-matchingbracket-line-finish.zsh | 1 - .../test-data/cursor-matchingbracket.zsh | 8 ++ .../brackets/test-data/empty-styles.zsh | 1 - .../brackets/test-data/loop-styles.zsh | 2 + .../test-data/mismatch-patentheses.zsh | 2 + .../brackets/test-data/near-quotes.zsh | 5 +- .../brackets/test-data/nested-parentheses.zsh | 2 + .../brackets/test-data/only-error.zsh | 1 - .../brackets/test-data/quoted-patentheses.zsh | 2 - .../brackets/test-data/simple-parentheses.zsh | 2 + .../test-data/unclosed-patentheses.zsh | 2 + .../test-data/unclosed-patentheses2.zsh | 2 + .../main/test-data/alias-assignment1.zsh | 1 + highlighters/main/test-data/alias.zsh | 1 + .../main/test-data/anonymous-function.zsh | 3 + highlighters/main/test-data/assign-append.zsh | 3 + highlighters/main/test-data/assign-array.zsh | 2 + highlighters/main/test-data/assign-array2.zsh | 2 + highlighters/main/test-data/assign-array3.zsh | 2 + .../main/test-data/assign-semicolon.zsh | 3 + highlighters/main/test-data/assign.zsh | 1 + .../main/test-data/back-quoted-argument.zsh | 7 +- .../main/test-data/brackets-mismatch7.zsh | 1 + .../main/test-data/commandseparator.zsh | 1 + .../main/test-data/comment-leading.zsh | 3 +- highlighters/main/test-data/comments.zsh | 1 + .../main/test-data/commmand-parameter.zsh | 1 + highlighters/main/test-data/control-flow.zsh | 7 ++ highlighters/main/test-data/dollar-dollar.zsh | 4 +- highlighters/main/test-data/dollar-noise.zsh | 8 +- highlighters/main/test-data/dollar-paren.zsh | 4 +- highlighters/main/test-data/dollar-quoted.zsh | 3 + .../main/test-data/dollar-quoted2.zsh | 7 +- .../main/test-data/dollar-quoted3.zsh | 4 +- .../main/test-data/double-hyphen-option.zsh | 1 + highlighters/main/test-data/double-quoted.zsh | 9 +-- .../main/test-data/double-quoted2.zsh | 4 +- .../main/test-data/double-quoted3.zsh | 7 +- .../main/test-data/double-quoted4.zsh | 5 +- highlighters/main/test-data/empty-command.zsh | 1 + .../main/test-data/empty-command2.zsh | 1 + .../main/test-data/escaped-single-quote.zsh | 2 +- highlighters/main/test-data/function.zsh | 1 + highlighters/main/test-data/glob.zsh | 6 +- .../main/test-data/globs-with-quoting.zsh | 1 + .../history-double-quoted-escaped.zsh | 4 +- .../test-data/history-double-quoted-no.zsh | 1 + .../history-double-quoted-unescaped.zsh | 4 +- .../test-data/history-double-quoted-yes.zsh | 4 +- .../main/test-data/history-expansion.zsh | 5 +- .../main/test-data/multiline-string.zsh | 1 + .../main/test-data/multiline-string2.zsh | 4 +- .../main/test-data/multiple-quotes.zsh | 13 +-- highlighters/main/test-data/noglob-alias.zsh | 1 + highlighters/main/test-data/noglob1.zsh | 4 + highlighters/main/test-data/noglob2.zsh | 5 ++ highlighters/main/test-data/noglob3.zsh | 2 + .../main/test-data/number_range-glob.zsh | 4 +- .../main/test-data/option-with-quotes.zsh | 2 +- .../test-data/order-path-before-globbing.zsh | 1 + .../main/test-data/parameter-star.zsh | 4 + .../main/test-data/path-broken-symlink.zsh | 1 + .../main/test-data/path-dollared-word2.zsh | 3 +- .../main/test-data/path-dollared-word3.zsh | 1 + .../main/test-data/path-separators.zsh | 10 +-- .../main/test-data/path-separators2.zsh | 1 + highlighters/main/test-data/path-space.zsh | 2 +- highlighters/main/test-data/path_prefix.zsh | 3 +- highlighters/main/test-data/path_prefix2.zsh | 3 +- .../main/test-data/prefix-redirection.zsh | 3 + highlighters/main/test-data/rc-quotes.zsh | 6 +- highlighters/main/test-data/redirection.zsh | 3 + highlighters/main/test-data/reserved-word.zsh | 1 + highlighters/main/test-data/subshell.zsh | 10 +++ highlighters/main/test-data/sudo-command.zsh | 5 ++ .../main/test-data/vi-linewise-mode.zsh | 7 +- tests/README.md | 5 +- tests/test-highlighting.zsh | 80 +++++++++---------- 78 files changed, 219 insertions(+), 121 deletions(-) diff --git a/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh b/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh index 23b317b..b2acd31 100644 --- a/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh +++ b/highlighters/brackets/test-data/cursor-matchingbracket-line-finish.zsh @@ -33,5 +33,4 @@ BUFFER=': $foo[bar]' CURSOR=6 # cursor is zero-based expected_region_highlight=( - "11 11 NONE" ) diff --git a/highlighters/brackets/test-data/cursor-matchingbracket.zsh b/highlighters/brackets/test-data/cursor-matchingbracket.zsh index 5e9cf62..e05b4e9 100644 --- a/highlighters/brackets/test-data/cursor-matchingbracket.zsh +++ b/highlighters/brackets/test-data/cursor-matchingbracket.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= ZSH_HIGHLIGHT_STYLES[bracket-level-3]= @@ -35,5 +37,11 @@ BUFFER=': ((( )))' CURSOR=2 # cursor is zero-based expected_region_highlight=( + "3 3 bracket-level-1" + "4 4 bracket-level-2" + "5 5 bracket-level-3" + "7 7 bracket-level-3" + "8 8 bracket-level-2" + "9 9 bracket-level-1" "9 9 cursor-matchingbracket" ) diff --git a/highlighters/brackets/test-data/empty-styles.zsh b/highlighters/brackets/test-data/empty-styles.zsh index 2de1b20..e60657b 100644 --- a/highlighters/brackets/test-data/empty-styles.zsh +++ b/highlighters/brackets/test-data/empty-styles.zsh @@ -30,5 +30,4 @@ BUFFER=': (x)' expected_region_highlight=( - "1 5 NONE" ) diff --git a/highlighters/brackets/test-data/loop-styles.zsh b/highlighters/brackets/test-data/loop-styles.zsh index a5be21d..e5cfcdf 100644 --- a/highlighters/brackets/test-data/loop-styles.zsh +++ b/highlighters/brackets/test-data/loop-styles.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= ZSH_HIGHLIGHT_STYLES[bracket-level-3]= diff --git a/highlighters/brackets/test-data/mismatch-patentheses.zsh b/highlighters/brackets/test-data/mismatch-patentheses.zsh index f40226f..5cc588f 100644 --- a/highlighters/brackets/test-data/mismatch-patentheses.zsh +++ b/highlighters/brackets/test-data/mismatch-patentheses.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= diff --git a/highlighters/brackets/test-data/near-quotes.zsh b/highlighters/brackets/test-data/near-quotes.zsh index d3965d2..49f002b 100644 --- a/highlighters/brackets/test-data/near-quotes.zsh +++ b/highlighters/brackets/test-data/near-quotes.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= @@ -34,10 +36,7 @@ BUFFER=': {"{x}"}' expected_region_highlight=( "3 3 bracket-level-1" - "4 4 NONE" "5 5 bracket-level-2" - "6 6 NONE" "7 7 bracket-level-2" - "8 8 NONE" "9 9 bracket-level-1" ) diff --git a/highlighters/brackets/test-data/nested-parentheses.zsh b/highlighters/brackets/test-data/nested-parentheses.zsh index 413394f..21a20fb 100644 --- a/highlighters/brackets/test-data/nested-parentheses.zsh +++ b/highlighters/brackets/test-data/nested-parentheses.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= ZSH_HIGHLIGHT_STYLES[bracket-level-3]= diff --git a/highlighters/brackets/test-data/only-error.zsh b/highlighters/brackets/test-data/only-error.zsh index 1c3a159..00fe557 100644 --- a/highlighters/brackets/test-data/only-error.zsh +++ b/highlighters/brackets/test-data/only-error.zsh @@ -30,6 +30,5 @@ BUFFER=': x)' expected_region_highlight=( - "1 3 NONE" "4 4 bracket-error" # ) ) diff --git a/highlighters/brackets/test-data/quoted-patentheses.zsh b/highlighters/brackets/test-data/quoted-patentheses.zsh index 8d1e26d..81ee04f 100644 --- a/highlighters/brackets/test-data/quoted-patentheses.zsh +++ b/highlighters/brackets/test-data/quoted-patentheses.zsh @@ -30,7 +30,5 @@ BUFFER='echo "foo ( bar"' expected_region_highlight=( -"1 10 NONE" "11 11 bracket-error" -"12 16 NONE" ) diff --git a/highlighters/brackets/test-data/simple-parentheses.zsh b/highlighters/brackets/test-data/simple-parentheses.zsh index 186d0b9..2ccfbab 100644 --- a/highlighters/brackets/test-data/simple-parentheses.zsh +++ b/highlighters/brackets/test-data/simple-parentheses.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= diff --git a/highlighters/brackets/test-data/unclosed-patentheses.zsh b/highlighters/brackets/test-data/unclosed-patentheses.zsh index 941d092..d3f6560 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= ZSH_HIGHLIGHT_STYLES[bracket-level-2]= diff --git a/highlighters/brackets/test-data/unclosed-patentheses2.zsh b/highlighters/brackets/test-data/unclosed-patentheses2.zsh index 41b6836..2c489c3 100644 --- a/highlighters/brackets/test-data/unclosed-patentheses2.zsh +++ b/highlighters/brackets/test-data/unclosed-patentheses2.zsh @@ -27,6 +27,8 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +unsorted=1 + ZSH_HIGHLIGHT_STYLES[bracket-level-1]= BUFFER='echo {x})' diff --git a/highlighters/main/test-data/alias-assignment1.zsh b/highlighters/main/test-data/alias-assignment1.zsh index cf5be75..0c101c8 100644 --- a/highlighters/main/test-data/alias-assignment1.zsh +++ b/highlighters/main/test-data/alias-assignment1.zsh @@ -34,4 +34,5 @@ BUFFER='x=y ls' expected_region_highlight=( "1 3 unknown-token" # x=y + "5 6 default" # ls ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 5ec2a2d..fd867bf 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -49,5 +49,6 @@ if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then ) fi expected_region_highlight+=( + "9 9 commandseparator" # ; "11 16 alias" # alias1 ) diff --git a/highlighters/main/test-data/anonymous-function.zsh b/highlighters/main/test-data/anonymous-function.zsh index 5b8e0b6..9d67fb1 100644 --- a/highlighters/main/test-data/anonymous-function.zsh +++ b/highlighters/main/test-data/anonymous-function.zsh @@ -37,5 +37,8 @@ expected_region_highlight=( "16 17 reserved-word" # () "19 19 reserved-word" # { "21 24 builtin" # echo + "26 30 default" # world + "32 32 reserved-word" # } + "34 43 default" # "argument" "34 43 double-quoted-argument" # "argument" ) diff --git a/highlighters/main/test-data/assign-append.zsh b/highlighters/main/test-data/assign-append.zsh index 6485f0e..eb9fbbd 100644 --- a/highlighters/main/test-data/assign-append.zsh +++ b/highlighters/main/test-data/assign-append.zsh @@ -31,4 +31,7 @@ BUFFER='a+=(lorem ipsum)' expected_region_highlight=( "1 4 assign" # a+=( + "5 9 default" # lorem + "11 15 default" # ipsum + "16 16 assign" # ) ) diff --git a/highlighters/main/test-data/assign-array.zsh b/highlighters/main/test-data/assign-array.zsh index 8995162..0624f9b 100644 --- a/highlighters/main/test-data/assign-array.zsh +++ b/highlighters/main/test-data/assign-array.zsh @@ -32,6 +32,8 @@ BUFFER='(A=(hello world))' expected_region_highlight=( "1 1 reserved-word" # ( "2 4 assign" # A=( + "5 9 default" # hello + "11 15 default" # world "16 16 assign" # ) "17 17 reserved-word" # ) ) diff --git a/highlighters/main/test-data/assign-array2.zsh b/highlighters/main/test-data/assign-array2.zsh index 37ba372..cdc9e63 100644 --- a/highlighters/main/test-data/assign-array2.zsh +++ b/highlighters/main/test-data/assign-array2.zsh @@ -31,6 +31,8 @@ BUFFER='A=(hello world) ls' expected_region_highlight=( "1 3 assign" # A=( + "4 8 default" # hello + "10 14 default" # world "15 15 assign" # ) "17 18 command" # ls ) diff --git a/highlighters/main/test-data/assign-array3.zsh b/highlighters/main/test-data/assign-array3.zsh index 26c42e9..4e20cfc 100644 --- a/highlighters/main/test-data/assign-array3.zsh +++ b/highlighters/main/test-data/assign-array3.zsh @@ -31,6 +31,8 @@ BUFFER='A=(hello world) b=42' expected_region_highlight=( "1 3 assign" # A=( + "4 8 default" # hello + "10 14 default" # world "15 15 assign" # ) "17 20 assign" # b=42 ) diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index c2618b0..fe55b6a 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -30,6 +30,9 @@ BUFFER='A=1; echo hello world' expected_region_highlight=( + "1 3 assign" # A=1 "4 4 commandseparator" # ; "6 9 builtin" # echo + "11 15 default" # hello + "17 21 default" # world ) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 713a5f2..36fa5d1 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -32,6 +32,7 @@ BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( "1 3 assign" # A=1 "5 7 assign" # b=( + "8 12 default" # "foo" "8 12 double-quoted-argument" # "foo" "14 16 default" # bar "17 17 assign" # ) diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index 9355b28..346d9fa 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -31,9 +31,12 @@ BUFFER='echo `echo \`42\`` "is `echo equal` to" `echo 6 times 9' expected_region_highlight=( + "1 4 builtin" # echo + "6 18 default" # `echo \`42\`` "6 18 back-quoted-argument" # `echo \`42\`` - "20 23 double-quoted-argument" # "is + "20 39 default" # "is `echo equal` to" + "20 39 double-quoted-argument" # "is `echo equal` to" "24 35 back-quoted-argument" # `echo equal` - "36 39 double-quoted-argument" # to" + "41 55 default" # `echo 6 times 9 "41 55 back-quoted-argument-unclosed" # `echo 6 times 9 ) diff --git a/highlighters/main/test-data/brackets-mismatch7.zsh b/highlighters/main/test-data/brackets-mismatch7.zsh index 27d5920..1caa936 100644 --- a/highlighters/main/test-data/brackets-mismatch7.zsh +++ b/highlighters/main/test-data/brackets-mismatch7.zsh @@ -34,6 +34,7 @@ expected_region_highlight=( '1 3 reserved-word' # for '5 5 default' # n '7 8 default' # in + '10 10 default' # * '10 10 globbing' # * '11 11 commandseparator' # ; '13 14 reserved-word' # do diff --git a/highlighters/main/test-data/commandseparator.zsh b/highlighters/main/test-data/commandseparator.zsh index e8d93a6..f504847 100644 --- a/highlighters/main/test-data/commandseparator.zsh +++ b/highlighters/main/test-data/commandseparator.zsh @@ -30,6 +30,7 @@ BUFFER=':; pwd &! ls' expected_region_highlight=( + "1 1 builtin" # : "2 2 commandseparator" # ; "4 6 builtin" # pwd "8 9 commandseparator" # &! diff --git a/highlighters/main/test-data/comment-leading.zsh b/highlighters/main/test-data/comment-leading.zsh index f750cc4..b4c9910 100644 --- a/highlighters/main/test-data/comment-leading.zsh +++ b/highlighters/main/test-data/comment-leading.zsh @@ -32,6 +32,5 @@ setopt interactive_comments BUFFER='# echo foo' expected_region_highlight=( - "1 1 comment" # # - "2 10 comment" # " echo foo" + "1 10 comment" # # echo foo ) diff --git a/highlighters/main/test-data/comments.zsh b/highlighters/main/test-data/comments.zsh index 3bb008e..f3cc57e 100644 --- a/highlighters/main/test-data/comments.zsh +++ b/highlighters/main/test-data/comments.zsh @@ -33,6 +33,7 @@ BUFFER='echo "foo #bar" #baz # quux' expected_region_highlight=( "1 4 builtin" # echo + "6 15 default" # "foo #bar" "6 15 double-quoted-argument" # "foo #bar" "17 27 comment" # #baz # quux ) diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index 355f890..07dfc4c 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -32,5 +32,6 @@ BUFFER='$x "argument"' expected_region_highlight=( "1 2 command" # $x + "4 13 default" # "argument" "4 13 double-quoted-argument" # "argument" ) diff --git a/highlighters/main/test-data/control-flow.zsh b/highlighters/main/test-data/control-flow.zsh index 2f6a160..a610bdc 100644 --- a/highlighters/main/test-data/control-flow.zsh +++ b/highlighters/main/test-data/control-flow.zsh @@ -34,17 +34,24 @@ expected_region_highlight+=( "7 8 reserved-word" # if "10 13 builtin" # echo "15 19 default" # Hello + "20 20 commandseparator" # ; "22 25 reserved-word" # then "27 28 command" # ls "30 30 path" # / "31 31 commandseparator" # ; "33 36 reserved-word" # else "38 39 command" # ls + "40 40 commandseparator" # ; "42 43 reserved-word" # fi + "44 44 commandseparator" # ; "46 47 reserved-word" # do "49 52 command" # stat + "54 56 default" # "x" "54 56 double-quoted-argument" # "x" + "57 57 commandseparator" # ; "59 62 reserved-word" # done + "63 63 commandseparator" # ; "65 70 reserved-word" # repeat + "72 73 default" # 10 "75 76 command" # ls ) diff --git a/highlighters/main/test-data/dollar-dollar.zsh b/highlighters/main/test-data/dollar-dollar.zsh index 79d7f7d..e3f387c 100644 --- a/highlighters/main/test-data/dollar-dollar.zsh +++ b/highlighters/main/test-data/dollar-dollar.zsh @@ -32,8 +32,8 @@ BUFFER=': "$$ $$foo"' expected_region_highlight=( '1 1 builtin' # : - '3 3 double-quoted-argument' # " + '3 12 default' # "$$ $$foo" + '3 12 double-quoted-argument' # "$$ $$foo" '4 5 dollar-double-quoted-argument' # $$ '7 8 dollar-double-quoted-argument' # $$ - '9 12 double-quoted-argument' # foo" ) diff --git a/highlighters/main/test-data/dollar-noise.zsh b/highlighters/main/test-data/dollar-noise.zsh index e900b02..9bb11bd 100644 --- a/highlighters/main/test-data/dollar-noise.zsh +++ b/highlighters/main/test-data/dollar-noise.zsh @@ -32,15 +32,11 @@ BUFFER=': "$- $# $* $@ $?"' expected_region_highlight=( '1 1 builtin' # : - '3 3 double-quoted-argument' # " + '3 18 default' # "$- $# $* $@ $?" + '3 18 double-quoted-argument' # "$- $# $* $@ $?" '4 5 dollar-double-quoted-argument' # $- - '6 6 double-quoted-argument' # '7 8 dollar-double-quoted-argument' # $# - '9 9 double-quoted-argument' # '10 11 dollar-double-quoted-argument' # $* - '12 12 double-quoted-argument' # '13 14 dollar-double-quoted-argument' # $@ - '15 15 double-quoted-argument' # '16 17 dollar-double-quoted-argument' # $? - '18 18 double-quoted-argument' # " ) diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index 354daa0..2a1aecd 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -32,7 +32,7 @@ BUFFER=': "$(:)"' expected_region_highlight=( '1 1 builtin' # : - '3 3 double-quoted-argument' # " + '3 8 default' # "$(:)" + '3 8 double-quoted-argument' # "$(:)" '4 4 dollar-double-quoted-argument' # $ - '5 8 double-quoted-argument' # (:)" ) diff --git a/highlighters/main/test-data/dollar-quoted.zsh b/highlighters/main/test-data/dollar-quoted.zsh index 8c4c16f..081a365 100644 --- a/highlighters/main/test-data/dollar-quoted.zsh +++ b/highlighters/main/test-data/dollar-quoted.zsh @@ -30,6 +30,9 @@ BUFFER=": \$'*' 'foo'" expected_region_highlight=( + "1 1 builtin" # : + "3 6 default" # $'*' "3 6 dollar-quoted-argument" # $'*' - not a glob + "8 12 default" # 'foo' "8 12 single-quoted-argument" # 'foo' ) diff --git a/highlighters/main/test-data/dollar-quoted2.zsh b/highlighters/main/test-data/dollar-quoted2.zsh index a69373f..ed7428b 100644 --- a/highlighters/main/test-data/dollar-quoted2.zsh +++ b/highlighters/main/test-data/dollar-quoted2.zsh @@ -30,11 +30,10 @@ BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'" expected_region_highlight=( - "3 7 dollar-quoted-argument" # $'foo + "1 1 builtin" # : + "3 29 default" # $'foo\xbar\udeadbeef\uzzzz' + "3 29 dollar-quoted-argument" # $'foo\xbar\udeadbeef\uzzzz' "8 11 back-dollar-quoted-argument" # \xba - "12 12 dollar-quoted-argument" # r "13 18 back-dollar-quoted-argument" # \dead - "19 22 dollar-quoted-argument" # beef "23 24 unknown-token" # \u - "25 29 dollar-quoted-argument" # zzzz' ) diff --git a/highlighters/main/test-data/dollar-quoted3.zsh b/highlighters/main/test-data/dollar-quoted3.zsh index 2872f7f..365f351 100644 --- a/highlighters/main/test-data/dollar-quoted3.zsh +++ b/highlighters/main/test-data/dollar-quoted3.zsh @@ -32,6 +32,8 @@ BUFFER=": \$'\xa1" expected_region_highlight=( - "3 4 dollar-quoted-argument-unclosed" # $' + "1 1 builtin" # : + "3 8 default" # $'\xa1 + "3 8 dollar-quoted-argument-unclosed" # $'\xa1 "5 8 back-dollar-quoted-argument" # \xa1 ) diff --git a/highlighters/main/test-data/double-hyphen-option.zsh b/highlighters/main/test-data/double-hyphen-option.zsh index 9728cd8..e5cacd3 100644 --- a/highlighters/main/test-data/double-hyphen-option.zsh +++ b/highlighters/main/test-data/double-hyphen-option.zsh @@ -30,5 +30,6 @@ BUFFER='hello --world' expected_region_highlight=( + "1 5 unknown-token" # hello "7 13 double-hyphen-option" # --world ) diff --git a/highlighters/main/test-data/double-quoted.zsh b/highlighters/main/test-data/double-quoted.zsh index 7e379f8..0a4336c 100644 --- a/highlighters/main/test-data/double-quoted.zsh +++ b/highlighters/main/test-data/double-quoted.zsh @@ -31,15 +31,12 @@ BUFFER=': "foo$bar:\`:\":\$:' BUFFER+=\\\\:\" expected_region_highlight=( - "3 6 double-quoted-argument" # "foo + "1 1 builtin" # : + "3 24 default" # "foo$bar:\`:\":\$:\\:" + "3 24 double-quoted-argument" # "foo$bar:\`:\":\$:\\:" "7 10 dollar-double-quoted-argument" # $bar - "11 11 double-quoted-argument" # : "12 13 back-double-quoted-argument" # \` - "14 14 double-quoted-argument" # : "15 16 back-double-quoted-argument" # \$ - "17 17 double-quoted-argument" # : "18 19 back-double-quoted-argument" # \" - "20 20 double-quoted-argument" # : "21 22 back-double-quoted-argument" # \\ - "23 24 double-quoted-argument" # :" ) diff --git a/highlighters/main/test-data/double-quoted2.zsh b/highlighters/main/test-data/double-quoted2.zsh index ecd79ea..c400e54 100644 --- a/highlighters/main/test-data/double-quoted2.zsh +++ b/highlighters/main/test-data/double-quoted2.zsh @@ -32,6 +32,8 @@ BUFFER=': "foo$bar' expected_region_highlight=( - "3 6 double-quoted-argument-unclosed" # "foo + "1 1 builtin" # : + "3 10 default" # "foo$bar + "3 10 double-quoted-argument-unclosed" # "foo$bar "7 10 dollar-double-quoted-argument" # $bar ) diff --git a/highlighters/main/test-data/double-quoted3.zsh b/highlighters/main/test-data/double-quoted3.zsh index 39514e0..86e3ced 100644 --- a/highlighters/main/test-data/double-quoted3.zsh +++ b/highlighters/main/test-data/double-quoted3.zsh @@ -31,9 +31,12 @@ BUFFER=': "$" "$42foo"' BUFFER+=\ \"\\\'\\x\" expected_region_highlight=( + "1 1 builtin" # : + "3 5 default" # "$" "3 5 double-quoted-argument" # "$" - "7 7 double-quoted-argument" # " + "7 14 default" # "$42foo" + "7 14 double-quoted-argument" # "$42foo" "8 10 dollar-double-quoted-argument" # $42 - "11 14 double-quoted-argument" # foo" + "16 21 default" # "\'\x" "16 21 double-quoted-argument" # "\'\x" - \' and \x are not escape sequences ) diff --git a/highlighters/main/test-data/double-quoted4.zsh b/highlighters/main/test-data/double-quoted4.zsh index 51bb25e..c59d5d8 100644 --- a/highlighters/main/test-data/double-quoted4.zsh +++ b/highlighters/main/test-data/double-quoted4.zsh @@ -30,7 +30,8 @@ BUFFER=': "${foo}bar"' expected_region_highlight=( - "3 3 double-quoted-argument" # " + "1 1 builtin" # : + "3 13 default" # "${foo}bar" + "3 13 double-quoted-argument" # "${foo}bar" "4 9 dollar-double-quoted-argument" # ${foo} - "10 13 double-quoted-argument" # bar" ) diff --git a/highlighters/main/test-data/empty-command.zsh b/highlighters/main/test-data/empty-command.zsh index 6e68184..5831464 100644 --- a/highlighters/main/test-data/empty-command.zsh +++ b/highlighters/main/test-data/empty-command.zsh @@ -30,6 +30,7 @@ BUFFER='echo; ;' expected_region_highlight=( + "1 4 builtin" # echo "5 5 commandseparator" # ; "7 7 unknown-token" # ; ) diff --git a/highlighters/main/test-data/empty-command2.zsh b/highlighters/main/test-data/empty-command2.zsh index 698b3a7..dcb4e6f 100644 --- a/highlighters/main/test-data/empty-command2.zsh +++ b/highlighters/main/test-data/empty-command2.zsh @@ -33,6 +33,7 @@ touch ';' BUFFER='echo; ;' expected_region_highlight=( + "1 4 builtin" # echo "5 5 commandseparator" # ; "7 7 unknown-token" # ; ) diff --git a/highlighters/main/test-data/escaped-single-quote.zsh b/highlighters/main/test-data/escaped-single-quote.zsh index 77a01b4..4b2fe4b 100644 --- a/highlighters/main/test-data/escaped-single-quote.zsh +++ b/highlighters/main/test-data/escaped-single-quote.zsh @@ -32,7 +32,7 @@ BUFFER=$': \'foo\'\\\'\'bar\'' # <<<: 'foo'\''bar'>>> expected_region_highlight=( '1 1 builtin' # : + '3 14 default' # 'foo'\''bar' '3 7 single-quoted-argument' # 'foo' - '8 9 default' # \' '10 14 single-quoted-argument' # 'bar' ) diff --git a/highlighters/main/test-data/function.zsh b/highlighters/main/test-data/function.zsh index 426ee76..b1be853 100644 --- a/highlighters/main/test-data/function.zsh +++ b/highlighters/main/test-data/function.zsh @@ -37,5 +37,6 @@ BUFFER='cd;ls' expected_region_highlight=( "1 2 function" # cd + "3 3 commandseparator" # ; "4 5 function" # ls ) diff --git a/highlighters/main/test-data/glob.zsh b/highlighters/main/test-data/glob.zsh index b8b542b..2ff1022 100644 --- a/highlighters/main/test-data/glob.zsh +++ b/highlighters/main/test-data/glob.zsh @@ -31,11 +31,11 @@ BUFFER=': foo* bar? *baz qux\?' expected_region_highlight=( "1 1 builtin" # : - "3 5 default" # foo + "3 6 default" # foo* "6 6 globbing" # * - "8 10 default" # bar + "8 11 default" # bar? "11 11 globbing" # ? + "13 16 default" # *baz "13 13 globbing" # * - "14 16 default" # baz "18 22 default" # qux\? ) diff --git a/highlighters/main/test-data/globs-with-quoting.zsh b/highlighters/main/test-data/globs-with-quoting.zsh index b1ef63e..d7d74bc 100644 --- a/highlighters/main/test-data/globs-with-quoting.zsh +++ b/highlighters/main/test-data/globs-with-quoting.zsh @@ -32,6 +32,7 @@ BUFFER=$': "foo"*\'bar\'?"baz?"<17-29>"qu*ux"' expected_region_highlight=( '1 1 builtin' # : + '3 34 default' # "foo"*'bar'?"baz?"<17-29>"qu*ux" '3 7 double-quoted-argument' # "foo" '8 8 globbing' # * '9 13 single-quoted-argument' # 'bar' diff --git a/highlighters/main/test-data/history-double-quoted-escaped.zsh b/highlighters/main/test-data/history-double-quoted-escaped.zsh index c447a78..7807cc0 100644 --- a/highlighters/main/test-data/history-double-quoted-escaped.zsh +++ b/highlighters/main/test-data/history-double-quoted-escaped.zsh @@ -32,7 +32,7 @@ BUFFER='echo "Hello\!"' expected_region_highlight=( '1 4 builtin' # echo - '6 11 double-quoted-argument' # "Hello + '6 14 default' # "Hello\!" + '6 14 double-quoted-argument' # "Hello\!" '12 13 back-double-quoted-argument' # \! - '14 14 double-quoted-argument' # "Hello\!" ) diff --git a/highlighters/main/test-data/history-double-quoted-no.zsh b/highlighters/main/test-data/history-double-quoted-no.zsh index 7867e83..e082dbc 100644 --- a/highlighters/main/test-data/history-double-quoted-no.zsh +++ b/highlighters/main/test-data/history-double-quoted-no.zsh @@ -32,5 +32,6 @@ BUFFER='echo "foo != bar !{baz}"' expected_region_highlight=( '1 4 builtin' # echo + '6 24 default' # "foo != bar !{baz}" '6 24 double-quoted-argument' # "foo != bar !{baz}" - no history expansions ) diff --git a/highlighters/main/test-data/history-double-quoted-unescaped.zsh b/highlighters/main/test-data/history-double-quoted-unescaped.zsh index c828b44..cfe6a11 100644 --- a/highlighters/main/test-data/history-double-quoted-unescaped.zsh +++ b/highlighters/main/test-data/history-double-quoted-unescaped.zsh @@ -32,7 +32,7 @@ BUFFER='echo "Hello!"' expected_region_highlight=( '1 4 builtin' # echo - '6 11 double-quoted-argument' # "Hello + '6 13 default' # "Hello!" + '6 13 double-quoted-argument' # "Hello!" '12 12 history-expansion' # ! - '13 13 double-quoted-argument' # " ) diff --git a/highlighters/main/test-data/history-double-quoted-yes.zsh b/highlighters/main/test-data/history-double-quoted-yes.zsh index 88c300e..e963c3b 100644 --- a/highlighters/main/test-data/history-double-quoted-yes.zsh +++ b/highlighters/main/test-data/history-double-quoted-yes.zsh @@ -32,7 +32,7 @@ BUFFER='echo "foo !bar"' expected_region_highlight=( '1 4 builtin' # echo - '6 10 double-quoted-argument' # "foo + '6 15 default' # "foo !bar" + '6 15 double-quoted-argument' # "foo !bar" '11 11 history-expansion' # ! - '12 15 double-quoted-argument' # bar" ) diff --git a/highlighters/main/test-data/history-expansion.zsh b/highlighters/main/test-data/history-expansion.zsh index 3e23711..05e20fc 100644 --- a/highlighters/main/test-data/history-expansion.zsh +++ b/highlighters/main/test-data/history-expansion.zsh @@ -33,6 +33,7 @@ expected_region_highlight=( "1 4 history-expansion" # !foo "6 8 default" # bar "10 13 history-expansion" # !baz - "15 15 default" # ! (before the semicolon) - "19 19 reserved-word" # ! (after the semicolon) + "15 15 default" # ! + "17 17 commandseparator" # ; + "19 19 reserved-word" # ! ) diff --git a/highlighters/main/test-data/multiline-string.zsh b/highlighters/main/test-data/multiline-string.zsh index 484c951..0127b4b 100644 --- a/highlighters/main/test-data/multiline-string.zsh +++ b/highlighters/main/test-data/multiline-string.zsh @@ -31,6 +31,7 @@ PREBUFFER=$'echo "foo1\n' BUFFER='foo2" ./' expected_region_highlight=( + "1 5 default" # 'foo2"' "1 5 double-quoted-argument" # 'foo2"' "7 8 path" # './' ) diff --git a/highlighters/main/test-data/multiline-string2.zsh b/highlighters/main/test-data/multiline-string2.zsh index 7c5845e..3a90dce 100644 --- a/highlighters/main/test-data/multiline-string2.zsh +++ b/highlighters/main/test-data/multiline-string2.zsh @@ -30,5 +30,7 @@ BUFFER=$'echo \'foo1\n' expected_region_highlight=( - "6 10 single-quoted-argument-unclosed" # 'foo1 + "1 4 builtin" # echo + "6 11 default" # 'foo1\n + "6 11 single-quoted-argument-unclosed" # 'foo1\n ) diff --git a/highlighters/main/test-data/multiple-quotes.zsh b/highlighters/main/test-data/multiple-quotes.zsh index 10b8d14..dabf70c 100644 --- a/highlighters/main/test-data/multiple-quotes.zsh +++ b/highlighters/main/test-data/multiple-quotes.zsh @@ -30,18 +30,13 @@ BUFFER=$': \'foo\'bar"baz$quux/foo\\\\bar"baz$\'quux\\nfoo\\001bar\'baz' expected_region_highlight=( + "1 1 builtin" # : + "3 54 default" # 'foo'bar"baz$quux/foo\\bar"baz$'quux\nfoo\001'baz "3 7 single-quoted-argument" # 'foo' - "8 10 default" # bar - "11 14 double-quoted-argument" #"baz + "11 29 double-quoted-argument" #"baz "15 19 dollar-double-quoted-argument" # $quux - "20 23 double-quoted-argument" # /foo "24 25 back-double-quoted-argument" # \\ - "26 29 double-quoted-argument" # bar" - "30 32 default" # baz - "33 38 dollar-quoted-argument" # $'quux + "33 51 dollar-quoted-argument" # $'quux\nfoo\001bar' "39 40 back-dollar-quoted-argument" # \n - "41 43 dollar-quoted-argument" # foo "44 47 back-dollar-quoted-argument" # \001 - "48 51 dollar-quoted-argument" # bar' - "52 54 default" # baz ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 6f3a7f7..2f96445 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -31,5 +31,6 @@ alias x=command BUFFER='x ls' expected_region_highlight=( + "1 1 alias" # x "3 4 command" # ls ) diff --git a/highlighters/main/test-data/noglob1.zsh b/highlighters/main/test-data/noglob1.zsh index ea70a83..1857db0 100644 --- a/highlighters/main/test-data/noglob1.zsh +++ b/highlighters/main/test-data/noglob1.zsh @@ -30,5 +30,9 @@ BUFFER=':; noglob echo *' expected_region_highlight=( + "1 1 builtin" # : + "2 2 commandseparator" # ; + "4 9 precommand" # noglob + "11 14 builtin" # echo "16 16 default" # * ) diff --git a/highlighters/main/test-data/noglob2.zsh b/highlighters/main/test-data/noglob2.zsh index 6d7a940..3b4fcd7 100644 --- a/highlighters/main/test-data/noglob2.zsh +++ b/highlighters/main/test-data/noglob2.zsh @@ -30,6 +30,11 @@ BUFFER='noglob echo *; echo *' expected_region_highlight=( + "1 6 precommand" # noglob + "8 11 builtin" # echo "13 13 default" # * + "14 14 commandseparator" # ; + "16 19 builtin" # echo + "21 21 default" # * "21 21 globbing" # * ) diff --git a/highlighters/main/test-data/noglob3.zsh b/highlighters/main/test-data/noglob3.zsh index 361ea8c..c404aaa 100644 --- a/highlighters/main/test-data/noglob3.zsh +++ b/highlighters/main/test-data/noglob3.zsh @@ -32,5 +32,7 @@ touch \* BUFFER='noglob echo *' expected_region_highlight=( + "1 6 precommand" # noglob + "8 11 builtin" # echo "13 13 path" # * ) diff --git a/highlighters/main/test-data/number_range-glob.zsh b/highlighters/main/test-data/number_range-glob.zsh index c13c6b7..c840951 100644 --- a/highlighters/main/test-data/number_range-glob.zsh +++ b/highlighters/main/test-data/number_range-glob.zsh @@ -32,10 +32,10 @@ BUFFER='print <-> x<->y ' expected_region_highlight=( '1 5 builtin' # print + '7 9 default' # <-> '7 9 globbing' # <-> - '11 11 default' # x + '11 15 default' # x<->y '12 14 globbing' # <-> - '15 15 default' # y '17 17 redirection' # < '18 23 default' # foo2-3 (the filename) '24 24 redirection' # > diff --git a/highlighters/main/test-data/option-with-quotes.zsh b/highlighters/main/test-data/option-with-quotes.zsh index b87fb77..6286f03 100644 --- a/highlighters/main/test-data/option-with-quotes.zsh +++ b/highlighters/main/test-data/option-with-quotes.zsh @@ -32,6 +32,6 @@ BUFFER=$': --user="phy1729"' expected_region_highlight=( '1 1 builtin' # : - '3 9 double-hyphen-option' # --user= + '3 18 double-hyphen-option' # --user="phy1729" '10 18 double-quoted-argument' # "phy1729" ) diff --git a/highlighters/main/test-data/order-path-before-globbing.zsh b/highlighters/main/test-data/order-path-before-globbing.zsh index b1695fc..8456b18 100644 --- a/highlighters/main/test-data/order-path-before-globbing.zsh +++ b/highlighters/main/test-data/order-path-before-globbing.zsh @@ -33,6 +33,7 @@ BUFFER=': * \*' expected_region_highlight=( '1 1 builtin' # : + '3 3 default' # * '3 3 globbing' # * '5 6 path' # \* ) diff --git a/highlighters/main/test-data/parameter-star.zsh b/highlighters/main/test-data/parameter-star.zsh index 1797e58..2311be0 100644 --- a/highlighters/main/test-data/parameter-star.zsh +++ b/highlighters/main/test-data/parameter-star.zsh @@ -32,5 +32,9 @@ BUFFER='() { : $* }' # This tests that $* isn't highlighted as a glob. # If we ever add a "unquoted parameter" style, the expectation may change. expected_region_highlight=( + "1 2 reserved-word" # () + "4 4 reserved-word" # { + "6 6 builtin" # : "8 9 default" # $* + "11 11 reserved-word" # } ) diff --git a/highlighters/main/test-data/path-broken-symlink.zsh b/highlighters/main/test-data/path-broken-symlink.zsh index c99f872..baebee3 100644 --- a/highlighters/main/test-data/path-broken-symlink.zsh +++ b/highlighters/main/test-data/path-broken-symlink.zsh @@ -35,6 +35,7 @@ else CURSOR=5 # to make path_prefix ineligible expected_region_highlight=( + "1 1 builtin" # : "3 16 path" # broken-symlink ) fi diff --git a/highlighters/main/test-data/path-dollared-word2.zsh b/highlighters/main/test-data/path-dollared-word2.zsh index d1c34af..f404d5d 100644 --- a/highlighters/main/test-data/path-dollared-word2.zsh +++ b/highlighters/main/test-data/path-dollared-word2.zsh @@ -32,5 +32,6 @@ touch \$lambda BUFFER=': \$lambda' expected_region_highlight=( - "3 8 path" # \$lambda + "1 1 builtin" # : + "3 10 path" # \$lambda ) diff --git a/highlighters/main/test-data/path-dollared-word3.zsh b/highlighters/main/test-data/path-dollared-word3.zsh index fc3324e..a9a5fa3 100644 --- a/highlighters/main/test-data/path-dollared-word3.zsh +++ b/highlighters/main/test-data/path-dollared-word3.zsh @@ -33,5 +33,6 @@ BUFFER='$PWD; ${PWD}' expected_region_highlight=( "1 4 unknown-token" # $PWD - not eval'd; issue #328 + "5 5 commandseparator" # ; "7 12 unknown-token" # ${PWD} ) diff --git a/highlighters/main/test-data/path-separators.zsh b/highlighters/main/test-data/path-separators.zsh index cf13dad..52749b7 100644 --- a/highlighters/main/test-data/path-separators.zsh +++ b/highlighters/main/test-data/path-separators.zsh @@ -37,17 +37,17 @@ touch A/mu BUFFER='ls /bin/ / A/mu A/m' expected_region_highlight=( + "1 2 command" # ls + "4 8 path" # /bin/ "4 4 path_pathseparator" # / - "5 7 path" # bin "8 8 path_pathseparator" # / + "10 10 path" # / "10 10 path_pathseparator" # / - "12 12 path" # A + "12 15 path" # A/mu "13 13 path_pathseparator" # / - "14 15 path" # mu - "17 17 path_prefix" # A + "17 19 path_prefix" # A/m "18 18 path_prefix_pathseparator" # / - "19 19 path_prefix" # m ) diff --git a/highlighters/main/test-data/path-separators2.zsh b/highlighters/main/test-data/path-separators2.zsh index db4e706..bc885a0 100644 --- a/highlighters/main/test-data/path-separators2.zsh +++ b/highlighters/main/test-data/path-separators2.zsh @@ -35,5 +35,6 @@ ZSH_HIGHLIGHT_STYLES[path_pathseparator]=value BUFFER='ls /bin/' expected_region_highlight=( + "1 2 command" # ls "4 8 path" # /bin/ ) diff --git a/highlighters/main/test-data/path-space.zsh b/highlighters/main/test-data/path-space.zsh index 67a26fd..87cc22f 100644 --- a/highlighters/main/test-data/path-space.zsh +++ b/highlighters/main/test-data/path-space.zsh @@ -33,5 +33,5 @@ BUFFER='ls A/mu\ with\ spaces' expected_region_highlight=( "1 2 command" # ls - "4 19 path" # A/mu\ with\ spaces + "4 21 path" # A/mu\ with\ spaces ) diff --git a/highlighters/main/test-data/path_prefix.zsh b/highlighters/main/test-data/path_prefix.zsh index 12fb30b..3303bfb 100644 --- a/highlighters/main/test-data/path_prefix.zsh +++ b/highlighters/main/test-data/path_prefix.zsh @@ -33,5 +33,6 @@ BUFFER='ls /bin/s' expected_region_highlight=( - "4 9 path_prefix" # /bin/s + "1 2 command" # ls + "4 9 path_prefix" # /bin/s ) diff --git a/highlighters/main/test-data/path_prefix2.zsh b/highlighters/main/test-data/path_prefix2.zsh index 501928a..4f40f7e 100644 --- a/highlighters/main/test-data/path_prefix2.zsh +++ b/highlighters/main/test-data/path_prefix2.zsh @@ -34,5 +34,6 @@ BUFFER='ls /bin/s' WIDGET=zle-line-finish expected_region_highlight=( - "4 9 default" # /bin/s + "1 2 command" # ls + "4 9 default" # /bin/s ) diff --git a/highlighters/main/test-data/prefix-redirection.zsh b/highlighters/main/test-data/prefix-redirection.zsh index 6a13aa6..a0f0ed5 100644 --- a/highlighters/main/test-data/prefix-redirection.zsh +++ b/highlighters/main/test-data/prefix-redirection.zsh @@ -30,10 +30,13 @@ BUFFER='>/tmp >/tmp command echo >/tmp foo' expected_region_highlight=( + "1 1 redirection" # > "2 5 path" # /tmp + "7 7 redirection" # > "8 11 path" # /tmp "13 19 precommand" # command "21 24 builtin" # echo + "26 26 redirection" # > "27 30 path" # /tmp "32 34 default" # foo ) diff --git a/highlighters/main/test-data/rc-quotes.zsh b/highlighters/main/test-data/rc-quotes.zsh index 6d1d6ed..8cd427a 100644 --- a/highlighters/main/test-data/rc-quotes.zsh +++ b/highlighters/main/test-data/rc-quotes.zsh @@ -32,8 +32,8 @@ setopt RC_QUOTES BUFFER=": 'foo''bar'baz" expected_region_highlight=( - "3 6 single-quoted-argument" # 'foo + "1 1 builtin" # : + "3 15 default" # 'foo''bar'baz + "3 12 single-quoted-argument" # 'foo''bar' "7 8 rc-quote" # '' - "9 12 single-quoted-argument" # bar' - "13 15 default" # baz ) diff --git a/highlighters/main/test-data/redirection.zsh b/highlighters/main/test-data/redirection.zsh index 5086082..6a25971 100644 --- a/highlighters/main/test-data/redirection.zsh +++ b/highlighters/main/test-data/redirection.zsh @@ -32,5 +32,8 @@ BUFFER='<<>&!bar' expected_region_highlight=( "1 3 redirection" # <<< + "4 6 default" # foo + "8 11 builtin" # echo "13 16 redirection" # >>&! + "17 19 default" # bar ) diff --git a/highlighters/main/test-data/reserved-word.zsh b/highlighters/main/test-data/reserved-word.zsh index e71fe0a..aca3796 100644 --- a/highlighters/main/test-data/reserved-word.zsh +++ b/highlighters/main/test-data/reserved-word.zsh @@ -31,6 +31,7 @@ BUFFER='repeat "1" do done' expected_region_highlight=( "1 6 reserved-word" # repeat + "8 10 default" # "1" "8 10 double-quoted-argument" # "1" "12 13 reserved-word" # do "15 18 reserved-word" # done diff --git a/highlighters/main/test-data/subshell.zsh b/highlighters/main/test-data/subshell.zsh index 0080ad2..c068013 100644 --- a/highlighters/main/test-data/subshell.zsh +++ b/highlighters/main/test-data/subshell.zsh @@ -31,10 +31,20 @@ BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }' expected_region_highlight=( "1 3 command" # tar + "5 6 default" # cf + "8 8 single-hyphen-option" # - + "10 10 default" # * + "10 10 globbing" # * + "12 12 commandseparator" # | "14 14 reserved-word" # ( "15 16 builtin" # cd + "18 24 default" # /target + "25 25 commandseparator" # ; "27 29 command" # tar + "31 33 default" # xfp + "35 35 single-hyphen-option" # - "36 36 reserved-word" # ) + "38 38 commandseparator" # | "40 40 reserved-word" # { "42 44 command" # cat "46 46 reserved-word" # } diff --git a/highlighters/main/test-data/sudo-command.zsh b/highlighters/main/test-data/sudo-command.zsh index 266ace2..941349a 100644 --- a/highlighters/main/test-data/sudo-command.zsh +++ b/highlighters/main/test-data/sudo-command.zsh @@ -43,7 +43,12 @@ expected_region_highlight=( "23 24 single-hyphen-option" # -i "26 27 command" # ls "29 29 path" # / + "30 30 commandseparator" # ; + "32 35 precommand" # sudo "37 37 unknown-token" # ;, error because empty command + "39 42 precommand" # sudo + "44 45 single-hyphen-option" # -u "47 47 unknown-token" # ;, error because incomplete command + "49 52 precommand" # sudo "54 64 unknown-token" # notacommand - doesn't falls back to "not a command word" codepath ) diff --git a/highlighters/main/test-data/vi-linewise-mode.zsh b/highlighters/main/test-data/vi-linewise-mode.zsh index 4b77766..7003c49 100644 --- a/highlighters/main/test-data/vi-linewise-mode.zsh +++ b/highlighters/main/test-data/vi-linewise-mode.zsh @@ -34,5 +34,10 @@ CURSOR=4 MARK=12 expected_region_highlight=( - "1 3 standout" # foo + "1 3 unknown-token" # foo + "5 7 default" # foo + "8 8 commandseparator" # \n + "9 11 unknown-token" # bar + "13 15 default" # bar + "1 15 standout" # foo foo\nbar bar ) diff --git a/tests/README.md b/tests/README.md index 78433c3..8487b3c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -13,12 +13,13 @@ The value of that parameter is a list of strings of the form `"$i $j $style"`. or `"$i $j $style $todo"`. Each string specifies the highlighting that `$BUFFER[$i,$j]` should have; that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints. -`$style` is either a key of `$ZSH_HIGHLIGHT_STYLES` or `NONE` to specify no -highlighting should be observed. +`$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`. **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 9c6b145..812b1a7 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -97,7 +97,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 + local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test unsorted=0 local -a expected_region_highlight region_highlight . "$srcdir"/"$1" @@ -106,7 +106,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 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 or empty."; return 1; } + (( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return 1; } # Set sane defaults for ZLE variables : ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget} @@ -114,54 +114,48 @@ run_test_internal() { # Process the data. _zsh_highlight - # Overlapping regions can be declared in region_highlight, so we first build an array of the - # observed highlighting. - local i j - local -A observed_result - for ((i=1; i<=${#region_highlight}; i++)); do - local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} ) - integer start=$highlight_zone[1] end=$highlight_zone[2] - if (( start < end )) # region_highlight ranges are half-open - then - (( --end )) # convert to closed range, like expected_region_highlight - (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed - for j in {$start..$end}; do - observed_result[$j]=$highlight_zone[3] - done - else - # noop range; ignore. - fi - unset start end - unset highlight_zone - done + if (( unsorted )); then + region_highlight=("${(@n)region_highlight}") + expected_region_highlight=("${(@n)expected_region_highlight}") + fi - # Then we compare the observed result with the expected one. - echo "1..${#expected_region_highlight}" - for ((i=1; i<=${#expected_region_highlight}; i++)); do - local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} ) + echo "1..$(( $#expected_region_highlight + 1))" + local i + for ((i=1; i<=$#expected_region_highlight; i++)); do + 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= - integer start=$highlight_zone[1] end=$highlight_zone[2] + (( $+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])" + continue + 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'/↵}»" - (( $+highlight_zone[4] )) && todo="# TODO $highlight_zone[4]" - for j in {$start..$end}; do - if - if [[ $highlight_zone[3] == NONE ]]; then - (( $+observed_result[$j] )) - else - [[ "$observed_result[$j]" != "$highlight_zone[3]" ]] - fi - then - print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]-NONE}. $todo" - continue 2 - fi - done - print -r -- "ok $i - $desc${todo:+ - }$todo" - unset desc - unset start end + if + [[ $start != $exp_start ]] || + [[ $end != $exp_end ]] || + [[ $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" + else + print -r -- "ok $i - $desc${todo:+ - }$todo" + fi + unset expected_highlight_zone + unset exp_start exp_end unset todo unset highlight_zone + unset start end + unset desc done + + 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" + fi } # Run a single test file. The exit status is 1 if the test harness had From be26017e392e0971551034f7caa3591348ed862e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 11 Feb 2018 09:58:00 -0600 Subject: [PATCH 0600/1080] regexp: Add test for subexpression match Closes #497 --- .../regexp/test-data/subexpression.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/regexp/test-data/subexpression.zsh diff --git a/highlighters/regexp/test-data/subexpression.zsh b/highlighters/regexp/test-data/subexpression.zsh new file mode 100644 index 0000000..308cb41 --- /dev/null +++ b/highlighters/regexp/test-data/subexpression.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='ls foo' +ZSH_HIGHLIGHT_REGEXP=('(^| )(ls|cd)($| )' 'fg=green') + +expected_region_highlight=( + '1 3 fg=green' # "ls " +) From 9706af4b8135d030a33ba4e9534b853dc9969327 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 11 Feb 2018 11:07:08 -0600 Subject: [PATCH 0601/1080] main: Simplify for next commit; no functional change --- highlighters/main/main-highlighter.zsh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 26fcb4b..6cf0380 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -830,14 +830,12 @@ _zsh_highlight_main_highlighter_highlight_argument() _zsh_highlight_main_highlighter_highlight_dollar_quote $i (( i = REPLY )) highlights+=($reply) - elif [[ $arg[i+1] == [\^=~#+] ]]; then - while [[ $arg[i+1] == [\^=~#+] ]]; do - (( i += 1 )) - done - if [[ $arg[i+1] == [*@#?-$!] ]]; then - (( i += 1 )) - fi - elif [[ $arg[i+1] == [*@#?-$!] ]]; then + continue + fi + while [[ $arg[i+1] == [\^=~#+] ]]; do + (( i += 1 )) + done + if [[ $arg[i+1] == [*@#?-$!] ]]; then (( i += 1 )) fi;; *) From 90b09f88eee44b18751e23dc27c5f615ced54ac9 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 11 Feb 2018 11:08:27 -0600 Subject: [PATCH 0602/1080] main: Move - to end of character class Closes #472 --- 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 6cf0380..b100dd9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -835,7 +835,7 @@ _zsh_highlight_main_highlighter_highlight_argument() while [[ $arg[i+1] == [\^=~#+] ]]; do (( i += 1 )) done - if [[ $arg[i+1] == [*@#?-$!] ]]; then + if [[ $arg[i+1] == [*@#?$!-] ]]; then (( i += 1 )) fi;; *) From 67137277420061d396900d8a7c85f1a444112820 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 21 Jan 2018 14:48:47 -0600 Subject: [PATCH 0603/1080] main: Add ZSH_HIGHLIGHT_DIRS_BLACKLIST Closes #379. --- docs/highlighters/main.md | 6 +++ highlighters/main/main-highlighter.zsh | 16 +++++++- .../main/test-data/dirs_blacklist.zsh | 40 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/dirs_blacklist.zsh diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 3459e90..169b00d 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -71,6 +71,12 @@ 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)` manual page][zshzle-Character-Highlighting]. +#### Parameters + +To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. + + ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) + ### Useless trivia #### Forward compatibility. diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b100dd9..21b530a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -757,7 +757,7 @@ _zsh_highlight_main_highlighter_highlight_path_separators() _zsh_highlight_main_highlighter_check_path() { _zsh_highlight_main_highlighter_expand_path $arg; - local expanded_path="$REPLY" + local expanded_path="$REPLY" tmp_path REPLY=path @@ -765,6 +765,19 @@ _zsh_highlight_main_highlighter_check_path() [[ -L $expanded_path ]] && return 0 [[ -e $expanded_path ]] && return 0 + # Check if this is a blacklisted path + if [[ $expanded_path[1] == / ]]; then + tmp_path=$expanded_path + else + tmp_path=$PWD/$expanded_path + fi + tmp_path=$tmp_path:a + + while [[ $tmp_path != / ]]; do + [[ -n "${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path}" ]] && return 1 + tmp_path=$tmp_path:h + done + # Search the path in CDPATH local cdpath_dir for cdpath_dir in $cdpath ; do @@ -1070,3 +1083,4 @@ else # Make sure the cache is unset unset _zsh_highlight_main__command_type_cache fi +typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST diff --git a/highlighters/main/test-data/dirs_blacklist.zsh b/highlighters/main/test-data/dirs_blacklist.zsh new file mode 100644 index 0000000..9c45ea1 --- /dev/null +++ b/highlighters/main/test-data/dirs_blacklist.zsh @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +mkdir foo +touch foo/bar +BUFFER=": foo/bar $PWD/foo foo/b" +ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo) + +expected_region_highlight=( + '1 1 builtin' # : + '3 9 path' # foo/bar + "11 $(( 14 + $#PWD )) path" # $PWD/foo + "$(( 16 + $#PWD )) $(( 20 + $#PWD )) default" # foo/b +) From 15e288a25ca0fbad5ad3aeddf134910ee2cf5e8a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 17 Feb 2018 20:08:25 -0600 Subject: [PATCH 0604/1080] main: Mark ZSH_HIGHLIGHT_DIRS_BLACKLIST experimental --- docs/highlighters/main.md | 5 +++-- highlighters/main/main-highlighter.zsh | 4 ++-- highlighters/main/test-data/dirs_blacklist.zsh | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 169b00d..9ecf042 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -73,9 +73,10 @@ manual page][zshzle-Character-Highlighting]. #### Parameters -To avoid partial path lookups on a path, add the path to the `ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. +To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array. +This interface is still experimental. - ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) + X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share) ### Useless trivia diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 21b530a..baf4193 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -774,7 +774,7 @@ _zsh_highlight_main_highlighter_check_path() tmp_path=$tmp_path:a while [[ $tmp_path != / ]]; do - [[ -n "${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path}" ]] && return 1 + [[ -n "${(M)X_ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path}" ]] && return 1 tmp_path=$tmp_path:h done @@ -1083,4 +1083,4 @@ else # Make sure the cache is unset unset _zsh_highlight_main__command_type_cache fi -typeset -ga ZSH_HIGHLIGHT_DIRS_BLACKLIST +typeset -ga X_ZSH_HIGHLIGHT_DIRS_BLACKLIST diff --git a/highlighters/main/test-data/dirs_blacklist.zsh b/highlighters/main/test-data/dirs_blacklist.zsh index 9c45ea1..0d4d666 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" -ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo) +X_ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo) expected_region_highlight=( '1 1 builtin' # : From 2c0c75a8ee9a0f212eebbe4ee91ca5884f18e52f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 6 Mar 2018 11:31:50 -0600 Subject: [PATCH 0605/1080] driver, main: Add -z to autoload calls --- 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 baf4193..83d93e8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1074,7 +1074,7 @@ _zsh_highlight_main__precmd_hook() { _zsh_highlight_main__command_type_cache=() } -autoload -U add-zsh-hook +autoload -Uz add-zsh-hook if add-zsh-hook precmd _zsh_highlight_main__precmd_hook 2>/dev/null; then # Initialize command type cache typeset -gA _zsh_highlight_main__command_type_cache diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index eee0284..9ffde76 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -55,7 +55,7 @@ fi # Use workaround for bug in ZSH? # zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html -autoload -U is-at-least +autoload -Uz is-at-least if is-at-least 5.4; then zsh_highlight__pat_static_bug=false else @@ -421,7 +421,7 @@ _zsh_highlight_preexec_hook() typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER= typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR= } -autoload -U add-zsh-hook +autoload -Uz add-zsh-hook add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || { print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.' } From d2c8f3a56d2a9d7357b2a7a50ae4b8c740bc41e1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 09:40:49 -0600 Subject: [PATCH 0606/1080] main: Fix end of buffer check for path_prefix with non-null PREBUFFER --- highlighters/main/main-highlighter.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 83d93e8..b5b5a28 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -229,7 +229,6 @@ _zsh_highlight_highlighter_main_paint() local -a options_to_set # used in callees local buf="$PREBUFFER$BUFFER" integer len="${#buf}" - integer pure_buf_len=$(( len - ${#PREBUFFER} )) # == $#BUFFER, used e.g. in *_check_path # "R" for round # "Q" for square @@ -788,7 +787,7 @@ _zsh_highlight_main_highlighter_check_path() [[ ! -d ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. - if [[ ${BUFFER[1]} != "-" && $pure_buf_len == $end_pos ]] && + if [[ ${BUFFER[1]} != "-" && $len == $end_pos ]] && [[ $WIDGET != zle-line-finish ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) From 5e9b7c4650e4386a4620011c589475baa6263eb1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 09:45:18 -0600 Subject: [PATCH 0607/1080] main: Add test for previous --- highlighters/main/test-data/path_prefix3.zsh | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/path_prefix3.zsh diff --git a/highlighters/main/test-data/path_prefix3.zsh b/highlighters/main/test-data/path_prefix3.zsh new file mode 100644 index 0000000..f4a0189 --- /dev/null +++ b/highlighters/main/test-data/path_prefix3.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# 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 +# ------------------------------------------------------------------------------------------------- + +# Assumes that '/bin/sh' exists and '/bin/s' does not exist. +# Related to path_prefix.zsh + +PREBUFFER='ls \' +BUFFER='/bin/s' + +expected_region_highlight=( + '1 6 path_prefix' # /bin/s +) From e4fffa4de566c9552f9284fd75e689edb3a1083d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 16 Mar 2018 17:18:31 -0500 Subject: [PATCH 0608/1080] main: Correct dollar-quoted-argument-unclosed fallback 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 b5b5a28..8b373ab 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -88,7 +88,7 @@ _zsh_highlight_main_add_region_highlight() { single-quoted-argument{-unclosed,} double-quoted-argument{-unclosed,} - dollar-single-quoted-argument{-unclosed,} + dollar-quoted-argument{-unclosed,} back-quoted-argument{-unclosed,} ) local needle=$1 value From 02b839550fae0b79121307bca57c2994159ae36d Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Wed, 11 Apr 2018 22:00:50 +0200 Subject: [PATCH 0609/1080] CI: add zsh 5.5 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index db5dbc4..8b08d0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: required env: - ZSH=master + - ZSH=5.5 - ZSH=5.4.2 - ZSH=5.4.1 - ZSH=5.4 From 02a37dd919dc48e0821186e5f20e78bd0215f86a Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Wed, 11 Apr 2018 22:19:49 +0200 Subject: [PATCH 0610/1080] CI: install packages required by test suite --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8b08d0b..2b801bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ env: - ZSH=4.3.12 - ZSH=4.3.11 -script: docker run -v $PWD:/work -w /work zshusers/zsh-${ZSH} /bin/sh -c '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 5b539663c0d740a0c00169d5ecbd58e47ff16252 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 12 May 2018 00:04:19 +0000 Subject: [PATCH 0611/1080] Add a regression test for a problem seen during development. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The «=(' to the ')'. --- ...substitution-redirection-isnt-globbing.zsh | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh diff --git a/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh new file mode 100644 index 0000000..05c11b8 --- /dev/null +++ b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.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=$': =( Date: Sat, 26 May 2018 09:39:25 -0400 Subject: [PATCH 0612/1080] docs: fix typos --- README.md | 4 ++-- docs/highlighters/main.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index decb30b..08af2b6 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travi [fish]: http://www.fishshell.com/ [zsh]: http://www.zsh.org/ -This package provides syntax highlighing for the shell zsh. It enables -highlighing of commands whilst they are typed at a zsh prompt into an +This package provides syntax highlighting for the shell zsh. It enables +highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors. diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 9ecf042..c14b32f 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -49,7 +49,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`) -* `arg0` - a command word other than one of those enumrated above (other than a command, precommand, alias, function, or shell builtin command). +* `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 To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`, From db6cac391bee957c20ff3175b2f03c4817253e60 Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Wed, 30 May 2018 19:03:36 +0200 Subject: [PATCH 0613/1080] main: Add glob qualifier to work around zsh/macOS bug zsh/macOS bug: http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=42891 --- 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 9ffde76..6838e1d 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -373,7 +373,7 @@ _zsh_highlight_load_highlighters() # Load highlighters from highlighters directory and check they define required functions. local highlighter highlighter_dir - for highlighter_dir ($1/*/); do + for highlighter_dir ($1/*/(/)); do highlighter="${highlighter_dir:t}" [[ -f "$highlighter_dir${highlighter}-highlighter.zsh" ]] && . "$highlighter_dir${highlighter}-highlighter.zsh" From 47d6dac133094e0a60c9e1fcbb28a810a98fa0ec Mon Sep 17 00:00:00 2001 From: "Sam Jorna (wraeth)" Date: Thu, 30 Aug 2018 10:12:55 +1000 Subject: [PATCH 0614/1080] main-highlighter: Probe dirs after blacklist Move tests on the highlight path until after the blacklist is checked so that blacklisted paths are not tested. This should prevent hangs on dead remote filesystems provided the path is blacklisted in X_ZSH_HIGHLIGHT_DIRS_BLACKLIST. Updated tests to 'default' highlight as the blacklist is now checked before the path is tested. Bug: https://github.com/zsh-users/zsh-syntax-highlighting/issues/528 --- highlighters/main/main-highlighter.zsh | 5 +++-- highlighters/main/test-data/dirs_blacklist.zsh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8b373ab..83571f6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -761,8 +761,6 @@ _zsh_highlight_main_highlighter_check_path() REPLY=path [[ -z $expanded_path ]] && return 1 - [[ -L $expanded_path ]] && return 0 - [[ -e $expanded_path ]] && return 0 # Check if this is a blacklisted path if [[ $expanded_path[1] == / ]]; then @@ -777,6 +775,9 @@ _zsh_highlight_main_highlighter_check_path() tmp_path=$tmp_path:h done + [[ -L $expanded_path ]] && return 0 + [[ -e $expanded_path ]] && return 0 + # Search the path in CDPATH local cdpath_dir for cdpath_dir in $cdpath ; do diff --git a/highlighters/main/test-data/dirs_blacklist.zsh b/highlighters/main/test-data/dirs_blacklist.zsh index 0d4d666..7fff7e2 100644 --- a/highlighters/main/test-data/dirs_blacklist.zsh +++ b/highlighters/main/test-data/dirs_blacklist.zsh @@ -34,7 +34,7 @@ X_ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo) expected_region_highlight=( '1 1 builtin' # : - '3 9 path' # foo/bar - "11 $(( 14 + $#PWD )) path" # $PWD/foo + '3 9 default' # foo/bar + "11 $(( 14 + $#PWD )) default" # $PWD/foo "$(( 16 + $#PWD )) $(( 20 + $#PWD )) default" # foo/b ) From 42d396d8190b93ae0bb45ed22039589b4840ab82 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 7 Sep 2018 18:21:53 +0000 Subject: [PATCH 0615/1080] driver: Exclude yank-pop again (#183). --- 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 6838e1d..561ac81 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -305,7 +305,7 @@ _zsh_highlight_bind_widgets() # Override ZLE widgets to make them invoke _zsh_highlight. local -U widgets_to_bind - widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)}) + widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)}) # Always wrap special zle-line-finish widget. This is needed to decide if the # current line ends and special highlighting logic needs to be applied. From 8348e2d2ccfe4c04168963bc9a3b1fd2181783e5 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Sat, 22 Sep 2018 21:27:01 +0200 Subject: [PATCH 0616/1080] Enable testing on zsh 5.5.x/5.6.x releases --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2b801bd..cea0ad9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ sudo: required env: - ZSH=master + - ZSH=5.6.2 + - ZSH=5.6.1 + - ZSH=5.6 + - ZSH=5.5.1 - ZSH=5.5 - ZSH=5.4.2 - ZSH=5.4.1 From 3a7ddcda0b854d60058ac488b52c837e7ea92fc6 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Sat, 22 Sep 2018 22:50:46 +0200 Subject: [PATCH 0617/1080] #535: locally enable BARE_GLOB_QUAL option when loading highlighters --- 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 561ac81..4caf3a8 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -363,7 +363,7 @@ _zsh_highlight_bind_widgets() # 1) Path to the highlighters directory. _zsh_highlight_load_highlighters() { - setopt localoptions noksharrays + setopt localoptions noksharrays bareglobqual # Check the directory exists. [[ -d "$1" ]] || { From 1eedb23c654450585d9e47d490019ff0b48382ed Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 24 Sep 2018 07:07:32 -0500 Subject: [PATCH 0618/1080] main: Fix blacklist dirs check when there is more than one element --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/dirs_blacklist.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 83571f6..08747ab 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -771,7 +771,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)X_ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1 tmp_path=$tmp_path:h done diff --git a/highlighters/main/test-data/dirs_blacklist.zsh b/highlighters/main/test-data/dirs_blacklist.zsh index 7fff7e2..8cf04be 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) +X_ZSH_HIGHLIGHT_DIRS_BLACKLIST=($PWD/foo $PWD/bar) expected_region_highlight=( '1 1 builtin' # : From 2fd7fbc3c24c17a94140cbb32e8653379a4856aa Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 29 Sep 2018 21:29:45 -0400 Subject: [PATCH 0619/1080] main: Do not skip over backslash floowed by space or tab Fixes #539. --- highlighters/main/main-highlighter.zsh | 2 +- .../main/test-data/backslash-space.zsh | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/backslash-space.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 08747ab..2a5b8c4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -384,7 +384,7 @@ _zsh_highlight_highlighter_main_paint() # - 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:]]|\\[[:space:]])##)* ]]; then + if [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')##)* ]]; then # The first, outer parenthesis integer offset="${#match[1]}" else diff --git a/highlighters/main/test-data/backslash-space.zsh b/highlighters/main/test-data/backslash-space.zsh new file mode 100644 index 0000000..0d8a63c --- /dev/null +++ b/highlighters/main/test-data/backslash-space.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=$'echo \\ \'foo\' ; ls' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 12 default' # \ \'foo\' + '8 12 single-quoted-argument' # 'foo' + '14 14 commandseparator' # ; + '16 17 command' # ls +) From 8a0ffe1c43b8562829274beaff456f19907201ad Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 12 Mar 2018 19:34:25 -0500 Subject: [PATCH 0620/1080] main: Allow for patterned fallbacks --- highlighters/main/main-highlighter.zsh | 57 ++++++++++++-------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2a5b8c4..d204f23 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -67,37 +67,34 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 - if (( $+argv[2] )); then - # Caller specified inheritance explicitly. - else - # Automate inheritance. - typeset -A fallback_of; fallback_of=( - alias arg0 - suffix-alias arg0 - builtin arg0 - function arg0 - command arg0 - precommand arg0 - hashed-command arg0 + # Automate inheritance. + typeset -A fallback_of; fallback_of=( + alias arg0 + suffix-alias arg0 + builtin arg0 + function arg0 + command arg0 + precommand arg0 + hashed-command arg0 + arg0_\* arg0 - path_prefix path - # The path separator fallback won't ever be used, due to the optimisation - # in _zsh_highlight_main_highlighter_highlight_path_separators(). - path_pathseparator path - path_prefix_pathseparator path_prefix + path_prefix path + # The path separator fallback won't ever be used, due to the optimisation + # in _zsh_highlight_main_highlighter_highlight_path_separators(). + path_pathseparator path + path_prefix_pathseparator path_prefix - single-quoted-argument{-unclosed,} - double-quoted-argument{-unclosed,} - dollar-quoted-argument{-unclosed,} - back-quoted-argument{-unclosed,} - ) - local needle=$1 value - while [[ -n ${value::=$fallback_of[$needle]} ]]; do - unset "fallback_of[$needle]" # paranoia against infinite loops - argv+=($value) - needle=$value - done - fi + single-quoted-argument{-unclosed,} + double-quoted-argument{-unclosed,} + dollar-quoted-argument{-unclosed,} + back-quoted-argument{-unclosed,} + ) + local needle=$1 value + while [[ -n ${value::=$fallback_of[(k)$needle]} ]]; do + unset "fallback_of[$needle]" # paranoia against infinite loops + argv+=($value) + needle=$value + done # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is # relative to $BUFFER. @@ -640,7 +637,7 @@ _zsh_highlight_highlighter_main_paint() fi fi ;; - *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res arg0 + *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res already_added=1 ;; esac From b1eb0358fa4cca998a44b0b862b8d4162ce81285 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 12 Mar 2018 20:11:59 -0500 Subject: [PATCH 0621/1080] main: Move fallback calculation to a function No functional change. --- highlighters/main/main-highlighter.zsh | 43 ++++++++++++++------------ 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d204f23..7a06ec4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -65,10 +65,30 @@ _zsh_highlight_highlighter_main_predicate() # Helper to deal with tokens crossing line boundaries. _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 + local reply shift 2 - # Automate inheritance. - typeset -A fallback_of; fallback_of=( + # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is + # relative to $BUFFER. + (( start -= $#PREBUFFER )) + (( end -= $#PREBUFFER )) + + (( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return } + (( end <= 0 )) && return + (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings + + _zsh_highlight_main_calculate_fallback $1 + _zsh_highlight_add_highlight $start $end $reply +} + +_zsh_highlight_main_add_many_region_highlights() { + for 1 2 3; do + _zsh_highlight_main_add_region_highlight $1 $2 $3 + done +} + +_zsh_highlight_main_calculate_fallback() { + local -A fallback_of; fallback_of=( alias arg0 suffix-alias arg0 builtin arg0 @@ -90,27 +110,12 @@ _zsh_highlight_main_add_region_highlight() { back-quoted-argument{-unclosed,} ) local needle=$1 value + reply=($1) while [[ -n ${value::=$fallback_of[(k)$needle]} ]]; do unset "fallback_of[$needle]" # paranoia against infinite loops - argv+=($value) + reply+=($value) needle=$value done - - # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is - # relative to $BUFFER. - (( start -= $#PREBUFFER )) - (( end -= $#PREBUFFER )) - - (( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return } - (( end <= 0 )) && return - (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings - _zsh_highlight_add_highlight $start $end "$@" -} - -_zsh_highlight_main_add_many_region_highlights() { - for 1 2 3; do - _zsh_highlight_main_add_region_highlight $1 $2 $3 - done } # Get the type of a command. From 49cc5e25b8f7b7c5743123caa69410a9a0134eb5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 14:31:15 -0600 Subject: [PATCH 0622/1080] main: Simplify interface to __stack_pop --- highlighters/main/main-highlighter.zsh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7a06ec4..96b5a61 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -198,13 +198,18 @@ _zsh_highlight_main__resolve_alias() { # the style according to $2; otherwise, set style=unknown-token. # # $1: character expected to be at the top of $braces_stack -# $2: assignment to execute it if matches +# $2: optional assignment to style it if matches +# return value is 0 if there is a match else 1 _zsh_highlight_main__stack_pop() { if [[ $braces_stack[1] == $1 ]]; then braces_stack=${braces_stack:1} - eval "$2" + if (( $+2 )); then + style=$2 + fi + return 0 else style=unknown-token + return 1 fi } @@ -512,7 +517,7 @@ _zsh_highlight_highlighter_main_paint() ;; ($'\x7d') # We're at command word, so no need to check $right_brace_is_recognised_everywhere - _zsh_highlight_main__stack_pop 'Y' style=reserved-word + _zsh_highlight_main__stack_pop 'Y' reserved-word if [[ $style == reserved-word ]]; then next_word+=':always:' fi @@ -521,13 +526,13 @@ _zsh_highlight_highlighter_main_paint() braces_stack='D'"$braces_stack" ;; ('done') - _zsh_highlight_main__stack_pop 'D' style=reserved-word + _zsh_highlight_main__stack_pop 'D' reserved-word ;; ('if') braces_stack=':?'"$braces_stack" ;; ('then') - _zsh_highlight_main__stack_pop ':' style=reserved-word + _zsh_highlight_main__stack_pop ':' reserved-word ;; ('elif') if [[ ${braces_stack[1]} == '?' ]]; then @@ -544,13 +549,13 @@ _zsh_highlight_highlighter_main_paint() fi ;; ('fi') - _zsh_highlight_main__stack_pop '?' "" + _zsh_highlight_main__stack_pop '?' ;; ('foreach') braces_stack='$'"$braces_stack" ;; ('end') - _zsh_highlight_main__stack_pop '$' style=reserved-word + _zsh_highlight_main__stack_pop '$' reserved-word ;; esac ;; @@ -633,7 +638,7 @@ _zsh_highlight_highlighter_main_paint() braces_stack='R'"$braces_stack" elif [[ $arg == $'\x29' ]]; then # end of subshell - _zsh_highlight_main__stack_pop 'R' style=reserved-word + _zsh_highlight_main__stack_pop 'R' reserved-word else if _zsh_highlight_main_highlighter_check_path; then style=$REPLY @@ -658,7 +663,7 @@ _zsh_highlight_highlighter_main_paint() in_array_assignment=false next_word+=':start:' else - _zsh_highlight_main__stack_pop 'R' style=reserved-word + _zsh_highlight_main__stack_pop 'R' reserved-word fi;; $'\x28\x29') # possibly a function definition if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word @@ -673,7 +678,7 @@ _zsh_highlight_highlighter_main_paint() # # Additionally, `tt(})' is recognized in any position if neither the # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. - _zsh_highlight_main__stack_pop 'Y' style=reserved-word + _zsh_highlight_main__stack_pop 'Y' reserved-word if [[ $style == reserved-word ]]; then next_word+=':always:' fi From dbce7317c78a4cec5cb6ae341a147e9f4cd30d98 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 14:34:46 -0600 Subject: [PATCH 0623/1080] main: Add buf_offset variable No functional 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 96b5a61..e53bd8b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -68,10 +68,9 @@ _zsh_highlight_main_add_region_highlight() { local reply shift 2 - # The calculation was relative to $PREBUFFER$BUFFER, but region_highlight is - # relative to $BUFFER. - (( start -= $#PREBUFFER )) - (( end -= $#PREBUFFER )) + # The calculation was relative to $buf but region_highlight is relative to $BUFFER. + (( start += buf_offset )) + (( end += buf_offset )) (( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return } (( end <= 0 )) && return @@ -228,7 +227,7 @@ _zsh_highlight_highlighter_main_paint() fi ## Variable declarations and initializations - local start_pos=0 end_pos highlight_glob=true arg style + local start_pos=0 end_pos buf_offset=-$#PREBUFFER highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS From 81e89a88009f6c69fb7bcbea28b1b86c3364e125 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 14:45:47 -0600 Subject: [PATCH 0624/1080] main: Reorder declarations for next commit No functional change. --- highlighters/main/main-highlighter.zsh | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e53bd8b..62063a7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -226,24 +226,10 @@ _zsh_highlight_highlighter_main_paint() return fi - ## Variable declarations and initializations - local start_pos=0 end_pos buf_offset=-$#PREBUFFER highlight_glob=true arg style - local in_array_assignment=false # true between 'a=(' and the matching ')' typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW local -a options_to_set # used in callees - local buf="$PREBUFFER$BUFFER" - integer len="${#buf}" - - # "R" for round - # "Q" for square - # "Y" for curly - # "D" for do/done - # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) - # "?" for 'if'/'fi'; also checked by 'elif'/'else' - # ":" for 'then' - local braces_stack if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false @@ -285,8 +271,22 @@ _zsh_highlight_highlighter_main_paint() '!' # reserved word; unrelated to $histchars[1] ) + integer start_pos=0 end_pos buf_offset=-$#PREBUFFER + local buf="$PREBUFFER$BUFFER" highlight_glob=true arg style + local in_array_assignment=false # true between 'a=(' and the matching ')' + integer len=$#buf local -a match mbegin mend + # "R" for round + # "Q" for square + # "Y" for curly + # "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' + # ":" for 'then' + local braces_stack + # State machine # # The states are: From ead8f8a1fc88207a504e6c8db71954be54207d79 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 14:47:52 -0600 Subject: [PATCH 0625/1080] main: Split highlighting code into another function This will allow for highlighting $( ) and similar. --- highlighters/main/main-highlighter.zsh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 62063a7..04f218b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -271,8 +271,16 @@ _zsh_highlight_highlighter_main_paint() '!' # reserved word; unrelated to $histchars[1] ) - integer start_pos=0 end_pos buf_offset=-$#PREBUFFER - local buf="$PREBUFFER$BUFFER" highlight_glob=true arg style + _zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' "$PREBUFFER$BUFFER" +} + +# $1 is the offset of $3 from the parent buffer. Added to the returned highlights. +# $2 is the initial braces_stack (for a closing paren). +# $3 is the buffer to highlight. +_zsh_highlight_main_highlighter_highlight_list() +{ + integer start_pos=0 end_pos buf_offset=$1 + local buf=$3 highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' integer len=$#buf local -a match mbegin mend @@ -285,7 +293,7 @@ _zsh_highlight_highlighter_main_paint() # "$" for 'end' (matches 'foreach' always; also used with cshjunkiequotes in repeat/while) # "?" for 'if'/'fi'; also checked by 'elif'/'else' # ":" for 'then' - local braces_stack + local braces_stack=$2 # State machine # From ce592bd5c7779124f66e0dbd500a35d279d9ddfe Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 14:58:01 -0600 Subject: [PATCH 0626/1080] main: Move highlighting to _main_paint This allows for callees to prepend highlights before $reply after the length of the feature (e.g. command substution) is known. --- highlighters/main/main-highlighter.zsh | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 04f218b..6d4062f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -65,19 +65,13 @@ _zsh_highlight_highlighter_main_predicate() # Helper to deal with tokens crossing line boundaries. _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 - local reply shift 2 # The calculation was relative to $buf but region_highlight is relative to $BUFFER. (( start += buf_offset )) (( end += buf_offset )) - (( start >= end )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start($start) >= end($end)"; return } - (( end <= 0 )) && return - (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings - - _zsh_highlight_main_calculate_fallback $1 - _zsh_highlight_add_highlight $start $end $reply + list_highlights+=($start $end $1) } _zsh_highlight_main_add_many_region_highlights() { @@ -229,7 +223,8 @@ _zsh_highlight_highlighter_main_paint() typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW - local -a options_to_set # used in callees + local -a options_to_set reply # used in callees + local REPLY if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false @@ -272,18 +267,32 @@ _zsh_highlight_highlighter_main_paint() ) _zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' "$PREBUFFER$BUFFER" + + # end is a reserved word + local start end_ style + for start end_ style in $reply; do + (( start >= end_ )) && { print -r -- >&2 "zsh-syntax-highlighting: BUG: _zsh_highlight_highlighter_main_paint: start($start) >= end($end_)"; return } + (( end_ <= 0 )) && continue + (( start < 0 )) && start=0 # having start<0 is normal with e.g. multiline strings + _zsh_highlight_main_calculate_fallback $style + _zsh_highlight_add_highlight $start $end_ $reply + done } # $1 is the offset of $3 from the parent buffer. Added to the returned highlights. # $2 is the initial braces_stack (for a closing paren). # $3 is the buffer to highlight. +# Returns: +# $REPLY: $buf[REPLY] is the last character parsed. +# $reply is an array of region_highlight additions. _zsh_highlight_main_highlighter_highlight_list() { integer start_pos=0 end_pos buf_offset=$1 local buf=$3 highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' integer len=$#buf - local -a match mbegin mend + local -a match mbegin mend list_highlights + list_highlights=() # "R" for round # "Q" for square @@ -741,6 +750,9 @@ _zsh_highlight_main_highlighter_highlight_list() # Stall $this_word. fi done + REPLY=$(( end_pos - 1 )) + reply=($list_highlights) + return } # Check if $arg is variable assignment From b75169597e1ad4ca1371dd7ea055c50304ab99c2 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 15:03:02 -0600 Subject: [PATCH 0627/1080] main: Highlight command substitutions --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 31 ++++++++++++++++--- highlighters/main/test-data/dollar-paren.zsh | 3 +- .../test-data/redirection-in-cmdsubst.zsh | 3 ++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index c14b32f..71c8ec3 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -32,6 +32,7 @@ This highlighter defines the following styles: * `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default) * `globbing` - globbing expressions (`*.txt`) * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`) +* `command-substitution` - command substitutions (`$(echo foo)`) * `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 6d4062f..c80a9e6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -40,6 +40,7 @@ : ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} +: ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} @@ -653,7 +654,12 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word braces_stack='R'"$braces_stack" elif [[ $arg == $'\x29' ]]; then - # end of subshell + # end of subshell or command substitution + if _zsh_highlight_main__stack_pop 'S'; then + REPLY=$start_pos + reply=($list_highlights) + return + fi _zsh_highlight_main__stack_pop 'R' reserved-word else if _zsh_highlight_main_highlighter_check_path; then @@ -679,6 +685,11 @@ _zsh_highlight_main_highlighter_highlight_list() in_array_assignment=false next_word+=':start:' else + if _zsh_highlight_main__stack_pop 'S'; then + REPLY=$start_pos + reply=($list_highlights) + return + fi _zsh_highlight_main__stack_pop 'R' reserved-word fi;; $'\x28\x29') # possibly a function definition @@ -829,8 +840,8 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight start_pos to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i path_eligible=1 style - local -a highlights reply + local base_style=default i path_eligible=1 start style + local -a highlights local -a match mbegin mend local MATCH; integer MBEGIN MEND @@ -870,6 +881,13 @@ _zsh_highlight_main_highlighter_highlight_argument() (( i = REPLY )) highlights+=($reply) continue + elif [[ $arg[i+1] == $'\x28' ]]; then + start=$i + (( i += 2 )) + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $arg[i,end_pos] + (( i += REPLY )) + highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) command-substitution $reply) + continue fi while [[ $arg[i+1] == [\^=~#+] ]]; do (( i += 1 )) @@ -969,7 +987,12 @@ _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 - # Highlight just the '$'. + (( i += 2 )) + saved_reply=($reply) + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $arg[i,end_pos] + (( i += REPLY )) + reply=($saved_reply $j $(( start_pos + i )) command-substitution $reply) + continue else continue fi diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index 2a1aecd..c64a764 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -34,5 +34,6 @@ expected_region_highlight=( '1 1 builtin' # : '3 8 default' # "$(:)" '3 8 double-quoted-argument' # "$(:)" - '4 4 dollar-double-quoted-argument' # $ + '4 7 command-substitution' # $(:) + '6 6 builtin' # : ) diff --git a/highlighters/main/test-data/redirection-in-cmdsubst.zsh b/highlighters/main/test-data/redirection-in-cmdsubst.zsh index ac7a365..d5020f0 100644 --- a/highlighters/main/test-data/redirection-in-cmdsubst.zsh +++ b/highlighters/main/test-data/redirection-in-cmdsubst.zsh @@ -33,4 +33,7 @@ BUFFER=$': $( Date: Tue, 20 Mar 2018 21:03:22 -0500 Subject: [PATCH 0628/1080] main: Track if $buf has the end of $BUFFER This will allow for correct path_prefix highlighting in backticks. --- highlighters/main/main-highlighter.zsh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c80a9e6..2592359 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -267,7 +267,7 @@ _zsh_highlight_highlighter_main_paint() '!' # reserved word; unrelated to $histchars[1] ) - _zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' "$PREBUFFER$BUFFER" + _zsh_highlight_main_highlighter_highlight_list -$#PREBUFFER '' 1 "$PREBUFFER$BUFFER" # end is a reserved word local start end_ style @@ -280,16 +280,17 @@ _zsh_highlight_highlighter_main_paint() done } -# $1 is the offset of $3 from the parent buffer. Added to the returned highlights. +# $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 the buffer to highlight. +# $3 is 1 if $4 contains the end of $BUFFER, else 0. +# $4 is the buffer to highlight. # Returns: # $REPLY: $buf[REPLY] is the last character parsed. # $reply is an array of region_highlight additions. _zsh_highlight_main_highlighter_highlight_list() { - integer start_pos=0 end_pos buf_offset=$1 - local buf=$3 highlight_glob=true arg style + integer start_pos=0 end_pos buf_offset=$1 has_end=$3 + local buf=$4 highlight_glob=true arg style local in_array_assignment=false # true between 'a=(' and the matching ')' integer len=$#buf local -a match mbegin mend list_highlights @@ -825,7 +826,7 @@ _zsh_highlight_main_highlighter_check_path() [[ ! -d ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. - if [[ ${BUFFER[1]} != "-" && $len == $end_pos ]] && + if (( has_end && (len == end_pos) )) && [[ $WIDGET != zle-line-finish ]]; then local -a tmp tmp=( ${expanded_path}*(N) ) @@ -884,7 +885,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 $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] (( i += REPLY )) highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) command-substitution $reply) continue @@ -989,7 +990,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() elif [[ $arg[i+1] == $'\x28' ]]; then (( i += 2 )) saved_reply=($reply) - _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $arg[i,end_pos] + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] (( i += REPLY )) reply=($saved_reply $j $(( start_pos + i )) command-substitution $reply) continue From 9db393309e38c1fae82a5cc06abddc190e3161bb Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 12 Mar 2018 19:29:09 -0500 Subject: [PATCH 0629/1080] main: Recurse into backtick command substitutions --- highlighters/main/main-highlighter.zsh | 68 ++++++++++++++++--- .../main/test-data/back-quoted-argument.zsh | 11 ++- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2592359..b1d614c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1084,21 +1084,67 @@ _zsh_highlight_main_highlighter_highlight_dollar_quote() REPLY=$i } -# Highlight backtick subshells +# Highlight backtick substitutions _zsh_highlight_main_highlighter_highlight_backtick() { - local arg1=$1 i=$1 q=\` style + # buf is the contents of the backticks with a layer of backslashes removed. + # last is the index of arg for the start of the string to be copied into buf. + # It is either one past the beginning backtick or one past the last backslash. + # offset is a count of consumed \ (the delta between buf and arg). + # offsets is an array indexed by buf offset of when the delta between buf and arg changes. + # It is sparse, so search backwards to the last value + # unclosed is an array of one highlight to append to reply if this back-quoted-argument + # is closed and there is an unclosed back-quoted-argument in buf. + local buf highlight style=back-quoted-argument-unclosed + local -i arg1=$1 end_ i=$1 last offset=0 start subshell_has_end=0 + local -a highlight_zone highlights offsets unclosed reply=() - while i=$arg[(ib:i+1:)$q]; [[ $arg[i-1] == '\' && $i -lt $(( end_pos - start_pos )) ]]; do done - if [[ $arg[i] == '`' ]]; then - style=back-quoted-argument - else - # If unclosed, i points past the end - (( i-- )) - style=back-quoted-argument-unclosed - fi - reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style) + 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 + buf=$buf$arg[last,i] + offsets[i-arg1-offset]='' # So we never index past the end + (( i-- )) + subshell_has_end=$(( has_end && (start_pos + i == len) )) + break + fi + + if [[ $arg[i] == '\' ]]; then + (( i++ )) + # POSIX XCU 2.6.3 + if [[ $arg[i] == ('$'|'`'|'\') ]]; then + buf=$buf$arg[last,i-2] + (( offset++ )) + # offsets is relative to buf, so adjust by -arg1 + offsets[i-arg1-offset]=$offset + else + buf=$buf$arg[last,i-1] + fi + else # it's an unquoted ` and this is the end + style=back-quoted-argument + buf=$buf$arg[last,i-1] + offsets[i-arg1-offset]='' # So we never index past the end + break + fi + last=$i + done + + _zsh_highlight_main_highlighter_highlight_list 0 '' $subshell_has_end $buf + + # Munge the reply to account for removed backslashes + for start end_ highlight in $reply; do + start=$(( start_pos + arg1 + start + offsets[(Rb:start:)?*] )) + end_=$(( start_pos + arg1 + end_ + offsets[(Rb:end_:)?*] )) + highlights+=($start $end_ $highlight) + if [[ $highlight == back-quoted-argument-unclosed && $style == back-quoted-argument ]]; then + # An inner backtick command substitution is unclosed, but this level is closed + unclosed=($(( start_pos + i - 1)) $(( start_pos + i )) unknown-token) + fi + done + + reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $highlights $unclosed) REPLY=$i } diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index 346d9fa..8b13729 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -27,16 +27,25 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -# 42 is in the command position in a nested subshell. BUFFER='echo `echo \`42\`` "is `echo equal` to" `echo 6 times 9' expected_region_highlight=( "1 4 builtin" # echo "6 18 default" # `echo \`42\`` "6 18 back-quoted-argument" # `echo \`42\`` + "7 10 builtin" # echo + "12 17 default" # \`42\` + "12 17 back-quoted-argument" # \`42\` + "14 15 unknown-token" # 42 "20 39 default" # "is `echo equal` to" "20 39 double-quoted-argument" # "is `echo equal` to" "24 35 back-quoted-argument" # `echo equal` + "25 28 builtin" # echo + "30 34 default" # equal "41 55 default" # `echo 6 times 9 "41 55 back-quoted-argument-unclosed" # `echo 6 times 9 + "42 45 builtin" # echo + "47 47 default" # 6 + "49 53 default" # times + "55 55 default" # 9 ) From 3ac7d1c785798077171db60ab3855ae69909ed93 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 15 Mar 2018 07:27:00 -0500 Subject: [PATCH 0630/1080] main: Add test for nested backticks; summon Cthulhu --- highlighters/main/test-data/cthulhu.zsh | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 highlighters/main/test-data/cthulhu.zsh diff --git a/highlighters/main/test-data/cthulhu.zsh b/highlighters/main/test-data/cthulhu.zsh new file mode 100644 index 0000000..0350640 --- /dev/null +++ b/highlighters/main/test-data/cthulhu.zsh @@ -0,0 +1,62 @@ +#!/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 +# ------------------------------------------------------------------------------------------------- + +# 0000000 0 01111111111222222 222233333 3 333344 4 4 444444555555555 5 6 6666 6 6 6667777777777888 8 8 88888999 9 9999 9 9 00 00 0000001111 +# 1234567 8 90123456789012345 678901234 5 678901 2 3 456789012345678 9 0 1234 5 6 7890123456789012 3 4 56789012 3 4567 8 9 01 23 4567890123 +BUFFER=$'echo Ph\\\'ng`echo lui "mg"\\`echo lw\\\'nafh \\\\\\`echo Cthu"lhu\\\\\\` R\\\\\'ly$(echo eh wag\\\\\\`echo h\\\'nag\\\\\\`\'l\' fht)agn`' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 113 default' # Ph\'ng`echo lui "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn` + '12 113 back-quoted-argument' # `echo lui "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn` + '13 16 builtin' # echo + '18 20 default' # lui + '22 112 default' # "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn + '22 25 double-quoted-argument' # "mg" + '26 112 back-quoted-argument-unclosed' # \`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn + '28 31 builtin' # echo + '33 40 default' # lw\'nafh + '42 62 default' # \\\`echo Cthu"lhu\\\` + '42 62 back-quoted-argument' # \\\`echo Cthu"lhu\\\` + '46 49 builtin' # echo + '51 58 default' # Cthu"lhu + '55 58 double-quoted-argument-unclosed' # "lhu + '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) + '72 75 builtin' # echo + '77 78 default' # eh + '80 104 default' # wag\\\`echo h\'nag\\\`'l' + '83 101 back-quoted-argument' # \\\`echo h\'nag\\\` + '87 90 builtin' # echo + '92 97 default' # h\'nag + '102 104 single-quoted-argument' # 'l' + '106 108 default' # fht + '113 113 unknown-token' # ` +) From 08d4401faef4539cdf0c1a2c9626e4e8ed6cb0f8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 15:03:25 -0600 Subject: [PATCH 0631/1080] main: Highlight <( ) and >( ) process substitutions Fixes #494 --- docs/highlighters/main.md | 1 + highlighters/main/main-highlighter.zsh | 11 +++++++++++ highlighters/main/test-data/redirection2.zsh | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index 71c8ec3..af7815e 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -33,6 +33,7 @@ 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)`) +* `process-substitution` - process substitutions (`<(echo foo)`) * `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 b1d614c..5015d65 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -41,6 +41,7 @@ : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=fg=magenta} +: ${ZSH_HIGHLIGHT_STYLES[process-substitution]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} @@ -896,6 +897,16 @@ _zsh_highlight_main_highlighter_highlight_argument() if [[ $arg[i+1] == [*@#?$!-] ]]; then (( i += 1 )) fi;; + [\<\>]) + 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] + (( i += REPLY )) + highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) process-substitution $reply) + continue + fi + ;| *) if $highlight_glob && [[ ${arg[$i]} =~ ^[*?] || ${arg:$i-1} =~ ^\<[0-9]*-[0-9]*\> ]]; then highlights+=($(( start_pos + i - 1 )) $(( start_pos + i + $#MATCH - 1)) globbing) diff --git a/highlighters/main/test-data/redirection2.zsh b/highlighters/main/test-data/redirection2.zsh index 1a1588d..7a8c6e1 100644 --- a/highlighters/main/test-data/redirection2.zsh +++ b/highlighters/main/test-data/redirection2.zsh @@ -31,7 +31,9 @@ BUFFER='ls >(wc) | nl' expected_region_highlight=( "1 2 command" # ls - "4 8 process-substitution 'issue #494'" # >(wc) + "4 8 default" # >(wc) + "4 8 process-substitution" # >(wc) + "6 7 command" # wc "10 10 commandseparator" # | "12 13 command" # nl ) From beae08776a18b1509e056d4c9bc93089b07016e8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 10 Mar 2018 15:05:03 -0600 Subject: [PATCH 0632/1080] main: Add test for embedded process substitution --- .../main/test-data/process-substitution.zsh | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 highlighters/main/test-data/process-substitution.zsh diff --git a/highlighters/main/test-data/process-substitution.zsh b/highlighters/main/test-data/process-substitution.zsh new file mode 100644 index 0000000..d4bb378 --- /dev/null +++ b/highlighters/main/test-data/process-substitution.zsh @@ -0,0 +1,41 @@ +#!/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=<(echo bar) "<(:)"' + +expected_region_highlight=( + '1 1 builtin' # : + '3 19 double-hyphen-option' # --foo=<(echo bar) + '9 19 process-substitution' # <(echo bar) + '11 14 builtin' # echo + '16 18 default' # bar + '21 26 default' # "<(:)" + '21 26 double-quoted-argument' # "<(:)" +) From 73640b79eaf3f0d50c632b251f44ad410fd206ac Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 14 Mar 2018 22:46:49 -0500 Subject: [PATCH 0633/1080] main: Change conditional to a switch Prepares for next commit. No functional change. --- highlighters/main/main-highlighter.zsh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5015d65..7b71ec7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -848,14 +848,16 @@ _zsh_highlight_main_highlighter_highlight_argument() local -a match mbegin mend local MATCH; integer MBEGIN MEND - if [[ $arg[1] == - ]]; then - if [[ $arg[2] == - ]]; then - base_style=double-hyphen-option - else - base_style=single-hyphen-option - fi - path_eligible=0 - fi + case "$arg[1]" in + '-') + if [[ $arg[2] == - ]]; then + base_style=double-hyphen-option + else + base_style=single-hyphen-option + fi + path_eligible=0 + ;; + esac for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in From c0e64fe13178a6614a18ed7c0da52b8d2266a02b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 14 Mar 2018 22:47:33 -0500 Subject: [PATCH 0634/1080] main: Highlight =( ) process substitutions --- highlighters/main/main-highlighter.zsh | 11 +++++++++-- ...process-substitution-redirection-isnt-globbing.zsh | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 7b71ec7..2373ccd 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -842,7 +842,7 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight start_pos to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i path_eligible=1 start style + local base_style=default i=1 path_eligible=1 start style local -a highlights local -a match mbegin mend @@ -857,9 +857,16 @@ _zsh_highlight_main_highlighter_highlight_argument() fi path_eligible=0 ;; + '=') + if [[ $arg[2] == $'\x28' ]]; then + (( i += 2 )) + _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + (( i += REPLY )) + highlights+=($start_pos $(( start_pos + i )) process-substitution $reply) + fi esac - for (( i = 1 ; i <= end_pos - start_pos ; i += 1 )); do + for (( ; i <= end_pos - start_pos ; i += 1 )); do case "$arg[$i]" in "\\") (( i += 1 )); continue;; "'") diff --git a/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh index 05c11b8..d5de3fd 100644 --- a/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh +++ b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh @@ -33,4 +33,7 @@ BUFFER=$': =( Date: Wed, 14 Mar 2018 22:56:21 -0500 Subject: [PATCH 0635/1080] main: Add test for =( ) process substitution --- .../main/test-data/process-substitution2.zsh | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 highlighters/main/test-data/process-substitution2.zsh diff --git a/highlighters/main/test-data/process-substitution2.zsh b/highlighters/main/test-data/process-substitution2.zsh new file mode 100644 index 0000000..da3f41f --- /dev/null +++ b/highlighters/main/test-data/process-substitution2.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 =(:) a=(:) =(echo foo' + +expected_region_highlight=( + '1 4 builtin' # echo + '6 9 default' # =(:) + '6 9 process-substitution' # =(:) + '8 8 builtin' # : + '11 15 default' # a=(:) + '17 26 default' # =(echo foo + '17 26 process-substitution' # =(echo foo + '19 22 builtin' # echo + '24 26 default' # foo +) From 57e451b531421284c98fef015af65eded1054067 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 14 Mar 2018 23:03:35 -0500 Subject: [PATCH 0636/1080] main: Add test for unclosed command substitution --- .../command-substitution-unclosed.zsh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/command-substitution-unclosed.zsh diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh new file mode 100644 index 0000000..6a2b73d --- /dev/null +++ b/highlighters/main/test-data/command-substitution-unclosed.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=$': foo$(echo bar' + +expected_region_highlight=( + '1 1 builtin' # : + '3 15 default' # foo$(echo bar + '6 15 command-substitution' # $(echo bar + '8 11 builtin' # echo + '13 15 default' # bar +) From 13d332af95d959be9d0decec74b8ae732092abc2 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 21 Mar 2018 19:24:53 -0500 Subject: [PATCH 0637/1080] main: Make _check_path's argument explicit No functional change. --- highlighters/main/main-highlighter.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2373ccd..29ba769 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -664,7 +664,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main__stack_pop 'R' reserved-word else - if _zsh_highlight_main_highlighter_check_path; then + if _zsh_highlight_main_highlighter_check_path $arg; then style=$REPLY else style=unknown-token @@ -789,12 +789,12 @@ _zsh_highlight_main_highlighter_highlight_path_separators() done } -# Check if $arg is a path. +# 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). _zsh_highlight_main_highlighter_check_path() { - _zsh_highlight_main_highlighter_expand_path $arg; + _zsh_highlight_main_highlighter_expand_path $1 local expanded_path="$REPLY" tmp_path REPLY=path @@ -823,7 +823,7 @@ _zsh_highlight_main_highlighter_check_path() [[ -e "$cdpath_dir/$expanded_path" ]] && return 0 done - # If dirname($arg) doesn't exist, neither does $arg. + # If dirname($1) doesn't exist, neither does $1. [[ ! -d ${expanded_path:h} ]] && return 1 # If this word ends the buffer, check if it's the prefix of a valid path. @@ -928,7 +928,7 @@ _zsh_highlight_main_highlighter_highlight_argument() esac done - if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path; then + if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg; then base_style=$REPLY _zsh_highlight_main_highlighter_highlight_path_separators $base_style highlights+=($reply) From 12e01336f1e3bd049b3e91fad3e6d961279fdd34 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 21 Mar 2018 19:43:19 -0500 Subject: [PATCH 0638/1080] main: Start _highlight_argument at $1 No functional change. --- highlighters/main/main-highlighter.zsh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 29ba769..d235a95 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -722,7 +722,7 @@ _zsh_highlight_main_highlighter_highlight_list() elif (( in_redirection == 2 )); then style=redirection else - _zsh_highlight_main_highlighter_highlight_argument + _zsh_highlight_main_highlighter_highlight_argument 1 already_added=1 fi ;; @@ -838,19 +838,19 @@ _zsh_highlight_main_highlighter_check_path() return 1 } -# Highlight an argument and possibly special chars in quotes -# This command will at least highlight start_pos to end_pos with the default style +# 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 _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i=1 path_eligible=1 start style + local base_style=default i=$1 path_eligible=1 start style local -a highlights local -a match mbegin mend local MATCH; integer MBEGIN MEND - case "$arg[1]" in + case "$arg[i]" in '-') - if [[ $arg[2] == - ]]; then + if [[ $arg[i+1] == - ]]; then base_style=double-hyphen-option else base_style=single-hyphen-option @@ -858,11 +858,11 @@ _zsh_highlight_main_highlighter_highlight_argument() path_eligible=0 ;; '=') - if [[ $arg[2] == $'\x28' ]]; then + 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] (( i += REPLY )) - highlights+=($start_pos $(( start_pos + i )) process-substitution $reply) + highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) process-substitution $reply) fi esac @@ -928,13 +928,13 @@ _zsh_highlight_main_highlighter_highlight_argument() esac done - if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg; then + if (( path_eligible )) && _zsh_highlight_main_highlighter_check_path $arg[$1,end_pos]; then base_style=$REPLY _zsh_highlight_main_highlighter_highlight_path_separators $base_style highlights+=($reply) fi - highlights=($start_pos $end_pos $base_style $highlights) + highlights=($(( start_pos + $1 - 1 )) $end_pos $base_style $highlights) _zsh_highlight_main_add_many_region_highlights $highlights } From c06e5e95dc35c794a135a736cc6725d255429339 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 21 Mar 2018 19:51:48 -0500 Subject: [PATCH 0639/1080] main: Correct array assignment check --- highlighters/main/main-highlighter.zsh | 3 +- .../main/test-data/assign-not-array.zsh | 35 +++++++++++++++++++ .../main/test-data/assign-not-array2.zsh | 35 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 highlighters/main/test-data/assign-not-array.zsh create mode 100644 highlighters/main/test-data/assign-not-array2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d235a95..cfac262 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -610,7 +610,8 @@ _zsh_highlight_main_highlighter_highlight_list() hashed) style=hashed-command;; none) if _zsh_highlight_main_highlighter_check_assign; then style=assign - if [[ $arg[-1] == '(' ]]; then + local i=$(( arg[(i)=] + 1 )) + if [[ $arg[i] == '(' ]]; then in_array_assignment=true else # assignment to a scalar parameter. diff --git a/highlighters/main/test-data/assign-not-array.zsh b/highlighters/main/test-data/assign-not-array.zsh new file mode 100644 index 0000000..658cc89 --- /dev/null +++ b/highlighters/main/test-data/assign-not-array.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# 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='a=foo( bar ) :' + +expected_region_highlight=( + '1 12 assign' # a=foo( bar ) + '14 14 builtin' # : +) diff --git a/highlighters/main/test-data/assign-not-array2.zsh b/highlighters/main/test-data/assign-not-array2.zsh new file mode 100644 index 0000000..3ca2214 --- /dev/null +++ b/highlighters/main/test-data/assign-not-array2.zsh @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------------------- +# 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='a=foo\( :' + +expected_region_highlight=( + '1 7 assign' # a=foo\( + '9 9 builtin' # : +) From 932eb380e24b52839725ff8813e42916778cbd3a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 21 Mar 2018 19:59:53 -0500 Subject: [PATCH 0640/1080] main: Highlight the value of an assignment --- highlighters/main/main-highlighter.zsh | 5 +++++ highlighters/main/test-data/assign-argv.zsh | 3 +++ highlighters/main/test-data/assign-array3.zsh | 1 + highlighters/main/test-data/assign-not-array.zsh | 1 + highlighters/main/test-data/assign-not-array2.zsh | 1 + highlighters/main/test-data/assign-semicolon.zsh | 1 + highlighters/main/test-data/assign-subshell.zsh | 1 + highlighters/main/test-data/assign.zsh | 1 + 8 files changed, 14 insertions(+) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index cfac262..f0f2215 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -610,6 +610,8 @@ _zsh_highlight_main_highlighter_highlight_list() hashed) style=hashed-command;; none) if _zsh_highlight_main_highlighter_check_assign; then style=assign + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style + already_added=1 local i=$(( arg[(i)=] + 1 )) if [[ $arg[i] == '(' ]]; then in_array_assignment=true @@ -617,6 +619,9 @@ _zsh_highlight_main_highlighter_highlight_list() # assignment to a scalar parameter. # (For array assignments, the command doesn't start until the ")" token.) next_word+=':start:' + if (( start_pos + i <= end_pos )); then + highlight_glob=false _zsh_highlight_main_highlighter_highlight_argument $i + fi fi elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion diff --git a/highlighters/main/test-data/assign-argv.zsh b/highlighters/main/test-data/assign-argv.zsh index fdf30aa..ec5acc2 100644 --- a/highlighters/main/test-data/assign-argv.zsh +++ b/highlighters/main/test-data/assign-argv.zsh @@ -27,9 +27,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +touch foo BUFFER='42=foo 43+=bar' expected_region_highlight=( "1 6 assign" # 42=foo + "4 6 path" # foo "8 14 assign" # 43+=bar + "12 14 default" # bar ) diff --git a/highlighters/main/test-data/assign-array3.zsh b/highlighters/main/test-data/assign-array3.zsh index 4e20cfc..986d71f 100644 --- a/highlighters/main/test-data/assign-array3.zsh +++ b/highlighters/main/test-data/assign-array3.zsh @@ -35,4 +35,5 @@ expected_region_highlight=( "10 14 default" # world "15 15 assign" # ) "17 20 assign" # b=42 + "19 20 default" # 42 ) diff --git a/highlighters/main/test-data/assign-not-array.zsh b/highlighters/main/test-data/assign-not-array.zsh index 658cc89..651ab80 100644 --- a/highlighters/main/test-data/assign-not-array.zsh +++ b/highlighters/main/test-data/assign-not-array.zsh @@ -31,5 +31,6 @@ BUFFER='a=foo( bar ) :' expected_region_highlight=( '1 12 assign' # a=foo( bar ) + '3 12 default' # foo( bar ) '14 14 builtin' # : ) diff --git a/highlighters/main/test-data/assign-not-array2.zsh b/highlighters/main/test-data/assign-not-array2.zsh index 3ca2214..dfda106 100644 --- a/highlighters/main/test-data/assign-not-array2.zsh +++ b/highlighters/main/test-data/assign-not-array2.zsh @@ -31,5 +31,6 @@ BUFFER='a=foo\( :' expected_region_highlight=( '1 7 assign' # a=foo\( + '3 7 default' # foo\( '9 9 builtin' # : ) diff --git a/highlighters/main/test-data/assign-semicolon.zsh b/highlighters/main/test-data/assign-semicolon.zsh index fe55b6a..f748c94 100644 --- a/highlighters/main/test-data/assign-semicolon.zsh +++ b/highlighters/main/test-data/assign-semicolon.zsh @@ -31,6 +31,7 @@ BUFFER='A=1; echo hello world' expected_region_highlight=( "1 3 assign" # A=1 + "3 3 default" # 1 "4 4 commandseparator" # ; "6 9 builtin" # echo "11 15 default" # hello diff --git a/highlighters/main/test-data/assign-subshell.zsh b/highlighters/main/test-data/assign-subshell.zsh index fc04f6b..2022889 100644 --- a/highlighters/main/test-data/assign-subshell.zsh +++ b/highlighters/main/test-data/assign-subshell.zsh @@ -32,5 +32,6 @@ BUFFER='(A=1)' expected_region_highlight=( "1 1 reserved-word" # ( "2 4 assign" # A=1 + "4 4 default" # 1 "5 5 reserved-word" # ) ) diff --git a/highlighters/main/test-data/assign.zsh b/highlighters/main/test-data/assign.zsh index 36fa5d1..6e797ac 100644 --- a/highlighters/main/test-data/assign.zsh +++ b/highlighters/main/test-data/assign.zsh @@ -31,6 +31,7 @@ BUFFER='A=1 b=("foo" bar)' expected_region_highlight=( "1 3 assign" # A=1 + "3 3 default" # 1 "5 7 assign" # b=( "8 12 default" # "foo" "8 12 double-quoted-argument" # "foo" From 8a93b852cac63e258115d0c5973072d0c85e0fdc Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 27 Mar 2018 23:11:21 -0500 Subject: [PATCH 0641/1080] main: Add test for command substitution in assignment --- .../command-substitution-in-assignment.zsh | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 highlighters/main/test-data/command-substitution-in-assignment.zsh diff --git a/highlighters/main/test-data/command-substitution-in-assignment.zsh b/highlighters/main/test-data/command-substitution-in-assignment.zsh new file mode 100644 index 0000000..db82b7c --- /dev/null +++ b/highlighters/main/test-data/command-substitution-in-assignment.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=$(echo bar) :' + +expected_region_highlight=( + '1 15 assign' # foo=$(echo bar) + '5 15 default' # $(echo bar) + '5 15 command-substitution' # $(echo bar) + '7 10 builtin' # echo + '12 14 default' # bar + '17 17 builtin' # : +) From 9616bfdb204359b1dd813deee6b279fc750d2fc1 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 4 Apr 2018 23:10:54 -0500 Subject: [PATCH 0642/1080] main: Ignore zsh 5.0.8 off by one bug in tests --- highlighters/main/test-data/command-substitution-unclosed.zsh | 4 ++++ highlighters/main/test-data/process-substitution2.zsh | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh index 6a2b73d..198e710 100644 --- a/highlighters/main/test-data/command-substitution-unclosed.zsh +++ b/highlighters/main/test-data/command-substitution-unclosed.zsh @@ -37,3 +37,7 @@ expected_region_highlight=( '8 11 builtin' # echo '13 15 default' # bar ) + +if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug + expected_region_highlight[2]='3 16 default' # foo$(echo bar +fi diff --git a/highlighters/main/test-data/process-substitution2.zsh b/highlighters/main/test-data/process-substitution2.zsh index da3f41f..dff3108 100644 --- a/highlighters/main/test-data/process-substitution2.zsh +++ b/highlighters/main/test-data/process-substitution2.zsh @@ -41,3 +41,7 @@ expected_region_highlight=( '19 22 builtin' # echo '24 26 default' # foo ) + +if [[ ${(z):-'$('} == '$( ' ]]; then # ignore zsh 5.0.8 bug + expected_region_highlight[6]='17 27 default' # =(echo foo +fi From 472c71c1fa67361ec6a57441e4b73cf06629eb26 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 14 Apr 2018 08:31:15 -0500 Subject: [PATCH 0643/1080] main: Support the glob_assign option --- highlighters/main/main-highlighter.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f0f2215..cc3078e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -620,7 +620,11 @@ _zsh_highlight_main_highlighter_highlight_list() # (For array assignments, the command doesn't start until the ")" token.) next_word+=':start:' if (( start_pos + i <= end_pos )); then - highlight_glob=false _zsh_highlight_main_highlighter_highlight_argument $i + () { + local highlight_glob=false + [[ $zsyh_user_options[globassign] == on ]] && highlight_glob=true + _zsh_highlight_main_highlighter_highlight_argument $i + } fi fi elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then From 22839d08ef92453923531561e6ac3d6c5a1a8bdc Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 14 Apr 2018 13:38:02 -0500 Subject: [PATCH 0644/1080] main: Return 0 if braces_stack is empty This allows a caller to know if the command or process substitution is complete. --- highlighters/main/main-highlighter.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index cc3078e..cce0317 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -288,6 +288,7 @@ _zsh_highlight_highlighter_main_paint() # Returns: # $REPLY: $buf[REPLY] is the last character parsed. # $reply is an array of region_highlight additions. +# exit code is 0 if the braces_stack is empty, 1 otherwise. _zsh_highlight_main_highlighter_highlight_list() { integer start_pos=0 end_pos buf_offset=$1 has_end=$3 @@ -670,7 +671,7 @@ _zsh_highlight_main_highlighter_highlight_list() if _zsh_highlight_main__stack_pop 'S'; then REPLY=$start_pos reply=($list_highlights) - return + return 0 fi _zsh_highlight_main__stack_pop 'R' reserved-word else @@ -700,7 +701,7 @@ _zsh_highlight_main_highlighter_highlight_list() if _zsh_highlight_main__stack_pop 'S'; then REPLY=$start_pos reply=($list_highlights) - return + return 0 fi _zsh_highlight_main__stack_pop 'R' reserved-word fi;; @@ -775,7 +776,7 @@ _zsh_highlight_main_highlighter_highlight_list() done REPLY=$(( end_pos - 1 )) reply=($list_highlights) - return + return $(( $#braces_stack > 0 )) } # Check if $arg is variable assignment From e86f75a840e739652b337729c14d16c2f5f71553 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 14 Apr 2018 14:00:03 -0500 Subject: [PATCH 0645/1080] main: Highlight {command,process} substitution delimiters --- docs/highlighters/main.md | 3 + highlighters/main/main-highlighter.zsh | 74 +++++++++++++++---- .../main/test-data/back-quoted-argument.zsh | 7 ++ .../command-substitution-in-assignment.zsh | 2 + .../command-substitution-unclosed.zsh | 1 + highlighters/main/test-data/cthulhu.zsh | 8 ++ highlighters/main/test-data/dollar-paren.zsh | 2 + ...substitution-redirection-isnt-globbing.zsh | 2 + .../main/test-data/process-substitution.zsh | 2 + .../main/test-data/process-substitution2.zsh | 5 +- .../test-data/redirection-in-cmdsubst.zsh | 2 + highlighters/main/test-data/redirection2.zsh | 2 + 12 files changed, 95 insertions(+), 15 deletions(-) diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index af7815e..188da07 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -33,11 +33,14 @@ 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-delimiter` - command substitution delimiters (`$(` and `)`) * `process-substitution` - process substitutions (`<(echo foo)`) +* `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`) * `single-hyphen-option` - single-hyphen options (`-o`) * `double-hyphen-option` - double-hyphen options (`--option`) * `back-quoted-argument` - backtick command substitution (`` `foo` ``) * `back-quoted-argument-unclosed` - unclosed backtick command substitution (`` `foo ``) +* `back-quoted-argument-delimiter` - backtick command substitution delimiters (`` ` ``) * `single-quoted-argument` - single-quoted arguments (`` 'foo' ``) * `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``) * `double-quoted-argument` - double-quoted arguments (`` "foo" ``) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index cce0317..5f23357 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -40,11 +40,14 @@ : ${ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]:=} : ${ZSH_HIGHLIGHT_STYLES[globbing]:=fg=blue} : ${ZSH_HIGHLIGHT_STYLES[history-expansion]:=fg=blue} -: ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=fg=magenta} -: ${ZSH_HIGHLIGHT_STYLES[process-substitution]:=fg=magenta} +: ${ZSH_HIGHLIGHT_STYLES[command-substitution]:=none} +: ${ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]:=fg=magenta} +: ${ZSH_HIGHLIGHT_STYLES[process-substitution]:=none} +: ${ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[single-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[double-hyphen-option]:=none} : ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument]:=none} +: ${ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]:=fg=magenta} : ${ZSH_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow} : ${ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow} @@ -103,6 +106,10 @@ _zsh_highlight_main_calculate_fallback() { double-quoted-argument{-unclosed,} dollar-quoted-argument{-unclosed,} back-quoted-argument{-unclosed,} + + command-substitution{-delimiter,} + process-substitution{-delimiter,} + back-quoted-argument{-delimiter,} ) local needle=$1 value reply=($1) @@ -853,7 +860,7 @@ _zsh_highlight_main_highlighter_check_path() # This command will at least highlight $1 to end_pos with the default style _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i=$1 path_eligible=1 start style + local base_style=default i=$1 path_eligible=1 ret start style local -a highlights local -a match mbegin mend @@ -872,8 +879,16 @@ _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] + ret=$? (( i += REPLY )) - highlights+=($(( start_pos + $1 - 1 )) $(( start_pos + i )) process-substitution $reply) + highlights+=( + $(( start_pos + $1 - 1 )) $(( start_pos + i )) process-substitution + $(( start_pos + $1 - 1 )) $(( start_pos + $1 + 1 )) process-substitution-delimiter + $reply + ) + if (( ret == 0 )); then + highlights+=($(( start_pos + i - 1 )) $(( start_pos + i )) process-substitution-delimiter) + fi fi esac @@ -907,8 +922,16 @@ _zsh_highlight_main_highlighter_highlight_argument() start=$i (( i += 2 )) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + ret=$? (( i += REPLY )) - highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) command-substitution $reply) + highlights+=( + $(( start_pos + start - 1)) $(( start_pos + i )) command-substitution + $(( start_pos + start - 1)) $(( start_pos + start + 1)) command-substitution-delimiter + $reply + ) + if (( ret == 0 )); then + highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) command-substitution-delimiter) + fi continue fi while [[ $arg[i+1] == [\^=~#+] ]]; do @@ -922,8 +945,16 @@ _zsh_highlight_main_highlighter_highlight_argument() start=$i (( i += 2 )) _zsh_highlight_main_highlighter_highlight_list $(( start_pos + i - 1 )) S $has_end $arg[i,end_pos] + ret=$? (( i += REPLY )) - highlights+=($(( start_pos + start - 1)) $(( start_pos + i )) process-substitution $reply) + highlights+=( + $(( start_pos + start - 1)) $(( start_pos + i )) process-substitution + $(( start_pos + start - 1)) $(( start_pos + start + 1 )) process-substitution-delimiter + $reply + ) + if (( ret == 0 )); then + highlights+=($(( start_pos + i - 1)) $(( start_pos + i )) process-substitution-delimiter) + fi continue fi ;| @@ -988,7 +1019,7 @@ _zsh_highlight_main_highlighter_highlight_double_quote() { local -a match mbegin mend saved_reply local MATCH; integer MBEGIN MEND - local i j k style + local i j k ret style reply=() for (( i = $1 + 1 ; i <= end_pos - start_pos ; i += 1 )) ; do @@ -1022,8 +1053,17 @@ _zsh_highlight_main_highlighter_highlight_double_quote() (( 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 )) - reply=($saved_reply $j $(( start_pos + i )) command-substitution $reply) + reply=( + $saved_reply + $j $(( start_pos + i )) command-substitution + $j $(( j + 2 )) command-substitution-delimiter + $reply + ) + if (( ret == 0 )); then + reply+=($(( start_pos + i - 1 )) $(( start_pos + i )) command-substitution-delimiter) + fi continue else continue @@ -1124,11 +1164,9 @@ _zsh_highlight_main_highlighter_highlight_backtick() # offset is a count of consumed \ (the delta between buf and arg). # offsets is an array indexed by buf offset of when the delta between buf and arg changes. # It is sparse, so search backwards to the last value - # unclosed is an array of one highlight to append to reply if this back-quoted-argument - # is closed and there is an unclosed back-quoted-argument in buf. - local buf highlight style=back-quoted-argument-unclosed + local buf highlight style=back-quoted-argument-unclosed style_end local -i arg1=$1 end_ i=$1 last offset=0 start subshell_has_end=0 - local -a highlight_zone highlights offsets unclosed + local -a highlight_zone highlights offsets reply=() last=$(( arg1 + 1 )) @@ -1155,6 +1193,7 @@ _zsh_highlight_main_highlighter_highlight_backtick() fi else # it's an unquoted ` and this is the end style=back-quoted-argument + style_end=back-quoted-argument-delimiter buf=$buf$arg[last,i-1] offsets[i-arg1-offset]='' # So we never index past the end break @@ -1171,11 +1210,18 @@ _zsh_highlight_main_highlighter_highlight_backtick() highlights+=($start $end_ $highlight) if [[ $highlight == back-quoted-argument-unclosed && $style == back-quoted-argument ]]; then # An inner backtick command substitution is unclosed, but this level is closed - unclosed=($(( start_pos + i - 1)) $(( start_pos + i )) unknown-token) + style_end=unknown-token fi done - reply=($(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style $highlights $unclosed) + reply=( + $(( start_pos + arg1 - 1 )) $(( start_pos + i )) $style + $(( start_pos + arg1 - 1 )) $(( start_pos + arg1 )) back-quoted-argument-delimiter + $highlights + ) + if (( $#style_end )); then + reply+=($(( start_pos + i - 1)) $(( start_pos + i )) $style_end) + fi REPLY=$i } diff --git a/highlighters/main/test-data/back-quoted-argument.zsh b/highlighters/main/test-data/back-quoted-argument.zsh index 8b13729..d504a2c 100644 --- a/highlighters/main/test-data/back-quoted-argument.zsh +++ b/highlighters/main/test-data/back-quoted-argument.zsh @@ -33,17 +33,24 @@ expected_region_highlight=( "1 4 builtin" # echo "6 18 default" # `echo \`42\`` "6 18 back-quoted-argument" # `echo \`42\`` + "6 6 back-quoted-argument-delimiter" # ` "7 10 builtin" # echo "12 17 default" # \`42\` "12 17 back-quoted-argument" # \`42\` + "12 13 back-quoted-argument-delimiter" # \` "14 15 unknown-token" # 42 + "16 17 back-quoted-argument-delimiter" # \` + "18 18 back-quoted-argument-delimiter" # ` "20 39 default" # "is `echo equal` to" "20 39 double-quoted-argument" # "is `echo equal` to" "24 35 back-quoted-argument" # `echo equal` + "24 24 back-quoted-argument-delimiter" # ` "25 28 builtin" # echo "30 34 default" # equal + "35 35 back-quoted-argument-delimiter" # ` "41 55 default" # `echo 6 times 9 "41 55 back-quoted-argument-unclosed" # `echo 6 times 9 + "41 41 back-quoted-argument-delimiter" # ` "42 45 builtin" # echo "47 47 default" # 6 "49 53 default" # times diff --git a/highlighters/main/test-data/command-substitution-in-assignment.zsh b/highlighters/main/test-data/command-substitution-in-assignment.zsh index db82b7c..010df7f 100644 --- a/highlighters/main/test-data/command-substitution-in-assignment.zsh +++ b/highlighters/main/test-data/command-substitution-in-assignment.zsh @@ -34,7 +34,9 @@ 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' # $( '7 10 builtin' # echo '12 14 default' # bar + '15 15 command-substitution-delimiter' # ) '17 17 builtin' # : ) diff --git a/highlighters/main/test-data/command-substitution-unclosed.zsh b/highlighters/main/test-data/command-substitution-unclosed.zsh index 198e710..570471b 100644 --- a/highlighters/main/test-data/command-substitution-unclosed.zsh +++ b/highlighters/main/test-data/command-substitution-unclosed.zsh @@ -34,6 +34,7 @@ expected_region_highlight=( '1 1 builtin' # : '3 15 default' # foo$(echo bar '6 15 command-substitution' # $(echo bar + '6 7 command-substitution-delimiter' # $( '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 0350640..7a1b7f1 100644 --- a/highlighters/main/test-data/cthulhu.zsh +++ b/highlighters/main/test-data/cthulhu.zsh @@ -36,27 +36,35 @@ expected_region_highlight=( '1 4 builtin' # echo '6 113 default' # Ph\'ng`echo lui "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn` '12 113 back-quoted-argument' # `echo lui "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn` + '12 12 back-quoted-argument-delimiter' # ` '13 16 builtin' # echo '18 20 default' # lui '22 112 default' # "mg"\`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn '22 25 double-quoted-argument' # "mg" '26 112 back-quoted-argument-unclosed' # \`echo lw\'nafh \\\`echo Cthu"lhu\\\` R\\'ly$(echo eh wag\\\`echo h\'nag\\\`'l' fht)agn + '26 27 back-quoted-argument-delimiter' # \` '28 31 builtin' # echo '33 40 default' # lw\'nafh '42 62 default' # \\\`echo Cthu"lhu\\\` '42 62 back-quoted-argument' # \\\`echo Cthu"lhu\\\` + '42 45 back-quoted-argument-delimiter' # \\\` '46 49 builtin' # echo '51 58 default' # Cthu"lhu '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' # $( '72 75 builtin' # echo '77 78 default' # eh '80 104 default' # wag\\\`echo h\'nag\\\`'l' '83 101 back-quoted-argument' # \\\`echo h\'nag\\\` + '83 86 back-quoted-argument-delimiter' # \\\` '87 90 builtin' # echo '92 97 default' # h\'nag + '98 101 back-quoted-argument-delimiter' # \\\` '102 104 single-quoted-argument' # 'l' '106 108 default' # fht + '109 109 command-substitution-delimiter' # ) '113 113 unknown-token' # ` ) diff --git a/highlighters/main/test-data/dollar-paren.zsh b/highlighters/main/test-data/dollar-paren.zsh index c64a764..f051e4a 100644 --- a/highlighters/main/test-data/dollar-paren.zsh +++ b/highlighters/main/test-data/dollar-paren.zsh @@ -35,5 +35,7 @@ expected_region_highlight=( '3 8 default' # "$(:)" '3 8 double-quoted-argument' # "$(:)" '4 7 command-substitution' # $(:) + '4 5 command-substitution-delimiter' # $( '6 6 builtin' # : + '7 7 command-substitution-delimiter' # ) ) diff --git a/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh index d5de3fd..f8dbd6b 100644 --- a/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh +++ b/highlighters/main/test-data/process-substitution-redirection-isnt-globbing.zsh @@ -34,6 +34,8 @@ expected_region_highlight=( '1 1 builtin' # : '3 9 default' # =((wc) "4 8 process-substitution" # >(wc) + "4 5 process-substitution-delimiter" # >( "6 7 command" # wc + "8 8 process-substitution-delimiter" # ) "10 10 commandseparator" # | "12 13 command" # nl ) From 565463ca8f3cd3e17193b2735d02a39f327aaa65 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 30 Sep 2018 15:45:18 -0400 Subject: [PATCH 0646/1080] 'main': Add regression test for an unclosed backtick substitution --- .../main/test-data/back-quoted-open.zsh | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 highlighters/main/test-data/back-quoted-open.zsh diff --git a/highlighters/main/test-data/back-quoted-open.zsh b/highlighters/main/test-data/back-quoted-open.zsh new file mode 100644 index 0000000..f188d81 --- /dev/null +++ b/highlighters/main/test-data/back-quoted-open.zsh @@ -0,0 +1,41 @@ +#!/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 +# ------------------------------------------------------------------------------------------------- + +touch foo +BUFFER=$': `ls fo' + +expected_region_highlight=( + '1 1 builtin' # : + '3 8 default' # `ls fo + '3 8 back-quoted-argument-unclosed' # `ls fo + '3 3 back-quoted-argument-delimiter' # ` + '4 5 command' # ls + '7 8 path_prefix' # fo +) From cf88b63523e8f861cb59fcf04be8f8d8c741b120 Mon Sep 17 00:00:00 2001 From: MinJae Kwon Date: Wed, 3 Oct 2018 22:07:46 +0900 Subject: [PATCH 0647/1080] docs: Remove superfluous indentations in code block --- INSTALL.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 1f0d923..468e9bd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -33,17 +33,17 @@ 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 + 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 + 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,15 +69,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 + 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) + plugins=( [plugins...] zsh-syntax-highlighting) 3. Source `~/.zshrc` to take changes into account: - source ~/.zshrc + source ~/.zshrc #### [Prezto](https://github.com/sorin-ionescu/prezto) From f3410c5862fc6d89ee3661f7d140e570d6740e8c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 08:16:22 +0000 Subject: [PATCH 0648/1080] 'main': Expand aliases first. (Issue #264.) This commit causes an alias to an invalid command to be highlighted as an error (unknown-token). --- highlighters/main/main-highlighter.zsh | 43 +++++++++++++++---- .../main/test-data/alias-comment1.zsh | 37 ++++++++++++++++ .../main/test-data/alias-comment2.zsh | 37 ++++++++++++++++ highlighters/main/test-data/noglob-alias.zsh | 2 +- highlighters/main/test-data/off-by-one.zsh | 2 +- 5 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 highlighters/main/test-data/alias-comment1.zsh create mode 100644 highlighters/main/test-data/alias-comment2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5f23357..616d59b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -299,7 +299,7 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main_highlighter_highlight_list() { integer start_pos=0 end_pos buf_offset=$1 has_end=$3 - local buf=$4 highlight_glob=true arg style + local buf=$4 highlight_glob=true arg arg_raw style local in_array_assignment=false # true between 'a=(' and the matching ')' integer len=$#buf local -a match mbegin mend list_highlights @@ -362,6 +362,9 @@ _zsh_highlight_main_highlighter_highlight_list() args=(${(z)buf}) fi for arg in $args; do + # Save an unmunged copy of the current word. + arg_raw="$arg" + # Initialize $next_word. if (( in_redirection )); then (( --in_redirection )) @@ -472,6 +475,30 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi + # Expand aliases. + # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' + # And then the entire 'alias' branch of the 'case' statement should + # be done here. + () { + # TODO: path expansion should happen _after_ alias expansion + _zsh_highlight_main_highlighter_expand_path $arg + local expanded_arg="$REPLY" + _zsh_highlight_main__type ${expanded_arg} + } + local res="$REPLY" + if [[ $res == "alias" ]]; then + _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}} ) + arg=$reply[1] + } + fi + # Special-case the first word after 'sudo'. if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then @@ -512,10 +539,6 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':sudo_opt:' next_word+=':start:' else - _zsh_highlight_main_highlighter_expand_path $arg - local expanded_arg="$REPLY" - _zsh_highlight_main__type ${expanded_arg} - local res="$REPLY" () { # Special-case: command word is '$foo', like that, without braces or anything. # @@ -588,8 +611,9 @@ _zsh_highlight_main_highlighter_highlight_list() ;; 'suffix alias') style=suffix-alias;; alias) () { + # Make sure to use $arg_raw here, rather than $arg. integer insane_alias - case $arg in + case $arg_raw in # Issue #263: aliases with '=' on their LHS. # # There are three cases: @@ -603,12 +627,13 @@ _zsh_highlight_main_highlighter_highlight_list() 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 - _zsh_highlight_main__resolve_alias $arg - local alias_target="$REPLY" - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$alias_target"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg) + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg_raw"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg_raw) fi } ;; diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh new file mode 100644 index 0000000..a2b56c6 --- /dev/null +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# see alias-comment2.zsh +setopt interactivecomments +alias x=$'# foo\npwd' +BUFFER='x' + +expected_region_highlight=( + "1 1 alias 'interactivecomments applies to aliases'" # x becomes pwd +) diff --git a/highlighters/main/test-data/alias-comment2.zsh b/highlighters/main/test-data/alias-comment2.zsh new file mode 100644 index 0000000..e9ecfca --- /dev/null +++ b/highlighters/main/test-data/alias-comment2.zsh @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +# see alias-comment1.zsh +setopt NO_interactivecomments +alias x=$'# foo\npwd' +BUFFER='x' + +expected_region_highlight=( + "1 1 unknown-token" # x becomes # +) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 2f96445..e6c9f3c 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -31,6 +31,6 @@ alias x=command BUFFER='x ls' expected_region_highlight=( - "1 1 alias" # x + "1 1 precommand" # x "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 550c09f..3870e20 100644 --- a/highlighters/main/test-data/off-by-one.zsh +++ b/highlighters/main/test-data/off-by-one.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias a=A +alias a=: f() {} BUFFER='a;f;' From 76d61360a7499d674bf0e300b2a5b77d044c71a8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 22:41:23 +0000 Subject: [PATCH 0649/1080] 'main': New XFail test for parameter expansion at command word. --- highlighters/main/test-data/commmand-parameter.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index 07dfc4c..5cded9b 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -28,10 +28,13 @@ # ------------------------------------------------------------------------------------------------- local x=/usr/bin/env -BUFFER='$x "argument"' +local y=sudo +BUFFER='$x "argument"; $y' expected_region_highlight=( "1 2 command" # $x "4 13 default" # "argument" "4 13 double-quoted-argument" # "argument" + "14 14 commandseparator" # ; + "16 17 precommand 'parameter expansion precedes precommand recognition'" # $y (sudo) ) From bf055f7df2f2e9c825ebb6f306eb171233d3cfcf Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 22:41:23 +0000 Subject: [PATCH 0650/1080] 'main': Fix the last commit's issue concerning parameter expansion at command word. --- highlighters/main/main-highlighter.zsh | 37 ++++++++++--------- .../main/test-data/commmand-parameter.zsh | 4 +- .../main/test-data/path-dollared-word3.zsh | 4 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 616d59b..667b0ac 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -499,6 +499,26 @@ _zsh_highlight_main_highlighter_highlight_list() } fi + # Expand parameters. + # + # ### For now, expand just '$foo', like that, without braces or anything. + () { + # 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 + if [[ $res == none ]] && (( ${+parameters} )) && + [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && + (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] + then + arg=${(P)MATCH} + _zsh_highlight_main__type "$arg" + res=$REPLY + fi + } + # Special-case the first word after 'sudo'. if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then @@ -539,23 +559,6 @@ _zsh_highlight_main_highlighter_highlight_list() next_word+=':sudo_opt:' next_word+=':start:' else - () { - # Special-case: command word is '$foo', like that, without braces or anything. - # - # 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 - if [[ $res == none ]] && (( ${+parameters} )) && - [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && - (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] - then - _zsh_highlight_main__type ${(P)MATCH} - res=$REPLY - fi - } case $res in reserved) # reserved word style=reserved-word diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index 5cded9b..afa9bc5 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -29,6 +29,8 @@ local x=/usr/bin/env local y=sudo +sudo(){} + BUFFER='$x "argument"; $y' expected_region_highlight=( @@ -36,5 +38,5 @@ expected_region_highlight=( "4 13 default" # "argument" "4 13 double-quoted-argument" # "argument" "14 14 commandseparator" # ; - "16 17 precommand 'parameter expansion precedes precommand recognition'" # $y (sudo) + "16 17 precommand" # $y (sudo) ) diff --git a/highlighters/main/test-data/path-dollared-word3.zsh b/highlighters/main/test-data/path-dollared-word3.zsh index a9a5fa3..911ea81 100644 --- a/highlighters/main/test-data/path-dollared-word3.zsh +++ b/highlighters/main/test-data/path-dollared-word3.zsh @@ -29,10 +29,12 @@ # «/usr» at this point would be highlighted as path_prefix; so should # a parameter that expands to an equivalent string be highlighted. +# +# More complicated parameter substitutions aren't eval'd; issue #328. BUFFER='$PWD; ${PWD}' expected_region_highlight=( - "1 4 unknown-token" # $PWD - not eval'd; issue #328 + "1 4 path" # $PWD "5 5 commandseparator" # ; "7 12 unknown-token" # ${PWD} ) From dbdebfaaa5d4ac7af8ab6ea5fc168620137a575f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 25 Dec 2017 05:20:40 +0000 Subject: [PATCH 0651/1080] =?UTF-8?q?'main':=20Following=20up=20to=20the?= =?UTF-8?q?=20last=20commit,=20also=20highlight=20braced=20parameter=20exp?= =?UTF-8?q?ansions:=20=C2=AB${foo}=C2=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- highlighters/main/main-highlighter.zsh | 8 +++++++- highlighters/main/test-data/path-dollared-word3.zsh | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 667b0ac..e53c93e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -509,8 +509,14 @@ _zsh_highlight_main_highlighter_highlight_list() # parameters that refer to commands, functions, and builtins. local -a match mbegin mend local MATCH; integer MBEGIN MEND + local parameter_name + if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then + parameter_name=${${arg:2}%?} + elif [[ $arg[1] == '$' ]]; then + parameter_name=${arg:1} + fi if [[ $res == none ]] && (( ${+parameters} )) && - [[ ${arg[1]} == \$ ]] && [[ ${arg:1} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && + [[ ${parameter_name} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then arg=${(P)MATCH} diff --git a/highlighters/main/test-data/path-dollared-word3.zsh b/highlighters/main/test-data/path-dollared-word3.zsh index 911ea81..6921cba 100644 --- a/highlighters/main/test-data/path-dollared-word3.zsh +++ b/highlighters/main/test-data/path-dollared-word3.zsh @@ -36,5 +36,5 @@ BUFFER='$PWD; ${PWD}' expected_region_highlight=( "1 4 path" # $PWD "5 5 commandseparator" # ; - "7 12 unknown-token" # ${PWD} + "7 12 path" # ${PWD} ) From 6e8984e2ecc16039855799cc798dd9353ed69906 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 07:37:59 +0000 Subject: [PATCH 0652/1080] 'main': Make sudo handling more generic. Part of issue #343. --- highlighters/main/main-highlighter.zsh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e53c93e..30a2848 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -235,6 +235,16 @@ _zsh_highlight_highlighter_main_paint() local -a options_to_set reply # used in callees local REPLY + # $flags_with_argument is a set of letters, corresponding to the option letters + # that would be followed by a colon in a getopts specification. + local flags_with_argument + # $precommand_options maps precommand name to value of $flags_with_argument + # for that precommand. + local -A precommand_options + precommand_options=( + 'sudo' Cgprtu + ) + if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false else @@ -537,7 +547,8 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *':sudo_opt:'* ]]; then case "$arg" in # Flag that requires an argument - '-'[Cgprtu]) this_word=${this_word//:start:/}; + '-'[$flags_with_argument]) + this_word=${this_word//:start:/}; next_word=':sudo_arg:';; # This prevents misbehavior with sudo -u -otherargument '-'*) this_word=${this_word//:start:/}; @@ -559,8 +570,9 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then style=precommand - elif [[ "$arg" = "sudo" ]] && { _zsh_highlight_main__type sudo; [[ -n $REPLY && $REPLY != "none" ]] }; then + elif (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand + flags_with_argument=${precommand_options[$arg]} next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' From add2ac59fc60311d2ab2ca52f9139037bd0f7682 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 07:42:54 +0000 Subject: [PATCH 0653/1080] 'main': Permit $flags_with_argument to be empty. --- highlighters/main/main-highlighter.zsh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 30a2848..ac2406d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -545,17 +545,20 @@ _zsh_highlight_main_highlighter_highlight_list() # Parse the sudo command line if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then - case "$arg" in + if [[ -n $flags_with_argument ]] && + [[ $arg == '-'[$flags_with_argument] ]]; then # Flag that requires an argument - '-'[$flags_with_argument]) - this_word=${this_word//:start:/}; - next_word=':sudo_arg:';; + this_word=${this_word//:start:/} + next_word=':sudo_arg:' + elif [[ $arg == '-'* ]]; then + # Flag that requires no argument, or unknown flag. # This prevents misbehavior with sudo -u -otherargument - '-'*) this_word=${this_word//:start:/}; - next_word+=':start:'; - next_word+=':sudo_opt:';; - *) ;; - esac + this_word=${this_word//:start:/} + next_word+=':start:' + next_word+=':sudo_opt:' + else + # + fi elif [[ $this_word == *':sudo_arg:'* ]]; then next_word+=':sudo_opt:' next_word+=':start:' From 4c7db4e886e9aba97dab4299015f62f01d3e3f78 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 08:26:48 +0000 Subject: [PATCH 0654/1080] 'main': Update state machine docs. No functional change. --- 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 ac2406d..695d4fd 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -329,8 +329,9 @@ _zsh_highlight_main_highlighter_highlight_list() # # The states are: # - :start: Command word - # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i") - # - :sudo_arg: The argument to a sudo leading-dash option that takes one, + # - :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, # when given as a separate word; i.e., "foo" in "-u foo" (two # words) but not in "-ufoo" (one word). # - :regular: "Not a command word", and command delimiters are permitted. From 5694221939b79e9e6243d733c081a21d3cba8df4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 07:50:38 +0000 Subject: [PATCH 0655/1080] 'main': Highlight the 'command' precommand. Fixes #343. --- highlighters/main/main-highlighter.zsh | 9 +++++---- highlighters/main/test-data/precommand2.zsh | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 695d4fd..f8cd254 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -242,6 +242,7 @@ _zsh_highlight_highlighter_main_paint() # for that precommand. local -A precommand_options precommand_options=( + 'command' '' 'sudo' Cgprtu ) @@ -263,7 +264,7 @@ _zsh_highlight_highlighter_main_paint() # ';;' ';&' ';|' ) ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( - 'builtin' 'command' 'exec' 'nocorrect' 'noglob' + 'builtin' 'exec' 'nocorrect' 'noglob' 'pkexec' # immune to #121 because it's usually not passed --option flags ) @@ -572,14 +573,14 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word # de facto a reserved word, although not de jure next_word=':start:' elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then - style=precommand - elif (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then + if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand flags_with_argument=${precommand_options[$arg]} next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' + elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then + style=precommand else case $res in reserved) # reserved word diff --git a/highlighters/main/test-data/precommand2.zsh b/highlighters/main/test-data/precommand2.zsh index 3d8f332..75dceab 100644 --- a/highlighters/main/test-data/precommand2.zsh +++ b/highlighters/main/test-data/precommand2.zsh @@ -31,6 +31,6 @@ BUFFER='command -v ls' expected_region_highlight=( "1 7 precommand" # command - "9 10 single-hyphen-option 'issue #343'" # -v - "12 13 command 'issue #343'" # ls + "9 10 single-hyphen-option" # -v + "12 13 command" # ls ) From 8b11ca087ec0495f01792488ff6421aa92ff2008 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 08:22:40 +0000 Subject: [PATCH 0656/1080] 'main': Highlight 'nice'. Fixes #168. --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/precommand3.zsh | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 highlighters/main/test-data/precommand3.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f8cd254..1ff076a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -243,6 +243,7 @@ _zsh_highlight_highlighter_main_paint() local -A precommand_options precommand_options=( 'command' '' + 'nice' n 'sudo' Cgprtu ) diff --git a/highlighters/main/test-data/precommand3.zsh b/highlighters/main/test-data/precommand3.zsh new file mode 100644 index 0000000..f8b0c78 --- /dev/null +++ b/highlighters/main/test-data/precommand3.zsh @@ -0,0 +1,41 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +BUFFER='nice -n10 ls; nice -n 10 ls' + +expected_region_highlight=( + "1 4 precommand" # nice + "6 9 single-hyphen-option" # -n10 + "11 12 command" # ls + "13 13 commandseparator" # ; + "15 18 precommand" # nice + "20 21 single-hyphen-option" # -n + "23 24 default" # 10 + "26 27 command" # ls +) From 78be8f611f94a61fb2bde7dde1e872f69ff7a827 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 15 Sep 2016 15:42:35 +0000 Subject: [PATCH 0657/1080] 'main': Highlight 'doas'. Fixes #365. --- 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 1ff076a..2661e8d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -245,6 +245,7 @@ _zsh_highlight_highlighter_main_paint() 'command' '' 'nice' n 'sudo' Cgprtu + 'doas' aCu ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From 7f5e11e38b0b020b756fe4e14ae82c53462eee2b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:02:39 +0000 Subject: [PATCH 0658/1080] 'main': Remove superfluous variable. No functional change. --- highlighters/main/main-highlighter.zsh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2661e8d..7479e48 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -496,8 +496,7 @@ _zsh_highlight_main_highlighter_highlight_list() () { # TODO: path expansion should happen _after_ alias expansion _zsh_highlight_main_highlighter_expand_path $arg - local expanded_arg="$REPLY" - _zsh_highlight_main__type ${expanded_arg} + _zsh_highlight_main__type "$REPLY" } local res="$REPLY" if [[ $res == "alias" ]]; then From bee115f797c674a06c5cab634f0b2cf328e9ad4c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:05:07 +0000 Subject: [PATCH 0659/1080] 'main': Correct a comment. --- 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 7479e48..4be7a0e 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -514,7 +514,9 @@ _zsh_highlight_main_highlighter_highlight_list() # Expand parameters. # - # ### For now, expand just '$foo', like that, without braces or anything. + # ### 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}.) () { # 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 From a2e993c59f9dbe7da2fd7a96828214641c989b6d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:32:30 +0000 Subject: [PATCH 0660/1080] 'main': Learn $flags_sans_arguments and use that to parse '-xy foo' correctly where -x takes no argument and -y does. --- highlighters/main/main-highlighter.zsh | 23 +++++++----- highlighters/main/test-data/precommand4.zsh | 39 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 highlighters/main/test-data/precommand4.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4be7a0e..87bc229 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -238,14 +238,20 @@ _zsh_highlight_highlighter_main_paint() # $flags_with_argument is a set of letters, corresponding to the option letters # that would be followed by a colon in a getopts specification. local flags_with_argument - # $precommand_options maps precommand name to value of $flags_with_argument - # for that precommand. + # $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. + # + # Currently, setting $flags_sans_argument is only important for commands that + # have a non-empty $flags_with_argument; see test-data/precommand4.zsh. local -A precommand_options precommand_options=( - 'command' '' - 'nice' n - 'sudo' Cgprtu - 'doas' aCu + 'command' :pvV # as of zsh 5.4.2 + 'nice' n # as of current POSIX spec + 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 + 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then @@ -551,7 +557,7 @@ _zsh_highlight_main_highlighter_highlight_list() if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then if [[ -n $flags_with_argument ]] && - [[ $arg == '-'[$flags_with_argument] ]]; then + [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]]; then # Flag that requires an argument this_word=${this_word//:start:/} next_word=':sudo_arg:' @@ -578,7 +584,8 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then style=precommand - flags_with_argument=${precommand_options[$arg]} + flags_with_argument=${precommand_options[$arg]%:*} + flags_sans_argument=${precommand_options[$arg]#*:} next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' diff --git a/highlighters/main/test-data/precommand4.zsh b/highlighters/main/test-data/precommand4.zsh new file mode 100644 index 0000000..b9e6119 --- /dev/null +++ b/highlighters/main/test-data/precommand4.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 +# ------------------------------------------------------------------------------------------------- + +doas(){} +BUFFER=$'doas -nu phy1729 ls' + +expected_region_highlight=( + '1 4 precommand' # doas + '6 8 single-hyphen-option' # -nu + '10 16 default' # phy1729 + '18 19 command' # ls +) From 82c39716ebdb3a494ec30a4c0c6677c9a2fd83a0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:38:06 +0000 Subject: [PATCH 0661/1080] 'main': Write the "remainder" of the sentence in a comment. No functional change. --- 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 87bc229..c3cb7a9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -568,7 +568,9 @@ _zsh_highlight_main_highlighter_highlight_list() 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 + # non-empty now.) fi elif [[ $this_word == *':sudo_arg:'* ]]; then next_word+=':sudo_opt:' From f3425e18fe4aaf342d73ffedfd817caf35bbf0cd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:45:52 +0000 Subject: [PATCH 0662/1080] 'main': Let _zsh_highlight_main__type return false on failure. --- 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 c3cb7a9..47c9cae 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -170,6 +170,8 @@ _zsh_highlight_main__type() { if (( $+_zsh_highlight_main__command_type_cache )); then _zsh_highlight_main__command_type_cache[(e)$1]=$REPLY fi + [[ -n $REPLY ]] + return $? } # Check whether the first argument is a redirection operator token. @@ -584,7 +586,7 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word # de facto a reserved word, although not de jure next_word=':start:' elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word - if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg; [[ -n $REPLY && $REPLY != "none" ]] }; then + if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg && [[ $REPLY != "none" ]] }; then style=precommand flags_with_argument=${precommand_options[$arg]%:*} flags_sans_argument=${precommand_options[$arg]#*:} @@ -666,7 +668,7 @@ _zsh_highlight_main_highlighter_highlight_list() 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 + elif _zsh_highlight_main__type "$arg" && [[ $REPLY == 'none' ]]; then style=unknown-token else # The common case. From 3a33ac1d202176c371bc7c3c33f433d5686c30d7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:46:11 +0000 Subject: [PATCH 0663/1080] 'main': Break out a new helper function for readability. --- highlighters/main/main-highlighter.zsh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 47c9cae..c5e45a8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -174,6 +174,17 @@ _zsh_highlight_main__type() { return $? } +# Checks whether $1 is something that can be run. +# +# Return 0 if runnable, 1 if not runnable, 2 if trouble. +_zsh_highlight_main__is_runnable() { + if _zsh_highlight_main__type "$1"; then + [[ $REPLY != none ]] + else + return 2 + fi +} + # Check whether the first argument is a redirection operator token. # Report result via the exit code. _zsh_highlight_main__is_redirection() { @@ -586,7 +597,7 @@ _zsh_highlight_main_highlighter_highlight_list() style=reserved-word # de facto a reserved word, although not de jure next_word=':start:' elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word - if (( ${+precommand_options[$arg]} )) && { _zsh_highlight_main__type $arg && [[ $REPLY != "none" ]] }; then + 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]#*:} From ad6261fbca8b9a40eaa662fa9df2f37f888b6e33 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:49:03 +0000 Subject: [PATCH 0664/1080] 'main': Use a more robust way of testing for $parameters' availability. --- 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 c5e45a8..c2f68d7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -549,7 +549,7 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ $arg[1] == '$' ]]; then parameter_name=${arg:1} fi - if [[ $res == none ]] && (( ${+parameters} )) && + if [[ $res == none ]] && zmodload -e zsh/parameter && [[ ${parameter_name} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then From 31ceaed4f4d38f76a220aef783ab7bb7e3d3236e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 13:54:02 +0000 Subject: [PATCH 0665/1080] 'main': Highlight array parameters in command position. --- highlighters/main/main-highlighter.zsh | 12 +++++++++++- highlighters/main/test-data/commmand-parameter.zsh | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c2f68d7..2586206 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -553,7 +553,17 @@ _zsh_highlight_main_highlighter_highlight_list() [[ ${parameter_name} =~ ^([A-Za-z_][A-Za-z0-9_]*|[0-9]+)$ ]] && (( ${+parameters[(e)${MATCH}]} )) && [[ ${parameters[(e)$MATCH]} != *special* ]] then - arg=${(P)MATCH} + # Set $arg. + case ${(tP)MATCH} in + (*array*|*assoc*) + local -a words; words=( ${(P)MATCH} ) + arg=${words[1]} + ;; + (*) + # scalar, presumably + arg=${(P)MATCH} + ;; + esac _zsh_highlight_main__type "$arg" res=$REPLY fi diff --git a/highlighters/main/test-data/commmand-parameter.zsh b/highlighters/main/test-data/commmand-parameter.zsh index afa9bc5..48d20ba 100644 --- a/highlighters/main/test-data/commmand-parameter.zsh +++ b/highlighters/main/test-data/commmand-parameter.zsh @@ -29,9 +29,10 @@ local x=/usr/bin/env local y=sudo +local -a z; z=(zsh -f) sudo(){} -BUFFER='$x "argument"; $y' +BUFFER='$x "argument"; $y; $z' expected_region_highlight=( "1 2 command" # $x @@ -39,4 +40,6 @@ expected_region_highlight=( "4 13 double-quoted-argument" # "argument" "14 14 commandseparator" # ; "16 17 precommand" # $y (sudo) + "18 18 unknown-token" # ; + "20 21 command" # $z - 'zsh' being the command ) From f7ac43cd4921d0260ef64090b232fc7029cc2773 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 14:03:39 +0000 Subject: [PATCH 0666/1080] 'main': Unify $ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS and $precommand_options. --- highlighters/main/main-highlighter.zsh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2586206..d19364b 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -243,7 +243,6 @@ _zsh_highlight_highlighter_main_paint() fi typeset -a ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR - typeset -a ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW local -a options_to_set reply # used in callees local REPLY @@ -265,6 +264,11 @@ _zsh_highlight_highlighter_main_paint() 'nice' n # as of current POSIX spec 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 + 'builtin' '' # as of zsh 5.4.2 + 'exec' a:cl # as of zsh 5.4.2 + 'nocorrect' '' # as of zsh 5.4.2 + 'noglob' '' # as of zsh 5.4.2 + 'pkexec' '' # doesn't take short options; immune to #121 because it's usually not passed --option flags ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then @@ -284,10 +288,6 @@ _zsh_highlight_highlighter_main_paint() # ### 'case' syntax, but followed by a pattern, not by a command # ';;' ';&' ';|' ) - ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS=( - 'builtin' 'exec' 'nocorrect' 'noglob' - 'pkexec' # immune to #121 because it's usually not passed --option flags - ) # Tokens that, at (naively-determined) "command position", are followed by # a de jure command position. All of these are reserved words. @@ -614,8 +614,6 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=${next_word//:regular:/} next_word+=':sudo_opt:' next_word+=':start:' - elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} ]]; then - style=precommand else case $res in reserved) # reserved word @@ -694,7 +692,9 @@ _zsh_highlight_main_highlighter_highlight_list() else # The common case. style=alias - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && -z ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg_raw"} ]] && ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS+=($arg_raw) + if (( ${+precommand_options[(re)"$arg"]} )) && (( ! ${+precommand_options[(re)"$arg_raw"]} )); then + precommand_options[$arg_raw]=$precommand_options[$arg] + fi fi } ;; @@ -844,8 +844,7 @@ _zsh_highlight_main_highlighter_highlight_list() highlight_glob=true fi elif - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]] || - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_PRECOMMANDS:#"$arg"} && $this_word == *':start:'* ]]; then + [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then next_word=':start:' elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then # skip the repeat-count word From 0709520597e97736f306515648f4a36305157829 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 16:02:41 +0000 Subject: [PATCH 0667/1080] No functional change. Follow-up to 1fee620e6235d3d1789dd3b62e65f5618464dbea. --- highlighters/main/main-highlighter.zsh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index d19364b..6f5227d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -512,11 +512,9 @@ _zsh_highlight_main_highlighter_highlight_list() # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' # And then the entire 'alias' branch of the 'case' statement should # be done here. - () { - # TODO: path expansion should happen _after_ alias expansion - _zsh_highlight_main_highlighter_expand_path $arg - _zsh_highlight_main__type "$REPLY" - } + # TODO: path expansion should happen _after_ alias expansion + _zsh_highlight_main_highlighter_expand_path $arg + _zsh_highlight_main__type "$REPLY" local res="$REPLY" if [[ $res == "alias" ]]; then _zsh_highlight_main__resolve_alias $arg From 005179ed8ef131bd0930bb83fa8097334b407e0f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 12 Jan 2018 16:08:22 +0000 Subject: [PATCH 0668/1080] 'main': Update $this_word state with our inferences. Found by code inspection. --- 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 6f5227d..c0e952f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -592,6 +592,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Not an option flag; nothing to do. (If the command line is # syntactically valid, ${this_word//:sudo_opt:/} should be # non-empty now.) + this_word=${this_word//:sudo_opt:/} fi elif [[ $this_word == *':sudo_arg:'* ]]; then next_word+=':sudo_opt:' From a56c33c3be604cdc49259c39ed11afd9f3c7cd19 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 13 Jan 2018 14:05:25 +0000 Subject: [PATCH 0669/1080] 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 c0e952f..d5d2fb7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------------------------------- -# Copyright (c) 2010-2017 zsh-syntax-highlighting contributors +# Copyright (c) 2010-2018 zsh-syntax-highlighting contributors # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted From e43e4fd2c7d63297cc88beacadc2bf1daa26aa02 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 13 Jan 2018 14:21:30 +0000 Subject: [PATCH 0670/1080] 'main': Fix $flags_sans_argument for 'nice'. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to 2c15b0e996ad24ab0517a978ce43d1eab92086c7 ("Learn $flags_sans_arguments…"). --- 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 d5d2fb7..c6ce7e8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -261,7 +261,7 @@ _zsh_highlight_highlighter_main_paint() local -A precommand_options precommand_options=( 'command' :pvV # as of zsh 5.4.2 - 'nice' n # as of current POSIX spec + 'nice' n: # as of current POSIX spec 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 'builtin' '' # as of zsh 5.4.2 From 05a55108c915fad32d39c21fe8ee2f7a02c14024 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:41:03 -0500 Subject: [PATCH 0671/1080] main: Expand aliases before looking for redirections --- highlighters/main/main-highlighter.zsh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c6ce7e8..37de2cc 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -498,16 +498,6 @@ _zsh_highlight_main_highlighter_highlight_list() continue fi - # Analyse the current word. - if _zsh_highlight_main__is_redirection $arg ; then - if (( in_redirection )); then - _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token - already_added=1 - else - in_redirection=2 - fi - fi - # Expand aliases. # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' # And then the entire 'alias' branch of the 'case' statement should @@ -529,6 +519,16 @@ _zsh_highlight_main_highlighter_highlight_list() } fi + # Analyse the current word. + if _zsh_highlight_main__is_redirection $arg ; then + if (( in_redirection )); then + _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token + already_added=1 + else + in_redirection=2 + fi + fi + # Expand parameters. # # ### For now, expand just '$foo' or '${foo}', possibly with braces, but with From 99d7235c2bae8fc0615fe4f9b4b49b726aff6fcb Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:44:55 -0500 Subject: [PATCH 0672/1080] main: Add test for an alias to a redirection --- .../main/test-data/alias-redirect.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/alias-redirect.zsh diff --git a/highlighters/main/test-data/alias-redirect.zsh b/highlighters/main/test-data/alias-redirect.zsh new file mode 100644 index 0000000..518cdc3 --- /dev/null +++ b/highlighters/main/test-data/alias-redirect.zsh @@ -0,0 +1,38 @@ +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2016 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias x=\> +BUFFER='x foo echo bar' + +expected_region_highlight=( + '1 1 redirection' # x becomes > + '3 5 default' # foo + '7 10 builtin' # echo + '12 14 default' # bar +) From f46b148c5298f707cd0b8d3eec2f5e2f48e9e27e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:42:36 -0500 Subject: [PATCH 0673/1080] main: Only expand aliases in command position --- highlighters/main/main-highlighter.zsh | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 37de2cc..663913a 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -498,25 +498,27 @@ _zsh_highlight_main_highlighter_highlight_list() continue fi - # Expand aliases. - # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' - # And then the entire 'alias' branch of the 'case' statement should - # be done here. - # TODO: path expansion should happen _after_ alias expansion - _zsh_highlight_main_highlighter_expand_path $arg - _zsh_highlight_main__type "$REPLY" - local res="$REPLY" - if [[ $res == "alias" ]]; then - _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}} ) - arg=$reply[1] - } + if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then + # Expand aliases. + # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' + # And then the entire 'alias' branch of the 'case' statement should + # be done here. + # TODO: path expansion should happen _after_ alias expansion + _zsh_highlight_main_highlighter_expand_path $arg + _zsh_highlight_main__type "$REPLY" + local res="$REPLY" + if [[ $res == "alias" ]]; then + _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}} ) + arg=$reply[1] + } + fi fi # Analyse the current word. From e1ecf950e23471b235e318ba7b85e77395a6b146 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 11:10:44 -0400 Subject: [PATCH 0674/1080] main: Do path expanstion after alias expansion --- highlighters/main/main-highlighter.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 663913a..3a8419f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -503,9 +503,7 @@ _zsh_highlight_main_highlighter_highlight_list() # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' # And then the entire 'alias' branch of the 'case' statement should # be done here. - # TODO: path expansion should happen _after_ alias expansion - _zsh_highlight_main_highlighter_expand_path $arg - _zsh_highlight_main__type "$REPLY" + _zsh_highlight_main__type "$arg" local res="$REPLY" if [[ $res == "alias" ]]; then _zsh_highlight_main__resolve_alias $arg @@ -519,6 +517,12 @@ _zsh_highlight_main_highlighter_highlight_list() arg=$reply[1] } fi + _zsh_highlight_main_highlighter_expand_path $arg + arg=$REPLY + if [[ $res != alias ]]; then + _zsh_highlight_main__type "$arg" + res="$REPLY" + fi fi # Analyse the current word. From 57386f30aec8612fd1854bdd60b64a7e70acf57b Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 11:23:59 -0400 Subject: [PATCH 0675/1080] main: Recursively expand aliases --- highlighters/main/main-highlighter.zsh | 39 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 3a8419f..29b3f71 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -500,26 +500,37 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then # Expand aliases. - # TODO: this should be done iteratively, e.g., 'alias x=y y=z z=w\n x' - # And then the entire 'alias' branch of the 'case' statement should + # TODO: the entire 'alias' branch of the 'case' statement should # be done here. _zsh_highlight_main__type "$arg" local res="$REPLY" if [[ $res == "alias" ]]; then - _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}} ) - arg=$reply[1] + 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 } - fi - _zsh_highlight_main_highlighter_expand_path $arg - arg=$REPLY - if [[ $res != alias ]]; then + _zsh_highlight_main_highlighter_expand_path $arg + arg=$REPLY + else + _zsh_highlight_main_highlighter_expand_path $arg + arg=$REPLY _zsh_highlight_main__type "$arg" res="$REPLY" fi From c138123397685ee805325b6eee0353d99148f172 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 11:54:25 -0400 Subject: [PATCH 0676/1080] main: Move alias handling up. This will set style=alias before the great fork. --- highlighters/main/main-highlighter.zsh | 60 +++++++++++++------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 29b3f71..ffe68dd 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -500,8 +500,6 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $this_word == *:start:* ]] && ! (( in_redirection )); then # Expand aliases. - # TODO: the entire 'alias' branch of the 'case' statement should - # be done here. _zsh_highlight_main__type "$arg" local res="$REPLY" if [[ $res == "alias" ]]; then @@ -528,6 +526,34 @@ _zsh_highlight_main_highlighter_highlight_list() } _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 + fi + } else _zsh_highlight_main_highlighter_expand_path $arg arg=$REPLY @@ -685,35 +711,7 @@ _zsh_highlight_main_highlighter_highlight_list() esac ;; 'suffix alias') style=suffix-alias;; - alias) () { - # 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 - } - ;; + alias) :;; builtin) style=builtin;; function) style=function;; command) style=command;; From e3edddd8eccec96c4bf05bb6926ead86dc9f7f5a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 11:56:08 -0400 Subject: [PATCH 0677/1080] main: alias style overrides precommand style --- highlighters/main/main-highlighter.zsh | 2 +- highlighters/main/test-data/noglob-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 ffe68dd..b32d415 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -650,7 +650,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then - style=precommand + [[ $res != alias ]] && 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/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index e6c9f3c..2f96445 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -31,6 +31,6 @@ alias x=command BUFFER='x ls' expected_region_highlight=( - "1 1 precommand" # x + "1 1 alias" # x "3 4 command" # ls ) From 4748f9bd3df3d2c5c9d5fdc1bb08965f2ea8cc49 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 12:04:36 -0400 Subject: [PATCH 0678/1080] main: Add alias tests --- highlighters/main/test-data/alias-loop.zsh | 40 +++++++++++++++++ .../test-data/alias-nested-precommand.zsh | 43 +++++++++++++++++++ highlighters/main/test-data/alias-nested.zsh | 40 +++++++++++++++++ .../alias-precommand-option-argument.zsh | 41 ++++++++++++++++++ highlighters/main/test-data/alias-quoted.zsh | 39 +++++++++++++++++ highlighters/main/test-data/alias-self.zsh | 38 ++++++++++++++++ 6 files changed, 241 insertions(+) create mode 100644 highlighters/main/test-data/alias-loop.zsh create mode 100644 highlighters/main/test-data/alias-nested-precommand.zsh create mode 100644 highlighters/main/test-data/alias-nested.zsh create mode 100644 highlighters/main/test-data/alias-precommand-option-argument.zsh create mode 100644 highlighters/main/test-data/alias-quoted.zsh create mode 100644 highlighters/main/test-data/alias-self.zsh diff --git a/highlighters/main/test-data/alias-loop.zsh b/highlighters/main/test-data/alias-loop.zsh new file mode 100644 index 0000000..46e900b --- /dev/null +++ b/highlighters/main/test-data/alias-loop.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 +# ------------------------------------------------------------------------------------------------- + +alias a=b b=c c=b + +BUFFER='a foo; :' + +expected_region_highlight=( + '1 1 unknown-token' # a + '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 new file mode 100644 index 0000000..6d4172b --- /dev/null +++ b/highlighters/main/test-data/alias-nested-precommand.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 a=b b=sudo +sudo(){} + +BUFFER='a -u phy1729 echo; :' + +expected_region_highlight=( + '1 1 alias' # a + '3 4 single-hyphen-option' # -u + '6 12 default' # phy1729 + '14 17 builtin' # echo + '18 18 commandseparator' # ; + '20 20 builtin' # : +) diff --git a/highlighters/main/test-data/alias-nested.zsh b/highlighters/main/test-data/alias-nested.zsh new file mode 100644 index 0000000..b24b496 --- /dev/null +++ b/highlighters/main/test-data/alias-nested.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 +# ------------------------------------------------------------------------------------------------- + +alias a=b b=: + +BUFFER='a foo; :' + +expected_region_highlight=( + '1 1 alias' # 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-argument.zsh new file mode 100644 index 0000000..ac96ad6 --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument.zsh @@ -0,0 +1,41 @@ +#!/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 sdu='sudo -u' +sudo(){} + +BUFFER='sdu phy1729 echo foo' + +expected_region_highlight=( + '1 3 alias' # sdu + '5 11 default "issue #540"' # 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 new file mode 100644 index 0000000..bf397f9 --- /dev/null +++ b/highlighters/main/test-data/alias-quoted.zsh @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) YYYY 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='ls -l' +BUFFER='"a" foo; \ls' + +expected_region_highlight=( + '1 3 unknown-token' # "a" + '5 7 default' # foo + '8 8 commandseparator' # ; + '10 12 command "issue #544' # \ls +) diff --git a/highlighters/main/test-data/alias-self.zsh b/highlighters/main/test-data/alias-self.zsh new file mode 100644 index 0000000..c6f12b1 --- /dev/null +++ b/highlighters/main/test-data/alias-self.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 +# ------------------------------------------------------------------------------------------------- + +alias echo='echo foo' + +BUFFER='echo bar' + +expected_region_highlight=( + '1 4 alias' # echo + '6 8 default' # bar +) From b6e0aeb380b313ee0a6745a4ba4bc7db5cc2eec0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 12:23:47 -0400 Subject: [PATCH 0679/1080] main: Use unknown-token when the token type is unknown --- 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 b32d415..8b9a2aa 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -544,7 +544,7 @@ _zsh_highlight_main_highlighter_highlight_list() 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 + elif ! _zsh_highlight_main__type "$arg" || [[ $REPLY == 'none' ]]; then style=unknown-token else # The common case. From 3ddb974a3d21262f6b5de933325c744117ba0adb Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:42:57 -0500 Subject: [PATCH 0680/1080] main: Remove needless code The below code handles this case. --- highlighters/main/main-highlighter.zsh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8b9a2aa..00c6838 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -610,13 +610,6 @@ _zsh_highlight_main_highlighter_highlight_list() fi } - # Special-case the first word after 'sudo'. - if (( ! in_redirection )); then - if [[ $this_word == *':sudo_opt:'* ]] && [[ $arg != -* ]]; then - this_word=${this_word//:sudo_opt:/} - fi - fi - # Parse the sudo command line if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then From df431eeee88a8e51c86866ae6e416a014fa25d33 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:43:24 -0500 Subject: [PATCH 0681/1080] main: Recognize repeat with the other reserved words --- 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 00c6838..c9d5050 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -701,6 +701,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:' esac ;; 'suffix alias') style=suffix-alias;; @@ -853,17 +864,6 @@ _zsh_highlight_main_highlighter_highlight_list() elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then next_word=':start:' - elif [[ $arg == "repeat" && $this_word == *':start:'* ]]; then - # 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:' fi start_pos=$end_pos if (( in_redirection == 0 )); then From ae5b9b2dc9efbd9f26d188be3784ae6184ac10d7 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:43:40 -0500 Subject: [PATCH 0682/1080] main: Set redirection style when recognizing the redirection --- highlighters/main/main-highlighter.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index c9d5050..1289fec 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -569,6 +569,7 @@ _zsh_highlight_main_highlighter_highlight_list() already_added=1 else in_redirection=2 + style=redirection fi fi @@ -751,8 +752,6 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi - elif (( in_redirection == 2 )); then - style=redirection elif [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # @@ -841,8 +840,6 @@ _zsh_highlight_main_highlighter_highlight_list() else style=unknown-token fi - elif (( in_redirection == 2 )); then - style=redirection else _zsh_highlight_main_highlighter_highlight_argument 1 already_added=1 From c05ebf762c34b41434bfa22480a5fdde3ad780f6 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:43:56 -0500 Subject: [PATCH 0683/1080] main: Do not recognize always as a reserved word in a redirection --- 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 1289fec..b8a398f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -638,11 +638,12 @@ _zsh_highlight_main_highlighter_highlight_list() fi # The Great Fork: is this a command word? Is this a non-command word? - if [[ $this_word == *':always:'* && $arg == 'always' ]]; then + if (( in_redirection )); then + elif [[ $this_word == *':always:'* && $arg == 'always' ]]; then # try-always construct style=reserved-word # de facto a reserved word, although not de jure next_word=':start:' - elif [[ $this_word == *':start:'* ]] && (( in_redirection == 0 )); then # $arg is the command word + elif [[ $this_word == *':start:'* ]]; then # $arg is the command word if (( ${+precommand_options[$arg]} )) && _zsh_highlight_main__is_runnable $arg; then [[ $res != alias ]] && style=precommand flags_with_argument=${precommand_options[$arg]%:*} From de28e20fbc8103911bc898097b6675348a533c0c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Mar 2018 21:44:39 -0500 Subject: [PATCH 0684/1080] main: Simplify this_word next_word updating --- highlighters/main/main-highlighter.zsh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b8a398f..1d83e02 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -384,7 +384,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=':start:' next_word + local this_word next_word=':start:' integer in_redirection # Processing buffer local proc_buf="$buf" @@ -398,15 +398,13 @@ _zsh_highlight_main_highlighter_highlight_list() # Save an unmunged copy of the current word. arg_raw="$arg" - # Initialize $next_word. - if (( in_redirection )); then - (( --in_redirection )) - fi + # Initialize this_word and next_word. if (( in_redirection == 0 )); then - # Initialize $next_word to its default value. + this_word=$next_word next_word=':regular:' else # Stall $next_word. + (( --in_redirection )) fi # Initialize per-"simple command" [zshmisc(1)] variables: @@ -493,7 +491,8 @@ _zsh_highlight_main_highlighter_highlight_list() style=unknown-token # prematurely terminated fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - already_added=1 + # Stall this arg + in_redirection=1 start_pos=$end_pos continue fi @@ -864,12 +863,6 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' fi start_pos=$end_pos - if (( in_redirection == 0 )); then - # This is the default/common codepath. - this_word=$next_word - else - # Stall $this_word. - fi done REPLY=$(( end_pos - 1 )) reply=($list_highlights) From c76daac095f03c6dcfb08a61c071d55bc3ccc245 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 13:47:13 -0400 Subject: [PATCH 0685/1080] main: Move start_pos=$end_pos to the beginning of the loop This allows for use of continue. --- highlighters/main/main-highlighter.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 1d83e02..463a439 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -330,7 +330,7 @@ _zsh_highlight_highlighter_main_paint() # exit code is 0 if the braces_stack is empty, 1 otherwise. _zsh_highlight_main_highlighter_highlight_list() { - integer start_pos=0 end_pos buf_offset=$1 has_end=$3 + integer start_pos end_pos=0 buf_offset=$1 has_end=$3 local buf=$4 highlight_glob=true arg arg_raw style local in_array_assignment=false # true between 'a=(' and the matching ')' integer len=$#buf @@ -428,6 +428,7 @@ _zsh_highlight_main_highlighter_highlight_list() 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)..} @@ -493,7 +494,6 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style # Stall this arg in_redirection=1 - start_pos=$end_pos continue fi @@ -862,7 +862,6 @@ _zsh_highlight_main_highlighter_highlight_list() [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then next_word=':start:' fi - start_pos=$end_pos done REPLY=$(( end_pos - 1 )) reply=($list_highlights) From 9289a57de041d3ec55a6276ad6e0237ddfd21e33 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 13:55:14 -0400 Subject: [PATCH 0686/1080] main: Remove already_assigned --- highlighters/main/main-highlighter.zsh | 33 +++++++++----------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 463a439..014eeb3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -409,16 +409,10 @@ _zsh_highlight_main_highlighter_highlight_list() # Initialize per-"simple command" [zshmisc(1)] variables: # - # $already_added (see next paragraph) # $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" # - # $already_added is set to 1 to disable adding an entry to region_highlight - # for this iteration. Currently, that is done for "" and $'' strings, - # which add the entry early so escape sequences within the string override - # the string's color. - integer already_added=0 style=unknown-token if [[ $this_word == *':start:'* ]]; then in_array_assignment=false @@ -565,11 +559,11 @@ _zsh_highlight_main_highlighter_highlight_list() if _zsh_highlight_main__is_redirection $arg ; then if (( in_redirection )); then _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token - already_added=1 else in_redirection=2 - style=redirection + _zsh_highlight_main_add_region_highlight $start_pos $end_pos redirection fi + continue fi # Expand parameters. @@ -722,9 +716,7 @@ _zsh_highlight_main_highlighter_highlight_list() command) style=command;; hashed) style=hashed-command;; none) if _zsh_highlight_main_highlighter_check_assign; then - style=assign - _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - already_added=1 + _zsh_highlight_main_add_region_highlight $start_pos $end_pos assign local i=$(( arg[(i)=] + 1 )) if [[ $arg[i] == '(' ]]; then in_array_assignment=true @@ -740,6 +732,7 @@ _zsh_highlight_main_highlighter_highlight_list() } fi fi + continue elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion elif [[ $arg[0,1] == $histchars[2,2] ]]; then @@ -762,13 +755,11 @@ _zsh_highlight_main_highlighter_highlight_list() # # We highlight just the opening parentheses, as a reserved word; this # is how [[ ... ]] is highlighted, too. - style=reserved-word - _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) $style - already_added=1 + _zsh_highlight_main_add_region_highlight $start_pos $((start_pos + 2)) reserved-word if [[ $arg[-2,-1] == '))' ]]; then - _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos $style - already_added=1 + _zsh_highlight_main_add_region_highlight $((end_pos - 2)) $end_pos reserved-word fi + continue elif [[ $arg == '()' ]]; then # anonymous function style=reserved-word @@ -793,12 +784,12 @@ _zsh_highlight_main_highlighter_highlight_list() fi ;; *) _zsh_highlight_main_add_region_highlight $start_pos $end_pos arg0_$res - already_added=1 + continue ;; esac fi fi - if (( ! already_added )) && [[ $style == unknown-token ]] && # not handled by the 'command word' codepath + if [[ $style == unknown-token ]] && # not handled by the 'command word' codepath { (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] } then # $arg is a non-command word case $arg in @@ -842,14 +833,12 @@ _zsh_highlight_main_highlighter_highlight_list() fi else _zsh_highlight_main_highlighter_highlight_argument 1 - already_added=1 + continue fi ;; esac fi - if ! (( already_added )); then - _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - fi + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then if [[ $arg == ';' ]] && $in_array_assignment; then # literal newline inside an array assignment From b07514788881a2196df1834f79a4062308dd8dd2 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 18:06:33 -0400 Subject: [PATCH 0687/1080] main: Consolidate conditionals together. No functional change. --- 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 014eeb3..6930ec2 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -631,12 +631,12 @@ _zsh_highlight_main_highlighter_highlight_list() fi # The Great Fork: is this a command word? Is this a non-command word? - if (( in_redirection )); then - elif [[ $this_word == *':always:'* && $arg == 'always' ]]; then + if false; then + 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:' - elif [[ $this_word == *':start:'* ]]; then # $arg is the command word + 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 flags_with_argument=${precommand_options[$arg]%:*} @@ -788,10 +788,7 @@ _zsh_highlight_main_highlighter_highlight_list() ;; esac fi - fi - if [[ $style == unknown-token ]] && # not handled by the 'command word' codepath - { (( in_redirection )) || [[ $this_word == *':regular:'* ]] || [[ $this_word == *':sudo_opt:'* ]] || [[ $this_word == *':sudo_arg:'* ]] } - then # $arg is a non-command word + else # $arg is a non-command word case $arg in $'\x29') # subshell or end of array assignment if $in_array_assignment; then From 2f03b6d704afd172d5fdf73ca5ebde8be5824056 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 18:14:56 -0400 Subject: [PATCH 0688/1080] main: Do not highlight a redirection target as an option --- highlighters/main/main-highlighter.zsh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6930ec2..167aa73 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -829,7 +829,7 @@ _zsh_highlight_main_highlighter_highlight_list() style=unknown-token fi else - _zsh_highlight_main_highlighter_highlight_argument 1 + _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 - in_redirection )) continue fi ;; @@ -926,9 +926,10 @@ _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. _zsh_highlight_main_highlighter_highlight_argument() { - local base_style=default i=$1 path_eligible=1 ret start style + local base_style=default i=$1 option_eligible=${2:-1} path_eligible=1 ret start style local -a highlights local -a match mbegin mend @@ -936,12 +937,14 @@ _zsh_highlight_main_highlighter_highlight_argument() case "$arg[i]" in '-') - if [[ $arg[i+1] == - ]]; then - base_style=double-hyphen-option - else - base_style=single-hyphen-option + if (( option_eligible )); then + if [[ $arg[i+1] == - ]]; then + base_style=double-hyphen-option + else + base_style=single-hyphen-option + fi + path_eligible=0 fi - path_eligible=0 ;; '=') if [[ $arg[i+1] == $'\x28' ]]; then From dea05e44e67129768d0321ed6e2a8c4cd599b922 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 18:18:52 -0400 Subject: [PATCH 0689/1080] main: Recognize more redirection and array assignment parse errors () ) } are invalid as a redirection target. () } are invalid in an array assignment. --- highlighters/main/main-highlighter.zsh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 167aa73..18c30a3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -795,6 +795,8 @@ _zsh_highlight_main_highlighter_highlight_list() 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 @@ -804,11 +806,15 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main__stack_pop 'R' reserved-word fi;; $'\x28\x29') # possibly a function definition - if [[ $zsyh_user_options[multifuncdef] == on ]] || false # TODO: or if the previous word was a command word - then - next_word+=':start:' + 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:' + fi + style=reserved-word fi - style=reserved-word ;; *) if false; then elif [[ $arg = $'\x7d' ]] && $right_brace_is_recognised_everywhere; then @@ -816,9 +822,13 @@ _zsh_highlight_main_highlighter_highlight_list() # # Additionally, `tt(})' is recognized in any position if neither the # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. - _zsh_highlight_main__stack_pop 'Y' reserved-word - if [[ $style == reserved-word ]]; then - next_word+=':always:' + 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 From 5bb5703b0dab128125c4948fb41d543c644452ed Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 18:24:03 -0400 Subject: [PATCH 0690/1080] main: Move TOKENS_CONTROL_FLOW handling into command word branch No functional change. --- highlighters/main/main-highlighter.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 18c30a3..210c735 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -788,6 +788,9 @@ _zsh_highlight_main_highlighter_highlight_list() ;; esac fi + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} ]]; then + next_word=':start:' + fi else # $arg is a non-command word case $arg in $'\x29') # subshell or end of array assignment @@ -854,9 +857,6 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' highlight_glob=true fi - elif - [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW:#"$arg"} && $this_word == *':start:'* ]]; then - next_word=':start:' fi done REPLY=$(( end_pos - 1 )) From c6e3d216ec005c6c127a82d5e9f3493954028510 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 1 Oct 2018 18:24:51 -0400 Subject: [PATCH 0691/1080] main: Consolidate TOKENS_COMMANDSEPARATOR handling No functional change. --- highlighters/main/main-highlighter.zsh | 39 ++++++++++---------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 210c735..dcd3355 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -631,7 +631,21 @@ _zsh_highlight_main_highlighter_highlight_list() fi # The Great Fork: is this a command word? Is this a non-command word? - if false; then + if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then + if [[ $this_word == *':regular:'* ]]; then + # This highlights empty commands (semicolon follows nothing) as an error. + # Zsh accepts them, though. + style=commandseparator + else + style=unknown-token + fi + if [[ $arg == ';' ]] && $in_array_assignment; then + # literal newline inside an array assignment + next_word=':regular:' + else + next_word=':start:' + highlight_glob=true + 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 @@ -737,14 +751,6 @@ _zsh_highlight_main_highlighter_highlight_list() style=history-expansion elif [[ $arg[0,1] == $histchars[2,2] ]]; then style=history-expansion - elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - if [[ $this_word == *':regular:'* ]]; then - # This highlights empty commands (semicolon follows nothing) as an error. - # Zsh accepts them, though. - style=commandseparator - else - style=unknown-token - fi elif [[ $arg[1,2] == '((' ]]; then # Arithmetic evaluation. # @@ -835,12 +841,6 @@ _zsh_highlight_main_highlighter_highlight_list() fi elif [[ $arg[0,1] = $histchars[0,1] ]] && (( $#arg[0,2] == 2 )); then style=history-expansion - elif [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - if [[ $this_word == *':regular:'* ]]; then - style=commandseparator - else - style=unknown-token - fi else _zsh_highlight_main_highlighter_highlight_argument 1 $(( 1 - in_redirection )) continue @@ -849,15 +849,6 @@ _zsh_highlight_main_highlighter_highlight_list() esac fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style - if [[ -n ${(M)ZSH_HIGHLIGHT_TOKENS_COMMANDSEPARATOR:#"$arg"} ]]; then - if [[ $arg == ';' ]] && $in_array_assignment; then - # literal newline inside an array assignment - next_word=':regular:' - else - next_word=':start:' - highlight_glob=true - fi - fi done REPLY=$(( end_pos - 1 )) reply=($list_highlights) From e27e53b1ef19387949f4a214c641c568539bb027 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 9 Oct 2018 22:51:54 -0500 Subject: [PATCH 0692/1080] main: Highlight unknown precommand option as unknown-token --- highlighters/main/main-highlighter.zsh | 18 ++++++-- .../test-data/precommand-unknown-option.zsh | 43 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 highlighters/main/test-data/precommand-unknown-option.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index dcd3355..5e5740f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -612,12 +612,24 @@ _zsh_highlight_main_highlighter_highlight_list() # Flag that requires an argument this_word=${this_word//:start:/} next_word=':sudo_arg:' - elif [[ $arg == '-'* ]]; then - # Flag that requires no argument, or unknown flag. - # This prevents misbehavior with sudo -u -otherargument + elif [[ -n $flags_with_argument ]] && + [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]]; then + # Argument attached in the same word this_word=${this_word//:start:/} next_word+=':start:' next_word+=':sudo_opt:' + elif [[ $arg == '-'[$flags_sans_argument]# ]]; then + # Flag that requires no argument + this_word=:sudo_opt: + next_word+=':start:' + next_word+=':sudo_opt:' + elif [[ $arg == '-'* ]]; then + # Unknown flag + 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 new file mode 100644 index 0000000..1fba1b9 --- /dev/null +++ b/highlighters/main/test-data/precommand-unknown-option.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 +# ------------------------------------------------------------------------------------------------- + +sudo(){} + +BUFFER='sudo -ux ls; sudo -x ls' + +expected_region_highlight=( + '1 4 precommand' # sudo + '6 8 single-hyphen-option' # -ux + '10 11 command' # ls + '12 12 commandseparator' # ; + '14 17 precommand' # sudo + '19 20 unknown-token' # -x + '22 23 command' # ls +) From 07f259f653df042e599975261cac7be1bda17b5c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 9 Oct 2018 23:25:31 -0500 Subject: [PATCH 0693/1080] main: Avoid null elision in _check_path This could be triggered if BUFFER='\'. --- 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 5e5740f..e5f879c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -893,7 +893,7 @@ _zsh_highlight_main_highlighter_highlight_path_separators() # Else, return non-zero (and the contents of $REPLY is undefined). _zsh_highlight_main_highlighter_check_path() { - _zsh_highlight_main_highlighter_expand_path $1 + _zsh_highlight_main_highlighter_expand_path "$1" local expanded_path="$REPLY" tmp_path REPLY=path From 31276c1b64094f3919bb3595c547b66b222a17c6 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 10 Oct 2018 23:02:33 -0500 Subject: [PATCH 0694/1080] main: Avoid empty character classes Avoids an error in pre-5.0.8: bad pattern: -[]# --- highlighters/main/main-highlighter.zsh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e5f879c..fceddc4 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -608,17 +608,20 @@ _zsh_highlight_main_highlighter_highlight_list() if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then if [[ -n $flags_with_argument ]] && - [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]]; then + { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]] || + [[ $arg == '-'[$flags_with_argument] ]] }; then # Flag that requires an argument this_word=${this_word//:start:/} next_word=':sudo_arg:' elif [[ -n $flags_with_argument ]] && - [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]]; then + { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]] || + [[ $arg == '-'[$flags_with_argument]* ]] }; then # Argument attached in the same word this_word=${this_word//:start:/} next_word+=':start:' next_word+=':sudo_opt:' - elif [[ $arg == '-'[$flags_sans_argument]# ]]; then + elif [[ -n $flags_sans_argument ]] && + [[ $arg == '-'[$flags_sans_argument]# ]]; then # Flag that requires no argument this_word=:sudo_opt: next_word+=':start:' From d6586e2a4f54a66808aba3c325a614d5166342f8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 10 Oct 2018 23:22:41 -0500 Subject: [PATCH 0695/1080] main: Order precommand_options and add '-' Fixes #499. --- highlighters/main/main-highlighter.zsh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index fceddc4..41a4fb9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -260,15 +260,18 @@ _zsh_highlight_highlighter_main_paint() # have a non-empty $flags_with_argument; see test-data/precommand4.zsh. local -A precommand_options precommand_options=( - 'command' :pvV # as of zsh 5.4.2 - 'nice' n: # as of current POSIX spec - 'sudo' Cgprtu:AEHKPSVbhiklnsv # as of sudo 1.8.21p2 + # Precommand modifiers as of zsh 5.6.2 cf. zshmisc(1). + '-' '' + 'builtin' '' + 'command' :pvV + 'exec' a:cl + 'nocorrect' '' + 'noglob' '' + 'doas' aCu:Lns # as of OpenBSD's doas(1) dated September 4, 2016 - 'builtin' '' # as of zsh 5.4.2 - 'exec' a:cl # as of zsh 5.4.2 - 'nocorrect' '' # as of zsh 5.4.2 - 'noglob' '' # as of zsh 5.4.2 + '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 ) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then From aed99f6a3e9f29859682d92003731c75e43362e8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 30 Sep 2015 18:56:35 +0000 Subject: [PATCH 0696/1080] wrappers: Reimplement using Mikachu's zle-line-pre-redraw hook (workers/36650). --- zsh-syntax-highlighting.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4caf3a8..02d45f9 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,6 +49,11 @@ if true; then fi fi +integer zsh_highlight_use_redrawhook +if zle -la .match-bracket; then + (( zsh_highlight_use_redrawhook=1 )) +fi + # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- @@ -357,6 +362,11 @@ _zsh_highlight_bind_widgets() done } +if (( $zsh_highlight_use_redrawhook )); then + _zsh_highlight_bind_widgets(){} + zle -N zle-line-pre-redraw _zsh_highlight +fi + # Load highlighters from directory. # # Arguments: From 85e62a81716e194a91ed1e9c78cac45e5cba4fa6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 15 Jun 2016 23:26:23 +0000 Subject: [PATCH 0697/1080] driver: Reimplement using 'add-zle-hook-widget zle-line-pre-redraw' This feature will be released in zsh 5.3. Older zsh's will use the existing codepath. --- zsh-syntax-highlighting.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 02d45f9..8476c1a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -50,7 +50,9 @@ if true; then fi integer zsh_highlight_use_redrawhook -if zle -la .match-bracket; then +if autoload -U +X -- add-zle-hook-widget 2>/dev/null; + [[ "${${(@f)"$(which -- add-zle-hook-widget)"}[2]}" != $'\t'$histchars[3]' undefined' ]]; +then (( zsh_highlight_use_redrawhook=1 )) fi @@ -364,7 +366,9 @@ _zsh_highlight_bind_widgets() if (( $zsh_highlight_use_redrawhook )); then _zsh_highlight_bind_widgets(){} - zle -N zle-line-pre-redraw _zsh_highlight + if [[ -o zle ]]; then + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + fi fi # Load highlighters from directory. From 74a27de70d7d21e92a50a6398a5eeeb12b884a4f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 29 Jul 2016 20:32:29 +0000 Subject: [PATCH 0698/1080] driver: Hook zle-line-finish. Compare issue #288. --- zsh-syntax-highlighting.zsh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 8476c1a..1f5b827 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -365,9 +365,20 @@ _zsh_highlight_bind_widgets() } if (( $zsh_highlight_use_redrawhook )); then + _zsh_highlight__zle-line-finish() { + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # A nested function is required to hide zle parameters; see + # "User-defined widgets" in zshall. + () { + local -h +r WIDGET=zle-line-finish + _zsh_highlight "$@" + } + } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish fi fi From 30c6e7039453c9f62b52caac1d202f57c48be442 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 24 Aug 2016 22:56:09 +0000 Subject: [PATCH 0699/1080] driver: Pass zle-line-finish arguments on to _zsh_highlight. (Currently a noop) --- 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 1f5b827..4769255 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -373,7 +373,7 @@ if (( $zsh_highlight_use_redrawhook )); then () { local -h +r WIDGET=zle-line-finish _zsh_highlight "$@" - } + } "$@" } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then From 04fd6bbf53a637129f9a11137314d74d0e103d8a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 04:41:51 +0000 Subject: [PATCH 0700/1080] changelog: Note the effect of fixing #245/#90 and an alternative. --- changelog.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/changelog.md b/changelog.md index f20e69d..33cd461 100644 --- a/changelog.md +++ b/changelog.md @@ -292,6 +292,27 @@ in this area. (0a9b347483ae) +# Changes in version 0.5.0 + + +## Incompatible changes: + +- An unsuccessful completion (a ⮀ Tab press that doesn't change the + command line) no longer causes highlighting to be lost. Visual feedback can + alternatively be achieved by setting the `format` zstyle under the `warnings` + tag, for example, + + zstyle ':completion:*:warnings' format '%F{red}No matches%f' + + Refer to the [description of the `format` style in `zshcompsys(1)`] + [zshcompsys-Standard-Styles]. + + (#90, part of #245, XXXXXXXXXXXX) + +[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles + + + # Changes in version 0.4.1 ## Fixes: From d98622dcd03cf3714e0679f13582e56ebb3a8f22 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 04:45:05 +0000 Subject: [PATCH 0701/1080] changelog: Use a more specific link. --- changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 33cd461..6ed90f1 100644 --- a/changelog.md +++ b/changelog.md @@ -305,11 +305,12 @@ in this area. zstyle ':completion:*:warnings' format '%F{red}No matches%f' Refer to the [description of the `format` style in `zshcompsys(1)`] - [zshcompsys-Standard-Styles]. + [zshcompsys-Standard-Styles-format]. (#90, part of #245, XXXXXXXXXXXX) [zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style From 38477f2a3d3ffd06ec2b7496d18cc97d6ee0c4bc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 5 Sep 2016 03:23:08 +0000 Subject: [PATCH 0702/1080] driver: Use a different way of checking whether add-zle-hook-widget is present. Based on code by Bart Schaefer (reference within). Tested with zsh 5.0.7-5 (debian package) and with 5b4cbcc842c6 (39158, 5.3-to-be of today). --- zsh-syntax-highlighting.zsh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4769255..dd28bc7 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,10 +49,37 @@ if true; then fi fi +# This function takes a single argument F and returns True iff F denotes the +# name of a callable function. A function is callable if it is fully defined +# or if it is marked for autoloading and autoloading it at the first call to it +# will succeed. In particular, if a function has been marked for autoloading +# but is not available in $fpath, then this function will return False therefor. +# +# See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 +_zsh_highlight__function_callable_p() { + { # Trenary condition: if the zle/parameter module is available, ... + if (( ${+functions} )); then + # ... then use it to make the decision, ... + if (( ${+functions[$1]} )); then + [[ "$functions[$1]" != *"builtin autoload -X" ]] \ + || + ( unfunction -- "$1" && autoload -U +X -- "$1" 2>/dev/null ) + else + ( autoload -U +X -- "$1" 2>/dev/null ) + fi + else + # ... otherwise, use a fallback approach. + autoload -U +X -- "$1" 2>/dev/null + [[ "${${(@f)"$(which -- "$1")"}[2]}" != $'\t'$histchars[3]' undefined' ]] + fi + } + # Do nothing here! We return the exit code of the if. +} + integer zsh_highlight_use_redrawhook -if autoload -U +X -- add-zle-hook-widget 2>/dev/null; - [[ "${${(@f)"$(which -- add-zle-hook-widget)"}[2]}" != $'\t'$histchars[3]' undefined' ]]; +if _zsh_highlight__function_callable_p add-zle-hook-widget then + autoload -U add-zle-hook-widget (( zsh_highlight_use_redrawhook=1 )) fi From d4ab7e51d2f0d1231221e87e3f5899104bf1f0ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 16 Sep 2016 04:34:59 +0000 Subject: [PATCH 0703/1080] redo _zsh_highlight__function_callable_p --- zsh-syntax-highlighting.zsh | 51 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index dd28bc7..4aa7b99 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -49,6 +49,25 @@ if true; then fi fi +# This function takes a single argument F and returns True iff F is an autoload stub. +_zsh_highlight__function_is_autoload_stub_p() { + if (( ${+functions} )); then + ## zsh/parameter is available + #(( ${+functions[$1]} )) && + [[ "$functions[$1]" == *"builtin autoload -X" ]] + else + ## zsh/parameter isn't available + #[[ $(type -wa -- "$1") == *'function'* ]] && + [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] + fi + # Do nothing here: return the exit code of the if. +} + +# Return True iff the argument denotes a function name. +_zsh_highlight__is_function_p() { + (( ${+functions[$1]} )) || [[ $(type -wa -- "$1") == *'function'* ]] +} + # This function takes a single argument F and returns True iff F denotes the # name of a callable function. A function is callable if it is fully defined # or if it is marked for autoloading and autoloading it at the first call to it @@ -57,23 +76,21 @@ fi # # See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { - { # Trenary condition: if the zle/parameter module is available, ... - if (( ${+functions} )); then - # ... then use it to make the decision, ... - if (( ${+functions[$1]} )); then - [[ "$functions[$1]" != *"builtin autoload -X" ]] \ - || - ( unfunction -- "$1" && autoload -U +X -- "$1" 2>/dev/null ) - else - ( autoload -U +X -- "$1" 2>/dev/null ) - fi - else - # ... otherwise, use a fallback approach. - autoload -U +X -- "$1" 2>/dev/null - [[ "${${(@f)"$(which -- "$1")"}[2]}" != $'\t'$histchars[3]' undefined' ]] - fi - } - # Do nothing here! We return the exit code of the if. + if _zsh_highlight__is_function_p "$1" && + ! _zsh_highlight__function_is_autoload_stub_p "$1" + then + # Already fully loaded. + return 0 # true + else + # "$1" is either an autoload stub, or not a function at all. + # + # Use a subshell to avoid affecting the calling shell. + # + # We expect 'autoload +X' to return non-zero if it fails to fully load + # the function. + ( autoload -U +X -- "$1" 2>/dev/null ) + return $? + fi } integer zsh_highlight_use_redrawhook From 1651137f5ca9673e4d40b43d8bcea450e10ec9f9 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 7 Oct 2016 14:21:57 +0000 Subject: [PATCH 0704/1080] docs: Update FAQ answer per changes on this branch. --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08af2b6..34b5ef1 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,23 @@ FAQ ### Why must `zsh-syntax-highlighting.zsh` be sourced at the end of the `.zshrc` file? -`zsh-syntax-highlighting.zsh` wraps ZLE widgets. It must be sourced after all +zsh-syntax-highlighting works by hooking into the Zsh Line Editor (ZLE) and +computing syntax highlighting for the command-line buffer as it stands at the +time z-sy-h's hook is invoked. + +In zsh 5.2 and older, +`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must be sourced after all custom widgets have been created (i.e., after all `zle -N` calls and after -running `compinit`). Widgets created later will work, but will not update the +running `compinit`) in order to be able to wrap all of them. +Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. +In zsh 5.3 and newer, +zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install +a `zle-line-pre-redraw` hook. Hooks are run in order of registration, +therefore, z-sy-h must be sourced (and register its hook) after anything else +that adds hooks that modify the command-line buffer. + ### Does syntax highlighting work during incremental history search? Highlighting the command line during an incremental history search (by default bound to From 66ae59ecccffb31722e4924028ae4949c3380af2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 7 Oct 2016 14:22:23 +0000 Subject: [PATCH 0705/1080] docs: Rewrap. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 34b5ef1..dbfc8b8 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ computing syntax highlighting for the command-line buffer as it stands at the time z-sy-h's hook is invoked. In zsh 5.2 and older, -`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must be sourced after all -custom widgets have been created (i.e., after all `zle -N` calls and after -running `compinit`) in order to be able to wrap all of them. +`zsh-syntax-highlighting.zsh` hooks into ZLE by wrapping ZLE widgets. It must +be sourced after all custom widgets have been created (i.e., after all `zle -N` +calls and after running `compinit`) in order to be able to wrap all of them. Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. From d2594c115796a90e548c3249684bc5ce5fdfb68e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 14:49:53 +0000 Subject: [PATCH 0706/1080] noop: Make a whitespace-only change to reduce noise in the next commit. --- zsh-syntax-highlighting.zsh | 132 ++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 4aa7b99..5e16fd2 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -337,76 +337,78 @@ _zsh_highlight_add_highlight() # $1 is name of widget to call _zsh_highlight_call_widget() { - builtin zle "$@" && + builtin zle "$@" && _zsh_highlight } -# Rebind all ZLE widgets to make them invoke _zsh_highlights. -_zsh_highlight_bind_widgets() -{ - setopt localoptions noksharrays - typeset -F SECONDS - local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once +if true; then + # Rebind all ZLE widgets to make them invoke _zsh_highlights. + _zsh_highlight_bind_widgets() + { + setopt localoptions noksharrays + typeset -F SECONDS + local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once - # Load ZSH module zsh/zleparameter, needed to override user defined widgets. - zmodload zsh/zleparameter 2>/dev/null || { - print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' - return 1 + # Load ZSH module zsh/zleparameter, needed to override user defined widgets. + zmodload zsh/zleparameter 2>/dev/null || { + print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' + return 1 + } + + # Override ZLE widgets to make them invoke _zsh_highlight. + local -U widgets_to_bind + widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)}) + + # Always wrap special zle-line-finish widget. This is needed to decide if the + # current line ends and special highlighting logic needs to be applied. + # E.g. remove cursor imprint, don't highlight partial paths, ... + widgets_to_bind+=(zle-line-finish) + + # Always wrap special zle-isearch-update widget to be notified of updates in isearch. + # This is needed because we need to disable highlighting in that case. + widgets_to_bind+=(zle-isearch-update) + + local cur_widget + for cur_widget in $widgets_to_bind; do + case ${widgets[$cur_widget]:-""} in + + # Already rebound event: do nothing. + user:_zsh_highlight_widget_*);; + + # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function + # definition time is used. + # + # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with + # NO_function_argzero, regardless of the option's setting here. + + # User defined widget: override and rebind old one with prefix "orig-". + user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Completion widget: override and rebind old one with prefix "orig-". + completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} + eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Builtin widget: override and make it call the builtin ".widget". + builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" + zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; + + # Incomplete or nonexistent widget: Bind to z-sy-h directly. + *) + if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then + _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } + zle -N $cur_widget _zsh_highlight_widget_$cur_widget + else + # Default: unhandled case. + print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" + print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)" + fi + esac + done } - - # Override ZLE widgets to make them invoke _zsh_highlight. - local -U widgets_to_bind - widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank|yank-pop)}) - - # Always wrap special zle-line-finish widget. This is needed to decide if the - # current line ends and special highlighting logic needs to be applied. - # E.g. remove cursor imprint, don't highlight partial paths, ... - widgets_to_bind+=(zle-line-finish) - - # Always wrap special zle-isearch-update widget to be notified of updates in isearch. - # This is needed because we need to disable highlighting in that case. - widgets_to_bind+=(zle-isearch-update) - - local cur_widget - for cur_widget in $widgets_to_bind; do - case ${widgets[$cur_widget]:-""} in - - # Already rebound event: do nothing. - user:_zsh_highlight_widget_*);; - - # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function - # definition time is used. - # - # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with - # NO_function_argzero, regardless of the option's setting here. - - # User defined widget: override and rebind old one with prefix "orig-". - user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Completion widget: override and rebind old one with prefix "orig-". - completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]} - eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Builtin widget: override and make it call the builtin ".widget". - builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }" - zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;; - - # Incomplete or nonexistent widget: Bind to z-sy-h directly. - *) - if [[ $cur_widget == zle-* ]] && (( ! ${+widgets[$cur_widget]} )); then - _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight } - zle -N $cur_widget _zsh_highlight_widget_$cur_widget - else - # Default: unhandled case. - print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}" - print -r -- >&2 "zsh-syntax-highlighting: (This is sometimes caused by doing \`bindkey ${(q-)cur_widget}\` without creating the ${(qq)cur_widget} widget with \`zle -N\` or \`zle -C\`.)" - fi - esac - done -} +fi if (( $zsh_highlight_use_redrawhook )); then _zsh_highlight__zle-line-finish() { From b5249f17abe4850ae3a6fa9130b3be78923e41dc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 15:12:24 +0000 Subject: [PATCH 0707/1080] driver: Rewrite without a state variable Suggested-by: m0viefreak --- zsh-syntax-highlighting.zsh | 45 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 5e16fd2..f020b33 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -93,13 +93,6 @@ _zsh_highlight__function_callable_p() { fi } -integer zsh_highlight_use_redrawhook -if _zsh_highlight__function_callable_p add-zle-hook-widget -then - autoload -U add-zle-hook-widget - (( zsh_highlight_use_redrawhook=1 )) -fi - # ------------------------------------------------------------------------------------------------- # Core highlighting update system # ------------------------------------------------------------------------------------------------- @@ -341,7 +334,25 @@ _zsh_highlight_call_widget() _zsh_highlight } -if true; then +if _zsh_highlight__function_callable_p add-zle-hook-widget +then + autoload -U add-zle-hook-widget + _zsh_highlight__zle-line-finish() { + # Reset $WIDGET since the 'main' highlighter depends on it. + # + # A nested function is required to hide zle parameters; see + # "User-defined widgets" in zshall. + () { + local -h +r WIDGET=zle-line-finish + _zsh_highlight "$@" + } "$@" + } + _zsh_highlight_bind_widgets(){} + if [[ -o zle ]]; then + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish + fi +else # Rebind all ZLE widgets to make them invoke _zsh_highlights. _zsh_highlight_bind_widgets() { @@ -410,24 +421,6 @@ if true; then } fi -if (( $zsh_highlight_use_redrawhook )); then - _zsh_highlight__zle-line-finish() { - # Reset $WIDGET since the 'main' highlighter depends on it. - # - # A nested function is required to hide zle parameters; see - # "User-defined widgets" in zshall. - () { - local -h +r WIDGET=zle-line-finish - _zsh_highlight "$@" - } "$@" - } - _zsh_highlight_bind_widgets(){} - if [[ -o zle ]]; then - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight - add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish - fi -fi - # Load highlighters from directory. # # Arguments: From a868b6942ea017dcd09cdcd6461d27825838364e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 17 Oct 2016 17:51:04 +0000 Subject: [PATCH 0708/1080] test harness: Actually test the new code. Currently, without zsh/zle loaded, the tests silently fall back to the 5.2-and-earlier codepath; see: . https://github.com/zsh-users/zsh-syntax-highlighting/pull/356#issuecomment-243651251 --- tests/generate.zsh | 3 +++ tests/test-highlighting.zsh | 3 +++ tests/test-perfs.zsh | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/generate.zsh b/tests/generate.zsh index 64a1ede..ef89f94 100755 --- a/tests/generate.zsh +++ b/tests/generate.zsh @@ -31,6 +31,9 @@ emulate -LR zsh setopt localoptions extendedglob +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Argument parsing. if (( $# != 3 )) || [[ $1 == -* ]]; then print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME" diff --git a/tests/test-highlighting.zsh b/tests/test-highlighting.zsh index 812b1a7..e5c85a1 100755 --- a/tests/test-highlighting.zsh +++ b/tests/test-highlighting.zsh @@ -31,6 +31,9 @@ setopt NO_UNSET WARN_CREATE_GLOBAL +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." diff --git a/tests/test-perfs.zsh b/tests/test-perfs.zsh index 3411754..49d95c7 100755 --- a/tests/test-perfs.zsh +++ b/tests/test-perfs.zsh @@ -29,6 +29,9 @@ # ------------------------------------------------------------------------------------------------- +# Required for add-zle-hook-widget. +zmodload zsh/zle + # Check an highlighter was given as argument. [[ -n "$1" ]] || { echo >&2 "Bail out! You must provide the name of a valid highlighter as argument." From f665eec230e66cc62f0c6a02cc63dc13e3124e5c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jan 2018 05:44:54 +0000 Subject: [PATCH 0709/1080] driver: Avoid a fork in the common case. Found-by: Matthew Martin --- 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 f020b33..04152c4 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -65,7 +65,13 @@ _zsh_highlight__function_is_autoload_stub_p() { # Return True iff the argument denotes a function name. _zsh_highlight__is_function_p() { - (( ${+functions[$1]} )) || [[ $(type -wa -- "$1") == *'function'* ]] + if (( ${+functions} )); then + ## zsh/parameter is available + (( ${+functions[$1]} )) + else + ## zsh/parameter isn't available + [[ $(type -wa -- "$1") == *'function'* ]] + fi } # This function takes a single argument F and returns True iff F denotes the From d0fb0df4ff96209d6623896f07be7db2655cf1b4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 8 Jan 2018 06:03:38 +0000 Subject: [PATCH 0710/1080] driver: Make the shadowing $WIDGET read only. --- 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 04152c4..6fb1c12 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -349,7 +349,7 @@ then # A nested function is required to hide zle parameters; see # "User-defined widgets" in zshall. () { - local -h +r WIDGET=zle-line-finish + local -h -r WIDGET=zle-line-finish _zsh_highlight "$@" } "$@" } From f265ef0b9aadfea02c696821664c8598f5809b91 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 8 Jan 2018 12:35:45 -0600 Subject: [PATCH 0711/1080] driver: Use idiomatic module check --- zsh-syntax-highlighting.zsh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 6fb1c12..c03c434 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -51,12 +51,10 @@ fi # This function takes a single argument F and returns True iff F is an autoload stub. _zsh_highlight__function_is_autoload_stub_p() { - if (( ${+functions} )); then - ## zsh/parameter is available + if zmodload -e zsh/parameter; then #(( ${+functions[$1]} )) && [[ "$functions[$1]" == *"builtin autoload -X" ]] else - ## zsh/parameter isn't available #[[ $(type -wa -- "$1") == *'function'* ]] && [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] fi @@ -65,11 +63,9 @@ _zsh_highlight__function_is_autoload_stub_p() { # Return True iff the argument denotes a function name. _zsh_highlight__is_function_p() { - if (( ${+functions} )); then - ## zsh/parameter is available + if zmodload -e zsh/parameter; then (( ${+functions[$1]} )) else - ## zsh/parameter isn't available [[ $(type -wa -- "$1") == *'function'* ]] fi } From 2cbb3fb24ecf0880165f57d823746e2f257c3619 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 8 Jan 2018 12:59:56 -0600 Subject: [PATCH 0712/1080] driver: Allow for -U in autoloaded function definition --- 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 c03c434..17ce59c 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -53,7 +53,7 @@ fi _zsh_highlight__function_is_autoload_stub_p() { if zmodload -e zsh/parameter; then #(( ${+functions[$1]} )) && - [[ "$functions[$1]" == *"builtin autoload -X" ]] + [[ "$functions[$1]" == *"builtin autoload -X"* ]] else #[[ $(type -wa -- "$1") == *'function'* ]] && [[ "${${(@f)"$(which -- "$1")"}[2]}" == $'\t'$histchars[3]' undefined' ]] From 56ba7f082d171102deaeb35a14e900ab1a6a6495 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 9 Jan 2018 19:23:45 +0000 Subject: [PATCH 0713/1080] driver: Clarify comment. No functional change. --- zsh-syntax-highlighting.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 17ce59c..9dc6c1f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -342,8 +342,9 @@ then _zsh_highlight__zle-line-finish() { # Reset $WIDGET since the 'main' highlighter depends on it. # - # A nested function is required to hide zle parameters; see - # "User-defined widgets" in zshall. + # Since $WIDGET is declared by zle as read-only in this function's scope, + # a nested function is required in order to shadow its built-in value; + # see "User-defined widgets" in zshall. () { local -h -r WIDGET=zle-line-finish _zsh_highlight "$@" From 47c2b7e1851375c3a9d3c1faec5851fc8409da08 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 08:14:42 -0500 Subject: [PATCH 0714/1080] 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: Sat, 13 Oct 2018 21:55:45 -0500 Subject: [PATCH 0715/1080] driver: Do not pass widget arguments to _zsh_highlight This avoids a bug in zsh 4.3.12 and prior which affects passing arguments to an anonymous function. --- 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 9dc6c1f..aa650d3 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -347,8 +347,8 @@ then # see "User-defined widgets" in zshall. () { local -h -r WIDGET=zle-line-finish - _zsh_highlight "$@" - } "$@" + _zsh_highlight + } } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then From 9d6ecea21c0c4328cf215091f8b99ab762039104 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 18 Oct 2018 23:45:17 +0000 Subject: [PATCH 0716/1080] 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 0717/1080] 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 0718/1080] 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 0719/1080] 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 0720/1080] '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 0721/1080] 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 0722/1080] 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 0723/1080] 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 0724/1080] 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 0725/1080] 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 0726/1080] 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 0727/1080] 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 0728/1080] 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 0729/1080] '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 0730/1080] 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 0731/1080] '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 0732/1080] '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 0733/1080] 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 0734/1080] 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 0735/1080] 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 0736/1080] 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 0737/1080] 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 0738/1080] 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 0739/1080] 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 0740/1080] 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 0741/1080] 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 0742/1080] 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 0743/1080] 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 0744/1080] 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 0745/1080] 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 0746/1080] 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 0747/1080] 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 0748/1080] 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 0749/1080] 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 0750/1080] 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 0751/1080] 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 0752/1080] 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 0753/1080] 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 0754/1080] 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 0755/1080] 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 0756/1080] 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 0757/1080] 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 0758/1080] 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 0759/1080] 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 0760/1080] 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 0761/1080] '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 0762/1080] '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 0763/1080] '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 0764/1080] '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 0765/1080] 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 0766/1080] '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 0767/1080] '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 0768/1080] '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 0769/1080] '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 0770/1080] 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 0771/1080] '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 0772/1080] 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 0773/1080] '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 0774/1080] '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 0775/1080] '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 0776/1080] 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 0777/1080] 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 0778/1080] 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 0779/1080] 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 0780/1080] 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 0781/1080] 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 0782/1080] 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 0783/1080] '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 0784/1080] 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 0785/1080] 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 0786/1080] 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 0787/1080] 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 0788/1080] 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 0789/1080] 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 0790/1080] 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 0791/1080] 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 0792/1080] 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 0793/1080] 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 0794/1080] '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 0795/1080] '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 0796/1080] '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 0797/1080] '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 0798/1080] 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 0799/1080] '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 0800/1080] 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 0801/1080] 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 0802/1080] 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 0803/1080] 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 0804/1080] 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 0805/1080] 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 0806/1080] 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 0807/1080] 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 0808/1080] 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 0809/1080] 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 0810/1080] 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 0811/1080] 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 0812/1080] '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 0813/1080] '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 0814/1080] '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 0815/1080] '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 0816/1080] '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 0817/1080] '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 0818/1080] '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 0819/1080] '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 0820/1080] '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 0821/1080] '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 0822/1080] '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 0823/1080] '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 0824/1080] '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 0825/1080] '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 0826/1080] 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 0827/1080] 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 0828/1080] 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 0829/1080] 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 0830/1080] 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 0831/1080] 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 0832/1080] 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 0833/1080] '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 0834/1080] 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 0835/1080] '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 0836/1080] 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 0837/1080] 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 0838/1080] 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 0839/1080] 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 0840/1080] 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 0841/1080] 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 0842/1080] 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 0843/1080] '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 0844/1080] '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 0845/1080] 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 0846/1080] '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 0847/1080] '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 0848/1080] '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 0849/1080] 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 0850/1080] 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 0851/1080] 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 0852/1080] 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 0853/1080] 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 0854/1080] 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 0855/1080] 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 0856/1080] 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 0857/1080] 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 0858/1080] 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 0859/1080] 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 0860/1080] 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 0861/1080] 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 0862/1080] 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 0863/1080] 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 0864/1080] 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 0865/1080] 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 0866/1080] 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 0867/1080] '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 0868/1080] '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 0869/1080] 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 0870/1080] 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 zcmeAS@N?(olHy`uVBq!ia0y~yU}R!oU=Zd2kzX!M>1AMG;LLY(D`tQIa|SP6v0n@f z3R7#Mi;JY5_^GVZ;NN{&fcFzmtZPOz<6ctw_R3>zCl?jU;6cX(eNnRTsPCzAO^o`@&WKR>PmASA-eD`;z_og!n z#IC>KZSQmC#m?e`3}p=4Yz4K1m2)51^Ua?7aUY+At;5Mpw;`WWXtq1u&gfKH~lbaTK_{Y{O3R!ZepBa8*pI3YMW!d$7|D&4I zpZnhDy~k(3Xb|b+85|s(`<7d*J%3}y-rKzO%a2s;w13LL%&7N4pyFDcm;41*t_JnD z$9FcUDlo}ymrP+!V-WUWfA!?Yn!29YOZUSbZjoE|>OqRC)Txgi{HyOwnAMp)v*ON* zieFPs&UyM+p6%xSwd@SbzByR0J+*@Co>)VQ08}(?ah3cY7vZl6jGF zZAzK-;zc*5?`H(mr>J%PWX@%Is+780vFXeGM_yaod$%cj25zh@jr|pRX}i4fqWLP? zdh5g#o|JxCdVQ^T$vXb%>;-=Xyc3h_F3nx?ZPUe9Cj$&ii?*q(+_*nIY~K`Kp?wb@ zJnTzr+SH3b}Ra|ZI_TAhihs?O$Ui#miK4IdtnZLT<&#;`ha{2QY z!9~FaY}=Ua4lpH%Cn!ljXO3rTJP@QH5y7(|#r0x|0z(923-kLe4>?)>Fw`sT;O(~& zFtaOc?azD7F`J#g`pt}npMMu9+B2@)@V;*TEZIlP?wrw_BOhA)|3hE!bv+lE&Z>~O zi93=v$+0p_`8etI)$2|Bd(WNPSNiP4#@9C&85e)yV3_wd-94CV(mDCwJyW9Q)PDP1 zUU4?$)#0#t=LA&a?Fzqy=iMvm*>MpyB zp_L!izrEWx<-f|iKPxBi{(fBaIZJ=wqVL`%YOLzd)aUWt-1z^|-W$f^mp_&Frj}dB zSKWOveSL9lN89ahyDj+_@wL6Pt1)#hsXi@Hda2d+w5rDP7dMWbz1V4fUS|Ka;F+7U zo3>qvJ6ZPdBs;(UyL;d6-a9>$)lfU-^�UI$EDE9<9C2>~#Ll>GL+*ugtryr`M(Z z!1(96#!mCUYo2bC5!t{gp}1RyyM|Ywf#KePAd~BFauRmEk$A)Mhmnurfba))jsr~F znBE!5`6n1Zx%RuIThi}_kzn>O=aq+b+WS5EIOO>GO?S@j=189>az83p@w3O4=k8a- zVq?<|GBRv?+LbN3Q!%gUS?b6&nR zHS=j$v9mqpne5*i9;;NYR~=l&8s@d7Znw00$G11Zs`YEkrt@*AwJx1MW2tM$I{%WZ zQ(f6aPHQUcee=XechQr|9dEkUGrAsM{AQQ7w&jJ$DlL}9&6i$xI~_aO*ZAn?rPprL z1=iZR96jRWZsqm$#O_Wvrca7JfOYE=6U->otN7x=E<6L-R^5J zwX%rca(iuR{pt$WDR=+hYGb@AdHnSIpV7u5UvA&EU|g|hfBcj^M<=ohtnKe#F8{+p zRAHB$_|b>LmI+olbu)h5H4w9y%s(wAI?3nahYfA{{@ypAsa&3K{L`UwcJhLXeP4E6 zT##MM5xsZ)*5=C}0{2a1JsB-ChzSJ1S~oRAFH2u5D_rD_?R%E zHB)BTMqgX^=TP+@2Gy=byEd__l%CH@eXK7n&FRYE6};l&flIZ=J-OT;KiaGqc(a#5 zrQiRItWC{P)os6zanE!;d3@RpbN7=u%O33geKl+EhM6DbtoM0*lKVCF^-t&SoH^Ij zOYh}|F|k-&O*|gXsLx>hpf5=~hAo4^Mv|XDfbEp%Z{2`zGEA}?8l$+xmd(iRV-sXr zJaMhZZBNOwQD&OT6))b3zjc`!pp~Vy>FeW{(knVAyROyRpR<2!oXC@@FQTJYPW-)8 zh{5IPkq~DY?W`=Vljkb)Ob-Q?p1*Dm0p-SjJihMqxAlL1_NmM)LG|s*Z+n(| z#{6)(e<{X6NLz)$Vpf#amCM&MTR%@-9L;{=rL*L@yOKHOb#E5rPtIc4Ft^@^@9n91 zeERa;U7mqgo`teo-^t?0)bj87lUDb{d|#VfbiHL+hVPu-_?qO;mm3TV9xl5We(jx4 za8T$vJnVxwUx(09t-f-Er#hjxc>n-n# z$_lgjvc9X=X$p21C!78FH{**+jneYlphCX?+*iRq{vVG|Uf%OV`s2%$;m&oxOwCho z2dM3>{e3hFl@N81AMG;LLY(D`tQIa|SP6v0n@f z3R7#O%6JzX3_GVZ;NN{6?p2{Ijg|InE(z~M z?2`WMJM+u@yLI{dt=Hq8->E()%fP8J!GQ@v*fITj?UWq#*`};!vG=dt-bXZJGB<6V z$@O#ddFv>fkB=0NM&`})6Sljo_wn$HUtF3uE7YG(7x`Oxvyz9AVWX_R%DkES_En#o zQXU2eJxw>|@^iiyrFK$G6MFbl!dUCAyPp0tt#t2J&y#6-x9-ZN z&&BqCs|-E`xt$G{U~qgMZ$I<6^^03=FW;4$t9s6Se=Glwg~Gy#zstidWjyNIx>Nnn z?3>z`_dNbQf6tdWE=&xw?oPaLSg)<*n*udMI>YyUTebFc+>bfuUobH!X!Xutv)o7RA=a{_U{hIjgPa?~}Oa<`w;?Y@0kYr6jYx6otIMuhx$^ z<#z3Jdf&uDOOBt3*io@eEHol+)vV6BlP9n3+-1VnaKYo%(d)hnKVCbB$=K)Ko8%fl zn`g4GP5i^3!iHOx->iMTC1cyfUk}<6v+l>8(>bAk=J(m!cdIt+SrMA$bUk#{!?up+ z`j7tf&)-q9euGltZI!BczMYx37jvyDdUuzn(?@UJY2GNqd8eu?LfhqSq~?EB`E_jZ zq-S^H-%hFEdC~UTsYrX%`<52fXIDjz=e+7y7V$XuC?)NrYxK*;cNvj+`zC}0{rU0d zSY(!xo%%{+|EHqABfqmct})&C_I%TMSG!%(Rkq(!lY_5WR*Uj5FkJprap&8K?;bUQ zg;`&|emH(K^y2D}2@L=KlpZ*#t>^D^`fr@`BevdudMB+~r?p$1RN59@lO6f%toOgp zr&~44m6ZRiUvg#2k8?{OJ$F6DUAy_z=0$(b#dcQDl98Pr|8KQwrerPqerxxg?E4SHez5nd%<|8UG8?qK#wAyv;P7--po%; zEw|-q|J`9%c5mDNWn#~d<;+tl(Neg!iNo)e-rj$vEShUO-)7WqaP4PeaG1B@ZD8=q z`KF7{i_N`z_T+CLNd^XwICpnPhI$*>f=^wig(qCX?Bypt12MKeyLQG1DsGFe zdHuKdmBh(2zeAmm7`eK{3f(EVA1iyfTRHb@cHp_p;(1*?mUioRt@^v~-F&u1*SptC z$2so!r68Frn|d$Qr}XXJT`jz?ls|~hvu`vxzJ1N7Ce!tzET*%UPSdfAUh=kobL}&Z z_(dF#%a&|gGAHKUf#%2jjz4?S-(4R+Hy6JD3~;_>D(9M{+adyyUs-{43*wkd-dLtsDHOLd>U2%&pR?NCGFbj z-2uXnr^nvmow3QNJ0w2%{^{p(?{=HZ{=HtkYqwwWscedU@bJ^ODzu01fb@coHhn%?#6-?AM{h^Sn% zG`_TRmAu9z?gMXMRo$r?+ZCl{%*^z;@riJGsDf|^}p^}x61MAM)&d<*-NK( zJ({##INfLBUWv;(Uj5eEr(Rw8qHc6?bCn*0g5=wcpXNMS6(^X-+OY1_Co5O&Qmq5k zn_jIcW%sMNRdVmn`xKce7cVIP$@3}xIjxm-U+`rs_RdpBQ)U?b{kwSeN@GjQP-d;~ zJnOjn>(?{L{&+4rUH!mr^~USB^Xm7jtjaNcI?Mai?ukcUJ`K6H%J)L*f;DP-3;`k{ zsT-#C-_pt2>r^7mW>ag>d-Zv3@B0WT*^_zf44Z!5oWtF8>@nl@`3xLi&C*(ByPMB;^XmsF zGYL#tySL28cc(;@%7G&$i+z`WI}@nJC=i-sV=l2ob;&-)1grUb_pJE&#)i53EThs{ zMux7J$K;RwEqfJp^Fo}U`i?c*!_*iAZkn-wKXZ1c&>yDn8=Fqc$FtW}z7&rAR<+hF zF{tE?Eq~6Ol`bLMZ&f9%o@(VN;9oIcvSjO#cOeVBXVxdoyD;nLv6pp{WqVKDDxR;} z&7d;v=YHFqB`o_^aK4&uvFqW>W(lrON51_!#>e2WY4Y}W@#{PVOyu}?{8RD0QKfqz zm#dqJA@=LiRNnWqW=FBh_31o+eeZQq{l>5zSV5XaiMhjFT00(GS{tJk^NL3X zSGZlpxochdt$A^FWsg%`3opL@Hch-yyR`EC+!@o3KfX3Y^i1N!f}fwSHs;42VmZI1 zJoe{)ANk#O`}WQ*KInGTa?Qr&hG#ta9)5W9zHwJ{P4?5J{Oze7Z^e#t&hUTsmUqut zwr^}d3SY3jcKUSt)@zG7ms*(LrEkt=eja>eop`)?&4=slrsse6-{rRbt_uyGk4Z4X`|+AQjg~OD9xI*Yts~u`HMPuM0HJX zK8#j$nRfX~*i^BvDlCh&>lZ5jDsY(?em!7G?~~-ndZ%qi`K5K*-v&-R^y>CnPy4=u z0=|`RBCajq;W%6%{OFVXD(1MjSxt*f*ce1ARVA4iCd}~i5&HLoUm;-WOO-}$hPFhH z2pN~qkWi^zeI3F2eR(rpO?v!rqO-uR(=`eA&z@KBP+I@9b(&49e57G*>vR7mljWdG?rRnL8f>u$)_U~Mg^8i&?u%P##>Yw<9a;P4vE>P5+@k>AY0MuD!aRz8XJwpY&8{WD)XEXk78bzBM^tox$yUJ*Z*r M>FVdQ&MBb@0H49S#{d8T literal 0 HcmV?d00001 From 34df84a7dd88e55a629d90f644e021d995e1a616 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 11 Mar 2020 16:52:08 +0000 Subject: [PATCH 0871/1080] '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 0872/1080] 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 0873/1080] 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 0874/1080] 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 0875/1080] 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 0876/1080] 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 0877/1080] 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 0878/1080] '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 0879/1080] '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 0880/1080] 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 0881/1080] '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 0882/1080] 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 0883/1080] 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 0884/1080] '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 0885/1080] 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 0886/1080] 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 0887/1080] '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 0888/1080] 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 0889/1080] 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 0890/1080] 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 0891/1080] 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 0892/1080] '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 0893/1080] '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 0894/1080] '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 0895/1080] '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 0896/1080] 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 0897/1080] 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 0898/1080] 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 0899/1080] 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 0900/1080] '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 0901/1080] =?UTF-8?q?'main':=20Don't=20use=20=C2=ABfoo=20&?= =?UTF-8?q?&=20bar=20||=20baz=C2=BB=20where=20a=20trenary=20is=20more=20ap?= =?UTF-8?q?propriate.?= 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 0902/1080] '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 0903/1080] '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 0904/1080] 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 0905/1080] 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 0906/1080] '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 0907/1080] '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 0908/1080] 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 0909/1080] 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 0910/1080] 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 0911/1080] 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 0912/1080] 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 0913/1080] '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 0914/1080] '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 0915/1080] '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 0916/1080] 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 0917/1080] '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 0918/1080] '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 0919/1080] '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 0920/1080] 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 0921/1080] 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 0922/1080] 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 0923/1080] '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 0924/1080] '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 0925/1080] 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 0926/1080] 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 0927/1080] 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 0928/1080] 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 0929/1080] 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 0930/1080] 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 0931/1080] 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 0932/1080] 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 0933/1080] 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 0934/1080] 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 0935/1080] 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 0936/1080] '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 0937/1080] 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 0938/1080] 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 0939/1080] 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 0940/1080] '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 0941/1080] 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 0942/1080] 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 0943/1080] '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 0944/1080] '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 0945/1080] '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 0946/1080] '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 0947/1080] '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 0948/1080] '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 0949/1080] '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 0950/1080] '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 0951/1080] '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 0952/1080] '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 0953/1080] '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 0954/1080] 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 0955/1080] 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 0956/1080] 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 0957/1080] 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 0958/1080] 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 0959/1080] 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 0960/1080] '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 0961/1080] =?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 0962/1080] 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 0963/1080] 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 0964/1080] 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 0965/1080] '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 0966/1080] 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 0967/1080] 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 0968/1080] '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 0969/1080] '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 0970/1080] 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 0971/1080] 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 0972/1080] '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 0973/1080] '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 0974/1080] '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 0975/1080] 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 0976/1080] 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 0977/1080] 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 0978/1080] 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 0979/1080] 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 0980/1080] '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 0981/1080] '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 0982/1080] '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 b08d508cd8792df2b6c8e044e42dffeb7f9118fe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 15:49:24 +0000 Subject: [PATCH 0983/1080] driver: Fix a bug that prevented subsequent, third-party zle-line-pre-redraw hooks from running. Without this patch, `_zsh_highlight` was invoked by add-zle-hook-widget with `$?` being non-zero (see add-zle-hook-widget:48-52). Since `_zsh_highlight` preserves `$?` from its caller's point of view, add-zle-hook-widget saw a non-zero exit code from `_zsh_highlight` and did not run any the remaining zle-line-pre-redraw hooks. See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-623576907. --- 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 aa650d3..47a4e07 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -350,9 +350,15 @@ then _zsh_highlight } } + _zsh_highlight__zle-line-pre-redraw() { + # Set $? to 0 for _zsh_highlight. Without this, subsequent + # zle-line-pre-redraw hooks won't run, since add-zle-hook-widget happens to + # call us with $? == 1 in the common case. + true && _zsh_highlight "$@" + } _zsh_highlight_bind_widgets(){} if [[ -o zle ]]; then - add-zle-hook-widget zle-line-pre-redraw _zsh_highlight + add-zle-hook-widget zle-line-pre-redraw _zsh_highlight__zle-line-pre-redraw add-zle-hook-widget zle-line-finish _zsh_highlight__zle-line-finish fi else From 343ec1061fda6ecbc9782e33a8e4539525899594 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 4 May 2020 17:34:59 +0000 Subject: [PATCH 0984/1080] '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 0985/1080] '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 0986/1080] '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 0987/1080] 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 0988/1080] '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 0989/1080] '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 0990/1080] '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 0991/1080] 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 0992/1080] 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 0993/1080] 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 0994/1080] 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 0995/1080] '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 0996/1080] '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 0997/1080] 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 0998/1080] '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 0999/1080] 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 1000/1080] 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 1001/1080] 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 1002/1080] 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 1003/1080] '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 1004/1080] 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 1005/1080] '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 1006/1080] 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 1007/1080] 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 1008/1080] 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 1009/1080] 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 1010/1080] 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 1011/1080] 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 1012/1080] 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. From daf0d94baedab4f8bf76dbfb0bcdae3dba005e11 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:00:45 +0000 Subject: [PATCH 1013/1080] On the feature/redrawhook branch, move the changelog entry to the current release's section. --- changelog.md | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index 280f434..7951f38 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,25 @@ added to zsh at z-sy-h's initiative. The new feature is used in the fix to issue #418. +## Incompatible changes: + +- An unsuccessful completion (a ⮀ Tab press that doesn't change the + command line) no longer causes highlighting to be lost. Visual feedback can + alternatively be achieved by setting the `format` zstyle under the `warnings` + tag, for example, + + zstyle ':completion:*:warnings' format '%F{red}No matches%f' + + Refer to the [description of the `format` style in `zshcompsys(1)`] + [zshcompsys-Standard-Styles-format]. + + (#90, part of #245 (feature/redrawhook)) + +[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style + + + ## Other changes: - Document `$ZSH_HIGHLIGHT_MAXLENGTH`. @@ -485,28 +504,6 @@ in this area. (0a9b347483ae) -# Changes in version 0.5.0 - - -## Incompatible changes: - -- An unsuccessful completion (a ⮀ Tab press that doesn't change the - command line) no longer causes highlighting to be lost. Visual feedback can - alternatively be achieved by setting the `format` zstyle under the `warnings` - tag, for example, - - zstyle ':completion:*:warnings' format '%F{red}No matches%f' - - Refer to the [description of the `format` style in `zshcompsys(1)`] - [zshcompsys-Standard-Styles-format]. - - (#90, part of #245, XXXXXXXXXXXX) - -[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles -[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style - - - # Changes in version 0.4.1 ## Fixes: From 8a1bd7c8b647fb237bd0d2b475d3fcabcc9d7463 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:07:32 +0000 Subject: [PATCH 1014/1080] driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function. This is needed for feature/redrawhook to be able to use it. --- zsh-syntax-highlighting.zsh | 48 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index f98dc4b..b899050 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -62,28 +62,12 @@ else typeset -g zsh_highlight__pat_static_bug=true fi -# Array declaring active highlighters names. -typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS +# Probe the memo= feature, once. When this anonymous function returns, +# $zsh_highlight__memo_feature will be set (either to 0 or to 1). +() { + # Provide a mock $region_highlight. (The test suite's mock might not have been set up yet.) + (( ${+region_highlight} )) || typeset -a region_highlight -# Update ZLE buffer syntax highlighting. -# -# Invokes each highlighter that needs updating. -# This function is supposed to be called whenever the ZLE state changes. -_zsh_highlight() -{ - # Store the previous command return code to restore it whatever happens. - local ret=$? - # 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 - } - - # Probe the memo= feature, once. (( ${+zsh_highlight__memo_feature} )) || { region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" ) case ${region_highlight[-1]} in @@ -126,6 +110,28 @@ _zsh_highlight() esac region_highlight[-1]=() } +} + +# Array declaring active highlighters names. +typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS + +# Update ZLE buffer syntax highlighting. +# +# Invokes each highlighter that needs updating. +# This function is supposed to be called whenever the ZLE state changes. +_zsh_highlight() +{ + # Store the previous command return code to restore it whatever happens. + local ret=$? + # 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 + } # Reset region_highlight to build it from scratch if (( zsh_highlight__memo_feature )); then From 59cb9a560d3b2acdb21c666d09ff43411c2153a0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:13:51 +0000 Subject: [PATCH 1015/1080] driver: Make the redrawhook codepath conditional upon the memo= feature. Fixes #579 (zsh-autosuggestions interoperability). Fixes #735 (ditto). See https://github.com/zsh-users/zsh-syntax-highlighting/issues/579#issuecomment-650126055 See https://github.com/zsh-users/zsh-autosuggestions/issues/529#issuecomment-650481227 --- zsh-syntax-highlighting.zsh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index c2811a0..87ffb6a 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -403,7 +403,17 @@ _zsh_highlight_call_widget() _zsh_highlight } -if _zsh_highlight__function_callable_p add-zle-hook-widget +# Decide whether to use the zle-line-pre-redraw codepath (colloquially known as +# "feature/redrawhook", after the topic branch's name) or the legacy "bind all +# widgets" codepath. +# +# We use the new codepath under two conditions: +# +# 1. If it's available, which we check by testing for add-zle-hook-widget's availability. +# +# 2. If zsh has the memo= feature, which is required for interoperability reasons. +# See issues #579 and #735, and the issues referenced from them. +if (( zsh_highlight__memo_feature )) && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From d62baa50f48fb9780f900c93c762992ce7f76826 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:29:46 +0000 Subject: [PATCH 1016/1080] Revert "driver: Move the initialization of $zsh_highlight__memo_feature out of the entry point function." This reverts commit 8a1bd7c8b647fb237bd0d2b475d3fcabcc9d7463. The detection only works correctly from a widget function, so the change was wrong: it caused zsh_highlight__memo_feature to be set to false every time. --- zsh-syntax-highlighting.zsh | 48 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index b899050..f98dc4b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -62,12 +62,28 @@ else typeset -g zsh_highlight__pat_static_bug=true fi -# Probe the memo= feature, once. When this anonymous function returns, -# $zsh_highlight__memo_feature will be set (either to 0 or to 1). -() { - # Provide a mock $region_highlight. (The test suite's mock might not have been set up yet.) - (( ${+region_highlight} )) || typeset -a region_highlight +# Array declaring active highlighters names. +typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS +# Update ZLE buffer syntax highlighting. +# +# Invokes each highlighter that needs updating. +# This function is supposed to be called whenever the ZLE state changes. +_zsh_highlight() +{ + # Store the previous command return code to restore it whatever happens. + local ret=$? + # 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 + } + + # Probe the memo= feature, once. (( ${+zsh_highlight__memo_feature} )) || { region_highlight+=( " 0 0 fg=red, memo=zsh-syntax-highlighting" ) case ${region_highlight[-1]} in @@ -110,28 +126,6 @@ fi esac region_highlight[-1]=() } -} - -# Array declaring active highlighters names. -typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS - -# Update ZLE buffer syntax highlighting. -# -# Invokes each highlighter that needs updating. -# This function is supposed to be called whenever the ZLE state changes. -_zsh_highlight() -{ - # Store the previous command return code to restore it whatever happens. - local ret=$? - # 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 - } # Reset region_highlight to build it from scratch if (( zsh_highlight__memo_feature )); then From cb33cc0081234c0f8e48d89e0ba81cf58a8f7635 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 02:37:41 +0000 Subject: [PATCH 1017/1080] On the feature/redrawhook branch, change the detection of the 'memo=' feature to avoid a catch-22. --- zsh-syntax-highlighting.zsh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index cbdd530..3608203 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -407,7 +407,14 @@ _zsh_highlight_call_widget() # # 2. If zsh has the memo= feature, which is required for interoperability reasons. # See issues #579 and #735, and the issues referenced from them. -if (( zsh_highlight__memo_feature )) && _zsh_highlight__function_callable_p add-zle-hook-widget +# +# We check this with a plain version number check, since a functional check, +# as done by _zsh_highlight, can only be done from inside a widget +# function — a catch-22. +# +# See _zsh_highlight for the magic version number. (The use of 5.8.0.2 +# rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) +if is-at-least 5.8.0.2 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From cdd7f899cb9aae7b5a39729d3b5aab33f89b4f6f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 20:15:50 +0000 Subject: [PATCH 1018/1080] brackets: Optimize the character iteration Test case: See the first comment of issue #295. Before: num calls time self name ----------------------------------------------------------------------------------- 1) 14 284.67 20.33 82.84% 284.67 20.33 82.84% _zsh_highlight_highlighter_brackets_paint 2) 15 313.72 20.91 91.30% 26.62 1.77 7.75% _zsh_highlight 3) 14 318.68 22.76 92.74% 7.41 0.53 2.16% _zsh_highlight_call_widget After: num calls time self name ----------------------------------------------------------------------------------- 1) 15 57.25 3.82 45.33% 28.30 1.89 22.41% _zsh_highlight 2) 14 81.96 5.85 64.90% 27.02 1.93 21.40% _zsh_highlight_call_widget 3) 14 26.31 1.88 20.84% 26.31 1.88 20.84% _zsh_highlight_highlighter_brackets_paint 4) 2 10.66 5.33 8.44% 8.97 4.49 7.10% VCS_INFO_formats 5) 2 25.92 12.96 20.52% 7.72 3.86 6.11% VCS_INFO_get_data_git (That's not in my everyday configuration but in my minimal testing setup, which runs vcs_info with the default settings.) --- changelog.md | 2 ++ highlighters/brackets/brackets-highlighter.zsh | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index daeda05..cc3153e 100644 --- a/changelog.md +++ b/changelog.md @@ -112,6 +112,8 @@ to issue #418. revision zsh-5.8-172-gdd6e702ee or newer is also fine.) [#418, https://github.com/okapia/zsh-viexchange/issues/1] +- Improve performance of the `brackets` highlighter. + # Changes in version 0.7.1 diff --git a/highlighters/brackets/brackets-highlighter.zsh b/highlighters/brackets/brackets-highlighter.zsh index fc71f2a..bc388fd 100644 --- a/highlighters/brackets/brackets-highlighter.zsh +++ b/highlighters/brackets/brackets-highlighter.zsh @@ -51,8 +51,9 @@ _zsh_highlight_highlighter_brackets_paint() local -A levelpos lastoflevel matching # Find all brackets and remember which one is matching - for (( pos = 1; pos <= buflen; pos++ )) ; do - char=$BUFFER[pos] + pos=0 + for char in ${(s..)BUFFER} ; do + (( ++pos )) case $char in ["([{"]) levelpos[$pos]=$((++level)) From 00a5fd11eb9d1c163fb49da5310c8f4b09fb3022 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 21:05:34 +0000 Subject: [PATCH 1019/1080] Tag version 0.8.0-alpha1-pre-redrawhook. --- .version | 2 +- changelog.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.version b/.version index c7d2522..41c20b3 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.7.2-dev +0.8.0-alpha1-pre-redrawhook diff --git a/changelog.md b/changelog.md index cc3153e..96ad507 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -# Changes in HEAD +# Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility From 2d60a47cc407117815a1d7b331ef226aa400a344 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 1020/1080] Post-release version number bump. --- .version | 2 +- changelog.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.version b/.version index 41c20b3..9fb1210 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0-alpha1-pre-redrawhook +0.8.0-alpha2-dev diff --git a/changelog.md b/changelog.md index 96ad507..518d6a8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +# Changes in HEAD + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility From cba4a1bc2e62833a4f5631b89e0974585db39103 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 14 Jul 2020 23:20:29 +0000 Subject: [PATCH 1021/1080] On the feature/redrawhook branch, changelog: Add entries for issues fixed by this branch. This covers issues referenced from #245 or labelled "feature:redrawhook" or "widget-wrapping". See #749 for details. --- changelog.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/changelog.md b/changelog.md index 44ddbe0..1bc1ac0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,57 @@ # Changes in HEAD +## Changes fixed as part of the switch to zle-line-pre-redraw + +The changes in this section were fixed by switching to a `zle-line-pre-redraw`-based +implementation. + +Note: The new implementation will only be used on future zsh releases, +numbered 5.8.0.3 and newer, due to interoperability issues with other plugins +(issues #418 and #579). The underlying zsh feature has been available since +zsh 5.2. + +Whilst under development, the new implementation was known as the +"feature/redrawhook" topic branch. + +- Fixed: Highlighting not triggered after popping a buffer from the buffer stack + (using the `push-line` widget, default binding: `M-q`) + [#40] + +- Fixed: Invoking completion when there were no matches removed highlighting + [#90, #470] + +- Fixed: Two successive deletes followed by a yank only yanked the latest + delete, rather than both of them + [#150, #151, #160; cf. #183] + +- Presumed fixed: Completing `$(xsel)` results in an error message from `xsel`, + with pre-2017 versions of `xsel`. (For 2017 vintage and newer, see the issue + for details.) + [#154] + +- Fixed: When the standard `bracketed-paste-magic` widget is in use, pastes were slow + [#295] + +- Fixed: No way to prevent a widget from being wrapped + [#324] + +- Fixed: No highlighting while cycling menu completion + [#375] + +- Fixed: Does not coexist with the `IGNORE_EOF` option + [#377] + +- Fixed: The `undefined-key` widget was wrapped + [#421] + +- Fixed: Does not coexist with the standard `surround` family of widgets + [#520] + +- Fixed: First completed filename doesn't get `path` highlighting + [#632] + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility From 7cc6226477a46e7f8217239686912c9cc4a7696b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 9 Aug 2020 10:54:01 +0000 Subject: [PATCH 1022/1080] docs: Track making the new codepath conditional upon the 'memo=' feature. The new codepath is used in 5.8.0.2 and newer; see zsh-syntax-highlighting.zsh:417. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52896c0..303ee1e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ calls and after running `compinit`) in order to be able to wrap all of them. Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting. -In zsh 5.3 and newer, +In zsh newer than 5.8 (not including 5.8 itself), zsh-syntax-highlighting uses the `add-zle-hook-widget` facility to install a `zle-line-pre-redraw` hook. Hooks are run in order of registration, therefore, z-sy-h must be sourced (and register its hook) after anything else From c14fcad3b08e19dce750b4b0eb6cc597e0f93d57 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 9 Aug 2020 11:09:19 +0000 Subject: [PATCH 1023/1080] empty commit: Close redrawhook bugs The parent commit, which merged the feature/redrawhook bug and thereby closed PR #749, also fixed the following issue: Fixes #40. Fixes #90, closes #470. (The latter is a PR for the former.) Fixes #150, closes #151, closes #160. (The latter two are PR's for the first one.) The related issue #183 appears to have been fixed in master. For #150, a different fix for older versions of zsh was considered but has not been implemented. Issue #154 was fixed in xsel(1) in 2017. The parent commit probably fixed that issue for pre-2017 xsel(1). Is #245, #356, and #749. Fixes #245 (redrawhook umbrella issue). Does not reintroduce #257 (comment). Does not reintroduce #259 (comment) Closes #281 as obsolete. Fixes #295. Fixes #324. Fixes #375. Fixes #377. Closes #421 as obsolete. Fixes #520. Unblocks #536 (already milestoned). Fixes #632. Unblocks #635. Milestoned. Unblocks #688. Milestoned. Unblocks administrative issue #655 (already milestoned). (The above is copied from https://github.com/zsh-users/zsh-syntax-highlighting/pull/749#issuecomment-658407330, but repeated here for the sake of github's commit-to-issue linking magic.) From e4d1db1e2cf2f0bb6158408e8adf3c9938f2f8df Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Jul 2020 23:23:20 -0500 Subject: [PATCH 1024/1080] docs: Sort INSTALL.md --- INSTALL.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index fc0f752..834cdae 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,21 +9,21 @@ How to install * 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]) -* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] +* Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) * Void Linux: `zsh-syntax-highlighting package` [in XBPS][void-package] [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git -[debian-package]: https://packages.debian.org/zsh-syntax-highlighting -[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ -[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb -[ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting +[debian-package]: https://packages.debian.org/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 +[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ +[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting +[ubuntu-package]: https://launchpad.net/ubuntu/+source/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 34674d7860ea34bad2bdc4afc8beb8af6dc245a8 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 14 Jul 2020 23:23:58 -0500 Subject: [PATCH 1025/1080] docs: Add OpenBSD port --- INSTALL.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 834cdae..49b8ce5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,6 +9,7 @@ How to install * 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] +* OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * Ubuntu: `zsh-syntax-highlighting` package [in Xenial][ubuntu-package] (or in [OBS repository][obs-repository]) @@ -23,6 +24,7 @@ How to install [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting +[openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting From 3944a44ffe447b64d4bc55a1ff66154363bb0dd6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 10 Aug 2020 07:36:40 +0000 Subject: [PATCH 1026/1080] driver: Fix a version number check to work around a bug in the zsh version whereunder the check should return false. The bug is as follows: % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 && echo yes || echo no' yes % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION && echo yes || echo no' yes This commit deploys the following workaround: % zsh-5.8 -fc 'autoload is-at-least; is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && echo yes || echo no' no Fixes #756. --- 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 3608203..d20dc5b 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -163,7 +163,7 @@ _zsh_highlight() # 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 + if is-at-least 5.8.0.3 $ZSH_VERSION.0.0; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -414,7 +414,7 @@ _zsh_highlight_call_widget() # # See _zsh_highlight for the magic version number. (The use of 5.8.0.2 # rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) -if is-at-least 5.8.0.2 && _zsh_highlight__function_callable_p add-zle-hook-widget +if is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From 79b6e7e05f96f777244686be513b2e583b6143f6 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 9 Aug 2020 21:58:48 +0200 Subject: [PATCH 1027/1080] tests: precommand-killing1: Use a dummy path that always exists E.g., on Cygwin /etc/passwd does not necessarily exist. --- highlighters/main/test-data/precommand-killing1.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/precommand-killing1.zsh b/highlighters/main/test-data/precommand-killing1.zsh index 80d279b..7598346 100644 --- a/highlighters/main/test-data/precommand-killing1.zsh +++ b/highlighters/main/test-data/precommand-killing1.zsh @@ -29,11 +29,12 @@ # ------------------------------------------------------------------------------------------------- hash sudo=false +touch foo -BUFFER='sudo -e /etc/passwd' +BUFFER='sudo -e ./foo' expected_region_highlight=( '1 4 precommand' # sudo '6 7 single-hyphen-option' # -e - '9 19 path' # /etc/passwd + '9 13 path' # ./foo ) From e9cad1493fe1ef85945df66af2a5e015cfaebea8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 11 Aug 2020 08:42:59 +0000 Subject: [PATCH 1028/1080] changelog: Document #712 under the last tag, 0.8.0-alpha1-pre-redrawhook. --- changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/changelog.md b/changelog.md index 1bc1ac0..9230236 100644 --- a/changelog.md +++ b/changelog.md @@ -52,6 +52,11 @@ Whilst under development, the new implementation was known as the [#632] +## Other changes + +- Add issue #712 to the previous release's changelog (hereinafter). + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility @@ -187,6 +192,9 @@ to issue #418. - Improve performance of the `brackets` highlighter. +- Fix highlighting of pre-command redirections (e.g., the `$fn` in `<$fn cat`) + [#712] + # Changes in version 0.7.1 From 6d5372a937c63a565a1ff93aa6efa9a2b6179917 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 11 Aug 2020 09:21:21 +0000 Subject: [PATCH 1029/1080] tests: parameter-to-global-alias: Fix a false positive failure when 'x' happens to be a valid external command name. Reported on issue #757 along with other issues. --- highlighters/main/test-data/parameter-to-global-alias.zsh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh index 2c4b9bb..cd2283b 100644 --- a/highlighters/main/test-data/parameter-to-global-alias.zsh +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -28,6 +28,10 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- +if type x >/dev/null; then + skip_test="Test is written on the assumption that 'x' is not a valid command name, but that assumption does not hold" + return 0 +fi alias -g x=y local s=x From 4cf464f843902b6e1e2778b85b70f4c098789b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivo=20=C5=A0merek?= Date: Sat, 15 Aug 2020 12:24:09 +0200 Subject: [PATCH 1030/1080] docs: Update Gentoo link --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 49b8ce5..0ca2295 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -7,7 +7,7 @@ How to install * 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: [`shells/zsh-syntax-highlighting`][freebsd-port]) -* Gentoo: [mv overlay][gentoo-overlay] +* Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] @@ -22,7 +22,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 [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ -[gentoo-overlay]: http://gpo.zugaina.org/app-shells/zsh-syntax-highlighting +[gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting [openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting From 62c5575848f1f0a96161243d18497c247c9f52df Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Wed, 26 Aug 2020 08:46:53 +0000 Subject: [PATCH 1031/1080] tests: Add a test that 'rehash' isn't run. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See comments within for the rationale. This is a regression test for a regression that was only present in development versions of PR #764 and was never present in master. --- highlighters/main/test-data/no-rehash.zsh | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 highlighters/main/test-data/no-rehash.zsh diff --git a/highlighters/main/test-data/no-rehash.zsh b/highlighters/main/test-data/no-rehash.zsh new file mode 100644 index 0000000..ca11414 --- /dev/null +++ b/highlighters/main/test-data/no-rehash.zsh @@ -0,0 +1,39 @@ +# ------------------------------------------------------------------------------------------------- +# 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 zsyh-hashed-command=/usr/bin/env +BUFFER='doesnotexist; zsyh-hashed-command' + +# Test that highlighting "doesnotexist" does not invoke the "rehash" builtin, +# which would delete hashed commands (such as "zsyh-hashed-command"). +expected_region_highlight=( + "1 12 unknown-token" # doesnotexist + "13 13 commandseparator" # ; + "15 33 hashed-command" # zsyh-hashed-command +) From aac09942b86934b5d4467225d7336f495c466d10 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 12 Oct 2020 19:28:53 -0500 Subject: [PATCH 1032/1080] Revert "tests: Add a test that 'rehash' isn't run." This reverts commit 62c5575848f1f0a96161243d18497c247c9f52df. The test fails when zsh/parameter is available. --- highlighters/main/test-data/no-rehash.zsh | 39 ----------------------- 1 file changed, 39 deletions(-) delete mode 100644 highlighters/main/test-data/no-rehash.zsh diff --git a/highlighters/main/test-data/no-rehash.zsh b/highlighters/main/test-data/no-rehash.zsh deleted file mode 100644 index ca11414..0000000 --- a/highlighters/main/test-data/no-rehash.zsh +++ /dev/null @@ -1,39 +0,0 @@ -# ------------------------------------------------------------------------------------------------- -# 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 zsyh-hashed-command=/usr/bin/env -BUFFER='doesnotexist; zsyh-hashed-command' - -# Test that highlighting "doesnotexist" does not invoke the "rehash" builtin, -# which would delete hashed commands (such as "zsyh-hashed-command"). -expected_region_highlight=( - "1 12 unknown-token" # doesnotexist - "13 13 commandseparator" # ; - "15 33 hashed-command" # zsyh-hashed-command -) From 2ebfa6a59879b66b02712693731c84831255601d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 8 Oct 2020 19:35:12 -0500 Subject: [PATCH 1033/1080] main: Forget seen aliases when starting a new command Fixes #769 --- highlighters/main/main-highlighter.zsh | 1 + highlighters/main/test-data/alias-reuse1.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse2.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse3.zsh | 39 ++++++++++++++++++ highlighters/main/test-data/alias-reuse4.zsh | 42 +++++++++++++++++++ highlighters/main/test-data/alias-reuse5.zsh | 43 ++++++++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 highlighters/main/test-data/alias-reuse1.zsh create mode 100644 highlighters/main/test-data/alias-reuse2.zsh create mode 100644 highlighters/main/test-data/alias-reuse3.zsh create mode 100644 highlighters/main/test-data/alias-reuse4.zsh create mode 100644 highlighters/main/test-data/alias-reuse5.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index e59c61c..2a29d0d 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -879,6 +879,7 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' highlight_glob=true saw_assignment=false + seen_alias=() if [[ $arg != '|' && $arg != '|&' ]]; then next_word+=':start_of_pipeline:' fi diff --git a/highlighters/main/test-data/alias-reuse1.zsh b/highlighters/main/test-data/alias-reuse1.zsh new file mode 100644 index 0000000..1fd61a0 --- /dev/null +++ b/highlighters/main/test-data/alias-reuse1.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 +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a | a' + +BUFFER='b | b' + +expected_region_highlight=( + '1 1 alias' # b + '3 3 commandseparator' # | + '5 5 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse2.zsh b/highlighters/main/test-data/alias-reuse2.zsh new file mode 100644 index 0000000..37251fb --- /dev/null +++ b/highlighters/main/test-data/alias-reuse2.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 +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a && a' + +BUFFER='b && b' + +expected_region_highlight=( + '1 1 alias' # b + '3 4 commandseparator' # && + '6 6 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse3.zsh b/highlighters/main/test-data/alias-reuse3.zsh new file mode 100644 index 0000000..5d7150a --- /dev/null +++ b/highlighters/main/test-data/alias-reuse3.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 +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a; a' + +BUFFER='b; b' + +expected_region_highlight=( + '1 1 alias' # b + '2 2 commandseparator' # ; + '4 4 alias' # b +) diff --git a/highlighters/main/test-data/alias-reuse4.zsh b/highlighters/main/test-data/alias-reuse4.zsh new file mode 100644 index 0000000..7ad7038 --- /dev/null +++ b/highlighters/main/test-data/alias-reuse4.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 +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a $(a)' + +BUFFER='b $(b)' + +expected_region_highlight=( + '1 1 alias' # b + '3 6 default' # $(b) + '3 6 command-substitution-unquoted' # $(b) + '3 4 command-substitution-delimiter-unquoted' # $( + '5 5 alias' # b + '6 6 command-substitution-delimiter-unquoted' # ) +) diff --git a/highlighters/main/test-data/alias-reuse5.zsh b/highlighters/main/test-data/alias-reuse5.zsh new file mode 100644 index 0000000..881401b --- /dev/null +++ b/highlighters/main/test-data/alias-reuse5.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 +# ------------------------------------------------------------------------------------------------- + +alias a=: b='a < <(a)' + +BUFFER='b < <(b)' + +expected_region_highlight=( + '1 1 alias' # b + '3 3 redirection' # < + '5 8 default' # <(b) + '5 8 process-substitution' # <(b) + '5 6 process-substitution-delimiter' # <( + '7 7 alias' # b + '8 8 process-substitution-delimiter' # ) +) From 1715f39a4680a27abd57fc30c98a95fdf191be45 Mon Sep 17 00:00:00 2001 From: Hussaina Begum Nandyala Date: Thu, 15 Oct 2020 09:39:04 +0530 Subject: [PATCH 1034/1080] docs: Add resource link for NetBSD operating system Signed-off-by: Hussaina Begum Nandyala --- INSTALL.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 0ca2295..48b724f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,6 +9,7 @@ How to install * FreeBSD: `pkg install zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] * Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* NetBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][netbsd-port]) * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] * RHEL / CentOS / Scientific Linux: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] @@ -23,8 +24,9 @@ How to install [fedora-package-alt]: https://bodhi.fedoraproject.org/updates/?packages=zsh-syntax-highlighting [freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting +[netbsd-port]: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/shells/zsh-syntax-highlighting/ [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting -[openbsd-package]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ +[openbsd-port]: https://cvsweb.openbsd.org/ports/shells/zsh-syntax-highlighting/ [ubuntu-package]: https://launchpad.net/ubuntu/+source/zsh-syntax-highlighting [void-package]: https://github.com/void-linux/void-packages/tree/master/srcpkgs/zsh-syntax-highlighting From 046cb03a120ca3376f076d746009bf9b7f052969 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 28 Oct 2020 22:46:04 -0500 Subject: [PATCH 1035/1080] main: Convert in_alias to an array of shift counts No functional change. Keeps track of how deep we are in expanding nested aliases for the next commit. --- highlighters/main/main-highlighter.zsh | 42 ++++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 2a29d0d..45835c3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -76,7 +76,7 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 - if (( in_alias )); then + if (( $#in_alias )); then [[ $1 == unknown-token ]] && alias_style=unknown-token return fi @@ -498,17 +498,18 @@ _zsh_highlight_main_highlighter__try_expand_parameter() _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 + # 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 # param_style is analogous for parameter expansions 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. + # in_alias is an array of integers with each element equal to the number + # of shifts needed until arg=args[1] pops an arg from the next level up + # alias or from BUFFER. # in_param is analogous for parameter expansions - integer in_alias=0 in_param=0 len=$#buf - local -a match mbegin mend list_highlights + integer in_param=0 len=$#buf + local -a in_alias 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 @@ -596,9 +597,11 @@ _zsh_highlight_main_highlighter_highlight_list() last_arg=$arg arg=$args[1] shift args - if (( in_alias )); then - (( in_alias-- )) - if (( in_alias == 0 )); then + if (( $#in_alias )); then + (( in_alias[1]-- )) + # Remove leading 0 entries + in_alias=($in_alias[$in_alias[(i)<1->],-1]) + if (( $#in_alias == 0 )); then 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 @@ -637,7 +640,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi fi - if (( in_alias == 0 && in_param == 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 @@ -693,7 +696,6 @@ _zsh_highlight_main_highlighter_highlight_list() if [[ $res == "alias" ]]; then # 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 continue fi @@ -707,15 +709,15 @@ _zsh_highlight_main_highlighter_highlight_list() alias_args=(${(z)REPLY}) fi args=( $alias_args $args ) - if (( in_alias == 0 )); then + if (( $#in_alias == 0 )); then 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 )) else - # This arg is already included in the count, so no need to + 1. - (( in_alias += $#alias_args )) + # Transfer the count of this arg to the new element about to be appended. + (( in_alias[1]-- )) fi + # Add one because we will in_alias[1]-- on the next loop iteration so + # this iteration should be considered in in_alias as well + in_alias=( $(($#alias_args + 1)) $in_alias ) (( in_redirection++ )) # Stall this arg continue else @@ -854,7 +856,7 @@ _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 + elif [[ $this_word == *':start:'* ]] && [[ $arg == ';' ]] && (( $#in_alias )); then style=commandseparator else # Empty commands (semicolon follows nothing) are valid syntax. @@ -1147,7 +1149,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 + (( $#in_alias )) && in_alias=() _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 )) @@ -1258,7 +1260,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 )) && + (( ! $#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 From 75c0eb0717aa9e2f5668212155398867032df74e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 28 Oct 2020 23:09:40 -0500 Subject: [PATCH 1036/1080] main: Remember nest level an alias was seen in for seen_alias Fixes #775. --- highlighters/main/main-highlighter.zsh | 15 +++++++-- highlighters/main/test-data/alias-self2.zsh | 37 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/alias-self2.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 45835c3..4ea3f34 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -601,6 +601,12 @@ _zsh_highlight_main_highlighter_highlight_list() (( in_alias[1]-- )) # Remove leading 0 entries in_alias=($in_alias[$in_alias[(i)<1->],-1]) + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + unset "seen_alias[$alias_name]" + done + } if (( $#in_alias == 0 )); then seen_alias=() # start_pos and end_pos are of the alias (previous $arg) here @@ -699,7 +705,7 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi - seen_alias[$arg]=1 + seen_alias[$arg]=$#in_alias _zsh_highlight_main__resolve_alias $arg local -a alias_args # Elision is desired in case alias x='' @@ -881,7 +887,12 @@ _zsh_highlight_main_highlighter_highlight_list() next_word=':start:' highlight_glob=true saw_assignment=false - seen_alias=() + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + unset "seen_alias[$alias_name]" + done + } if [[ $arg != '|' && $arg != '|&' ]]; then next_word+=':start_of_pipeline:' fi diff --git a/highlighters/main/test-data/alias-self2.zsh b/highlighters/main/test-data/alias-self2.zsh new file mode 100644 index 0000000..fd6ae03 --- /dev/null +++ b/highlighters/main/test-data/alias-self2.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 +# ------------------------------------------------------------------------------------------------- + +alias cat='cat | cat' + +BUFFER='cat' + +expected_region_highlight=( + '1 3 alias' # cat +) From 5eb494852ebb99cf5c2c2bffee6b74e6f1bf38d0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 23 Dec 2020 22:13:22 -0600 Subject: [PATCH 1037/1080] Switch to GitHub Actions from Travis --- .github/workflows/test.yml | 73 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 56 ----------------------------- README.md | 6 ++-- release.md | 2 +- 4 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8221926 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,73 @@ +--- +name: Tests +on: + push: + paths-ignore: + - '**.md' + - '**.png' + pull_request: + paths-ignore: + - '**.md' + - '**.png' + schedule: + - cron: '29 7 * * 1' + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - master + - 5.8 + - 5.7.1 + - 5.7 + - 5.6.2 + - 5.6.1 + - 5.6 + - 5.5.1 + - 5.5 + - 5.4.2 + - 5.4.1 + - 5.4 + - 5.3.1 + - 5.3 + - 5.2 + - 5.1.1 + - 5.1 + - 5.0.8 + - 5.0.7 + - 5.0.6 + - 5.0.5 + - 5.0.4 + - 5.0.3 + - 5.0.2 + - 5.0.1 + - 5.0.0 + - 4.3.17 + - 4.3.16 + - 4.3.15 + - 4.3.14 + - 4.3.13 + - 4.3.12 + - 4.3.11 + container: + image: zshusers/zsh:${{ matrix.version }} + steps: + - uses: actions/checkout@v2 + - run: install_packages bsdmainutils make procps + - run: make test + + notify: + runs-on: ubuntu-latest + needs: test + if: failure() && (github.repository_owner == 'zsh-users') + steps: + - + name: Notify IRC + uses: Gottox/irc-message-action@v1 + with: + channel: '#zsh-syntax-highlighting' + nickname: zsyh-gh-bot + message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4ee2765..0000000 --- a/.travis.yml +++ /dev/null @@ -1,56 +0,0 @@ -language: generic -sudo: required - -env: - - ZSH=master - - ZSH=5.8 - - ZSH=5.7.1 - - ZSH=5.7 - - ZSH=5.6.2 - - ZSH=5.6.1 - - ZSH=5.6 - - ZSH=5.5.1 - - ZSH=5.5 - - ZSH=5.4.2 - - ZSH=5.4.1 - - ZSH=5.4 - - ZSH=5.3.1 - - ZSH=5.3 - - ZSH=5.2 - - ZSH=5.1.1 - - ZSH=5.1 - - ZSH=5.0.8 - - ZSH=5.0.7 - - ZSH=5.0.6 - - ZSH=5.0.5 - - ZSH=5.0.4 - - ZSH=5.0.3 - - ZSH=5.0.2 - - ZSH=5.0.1 - - ZSH=5.0.0 - - ZSH=4.3.17 - - ZSH=4.3.16 - - ZSH=4.3.15 - - ZSH=4.3.14 - - ZSH=4.3.13 - - 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' - -notifications: - webhooks: - urls: - - https://webhooks.gitter.im/e/367e241cdea60cb2070b - on_success: change - on_failure: always - on_start: never - irc: - channels: - - "chat.freenode.net#zsh-syntax-highlighting" - on_success: change - on_failure: always - on_start: never - use_notice: true - template: - - "%{repository}/%{branch}#%{build_number}: %{message} Changes : %{compare_url} | Build : %{build_url}" diff --git a/README.md b/README.md index 303ee1e..36fbdd7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -zsh-syntax-highlighting [![Build Status][build-status-image]][build-status-travis] +zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] ======================= **[Fish shell][fish]-like syntax highlighting for [Zsh][zsh].** @@ -93,5 +93,5 @@ Syntax highlighting is done by pluggable highlighter scripts. See the [documentation on highlighters](docs/highlighters.md) for details and configuration settings. -[build-status-image]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting.svg?branch=master -[build-status-travis]: https://travis-ci.org/zsh-users/zsh-syntax-highlighting +[build-status]: https://github.com/zsh-users/zsh-syntax-highlighting/actions +[build-status-image]: https://github.com/zsh-users/zsh-syntax-highlighting/workflows/Tests/badge.svg diff --git a/release.md b/release.md index 8df4b9c..075f221 100644 --- a/release.md +++ b/release.md @@ -5,7 +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/) + (easiest to check GitHub Actions: https://github.com/zsh-users/zsh-syntax-highlighting/actions) - Update changelog.md `tig --abbrev=12 --abbrev-commit 0.4.1..upstream/master` - Make sure there are no local commits and that `git status` is clean; From 205bc7ea199cfd4cded51d465baad63b3d7f3aad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 1 Mar 2021 20:21:39 +0000 Subject: [PATCH 1038/1080] 'main': Disable a lint warning when env(1) was followed by a pipe. Fixes #797. --- highlighters/main/main-highlighter.zsh | 4 +- .../main/test-data/null-exec2-printenv.zsh | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/null-exec2-printenv.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 4ea3f34..8f792e6 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -916,8 +916,8 @@ _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 + if [[ $arg == 'exec' || $arg == 'env' ]]; then + # To allow "exec 2>&1;" and "env | grep" where there's no command word next_word+=':regular:' fi else diff --git a/highlighters/main/test-data/null-exec2-printenv.zsh b/highlighters/main/test-data/null-exec2-printenv.zsh new file mode 100644 index 0000000..59a2cef --- /dev/null +++ b/highlighters/main/test-data/null-exec2-printenv.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 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=$'env | grep $needle' + +expected_region_highlight=( + '1 3 precommand' # env + '5 5 commandseparator' # | + '7 10 command' # grep + '12 18 default' # $needle +) From e8517244f7d2ae4f9d979faf94608d6e4a74a73e Mon Sep 17 00:00:00 2001 From: Nikola Knezevic Date: Tue, 9 Feb 2021 15:34:36 +0100 Subject: [PATCH 1039/1080] main: Allow for "]" in shell aliases PR #776 fixed an issue with complex aliases and expansion. However, this change also introduced a problem with aliases which contain `]` (for example, commonly seen on macOS: `alias ]=open`), due to using an associative array `seen_alias`, indexed by the alias name. Due to `"$seen_alias[$arg]"`, it would fail when `$arg` is expanded to anything containing `]`'. Thus, typing `] /` would result in: ``` > ] / (anon):unset:3: seen_alias[]]: invalid parameter name ``` This change fixes the issue by ensuring we properly access keys in the associative array `seen_alias`. Older versions of zsh have issues with map keys having special characters, especially lacking ways to remove such keys. The issue is described in detail in https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element. This fix uses proposal from [zsh-workers/43269](https://www.zsh.org/mla/workers/2018/msg01073.html), discovered by Stephane Chazelas, that boils down to avoid removing keys from the map, and reconstruct the map anew with some keys omitted. Co-authored-by: @phy1729 --- highlighters/main/main-highlighter.zsh | 19 +++++---- .../main/test-data/alias-brackets.zsh | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 highlighters/main/test-data/alias-brackets.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 8f792e6..9186157 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -601,16 +601,19 @@ _zsh_highlight_main_highlighter_highlight_list() (( in_alias[1]-- )) # Remove leading 0 entries in_alias=($in_alias[$in_alias[(i)<1->],-1]) - (){ - local alias_name - for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do - unset "seen_alias[$alias_name]" - done - } if (( $#in_alias == 0 )); then 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 + else + # We can't unset keys that contain special characters (] \ and some others). + # More details: https://www.zsh.org/workers/43269 + (){ + local alias_name + for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do + seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}") + done + } fi fi if (( in_param )); then @@ -890,7 +893,9 @@ _zsh_highlight_main_highlighter_highlight_list() (){ local alias_name for alias_name in ${(k)seen_alias[(R)<$#in_alias->]}; do - unset "seen_alias[$alias_name]" + # We can't unset keys that contain special characters (] \ and some others). + # More details: https://www.zsh.org/workers/43269 + seen_alias=("${(@kv)seen_alias[(I)^$alias_name]}") done } if [[ $arg != '|' && $arg != '|&' ]]; then diff --git a/highlighters/main/test-data/alias-brackets.zsh b/highlighters/main/test-data/alias-brackets.zsh new file mode 100644 index 0000000..ede6c9a --- /dev/null +++ b/highlighters/main/test-data/alias-brackets.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 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 +# ------------------------------------------------------------------------------------------------- + +# Have to use cat here as it must be a command that exists. +# Otherwise, the test would fail with the first token being recognized +# as an "unknown-token". +alias ]=cat + +BUFFER='] /' + +expected_region_highlight=( + '1 1 alias' # ] + '3 3 path' # / +) From 993a07fc7f4e077b556192cfc5c3efc29b40fd96 Mon Sep 17 00:00:00 2001 From: Robert <64484887+robert5800@users.noreply.github.com> Date: Sat, 10 Apr 2021 22:48:51 +0200 Subject: [PATCH 1040/1080] docs: Fix broken link to fish shell --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36fbdd7..4803ec7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] *Requirements: zsh 4.3.11+.* -[fish]: http://www.fishshell.com/ +[fish]: https://fishshell.com/ [zsh]: http://www.zsh.org/ This package provides syntax highlighting for the shell zsh. It enables From ebef4e55691f62e630318d56468e5798367aa81c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 14 Apr 2021 10:39:01 +0000 Subject: [PATCH 1041/1080] docs: Use SSL for the link to zsh's homepage. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4803ec7..482a648 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ zsh-syntax-highlighting [![Build Status][build-status-image]][build-status] *Requirements: zsh 4.3.11+.* [fish]: https://fishshell.com/ -[zsh]: http://www.zsh.org/ +[zsh]: https://www.zsh.org/ This package provides syntax highlighting for the shell zsh. It enables highlighting of commands whilst they are typed at a zsh prompt into an From 894127b221ab73847847bf7cf31eeb709bc16dc5 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 20 May 2021 20:10:34 -0500 Subject: [PATCH 1042/1080] docs,CI: Switch to Libera.Chat --- .github/workflows/test.yml | 1 + HACKING.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8221926..df2b726 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,6 +68,7 @@ jobs: name: Notify IRC uses: Gottox/irc-message-action@v1 with: + server: irc.libera.chat channel: '#zsh-syntax-highlighting' nickname: zsyh-gh-bot message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' diff --git a/HACKING.md b/HACKING.md index 6fd195c..ddd39a4 100644 --- a/HACKING.md +++ b/HACKING.md @@ -95,5 +95,5 @@ zstyle ':completion:*:*:*:*:globbed-files' ignored-patterns {'*/',}zsh-syntax-hi IRC channel ----------- -We're on #zsh-syntax-highlighting on freenode. +We're on #zsh-syntax-highlighting on Libera.Chat. From 0e1bb14452e3fc66dcc81531212e1061e02c1a61 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 29 May 2021 23:24:20 -0500 Subject: [PATCH 1043/1080] main: precommands += proxychains --- 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 9186157..6f14f53 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -362,6 +362,7 @@ _zsh_highlight_highlighter_main_paint() 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 + 'proxychains' q:f # proxychains 4.4.0 # As of OpenSSH 8.1p1 'ssh-agent' aEPt:csDd:k From f0e6a8ef5c90ff3e1e9516df666e36e02d0f362d Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 28 Jun 2021 23:02:31 -0500 Subject: [PATCH 1044/1080] main: Honor shwordsplit when expanding parameters Closes #687, #818. --- highlighters/main/main-highlighter.zsh | 6 ++- .../main/test-data/opt-shwordsplit1.zsh | 2 +- .../parameter-expansion-shwordsplit.zsh | 38 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 highlighters/main/test-data/parameter-expansion-shwordsplit.zsh diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6f14f53..b251a3c 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -477,7 +477,11 @@ _zsh_highlight_main_highlighter__try_expand_parameter() ;; (*) # scalar, presumably - words=( ${(P)MATCH} ) + if [[ $zsyh_user_options[shwordsplit] == on ]]; then + words=( ${(P)=MATCH} ) + else + words=( ${(P)MATCH} ) + fi ;; esac reply=( "${words[@]}" ) diff --git a/highlighters/main/test-data/opt-shwordsplit1.zsh b/highlighters/main/test-data/opt-shwordsplit1.zsh index 7455785..4a7689b 100644 --- a/highlighters/main/test-data/opt-shwordsplit1.zsh +++ b/highlighters/main/test-data/opt-shwordsplit1.zsh @@ -36,5 +36,5 @@ ed() { command ed "$@" } BUFFER=$'$EDITOR' expected_region_highlight=( - '1 7 function "issue #687"' # $EDITOR + '1 7 function' # $EDITOR ) diff --git a/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh b/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh new file mode 100644 index 0000000..0bf6f4c --- /dev/null +++ b/highlighters/main/test-data/parameter-expansion-shwordsplit.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2021 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 sh_word_split +local foo='echo foo' + +BUFFER='$foo' + +expected_region_highlight=( + '1 4 builtin' # $foo +) From dffe304567c86f06bf1be0fce200077504e79783 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 3 Jul 2021 14:33:17 -0500 Subject: [PATCH 1045/1080] CI: Pull image from the GitHub container registry --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index df2b726..087a25e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: - 4.3.12 - 4.3.11 container: - image: zshusers/zsh:${{ matrix.version }} + image: ghcr.io/zsh-users/zsh:${{ matrix.version }} steps: - uses: actions/checkout@v2 - run: install_packages bsdmainutils make procps From 6e0e950154a4c6983d9e077ed052298ad9126144 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Fri, 20 Aug 2021 11:26:52 +0000 Subject: [PATCH 1046/1080] *: Fix spelling Part of PR #832. --- docs/highlighters.md | 2 +- highlighters/main/main-highlighter.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index bb72e54..17b9df4 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -25,7 +25,7 @@ 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 +editing very long command lines (for example, with the [`fned`][fned] utility function). Example: [fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b251a3c..8881dfa 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -744,7 +744,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Analyse the current word. if _zsh_highlight_main__is_redirection $arg ; then if (( in_redirection == 1 )); then - # Two consecuive redirection operators is an error. + # Two consecutive redirection operators is an error. _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token else in_redirection=2 From f6a22fa842e0e6af00df2e9c21c8de6c4614d6fc Mon Sep 17 00:00:00 2001 From: Leonardo Gama Date: Tue, 21 Sep 2021 10:48:51 -0300 Subject: [PATCH 1047/1080] docs: Change highlighters' URL indexes from numbers to labels --- docs/highlighters.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 17b9df4..1b4992b 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -3,19 +3,19 @@ zsh-syntax-highlighting / highlighters Syntax highlighting is done by pluggable highlighters: -* `main` - the base highlighter, and the only one [active by default][1]. -* `brackets` - [matches brackets][2] and parenthesis. -* `pattern` - matches [user-defined patterns][3]. -* `cursor` - matches [the cursor position][4]. -* `root` - highlights the whole command line [if the current user is root][5]. -* `line` - applied to [the whole command line][6]. +* `main` - the base highlighter, and the only one [active by default][main]. +* `brackets` - [matches brackets][brackets] and parenthesis. +* `pattern` - matches [user-defined patterns][pattern]. +* `cursor` - matches [the cursor position][cursor]. +* `root` - highlights the whole command line [if the current user is root][root]. +* `line` - applied to [the whole command line][line]. -[1]: highlighters/main.md -[2]: highlighters/brackets.md -[3]: highlighters/pattern.md -[4]: highlighters/cursor.md -[5]: highlighters/root.md -[6]: highlighters/line.md +[main]: highlighters/main.md +[brackets]: highlighters/brackets.md +[pattern]: highlighters/pattern.md +[cursor]: highlighters/cursor.md +[root]: highlighters/root.md +[line]: highlighters/line.md Highlighter-independent settings From 1a9264bc661b3d52756916bf9ec3f41687d64db2 Mon Sep 17 00:00:00 2001 From: Leonardo Gama Date: Tue, 21 Sep 2021 10:52:48 -0300 Subject: [PATCH 1048/1080] docs: Add `regexp` to the list of built-in highlighters --- docs/highlighters.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/highlighters.md b/docs/highlighters.md index 1b4992b..544dffb 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -6,6 +6,7 @@ Syntax highlighting is done by pluggable highlighters: * `main` - the base highlighter, and the only one [active by default][main]. * `brackets` - [matches brackets][brackets] and parenthesis. * `pattern` - matches [user-defined patterns][pattern]. +* `regexp` - matches [user-defined regular expressions][regexp]. * `cursor` - matches [the cursor position][cursor]. * `root` - highlights the whole command line [if the current user is root][root]. * `line` - applied to [the whole command line][line]. @@ -13,6 +14,7 @@ Syntax highlighting is done by pluggable highlighters: [main]: highlighters/main.md [brackets]: highlighters/brackets.md [pattern]: highlighters/pattern.md +[regexp]: highlighters/regexp.md [cursor]: highlighters/cursor.md [root]: highlighters/root.md [line]: highlighters/line.md From c7caf57ca805abd54f11f756fda6395dd4187f8a Mon Sep 17 00:00:00 2001 From: Daniel Kuettel Date: Sat, 25 Sep 2021 11:21:23 +0200 Subject: [PATCH 1049/1080] check KEYS_QUEUED_COUNT and PENDING to skip parsing when pasting --- zsh-syntax-highlighting.zsh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index d20dc5b..14f6e1f 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -219,7 +219,8 @@ _zsh_highlight() [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret # Do not highlight if there are pending inputs (copy/paste). - [[ $PENDING -gt 0 ]] && return $ret + (( KEYS_QUEUED_COUNT > 0 )) && return $ret + (( PENDING > 0 )) && return $ret { local cache_place From b392045e6f37610a79c891db1529ae5f6ad752d7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 24 Jan 2022 07:57:33 +0000 Subject: [PATCH 1050/1080] driver: Simplify grammar of a comment. No functional change. --- 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 14f6e1f..2b42910 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -73,8 +73,8 @@ _zsh_highlight__is_function_p() { # This function takes a single argument F and returns True iff F denotes the # name of a callable function. A function is callable if it is fully defined # or if it is marked for autoloading and autoloading it at the first call to it -# will succeed. In particular, if a function has been marked for autoloading -# but is not available in $fpath, then this function will return False therefor. +# will succeed. In particular, if F has been marked for autoloading +# but is not available in $fpath, then calling this function on F will return False. # # See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { From c10808ad5f3ace0696f900b9c543172bc1f8e27c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 31 Jan 2022 09:54:35 +0000 Subject: [PATCH 1051/1080] main: New test for issue #854 --- .../test-data/block-assignment-no-command.zsh | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 highlighters/main/test-data/block-assignment-no-command.zsh diff --git a/highlighters/main/test-data/block-assignment-no-command.zsh b/highlighters/main/test-data/block-assignment-no-command.zsh new file mode 100644 index 0000000..ec52c98 --- /dev/null +++ b/highlighters/main/test-data/block-assignment-no-command.zsh @@ -0,0 +1,38 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2022 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=42 }' + +expected_region_highlight=( + '1 1 reserved-word' # { + '3 6 assign' # a=42 + '5 6 default' # 42 + '8 8 reserved word "issue #854"' # } +) From 0ddb1a8d51205d53ea283e9fdd5135eb4039fec8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Feb 2022 18:03:11 +0000 Subject: [PATCH 1052/1080] driver: Bump the in-development is-at-least checks so they return false on zsh 5.8.1, released yesterday. Fixes #856 Fixes #857 --- release.md | 1 + zsh-syntax-highlighting.zsh | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/release.md b/release.md index 075f221..f8565e8 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,6 @@ # Release procedure (for developers): +- Ensure every `is-at-least` invocation passes a stable zsh release's version number as the first argument - For minor (A.B.0) releases: - Check whether the release uses any not-yet-released zsh features - Check open issues and outstanding pull requests diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 2b42910..bec0189 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -158,12 +158,15 @@ _zsh_highlight() # # 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. + # Therefore, on zsh master 5.8.0.3 and newer the memo= feature is available. + # However, there's also the zsh 5.8.1 release, which doesn't have the + # memo= feature. # - # 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 $ZSH_VERSION.0.0; then + # On zsh master 5.8.0.2 between the aforementioned commit and the + # first Config/version.mk bump after it (zsh-5.8-607-g75c1edde5, the + # bump to 5.8.1.1-dev following the backport to master of the bump + # to 5.8.1), this condition will false negative. + if is-at-least 5.8.1.1 $ZSH_VERSION.0.0; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -413,9 +416,8 @@ _zsh_highlight_call_widget() # as done by _zsh_highlight, can only be done from inside a widget # function — a catch-22. # -# See _zsh_highlight for the magic version number. (The use of 5.8.0.2 -# rather than 5.8.0.3 as in the _zsh_highlight is deliberate.) -if is-at-least 5.8.0.2 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget +# See _zsh_highlight for the magic version number. +if is-at-least 5.8.1.1 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From 56b44334617aa719e8e01bb5e00d3e176114a036 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 13 Feb 2022 21:31:46 +0000 Subject: [PATCH 1053/1080] CI += zsh 5.8.1 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 087a25e..60818a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: matrix: version: - master + - 5.8.1 - 5.8 - 5.7.1 - 5.7 From caeca0bf6b4dd26026df884e32ca3915f0e1b780 Mon Sep 17 00:00:00 2001 From: Nuri Jung Date: Tue, 22 Feb 2022 10:32:37 +0000 Subject: [PATCH 1054/1080] docs: regexp: Document the platform dependency Patch by Nuri Jung; extension to cover PCRE by me. See #747. Fixes #747. --- docs/highlighters/regexp.md | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 5c8a89e..8f96826 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -12,11 +12,44 @@ To use this highlighter, associate regular expressions with styles in the ```zsh typeset -A ZSH_HIGHLIGHT_REGEXP -ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) +ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold) ``` -This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not -"sudoedit" +This will highlight lines that start with a call to the `rm` command. + +The regular expressions flavour used is [PCRE][pcresyntax] when the +`RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE), +as implemented by the platform's C library, otherwise. For details on the +latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the +`regcomp(3)` and `re_format(7)` manual pages on your system. + +For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`, +but not `sudoedit`, one might use: + +* When the `RE_MATCH_PCRE` is set: + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold) + ``` + +* When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions): + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('\' fg=123,bold) + ``` + +* When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS): + + ```zsh + typeset -A ZSH_HIGHLIGHT_REGEXP + ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold) + ``` + +Note, however, that PCRE and POSIX ERE have a large common subset: +for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same +meaning in both flavours. 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)` @@ -28,3 +61,5 @@ in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [perlretut]: http://perldoc.perl.org/perlretut.html [zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions +[MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module +[pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html From 643717ccafb35a1b56a1407c852275406467b6f0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 22 Feb 2022 10:38:45 +0000 Subject: [PATCH 1055/1080] changelog: Update zsh version numbers 5.8.0.3 was correct until 5.8.1 was released (see the great-grandparent of this commit, "driver: Bump the in-development is-at-least checks so they return false on zsh 5.8.1, released yesterday"). 5.2 -> 5.3 is simply a typo fix. zle-line-pre-redraw has been available since then. --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 9230236..d0a575a 100644 --- a/changelog.md +++ b/changelog.md @@ -7,9 +7,9 @@ The changes in this section were fixed by switching to a `zle-line-pre-redraw`-b implementation. Note: The new implementation will only be used on future zsh releases, -numbered 5.8.0.3 and newer, due to interoperability issues with other plugins +numbered 5.8.1.1 and newer, due to interoperability issues with other plugins (issues #418 and #579). The underlying zsh feature has been available since -zsh 5.2. +zsh 5.3. Whilst under development, the new implementation was known as the "feature/redrawhook" topic branch. From 2cd73fcbde1b47f0952027c0674c32b9f1756a59 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 22 Feb 2022 10:42:05 +0000 Subject: [PATCH 1056/1080] *: Update sourceforge links * changelog.md: Update links here too. They have not yet appeared in any stable release. Command used: perl -pi -e 's#http://zsh.sourceforge.net#https://zsh.sourceforge.io#g' **/*(.) --- README.md | 2 +- changelog.md | 6 +++--- docs/highlighters.md | 4 ++-- docs/highlighters/brackets.md | 2 +- docs/highlighters/cursor.md | 2 +- docs/highlighters/line.md | 2 +- docs/highlighters/main.md | 4 ++-- docs/highlighters/pattern.md | 2 +- docs/highlighters/regexp.md | 4 ++-- docs/highlighters/root.md | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 482a648..4768b3d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ enough information to allow computing the highlighting correctly.) See issues [#288][i288] and [#415][i415] for details. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [i288]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/288 [i415]: https://github.com/zsh-users/zsh-syntax-highlighting/pull/415 diff --git a/changelog.md b/changelog.md index d0a575a..861fea5 100644 --- a/changelog.md +++ b/changelog.md @@ -89,8 +89,8 @@ to issue #418. (#90, part of #245 (feature/redrawhook)) -[zshcompsys-Standard-Styles]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles -[zshcompsys-Standard-Styles-format]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-format_002c-completion-style +[zshcompsys-Standard-Styles]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Standard-Styles +[zshcompsys-Standard-Styles-format]: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#index-format_002c-completion-style @@ -289,7 +289,7 @@ This is a stable release, featuring bugfixes and minor improvements. - The `isearch` and `suffix` [`$zle_highlight` settings][zshzle-Character-Highlighting]. (79e4d3d12405, 15db71abd0cc, b56ee542d619; requires zsh 5.3 for `$ISEARCHMATCH_ACTIVE` / `$SUFFIX_ACTIVE` support) -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting - Possible history expansions in double-quoted strings. (76ea9e1df316) diff --git a/docs/highlighters.md b/docs/highlighters.md index 544dffb..3a289ca 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -30,7 +30,7 @@ length (in characters) of command lines to be highlighter. This is useful when editing very long command lines (for example, with the [`fned`][fned] utility function). Example: -[fned]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#index-zed +[fned]: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zed ```zsh ZSH_HIGHLIGHT_MAXLENGTH=512 @@ -61,7 +61,7 @@ same as the syntax of "types of highlighting" of the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting Some highlighters support additional configuration parameters; see each highlighter's documentation for details and examples. diff --git a/docs/highlighters/brackets.md b/docs/highlighters/brackets.md index 8410135..0101699 100644 --- a/docs/highlighters/brackets.md +++ b/docs/highlighters/brackets.md @@ -28,4 +28,4 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/cursor.md b/docs/highlighters/cursor.md index c4f22b8..3f87d42 100644 --- a/docs/highlighters/cursor.md +++ b/docs/highlighters/cursor.md @@ -21,4 +21,4 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/line.md b/docs/highlighters/line.md index 1081fe1..f76639e 100644 --- a/docs/highlighters/line.md +++ b/docs/highlighters/line.md @@ -21,4 +21,4 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/main.md b/docs/highlighters/main.md index cc6186b..4a27653 100644 --- a/docs/highlighters/main.md +++ b/docs/highlighters/main.md @@ -116,6 +116,6 @@ of that (new) kind will be highlighted by the style `arg0_$kind`, where `$kind` is the output of `type -w` on the new kind of command word. If that style is not defined, then the style `arg0` will be used instead. -[zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines +[zshmisc-Simple-Commands-And-Pipelines]: https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/pattern.md b/docs/highlighters/pattern.md index e67d79f..ecaa6a7 100644 --- a/docs/highlighters/pattern.md +++ b/docs/highlighters/pattern.md @@ -21,4 +21,4 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index 8f96826..b1bed91 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -58,8 +58,8 @@ manual page][zshzle-Character-Highlighting]. See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting [perlretut]: http://perldoc.perl.org/perlretut.html -[zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions +[zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions [MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module [pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html diff --git a/docs/highlighters/root.md b/docs/highlighters/root.md index d120d20..8197e4b 100644 --- a/docs/highlighters/root.md +++ b/docs/highlighters/root.md @@ -22,4 +22,4 @@ 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)` manual page][zshzle-Character-Highlighting]. -[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting +[zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting From 5459ebcc4e788e1db514d95a0bf81adb6f19ea74 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Feb 2022 18:19:58 +0000 Subject: [PATCH 1057/1080] main: precommand_options += grc --- 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 8881dfa..59e54ff 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -374,6 +374,9 @@ _zsh_highlight_highlighter_main_paint() 'chronic' :ev 'ifne' :n + # grc - a "generic colouriser" (that's their spelling, not mine) + 'grc' :se + ) # Commands that would need to skip one positional argument: # flock From c5ce0014677a0f69a10b676b6038ad127f40c6b1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 23 Feb 2022 18:48:13 +0000 Subject: [PATCH 1058/1080] main: Deconfuse $EDITOR Work around . --- 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 59e54ff..ecdd0b8 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -659,7 +659,7 @@ _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 )) From caa749d030d22168445c4cb97befd406d2828db0 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 14 May 2022 18:47:37 +0000 Subject: [PATCH 1059/1080] main: Housekeep $precommand_options. Add -v to tabbed(1). --- highlighters/main/main-highlighter.zsh | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index ecdd0b8..0bd6dde 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -349,6 +349,7 @@ _zsh_highlight_highlighter_main_paint() 'noglob' '' # 'time' and 'nocorrect' shouldn't be added here; they're reserved words, not precommands. + # miscellaneous commands '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 @@ -363,24 +364,16 @@ _zsh_highlight_highlighter_main_paint() 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 'proxychains' q:f # proxychains 4.4.0 - - # 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 - - # moreutils 0.62-1 - 'chronic' :ev - 'ifne' :n - - # grc - a "generic colouriser" (that's their spelling, not mine) - 'grc' :se - + 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 + 'tabbed' gnprtTuU:cdfhs:v # suckless-tools v44 + 'chronic' :ev # moreutils 0.62-1 + 'ifne' :n # moreutils 0.62-1 + 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) ) # Commands that would need to skip one positional argument: # flock # ssh + # _wanted (skip two) if [[ $zsyh_user_options[ignorebraces] == on || ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]; then local right_brace_is_recognised_everywhere=false From b828f45da63fe57295ab6fafac240af6bd320f5c Mon Sep 17 00:00:00 2001 From: inventor500 Date: Fri, 23 Sep 2022 08:17:50 -0500 Subject: [PATCH 1060/1080] main precommands += torsocks --- 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 0bd6dde..55fcdf3 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -364,6 +364,8 @@ _zsh_highlight_highlighter_main_paint() 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 'proxychains' q:f # proxychains 4.4.0 + 'torsocks' idq:upaP # Torsocks 2.3.0 + 'torify' idq:upaP # Torsocks 2.3.0 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 'tabbed' gnprtTuU:cdfhs:v # suckless-tools v44 'chronic' :ev # moreutils 0.62-1 From 122dc464392302114556b53ec01a1390c54f739f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Fri, 23 Sep 2022 19:33:44 -0500 Subject: [PATCH 1061/1080] main: Add cpulimit to precommands Closes #897 --- 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 55fcdf3..7ec6249 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -371,6 +371,7 @@ _zsh_highlight_highlighter_main_paint() 'chronic' :ev # moreutils 0.62-1 'ifne' :n # moreutils 0.62-1 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) + 'cpulimit' elp:ivz # cpulimit 0.2 ) # Commands that would need to skip one positional argument: # flock From b2c910a85ed84cb7e5108e7cb3406a2e825a858f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 15 Jun 2022 18:05:01 -0500 Subject: [PATCH 1062/1080] docs: Add Fig instructions Closes #877 --- INSTALL.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 48b724f..024dbd9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -75,6 +75,12 @@ This list is incomplete as there are too many Add `antigen bundle zsh-users/zsh-syntax-highlighting` as the last bundle in your `.zshrc`. +#### [Fig](https://fig.io) + +Click the `Install Plugin` button on the [Fig plugin page][fig-plugin]. + +[fig-plugin]: https://fig.io/plugins/other/zsh-syntax-highlighting + #### [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) 1. Clone this repository in oh-my-zsh's plugins directory: From 75ba3d87e346de4fda7ce35c546ed8fa74d73a90 Mon Sep 17 00:00:00 2001 From: DiegoBoy Date: Tue, 31 Jan 2023 09:06:37 -0800 Subject: [PATCH 1063/1080] Fix proxychains args Args for proxychains should be f:q => -f file : -q quiet. From comments in the same function: # $precommand_options maps precommand name to values of $flags_with_argument, # $flags_sans_argument, and flags_solo for that precommand, joined by a # colon. --- 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 7ec6249..f691051 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -363,7 +363,7 @@ _zsh_highlight_highlighter_main_paint() 'env' u:i 'ionice' cn:t:pPu # util-linux 2.33.1-0.1 'strace' IbeaosXPpEuOS:ACdfhikqrtTvVxyDc # strace 4.26-0.2 - 'proxychains' q:f # proxychains 4.4.0 + 'proxychains' f:q # proxychains 4.4.0 'torsocks' idq:upaP # Torsocks 2.3.0 'torify' idq:upaP # Torsocks 2.3.0 'ssh-agent' aEPt:csDd:k # As of OpenSSH 8.1p1 From 754cefe0181a7acd42fdcb357a67d0217291ac47 Mon Sep 17 00:00:00 2001 From: Johan van Eck <95653001+johanvaneck@users.noreply.github.com> Date: Fri, 3 Feb 2023 12:47:47 +0200 Subject: [PATCH 1064/1080] docs: Markup changes only (in the brew installation instructions) --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 024dbd9..89bf96c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,7 +8,7 @@ How to install * 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: [`shells/zsh-syntax-highlighting`][freebsd-port]) * Gentoo: [app-shells/zsh-syntax-highlighting][gentoo-repository] -* Mac OS X / Homebrew: [brew install zsh-syntax-highlighting][brew-package] +* Mac OS X / Homebrew: `brew install zsh-syntax-highlighting` ([formula][brew-package]) * NetBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][netbsd-port]) * OpenBSD: `pkg_add zsh-syntax-highlighting` (port name: [`shells/zsh-syntax-highlighting`][openbsd-port]) * openSUSE / SLE: `zsh-syntax-highlighting` package in [OBS repository][obs-repository] From 1386f1213eb0b0589d73cd3cf7c56e6a972a9bfd Mon Sep 17 00:00:00 2001 From: Henry Bley-Vroman Date: Sun, 21 May 2023 14:05:53 -0400 Subject: [PATCH 1065/1080] docs: ZSH_HIGHLIGHT_HIGHLIGHTERS is (main) by default --- docs/highlighters.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/highlighters.md b/docs/highlighters.md index 3a289ca..fb64c3a 100644 --- a/docs/highlighters.md +++ b/docs/highlighters.md @@ -40,16 +40,14 @@ ZSH_HIGHLIGHT_MAXLENGTH=512 How to activate highlighters ---------------------------- -To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array in -`~/.zshrc`, for example: +To activate an highlighter, add it to the `ZSH_HIGHLIGHT_HIGHLIGHTERS` array. +By default `ZSH_HIGHLIGHT_HIGHLIGHTERS` is `(main)`. For example to activate +`brackets`, `pattern`, and `cursor` highlighters, in `~/.zshrc` do: ```zsh -ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) +ZSH_HIGHLIGHT_HIGHLIGHTERS+=(brackets pattern cursor) ``` -By default, `$ZSH_HIGHLIGHT_HIGHLIGHTERS` is unset and only the `main` -highlighter is active. - How to tweak highlighters ------------------------- From 143b25eb98aa3227af63bd7f04413e1b3e7888ec Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Tue, 5 Sep 2023 23:23:07 -0500 Subject: [PATCH 1066/1080] docs: Fix Homebrew link Closes #937. --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 89bf96c..cce1411 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -18,7 +18,7 @@ How to install [arch-package]: https://www.archlinux.org/packages/zsh-syntax-highlighting [AUR-package]: https://aur.archlinux.org/packages/zsh-syntax-highlighting-git -[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-syntax-highlighting.rb +[brew-package]: https://github.com/Homebrew/homebrew-core/blob/master/Formula/z/zsh-syntax-highlighting.rb [debian-package]: https://packages.debian.org/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 From 65071902d306d543b2eecc6e954c6adaec9238a2 Mon Sep 17 00:00:00 2001 From: "Mario P. Cardenas" <15961362+Mario-paul@users.noreply.github.com> Date: Wed, 18 Aug 2021 01:26:20 -0400 Subject: [PATCH 1067/1080] docs: add instructions to source .zshrc file after package install --- INSTALL.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index cce1411..1c20468 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -3,6 +3,8 @@ How to install ### Using packages +First, install the package: + * 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]) @@ -32,6 +34,36 @@ How to install See also [repology's cross-distro index](https://repology.org/metapackage/zsh-syntax-highlighting/versions) +Second, enable zsh-syntax-highlighting by sourcing the script. Running this command on the terminal will add the source line to the end of your .zshrc: + +* On most Linux distributions (except perhaps NixOS): + + ```zsh + echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +* NetBSD and OpenBSD: + + ```zsh + echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +* Mac OS X / Homebrew: + + ```zsh + echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc + ``` + +Then restart zsh (such as by opening a new instance of your terminal emulator). + + Alternatively, add the `source` command manually **at the end** of your `.zshrc`: + +* On most Linux distributions (except perhaps NixOS): +`source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` +* NetBSD and OpenBSD: +`source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh` + +Then restart zsh. ### In your ~/.zshrc From dd0cf649d13e9bfdb86d6bf2c3df0131a0ab5df3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 21:33:29 -0500 Subject: [PATCH 1068/1080] *: Use https in URLs --- INSTALL.md | 2 +- changelog.md | 2 +- docs/highlighters/regexp.md | 2 +- tests/README.md | 2 +- zsh-syntax-highlighting.zsh | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 1c20468..af92ac1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -24,7 +24,7 @@ First, install the package: [debian-package]: https://packages.debian.org/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 -[freebsd-port]: http://www.freshports.org/textproc/zsh-syntax-highlighting/ +[freebsd-port]: https://www.freshports.org/textproc/zsh-syntax-highlighting/ [gentoo-repository]: https://packages.gentoo.org/packages/app-shells/zsh-syntax-highlighting [netbsd-port]: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/shells/zsh-syntax-highlighting/ [obs-repository]: https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-syntax-highlighting&package=zsh-syntax-highlighting diff --git a/changelog.md b/changelog.md index 861fea5..e56f259 100644 --- a/changelog.md +++ b/changelog.md @@ -735,7 +735,7 @@ in this area. ## Developer-visible changes: -- Test harness converted to [TAP](http://testanything.org/tap-specification.html) format +- Test harness converted to [TAP](https://testanything.org/tap-specification.html) format (d99aa58aaaef, et seq) - Run each test in a separate subprocess, isolating them from each other diff --git a/docs/highlighters/regexp.md b/docs/highlighters/regexp.md index b1bed91..8c711a3 100644 --- a/docs/highlighters/regexp.md +++ b/docs/highlighters/regexp.md @@ -59,7 +59,7 @@ See also: [regular expressions tutorial][perlretut], zsh regexp operator `=~` in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions] [zshzle-Character-Highlighting]: https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting -[perlretut]: http://perldoc.perl.org/perlretut.html +[perlretut]: https://perldoc.perl.org/perlretut [zshmisc-Conditional-Expressions]: https://zsh.sourceforge.io/Doc/Release/Conditional-Expressions.html#Conditional-Expressions [MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module [pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html diff --git a/tests/README.md b/tests/README.md index cb3d943..eefeb54 100644 --- a/tests/README.md +++ b/tests/README.md @@ -104,7 +104,7 @@ By default, the results of all tests will be printed; to show only "interesting" results (tests that failed but were expected to succeed, or vice-versa), run `make quiet-test` (or `make test QUIET=y`). -[TAP]: http://testanything.org/ +[TAP]: https://testanything.org/ Performance test diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index bec0189..7827256 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -76,7 +76,7 @@ _zsh_highlight__is_function_p() { # will succeed. In particular, if F has been marked for autoloading # but is not available in $fpath, then calling this function on F will return False. # -# See users/21671 http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 +# See users/21671 https://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=21671 _zsh_highlight__function_callable_p() { if _zsh_highlight__is_function_p "$1" && ! _zsh_highlight__function_is_autoload_stub_p "$1" @@ -100,7 +100,7 @@ _zsh_highlight__function_callable_p() { # ------------------------------------------------------------------------------------------------- # Use workaround for bug in ZSH? -# zsh-users/zsh@48cadf4 http://www.zsh.org/mla/workers//2017/msg00034.html +# zsh-users/zsh@48cadf4 https://www.zsh.org/mla/workers/2017/msg00034.html autoload -Uz is-at-least if is-at-least 5.4; then typeset -g zsh_highlight__pat_static_bug=false From 1e82d8c83efa8b9fd0c7d1b9baffeb47d6cff960 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 22:11:43 -0500 Subject: [PATCH 1069/1080] changelog: Update through HEAD --- changelog.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/changelog.md b/changelog.md index e56f259..ee124d3 100644 --- a/changelog.md +++ b/changelog.md @@ -56,6 +56,28 @@ Whilst under development, the new implementation was known as the - Add issue #712 to the previous release's changelog (hereinafter). +- Fix highlighting when using an alias twice inside another alias + [#769, #775] + +- Remove lint warning for `env` followed by a pipe + [#797] + +- Recognize `proxychains` as a precommand + [#814, #914] + +- Honor shwordsplit when expanding parameters + [#687, #818] + +- Skip highlighting when keys are still pending in more cases + [#835] + +- Recognize `grc` as a precommand + +- Recognize `torsocks` and `torift` as precommands + [#898] + +- Recognize `cpulimit` as a precommand + [#897] # Changes in 0.8.0-alpha1-pre-redrawhook @@ -168,6 +190,8 @@ to issue #418. - Recognize `env` as a precommand (e.g., `env FOO=bar ls`) +- Recognize `ionice` as a precommand + - Recognize `strace` as a precommand - Fix an error message on stderr before every prompt when the `WARN_NESTED_VAR` zsh option is set: From f8cd0b55b3d134cbc71360c94737528bca1a526f Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Wed, 25 Oct 2023 22:33:02 -0500 Subject: [PATCH 1070/1080] docs: Replace zplug instructions with zinit Fixes #883. --- INSTALL.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index af92ac1..2e1286d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -140,15 +140,15 @@ Zsh-syntax-highlighting is included with Prezto. See the Add `zgen load zsh-users/zsh-syntax-highlighting` to the end of your `.zshrc`. +#### [zinit](https://github.com/zdharma-continuum/zinit) + +Add `zinit light zsh-users/zsh-syntax-highlighting` to the end of your +`.zshrc`. + #### [zplug](https://github.com/zplug/zplug) Add `zplug "zsh-users/zsh-syntax-highlighting", defer:2` to your `.zshrc`. -#### [zplugin](https://github.com/psprint/zplugin) - -Add `zplugin load zsh-users/zsh-syntax-highlighting` to the end of your -`.zshrc`. - ### System-wide installation From 0b5b3dcc0c603c9e1b3ad9d59b3d923a4b2d2437 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Tue, 11 Aug 2020 22:05:17 +0200 Subject: [PATCH 1071/1080] tests: parameter-to-global-alias: Use alias name less likely to clash --- highlighters/main/test-data/parameter-to-global-alias.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/highlighters/main/test-data/parameter-to-global-alias.zsh b/highlighters/main/test-data/parameter-to-global-alias.zsh index cd2283b..63f95da 100644 --- a/highlighters/main/test-data/parameter-to-global-alias.zsh +++ b/highlighters/main/test-data/parameter-to-global-alias.zsh @@ -28,12 +28,12 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -if type x >/dev/null; then - skip_test="Test is written on the assumption that 'x' is not a valid command name, but that assumption does not hold" +if type global_alias >/dev/null; then + skip_test="Test is written on the assumption that 'global_alias' is not a valid command name, but that assumption does not hold" return 0 fi -alias -g x=y -local s=x +alias -g global_alias=y +local s=global_alias BUFFER=$'$s' From e82e2d042d55391e5c136c92ead4714db2d60b1a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 12:50:08 -0500 Subject: [PATCH 1072/1080] main: precommand_options += ktrace --- changelog.md | 3 +++ highlighters/main/main-highlighter.zsh | 1 + 2 files changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index ee124d3..851a918 100644 --- a/changelog.md +++ b/changelog.md @@ -79,6 +79,9 @@ Whilst under development, the new implementation was known as the - Recognize `cpulimit` as a precommand [#897] +- Recognize `ktrace` as a precommand + + # Changes in 0.8.0-alpha1-pre-redrawhook ## Notice about an improbable-but-not-impossible forward incompatibility diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f691051..54938b7 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -372,6 +372,7 @@ _zsh_highlight_highlighter_main_paint() 'ifne' :n # moreutils 0.62-1 'grc' :se # grc - a "generic colouriser" (that's their spelling, not mine) 'cpulimit' elp:ivz # cpulimit 0.2 + 'ktrace' fgpt:aBCcdiT ) # Commands that would need to skip one positional argument: # flock From d59ce0fbd014bd69b1eed21c029c0d51bf8d6a09 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 12:53:19 -0500 Subject: [PATCH 1073/1080] driver: Be resilient to KSH_ARRAYS being set in the calling scope --- 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 7827256..9f8fe48 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -123,7 +123,7 @@ _zsh_highlight() typeset -r ret # $region_highlight should be predefined, either by zle or by the test suite's mock (non-special) array. - (( ${+region_highlight} )) || { + (( ${+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 From 71bd576af836517bda6dd574ef81176339144568 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 13:13:49 -0500 Subject: [PATCH 1074/1080] CI += zsh 5.9 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60818a6..76a7484 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: matrix: version: - master + - 5.9 - 5.8.1 - 5.8 - 5.7.1 From bb27265aeeb0a22fb77f1275118a5edba260ec47 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 29 Oct 2023 13:25:08 -0500 Subject: [PATCH 1075/1080] CI: Update action versions --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 76a7484..cd50b8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,7 +57,7 @@ jobs: container: image: ghcr.io/zsh-users/zsh:${{ matrix.version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: install_packages bsdmainutils make procps - run: make test @@ -68,9 +68,8 @@ jobs: steps: - name: Notify IRC - uses: Gottox/irc-message-action@v1 + uses: Gottox/irc-message-action@v2 with: - server: irc.libera.chat channel: '#zsh-syntax-highlighting' nickname: zsyh-gh-bot message: '${{ github.ref }} failed tests: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' From 9bb3db7fd2715e07804b23a78e0eed797e137610 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:02:40 -0600 Subject: [PATCH 1076/1080] driver: Use stable zsh release in is-at-least calls --- zsh-syntax-highlighting.zsh | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/zsh-syntax-highlighting.zsh b/zsh-syntax-highlighting.zsh index 9f8fe48..4295c93 100644 --- a/zsh-syntax-highlighting.zsh +++ b/zsh-syntax-highlighting.zsh @@ -155,18 +155,7 @@ _zsh_highlight() # 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 zsh master 5.8.0.3 and newer the memo= feature is available. - # However, there's also the zsh 5.8.1 release, which doesn't have the - # memo= feature. - # - # On zsh master 5.8.0.2 between the aforementioned commit and the - # first Config/version.mk bump after it (zsh-5.8-607-g75c1edde5, the - # bump to 5.8.1.1-dev following the backport to master of the bump - # to 5.8.1), this condition will false negative. - if is-at-least 5.8.1.1 $ZSH_VERSION.0.0; then + if is-at-least 5.9; then integer -gr zsh_highlight__memo_feature=1 else integer -gr zsh_highlight__memo_feature=0 @@ -415,9 +404,7 @@ _zsh_highlight_call_widget() # We check this with a plain version number check, since a functional check, # as done by _zsh_highlight, can only be done from inside a widget # function — a catch-22. -# -# See _zsh_highlight for the magic version number. -if is-at-least 5.8.1.1 $ZSH_VERSION.0.0 && _zsh_highlight__function_callable_p add-zle-hook-widget +if is-at-least 5.9 && _zsh_highlight__function_callable_p add-zle-hook-widget then autoload -U add-zle-hook-widget _zsh_highlight__zle-line-finish() { From db085e4661f6aafd24e5acb5b2e17e4dd5dddf3e Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:05:43 -0600 Subject: [PATCH 1077/1080] Tag version 0.8.0. --- .version | 2 +- changelog.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.version b/.version index 9fb1210..a3df0a6 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0-alpha2-dev +0.8.0 diff --git a/changelog.md b/changelog.md index 851a918..bc6614d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,6 @@ -# Changes in HEAD +# Changes in 0.8.0 + +This is a stable bugfix and feature release. Major new features and changes include: ## Changes fixed as part of the switch to zle-line-pre-redraw From dcc99a86497491dfe41fb8b0d5f506033546a8c0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 18 Dec 2023 16:07:39 -0600 Subject: [PATCH 1078/1080] Post-release version number bump. --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index a3df0a6..d182dc9 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.8.0 +0.8.1-dev From e0165eaa730dd0fa321a6a6de74f092fe87630b0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 6 Jan 2024 12:33:41 -0600 Subject: [PATCH 1079/1080] main: Refactor __is_redirection Fixes #942. --- changelog.md | 7 ++ highlighters/main/main-highlighter.zsh | 7 +- .../main/test-data/redirection-all.zsh | 95 +++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 highlighters/main/test-data/redirection-all.zsh diff --git a/changelog.md b/changelog.md index bc6614d..8ee5088 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +# Changes in HEAD + + +- Highlight `&>` `>&|` `>&!` `&>|` and `&>!` as redirection. + [#942] + + # Changes in 0.8.0 This is a stable bugfix and feature release. Major new features and changes include: diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 54938b7..3ec96d9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -254,10 +254,9 @@ _zsh_highlight_main__is_runnable() { _zsh_highlight_main__is_redirection() { # A redirection operator token: # - starts with an optional single-digit number; - # - then, has a '<' or '>' character; - # - is not a process substitution [<(...) or >(...)]. - # - is not a numeric glob <-> - [[ $1 == (<0-9>|)(\<|\>)* ]] && [[ $1 != (\<|\>)$'\x28'* ]] && [[ $1 != *'<'*'-'*'>'* ]] + # - is one of the tokens listed in zshmisc(1) + # - however (z) normalizes ! to | + [[ ${1#[0-9]} == (\<|\<\>|(\>|\>\>)(|\|)|\<\<(|-)|\<\<\<|\<\&|\&\<|(\>|\>\>)\&(|\|)|\&(\>|\>\>)(|\||\!)) ]] } # Resolve alias. diff --git a/highlighters/main/test-data/redirection-all.zsh b/highlighters/main/test-data/redirection-all.zsh new file mode 100644 index 0000000..e8ffb5d --- /dev/null +++ b/highlighters/main/test-data/redirection-all.zsh @@ -0,0 +1,95 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2024 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 9<>foo >foo 9>foo >|foo >\!foo >>foo >>|foo >>\!foo <<&9 <&- >&- <&p >&p >&foo &>foo >&|foo >&\!foo &>|foo &>\!foo >>&foo &>>foo >>&|foo >>&\!foo &>>|foo &>>\!foo' + +expected_region_highlight=( + '1 1 builtin' # : + '3 3 redirection' # < + '4 6 default' # foo + '8 9 redirection' # 9< + '10 12 default' # foo + '14 15 redirection' # <> + '16 18 default' # foo + '20 22 redirection' # 9<> + '23 25 default' # foo + '27 27 redirection' # > + '28 30 default' # foo + '32 33 redirection' # 9> + '34 36 default' # foo + '38 39 redirection' # >| + '40 42 default' # foo + '44 45 redirection' # >\! + '46 48 default' # foo + '50 51 redirection' # >> + '52 54 default' # foo + '56 58 redirection' # >>| + '59 61 default' # foo + '63 65 redirection' # >>\! + '66 68 default' # foo + '70 72 redirection' # <<< + '73 75 default' # foo + '77 78 redirection' # <& + '79 79 numeric-fd' # 9 + '81 82 redirection' # >& + '83 83 numeric-fd' # 9 + '85 86 redirection' # <& + '87 87 redirection' # - + '89 90 redirection' # >& + '91 91 redirection' # - + '93 94 redirection' # <& + '95 95 redirection' # p + '97 98 redirection' # >& + '99 99 redirection' # p + '101 102 redirection' # >& + '103 105 default' # foo + '107 108 redirection' # &> + '109 111 default' # foo + '113 115 redirection' # >&| + '116 118 default' # foo + '120 122 redirection' # >&\! + '123 125 default' # foo + '127 129 redirection' # &>| + '130 132 default' # foo + '134 136 redirection' # &>\! + '137 139 default' # foo + '141 143 redirection' # >>& + '144 146 default' # foo + '148 150 redirection' # &>> + '151 153 default' # foo + '155 158 redirection' # >>&| + '159 161 default' # foo + '163 166 redirection' # >>&\! + '167 169 default' # foo + '171 174 redirection' # &>>| + '175 177 default' # foo + '179 182 redirection' # &>>\! + '183 185 default' # foo +) From 5eb677bb0fa9a3e60f0eff031dc13926e093df92 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 21 Nov 2024 14:56:08 +0000 Subject: [PATCH 1080/1080] 'main' tests: Don't assume ps(1) is available. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's actually unavailable in the minimal chroots Debian builds our package on. That's allowed by POSIX, which specifies ps(1) to be optional, whereas id(1) — - is not optional in POSIX - should exist on every system anyone might run the testsuite on - has the same length name, so test expectations don't have to be updated - doesn't take a filename argument (ditto) That does make the pipeline as a whole somewhat nonsensical semantically, but it remains just as valid syntactically. --- highlighters/main/test-data/multiple-redirections.zsh | 2 +- highlighters/main/test-data/simple-redirection.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/multiple-redirections.zsh b/highlighters/main/test-data/multiple-redirections.zsh index 778e712..1545c1b 100644 --- a/highlighters/main/test-data/multiple-redirections.zsh +++ b/highlighters/main/test-data/multiple-redirections.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ps aux | grep java | sort | uniq | tail | head' +BUFFER='id bob | grep java | sort | uniq | tail | head' expected_region_highlight=( "1 2 command" # ps diff --git a/highlighters/main/test-data/simple-redirection.zsh b/highlighters/main/test-data/simple-redirection.zsh index e8c25e5..fb06f19 100644 --- a/highlighters/main/test-data/simple-redirection.zsh +++ b/highlighters/main/test-data/simple-redirection.zsh @@ -27,7 +27,7 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -BUFFER='ps aux | grep java' +BUFFER='id bob | grep java' expected_region_highlight=( "1 2 command" # ps