zsh-workers
 help / color / mirror / code / Atom feed
* Re: Bug#270632: zsh: Completion and spaces
       [not found]   ` <20040908194101.GD2775@larve.net>
@ 2004-09-08 20:26     ` Clint Adams
  2004-09-08 21:22       ` Hugo Haas
  2004-09-08 23:48       ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: Clint Adams @ 2004-09-08 20:26 UTC (permalink / raw)
  To: zsh-workers; +Cc: Hugo Haas, 270632-forwarded

> Oh, you're right. It's not insert-last-word which is the culprit, but
> smart-insert-last-word.
> 
> I have done:
> 
>   autoload smart-insert-last-word
>   zle -N insert-last-word smart-insert-last-word
> 
> With this, you should be able to witness the problem.

Is this the correct fix?

Index: Functions/Zle/smart-insert-last-word
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/smart-insert-last-word,v
retrieving revision 1.2
diff -u -r1.2 smart-insert-last-word
--- Functions/Zle/smart-insert-last-word	27 Jan 2003 16:41:17 -0000	1.2
+++ Functions/Zle/smart-insert-last-word	8 Sep 2004 20:25:14 -0000
@@ -86,5 +86,5 @@
 	fi
     done
 fi
-LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC]
+LBUFFER[lcursor+1,cursor+1]=" $lastcmd[-NUMERIC]"
 _ilw_cursor=$CURSOR


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-08 20:26     ` Bug#270632: zsh: Completion and spaces Clint Adams
@ 2004-09-08 21:22       ` Hugo Haas
  2004-09-08 23:48       ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Hugo Haas @ 2004-09-08 21:22 UTC (permalink / raw)
  To: Clint Adams; +Cc: zsh-workers, 270632-quiet

[-- Attachment #1: Type: text/plain, Size: 1897 bytes --]

* Clint Adams <schizo@debian.org> [2004-09-08 16:26-0400]
> > Oh, you're right. It's not insert-last-word which is the culprit, but
> > smart-insert-last-word.
> > 
> > I have done:
> > 
> >   autoload smart-insert-last-word
> >   zle -N insert-last-word smart-insert-last-word
> > 
> > With this, you should be able to witness the problem.
> 
> Is this the correct fix?
> 
> Index: Functions/Zle/smart-insert-last-word
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/Zle/smart-insert-last-word,v
> retrieving revision 1.2
> diff -u -r1.2 smart-insert-last-word
> --- Functions/Zle/smart-insert-last-word	27 Jan 2003 16:41:17 -0000	1.2
> +++ Functions/Zle/smart-insert-last-word	8 Sep 2004 20:25:14 -0000
> @@ -86,5 +86,5 @@
>  	fi
>      done
>  fi
> -LBUFFER[lcursor+1,cursor+1]=$lastcmd[-NUMERIC]
> +LBUFFER[lcursor+1,cursor+1]=" $lastcmd[-NUMERIC]"
>  _ilw_cursor=$CURSOR

Your patch fixes the issue with a minor other issue, which is purely
cosmetic.

This always insert a space, whether it's needed or not. Basically,
with my original scenario:

  hugo@buena /tmp% touch test
  hugo@buena /tmp% alias myfoobarcat=cat
  hugo@buena /tmp% cat test

Then:

  hugo@buena /tmp% myfoob[]

Tab:

  hugo@buena /tmp% myfoobarcat []

smart-insert-last-word:

  hugo@buena /tmp% myfoobarcat test[]

smart-insert-last-word again:

  hugo@buena /tmp% myfoobarcattest  myfoobarcat=cat[]

So the first call to smart-insert-last-word did put a space between
myfoobarcat and test, but the second call added another leading space
between myfoobarcattest and myfoobarcat=cat. This extra space should
only be added if the previous word was generated by a completion
function, FWICT.

Again, this is purely cosmetic IMO.

Regards,

Hugo

-- 
Hugo Haas - http://larve.net/people/hugo/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 307 bytes --]

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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-08 20:26     ` Bug#270632: zsh: Completion and spaces Clint Adams
  2004-09-08 21:22       ` Hugo Haas
@ 2004-09-08 23:48       ` Bart Schaefer
  2004-09-08 23:56         ` Clint Adams
  1 sibling, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2004-09-08 23:48 UTC (permalink / raw)
  To: Clint Adams; +Cc: zsh-workers, 270632-forwarded

On Wed, 8 Sep 2004, Clint Adams wrote:

> Is this the correct fix?

No, it isn't.  See zsh-users/7841 for discussion, and the final three 
paragraphs therein for suggested repair.


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-08 23:48       ` Bart Schaefer
@ 2004-09-08 23:56         ` Clint Adams
  2004-09-09 14:59           ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Clint Adams @ 2004-09-08 23:56 UTC (permalink / raw)
  To: zsh-workers; +Cc: 270632-submitter

> No, it isn't.  See zsh-users/7841 for discussion, and the final three 
> paragraphs therein for suggested repair.

Ah.  Is there a downside to the LBUFFER+='' workaround?


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-08 23:56         ` Clint Adams
@ 2004-09-09 14:59           ` Bart Schaefer
  2004-09-09 15:15             ` Clint Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2004-09-09 14:59 UTC (permalink / raw)
  To: Clint Adams; +Cc: zsh-workers, 270632-submitter

On Wed, 8 Sep 2004, Clint Adams wrote:

> > No, it isn't.  See zsh-users/7841 for discussion, and the final three 
> > paragraphs therein for suggested repair.
> 
> Ah.  Is there a downside to the LBUFFER+='' workaround?

Only that it always disables auto-suffix-removal.  E.g., if $LBUFFER ends 
in a slash which was added as a completion suffix, and the first character 
of the word to be inserted is also a slash, then normally the suffix would 
be deleted in order that the slash not become doubled; but with the work- 
around, you get the double slash.


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-09 14:59           ` Bart Schaefer
@ 2004-09-09 15:15             ` Clint Adams
  2004-09-09 21:37               ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Clint Adams @ 2004-09-09 15:15 UTC (permalink / raw)
  To: zsh-workers; +Cc: 270632-submitter

> Only that it always disables auto-suffix-removal.  E.g., if $LBUFFER ends 
> in a slash which was added as a completion suffix, and the first character 
> of the word to be inserted is also a slash, then normally the suffix would 
> be deleted in order that the slash not become doubled; but with the work- 
> around, you get the double slash.

That sounds like it's a purely cosmetic problem, but how about this for
the zsh/parameter solution?

Index: Functions/Zle/smart-insert-last-word
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/smart-insert-last-word,v
retrieving revision 1.2
diff -u -r1.2 smart-insert-last-word
--- Functions/Zle/smart-insert-last-word	27 Jan 2003 16:41:17 -0000	1.2
+++ Functions/Zle/smart-insert-last-word	9 Sep 2004 15:14:21 -0000
@@ -35,13 +35,14 @@
 #   bindkey '\e=' insert-last-assignment
 
 emulate -L zsh
+zmodload -i zsh/parameter || return 1
 setopt extendedglob
 
 # Not strictly necessary:
 # (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor _ilw_lcursor
 
 integer cursor=$CURSOR lcursor=$CURSOR
-local lastcmd pattern numeric=$NUMERIC
+local lastc lastcmd pattern numeric=$NUMERIC
 
 # Save state for repeated calls
 if (( HISTNO == _ilw_hist && cursor == _ilw_cursor )); then
@@ -64,10 +65,8 @@
 _ilw_hist=$HISTNO
 _ilw_count=$NUMERIC
 
-zle .up-history || return 1      # Retrieve previous command
-lastcmd=( ${${(z)BUFFER}:#\;} )  # Split into shell words
-zle .down-history                # Return to current command
-CURSOR=$cursor                   # Restore cursor position
+lastc="$history[$#history]"      # Retrieve previous command
+lastcmd=( ${${(z)lastc}:#\;} )   # Split into shell words
 NUMERIC=${numeric:-1}            # In case of fall through
 
 (( NUMERIC > $#lastcmd )) && return 1


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-09 15:15             ` Clint Adams
@ 2004-09-09 21:37               ` Bart Schaefer
  2004-09-11  8:11                 ` Hugo Haas
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2004-09-09 21:37 UTC (permalink / raw)
  To: Clint Adams; +Cc: zsh-workers, 270632-submitter

On Thu, 9 Sep 2004, Clint Adams wrote:

> ... how about this for the zsh/parameter solution?
> 
[...]
> +lastc="$history[$#history]"      # Retrieve previous command

That doesn't account for $NUMERIC, nor for "holes" in the history number 
sequence (the various "ignore" options) that can cause upwards movement to 
skip certain numbers.  That's part of the reason that I didn't try to 
write this patch before ...

The following is untested.


Index: Functions/Zle/smart-insert-last-word
--- smart-insert-last-word.~1.2.~	2003-03-14 17:27:01.000000000 -0800
+++ smart-insert-last-word	2004-09-09 14:34:57.000000000 -0700
@@ -1,7 +1,8 @@
 # smart-insert-last-word
 # Inspired by Christoph Lange <langec@gmx.de> from zsh-users/3265;
 # rewritten to correct multiple-call behavior after zsh-users/3270;
-# modified to work with copy-earlier-word after zsh-users/5832.
+# modified to work with copy-earlier-word after zsh-users/5832;
+# tweaked for auto-suffix-removal behavior after zsh-users/7841.
 #
 # This function as a ZLE widget can replace insert-last-word, like so:
 #
@@ -41,7 +42,7 @@
 # (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor 
_ilw_lcursor
 
 integer cursor=$CURSOR lcursor=$CURSOR
-local lastcmd pattern numeric=$NUMERIC
+local lastc lastcmd pattern numeric=$NUMERIC
 
 # Save state for repeated calls
 if (( HISTNO == _ilw_hist && cursor == _ilw_cursor )); then
@@ -64,11 +65,19 @@
 _ilw_hist=$HISTNO
 _ilw_count=$NUMERIC
 
-zle .up-history || return 1      # Retrieve previous command
-lastcmd=( ${${(z)BUFFER}:#\;} )  # Split into shell words
-zle .down-history                # Return to current command
-CURSOR=$cursor                   # Restore cursor position
-NUMERIC=${numeric:-1}            # In case of fall through
+if zmodload -i zsh/parameter
+then
+    lastc=( ${(kOn)history} )            # Get all history numbers
+    (( $#lastc > NUMERIC )) || return 1  # Check for overflow
+    lastc=$history[$lastc[NUMERIC]]      # Remember previous command
+else
+    zle .up-history || return 1          # Check for overflow
+    lastc=$BUFFER                        # Remember previous command
+    zle .down-history                    # Return to current command
+fi
+lastcmd=( ${${(z)lastc}:#\;} )           # Split into shell words
+CURSOR=$cursor                           # Restore cursor position
+NUMERIC=${numeric:-1}                    # In case of fall through
 
 (( NUMERIC > $#lastcmd )) && return 1
 


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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-09 21:37               ` Bart Schaefer
@ 2004-09-11  8:11                 ` Hugo Haas
  2004-09-13 18:04                   ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Hugo Haas @ 2004-09-11  8:11 UTC (permalink / raw)
  To: zsh-workers, 270632-quiet; +Cc: Clint Adams, 270632-submitter

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

* Bart Schaefer <schaefer@brasslantern.com> [2004-09-09 14:37-0700]
> The following is untested.

It seems to do the trick indeed.

Thanks,

Hugo

-- 
Hugo Haas - http://larve.net/people/hugo/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 307 bytes --]

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

* Re: Bug#270632: zsh: Completion and spaces
  2004-09-11  8:11                 ` Hugo Haas
@ 2004-09-13 18:04                   ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2004-09-13 18:04 UTC (permalink / raw)
  To: Hugo Haas; +Cc: zsh-workers

[I've dropped the Debian bugs addresses for now.]

On Sat, 11 Sep 2004, Hugo Haas wrote:

> * Bart Schaefer <schaefer@brasslantern.com> [2004-09-09 14:37-0700]
> > The following is untested.
> 
> It seems to do the trick indeed.

Having finally had a chance to try it ...

With the zsh/paramter patch it _never_ removes the auto-suffix, because it 
never calls a zle insert widget.  It's no better than LBUFFER+=''.

I'm reaching the conclusion that we do need some way for a user-defined 
widget to announce whether it should be considered an insertion, deletion, 
or motion, so that zle can deal properly with the suffixes added by the 
previous widget.


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

end of thread, other threads:[~2004-09-13 18:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20040908115321.GA2417@larve.net>
     [not found] ` <20040908180950.GC25987@scowler.net>
     [not found]   ` <20040908194101.GD2775@larve.net>
2004-09-08 20:26     ` Bug#270632: zsh: Completion and spaces Clint Adams
2004-09-08 21:22       ` Hugo Haas
2004-09-08 23:48       ` Bart Schaefer
2004-09-08 23:56         ` Clint Adams
2004-09-09 14:59           ` Bart Schaefer
2004-09-09 15:15             ` Clint Adams
2004-09-09 21:37               ` Bart Schaefer
2004-09-11  8:11                 ` Hugo Haas
2004-09-13 18:04                   ` Bart Schaefer

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).