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