zsh-users
 help / color / mirror / code / Atom feed
* insert-last-word makes space disappear
@ 2004-08-13  8:23 Jesper Holmberg
  2004-08-13 23:32 ` Andy Spiegl
  2004-08-14  7:39 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Jesper Holmberg @ 2004-08-13  8:23 UTC (permalink / raw)
  To: Zsh-users List

Here's a problem I've seen for a long time, but never gotten around
to reporting. It seems like a bug to me, but perhaps I have something
configured incorrectly.

I use the new completion system with <TAB> bound to menu-complete, on zsh
4.2.0.

What happens is that the combination of menu-complete and insert-last-word
(bound to alt-.) sometimes makes a vital space disappear on the command
line. I'll give an example:

% ls last.avi
last.avi
% mpl<TAB>

zsh now completes 'mpl' to 'mplayer ', which leaves me with the command
line:

% mplayer 

with a space after 'mplayer'.

Now, if I hit alt-. (insert-last-word), this is the result:

% mplayerlast.avi

The space that was after 'mplayer' has been eaten!

It seems to me that this only happens when the menu-complete has something
unambiguous to complete, i.e. when 'mplayer' is the only completion of
'mpl'. If there had been more than one alternative, the space would not
have been added after 'mplayer', and the problem wouldn't have manifested
itself.

Is this a bug?

TIA,

Jesper


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

* Re: insert-last-word makes space disappear
  2004-08-13  8:23 insert-last-word makes space disappear Jesper Holmberg
@ 2004-08-13 23:32 ` Andy Spiegl
  2004-08-14  7:39 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Spiegl @ 2004-08-13 23:32 UTC (permalink / raw)
  To: Zsh-users List

> The space that was after 'mplayer' has been eaten!
What version of zsh are you using?
I use "insert-last-word" all the time and have never noticed this bug
before.  Maybe it's some (wrong) option you have set but I have no idea
which one it could be.

Where are the zsh-experts?  :-)
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Money often costs to much.  -- Ralph Waldo Emerson


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

* Re: insert-last-word makes space disappear
  2004-08-13  8:23 insert-last-word makes space disappear Jesper Holmberg
  2004-08-13 23:32 ` Andy Spiegl
@ 2004-08-14  7:39 ` Bart Schaefer
  2004-08-16  6:46   ` Jesper Holmberg
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2004-08-14  7:39 UTC (permalink / raw)
  To: Zsh-users List

On Fri, 13 Aug 2004, Jesper Holmberg wrote:

> What happens is that the combination of menu-complete and 
> insert-last-word (bound to alt-.) sometimes makes a vital space 
> disappear on the command line.

I suspect that you don't really have alt-. bound to insert-last-word,
or more precisely that you have replaced the builtin insert-last-word
widget with a user-defined widget such as smart-insert-last-word from
the Functions/Zle directory.

Automatic removal of spaces (auto-suffixes in general, really) is a tricky 
business.  The rule (as nearly as it can be stated) is supposed to be that 
the suffix gets removed if the _next_ widget is any one that either does 
_not_ perform an insertion, or that inserts the suffix.  What this means 
is that completion puts the suffix into the buffer and stashes away the 
fact that a suffix was added and what it was, and then it's up to zle (not 
any particular widget, but the editor engine itself) to adjust the suffix
properly _after_ the next keystroke has been read but _before_ the widget
for that keystroke is called.

This is handled for builtin widgets by flagging in the widget table those 
widgets that perform insertions -- but there's no provision for flagging a 
user-defined widget one way or the other.  This is dealt with by deferring 
the suffix decision until either (1) "zle any-builtin-widget-name-here" is 
called, in which case the flag for that builtin applies, or (2) one of the 
buffer variables is modified, in which case the suffix is normally kept.  
Most of the time, this results in the right behavior.

In the case of smart-insert-last-word, unfortunately, the first thing that 
happens is a call to "zle .up-history" so that it can fetch the last word 
from the previous history entry.  Case (1) applies; the suffix removal 
rule for a motion like up-history is to remove the suffix; and thus you
get the behavior you saw.

The workaround for this is to make smart-insert-last-word (or whatever the 
function for your user-defined widget is) forcibly keep the suffix, by 
e.g. placing LBUFFER+='' or an equivalent assignment before the call to 
"zle .up-history".

An alternate solution would be to rewrite smart-insert-last-word to use
(and thus require) the zsh/parameter module and the $history variable,
rather than using zle history motion widgets.

The best long-term solution would be to extend the user-defined widget
creation routines to flag widgets that should keep (or erase) a previous
auto-suffix, so that the internal implementation of the widget doesn't
matter.


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

* Re: insert-last-word makes space disappear
  2004-08-14  7:39 ` Bart Schaefer
@ 2004-08-16  6:46   ` Jesper Holmberg
  0 siblings, 0 replies; 4+ messages in thread
From: Jesper Holmberg @ 2004-08-16  6:46 UTC (permalink / raw)
  To: Zsh-users List

* On Sat Aug 14, Bart Schaefer wrote:
> On Fri, 13 Aug 2004, Jesper Holmberg wrote:
> 
> > What happens is that the combination of menu-complete and 
> > insert-last-word (bound to alt-.) sometimes makes a vital space 
> > disappear on the command line.
> 
> I suspect that you don't really have alt-. bound to insert-last-word,
> or more precisely that you have replaced the builtin insert-last-word
> widget with a user-defined widget such as smart-insert-last-word from
> the Functions/Zle directory.

Yes, I do use smart-insert-last-word, sorry for the confusion. I have now
added your LBUFFER+='' trick to the start of this function, and so far it
seems to be working well. I'll report back if I find any problems.

As for the long-time solution, I suppose others are better fit than me to
tackle this.

Thank you for your help, Bart!

Jesper


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

end of thread, other threads:[~2004-08-16  6:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-13  8:23 insert-last-word makes space disappear Jesper Holmberg
2004-08-13 23:32 ` Andy Spiegl
2004-08-14  7:39 ` Bart Schaefer
2004-08-16  6:46   ` Jesper Holmberg

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