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 14545
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: the function to show a digit argument while it is being typed
- Date: Wed, 11 Nov 2009 00:14:18 -0800
- In-reply-to: <237967ef0911102217m1325dc59y8d7388e9f6f21c7b@xxxxxxxxxxxxxx>
- 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> <237967ef0911102217m1325dc59y8d7388e9f6f21c7b@xxxxxxxxxxxxxx>
On Nov 11, 7:17am, Mikael Magnusson wrote:
} Subject: Re: the function to show a digit argument while it is being typed
}
} 2009/11/11 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
} >
} > 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 $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.
I have no idea whether that should be considered a bug. One possible
interpretation is that ESC 5 ESC - should run neg-argument five times,
which would result in -1, but in practice neg-argument after either
digit-argument or neg-argument simply erases NUMERIC. At the very
least there's a documentation omission.
} elif [[ $LASTWIDGET = neg-argument ]]; then
} zle -M - "$((NUMERIC * $KEYS[-1] ? NUMERIC * $KEYS[-1] : $KEYS[-1]))"
I think [[ $LASTWIDGET = neg-argument && -n $NUMERIC ]] also works,
and may in fact be better ... then you don't need the ternary.
} 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.
That's quite interesting; it means a tty interrupt stops read-command
but doesn't set $KEYS. In fact after some quick testing the doc for
read-command is wildly inaccurate:
... If the key sequence is not bound, status 1 is
returned; typically, however, REPLY is set to undefined-key to
indicate a useless key sequence.
In fact for an unbound sequence status 0 is returned and REPLY is set
to undefined-key. The only way I can get a 1 for the status is with
the tty interrupt character, and then REPLY is set to self-insert
(which makes no sense at all). That also means zle read-command is a
way to trap interrupts, which may be yet another bug.
function digit-argument-show {
if [[ $LASTWIDGET == neg-argument && -n $NUMERIC ]]
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=""
[[ -n $KEYS ]] && zle -U $KEYS
}
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author