calc-mode.el 21 KB

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