aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2004-11-11 05:48:50 +0000
committerJay Belanger2004-11-11 05:48:50 +0000
commit3cedbf72177e9126af44caa02be0ccd27a5cd6bc (patch)
tree95191f9878808fc4db9e363cd1f9af7d5f11f68e
parent32a0479a9d9bffd3c1a8e29b5e682669ce38073a (diff)
downloademacs-3cedbf72177e9126af44caa02be0ccd27a5cd6bc.tar.gz
emacs-3cedbf72177e9126af44caa02be0ccd27a5cd6bc.zip
(calc-do-quick-calc): Use kill-new to append string to kill-ring.
(calc-alg-exp, math-toks, math-exp-pos,math-exp-old-pos) (math-exp-token, math-exp-keep-spaces, math-exp-str): New variables. (calc-do-alg-entry, calcAlg-equals, calcAlg-edit, calcAlg-enter): Use declared variable calc-alg-exp. (math-build-parse-table, math-find-user-token): Use declared variable math-toks. (math-read-exprs, math-read-token, calc-check-user-syntax, calc-match-user-syntax, match-factor-after, math-read-factor): Use declared variables math-exp-pos math-exp-old-pos. (math-read-exprs, math-read-token, math-read-expr-level) (calc-check-user-syntax, calc-match-user-syntax, match-factor-after) (math-read-factor): Use declared variable math-exp-token. (math-read-exprs, math-read-expr-list, math-read-token, math-read-factor): Use declared variable math-exp-keep-spaces. (math-read-exprs, math-read-token): Use declared variable math-exp-str. (calc-match-user-syntax): Made m a local variable.
-rw-r--r--lisp/calc/calc-aent.el335
1 files changed, 177 insertions, 158 deletions
diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el
index fef561742dc..182b3b0635c 100644
--- a/lisp/calc/calc-aent.el
+++ b/lisp/calc/calc-aent.el
@@ -101,10 +101,7 @@
101 (message "Result: %s" buf))) 101 (message "Result: %s" buf)))
102 (if (eq last-command-char 10) 102 (if (eq last-command-char 10)
103 (insert shortbuf) 103 (insert shortbuf)
104 (setq kill-ring (cons shortbuf kill-ring)) 104 (kill-new shortbuf)))))
105 (when (> (length kill-ring) kill-ring-max)
106 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
107 (setq kill-ring-yank-pointer kill-ring)))))
108 105
109(defun calc-do-calc-eval (str separator args) 106(defun calc-do-calc-eval (str separator args)
110 (calc-check-defines) 107 (calc-check-defines)
@@ -301,10 +298,12 @@
301(defvar calc-alg-ent-esc-map nil 298(defvar calc-alg-ent-esc-map nil
302 "The keymap used for escapes in algebraic entry.") 299 "The keymap used for escapes in algebraic entry.")
303 300
301(defvar calc-alg-exp)
302
304(defun calc-do-alg-entry (&optional initial prompt no-normalize) 303(defun calc-do-alg-entry (&optional initial prompt no-normalize)
305 (let* ((calc-buffer (current-buffer)) 304 (let* ((calc-buffer (current-buffer))
306 (blink-paren-function 'calcAlg-blink-matching-open) 305 (blink-paren-function 'calcAlg-blink-matching-open)
307 (alg-exp 'error)) 306 (calc-alg-exp 'error))
308 (unless calc-alg-ent-map 307 (unless calc-alg-ent-map
309 (setq calc-alg-ent-map (copy-keymap minibuffer-local-map)) 308 (setq calc-alg-ent-map (copy-keymap minibuffer-local-map))
310 (define-key calc-alg-ent-map "'" 'calcAlg-previous) 309 (define-key calc-alg-ent-map "'" 'calcAlg-previous)
@@ -328,13 +327,13 @@
328 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ") 327 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
329 (or initial "") 328 (or initial "")
330 calc-alg-ent-map nil))) 329 calc-alg-ent-map nil)))
331 (when (eq alg-exp 'error) 330 (when (eq calc-alg-exp 'error)
332 (when (eq (car-safe (setq alg-exp (math-read-exprs buf))) 'error) 331 (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error)
333 (setq alg-exp nil))) 332 (setq calc-alg-exp nil)))
334 (setq calc-aborted-prefix "alg'") 333 (setq calc-aborted-prefix "alg'")
335 (or no-normalize 334 (or no-normalize
336 (and alg-exp (setq alg-exp (mapcar 'calc-normalize alg-exp)))) 335 (and calc-alg-exp (setq calc-alg-exp (mapcar 'calc-normalize calc-alg-exp))))
337 alg-exp))) 336 calc-alg-exp)))
338 337
339(defun calcAlg-plus-minus () 338(defun calcAlg-plus-minus ()
340 (interactive) 339 (interactive)
@@ -364,8 +363,8 @@
364 (interactive) 363 (interactive)
365 (unwind-protect 364 (unwind-protect
366 (calcAlg-enter) 365 (calcAlg-enter)
367 (if (consp alg-exp) 366 (if (consp calc-alg-exp)
368 (progn (setq prefix-arg (length alg-exp)) 367 (progn (setq prefix-arg (length calc-alg-exp))
369 (calc-unread-command ?=))))) 368 (calc-unread-command ?=)))))
370 369
371(defun calcAlg-escape () 370(defun calcAlg-escape ()
@@ -383,8 +382,8 @@
383 (calc-minibuffer-contains 382 (calc-minibuffer-contains
384 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'")) 383 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'"))
385 (insert "`") 384 (insert "`")
386 (setq alg-exp (minibuffer-contents)) 385 (setq calc-alg-exp (minibuffer-contents))
387 (and (> (length alg-exp) 0) (setq calc-previous-alg-entry alg-exp)) 386 (and (> (length calc-alg-exp) 0) (setq calc-previous-alg-entry calc-alg-exp))
388 (exit-minibuffer))) 387 (exit-minibuffer)))
389 388
390(defun calcAlg-enter () 389(defun calcAlg-enter ()
@@ -402,7 +401,7 @@
402 (calc-temp-minibuffer-message 401 (calc-temp-minibuffer-message
403 (concat " [" (or (nth 2 exp) "Error") "]")) 402 (concat " [" (or (nth 2 exp) "Error") "]"))
404 (calc-clear-unread-commands)) 403 (calc-clear-unread-commands))
405 (setq alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'") 404 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'")
406 '((incomplete vec)) 405 '((incomplete vec))
407 exp)) 406 exp))
408 (and (> (length str) 0) (setq calc-previous-alg-entry str)) 407 (and (> (length str) 0) (setq calc-previous-alg-entry str))
@@ -460,27 +459,36 @@
460 459
461;;; Algebraic expression parsing. [Public] 460;;; Algebraic expression parsing. [Public]
462 461
463(defun math-read-exprs (exp-str) 462;;; The next few variables are local to math-read-exprs (and math-read-expr)
464 (let ((exp-pos 0) 463;;; but are set in functions they call.
465 (exp-old-pos 0) 464
466 (exp-keep-spaces nil) 465(defvar math-exp-pos)
467 exp-token math-expr-data) 466(defvar math-exp-str)
467(defvar math-exp-old-pos)
468(defvar math-exp-token)
469(defvar math-exp-keep-spaces)
470
471(defun math-read-exprs (math-exp-str)
472 (let ((math-exp-pos 0)
473 (math-exp-old-pos 0)
474 (math-exp-keep-spaces nil)
475 math-exp-token math-expr-data)
468 (if calc-language-input-filter 476 (if calc-language-input-filter
469 (setq exp-str (funcall calc-language-input-filter exp-str))) 477 (setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
470 (while (setq exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" exp-str)) 478 (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
471 (setq exp-str (concat (substring exp-str 0 exp-token) "\\dots" 479 (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots"
472 (substring exp-str (+ exp-token 2))))) 480 (substring math-exp-str (+ math-exp-token 2)))))
473 (math-build-parse-table) 481 (math-build-parse-table)
474 (math-read-token) 482 (math-read-token)
475 (let ((val (catch 'syntax (math-read-expr-list)))) 483 (let ((val (catch 'syntax (math-read-expr-list))))
476 (if (stringp val) 484 (if (stringp val)
477 (list 'error exp-old-pos val) 485 (list 'error math-exp-old-pos val)
478 (if (equal exp-token 'end) 486 (if (equal math-exp-token 'end)
479 val 487 val
480 (list 'error exp-old-pos "Syntax error")))))) 488 (list 'error math-exp-old-pos "Syntax error"))))))
481 489
482(defun math-read-expr-list () 490(defun math-read-expr-list ()
483 (let* ((exp-keep-spaces nil) 491 (let* ((math-exp-keep-spaces nil)
484 (val (list (math-read-expr-level 0))) 492 (val (list (math-read-expr-level 0)))
485 (last val)) 493 (last val))
486 (while (equal math-expr-data ",") 494 (while (equal math-expr-data ",")
@@ -496,20 +504,23 @@
496(defvar calc-user-tokens nil) 504(defvar calc-user-tokens nil)
497(defvar calc-user-token-chars nil) 505(defvar calc-user-token-chars nil)
498 506
507(defvar math-toks nil
508 "Tokens to pass between math-build-parse-table and math-find-user-tokens.")
509
499(defun math-build-parse-table () 510(defun math-build-parse-table ()
500 (let ((mtab (cdr (assq nil calc-user-parse-tables))) 511 (let ((mtab (cdr (assq nil calc-user-parse-tables)))
501 (ltab (cdr (assq calc-language calc-user-parse-tables)))) 512 (ltab (cdr (assq calc-language calc-user-parse-tables))))
502 (or (and (eq mtab calc-last-main-parse-table) 513 (or (and (eq mtab calc-last-main-parse-table)
503 (eq ltab calc-last-lang-parse-table)) 514 (eq ltab calc-last-lang-parse-table))
504 (let ((p (append mtab ltab)) 515 (let ((p (append mtab ltab))
505 (toks nil)) 516 (math-toks nil))
506 (setq calc-user-parse-table p) 517 (setq calc-user-parse-table p)
507 (setq calc-user-token-chars nil) 518 (setq calc-user-token-chars nil)
508 (while p 519 (while p
509 (math-find-user-tokens (car (car p))) 520 (math-find-user-tokens (car (car p)))
510 (setq p (cdr p))) 521 (setq p (cdr p)))
511 (setq calc-user-tokens (mapconcat 'identity 522 (setq calc-user-tokens (mapconcat 'identity
512 (sort (mapcar 'car toks) 523 (sort (mapcar 'car math-toks)
513 (function (lambda (x y) 524 (function (lambda (x y)
514 (> (length x) 525 (> (length x)
515 (length y))))) 526 (length y)))))
@@ -517,7 +528,7 @@
517 calc-last-main-parse-table mtab 528 calc-last-main-parse-table mtab
518 calc-last-lang-parse-table ltab))))) 529 calc-last-lang-parse-table ltab)))))
519 530
520(defun math-find-user-tokens (p) ; uses "toks" 531(defun math-find-user-tokens (p)
521 (while p 532 (while p
522 (cond ((and (stringp (car p)) 533 (cond ((and (stringp (car p))
523 (or (> (length (car p)) 1) (equal (car p) "$") 534 (or (> (length (car p)) 1) (equal (car p) "$")
@@ -528,9 +539,9 @@
528 (setq s (concat "\\<" s))) 539 (setq s (concat "\\<" s)))
529 (if (string-match "[a-zA-Z0-9]\\'" s) 540 (if (string-match "[a-zA-Z0-9]\\'" s)
530 (setq s (concat s "\\>"))) 541 (setq s (concat s "\\>")))
531 (or (assoc s toks) 542 (or (assoc s math-toks)
532 (progn 543 (progn
533 (setq toks (cons (list s) toks)) 544 (setq math-toks (cons (list s) math-toks))
534 (or (memq (aref (car p) 0) calc-user-token-chars) 545 (or (memq (aref (car p) 0) calc-user-token-chars)
535 (setq calc-user-token-chars 546 (setq calc-user-token-chars
536 (cons (aref (car p) 0) 547 (cons (aref (car p) 0)
@@ -542,35 +553,35 @@
542 (setq p (cdr p)))) 553 (setq p (cdr p))))
543 554
544(defun math-read-token () 555(defun math-read-token ()
545 (if (>= exp-pos (length exp-str)) 556 (if (>= math-exp-pos (length math-exp-str))
546 (setq exp-old-pos exp-pos 557 (setq math-exp-old-pos math-exp-pos
547 exp-token 'end 558 math-exp-token 'end
548 math-expr-data "\000") 559 math-expr-data "\000")
549 (let ((ch (aref exp-str exp-pos))) 560 (let ((ch (aref math-exp-str math-exp-pos)))
550 (setq exp-old-pos exp-pos) 561 (setq math-exp-old-pos math-exp-pos)
551 (cond ((memq ch '(32 10 9)) 562 (cond ((memq ch '(32 10 9))
552 (setq exp-pos (1+ exp-pos)) 563 (setq math-exp-pos (1+ math-exp-pos))
553 (if exp-keep-spaces 564 (if math-exp-keep-spaces
554 (setq exp-token 'space 565 (setq math-exp-token 'space
555 math-expr-data " ") 566 math-expr-data " ")
556 (math-read-token))) 567 (math-read-token)))
557 ((and (memq ch calc-user-token-chars) 568 ((and (memq ch calc-user-token-chars)
558 (let ((case-fold-search nil)) 569 (let ((case-fold-search nil))
559 (eq (string-match calc-user-tokens exp-str exp-pos) 570 (eq (string-match calc-user-tokens math-exp-str math-exp-pos)
560 exp-pos))) 571 math-exp-pos)))
561 (setq exp-token 'punc 572 (setq math-exp-token 'punc
562 math-expr-data (math-match-substring exp-str 0) 573 math-expr-data (math-match-substring math-exp-str 0)
563 exp-pos (match-end 0))) 574 math-exp-pos (match-end 0)))
564 ((or (and (>= ch ?a) (<= ch ?z)) 575 ((or (and (>= ch ?a) (<= ch ?z))
565 (and (>= ch ?A) (<= ch ?Z))) 576 (and (>= ch ?A) (<= ch ?Z)))
566 (string-match (if (memq calc-language '(c fortran pascal maple)) 577 (string-match (if (memq calc-language '(c fortran pascal maple))
567 "[a-zA-Z0-9_#]*" 578 "[a-zA-Z0-9_#]*"
568 "[a-zA-Z0-9'#]*") 579 "[a-zA-Z0-9'#]*")
569 exp-str exp-pos) 580 math-exp-str math-exp-pos)
570 (setq exp-token 'symbol 581 (setq math-exp-token 'symbol
571 exp-pos (match-end 0) 582 math-exp-pos (match-end 0)
572 math-expr-data (math-restore-dashes 583 math-expr-data (math-restore-dashes
573 (math-match-substring exp-str 0))) 584 (math-match-substring math-exp-str 0)))
574 (if (eq calc-language 'eqn) 585 (if (eq calc-language 'eqn)
575 (let ((code (assoc math-expr-data math-eqn-ignore-words))) 586 (let ((code (assoc math-expr-data math-eqn-ignore-words)))
576 (cond ((null code)) 587 (cond ((null code))
@@ -582,121 +593,128 @@
582 (setq math-expr-data (format "%s %s" 593 (setq math-expr-data (format "%s %s"
583 (car code) math-expr-data)))) 594 (car code) math-expr-data))))
584 ((eq (nth 1 code) 'punc) 595 ((eq (nth 1 code) 'punc)
585 (setq exp-token 'punc 596 (setq math-exp-token 'punc
586 math-expr-data (nth 2 code))) 597 math-expr-data (nth 2 code)))
587 (t 598 (t
588 (math-read-token) 599 (math-read-token)
589 (math-read-token)))))) 600 (math-read-token))))))
590 ((or (and (>= ch ?0) (<= ch ?9)) 601 ((or (and (>= ch ?0) (<= ch ?9))
591 (and (eq ch '?\.) 602 (and (eq ch '?\.)
592 (eq (string-match "\\.[0-9]" exp-str exp-pos) exp-pos)) 603 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos)
604 math-exp-pos))
593 (and (eq ch '?_) 605 (and (eq ch '?_)
594 (eq (string-match "_\\.?[0-9]" exp-str exp-pos) exp-pos) 606 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos)
595 (or (eq exp-pos 0) 607 math-exp-pos)
608 (or (eq math-exp-pos 0)
596 (and (memq calc-language '(nil flat big unform 609 (and (memq calc-language '(nil flat big unform
597 tex eqn)) 610 tex eqn))
598 (eq (string-match "[^])}\"a-zA-Z0-9'$]_" 611 (eq (string-match "[^])}\"a-zA-Z0-9'$]_"
599 exp-str (1- exp-pos)) 612 math-exp-str (1- math-exp-pos))
600 (1- exp-pos)))))) 613 (1- math-exp-pos))))))
601 (or (and (eq calc-language 'c) 614 (or (and (eq calc-language 'c)
602 (string-match "0[xX][0-9a-fA-F]+" exp-str exp-pos)) 615 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
603 (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]+\\)?\"?\\)?" exp-str exp-pos)) 616 (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\(0*\\([2-9]\\|1[0-4]\\)\\(#\\|\\^\\^\\)[0-9a-dA-D.]+[eE][-+_]?[0-9]+\\|0*\\([2-9]\\|[0-2][0-9]\\|3[0-6]\\)\\(#\\|\\^\\^\\)[0-9a-zA-Z:.]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?"
604 (setq exp-token 'number 617 math-exp-str math-exp-pos))
605 math-expr-data (math-match-substring exp-str 0) 618 (setq math-exp-token 'number
606 exp-pos (match-end 0))) 619 math-expr-data (math-match-substring math-exp-str 0)
620 math-exp-pos (match-end 0)))
607 ((eq ch ?\$) 621 ((eq ch ?\$)
608 (if (and (eq calc-language 'pascal) 622 (if (and (eq calc-language 'pascal)
609 (eq (string-match 623 (eq (string-match
610 "\\(\\$[0-9a-fA-F]+\\)\\($\\|[^0-9a-zA-Z]\\)" 624 "\\(\\$[0-9a-fA-F]+\\)\\($\\|[^0-9a-zA-Z]\\)"
611 exp-str exp-pos) 625 math-exp-str math-exp-pos)
612 exp-pos)) 626 math-exp-pos))
613 (setq exp-token 'number 627 (setq math-exp-token 'number
614 math-expr-data (math-match-substring exp-str 1) 628 math-expr-data (math-match-substring math-exp-str 1)
615 exp-pos (match-end 1)) 629 math-exp-pos (match-end 1))
616 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" exp-str exp-pos) 630 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
617 exp-pos) 631 math-exp-pos)
618 (setq math-expr-data (- (string-to-int (math-match-substring 632 (setq math-expr-data (- (string-to-int (math-match-substring
619 exp-str 1)))) 633 math-exp-str 1))))
620 (string-match "\\$+" exp-str exp-pos) 634 (string-match "\\$+" math-exp-str math-exp-pos)
621 (setq math-expr-data (- (match-end 0) (match-beginning 0)))) 635 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
622 (setq exp-token 'dollar 636 (setq math-exp-token 'dollar
623 exp-pos (match-end 0)))) 637 math-exp-pos (match-end 0))))
624 ((eq ch ?\#) 638 ((eq ch ?\#)
625 (if (eq (string-match "#\\([1-9][0-9]*\\)" exp-str exp-pos) 639 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
626 exp-pos) 640 math-exp-pos)
627 (setq math-expr-data (string-to-int 641 (setq math-expr-data (string-to-int
628 (math-match-substring exp-str 1)) 642 (math-match-substring math-exp-str 1))
629 exp-pos (match-end 0)) 643 math-exp-pos (match-end 0))
630 (setq math-expr-data 1 644 (setq math-expr-data 1
631 exp-pos (1+ exp-pos))) 645 math-exp-pos (1+ math-exp-pos)))
632 (setq exp-token 'hash)) 646 (setq math-exp-token 'hash))
633 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>" 647 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>"
634 exp-str exp-pos) 648 math-exp-str math-exp-pos)
635 exp-pos) 649 math-exp-pos)
636 (setq exp-token 'punc 650 (setq math-exp-token 'punc
637 math-expr-data (math-match-substring exp-str 0) 651 math-expr-data (math-match-substring math-exp-str 0)
638 exp-pos (match-end 0))) 652 math-exp-pos (match-end 0)))
639 ((and (eq ch ?\") 653 ((and (eq ch ?\")
640 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)" exp-str exp-pos)) 654 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
655 math-exp-str math-exp-pos))
641 (if (eq calc-language 'eqn) 656 (if (eq calc-language 'eqn)
642 (progn 657 (progn
643 (setq exp-str (copy-sequence exp-str)) 658 (setq math-exp-str (copy-sequence math-exp-str))
644 (aset exp-str (match-beginning 1) ?\{) 659 (aset math-exp-str (match-beginning 1) ?\{)
645 (if (< (match-end 1) (length exp-str)) 660 (if (< (match-end 1) (length math-exp-str))
646 (aset exp-str (match-end 1) ?\})) 661 (aset math-exp-str (match-end 1) ?\}))
647 (math-read-token)) 662 (math-read-token))
648 (setq exp-token 'string 663 (setq math-exp-token 'string
649 math-expr-data (math-match-substring exp-str 1) 664 math-expr-data (math-match-substring math-exp-str 1)
650 exp-pos (match-end 0)))) 665 math-exp-pos (match-end 0))))
651 ((and (= ch ?\\) (eq calc-language 'tex) 666 ((and (= ch ?\\) (eq calc-language 'tex)
652 (< exp-pos (1- (length exp-str)))) 667 (< math-exp-pos (1- (length math-exp-str))))
653 (or (string-match "\\\\hbox *{\\([a-zA-Z0-9]+\\)}" exp-str exp-pos) 668 (or (string-match "\\\\hbox *{\\([a-zA-Z0-9]+\\)}"
654 (string-match "\\(\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\)" exp-str exp-pos)) 669 math-exp-str math-exp-pos)
655 (setq exp-token 'symbol 670 (string-match "\\(\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\)"
656 exp-pos (match-end 0) 671 math-exp-str math-exp-pos))
672 (setq math-exp-token 'symbol
673 math-exp-pos (match-end 0)
657 math-expr-data (math-restore-dashes 674 math-expr-data (math-restore-dashes
658 (math-match-substring exp-str 1))) 675 (math-match-substring math-exp-str 1)))
659 (let ((code (assoc math-expr-data math-tex-ignore-words))) 676 (let ((code (assoc math-expr-data math-tex-ignore-words)))
660 (cond ((null code)) 677 (cond ((null code))
661 ((null (cdr code)) 678 ((null (cdr code))
662 (math-read-token)) 679 (math-read-token))
663 ((eq (nth 1 code) 'punc) 680 ((eq (nth 1 code) 'punc)
664 (setq exp-token 'punc 681 (setq math-exp-token 'punc
665 math-expr-data (nth 2 code))) 682 math-expr-data (nth 2 code)))
666 ((and (eq (nth 1 code) 'mat) 683 ((and (eq (nth 1 code) 'mat)
667 (string-match " *{" exp-str exp-pos)) 684 (string-match " *{" math-exp-str math-exp-pos))
668 (setq exp-pos (match-end 0) 685 (setq math-exp-pos (match-end 0)
669 exp-token 'punc 686 math-exp-token 'punc
670 math-expr-data "[") 687 math-expr-data "[")
671 (let ((right (string-match "}" exp-str exp-pos))) 688 (let ((right (string-match "}" math-exp-str math-exp-pos)))
672 (and right 689 (and right
673 (setq exp-str (copy-sequence exp-str)) 690 (setq math-exp-str (copy-sequence math-exp-str))
674 (aset exp-str right ?\]))))))) 691 (aset math-exp-str right ?\])))))))
675 ((and (= ch ?\.) (eq calc-language 'fortran) 692 ((and (= ch ?\.) (eq calc-language 'fortran)
676 (eq (string-match "\\.[a-zA-Z][a-zA-Z][a-zA-Z]?\\." 693 (eq (string-match "\\.[a-zA-Z][a-zA-Z][a-zA-Z]?\\."
677 exp-str exp-pos) exp-pos)) 694 math-exp-str math-exp-pos) math-exp-pos))
678 (setq exp-token 'punc 695 (setq math-exp-token 'punc
679 math-expr-data (upcase (math-match-substring exp-str 0)) 696 math-expr-data (upcase (math-match-substring math-exp-str 0))
680 exp-pos (match-end 0))) 697 math-exp-pos (match-end 0)))
681 ((and (eq calc-language 'math) 698 ((and (eq calc-language 'math)
682 (eq (string-match "\\[\\[\\|->\\|:>" exp-str exp-pos) 699 (eq (string-match "\\[\\[\\|->\\|:>" math-exp-str math-exp-pos)
683 exp-pos)) 700 math-exp-pos))
684 (setq exp-token 'punc 701 (setq math-exp-token 'punc
685 math-expr-data (math-match-substring exp-str 0) 702 math-expr-data (math-match-substring math-exp-str 0)
686 exp-pos (match-end 0))) 703 math-exp-pos (match-end 0)))
687 ((and (eq calc-language 'eqn) 704 ((and (eq calc-language 'eqn)
688 (eq (string-match "->\\|<-\\|+-\\|\\\\dots\\|~\\|\\^" 705 (eq (string-match "->\\|<-\\|+-\\|\\\\dots\\|~\\|\\^"
689 exp-str exp-pos) 706 math-exp-str math-exp-pos)
690 exp-pos)) 707 math-exp-pos))
691 (setq exp-token 'punc 708 (setq math-exp-token 'punc
692 math-expr-data (math-match-substring exp-str 0) 709 math-expr-data (math-match-substring math-exp-str 0)
693 exp-pos (match-end 0)) 710 math-exp-pos (match-end 0))
694 (and (eq (string-match "\\\\dots\\." exp-str exp-pos) exp-pos) 711 (and (eq (string-match "\\\\dots\\." math-exp-str math-exp-pos)
695 (setq exp-pos (match-end 0))) 712 math-exp-pos)
713 (setq math-exp-pos (match-end 0)))
696 (if (memq (aref math-expr-data 0) '(?~ ?^)) 714 (if (memq (aref math-expr-data 0) '(?~ ?^))
697 (math-read-token))) 715 (math-read-token)))
698 ((eq (string-match "%%.*$" exp-str exp-pos) exp-pos) 716 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos)
699 (setq exp-pos (match-end 0)) 717 (setq math-exp-pos (match-end 0))
700 (math-read-token)) 718 (math-read-token))
701 (t 719 (t
702 (if (and (eq ch ?\{) (memq calc-language '(tex eqn))) 720 (if (and (eq ch ?\{) (memq calc-language '(tex eqn)))
@@ -705,9 +723,9 @@
705 (setq ch ?\))) 723 (setq ch ?\)))
706 (if (and (eq ch ?\&) (eq calc-language 'tex)) 724 (if (and (eq ch ?\&) (eq calc-language 'tex))
707 (setq ch ?\,)) 725 (setq ch ?\,))
708 (setq exp-token 'punc 726 (setq math-exp-token 'punc
709 math-expr-data (char-to-string ch) 727 math-expr-data (char-to-string ch)
710 exp-pos (1+ exp-pos))))))) 728 math-exp-pos (1+ math-exp-pos)))))))
711 729
712 730
713(defun math-read-expr-level (exp-prec &optional exp-term) 731(defun math-read-expr-level (exp-prec &optional exp-term)
@@ -728,16 +746,16 @@
728 (setq op op2)) 746 (setq op op2))
729 t)) 747 t))
730 (and (or (eq (nth 2 op) -1) 748 (and (or (eq (nth 2 op) -1)
731 (memq exp-token '(symbol number dollar hash)) 749 (memq math-exp-token '(symbol number dollar hash))
732 (equal math-expr-data "(") 750 (equal math-expr-data "(")
733 (and (equal math-expr-data "[") 751 (and (equal math-expr-data "[")
734 (not (eq calc-language 'math)) 752 (not (eq calc-language 'math))
735 (not (and exp-keep-spaces 753 (not (and math-exp-keep-spaces
736 (eq (car-safe x) 'vec))))) 754 (eq (car-safe x) 'vec)))))
737 (or (not (setq op (assoc math-expr-data math-expr-opers))) 755 (or (not (setq op (assoc math-expr-data math-expr-opers)))
738 (/= (nth 2 op) -1)) 756 (/= (nth 2 op) -1))
739 (or (not calc-user-parse-table) 757 (or (not calc-user-parse-table)
740 (not (eq exp-token 'symbol)) 758 (not (eq math-exp-token 'symbol))
741 (let ((p calc-user-parse-table)) 759 (let ((p calc-user-parse-table))
742 (while (and p 760 (while (and p
743 (or (not (integerp 761 (or (not (integerp
@@ -790,9 +808,9 @@
790 (equal math-expr-data 808 (equal math-expr-data
791 (car (setq rule (cdr rule))))) 809 (car (setq rule (cdr rule)))))
792 (equal math-expr-data (car rule))))) 810 (equal math-expr-data (car rule)))))
793 (let ((save-exp-pos exp-pos) 811 (let ((save-exp-pos math-exp-pos)
794 (save-exp-old-pos exp-old-pos) 812 (save-exp-old-pos math-exp-old-pos)
795 (save-exp-token exp-token) 813 (save-exp-token math-exp-token)
796 (save-exp-data math-expr-data)) 814 (save-exp-data math-expr-data))
797 (or (not (listp 815 (or (not (listp
798 (setq matches (calc-match-user-syntax rule)))) 816 (setq matches (calc-match-user-syntax rule))))
@@ -856,19 +874,20 @@
856 (if match 874 (if match
857 (not (setq match (math-multi-subst 875 (not (setq match (math-multi-subst
858 match args matches))) 876 match args matches)))
859 (setq exp-old-pos save-exp-old-pos 877 (setq math-exp-old-pos save-exp-old-pos
860 exp-token save-exp-token 878 math-exp-token save-exp-token
861 math-expr-data save-exp-data 879 math-expr-data save-exp-data
862 exp-pos save-exp-pos))))))) 880 math-exp-pos save-exp-pos)))))))
863 (setq p (cdr p))) 881 (setq p (cdr p)))
864 (and p match))) 882 (and p match)))
865 883
866(defun calc-match-user-syntax (p &optional term) 884(defun calc-match-user-syntax (p &optional term)
867 (let ((matches nil) 885 (let ((matches nil)
868 (save-exp-pos exp-pos) 886 (save-exp-pos math-exp-pos)
869 (save-exp-old-pos exp-old-pos) 887 (save-exp-old-pos math-exp-old-pos)
870 (save-exp-token exp-token) 888 (save-exp-token math-exp-token)
871 (save-exp-data math-expr-data)) 889 (save-exp-data math-expr-data)
890 m)
872 (while (and p 891 (while (and p
873 (cond ((stringp (car p)) 892 (cond ((stringp (car p))
874 (and (equal math-expr-data (car p)) 893 (and (equal math-expr-data (car p))
@@ -895,7 +914,7 @@
895 (cons 'vec (and (listp m) m)))))) 914 (cons 'vec (and (listp m) m))))))
896 (or (listp m) (not (nth 2 (car p))) 915 (or (listp m) (not (nth 2 (car p)))
897 (not (eq (aref (car (nth 2 (car p))) 0) ?\$)) 916 (not (eq (aref (car (nth 2 (car p))) 0) ?\$))
898 (eq exp-token 'end))) 917 (eq math-exp-token 'end)))
899 (t 918 (t
900 (setq m (calc-match-user-syntax (nth 1 (car p)) 919 (setq m (calc-match-user-syntax (nth 1 (car p))
901 (car (nth 2 (car p))))) 920 (car (nth 2 (car p)))))
@@ -903,21 +922,21 @@
903 (let ((vec (cons 'vec m)) 922 (let ((vec (cons 'vec m))
904 opos mm) 923 opos mm)
905 (while (and (listp 924 (while (and (listp
906 (setq opos exp-pos 925 (setq opos math-exp-pos
907 mm (calc-match-user-syntax 926 mm (calc-match-user-syntax
908 (or (nth 2 (car p)) 927 (or (nth 2 (car p))
909 (nth 1 (car p))) 928 (nth 1 (car p)))
910 (car (nth 2 (car p)))))) 929 (car (nth 2 (car p))))))
911 (> exp-pos opos)) 930 (> math-exp-pos opos))
912 (setq vec (nconc vec mm))) 931 (setq vec (nconc vec mm)))
913 (setq matches (nconc matches (list vec)))) 932 (setq matches (nconc matches (list vec))))
914 (and (eq (car (car p)) '*) 933 (and (eq (car (car p)) '*)
915 (setq matches (nconc matches (list '(vec))))))))) 934 (setq matches (nconc matches (list '(vec)))))))))
916 (setq p (cdr p))) 935 (setq p (cdr p)))
917 (if p 936 (if p
918 (setq exp-pos save-exp-pos 937 (setq math-exp-pos save-exp-pos
919 exp-old-pos save-exp-old-pos 938 math-exp-old-pos save-exp-old-pos
920 exp-token save-exp-token 939 math-exp-token save-exp-token
921 math-expr-data save-exp-data 940 math-expr-data save-exp-data
922 matches "Failed")) 941 matches "Failed"))
923 matches)) 942 matches))
@@ -946,10 +965,10 @@
946 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op))))) 965 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
947 966
948(defun math-factor-after () 967(defun math-factor-after ()
949 (let ((exp-pos exp-pos) 968 (let ((math-exp-pos math-exp-pos)
950 exp-old-pos exp-token math-expr-data) 969 math-exp-old-pos math-exp-token math-expr-data)
951 (math-read-token) 970 (math-read-token)
952 (or (memq exp-token '(number symbol dollar hash string)) 971 (or (memq math-exp-token '(number symbol dollar hash string))
953 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/"))) 972 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/")))
954 (assoc (concat "u" math-expr-data) math-expr-opers)) 973 (assoc (concat "u" math-expr-data) math-expr-opers))
955 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1) 974 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1)
@@ -957,11 +976,11 @@
957 976
958(defun math-read-factor () 977(defun math-read-factor ()
959 (let (op) 978 (let (op)
960 (cond ((eq exp-token 'number) 979 (cond ((eq math-exp-token 'number)
961 (let ((num (math-read-number math-expr-data))) 980 (let ((num (math-read-number math-expr-data)))
962 (if (not num) 981 (if (not num)
963 (progn 982 (progn
964 (setq exp-old-pos exp-pos) 983 (setq math-exp-old-pos math-exp-pos)
965 (throw 'syntax "Bad format"))) 984 (throw 'syntax "Bad format")))
966 (math-read-token) 985 (math-read-token)
967 (if (and math-read-expr-quotes 986 (if (and math-read-expr-quotes
@@ -990,7 +1009,7 @@
990 (equal (car op) "u-")) 1009 (equal (car op) "u-"))
991 (math-neg val)) 1010 (math-neg val))
992 (t (list (nth 1 op) val)))))) 1011 (t (list (nth 1 op) val))))))
993 ((eq exp-token 'symbol) 1012 ((eq math-exp-token 'symbol)
994 (let ((sym (intern math-expr-data))) 1013 (let ((sym (intern math-expr-data)))
995 (math-read-token) 1014 (math-read-token)
996 (if (equal math-expr-data calc-function-open) 1015 (if (equal math-expr-data calc-function-open)
@@ -999,11 +1018,11 @@
999 (if (consp (cdr f)) 1018 (if (consp (cdr f))
1000 (funcall (car (cdr f)) f sym) 1019 (funcall (car (cdr f)) f sym)
1001 (let ((args (if (or (equal math-expr-data calc-function-close) 1020 (let ((args (if (or (equal math-expr-data calc-function-close)
1002 (eq exp-token 'end)) 1021 (eq math-exp-token 'end))
1003 nil 1022 nil
1004 (math-read-expr-list)))) 1023 (math-read-expr-list))))
1005 (if (not (or (equal math-expr-data calc-function-close) 1024 (if (not (or (equal math-expr-data calc-function-close)
1006 (eq exp-token 'end))) 1025 (eq math-exp-token 'end)))
1007 (throw 'syntax "Expected `)'")) 1026 (throw 'syntax "Expected `)'"))
1008 (math-read-token) 1027 (math-read-token)
1009 (if (and (eq calc-language 'fortran) args 1028 (if (and (eq calc-language 'fortran) args
@@ -1053,7 +1072,7 @@
1053 (math-read-token) 1072 (math-read-token)
1054 (throw 'syntax "Expected ']'"))) 1073 (throw 'syntax "Expected ']'")))
1055 val))))) 1074 val)))))
1056 ((eq exp-token 'dollar) 1075 ((eq math-exp-token 'dollar)
1057 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data)))) 1076 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data))))
1058 (if (>= (length calc-dollar-values) abs) 1077 (if (>= (length calc-dollar-values) abs)
1059 (let ((num math-expr-data)) 1078 (let ((num math-expr-data))
@@ -1063,7 +1082,7 @@
1063 (throw 'syntax (if calc-dollar-values 1082 (throw 'syntax (if calc-dollar-values
1064 "Too many $'s" 1083 "Too many $'s"
1065 "$'s not allowed in this context"))))) 1084 "$'s not allowed in this context")))))
1066 ((eq exp-token 'hash) 1085 ((eq math-exp-token 'hash)
1067 (or calc-hashes-used 1086 (or calc-hashes-used
1068 (throw 'syntax "#'s not allowed in this context")) 1087 (throw 'syntax "#'s not allowed in this context"))
1069 (calc-extensions) 1088 (calc-extensions)
@@ -1074,13 +1093,13 @@
1074 (nth (1- num) calc-arg-values)) 1093 (nth (1- num) calc-arg-values))
1075 (throw 'syntax "Too many # arguments"))) 1094 (throw 'syntax "Too many # arguments")))
1076 ((equal math-expr-data "(") 1095 ((equal math-expr-data "(")
1077 (let* ((exp (let ((exp-keep-spaces nil)) 1096 (let* ((exp (let ((math-exp-keep-spaces nil))
1078 (math-read-token) 1097 (math-read-token)
1079 (if (or (equal math-expr-data "\\dots") 1098 (if (or (equal math-expr-data "\\dots")
1080 (equal math-expr-data "\\ldots")) 1099 (equal math-expr-data "\\ldots"))
1081 '(neg (var inf var-inf)) 1100 '(neg (var inf var-inf))
1082 (math-read-expr-level 0))))) 1101 (math-read-expr-level 0)))))
1083 (let ((exp-keep-spaces nil)) 1102 (let ((math-exp-keep-spaces nil))
1084 (cond 1103 (cond
1085 ((equal math-expr-data ",") 1104 ((equal math-expr-data ",")
1086 (progn 1105 (progn
@@ -1109,7 +1128,7 @@
1109 (math-read-token) 1128 (math-read-token)
1110 (let ((exp2 (if (or (equal math-expr-data ")") 1129 (let ((exp2 (if (or (equal math-expr-data ")")
1111 (equal math-expr-data "]") 1130 (equal math-expr-data "]")
1112 (eq exp-token 'end)) 1131 (eq math-exp-token 'end))
1113 '(var inf var-inf) 1132 '(var inf var-inf)
1114 (math-read-expr-level 0)))) 1133 (math-read-expr-level 0))))
1115 (setq exp 1134 (setq exp
@@ -1119,11 +1138,11 @@
1119 exp2))))))) 1138 exp2)))))))
1120 (if (not (or (equal math-expr-data ")") 1139 (if (not (or (equal math-expr-data ")")
1121 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv)) 1140 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv))
1122 (eq exp-token 'end))) 1141 (eq math-exp-token 'end)))
1123 (throw 'syntax "Expected `)'")) 1142 (throw 'syntax "Expected `)'"))
1124 (math-read-token) 1143 (math-read-token)
1125 exp)) 1144 exp))
1126 ((eq exp-token 'string) 1145 ((eq math-exp-token 'string)
1127 (calc-extensions) 1146 (calc-extensions)
1128 (math-read-string)) 1147 (math-read-string))
1129 ((equal math-expr-data "[") 1148 ((equal math-expr-data "[")