zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global
@ 2013-01-23 21:16 Frank Terbeck
  2013-01-23 21:26 ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2013-01-23 21:16 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global
  2013-01-23 21:16 [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global Frank Terbeck
@ 2013-01-23 21:26 ` Frank Terbeck
  2013-01-24  9:47   ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2013-01-23 21:26 UTC (permalink / raw)
  To: zsh-workers

[...]
>  Functions/Zle/down-line-or-beginning-search | 40 +++++++++++++++++------------
>  Functions/Zle/up-line-or-beginning-search   | 38 +++++++++++++++------------
[...]

The diff looks more invasive then it really is. Here is a diff that
ignores all whitespace-related changes via:

  % git diff --ignore-all-space

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,6 +1,9 @@
 # Like down-line-or-search, but uses the whole line prefix up to the
 # cursor position for searching forwards.
 
+typeset -g __searching __savecursor
+
+down-line-or-beginning-search () {
     emulate -L zsh
 
     if [[ ${+NUMERIC} -eq 0 &&
@@ -19,3 +22,6 @@ then
     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,6 +1,9 @@
 # Like up-line-or-search, but uses the whole line prefix up to the
 # cursor position for searching backwards.
 
+typeset -g __searching __savecursor
+
+up-line-or-beginning-search () {
     emulate -L zsh
 
     if [[ $LBUFFER == *$'\n'* ]]; then
@@ -18,3 +21,6 @@ else
         zstyle -T ':zle:up-line-or-beginning-search' leave-cursor &&
         zle .end-of-line
     fi
+}
+
+up-line-or-beginning-search "$@"


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global
  2013-01-23 21:26 ` Frank Terbeck
@ 2013-01-24  9:47   ` Peter Stephenson
  2013-01-24 12:25     ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2013-01-24  9:47 UTC (permalink / raw)
  To: zsh-workers

On Wed, 23 Jan 2013 22:26:22 +0100
Frank Terbeck <ft@bewatermyfriend.org> wrote:
> 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,6 +1,9 @@
>...
> +up-line-or-beginning-search "$@"

This one should presumably be "down".

However, I'm not sure you need to go to these lengths (not that it's
doing anything particularly out of the ordinary): I think using the
"typeset -g" within the original functions would work OK.

pws


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global
  2013-01-24  9:47   ` Peter Stephenson
@ 2013-01-24 12:25     ` Frank Terbeck
  0 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2013-01-24 12:25 UTC (permalink / raw)
  To: zsh-workers

Peter Stephenson wrote:
> Frank Terbeck <ft@bewatermyfriend.org> wrote:
>> 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,6 +1,9 @@
>>...
>> +up-line-or-beginning-search "$@"
>
> This one should presumably be "down".

Meh. I should be attached to a device, that delivers an electric shock
every time I use copy-and-paste in source code...

> However, I'm not sure you need to go to these lengths (not that it's
> doing anything particularly out of the ordinary): I think using the
> "typeset -g" within the original functions would work OK.

You're right. The impact is probably negligible. I'll do it that way.

Regards, Frank


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global
@ 2013-04-05 18:39 Frank Terbeck
  0 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2013-04-05 18:39 UTC (permalink / raw)
  To: zsh-workers

This is a followup to 30995 taking Peter's suggestions from 30997 into
account.
---
 Functions/Zle/down-line-or-beginning-search | 2 ++
 Functions/Zle/up-line-or-beginning-search   | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/Functions/Zle/down-line-or-beginning-search b/Functions/Zle/down-line-or-beginning-search
index fbd2c33..4c713f1 100644
--- a/Functions/Zle/down-line-or-beginning-search
+++ b/Functions/Zle/down-line-or-beginning-search
@@ -3,6 +3,8 @@
 
 emulate -L zsh
 
+typeset -g __searching __savecursor
+
 if [[ ${+NUMERIC} -eq 0 &&
     ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
 then
diff --git a/Functions/Zle/up-line-or-beginning-search b/Functions/Zle/up-line-or-beginning-search
index 5348e7a..bdc3933 100644
--- a/Functions/Zle/up-line-or-beginning-search
+++ b/Functions/Zle/up-line-or-beginning-search
@@ -3,6 +3,8 @@
 
 emulate -L zsh
 
+typeset -g __searching __savecursor
+
 if [[ $LBUFFER == *$'\n'* ]]; then
   zle .up-line-or-history
   __searching=''
-- 
1.8.2.rc1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-05 19:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-23 21:16 [PATCH] Stop {up,down}-line-or-beginning-search from triggeing warn_create_global Frank Terbeck
2013-01-23 21:26 ` Frank Terbeck
2013-01-24  9:47   ` Peter Stephenson
2013-01-24 12:25     ` Frank Terbeck
2013-04-05 18:39 Frank Terbeck

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).