calc-mode.el 21.4 KB
Newer Older
1 2
;;; calc-mode.el --- calculator modes for Calc

3
;; Copyright (C) 1990-1993, 2001-2012 Free Software Foundation, Inc.
4 5

;; Author: David Gillespie <daveg@synaptics.com>
Jay Belanger's avatar
Jay Belanger committed
6
;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
Eli Zaretskii's avatar
Eli Zaretskii committed
7 8 9

;; This file is part of GNU Emacs.

10
;; GNU Emacs is free software: you can redistribute it and/or modify
11
;; it under the terms of the GNU General Public License as published by
12 13
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
14

Eli Zaretskii's avatar
Eli Zaretskii committed
15
;; GNU Emacs is distributed in the hope that it will be useful,
16 17 18 19 20
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
21
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Eli Zaretskii's avatar
Eli Zaretskii committed
22

23 24 25
;;; Commentary:

;;; Code:
Eli Zaretskii's avatar
Eli Zaretskii committed
26 27 28

;; This file is autoloaded from calc-ext.el.

Jay Belanger's avatar
Jay Belanger committed
29
(require 'calc-ext)
Eli Zaretskii's avatar
Eli Zaretskii committed
30 31
(require 'calc-macs)

32 33 34 35
;; Declare functions which are defined elsewhere.
(declare-function calc-embedded-save-original-modes "calc-embed" ())


Eli Zaretskii's avatar
Eli Zaretskii committed
36 37 38 39
(defun calc-line-numbering (n)
  (interactive "P")
  (calc-wrapper
   (message (if (calc-change-mode 'calc-line-numbering n t t)
40 41
		"Displaying stack level numbers"
	      "Hiding stack level numbers"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
42 43 44 45 46 47 48 49 50 51 52

(defun calc-line-breaking (n)
  (interactive "P")
  (calc-wrapper
   (setq n (if n
	       (and (> (setq n (prefix-numeric-value n)) 0)
		    (or (< n 5)
			n))
	     (not calc-line-breaking)))
   (if (calc-change-mode 'calc-line-breaking n t)
       (if (integerp calc-line-breaking)
53 54 55
	   (message "Breaking lines longer than %d characters" n)
	 (message "Breaking long lines in Stack display"))
     (message "Not breaking long lines in Stack display"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
56 57 58 59 60 61 62 63 64


(defun calc-left-justify (n)
  (interactive "P")
  (calc-wrapper
   (and n (setq n (prefix-numeric-value n)))
   (calc-change-mode '(calc-display-just calc-display-origin)
		     (list nil n) t)
   (if n
65 66
       (message "Displaying stack entries indented by %d" n)
     (message "Displaying stack entries left-justified"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
67 68 69 70 71 72 73 74

(defun calc-center-justify (n)
  (interactive "P")
  (calc-wrapper
   (and n (setq n (prefix-numeric-value n)))
   (calc-change-mode '(calc-display-just calc-display-origin)
		     (list 'center n) t)
   (if n
75 76
       (message "Displaying stack entries centered on column %d" n)
     (message "Displaying stack entries centered in window"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
77 78 79 80 81 82 83 84

(defun calc-right-justify (n)
  (interactive "P")
  (calc-wrapper
   (and n (setq n (prefix-numeric-value n)))
   (calc-change-mode '(calc-display-just calc-display-origin)
		     (list 'right n) t)
   (if n
85 86
       (message "Displaying stack entries right-justified to column %d" n)
     (message "Displaying stack entries right-justified in window"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
87 88 89 90 91 92

(defun calc-left-label (s)
  (interactive "sLefthand label: ")
  (calc-wrapper
   (or (equal s "")
       (setq s (concat s " ")))
93
   (calc-change-mode 'calc-left-label s t)))
Eli Zaretskii's avatar
Eli Zaretskii committed
94 95 96 97 98 99

(defun calc-right-label (s)
  (interactive "sRighthand label: ")
  (calc-wrapper
   (or (equal s "")
       (setq s (concat " " s)))
100
   (calc-change-mode 'calc-right-label s t)))
Eli Zaretskii's avatar
Eli Zaretskii committed
101 102 103 104 105 106 107 108 109 110 111 112

(defun calc-auto-why (n)
  (interactive "P")
  (calc-wrapper
   (if n
       (progn
	 (setq n (prefix-numeric-value n))
	 (if (<= n 0) (setq n nil)
	   (if (> n 1) (setq n t))))
     (setq n (and (not (eq calc-auto-why t)) (if calc-auto-why t 1))))
   (calc-change-mode 'calc-auto-why n nil)
   (cond ((null n)
113
	  (message "User must press `w' to explain unsimplified results"))
Eli Zaretskii's avatar
Eli Zaretskii committed
114
	 ((eq n t)
115
	  (message "Automatically doing `w' to explain unsimplified results"))
Eli Zaretskii's avatar
Eli Zaretskii committed
116
	 (t
117
	  (message "Automatically doing `w' only for unusual messages")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

(defun calc-group-digits (n)
  (interactive "P")
  (calc-wrapper
   (if n
       (progn
	 (setq n (prefix-numeric-value n))
	 (cond ((or (> n 0) (< n -1)))
	       ((= n -1)
		(setq n nil))
	       (t
		(setq n calc-group-digits))))
     (setq n (not calc-group-digits)))
   (calc-change-mode 'calc-group-digits n t)
   (cond ((null n)
133
	  (message "Grouping is off"))
Eli Zaretskii's avatar
Eli Zaretskii committed
134
	 ((integerp n)
135
	  (message "Grouping every %d digits" (math-abs n)))
Eli Zaretskii's avatar
Eli Zaretskii committed
136
	 (t
137
	  (message "Grouping is on")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
138 139 140 141 142

(defun calc-group-char (ch)
  (interactive "cGrouping character: ")
  (calc-wrapper
   (or (>= ch 32)
143
       (error "Control characters not allowed for grouping"))
Eli Zaretskii's avatar
Eli Zaretskii committed
144 145 146 147
   (if (= ch ?\\)
       (setq ch "\\,")
     (setq ch (char-to-string ch)))
   (calc-change-mode 'calc-group-char ch calc-group-digits)
148
   (message "Digit grouping character is \"%s\"" ch)))
Eli Zaretskii's avatar
Eli Zaretskii committed
149 150 151 152 153

(defun calc-point-char (ch)
  (interactive "cCharacter to use as decimal point: ")
  (calc-wrapper
   (or (>= ch 32)
154
       (error "Control characters not allowed as decimal point"))
Eli Zaretskii's avatar
Eli Zaretskii committed
155
   (calc-change-mode 'calc-point-char (char-to-string ch) t)
156
   (message "Decimal point character is \"%c\"" ch)))
Eli Zaretskii's avatar
Eli Zaretskii committed
157 158 159 160 161 162 163 164 165 166 167 168 169

(defun calc-normal-notation (n)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-float-format
		     (let* ((val (if n (prefix-numeric-value n) 0))
			    (mode (/ (+ val 5000) 10000)))
		       (if (or (< val -5000) (> mode 3))
			   (error "Prefix out of range"))
		       (setq n (list (aref [float sci eng fix] mode)
				     (- (% (+ val 5000) 10000) 5000))))
		     t)
   (if (eq (nth 1 n) 0)
170
       (message "Displaying floating-point numbers normally")
Eli Zaretskii's avatar
Eli Zaretskii committed
171 172
     (if (> (nth 1 n) 0)
	 (message
173
	  "Displaying floating-point numbers with %d significant digits"
Eli Zaretskii's avatar
Eli Zaretskii committed
174
	  (nth 1 n))
175
       (message "Displaying floating-point numbers with (precision%d)"
176
		(nth 1 n))))))
Eli Zaretskii's avatar
Eli Zaretskii committed
177 178 179 180 181 182 183

(defun calc-fix-notation (n)
  (interactive "NDigits after decimal point: ")
  (calc-wrapper
   (calc-change-mode 'calc-float-format
		     (setq n (list 'fix (if n (prefix-numeric-value n) 0)))
		     t)
184
   (message "Displaying floats with %d digits after decimal"
185
	    (math-abs (nth 1 n)))))
Eli Zaretskii's avatar
Eli Zaretskii committed
186 187 188 189 190 191 192 193

(defun calc-sci-notation (n)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-float-format
		     (setq n (list 'sci (if n (prefix-numeric-value n) 0)))
		     t)
   (if (eq (nth 1 n) 0)
194
       (message "Displaying floats in scientific notation")
Eli Zaretskii's avatar
Eli Zaretskii committed
195
     (if (> (nth 1 n) 0)
196
	 (message "Displaying scientific notation with %d significant digits"
Eli Zaretskii's avatar
Eli Zaretskii committed
197
		  (nth 1 n))
198
       (message "Displaying scientific notation with (precision%d)"
199
		(nth 1 n))))))
Eli Zaretskii's avatar
Eli Zaretskii committed
200 201 202 203 204 205 206 207

(defun calc-eng-notation (n)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-float-format
		     (setq n (list 'eng (if n (prefix-numeric-value n) 0)))
		     t)
   (if (eq (nth 1 n) 0)
208
       (message "Displaying floats in engineering notation")
Eli Zaretskii's avatar
Eli Zaretskii committed
209
     (if (> (nth 1 n) 0)
210
	 (message "Displaying engineering notation with %d significant digits"
Eli Zaretskii's avatar
Eli Zaretskii committed
211
		  (nth 1 n))
212
       (message "Displaying engineering notation with (precision%d)"
213
		(nth 1 n))))))
Eli Zaretskii's avatar
Eli Zaretskii committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244


(defun calc-truncate-stack (n &optional rel)
  (interactive "P")
  (calc-wrapper
   (let ((oldtop calc-stack-top)
	 (newtop calc-stack-top))
     (calc-record-undo (list 'set 'saved-stack-top calc-stack-top))
     (let ((calc-stack-top 0)
	   (nn (prefix-numeric-value n)))
       (setq newtop
	     (if n
		 (progn
		   (if rel
		       (setq nn (+ oldtop nn))
		     (if (< nn 0)
			 (setq nn (+ nn (calc-stack-size)))
		       (setq nn (1+ nn))))
		   (if (< nn 1)
		       1
		     (if (> nn (calc-stack-size))
			 (calc-stack-size)
		       nn)))
	       (max 1 (calc-locate-cursor-element (point)))))
       (if (= newtop oldtop)
	   ()
	 (calc-pop-stack 1 oldtop t)
	 (calc-push-list '(top-of-stack) newtop)
	 (if calc-line-numbering
	     (calc-refresh))))
     (calc-record-undo (list 'set 'saved-stack-top 0))
245
     (setq calc-stack-top newtop))))
Eli Zaretskii's avatar
Eli Zaretskii committed
246 247 248

(defun calc-truncate-up (n)
  (interactive "p")
249
  (calc-truncate-stack n t))
Eli Zaretskii's avatar
Eli Zaretskii committed
250 251 252

(defun calc-truncate-down (n)
  (interactive "p")
253
  (calc-truncate-stack (- n) t))
Eli Zaretskii's avatar
Eli Zaretskii committed
254 255 256 257 258 259 260

(defun calc-display-raw (arg)
  (interactive "P")
  (calc-wrapper
   (setq calc-display-raw (if calc-display-raw nil (if arg 0 t)))
   (calc-do-refresh)
   (if calc-display-raw
261
       (message "Press d ' again to cancel \"raw\" display mode"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
262 263 264 265 266 267




;;; Mode commands.

268
(defun calc-save-modes ()
Eli Zaretskii's avatar
Eli Zaretskii committed
269 270 271 272 273
  (interactive)
  (calc-wrapper
   (let (pos
	 (vals (mapcar (function (lambda (v) (symbol-value (car v))))
		       calc-mode-var-list)))
274 275
     (unless calc-settings-file
       (error "No `calc-settings-file' specified"))
Eli Zaretskii's avatar
Eli Zaretskii committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
     (set-buffer (find-file-noselect (substitute-in-file-name
				      calc-settings-file)))
     (goto-char (point-min))
     (if (and (search-forward ";;; Mode settings stored by Calc" nil t)
	      (progn
		(beginning-of-line)
		(setq pos (point))
		(search-forward "\n;;; End of mode settings" nil t)))
	 (progn
	   (beginning-of-line)
	   (forward-line 1)
	   (delete-region pos (point)))
       (goto-char (point-max))
       (insert "\n\n")
       (forward-char -1))
     (insert ";;; Mode settings stored by Calc on " (current-time-string) "\n")
     (let ((list calc-mode-var-list))
       (while list
	 (let* ((v (car (car list)))
		(def (nth 1 (car list)))
		(val (car vals)))
	   (or (equal val def)
	       (progn
		 (insert "(setq " (symbol-name v) " ")
		 (if (and (or (listp val)
			      (symbolp val))
			  (not (memq val '(nil t))))
		     (insert "'"))
		 (insert (prin1-to-string val) ")\n"))))
	 (setq list (cdr list)
	       vals (cdr vals))))
     (run-hooks 'calc-mode-save-hook)
     (insert ";;; End of mode settings\n")
309 310 311
     (save-buffer)
     (if calc-embedded-info
         (calc-embedded-save-original-modes)))))
Eli Zaretskii's avatar
Eli Zaretskii committed
312 313

(defun calc-settings-file-name (name &optional arg)
314 315
  (interactive
   (list (read-file-name (format "Settings file name (normally %s): "
316
				 (abbreviate-file-name calc-settings-file)))
317
	 current-prefix-arg))
Eli Zaretskii's avatar
Eli Zaretskii committed
318 319
  (calc-wrapper
   (setq arg (if arg (prefix-numeric-value arg) 0))
320
   (if (string-equal (file-name-nondirectory name) "")
Eli Zaretskii's avatar
Eli Zaretskii committed
321 322 323 324 325 326 327
       (message "Calc settings file is \"%s\"" calc-settings-file)
     (if (< (math-abs arg) 2)
	 (let ((list calc-mode-var-list))
	   (while list
	     (set (car (car list)) (nth 1 (car list)))
	     (setq list (cdr list)))))
     (setq calc-settings-file name)
328 329
     (or (and
	  calc-settings-file
330 331
          (equal user-init-file calc-settings-file)
          (> arg 0))
Eli Zaretskii's avatar
Eli Zaretskii committed
332 333
	 (< arg 0)
	 (load name t)
334
	 (message "New file")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

(defun math-get-modes-vec ()
  (list 'vec
	calc-internal-prec
	calc-word-size
	(calc-stack-size)
	calc-number-radix
	(+ (if (<= (nth 1 calc-float-format) 0)
	       (+ calc-internal-prec (nth 1 calc-float-format))
	     (nth 1 calc-float-format))
	   (cdr (assq (car calc-float-format)
		      '((float . 0) (sci . 10000)
			(eng . 20000) (fix . 30000)))))
	(cond ((eq calc-angle-mode 'rad) 2)
	      ((eq calc-angle-mode 'hms) 3)
	      (t 1))
	(if calc-symbolic-mode 1 0)
	(if calc-prefer-frac 1 0)
	(if (eq calc-complex-mode 'polar) 1 0)
	(cond ((eq calc-matrix-mode 'scalar) 0)
	      ((eq calc-matrix-mode 'matrix) -2)
356
	      ((eq calc-matrix-mode 'sqmatrix) -3)
Eli Zaretskii's avatar
Eli Zaretskii committed
357 358 359 360 361 362 363 364 365 366 367
	      (calc-matrix-mode)
	      (t -1))
	(cond ((eq calc-simplify-mode 'none) -1)
	      ((eq calc-simplify-mode 'num) 0)
	      ((eq calc-simplify-mode 'binary) 2)
	      ((eq calc-simplify-mode 'alg) 3)
	      ((eq calc-simplify-mode 'ext) 4)
	      ((eq calc-simplify-mode 'units) 5)
	      (t 1))
	(cond ((eq calc-infinite-mode 1) 0)
	      (calc-infinite-mode 1)
368
	      (t -1))))
Eli Zaretskii's avatar
Eli Zaretskii committed
369 370 371 372 373 374 375 376 377 378 379

(defun calc-get-modes (n)
  (interactive "P")
  (calc-wrapper
   (let ((modes (math-get-modes-vec)))
     (calc-enter-result 0 "mode"
			(if n
			    (if (and (>= (setq n (prefix-numeric-value n)) 1)
				     (< n (length modes)))
				(nth n modes)
			      (error "Prefix out of range"))
380
			  modes)))))
Eli Zaretskii's avatar
Eli Zaretskii committed
381 382 383 384 385 386 387 388 389 390

(defun calc-shift-prefix (arg)
  (interactive "P")
  (calc-wrapper
   (setq calc-shift-prefix (if arg
			       (> (prefix-numeric-value arg) 0)
			     (not calc-shift-prefix)))
   (calc-init-prefixes)
   (message (if calc-shift-prefix
		"Prefix keys are now case-insensitive"
391
	      "Prefix keys must be unshifted (except V, Z)"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

(defun calc-mode-record-mode (n)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-mode-save-mode
		     (cond ((null n)
			    (cond ((not calc-embedded-info)
				   (if (eq calc-mode-save-mode 'save)
				       'local 'save))
				  ((eq calc-mode-save-mode 'local)  'edit)
				  ((eq calc-mode-save-mode 'edit)   'perm)
				  ((eq calc-mode-save-mode 'perm)   'global)
				  ((eq calc-mode-save-mode 'global) 'save)
				  ((eq calc-mode-save-mode 'save)   nil)
				  ((eq calc-mode-save-mode nil)     'local)))
			   ((= (setq n (prefix-numeric-value n)) 0) nil)
			   ((= n 2) 'edit)
			   ((= n 3) 'perm)
			   ((= n 4) 'global)
			   ((= n 5) 'save)
			   (t 'local)))
413 414
   (message "%s" 
	    (cond ((and (eq calc-mode-save-mode 'local) calc-embedded-info)
Eli Zaretskii's avatar
Eli Zaretskii committed
415 416 417 418 419 420 421 422
		   "Recording mode changes with [calc-mode: ...]")
		  ((eq calc-mode-save-mode 'edit)
		   "Recording mode changes with [calc-edit-mode: ...]")
		  ((eq calc-mode-save-mode 'perm)
		   "Recording mode changes with [calc-perm-mode: ...]")
		  ((eq calc-mode-save-mode 'global)
		   "Recording mode changes with [calc-global-mode: ...]")
		  ((eq calc-mode-save-mode 'save)
423
		   (format "Recording mode changes in \"%s\""
Eli Zaretskii's avatar
Eli Zaretskii committed
424 425
			   calc-settings-file))
		  (t
426
		   "Not recording mode changes permanently")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
427 428 429 430 431 432 433 434 435 436

(defun calc-total-algebraic-mode (flag)
  (interactive "P")
  (calc-wrapper
   (if (eq calc-algebraic-mode 'total)
       (calc-algebraic-mode nil)
     (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode)
		       '(total nil))
     (use-local-map calc-alg-map)
     (message
437
      "All keys begin algebraic entry; use Meta (ESC) for Calc keys"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
438 439 440 441 442 443 444 445 446 447 448 449

(defun calc-algebraic-mode (flag)
  (interactive "P")
  (calc-wrapper
   (if flag
       (calc-change-mode '(calc-algebraic-mode
			   calc-incomplete-algebraic-mode)
			 (list nil (not calc-incomplete-algebraic-mode)))
     (calc-change-mode '(calc-algebraic-mode calc-incomplete-algebraic-mode)
		       (list (not calc-algebraic-mode) nil)))
   (use-local-map calc-mode-map)
   (message (if calc-algebraic-mode
450
		"Numeric keys and ( and [ begin algebraic entry"
Eli Zaretskii's avatar
Eli Zaretskii committed
451
	      (if calc-incomplete-algebraic-mode
452 453
		  "Only ( and [ begin algebraic entry"
		"No keys except ' and $ begin algebraic entry")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
454 455 456 457

(defun calc-symbolic-mode (n)
  (interactive "P")
  (calc-wrapper
458

Eli Zaretskii's avatar
Eli Zaretskii committed
459
   (message (if (calc-change-mode 'calc-symbolic-mode n nil t)
460 461
		"Inexact computations like sqrt(2) are deferred"
	      "Numerical computations are always done immediately"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
462 463 464 465 466 467 468

(defun calc-infinite-mode (n)
  (interactive "P")
  (calc-wrapper
   (if (eq n 0)
       (progn
	 (calc-change-mode 'calc-infinite-mode 1)
469
	 (message "Computations like 1 / 0 produce \"inf\""))
Eli Zaretskii's avatar
Eli Zaretskii committed
470
     (message (if (calc-change-mode 'calc-infinite-mode n nil t)
471 472
		  "Computations like 1 / 0 produce \"uinf\""
		"Computations like 1 / 0 are left unsimplified")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
473 474 475 476 477 478 479 480

(defun calc-matrix-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-matrix-mode
		     (cond ((eq arg 0) 'scalar)
			   ((< (prefix-numeric-value arg) 1)
			    (and (< (prefix-numeric-value arg) -1) 'matrix))
481
			   (arg 
482
                            (if (consp arg) 'sqmatrix
483
                              (prefix-numeric-value arg)))
Eli Zaretskii's avatar
Eli Zaretskii committed
484 485 486 487
			   ((eq calc-matrix-mode 'matrix) 'scalar)
			   ((eq calc-matrix-mode 'scalar) nil)
			   (t 'matrix)))
   (if (integerp calc-matrix-mode)
488
       (message "Variables are assumed to be %dx%d matrices"
Eli Zaretskii's avatar
Eli Zaretskii committed
489 490
		calc-matrix-mode calc-matrix-mode)
     (message (if (eq calc-matrix-mode 'matrix)
491
		  "Variables are assumed to be matrices"
492
                (if (eq calc-matrix-mode 'sqmatrix)
493 494 495 496
                    "Variables are assumed to be square matrices"
                  (if calc-matrix-mode
                      "Variables are assumed to be scalars (non-matrices)"
                    "Variables are not assumed to be matrix or scalar")))))))
Eli Zaretskii's avatar
Eli Zaretskii committed
497 498 499 500 501 502 503 504

(defun calc-set-simplify-mode (mode arg msg)
  (calc-change-mode 'calc-simplify-mode
		    (if arg
			(and (> (prefix-numeric-value arg) 0)
			     mode)
		      (and (not (eq calc-simplify-mode mode))
			   mode)))
505
  (message "%s" (if (eq calc-simplify-mode mode)
Eli Zaretskii's avatar
Eli Zaretskii committed
506
	       msg
507
	     "Algebraic simplification occurs by default")))
Eli Zaretskii's avatar
Eli Zaretskii committed
508 509 510 511 512

(defun calc-no-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'none arg
513
			   "Simplification is disabled")))
Eli Zaretskii's avatar
Eli Zaretskii committed
514 515 516 517 518

(defun calc-num-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'num arg
519
			   "Basic simplifications apply only if arguments are numeric")))
Eli Zaretskii's avatar
Eli Zaretskii committed
520 521

(defun calc-default-simplify-mode (arg)
522 523 524 525
  (interactive "P")
  (cond ((or (not arg) (= arg 3))
         (calc-wrapper
	  (calc-set-simplify-mode
526
	   'alg nil "Algebraic simplification occurs by default")))
527
         ((= arg 1)
Eli Zaretskii's avatar
Eli Zaretskii committed
528 529
	 (calc-wrapper
	  (calc-set-simplify-mode
530
	   nil nil "Only basic simplifications occur by default")))
Eli Zaretskii's avatar
Eli Zaretskii committed
531 532 533 534 535
	((= arg 0) (calc-num-simplify-mode 1))
	((< arg 0) (calc-no-simplify-mode 1))
	((= arg 2) (calc-bin-simplify-mode 1))
	((= arg 4) (calc-ext-simplify-mode 1))
	((= arg 5) (calc-units-simplify-mode 1))
536
	(t (error "Prefix argument out of range"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
537 538 539 540 541

(defun calc-bin-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'binary arg
542
			   (format "Binary simplification occurs by default (word size=%d)"
543
				   calc-word-size))))
Eli Zaretskii's avatar
Eli Zaretskii committed
544

545
(defun calc-basic-simplify-mode (arg)
Eli Zaretskii's avatar
Eli Zaretskii committed
546 547
  (interactive "P")
  (calc-wrapper
548
   (calc-set-simplify-mode nil arg
549 550 551 552 553 554 555
			   "Only basic simplifications occur by default")))

(defun calc-alg-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'alg arg
			   "Algebraic simplification occurs by default")))
Eli Zaretskii's avatar
Eli Zaretskii committed
556 557 558 559 560

(defun calc-ext-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'ext arg
561
			   "Extended algebraic simplification occurs by default")))
Eli Zaretskii's avatar
Eli Zaretskii committed
562 563 564 565 566

(defun calc-units-simplify-mode (arg)
  (interactive "P")
  (calc-wrapper
   (calc-set-simplify-mode 'units arg
567
			   "Units simplification occurs by default")))
Eli Zaretskii's avatar
Eli Zaretskii committed
568 569 570 571 572 573 574

(defun calc-auto-recompute (arg)
  (interactive "P")
  (calc-wrapper
   (calc-change-mode 'calc-auto-recompute arg nil t)
   (calc-refresh-evaltos)
   (message (if calc-auto-recompute
575 576
		"Automatically recomputing `=>' forms when necessary"
	      "Not recomputing `=>' forms automatically"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
577 578 579 580 581 582 583 584 585 586 587 588 589

(defun calc-working (n)
  (interactive "P")
  (calc-wrapper
   (cond ((consp n)
	  (calc-pop-push-record 0 "work"
				(cond ((eq calc-display-working-message t) 1)
				      (calc-display-working-message 2)
				      (t 0))))
	 ((eq n 2) (calc-change-mode 'calc-display-working-message 'lots))
	 ((eq n 0) (calc-change-mode 'calc-display-working-message nil))
	 ((eq n 1) (calc-change-mode 'calc-display-working-message t)))
   (cond ((eq calc-display-working-message t)
590
	  (message "\"Working...\" messages enabled"))
Eli Zaretskii's avatar
Eli Zaretskii committed
591
	 (calc-display-working-message
592
	  (message "Detailed \"Working...\" messages enabled"))
Eli Zaretskii's avatar
Eli Zaretskii committed
593
	 (t
594
	  (message "\"Working...\" messages disabled")))))
Eli Zaretskii's avatar
Eli Zaretskii committed
595 596 597 598 599

(defun calc-always-load-extensions ()
  (interactive)
  (calc-wrapper
   (if (setq calc-always-load-extensions (not calc-always-load-extensions))
600 601
       (message "Always loading extensions package")
     (message "Loading extensions package on demand only"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
602 603 604 605 606 607


(defun calc-matrix-left-justify ()
  (interactive)
  (calc-wrapper
   (calc-change-mode 'calc-matrix-just nil t)
608
   (message "Matrix elements will be left-justified in columns")))
Eli Zaretskii's avatar
Eli Zaretskii committed
609 610 611 612 613

(defun calc-matrix-center-justify ()
  (interactive)
  (calc-wrapper
   (calc-change-mode 'calc-matrix-just 'center t)
614
   (message "Matrix elements will be centered in columns")))
Eli Zaretskii's avatar
Eli Zaretskii committed
615 616 617 618 619

(defun calc-matrix-right-justify ()
  (interactive)
  (calc-wrapper
   (calc-change-mode 'calc-matrix-just 'right t)
620
   (message "Matrix elements will be right-justified in columns")))
Eli Zaretskii's avatar
Eli Zaretskii committed
621 622 623 624 625

(defun calc-full-vectors (n)
  (interactive "P")
  (calc-wrapper
   (message (if (calc-change-mode 'calc-full-vectors n t t)
626 627
		"Displaying long vectors in full"
	      "Displaying long vectors in [a, b, c, ..., z] notation"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
628 629 630 631 632

(defun calc-full-trail-vectors (n)
  (interactive "P")
  (calc-wrapper
   (message (if (calc-change-mode 'calc-full-trail-vectors n nil t)
633 634
		"Recording long vectors in full"
	      "Recording long vectors in [a, b, c, ..., z] notation"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
635 636 637 638 639

(defun calc-break-vectors (n)
  (interactive "P")
  (calc-wrapper
   (message (if (calc-change-mode 'calc-break-vectors n t t)
640 641
		"Displaying vector elements one-per-line"
	      "Displaying vector elements all on one line"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
642 643 644 645 646

(defun calc-vector-commas ()
  (interactive)
  (calc-wrapper
   (if (calc-change-mode 'calc-vector-commas (if calc-vector-commas nil ",") t)
647 648
       (message "Separating vector elements with \",\"")
     (message "Separating vector elements with spaces"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
649 650 651 652 653 654

(defun calc-vector-brackets ()
  (interactive)
  (calc-wrapper
   (if (calc-change-mode 'calc-vector-brackets
			 (if (equal calc-vector-brackets "[]") nil "[]") t)
655 656
       (message "Surrounding vectors with \"[]\"")
     (message "Not surrounding vectors with brackets"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
657 658 659 660 661 662

(defun calc-vector-braces ()
  (interactive)
  (calc-wrapper
   (if (calc-change-mode 'calc-vector-brackets
			 (if (equal calc-vector-brackets "{}") nil "{}") t)
663 664
       (message "Surrounding vectors with \"{}\"")
     (message "Not surrounding vectors with brackets"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
665 666 667 668 669 670

(defun calc-vector-parens ()
  (interactive)
  (calc-wrapper
   (if (calc-change-mode 'calc-vector-brackets
			 (if (equal calc-vector-brackets "()") nil "()") t)
671 672
       (message "Surrounding vectors with \"()\"")
     (message "Not surrounding vectors with brackets"))))
Eli Zaretskii's avatar
Eli Zaretskii committed
673 674

(defun calc-matrix-brackets (arg)
675
  (interactive "sCode letters (R, O, C): ")
Eli Zaretskii's avatar
Eli Zaretskii committed
676 677 678 679 680 681 682 683
  (calc-wrapper
   (let ((code (append (and (string-match "[rR]" arg) '(R))
		       (and (string-match "[oO]" arg) '(O))
		       (and (string-match "[cC]" arg) '(C))
		       (and (string-match "[pP]" arg) '(P))))
	 (bad (string-match "[^rRoOcCpP ]" arg)))
     (if bad
	 (error "Unrecognized character: %c" (aref arg bad)))
684
     (calc-change-mode 'calc-matrix-brackets code t))))
Eli Zaretskii's avatar
Eli Zaretskii committed
685

Jay Belanger's avatar
Jay Belanger committed
686 687
(provide 'calc-mode)

688
;;; calc-mode.el ends here