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