]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-embed.el
Add a provide statement.
[gnu-emacs] / lisp / calc / calc-embed.el
index b07df1eda04f5d1ff158ef57e2c2ec7cd44e6ee4..067d233bf4a5d9302eab382ba32405b0a4c4467a 100644 (file)
@@ -1,6 +1,9 @@
-;; Calculator for GNU Emacs, part II [calc-embed.el]
+;;; calc-embed.el --- embed Calc in a buffer
+
 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
 
 ;; This file is part of GNU Emacs.
 
 
 ;; This file is part of GNU Emacs.
 
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
 
 
+;;; Code:
 
 ;; This file is autoloaded from calc-ext.el.
 
 ;; This file is autoloaded from calc-ext.el.
-(require 'calc-ext)
 
 
+(require 'calc-ext)
 (require 'calc-macs)
 
 (require 'calc-macs)
 
-(defun calc-Need-calc-embed () nil)
-
-
 (defun calc-show-plain (n)
   (interactive "P")
   (calc-wrapper
    (calc-set-command-flag 'renum-stack)
    (message (if (calc-change-mode 'calc-show-plain n nil t)
 (defun calc-show-plain (n)
   (interactive "P")
   (calc-wrapper
    (calc-set-command-flag 'renum-stack)
    (message (if (calc-change-mode 'calc-show-plain n nil t)
-               "Including \"plain\" formulas in Calc Embedded mode."
-             "Omitting \"plain\" formulas in Calc Embedded mode."))))
-
-
-
-
-;;; Things to do for Embedded Mode:
-;;; 
-;;;  Detect and strip off unexpected labels during reading.
-;;;
-;;;  Get calc-grab-region to use math-read-big-expr.
-;;;  If calc-show-plain, main body should have only righthand side of => expr.
-;;;  Handle tabs that have crept into embedded formulas.
-;;;  After "switching to new formula", home cursor to that formula.
-;;;  Do something like \evalto ... \to for \gets operators.
-;;;
+               "Including \"plain\" formulas in Calc Embedded mode"
+             "Omitting \"plain\" formulas in Calc Embedded mode"))))
 
 
 (defvar calc-embedded-modes nil)
 (defvar calc-embedded-globals nil)
 (defvar calc-embedded-active nil)
 
 
 (defvar calc-embedded-modes nil)
 (defvar calc-embedded-globals nil)
 (defvar calc-embedded-active nil)
-
+(defvar calc-embedded-all-active nil)
 (make-variable-buffer-local 'calc-embedded-all-active)
 (make-variable-buffer-local 'calc-embedded-all-active)
+(defvar calc-embedded-some-active nil)
 (make-variable-buffer-local 'calc-embedded-some-active)
 
 (make-variable-buffer-local 'calc-embedded-some-active)
 
-
 (defvar calc-embedded-open-formula "\\`\\|^\n\\|\\$\\$?\\|\\\\\\[\\|^\\\\begin.*\n\\|^@.*\n\\|^\\.EQ.*\n\\|\\\\(\\|^%\n\\|^\\.\\\\\"\n"
   "*A regular expression for the opening delimiter of a formula used by
 calc-embedded.")
 (defvar calc-embedded-open-formula "\\`\\|^\n\\|\\$\\$?\\|\\\\\\[\\|^\\\\begin.*\n\\|^@.*\n\\|^\\.EQ.*\n\\|\\\\(\\|^%\n\\|^\\.\\\\\"\n"
   "*A regular expression for the opening delimiter of a formula used by
 calc-embedded.")
@@ -161,7 +149,18 @@ This is not required to be present for user-written mode annotations.")
 ;;; rather than using buffer-local variables because the latter are
 ;;; thrown away when a buffer changes major modes.
 
 ;;; rather than using buffer-local variables because the latter are
 ;;; thrown away when a buffer changes major modes.
 
-
+;; The variables calc-embed-outer-top, calc-embed-outer-bot, 
+;; calc-embed-top and calc-embed-bot are
+;; local to calc-do-embedded, calc-embedded-mark-formula,
+;; calc-embedded-duplicate, calc-embedded-new-formula and
+;; calc-embedded-make-info, but are used by calc-embedded-find-bounds,
+;; which is called (directly or indirectly) by the above functions.
+(defvar calc-embed-outer-top)
+(defvar calc-embed-outer-bot)
+(defvar calc-embed-top)
+(defvar calc-embed-bot)
+
+(defvar calc-embedded-quiet nil)
 (defun calc-do-embedded (arg end obeg oend)
   (if calc-embedded-info
 
 (defun calc-do-embedded (arg end obeg oend)
   (if calc-embedded-info
 
@@ -195,7 +194,7 @@ This is not required to be present for user-written mode annotations.")
               (use-local-map (nth 1 mode))
               (set-buffer-modified-p (buffer-modified-p))
               (or calc-embedded-quiet
               (use-local-map (nth 1 mode))
               (set-buffer-modified-p (buffer-modified-p))
               (or calc-embedded-quiet
-                  (message "Back to %s mode." mode-name))))
+                  (message "Back to %s mode" mode-name))))
 
            (t
             (if (buffer-name (aref calc-embedded-info 0))
 
            (t
             (if (buffer-name (aref calc-embedded-info 0))
@@ -212,7 +211,7 @@ This is not required to be present for user-written mode annotations.")
     (let ((modes (list mode-line-buffer-identification
                       (current-local-map)
                       truncate-lines))
     (let ((modes (list mode-line-buffer-identification
                       (current-local-map)
                       truncate-lines))
-         top bot outer-top outer-bot
+         calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
          info chg ident)
       (barf-if-buffer-read-only)
       (or calc-embedded-globals
          info chg ident)
       (barf-if-buffer-read-only)
       (or calc-embedded-globals
@@ -246,12 +245,11 @@ This is not required to be present for user-written mode annotations.")
       (setq calc-no-refresh-evaltos nil)
       (and chg calc-any-evaltos (calc-wrapper (calc-refresh-evaltos)))
       (or (eq calc-embedded-quiet t)
       (setq calc-no-refresh-evaltos nil)
       (and chg calc-any-evaltos (calc-wrapper (calc-refresh-evaltos)))
       (or (eq calc-embedded-quiet t)
-         (message "Embedded Calc mode enabled.  %s to return to normal."
+         (message "Embedded Calc mode enabled; %s to return to normal"
                   (if calc-embedded-quiet
                       "Type `M-# x'"
                     "Give this command again")))))
   (scroll-down 0))    ; fix a bug which occurs when truncate-lines is changed.
                   (if calc-embedded-quiet
                       "Type `M-# x'"
                     "Give this command again")))))
   (scroll-down 0))    ; fix a bug which occurs when truncate-lines is changed.
-(setq calc-embedded-quiet nil)
 
 
 (defun calc-embedded-select (arg)
 
 
 (defun calc-embedded-select (arg)
@@ -309,6 +307,8 @@ This is not required to be present for user-written mode annotations.")
      (insert str "\n")))
   (calc-show-edit-buffer))
 
      (insert str "\n")))
   (calc-show-edit-buffer))
 
+(defvar calc-original-buffer)
+
 (defun calc-embedded-finish-edit (info)
   (let ((buf (current-buffer))
        (str (buffer-substring (point) (point-max)))
 (defun calc-embedded-finish-edit (info)
   (let ((buf (current-buffer))
        (str (buffer-substring (point) (point-max)))
@@ -335,7 +335,7 @@ This is not required to be present for user-written mode annotations.")
       (calc-embedded-forget))
   (calc-find-globals)
   (if (< (prefix-numeric-value arg) 0)
       (calc-embedded-forget))
   (calc-find-globals)
   (if (< (prefix-numeric-value arg) 0)
-      (message "Deactivating %s for Calc Embedded mode." (buffer-name))
+      (message "Deactivating %s for Calc Embedded mode" (buffer-name))
     (message "Activating %s for Calc Embedded mode..." (buffer-name))
     (save-excursion
       (let* ((active (assq (current-buffer) calc-embedded-active))
     (message "Activating %s for Calc Embedded mode..." (buffer-name))
     (save-excursion
       (let* ((active (assq (current-buffer) calc-embedded-active))
@@ -350,8 +350,8 @@ This is not required to be present for user-written mode annotations.")
              (setcdr active (delq (car info) (cdr active)))))
        (goto-char (point-min))
        (while (re-search-forward pat nil t)
              (setcdr active (delq (car info) (cdr active)))))
        (goto-char (point-min))
        (while (re-search-forward pat nil t)
-         (if (looking-at calc-embedded-open-formula)
-             (goto-char (match-end 1)))
+;;;      (if (looking-at calc-embedded-open-formula)
+;;;          (goto-char (match-end 1)))
          (setq info (calc-embedded-make-info (point) cbuf nil))
          (or (eq (car-safe (aref info 8)) 'error)
              (goto-char (aref info 5))))))
          (setq info (calc-embedded-make-info (point) cbuf nil))
          (or (eq (car-safe (aref info 8)) 'error)
              (goto-char (aref info 5))))))
@@ -396,11 +396,11 @@ With any prefix argument, marks only the formula itself."
   (interactive "P")
   (and (eq major-mode 'calc-mode)
        (error "This command should be used in a normal editing buffer"))
   (interactive "P")
   (and (eq major-mode 'calc-mode)
        (error "This command should be used in a normal editing buffer"))
-  (let (top bot outer-top outer-bot)
+  (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot)
     (save-excursion
       (calc-embedded-find-bounds body-only))
     (save-excursion
       (calc-embedded-find-bounds body-only))
-    (push-mark (if body-only bot outer-bot) t)
-    (goto-char (if body-only top outer-top))))
+    (push-mark (if body-only calc-embed-bot calc-embed-outer-bot) t)
+    (goto-char (if body-only calc-embed-top calc-embed-outer-top))))
 
 (defun calc-embedded-find-bounds (&optional plain)
   ;; (while (and (bolp) (eq (following-char) ?\n))
 
 (defun calc-embedded-find-bounds (&optional plain)
   ;; (while (and (bolp) (eq (following-char) ?\n))
@@ -415,7 +415,7 @@ With any prefix argument, marks only the formula itself."
     (and (eq (preceding-char) ?\$)  ; backward search for \$\$? won't back
         (eq (following-char) ?\$)  ; up over a second $, so do it by hand.
         (forward-char -1))
     (and (eq (preceding-char) ?\$)  ; backward search for \$\$? won't back
         (eq (following-char) ?\$)  ; up over a second $, so do it by hand.
         (forward-char -1))
-    (setq outer-top (point))
+    (setq calc-embed-outer-top (point))
     (goto-char (match-end 0))
     (if (eq (following-char) ?\n)
        (forward-char 1))
     (goto-char (match-end 0))
     (if (eq (following-char) ?\n)
        (forward-char 1))
@@ -427,21 +427,21 @@ With any prefix argument, marks only the formula itself."
            (progn
              (goto-char (match-end 0))
              (search-forward calc-embedded-close-plain))))
            (progn
              (goto-char (match-end 0))
              (search-forward calc-embedded-close-plain))))
-    (setq top (point))
+    (setq calc-embed-top (point))
     (or (re-search-forward calc-embedded-close-formula nil t)
        (error "Can't find end of formula"))
     (if (< (point) home)
        (error "Not inside a formula"))
     (and (eq (following-char) ?\n) (not (bolp))
         (forward-char 1))
     (or (re-search-forward calc-embedded-close-formula nil t)
        (error "Can't find end of formula"))
     (if (< (point) home)
        (error "Not inside a formula"))
     (and (eq (following-char) ?\n) (not (bolp))
         (forward-char 1))
-    (setq outer-bot (point))
+    (setq calc-embed-outer-bot (point))
     (goto-char (match-beginning 0))
     (if (eq (preceding-char) ?\n)
        (backward-char 1))
     (or (eolp)
        (while (eq (preceding-char) ?\ )
          (backward-char 1)))
     (goto-char (match-beginning 0))
     (if (eq (preceding-char) ?\n)
        (backward-char 1))
     (or (eolp)
        (while (eq (preceding-char) ?\ )
          (backward-char 1)))
-    (setq bot (point))))
+    (setq calc-embed-bot (point))))
 
 (defun calc-embedded-kill-formula ()
   "Kill the formula surrounding point.
 
 (defun calc-embedded-kill-formula ()
   "Kill the formula surrounding point.
@@ -466,25 +466,26 @@ The command \\[yank] can retrieve it from there."
 (defun calc-embedded-duplicate ()
   (interactive)
   (let ((already calc-embedded-info)
 (defun calc-embedded-duplicate ()
   (interactive)
   (let ((already calc-embedded-info)
-       top bot outer-top outer-bot new-top)
+       calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot new-top)
     (if calc-embedded-info
        (progn
     (if calc-embedded-info
        (progn
-         (setq top (+ (aref calc-embedded-info 2))
-               bot (+ (aref calc-embedded-info 3))
-               outer-top (+ (aref calc-embedded-info 4))
-               outer-bot (+ (aref calc-embedded-info 5)))
+         (setq calc-embed-top (+ (aref calc-embedded-info 2))
+               calc-embed-bot (+ (aref calc-embedded-info 3))
+               calc-embed-outer-top (+ (aref calc-embedded-info 4))
+               calc-embed-outer-bot (+ (aref calc-embedded-info 5)))
          (calc-embedded nil))
       (calc-embedded-find-bounds))
          (calc-embedded nil))
       (calc-embedded-find-bounds))
-    (goto-char outer-bot)
+    (goto-char calc-embed-outer-bot)
     (insert "\n")
     (setq new-top (point))
     (insert "\n")
     (setq new-top (point))
-    (insert-buffer-substring (current-buffer) outer-top outer-bot)
-    (goto-char (+ new-top (- top outer-top)))
+    (insert-buffer-substring (current-buffer) 
+                             calc-embed-outer-top calc-embed-outer-bot)
+    (goto-char (+ new-top (- calc-embed-top calc-embed-outer-top)))
     (let ((calc-embedded-quiet (if already t 'x)))
     (let ((calc-embedded-quiet (if already t 'x)))
-      (calc-embedded (+ new-top (- top outer-top))
-                    (+ new-top (- bot outer-top))
+      (calc-embedded (+ new-top (- calc-embed-top calc-embed-outer-top))
+                    (+ new-top (- calc-embed-bot calc-embed-outer-top))
                     new-top
                     new-top
-                    (+ new-top (- outer-bot outer-top))))))
+                    (+ new-top (- calc-embed-outer-bot calc-embed-outer-top))))))
 
 (defun calc-embedded-next (arg)
   (interactive "P")
 
 (defun calc-embedded-next (arg)
   (interactive "P")
@@ -523,26 +524,26 @@ The command \\[yank] can retrieve it from there."
        (error "This command should be used in a normal editing buffer"))
   (if calc-embedded-info
       (calc-embedded nil))
        (error "This command should be used in a normal editing buffer"))
   (if calc-embedded-info
       (calc-embedded nil))
-  (let (top bot outer-top outer-bot)
+  (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot)
     (if (and (eq (preceding-char) ?\n)
             (string-match "\\`\n" calc-embedded-open-new-formula))
        (progn
     (if (and (eq (preceding-char) ?\n)
             (string-match "\\`\n" calc-embedded-open-new-formula))
        (progn
-         (setq outer-top (1- (point)))
+         (setq calc-embed-outer-top (1- (point)))
          (forward-char -1)
          (insert (substring calc-embedded-open-new-formula 1)))
          (forward-char -1)
          (insert (substring calc-embedded-open-new-formula 1)))
-      (setq outer-top (point))
+      (setq calc-embed-outer-top (point))
       (insert calc-embedded-open-new-formula))
       (insert calc-embedded-open-new-formula))
-    (setq top (point))
+    (setq calc-embed-top (point))
     (insert " ")
     (insert " ")
-    (setq bot (point))
+    (setq calc-embed-bot (point))
     (insert calc-embedded-close-new-formula)
     (if (and (eq (following-char) ?\n)
             (string-match "\n\\'" calc-embedded-close-new-formula))
        (delete-char 1))
     (insert calc-embedded-close-new-formula)
     (if (and (eq (following-char) ?\n)
             (string-match "\n\\'" calc-embedded-close-new-formula))
        (delete-char 1))
-    (setq outer-bot (point))
-    (goto-char top)
+    (setq calc-embed-outer-bot (point))
+    (goto-char calc-embed-top)
     (let ((calc-embedded-quiet 'x))
     (let ((calc-embedded-quiet 'x))
-      (calc-embedded top bot outer-top outer-bot))))
+      (calc-embedded calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot))))
 
 (defun calc-embedded-forget ()
   (interactive)
 
 (defun calc-embedded-forget ()
   (interactive)
@@ -550,6 +551,9 @@ The command \\[yank] can retrieve it from there."
                                   calc-embedded-active))
   (calc-embedded-active-state nil))
 
                                   calc-embedded-active))
   (calc-embedded-active-state nil))
 
+;; The variables calc-embed-prev-modes is local to calc-embedded-update,
+;; but is used by calc-embedded-set-modes.
+(defvar calc-embed-prev-modes)
 
 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp)
   (let ((the-language (calc-embedded-language))
 
 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp)
   (let ((the-language (calc-embedded-language))
@@ -565,13 +569,14 @@ The command \\[yank] can retrieve it from there."
               (not (eq (cdr found) 'default)))
          (progn
            (if (eq (setq value (cdr (car v))) 'default)
               (not (eq (cdr found) 'default)))
          (progn
            (if (eq (setq value (cdr (car v))) 'default)
-               (setq value (cdr (assq (car (car v)) calc-mode-var-list))))
+               (setq value (list (nth 1 (assq (car (car v)) calc-mode-var-list)))))
            (equal (symbol-value (car (car v))) value))
          (progn
            (setq changed t)
            (equal (symbol-value (car (car v))) value))
          (progn
            (setq changed t)
-           (if temp (setq prev-modes (cons (cons (car (car v))
-                                                 (symbol-value (car (car v))))
-                                           prev-modes)))
+           (if temp (setq calc-embed-prev-modes 
+                           (cons (cons (car (car v))
+                                       (symbol-value (car (car v))))
+                                 calc-embed-prev-modes)))
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (setq v modes)
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (setq v modes)
@@ -582,9 +587,9 @@ The command \\[yank] can retrieve it from there."
          (equal (symbol-value (car (car v))) value)
          (progn
            (setq changed t)
          (equal (symbol-value (car (car v))) value)
          (progn
            (setq changed t)
-           (if temp (setq prev-modes (cons (cons (car (car v))
+           (if temp (setq calc-embed-prev-modes (cons (cons (car (car v))
                                                  (symbol-value (car (car v))))
                                                  (symbol-value (car (car v))))
-                                           prev-modes)))
+                                           calc-embed-prev-modes)))
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (setq v local-modes)
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (setq v local-modes)
@@ -593,9 +598,9 @@ The command \\[yank] can retrieve it from there."
          (equal (symbol-value (car (car v))) value)
          (progn
            (setq changed t)
          (equal (symbol-value (car (car v))) value)
          (progn
            (setq changed t)
-           (if temp (setq prev-modes (cons (cons (car (car v))
+           (if temp (setq calc-embed-prev-modes (cons (cons (car (car v))
                                                  (symbol-value (car (car v))))
                                                  (symbol-value (car (car v))))
-                                           prev-modes)))
+                                           calc-embed-prev-modes)))
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (and changed (not (eq temp t))
            (set (car (car v)) value)))
       (setq v (cdr v)))
     (and changed (not (eq temp t))
@@ -712,13 +717,18 @@ The command \\[yank] can retrieve it from there."
     (goto-char save-pt)
     (list modes emodes pmodes)))
 
     (goto-char save-pt)
     (list modes emodes pmodes)))
 
+;; The variable calc-embed-vars-used is local to calc-embedded-make-info,
+;; calc-embedded-evaluate-expr and calc-embedded-update, but is 
+;; used by calc-embedded-find-vars, which is called by the above functions.
+(defvar calc-embed-vars-used)
 
 (defun calc-embedded-make-info (point cbuf fresh &optional
 
 (defun calc-embedded-make-info (point cbuf fresh &optional
-                                     top bot outer-top outer-bot)
+                                     calc-embed-top calc-embed-bot 
+                                      calc-embed-outer-top calc-embed-outer-bot)
   (let* ((bufentry (assq (current-buffer) calc-embedded-active))
         (found bufentry)
   (let* ((bufentry (assq (current-buffer) calc-embedded-active))
         (found bufentry)
-        (force (and fresh top))
-        (fixed top)
+        (force (and fresh calc-embed-top))
+        (fixed calc-embed-top)
         (new-info nil)
         info str)
     (or found
         (new-info nil)
         info str)
     (or found
@@ -737,7 +747,8 @@ The command \\[yank] can retrieve it from there."
       (aset info 1 (or cbuf (save-excursion
                              (calc-create-buffer)
                              (current-buffer)))))
       (aset info 1 (or cbuf (save-excursion
                              (calc-create-buffer)
                              (current-buffer)))))
-    (if (and (integerp top) (not bot))  ; started with a user-supplied argument
+    (if (and (integerp calc-embed-top) (not calc-embed-bot))  
+                                        ; started with a user-supplied argument
        (progn
          (if (= (setq arg (prefix-numeric-value arg)) 0)
              (progn
        (progn
          (if (= (setq arg (prefix-numeric-value arg)) 0)
              (progn
@@ -749,18 +760,18 @@ The command \\[yank] can retrieve it from there."
          (aset info 4 (copy-marker (aref info 2)))
          (aset info 5 (copy-marker (aref info 3))))
       (if (aref info 4)
          (aset info 4 (copy-marker (aref info 2)))
          (aset info 5 (copy-marker (aref info 3))))
       (if (aref info 4)
-         (setq top (aref info 2)
-               fixed top)
-       (if (consp top)
+         (setq calc-embed-top (aref info 2)
+               fixed calc-embed-top)
+       (if (consp calc-embed-top)
            (let ((calc-embedded-open-formula calc-embedded-open-word)
                  (calc-embedded-close-formula calc-embedded-close-word))
              (calc-embedded-find-bounds 'plain))
            (let ((calc-embedded-open-formula calc-embedded-open-word)
                  (calc-embedded-close-formula calc-embedded-close-word))
              (calc-embedded-find-bounds 'plain))
-         (or top
+         (or calc-embed-top
              (calc-embedded-find-bounds 'plain)))
              (calc-embedded-find-bounds 'plain)))
-       (aset info 2 (copy-marker (min top bot)))
-       (aset info 3 (copy-marker (max top bot)))
-       (aset info 4 (copy-marker (or outer-top (aref info 2))))
-       (aset info 5 (copy-marker (or outer-bot (aref info 3))))))
+       (aset info 2 (copy-marker (min calc-embed-top calc-embed-bot)))
+       (aset info 3 (copy-marker (max calc-embed-top calc-embed-bot)))
+       (aset info 4 (copy-marker (or calc-embed-outer-top (aref info 2))))
+       (aset info 5 (copy-marker (or calc-embed-outer-bot (aref info 3))))))
     (goto-char (aref info 2))
     (if new-info
        (progn
     (goto-char (aref info 2))
     (if new-info
        (progn
@@ -784,7 +795,7 @@ The command \\[yank] can retrieve it from there."
          (let* ((open-plain calc-embedded-open-plain)
                 (close-plain calc-embedded-close-plain)
                 (pref-len (length open-plain))
          (let* ((open-plain calc-embedded-open-plain)
                 (close-plain calc-embedded-close-plain)
                 (pref-len (length open-plain))
-                (vars-used nil)
+                (calc-embed-vars-used nil)
                 suff-pos val temp)
            (save-excursion
              (set-buffer (aref info 1))
                 suff-pos val temp)
            (save-excursion
              (set-buffer (aref info 1))
@@ -818,7 +829,7 @@ The command \\[yank] can retrieve it from there."
                              (nth 1 temp)))
            (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign))
                (calc-embedded-find-vars val))
                              (nth 1 temp)))
            (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign))
                (calc-embedded-find-vars val))
-           (aset info 10 vars-used)
+           (aset info 10 calc-embed-vars-used)
            (aset info 11 nil))))
     (if new-info
        (progn
            (aset info 11 nil))))
     (if new-info
        (progn
@@ -829,8 +840,8 @@ The command \\[yank] can retrieve it from there."
 (defun calc-embedded-find-vars (x)
   (cond ((Math-primp x)
         (and (eq (car-safe x) 'var)
 (defun calc-embedded-find-vars (x)
   (cond ((Math-primp x)
         (and (eq (car-safe x) 'var)
-             (not (assoc x vars-used))
-             (setq vars-used (cons (list x) vars-used))))
+             (not (assoc x calc-embed-vars-used))
+             (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used))))
        ((eq (car x) 'calcFunc-evalto)
         (calc-embedded-find-vars (nth 1 x)))
        ((eq (car x) 'calcFunc-assign)
        ((eq (car x) 'calcFunc-evalto)
         (calc-embedded-find-vars (nth 1 x)))
        ((eq (car x) 'calcFunc-assign)
@@ -839,16 +850,16 @@ The command \\[yank] can retrieve it from there."
         (and (eq (car x) 'calcFunc-subscr)
              (eq (car-safe (nth 1 x)) 'var)
              (Math-primp (nth 2 x))
         (and (eq (car x) 'calcFunc-subscr)
              (eq (car-safe (nth 1 x)) 'var)
              (Math-primp (nth 2 x))
-             (not (assoc x vars-used))
-             (setq vars-used (cons (list x) vars-used)))
+             (not (assoc x calc-embed-vars-used))
+             (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used)))
         (while (setq x (cdr x))
           (calc-embedded-find-vars (car x))))))
 
 
 (defun calc-embedded-evaluate-expr (x)
         (while (setq x (cdr x))
           (calc-embedded-find-vars (car x))))))
 
 
 (defun calc-embedded-evaluate-expr (x)
-  (let ((vars-used (aref calc-embedded-info 10)))
-    (or vars-used (calc-embedded-find-vars x))
-    (if vars-used
+  (let ((calc-embed-vars-used (aref calc-embedded-info 10)))
+    (or calc-embed-vars-used (calc-embedded-find-vars x))
+    (if calc-embed-vars-used
        (let ((active (assq (aref calc-embedded-info 0) calc-embedded-active))
              (args nil))
          (save-excursion
        (let ((active (assq (aref calc-embedded-info 0) calc-embedded-active))
              (args nil))
          (save-excursion
@@ -858,9 +869,9 @@ The command \\[yank] can retrieve it from there."
                  (calc-embedded-activate)
                  (setq active (assq (aref calc-embedded-info 0)
                                     calc-embedded-active))))
                  (calc-embedded-activate)
                  (setq active (assq (aref calc-embedded-info 0)
                                     calc-embedded-active))))
-           (while vars-used
-             (calc-embedded-eval-get-var (car (car vars-used)) active)
-             (setq vars-used (cdr vars-used))))
+           (while calc-embed-vars-used
+             (calc-embedded-eval-get-var (car (car calc-embed-vars-used)) active)
+             (setq calc-embed-vars-used (cdr calc-embed-vars-used))))
          (calc-embedded-subst x))
       (calc-normalize (math-evaluate-expr-rec x)))))
 
          (calc-embedded-subst x))
       (calc-normalize (math-evaluate-expr-rec x)))))
 
@@ -908,10 +919,10 @@ The command \\[yank] can retrieve it from there."
 
 (defun calc-embedded-update (info which need-eval need-display
                                  &optional str entry old-val)
 
 (defun calc-embedded-update (info which need-eval need-display
                                  &optional str entry old-val)
-  (let* ((prev-modes nil)
+  (let* ((calc-embed-prev-modes nil)
         (open-plain calc-embedded-open-plain)
         (close-plain calc-embedded-close-plain)
         (open-plain calc-embedded-open-plain)
         (close-plain calc-embedded-close-plain)
-        (vars-used nil)
+        (calc-embed-vars-used nil)
         (evalled nil)
         (val (aref info 8))
         (old-eval (aref info 11)))
         (evalled nil)
         (val (aref info 8))
         (old-eval (aref info 11)))
@@ -934,7 +945,7 @@ The command \\[yank] can retrieve it from there."
          (if (or (eq need-eval 'eval) (eq (car-safe val) 'calcFunc-evalto))
              (aset info 8 val))
          (aset info 9 nil)
          (if (or (eq need-eval 'eval) (eq (car-safe val) 'calcFunc-evalto))
              (aset info 8 val))
          (aset info 9 nil)
-         (aset info 10 vars-used)
+         (aset info 10 calc-embed-vars-used)
          (aset info 11 nil)
          (if (or need-display (eq (car-safe val) 'calcFunc-evalto))
              (let ((extra (if (eq calc-language 'big) 1 0)))
          (aset info 11 nil)
          (if (or need-display (eq (car-safe val) 'calcFunc-evalto))
              (let ((extra (if (eq calc-language 'big) 1 0)))
@@ -986,22 +997,24 @@ The command \\[yank] can retrieve it from there."
            (if (eq (car-safe old-val) 'calcFunc-assign)
                (calc-embedded-var-change (nth 1 old-val) (aref info 0)))))
       (set-buffer (aref info 1))
            (if (eq (car-safe old-val) 'calcFunc-assign)
                (calc-embedded-var-change (nth 1 old-val) (aref info 0)))))
       (set-buffer (aref info 1))
-      (while prev-modes
-       (cond ((eq (car (car prev-modes)) 'the-language)
+      (while calc-embed-prev-modes
+       (cond ((eq (car (car calc-embed-prev-modes)) 'the-language)
               (if need-display
               (if need-display
-                  (calc-embedded-set-language (cdr (car prev-modes)))))
-             ((eq (car (car prev-modes)) 'the-display-just)
+                  (calc-embedded-set-language (cdr (car calc-embed-prev-modes)))))
+             ((eq (car (car calc-embed-prev-modes)) 'the-display-just)
               (if need-display
               (if need-display
-                  (calc-embedded-set-justify (cdr (car prev-modes)))))
+                  (calc-embedded-set-justify (cdr (car calc-embed-prev-modes)))))
              (t
              (t
-              (set (car (car prev-modes)) (cdr (car prev-modes)))))
-       (setq prev-modes (cdr prev-modes))))))
+              (set (car (car calc-embed-prev-modes)) 
+                    (cdr (car calc-embed-prev-modes)))))
+       (setq calc-embed-prev-modes (cdr calc-embed-prev-modes))))))
 
 
 
 
 ;;; These are hooks called by the main part of Calc.
 
 
 
 
 
 ;;; These are hooks called by the main part of Calc.
 
+(defvar calc-embedded-no-reselect nil)
 (defun calc-embedded-select-buffer ()
   (if (eq (current-buffer) (aref calc-embedded-info 0))
       (let ((info calc-embedded-info)
 (defun calc-embedded-select-buffer ()
   (if (eq (current-buffer) (aref calc-embedded-info 0))
       (let ((info calc-embedded-info)
@@ -1031,7 +1044,6 @@ The command \\[yank] can retrieve it from there."
        (forward-char (min horiz
                           (- (point-max) (point)))))
     (calc-select-buffer)))
        (forward-char (min horiz
                           (- (point-max) (point)))))
     (calc-select-buffer)))
-(setq calc-embedded-no-reselect nil)
 
 (defun calc-embedded-finish-command ()
   (let ((buf (current-buffer))
 
 (defun calc-embedded-finish-command ()
   (let ((buf (current-buffer))
@@ -1206,12 +1218,12 @@ The command \\[yank] can retrieve it from there."
                         (calc-embedded-update (car p) 14 t nil)))
                    (setcdr (car bp) (delq (car p) (cdr (car bp))))
                    (message
                         (calc-embedded-update (car p) 14 t nil)))
                    (setcdr (car bp) (delq (car p) (cdr (car bp))))
                    (message
-                    "(Tried to recompute but formula was changed or missing.)"))))
+                    "(Tried to recompute but formula was changed or missing)"))))
            (setq p (cdr p))))
        (setq bp (if buf nil (cdr bp))))
       (or first calc-embedded-quiet (message "")))))
 
            (setq p (cdr p))))
        (setq bp (if buf nil (cdr bp))))
       (or first calc-embedded-quiet (message "")))))
 
-;;; calc-embed.el ends here
-
-
+(provide 'calc-embed)
 
 
+;;; arch-tag: 1b8f311e-fba1-40d3-b8c3-1d6f68fd26fc
+;;; calc-embed.el ends here