From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22473 invoked by alias); 11 Sep 2012 15:09:35 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17260 Received: (qmail 13578 invoked from network); 11 Sep 2012 15:09:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120911080919.ZM19507@torch.brasslantern.com> Date: Tue, 11 Sep 2012 08:09:19 -0700 In-reply-to: <504EED6B.7030403@gmx.net> Comments: In reply to Pascal Wittmann "Magic-Backspace" (Sep 11, 9:51am) References: <504EED6B.7030403@gmx.net> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Magic-Backspace MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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!