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