diff options
| author | Gerd Moellmann | 2000-11-20 12:38:11 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-11-20 12:38:11 +0000 |
| commit | cbb2dddb651bfcbb4fcb91c4b2b57651ad1a7ed0 (patch) | |
| tree | df735efaf39937d6645f23084bb1d0ce3d66a961 | |
| parent | c245b580815a0c753504b93cb6a9d23ecfbb587c (diff) | |
| download | emacs-cbb2dddb651bfcbb4fcb91c4b2b57651ad1a7ed0.tar.gz emacs-cbb2dddb651bfcbb4fcb91c4b2b57651ad1a7ed0.zip | |
New version from author.
| -rw-r--r-- | lisp/calculator.el | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el index a19d84b5279..a1d7412e73a 100644 --- a/lisp/calculator.el +++ b/lisp/calculator.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Eli Barzilay <eli@www.barzilay.org> | 5 | ;; Author: Eli Barzilay <eli@www.barzilay.org> |
| 6 | ;; Keywords: tools, convenience | 6 | ;; Keywords: tools, convenience |
| 7 | ;; Time-stamp: <2000-11-07 15:04:06 eli> | 7 | ;; Time-stamp: <2000-11-19 20:59:59 eli> |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 10 | 10 | ||
| @@ -23,7 +23,7 @@ | |||
| 23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | 23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 24 | ;; MA 02111-1307, USA. | 24 | ;; MA 02111-1307, USA. |
| 25 | 25 | ||
| 26 | ;;;============================================================================ | 26 | ;;;===================================================================== |
| 27 | ;;; Commentary: | 27 | ;;; Commentary: |
| 28 | ;; | 28 | ;; |
| 29 | ;; A calculator for Emacs. | 29 | ;; A calculator for Emacs. |
| @@ -47,7 +47,7 @@ | |||
| 47 | (defmacro defgroup (&rest forms) nil) | 47 | (defmacro defgroup (&rest forms) nil) |
| 48 | (defmacro defcustom (s v d &rest r) (list 'defvar s v d)))) | 48 | (defmacro defcustom (s v d &rest r) (list 'defvar s v d)))) |
| 49 | 49 | ||
| 50 | ;;;============================================================================ | 50 | ;;;===================================================================== |
| 51 | ;;; Customization: | 51 | ;;; Customization: |
| 52 | 52 | ||
| 53 | (defgroup calculator nil | 53 | (defgroup calculator nil |
| @@ -209,10 +209,10 @@ Examples: | |||
| 209 | :type '(repeat (list string symbol sexp integer integer)) | 209 | :type '(repeat (list string symbol sexp integer integer)) |
| 210 | :group 'calculator) | 210 | :group 'calculator) |
| 211 | 211 | ||
| 212 | ;;;============================================================================ | 212 | ;;;===================================================================== |
| 213 | ;;; Code: | 213 | ;;; Code: |
| 214 | 214 | ||
| 215 | ;;;---------------------------------------------------------------------------- | 215 | ;;;--------------------------------------------------------------------- |
| 216 | ;;; Variables | 216 | ;;; Variables |
| 217 | 217 | ||
| 218 | (defvar calculator-initial-operators | 218 | (defvar calculator-initial-operators |
| @@ -346,7 +346,7 @@ Used for repeating operations in calculator-repR/L.") | |||
| 346 | (defvar calculator-restart-other-mode nil | 346 | (defvar calculator-restart-other-mode nil |
| 347 | "Used to hack restarting with the electric mode changed.") | 347 | "Used to hack restarting with the electric mode changed.") |
| 348 | 348 | ||
| 349 | ;;;---------------------------------------------------------------------------- | 349 | ;;;--------------------------------------------------------------------- |
| 350 | ;;; Key bindings | 350 | ;;; Key bindings |
| 351 | 351 | ||
| 352 | (defvar calculator-mode-map nil | 352 | (defvar calculator-mode-map nil |
| @@ -389,7 +389,8 @@ Used for repeating operations in calculator-repR/L.") | |||
| 389 | (calculator-clear-saved [?\C-c] [(control delete)]) | 389 | (calculator-clear-saved [?\C-c] [(control delete)]) |
| 390 | (calculator-save-and-quit [(control return)] | 390 | (calculator-save-and-quit [(control return)] |
| 391 | [(control kp-enter)]) | 391 | [(control kp-enter)]) |
| 392 | (calculator-paste [insert] [(shift insert)] [mouse-2]) | 392 | (calculator-paste [insert] [(shift insert)] |
| 393 | [mouse-2]) | ||
| 393 | (calculator-clear [delete] [?\C-?] [?\C-d]) | 394 | (calculator-clear [delete] [?\C-?] [?\C-d]) |
| 394 | (calculator-help [?h] [??] [f1] [help]) | 395 | (calculator-help [?h] [??] [f1] [help]) |
| 395 | (calculator-copy [(control insert)]) | 396 | (calculator-copy [(control insert)]) |
| @@ -540,7 +541,7 @@ Used for repeating operations in calculator-repR/L.") | |||
| 540 | ["Quit" calculator-quit])))) | 541 | ["Quit" calculator-quit])))) |
| 541 | (setq calculator-mode-map map))) | 542 | (setq calculator-mode-map map))) |
| 542 | 543 | ||
| 543 | ;;;---------------------------------------------------------------------------- | 544 | ;;;--------------------------------------------------------------------- |
| 544 | ;;; Startup and mode stuff | 545 | ;;; Startup and mode stuff |
| 545 | 546 | ||
| 546 | (defun calculator-mode () | 547 | (defun calculator-mode () |
| @@ -716,7 +717,7 @@ See the documentation for `calculator-mode' for more information." | |||
| 716 | (if (and calculator-restart-other-mode calculator-electric-mode) | 717 | (if (and calculator-restart-other-mode calculator-electric-mode) |
| 717 | (calculator))) | 718 | (calculator))) |
| 718 | 719 | ||
| 719 | ;;;---------------------------------------------------------------------------- | 720 | ;;;--------------------------------------------------------------------- |
| 720 | ;;; Operatos | 721 | ;;; Operatos |
| 721 | 722 | ||
| 722 | (defun calculator-op-arity (op) | 723 | (defun calculator-op-arity (op) |
| @@ -759,7 +760,7 @@ Adds MORE-OPS to `calculator-operator', called initially to handle | |||
| 759 | (setq calculator-operators | 760 | (setq calculator-operators |
| 760 | (append (nreverse added-ops) calculator-operators)))) | 761 | (append (nreverse added-ops) calculator-operators)))) |
| 761 | 762 | ||
| 762 | ;;;---------------------------------------------------------------------------- | 763 | ;;;--------------------------------------------------------------------- |
| 763 | ;;; Display stuff | 764 | ;;; Display stuff |
| 764 | 765 | ||
| 765 | (defun calculator-reset () | 766 | (defun calculator-reset () |
| @@ -1065,7 +1066,7 @@ If optional argument FORCE is non-nil, don't use the cached string." | |||
| 1065 | (goto-char (1+ (length calculator-prompt))) | 1066 | (goto-char (1+ (length calculator-prompt))) |
| 1066 | (goto-char (1- (point))))) | 1067 | (goto-char (1- (point))))) |
| 1067 | 1068 | ||
| 1068 | ;;;---------------------------------------------------------------------------- | 1069 | ;;;--------------------------------------------------------------------- |
| 1069 | ;;; Stack computations | 1070 | ;;; Stack computations |
| 1070 | 1071 | ||
| 1071 | (defun calculator-reduce-stack (prec) | 1072 | (defun calculator-reduce-stack (prec) |
| @@ -1195,7 +1196,7 @@ arguments." | |||
| 1195 | (or (fboundp 'key-press-event-p) | 1196 | (or (fboundp 'key-press-event-p) |
| 1196 | (defun key-press-event-p (&rest _) nil))) | 1197 | (defun key-press-event-p (&rest _) nil))) |
| 1197 | 1198 | ||
| 1198 | ;;;---------------------------------------------------------------------------- | 1199 | ;;;--------------------------------------------------------------------- |
| 1199 | ;;; Input interaction | 1200 | ;;; Input interaction |
| 1200 | 1201 | ||
| 1201 | (defun calculator-last-input (&optional keys) | 1202 | (defun calculator-last-input (&optional keys) |
| @@ -1356,7 +1357,7 @@ operators)." | |||
| 1356 | (calculator-digit) | 1357 | (calculator-digit) |
| 1357 | (calculator-op))) | 1358 | (calculator-op))) |
| 1358 | 1359 | ||
| 1359 | ;;;---------------------------------------------------------------------------- | 1360 | ;;;--------------------------------------------------------------------- |
| 1360 | ;;; Input/output modes (not display) | 1361 | ;;; Input/output modes (not display) |
| 1361 | 1362 | ||
| 1362 | (defun calculator-dec/deg-mode () | 1363 | (defun calculator-dec/deg-mode () |
| @@ -1408,7 +1409,7 @@ Optional string argument KEYS will force using it as the keys entered." | |||
| 1408 | calculator-char-radix)))) | 1409 | calculator-char-radix)))) |
| 1409 | (calculator-update-display t)) | 1410 | (calculator-update-display t)) |
| 1410 | 1411 | ||
| 1411 | ;;;---------------------------------------------------------------------------- | 1412 | ;;;--------------------------------------------------------------------- |
| 1412 | ;;; Saved values list | 1413 | ;;; Saved values list |
| 1413 | 1414 | ||
| 1414 | (defun calculator-save-on-list () | 1415 | (defun calculator-save-on-list () |
| @@ -1451,7 +1452,7 @@ Optional string argument KEYS will force using it as the keys entered." | |||
| 1451 | (interactive) | 1452 | (interactive) |
| 1452 | (calculator-saved-move -1)) | 1453 | (calculator-saved-move -1)) |
| 1453 | 1454 | ||
| 1454 | ;;;---------------------------------------------------------------------------- | 1455 | ;;;--------------------------------------------------------------------- |
| 1455 | ;;; Misc functions | 1456 | ;;; Misc functions |
| 1456 | 1457 | ||
| 1457 | (defun calculator-open-paren () | 1458 | (defun calculator-open-paren () |
| @@ -1544,15 +1545,15 @@ Used by `calculator-paste' and `get-register'." | |||
| 1544 | (interactive) | 1545 | (interactive) |
| 1545 | (calculator-put-value | 1546 | (calculator-put-value |
| 1546 | (let ((str (current-kill 0))) | 1547 | (let ((str (current-kill 0))) |
| 1547 | (if calculator-paste-decimals | 1548 | (and calculator-paste-decimals |
| 1548 | (progn | 1549 | (string-match "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?" |
| 1549 | (string-match "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?" str) | 1550 | str) |
| 1550 | (if (or (match-string 1 str) | 1551 | (or (match-string 1 str) |
| 1551 | (match-string 2 str) | 1552 | (match-string 2 str) |
| 1552 | (match-string 3 str)) | 1553 | (match-string 3 str)) |
| 1553 | (setq str (concat (match-string 1 str) | 1554 | (setq str (concat (match-string 1 str) |
| 1554 | (or (match-string 2 str) ".0") | 1555 | (or (match-string 2 str) ".0") |
| 1555 | (match-string 3 str)))))) | 1556 | (match-string 3 str)))) |
| 1556 | (condition-case nil (car (read-from-string str)) | 1557 | (condition-case nil (car (read-from-string str)) |
| 1557 | (error nil))))) | 1558 | (error nil))))) |
| 1558 | 1559 | ||
| @@ -1588,7 +1589,11 @@ Used by `calculator-paste' and `get-register'." | |||
| 1588 | (require 'ehelp) | 1589 | (require 'ehelp) |
| 1589 | (if calculator-electric-mode | 1590 | (if calculator-electric-mode |
| 1590 | (use-global-map calculator-saved-global-map)) | 1591 | (use-global-map calculator-saved-global-map)) |
| 1591 | (electric-describe-mode) | 1592 | (if (or (not calculator-electric-mode) |
| 1593 | ;; XEmacs has a problem with electric-describe-mode | ||
| 1594 | (string-match "XEmacs" (emacs-version))) | ||
| 1595 | (describe-mode) | ||
| 1596 | (electric-describe-mode)) | ||
| 1592 | (if calculator-electric-mode | 1597 | (if calculator-electric-mode |
| 1593 | (use-global-map g-map)) | 1598 | (use-global-map g-map)) |
| 1594 | (select-window win) ; these are for XEmacs (also below) | 1599 | (select-window win) ; these are for XEmacs (also below) |