1 |
;; Calculator for GNU Emacs, part I |
;;; calc.el --- |
2 |
|
|
3 |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
4 |
;; Written by Dave Gillespie, daveg@synaptics.com. |
|
5 |
|
;; Author: David Gillespie <daveg@synaptics.com> |
6 |
|
;; Maintainer: Colin Walters <walters@debian.org> |
7 |
|
;; Keywords: convenience, extensions |
8 |
|
|
9 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
10 |
|
|
23 |
;; file named COPYING. Among other things, the copyright notice |
;; file named COPYING. Among other things, the copyright notice |
24 |
;; and this notice must be preserved on all copies. |
;; and this notice must be preserved on all copies. |
25 |
|
|
26 |
|
;;; Commentary: |
27 |
|
|
28 |
;;; Calc is split into many files. This file is the main entry point. |
;;; Calc is split into many files. This file is the main entry point. |
29 |
;;; This file includes autoload commands for various other basic Calc |
;;; This file includes autoload commands for various other basic Calc |
68 |
;;; "report-calc-bug", and "defmath". User-accessible variables begin |
;;; "report-calc-bug", and "defmath". User-accessible variables begin |
69 |
;;; with "var-". |
;;; with "var-". |
70 |
|
|
71 |
|
;;; Code: |
72 |
|
|
73 |
|
|
74 |
(provide 'calc) |
(provide 'calc) |
75 |
(require 'calc-macs) |
(require 'calc-macs) |
76 |
|
|
|
(defun calc-record-compilation-date () |
|
|
(calc-record-compilation-date-macro)) |
|
|
(calc-record-compilation-date) |
|
|
|
|
|
|
|
77 |
;;; The "###autoload" comment will be used by Emacs version 19 for |
;;; The "###autoload" comment will be used by Emacs version 19 for |
78 |
;;; maintaining the loaddefs.el file automatically. |
;;; maintaining the loaddefs.el file automatically. |
79 |
|
|
82 |
"*File name in which to look for the Calculator's Info documentation.") |
"*File name in which to look for the Calculator's Info documentation.") |
83 |
|
|
84 |
;;;###autoload |
;;;###autoload |
85 |
(defvar calc-settings-file "~/.emacs" |
(defvar calc-settings-file user-init-file |
86 |
"*File in which to record permanent settings; default is \"~/.emacs\".") |
"*File in which to record permanent settings; default is `user-init-file'.") |
87 |
|
|
88 |
;;;###autoload |
;;;###autoload |
89 |
(defvar calc-autoload-directory nil |
(defvar calc-autoload-directory nil |
104 |
(defvar calc-gnuplot-print-command "lp %s" |
(defvar calc-gnuplot-print-command "lp %s" |
105 |
"*Name of command for printing GNUPLOT output; %s = file name to print.") |
"*Name of command for printing GNUPLOT output; %s = file name to print.") |
106 |
|
|
|
|
|
107 |
;; Address of the author of Calc, for use by report-calc-bug. |
;; Address of the author of Calc, for use by report-calc-bug. |
108 |
(defvar calc-bug-address "daveg@synaptics.com") |
(defvar calc-bug-address "walters@debian.org") |
|
|
|
109 |
|
|
110 |
;; If T, scan keymaps to find all DEL-like keys. |
;; If T, scan keymaps to find all DEL-like keys. |
111 |
;; If NIL, only DEL itself is mapped to calc-pop. |
;; If NIL, only DEL itself is mapped to calc-pop. |
116 |
(defvar calc-extensions-loaded nil) |
(defvar calc-extensions-loaded nil) |
117 |
|
|
118 |
|
|
|
|
|
119 |
;;; IDEAS: |
;;; IDEAS: |
120 |
;;; |
;;; |
121 |
;;; Fix rewrite mechanism to do less gratuitous rearrangement of terms. |
;;; Fix rewrite mechanism to do less gratuitous rearrangement of terms. |
733 |
(mapcar (function (lambda (v) (or (boundp v) (set v nil)))) |
(mapcar (function (lambda (v) (or (boundp v) (set v nil)))) |
734 |
calc-local-var-list) |
calc-local-var-list) |
735 |
|
|
736 |
(if (boundp 'calc-mode-map) |
(unless (boundp 'calc-mode-map) |
|
nil |
|
737 |
(setq calc-mode-map (make-keymap)) |
(setq calc-mode-map (make-keymap)) |
738 |
(suppress-keymap calc-mode-map t) |
(suppress-keymap calc-mode-map t) |
739 |
(define-key calc-mode-map "+" 'calc-plus) |
(define-key calc-mode-map "+" 'calc-plus) |
915 |
calc-missing-key calc-mod calc-other-window calc-over calc-percent |
calc-missing-key calc-mod calc-other-window calc-over calc-percent |
916 |
calc-pop-above calc-power calc-roll-down calc-roll-up |
calc-pop-above calc-power calc-roll-down calc-roll-up |
917 |
calc-shift-Y-prefix-help calc-tutorial calcDigit-letter |
calc-shift-Y-prefix-help calc-tutorial calcDigit-letter |
918 |
report-calc-bug) |
report-calc-bug)))) |
|
|
|
|
)) |
|
|
) |
|
919 |
|
|
920 |
(calc-init-base) |
(calc-init-base) |
921 |
|
|
924 |
|
|
925 |
;;;###autoload |
;;;###autoload |
926 |
(defun calc-dispatch (&optional arg) |
(defun calc-dispatch (&optional arg) |
927 |
"Invoke the GNU Emacs Calculator. See calc-dispatch-help for details." |
"Invoke the GNU Emacs Calculator. See `calc-dispatch-help' for details." |
928 |
(interactive "P") |
(interactive "P") |
929 |
(sit-for echo-keystrokes) |
(sit-for echo-keystrokes) |
930 |
(condition-case err ; look for other keys bound to calc-dispatch |
(condition-case err ; look for other keys bound to calc-dispatch |
941 |
(error nil)) |
(error nil)) |
942 |
(calc-do-dispatch arg)) |
(calc-do-dispatch arg)) |
943 |
|
|
944 |
|
(defvar calc-dispatch-help nil) |
945 |
(defun calc-do-dispatch (arg) |
(defun calc-do-dispatch (arg) |
946 |
(let ((key (calc-read-key-sequence |
(let ((key (calc-read-key-sequence |
947 |
(if calc-dispatch-help |
(if calc-dispatch-help |
956 |
(or (commandp key) (calc-extensions)) |
(or (commandp key) (calc-extensions)) |
957 |
(call-interactively key)) |
(call-interactively key)) |
958 |
(beep)))) |
(beep)))) |
|
(setq calc-dispatch-help nil) |
|
959 |
|
|
960 |
(defun calc-read-key-sequence (prompt map) |
(defun calc-read-key-sequence (prompt map) |
961 |
(let ((prompt2 (format "%s " (key-description (this-command-keys)))) |
(let ((prompt2 (format "%s " (key-description (this-command-keys)))) |
1028 |
1 nil)))))) |
1 nil)))))) |
1029 |
(setq calc-stack-top (- (length calc-stack) calc-stack-top -1)) |
(setq calc-stack-top (- (length calc-stack) calc-stack-top -1)) |
1030 |
(or calc-loaded-settings-file |
(or calc-loaded-settings-file |
1031 |
|
(null calc-settings-file) |
1032 |
(string-match "\\.emacs" calc-settings-file) |
(string-match "\\.emacs" calc-settings-file) |
1033 |
(progn |
(progn |
1034 |
(setq calc-loaded-settings-file t) |
(setq calc-loaded-settings-file t) |
1057 |
(calc-set-mode-line))) |
(calc-set-mode-line))) |
1058 |
(calc-check-defines)) |
(calc-check-defines)) |
1059 |
|
|
1060 |
|
(defvar calc-check-defines 'calc-check-defines) ; suitable for run-hooks |
1061 |
(defun calc-check-defines () |
(defun calc-check-defines () |
1062 |
(if (symbol-plist 'calc-define) |
(if (symbol-plist 'calc-define) |
1063 |
(let ((plist (copy-sequence (symbol-plist 'calc-define)))) |
(let ((plist (copy-sequence (symbol-plist 'calc-define)))) |
1075 |
;; See if this has added any more calc-define properties. |
;; See if this has added any more calc-define properties. |
1076 |
(calc-check-defines)) |
(calc-check-defines)) |
1077 |
(setplist 'calc-define nil))))) |
(setplist 'calc-define nil))))) |
|
(setq calc-check-defines 'calc-check-defines) ; suitable for run-hooks |
|
1078 |
|
|
1079 |
(defun calc-trail-mode (&optional buf) |
(defun calc-trail-mode (&optional buf) |
1080 |
"Calc Trail mode. |
"Calc Trail mode. |
1101 |
(setq calc-main-buffer buf))) |
(setq calc-main-buffer buf))) |
1102 |
(if (= (buffer-size) 0) |
(if (= (buffer-size) 0) |
1103 |
(let ((buffer-read-only nil)) |
(let ((buffer-read-only nil)) |
1104 |
(insert "Emacs Calculator v" calc-version " by Dave Gillespie, " |
(insert "Emacs Calculator v" calc-version " by Dave Gillespie\n"))) |
|
"installed " calc-installed-date "\n"))) |
|
1105 |
(run-hooks 'calc-trail-mode-hook)) |
(run-hooks 'calc-trail-mode-hook)) |
1106 |
|
|
1107 |
(defun calc-create-buffer () |
(defun calc-create-buffer () |
1165 |
(and calc-display-trail |
(and calc-display-trail |
1166 |
(= (window-width) (frame-width)) |
(= (window-width) (frame-width)) |
1167 |
(calc-trail-display 1 t))) |
(calc-trail-display 1 t))) |
1168 |
(message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for help, `q' to quit.") |
(message "Welcome to the GNU Emacs Calculator! Press `?' or `h' for help, `q' to quit") |
1169 |
(run-hooks 'calc-start-hook) |
(run-hooks 'calc-start-hook) |
1170 |
(and (windowp full-display) |
(and (windowp full-display) |
1171 |
(window-point full-display) |
(window-point full-display) |
1214 |
calc-embedded-info |
calc-embedded-info |
1215 |
(eq (current-buffer) (aref calc-embedded-info 0))) |
(eq (current-buffer) (aref calc-embedded-info 0))) |
1216 |
(calc-embedded nil) |
(calc-embedded nil) |
1217 |
(or (eq major-mode 'calc-mode) |
(unless (eq major-mode 'calc-mode) |
1218 |
(calc-create-buffer)) |
(calc-create-buffer)) |
1219 |
(run-hooks 'calc-end-hook) |
(run-hooks 'calc-end-hook) |
1220 |
(setq calc-undo-list nil calc-redo-list nil) |
(setq calc-undo-list nil calc-redo-list nil) |
1221 |
(mapcar (function (lambda (v) (set-default v (symbol-value v)))) |
(mapcar (function (lambda (v) (set-default v (symbol-value v)))) |
1269 |
(calc-do-keypad t (interactive-p))) |
(calc-do-keypad t (interactive-p))) |
1270 |
|
|
1271 |
|
|
1272 |
|
(defvar calc-aborted-prefix nil) |
1273 |
|
(defvar calc-start-time nil) |
1274 |
;;; Note that modifications to this function may break calc-pass-errors. |
;;; Note that modifications to this function may break calc-pass-errors. |
1275 |
(defun calc-do (do-body &optional do-slow) |
(defun calc-do (do-body &optional do-slow) |
1276 |
(calc-check-defines) |
(calc-check-defines) |
1290 |
(and (eq calc-algebraic-mode 'total) |
(and (eq calc-algebraic-mode 'total) |
1291 |
(calc-extensions) |
(calc-extensions) |
1292 |
(use-local-map calc-alg-map)) |
(use-local-map calc-alg-map)) |
1293 |
(and do-slow calc-display-working-message |
(when (and do-slow calc-display-working-message) |
1294 |
(progn |
(message "Working...") |
1295 |
(message "Working...") |
(calc-set-command-flag 'clear-message)) |
|
(calc-set-command-flag 'clear-message))) |
|
1296 |
(funcall do-body) |
(funcall do-body) |
1297 |
(setq calc-aborted-prefix nil) |
(setq calc-aborted-prefix nil) |
1298 |
(and (memq 'renum-stack calc-command-flags) |
(when (memq 'renum-stack calc-command-flags) |
1299 |
(calc-renumber-stack)) |
(calc-renumber-stack)) |
1300 |
(and (memq 'clear-message calc-command-flags) |
(when (memq 'clear-message calc-command-flags) |
1301 |
(message ""))) |
(message ""))) |
1302 |
(error |
(error |
1303 |
(if (and (eq (car err) 'error) |
(if (and (eq (car err) 'error) |
1304 |
(stringp (nth 1 err)) |
(stringp (nth 1 err)) |
1305 |
(string-match "max-specpdl-size\\|max-lisp-eval-depth" |
(string-match "max-specpdl-size\\|max-lisp-eval-depth" |
1306 |
(nth 1 err))) |
(nth 1 err))) |
1307 |
(error "Computation got stuck or ran too long. Type `M' to increase the limit.") |
(error "Computation got stuck or ran too long. Type `M' to increase the limit") |
1308 |
(setq calc-aborted-prefix nil) |
(setq calc-aborted-prefix nil) |
1309 |
(signal (car err) (cdr err))))) |
(signal (car err) (cdr err))))) |
1310 |
(setq calc-old-aborted-prefix calc-aborted-prefix) |
(setq calc-old-aborted-prefix calc-aborted-prefix) |
1311 |
(and calc-aborted-prefix |
(when calc-aborted-prefix |
1312 |
(calc-record "<Aborted>" calc-aborted-prefix)) |
(calc-record "<Aborted>" calc-aborted-prefix)) |
1313 |
(and calc-start-time |
(and calc-start-time |
1314 |
(let* ((calc-internal-prec 12) |
(let* ((calc-internal-prec 12) |
1315 |
(calc-date-format nil) |
(calc-date-format nil) |
1334 |
(calc-select-buffer) |
(calc-select-buffer) |
1335 |
(goto-line calc-final-point-line) |
(goto-line calc-final-point-line) |
1336 |
(move-to-column calc-final-point-column)))) |
(move-to-column calc-final-point-column)))) |
1337 |
(or (memq 'keep-flags calc-command-flags) |
(unless (memq 'keep-flags calc-command-flags) |
1338 |
(save-excursion |
(save-excursion |
1339 |
(calc-select-buffer) |
(calc-select-buffer) |
1340 |
(setq calc-inverse-flag nil |
(setq calc-inverse-flag nil |
1341 |
calc-hyperbolic-flag nil |
calc-hyperbolic-flag nil |
1342 |
calc-keep-args-flag nil))) |
calc-keep-args-flag nil))) |
1343 |
(and (memq 'do-edit calc-command-flags) |
(when (memq 'do-edit calc-command-flags) |
1344 |
(switch-to-buffer (get-buffer-create "*Calc Edit*"))) |
(switch-to-buffer (get-buffer-create "*Calc Edit*"))) |
1345 |
(calc-set-mode-line) |
(calc-set-mode-line) |
1346 |
(and calc-embedded-info |
(when calc-embedded-info |
1347 |
(calc-embedded-finish-command)))) |
(calc-embedded-finish-command)))) |
1348 |
(identity nil)) ; allow a GC after timing is done |
(identity nil)) ; allow a GC after timing is done |
1349 |
|
|
|
(setq calc-aborted-prefix nil) |
|
|
(setq calc-start-time nil) |
|
1350 |
|
|
1351 |
(defun calc-set-command-flag (f) |
(defun calc-set-command-flag (f) |
1352 |
(if (not (memq f calc-command-flags)) |
(unless (memq f calc-command-flags) |
1353 |
(setq calc-command-flags (cons f calc-command-flags)))) |
(setq calc-command-flags (cons f calc-command-flags)))) |
1354 |
|
|
1355 |
(defun calc-select-buffer () |
(defun calc-select-buffer () |
1356 |
(or (eq major-mode 'calc-mode) |
(or (eq major-mode 'calc-mode) |
3324 |
( ":=" calcFunc-assign 51 50 ) |
( ":=" calcFunc-assign 51 50 ) |
3325 |
( "::" calcFunc-condition 45 46 ) |
( "::" calcFunc-condition 45 46 ) |
3326 |
( "=>" calcFunc-evalto 40 41 ) |
( "=>" calcFunc-evalto 40 41 ) |
3327 |
( "=>" calcFunc-evalto 40 -1 ) |
( "=>" calcFunc-evalto 40 -1 ))) |
3328 |
)) |
(defvar math-expr-opers math-standard-opers) |
|
(setq math-expr-opers math-standard-opers) |
|
|
|
|
3329 |
|
|
3330 |
;;;###autoload |
;;;###autoload |
3331 |
(defun calc-grab-region (top bot arg) |
(defun calc-grab-region (top bot arg) |