mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-01 21:51:40 +02:00
32527: zcalc-auto-insert key binding for use in zcalc
This commit is contained in:
parent
21d01000be
commit
47c440aa2a
4 changed files with 36 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2014-04-07 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 32527: Doc/Zsh/contrib.yo, Functions/Misc/zcalc,
|
||||
Functions/Zle/zcalc-auto-insert: zcalc-auto-insert widget
|
||||
for key binding in zcalc.
|
||||
|
||||
2014-04-06 Barton E. Schaefer <schaefer@brasslantern.com>
|
||||
|
||||
* unposted: Doc/Zsh/options.yo: fix typo in option cross-reference
|
||||
|
|
|
@ -2473,6 +2473,25 @@ The style tt(whence) is available in the context tt(:zle:$WIDGET); this
|
|||
may be set to an array to give the command and options that will be used to
|
||||
investigate the command word found. The default is tt(whence -c).
|
||||
)
|
||||
tindex(zcalc-auto-insert)
|
||||
item(tt(zcalc-auto-insert))(
|
||||
This function is useful together with the tt(zcalc) function described in
|
||||
ifzman(the section Mathematical Functions)\
|
||||
ifnzman(noderef(Mathematical Functions)).
|
||||
It should be bound to a key representing a binary operator such
|
||||
as `tt(PLUS())', `tt(-)', `tt(*)' or `tt(/)'. When running in zcalc,
|
||||
if the key occurs at the start of the line or immediately following
|
||||
an open parenthesis, the text tt("ans ") is inserted before the
|
||||
representation of the key itself. This allows easy use of the
|
||||
answer from the previous calculation in the current line. The
|
||||
text to be inserted before the symbol typed can be modified by setting
|
||||
the variable tt(ZCALC_AUTO_INSERT_PREFIX).
|
||||
|
||||
Hence, for example, typing `tt(PLUS()12)' followed by return adds 12
|
||||
to the previous result.
|
||||
|
||||
When not in zcalc, the key simply inserts the symbol itself.
|
||||
)
|
||||
enditem()
|
||||
|
||||
subsect(Utility Functions)
|
||||
|
|
|
@ -96,6 +96,9 @@
|
|||
emulate -L zsh
|
||||
setopt extendedglob
|
||||
|
||||
# For testing in ZLE functions.
|
||||
local ZCALC_ACTIVE=1
|
||||
|
||||
# TODO: make local variables that shouldn't be visible in expressions
|
||||
# begin with _.
|
||||
local line ans base defbase forms match mbegin mend psvar optlist opt arg
|
||||
|
|
8
Functions/Zle/zcalc-auto-insert
Normal file
8
Functions/Zle/zcalc-auto-insert
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Bind to a binary operator keystroke for use with zcalc
|
||||
|
||||
if [[ -n $ZCALC_ACTIVE ]]; then
|
||||
if [[ $CURSOR -eq 0 || $LBUFFER[-1] = "(" ]]; then
|
||||
LBUFFER+=${ZCALC_AUTO_INSERT_PREFIX:-"ans "}
|
||||
fi
|
||||
fi
|
||||
zle .self-insert
|
Loading…
Reference in a new issue