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 14543
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: the function to show a digit argument while it is being typed
- Date: Wed, 11 Nov 2009 07:17:58 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=GAiADK8M2hgy5ZXV0mOanR2PmUJ1o+uJy+B11jx8rKA=; b=nbZ1OenpIIeTUPmPV23aiyvclXViybJt5YeGoi11XRqS3JkYWel6mUpZ92g3R09xYC GAv7ZY2oki68/Gsv1aXl5hq76tyaZY4fxc70kJxfrYQVu/BQqX9UmPNQlWq0TVGkDHF9 lUfIjPJ8MNFwgHoFUxYEHcNZEauvaHWTw1KkE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=abloGDUGcR7KYqGg82UDbY7az7v0N+RvB7jGMDdj7D9kgVYB4TeTAmGhtSVlYh8i5E gwpKSadZUlRLHG3s5IqvvwGPGDcRZkQiaGrmncFYHAYshFRzoKFNtT90cNAhTaaYEPmr zeupTVR1+J7NAzWbcj916j3RFN7eQOrFa/k4c=
- In-reply-to: <091110204748.ZM28704@xxxxxxxxxxxxxxxxxxxxxx>
- 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> <237967ef0911101822g5bfcf4fao25fc33ba0a2e8604@xxxxxxxxxxxxxx> <091110204748.ZM28704@xxxxxxxxxxxxxxxxxxxxxx>
2009/11/11 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> On Nov 11, Â3:22am, Mikael Magnusson wrote:
> }
> } I have a similar function, it doesn't work well for negative arguments
> } though:
> }
> } function _digit_argument () {
> } Â zle -M "$NUMERIC$KEYS[-1]"
> } Â zle .digit-argument
> } }
>
> Hmm, that suggests yet another possible improvement to my function. ÂI
> assumed $NUMERIC was updated too late to use it in PREDISPLAY, but it
> is updated in time to be used in place of my __digit_arg global.
>
> Â Âfunction digit-argument-show {
> Â Â Âif [[ $LASTWIDGET == neg-argument ]]
> Â Â Âthen PREDISPLAY="(arg: $((NUMERIC*$KEYS[-1]))) "
> Â Â Âelse PREDISPLAY="(arg: $NUMERIC$KEYS[-1]) "
> Â Â Âfi
> Â Â Âzle -R
> Â Â Âzle .digit-argument
> Â Â Âzle read-command
> Â Â Â[[ $REPLY != digit-argument ]] && PREDISPLAY=""
> Â Â Âzle -U $KEYS
> Â Â}
>
> With this, you don't need the neg-argument-show function at all, and
> assignments to PREDISPLAY can be replaced with zle -M if you like.
With $LASTWIDGET, I can make my function work pretty well too. It only
messes up when you do a neg-argument when there are already some
digits in numeric. Apparently that only clears numeric, rather than
starting over with a new -1. Pressing alt-5 alt-- alt-5 shows arg: 0,
but pressing a key at this point inserts 5 characters. Pressing alt-5
again correctly shows arg: 55. I tried to work around it by running
zle .neg-argument twice, but it has no apparent effect. Aha, this
works:
elif [[ $LASTWIDGET = neg-argument ]]; then
zle -M - "$((NUMERIC * $KEYS[-1] ? NUMERIC * $KEYS[-1] : $KEYS[-1]))"
I also noticed ctrl-c gives this message for your function:
_digit_argument:zle:9: not enough arguments for -U
and doesn't reset numeric.
I also noticed zle -M -5 complains about 5 not being an option, zle -M
- -5 does work but I pretty much had to guess that.
Here's my whole working (as far as I can tell) function, bound both to
digit-argument and neg-argument:
function _digit_argument () {
if [[ $WIDGET = neg-argument ]]; then
if [[ -n $NUMERIC ]]; then
zle -M - ""
else
zle -M - -
fi
elif [[ $LASTWIDGET = neg-argument ]]; then
zle -M - "$((NUMERIC * $KEYS[-1] ? NUMERIC * $KEYS[-1] : $KEYS[-1]))"
else
zle -M - "$NUMERIC$KEYS[-1]"
fi
zle .$WIDGET
}
(It does not clear the display when something else is pressed).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author