]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-aent.el
(calc-get-operator-history): New variable.
[gnu-emacs] / lisp / calc / calc-aent.el
index e174d81c41da6f25d98a8eeaf252383ee6cc6fcf..fe5bf4cf9e0a80c345a61e82f009601db627e5e7 100644 (file)
@@ -1,6 +1,7 @@
 ;;; calc-aent.el --- algebraic entry functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <belanger@truman.edu>
 (require 'calc)
 (require 'calc-macs)
 
+(defvar calc-quick-calc-history nil
+  "The history list for quick-calc.")
+
 (defun calc-do-quick-calc ()
+  (require 'calc-ext)
   (calc-check-defines)
   (if (eq major-mode 'calc-mode)
       (calc-algebraic-entry t)
               (enable-recursive-minibuffers t)
               (calc-language (if (memq calc-language '(nil big))
                                  'flat calc-language))
-              (entry (calc-do-alg-entry "" "Quick calc: " t))
-              (alg-exp (mapcar (function
-                                (lambda (x)
-                                  (if (and (not (featurep 'calc-ext))
-                                           calc-previous-alg-entry
-                                           (string-match
-                                            "\\`[-0-9._+*/^() ]+\\'"
-                                            calc-previous-alg-entry))
-                                      (calc-normalize x)
-                                    (require 'calc-ext)
-                                    (math-evaluate-expr x))))
-                               entry)))
+              (entry (calc-do-alg-entry "" "Quick calc: " t 'calc-quick-calc-history))
+              (alg-exp (mapcar 'math-evaluate-expr entry)))
          (when (and (= (length alg-exp) 1)
                     (eq (car-safe (car alg-exp)) 'calcFunc-assign)
                     (= (length (car alg-exp)) 3)
                     (eq (car-safe (nth 1 (car alg-exp))) 'var))
-           (require 'calc-ext)
            (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
            (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
            (setq alg-exp (list (nth 2 (car alg-exp)))))
@@ -263,13 +257,16 @@ T means abort and give an error message.")
         (math-expr-opers (if prefix math-standard-opers math-expr-opers)))
      (calc-alg-entry (and auto (char-to-string last-command-char))))))
 
+(defvar calc-alg-entry-history nil
+  "History for algebraic entry.")
+
 (defun calc-alg-entry (&optional initial prompt)
   (let* ((sel-mode nil)
         (calc-dollar-values (mapcar 'calc-get-stack-element
                                     (nthcdr calc-stack-top calc-stack)))
         (calc-dollar-used 0)
         (calc-plain-entry t)
-        (alg-exp (calc-do-alg-entry initial prompt t)))
+        (alg-exp (calc-do-alg-entry initial prompt t 'calc-alg-entry-history)))
     (if (stringp alg-exp)
        (progn
          (require 'calc-ext)
@@ -300,7 +297,7 @@ T means abort and give an error message.")
 
 (defvar calc-alg-exp)
 
-(defun calc-do-alg-entry (&optional initial prompt no-normalize)
+(defun calc-do-alg-entry (&optional initial prompt no-normalize history)
   (let* ((calc-buffer (current-buffer))
         (blink-paren-function 'calcAlg-blink-matching-open)
         (calc-alg-exp 'error))
@@ -318,15 +315,17 @@ T means abort and give an error message.")
     (define-key calc-alg-ent-map "\e" nil)
     (if (eq calc-algebraic-mode 'total)
        (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
-      (define-key calc-alg-ent-map "\ep" 'calcAlg-plus-minus)
+      (define-key calc-alg-ent-map "\e+" 'calcAlg-plus-minus)
       (define-key calc-alg-ent-map "\em" 'calcAlg-mod)
       (define-key calc-alg-ent-map "\e=" 'calcAlg-equals)
       (define-key calc-alg-ent-map "\e\r" 'calcAlg-equals)
+      (define-key calc-alg-ent-map "\ep" 'previous-history-element)
+      (define-key calc-alg-ent-map "\en" 'next-history-element)
       (define-key calc-alg-ent-map "\e%" 'self-insert-command))
     (setq calc-aborted-prefix nil)
     (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
                                     (or initial "")
-                                    calc-alg-ent-map nil)))
+                                    calc-alg-ent-map nil history)))
       (when (eq calc-alg-exp 'error)
        (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error)
          (setq calc-alg-exp nil)))
@@ -354,9 +353,7 @@ T means abort and give an error message.")
 (defun calcAlg-previous ()
   (interactive)
   (if (calc-minibuffer-contains "\\'")
-      (if calc-previous-alg-entry
-         (insert calc-previous-alg-entry)
-       (beep))
+      (previous-history-element 1)
     (insert "'")))
 
 (defun calcAlg-equals ()
@@ -383,7 +380,6 @@ T means abort and give an error message.")
           "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'"))
       (insert "`")
     (setq calc-alg-exp (minibuffer-contents))
-    (and (> (length calc-alg-exp) 0) (setq calc-previous-alg-entry calc-alg-exp))
     (exit-minibuffer)))
 
 (defvar calc-buffer)
@@ -406,7 +402,6 @@ T means abort and give an error message.")
       (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'")
                        '((incomplete vec))
                      exp))
-      (and (> (length str) 0) (setq calc-previous-alg-entry str))
       (exit-minibuffer))))
 
 (defun calcAlg-blink-matching-open ()
@@ -519,7 +514,22 @@ T means abort and give an error message.")
     ("⁽" "(")  ; (
     ("⁾" ")")  ; )
     ("ⁿ" "n")  ; n
-    ("ⁱ" "i")) ; i
+    ("ⁱ" "i")  ; i
+    ;; subscripts
+    ("₀"  "0")  ; 0
+    ("₁"  "1")  ; 1
+    ("₂"  "2")  ; 2
+    ("₃"  "3")  ; 3
+    ("₄"  "4")  ; 4
+    ("₅"  "5")  ; 5
+    ("₆"  "6")  ; 6
+    ("₇"  "7")  ; 7
+    ("₈"  "8")  ; 8
+    ("₉"  "9")  ; 9
+    ("₊"  "+")  ; +
+    ("₋"  "-")  ; -
+    ("₍"  "(")  ; (
+    ("₎"  ")"))  ; )
   "A list whose elements (old new) indicate replacements to make
 in Calc algebraic input.")
 
@@ -527,11 +537,18 @@ in Calc algebraic input.")
   "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni
   "A string consisting of the superscripts allowed by Calc.")
 
+(defvar math-read-subscripts
+  "₀₁₂₃₄₅₆₇₈₉₊₋₍₎" ; 0123456789+-()
+  "A string consisting of the subscripts 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))
+  (setq str
+        (replace-regexp-in-string (concat "[" math-read-subscripts "]+")
+                                  "_(\\&)" str))
   (let ((rep-list math-read-replacement-list))
     (while rep-list
       (setq str
@@ -712,7 +729,7 @@ in Calc algebraic input.")
                       math-exp-pos (match-end 1))
               (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
                       math-exp-pos)
-                  (setq math-expr-data (- (string-to-int (math-match-substring
+                  (setq math-expr-data (- (string-to-number (math-match-substring
                                                     math-exp-str 1))))
                 (string-match "\\$+" math-exp-str math-exp-pos)
                 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
@@ -721,7 +738,7 @@ in Calc algebraic input.")
            ((eq ch ?\#)
             (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
                     math-exp-pos)
-                (setq math-expr-data (string-to-int
+                (setq math-expr-data (string-to-number
                                 (math-match-substring math-exp-str 1))
                       math-exp-pos (match-end 0))
               (setq math-expr-data 1
@@ -925,6 +942,9 @@ in Calc algebraic input.")
            first nil))
     x))
 
+;; calc-arg-values is defined in calc-ext.el, but is used here.
+(defvar calc-arg-values)
+
 (defun calc-check-user-syntax (&optional x prec)
   (let ((p calc-user-parse-table)
        (matches nil)