calculator-mode

calculator-mode is an interactive compiled Lisp function in `calculator.el'.


(calculator-mode)

A [not so] simple calculator for Emacs.

This calculator is used in the same way as other popular calculators
like xcalc or calc.exe -- but using an Emacs interface.

Expressions are entered using normal infix notation, parens are used as
normal. Unary functions are usually postfix, but some depends on the
value of `calculator-unary-style' (if the style for an operator below is
specified, then it is fixed, otherwise it depends on this variable).
`+' and `-' can be used as either binary operators or prefix unary
operators. Numbers can be entered with exponential notation using `e',
except when using a non-decimal radix mode for input (in this case `e'
will be the hexadecimal digit).

Here are the editing keys:
* `RET' `=' evaluate the current expression
* `C-insert' copy the whole current expression to the `kill-ring'
* `C-return' evaluate, save result the `kill-ring' and exit
* `insert' paste a number if the one was copied (normally)
* `delete' `C-d' clear last argument or whole expression (hit twice)
* `backspace' delete a digit or a previous expression element
* `h' `?' pop-up a quick reference help
* `ESC' `q' exit (`ESC' can be used if `calculator-bind-escape' is
non-nil, otherwise use three consecutive `ESC's)

These operators are pre-defined:
* `+' `-' `*' `/' the common binary operators
* `\' `%' integer division and reminder
* `_' `;' postfix unary negation and reciprocal
* `^' `L' binary operators for x^y and log(x) in base y
* `Q' `!' unary square root and factorial
* `S' `C' `T' unary trigonometric operators: sin, cos and tan
* `|' `#' `&' `~' bitwise operators: or, xor, and, not

The trigonometric functions can be inverted if prefixed with an `I', see
below for the way to use degrees instead of the default radians.

Two special postfix unary operators are `>' and `<': whenever a binary
operator is performed, it is remembered along with its arguments; then
`>' (`<') will apply the same operator with the same right (left)
argument.

hex/oct/bin modes can be set for input and for display separately.
Another toggle-able mode is for using degrees instead of radians for
trigonometric functions.
The keys to switch modes are (`X' is shortcut for `H'):
* `D' switch to all-decimal mode, or toggle degrees/radians
* `B' `O' `H' `X' binary/octal/hexadecimal modes for input & display
* `i' `o' followed by one of `D' `B' `O' `H' `X' (case
insensitive) sets only the input or display radix mode
The prompt indicates the current modes:
* "D=": degrees mode;
* "?=": (? is B/O/H) this is the radix for both input and output;
* "=?": (? is B/O/H) the display radix (when input is decimal);
* "??": (? is D/B/O/H) 1st char for input radix, 2nd for display.

Also, the quote key can be used to switch display modes for decimal
numbers (double-quote rotates back), and the two brace characters
("{" and "}" change display parameters that these displayers use,
if they handle such). If output is using any radix mode, then these
keys toggle digit grouping mode and the chunk size.

Values can be saved for future reference in either a list of saved
values, or in registers.

The list of saved values is useful for statistics operations on some
collected data. It is possible to navigate in this list, and if the
value shown is the current one on the list, an indication is displayed
as "[N]" if this is the last number and there are N numbers, or
"[M/N]" if the M-th value is shown.
* `SPC' evaluate the current value as usual, but also adds
the result to the list of saved values
* `l' `v' computes total / average of saved values
* `up' `C-p' browse to the previous value in the list
* `down' `C-n' browse to the next value in the list
* `delete' `C-d' remove current value from the list (if it is on it)
* `C-delete' `C-c' delete the whole list

Registers are variable-like place-holders for values:
* `s' followed by a character attach the current value to that character
* `g' followed by a character fetches the attached value

There are many variables that can be used to customize the calculator.
Some interesting customization variables are:
* `calculator-electric-mode' use only the echo-area electrically.
* `calculator-unary-style' set most unary ops to pre/postfix style.
* `calculator-user-registers' to define user-preset registers.
* `calculator-user-operators' to add user-defined operators.
See the documentation for these variables, and "calculator.el" for
more information.

key binding
--- -------

C-c calculator-clear-saved
C-d calculator-clear
C-g calculator-quit
C-h calculator-backspace
C-j calculator-enter
RET calculator-enter
C-n calculator-saved-down
C-p calculator-saved-up
C-y calculator-paste
ESC Prefix Command
SPC calculator-save-on-list
" calculator-rotate-displayer-back
' calculator-rotate-displayer
+ calculator-op-or-exp
- calculator-op-or-exp
. calculator-decimal
0 .. 9 calculator-digit
? calculator-help
B calculator-radix-mode
D calculator-dec/deg-mode
H calculator-radix-mode
O calculator-radix-mode
X calculator-radix-mode
[ calculator-open-paren
] calculator-close-paren
a .. d calculator-digit
e calculator-exp
f calculator-digit
g calculator-get-register
h calculator-help
i Prefix Command
o Prefix Command
q calculator-quit
s calculator-set-register
{ calculator-displayer-prev
} calculator-displayer-next
DEL calculator-clear
<C-delete> calculator-clear-saved
<C-insert> calculator-copy
<C-kp-enter> calculator-save-and-quit
<C-return> calculator-save-and-quit
<S-insert> calculator-paste
<backspace> calculator-backspace
<copy> calculator-copy
<delete> calculator-clear
<down> calculator-saved-down
<enter> calculator-enter
<f1> calculator-help
<help> calculator-help
<insert> calculator-paste
<kp-0> calculator-digit
<kp-1> calculator-digit
<kp-2> calculator-digit
<kp-3> calculator-digit
<kp-4> calculator-digit
<kp-5> calculator-digit
<kp-6> calculator-digit
<kp-7> calculator-digit
<kp-8> calculator-digit
<kp-9> calculator-digit
<kp-add> calculator-op-or-exp
<kp-decimal> calculator-decimal
<kp-divide> calculator-op
<kp-enter> calculator-enter
<kp-multiply> calculator-op
<kp-subtract> calculator-op-or-exp
<linefeed> calculator-enter
<mouse-2> calculator-paste
<paste> calculator-paste
<remap> Prefix Command
<return> calculator-enter
<space> calculator-save-on-list
<up> calculator-saved-up

ESC ESC Prefix Command

M-ESC ESC calculator-quit

o B calculator-radix-output-mode
o D calculator-radix-output-mode
o H calculator-radix-output-mode
o O calculator-radix-output-mode
o X calculator-radix-output-mode
o b calculator-radix-output-mode
o d calculator-radix-output-mode
o h calculator-radix-output-mode
o o calculator-radix-output-mode
o x calculator-radix-output-mode

i B calculator-radix-input-mode
i D calculator-radix-input-mode
i H calculator-radix-input-mode
i O calculator-radix-input-mode
i X calculator-radix-input-mode
i b calculator-radix-input-mode
i d calculator-radix-input-mode
i h calculator-radix-input-mode
i o calculator-radix-input-mode
i x calculator-radix-input-mode



This mode runs the hook `calculator-mode-hook', as the final step
during initialization.