1 ;;; calc-embed.el --- embed Calc in a buffer
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <belanger@truman.edu>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY. No author or distributor
13 ;; accepts responsibility to anyone for the consequences of using it
14 ;; or for whether it serves any particular purpose or works at all,
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public
16 ;; License for full details.
18 ;; Everyone is granted permission to copy, modify and redistribute
19 ;; GNU Emacs, but only under the conditions described in the
20 ;; GNU Emacs General Public License. A copy of this license is
21 ;; supposed to have been given to you along with GNU Emacs so you
22 ;; can know your rights and responsibilities. It should be in a
23 ;; file named COPYING. Among other things, the copyright notice
24 ;; and this notice must be preserved on all copies.
30 ;; This file is autoloaded from calc-ext.el.
35 (defun calc-show-plain (n)
38 (calc-set-command-flag 'renum-stack
)
39 (message (if (calc-change-mode 'calc-show-plain n nil t
)
40 "Including \"plain\" formulas in Calc Embedded mode"
41 "Omitting \"plain\" formulas in Calc Embedded mode"))))
44 (defvar calc-embedded-modes nil
)
45 (defvar calc-embedded-globals nil
)
46 (defvar calc-embedded-active nil
)
47 (defvar calc-embedded-all-active nil
)
48 (make-variable-buffer-local 'calc-embedded-all-active
)
49 (defvar calc-embedded-some-active nil
)
50 (make-variable-buffer-local 'calc-embedded-some-active
)
52 ;; The following variables are customizable and defined in calc.el.
53 (defvar calc-embedded-announce-formula
)
54 (defvar calc-embedded-open-formula
)
55 (defvar calc-embedded-close-formula
)
56 (defvar calc-embedded-open-word
)
57 (defvar calc-embedded-close-word
)
58 (defvar calc-embedded-open-plain
)
59 (defvar calc-embedded-close-plain
)
60 (defvar calc-embedded-open-new-formula
)
61 (defvar calc-embedded-close-new-formula
)
62 (defvar calc-embedded-open-mode
)
63 (defvar calc-embedded-close-mode
)
65 (defconst calc-embedded-mode-vars
'(("precision" . calc-internal-prec
)
66 ("word-size" . calc-word-size
)
67 ("angles" . calc-angle-mode
)
68 ("symbolic" . calc-symbolic-mode
)
69 ("matrix" . calc-matrix-mode
)
70 ("fractions" . calc-prefer-frac
)
71 ("complex" . calc-complex-mode
)
72 ("simplify" . calc-simplify-mode
)
73 ("language" . the-language
)
74 ("plain" . calc-show-plain
)
75 ("break" . calc-line-breaking
)
76 ("justify" . the-display-just
)
77 ("left-label" . calc-left-label
)
78 ("right-label" . calc-right-label
)
79 ("radix" . calc-number-radix
)
80 ("leading-zeros" . calc-leading-zeros
)
81 ("grouping" . calc-group-digits
)
82 ("group-char" . calc-group-char
)
83 ("point-char" . calc-point-char
)
84 ("frac-format" . calc-frac-format
)
85 ("float-format" . calc-float-format
)
86 ("complex-format" . calc-complex-format
)
87 ("hms-format" . calc-hms-format
)
88 ("date-format" . calc-date-format
)
89 ("matrix-justify" . calc-matrix-just
)
90 ("full-vectors" . calc-full-vectors
)
91 ("break-vectors" . calc-break-vectors
)
92 ("vector-commas" . calc-vector-commas
)
93 ("vector-brackets" . calc-vector-brackets
)
94 ("matrix-brackets" . calc-matrix-brackets
)
95 ("strings" . calc-display-strings
)
99 ;;; Format of calc-embedded-info vector:
100 ;;; 0 Editing buffer.
101 ;;; 1 Calculator buffer.
102 ;;; 2 Top of current formula (marker).
103 ;;; 3 Bottom of current formula (marker).
104 ;;; 4 Top of current formula's delimiters (marker).
105 ;;; 5 Bottom of current formula's delimiters (marker).
106 ;;; 6 String representation of current formula.
107 ;;; 7 Non-nil if formula is embedded within a single line.
108 ;;; 8 Internal representation of current formula.
109 ;;; 9 Variable assigned by this formula, or nil.
110 ;;; 10 List of variables upon which this formula depends.
111 ;;; 11 Evaluated value of the formula, or nil.
112 ;;; 12 Mode settings for current formula.
113 ;;; 13 Local mode settings for current formula.
114 ;;; 14 Permanent mode settings for current formula.
115 ;;; 15 Global mode settings for editing buffer.
118 ;;; calc-embedded-active is an a-list keyed on buffers; each cdr is a
119 ;;; sorted list of calc-embedded-infos in that buffer. We do this
120 ;;; rather than using buffer-local variables because the latter are
121 ;;; thrown away when a buffer changes major modes.
123 (defvar calc-embedded-original-modes nil
124 "The mode settings for Calc buffer when put in embedded mode.")
126 (defun calc-embedded-save-original-modes ()
127 "Save the current Calc modes when entereding embedded mode."
128 (let ((calcbuf (save-excursion
133 (with-current-buffer calcbuf
135 (cons calc-language calc-language-option
))
137 (list (cons 'calc-display-just
139 (cons 'calc-display-origin
140 calc-display-origin
)))
141 (let ((v calc-embedded-mode-vars
))
143 (let ((var (cdr (car v
))))
144 (unless (memq var
'(the-language the-display-just
))
146 (cons (cons var
(symbol-value var
))
149 (setq calc-embedded-original-modes
(cons lang modes
)))
150 (setq calc-embedded-original-modes nil
))))
152 (defun calc-embedded-preserve-modes ()
153 "Preserve the current modes when leaving embedded mode."
155 (if calc-embedded-info
157 (calc-embedded-save-original-modes)
158 (message "Current modes will be preserved when leaving embedded mode."))
159 (message "Not in embedded mode.")))
161 (defun calc-embedded-restore-original-modes ()
162 "Restore the original Calc modes when leaving embedded mode."
163 (let ((calcbuf (get-buffer "*Calculator*"))
165 (lang (car calc-embedded-original-modes
))
166 (modes (cdr calc-embedded-original-modes
)))
167 (if (and calcbuf calc-embedded-original-modes
)
168 (with-current-buffer calcbuf
170 (equal calc-language
(car lang
))
171 (equal calc-language-option
(cdr lang
)))
172 (calc-set-language (car lang
) (cdr lang
))
175 (let ((mode (car modes
)))
176 (unless (equal (symbol-value (car mode
)) (cdr mode
))
177 (set (car mode
) (cdr mode
))
179 (setq modes
(cdr modes
)))
182 (calc-set-mode-line))))
183 (setq calc-embedded-original-modes nil
)))
185 ;; The variables calc-embed-outer-top, calc-embed-outer-bot,
186 ;; calc-embed-top and calc-embed-bot are
187 ;; local to calc-do-embedded, calc-embedded-mark-formula,
188 ;; calc-embedded-duplicate, calc-embedded-new-formula and
189 ;; calc-embedded-make-info, but are used by calc-embedded-find-bounds,
190 ;; which is called (directly or indirectly) by the above functions.
191 (defvar calc-embed-outer-top
)
192 (defvar calc-embed-outer-bot
)
193 (defvar calc-embed-top
)
194 (defvar calc-embed-bot
)
196 ;; The variable calc-embed-arg is local to calc-do-embedded,
197 ;; calc-embedded-update-formula, calc-embedded-edit and
198 ;; calc-do-embedded-activate, but is used by
199 ;; calc-embedded-make-info, which is called by the above
201 (defvar calc-embed-arg
)
203 (defvar calc-embedded-quiet nil
)
205 (defvar calc-embedded-firsttime
)
206 (defvar calc-embedded-firsttime-buf
)
207 (defvar calc-embedded-firsttime-formula
)
209 (defun calc-do-embedded (calc-embed-arg end obeg oend
)
210 (if calc-embedded-info
212 ;; Turn embedded mode off or switch to a new buffer.
213 (cond ((eq (current-buffer) (aref calc-embedded-info
1))
214 (let ((calcbuf (current-buffer))
215 (buf (aref calc-embedded-info
0)))
216 (calc-embedded-original-buffer t
)
218 (switch-to-buffer calcbuf
)))
220 ((eq (current-buffer) (aref calc-embedded-info
0))
221 (let* ((info calc-embedded-info
)
222 (mode calc-embedded-modes
))
224 (set-buffer (aref info
1))
225 (if (and (> (calc-stack-size) 0)
226 (equal (calc-top 1 'full
) (aref info
8)))
227 (let ((calc-no-refresh-evaltos t
))
228 (if (calc-top 1 'sel
)
230 (calc-embedded-set-modes
231 (aref info
15) (aref info
12) (aref info
14))
232 (let ((calc-embedded-info nil
))
233 (calc-wrapper (calc-pop-stack))))
234 (calc-set-mode-line)))
235 (setq calc-embedded-info nil
236 mode-line-buffer-identification
(car mode
)
237 truncate-lines
(nth 2 mode
)
238 buffer-read-only nil
)
239 (use-local-map (nth 1 mode
))
240 (set-buffer-modified-p (buffer-modified-p))
241 (calc-embedded-restore-original-modes)
242 (or calc-embedded-quiet
243 (message "Back to %s mode" mode-name
))))
246 (if (buffer-name (aref calc-embedded-info
0))
248 (set-buffer (aref calc-embedded-info
0))
249 (or (y-or-n-p (format "Cancel Calc Embedded mode in buffer %s? "
252 (calc-embedded nil
)))
253 (calc-embedded calc-embed-arg end obeg oend
)))
255 ;; Turn embedded mode on.
256 (calc-plain-buffer-only)
257 (let ((modes (list mode-line-buffer-identification
260 (calc-embedded-firsttime (not calc-embedded-active
))
261 (calc-embedded-firsttime-buf nil
)
262 (calc-embedded-firsttime-formula nil
)
263 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
265 (barf-if-buffer-read-only)
266 (calc-embedded-save-original-modes)
267 (or calc-embedded-globals
270 (calc-embedded-make-info (point) nil t calc-embed-arg end obeg oend
))
271 (if (eq (car-safe (aref info
8)) 'error
)
273 (setq calc-embedded-original-modes nil
)
274 (goto-char (nth 1 (aref info
8)))
275 (error (nth 2 (aref info
8)))))
276 (let ((mode-line-buffer-identification mode-line-buffer-identification
)
277 (calc-embedded-info info
)
278 (calc-embedded-no-reselect t
))
281 (calc-no-refresh-evaltos t
))
284 (calc-push (calc-normalize (aref info
8)))
285 (setq chg
(calc-embedded-set-modes
286 (aref info
15) (aref info
12) (aref info
13))))
287 (setq chg
(calc-embedded-set-modes
288 (aref info
15) (aref info
12) (aref info
13)))
290 (setq calc-undo-list nil
292 ident mode-line-buffer-identification
)))
293 (setq calc-embedded-info info
294 calc-embedded-modes modes
295 mode-line-buffer-identification ident
298 (set-buffer-modified-p (buffer-modified-p))
299 (use-local-map calc-mode-map
)
300 (setq calc-no-refresh-evaltos nil
)
301 (and chg calc-any-evaltos
(calc-wrapper (calc-refresh-evaltos)))
305 (setq str mode-line-buffer-identification
))
306 (unless (equal str mode-line-buffer-identification
)
307 (setq mode-line-buffer-identification str
)
308 (set-buffer-modified-p (buffer-modified-p))))
309 (if calc-embedded-firsttime
310 (run-hooks 'calc-embedded-mode-hook
))
311 (if calc-embedded-firsttime-buf
312 (run-hooks 'calc-embedded-new-buffer-hook
))
313 (if calc-embedded-firsttime-formula
314 (run-hooks 'calc-embedded-new-formula-hook
))
315 (or (eq calc-embedded-quiet t
)
316 (message "Embedded Calc mode enabled; %s to return to normal"
317 (if calc-embedded-quiet
319 "Give this command again")))))
320 (scroll-down 0)) ; fix a bug which occurs when truncate-lines is changed.
323 (defun calc-embedded-select (arg)
326 (and calc-embedded-info
327 (eq (car-safe (aref calc-embedded-info
8)) 'calcFunc-evalto
)
328 (calc-select-part 1))
329 (and calc-embedded-info
330 (or (eq (car-safe (aref calc-embedded-info
8)) 'calcFunc-assign
)
331 (and (eq (car-safe (aref calc-embedded-info
8)) 'calcFunc-evalto
)
332 (eq (car-safe (nth 1 (aref calc-embedded-info
8)))
334 (calc-select-part 2)))
337 (defun calc-embedded-update-formula (calc-embed-arg)
340 (let ((entry (assq (current-buffer) calc-embedded-active
)))
341 (while (setq entry
(cdr entry
))
342 (and (eq (car-safe (aref (car entry
) 8)) 'calcFunc-evalto
)
343 (or (not (consp calc-embed-arg
))
344 (and (<= (aref (car entry
) 2) (region-beginning))
345 (>= (aref (car entry
) 3) (region-end))))
347 (calc-embedded-update (car entry
) 14 t t
)))))
348 (if (and calc-embedded-info
349 (eq (current-buffer) (aref calc-embedded-info
0))
350 (>= (point) (aref calc-embedded-info
4))
351 (<= (point) (aref calc-embedded-info
5)))
354 (info (calc-embedded-make-info (point) nil t
))
355 (pt (- opt
(aref info
4))))
356 (or (eq (car-safe (aref info
8)) 'error
)
359 (calc-embedded-update info
14 'eval t
))
360 (goto-char (+ (aref info
4) pt
))))))))
363 (defun calc-embedded-edit (calc-embed-arg)
365 (let ((info (calc-embedded-make-info (point) nil t calc-embed-arg
))
367 (if (eq (car-safe (aref info
8)) 'error
)
369 (goto-char (nth 1 (aref info
8)))
370 (error (nth 2 (aref info
8)))))
372 (setq str
(math-showing-full-precision
373 (math-format-nice-expr (aref info
8) (frame-width))))
374 (calc-edit-mode (list 'calc-embedded-finish-edit info
))
376 (calc-show-edit-buffer))
378 (defvar calc-original-buffer
)
379 (defvar calc-edit-top
)
380 (defun calc-embedded-finish-edit (info)
381 (let ((buf (current-buffer))
382 (str (buffer-substring calc-edit-top
(point-max)))
385 (switch-to-buffer calc-original-buffer
)
386 (let ((val (save-excursion
387 (set-buffer (aref info
1))
388 (let ((calc-language nil
)
389 (math-expr-opers math-standard-opers
))
390 (math-read-expr str
)))))
391 (if (eq (car-safe val
) 'error
)
393 (switch-to-buffer buf
)
394 (goto-char (+ start
(nth 1 val
)))
395 (error (nth 2 val
))))
396 (calc-embedded-original-buffer t info
)
398 (calc-embedded-update info
14 t t
))))
400 (defun calc-do-embedded-activate (calc-embed-arg cbuf
)
401 (calc-plain-buffer-only)
403 (calc-embedded-forget))
405 (if (< (prefix-numeric-value calc-embed-arg
) 0)
406 (message "Deactivating %s for Calc Embedded mode" (buffer-name))
407 (message "Activating %s for Calc Embedded mode..." (buffer-name))
409 (let* ((active (assq (current-buffer) calc-embedded-active
))
411 (pat " := \\| \\\\gets \\| => \\| \\\\evalto "))
412 (if calc-embedded-announce-formula
413 (setq pat
(format "%s\\|\\(%s\\)"
414 pat calc-embedded-announce-formula
)))
415 (while (setq info
(cdr info
))
416 (or (equal (buffer-substring (aref (car info
) 2) (aref (car info
) 3))
418 (setcdr active
(delq (car info
) (cdr active
)))))
419 (goto-char (point-min))
420 (while (re-search-forward pat nil t
)
421 ;;; (if (looking-at calc-embedded-open-formula)
422 ;;; (goto-char (match-end 1)))
423 (setq info
(calc-embedded-make-info (point) cbuf nil
))
424 (or (eq (car-safe (aref info
8)) 'error
)
425 (goto-char (aref info
5))))))
426 (message "Activating %s for Calc Embedded mode...done" (buffer-name)))
427 (calc-embedded-active-state t
))
429 (defun calc-plain-buffer-only ()
430 (if (memq major-mode
'(calc-mode calc-trail-mode calc-edit-mode
))
431 (error "This command should be used in a normal editing buffer")))
433 (defun calc-embedded-active-state (state)
434 (or (assq 'calc-embedded-all-active minor-mode-alist
)
435 (setq minor-mode-alist
436 (cons '(calc-embedded-all-active " Active")
437 (cons '(calc-embedded-some-active " ~Active")
439 (let ((active (assq (current-buffer) calc-embedded-active
)))
442 (and (eq state
'more
) calc-embedded-all-active
(setq state t
))
443 (setq calc-embedded-all-active
(eq state t
)
444 calc-embedded-some-active
(not (memq state
'(nil t
))))
445 (set-buffer-modified-p (buffer-modified-p)))
448 (defun calc-embedded-original-buffer (switch &optional info
)
449 (or info
(setq info calc-embedded-info
))
450 (or (buffer-name (aref info
0))
452 (error "Calc embedded mode: Original buffer has been killed")))
454 (set-buffer (aref info
0))))
456 (defun calc-embedded-word ()
458 (calc-embedded '(t)))
460 (defun calc-embedded-mark-formula (&optional body-only
)
461 "Put point at the beginning of this Calc formula, mark at the end.
462 This normally marks the whole formula, including surrounding delimiters.
463 With any prefix argument, marks only the formula itself."
465 (and (eq major-mode
'calc-mode
)
466 (error "This command should be used in a normal editing buffer"))
467 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
)
469 (calc-embedded-find-bounds body-only
))
470 (push-mark (if body-only calc-embed-bot calc-embed-outer-bot
) t
)
471 (goto-char (if body-only calc-embed-top calc-embed-outer-top
))))
473 (defun calc-embedded-find-bounds (&optional plain
)
474 ;; (while (and (bolp) (eq (following-char) ?\n))
476 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?
\n))
478 (let ((home (point)))
479 (or (and (looking-at calc-embedded-open-formula
)
480 (not (looking-at calc-embedded-close-formula
)))
481 (re-search-backward calc-embedded-open-formula nil t
)
482 (error "Can't find start of formula"))
483 (and (eq (preceding-char) ?\$
) ; backward search for \$\$? won't back
484 (eq (following-char) ?\$
) ; up over a second $, so do it by hand.
486 (setq calc-embed-outer-top
(point))
487 (goto-char (match-end 0))
488 (if (looking-at "[ \t]*$")
490 (if (eq (following-char) ?
\n)
493 (while (eq (following-char) ?\
)
495 (or (eq plain
'plain
)
496 (if (looking-at (regexp-quote calc-embedded-open-plain
))
498 (goto-char (match-end 0))
499 (search-forward calc-embedded-close-plain
))))
500 (setq calc-embed-top
(point))
501 (or (re-search-forward calc-embedded-close-formula nil t
)
502 (error "Can't find end of formula"))
504 (error "Not inside a formula"))
505 (and (eq (following-char) ?
\n) (not (bolp))
507 (setq calc-embed-outer-bot
(point))
508 (goto-char (match-beginning 0))
509 (if (eq (preceding-char) ?
\n)
512 (while (eq (preceding-char) ?\
)
514 (setq calc-embed-bot
(point))))
516 (defun calc-embedded-kill-formula ()
517 "Kill the formula surrounding point.
518 If Calc Embedded mode was active, this deactivates it.
519 The formula (including its surrounding delimiters) is saved in the kill ring.
520 The command \\[yank] can retrieve it from there."
522 (and calc-embedded-info
524 (calc-embedded-mark-formula)
525 (kill-region (point) (mark))
528 (defun calc-embedded-copy-formula-as-kill ()
529 "Save the formula surrounding point as if killed, but don't kill it."
532 (calc-embedded-mark-formula)
533 (copy-region-as-kill (point) (mark))
536 (defun calc-embedded-duplicate ()
538 (let ((already calc-embedded-info
)
539 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot new-top
)
540 (if calc-embedded-info
542 (setq calc-embed-top
(+ (aref calc-embedded-info
2))
543 calc-embed-bot
(+ (aref calc-embedded-info
3))
544 calc-embed-outer-top
(+ (aref calc-embedded-info
4))
545 calc-embed-outer-bot
(+ (aref calc-embedded-info
5)))
547 (calc-embedded-find-bounds))
548 (goto-char calc-embed-outer-bot
)
550 (setq new-top
(point))
551 (insert-buffer-substring (current-buffer)
552 calc-embed-outer-top calc-embed-outer-bot
)
553 (goto-char (+ new-top
(- calc-embed-top calc-embed-outer-top
)))
554 (let ((calc-embedded-quiet (if already t
'x
)))
555 (calc-embedded (+ new-top
(- calc-embed-top calc-embed-outer-top
))
556 (+ new-top
(- calc-embed-bot calc-embed-outer-top
))
558 (+ new-top
(- calc-embed-outer-bot calc-embed-outer-top
))))))
560 (defun calc-embedded-next (arg)
562 (setq arg
(prefix-numeric-value arg
))
563 (let* ((active (cdr (assq (current-buffer) calc-embedded-active
)))
565 (num (length active
)))
567 (error "No active formulas in buffer"))
570 (if (<= (point) (aref (car active
) 3))
571 (goto-char (aref (nth (1- num
) active
) 2))
573 (> (point) (aref (nth 1 p
) 3)))
575 (goto-char (aref (car p
) 2))))
577 (calc-embedded-next -
1)
578 (calc-embedded-next (+ (* num
1000) arg
1)))
580 (setq arg
(1+ (%
(1- arg
) num
)))
581 (while (and p
(>= (point) (aref (car p
) 2)))
583 (while (> (setq arg
(1- arg
)) 0)
584 (setq p
(if p
(cdr p
) (cdr active
))))
585 (goto-char (aref (car (or p active
)) 2))))))
587 (defun calc-embedded-previous (arg)
589 (calc-embedded-next (- (prefix-numeric-value arg
))))
591 (defun calc-embedded-new-formula ()
593 (and (eq major-mode
'calc-mode
)
594 (error "This command should be used in a normal editing buffer"))
595 (if calc-embedded-info
597 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
)
598 (if (and (eq (preceding-char) ?
\n)
599 (string-match "\\`\n" calc-embedded-open-new-formula
))
601 (setq calc-embed-outer-top
(1- (point)))
603 (insert (substring calc-embedded-open-new-formula
1)))
604 (setq calc-embed-outer-top
(point))
605 (insert calc-embedded-open-new-formula
))
606 (setq calc-embed-top
(point))
608 (setq calc-embed-bot
(point))
609 (insert calc-embedded-close-new-formula
)
610 (if (and (eq (following-char) ?
\n)
611 (string-match "\n\\'" calc-embedded-close-new-formula
))
613 (setq calc-embed-outer-bot
(point))
614 (goto-char calc-embed-top
)
615 (let ((calc-embedded-quiet 'x
))
616 (calc-embedded calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot
))))
618 (defun calc-embedded-forget ()
620 (setq calc-embedded-active
(delq (assq (current-buffer) calc-embedded-active
)
621 calc-embedded-active
))
622 (calc-embedded-active-state nil
))
624 ;; The variables calc-embed-prev-modes is local to calc-embedded-update,
625 ;; but is used by calc-embedded-set-modes.
626 (defvar calc-embed-prev-modes
)
628 (defun calc-embedded-set-modes (gmodes modes local-modes
&optional temp
)
629 (let ((the-language (calc-embedded-language))
630 (the-display-just (calc-embedded-justify))
635 (or (symbolp (car v
))
636 (and (setq found
(assq (car (car v
)) modes
))
637 (not (eq (cdr found
) 'default
)))
638 (and (setq found
(assq (car (car v
)) local-modes
))
639 (not (eq (cdr found
) 'default
)))
641 (if (eq (setq value
(cdr (car v
))) 'default
)
642 (setq value
(list (nth 1 (assq (car (car v
)) calc-mode-var-list
)))))
643 (equal (symbol-value (car (car v
))) value
))
646 (if temp
(setq calc-embed-prev-modes
647 (cons (cons (car (car v
))
648 (symbol-value (car (car v
))))
649 calc-embed-prev-modes
)))
650 (set (car (car v
)) value
)))
654 (or (and (setq found
(assq (car (car v
)) local-modes
))
655 (not (eq (cdr found
) 'default
)))
656 (eq (setq value
(cdr (car v
))) 'default
)
657 (equal (symbol-value (car (car v
))) value
)
660 (if temp
(setq calc-embed-prev-modes
(cons (cons (car (car v
))
661 (symbol-value (car (car v
))))
662 calc-embed-prev-modes
)))
663 (set (car (car v
)) value
)))
667 (or (eq (setq value
(cdr (car v
))) 'default
)
668 (equal (symbol-value (car (car v
))) value
)
671 (if temp
(setq calc-embed-prev-modes
(cons (cons (car (car v
))
672 (symbol-value (car (car v
))))
673 calc-embed-prev-modes
)))
674 (set (car (car v
)) value
)))
676 (and changed
(not (eq temp t
))
678 (calc-embedded-set-justify the-display-just
)
679 (calc-embedded-set-language the-language
)))
680 (and changed
(not temp
)
682 (setq calc-full-float-format
(list (if (eq (car calc-float-format
)
685 (car calc-float-format
))
690 (defun calc-embedded-language ()
691 (if calc-language-option
692 (list calc-language calc-language-option
)
695 (defun calc-embedded-set-language (lang)
698 (setq option
(nth 1 lang
)
700 (or (and (eq lang calc-language
)
701 (equal option calc-language-option
))
702 (calc-set-language lang option t
))))
704 (defun calc-embedded-justify ()
705 (if calc-display-origin
706 (list calc-display-just calc-display-origin
)
709 (defun calc-embedded-set-justify (just)
711 (setq calc-display-origin
(nth 1 just
)
712 calc-display-just
(car just
))
713 (setq calc-display-just just
714 calc-display-origin nil
)))
717 (defun calc-find-globals ()
719 (and (eq major-mode
'calc-mode
)
720 (error "This command should be used in a normal editing buffer"))
721 (make-local-variable 'calc-embedded-globals
)
722 (let ((case-fold-search nil
)
726 (goto-char (point-min))
727 (while (re-search-forward "\\[calc-global-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)\\]" nil t
)
728 (and (setq found
(assoc (buffer-substring (match-beginning 1)
730 calc-embedded-mode-vars
))
731 (or (assq (cdr found
) modes
)
732 (setq modes
(cons (cons (cdr found
)
733 (car (read-from-string
738 (setq calc-embedded-globals
(cons t modes
))
739 (goto-char save-pt
)))
741 (defun calc-embedded-find-modes ()
742 (let ((case-fold-search nil
)
749 (while (and no-defaults
(search-backward "[calc-" nil t
))
751 (or (and (looking-at "mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]")
752 (setq found
(assoc (buffer-substring (match-beginning 1)
754 calc-embedded-mode-vars
))
755 (or (assq (cdr found
) modes
)
756 (setq modes
(cons (cons (cdr found
)
757 (car (read-from-string
762 (and (looking-at "perm-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]")
763 (setq found
(assoc (buffer-substring (match-beginning 1)
765 calc-embedded-mode-vars
))
766 (or (assq (cdr found
) pmodes
)
767 (setq pmodes
(cons (cons (cdr found
)
768 (car (read-from-string
773 (and (looking-at "edit-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]")
774 (setq found
(assoc (buffer-substring (match-beginning 1)
776 calc-embedded-mode-vars
))
777 (or (assq (cdr found
) emodes
)
778 (setq emodes
(cons (cons (cdr found
)
779 (car (read-from-string
784 (and (looking-at "defaults]")
785 (setq no-defaults nil
)))
788 (unless (assq 'the-language modes
)
789 (let ((lang (assoc major-mode calc-language-alist
)))
791 (setq modes
(cons (cons 'the-language
(cdr lang
))
793 (list modes emodes pmodes
)))
795 ;; The variable calc-embed-vars-used is local to calc-embedded-make-info,
796 ;; calc-embedded-evaluate-expr and calc-embedded-update, but is
797 ;; used by calc-embedded-find-vars, which is called by the above functions.
798 (defvar calc-embed-vars-used
)
800 (defun calc-embedded-make-info (point cbuf fresh
&optional
801 calc-embed-top calc-embed-bot
802 calc-embed-outer-top calc-embed-outer-bot
)
803 (let* ((bufentry (assq (current-buffer) calc-embedded-active
))
805 (force (and fresh calc-embed-top
))
806 (fixed calc-embed-top
)
811 (setq found
(list (current-buffer))
812 calc-embedded-active
(cons found calc-embedded-active
)
813 calc-embedded-firsttime-buf t
)
814 (let ((newann (assoc major-mode calc-embedded-announce-formula-alist
))
815 (newform (assoc major-mode calc-embedded-open-close-formula-alist
))
816 (newword (assoc major-mode calc-embedded-open-close-word-alist
))
817 (newplain (assoc major-mode calc-embedded-open-close-plain-alist
))
819 (assoc major-mode calc-embedded-open-close-new-formula-alist
))
820 (newmode (assoc major-mode calc-embedded-open-close-mode-alist
)))
822 (make-local-variable 'calc-embedded-announce-formula
)
823 (setq calc-embedded-announce-formula
(cdr newann
)))
825 (make-local-variable 'calc-embedded-open-formula
)
826 (make-local-variable 'calc-embedded-close-formula
)
827 (setq calc-embedded-open-formula
(nth 0 (cdr newform
)))
828 (setq calc-embedded-close-formula
(nth 1 (cdr newform
))))
830 (make-local-variable 'calc-embedded-open-word
)
831 (make-local-variable 'calc-embedded-close-word
)
832 (setq calc-embedded-open-word
(nth 0 (cdr newword
)))
833 (setq calc-embedded-close-word
(nth 1 (cdr newword
))))
835 (make-local-variable 'calc-embedded-open-plain
)
836 (make-local-variable 'calc-embedded-close-plain
)
837 (setq calc-embedded-open-plain
(nth 0 (cdr newplain
)))
838 (setq calc-embedded-close-plain
(nth 1 (cdr newplain
))))
840 (make-local-variable 'calc-embedded-open-new-formula
)
841 (make-local-variable 'calc-embedded-close-new-formula
)
842 (setq calc-embedded-open-new-formula
(nth 0 (cdr newnewform
)))
843 (setq calc-embedded-close-new-formula
(nth 1 (cdr newnewform
))))
845 (make-local-variable 'calc-embedded-open-mode
)
846 (make-local-variable 'calc-embedded-close-mode
)
847 (setq calc-embedded-open-mode
(nth 0 (cdr newmode
)))
848 (setq calc-embedded-close-mode
(nth 1 (cdr newmode
)))))))
849 (while (and (cdr found
)
850 (> point
(aref (car (cdr found
)) 3)))
851 (setq found
(cdr found
)))
853 (>= point
(aref (nth 1 found
) 2)))
854 (setq info
(nth 1 found
))
855 (setq calc-embedded-firsttime-formula t
)
856 (setq info
(make-vector 16 nil
)
859 (aset info
0 (current-buffer))
860 (aset info
1 (or cbuf
(save-excursion
864 (or (integerp calc-embed-top
) (equal calc-embed-top
'(4)))
865 (not calc-embed-bot
))
866 ; started with a user-supplied argument
868 (if (equal calc-embed-top
'(4))
870 (aset info
2 (copy-marker (line-beginning-position)))
871 (aset info
3 (copy-marker (line-end-position))))
872 (if (= (setq calc-embed-arg
(prefix-numeric-value calc-embed-arg
)) 0)
874 (aset info
2 (copy-marker (region-beginning)))
875 (aset info
3 (copy-marker (region-end))))
876 (aset info
(if (> calc-embed-arg
0) 2 3) (point-marker))
877 (if (> calc-embed-arg
0)
879 (forward-line (1- calc-embed-arg
))
881 (forward-line (1+ calc-embed-arg
)))
882 (aset info
(if (> calc-embed-arg
0) 3 2) (point-marker))))
883 (aset info
4 (copy-marker (aref info
2)))
884 (aset info
5 (copy-marker (aref info
3))))
886 (setq calc-embed-top
(aref info
2)
887 fixed calc-embed-top
)
888 (if (consp calc-embed-top
)
889 (let ((calc-embedded-open-formula calc-embedded-open-word
)
890 (calc-embedded-close-formula calc-embedded-close-word
))
891 (calc-embedded-find-bounds 'plain
))
893 (calc-embedded-find-bounds 'plain
)))
894 (aset info
2 (copy-marker (min calc-embed-top calc-embed-bot
)))
895 (aset info
3 (copy-marker (max calc-embed-top calc-embed-bot
)))
896 (aset info
4 (copy-marker (or calc-embed-outer-top
(aref info
2))))
897 (aset info
5 (copy-marker (or calc-embed-outer-bot
(aref info
3))))))
898 (goto-char (aref info
2))
901 (or (bolp) (aset info
7 t
))
902 (goto-char (aref info
3))
903 (or (bolp) (eolp) (aset info
7 t
))))
905 (let ((modes (calc-embedded-find-modes)))
906 (aset info
12 (car modes
))
907 (aset info
13 (nth 1 modes
))
908 (aset info
14 (nth 2 modes
))))
909 (aset info
15 calc-embedded-globals
)
910 (setq str
(buffer-substring (aref info
2) (aref info
3)))
912 (not (equal str
(aref info
6))))
913 (if (and fixed
(aref info
6))
916 (calc-embedded-make-info point cbuf nil
)
918 (let* ((open-plain calc-embedded-open-plain
)
919 (close-plain calc-embedded-close-plain
)
920 (pref-len (length open-plain
))
921 (calc-embed-vars-used nil
)
924 (set-buffer (aref info
1))
925 (calc-embedded-set-modes (aref info
15)
926 (aref info
12) (aref info
14))
927 (if (and (> (length str
) pref-len
)
928 (equal (substring str
0 pref-len
) open-plain
)
929 (setq suff-pos
(string-match (regexp-quote close-plain
)
931 (setq val
(math-read-plain-expr
932 (substring str pref-len suff-pos
)))
933 (if (string-match "[^ \t\n]" str
)
935 val
(math-read-big-expr str
))
937 (if (eq (car-safe val
) 'error
)
938 (setq val
(list 'error
939 (+ (aref info
2) pref-len
(nth 1 val
))
944 (if (eq (car-safe temp
) 'calcFunc-evalto
)
945 (setq temp
(nth 1 temp
))
946 (if (eq (car-safe temp
) 'error
)
949 (setcdr found
(delq info
(cdr found
)))
950 (calc-embedded-active-state 'less
))))
951 (aset info
9 (and (eq (car-safe temp
) 'calcFunc-assign
)
953 (if (memq (car-safe val
) '(calcFunc-evalto calcFunc-assign
))
954 (calc-embedded-find-vars val
))
955 (aset info
10 calc-embed-vars-used
)
956 (aset info
11 nil
))))
959 (setcdr found
(cons info
(cdr found
)))
960 (calc-embedded-active-state 'more
)))
963 (defun calc-embedded-find-vars (x)
964 (cond ((Math-primp x
)
965 (and (eq (car-safe x
) 'var
)
966 (not (assoc x calc-embed-vars-used
))
967 (setq calc-embed-vars-used
(cons (list x
) calc-embed-vars-used
))))
968 ((eq (car x
) 'calcFunc-evalto
)
969 (calc-embedded-find-vars (nth 1 x
)))
970 ((eq (car x
) 'calcFunc-assign
)
971 (calc-embedded-find-vars (nth 2 x
)))
973 (and (eq (car x
) 'calcFunc-subscr
)
974 (eq (car-safe (nth 1 x
)) 'var
)
975 (Math-primp (nth 2 x
))
976 (not (assoc x calc-embed-vars-used
))
977 (setq calc-embed-vars-used
(cons (list x
) calc-embed-vars-used
)))
978 (while (setq x
(cdr x
))
979 (calc-embedded-find-vars (car x
))))))
981 (defvar math-ms-args
)
982 (defun calc-embedded-evaluate-expr (x)
983 (let ((calc-embed-vars-used (aref calc-embedded-info
10)))
984 (or calc-embed-vars-used
(calc-embedded-find-vars x
))
985 (if calc-embed-vars-used
986 (let ((active (assq (aref calc-embedded-info
0) calc-embedded-active
))
989 (calc-embedded-original-buffer t
)
992 (calc-embedded-activate)
993 (setq active
(assq (aref calc-embedded-info
0)
994 calc-embedded-active
))))
995 (while calc-embed-vars-used
996 (calc-embedded-eval-get-var (car (car calc-embed-vars-used
)) active
)
997 (setq calc-embed-vars-used
(cdr calc-embed-vars-used
))))
998 (calc-embedded-subst x
))
999 (calc-normalize (math-evaluate-expr-rec x
)))))
1001 (defun calc-embedded-subst (x)
1002 (if (and (eq (car-safe x
) 'calcFunc-evalto
) (cdr x
))
1003 (let ((rhs (calc-embedded-subst (nth 1 x
))))
1004 (list 'calcFunc-evalto
1006 (if (eq (car-safe rhs
) 'calcFunc-assign
) (nth 2 rhs
) rhs
)))
1007 (if (and (eq (car-safe x
) 'calcFunc-assign
) (= (length x
) 3))
1008 (list 'calcFunc-assign
1010 (calc-embedded-subst (nth 2 x
)))
1011 (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x
))))))
1013 (defun calc-embedded-eval-get-var (var base
)
1015 (point (aref calc-embedded-info
2))
1018 (while (and (setq entry
(cdr entry
))
1019 (or (not (equal var
(aref (car entry
) 9)))
1020 (and (> point
(aref (car entry
) 3))
1021 (setq last entry
)))))
1026 (setq entry
(car entry
))
1027 (if (equal (buffer-substring (aref entry
2) (aref entry
3))
1032 (calc-embedded-update entry
14 t nil
)))
1033 (setq val
(aref entry
11))
1034 (if (eq (car-safe val
) 'calcFunc-evalto
)
1035 (setq val
(nth 2 val
)))
1036 (if (eq (car-safe val
) 'calcFunc-assign
)
1037 (setq val
(nth 2 val
)))
1038 (setq math-ms-args
(cons (cons var val
) math-ms-args
)))
1039 (calc-embedded-activate)
1040 (calc-embedded-eval-get-var var base
))))))
1043 (defun calc-embedded-update (info which need-eval need-display
1044 &optional str entry old-val
)
1045 (let* ((calc-embed-prev-modes nil
)
1046 (open-plain calc-embedded-open-plain
)
1047 (close-plain calc-embedded-close-plain
)
1048 (calc-embed-vars-used nil
)
1051 (old-eval (aref info
11)))
1052 (or old-val
(setq old-val val
))
1053 (if (eq (car-safe val
) 'calcFunc-evalto
)
1054 (setq need-display t
))
1057 (set-buffer (aref info
1))
1059 (calc-embedded-set-modes (aref info
15) (aref info
12)
1061 (if need-display
'full t
)))
1062 (if (memq (car-safe val
) '(calcFunc-evalto calcFunc-assign
))
1063 (calc-embedded-find-vars val
))
1065 (let ((calc-embedded-info info
))
1066 (setq val
(math-evaluate-expr val
)
1068 (if (or (eq need-eval
'eval
) (eq (car-safe val
) 'calcFunc-evalto
))
1071 (aset info
10 calc-embed-vars-used
)
1073 (if (or need-display
(eq (car-safe val
) 'calcFunc-evalto
))
1074 (let ((extra (if (eq calc-language
'big
) 1 0)))
1075 (or entry
(setq entry
(list val
1 nil
)))
1077 (setq str
(let ((calc-line-numbering nil
))
1078 (math-format-stack-value entry
)))
1079 (if (eq calc-language
'big
)
1080 (setq str
(substring str
0 -
1)))))
1081 (and calc-show-plain
1082 (setq str
(concat open-plain
1083 (math-showing-full-precision
1084 (math-format-flat-expr val
0))
1088 (calc-embedded-original-buffer t info
)
1089 (or (equal str
(aref info
6))
1090 (let ((delta (- (aref info
5) (aref info
3)))
1092 (buffer-read-only nil
))
1093 (goto-char (aref info
2))
1094 (delete-region (point) (aref info
3))
1095 (and (> (nth 1 entry
) (1+ extra
))
1098 (delete-horizontal-space)
1099 (if (looking-at "\n")
1100 ;; If there's a newline there, don't add one
1103 (delete-horizontal-space)
1105 ; (setq delta (1+ delta))
1106 (backward-char 1))))
1108 (set-marker (aref info
3) (+ (point) adjbot
))
1109 (set-marker (aref info
5) (+ (point) delta
))
1110 (aset info
6 str
))))))
1111 (if (eq (car-safe val
) 'calcFunc-evalto
)
1113 (setq evalled
(nth 2 val
)
1115 (if (eq (car-safe val
) 'calcFunc-assign
)
1117 (aset info
9 (nth 1 val
))
1118 (aset info
11 (or evalled
1119 (let ((calc-embedded-info info
))
1120 (math-evaluate-expr (nth 2 val
)))))
1121 (or (equal old-eval
(aref info
11))
1122 (calc-embedded-var-change (nth 1 val
) (aref info
0))))
1123 (if (eq (car-safe old-val
) 'calcFunc-evalto
)
1124 (setq old-val
(nth 1 old-val
)))
1125 (if (eq (car-safe old-val
) 'calcFunc-assign
)
1126 (calc-embedded-var-change (nth 1 old-val
) (aref info
0)))))
1127 (set-buffer (aref info
1))
1128 (while calc-embed-prev-modes
1129 (cond ((eq (car (car calc-embed-prev-modes
)) 'the-language
)
1131 (calc-embedded-set-language (cdr (car calc-embed-prev-modes
)))))
1132 ((eq (car (car calc-embed-prev-modes
)) 'the-display-just
)
1134 (calc-embedded-set-justify (cdr (car calc-embed-prev-modes
)))))
1136 (set (car (car calc-embed-prev-modes
))
1137 (cdr (car calc-embed-prev-modes
)))))
1138 (setq calc-embed-prev-modes
(cdr calc-embed-prev-modes
))))))
1143 ;;; These are hooks called by the main part of Calc.
1145 (defvar calc-embedded-no-reselect nil
)
1146 (defun calc-embedded-select-buffer ()
1147 (if (eq (current-buffer) (aref calc-embedded-info
0))
1148 (let ((info calc-embedded-info
)
1150 (if (and (or (< (point) (aref info
4))
1151 (> (point) (aref info
5)))
1152 (not calc-embedded-no-reselect
))
1153 (let ((calc-embedded-quiet t
))
1154 (message "(Switching Calc Embedded mode to new formula.)")
1156 (calc-embedded nil
)))
1157 (setq horiz
(max (min (current-column) (- (point) (aref info
2))) 0)
1158 vert
(if (<= (aref info
2) (point))
1159 (- (count-lines (aref info
2) (point))
1162 (set-buffer (aref info
1))
1166 (setq vert
(1- vert
))))
1167 (calc-cursor-stack-index 1)
1168 (if calc-line-numbering
1169 (setq horiz
(+ horiz
4)))
1171 (forward-line vert
))
1172 (forward-char (min horiz
1173 (- (point-max) (point)))))
1174 (calc-select-buffer)))
1176 (defun calc-embedded-finish-command ()
1177 (let ((buf (current-buffer))
1180 (set-buffer (aref calc-embedded-info
1))
1181 (if (> (calc-stack-size) 0)
1183 (col (current-column))
1185 (calc-cursor-stack-index 0)
1188 (calc-cursor-stack-index 1)
1191 (setq horiz
(- col
(if calc-line-numbering
4 0))
1192 vert
(- (count-lines (point) pt
)
1195 (setq vert
(max 1 (1+ vert
))))))))
1199 (set-buffer (aref calc-embedded-info
0))
1200 (goto-char (aref calc-embedded-info
2))
1202 (forward-line vert
))
1203 (forward-char (max horiz
0))
1204 (set-buffer buf
)))))
1206 (defun calc-embedded-stack-change ()
1207 (or calc-executing-macro
1209 (set-buffer (aref calc-embedded-info
1))
1210 (let* ((info calc-embedded-info
)
1211 (extra-line (if (eq calc-language
'big
) 1 0))
1213 (empty (= (calc-stack-size) 0))
1215 (list '(var empty var-empty
) 1 nil
)
1216 (calc-top 1 'entry
)))
1217 (old-val (aref info
8))
1222 (calc-cursor-stack-index 1)
1224 (calc-cursor-stack-index 0)
1225 (setq bot
(- (point) extra-line
))
1226 (setq str
(buffer-substring top
(- bot
1))))
1227 (if calc-line-numbering
1229 (setq str
(substring str
4))
1230 (while (setq pos
(string-match "\n...." str pos
))
1231 (setq str
(concat (substring str
0 (1+ pos
))
1232 (substring str
(+ pos
5)))
1234 (calc-embedded-original-buffer t
)
1235 (aset info
8 (car entry
))
1236 (calc-embedded-update info
13 nil t str entry old-val
)))))
1238 (defun calc-embedded-mode-line-change ()
1239 (let ((str mode-line-buffer-identification
))
1241 (calc-embedded-original-buffer t
)
1242 (setq mode-line-buffer-identification str
)
1243 (set-buffer-modified-p (buffer-modified-p)))))
1245 (defun calc-embedded-modes-change (vars)
1246 (if (eq (car vars
) 'calc-language
) (setq vars
'(the-language)))
1247 (if (eq (car vars
) 'calc-display-just
) (setq vars
'(the-display-just)))
1249 (not (rassq (car vars
) calc-embedded-mode-vars
)))
1250 (setq vars
(cdr vars
)))
1251 (if (and vars calc-mode-save-mode
(not (eq calc-mode-save-mode
'save
)))
1253 (let* ((save-mode calc-mode-save-mode
)
1254 (header (if (eq save-mode
'local
)
1256 (format "calc-%s-mode:" save-mode
)))
1257 (the-language (calc-embedded-language))
1258 (the-display-just (calc-embedded-justify))
1259 (values (mapcar 'symbol-value vars
))
1260 (num (cond ((eq save-mode
'local
) 12)
1261 ((eq save-mode
'edit
) 13)
1262 ((eq save-mode
'perm
) 14)
1264 base limit mname mlist
)
1265 (calc-embedded-original-buffer t
)
1267 (if (eq save-mode
'global
)
1268 (setq base
(point-max)
1270 mlist calc-embedded-globals
)
1271 (goto-char (aref calc-embedded-info
4))
1274 limit
(max (- (point) 1000) (point-min))
1275 mlist
(and num
(aref calc-embedded-info num
)))
1276 (and (re-search-backward
1277 (format "\\(%s\\)[^\001]*\\(%s\\)\\|\\[calc-defaults]"
1278 calc-embedded-open-formula
1279 calc-embedded-close-formula
) limit t
)
1280 (setq limit
(point))))
1283 (if (setq mname
(car (rassq (car vars
)
1284 calc-embedded-mode-vars
)))
1285 (let ((buffer-read-only nil
)
1286 (found (assq (car vars
) mlist
)))
1288 (setcdr found
(car values
))
1289 (setq mlist
(cons (cons (car vars
) (car values
)) mlist
))
1291 (aset calc-embedded-info num mlist
)
1292 (if (eq save-mode
'global
)
1293 (setq calc-embedded-globals mlist
))))
1294 (if (re-search-backward
1295 (format "\\[%s *%s: *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]"
1299 (goto-char (match-beginning 1))
1300 (delete-region (point) (match-end 1))
1301 (insert (prin1-to-string (car values
))))
1303 (insert-before-markers
1304 calc-embedded-open-mode
1305 "[" header
" " mname
": "
1306 (prin1-to-string (car values
)) "]"
1307 calc-embedded-close-mode
))))
1308 (setq vars
(cdr vars
)
1309 values
(cdr values
))))))
1310 (when (and vars
(eq calc-mode-save-mode
'save
))
1311 (calc-embedded-save-original-modes))))
1313 (defun calc-embedded-var-change (var &optional buf
)
1315 (setq var
(list 'var
1316 (if (string-match "\\`var-.+\\'"
1318 (intern (substring (symbol-name var
) 4))
1322 (let ((manual (not calc-auto-recompute
))
1323 (bp calc-embedded-active
)
1325 (if buf
(setq bp
(memq (assq buf bp
) bp
)))
1327 (let ((calc-embedded-no-reselect t
)
1328 (p (and (buffer-name (car (car bp
)))
1331 (if (assoc var
(aref (car p
) 10))
1333 (if (aref (car p
) 11)
1335 (aset (car p
) 11 nil
)
1336 (if (aref (car p
) 9)
1337 (calc-embedded-var-change (aref (car p
) 9)))))
1338 (set-buffer (aref (car p
) 0))
1339 (if (equal (buffer-substring (aref (car p
) 2)
1342 (let ((calc-embedded-info nil
))
1343 (or calc-embedded-quiet
1344 (message "Recomputing..."))
1347 (set-buffer (aref (car p
) 0))
1348 (calc-embedded-update (car p
) 14 t nil
)))
1349 (setcdr (car bp
) (delq (car p
) (cdr (car bp
))))
1351 "(Tried to recompute but formula was changed or missing)"))))
1353 (setq bp
(if buf nil
(cdr bp
))))
1354 (or first calc-embedded-quiet
(message "")))))
1356 (provide 'calc-embed
)
1358 ;;; arch-tag: 1b8f311e-fba1-40d3-b8c3-1d6f68fd26fc
1359 ;;; calc-embed.el ends here