From aed99f6a3e9f29859682d92003731c75e43362e8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 30 Sep 2015 18:56:35 +0000 Subject: [PATCH 001/248] 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 002/248] 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 003/248] 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 004/248] 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 005/248] 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 006/248] 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 007/248] 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 008/248] 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 009/248] 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 010/248] 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 011/248] 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 012/248] 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 013/248] 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 014/248] 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 015/248] 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 016/248] 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 017/248] 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 018/248] 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 8d4c6355e6d252f1d67beca4df946f8335fac51c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 13 Oct 2018 21:55:45 -0500 Subject: [PATCH 019/248] 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 e209cbe61aacea60ccff7b806d2a8fab05750e18 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 10 Nov 2019 11:20:21 +0000 Subject: [PATCH 020/248] 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 021/248] 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 022/248] 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 023/248] 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 024/248] 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 6629a1f432b8b8bfec92c98ce3fa03fcf5ac79ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 12 Jan 2020 19:37:30 +0000 Subject: [PATCH 025/248] '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 026/248] '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 027/248] '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 4eb8a19133c4f346af35436cf38a27d43fb458e7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 20 Oct 2015 14:35:21 +0000 Subject: [PATCH 028/248] 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 029/248] 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 030/248] 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 031/248] 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 032/248] 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 033/248] 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 034/248] 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 035/248] '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 036/248] '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 037/248] 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 038/248] 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 039/248] '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 040/248] 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 041/248] 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 042/248] 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 043/248] 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 044/248] 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 045/248] 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 046/248] '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 047/248] '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 048/248] 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 049/248] '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 050/248] 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 051/248] 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 052/248] '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 053/248] 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 054/248] 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 055/248] '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 056/248] 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 057/248] 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 058/248] 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 059/248] 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 060/248] '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 061/248] '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 062/248] '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 063/248] '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 064/248] 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 065/248] 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 066/248] 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 067/248] 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 068/248] '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 069/248] =?UTF-8?q?'main':=20Don't=20use=20=C2=ABfoo=20&&?= =?UTF-8?q?=20bar=20||=20baz=C2=BB=20where=20a=20trenary=20is=20more=20app?= =?UTF-8?q?ropriate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents the baz pattern match from being attempted whenever the bar pattern match was tried and failed. --- highlighters/main/main-highlighter.zsh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 0a899d8..0b40b08 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -698,14 +698,24 @@ _zsh_highlight_main_highlighter_highlight_list() if (( ! in_redirection )); then if [[ $this_word == *':sudo_opt:'* ]]; then if [[ -n $flags_with_argument ]] && - { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]] || - [[ $arg == '-'[$flags_with_argument] ]] }; then + { + # Trenary + if [[ -n $flags_sans_argument ]] + then [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument] ]] + else [[ $arg == '-'[$flags_with_argument] ]] + fi + } then # Flag that requires an argument this_word=${this_word//:start:/} next_word=':sudo_arg:' elif [[ -n $flags_with_argument ]] && - { [[ -n $flags_sans_argument ]] && [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]] || - [[ $arg == '-'[$flags_with_argument]* ]] }; then + { + # Trenary + if [[ -n $flags_sans_argument ]] + then [[ $arg == '-'[$flags_sans_argument]#[$flags_with_argument]* ]] + else [[ $arg == '-'[$flags_with_argument]* ]] + fi + } then # Argument attached in the same word this_word=${this_word//:start:/} next_word+=':start:' From c73153c6e848eae00918ba27da51fb2d862278a2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 16 Mar 2020 19:20:31 +0000 Subject: [PATCH 070/248] '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 071/248] '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 072/248] 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 073/248] 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 074/248] '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 075/248] '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 076/248] 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 077/248] 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 078/248] 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 079/248] 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 080/248] 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 081/248] '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 082/248] '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 083/248] '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 084/248] 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 085/248] '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 086/248] '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 087/248] '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 088/248] 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 089/248] 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 090/248] 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 091/248] '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 092/248] '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 093/248] 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 094/248] 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 095/248] 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 096/248] 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 097/248] 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 098/248] 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 099/248] 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 100/248] 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 101/248] 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 102/248] 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 103/248] 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 104/248] '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 105/248] 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 106/248] 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 107/248] 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 108/248] '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 109/248] 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 110/248] 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 111/248] '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 112/248] '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 113/248] '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 114/248] '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 115/248] '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 116/248] '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 117/248] '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 118/248] '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 119/248] '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 120/248] '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 121/248] '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 122/248] 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 123/248] 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 124/248] 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 125/248] 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 126/248] 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 127/248] 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 128/248] '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 129/248] =?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 130/248] 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 131/248] 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 132/248] 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 133/248] '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 134/248] 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 135/248] 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 136/248] '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 137/248] '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 138/248] 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 139/248] 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 140/248] '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 141/248] '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 142/248] '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 143/248] 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 144/248] 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 145/248] 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 146/248] 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 147/248] 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 148/248] '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 149/248] '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 150/248] '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 151/248] 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 152/248] '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 153/248] '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 154/248] '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 155/248] 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 156/248] '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 157/248] '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 158/248] '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 159/248] 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 160/248] 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 161/248] 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 162/248] 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 163/248] '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 164/248] '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 165/248] 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 166/248] '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 167/248] 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 168/248] 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 169/248] 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 170/248] 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 171/248] '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 172/248] 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 173/248] '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 174/248] 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 175/248] 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 176/248] 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 177/248] 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 178/248] 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 179/248] 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 180/248] 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 181/248] 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 182/248] 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 183/248] 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 184/248] 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 185/248] 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 186/248] 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 187/248] 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 188/248] 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 189/248] 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 190/248] 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 191/248] 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 192/248] 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 193/248] 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 194/248] 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 195/248] 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 196/248] 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 197/248] 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 198/248] 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 199/248] 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 200/248] 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 201/248] 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 202/248] 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 203/248] 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 204/248] 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 205/248] 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 206/248] '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 207/248] 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 208/248] 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 209/248] 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 210/248] 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 211/248] 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 212/248] 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 213/248] 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 214/248] *: 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 215/248] 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 216/248] 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 217/248] 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 218/248] 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 219/248] 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 220/248] 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 221/248] 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 222/248] 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 223/248] 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 224/248] *: 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 225/248] 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 226/248] 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 227/248] 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 228/248] 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 229/248] 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 230/248] 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 231/248] 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 232/248] 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 233/248] 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 234/248] 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 235/248] 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 236/248] *: 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 237/248] 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 238/248] 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 239/248] 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 240/248] 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 241/248] 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 242/248] 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 243/248] 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 244/248] 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 245/248] 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 246/248] 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 247/248] 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 248/248] '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