Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: the function to show a digit argument while it is being typed
- X-seq: zsh-users 14541
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: the function to show a digit argument while it is being typed
- Date: Tue, 10 Nov 2009 19:56:43 -0800
- In-reply-to: <10081257897632@xxxxxxxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <10081257897632@xxxxxxxxxxxxxxxxxxx>
On Nov 11, 3:00am, Dmitry Bolshakov wrote:
} Subject: the function to show a digit argument while it is being typed
}
} in bash a digit argument is showed when it is being typed
}
} i have writed small function which do the same
That's very nice, but it shouldn't need to be that complex. ZLE will
make sure that your function is never called except when $KEYS[2] is a
digit, so you don't need to do your own loop to read more keys.
function digit-argument-show {
typeset -g __digit_arg
if [[ $LASTWIDGET != *-argument ]]
then
__digit_arg=""
PREDISPLAY=""
fi
__digit_arg+=$KEYS[2]
PREDISPLAY="(arg: $__digit_arg) "
zle -R
zle .digit-argument
}
function neg-argument-show {
typeset -g __digit_arg=-
zle .neg-argument
}
Aha, I see the problem with that ... you need to erase PREDISPLAY after
the last digit-argument has happened. There's still a simpler way than
writing your own loop, namely by using zle read-command.
function digit-argument-show {
typeset -g __digit_arg
if [[ $LASTWIDGET != (digit|neg)-argument ]]
then
__digit_arg=""
PREDISPLAY=""
fi
__digit_arg+=$KEYS[2]
PREDISPLAY="(arg: $__digit_arg) "
zle -R
zle .digit-argument
local REPLY # Not strictly necessary
zle read-command # Sets $REPLY and $KEYS
if [[ $REPLY != digit-argument ]]
then
__digit_arg=""
PREDISPLAY=""
fi
zle -U $KEYS
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author