From 22b8fd6da931657ec930ba2625179c704de3e830 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 23 Jan 2014 10:32:59 +0000 Subject: 32299: add use of underscores on arithmetic output for spacing --- Functions/Misc/zcalc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Functions/Misc/zcalc') diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 1f3392d92..6a56d4782 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -196,7 +196,7 @@ while (( expression_mode )) || # special cases # Set default base if `[#16]' or `[##16]' etc. on its own. # Unset it if `[#]' or `[##]'. - if [[ $line = (#b)[[:blank:]]#('[#'(\#|)(<->|)']')[[:blank:]]#(*) ]]; then + if [[ $line = (#b)[[:blank:]]#('[#'(\#|)((<->|)(|_|_<->))']')[[:blank:]]#(*) ]]; then if [[ -z $match[4] ]]; then if [[ -z $match[3] ]]; then defbase= -- cgit v1.2.3 From 965d7305e57b9b1a009af71368fcbf6da4e756a8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 1 Mar 2014 21:27:47 +0000 Subject: 32453: fix zcalc default base handling --- ChangeLog | 2 ++ Functions/Misc/zcalc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Functions/Misc/zcalc') diff --git a/ChangeLog b/ChangeLog index 7344e7a16..1cd1431d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2014-03-01 Peter Stephenson + * 32453: Functions/Misc/zcalc: fix default base handling. + * Manuel Presnitz: 32412 modified c.f. 32415: Completion/Zsh/Type/_globquals, Doc/Zsh/expn.yo, Src/glob.c, Src/zsh.h: gigabyte and terabyte units for glob qualifiers. diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 6a56d4782..b79644687 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -197,7 +197,7 @@ while (( expression_mode )) || # Set default base if `[#16]' or `[##16]' etc. on its own. # Unset it if `[#]' or `[##]'. if [[ $line = (#b)[[:blank:]]#('[#'(\#|)((<->|)(|_|_<->))']')[[:blank:]]#(*) ]]; then - if [[ -z $match[4] ]]; then + if [[ -z $match[6] ]]; then if [[ -z $match[3] ]]; then defbase= else -- cgit v1.2.3 From 47c440aa2a141b1af60c2df192ff257b902dd177 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 7 Apr 2014 09:58:30 +0100 Subject: 32527: zcalc-auto-insert key binding for use in zcalc --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 19 +++++++++++++++++++ Functions/Misc/zcalc | 3 +++ Functions/Zle/zcalc-auto-insert | 8 ++++++++ 4 files changed, 36 insertions(+) create mode 100644 Functions/Zle/zcalc-auto-insert (limited to 'Functions/Misc/zcalc') diff --git a/ChangeLog b/ChangeLog index 0488ea158..f91b414f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-04-07 Peter Stephenson + + * 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 * unposted: Doc/Zsh/options.yo: fix typo in option cross-reference diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index a4000fd12..9f59f231d 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -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) diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index b79644687..63f67adb0 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -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 diff --git a/Functions/Zle/zcalc-auto-insert b/Functions/Zle/zcalc-auto-insert new file mode 100644 index 000000000..c9a5c8867 --- /dev/null +++ b/Functions/Zle/zcalc-auto-insert @@ -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 -- cgit v1.2.3