X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/bf77c646a591144c34d7dca5eaf6141c38393903..f0fa15c5e512e4b6fd2f7bd65ea6cfbb8f960942:/lisp/calc/calc-mode.el diff --git a/lisp/calc/calc-mode.el b/lisp/calc/calc-mode.el index ef860d8290..14cb3c746d 100644 --- a/lisp/calc/calc-mode.el +++ b/lisp/calc/calc-mode.el @@ -1,6 +1,10 @@ -;; Calculator for GNU Emacs, part II [calc-mode.el] -;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. -;; Written by Dave Gillespie, daveg@synaptics.com. +;;; calc-mode.el --- calculator modes for Calc + +;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, +;; 2005, 2006, 2007 Free Software Foundation, Inc. + +;; Author: David Gillespie +;; Maintainer: Jay Belanger ;; This file is part of GNU Emacs. @@ -19,22 +23,21 @@ ;; file named COPYING. Among other things, the copyright notice ;; and this notice must be preserved on all copies. +;;; Commentary: +;;; Code: ;; This file is autoloaded from calc-ext.el. -(require 'calc-ext) +(require 'calc-ext) (require 'calc-macs) -(defun calc-Need-calc-mode () nil) - - (defun calc-line-numbering (n) (interactive "P") (calc-wrapper (message (if (calc-change-mode 'calc-line-numbering n t t) - "Displaying stack level numbers." - "Hiding stack level numbers.")))) + "Displaying stack level numbers" + "Hiding stack level numbers")))) (defun calc-line-breaking (n) (interactive "P") @@ -46,9 +49,9 @@ (not calc-line-breaking))) (if (calc-change-mode 'calc-line-breaking n t) (if (integerp calc-line-breaking) - (message "Breaking lines longer than %d characters." n) - (message "Breaking long lines in Stack display.")) - (message "Not breaking long lines in Stack display.")))) + (message "Breaking lines longer than %d characters" n) + (message "Breaking long lines in Stack display")) + (message "Not breaking long lines in Stack display")))) (defun calc-left-justify (n) @@ -58,8 +61,8 @@ (calc-change-mode '(calc-display-just calc-display-origin) (list nil n) t) (if n - (message "Displaying stack entries indented by %d." n) - (message "Displaying stack entries left-justified.")))) + (message "Displaying stack entries indented by %d" n) + (message "Displaying stack entries left-justified")))) (defun calc-center-justify (n) (interactive "P") @@ -68,8 +71,8 @@ (calc-change-mode '(calc-display-just calc-display-origin) (list 'center n) t) (if n - (message "Displaying stack entries centered on column %d." n) - (message "Displaying stack entries centered in window.")))) + (message "Displaying stack entries centered on column %d" n) + (message "Displaying stack entries centered in window")))) (defun calc-right-justify (n) (interactive "P") @@ -78,8 +81,8 @@ (calc-change-mode '(calc-display-just calc-display-origin) (list 'right n) t) (if n - (message "Displaying stack entries right-justified to column %d." n) - (message "Displaying stack entries right-justified in window.")))) + (message "Displaying stack entries right-justified to column %d" n) + (message "Displaying stack entries right-justified in window")))) (defun calc-left-label (s) (interactive "sLefthand label: ") @@ -106,11 +109,11 @@ (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) - (message "User must press `w' to explain unsimplified results.")) + (message "User must press `w' to explain unsimplified results")) ((eq n t) - (message "Automatically doing `w' to explain unsimplified results.")) + (message "Automatically doing `w' to explain unsimplified results")) (t - (message "Automatically doing `w' only for unusual messages."))))) + (message "Automatically doing `w' only for unusual messages"))))) (defun calc-group-digits (n) (interactive "P") @@ -126,30 +129,30 @@ (setq n (not calc-group-digits))) (calc-change-mode 'calc-group-digits n t) (cond ((null n) - (message "Grouping is off.")) + (message "Grouping is off")) ((integerp n) - (message "Grouping every %d digits." (math-abs n))) + (message "Grouping every %d digits" (math-abs n))) (t - (message "Grouping is on."))))) + (message "Grouping is on"))))) (defun calc-group-char (ch) (interactive "cGrouping character: ") (calc-wrapper (or (>= ch 32) - (error "Control characters not allowed for grouping.")) + (error "Control characters not allowed for grouping")) (if (= ch ?\\) (setq ch "\\,") (setq ch (char-to-string ch))) (calc-change-mode 'calc-group-char ch calc-group-digits) - (message "Digit grouping character is \"%s\"." ch))) + (message "Digit grouping character is \"%s\"" ch))) (defun calc-point-char (ch) (interactive "cCharacter to use as decimal point: ") (calc-wrapper (or (>= ch 32) - (error "Control characters not allowed as decimal point.")) + (error "Control characters not allowed as decimal point")) (calc-change-mode 'calc-point-char (char-to-string ch) t) - (message "Decimal point character is \"%c\"." ch))) + (message "Decimal point character is \"%c\"" ch))) (defun calc-normal-notation (n) (interactive "P") @@ -163,12 +166,12 @@ (- (% (+ val 5000) 10000) 5000)))) t) (if (eq (nth 1 n) 0) - (message "Displaying floating-point numbers normally.") + (message "Displaying floating-point numbers normally") (if (> (nth 1 n) 0) (message - "Displaying floating-point numbers with %d significant digits." + "Displaying floating-point numbers with %d significant digits" (nth 1 n)) - (message "Displaying floating-point numbers with (precision%d)." + (message "Displaying floating-point numbers with (precision%d)" (nth 1 n)))))) (defun calc-fix-notation (n) @@ -177,7 +180,7 @@ (calc-change-mode 'calc-float-format (setq n (list 'fix (if n (prefix-numeric-value n) 0))) t) - (message "Displaying floats with %d digits after decimal." + (message "Displaying floats with %d digits after decimal" (math-abs (nth 1 n))))) (defun calc-sci-notation (n) @@ -187,11 +190,11 @@ (setq n (list 'sci (if n (prefix-numeric-value n) 0))) t) (if (eq (nth 1 n) 0) - (message "Displaying floats in scientific notation.") + (message "Displaying floats in scientific notation") (if (> (nth 1 n) 0) - (message "Displaying scientific notation with %d significant digits." + (message "Displaying scientific notation with %d significant digits" (nth 1 n)) - (message "Displaying scientific notation with (precision%d)." + (message "Displaying scientific notation with (precision%d)" (nth 1 n)))))) (defun calc-eng-notation (n) @@ -201,11 +204,11 @@ (setq n (list 'eng (if n (prefix-numeric-value n) 0))) t) (if (eq (nth 1 n) 0) - (message "Displaying floats in engineering notation.") + (message "Displaying floats in engineering notation") (if (> (nth 1 n) 0) - (message "Displaying engineering notation with %d significant digits." + (message "Displaying engineering notation with %d significant digits" (nth 1 n)) - (message "Displaying engineering notation with (precision%d)." + (message "Displaying engineering notation with (precision%d)" (nth 1 n)))))) @@ -254,19 +257,21 @@ (setq calc-display-raw (if calc-display-raw nil (if arg 0 t))) (calc-do-refresh) (if calc-display-raw - (message "Press d ' again to cancel \"raw\" display mode.")))) + (message "Press d ' again to cancel \"raw\" display mode")))) ;;; Mode commands. -(defun calc-save-modes (&optional quiet) +(defun calc-save-modes () (interactive) (calc-wrapper (let (pos (vals (mapcar (function (lambda (v) (symbol-value (car v)))) calc-mode-var-list))) + (unless calc-settings-file + (error "No `calc-settings-file' specified")) (set-buffer (find-file-noselect (substitute-in-file-name calc-settings-file))) (goto-char (point-min)) @@ -300,32 +305,29 @@ vals (cdr vals)))) (run-hooks 'calc-mode-save-hook) (insert ";;; End of mode settings\n") - (if quiet - ;; FIXME: why is this here? -cgw 2001.11.12 - (let ((executing-kbd-macro "")) ; what a kludge! - (save-buffer)) - (save-buffer))))) + (save-buffer) + (if calc-embedded-info + (calc-embedded-save-original-modes))))) (defun calc-settings-file-name (name &optional arg) (interactive (list (read-file-name (format "Settings file name (normally %s): " - (abbreviate-file-name (or user-init-file - "~/.emacs")))) + (abbreviate-file-name calc-settings-file))) current-prefix-arg)) (calc-wrapper (setq arg (if arg (prefix-numeric-value arg) 0)) - (if (equal name "") + (if (string-equal (file-name-nondirectory name) "") (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))))) - ;; FIXME: we should use ~/.calc or so in order to avoid - ;; reexecuting ~/.emacs (it's not always idempotent) -cgw 2001.11.12 (setq calc-settings-file name) - (or (and (string-match "\\.emacs" calc-settings-file) - (> arg 0)) + (or (and + calc-settings-file + (equal user-init-file calc-settings-file) + (> arg 0)) (< arg 0) (load name t) (message "New file"))))) @@ -350,6 +352,7 @@ (if (eq calc-complex-mode 'polar) 1 0) (cond ((eq calc-matrix-mode 'scalar) 0) ((eq calc-matrix-mode 'matrix) -2) + ((eq calc-matrix-mode 'sqmatrix) -3) (calc-matrix-mode) (t -1)) (cond ((eq calc-simplify-mode 'none) -1) @@ -406,7 +409,8 @@ ((= n 4) 'global) ((= n 5) 'save) (t 'local))) - (message (cond ((and (eq calc-mode-save-mode 'local) calc-embedded-info) + (message "%s" + (cond ((and (eq calc-mode-save-mode 'local) calc-embedded-info) "Recording mode changes with [calc-mode: ...]") ((eq calc-mode-save-mode 'edit) "Recording mode changes with [calc-edit-mode: ...]") @@ -415,15 +419,13 @@ ((eq calc-mode-save-mode 'global) "Recording mode changes with [calc-global-mode: ...]") ((eq calc-mode-save-mode 'save) - (format "Recording mode changes in \"%s\"." + (format "Recording mode changes in \"%s\"" calc-settings-file)) (t - "Not recording mode changes permanently."))))) + "Not recording mode changes permanently"))))) (defun calc-total-algebraic-mode (flag) (interactive "P") - (if calc-emacs-type-19 - (error "Total algebraic mode not yet supported for Emacs 19")) (calc-wrapper (if (eq calc-algebraic-mode 'total) (calc-algebraic-mode nil) @@ -431,7 +433,7 @@ '(total nil)) (use-local-map calc-alg-map) (message - "All keys begin algebraic entry; use Meta (ESC) for Calc keys.")))) + "All keys begin algebraic entry; use Meta (ESC) for Calc keys")))) (defun calc-algebraic-mode (flag) (interactive "P") @@ -444,18 +446,18 @@ (list (not calc-algebraic-mode) nil))) (use-local-map calc-mode-map) (message (if calc-algebraic-mode - "Numeric keys and ( and [ begin algebraic entry." + "Numeric keys and ( and [ begin algebraic entry" (if calc-incomplete-algebraic-mode - "Only ( and [ begin algebraic entry." - "No keys except ' and $ begin algebraic entry."))))) + "Only ( and [ begin algebraic entry" + "No keys except ' and $ begin algebraic entry"))))) (defun calc-symbolic-mode (n) (interactive "P") (calc-wrapper - + (message (if (calc-change-mode 'calc-symbolic-mode n nil t) - "Inexact computations like sqrt(2) are deferred." - "Numerical computations are always done immediately.")))) + "Inexact computations like sqrt(2) are deferred" + "Numerical computations are always done immediately")))) (defun calc-infinite-mode (n) (interactive "P") @@ -463,10 +465,10 @@ (if (eq n 0) (progn (calc-change-mode 'calc-infinite-mode 1) - (message "Computations like 1 / 0 produce \"inf\".")) + (message "Computations like 1 / 0 produce \"inf\"")) (message (if (calc-change-mode 'calc-infinite-mode n nil t) - "Computations like 1 / 0 produce \"uinf\"." - "Computations like 1 / 0 are left unsimplified."))))) + "Computations like 1 / 0 produce \"uinf\"" + "Computations like 1 / 0 are left unsimplified"))))) (defun calc-matrix-mode (arg) (interactive "P") @@ -475,18 +477,22 @@ (cond ((eq arg 0) 'scalar) ((< (prefix-numeric-value arg) 1) (and (< (prefix-numeric-value arg) -1) 'matrix)) - (arg (prefix-numeric-value arg)) + (arg + (if (consp arg) 'sqmatrix + (prefix-numeric-value arg))) ((eq calc-matrix-mode 'matrix) 'scalar) ((eq calc-matrix-mode 'scalar) nil) (t 'matrix))) (if (integerp calc-matrix-mode) - (message "Variables are assumed to be %dx%d matrices." + (message "Variables are assumed to be %dx%d matrices" calc-matrix-mode calc-matrix-mode) (message (if (eq calc-matrix-mode 'matrix) - "Variables are assumed to be matrices." - (if calc-matrix-mode - "Variables are assumed to be scalars (non-matrices)." - "Variables are not assumed to be matrix or scalar.")))))) + "Variables are assumed to be matrices" + (if (eq calc-matrix-mode 'sqmatrix) + "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"))))))) (defun calc-set-simplify-mode (mode arg msg) (calc-change-mode 'calc-simplify-mode @@ -497,26 +503,26 @@ mode))) (message (if (eq calc-simplify-mode mode) msg - "Default simplifications enabled."))) + "Default simplifications enabled"))) (defun calc-no-simplify-mode (arg) (interactive "P") (calc-wrapper (calc-set-simplify-mode 'none arg - "All default simplifications are disabled."))) + "All default simplifications are disabled"))) (defun calc-num-simplify-mode (arg) (interactive "P") (calc-wrapper (calc-set-simplify-mode 'num arg - "Default simplifications apply only if arguments are numeric."))) + "Default simplifications apply only if arguments are numeric"))) (defun calc-default-simplify-mode (arg) (interactive "p") (cond ((= arg 1) (calc-wrapper (calc-set-simplify-mode - nil nil "Usual default simplifications are enabled."))) + nil nil "Usual default simplifications are enabled"))) ((= arg 0) (calc-num-simplify-mode 1)) ((< arg 0) (calc-no-simplify-mode 1)) ((= arg 2) (calc-bin-simplify-mode 1)) @@ -529,26 +535,26 @@ (interactive "P") (calc-wrapper (calc-set-simplify-mode 'binary arg - (format "Binary simplification occurs by default (word size=%d)." + (format "Binary simplification occurs by default (word size=%d)" calc-word-size)))) (defun calc-alg-simplify-mode (arg) (interactive "P") (calc-wrapper (calc-set-simplify-mode 'alg arg - "Algebraic simplification occurs by default."))) + "Algebraic simplification occurs by default"))) (defun calc-ext-simplify-mode (arg) (interactive "P") (calc-wrapper (calc-set-simplify-mode 'ext arg - "Extended algebraic simplification occurs by default."))) + "Extended algebraic simplification occurs by default"))) (defun calc-units-simplify-mode (arg) (interactive "P") (calc-wrapper (calc-set-simplify-mode 'units arg - "Units simplification occurs by default."))) + "Units simplification occurs by default"))) (defun calc-auto-recompute (arg) (interactive "P") @@ -556,8 +562,8 @@ (calc-change-mode 'calc-auto-recompute arg nil t) (calc-refresh-evaltos) (message (if calc-auto-recompute - "Automatically recomputing `=>' forms when necessary." - "Not recomputing `=>' forms automatically.")))) + "Automatically recomputing `=>' forms when necessary" + "Not recomputing `=>' forms automatically")))) (defun calc-working (n) (interactive "P") @@ -571,89 +577,89 @@ ((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) - (message "\"Working...\" messages enabled.")) + (message "\"Working...\" messages enabled")) (calc-display-working-message - (message "Detailed \"Working...\" messages enabled.")) + (message "Detailed \"Working...\" messages enabled")) (t - (message "\"Working...\" messages disabled."))))) + (message "\"Working...\" messages disabled"))))) (defun calc-always-load-extensions () (interactive) (calc-wrapper (if (setq calc-always-load-extensions (not calc-always-load-extensions)) - (message "Always loading extensions package.") - (message "Loading extensions package on demand only.")))) + (message "Always loading extensions package") + (message "Loading extensions package on demand only")))) (defun calc-matrix-left-justify () (interactive) (calc-wrapper (calc-change-mode 'calc-matrix-just nil t) - (message "Matrix elements will be left-justified in columns."))) + (message "Matrix elements will be left-justified in columns"))) (defun calc-matrix-center-justify () (interactive) (calc-wrapper (calc-change-mode 'calc-matrix-just 'center t) - (message "Matrix elements will be centered in columns."))) + (message "Matrix elements will be centered in columns"))) (defun calc-matrix-right-justify () (interactive) (calc-wrapper (calc-change-mode 'calc-matrix-just 'right t) - (message "Matrix elements will be right-justified in columns."))) + (message "Matrix elements will be right-justified in columns"))) (defun calc-full-vectors (n) (interactive "P") (calc-wrapper (message (if (calc-change-mode 'calc-full-vectors n t t) - "Displaying long vectors in full." - "Displaying long vectors in [a, b, c, ..., z] notation.")))) + "Displaying long vectors in full" + "Displaying long vectors in [a, b, c, ..., z] notation")))) (defun calc-full-trail-vectors (n) (interactive "P") (calc-wrapper (message (if (calc-change-mode 'calc-full-trail-vectors n nil t) - "Recording long vectors in full." - "Recording long vectors in [a, b, c, ..., z] notation.")))) + "Recording long vectors in full" + "Recording long vectors in [a, b, c, ..., z] notation")))) (defun calc-break-vectors (n) (interactive "P") (calc-wrapper (message (if (calc-change-mode 'calc-break-vectors n t t) - "Displaying vector elements one-per-line." - "Displaying vector elements all on one line.")))) + "Displaying vector elements one-per-line" + "Displaying vector elements all on one line")))) (defun calc-vector-commas () (interactive) (calc-wrapper (if (calc-change-mode 'calc-vector-commas (if calc-vector-commas nil ",") t) - (message "Separating vector elements with \",\".") - (message "Separating vector elements with spaces.")))) + (message "Separating vector elements with \",\"") + (message "Separating vector elements with spaces")))) (defun calc-vector-brackets () (interactive) (calc-wrapper (if (calc-change-mode 'calc-vector-brackets (if (equal calc-vector-brackets "[]") nil "[]") t) - (message "Surrounding vectors with \"[]\".") - (message "Not surrounding vectors with brackets.")))) + (message "Surrounding vectors with \"[]\"") + (message "Not surrounding vectors with brackets")))) (defun calc-vector-braces () (interactive) (calc-wrapper (if (calc-change-mode 'calc-vector-brackets (if (equal calc-vector-brackets "{}") nil "{}") t) - (message "Surrounding vectors with \"{}\".") - (message "Not surrounding vectors with brackets.")))) + (message "Surrounding vectors with \"{}\"") + (message "Not surrounding vectors with brackets")))) (defun calc-vector-parens () (interactive) (calc-wrapper (if (calc-change-mode 'calc-vector-brackets (if (equal calc-vector-brackets "()") nil "()") t) - (message "Surrounding vectors with \"()\".") - (message "Not surrounding vectors with brackets.")))) + (message "Surrounding vectors with \"()\"") + (message "Not surrounding vectors with brackets")))) (defun calc-matrix-brackets (arg) (interactive "sCode letters (R, O, C, P): ") @@ -667,4 +673,7 @@ (error "Unrecognized character: %c" (aref arg bad))) (calc-change-mode 'calc-matrix-brackets code t)))) +(provide 'calc-mode) + +;;; arch-tag: ecc70eea-c712-43f2-9085-4205e58d6ddf ;;; calc-mode.el ends here