Mercurial > emacs
annotate lisp/calc/calc-aent.el @ 58158:0d53729c8f7a
(cvs-mode-checkout): New command.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 11 Nov 2004 23:45:52 +0000 |
parents | be4a8443df49 |
children | 61e76fb7d4c9 cb7f41387eb3 |
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 |
40995 | 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 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> |
49262
eee2cd777144
*** empty log message ***
Deepak Goel <deego@gnufans.org>
parents:
49261
diff
changeset
|
6 ;; Maintainers: D. Goel <deego@gnufans.org> |
eee2cd777144
*** empty log message ***
Deepak Goel <deego@gnufans.org>
parents:
49261
diff
changeset
|
7 ;; Colin Walters <walters@debian.org> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc.el. | |
31 (require 'calc) | |
32 | |
33 (require 'calc-macs) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
34 (eval-when-compile '(require calc-macs)) |
40785 | 35 |
36 (defun calc-Need-calc-aent () nil) | |
37 | |
38 | |
39 (defun calc-do-quick-calc () | |
40 (calc-check-defines) | |
41 (if (eq major-mode 'calc-mode) | |
42 (calc-algebraic-entry t) | |
43 (let (buf shortbuf) | |
44 (save-excursion | |
45 (calc-create-buffer) | |
46 (let* ((calc-command-flags nil) | |
47 (calc-dollar-values calc-quick-prev-results) | |
48 (calc-dollar-used 0) | |
49 (enable-recursive-minibuffers t) | |
50 (calc-language (if (memq calc-language '(nil big)) | |
51 'flat calc-language)) | |
52 (entry (calc-do-alg-entry "" "Quick calc: " t)) | |
53 (alg-exp (mapcar (function | |
54 (lambda (x) | |
55 (if (and (not calc-extensions-loaded) | |
56 calc-previous-alg-entry | |
57 (string-match | |
58 "\\`[-0-9._+*/^() ]+\\'" | |
59 calc-previous-alg-entry)) | |
60 (calc-normalize x) | |
61 (calc-extensions) | |
62 (math-evaluate-expr x)))) | |
63 entry))) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
64 (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
|
65 (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
|
66 (= (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
|
67 (eq (car-safe (nth 1 (car alg-exp))) 'var)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
68 (calc-extensions) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
69 (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
|
70 (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
|
71 (setq alg-exp (list (nth 2 (car alg-exp))))) |
40785 | 72 (setq calc-quick-prev-results alg-exp |
73 buf (mapconcat (function (lambda (x) | |
74 (math-format-value x 1000))) | |
75 alg-exp | |
76 " ") | |
77 shortbuf buf) | |
78 (if (and (= (length alg-exp) 1) | |
79 (memq (car-safe (car alg-exp)) '(nil bigpos bigneg)) | |
80 (< (length buf) 20) | |
81 (= calc-number-radix 10)) | |
82 (setq buf (concat buf " (" | |
83 (let ((calc-number-radix 16)) | |
84 (math-format-value (car alg-exp) 1000)) | |
85 ", " | |
86 (let ((calc-number-radix 8)) | |
87 (math-format-value (car alg-exp) 1000)) | |
88 (if (and (integerp (car alg-exp)) | |
89 (> (car alg-exp) 0) | |
90 (< (car alg-exp) 127)) | |
91 (format ", \"%c\"" (car alg-exp)) | |
92 "") | |
93 ")"))) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
94 (if (and (< (length buf) (frame-width)) (= (length entry) 1) |
40785 | 95 calc-extensions-loaded) |
96 (let ((long (concat (math-format-value (car entry) 1000) | |
97 " => " buf))) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
98 (if (<= (length long) (- (frame-width) 8)) |
40785 | 99 (setq buf long)))) |
100 (calc-handle-whys) | |
101 (message "Result: %s" buf))) | |
102 (if (eq last-command-char 10) | |
103 (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
|
104 (kill-new shortbuf))))) |
40785 | 105 |
106 (defun calc-do-calc-eval (str separator args) | |
107 (calc-check-defines) | |
108 (catch 'calc-error | |
109 (save-excursion | |
110 (calc-create-buffer) | |
111 (cond | |
112 ((and (consp str) (not (symbolp (car str)))) | |
113 (let ((calc-language nil) | |
114 (math-expr-opers math-standard-opers) | |
115 (calc-internal-prec 12) | |
116 (calc-word-size 32) | |
117 (calc-symbolic-mode nil) | |
118 (calc-matrix-mode nil) | |
119 (calc-angle-mode 'deg) | |
120 (calc-number-radix 10) | |
121 (calc-leading-zeros nil) | |
122 (calc-group-digits nil) | |
123 (calc-point-char ".") | |
124 (calc-frac-format '(":" nil)) | |
125 (calc-prefer-frac nil) | |
126 (calc-hms-format "%s@ %s' %s\"") | |
127 (calc-date-format '((H ":" mm C SS pp " ") | |
128 Www " " Mmm " " D ", " YYYY)) | |
129 (calc-float-format '(float 0)) | |
130 (calc-full-float-format '(float 0)) | |
131 (calc-complex-format nil) | |
132 (calc-matrix-just nil) | |
133 (calc-full-vectors t) | |
134 (calc-break-vectors nil) | |
135 (calc-vector-commas ",") | |
136 (calc-vector-brackets "[]") | |
137 (calc-matrix-brackets '(R O)) | |
138 (calc-complex-mode 'cplx) | |
139 (calc-infinite-mode nil) | |
140 (calc-display-strings nil) | |
141 (calc-simplify-mode nil) | |
142 (calc-display-working-message 'lots) | |
143 (strp (cdr str))) | |
144 (while strp | |
145 (set (car strp) (nth 1 strp)) | |
146 (setq strp (cdr (cdr strp)))) | |
147 (calc-do-calc-eval (car str) separator args))) | |
148 ((eq separator 'eval) | |
149 (eval str)) | |
150 ((eq separator 'macro) | |
151 (calc-extensions) | |
152 (let* ((calc-buffer (current-buffer)) | |
153 (calc-window (get-buffer-window calc-buffer)) | |
154 (save-window (selected-window))) | |
155 (if calc-window | |
156 (unwind-protect | |
157 (progn | |
158 (select-window calc-window) | |
159 (calc-execute-kbd-macro str nil (car args))) | |
160 (and (window-point save-window) | |
161 (select-window save-window))) | |
162 (save-window-excursion | |
163 (select-window (get-largest-window)) | |
164 (switch-to-buffer calc-buffer) | |
165 (calc-execute-kbd-macro str nil (car args))))) | |
166 nil) | |
167 ((eq separator 'pop) | |
168 (or (not (integerp str)) | |
169 (= str 0) | |
170 (calc-pop (min str (calc-stack-size)))) | |
171 (calc-stack-size)) | |
172 ((eq separator 'top) | |
173 (and (integerp str) | |
174 (> str 0) | |
175 (<= str (calc-stack-size)) | |
176 (math-format-value (calc-top-n str (car args)) 1000))) | |
177 ((eq separator 'rawtop) | |
178 (and (integerp str) | |
179 (> str 0) | |
180 (<= str (calc-stack-size)) | |
181 (calc-top-n str (car args)))) | |
182 (t | |
183 (let* ((calc-command-flags nil) | |
184 (calc-next-why nil) | |
185 (calc-language (if (memq calc-language '(nil big)) | |
186 'flat calc-language)) | |
187 (calc-dollar-values (mapcar | |
188 (function | |
189 (lambda (x) | |
190 (if (stringp x) | |
191 (progn | |
192 (setq x (math-read-exprs x)) | |
193 (if (eq (car-safe x) | |
194 'error) | |
195 (throw 'calc-error | |
196 (calc-eval-error | |
197 (cdr x))) | |
198 (car x))) | |
199 x))) | |
200 args)) | |
201 (calc-dollar-used 0) | |
202 (res (if (stringp str) | |
203 (math-read-exprs str) | |
204 (list str))) | |
205 buf) | |
206 (if (eq (car res) 'error) | |
207 (calc-eval-error (cdr res)) | |
208 (setq res (mapcar 'calc-normalize res)) | |
209 (and (memq 'clear-message calc-command-flags) | |
210 (message "")) | |
211 (cond ((eq separator 'pred) | |
212 (calc-extensions) | |
213 (if (= (length res) 1) | |
214 (math-is-true (car res)) | |
215 (calc-eval-error '(0 "Single value expected")))) | |
216 ((eq separator 'raw) | |
217 (if (= (length res) 1) | |
218 (car res) | |
219 (calc-eval-error '(0 "Single value expected")))) | |
220 ((eq separator 'list) | |
221 res) | |
222 ((memq separator '(num rawnum)) | |
223 (if (= (length res) 1) | |
224 (if (math-constp (car res)) | |
225 (if (eq separator 'num) | |
226 (math-format-value (car res) 1000) | |
227 (car res)) | |
228 (calc-eval-error | |
229 (list 0 | |
230 (if calc-next-why | |
231 (calc-explain-why (car calc-next-why)) | |
232 "Number expected")))) | |
233 (calc-eval-error '(0 "Single value expected")))) | |
234 ((eq separator 'push) | |
235 (calc-push-list res) | |
236 nil) | |
237 (t (while res | |
238 (setq buf (concat buf | |
239 (and buf (or separator ", ")) | |
240 (math-format-value (car res) 1000)) | |
241 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
|
242 buf))))))))) |
40785 | 243 |
244 (defun calc-eval-error (msg) | |
245 (if (and (boundp 'calc-eval-error) | |
246 calc-eval-error) | |
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 | |
275 (calc-extensions) | |
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 | |
282 (calc-record (if calc-extensions-loaded (car alg-exp) (car nvals)) | |
283 "alg'") | |
284 (calc-pop-push-record-list calc-dollar-used | |
285 (and (not (equal (car alg-exp) | |
286 (car nvals))) | |
287 calc-extensions-loaded | |
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 |
389 (defun calcAlg-enter () | |
390 (interactive) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
391 (let* ((str (minibuffer-contents)) |
40785 | 392 (exp (and (> (length str) 0) |
393 (save-excursion | |
394 (set-buffer calc-buffer) | |
395 (math-read-exprs str))))) | |
396 (if (eq (car-safe exp) 'error) | |
397 (progn | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
398 (goto-char (minibuffer-prompt-end)) |
40785 | 399 (forward-char (nth 1 exp)) |
400 (beep) | |
401 (calc-temp-minibuffer-message | |
402 (concat " [" (or (nth 2 exp) "Error") "]")) | |
403 (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
|
404 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'") |
40785 | 405 '((incomplete vec)) |
406 exp)) | |
407 (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
|
408 (exit-minibuffer)))) |
40785 | 409 |
410 (defun calcAlg-blink-matching-open () | |
411 (let ((oldpos (point)) | |
412 (blinkpos nil)) | |
413 (save-excursion | |
414 (condition-case () | |
415 (setq blinkpos (scan-sexps oldpos -1)) | |
416 (error nil))) | |
417 (if (and blinkpos | |
418 (> oldpos (1+ (point-min))) | |
419 (or (and (= (char-after (1- oldpos)) ?\)) | |
420 (= (char-after blinkpos) ?\[)) | |
421 (and (= (char-after (1- oldpos)) ?\]) | |
422 (= (char-after blinkpos) ?\())) | |
423 (save-excursion | |
424 (goto-char blinkpos) | |
425 (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)"))) | |
426 (let ((saved (aref (syntax-table) (char-after blinkpos)))) | |
427 (unwind-protect | |
428 (progn | |
429 (aset (syntax-table) (char-after blinkpos) | |
430 (+ (logand saved 255) | |
431 (lsh (char-after (1- oldpos)) 8))) | |
432 (blink-matching-open)) | |
433 (aset (syntax-table) (char-after blinkpos) saved))) | |
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
|
434 (blink-matching-open)))) |
40785 | 435 |
436 | |
437 (defun calc-alg-digit-entry () | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49262
diff
changeset
|
438 (calc-alg-entry |
40785 | 439 (cond ((eq last-command-char ?e) |
440 (if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e")) | |
441 ((eq last-command-char ?#) (format "%d#" calc-number-radix)) | |
442 ((eq last-command-char ?_) "-") | |
443 ((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
|
444 (t (char-to-string last-command-char))))) |
40785 | 445 |
446 (defun calcDigit-algebraic () | |
447 (interactive) | |
448 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'") | |
449 (calcDigit-key) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
450 (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
|
451 (exit-minibuffer))) |
40785 | 452 |
453 (defun calcDigit-edit () | |
454 (interactive) | |
455 (calc-unread-command) | |
40909
09249b7679f6
(toplevel): Require calc-macs during compilation.
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
456 (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
|
457 (exit-minibuffer)) |
40785 | 458 |
459 | |
460 ;;; Algebraic expression parsing. [Public] | |
461 | |
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
|
462 ;;; The next few variables are local to math-read-exprs (and math-read-expr) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
463 ;;; but are set in functions they call. |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
464 |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
465 (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
|
466 (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
|
467 (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
|
468 (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
|
469 (defvar 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
|
470 |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
471 (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
|
472 (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
|
473 (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
|
474 (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
|
475 math-exp-token math-expr-data) |
40785 | 476 (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
|
477 (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
|
478 (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
|
479 (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
|
480 (substring math-exp-str (+ math-exp-token 2))))) |
40785 | 481 (math-build-parse-table) |
482 (math-read-token) | |
483 (let ((val (catch 'syntax (math-read-expr-list)))) | |
484 (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
|
485 (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
|
486 (if (equal math-exp-token 'end) |
40785 | 487 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
|
488 (list 'error math-exp-old-pos "Syntax error")))))) |
40785 | 489 |
490 (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
|
491 (let* ((math-exp-keep-spaces nil) |
40785 | 492 (val (list (math-read-expr-level 0))) |
493 (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
|
494 (while (equal math-expr-data ",") |
40785 | 495 (math-read-token) |
496 (let ((rest (list (math-read-expr-level 0)))) | |
497 (setcdr last rest) | |
498 (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
|
499 val)) |
40785 | 500 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41039
diff
changeset
|
501 (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
|
502 (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
|
503 (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
|
504 (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
|
505 (defvar calc-user-token-chars nil) |
40785 | 506 |
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
|
507 (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
|
508 "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
|
509 |
40785 | 510 (defun math-build-parse-table () |
511 (let ((mtab (cdr (assq nil calc-user-parse-tables))) | |
512 (ltab (cdr (assq calc-language calc-user-parse-tables)))) | |
513 (or (and (eq mtab calc-last-main-parse-table) | |
514 (eq ltab calc-last-lang-parse-table)) | |
515 (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
|
516 (math-toks nil)) |
40785 | 517 (setq calc-user-parse-table p) |
518 (setq calc-user-token-chars nil) | |
519 (while p | |
520 (math-find-user-tokens (car (car p))) | |
521 (setq p (cdr p))) | |
522 (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
|
523 (sort (mapcar 'car math-toks) |
40785 | 524 (function (lambda (x y) |
525 (> (length x) | |
526 (length y))))) | |
527 "\\|") | |
528 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
|
529 calc-last-lang-parse-table ltab))))) |
40785 | 530 |
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
|
531 (defun math-find-user-tokens (p) |
40785 | 532 (while p |
533 (cond ((and (stringp (car p)) | |
534 (or (> (length (car p)) 1) (equal (car p) "$") | |
535 (equal (car p) "\"")) | |
536 (string-match "[^a-zA-Z0-9]" (car p))) | |
537 (let ((s (regexp-quote (car p)))) | |
538 (if (string-match "\\`[a-zA-Z0-9]" s) | |
539 (setq s (concat "\\<" s))) | |
540 (if (string-match "[a-zA-Z0-9]\\'" s) | |
541 (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
|
542 (or (assoc s math-toks) |
40785 | 543 (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
|
544 (setq math-toks (cons (list s) math-toks)) |
40785 | 545 (or (memq (aref (car p) 0) calc-user-token-chars) |
546 (setq calc-user-token-chars | |
547 (cons (aref (car p) 0) | |
548 calc-user-token-chars))))))) | |
549 ((consp (car p)) | |
550 (math-find-user-tokens (nth 1 (car p))) | |
551 (or (eq (car (car p)) '\?) | |
552 (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
|
553 (setq p (cdr p)))) |
40785 | 554 |
555 (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
|
556 (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
|
557 (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
|
558 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
|
559 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
|
560 (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
|
561 (setq math-exp-old-pos math-exp-pos) |
40785 | 562 (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
|
563 (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
|
564 (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
|
565 (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
|
566 math-expr-data " ") |
40785 | 567 (math-read-token))) |
568 ((and (memq ch calc-user-token-chars) | |
569 (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
|
570 (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
|
571 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
|
572 (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
|
573 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
|
574 math-exp-pos (match-end 0))) |
40785 | 575 ((or (and (>= ch ?a) (<= ch ?z)) |
576 (and (>= ch ?A) (<= ch ?Z))) | |
577 (string-match (if (memq calc-language '(c fortran pascal maple)) | |
578 "[a-zA-Z0-9_#]*" | |
579 "[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
|
580 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
|
581 (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
|
582 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
|
583 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
|
584 (math-match-substring math-exp-str 0))) |
40785 | 585 (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
|
586 (let ((code (assoc math-expr-data math-eqn-ignore-words))) |
40785 | 587 (cond ((null code)) |
588 ((null (cdr code)) | |
589 (math-read-token)) | |
590 ((consp (nth 1 code)) | |
591 (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
|
592 (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
|
593 (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
|
594 (car code) math-expr-data)))) |
40785 | 595 ((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
|
596 (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
|
597 math-expr-data (nth 2 code))) |
40785 | 598 (t |
599 (math-read-token) | |
600 (math-read-token)))))) | |
601 ((or (and (>= ch ?0) (<= ch ?9)) | |
602 (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
|
603 (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
|
604 math-exp-pos)) |
40785 | 605 (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
|
606 (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
|
607 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
|
608 (or (eq math-exp-pos 0) |
40785 | 609 (and (memq calc-language '(nil flat big unform |
610 tex eqn)) | |
611 (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
|
612 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
|
613 (1- math-exp-pos)))))) |
40785 | 614 (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
|
615 (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
|
616 (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
|
617 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
|
618 (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
|
619 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
|
620 math-exp-pos (match-end 0))) |
40785 | 621 ((eq ch ?\$) |
622 (if (and (eq calc-language 'pascal) | |
623 (eq (string-match | |
624 "\\(\\$[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
|
625 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
|
626 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
|
627 (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
|
628 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
|
629 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
|
630 (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
|
631 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
|
632 (setq math-expr-data (- (string-to-int (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
|
633 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
|
634 (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
|
635 (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
|
636 (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
|
637 math-exp-pos (match-end 0)))) |
40785 | 638 ((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
|
639 (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
|
640 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
|
641 (setq math-expr-data (string-to-int |
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
|
642 (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
|
643 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
|
644 (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
|
645 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
|
646 (setq math-exp-token 'hash)) |
40785 | 647 ((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
|
648 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
|
649 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
|
650 (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
|
651 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
|
652 math-exp-pos (match-end 0))) |
40785 | 653 ((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
|
654 (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
|
655 math-exp-str math-exp-pos)) |
40785 | 656 (if (eq calc-language 'eqn) |
657 (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
|
658 (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
|
659 (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
|
660 (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
|
661 (aset math-exp-str (match-end 1) ?\})) |
40785 | 662 (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
|
663 (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
|
664 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
|
665 math-exp-pos (match-end 0)))) |
40785 | 666 ((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
|
667 (< 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
|
668 (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
|
669 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
|
670 (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
|
671 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
|
672 (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
|
673 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
|
674 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
|
675 (math-match-substring math-exp-str 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
|
676 (let ((code (assoc math-expr-data math-tex-ignore-words))) |
40785 | 677 (cond ((null code)) |
678 ((null (cdr code)) | |
679 (math-read-token)) | |
680 ((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
|
681 (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
|
682 math-expr-data (nth 2 code))) |
40785 | 683 ((and (eq (nth 1 code) 'mat) |
58131
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
684 (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
|
685 (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
|
686 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
|
687 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
|
688 (let ((right (string-match "}" math-exp-str math-exp-pos))) |
40785 | 689 (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
|
690 (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
|
691 (aset math-exp-str right ?\]))))))) |
40785 | 692 ((and (= ch ?\.) (eq calc-language 'fortran) |
693 (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
|
694 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
|
695 (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
|
696 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
|
697 math-exp-pos (match-end 0))) |
40785 | 698 ((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
|
699 (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
|
700 math-exp-pos)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
701 (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
|
702 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
|
703 math-exp-pos (match-end 0))) |
40785 | 704 ((and (eq calc-language 'eqn) |
705 (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
|
706 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
|
707 math-exp-pos)) |
be4a8443df49
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58108
diff
changeset
|
708 (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
|
709 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
|
710 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
|
711 (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
|
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 (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
|
714 (if (memq (aref math-expr-data 0) '(?~ ?^)) |
40785 | 715 (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
|
716 ((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
|
717 (setq math-exp-pos (match-end 0)) |
40785 | 718 (math-read-token)) |
719 (t | |
720 (if (and (eq ch ?\{) (memq calc-language '(tex eqn))) | |
721 (setq ch ?\()) | |
722 (if (and (eq ch ?\}) (memq calc-language '(tex eqn))) | |
723 (setq ch ?\))) | |
724 (if (and (eq ch ?\&) (eq calc-language 'tex)) | |
725 (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
|
726 (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
|
727 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
|
728 math-exp-pos (1+ math-exp-pos))))))) |
40785 | 729 |
730 | |
731 (defun math-read-expr-level (exp-prec &optional exp-term) | |
732 (let* ((x (math-read-factor)) (first t) op op2) | |
733 (while (and (or (and calc-user-parse-table | |
734 (setq op (calc-check-user-syntax x exp-prec)) | |
735 (setq x op | |
736 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
|
737 (and (setq op (assoc math-expr-data math-expr-opers)) |
40785 | 738 (/= (nth 2 op) -1) |
739 (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
|
740 math-expr-data |
40785 | 741 (cdr (memq op math-expr-opers)))) |
742 (eq (= (nth 3 op) -1) | |
743 (/= (nth 3 op2) -1)) | |
744 (eq (= (nth 3 op2) -1) | |
745 (not (math-factor-after))) | |
746 (setq op op2)) | |
747 t)) | |
748 (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
|
749 (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
|
750 (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
|
751 (and (equal math-expr-data "[") |
40785 | 752 (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
|
753 (not (and math-exp-keep-spaces |
40785 | 754 (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
|
755 (or (not (setq op (assoc math-expr-data math-expr-opers))) |
40785 | 756 (/= (nth 2 op) -1)) |
757 (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
|
758 (not (eq math-exp-token 'symbol)) |
40785 | 759 (let ((p calc-user-parse-table)) |
760 (while (and p | |
761 (or (not (integerp | |
762 (car (car (car p))))) | |
763 (not (equal | |
764 (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
|
765 math-expr-data)))) |
40785 | 766 (setq p (cdr p))) |
767 (not p))) | |
768 (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
|
769 (not (and exp-term (equal math-expr-data exp-term))) |
40785 | 770 (>= (nth 2 op) exp-prec)) |
771 (if (not (equal (car op) "2x")) | |
772 (math-read-token)) | |
773 (and (memq (nth 1 op) '(sdev mod)) | |
774 (calc-extensions)) | |
775 (setq x (cond ((consp (nth 1 op)) | |
776 (funcall (car (nth 1 op)) x op)) | |
777 ((eq (nth 3 op) -1) | |
778 (if (eq (nth 1 op) 'ident) | |
779 x | |
780 (if (eq (nth 1 op) 'closing) | |
781 (if (eq (nth 2 op) exp-prec) | |
782 (progn | |
783 (setq exp-prec 1000) | |
784 x) | |
785 (throw 'syntax "Mismatched delimiters")) | |
786 (list (nth 1 op) x)))) | |
787 ((and (not first) | |
788 (memq (nth 1 op) math-alg-inequalities) | |
789 (memq (car-safe x) math-alg-inequalities)) | |
790 (calc-extensions) | |
791 (math-composite-inequalities x op)) | |
792 (t (list (nth 1 op) | |
793 x | |
794 (math-read-expr-level (nth 3 op) exp-term)))) | |
795 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
|
796 x)) |
40785 | 797 |
798 (defun calc-check-user-syntax (&optional x prec) | |
799 (let ((p calc-user-parse-table) | |
800 (matches nil) | |
801 match rule) | |
802 (while (and p | |
803 (or (not (progn | |
804 (setq rule (car (car p))) | |
805 (if x | |
806 (and (integerp (car rule)) | |
807 (>= (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
|
808 (equal math-expr-data |
40785 | 809 (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
|
810 (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
|
811 (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
|
812 (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
|
813 (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
|
814 (save-exp-data math-expr-data)) |
40785 | 815 (or (not (listp |
816 (setq matches (calc-match-user-syntax rule)))) | |
817 (let ((args (progn | |
818 (calc-extensions) | |
819 calc-arg-values)) | |
820 (conds nil) | |
821 temp) | |
822 (if x | |
823 (setq matches (cons x matches))) | |
824 (setq match (cdr (car p))) | |
825 (while (and (eq (car-safe match) | |
826 'calcFunc-condition) | |
827 (= (length match) 3)) | |
828 (setq conds (append (math-flatten-lands | |
829 (nth 2 match)) | |
830 conds) | |
831 match (nth 1 match))) | |
832 (while (and conds match) | |
833 (calc-extensions) | |
834 (cond ((eq (car-safe (car conds)) | |
835 'calcFunc-let) | |
836 (setq temp (car conds)) | |
837 (or (= (length temp) 3) | |
838 (and (= (length temp) 2) | |
839 (eq (car-safe (nth 1 temp)) | |
840 'calcFunc-assign) | |
841 (= (length (nth 1 temp)) 3) | |
842 (setq temp (nth 1 temp))) | |
843 (setq match nil)) | |
844 (setq matches (cons | |
845 (math-normalize | |
846 (math-multi-subst | |
847 (nth 2 temp) | |
848 args matches)) | |
849 matches) | |
850 args (cons (nth 1 temp) | |
851 args))) | |
852 ((and (eq (car-safe (car conds)) | |
853 'calcFunc-matches) | |
854 (= (length (car conds)) 3)) | |
855 (setq temp (calcFunc-vmatches | |
856 (math-multi-subst | |
857 (nth 1 (car conds)) | |
858 args matches) | |
859 (nth 2 (car conds)))) | |
860 (if (eq temp 0) | |
861 (setq match nil) | |
862 (while (setq temp (cdr temp)) | |
863 (setq matches (cons (nth 2 (car temp)) | |
864 matches) | |
865 args (cons (nth 1 (car temp)) | |
866 args))))) | |
867 (t | |
868 (or (math-is-true (math-simplify | |
869 (math-multi-subst | |
870 (car conds) | |
871 args matches))) | |
872 (setq match nil)))) | |
873 (setq conds (cdr conds))) | |
874 (if match | |
875 (not (setq match (math-multi-subst | |
876 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
|
877 (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
|
878 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
|
879 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
|
880 math-exp-pos save-exp-pos))))))) |
40785 | 881 (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
|
882 (and p match))) |
40785 | 883 |
884 (defun calc-match-user-syntax (p &optional term) | |
885 (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
|
886 (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
|
887 (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
|
888 (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
|
889 (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
|
890 m) |
40785 | 891 (while (and p |
892 (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
|
893 (and (equal math-expr-data (car p)) |
40785 | 894 (progn |
895 (math-read-token) | |
896 t))) | |
897 ((integerp (car p)) | |
898 (and (setq m (catch 'syntax | |
899 (math-read-expr-level | |
900 (car p) | |
901 (if (cdr p) | |
902 (if (consp (nth 1 p)) | |
903 (car (nth 1 (nth 1 p))) | |
904 (nth 1 p)) | |
905 term)))) | |
906 (not (stringp m)) | |
907 (setq matches (nconc matches (list m))))) | |
908 ((eq (car (car p)) '\?) | |
909 (setq m (calc-match-user-syntax (nth 1 (car p)))) | |
910 (or (nth 2 (car p)) | |
911 (setq matches | |
912 (nconc matches | |
913 (list | |
914 (cons 'vec (and (listp m) m)))))) | |
915 (or (listp m) (not (nth 2 (car p))) | |
916 (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
|
917 (eq math-exp-token 'end))) |
40785 | 918 (t |
919 (setq m (calc-match-user-syntax (nth 1 (car p)) | |
920 (car (nth 2 (car p))))) | |
921 (if (listp m) | |
922 (let ((vec (cons 'vec m)) | |
923 opos mm) | |
924 (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
|
925 (setq opos math-exp-pos |
40785 | 926 mm (calc-match-user-syntax |
927 (or (nth 2 (car p)) | |
928 (nth 1 (car p))) | |
929 (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
|
930 (> math-exp-pos opos)) |
40785 | 931 (setq vec (nconc vec mm))) |
932 (setq matches (nconc matches (list vec)))) | |
933 (and (eq (car (car p)) '*) | |
934 (setq matches (nconc matches (list '(vec))))))))) | |
935 (setq p (cdr p))) | |
936 (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
|
937 (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
|
938 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
|
939 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
|
940 math-expr-data save-exp-data |
40785 | 941 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
|
942 matches)) |
40785 | 943 |
944 (defconst math-alg-inequalities | |
945 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq | |
946 calcFunc-eq calcFunc-neq)) | |
947 | |
948 (defun math-remove-dashes (x) | |
949 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x) | |
950 (math-remove-dashes | |
951 (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
|
952 x)) |
40785 | 953 |
954 (defun math-restore-dashes (x) | |
955 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x) | |
956 (math-restore-dashes | |
957 (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
|
958 x)) |
40785 | 959 |
960 (defun math-read-if (cond op) | |
961 (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
|
962 (or (equal math-expr-data ":") |
40785 | 963 (throw 'syntax "Expected ':'")) |
964 (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
|
965 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op))))) |
40785 | 966 |
967 (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
|
968 (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
|
969 math-exp-old-pos math-exp-token math-expr-data) |
40785 | 970 (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
|
971 (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
|
972 (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
|
973 (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
|
974 (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
|
975 (assoc math-expr-data '(("(") ("[") ("{")))))) |
40785 | 976 |
977 (defun math-read-factor () | |
978 (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
|
979 (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
|
980 (let ((num (math-read-number math-expr-data))) |
40785 | 981 (if (not num) |
982 (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
|
983 (setq math-exp-old-pos math-exp-pos) |
40785 | 984 (throw 'syntax "Bad format"))) |
985 (math-read-token) | |
986 (if (and math-read-expr-quotes | |
987 (consp num)) | |
988 (list 'quote num) | |
989 num))) | |
990 ((and calc-user-parse-table | |
991 (setq op (calc-check-user-syntax))) | |
992 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
|
993 ((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
|
994 (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
|
995 (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
|
996 (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
|
997 (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
|
998 (setq math-expr-data (concat "u" math-expr-data)) |
40785 | 999 (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
|
1000 ((and (setq op (assoc math-expr-data math-expr-opers)) |
40785 | 1001 (eq (nth 2 op) -1)) |
1002 (if (consp (nth 1 op)) | |
1003 (funcall (car (nth 1 op)) op) | |
1004 (math-read-token) | |
1005 (let ((val (math-read-expr-level (nth 3 op)))) | |
1006 (cond ((eq (nth 1 op) 'ident) | |
1007 val) | |
1008 ((and (Math-numberp val) | |
1009 (equal (car op) "u-")) | |
1010 (math-neg val)) | |
1011 (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
|
1012 ((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
|
1013 (let ((sym (intern math-expr-data))) |
40785 | 1014 (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
|
1015 (if (equal math-expr-data calc-function-open) |
40785 | 1016 (let ((f (assq sym math-expr-function-mapping))) |
1017 (math-read-token) | |
1018 (if (consp (cdr f)) | |
1019 (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
|
1020 (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
|
1021 (eq math-exp-token 'end)) |
40785 | 1022 nil |
1023 (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
|
1024 (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
|
1025 (eq math-exp-token 'end))) |
40785 | 1026 (throw 'syntax "Expected `)'")) |
1027 (math-read-token) | |
1028 (if (and (eq calc-language 'fortran) args | |
1029 (calc-extensions) | |
1030 (let ((calc-matrix-mode 'scalar)) | |
1031 (math-known-matrixp | |
1032 (list 'var sym | |
1033 (intern | |
1034 (concat "var-" | |
1035 (symbol-name sym))))))) | |
1036 (math-parse-fortran-subscr sym args) | |
1037 (if f | |
1038 (setq sym (cdr f)) | |
1039 (and (= (aref (symbol-name sym) 0) ?\\) | |
1040 (< (prefix-numeric-value calc-language-option) | |
1041 0) | |
1042 (setq sym (intern (substring (symbol-name sym) | |
1043 1)))) | |
1044 (or (string-match "-" (symbol-name sym)) | |
1045 (setq sym (intern | |
1046 (concat "calcFunc-" | |
1047 (symbol-name sym)))))) | |
1048 (cons sym args))))) | |
1049 (if math-read-expr-quotes | |
1050 sym | |
1051 (let ((val (list 'var | |
1052 (intern (math-remove-dashes | |
1053 (symbol-name sym))) | |
1054 (if (string-match "-" (symbol-name sym)) | |
1055 sym | |
1056 (intern (concat "var-" | |
1057 (symbol-name sym))))))) | |
1058 (let ((v (assq (nth 1 val) math-expr-variable-mapping))) | |
1059 (and v (setq val (if (consp (cdr v)) | |
1060 (funcall (car (cdr v)) v val) | |
1061 (list 'var | |
1062 (intern | |
1063 (substring (symbol-name (cdr v)) | |
1064 4)) | |
1065 (cdr v)))))) | |
1066 (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
|
1067 (equal math-expr-data "[")) |
40785 | 1068 (math-read-token) |
1069 (setq val (append (list 'calcFunc-subscr val) | |
1070 (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
|
1071 (if (equal math-expr-data "]") |
40785 | 1072 (math-read-token) |
1073 (throw 'syntax "Expected ']'"))) | |
1074 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
|
1075 ((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
|
1076 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data)))) |
40785 | 1077 (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
|
1078 (let ((num math-expr-data)) |
40785 | 1079 (math-read-token) |
1080 (setq calc-dollar-used (max calc-dollar-used num)) | |
1081 (math-check-complete (nth (1- abs) calc-dollar-values))) | |
1082 (throw 'syntax (if calc-dollar-values | |
1083 "Too many $'s" | |
1084 "$'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
|
1085 ((eq math-exp-token 'hash) |
40785 | 1086 (or calc-hashes-used |
1087 (throw 'syntax "#'s not allowed in this context")) | |
1088 (calc-extensions) | |
58108
46d104e25054
(math-read-exprs, math-read-expr-list, math-read-expr-level,
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57635
diff
changeset
|
1089 (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
|
1090 (let ((num math-expr-data)) |
40785 | 1091 (math-read-token) |
1092 (setq calc-hashes-used (max calc-hashes-used num)) | |
1093 (nth (1- num) calc-arg-values)) | |
1094 (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
|
1095 ((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
|
1096 (let* ((exp (let ((math-exp-keep-spaces nil)) |
40785 | 1097 (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
|
1098 (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
|
1099 (equal math-expr-data "\\ldots")) |
40785 | 1100 '(neg (var inf var-inf)) |
1101 (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
|
1102 (let ((math-exp-keep-spaces nil)) |
40785 | 1103 (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
|
1104 ((equal math-expr-data ",") |
40785 | 1105 (progn |
1106 (math-read-token) | |
1107 (let ((exp2 (math-read-expr-level 0))) | |
1108 (setq exp | |
1109 (if (and exp2 (Math-realp exp) (Math-realp exp2)) | |
1110 (math-normalize (list 'cplx exp exp2)) | |
1111 (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
|
1112 ((equal math-expr-data ";") |
40785 | 1113 (progn |
1114 (math-read-token) | |
1115 (let ((exp2 (math-read-expr-level 0))) | |
1116 (setq exp (if (and exp2 (Math-realp exp) | |
1117 (Math-anglep exp2)) | |
1118 (math-normalize (list 'polar exp exp2)) | |
1119 (calc-extensions) | |
1120 (list '* exp | |
1121 (list 'calcFunc-exp | |
1122 (list '* | |
1123 (math-to-radians-2 exp2) | |
1124 '(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
|
1125 ((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
|
1126 (equal math-expr-data "\\ldots")) |
40785 | 1127 (progn |
1128 (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
|
1129 (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
|
1130 (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
|
1131 (eq math-exp-token 'end)) |
40785 | 1132 '(var inf var-inf) |
1133 (math-read-expr-level 0)))) | |
1134 (setq exp | |
1135 (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
|
1136 (if (equal math-expr-data ")") 0 1) |
40785 | 1137 exp |
1138 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
|
1139 (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
|
1140 (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
|
1141 (eq math-exp-token 'end))) |
40785 | 1142 (throw 'syntax "Expected `)'")) |
1143 (math-read-token) | |
1144 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
|
1145 ((eq math-exp-token 'string) |
40785 | 1146 (calc-extensions) |
1147 (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
|
1148 ((equal math-expr-data "[") |
40785 | 1149 (calc-extensions) |
1150 (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
|
1151 ((equal math-expr-data "{") |
40785 | 1152 (calc-extensions) |
1153 (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
|
1154 ((equal math-expr-data "<") |
40785 | 1155 (calc-extensions) |
1156 (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
|
1157 (t (throw 'syntax "Expected a number"))))) |
40785 | 1158 |
52401 | 1159 ;;; 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
|
1160 ;;; calc-aent.el ends here |