aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/calc/calc-ext.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/calc/calc-ext.el')
-rw-r--r--lisp/calc/calc-ext.el114
1 files changed, 58 insertions, 56 deletions
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index 4679cf8abaa..77057fd4a7a 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -108,6 +108,7 @@
108 (define-key calc-mode-map "\C-w" 'calc-kill-region) 108 (define-key calc-mode-map "\C-w" 'calc-kill-region)
109 (define-key calc-mode-map "\M-w" 'calc-copy-region-as-kill) 109 (define-key calc-mode-map "\M-w" 'calc-copy-region-as-kill)
110 (define-key calc-mode-map "\C-y" 'calc-yank) 110 (define-key calc-mode-map "\C-y" 'calc-yank)
111 (define-key calc-mode-map [mouse-2] 'calc-yank)
111 (define-key calc-mode-map "\C-_" 'calc-undo) 112 (define-key calc-mode-map "\C-_" 'calc-undo)
112 (define-key calc-mode-map "\C-xu" 'calc-undo) 113 (define-key calc-mode-map "\C-xu" 'calc-undo)
113 (define-key calc-mode-map "\M-\C-m" 'calc-last-args) 114 (define-key calc-mode-map "\M-\C-m" 'calc-last-args)
@@ -662,16 +663,6 @@
662 (define-key calc-alg-map "\e\C-m" 'calc-last-args-stub) 663 (define-key calc-alg-map "\e\C-m" 'calc-last-args-stub)
663 (define-key calc-alg-map "\e\177" 'calc-pop-above) 664 (define-key calc-alg-map "\e\177" 'calc-pop-above)
664 665
665 ;; The following is a relic for backward compatability only.
666 ;; The calc-define property list is now the recommended method.
667 (if (and (boundp 'calc-ext-defs)
668 calc-ext-defs)
669 (progn
670 (calc-need-macros)
671 (message "Evaluating calc-ext-defs...")
672 (eval (cons 'progn calc-ext-defs))
673 (setq calc-ext-defs nil)))
674
675;;;; (Autoloads here) 666;;;; (Autoloads here)
676 (mapcar (function (lambda (x) 667 (mapcar (function (lambda (x)
677 (mapcar (function (lambda (func) 668 (mapcar (function (lambda (func)
@@ -1769,10 +1760,13 @@ calc-kill calc-kill-region calc-yank))))
1769 (cdr res) 1760 (cdr res)
1770 res))) 1761 res)))
1771 1762
1763(defvar calc-z-prefix-buf nil)
1764(defvar calc-z-prefix-msgs nil)
1765
1772(defun calc-z-prefix-help () 1766(defun calc-z-prefix-help ()
1773 (interactive) 1767 (interactive)
1774 (let* ((msgs nil) 1768 (let* ((calc-z-prefix-msgs nil)
1775 (buf "") 1769 (calc-z-prefix-buf "")
1776 (kmap (sort (copy-sequence (calc-user-key-map)) 1770 (kmap (sort (copy-sequence (calc-user-key-map))
1777 (function (lambda (x y) (< (car x) (car y)))))) 1771 (function (lambda (x y) (< (car x) (car y))))))
1778 (flags (apply 'logior 1772 (flags (apply 'logior
@@ -1783,12 +1777,12 @@ calc-kill calc-kill-region calc-yank))))
1783 (if (= (logand flags 8) 0) 1777 (if (= (logand flags 8) 0)
1784 (calc-user-function-list kmap 7) 1778 (calc-user-function-list kmap 7)
1785 (calc-user-function-list kmap 1) 1779 (calc-user-function-list kmap 1)
1786 (setq msgs (cons buf msgs) 1780 (setq calc-z-prefix-msgs (cons calc-z-prefix-buf calc-z-prefix-msgs)
1787 buf "") 1781 calc-z-prefix-buf "")
1788 (calc-user-function-list kmap 6)) 1782 (calc-user-function-list kmap 6))
1789 (if (/= flags 0) 1783 (if (/= flags 0)
1790 (setq msgs (cons buf msgs))) 1784 (setq calc-z-prefix-msgs (cons calc-z-prefix-buf calc-z-prefix-msgs)))
1791 (calc-do-prefix-help (nreverse msgs) "user" ?z))) 1785 (calc-do-prefix-help (nreverse calc-z-prefix-msgs) "user" ?z)))
1792 1786
1793(defun calc-user-function-classify (key) 1787(defun calc-user-function-classify (key)
1794 (cond ((/= key (downcase key)) ; upper-case 1788 (cond ((/= key (downcase key)) ; upper-case
@@ -1822,14 +1816,15 @@ calc-kill calc-kill-region calc-yank))))
1822 (upcase key) 1816 (upcase key)
1823 (downcase name)))) 1817 (downcase name))))
1824 (char-to-string (upcase key))))) 1818 (char-to-string (upcase key)))))
1825 (if (= (length buf) 0) 1819 (if (= (length calc-z-prefix-buf) 0)
1826 (setq buf (concat (if (= flags 1) "SHIFT + " "") 1820 (setq calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1827 desc)) 1821 desc))
1828 (if (> (+ (length buf) (length desc)) 58) 1822 (if (> (+ (length calc-z-prefix-buf) (length desc)) 58)
1829 (setq msgs (cons buf msgs) 1823 (setq calc-z-prefix-msgs
1830 buf (concat (if (= flags 1) "SHIFT + " "") 1824 (cons calc-z-prefix-buf calc-z-prefix-msgs)
1825 calc-z-prefix-buf (concat (if (= flags 1) "SHIFT + " "")
1831 desc)) 1826 desc))
1832 (setq buf (concat buf ", " desc)))))) 1827 (setq calc-z-prefix-buf (concat calc-z-prefix-buf ", " desc))))))
1833 (calc-user-function-list (cdr map) flags)))) 1828 (calc-user-function-list (cdr map) flags))))
1834 1829
1835 1830
@@ -1854,10 +1849,10 @@ calc-kill calc-kill-region calc-yank))))
1854 (last-prec (intern (concat (symbol-name name) "-last-prec"))) 1849 (last-prec (intern (concat (symbol-name name) "-last-prec")))
1855 (last-val (intern (concat (symbol-name name) "-last")))) 1850 (last-val (intern (concat (symbol-name name) "-last"))))
1856 (list 'progn 1851 (list 'progn
1857 (list 'setq cache-prec (if init (math-numdigs (nth 1 init)) -100)) 1852 (list 'defvar cache-prec (if init (math-numdigs (nth 1 init)) -100))
1858 (list 'setq cache-val (list 'quote init)) 1853 (list 'defvar cache-val (list 'quote init))
1859 (list 'setq last-prec -100) 1854 (list 'defvar last-prec -100)
1860 (list 'setq last-val nil) 1855 (list 'defvar last-val nil)
1861 (list 'setq 'math-cache-list 1856 (list 'setq 'math-cache-list
1862 (list 'cons 1857 (list 'cons
1863 (list 'quote cache-prec) 1858 (list 'quote cache-prec)
@@ -2223,25 +2218,25 @@ calc-kill calc-kill-region calc-yank))))
2223 (math-normalize (car a)) 2218 (math-normalize (car a))
2224 (error "Can't use multi-valued function in an expression"))))) 2219 (error "Can't use multi-valued function in an expression")))))
2225 2220
2226(defun math-normalize-nonstandard () ; uses "a" 2221(defun math-normalize-nonstandard ()
2227 (if (consp calc-simplify-mode) 2222 (if (consp calc-simplify-mode)
2228 (progn 2223 (progn
2229 (setq calc-simplify-mode 'none 2224 (setq calc-simplify-mode 'none
2230 math-simplify-only (car-safe (cdr-safe a))) 2225 math-simplify-only (car-safe (cdr-safe math-normalize-a)))
2231 nil) 2226 nil)
2232 (and (symbolp (car a)) 2227 (and (symbolp (car math-normalize-a))
2233 (or (eq calc-simplify-mode 'none) 2228 (or (eq calc-simplify-mode 'none)
2234 (and (eq calc-simplify-mode 'num) 2229 (and (eq calc-simplify-mode 'num)
2235 (let ((aptr (setq a (cons 2230 (let ((aptr (setq math-normalize-a
2236 (car a) 2231 (cons
2237 (mapcar 'math-normalize (cdr a)))))) 2232 (car math-normalize-a)
2233 (mapcar 'math-normalize
2234 (cdr math-normalize-a))))))
2238 (while (and aptr (math-constp (car aptr))) 2235 (while (and aptr (math-constp (car aptr)))
2239 (setq aptr (cdr aptr))) 2236 (setq aptr (cdr aptr)))
2240 aptr))) 2237 aptr)))
2241 (cons (car a) (mapcar 'math-normalize (cdr a)))))) 2238 (cons (car math-normalize-a)
2242 2239 (mapcar 'math-normalize (cdr math-normalize-a))))))
2243
2244
2245 2240
2246 2241
2247;;; Normalize a bignum digit list by trimming high-end zeros. [L l] 2242;;; Normalize a bignum digit list by trimming high-end zeros. [L l]
@@ -2619,22 +2614,27 @@ calc-kill calc-kill-region calc-yank))))
2619 2614
2620(defvar var-FactorRules 'calc-FactorRules) 2615(defvar var-FactorRules 'calc-FactorRules)
2621 2616
2622(defun math-map-tree (mmt-func mmt-expr &optional mmt-many) 2617(defvar math-mt-many nil)
2623 (or mmt-many (setq mmt-many 1000000)) 2618(defvar math-mt-func nil)
2619
2620(defun math-map-tree (math-mt-func mmt-expr &optional math-mt-many)
2621 (or math-mt-many (setq math-mt-many 1000000))
2624 (math-map-tree-rec mmt-expr)) 2622 (math-map-tree-rec mmt-expr))
2625 2623
2626(defun math-map-tree-rec (mmt-expr) 2624(defun math-map-tree-rec (mmt-expr)
2627 (or (= mmt-many 0) 2625 (or (= math-mt-many 0)
2628 (let ((mmt-done nil) 2626 (let ((mmt-done nil)
2629 mmt-nextval) 2627 mmt-nextval)
2630 (while (not mmt-done) 2628 (while (not mmt-done)
2631 (while (and (/= mmt-many 0) 2629 (while (and (/= math-mt-many 0)
2632 (setq mmt-nextval (funcall mmt-func mmt-expr)) 2630 (setq mmt-nextval (funcall math-mt-func mmt-expr))
2633 (not (equal mmt-expr mmt-nextval))) 2631 (not (equal mmt-expr mmt-nextval)))
2634 (setq mmt-expr mmt-nextval 2632 (setq mmt-expr mmt-nextval
2635 mmt-many (if (> mmt-many 0) (1- mmt-many) (1+ mmt-many)))) 2633 math-mt-many (if (> math-mt-many 0)
2634 (1- math-mt-many)
2635 (1+ math-mt-many))))
2636 (if (or (Math-primp mmt-expr) 2636 (if (or (Math-primp mmt-expr)
2637 (<= mmt-many 0)) 2637 (<= math-mt-many 0))
2638 (setq mmt-done t) 2638 (setq mmt-done t)
2639 (setq mmt-nextval (cons (car mmt-expr) 2639 (setq mmt-nextval (cons (car mmt-expr)
2640 (mapcar 'math-map-tree-rec 2640 (mapcar 'math-map-tree-rec
@@ -2885,22 +2885,24 @@ calc-kill calc-kill-region calc-yank))))
2885 2885
2886;;; Expression parsing. 2886;;; Expression parsing.
2887 2887
2888(defun math-read-expr (exp-str) 2888(defvar math-expr-data)
2889 (let ((exp-pos 0) 2889
2890 (exp-old-pos 0) 2890(defun math-read-expr (math-exp-str)
2891 (exp-keep-spaces nil) 2891 (let ((math-exp-pos 0)
2892 exp-token exp-data) 2892 (math-exp-old-pos 0)
2893 (while (setq exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" exp-str)) 2893 (math-exp-keep-spaces nil)
2894 (setq exp-str (concat (substring exp-str 0 exp-token) "\\dots" 2894 math-exp-token math-expr-data)
2895 (substring exp-str (+ exp-token 2))))) 2895 (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
2896 (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots"
2897 (substring math-exp-str (+ math-exp-token 2)))))
2896 (math-build-parse-table) 2898 (math-build-parse-table)
2897 (math-read-token) 2899 (math-read-token)
2898 (let ((val (catch 'syntax (math-read-expr-level 0)))) 2900 (let ((val (catch 'syntax (math-read-expr-level 0))))
2899 (if (stringp val) 2901 (if (stringp val)
2900 (list 'error exp-old-pos val) 2902 (list 'error math-exp-old-pos val)
2901 (if (equal exp-token 'end) 2903 (if (equal math-exp-token 'end)
2902 val 2904 val
2903 (list 'error exp-old-pos "Syntax error")))))) 2905 (list 'error math-exp-old-pos "Syntax error"))))))
2904 2906
2905(defun math-read-plain-expr (exp-str &optional error-check) 2907(defun math-read-plain-expr (exp-str &optional error-check)
2906 (let* ((calc-language nil) 2908 (let* ((calc-language nil)
@@ -2913,8 +2915,8 @@ calc-kill calc-kill-region calc-yank))))
2913 2915
2914 2916
2915(defun math-read-string () 2917(defun math-read-string ()
2916 (let ((str (read-from-string (concat exp-data "\"")))) 2918 (let ((str (read-from-string (concat math-expr-data "\""))))
2917 (or (and (= (cdr str) (1+ (length exp-data))) 2919 (or (and (= (cdr str) (1+ (length math-expr-data)))
2918 (stringp (car str))) 2920 (stringp (car str)))
2919 (throw 'syntax "Error in string constant")) 2921 (throw 'syntax "Error in string constant"))
2920 (math-read-token) 2922 (math-read-token)