Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global



The widgets introduce `$__savecursor' and `$__searching' without
declaring them global first, so you get a warning such as this during
the first invocation:

up-line-or-beginning-search:15: scalar parameter __savecursor created globally in function
up-line-or-beginning-search:16: scalar parameter __searching created globally in function

This fixes it.
---
 Functions/Zle/down-line-or-beginning-search | 40 +++++++++++++++++------------
 Functions/Zle/up-line-or-beginning-search   | 38 +++++++++++++++------------
 2 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/Functions/Zle/down-line-or-beginning-search b/Functions/Zle/down-line-or-beginning-search
index fbd2c33..ff3d1d2 100644
--- a/Functions/Zle/down-line-or-beginning-search
+++ b/Functions/Zle/down-line-or-beginning-search
@@ -1,21 +1,27 @@
 # Like down-line-or-search, but uses the whole line prefix up to the
 # cursor position for searching forwards.
 
-emulate -L zsh
+typeset -g __searching __savecursor
 
-if [[ ${+NUMERIC} -eq 0 &&
-    ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
-then
-  [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
-  __searching=$WIDGET
-  __savecursor=$CURSOR
-  if zle .history-beginning-search-forward; then
-    [[ $RBUFFER = *$'\n'* ]] || 
-	zstyle -T ':zle:down-line-or-beginning-search' leave-cursor &&
-	zle .end-of-line
-    return
-  fi
-  [[ $RBUFFER = *$'\n'* ]] || return
-fi
-__searching=''
-zle .down-line-or-history
+down-line-or-beginning-search () {
+    emulate -L zsh
+
+    if [[ ${+NUMERIC} -eq 0 &&
+                ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
+    then
+        [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
+        __searching=$WIDGET
+        __savecursor=$CURSOR
+        if zle .history-beginning-search-forward; then
+            [[ $RBUFFER = *$'\n'* ]] ||
+            zstyle -T ':zle:down-line-or-beginning-search' leave-cursor &&
+            zle .end-of-line
+            return
+        fi
+        [[ $RBUFFER = *$'\n'* ]] || return
+    fi
+    __searching=''
+    zle .down-line-or-history
+}
+
+up-line-or-beginning-search "$@"
diff --git a/Functions/Zle/up-line-or-beginning-search b/Functions/Zle/up-line-or-beginning-search
index 5348e7a..5bd5d57 100644
--- a/Functions/Zle/up-line-or-beginning-search
+++ b/Functions/Zle/up-line-or-beginning-search
@@ -1,20 +1,26 @@
 # Like up-line-or-search, but uses the whole line prefix up to the
 # cursor position for searching backwards.
 
-emulate -L zsh
+typeset -g __searching __savecursor
 
-if [[ $LBUFFER == *$'\n'* ]]; then
-  zle .up-line-or-history
-  __searching=''
-elif [[ -n $PREBUFFER ]] && 
-    zstyle -t ':zle:up-line-or-beginning-search' edit-buffer
-then
-  zle .push-line-or-edit
-else
-  [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
-  __savecursor=$CURSOR
-  __searching=$WIDGET
-  zle .history-beginning-search-backward
-  zstyle -T ':zle:up-line-or-beginning-search' leave-cursor &&
-      zle .end-of-line
-fi
+up-line-or-beginning-search () {
+    emulate -L zsh
+
+    if [[ $LBUFFER == *$'\n'* ]]; then
+        zle .up-line-or-history
+        __searching=''
+    elif [[ -n $PREBUFFER ]] &&
+        zstyle -t ':zle:up-line-or-beginning-search' edit-buffer
+    then
+        zle .push-line-or-edit
+    else
+        [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
+        __savecursor=$CURSOR
+        __searching=$WIDGET
+        zle .history-beginning-search-backward
+        zstyle -T ':zle:up-line-or-beginning-search' leave-cursor &&
+        zle .end-of-line
+    fi
+}
+
+up-line-or-beginning-search "$@"
-- 
1.8.0



Messages sorted by: Reverse Date, Date, Thread, Author