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