]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-ext.el
Add simplification rules for calcFunc-sec, calcFunc-csc, calcFunc-cot,
[gnu-emacs] / lisp / calc / calc-ext.el
index d308a391a059d478a3faf66a92c07ffd1b62bfd4..374e89ec1f13b1c476dc96ed7f88ae3ad594d29f 100644 (file)
   (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)
@@ -998,7 +999,7 @@ calc-keypad-press)
  ("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)
@@ -1240,36 +1241,54 @@ calc-kill calc-kill-region calc-yank))))
 
 (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)
@@ -1376,10 +1395,14 @@ calc-kill calc-kill-region calc-yank))))
 
 (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))
 
@@ -2874,73 +2897,6 @@ calc-kill calc-kill-region calc-yank))))
 
 (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)
@@ -2991,13 +2947,13 @@ in Calc algebraic input.")
        (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)