zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Magic-Backspace
Date: Tue, 11 Sep 2012 08:09:19 -0700	[thread overview]
Message-ID: <120911080919.ZM19507@torch.brasslantern.com> (raw)
In-Reply-To: <504EED6B.7030403@gmx.net>

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!


  reply	other threads:[~2012-09-11 15:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11  7:51 Magic-Backspace Pascal Wittmann
2012-09-11 15:09 ` Bart Schaefer [this message]
2012-09-11 15:21   ` Magic-Backspace Pascal Wittmann
2012-09-15 18:57 ` Magic-Backspace Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=120911080919.ZM19507@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).