* Magic-Backspace @ 2012-09-11 7:51 Pascal Wittmann 2012-09-11 15:09 ` Magic-Backspace Bart Schaefer 2012-09-15 18:57 ` Magic-Backspace Oliver Kiddle 0 siblings, 2 replies; 4+ messages in thread From: Pascal Wittmann @ 2012-09-11 7:51 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 478 bytes --] Hi, I thought of implementing some magic-backspace that removes characters until the 'current' completion is ambiguous (i.e. some extended version of undo). For example, if I type autoconf and press 'magic-backspace' it would result in auto The problem I'm facing is that I can not find out if the current completion is ambiguous. Is this possible at all? (I've tried to abuse complete-word and friends, but without success). Regards Pascal [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Magic-Backspace 2012-09-11 7:51 Magic-Backspace Pascal Wittmann @ 2012-09-11 15:09 ` Bart Schaefer 2012-09-11 15:21 ` Magic-Backspace Pascal Wittmann 2012-09-15 18:57 ` Magic-Backspace Oliver Kiddle 1 sibling, 1 reply; 4+ messages in thread From: Bart Schaefer @ 2012-09-11 15:09 UTC (permalink / raw) To: zsh-users 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! ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Magic-Backspace 2012-09-11 15:09 ` Magic-Backspace Bart Schaefer @ 2012-09-11 15:21 ` Pascal Wittmann 0 siblings, 0 replies; 4+ messages in thread From: Pascal Wittmann @ 2012-09-11 15:21 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1219 bytes --] On 09/11/2012 05:09 PM, Bart Schaefer wrote: > 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. > [snip] > > 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! > Thanks for all these pointers! Now I've a starting point. [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Magic-Backspace 2012-09-11 7:51 Magic-Backspace Pascal Wittmann 2012-09-11 15:09 ` Magic-Backspace Bart Schaefer @ 2012-09-15 18:57 ` Oliver Kiddle 1 sibling, 0 replies; 4+ messages in thread From: Oliver Kiddle @ 2012-09-15 18:57 UTC (permalink / raw) To: Pascal Wittmann; +Cc: zsh-users On 11 Sep, 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). I've got a function which does roughly this. It has a number of issues and, as I wrote it over eight years ago, I can't remember what those issues are. I've attached it below. It works by removing characters from the PREFIX and trying completion. It is intended to be used as a completion widget via _generic: zle -C retract complete-word _generic zstyle ':completion:retract::::' completer _retract bindkey '^[[24~' retract # F12 I'm not sure what the commented out line was for. Oliver #autoload local _comp_backup=1 bumax=30 if (( ! $+functions[compadd] )); then compadd() { local save oldp="$PREFIX" SUFFIX= # removing the -O option is a nasty way to make this work from _multi_parts zparseopts -D -E O:=save local i for ((i=_comp_backup;i>0;i--)); do PREFIX="${PREFIX%?}" done builtin compadd -S '' -F "( $oldp* )" "$@" } trap 'unfunction compadd' EXIT INT fi while [[ _comp_backup -le bumax ]]; do _complete && return (( _comp_backup++ )) done #builtin compadd - '' return 1 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-15 19:04 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-09-11 7:51 Magic-Backspace Pascal Wittmann 2012-09-11 15:09 ` Magic-Backspace Bart Schaefer 2012-09-11 15:21 ` Magic-Backspace Pascal Wittmann 2012-09-15 18:57 ` Magic-Backspace Oliver Kiddle
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).