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

Re: Magic-Backspace



On Sep 11,  9:51am, Pascal Wittmann wrote:
}
} I thought of implementing some magic-backspace that removes characters
} until the 'current' completion is ambiguous (i.e. some extended version
} of undo).
} 
} The problem I'm facing is that I can not find out if the current
} completion is ambiguous. Is this possible at all?

This is a rather tricky thing to attempt because the completion system
is a bit more than just a ZLE widget.  Completion wants to have control
of the editing process, i.e., you get *either* direct manipulation of
the editor buffer with BUFFER, LBUFFER, RBUFFER, etc., *or* you get the
completion system mucking about in the buffer as it deems necessary,
but not both at once.

That's one reason why completion widgets are created with "zle -C ..."
rather than with "zle -N ...".

So the best approach I can think of is to do this in two parts:  an
ordinary zle widget, that is a wrapper around a completion widget.  The
wrapper widget declares some variables as locals which the completion
widget then uses but does not declare.

This new completion widget does nothing but call _main_complete, then
copy some values from the $compstate hash into the shared variables,
and finally assign compstate[insert]='' so that the command line will
not be changed.  You need $compstate[unambiguous], and possibly also
context, unambiguous_cursor, unambiguous_positions, insert_positions.

Your wrapper will call the completion widget with "zle widget-name"
and then examine the shared variables to deterimine whether to delete
a character.  As you can probably tell, the completion system is very
strongly tied to detecting when the line is NOT ambiguous, so you're
going to have to figure out how to extrapolate back from that.

Obviously there's a whole lot of stuff I've glossed over here.  What
should your widget do if invoked in the middle of a word instead of
at the end?  What state do you need to clear before, or set after,
calling the completion widget to avoid entering menu completion or
displaying a listing?  And so on.

Have fun!



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