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