;;; calc-ext.el --- various extension functions for Calc
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
+;; 2005 Free Software Foundation, Inc.
;; Author: David Gillespie <daveg@synaptics.com>
;; Maintainer: Jay Belanger <belanger@truman.edu>
(defvar math-comp-sel-cpos nil)
(defvar math-compose-hash-args nil)
+(defvar calc-alg-map)
+(defvar calc-alg-esc-map)
+
;;; The following was made a function so that it could be byte-compiled.
(defun calc-init-extensions ()
(define-key calc-mode-map "dO" 'calc-flat-language)
(define-key calc-mode-map "dP" 'calc-pascal-language)
(define-key calc-mode-map "dT" 'calc-tex-language)
+ (define-key calc-mode-map "dL" 'calc-latex-language)
(define-key calc-mode-map "dU" 'calc-unformatted-language)
(define-key calc-mode-map "dW" 'calc-maple-language)
(define-key calc-mode-map "d[" 'calc-truncate-up)
(define-key calc-mode-map "m?" 'calc-m-prefix-help)
(define-key calc-mode-map "ma" 'calc-algebraic-mode)
(define-key calc-mode-map "md" 'calc-degrees-mode)
+ (define-key calc-mode-map "me" 'calc-embedded-preserve-modes)
(define-key calc-mode-map "mf" 'calc-frac-mode)
(define-key calc-mode-map "mg" 'calc-get-modes)
(define-key calc-mode-map "mh" 'calc-hms-mode)
(define-key calc-mode-map "sd" 'calc-declare-variable)
(define-key calc-mode-map "se" 'calc-edit-variable)
(define-key calc-mode-map "si" 'calc-insert-variables)
+ (define-key calc-mode-map "sk" 'calc-copy-special-constant)
(define-key calc-mode-map "sl" 'calc-let)
(define-key calc-mode-map "sm" 'calc-store-map)
(define-key calc-mode-map "sn" 'calc-store-neg)
("calc-embed" calc-do-embedded
calc-do-embedded-activate calc-embedded-evaluate-expr
-calc-embedded-modes-change calc-embedded-var-change)
+calc-embedded-modes-change calc-embedded-var-change
+calc-embedded-preserve-modes)
("calc-fin" calc-to-percentage calcFunc-ddb
calcFunc-fv calcFunc-fvb calcFunc-fvl calcFunc-irr calcFunc-irrb
("calc-math" calcFunc-alog calcFunc-arccos
calcFunc-arccosh calcFunc-arcsin calcFunc-arcsincos calcFunc-arcsinh
-calcFunc-arctan calcFunc-arctan2 calcFunc-arctanh calcFunc-cos
-calcFunc-cosh calcFunc-deg calcFunc-exp calcFunc-exp10 calcFunc-expm1
+calcFunc-arctan calcFunc-arctan2 calcFunc-arctanh calcFunc-csc
+calcFunc-csch calcFunc-cos calcFunc-cosh calcFunc-cot calcFunc-coth
+calcFunc-deg calcFunc-exp calcFunc-exp10 calcFunc-expm1
calcFunc-hypot calcFunc-ilog calcFunc-isqrt calcFunc-ln calcFunc-lnp1
-calcFunc-log calcFunc-log10 calcFunc-nroot calcFunc-rad calcFunc-sin
+calcFunc-log calcFunc-log10 calcFunc-nroot calcFunc-rad calcFunc-sec
+calcFunc-sech calcFunc-sin
calcFunc-sincos calcFunc-sinh calcFunc-sqr calcFunc-sqrt calcFunc-tan
calcFunc-tanh math-arccos-raw math-arcsin-raw math-arctan-raw
-math-arctan2-raw math-cos-raw math-exp-minus-1-raw math-exp-raw
+math-arctan2-raw math-cos-raw math-cot-raw math-csc-raw
+math-exp-minus-1-raw math-exp-raw
math-from-radians math-from-radians-2 math-hypot math-infinite-dir
math-isqrt-small math-ln-raw math-nearly-equal math-nearly-equal-float
math-nearly-zerop math-nearly-zerop-float math-nth-root
("calc-lang" calc-big-language calc-c-language calc-eqn-language
calc-flat-language calc-fortran-language calc-maple-language
calc-mathematica-language calc-normal-language calc-pascal-language
-calc-tex-language calc-unformatted-language)
+calc-tex-language calc-latex-language calc-unformatted-language)
("calc-map" calc-accumulate calc-apply calc-inner-product calc-map
calc-map-equation calc-map-stack calc-outer-product calc-reduce)
("calc-math" calc-arccos calc-arccosh calc-arcsin calc-arcsinh
calc-arctan calc-arctan2 calc-arctanh calc-conj calc-cos calc-cosh
+calc-cot calc-coth calc-csc calc-csch
calc-degrees-mode calc-exp calc-expm1 calc-hypot calc-ilog
calc-imaginary calc-isqrt calc-ln calc-lnp1 calc-log calc-log10
-calc-pi calc-radians-mode calc-sin calc-sincos calc-sinh calc-sqrt
+calc-pi calc-radians-mode calc-sec calc-sech
+calc-sin calc-sincos calc-sinh calc-sqrt
calc-tan calc-tanh calc-to-degrees calc-to-radians)
("calc-mode" calc-alg-simplify-mode calc-algebraic-mode
calc-vector-pop-variance calc-vector-product calc-vector-sdev
calc-vector-sum calc-vector-variance)
- ("calc-store" calc-assign calc-copy-variable calc-declare-variable
+ ("calc-store" calc-assign calc-copy-special-constant
+calc-copy-variable calc-declare-variable
calc-edit-AlgSimpRules calc-edit-Decls calc-edit-EvalRules
calc-edit-ExtSimpRules calc-edit-FitRules calc-edit-GenCount
calc-edit-Holidays calc-edit-IntegLimit calc-edit-LineStyles
(math-normalize val)))))
+(defvar calc-help-map nil)
-(if (boundp 'calc-help-map)
+(if calc-help-map
nil
(setq calc-help-map (make-keymap))
(define-key calc-help-map "b" 'calc-describe-bindings)
(defun calc-reset (arg)
(interactive "P")
- (save-excursion
- (or (eq major-mode 'calc-mode)
- (calc-create-buffer))
- (if calc-embedded-info
- (calc-embedded nil))
- (or arg
- (setq calc-stack nil))
- (setq calc-undo-list nil
- calc-redo-list nil)
- (let (calc-stack calc-user-parse-tables calc-standard-date-formats
- calc-invocation-macro)
- (mapcar (function (lambda (v) (set v nil))) calc-local-var-list)
- (mapcar (function (lambda (v) (set (car v) (nth 1 v))))
- calc-mode-var-list))
- (calc-set-language nil nil t)
- (calc-mode)
- (calc-flush-caches t)
- (run-hooks 'calc-reset-hook))
- (calc-wrapper
- (let ((win (get-buffer-window (current-buffer))))
- (calc-realign 0)
- (if win
- (let ((height (- (window-height win) 2)))
- (set-window-point win (point))
- (or (= height calc-window-height)
- (let ((swin (selected-window)))
- (select-window win)
- (enlarge-window (- calc-window-height height))
- (select-window swin)))))))
- (message "(Calculator reset)"))
+ (setq arg (if arg (prefix-numeric-value arg) nil))
+ (cond
+ ((and
+ calc-embedded-info
+ (equal (aref calc-embedded-info 0) (current-buffer))
+ (<= (point) (aref calc-embedded-info 5))
+ (>= (point) (aref calc-embedded-info 4)))
+ (let ((cbuf (aref calc-embedded-info 1))
+ (calc-embedded-quiet t))
+ (save-window-excursion
+ (calc-embedded nil)
+ (set-buffer cbuf)
+ (calc-reset arg))
+ (calc-embedded nil)))
+ ((eq major-mode 'calc-mode)
+ (save-excursion
+ (unless (and arg (> (abs arg) 0))
+ (setq calc-stack nil))
+ (setq calc-undo-list nil
+ calc-redo-list nil)
+ (let (calc-stack calc-user-parse-tables calc-standard-date-formats
+ calc-invocation-macro)
+ (mapcar (function (lambda (v) (set v nil))) calc-local-var-list)
+ (if (and arg (<= arg 0))
+ (calc-mode-var-list-restore-default-values)
+ (calc-mode-var-list-restore-saved-values)))
+ (calc-set-language nil nil t)
+ (calc-mode)
+ (calc-flush-caches t)
+ (run-hooks 'calc-reset-hook))
+ (calc-wrapper
+ (let ((win (get-buffer-window (current-buffer))))
+ (calc-realign 0)
+ ;; Adjust the window height if the window is visible, but doesn't
+ ;; take up the whole height of the frame.
+ (if (and
+ win
+ (< (window-height win) (1- (frame-height))))
+ (let ((height (- (window-height win) 2)))
+ (set-window-point win (point))
+ (or (= height calc-window-height)
+ (let ((swin (selected-window)))
+ (select-window win)
+ (enlarge-window (- calc-window-height height))
+ (select-window swin)))))))
+ (message "(Calculator reset)"))
+ (t
+ (message "(Not inside a Calc buffer)"))))
;; What a pain; scroll-left behaves differently when called non-interactively.
(defun calc-scroll-left (n)
(defun calc-inverse (&optional n)
(interactive "P")
- (let* ((hyp-flag (if (eq major-mode 'calc-keypad-mode)
+ (let* ((hyp-flag (if (or
+ (eq major-mode 'calc-keypad-mode)
+ (eq major-mode 'calc-trail-mode))
(with-current-buffer calc-main-buffer
calc-hyperbolic-flag)
calc-hyperbolic-flag))
(defun calc-fancy-prefix-other-key (arg)
(interactive "P")
- (if (or (not (integerp last-command-char))
- (and (>= last-command-char 0) (< last-command-char ? )
- (not (eq last-command-char meta-prefix-char))))
+ (if (and
+ (not (eq last-command-char 'tab))
+ (not (eq last-command-char 'M-tab))
+ (or (not (integerp last-command-char))
+ (and (>= last-command-char 0) (< last-command-char ? )
+ (not (eq last-command-char meta-prefix-char)))))
(calc-wrapper)) ; clear flags if not a Calc command.
+ (setq prefix-arg arg)
(calc-unread-command)
(setq overriding-terminal-local-map nil))
(defun calc-hyperbolic (&optional n)
(interactive "P")
- (let* ((inv-flag (if (eq major-mode 'calc-keypad-mode)
+ (let* ((inv-flag (if (or
+ (eq major-mode 'calc-keypad-mode)
+ (eq major-mode 'calc-trail-mode))
(with-current-buffer calc-main-buffer
calc-inverse-flag)
calc-inverse-flag))
;; Integer+fraction with explicit radix
((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]\\)$" s)
- (let ((radix (string-to-int (math-match-substring s 1)))
+ (let ((radix (string-to-number (math-match-substring s 1)))
(int (math-match-substring s 3))
(num (math-match-substring s 4))
(den (math-match-substring s 5)))
;; Fraction with explicit radix
((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)$" s)
- (let ((radix (string-to-int (math-match-substring s 1)))
+ (let ((radix (string-to-number (math-match-substring s 1)))
(num (math-match-substring s 3))
(den (math-match-substring s 4)))
(let ((num (if (> (length num) 0) (math-read-radix num radix) 1))
;; Float with explicit radix and exponent
((or (string-match "^0*\\(\\([2-9]\\|1[0-4]\\)\\(#\\|\\^\\^\\)[0-9a-dA-D.]+\\)[eE]\\([-+]?[0-9]+\\)$" s)
(string-match "^\\(\\([0-9]+\\)\\(#\\|\\^\\^\\)[0-9a-zA-Z.]+\\) *\\* *\\2\\.? *\\^ *\\([-+]?[0-9]+\\)$" s))
- (let ((radix (string-to-int (math-match-substring s 2)))
+ (let ((radix (string-to-number (math-match-substring s 2)))
(mant (math-match-substring s 1))
(exp (math-match-substring s 4)))
(let ((mant (math-read-number mant))
;; Float with explicit radix, no exponent
((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)\\.\\([0-9a-zA-Z]*\\)$" s)
- (let ((radix (string-to-int (math-match-substring s 1)))
+ (let ((radix (string-to-number (math-match-substring s 1)))
(int (math-match-substring s 3))
(fracs (math-match-substring s 4)))
(let ((int (if (> (length int) 0) (math-read-radix int radix) 0))
;; Integer with explicit radix
((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]+\\)$" s)
(math-read-radix (math-match-substring s 3)
- (string-to-int (math-match-substring s 1))))
+ (string-to-number (math-match-substring s 1))))
;; C language hexadecimal notation
((and (eq calc-language 'c)
(defvar math-expr-data)
-(defvar math-read-replacement-list
- '(;; Misc symbols
- ("±" "+/-") ; plus or minus
- ("×" "*") ; multiplication sign
- ("÷" ":") ; division sign
- ("−" "-") ; subtraction sign
- ("∕" "/") ; division sign
- ("∗" "*") ; asterisk multiplication
- ("∞" "inf") ; infinity symbol
- ("≤" "<=")
- ("≥" ">=")
- ("≦" "<=")
- ("≧" ">=")
- ;; fractions
- ("¼" "(1:4)") ; 1/4
- ("½" "(1:2)") ; 1/2
- ("¾" "(3:4)") ; 3/4
- ("⅓" "(1:3)") ; 1/3
- ("⅔" "(2:3)") ; 2/3
- ("⅕" "(1:5)") ; 1/5
- ("⅖" "(2:5)") ; 2/5
- ("⅗" "(3:5)") ; 3/5
- ("⅘" "(4:5)") ; 4/5
- ("⅙" "(1:6)") ; 1/6
- ("⅚" "(5:6)") ; 5/6
- ("⅛" "(1:8)") ; 1/8
- ("⅜" "(3:8)") ; 3/8
- ("⅝" "(5:8)") ; 5/8
- ("⅞" "(7:8)") ; 7/8
- ("⅟" "1:") ; 1/...
- ;; superscripts
- ("⁰" "0") ; 0
- ("¹" "1") ; 1
- ("²" "2") ; 2
- ("³" "3") ; 3
- ("⁴" "4") ; 4
- ("⁵" "5") ; 5
- ("⁶" "6") ; 6
- ("⁷" "7") ; 7
- ("⁸" "8") ; 8
- ("⁹" "9") ; 9
- ("⁺" "+") ; +
- ("⁻" "-") ; -
- ("⁽" "(") ; (
- ("⁾" ")") ; )
- ("ⁿ" "n") ; n
- ("ⁱ" "i")) ; i
- "A list whose elements (old new) indicate replacements to make
-in Calc algebraic input.")
-
-(defvar math-read-superscripts
- "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni
- "A string consisting of the superscripts allowed by Calc.")
-
-(defun math-read-preprocess-string (str)
- "Replace some substrings of STR by Calc equivalents."
- (setq str
- (replace-regexp-in-string (concat "[" math-read-superscripts "]+")
- "^(\\&)" str))
- (let ((rep-list math-read-replacement-list))
- (while rep-list
- (setq str
- (replace-regexp-in-string (nth 0 (car rep-list))
- (nth 1 (car rep-list)) str))
- (setq rep-list (cdr rep-list))))
- str)
-
(defun math-read-expr (math-exp-str)
(let ((math-exp-pos 0)
(math-exp-old-pos 0)
(setq str (concat (substring str 0 (match-beginning 0))
(substring str (match-end 0)))))
(if (string-match "\\\\[^ \n|]" str)
- (if (eq calc-language 'tex)
+ (if (eq calc-language 'latex)
(math-read-expr str)
- (let ((calc-language 'tex)
+ (let ((calc-language 'latex)
(calc-language-option nil)
- (math-expr-opers (get 'tex 'math-oper-table))
- (math-expr-function-mapping (get 'tex 'math-function-table))
- (math-expr-variable-mapping (get 'tex 'math-variable-table)))
+ (math-expr-opers (get 'latex 'math-oper-table))
+ (math-expr-function-mapping (get 'latex 'math-function-table))
+ (math-expr-variable-mapping (get 'latex 'math-variable-table)))
(math-read-expr str)))
(let ((math-read-big-lines nil)
(pos 0)