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