Mercurial > emacs
annotate lisp/calc/calc-mode.el @ 41091:418fff19f92e
Minor clarification.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 15 Nov 2001 18:53:38 +0000 |
parents | 73f364fd8aaa |
children | ca690490ae62 |
rev | line source |
---|---|
40785 | 1 ;; Calculator for GNU Emacs, part II [calc-mode.el] |
40997
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
40785 | 3 ;; Written by Dave Gillespie, daveg@synaptics.com. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is distributed in the hope that it will be useful, | |
8 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
9 ;; accepts responsibility to anyone for the consequences of using it | |
10 ;; or for whether it serves any particular purpose or works at all, | |
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
12 ;; License for full details. | |
13 | |
14 ;; Everyone is granted permission to copy, modify and redistribute | |
15 ;; GNU Emacs, but only under the conditions described in the | |
16 ;; GNU Emacs General Public License. A copy of this license is | |
17 ;; supposed to have been given to you along with GNU Emacs so you | |
18 ;; can know your rights and responsibilities. It should be in a | |
19 ;; file named COPYING. Among other things, the copyright notice | |
20 ;; and this notice must be preserved on all copies. | |
21 | |
22 | |
23 | |
24 ;; This file is autoloaded from calc-ext.el. | |
25 (require 'calc-ext) | |
26 | |
27 (require 'calc-macs) | |
28 | |
29 (defun calc-Need-calc-mode () nil) | |
30 | |
31 | |
32 (defun calc-line-numbering (n) | |
33 (interactive "P") | |
34 (calc-wrapper | |
35 (message (if (calc-change-mode 'calc-line-numbering n t t) | |
36 "Displaying stack level numbers." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
37 "Hiding stack level numbers.")))) |
40785 | 38 |
39 (defun calc-line-breaking (n) | |
40 (interactive "P") | |
41 (calc-wrapper | |
42 (setq n (if n | |
43 (and (> (setq n (prefix-numeric-value n)) 0) | |
44 (or (< n 5) | |
45 n)) | |
46 (not calc-line-breaking))) | |
47 (if (calc-change-mode 'calc-line-breaking n t) | |
48 (if (integerp calc-line-breaking) | |
49 (message "Breaking lines longer than %d characters." n) | |
50 (message "Breaking long lines in Stack display.")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
51 (message "Not breaking long lines in Stack display.")))) |
40785 | 52 |
53 | |
54 (defun calc-left-justify (n) | |
55 (interactive "P") | |
56 (calc-wrapper | |
57 (and n (setq n (prefix-numeric-value n))) | |
58 (calc-change-mode '(calc-display-just calc-display-origin) | |
59 (list nil n) t) | |
60 (if n | |
61 (message "Displaying stack entries indented by %d." n) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
62 (message "Displaying stack entries left-justified.")))) |
40785 | 63 |
64 (defun calc-center-justify (n) | |
65 (interactive "P") | |
66 (calc-wrapper | |
67 (and n (setq n (prefix-numeric-value n))) | |
68 (calc-change-mode '(calc-display-just calc-display-origin) | |
69 (list 'center n) t) | |
70 (if n | |
71 (message "Displaying stack entries centered on column %d." n) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
72 (message "Displaying stack entries centered in window.")))) |
40785 | 73 |
74 (defun calc-right-justify (n) | |
75 (interactive "P") | |
76 (calc-wrapper | |
77 (and n (setq n (prefix-numeric-value n))) | |
78 (calc-change-mode '(calc-display-just calc-display-origin) | |
79 (list 'right n) t) | |
80 (if n | |
81 (message "Displaying stack entries right-justified to column %d." n) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
82 (message "Displaying stack entries right-justified in window.")))) |
40785 | 83 |
84 (defun calc-left-label (s) | |
85 (interactive "sLefthand label: ") | |
86 (calc-wrapper | |
87 (or (equal s "") | |
88 (setq s (concat s " "))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
89 (calc-change-mode 'calc-left-label s t))) |
40785 | 90 |
91 (defun calc-right-label (s) | |
92 (interactive "sRighthand label: ") | |
93 (calc-wrapper | |
94 (or (equal s "") | |
95 (setq s (concat " " s))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
96 (calc-change-mode 'calc-right-label s t))) |
40785 | 97 |
98 (defun calc-auto-why (n) | |
99 (interactive "P") | |
100 (calc-wrapper | |
101 (if n | |
102 (progn | |
103 (setq n (prefix-numeric-value n)) | |
104 (if (<= n 0) (setq n nil) | |
105 (if (> n 1) (setq n t)))) | |
106 (setq n (and (not (eq calc-auto-why t)) (if calc-auto-why t 1)))) | |
107 (calc-change-mode 'calc-auto-why n nil) | |
108 (cond ((null n) | |
109 (message "User must press `w' to explain unsimplified results.")) | |
110 ((eq n t) | |
111 (message "Automatically doing `w' to explain unsimplified results.")) | |
112 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
113 (message "Automatically doing `w' only for unusual messages."))))) |
40785 | 114 |
115 (defun calc-group-digits (n) | |
116 (interactive "P") | |
117 (calc-wrapper | |
118 (if n | |
119 (progn | |
120 (setq n (prefix-numeric-value n)) | |
121 (cond ((or (> n 0) (< n -1))) | |
122 ((= n -1) | |
123 (setq n nil)) | |
124 (t | |
125 (setq n calc-group-digits)))) | |
126 (setq n (not calc-group-digits))) | |
127 (calc-change-mode 'calc-group-digits n t) | |
128 (cond ((null n) | |
129 (message "Grouping is off.")) | |
130 ((integerp n) | |
131 (message "Grouping every %d digits." (math-abs n))) | |
132 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
133 (message "Grouping is on."))))) |
40785 | 134 |
135 (defun calc-group-char (ch) | |
136 (interactive "cGrouping character: ") | |
137 (calc-wrapper | |
138 (or (>= ch 32) | |
139 (error "Control characters not allowed for grouping.")) | |
140 (if (= ch ?\\) | |
141 (setq ch "\\,") | |
142 (setq ch (char-to-string ch))) | |
143 (calc-change-mode 'calc-group-char ch calc-group-digits) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
144 (message "Digit grouping character is \"%s\"." ch))) |
40785 | 145 |
146 (defun calc-point-char (ch) | |
147 (interactive "cCharacter to use as decimal point: ") | |
148 (calc-wrapper | |
149 (or (>= ch 32) | |
150 (error "Control characters not allowed as decimal point.")) | |
151 (calc-change-mode 'calc-point-char (char-to-string ch) t) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
152 (message "Decimal point character is \"%c\"." ch))) |
40785 | 153 |
154 (defun calc-normal-notation (n) | |
155 (interactive "P") | |
156 (calc-wrapper | |
157 (calc-change-mode 'calc-float-format | |
158 (let* ((val (if n (prefix-numeric-value n) 0)) | |
159 (mode (/ (+ val 5000) 10000))) | |
160 (if (or (< val -5000) (> mode 3)) | |
161 (error "Prefix out of range")) | |
162 (setq n (list (aref [float sci eng fix] mode) | |
163 (- (% (+ val 5000) 10000) 5000)))) | |
164 t) | |
165 (if (eq (nth 1 n) 0) | |
166 (message "Displaying floating-point numbers normally.") | |
167 (if (> (nth 1 n) 0) | |
168 (message | |
169 "Displaying floating-point numbers with %d significant digits." | |
170 (nth 1 n)) | |
171 (message "Displaying floating-point numbers with (precision%d)." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
172 (nth 1 n)))))) |
40785 | 173 |
174 (defun calc-fix-notation (n) | |
175 (interactive "NDigits after decimal point: ") | |
176 (calc-wrapper | |
177 (calc-change-mode 'calc-float-format | |
178 (setq n (list 'fix (if n (prefix-numeric-value n) 0))) | |
179 t) | |
180 (message "Displaying floats with %d digits after decimal." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
181 (math-abs (nth 1 n))))) |
40785 | 182 |
183 (defun calc-sci-notation (n) | |
184 (interactive "P") | |
185 (calc-wrapper | |
186 (calc-change-mode 'calc-float-format | |
187 (setq n (list 'sci (if n (prefix-numeric-value n) 0))) | |
188 t) | |
189 (if (eq (nth 1 n) 0) | |
190 (message "Displaying floats in scientific notation.") | |
191 (if (> (nth 1 n) 0) | |
192 (message "Displaying scientific notation with %d significant digits." | |
193 (nth 1 n)) | |
194 (message "Displaying scientific notation with (precision%d)." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
195 (nth 1 n)))))) |
40785 | 196 |
197 (defun calc-eng-notation (n) | |
198 (interactive "P") | |
199 (calc-wrapper | |
200 (calc-change-mode 'calc-float-format | |
201 (setq n (list 'eng (if n (prefix-numeric-value n) 0))) | |
202 t) | |
203 (if (eq (nth 1 n) 0) | |
204 (message "Displaying floats in engineering notation.") | |
205 (if (> (nth 1 n) 0) | |
206 (message "Displaying engineering notation with %d significant digits." | |
207 (nth 1 n)) | |
208 (message "Displaying engineering notation with (precision%d)." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
209 (nth 1 n)))))) |
40785 | 210 |
211 | |
212 (defun calc-truncate-stack (n &optional rel) | |
213 (interactive "P") | |
214 (calc-wrapper | |
215 (let ((oldtop calc-stack-top) | |
216 (newtop calc-stack-top)) | |
217 (calc-record-undo (list 'set 'saved-stack-top calc-stack-top)) | |
218 (let ((calc-stack-top 0) | |
219 (nn (prefix-numeric-value n))) | |
220 (setq newtop | |
221 (if n | |
222 (progn | |
223 (if rel | |
224 (setq nn (+ oldtop nn)) | |
225 (if (< nn 0) | |
226 (setq nn (+ nn (calc-stack-size))) | |
227 (setq nn (1+ nn)))) | |
228 (if (< nn 1) | |
229 1 | |
230 (if (> nn (calc-stack-size)) | |
231 (calc-stack-size) | |
232 nn))) | |
233 (max 1 (calc-locate-cursor-element (point))))) | |
234 (if (= newtop oldtop) | |
235 () | |
236 (calc-pop-stack 1 oldtop t) | |
237 (calc-push-list '(top-of-stack) newtop) | |
238 (if calc-line-numbering | |
239 (calc-refresh)))) | |
240 (calc-record-undo (list 'set 'saved-stack-top 0)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
241 (setq calc-stack-top newtop)))) |
40785 | 242 |
243 (defun calc-truncate-up (n) | |
244 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
245 (calc-truncate-stack n t)) |
40785 | 246 |
247 (defun calc-truncate-down (n) | |
248 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
249 (calc-truncate-stack (- n) t)) |
40785 | 250 |
251 (defun calc-display-raw (arg) | |
252 (interactive "P") | |
253 (calc-wrapper | |
254 (setq calc-display-raw (if calc-display-raw nil (if arg 0 t))) | |
255 (calc-do-refresh) | |
256 (if calc-display-raw | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
257 (message "Press d ' again to cancel \"raw\" display mode.")))) |
40785 | 258 |
259 | |
260 | |
261 | |
262 ;;; Mode commands. | |
263 | |
264 (defun calc-save-modes (&optional quiet) | |
265 (interactive) | |
266 (calc-wrapper | |
267 (let (pos | |
268 (vals (mapcar (function (lambda (v) (symbol-value (car v)))) | |
269 calc-mode-var-list))) | |
270 (set-buffer (find-file-noselect (substitute-in-file-name | |
271 calc-settings-file))) | |
272 (goto-char (point-min)) | |
273 (if (and (search-forward ";;; Mode settings stored by Calc" nil t) | |
274 (progn | |
275 (beginning-of-line) | |
276 (setq pos (point)) | |
277 (search-forward "\n;;; End of mode settings" nil t))) | |
278 (progn | |
279 (beginning-of-line) | |
280 (forward-line 1) | |
281 (delete-region pos (point))) | |
282 (goto-char (point-max)) | |
283 (insert "\n\n") | |
284 (forward-char -1)) | |
285 (insert ";;; Mode settings stored by Calc on " (current-time-string) "\n") | |
286 (let ((list calc-mode-var-list)) | |
287 (while list | |
288 (let* ((v (car (car list))) | |
289 (def (nth 1 (car list))) | |
290 (val (car vals))) | |
291 (or (equal val def) | |
292 (progn | |
293 (insert "(setq " (symbol-name v) " ") | |
294 (if (and (or (listp val) | |
295 (symbolp val)) | |
296 (not (memq val '(nil t)))) | |
297 (insert "'")) | |
298 (insert (prin1-to-string val) ")\n")))) | |
299 (setq list (cdr list) | |
300 vals (cdr vals)))) | |
301 (run-hooks 'calc-mode-save-hook) | |
302 (insert ";;; End of mode settings\n") | |
303 (if quiet | |
40997
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
304 ;; FIXME: why is this here? -cgw 2001.11.12 |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
305 (let ((executing-kbd-macro "")) ; what a kludge! |
40785 | 306 (save-buffer)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
307 (save-buffer))))) |
40785 | 308 |
309 (defun calc-settings-file-name (name &optional arg) | |
40997
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
310 (interactive |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
311 (list (read-file-name (format "Settings file name (normally %s): " |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
312 (abbreviate-file-name (or user-init-file |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
313 "~/.emacs")))) |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
314 current-prefix-arg)) |
40785 | 315 (calc-wrapper |
316 (setq arg (if arg (prefix-numeric-value arg) 0)) | |
317 (if (equal name "") | |
318 (message "Calc settings file is \"%s\"" calc-settings-file) | |
319 (if (< (math-abs arg) 2) | |
320 (let ((list calc-mode-var-list)) | |
321 (while list | |
322 (set (car (car list)) (nth 1 (car list))) | |
323 (setq list (cdr list))))) | |
40997
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
324 ;; FIXME: we should use ~/.calc or so in order to avoid |
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
325 ;; reexecuting ~/.emacs (it's not always idempotent) -cgw 2001.11.12 |
40785 | 326 (setq calc-settings-file name) |
327 (or (and (string-match "\\.emacs" calc-settings-file) | |
328 (> arg 0)) | |
329 (< arg 0) | |
330 (load name t) | |
40997
70241447c9ef
(calc-settings-file-name): Don't hardcode
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
331 (message "New file"))))) |
40785 | 332 |
333 (defun math-get-modes-vec () | |
334 (list 'vec | |
335 calc-internal-prec | |
336 calc-word-size | |
337 (calc-stack-size) | |
338 calc-number-radix | |
339 (+ (if (<= (nth 1 calc-float-format) 0) | |
340 (+ calc-internal-prec (nth 1 calc-float-format)) | |
341 (nth 1 calc-float-format)) | |
342 (cdr (assq (car calc-float-format) | |
343 '((float . 0) (sci . 10000) | |
344 (eng . 20000) (fix . 30000))))) | |
345 (cond ((eq calc-angle-mode 'rad) 2) | |
346 ((eq calc-angle-mode 'hms) 3) | |
347 (t 1)) | |
348 (if calc-symbolic-mode 1 0) | |
349 (if calc-prefer-frac 1 0) | |
350 (if (eq calc-complex-mode 'polar) 1 0) | |
351 (cond ((eq calc-matrix-mode 'scalar) 0) | |
352 ((eq calc-matrix-mode 'matrix) -2) | |
353 (calc-matrix-mode) | |
354 (t -1)) | |
355 (cond ((eq calc-simplify-mode 'none) -1) | |
356 ((eq calc-simplify-mode 'num) 0) | |
357 ((eq calc-simplify-mode 'binary) 2) | |
358 ((eq calc-simplify-mode 'alg) 3) | |
359 ((eq calc-simplify-mode 'ext) 4) | |
360 ((eq calc-simplify-mode 'units) 5) | |
361 (t 1)) | |
362 (cond ((eq calc-infinite-mode 1) 0) | |
363 (calc-infinite-mode 1) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
364 (t -1)))) |
40785 | 365 |
366 (defun calc-get-modes (n) | |
367 (interactive "P") | |
368 (calc-wrapper | |
369 (let ((modes (math-get-modes-vec))) | |
370 (calc-enter-result 0 "mode" | |
371 (if n | |
372 (if (and (>= (setq n (prefix-numeric-value n)) 1) | |
373 (< n (length modes))) | |
374 (nth n modes) | |
375 (error "Prefix out of range")) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
376 modes))))) |
40785 | 377 |
378 (defun calc-shift-prefix (arg) | |
379 (interactive "P") | |
380 (calc-wrapper | |
381 (setq calc-shift-prefix (if arg | |
382 (> (prefix-numeric-value arg) 0) | |
383 (not calc-shift-prefix))) | |
384 (calc-init-prefixes) | |
385 (message (if calc-shift-prefix | |
386 "Prefix keys are now case-insensitive" | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
387 "Prefix keys must be unshifted (except V, Z)")))) |
40785 | 388 |
389 (defun calc-mode-record-mode (n) | |
390 (interactive "P") | |
391 (calc-wrapper | |
392 (calc-change-mode 'calc-mode-save-mode | |
393 (cond ((null n) | |
394 (cond ((not calc-embedded-info) | |
395 (if (eq calc-mode-save-mode 'save) | |
396 'local 'save)) | |
397 ((eq calc-mode-save-mode 'local) 'edit) | |
398 ((eq calc-mode-save-mode 'edit) 'perm) | |
399 ((eq calc-mode-save-mode 'perm) 'global) | |
400 ((eq calc-mode-save-mode 'global) 'save) | |
401 ((eq calc-mode-save-mode 'save) nil) | |
402 ((eq calc-mode-save-mode nil) 'local))) | |
403 ((= (setq n (prefix-numeric-value n)) 0) nil) | |
404 ((= n 2) 'edit) | |
405 ((= n 3) 'perm) | |
406 ((= n 4) 'global) | |
407 ((= n 5) 'save) | |
408 (t 'local))) | |
409 (message (cond ((and (eq calc-mode-save-mode 'local) calc-embedded-info) | |
410 "Recording mode changes with [calc-mode: ...]") | |
411 ((eq calc-mode-save-mode 'edit) | |
412 "Recording mode changes with [calc-edit-mode: ...]") | |
413 ((eq calc-mode-save-mode 'perm) | |
414 "Recording mode changes with [calc-perm-mode: ...]") | |
415 ((eq calc-mode-save-mode 'global) | |
416 "Recording mode changes with [calc-global-mode: ...]") | |
417 ((eq calc-mode-save-mode 'save) | |
418 (format "Recording mode changes in \"%s\"." | |
419 calc-settings-file)) | |
420 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
421 "Not recording mode changes permanently."))))) |
40785 | 422 |
423 (defun calc-total-algebraic-mode (flag) | |
424 (interactive "P") | |
425 (if calc-emacs-type-19 | |
426 (error "Total algebraic mode not yet supported for Emacs 19")) | |
427 (calc-wrapper | |
428 (if (eq calc-algebraic-mode 'total) | |
429 (calc-algebraic-mode nil) | |
430 (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode) | |
431 '(total nil)) | |
432 (use-local-map calc-alg-map) | |
433 (message | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
434 "All keys begin algebraic entry; use Meta (ESC) for Calc keys.")))) |
40785 | 435 |
436 (defun calc-algebraic-mode (flag) | |
437 (interactive "P") | |
438 (calc-wrapper | |
439 (if flag | |
440 (calc-change-mode '(calc-algebraic-mode | |
441 calc-incomplete-algebraic-mode) | |
442 (list nil (not calc-incomplete-algebraic-mode))) | |
443 (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode) | |
444 (list (not calc-algebraic-mode) nil))) | |
445 (use-local-map calc-mode-map) | |
446 (message (if calc-algebraic-mode | |
447 "Numeric keys and ( and [ begin algebraic entry." | |
448 (if calc-incomplete-algebraic-mode | |
449 "Only ( and [ begin algebraic entry." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
450 "No keys except ' and $ begin algebraic entry."))))) |
40785 | 451 |
452 (defun calc-symbolic-mode (n) | |
453 (interactive "P") | |
454 (calc-wrapper | |
455 | |
456 (message (if (calc-change-mode 'calc-symbolic-mode n nil t) | |
457 "Inexact computations like sqrt(2) are deferred." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
458 "Numerical computations are always done immediately.")))) |
40785 | 459 |
460 (defun calc-infinite-mode (n) | |
461 (interactive "P") | |
462 (calc-wrapper | |
463 (if (eq n 0) | |
464 (progn | |
465 (calc-change-mode 'calc-infinite-mode 1) | |
466 (message "Computations like 1 / 0 produce \"inf\".")) | |
467 (message (if (calc-change-mode 'calc-infinite-mode n nil t) | |
468 "Computations like 1 / 0 produce \"uinf\"." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
469 "Computations like 1 / 0 are left unsimplified."))))) |
40785 | 470 |
471 (defun calc-matrix-mode (arg) | |
472 (interactive "P") | |
473 (calc-wrapper | |
474 (calc-change-mode 'calc-matrix-mode | |
475 (cond ((eq arg 0) 'scalar) | |
476 ((< (prefix-numeric-value arg) 1) | |
477 (and (< (prefix-numeric-value arg) -1) 'matrix)) | |
478 (arg (prefix-numeric-value arg)) | |
479 ((eq calc-matrix-mode 'matrix) 'scalar) | |
480 ((eq calc-matrix-mode 'scalar) nil) | |
481 (t 'matrix))) | |
482 (if (integerp calc-matrix-mode) | |
483 (message "Variables are assumed to be %dx%d matrices." | |
484 calc-matrix-mode calc-matrix-mode) | |
485 (message (if (eq calc-matrix-mode 'matrix) | |
486 "Variables are assumed to be matrices." | |
487 (if calc-matrix-mode | |
488 "Variables are assumed to be scalars (non-matrices)." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
489 "Variables are not assumed to be matrix or scalar.")))))) |
40785 | 490 |
491 (defun calc-set-simplify-mode (mode arg msg) | |
492 (calc-change-mode 'calc-simplify-mode | |
493 (if arg | |
494 (and (> (prefix-numeric-value arg) 0) | |
495 mode) | |
496 (and (not (eq calc-simplify-mode mode)) | |
497 mode))) | |
498 (message (if (eq calc-simplify-mode mode) | |
499 msg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
500 "Default simplifications enabled."))) |
40785 | 501 |
502 (defun calc-no-simplify-mode (arg) | |
503 (interactive "P") | |
504 (calc-wrapper | |
505 (calc-set-simplify-mode 'none arg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
506 "All default simplifications are disabled."))) |
40785 | 507 |
508 (defun calc-num-simplify-mode (arg) | |
509 (interactive "P") | |
510 (calc-wrapper | |
511 (calc-set-simplify-mode 'num arg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
512 "Default simplifications apply only if arguments are numeric."))) |
40785 | 513 |
514 (defun calc-default-simplify-mode (arg) | |
515 (interactive "p") | |
516 (cond ((= arg 1) | |
517 (calc-wrapper | |
518 (calc-set-simplify-mode | |
519 nil nil "Usual default simplifications are enabled."))) | |
520 ((= arg 0) (calc-num-simplify-mode 1)) | |
521 ((< arg 0) (calc-no-simplify-mode 1)) | |
522 ((= arg 2) (calc-bin-simplify-mode 1)) | |
523 ((= arg 3) (calc-alg-simplify-mode 1)) | |
524 ((= arg 4) (calc-ext-simplify-mode 1)) | |
525 ((= arg 5) (calc-units-simplify-mode 1)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
526 (t (error "Prefix argument out of range")))) |
40785 | 527 |
528 (defun calc-bin-simplify-mode (arg) | |
529 (interactive "P") | |
530 (calc-wrapper | |
531 (calc-set-simplify-mode 'binary arg | |
532 (format "Binary simplification occurs by default (word size=%d)." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
533 calc-word-size)))) |
40785 | 534 |
535 (defun calc-alg-simplify-mode (arg) | |
536 (interactive "P") | |
537 (calc-wrapper | |
538 (calc-set-simplify-mode 'alg arg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
539 "Algebraic simplification occurs by default."))) |
40785 | 540 |
541 (defun calc-ext-simplify-mode (arg) | |
542 (interactive "P") | |
543 (calc-wrapper | |
544 (calc-set-simplify-mode 'ext arg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
545 "Extended algebraic simplification occurs by default."))) |
40785 | 546 |
547 (defun calc-units-simplify-mode (arg) | |
548 (interactive "P") | |
549 (calc-wrapper | |
550 (calc-set-simplify-mode 'units arg | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
551 "Units simplification occurs by default."))) |
40785 | 552 |
553 (defun calc-auto-recompute (arg) | |
554 (interactive "P") | |
555 (calc-wrapper | |
556 (calc-change-mode 'calc-auto-recompute arg nil t) | |
557 (calc-refresh-evaltos) | |
558 (message (if calc-auto-recompute | |
559 "Automatically recomputing `=>' forms when necessary." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
560 "Not recomputing `=>' forms automatically.")))) |
40785 | 561 |
562 (defun calc-working (n) | |
563 (interactive "P") | |
564 (calc-wrapper | |
565 (cond ((consp n) | |
566 (calc-pop-push-record 0 "work" | |
567 (cond ((eq calc-display-working-message t) 1) | |
568 (calc-display-working-message 2) | |
569 (t 0)))) | |
570 ((eq n 2) (calc-change-mode 'calc-display-working-message 'lots)) | |
571 ((eq n 0) (calc-change-mode 'calc-display-working-message nil)) | |
572 ((eq n 1) (calc-change-mode 'calc-display-working-message t))) | |
573 (cond ((eq calc-display-working-message t) | |
574 (message "\"Working...\" messages enabled.")) | |
575 (calc-display-working-message | |
576 (message "Detailed \"Working...\" messages enabled.")) | |
577 (t | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
578 (message "\"Working...\" messages disabled."))))) |
40785 | 579 |
580 (defun calc-always-load-extensions () | |
581 (interactive) | |
582 (calc-wrapper | |
583 (if (setq calc-always-load-extensions (not calc-always-load-extensions)) | |
584 (message "Always loading extensions package.") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
585 (message "Loading extensions package on demand only.")))) |
40785 | 586 |
587 | |
588 (defun calc-matrix-left-justify () | |
589 (interactive) | |
590 (calc-wrapper | |
591 (calc-change-mode 'calc-matrix-just nil t) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
592 (message "Matrix elements will be left-justified in columns."))) |
40785 | 593 |
594 (defun calc-matrix-center-justify () | |
595 (interactive) | |
596 (calc-wrapper | |
597 (calc-change-mode 'calc-matrix-just 'center t) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
598 (message "Matrix elements will be centered in columns."))) |
40785 | 599 |
600 (defun calc-matrix-right-justify () | |
601 (interactive) | |
602 (calc-wrapper | |
603 (calc-change-mode 'calc-matrix-just 'right t) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
604 (message "Matrix elements will be right-justified in columns."))) |
40785 | 605 |
606 (defun calc-full-vectors (n) | |
607 (interactive "P") | |
608 (calc-wrapper | |
609 (message (if (calc-change-mode 'calc-full-vectors n t t) | |
610 "Displaying long vectors in full." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
611 "Displaying long vectors in [a, b, c, ..., z] notation.")))) |
40785 | 612 |
613 (defun calc-full-trail-vectors (n) | |
614 (interactive "P") | |
615 (calc-wrapper | |
616 (message (if (calc-change-mode 'calc-full-trail-vectors n nil t) | |
617 "Recording long vectors in full." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
618 "Recording long vectors in [a, b, c, ..., z] notation.")))) |
40785 | 619 |
620 (defun calc-break-vectors (n) | |
621 (interactive "P") | |
622 (calc-wrapper | |
623 (message (if (calc-change-mode 'calc-break-vectors n t t) | |
624 "Displaying vector elements one-per-line." | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
625 "Displaying vector elements all on one line.")))) |
40785 | 626 |
627 (defun calc-vector-commas () | |
628 (interactive) | |
629 (calc-wrapper | |
630 (if (calc-change-mode 'calc-vector-commas (if calc-vector-commas nil ",") t) | |
631 (message "Separating vector elements with \",\".") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
632 (message "Separating vector elements with spaces.")))) |
40785 | 633 |
634 (defun calc-vector-brackets () | |
635 (interactive) | |
636 (calc-wrapper | |
637 (if (calc-change-mode 'calc-vector-brackets | |
638 (if (equal calc-vector-brackets "[]") nil "[]") t) | |
639 (message "Surrounding vectors with \"[]\".") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
640 (message "Not surrounding vectors with brackets.")))) |
40785 | 641 |
642 (defun calc-vector-braces () | |
643 (interactive) | |
644 (calc-wrapper | |
645 (if (calc-change-mode 'calc-vector-brackets | |
646 (if (equal calc-vector-brackets "{}") nil "{}") t) | |
647 (message "Surrounding vectors with \"{}\".") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
648 (message "Not surrounding vectors with brackets.")))) |
40785 | 649 |
650 (defun calc-vector-parens () | |
651 (interactive) | |
652 (calc-wrapper | |
653 (if (calc-change-mode 'calc-vector-brackets | |
654 (if (equal calc-vector-brackets "()") nil "()") t) | |
655 (message "Surrounding vectors with \"()\".") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
656 (message "Not surrounding vectors with brackets.")))) |
40785 | 657 |
658 (defun calc-matrix-brackets (arg) | |
659 (interactive "sCode letters (R, O, C, P): ") | |
660 (calc-wrapper | |
661 (let ((code (append (and (string-match "[rR]" arg) '(R)) | |
662 (and (string-match "[oO]" arg) '(O)) | |
663 (and (string-match "[cC]" arg) '(C)) | |
664 (and (string-match "[pP]" arg) '(P)))) | |
665 (bad (string-match "[^rRoOcCpP ]" arg))) | |
666 (if bad | |
667 (error "Unrecognized character: %c" (aref arg bad))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
668 (calc-change-mode 'calc-matrix-brackets code t)))) |
40785 | 669 |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40997
diff
changeset
|
670 ;;; calc-mode.el ends here |