From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: zcalc-auto-insert
Date: Fri, 04 Apr 2014 15:08:57 +0100 [thread overview]
Message-ID: <20140404150857.668be2ad@pwslap01u.europe.root.pri> (raw)
I came up with this, but I'm not sure how useful it actually is.
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index c446471..9eadc35 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -2449,6 +2449,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 b796446..63f67ad 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 0000000..c9a5c88
--- /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
pws
reply other threads:[~2014-04-04 14:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140404150857.668be2ad@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).