about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/zcalc3
-rw-r--r--Functions/Zle/zcalc-auto-insert8
2 files changed, 11 insertions, 0 deletions
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