comparison lisp/calc/calc-embed.el @ 90054:f2ebccfa87d4

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-74 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-709 Update from CVS: src/indent.c (Fvertical_motion): Fix last change. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-710 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-715 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-716 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-74 Update from CVS
author Miles Bader <miles@gnu.org>
date Wed, 08 Dec 2004 05:02:30 +0000
parents 2e44ef8c14b4 05765b6fc9cd
children cb67264d6096
comparison
equal deleted inserted replaced
90053:fff5f1a61d92 90054:f2ebccfa87d4
1 ;;; calc-embed.el --- embed Calc in a buffer 1 ;;; calc-embed.el --- embed Calc in a buffer
2 2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
4 4
5 ;; Author: David Gillespie <daveg@synaptics.com> 5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainers: D. Goel <deego@gnufans.org> 6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
7 ;; Colin Walters <walters@debian.org>
8 7
9 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
10 9
11 ;; GNU Emacs is distributed in the hope that it will be useful, 10 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor 11 ;; but WITHOUT ANY WARRANTY. No author or distributor
26 ;;; Commentary: 25 ;;; Commentary:
27 26
28 ;;; Code: 27 ;;; Code:
29 28
30 ;; This file is autoloaded from calc-ext.el. 29 ;; This file is autoloaded from calc-ext.el.
30
31 (require 'calc-ext) 31 (require 'calc-ext)
32
33 (require 'calc-macs) 32 (require 'calc-macs)
34
35 (defun calc-Need-calc-embed () nil)
36 33
37 (defun calc-show-plain (n) 34 (defun calc-show-plain (n)
38 (interactive "P") 35 (interactive "P")
39 (calc-wrapper 36 (calc-wrapper
40 (calc-set-command-flag 'renum-stack) 37 (calc-set-command-flag 'renum-stack)
150 ;;; calc-embedded-active is an a-list keyed on buffers; each cdr is a 147 ;;; calc-embedded-active is an a-list keyed on buffers; each cdr is a
151 ;;; sorted list of calc-embedded-infos in that buffer. We do this 148 ;;; sorted list of calc-embedded-infos in that buffer. We do this
152 ;;; rather than using buffer-local variables because the latter are 149 ;;; rather than using buffer-local variables because the latter are
153 ;;; thrown away when a buffer changes major modes. 150 ;;; thrown away when a buffer changes major modes.
154 151
152 ;; The variables calc-embed-outer-top, calc-embed-outer-bot,
153 ;; calc-embed-top and calc-embed-bot are
154 ;; local to calc-do-embedded, calc-embedded-mark-formula,
155 ;; calc-embedded-duplicate, calc-embedded-new-formula and
156 ;; calc-embedded-make-info, but are used by calc-embedded-find-bounds,
157 ;; which is called (directly or indirectly) by the above functions.
158 (defvar calc-embed-outer-top)
159 (defvar calc-embed-outer-bot)
160 (defvar calc-embed-top)
161 (defvar calc-embed-bot)
155 162
156 (defvar calc-embedded-quiet nil) 163 (defvar calc-embedded-quiet nil)
157 (defun calc-do-embedded (arg end obeg oend) 164 (defun calc-do-embedded (arg end obeg oend)
158 (if calc-embedded-info 165 (if calc-embedded-info
159 166
202 ;; Turn embedded mode on. 209 ;; Turn embedded mode on.
203 (calc-plain-buffer-only) 210 (calc-plain-buffer-only)
204 (let ((modes (list mode-line-buffer-identification 211 (let ((modes (list mode-line-buffer-identification
205 (current-local-map) 212 (current-local-map)
206 truncate-lines)) 213 truncate-lines))
207 top bot outer-top outer-bot 214 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
208 info chg ident) 215 info chg ident)
209 (barf-if-buffer-read-only) 216 (barf-if-buffer-read-only)
210 (or calc-embedded-globals 217 (or calc-embedded-globals
211 (calc-find-globals)) 218 (calc-find-globals))
212 (setq info (calc-embedded-make-info (point) nil t arg end obeg oend)) 219 (setq info (calc-embedded-make-info (point) nil t arg end obeg oend))
298 (math-format-nice-expr (aref info 8) (frame-width)))) 305 (math-format-nice-expr (aref info 8) (frame-width))))
299 (calc-edit-mode (list 'calc-embedded-finish-edit info)) 306 (calc-edit-mode (list 'calc-embedded-finish-edit info))
300 (insert str "\n"))) 307 (insert str "\n")))
301 (calc-show-edit-buffer)) 308 (calc-show-edit-buffer))
302 309
310 (defvar calc-original-buffer)
311
303 (defun calc-embedded-finish-edit (info) 312 (defun calc-embedded-finish-edit (info)
304 (let ((buf (current-buffer)) 313 (let ((buf (current-buffer))
305 (str (buffer-substring (point) (point-max))) 314 (str (buffer-substring (point) (point-max)))
306 (start (point)) 315 (start (point))
307 pos) 316 pos)
318 (error (nth 2 val)))) 327 (error (nth 2 val))))
319 (calc-embedded-original-buffer t info) 328 (calc-embedded-original-buffer t info)
320 (aset info 8 val) 329 (aset info 8 val)
321 (calc-embedded-update info 14 t t)))) 330 (calc-embedded-update info 14 t t))))
322 331
323 ;;;###autoload
324 (defun calc-do-embedded-activate (arg cbuf) 332 (defun calc-do-embedded-activate (arg cbuf)
325 (calc-plain-buffer-only) 333 (calc-plain-buffer-only)
326 (if arg 334 (if arg
327 (calc-embedded-forget)) 335 (calc-embedded-forget))
328 (calc-find-globals) 336 (calc-find-globals)
386 This normally marks the whole formula, including surrounding delimiters. 394 This normally marks the whole formula, including surrounding delimiters.
387 With any prefix argument, marks only the formula itself." 395 With any prefix argument, marks only the formula itself."
388 (interactive "P") 396 (interactive "P")
389 (and (eq major-mode 'calc-mode) 397 (and (eq major-mode 'calc-mode)
390 (error "This command should be used in a normal editing buffer")) 398 (error "This command should be used in a normal editing buffer"))
391 (let (top bot outer-top outer-bot) 399 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot)
392 (save-excursion 400 (save-excursion
393 (calc-embedded-find-bounds body-only)) 401 (calc-embedded-find-bounds body-only))
394 (push-mark (if body-only bot outer-bot) t) 402 (push-mark (if body-only calc-embed-bot calc-embed-outer-bot) t)
395 (goto-char (if body-only top outer-top)))) 403 (goto-char (if body-only calc-embed-top calc-embed-outer-top))))
396 404
397 (defun calc-embedded-find-bounds (&optional plain) 405 (defun calc-embedded-find-bounds (&optional plain)
398 ;; (while (and (bolp) (eq (following-char) ?\n)) 406 ;; (while (and (bolp) (eq (following-char) ?\n))
399 ;; (forward-char 1)) 407 ;; (forward-char 1))
400 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?\n)) 408 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?\n))
405 (re-search-backward calc-embedded-open-formula nil t) 413 (re-search-backward calc-embedded-open-formula nil t)
406 (error "Can't find start of formula")) 414 (error "Can't find start of formula"))
407 (and (eq (preceding-char) ?\$) ; backward search for \$\$? won't back 415 (and (eq (preceding-char) ?\$) ; backward search for \$\$? won't back
408 (eq (following-char) ?\$) ; up over a second $, so do it by hand. 416 (eq (following-char) ?\$) ; up over a second $, so do it by hand.
409 (forward-char -1)) 417 (forward-char -1))
410 (setq outer-top (point)) 418 (setq calc-embed-outer-top (point))
411 (goto-char (match-end 0)) 419 (goto-char (match-end 0))
412 (if (eq (following-char) ?\n) 420 (if (eq (following-char) ?\n)
413 (forward-char 1)) 421 (forward-char 1))
414 (or (bolp) 422 (or (bolp)
415 (while (eq (following-char) ?\ ) 423 (while (eq (following-char) ?\ )
417 (or (eq plain 'plain) 425 (or (eq plain 'plain)
418 (if (looking-at (regexp-quote calc-embedded-open-plain)) 426 (if (looking-at (regexp-quote calc-embedded-open-plain))
419 (progn 427 (progn
420 (goto-char (match-end 0)) 428 (goto-char (match-end 0))
421 (search-forward calc-embedded-close-plain)))) 429 (search-forward calc-embedded-close-plain))))
422 (setq top (point)) 430 (setq calc-embed-top (point))
423 (or (re-search-forward calc-embedded-close-formula nil t) 431 (or (re-search-forward calc-embedded-close-formula nil t)
424 (error "Can't find end of formula")) 432 (error "Can't find end of formula"))
425 (if (< (point) home) 433 (if (< (point) home)
426 (error "Not inside a formula")) 434 (error "Not inside a formula"))
427 (and (eq (following-char) ?\n) (not (bolp)) 435 (and (eq (following-char) ?\n) (not (bolp))
428 (forward-char 1)) 436 (forward-char 1))
429 (setq outer-bot (point)) 437 (setq calc-embed-outer-bot (point))
430 (goto-char (match-beginning 0)) 438 (goto-char (match-beginning 0))
431 (if (eq (preceding-char) ?\n) 439 (if (eq (preceding-char) ?\n)
432 (backward-char 1)) 440 (backward-char 1))
433 (or (eolp) 441 (or (eolp)
434 (while (eq (preceding-char) ?\ ) 442 (while (eq (preceding-char) ?\ )
435 (backward-char 1))) 443 (backward-char 1)))
436 (setq bot (point)))) 444 (setq calc-embed-bot (point))))
437 445
438 (defun calc-embedded-kill-formula () 446 (defun calc-embedded-kill-formula ()
439 "Kill the formula surrounding point. 447 "Kill the formula surrounding point.
440 If Calc Embedded mode was active, this deactivates it. 448 If Calc Embedded mode was active, this deactivates it.
441 The formula (including its surrounding delimiters) is saved in the kill ring. 449 The formula (including its surrounding delimiters) is saved in the kill ring.
456 (pop-mark))) 464 (pop-mark)))
457 465
458 (defun calc-embedded-duplicate () 466 (defun calc-embedded-duplicate ()
459 (interactive) 467 (interactive)
460 (let ((already calc-embedded-info) 468 (let ((already calc-embedded-info)
461 top bot outer-top outer-bot new-top) 469 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot new-top)
462 (if calc-embedded-info 470 (if calc-embedded-info
463 (progn 471 (progn
464 (setq top (+ (aref calc-embedded-info 2)) 472 (setq calc-embed-top (+ (aref calc-embedded-info 2))
465 bot (+ (aref calc-embedded-info 3)) 473 calc-embed-bot (+ (aref calc-embedded-info 3))
466 outer-top (+ (aref calc-embedded-info 4)) 474 calc-embed-outer-top (+ (aref calc-embedded-info 4))
467 outer-bot (+ (aref calc-embedded-info 5))) 475 calc-embed-outer-bot (+ (aref calc-embedded-info 5)))
468 (calc-embedded nil)) 476 (calc-embedded nil))
469 (calc-embedded-find-bounds)) 477 (calc-embedded-find-bounds))
470 (goto-char outer-bot) 478 (goto-char calc-embed-outer-bot)
471 (insert "\n") 479 (insert "\n")
472 (setq new-top (point)) 480 (setq new-top (point))
473 (insert-buffer-substring (current-buffer) outer-top outer-bot) 481 (insert-buffer-substring (current-buffer)
474 (goto-char (+ new-top (- top outer-top))) 482 calc-embed-outer-top calc-embed-outer-bot)
483 (goto-char (+ new-top (- calc-embed-top calc-embed-outer-top)))
475 (let ((calc-embedded-quiet (if already t 'x))) 484 (let ((calc-embedded-quiet (if already t 'x)))
476 (calc-embedded (+ new-top (- top outer-top)) 485 (calc-embedded (+ new-top (- calc-embed-top calc-embed-outer-top))
477 (+ new-top (- bot outer-top)) 486 (+ new-top (- calc-embed-bot calc-embed-outer-top))
478 new-top 487 new-top
479 (+ new-top (- outer-bot outer-top)))))) 488 (+ new-top (- calc-embed-outer-bot calc-embed-outer-top))))))
480 489
481 (defun calc-embedded-next (arg) 490 (defun calc-embedded-next (arg)
482 (interactive "P") 491 (interactive "P")
483 (setq arg (prefix-numeric-value arg)) 492 (setq arg (prefix-numeric-value arg))
484 (let* ((active (cdr (assq (current-buffer) calc-embedded-active))) 493 (let* ((active (cdr (assq (current-buffer) calc-embedded-active)))
513 (interactive) 522 (interactive)
514 (and (eq major-mode 'calc-mode) 523 (and (eq major-mode 'calc-mode)
515 (error "This command should be used in a normal editing buffer")) 524 (error "This command should be used in a normal editing buffer"))
516 (if calc-embedded-info 525 (if calc-embedded-info
517 (calc-embedded nil)) 526 (calc-embedded nil))
518 (let (top bot outer-top outer-bot) 527 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot)
519 (if (and (eq (preceding-char) ?\n) 528 (if (and (eq (preceding-char) ?\n)
520 (string-match "\\`\n" calc-embedded-open-new-formula)) 529 (string-match "\\`\n" calc-embedded-open-new-formula))
521 (progn 530 (progn
522 (setq outer-top (1- (point))) 531 (setq calc-embed-outer-top (1- (point)))
523 (forward-char -1) 532 (forward-char -1)
524 (insert (substring calc-embedded-open-new-formula 1))) 533 (insert (substring calc-embedded-open-new-formula 1)))
525 (setq outer-top (point)) 534 (setq calc-embed-outer-top (point))
526 (insert calc-embedded-open-new-formula)) 535 (insert calc-embedded-open-new-formula))
527 (setq top (point)) 536 (setq calc-embed-top (point))
528 (insert " ") 537 (insert " ")
529 (setq bot (point)) 538 (setq calc-embed-bot (point))
530 (insert calc-embedded-close-new-formula) 539 (insert calc-embedded-close-new-formula)
531 (if (and (eq (following-char) ?\n) 540 (if (and (eq (following-char) ?\n)
532 (string-match "\n\\'" calc-embedded-close-new-formula)) 541 (string-match "\n\\'" calc-embedded-close-new-formula))
533 (delete-char 1)) 542 (delete-char 1))
534 (setq outer-bot (point)) 543 (setq calc-embed-outer-bot (point))
535 (goto-char top) 544 (goto-char calc-embed-top)
536 (let ((calc-embedded-quiet 'x)) 545 (let ((calc-embedded-quiet 'x))
537 (calc-embedded top bot outer-top outer-bot)))) 546 (calc-embedded calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot))))
538 547
539 (defun calc-embedded-forget () 548 (defun calc-embedded-forget ()
540 (interactive) 549 (interactive)
541 (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active) 550 (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active)
542 calc-embedded-active)) 551 calc-embedded-active))
543 (calc-embedded-active-state nil)) 552 (calc-embedded-active-state nil))
544 553
554 ;; The variables calc-embed-prev-modes is local to calc-embedded-update,
555 ;; but is used by calc-embedded-set-modes.
556 (defvar calc-embed-prev-modes)
545 557
546 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp) 558 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp)
547 (let ((the-language (calc-embedded-language)) 559 (let ((the-language (calc-embedded-language))
548 (the-display-just (calc-embedded-justify)) 560 (the-display-just (calc-embedded-justify))
549 (v gmodes) 561 (v gmodes)
559 (if (eq (setq value (cdr (car v))) 'default) 571 (if (eq (setq value (cdr (car v))) 'default)
560 (setq value (list (nth 1 (assq (car (car v)) calc-mode-var-list))))) 572 (setq value (list (nth 1 (assq (car (car v)) calc-mode-var-list)))))
561 (equal (symbol-value (car (car v))) value)) 573 (equal (symbol-value (car (car v))) value))
562 (progn 574 (progn
563 (setq changed t) 575 (setq changed t)
564 (if temp (setq prev-modes (cons (cons (car (car v)) 576 (if temp (setq calc-embed-prev-modes
565 (symbol-value (car (car v)))) 577 (cons (cons (car (car v))
566 prev-modes))) 578 (symbol-value (car (car v))))
579 calc-embed-prev-modes)))
567 (set (car (car v)) value))) 580 (set (car (car v)) value)))
568 (setq v (cdr v))) 581 (setq v (cdr v)))
569 (setq v modes) 582 (setq v modes)
570 (while v 583 (while v
571 (or (and (setq found (assq (car (car v)) local-modes)) 584 (or (and (setq found (assq (car (car v)) local-modes))
572 (not (eq (cdr found) 'default))) 585 (not (eq (cdr found) 'default)))
573 (eq (setq value (cdr (car v))) 'default) 586 (eq (setq value (cdr (car v))) 'default)
574 (equal (symbol-value (car (car v))) value) 587 (equal (symbol-value (car (car v))) value)
575 (progn 588 (progn
576 (setq changed t) 589 (setq changed t)
577 (if temp (setq prev-modes (cons (cons (car (car v)) 590 (if temp (setq calc-embed-prev-modes (cons (cons (car (car v))
578 (symbol-value (car (car v)))) 591 (symbol-value (car (car v))))
579 prev-modes))) 592 calc-embed-prev-modes)))
580 (set (car (car v)) value))) 593 (set (car (car v)) value)))
581 (setq v (cdr v))) 594 (setq v (cdr v)))
582 (setq v local-modes) 595 (setq v local-modes)
583 (while v 596 (while v
584 (or (eq (setq value (cdr (car v))) 'default) 597 (or (eq (setq value (cdr (car v))) 'default)
585 (equal (symbol-value (car (car v))) value) 598 (equal (symbol-value (car (car v))) value)
586 (progn 599 (progn
587 (setq changed t) 600 (setq changed t)
588 (if temp (setq prev-modes (cons (cons (car (car v)) 601 (if temp (setq calc-embed-prev-modes (cons (cons (car (car v))
589 (symbol-value (car (car v)))) 602 (symbol-value (car (car v))))
590 prev-modes))) 603 calc-embed-prev-modes)))
591 (set (car (car v)) value))) 604 (set (car (car v)) value)))
592 (setq v (cdr v))) 605 (setq v (cdr v)))
593 (and changed (not (eq temp t)) 606 (and changed (not (eq temp t))
594 (progn 607 (progn
595 (calc-embedded-set-justify the-display-just) 608 (calc-embedded-set-justify the-display-just)
702 (setq no-defaults nil))) 715 (setq no-defaults nil)))
703 (backward-char 6)) 716 (backward-char 6))
704 (goto-char save-pt) 717 (goto-char save-pt)
705 (list modes emodes pmodes))) 718 (list modes emodes pmodes)))
706 719
720 ;; The variable calc-embed-vars-used is local to calc-embedded-make-info,
721 ;; calc-embedded-evaluate-expr and calc-embedded-update, but is
722 ;; used by calc-embedded-find-vars, which is called by the above functions.
723 (defvar calc-embed-vars-used)
707 724
708 (defun calc-embedded-make-info (point cbuf fresh &optional 725 (defun calc-embedded-make-info (point cbuf fresh &optional
709 top bot outer-top outer-bot) 726 calc-embed-top calc-embed-bot
727 calc-embed-outer-top calc-embed-outer-bot)
710 (let* ((bufentry (assq (current-buffer) calc-embedded-active)) 728 (let* ((bufentry (assq (current-buffer) calc-embedded-active))
711 (found bufentry) 729 (found bufentry)
712 (force (and fresh top)) 730 (force (and fresh calc-embed-top))
713 (fixed top) 731 (fixed calc-embed-top)
714 (new-info nil) 732 (new-info nil)
715 info str) 733 info str)
716 (or found 734 (or found
717 (setq found (list (current-buffer)) 735 (setq found (list (current-buffer))
718 calc-embedded-active (cons found calc-embedded-active))) 736 calc-embedded-active (cons found calc-embedded-active)))
727 fresh t) 745 fresh t)
728 (aset info 0 (current-buffer)) 746 (aset info 0 (current-buffer))
729 (aset info 1 (or cbuf (save-excursion 747 (aset info 1 (or cbuf (save-excursion
730 (calc-create-buffer) 748 (calc-create-buffer)
731 (current-buffer))))) 749 (current-buffer)))))
732 (if (and (integerp top) (not bot)) ; started with a user-supplied argument 750 (if (and (integerp calc-embed-top) (not calc-embed-bot))
751 ; started with a user-supplied argument
733 (progn 752 (progn
734 (if (= (setq arg (prefix-numeric-value arg)) 0) 753 (if (= (setq arg (prefix-numeric-value arg)) 0)
735 (progn 754 (progn
736 (aset info 2 (copy-marker (region-beginning))) 755 (aset info 2 (copy-marker (region-beginning)))
737 (aset info 3 (copy-marker (region-end)))) 756 (aset info 3 (copy-marker (region-end))))
739 (forward-line arg) 758 (forward-line arg)
740 (aset info (if (> arg 0) 3 2) (point-marker))) 759 (aset info (if (> arg 0) 3 2) (point-marker)))
741 (aset info 4 (copy-marker (aref info 2))) 760 (aset info 4 (copy-marker (aref info 2)))
742 (aset info 5 (copy-marker (aref info 3)))) 761 (aset info 5 (copy-marker (aref info 3))))
743 (if (aref info 4) 762 (if (aref info 4)
744 (setq top (aref info 2) 763 (setq calc-embed-top (aref info 2)
745 fixed top) 764 fixed calc-embed-top)
746 (if (consp top) 765 (if (consp calc-embed-top)
747 (let ((calc-embedded-open-formula calc-embedded-open-word) 766 (let ((calc-embedded-open-formula calc-embedded-open-word)
748 (calc-embedded-close-formula calc-embedded-close-word)) 767 (calc-embedded-close-formula calc-embedded-close-word))
749 (calc-embedded-find-bounds 'plain)) 768 (calc-embedded-find-bounds 'plain))
750 (or top 769 (or calc-embed-top
751 (calc-embedded-find-bounds 'plain))) 770 (calc-embedded-find-bounds 'plain)))
752 (aset info 2 (copy-marker (min top bot))) 771 (aset info 2 (copy-marker (min calc-embed-top calc-embed-bot)))
753 (aset info 3 (copy-marker (max top bot))) 772 (aset info 3 (copy-marker (max calc-embed-top calc-embed-bot)))
754 (aset info 4 (copy-marker (or outer-top (aref info 2)))) 773 (aset info 4 (copy-marker (or calc-embed-outer-top (aref info 2))))
755 (aset info 5 (copy-marker (or outer-bot (aref info 3)))))) 774 (aset info 5 (copy-marker (or calc-embed-outer-bot (aref info 3))))))
756 (goto-char (aref info 2)) 775 (goto-char (aref info 2))
757 (if new-info 776 (if new-info
758 (progn 777 (progn
759 (or (bolp) (aset info 7 t)) 778 (or (bolp) (aset info 7 t))
760 (goto-char (aref info 3)) 779 (goto-char (aref info 3))
774 (calc-embedded-make-info point cbuf nil) 793 (calc-embedded-make-info point cbuf nil)
775 (setq new-info nil)) 794 (setq new-info nil))
776 (let* ((open-plain calc-embedded-open-plain) 795 (let* ((open-plain calc-embedded-open-plain)
777 (close-plain calc-embedded-close-plain) 796 (close-plain calc-embedded-close-plain)
778 (pref-len (length open-plain)) 797 (pref-len (length open-plain))
779 (vars-used nil) 798 (calc-embed-vars-used nil)
780 suff-pos val temp) 799 suff-pos val temp)
781 (save-excursion 800 (save-excursion
782 (set-buffer (aref info 1)) 801 (set-buffer (aref info 1))
783 (calc-embedded-set-modes (aref info 15) 802 (calc-embedded-set-modes (aref info 15)
784 (aref info 12) (aref info 14)) 803 (aref info 12) (aref info 14))
808 (calc-embedded-active-state 'less)))) 827 (calc-embedded-active-state 'less))))
809 (aset info 9 (and (eq (car-safe temp) 'calcFunc-assign) 828 (aset info 9 (and (eq (car-safe temp) 'calcFunc-assign)
810 (nth 1 temp))) 829 (nth 1 temp)))
811 (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign)) 830 (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign))
812 (calc-embedded-find-vars val)) 831 (calc-embedded-find-vars val))
813 (aset info 10 vars-used) 832 (aset info 10 calc-embed-vars-used)
814 (aset info 11 nil)))) 833 (aset info 11 nil))))
815 (if new-info 834 (if new-info
816 (progn 835 (progn
817 (setcdr found (cons info (cdr found))) 836 (setcdr found (cons info (cdr found)))
818 (calc-embedded-active-state 'more))) 837 (calc-embedded-active-state 'more)))
819 info)) 838 info))
820 839
821 (defun calc-embedded-find-vars (x) 840 (defun calc-embedded-find-vars (x)
822 (cond ((Math-primp x) 841 (cond ((Math-primp x)
823 (and (eq (car-safe x) 'var) 842 (and (eq (car-safe x) 'var)
824 (not (assoc x vars-used)) 843 (not (assoc x calc-embed-vars-used))
825 (setq vars-used (cons (list x) vars-used)))) 844 (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used))))
826 ((eq (car x) 'calcFunc-evalto) 845 ((eq (car x) 'calcFunc-evalto)
827 (calc-embedded-find-vars (nth 1 x))) 846 (calc-embedded-find-vars (nth 1 x)))
828 ((eq (car x) 'calcFunc-assign) 847 ((eq (car x) 'calcFunc-assign)
829 (calc-embedded-find-vars (nth 2 x))) 848 (calc-embedded-find-vars (nth 2 x)))
830 (t 849 (t
831 (and (eq (car x) 'calcFunc-subscr) 850 (and (eq (car x) 'calcFunc-subscr)
832 (eq (car-safe (nth 1 x)) 'var) 851 (eq (car-safe (nth 1 x)) 'var)
833 (Math-primp (nth 2 x)) 852 (Math-primp (nth 2 x))
834 (not (assoc x vars-used)) 853 (not (assoc x calc-embed-vars-used))
835 (setq vars-used (cons (list x) vars-used))) 854 (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used)))
836 (while (setq x (cdr x)) 855 (while (setq x (cdr x))
837 (calc-embedded-find-vars (car x)))))) 856 (calc-embedded-find-vars (car x))))))
838 857
839 858
840 (defun calc-embedded-evaluate-expr (x) 859 (defun calc-embedded-evaluate-expr (x)
841 (let ((vars-used (aref calc-embedded-info 10))) 860 (let ((calc-embed-vars-used (aref calc-embedded-info 10)))
842 (or vars-used (calc-embedded-find-vars x)) 861 (or calc-embed-vars-used (calc-embedded-find-vars x))
843 (if vars-used 862 (if calc-embed-vars-used
844 (let ((active (assq (aref calc-embedded-info 0) calc-embedded-active)) 863 (let ((active (assq (aref calc-embedded-info 0) calc-embedded-active))
845 (args nil)) 864 (args nil))
846 (save-excursion 865 (save-excursion
847 (calc-embedded-original-buffer t) 866 (calc-embedded-original-buffer t)
848 (or active 867 (or active
849 (progn 868 (progn
850 (calc-embedded-activate) 869 (calc-embedded-activate)
851 (setq active (assq (aref calc-embedded-info 0) 870 (setq active (assq (aref calc-embedded-info 0)
852 calc-embedded-active)))) 871 calc-embedded-active))))
853 (while vars-used 872 (while calc-embed-vars-used
854 (calc-embedded-eval-get-var (car (car vars-used)) active) 873 (calc-embedded-eval-get-var (car (car calc-embed-vars-used)) active)
855 (setq vars-used (cdr vars-used)))) 874 (setq calc-embed-vars-used (cdr calc-embed-vars-used))))
856 (calc-embedded-subst x)) 875 (calc-embedded-subst x))
857 (calc-normalize (math-evaluate-expr-rec x))))) 876 (calc-normalize (math-evaluate-expr-rec x)))))
858 877
859 (defun calc-embedded-subst (x) 878 (defun calc-embedded-subst (x)
860 (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x)) 879 (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x))
898 (calc-embedded-eval-get-var var base)))))) 917 (calc-embedded-eval-get-var var base))))))
899 918
900 919
901 (defun calc-embedded-update (info which need-eval need-display 920 (defun calc-embedded-update (info which need-eval need-display
902 &optional str entry old-val) 921 &optional str entry old-val)
903 (let* ((prev-modes nil) 922 (let* ((calc-embed-prev-modes nil)
904 (open-plain calc-embedded-open-plain) 923 (open-plain calc-embedded-open-plain)
905 (close-plain calc-embedded-close-plain) 924 (close-plain calc-embedded-close-plain)
906 (vars-used nil) 925 (calc-embed-vars-used nil)
907 (evalled nil) 926 (evalled nil)
908 (val (aref info 8)) 927 (val (aref info 8))
909 (old-eval (aref info 11))) 928 (old-eval (aref info 11)))
910 (or old-val (setq old-val val)) 929 (or old-val (setq old-val val))
911 (if (eq (car-safe val) 'calcFunc-evalto) 930 (if (eq (car-safe val) 'calcFunc-evalto)
924 (setq val (math-evaluate-expr val) 943 (setq val (math-evaluate-expr val)
925 evalled val))) 944 evalled val)))
926 (if (or (eq need-eval 'eval) (eq (car-safe val) 'calcFunc-evalto)) 945 (if (or (eq need-eval 'eval) (eq (car-safe val) 'calcFunc-evalto))
927 (aset info 8 val)) 946 (aset info 8 val))
928 (aset info 9 nil) 947 (aset info 9 nil)
929 (aset info 10 vars-used) 948 (aset info 10 calc-embed-vars-used)
930 (aset info 11 nil) 949 (aset info 11 nil)
931 (if (or need-display (eq (car-safe val) 'calcFunc-evalto)) 950 (if (or need-display (eq (car-safe val) 'calcFunc-evalto))
932 (let ((extra (if (eq calc-language 'big) 1 0))) 951 (let ((extra (if (eq calc-language 'big) 1 0)))
933 (or entry (setq entry (list val 1 nil))) 952 (or entry (setq entry (list val 1 nil)))
934 (or str (progn 953 (or str (progn
976 (if (eq (car-safe old-val) 'calcFunc-evalto) 995 (if (eq (car-safe old-val) 'calcFunc-evalto)
977 (setq old-val (nth 1 old-val))) 996 (setq old-val (nth 1 old-val)))
978 (if (eq (car-safe old-val) 'calcFunc-assign) 997 (if (eq (car-safe old-val) 'calcFunc-assign)
979 (calc-embedded-var-change (nth 1 old-val) (aref info 0))))) 998 (calc-embedded-var-change (nth 1 old-val) (aref info 0)))))
980 (set-buffer (aref info 1)) 999 (set-buffer (aref info 1))
981 (while prev-modes 1000 (while calc-embed-prev-modes
982 (cond ((eq (car (car prev-modes)) 'the-language) 1001 (cond ((eq (car (car calc-embed-prev-modes)) 'the-language)
983 (if need-display 1002 (if need-display
984 (calc-embedded-set-language (cdr (car prev-modes))))) 1003 (calc-embedded-set-language (cdr (car calc-embed-prev-modes)))))
985 ((eq (car (car prev-modes)) 'the-display-just) 1004 ((eq (car (car calc-embed-prev-modes)) 'the-display-just)
986 (if need-display 1005 (if need-display
987 (calc-embedded-set-justify (cdr (car prev-modes))))) 1006 (calc-embedded-set-justify (cdr (car calc-embed-prev-modes)))))
988 (t 1007 (t
989 (set (car (car prev-modes)) (cdr (car prev-modes))))) 1008 (set (car (car calc-embed-prev-modes))
990 (setq prev-modes (cdr prev-modes)))))) 1009 (cdr (car calc-embed-prev-modes)))))
1010 (setq calc-embed-prev-modes (cdr calc-embed-prev-modes))))))
991 1011
992 1012
993 1013
994 1014
995 ;;; These are hooks called by the main part of Calc. 1015 ;;; These are hooks called by the main part of Calc.
1201 "(Tried to recompute but formula was changed or missing)")))) 1221 "(Tried to recompute but formula was changed or missing)"))))
1202 (setq p (cdr p)))) 1222 (setq p (cdr p))))
1203 (setq bp (if buf nil (cdr bp)))) 1223 (setq bp (if buf nil (cdr bp))))
1204 (or first calc-embedded-quiet (message ""))))) 1224 (or first calc-embedded-quiet (message "")))))
1205 1225
1226 (provide 'calc-embed)
1227
1206 ;;; arch-tag: 1b8f311e-fba1-40d3-b8c3-1d6f68fd26fc 1228 ;;; arch-tag: 1b8f311e-fba1-40d3-b8c3-1d6f68fd26fc
1207 ;;; calc-embed.el ends here 1229 ;;; calc-embed.el ends here