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