mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-28 17:10:59 +01:00
38783: zcalc tweaks for RPN mode.
Make it more straightforward to exchange variables with stack.
This commit is contained in:
parent
a73ae70e82
commit
a7d5d239e6
3 changed files with 35 additions and 12 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
2016-07-04 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* 38783: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: tweaks for
|
||||||
|
variable and stack interation in RPN mode.
|
||||||
|
|
||||||
2016-06-29 Oliver Kiddle <opk@zsh.org>
|
2016-06-29 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
* 38770: Src/Zle/zle_keymap.c, Src/Zle/zle_vi.c, Doc/Zsh/zle.yo,
|
* 38770: Src/Zle/zle_keymap.c, Src/Zle/zle_vi.c, Doc/Zsh/zle.yo,
|
||||||
|
|
|
||||||
|
|
@ -3829,16 +3829,24 @@ the stack to be duplicated onto the stack.
|
||||||
)
|
)
|
||||||
item(tt(pop))(
|
item(tt(pop))(
|
||||||
The pseudo-function tt(pop) causes the most recent element of
|
The pseudo-function tt(pop) causes the most recent element of
|
||||||
the stack to be popped. A `tt(<)' on its own has the same effect.
|
the stack to be popped. A `tt(>)' on its own has the same effect.
|
||||||
|
)
|
||||||
|
item(tt(>)var(ident))(
|
||||||
|
The expression tt(>) followed (with no space) by a shell identifier
|
||||||
|
causes the most recent element of the stack to be popped and
|
||||||
|
assigned to the variable with that name. The variable is
|
||||||
|
local to the tt(zcalc) function.
|
||||||
)
|
)
|
||||||
item(tt(<)var(ident))(
|
item(tt(<)var(ident))(
|
||||||
The expression tt(<) followed (with no space) by a shell identifier
|
The expression tt(<) followed (with no space) by a shell identifier
|
||||||
causes the most recent element of the stack to be popped and
|
causes the value of the variable with that name to be pushed
|
||||||
assigned to the identifier.
|
onto the stack. var(ident) may be an integer, in which
|
||||||
|
case the previous result with that number (as shown before
|
||||||
|
the tt(>) in th standard standard tt(zcalc) prompt) is put on the stack.
|
||||||
)
|
)
|
||||||
item(Exchange: tt(xy))(
|
item(Exchange: tt(xy))(
|
||||||
The pseudo-function tt(xy) causes the most recent two elements of
|
The pseudo-function tt(xy) causes the most recent two elements of
|
||||||
the stack to be exchanged.
|
the stack to be exchanged. `tt(<>)' has the same effect.
|
||||||
)
|
)
|
||||||
enditem()
|
enditem()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@
|
||||||
# sequentially just as if read automatically.
|
# sequentially just as if read automatically.
|
||||||
|
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
setopt extendedglob
|
setopt extendedglob typesetsilent
|
||||||
|
|
||||||
zcalc_show_value() {
|
zcalc_show_value() {
|
||||||
if [[ -n $_base ]]; then
|
if [[ -n $_base ]]; then
|
||||||
|
|
@ -301,7 +301,7 @@ while (( _expression_mode )) ||
|
||||||
;;
|
;;
|
||||||
|
|
||||||
((:|)local([[:blank:]]##*|))
|
((:|)local([[:blank:]]##*|))
|
||||||
eval $_line
|
eval ${_line##:}
|
||||||
_line=
|
_line=
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
|
@ -333,7 +333,11 @@ while (( _expression_mode )) ||
|
||||||
_push=1
|
_push=1
|
||||||
_matched=1
|
_matched=1
|
||||||
case $_line in
|
case $_line in
|
||||||
(\=|pop|\<[[:IDENT:]]#)
|
(\<[[:IDENT:]]##)
|
||||||
|
ans=${(P)${_line##\<}}
|
||||||
|
;;
|
||||||
|
|
||||||
|
(\=|pop|\>[[:IDENT:]]#)
|
||||||
if (( ${#stack} < 1 )); then
|
if (( ${#stack} < 1 )); then
|
||||||
print -r -- "${_line}: not enough values on stack" >&2
|
print -r -- "${_line}: not enough values on stack" >&2
|
||||||
_line=
|
_line=
|
||||||
|
|
@ -343,12 +347,18 @@ while (( _expression_mode )) ||
|
||||||
(=)
|
(=)
|
||||||
ans=${stack[1]}
|
ans=${stack[1]}
|
||||||
;;
|
;;
|
||||||
(pop|\<)
|
(pop|\>)
|
||||||
_push=0
|
_push=0
|
||||||
shift stack
|
shift stack
|
||||||
;;
|
;;
|
||||||
(\<[[:IDENT:]]##)
|
(\>[[:IDENT:]]##)
|
||||||
(( ${_line##\<} = ${stack[1]} ))
|
if [[ ${_line##\>} = (_*|stack|ans|PI|E) ]]; then
|
||||||
|
print "${_line##\>}: reserved variable" >&2
|
||||||
|
_line=
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
local ${_line##\>}
|
||||||
|
(( ${_line##\>} = ${stack[1]} ))
|
||||||
_push=0
|
_push=0
|
||||||
shift stack
|
shift stack
|
||||||
;;
|
;;
|
||||||
|
|
@ -371,14 +381,14 @@ while (( _expression_mode )) ||
|
||||||
shift 2 stack
|
shift 2 stack
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(ldexp|jn|yn|scalb|xy)
|
(ldexp|jn|yn|scalb|xy|\<\>)
|
||||||
# Functions with two arguments
|
# Functions with two arguments
|
||||||
if (( ${#stack} < 2 )); then
|
if (( ${#stack} < 2 )); then
|
||||||
print -r -- "${_line}: not enough values on stack" >&2
|
print -r -- "${_line}: not enough values on stack" >&2
|
||||||
_line=
|
_line=
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if [[ $_line = xy ]]; then
|
if [[ $_line = (xy|\<\>) ]]; then
|
||||||
_tmp=${stack[1]}
|
_tmp=${stack[1]}
|
||||||
stack[1]=${stack[2]}
|
stack[1]=${stack[2]}
|
||||||
stack[2]=$_tmp
|
stack[2]=$_tmp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue