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