Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Problem with motion commands defined using match-word-by-style used with vi-delete
- X-seq: zsh-users 10167
- From: "Nikolai Weibull" <now@xxxxxxxx>
- To: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Problem with motion commands defined using match-word-by-style used with vi-delete
- Date: Sat, 22 Apr 2006 23:38:48 +0200
- Cc: "Zsh Users" <zsh-users@xxxxxxxxxx>
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=K3s95qHXX1+uIQmkGPN298jskg9kIcbfgqTtGiExUIj5uhMSHJBXas/ekvHb1O7yAbGbsJ5nlJcfcrRgFhLvyzS9RNoqp02TqqMg/tThch9cK3JUHC9z3kB1rHRCvTtrTXuLmVbtA6NXitvRVX3xUP0Q7KZvGX6jcVnL/nWgjtQ=
- In-reply-to: <060422113544.ZM9246@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <dbfc82860604211610x70a12466j7eb5bb6758e85c0d@xxxxxxxxxxxxxx> <060421220035.ZM7625@xxxxxxxxxxxxxxxxxxxxxx> <dbfc82860604220404m121e4659i12a9cc901717a191@xxxxxxxxxxxxxx> <060422113544.ZM9246@xxxxxxxxxxxxxxxxxxxxxx>
- Sender: nikolai.weibull@xxxxxxxxx
On 4/22/06, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Apr 22, 1:04pm, Nikolai Weibull wrote:
> } > } Until then I'm going to use my own vi-delete
> } >
> } > Creating a vi-delete-match function seems like the next best thing.
> }
> } That's what I meant (I think) :-).
>
> Yes, I was agreeing with you.
Ah, :-).
> On further checking, however, the value of $WIDGETFUNC within the widget
> called by vi-delete appears to be ".internal" which means that although
> it's possible to determine *when* one of these functions has been called
> from vi-delete, it's not possible to determine under which name it was
> called. So a custom vi-delete replacement appears to be required, and
> perhaps we should consider adding one to the distribution. The same is
> going to be true of vi-change and any other widget that combines with a
> motion widget in this way.
I've begun writing one, but it won't work. What I do is roughly the following:
vi-delete-match () {
integer begin end
local motion
integer count=0
read -k 1 motion
while [[ $motion == [[:digit:]] ]]; do
(( count = count * 10 + motion ))
read -k 1 motion
done
(( count = (count == 0) ? 1 : count ))
case $motion in
(*)
local motion_command="${${:-$(bindkey -a $motion)}##* }"
if [[ -n $motion_command ]]; then
(( begin = CURSOR ))
zle $motion_command -n $count
(( end = CURSOR + 1 ))
(( CURSOR = begin ))
BUFFER="${BUFFER[1,begin]}${BUFFER[end,-1]}"
fi
;;
esac
}
zle -N vi-delete-match
bindkey -a "d" vi-delete-match
The convoluted handling of $motion is for future expansion with what
Vim refers to as text objects, i.e., "aw" for "a word", which selects
the current word you're in.
This, however, doesn't work. $WIDGET is set to vi-delete-match, which
is the top-level widget, not the widget run by the zle command in
zle $motion_command -n $count
I guess this makes sense in almost all cases, but not here.
$WIDGETFUNC is set to vi-delete-match, which is correct, given the
value of $WIDGET.
I'm positive that there's a way to do this, but I can't see it, so any
help is welcome.
I'm sure it'll break all kinds of stuff, but one solution would be to
have getvirange() set bindk to k2 once it has been read and checked.
Also, it would be great if we had a switch for bindkey that made it
print the widgets name, nothing else.
nikolai
Messages sorted by:
Reverse Date,
Date,
Thread,
Author