Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
aports
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alpine
aports
Commits
e10a5bef
Commit
e10a5bef
authored
2 years ago
by
Jakub Jirutka
Browse files
Options
Downloads
Patches
Plain Diff
community/zsh-history-substring-search: fix compat with zsh-syntax-highlighting
parent
80b1a0a1
No related branches found
No related tags found
2 merge requests
!54607
main/sofia-sip: backport support for forking SIP calls
,
!41733
community/linux-edge: fix build on x86_64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
community/zsh-history-substring-search/APKBUILD
+2
-0
2 additions, 0 deletions
community/zsh-history-substring-search/APKBUILD
community/zsh-history-substring-search/fix-zsh-syntax-highlighting-compat.patch
+259
-0
259 additions, 0 deletions
...substring-search/fix-zsh-syntax-highlighting-compat.patch
with
261 additions
and
0 deletions
community/zsh-history-substring-search/APKBUILD
+
2
−
0
View file @
e10a5bef
...
...
@@ -10,6 +10,7 @@ license="BSD-3-Clause"
depends
=
"zsh"
source
=
"https://github.com/zsh-users/zsh-history-substring-search/archive/v
$pkgver
/
$pkgname
-
$pkgver
.tar.gz
dont-overwrite-config-with-default-values.patch
fix-zsh-syntax-highlighting-compat.patch
"
options
=
"!check"
# upstream does not provide tests
...
...
@@ -20,4 +21,5 @@ package() {
sha512sums
=
"
9547cdd74f6bd5b102ca29b7b455cd4ce7450fe86864b5a149365de4c37d3da887edb403b195e80c142fe61861a3e4c063a5d8ba08ec0532b27a1207c80a023d zsh-history-substring-search-1.0.2.tar.gz
7aeafcb05532442fa2e5cce44913fccc73575b5398ad59100c9517fb4bf9e84aafe13847cafdaa28e954655fa064e6f3ba03f9a5f46cb1e8471f6bd41dfd6c1b dont-overwrite-config-with-default-values.patch
cc8f9e95f05cf39d32a23fb6a073694a16fac6f9352a23d4c5efc13c5fe4698faf4f3282fcecd0b12e1f0db27dc678e26d2121bcdcff6e379d494dfd2a4555b8 fix-zsh-syntax-highlighting-compat.patch
"
This diff is collapsed.
Click to expand it.
community/zsh-history-substring-search/fix-zsh-syntax-highlighting-compat.patch
0 → 100644
+
259
−
0
View file @
e10a5bef
Patch-Source: https://github.com/zsh-users/zsh-history-substring-search/pull/135
--
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sun, 7 Aug 2022 17:02:26 +0200
Subject: [PATCH] Fix compatibility with latest zsh-syntax-highlighting
(zle-line-pre-redraw) and use memo= feature
diff --git a/zsh-history-substring-search.zsh b/zsh-history-substring-search.zsh
index 1261e2e..b0a0a8d 100644
--- a/zsh-history-substring-search.zsh
+++ b/zsh-history-substring-search.zsh
@@ -65,6 +65,7 @@
typeset -g -i _history_substring_search_raw_match_index
typeset -g -a _history_substring_search_matches
typeset -g -i _history_substring_search_match_index
typeset -g -A _history_substring_search_unique_filter
+typeset -g -i _history_substring_search_zsh_5_9
#-----------------------------------------------------------------------------
# the main ZLE widgets
@@ -98,6 +99,11 @@
zle -N history-substring-search-down
#-----------------------------------------------------------------------------
zmodload -F zsh/parameter
+autoload -Uz is-at-least
+
+if is-at-least 5.9 $ZSH_VERSION; then
+ _history_substring_search_zsh_5_9=1
+fi
#
# We have to "override" some keys and widgets if the
@@ -118,80 +124,125 @@
if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
}
#
- # The following snippet was taken from the zsh-syntax-highlighting project:
- #
- # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
- #
- # Copyright (c) 2010-2011 zsh-syntax-highlighting contributors
- # All rights reserved.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are
- # met:
- #
- # * Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- #
- # * Redistributions in binary form must reproduce the above copyright
- # notice, this list of conditions and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- #
- # * Neither the name of the zsh-syntax-highlighting contributors nor the
- # names of its contributors may be used to endorse or promote products
- # derived from this software without specific prior written permission.
- #
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #
- #--------------8<-------------------8<-------------------8<-----------------
- # Rebind all ZLE widgets to make them invoke _zsh_highlights.
- _zsh_highlight_bind_widgets()
- {
- # Load ZSH module zsh/zleparameter, needed to override user defined widgets.
- zmodload zsh/zleparameter 2>/dev/null || {
- echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
- return 1
- }
-
- # Override ZLE widgets to make them invoke _zsh_highlight.
- local cur_widget
- for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
- case $widgets[$cur_widget] in
+ # Check if $1 denotes the name of a callable function, i.e. it is fully
+ # defined or it is marked for autoloading and autoloading it at the first
+ # call to it will succeed. In particular, if $1 has been marked for
+ # autoloading but is not available in $fpath, then it will return 1 (false).
+ #
+ # This is based on the zsh-syntax-highlighting plugin.
+ #
+ _history-substring-search-function-callable() {
+ if (( ${+functions[$1]} )) && ! [[ "$functions[$1]" == *"builtin autoload -X"* ]]; then
+ return 0 # already fully loaded
+ else
+ # "$1" is either an autoload stub, or not a function at all.
+ # 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
+ }
- # Already rebound event: do nothing.
- user:$cur_widget|user:_zsh_highlight_widget_*);;
+ #
+ # The zsh-syntax-highlighting plugin uses zle-line-pre-redraw hook instead
+ # of the legacy "bind all widgets" if 1) zsh has the memo= feature (added in
+ # version 5.9) and 2) add-zle-hook-widget is available.
+ #
+ if [[ $_history_substring_search_zsh_5_9 -eq 1 ]] && _history-substring-search-function-callable add-zle-hook-widget; then
+ #
+ # The following code is based on the zsh-syntax-highlighting plugin.
+ #
+ autoload -U add-zle-hook-widget
- # User defined widget: override and rebind old one with prefix "orig-".
- user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \
- _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
- zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+ _history-substring-search-zle-line-finish() {
+ #
+ # Reset $WIDGET since the 'main' highlighter depends on it.
+ #
+ # 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
+ }
+ }
- # Completion widget: override and rebind old one with prefix "orig-".
- completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
- _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
- zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+ _history-substring-search-zle-line-pre-redraw() {
+ #
+ # If the zsh-syntax-highlighting plugin has been loaded (after our plugin
+ # plugin, otherwise this hook wouldn't be called), remove our hooks.
+ #
+ if [[ $+ZSH_HIGHLIGHT_VERSION -eq 1 ]]; then
+ autoload -U add-zle-hook-widget
+ add-zle-hook-widget -d zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw
+ add-zle-hook-widget -d zle-line-finish _history-substring-search-zle-line-finish
+ return 0
+ fi
+ #
+ # 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 "$@"
+ }
- # Builtin widget: override and make it call the builtin ".widget".
- builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \
- zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+ if [[ -o zle ]]; then
+ add-zle-hook-widget zle-line-pre-redraw _history-substring-search-zle-line-pre-redraw
+ add-zle-hook-widget zle-line-finish _history-substring-search-zle-line-finish
+ fi
+ else
+ #
+ # The following snippet was taken from the zsh-syntax-highlighting project:
+ # https://github.com/zsh-users/zsh-syntax-highlighting/blob/56b134f5d62ae3d4e66c7f52bd0cc2595f9b305b/zsh-syntax-highlighting.zsh#L126-161
+ #
+ # SPDX-SnippetBegin
+ # SPDX-License-Identifier: BSD-3-Clause
+ # SPDX-SnippetCopyrightText: 2010-2011 zsh-syntax-highlighting contributors
+ #--------------8<-------------------8<-------------------8<-----------------
+ # Rebind all ZLE widgets to make them invoke _zsh_highlights.
+ _zsh_highlight_bind_widgets()
+ {
+ # Load ZSH module zsh/zleparameter, needed to override user defined widgets.
+ zmodload zsh/zleparameter 2>/dev/null || {
+ echo 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2
+ return 1
+ }
+
+ # Override ZLE widgets to make them invoke _zsh_highlight.
+ local cur_widget
+ for cur_widget in ${${(f)"$(builtin zle -la)"}:#(.*|_*|orig-*|run-help|which-command|beep|yank*)}; do
+ case $widgets[$cur_widget] in
+
+ # Already rebound event: do nothing.
+ user:$cur_widget|user:_zsh_highlight_widget_*);;
+
+ # User defined widget: override and rebind old one with prefix "orig-".
+ user:*) eval "zle -N orig-$cur_widget ${widgets[$cur_widget]#*:}; \
+ _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
+ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+
+ # Completion widget: override and rebind old one with prefix "orig-".
+ completion:*) eval "zle -C orig-$cur_widget ${${widgets[$cur_widget]#*:}/:/ }; \
+ _zsh_highlight_widget_$cur_widget() { builtin zle orig-$cur_widget -- \"\$@\" && _zsh_highlight }; \
+ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+
+ # Builtin widget: override and make it call the builtin ".widget".
+ builtin) eval "_zsh_highlight_widget_$cur_widget() { builtin zle .$cur_widget -- \"\$@\" && _zsh_highlight }; \
+ zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
+
+ # Default: unhandled case.
+ *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
+ esac
+ done
+ }
+ #-------------->8------------------->8------------------->8-----------------
+ # SPDX-SnippetEnd
- # Default: unhandled case.
- *) echo "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;;
- esac
- done
- }
- #-------------->8------------------->8------------------->8-----------------
+ _zsh_highlight_bind_widgets
+ fi
- _zsh_highlight_bind_widgets
+ unfunction _history-substring-search-function-callable
fi
_history-substring-search-begin() {
@@ -312,12 +363,21 @@
_history-substring-search-begin() {
_history-substring-search-end() {
setopt localoptions extendedglob
+ local highlight_memo=
_history_substring_search_result=$BUFFER
+ if [[ $_history_substring_search_zsh_5_9 -eq 1 ]]; then
+ highlight_memo='memo=history-substring-search'
+ fi
+
# the search was successful so display the result properly by clearing away
# existing highlights and moving the cursor to the end of the result buffer
if [[ $_history_substring_search_refresh_display -eq 1 ]]; then
- region_highlight=()
+ if [[ -n $highlight_memo ]]; then
+ region_highlight=( "${(@)region_highlight:#*${highlight_memo}*}" )
+ else
+ region_highlight=()
+ fi
CURSOR=${#BUFFER}
fi
@@ -337,7 +397,9 @@
_history-substring-search-end() {
if [[ $query_part_match_index -le ${#BUFFER:$highlight_start_index} ]]; then
highlight_start_index=$(( $highlight_start_index + $query_part_match_index ))
highlight_end_index=$(( $highlight_start_index + ${#query_part} ))
- region_highlight+=("$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) $_history_substring_search_query_highlight")
+ region_highlight+=(
+ "$(($highlight_start_index - 1)) $(($highlight_end_index - 1)) ${_history_substring_search_query_highlight}${highlight_memo:+,$highlight_memo}"
+ )
fi
done
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment