Mercurial > emacs
annotate lisp/calc/calc-aent.el @ 106915:ef4635609200
from trunk
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 18 Jan 2010 09:58:15 +0900 |
parents | 1d1d5d9bd884 |
children | c84578d13e42 376148b31b5e |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
1 ;;; calc-aent.el --- algebraic entry functions for Calc |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
2 |
64324
b0ebddde406c
Updated copyright information.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62835
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
106815 | 4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
5 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
6 ;; Author: Dave Gillespie <daveg@synaptics.com> |
77465
1154f082efd9
Update maintainer's address.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
76595
diff
changeset
|
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93880
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93880
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93880
diff
changeset
|
14 ;; (at your option) any later version. |
40785 | 15 |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
19 ;; GNU General Public License for more details. |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
20 |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
94654
6c9af2bfcfee
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93880
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
40785 | 23 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
24 ;;; Commentary: |
40785 | 25 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
26 ;;; Code: |
40785 | 27 |
28 ;; This file is autoloaded from calc.el. | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
29 |
40785 | 30 (require 'calc) |
31 (require 'calc-macs) | |
32 | |
86466
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
33 ;; Declare functions which are defined elsewhere. |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
34 (declare-function calc-refresh-evaltos "calc-ext" (&optional which-var)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
35 (declare-function calc-execute-kbd-macro "calc-prog" (mac arg &rest prefix)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
36 (declare-function math-is-true "calc-ext" (expr)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
37 (declare-function calc-explain-why "calc-stuff" (why &optional more)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
38 (declare-function calc-alg-edit "calc-yank" (str)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
39 (declare-function math-composite-inequalities "calc-prog" (x op)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
40 (declare-function math-flatten-lands "calc-rewr" (expr)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
41 (declare-function math-multi-subst "calc-map" (expr olds news)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
42 (declare-function calcFunc-vmatches "calc-rewr" (expr pat)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
43 (declare-function math-simplify "calc-alg" (top-expr)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
44 (declare-function math-known-matrixp "calc-arith" (a)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
45 (declare-function math-parse-fortran-subscr "calc-lang" (sym args)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
46 (declare-function math-to-radians-2 "calc-math" (a)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
47 (declare-function math-read-string "calc-ext" ()) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
48 (declare-function math-read-brackets "calc-vec" (space-sep math-rb-close)) |
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
49 (declare-function math-read-angle-brackets "calc-forms" ()) |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
50 (declare-function math-to-percentsigns "calccomp" (x)) |
86466
7777ff0392d6
(calc-refresh-evaltos, calc-execute-kbd-macro)
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86165
diff
changeset
|
51 |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
52 (defvar calc-quick-calc-history nil |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
53 "The history list for quick-calc.") |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
54 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
55 ;;;###autoload |
40785 | 56 (defun calc-do-quick-calc () |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
57 (require 'calc-ext) |
40785 | 58 (calc-check-defines) |
59 (if (eq major-mode 'calc-mode) | |
60 (calc-algebraic-entry t) | |
61 (let (buf shortbuf) | |
62 (save-excursion | |
63 (calc-create-buffer) | |
64 (let* ((calc-command-flags nil) | |
65 (calc-dollar-values calc-quick-prev-results) | |
66 (calc-dollar-used 0) | |
67 (enable-recursive-minibuffers t) | |
68 (calc-language (if (memq calc-language '(nil big)) | |
69 'flat calc-language)) | |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
70 (entry (calc-do-alg-entry "" "Quick calc: " t 'calc-quick-calc-history)) |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
71 (alg-exp (mapcar 'math-evaluate-expr entry))) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
72 (when (and (= (length alg-exp) 1) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
73 (eq (car-safe (car alg-exp)) 'calcFunc-assign) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
74 (= (length (car alg-exp)) 3) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
75 (eq (car-safe (nth 1 (car alg-exp))) 'var)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
76 (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
77 (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp)))) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
78 (setq alg-exp (list (nth 2 (car alg-exp))))) |
40785 | 79 (setq calc-quick-prev-results alg-exp |
80 buf (mapconcat (function (lambda (x) | |
81 (math-format-value x 1000))) | |
82 alg-exp | |
83 " ") | |
84 shortbuf buf) | |
85 (if (and (= (length alg-exp) 1) | |
86 (memq (car-safe (car alg-exp)) '(nil bigpos bigneg)) | |
87 (< (length buf) 20) | |
88 (= calc-number-radix 10)) | |
89 (setq buf (concat buf " (" | |
90 (let ((calc-number-radix 16)) | |
91 (math-format-value (car alg-exp) 1000)) | |
92 ", " | |
93 (let ((calc-number-radix 8)) | |
94 (math-format-value (car alg-exp) 1000)) | |
82378 | 95 ", " |
96 (let ((calc-number-radix 2)) | |
97 (math-format-value (car alg-exp) 1000)) | |
40785 | 98 (if (and (integerp (car alg-exp)) |
99 (> (car alg-exp) 0) | |
100 (< (car alg-exp) 127)) | |
101 (format ", \"%c\"" (car alg-exp)) | |
102 "") | |
103 ")"))) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
104 (if (and (< (length buf) (frame-width)) (= (length entry) 1) |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
105 (featurep 'calc-ext)) |
40785 | 106 (let ((long (concat (math-format-value (car entry) 1000) |
107 " => " buf))) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
108 (if (<= (length long) (- (frame-width) 8)) |
40785 | 109 (setq buf long)))) |
110 (calc-handle-whys) | |
111 (message "Result: %s" buf))) | |
101001
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
112 (if (eq last-command-event 10) |
40785 | 113 (insert shortbuf) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
114 (kill-new shortbuf))))) |
40785 | 115 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
116 ;;;###autoload |
40785 | 117 (defun calc-do-calc-eval (str separator args) |
118 (calc-check-defines) | |
119 (catch 'calc-error | |
120 (save-excursion | |
121 (calc-create-buffer) | |
122 (cond | |
123 ((and (consp str) (not (symbolp (car str)))) | |
124 (let ((calc-language nil) | |
81467
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
125 (math-expr-opers (math-standard-ops)) |
40785 | 126 (calc-internal-prec 12) |
127 (calc-word-size 32) | |
128 (calc-symbolic-mode nil) | |
129 (calc-matrix-mode nil) | |
130 (calc-angle-mode 'deg) | |
131 (calc-number-radix 10) | |
106136
72136220d7f5
(calc-do-calc-eval): Let `calc-twos-complement-mode' be nil.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
106037
diff
changeset
|
132 (calc-twos-complement-mode nil) |
40785 | 133 (calc-leading-zeros nil) |
134 (calc-group-digits nil) | |
135 (calc-point-char ".") | |
136 (calc-frac-format '(":" nil)) | |
137 (calc-prefer-frac nil) | |
138 (calc-hms-format "%s@ %s' %s\"") | |
139 (calc-date-format '((H ":" mm C SS pp " ") | |
140 Www " " Mmm " " D ", " YYYY)) | |
141 (calc-float-format '(float 0)) | |
142 (calc-full-float-format '(float 0)) | |
143 (calc-complex-format nil) | |
144 (calc-matrix-just nil) | |
145 (calc-full-vectors t) | |
146 (calc-break-vectors nil) | |
147 (calc-vector-commas ",") | |
148 (calc-vector-brackets "[]") | |
149 (calc-matrix-brackets '(R O)) | |
150 (calc-complex-mode 'cplx) | |
151 (calc-infinite-mode nil) | |
152 (calc-display-strings nil) | |
153 (calc-simplify-mode nil) | |
154 (calc-display-working-message 'lots) | |
155 (strp (cdr str))) | |
156 (while strp | |
157 (set (car strp) (nth 1 strp)) | |
158 (setq strp (cdr (cdr strp)))) | |
159 (calc-do-calc-eval (car str) separator args))) | |
160 ((eq separator 'eval) | |
161 (eval str)) | |
162 ((eq separator 'macro) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
163 (require 'calc-ext) |
40785 | 164 (let* ((calc-buffer (current-buffer)) |
165 (calc-window (get-buffer-window calc-buffer)) | |
166 (save-window (selected-window))) | |
167 (if calc-window | |
168 (unwind-protect | |
169 (progn | |
170 (select-window calc-window) | |
171 (calc-execute-kbd-macro str nil (car args))) | |
172 (and (window-point save-window) | |
173 (select-window save-window))) | |
174 (save-window-excursion | |
175 (select-window (get-largest-window)) | |
176 (switch-to-buffer calc-buffer) | |
177 (calc-execute-kbd-macro str nil (car args))))) | |
178 nil) | |
179 ((eq separator 'pop) | |
180 (or (not (integerp str)) | |
181 (= str 0) | |
182 (calc-pop (min str (calc-stack-size)))) | |
183 (calc-stack-size)) | |
184 ((eq separator 'top) | |
185 (and (integerp str) | |
186 (> str 0) | |
187 (<= str (calc-stack-size)) | |
188 (math-format-value (calc-top-n str (car args)) 1000))) | |
189 ((eq separator 'rawtop) | |
190 (and (integerp str) | |
191 (> str 0) | |
192 (<= str (calc-stack-size)) | |
193 (calc-top-n str (car args)))) | |
194 (t | |
195 (let* ((calc-command-flags nil) | |
196 (calc-next-why nil) | |
197 (calc-language (if (memq calc-language '(nil big)) | |
198 'flat calc-language)) | |
199 (calc-dollar-values (mapcar | |
200 (function | |
201 (lambda (x) | |
202 (if (stringp x) | |
203 (progn | |
204 (setq x (math-read-exprs x)) | |
205 (if (eq (car-safe x) | |
206 'error) | |
207 (throw 'calc-error | |
208 (calc-eval-error | |
209 (cdr x))) | |
210 (car x))) | |
211 x))) | |
212 args)) | |
213 (calc-dollar-used 0) | |
214 (res (if (stringp str) | |
215 (math-read-exprs str) | |
216 (list str))) | |
217 buf) | |
218 (if (eq (car res) 'error) | |
219 (calc-eval-error (cdr res)) | |
220 (setq res (mapcar 'calc-normalize res)) | |
221 (and (memq 'clear-message calc-command-flags) | |
222 (message "")) | |
223 (cond ((eq separator 'pred) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
224 (require 'calc-ext) |
40785 | 225 (if (= (length res) 1) |
226 (math-is-true (car res)) | |
227 (calc-eval-error '(0 "Single value expected")))) | |
228 ((eq separator 'raw) | |
229 (if (= (length res) 1) | |
230 (car res) | |
231 (calc-eval-error '(0 "Single value expected")))) | |
232 ((eq separator 'list) | |
233 res) | |
234 ((memq separator '(num rawnum)) | |
235 (if (= (length res) 1) | |
236 (if (math-constp (car res)) | |
237 (if (eq separator 'num) | |
238 (math-format-value (car res) 1000) | |
239 (car res)) | |
240 (calc-eval-error | |
241 (list 0 | |
242 (if calc-next-why | |
243 (calc-explain-why (car calc-next-why)) | |
244 "Number expected")))) | |
245 (calc-eval-error '(0 "Single value expected")))) | |
246 ((eq separator 'push) | |
247 (calc-push-list res) | |
248 nil) | |
249 (t (while res | |
250 (setq buf (concat buf | |
251 (and buf (or separator ", ")) | |
252 (math-format-value (car res) 1000)) | |
253 res (cdr res))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
254 buf))))))))) |
40785 | 255 |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
256 (defvar calc-eval-error nil |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
257 "Determines how calc handles errors. |
74579
d5f79339859e
(calc-eval-error): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
72037
diff
changeset
|
258 If nil, return a list containing the character position of error. |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
259 STRING means return error message as string rather than list. |
74579
d5f79339859e
(calc-eval-error): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
72037
diff
changeset
|
260 The value t means abort and give an error message.") |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
261 |
40785 | 262 (defun calc-eval-error (msg) |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
263 (if calc-eval-error |
40785 | 264 (if (eq calc-eval-error 'string) |
265 (nth 1 msg) | |
266 (error "%s" (nth 1 msg))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
267 msg)) |
40785 | 268 |
269 | |
270 ;;;; Reading an expression in algebraic form. | |
271 | |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
272 ;;;###autoload |
40785 | 273 (defun calc-auto-algebraic-entry (&optional prefix) |
274 (interactive "P") | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
275 (calc-algebraic-entry prefix t)) |
40785 | 276 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
277 ;;;###autoload |
40785 | 278 (defun calc-algebraic-entry (&optional prefix auto) |
279 (interactive "P") | |
280 (calc-wrapper | |
281 (let ((calc-language (if prefix nil calc-language)) | |
81467
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
282 (math-expr-opers (if prefix (math-standard-ops) (math-expr-ops)))) |
101001
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
283 (calc-alg-entry (and auto (char-to-string last-command-event)))))) |
40785 | 284 |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
285 (defvar calc-alg-entry-history nil |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
286 "History for algebraic entry.") |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
287 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
288 ;;;###autoload |
40785 | 289 (defun calc-alg-entry (&optional initial prompt) |
290 (let* ((sel-mode nil) | |
291 (calc-dollar-values (mapcar 'calc-get-stack-element | |
292 (nthcdr calc-stack-top calc-stack))) | |
293 (calc-dollar-used 0) | |
294 (calc-plain-entry t) | |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
295 (alg-exp (calc-do-alg-entry initial prompt t 'calc-alg-entry-history))) |
40785 | 296 (if (stringp alg-exp) |
297 (progn | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
298 (require 'calc-ext) |
40785 | 299 (calc-alg-edit alg-exp)) |
101001
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
300 (let* ((calc-simplify-mode (if (eq last-command-event ?\C-j) |
40785 | 301 'none |
302 calc-simplify-mode)) | |
303 (nvals (mapcar 'calc-normalize alg-exp))) | |
304 (while alg-exp | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
305 (calc-record (if (featurep 'calc-ext) (car alg-exp) (car nvals)) |
40785 | 306 "alg'") |
307 (calc-pop-push-record-list calc-dollar-used | |
308 (and (not (equal (car alg-exp) | |
309 (car nvals))) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
310 (featurep 'calc-ext) |
40785 | 311 "") |
312 (list (car nvals))) | |
313 (setq alg-exp (cdr alg-exp) | |
314 nvals (cdr nvals) | |
315 calc-dollar-used 0))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
316 (calc-handle-whys)))) |
40785 | 317 |
57635
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
318 (defvar calc-alg-ent-map nil |
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
319 "The keymap used for algebraic entry.") |
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
320 |
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
321 (defvar calc-alg-ent-esc-map nil |
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
322 "The keymap used for escapes in algebraic entry.") |
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
323 |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
324 (defvar calc-alg-exp) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
325 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
326 ;;;###autoload |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
327 (defun calc-do-alg-entry (&optional initial prompt no-normalize history) |
40785 | 328 (let* ((calc-buffer (current-buffer)) |
40995 | 329 (blink-paren-function 'calcAlg-blink-matching-open) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
330 (calc-alg-exp 'error)) |
57635
b1a458fd1ca9
(calc-alg-ent-map, calc-alg-ent-esc-map): Declared these variables
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57595
diff
changeset
|
331 (unless calc-alg-ent-map |
40785 | 332 (setq calc-alg-ent-map (copy-keymap minibuffer-local-map)) |
333 (define-key calc-alg-ent-map "'" 'calcAlg-previous) | |
334 (define-key calc-alg-ent-map "`" 'calcAlg-edit) | |
335 (define-key calc-alg-ent-map "\C-m" 'calcAlg-enter) | |
336 (define-key calc-alg-ent-map "\C-j" 'calcAlg-enter) | |
57590
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
337 (let ((i 33)) |
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
338 (setq calc-alg-ent-esc-map (copy-keymap esc-map)) |
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
339 (while (< i 127) |
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
340 (aset (nth 1 calc-alg-ent-esc-map) i 'calcAlg-escape) |
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
341 (setq i (1+ i))))) |
afc7ff1f1214
(calc-do-alg-entry): Remove Emacs version check. Use `copy-keymap' to
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
342 (define-key calc-alg-ent-map "\e" nil) |
40785 | 343 (if (eq calc-algebraic-mode 'total) |
344 (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map) | |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
345 (define-key calc-alg-ent-map "\e+" 'calcAlg-plus-minus) |
40785 | 346 (define-key calc-alg-ent-map "\em" 'calcAlg-mod) |
347 (define-key calc-alg-ent-map "\e=" 'calcAlg-equals) | |
348 (define-key calc-alg-ent-map "\e\r" 'calcAlg-equals) | |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
349 (define-key calc-alg-ent-map "\ep" 'previous-history-element) |
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
350 (define-key calc-alg-ent-map "\en" 'next-history-element) |
40785 | 351 (define-key calc-alg-ent-map "\e%" 'self-insert-command)) |
352 (setq calc-aborted-prefix nil) | |
353 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ") | |
354 (or initial "") | |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
355 calc-alg-ent-map nil history))) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
356 (when (eq calc-alg-exp 'error) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
357 (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
358 (setq calc-alg-exp nil))) |
40785 | 359 (setq calc-aborted-prefix "alg'") |
360 (or no-normalize | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
361 (and calc-alg-exp (setq calc-alg-exp (mapcar 'calc-normalize calc-alg-exp)))) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
362 calc-alg-exp))) |
40785 | 363 |
364 (defun calcAlg-plus-minus () | |
365 (interactive) | |
366 (if (calc-minibuffer-contains ".* \\'") | |
367 (insert "+/- ") | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
368 (insert " +/- "))) |
40785 | 369 |
370 (defun calcAlg-mod () | |
371 (interactive) | |
372 (if (not (calc-minibuffer-contains ".* \\'")) | |
373 (insert " ")) | |
374 (if (calc-minibuffer-contains ".* mod +\\'") | |
375 (if calc-previous-modulo | |
376 (insert (math-format-flat-expr calc-previous-modulo 0)) | |
377 (beep)) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
378 (insert "mod "))) |
40785 | 379 |
380 (defun calcAlg-previous () | |
381 (interactive) | |
57595
8ca090ac0a97
(calcAlg-previous): Changed the regexp to the end of buffer regexp.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57590
diff
changeset
|
382 (if (calc-minibuffer-contains "\\'") |
72037
52f1e8d569ad
(calcAlg-edit, calcAlg-enter): Remove reference to calc-previous-alg-entry.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
68636
diff
changeset
|
383 (previous-history-element 1) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
384 (insert "'"))) |
40785 | 385 |
386 (defun calcAlg-equals () | |
387 (interactive) | |
388 (unwind-protect | |
389 (calcAlg-enter) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
390 (if (consp calc-alg-exp) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
391 (progn (setq prefix-arg (length calc-alg-exp)) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
392 (calc-unread-command ?=))))) |
40785 | 393 |
394 (defun calcAlg-escape () | |
395 (interactive) | |
396 (calc-unread-command) | |
397 (save-excursion | |
398 (calc-select-buffer) | |
399 (use-local-map calc-mode-map)) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
400 (calcAlg-enter)) |
40785 | 401 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
402 (defvar calc-plain-entry nil) |
40785 | 403 (defun calcAlg-edit () |
404 (interactive) | |
405 (if (or (not calc-plain-entry) | |
406 (calc-minibuffer-contains | |
407 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'")) | |
408 (insert "`") | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
409 (setq calc-alg-exp (minibuffer-contents)) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
410 (exit-minibuffer))) |
40785 | 411 |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
412 (defvar calc-buffer) |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
413 |
40785 | 414 (defun calcAlg-enter () |
415 (interactive) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
416 (let* ((str (minibuffer-contents)) |
40785 | 417 (exp (and (> (length str) 0) |
105792
2c12fbae77c2
* calc/calc.el (calc, calc-refresh, calc-trail-buffer, calc-record)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101001
diff
changeset
|
418 (with-current-buffer calc-buffer |
40785 | 419 (math-read-exprs str))))) |
420 (if (eq (car-safe exp) 'error) | |
421 (progn | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
422 (goto-char (minibuffer-prompt-end)) |
40785 | 423 (forward-char (nth 1 exp)) |
424 (beep) | |
425 (calc-temp-minibuffer-message | |
426 (concat " [" (or (nth 2 exp) "Error") "]")) | |
427 (calc-clear-unread-commands)) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
428 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'") |
40785 | 429 '((incomplete vec)) |
430 exp)) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
431 (exit-minibuffer)))) |
40785 | 432 |
433 (defun calcAlg-blink-matching-open () | |
59037
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
434 (let ((rightpt (point)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
435 (leftpt nil) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
436 (rightchar (preceding-char)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
437 leftchar |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
438 rightsyntax |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
439 leftsyntax) |
40785 | 440 (save-excursion |
441 (condition-case () | |
59037
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
442 (setq leftpt (scan-sexps rightpt -1) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
443 leftchar (char-after leftpt)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
444 (error nil))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
445 (if (and leftpt |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
446 (or (and (= rightchar ?\)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
447 (= leftchar ?\[)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
448 (and (= rightchar ?\]) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
449 (= leftchar ?\())) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
450 (save-excursion |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
451 (goto-char leftpt) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
452 (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)"))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
453 (let ((leftsaved (aref (syntax-table) leftchar)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
454 (rightsaved (aref (syntax-table) rightchar))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
455 (unwind-protect |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
456 (progn |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
457 (cond ((= leftchar ?\[) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
458 (aset (syntax-table) leftchar (cons 4 ?\))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
459 (aset (syntax-table) rightchar (cons 5 ?\[))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
460 (t |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
461 (aset (syntax-table) leftchar (cons 4 ?\])) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
462 (aset (syntax-table) rightchar (cons 5 ?\()))) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
463 (blink-matching-open)) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
464 (aset (syntax-table) leftchar leftsaved) |
d572ad446699
(calcAlg-blank-matching-open): Temporarily adjust the syntax of both
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58843
diff
changeset
|
465 (aset (syntax-table) rightchar rightsaved))) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
466 (blink-matching-open)))) |
40785 | 467 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
468 ;;;###autoload |
40785 | 469 (defun calc-alg-digit-entry () |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49262
diff
changeset
|
470 (calc-alg-entry |
101001
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
471 (cond ((eq last-command-event ?e) |
40785 | 472 (if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e")) |
101001
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
473 ((eq last-command-event ?#) (format "%d#" calc-number-radix)) |
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
474 ((eq last-command-event ?_) "-") |
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
475 ((eq last-command-event ?@) "0@ ") |
14b421290b2f
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
476 (t (char-to-string last-command-event))))) |
40785 | 477 |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
478 ;; The variable calc-digit-value is initially declared in calc.el, |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
479 ;; but can be set by calcDigit-algebraic and calcDigit-edit. |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
480 (defvar calc-digit-value) |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
481 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
482 ;;;###autoload |
40785 | 483 (defun calcDigit-algebraic () |
484 (interactive) | |
485 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'") | |
486 (calcDigit-key) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
487 (setq calc-digit-value (minibuffer-contents)) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
488 (exit-minibuffer))) |
40785 | 489 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
490 ;;;###autoload |
40785 | 491 (defun calcDigit-edit () |
492 (interactive) | |
493 (calc-unread-command) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
494 (setq calc-digit-value (minibuffer-contents)) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
495 (exit-minibuffer)) |
40785 | 496 |
497 | |
498 ;;; Algebraic expression parsing. [Public] | |
499 | |
58843
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
500 (defvar math-read-replacement-list |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
501 '(;; Misc symbols |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
502 ("±" "+/-") ; plus or minus |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
503 ("×" "*") ; multiplication sign |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
504 ("÷" ":") ; division sign |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
505 ("−" "-") ; subtraction sign |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
506 ("∕" "/") ; division sign |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
507 ("∗" "*") ; asterisk multiplication |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
508 ("∞" "inf") ; infinity symbol |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
509 ("≤" "<=") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
510 ("≥" ">=") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
511 ("≦" "<=") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
512 ("≧" ">=") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
513 ;; fractions |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
514 ("¼" "(1:4)") ; 1/4 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
515 ("½" "(1:2)") ; 1/2 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
516 ("¾" "(3:4)") ; 3/4 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
517 ("⅓" "(1:3)") ; 1/3 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
518 ("⅔" "(2:3)") ; 2/3 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
519 ("⅕" "(1:5)") ; 1/5 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
520 ("⅖" "(2:5)") ; 2/5 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
521 ("⅗" "(3:5)") ; 3/5 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
522 ("⅘" "(4:5)") ; 4/5 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
523 ("⅙" "(1:6)") ; 1/6 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
524 ("⅚" "(5:6)") ; 5/6 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
525 ("⅛" "(1:8)") ; 1/8 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
526 ("⅜" "(3:8)") ; 3/8 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
527 ("⅝" "(5:8)") ; 5/8 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
528 ("⅞" "(7:8)") ; 7/8 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
529 ("⅟" "1:") ; 1/... |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
530 ;; superscripts |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
531 ("⁰" "0") ; 0 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
532 ("¹" "1") ; 1 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
533 ("²" "2") ; 2 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
534 ("³" "3") ; 3 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
535 ("⁴" "4") ; 4 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
536 ("⁵" "5") ; 5 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
537 ("⁶" "6") ; 6 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
538 ("⁷" "7") ; 7 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
539 ("⁸" "8") ; 8 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
540 ("⁹" "9") ; 9 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
541 ("⁺" "+") ; + |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
542 ("⁻" "-") ; - |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
543 ("⁽" "(") ; ( |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
544 ("⁾" ")") ; ) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
545 ("ⁿ" "n") ; n |
61303
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
546 ("ⁱ" "i") ; i |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
547 ;; subscripts |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
548 ("₀" "0") ; 0 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
549 ("₁" "1") ; 1 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
550 ("₂" "2") ; 2 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
551 ("₃" "3") ; 3 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
552 ("₄" "4") ; 4 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
553 ("₅" "5") ; 5 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
554 ("₆" "6") ; 6 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
555 ("₇" "7") ; 7 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
556 ("₈" "8") ; 8 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
557 ("₉" "9") ; 9 |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
558 ("₊" "+") ; + |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
559 ("₋" "-") ; - |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
560 ("₍" "(") ; ( |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
561 ("₎" ")")) ; ) |
58843
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
562 "A list whose elements (old new) indicate replacements to make |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
563 in Calc algebraic input.") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
564 |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
565 (defvar math-read-superscripts |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
566 "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
567 "A string consisting of the superscripts allowed by Calc.") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
568 |
61303
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
569 (defvar math-read-subscripts |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
570 "₀₁₂₃₄₅₆₇₈₉₊₋₍₎" ; 0123456789+-() |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
571 "A string consisting of the subscripts allowed by Calc.") |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
572 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
573 ;;;###autoload |
58843
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
574 (defun math-read-preprocess-string (str) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
575 "Replace some substrings of STR by Calc equivalents." |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
576 (setq str |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
577 (replace-regexp-in-string (concat "[" math-read-superscripts "]+") |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
578 "^(\\&)" str)) |
61303
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
579 (setq str |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
580 (replace-regexp-in-string (concat "[" math-read-subscripts "]+") |
b56d5250fbc3
(math-read-replacement-list): Add subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60169
diff
changeset
|
581 "_(\\&)" str)) |
58843
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
582 (let ((rep-list math-read-replacement-list)) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
583 (while rep-list |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
584 (setq str |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
585 (replace-regexp-in-string (nth 0 (car rep-list)) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
586 (nth 1 (car rep-list)) str)) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
587 (setq rep-list (cdr rep-list)))) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
588 str) |
f3d24ef9bf58
(math-read-replacement-list, math-read-superscripts): Move from
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58645
diff
changeset
|
589 |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
590 ;; The next few variables are local to math-read-exprs (and math-read-expr |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
591 ;; in calc-ext.el), but are set in functions they call. |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
592 |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
593 (defvar math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
594 (defvar math-exp-str) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
595 (defvar math-exp-old-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
596 (defvar math-exp-token) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
597 (defvar math-exp-keep-spaces) |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
598 (defvar math-expr-data) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
599 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
600 ;;;###autoload |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
601 (defun math-read-exprs (math-exp-str) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
602 (let ((math-exp-pos 0) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
603 (math-exp-old-pos 0) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
604 (math-exp-keep-spaces nil) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
605 math-exp-token math-expr-data) |
58455
61e76fb7d4c9
(math-read-exprs): Filter input through math-read-preprocess-string.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58131
diff
changeset
|
606 (setq math-exp-str (math-read-preprocess-string math-exp-str)) |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
607 (if (memq calc-language calc-lang-allow-percentsigns) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
608 (setq math-exp-str (math-remove-percentsigns math-exp-str))) |
40785 | 609 (if calc-language-input-filter |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
610 (setq math-exp-str (funcall calc-language-input-filter math-exp-str))) |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
611 (while (setq math-exp-token |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
612 (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str)) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
613 (setq math-exp-str |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
614 (concat (substring math-exp-str 0 math-exp-token) "\\dots" |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
615 (substring math-exp-str (+ math-exp-token 2))))) |
40785 | 616 (math-build-parse-table) |
617 (math-read-token) | |
618 (let ((val (catch 'syntax (math-read-expr-list)))) | |
619 (if (stringp val) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
620 (list 'error math-exp-old-pos val) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
621 (if (equal math-exp-token 'end) |
40785 | 622 val |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
623 (list 'error math-exp-old-pos "Syntax error")))))) |
40785 | 624 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
625 ;;;###autoload |
40785 | 626 (defun math-read-expr-list () |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
627 (let* ((math-exp-keep-spaces nil) |
40785 | 628 (val (list (math-read-expr-level 0))) |
629 (last val)) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
630 (while (equal math-expr-data ",") |
40785 | 631 (math-read-token) |
632 (let ((rest (list (math-read-expr-level 0)))) | |
633 (setcdr last rest) | |
634 (setq last rest))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
635 val)) |
40785 | 636 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
637 (defvar calc-user-parse-table nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
638 (defvar calc-last-main-parse-table nil) |
86165
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
639 (defvar calc-last-user-lang-parse-table nil) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
640 (defvar calc-last-lang-parse-table nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
641 (defvar calc-user-tokens nil) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
642 (defvar calc-user-token-chars nil) |
40785 | 643 |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
644 (defvar math-toks nil |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
645 "Tokens to pass between math-build-parse-table and math-find-user-tokens.") |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
646 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
647 ;;;###autoload |
40785 | 648 (defun math-build-parse-table () |
649 (let ((mtab (cdr (assq nil calc-user-parse-tables))) | |
86165
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
650 (ltab (cdr (assq calc-language calc-user-parse-tables))) |
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
651 (lltab (get calc-language 'math-parse-table))) |
40785 | 652 (or (and (eq mtab calc-last-main-parse-table) |
86165
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
653 (eq ltab calc-last-user-lang-parse-table) |
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
654 (eq lltab calc-last-lang-parse-table)) |
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
655 (let ((p (append mtab ltab lltab)) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
656 (math-toks nil)) |
40785 | 657 (setq calc-user-parse-table p) |
658 (setq calc-user-token-chars nil) | |
659 (while p | |
660 (math-find-user-tokens (car (car p))) | |
661 (setq p (cdr p))) | |
662 (setq calc-user-tokens (mapconcat 'identity | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
663 (sort (mapcar 'car math-toks) |
40785 | 664 (function (lambda (x y) |
665 (> (length x) | |
666 (length y))))) | |
667 "\\|") | |
668 calc-last-main-parse-table mtab | |
86165
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
669 calc-last-user-lang-parse-table ltab |
8d7e01d03e55
(calc-last-user-lang-parse-table): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
82378
diff
changeset
|
670 calc-last-lang-parse-table lltab))))) |
40785 | 671 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
672 ;;;###autoload |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
673 (defun math-find-user-tokens (p) |
40785 | 674 (while p |
675 (cond ((and (stringp (car p)) | |
676 (or (> (length (car p)) 1) (equal (car p) "$") | |
677 (equal (car p) "\"")) | |
678 (string-match "[^a-zA-Z0-9]" (car p))) | |
679 (let ((s (regexp-quote (car p)))) | |
680 (if (string-match "\\`[a-zA-Z0-9]" s) | |
681 (setq s (concat "\\<" s))) | |
682 (if (string-match "[a-zA-Z0-9]\\'" s) | |
683 (setq s (concat s "\\>"))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
684 (or (assoc s math-toks) |
40785 | 685 (progn |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
686 (setq math-toks (cons (list s) math-toks)) |
40785 | 687 (or (memq (aref (car p) 0) calc-user-token-chars) |
688 (setq calc-user-token-chars | |
689 (cons (aref (car p) 0) | |
690 calc-user-token-chars))))))) | |
691 ((consp (car p)) | |
692 (math-find-user-tokens (nth 1 (car p))) | |
693 (or (eq (car (car p)) '\?) | |
694 (math-find-user-tokens (nth 2 (car p)))))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
695 (setq p (cdr p)))) |
40785 | 696 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
697 ;;;###autoload |
40785 | 698 (defun math-read-token () |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
699 (if (>= math-exp-pos (length math-exp-str)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
700 (setq math-exp-old-pos math-exp-pos |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
701 math-exp-token 'end |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
702 math-expr-data "\000") |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
703 (let (adfn |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
704 (ch (aref math-exp-str math-exp-pos))) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
705 (setq math-exp-old-pos math-exp-pos) |
40785 | 706 (cond ((memq ch '(32 10 9)) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
707 (setq math-exp-pos (1+ math-exp-pos)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
708 (if math-exp-keep-spaces |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
709 (setq math-exp-token 'space |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
710 math-expr-data " ") |
40785 | 711 (math-read-token))) |
712 ((and (memq ch calc-user-token-chars) | |
713 (let ((case-fold-search nil)) | |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
714 (eq (string-match |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
715 calc-user-tokens math-exp-str math-exp-pos) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
716 math-exp-pos))) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
717 (setq math-exp-token 'punc |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
718 math-expr-data (math-match-substring math-exp-str 0) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
719 math-exp-pos (match-end 0))) |
40785 | 720 ((or (and (>= ch ?a) (<= ch ?z)) |
721 (and (>= ch ?A) (<= ch ?Z))) | |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
722 (string-match |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
723 (cond |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
724 ((and (memq calc-language calc-lang-allow-underscores) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
725 (memq calc-language calc-lang-allow-percentsigns)) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
726 "[a-zA-Z0-9_'#]*") |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
727 ((memq calc-language calc-lang-allow-underscores) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
728 "[a-zA-Z0-9_#]*") |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
729 (t "[a-zA-Z0-9'#]*")) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
730 math-exp-str math-exp-pos) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
731 (setq math-exp-token 'symbol |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
732 math-exp-pos (match-end 0) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
733 math-expr-data (math-restore-dashes |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
734 (math-match-substring math-exp-str 0))) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
735 (if (setq adfn (get calc-language 'math-lang-adjust-words)) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
736 (funcall adfn))) |
40785 | 737 ((or (and (>= ch ?0) (<= ch ?9)) |
738 (and (eq ch '?\.) | |
74579
d5f79339859e
(calc-eval-error): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
72037
diff
changeset
|
739 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
740 math-exp-pos)) |
40785 | 741 (and (eq ch '?_) |
74579
d5f79339859e
(calc-eval-error): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
72037
diff
changeset
|
742 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
743 math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
744 (or (eq math-exp-pos 0) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
745 (and (not (memq calc-language |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
746 calc-lang-allow-underscores)) |
40785 | 747 (eq (string-match "[^])}\"a-zA-Z0-9'$]_" |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
748 math-exp-str (1- math-exp-pos)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
749 (1- math-exp-pos)))))) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
750 (or (and (memq calc-language calc-lang-c-type-hex) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
751 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos)) |
106037
2d0a21ad00df
(math-read-token): Read complement signed numbers.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
105792
diff
changeset
|
752 (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\(0*\\([2-9]\\|1[0-4]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-dA-D.]+[eE][-+_]?[0-9]+\\|0*\\([2-9]\\|[0-2][0-9]\\|3[0-6]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-zA-Z:.]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
753 math-exp-str math-exp-pos)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
754 (setq math-exp-token 'number |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
755 math-expr-data (math-match-substring math-exp-str 0) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
756 math-exp-pos (match-end 0))) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
757 ((and (setq adfn |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
758 (assq ch (get calc-language 'math-lang-read-symbol))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
759 (eval (nth 1 adfn))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
760 (eval (nth 2 adfn))) |
40785 | 761 ((eq ch ?\$) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
762 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
763 math-exp-pos) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
764 (setq math-expr-data (- (string-to-number (math-match-substring |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
765 math-exp-str 1)))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
766 (string-match "\\$+" math-exp-str math-exp-pos) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
767 (setq math-expr-data (- (match-end 0) (match-beginning 0)))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
768 (setq math-exp-token 'dollar |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
769 math-exp-pos (match-end 0))) |
40785 | 770 ((eq ch ?\#) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
771 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
772 math-exp-pos) |
62032
e570688e1d80
(math-read-token): Replace string-to-int by string-to-number.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61303
diff
changeset
|
773 (setq math-expr-data (string-to-number |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
774 (math-match-substring math-exp-str 1)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
775 math-exp-pos (match-end 0)) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
776 (setq math-expr-data 1 |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
777 math-exp-pos (1+ math-exp-pos))) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
778 (setq math-exp-token 'hash)) |
40785 | 779 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>" |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
780 math-exp-str math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
781 math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
782 (setq math-exp-token 'punc |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
783 math-expr-data (math-match-substring math-exp-str 0) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
784 math-exp-pos (match-end 0))) |
40785 | 785 ((and (eq ch ?\") |
74579
d5f79339859e
(calc-eval-error): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
72037
diff
changeset
|
786 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)" |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
787 math-exp-str math-exp-pos)) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
788 (setq math-exp-token 'string |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
789 math-expr-data (math-match-substring math-exp-str 1) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
790 math-exp-pos (match-end 0))) |
87458
bb9a0a3cc5f2
(math-read-token): Fix misplaced parentheses.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87438
diff
changeset
|
791 ((and (setq adfn (get calc-language 'math-lang-read)) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
792 (eval (nth 0 adfn)) |
87458
bb9a0a3cc5f2
(math-read-token): Fix misplaced parentheses.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87438
diff
changeset
|
793 (eval (nth 1 adfn)))) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
794 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
795 (setq math-exp-pos (match-end 0)) |
40785 | 796 (math-read-token)) |
797 (t | |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
798 (if (setq adfn (assq ch (get calc-language 'math-punc-table))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
799 (setq ch (cdr adfn))) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
800 (setq math-exp-token 'punc |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
801 math-expr-data (char-to-string ch) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
802 math-exp-pos (1+ math-exp-pos))))))) |
40785 | 803 |
58569
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
804 (defconst math-alg-inequalities |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
805 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq |
cddffb5e15f3
(calc-eval-error): Declare and initialize the variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58455
diff
changeset
|
806 calcFunc-eq calcFunc-neq)) |
40785 | 807 |
808 (defun math-read-expr-level (exp-prec &optional exp-term) | |
81467
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
809 (let* ((math-expr-opers (math-expr-ops)) |
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
810 (x (math-read-factor)) |
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
811 (first t) |
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
812 op op2) |
40785 | 813 (while (and (or (and calc-user-parse-table |
814 (setq op (calc-check-user-syntax x exp-prec)) | |
815 (setq x op | |
816 op '("2x" ident 999999 -1))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
817 (and (setq op (assoc math-expr-data math-expr-opers)) |
40785 | 818 (/= (nth 2 op) -1) |
819 (or (and (setq op2 (assoc | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
820 math-expr-data |
40785 | 821 (cdr (memq op math-expr-opers)))) |
822 (eq (= (nth 3 op) -1) | |
823 (/= (nth 3 op2) -1)) | |
824 (eq (= (nth 3 op2) -1) | |
825 (not (math-factor-after))) | |
826 (setq op op2)) | |
827 t)) | |
828 (and (or (eq (nth 2 op) -1) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
829 (memq math-exp-token '(symbol number dollar hash)) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
830 (equal math-expr-data "(") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
831 (and (equal math-expr-data "[") |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
832 (not (equal |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
833 (get calc-language |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
834 'math-function-open) "[")) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
835 (not (and math-exp-keep-spaces |
40785 | 836 (eq (car-safe x) 'vec))))) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
837 (or (not (setq op (assoc math-expr-data math-expr-opers))) |
40785 | 838 (/= (nth 2 op) -1)) |
839 (or (not calc-user-parse-table) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
840 (not (eq math-exp-token 'symbol)) |
40785 | 841 (let ((p calc-user-parse-table)) |
842 (while (and p | |
843 (or (not (integerp | |
844 (car (car (car p))))) | |
845 (not (equal | |
846 (nth 1 (car (car p))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
847 math-expr-data)))) |
40785 | 848 (setq p (cdr p))) |
849 (not p))) | |
850 (setq op (assoc "2x" math-expr-opers)))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
851 (not (and exp-term (equal math-expr-data exp-term))) |
40785 | 852 (>= (nth 2 op) exp-prec)) |
853 (if (not (equal (car op) "2x")) | |
854 (math-read-token)) | |
855 (and (memq (nth 1 op) '(sdev mod)) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
856 (require 'calc-ext)) |
40785 | 857 (setq x (cond ((consp (nth 1 op)) |
858 (funcall (car (nth 1 op)) x op)) | |
859 ((eq (nth 3 op) -1) | |
860 (if (eq (nth 1 op) 'ident) | |
861 x | |
862 (if (eq (nth 1 op) 'closing) | |
863 (if (eq (nth 2 op) exp-prec) | |
864 (progn | |
865 (setq exp-prec 1000) | |
866 x) | |
867 (throw 'syntax "Mismatched delimiters")) | |
868 (list (nth 1 op) x)))) | |
869 ((and (not first) | |
870 (memq (nth 1 op) math-alg-inequalities) | |
871 (memq (car-safe x) math-alg-inequalities)) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
872 (require 'calc-ext) |
40785 | 873 (math-composite-inequalities x op)) |
874 (t (list (nth 1 op) | |
875 x | |
876 (math-read-expr-level (nth 3 op) exp-term)))) | |
877 first nil)) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
878 x)) |
40785 | 879 |
62835
6dcbf1f1fd92
(calc-arg-values): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62032
diff
changeset
|
880 ;; calc-arg-values is defined in calc-ext.el, but is used here. |
6dcbf1f1fd92
(calc-arg-values): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62032
diff
changeset
|
881 (defvar calc-arg-values) |
6dcbf1f1fd92
(calc-arg-values): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62032
diff
changeset
|
882 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
883 ;;;###autoload |
40785 | 884 (defun calc-check-user-syntax (&optional x prec) |
885 (let ((p calc-user-parse-table) | |
886 (matches nil) | |
887 match rule) | |
888 (while (and p | |
889 (or (not (progn | |
890 (setq rule (car (car p))) | |
891 (if x | |
892 (and (integerp (car rule)) | |
893 (>= (car rule) prec) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
894 (equal math-expr-data |
40785 | 895 (car (setq rule (cdr rule))))) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
896 (equal math-expr-data (car rule))))) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
897 (let ((save-exp-pos math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
898 (save-exp-old-pos math-exp-old-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
899 (save-exp-token math-exp-token) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
900 (save-exp-data math-expr-data)) |
40785 | 901 (or (not (listp |
902 (setq matches (calc-match-user-syntax rule)))) | |
903 (let ((args (progn | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
904 (require 'calc-ext) |
40785 | 905 calc-arg-values)) |
906 (conds nil) | |
907 temp) | |
908 (if x | |
909 (setq matches (cons x matches))) | |
910 (setq match (cdr (car p))) | |
911 (while (and (eq (car-safe match) | |
912 'calcFunc-condition) | |
913 (= (length match) 3)) | |
914 (setq conds (append (math-flatten-lands | |
915 (nth 2 match)) | |
916 conds) | |
917 match (nth 1 match))) | |
918 (while (and conds match) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
919 (require 'calc-ext) |
40785 | 920 (cond ((eq (car-safe (car conds)) |
921 'calcFunc-let) | |
922 (setq temp (car conds)) | |
923 (or (= (length temp) 3) | |
924 (and (= (length temp) 2) | |
925 (eq (car-safe (nth 1 temp)) | |
926 'calcFunc-assign) | |
927 (= (length (nth 1 temp)) 3) | |
928 (setq temp (nth 1 temp))) | |
929 (setq match nil)) | |
930 (setq matches (cons | |
931 (math-normalize | |
932 (math-multi-subst | |
933 (nth 2 temp) | |
934 args matches)) | |
935 matches) | |
936 args (cons (nth 1 temp) | |
937 args))) | |
938 ((and (eq (car-safe (car conds)) | |
939 'calcFunc-matches) | |
940 (= (length (car conds)) 3)) | |
941 (setq temp (calcFunc-vmatches | |
942 (math-multi-subst | |
943 (nth 1 (car conds)) | |
944 args matches) | |
945 (nth 2 (car conds)))) | |
946 (if (eq temp 0) | |
947 (setq match nil) | |
948 (while (setq temp (cdr temp)) | |
949 (setq matches (cons (nth 2 (car temp)) | |
950 matches) | |
951 args (cons (nth 1 (car temp)) | |
952 args))))) | |
953 (t | |
954 (or (math-is-true (math-simplify | |
955 (math-multi-subst | |
956 (car conds) | |
957 args matches))) | |
958 (setq match nil)))) | |
959 (setq conds (cdr conds))) | |
960 (if match | |
961 (not (setq match (math-multi-subst | |
962 match args matches))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
963 (setq math-exp-old-pos save-exp-old-pos |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
964 math-exp-token save-exp-token |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
965 math-expr-data save-exp-data |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
966 math-exp-pos save-exp-pos))))))) |
40785 | 967 (setq p (cdr p))) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
968 (and p match))) |
40785 | 969 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
970 ;;;###autoload |
40785 | 971 (defun calc-match-user-syntax (p &optional term) |
972 (let ((matches nil) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
973 (save-exp-pos math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
974 (save-exp-old-pos math-exp-old-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
975 (save-exp-token math-exp-token) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
976 (save-exp-data math-expr-data) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
977 m) |
40785 | 978 (while (and p |
979 (cond ((stringp (car p)) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
980 (and (equal math-expr-data (car p)) |
40785 | 981 (progn |
982 (math-read-token) | |
983 t))) | |
984 ((integerp (car p)) | |
985 (and (setq m (catch 'syntax | |
986 (math-read-expr-level | |
987 (car p) | |
988 (if (cdr p) | |
989 (if (consp (nth 1 p)) | |
990 (car (nth 1 (nth 1 p))) | |
991 (nth 1 p)) | |
992 term)))) | |
993 (not (stringp m)) | |
994 (setq matches (nconc matches (list m))))) | |
995 ((eq (car (car p)) '\?) | |
996 (setq m (calc-match-user-syntax (nth 1 (car p)))) | |
997 (or (nth 2 (car p)) | |
998 (setq matches | |
999 (nconc matches | |
1000 (list | |
1001 (cons 'vec (and (listp m) m)))))) | |
1002 (or (listp m) (not (nth 2 (car p))) | |
1003 (not (eq (aref (car (nth 2 (car p))) 0) ?\$)) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1004 (eq math-exp-token 'end))) |
40785 | 1005 (t |
1006 (setq m (calc-match-user-syntax (nth 1 (car p)) | |
1007 (car (nth 2 (car p))))) | |
1008 (if (listp m) | |
1009 (let ((vec (cons 'vec m)) | |
1010 opos mm) | |
1011 (while (and (listp | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1012 (setq opos math-exp-pos |
40785 | 1013 mm (calc-match-user-syntax |
1014 (or (nth 2 (car p)) | |
1015 (nth 1 (car p))) | |
1016 (car (nth 2 (car p)))))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1017 (> math-exp-pos opos)) |
40785 | 1018 (setq vec (nconc vec mm))) |
1019 (setq matches (nconc matches (list vec)))) | |
1020 (and (eq (car (car p)) '*) | |
1021 (setq matches (nconc matches (list '(vec))))))))) | |
1022 (setq p (cdr p))) | |
1023 (if p | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1024 (setq math-exp-pos save-exp-pos |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1025 math-exp-old-pos save-exp-old-pos |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1026 math-exp-token save-exp-token |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1027 math-expr-data save-exp-data |
40785 | 1028 matches "Failed")) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1029 matches)) |
40785 | 1030 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1031 ;;;###autoload |
40785 | 1032 (defun math-remove-dashes (x) |
1033 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x) | |
1034 (math-remove-dashes | |
1035 (concat (math-match-substring x 1) "#" (math-match-substring x 2))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1036 x)) |
40785 | 1037 |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1038 (defun math-remove-percentsigns (x) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1039 (if (string-match "\\`\\(.*\\)%\\(.*\\)\\'" x) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1040 (math-remove-percentsigns |
87438
3c99a3e95b64
(math-remove-percentsigns): Change placeholder for percent signs.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87416
diff
changeset
|
1041 (concat (math-match-substring x 1) "o'o" (math-match-substring x 2))) |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1042 x)) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1043 |
40785 | 1044 (defun math-restore-dashes (x) |
1045 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x) | |
1046 (math-restore-dashes | |
1047 (concat (math-match-substring x 1) "-" (math-match-substring x 2))) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1048 x)) |
40785 | 1049 |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1050 (defun math-restore-placeholders (x) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1051 "Replace placeholders by the proper characters in the symbol x. |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1052 This includes `#' for `_' and `'' for `%'. |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1053 If the current Calc language does not use placeholders, return nil." |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1054 (if (or (memq calc-language calc-lang-allow-underscores) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1055 (memq calc-language calc-lang-allow-percentsigns)) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1056 (let ((sx (symbol-name x))) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1057 (when (memq calc-language calc-lang-allow-percentsigns) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1058 (require 'calccomp) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1059 (setq sx (math-to-percentsigns sx))) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1060 (if (memq calc-language calc-lang-allow-underscores) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1061 (setq sx (math-string-restore-underscores sx))) |
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1062 (intern-soft sx)))) |
87269
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1063 |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1064 (defun math-string-restore-underscores (x) |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1065 "Replace pound signs by underscores in the string x." |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1066 (if (string-match "\\`\\(.*\\)#\\(.*\\)\\'" x) |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1067 (math-string-restore-underscores |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1068 (concat (math-match-substring x 1) "_" (math-match-substring x 2))) |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1069 x)) |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1070 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1071 ;;;###autoload |
40785 | 1072 (defun math-read-if (cond op) |
1073 (let ((then (math-read-expr-level 0))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1074 (or (equal math-expr-data ":") |
40785 | 1075 (throw 'syntax "Expected ':'")) |
1076 (math-read-token) | |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1077 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op))))) |
40785 | 1078 |
1079 (defun math-factor-after () | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1080 (let ((math-exp-pos math-exp-pos) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1081 math-exp-old-pos math-exp-token math-expr-data) |
40785 | 1082 (math-read-token) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1083 (or (memq math-exp-token '(number symbol dollar hash string)) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1084 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/"))) |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1085 (assoc (concat "u" math-expr-data) math-expr-opers)) |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1086 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1) |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1087 (assoc math-expr-data '(("(") ("[") ("{")))))) |
40785 | 1088 |
1089 (defun math-read-factor () | |
81467
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
1090 (let ((math-expr-opers (math-expr-ops)) |
a90e4a0758e3
(calc-do-calc-eval): Let math-expr-opers equal the function
Jay Belanger <jay.p.belanger@gmail.com>
parents:
77465
diff
changeset
|
1091 op) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1092 (cond ((eq math-exp-token 'number) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1093 (let ((num (math-read-number math-expr-data))) |
40785 | 1094 (if (not num) |
1095 (progn | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1096 (setq math-exp-old-pos math-exp-pos) |
40785 | 1097 (throw 'syntax "Bad format"))) |
1098 (math-read-token) | |
1099 (if (and math-read-expr-quotes | |
1100 (consp num)) | |
1101 (list 'quote num) | |
1102 num))) | |
1103 ((and calc-user-parse-table | |
1104 (setq op (calc-check-user-syntax))) | |
1105 op) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1106 ((or (equal math-expr-data "-") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1107 (equal math-expr-data "+") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1108 (equal math-expr-data "!") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1109 (equal math-expr-data "|") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1110 (equal math-expr-data "/")) |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1111 (setq math-expr-data (concat "u" math-expr-data)) |
40785 | 1112 (math-read-factor)) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1113 ((and (setq op (assoc math-expr-data math-expr-opers)) |
40785 | 1114 (eq (nth 2 op) -1)) |
1115 (if (consp (nth 1 op)) | |
1116 (funcall (car (nth 1 op)) op) | |
1117 (math-read-token) | |
1118 (let ((val (math-read-expr-level (nth 3 op)))) | |
1119 (cond ((eq (nth 1 op) 'ident) | |
1120 val) | |
1121 ((and (Math-numberp val) | |
1122 (equal (car op) "u-")) | |
1123 (math-neg val)) | |
1124 (t (list (nth 1 op) val)))))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1125 ((eq math-exp-token 'symbol) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1126 (let ((sym (intern math-expr-data))) |
40785 | 1127 (math-read-token) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1128 (if (equal math-expr-data calc-function-open) |
40785 | 1129 (let ((f (assq sym math-expr-function-mapping))) |
1130 (math-read-token) | |
1131 (if (consp (cdr f)) | |
1132 (funcall (car (cdr f)) f sym) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1133 (let ((args (if (or (equal math-expr-data calc-function-close) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1134 (eq math-exp-token 'end)) |
40785 | 1135 nil |
1136 (math-read-expr-list)))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1137 (if (not (or (equal math-expr-data calc-function-close) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1138 (eq math-exp-token 'end))) |
40785 | 1139 (throw 'syntax "Expected `)'")) |
1140 (math-read-token) | |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1141 (if (and (memq calc-language |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1142 calc-lang-parens-are-subscripts) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1143 args |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1144 (require 'calc-ext) |
40785 | 1145 (let ((calc-matrix-mode 'scalar)) |
1146 (math-known-matrixp | |
1147 (list 'var sym | |
1148 (intern | |
1149 (concat "var-" | |
1150 (symbol-name sym))))))) | |
1151 (math-parse-fortran-subscr sym args) | |
1152 (if f | |
1153 (setq sym (cdr f)) | |
1154 (and (= (aref (symbol-name sym) 0) ?\\) | |
1155 (< (prefix-numeric-value calc-language-option) | |
1156 0) | |
1157 (setq sym (intern (substring (symbol-name sym) | |
1158 1)))) | |
1159 (or (string-match "-" (symbol-name sym)) | |
1160 (setq sym (intern | |
1161 (concat "calcFunc-" | |
1162 (symbol-name sym)))))) | |
1163 (cons sym args))))) | |
1164 (if math-read-expr-quotes | |
1165 sym | |
1166 (let ((val (list 'var | |
1167 (intern (math-remove-dashes | |
1168 (symbol-name sym))) | |
1169 (if (string-match "-" (symbol-name sym)) | |
1170 sym | |
1171 (intern (concat "var-" | |
1172 (symbol-name sym))))))) | |
87269
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1173 (let ((v (or |
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1174 (assq (nth 1 val) math-expr-variable-mapping) |
87416
87a6da15351c
(math-to-percentsigns): Declare as function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87269
diff
changeset
|
1175 (assq (math-restore-placeholders (nth 1 val)) |
87269
59fee65281f5
(math-restore-underscores, math-string-restore-underscores):
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86929
diff
changeset
|
1176 math-expr-variable-mapping)))) |
40785 | 1177 (and v (setq val (if (consp (cdr v)) |
1178 (funcall (car (cdr v)) v val) | |
1179 (list 'var | |
1180 (intern | |
1181 (substring (symbol-name (cdr v)) | |
1182 4)) | |
1183 (cdr v)))))) | |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1184 (while (and (memq calc-language |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1185 calc-lang-brackets-are-subscripts) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1186 (equal math-expr-data "[")) |
40785 | 1187 (math-read-token) |
86929
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1188 (let ((el (math-read-expr-list))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1189 (while el |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1190 (setq val (append (list 'calcFunc-subscr val) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1191 (list (car el)))) |
edfd75871d15
(math-read-factor): Turn multiple subscripts into nested subscripts.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
86466
diff
changeset
|
1192 (setq el (cdr el)))) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1193 (if (equal math-expr-data "]") |
40785 | 1194 (math-read-token) |
1195 (throw 'syntax "Expected ']'"))) | |
1196 val))))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1197 ((eq math-exp-token 'dollar) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1198 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data)))) |
40785 | 1199 (if (>= (length calc-dollar-values) abs) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1200 (let ((num math-expr-data)) |
40785 | 1201 (math-read-token) |
1202 (setq calc-dollar-used (max calc-dollar-used num)) | |
1203 (math-check-complete (nth (1- abs) calc-dollar-values))) | |
1204 (throw 'syntax (if calc-dollar-values | |
1205 "Too many $'s" | |
1206 "$'s not allowed in this context"))))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1207 ((eq math-exp-token 'hash) |
40785 | 1208 (or calc-hashes-used |
1209 (throw 'syntax "#'s not allowed in this context")) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1210 (require 'calc-ext) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1211 (if (<= math-expr-data (length calc-arg-values)) |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1212 (let ((num math-expr-data)) |
40785 | 1213 (math-read-token) |
1214 (setq calc-hashes-used (max calc-hashes-used num)) | |
1215 (nth (1- num) calc-arg-values)) | |
1216 (throw 'syntax "Too many # arguments"))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1217 ((equal math-expr-data "(") |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1218 (let* ((exp (let ((math-exp-keep-spaces nil)) |
40785 | 1219 (math-read-token) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1220 (if (or (equal math-expr-data "\\dots") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1221 (equal math-expr-data "\\ldots")) |
40785 | 1222 '(neg (var inf var-inf)) |
1223 (math-read-expr-level 0))))) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1224 (let ((math-exp-keep-spaces nil)) |
40785 | 1225 (cond |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1226 ((equal math-expr-data ",") |
40785 | 1227 (progn |
1228 (math-read-token) | |
1229 (let ((exp2 (math-read-expr-level 0))) | |
1230 (setq exp | |
1231 (if (and exp2 (Math-realp exp) (Math-realp exp2)) | |
1232 (math-normalize (list 'cplx exp exp2)) | |
1233 (list '+ exp (list '* exp2 '(var i var-i)))))))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1234 ((equal math-expr-data ";") |
40785 | 1235 (progn |
1236 (math-read-token) | |
1237 (let ((exp2 (math-read-expr-level 0))) | |
1238 (setq exp (if (and exp2 (Math-realp exp) | |
1239 (Math-anglep exp2)) | |
1240 (math-normalize (list 'polar exp exp2)) | |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1241 (require 'calc-ext) |
40785 | 1242 (list '* exp |
1243 (list 'calcFunc-exp | |
1244 (list '* | |
1245 (math-to-radians-2 exp2) | |
1246 '(var i var-i))))))))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1247 ((or (equal math-expr-data "\\dots") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1248 (equal math-expr-data "\\ldots")) |
40785 | 1249 (progn |
1250 (math-read-token) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1251 (let ((exp2 (if (or (equal math-expr-data ")") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1252 (equal math-expr-data "]") |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1253 (eq math-exp-token 'end)) |
40785 | 1254 '(var inf var-inf) |
1255 (math-read-expr-level 0)))) | |
1256 (setq exp | |
1257 (list 'intv | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1258 (if (equal math-expr-data ")") 0 1) |
40785 | 1259 exp |
1260 exp2))))))) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1261 (if (not (or (equal math-expr-data ")") |
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1262 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv)) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1263 (eq math-exp-token 'end))) |
40785 | 1264 (throw 'syntax "Expected `)'")) |
1265 (math-read-token) | |
1266 exp)) | |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
1267 ((eq math-exp-token 'string) |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1268 (require 'calc-ext) |
40785 | 1269 (math-read-string)) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1270 ((equal math-expr-data "[") |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1271 (require 'calc-ext) |
40785 | 1272 (math-read-brackets t "]")) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1273 ((equal math-expr-data "{") |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1274 (require 'calc-ext) |
40785 | 1275 (math-read-brackets nil "}")) |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1276 ((equal math-expr-data "<") |
58611
79b3fe261527
Remove unnecessary eval-when-compile.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58569
diff
changeset
|
1277 (require 'calc-ext) |
40785 | 1278 (math-read-angle-brackets)) |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1279 (t (throw 'syntax "Expected a number"))))) |
40785 | 1280 |
58645
157fd661769f
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58611
diff
changeset
|
1281 (provide 'calc-aent) |
157fd661769f
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58611
diff
changeset
|
1282 |
93880
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1283 ;; Local variables: |
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1284 ;; generated-autoload-file: "calc-loaddefs.el" |
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1285 ;; End: |
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1286 |
c6152337e4ad
* calc/calc.el: Load "cal-loaddefs" rather than set up autoloads manually.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
1287 ;; arch-tag: 5599e45d-e51e-44bb-9a20-9f4ed8c96c32 |
41039
e65205f993f3
Style cleanup; don't put closing parens on their own line, add "foo.el
Colin Walters <walters@gnu.org>
parents:
40995
diff
changeset
|
1288 ;;; calc-aent.el ends here |