Mercurial > emacs
annotate lisp/calc/calc-embed.el @ 62492:2d94ce2501bb
*** empty log message ***
author | Daniel Pfeiffer <occitan@esperanto.org> |
---|---|
date | Wed, 18 May 2005 20:12:10 +0000 |
parents | eb739125ed5a |
children | 7cff9cbc5ea3 62afea0771d8 |
rev | line source |
---|---|
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1 ;;; calc-embed.el --- embed Calc in a buffer |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
2 |
61214 | 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2005 Free Software Foundation, Inc. |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
5 ;; Author: David Gillespie <daveg@synaptics.com> |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is distributed in the hope that it will be useful, | |
11 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
12 ;; accepts responsibility to anyone for the consequences of using it | |
13 ;; or for whether it serves any particular purpose or works at all, | |
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
15 ;; License for full details. | |
16 | |
17 ;; Everyone is granted permission to copy, modify and redistribute | |
18 ;; GNU Emacs, but only under the conditions described in the | |
19 ;; GNU Emacs General Public License. A copy of this license is | |
20 ;; supposed to have been given to you along with GNU Emacs so you | |
21 ;; can know your rights and responsibilities. It should be in a | |
22 ;; file named COPYING. Among other things, the copyright notice | |
23 ;; and this notice must be preserved on all copies. | |
24 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
25 ;;; Commentary: |
40785 | 26 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
27 ;;; Code: |
40785 | 28 |
29 ;; This file is autoloaded from calc-ext.el. | |
58651
05765b6fc9cd
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58557
diff
changeset
|
30 |
40785 | 31 (require 'calc-ext) |
32 (require 'calc-macs) | |
33 | |
34 (defun calc-show-plain (n) | |
35 (interactive "P") | |
36 (calc-wrapper | |
37 (calc-set-command-flag 'renum-stack) | |
38 (message (if (calc-change-mode 'calc-show-plain n nil t) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
39 "Including \"plain\" formulas in Calc Embedded mode" |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
40 "Omitting \"plain\" formulas in Calc Embedded mode")))) |
40785 | 41 |
42 | |
43 (defvar calc-embedded-modes nil) | |
44 (defvar calc-embedded-globals nil) | |
45 (defvar calc-embedded-active nil) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
46 (defvar calc-embedded-all-active nil) |
40785 | 47 (make-variable-buffer-local 'calc-embedded-all-active) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
48 (defvar calc-embedded-some-active nil) |
40785 | 49 (make-variable-buffer-local 'calc-embedded-some-active) |
50 | |
61214 | 51 ;; The following variables are customizable and defined in calc.el. |
52 (defvar calc-embedded-announce-formula) | |
53 (defvar calc-embedded-open-formula) | |
54 (defvar calc-embedded-close-formula) | |
55 (defvar calc-embedded-open-word) | |
56 (defvar calc-embedded-close-word) | |
57 (defvar calc-embedded-open-plain) | |
58 (defvar calc-embedded-close-plain) | |
59 (defvar calc-embedded-open-new-formula) | |
60 (defvar calc-embedded-close-new-formula) | |
61 (defvar calc-embedded-open-mode) | |
62 (defvar calc-embedded-close-mode) | |
40785 | 63 |
64 (defconst calc-embedded-mode-vars '(("precision" . calc-internal-prec) | |
65 ("word-size" . calc-word-size) | |
66 ("angles" . calc-angle-mode) | |
67 ("symbolic" . calc-symbolic-mode) | |
68 ("matrix" . calc-matrix-mode) | |
69 ("fractions" . calc-prefer-frac) | |
70 ("complex" . calc-complex-mode) | |
71 ("simplify" . calc-simplify-mode) | |
72 ("language" . the-language) | |
73 ("plain" . calc-show-plain) | |
74 ("break" . calc-line-breaking) | |
75 ("justify" . the-display-just) | |
76 ("left-label" . calc-left-label) | |
77 ("right-label" . calc-right-label) | |
78 ("radix" . calc-number-radix) | |
79 ("leading-zeros" . calc-leading-zeros) | |
80 ("grouping" . calc-group-digits) | |
81 ("group-char" . calc-group-char) | |
82 ("point-char" . calc-point-char) | |
83 ("frac-format" . calc-frac-format) | |
84 ("float-format" . calc-float-format) | |
85 ("complex-format" . calc-complex-format) | |
86 ("hms-format" . calc-hms-format) | |
87 ("date-format" . calc-date-format) | |
88 ("matrix-justify" . calc-matrix-just) | |
89 ("full-vectors" . calc-full-vectors) | |
90 ("break-vectors" . calc-break-vectors) | |
91 ("vector-commas" . calc-vector-commas) | |
92 ("vector-brackets" . calc-vector-brackets) | |
93 ("matrix-brackets" . calc-matrix-brackets) | |
94 ("strings" . calc-display-strings) | |
95 )) | |
96 | |
97 | |
98 ;;; Format of calc-embedded-info vector: | |
99 ;;; 0 Editing buffer. | |
100 ;;; 1 Calculator buffer. | |
101 ;;; 2 Top of current formula (marker). | |
102 ;;; 3 Bottom of current formula (marker). | |
103 ;;; 4 Top of current formula's delimiters (marker). | |
104 ;;; 5 Bottom of current formula's delimiters (marker). | |
105 ;;; 6 String representation of current formula. | |
106 ;;; 7 Non-nil if formula is embedded within a single line. | |
107 ;;; 8 Internal representation of current formula. | |
108 ;;; 9 Variable assigned by this formula, or nil. | |
109 ;;; 10 List of variables upon which this formula depends. | |
110 ;;; 11 Evaluated value of the formula, or nil. | |
111 ;;; 12 Mode settings for current formula. | |
112 ;;; 13 Local mode settings for current formula. | |
113 ;;; 14 Permanent mode settings for current formula. | |
114 ;;; 15 Global mode settings for editing buffer. | |
115 | |
116 | |
117 ;;; calc-embedded-active is an a-list keyed on buffers; each cdr is a | |
118 ;;; sorted list of calc-embedded-infos in that buffer. We do this | |
119 ;;; rather than using buffer-local variables because the latter are | |
120 ;;; thrown away when a buffer changes major modes. | |
121 | |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
122 (defvar calc-embedded-original-modes nil |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
123 "The mode settings for Calc buffer when put in embedded mode.") |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
124 |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
125 (defun calc-embedded-save-original-modes () |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
126 "Save the current Calc modes when entereding embedded mode." |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
127 (let ((calcbuf (save-excursion |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
128 (calc-create-buffer) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
129 (current-buffer))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
130 lang modes) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
131 (if calcbuf |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
132 (with-current-buffer calcbuf |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
133 (setq lang |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
134 (cons calc-language calc-language-option)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
135 (setq modes |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
136 (list (cons 'calc-display-just |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
137 calc-display-just) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
138 (cons 'calc-display-origin |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
139 calc-display-origin))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
140 (let ((v calc-embedded-mode-vars)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
141 (while v |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
142 (let ((var (cdr (car v)))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
143 (unless (memq var '(the-language the-display-just)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
144 (setq modes |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
145 (cons (cons var (symbol-value var)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
146 modes)))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
147 (setq v (cdr v)))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
148 (setq calc-embedded-original-modes (cons lang modes))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
149 (setq calc-embedded-original-modes nil)))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
150 |
62175
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
151 (defun calc-embedded-preserve-modes () |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
152 "Preserve the current modes when leaving embedded mode." |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
153 (interactive) |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
154 (if calc-embedded-info |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
155 (progn |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
156 (calc-embedded-save-original-modes) |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
157 (message "Current modes will be preserved when leaving embedded mode.")) |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
158 (message "Not in embedded mode."))) |
eb739125ed5a
(calc-embedded-preserve-modes): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
61214
diff
changeset
|
159 |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
160 (defun calc-embedded-restore-original-modes () |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
161 "Restore the original Calc modes when leaving embedded mode." |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
162 (let ((calcbuf (get-buffer "*Calculator*")) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
163 (changed nil) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
164 (lang (car calc-embedded-original-modes)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
165 (modes (cdr calc-embedded-original-modes))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
166 (if (and calcbuf calc-embedded-original-modes) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
167 (with-current-buffer calcbuf |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
168 (unless (and |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
169 (equal calc-language (car lang)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
170 (equal calc-language-option (cdr lang))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
171 (calc-set-language (car lang) (cdr lang)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
172 (setq changed t)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
173 (while modes |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
174 (let ((mode (car modes))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
175 (unless (equal (symbol-value (car mode)) (cdr mode)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
176 (set (car mode) (cdr mode)) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
177 (setq changed t))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
178 (setq modes (cdr modes))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
179 (when changed |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
180 (calc-refresh) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
181 (calc-set-mode-line)))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
182 (setq calc-embedded-original-modes nil))) |
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
183 |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
184 ;; The variables calc-embed-outer-top, calc-embed-outer-bot, |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
185 ;; calc-embed-top and calc-embed-bot are |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
186 ;; local to calc-do-embedded, calc-embedded-mark-formula, |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
187 ;; calc-embedded-duplicate, calc-embedded-new-formula and |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
188 ;; calc-embedded-make-info, but are used by calc-embedded-find-bounds, |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
189 ;; which is called (directly or indirectly) by the above functions. |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
190 (defvar calc-embed-outer-top) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
191 (defvar calc-embed-outer-bot) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
192 (defvar calc-embed-top) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
193 (defvar calc-embed-bot) |
40785 | 194 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
195 (defvar calc-embedded-quiet nil) |
40785 | 196 (defun calc-do-embedded (arg end obeg oend) |
197 (if calc-embedded-info | |
198 | |
199 ;; Turn embedded mode off or switch to a new buffer. | |
200 (cond ((eq (current-buffer) (aref calc-embedded-info 1)) | |
201 (let ((calcbuf (current-buffer)) | |
202 (buf (aref calc-embedded-info 0))) | |
203 (calc-embedded-original-buffer t) | |
204 (calc-embedded nil) | |
205 (switch-to-buffer calcbuf))) | |
206 | |
207 ((eq (current-buffer) (aref calc-embedded-info 0)) | |
208 (let* ((info calc-embedded-info) | |
209 (mode calc-embedded-modes)) | |
210 (save-excursion | |
211 (set-buffer (aref info 1)) | |
212 (if (and (> (calc-stack-size) 0) | |
213 (equal (calc-top 1 'full) (aref info 8))) | |
214 (let ((calc-no-refresh-evaltos t)) | |
215 (if (calc-top 1 'sel) | |
216 (calc-unselect 1)) | |
217 (calc-embedded-set-modes | |
218 (aref info 15) (aref info 12) (aref info 14)) | |
219 (let ((calc-embedded-info nil)) | |
220 (calc-wrapper (calc-pop-stack)))) | |
221 (calc-set-mode-line))) | |
222 (setq calc-embedded-info nil | |
223 mode-line-buffer-identification (car mode) | |
224 truncate-lines (nth 2 mode) | |
225 buffer-read-only nil) | |
226 (use-local-map (nth 1 mode)) | |
227 (set-buffer-modified-p (buffer-modified-p)) | |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
228 (calc-embedded-restore-original-modes) |
40785 | 229 (or calc-embedded-quiet |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
230 (message "Back to %s mode" mode-name)))) |
40785 | 231 |
232 (t | |
233 (if (buffer-name (aref calc-embedded-info 0)) | |
234 (save-excursion | |
235 (set-buffer (aref calc-embedded-info 0)) | |
40996
5a413baa253c
(calc-do-embedded): Call `y-or-n-p' with
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
236 (or (y-or-n-p (format "Cancel Calc Embedded mode in buffer %s? " |
5a413baa253c
(calc-do-embedded): Call `y-or-n-p' with
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
237 (buffer-name))) |
40785 | 238 (keyboard-quit)) |
239 (calc-embedded nil))) | |
240 (calc-embedded arg end obeg oend))) | |
241 | |
242 ;; Turn embedded mode on. | |
243 (calc-plain-buffer-only) | |
244 (let ((modes (list mode-line-buffer-identification | |
245 (current-local-map) | |
246 truncate-lines)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
247 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot |
40785 | 248 info chg ident) |
249 (barf-if-buffer-read-only) | |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
250 (calc-embedded-save-original-modes) |
40785 | 251 (or calc-embedded-globals |
252 (calc-find-globals)) | |
253 (setq info (calc-embedded-make-info (point) nil t arg end obeg oend)) | |
254 (if (eq (car-safe (aref info 8)) 'error) | |
255 (progn | |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
256 (setq calc-embedded-original-modes nil) |
40785 | 257 (goto-char (nth 1 (aref info 8))) |
258 (error (nth 2 (aref info 8))))) | |
259 (let ((mode-line-buffer-identification mode-line-buffer-identification) | |
260 (calc-embedded-info info) | |
261 (calc-embedded-no-reselect t)) | |
262 (calc-wrapper | |
263 (let* ((okay nil) | |
264 (calc-no-refresh-evaltos t)) | |
265 (if (aref info 8) | |
60770 | 266 (progn |
267 (calc-push (calc-normalize (aref info 8))) | |
268 (setq chg (calc-embedded-set-modes | |
269 (aref info 15) (aref info 12) (aref info 13)))) | |
270 (setq chg (calc-embedded-set-modes | |
271 (aref info 15) (aref info 12) (aref info 13))) | |
40785 | 272 (calc-alg-entry))) |
273 (setq calc-undo-list nil | |
274 calc-redo-list nil | |
275 ident mode-line-buffer-identification))) | |
276 (setq calc-embedded-info info | |
277 calc-embedded-modes modes | |
278 mode-line-buffer-identification ident | |
279 truncate-lines t | |
280 buffer-read-only t) | |
281 (set-buffer-modified-p (buffer-modified-p)) | |
282 (use-local-map calc-mode-map) | |
283 (setq calc-no-refresh-evaltos nil) | |
284 (and chg calc-any-evaltos (calc-wrapper (calc-refresh-evaltos))) | |
60507
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
285 (let (str) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
286 (save-excursion |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
287 (calc-select-buffer) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
288 (setq str mode-line-buffer-identification)) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
289 (unless (equal str mode-line-buffer-identification) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
290 (setq mode-line-buffer-identification str) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
291 (set-buffer-modified-p (buffer-modified-p)))) |
40785 | 292 (or (eq calc-embedded-quiet t) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
293 (message "Embedded Calc mode enabled; %s to return to normal" |
40785 | 294 (if calc-embedded-quiet |
295 "Type `M-# x'" | |
296 "Give this command again"))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
297 (scroll-down 0)) ; fix a bug which occurs when truncate-lines is changed. |
40785 | 298 |
299 | |
300 (defun calc-embedded-select (arg) | |
301 (interactive "P") | |
302 (calc-embedded arg) | |
303 (and calc-embedded-info | |
304 (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto) | |
305 (calc-select-part 1)) | |
306 (and calc-embedded-info | |
307 (or (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-assign) | |
308 (and (eq (car-safe (aref calc-embedded-info 8)) 'calcFunc-evalto) | |
309 (eq (car-safe (nth 1 (aref calc-embedded-info 8))) | |
310 'calcFunc-assign))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
311 (calc-select-part 2))) |
40785 | 312 |
313 | |
314 (defun calc-embedded-update-formula (arg) | |
315 (interactive "P") | |
316 (if arg | |
317 (let ((entry (assq (current-buffer) calc-embedded-active))) | |
318 (while (setq entry (cdr entry)) | |
319 (and (eq (car-safe (aref (car entry) 8)) 'calcFunc-evalto) | |
320 (or (not (consp arg)) | |
321 (and (<= (aref (car entry) 2) (region-beginning)) | |
322 (>= (aref (car entry) 3) (region-end)))) | |
323 (save-excursion | |
324 (calc-embedded-update (car entry) 14 t t))))) | |
325 (if (and calc-embedded-info | |
326 (eq (current-buffer) (aref calc-embedded-info 0)) | |
327 (>= (point) (aref calc-embedded-info 4)) | |
328 (<= (point) (aref calc-embedded-info 5))) | |
329 (calc-evaluate 1) | |
330 (let* ((opt (point)) | |
331 (info (calc-embedded-make-info (point) nil t)) | |
332 (pt (- opt (aref info 4)))) | |
333 (or (eq (car-safe (aref info 8)) 'error) | |
334 (progn | |
335 (save-excursion | |
336 (calc-embedded-update info 14 'eval t)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
337 (goto-char (+ (aref info 4) pt)))))))) |
40785 | 338 |
339 | |
340 (defun calc-embedded-edit (arg) | |
341 (interactive "P") | |
342 (let ((info (calc-embedded-make-info (point) nil t arg)) | |
343 str) | |
344 (if (eq (car-safe (aref info 8)) 'error) | |
345 (progn | |
346 (goto-char (nth 1 (aref info 8))) | |
347 (error (nth 2 (aref info 8))))) | |
348 (calc-wrapper | |
349 (setq str (math-showing-full-precision | |
40996
5a413baa253c
(calc-do-embedded): Call `y-or-n-p' with
Eli Zaretskii <eliz@gnu.org>
parents:
40785
diff
changeset
|
350 (math-format-nice-expr (aref info 8) (frame-width)))) |
40785 | 351 (calc-edit-mode (list 'calc-embedded-finish-edit info)) |
352 (insert str "\n"))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
353 (calc-show-edit-buffer)) |
40785 | 354 |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
355 (defvar calc-original-buffer) |
59308
8f487d424820
(calc-embedded-finish-edit): Use calc-edit-top for the beginning of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58651
diff
changeset
|
356 (defvar calc-edit-top) |
40785 | 357 (defun calc-embedded-finish-edit (info) |
358 (let ((buf (current-buffer)) | |
59308
8f487d424820
(calc-embedded-finish-edit): Use calc-edit-top for the beginning of
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58651
diff
changeset
|
359 (str (buffer-substring calc-edit-top (point-max))) |
40785 | 360 (start (point)) |
361 pos) | |
362 (switch-to-buffer calc-original-buffer) | |
363 (let ((val (save-excursion | |
364 (set-buffer (aref info 1)) | |
365 (let ((calc-language nil) | |
366 (math-expr-opers math-standard-opers)) | |
367 (math-read-expr str))))) | |
368 (if (eq (car-safe val) 'error) | |
369 (progn | |
370 (switch-to-buffer buf) | |
371 (goto-char (+ start (nth 1 val))) | |
372 (error (nth 2 val)))) | |
373 (calc-embedded-original-buffer t info) | |
374 (aset info 8 val) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
375 (calc-embedded-update info 14 t t)))) |
40785 | 376 |
377 (defun calc-do-embedded-activate (arg cbuf) | |
378 (calc-plain-buffer-only) | |
379 (if arg | |
380 (calc-embedded-forget)) | |
381 (calc-find-globals) | |
382 (if (< (prefix-numeric-value arg) 0) | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
383 (message "Deactivating %s for Calc Embedded mode" (buffer-name)) |
40785 | 384 (message "Activating %s for Calc Embedded mode..." (buffer-name)) |
385 (save-excursion | |
386 (let* ((active (assq (current-buffer) calc-embedded-active)) | |
387 (info active) | |
388 (pat " := \\| \\\\gets \\| => \\| \\\\evalto ")) | |
389 (if calc-embedded-announce-formula | |
390 (setq pat (format "%s\\|\\(%s\\)" | |
391 pat calc-embedded-announce-formula))) | |
392 (while (setq info (cdr info)) | |
393 (or (equal (buffer-substring (aref (car info) 2) (aref (car info) 3)) | |
394 (aref (car info) 6)) | |
395 (setcdr active (delq (car info) (cdr active))))) | |
396 (goto-char (point-min)) | |
397 (while (re-search-forward pat nil t) | |
53996
28c3a99598f0
(calc-do-embedded-activate): Add autoload
Eli Zaretskii <eliz@is.elta.co.il>
parents:
52401
diff
changeset
|
398 ;;; (if (looking-at calc-embedded-open-formula) |
28c3a99598f0
(calc-do-embedded-activate): Add autoload
Eli Zaretskii <eliz@is.elta.co.il>
parents:
52401
diff
changeset
|
399 ;;; (goto-char (match-end 1))) |
40785 | 400 (setq info (calc-embedded-make-info (point) cbuf nil)) |
401 (or (eq (car-safe (aref info 8)) 'error) | |
402 (goto-char (aref info 5)))))) | |
403 (message "Activating %s for Calc Embedded mode...done" (buffer-name))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
404 (calc-embedded-active-state t)) |
40785 | 405 |
406 (defun calc-plain-buffer-only () | |
407 (if (memq major-mode '(calc-mode calc-trail-mode calc-edit-mode)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
408 (error "This command should be used in a normal editing buffer"))) |
40785 | 409 |
410 (defun calc-embedded-active-state (state) | |
411 (or (assq 'calc-embedded-all-active minor-mode-alist) | |
412 (setq minor-mode-alist | |
413 (cons '(calc-embedded-all-active " Active") | |
414 (cons '(calc-embedded-some-active " ~Active") | |
415 minor-mode-alist)))) | |
416 (let ((active (assq (current-buffer) calc-embedded-active))) | |
417 (or (cdr active) | |
418 (setq state nil))) | |
419 (and (eq state 'more) calc-embedded-all-active (setq state t)) | |
420 (setq calc-embedded-all-active (eq state t) | |
421 calc-embedded-some-active (not (memq state '(nil t)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
422 (set-buffer-modified-p (buffer-modified-p))) |
40785 | 423 |
424 | |
425 (defun calc-embedded-original-buffer (switch &optional info) | |
426 (or info (setq info calc-embedded-info)) | |
427 (or (buffer-name (aref info 0)) | |
428 (progn | |
429 (error "Calc embedded mode: Original buffer has been killed"))) | |
430 (if switch | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
431 (set-buffer (aref info 0)))) |
40785 | 432 |
433 (defun calc-embedded-word () | |
434 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
435 (calc-embedded '(4))) |
40785 | 436 |
437 (defun calc-embedded-mark-formula (&optional body-only) | |
438 "Put point at the beginning of this Calc formula, mark at the end. | |
439 This normally marks the whole formula, including surrounding delimiters. | |
440 With any prefix argument, marks only the formula itself." | |
441 (interactive "P") | |
442 (and (eq major-mode 'calc-mode) | |
443 (error "This command should be used in a normal editing buffer")) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
444 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot) |
40785 | 445 (save-excursion |
446 (calc-embedded-find-bounds body-only)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
447 (push-mark (if body-only calc-embed-bot calc-embed-outer-bot) t) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
448 (goto-char (if body-only calc-embed-top calc-embed-outer-top)))) |
40785 | 449 |
450 (defun calc-embedded-find-bounds (&optional plain) | |
451 ;; (while (and (bolp) (eq (following-char) ?\n)) | |
452 ;; (forward-char 1)) | |
453 (and (eolp) (bolp) (not (eq (char-after (- (point) 2)) ?\n)) | |
454 (forward-char -1)) | |
455 (let ((home (point))) | |
456 (or (and (looking-at calc-embedded-open-formula) | |
457 (not (looking-at calc-embedded-close-formula))) | |
458 (re-search-backward calc-embedded-open-formula nil t) | |
459 (error "Can't find start of formula")) | |
460 (and (eq (preceding-char) ?\$) ; backward search for \$\$? won't back | |
461 (eq (following-char) ?\$) ; up over a second $, so do it by hand. | |
462 (forward-char -1)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
463 (setq calc-embed-outer-top (point)) |
40785 | 464 (goto-char (match-end 0)) |
59840
a4073cba09cb
(calc-embedded-find-bounds): Set formula bound on line with formula.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59827
diff
changeset
|
465 (if (looking-at "[ \t]*$") |
a4073cba09cb
(calc-embedded-find-bounds): Set formula bound on line with formula.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59827
diff
changeset
|
466 (end-of-line)) |
40785 | 467 (if (eq (following-char) ?\n) |
468 (forward-char 1)) | |
469 (or (bolp) | |
470 (while (eq (following-char) ?\ ) | |
471 (forward-char 1))) | |
472 (or (eq plain 'plain) | |
473 (if (looking-at (regexp-quote calc-embedded-open-plain)) | |
474 (progn | |
475 (goto-char (match-end 0)) | |
476 (search-forward calc-embedded-close-plain)))) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
477 (setq calc-embed-top (point)) |
40785 | 478 (or (re-search-forward calc-embedded-close-formula nil t) |
479 (error "Can't find end of formula")) | |
480 (if (< (point) home) | |
481 (error "Not inside a formula")) | |
482 (and (eq (following-char) ?\n) (not (bolp)) | |
483 (forward-char 1)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
484 (setq calc-embed-outer-bot (point)) |
40785 | 485 (goto-char (match-beginning 0)) |
486 (if (eq (preceding-char) ?\n) | |
487 (backward-char 1)) | |
488 (or (eolp) | |
489 (while (eq (preceding-char) ?\ ) | |
490 (backward-char 1))) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
491 (setq calc-embed-bot (point)))) |
40785 | 492 |
493 (defun calc-embedded-kill-formula () | |
494 "Kill the formula surrounding point. | |
495 If Calc Embedded mode was active, this deactivates it. | |
496 The formula (including its surrounding delimiters) is saved in the kill ring. | |
497 The command \\[yank] can retrieve it from there." | |
498 (interactive) | |
499 (and calc-embedded-info | |
500 (calc-embedded nil)) | |
501 (calc-embedded-mark-formula) | |
502 (kill-region (point) (mark)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
503 (pop-mark)) |
40785 | 504 |
505 (defun calc-embedded-copy-formula-as-kill () | |
506 "Save the formula surrounding point as if killed, but don't kill it." | |
507 (interactive) | |
508 (save-excursion | |
509 (calc-embedded-mark-formula) | |
510 (copy-region-as-kill (point) (mark)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
511 (pop-mark))) |
40785 | 512 |
513 (defun calc-embedded-duplicate () | |
514 (interactive) | |
515 (let ((already calc-embedded-info) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
516 calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot new-top) |
40785 | 517 (if calc-embedded-info |
518 (progn | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
519 (setq calc-embed-top (+ (aref calc-embedded-info 2)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
520 calc-embed-bot (+ (aref calc-embedded-info 3)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
521 calc-embed-outer-top (+ (aref calc-embedded-info 4)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
522 calc-embed-outer-bot (+ (aref calc-embedded-info 5))) |
40785 | 523 (calc-embedded nil)) |
524 (calc-embedded-find-bounds)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
525 (goto-char calc-embed-outer-bot) |
40785 | 526 (insert "\n") |
527 (setq new-top (point)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
528 (insert-buffer-substring (current-buffer) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
529 calc-embed-outer-top calc-embed-outer-bot) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
530 (goto-char (+ new-top (- calc-embed-top calc-embed-outer-top))) |
40785 | 531 (let ((calc-embedded-quiet (if already t 'x))) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
532 (calc-embedded (+ new-top (- calc-embed-top calc-embed-outer-top)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
533 (+ new-top (- calc-embed-bot calc-embed-outer-top)) |
40785 | 534 new-top |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
535 (+ new-top (- calc-embed-outer-bot calc-embed-outer-top)))))) |
40785 | 536 |
537 (defun calc-embedded-next (arg) | |
538 (interactive "P") | |
539 (setq arg (prefix-numeric-value arg)) | |
540 (let* ((active (cdr (assq (current-buffer) calc-embedded-active))) | |
541 (p active) | |
542 (num (length active))) | |
543 (or active | |
544 (error "No active formulas in buffer")) | |
545 (cond ((= arg 0)) | |
546 ((= arg -1) | |
547 (if (<= (point) (aref (car active) 3)) | |
548 (goto-char (aref (nth (1- num) active) 2)) | |
549 (while (and (cdr p) | |
550 (> (point) (aref (nth 1 p) 3))) | |
551 (setq p (cdr p))) | |
552 (goto-char (aref (car p) 2)))) | |
553 ((< arg -1) | |
554 (calc-embedded-next -1) | |
555 (calc-embedded-next (+ (* num 1000) arg 1))) | |
556 (t | |
557 (setq arg (1+ (% (1- arg) num))) | |
558 (while (and p (>= (point) (aref (car p) 2))) | |
559 (setq p (cdr p))) | |
560 (while (> (setq arg (1- arg)) 0) | |
561 (setq p (if p (cdr p) (cdr active)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
562 (goto-char (aref (car (or p active)) 2)))))) |
40785 | 563 |
564 (defun calc-embedded-previous (arg) | |
565 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
566 (calc-embedded-next (- (prefix-numeric-value arg)))) |
40785 | 567 |
568 (defun calc-embedded-new-formula () | |
569 (interactive) | |
570 (and (eq major-mode 'calc-mode) | |
571 (error "This command should be used in a normal editing buffer")) | |
572 (if calc-embedded-info | |
573 (calc-embedded nil)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
574 (let (calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot) |
40785 | 575 (if (and (eq (preceding-char) ?\n) |
576 (string-match "\\`\n" calc-embedded-open-new-formula)) | |
577 (progn | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
578 (setq calc-embed-outer-top (1- (point))) |
40785 | 579 (forward-char -1) |
580 (insert (substring calc-embedded-open-new-formula 1))) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
581 (setq calc-embed-outer-top (point)) |
40785 | 582 (insert calc-embedded-open-new-formula)) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
583 (setq calc-embed-top (point)) |
40785 | 584 (insert " ") |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
585 (setq calc-embed-bot (point)) |
40785 | 586 (insert calc-embedded-close-new-formula) |
587 (if (and (eq (following-char) ?\n) | |
588 (string-match "\n\\'" calc-embedded-close-new-formula)) | |
589 (delete-char 1)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
590 (setq calc-embed-outer-bot (point)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
591 (goto-char calc-embed-top) |
40785 | 592 (let ((calc-embedded-quiet 'x)) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
593 (calc-embedded calc-embed-top calc-embed-bot calc-embed-outer-top calc-embed-outer-bot)))) |
40785 | 594 |
595 (defun calc-embedded-forget () | |
596 (interactive) | |
597 (setq calc-embedded-active (delq (assq (current-buffer) calc-embedded-active) | |
598 calc-embedded-active)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
599 (calc-embedded-active-state nil)) |
40785 | 600 |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
601 ;; The variables calc-embed-prev-modes is local to calc-embedded-update, |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
602 ;; but is used by calc-embedded-set-modes. |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
603 (defvar calc-embed-prev-modes) |
40785 | 604 |
605 (defun calc-embedded-set-modes (gmodes modes local-modes &optional temp) | |
606 (let ((the-language (calc-embedded-language)) | |
607 (the-display-just (calc-embedded-justify)) | |
608 (v gmodes) | |
609 (changed nil) | |
610 found value) | |
611 (while v | |
612 (or (symbolp (car v)) | |
613 (and (setq found (assq (car (car v)) modes)) | |
614 (not (eq (cdr found) 'default))) | |
615 (and (setq found (assq (car (car v)) local-modes)) | |
616 (not (eq (cdr found) 'default))) | |
617 (progn | |
618 (if (eq (setq value (cdr (car v))) 'default) | |
57116
344baab70c72
calc/calc-embed.el (calc-embedded-set-modes): Use
Jay Belanger <jay.p.belanger@gmail.com>
parents:
53996
diff
changeset
|
619 (setq value (list (nth 1 (assq (car (car v)) calc-mode-var-list))))) |
40785 | 620 (equal (symbol-value (car (car v))) value)) |
621 (progn | |
622 (setq changed t) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
623 (if temp (setq calc-embed-prev-modes |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
624 (cons (cons (car (car v)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
625 (symbol-value (car (car v)))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
626 calc-embed-prev-modes))) |
40785 | 627 (set (car (car v)) value))) |
628 (setq v (cdr v))) | |
629 (setq v modes) | |
630 (while v | |
631 (or (and (setq found (assq (car (car v)) local-modes)) | |
632 (not (eq (cdr found) 'default))) | |
633 (eq (setq value (cdr (car v))) 'default) | |
634 (equal (symbol-value (car (car v))) value) | |
635 (progn | |
636 (setq changed t) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
637 (if temp (setq calc-embed-prev-modes (cons (cons (car (car v)) |
40785 | 638 (symbol-value (car (car v)))) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
639 calc-embed-prev-modes))) |
40785 | 640 (set (car (car v)) value))) |
641 (setq v (cdr v))) | |
642 (setq v local-modes) | |
643 (while v | |
644 (or (eq (setq value (cdr (car v))) 'default) | |
645 (equal (symbol-value (car (car v))) value) | |
646 (progn | |
647 (setq changed t) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
648 (if temp (setq calc-embed-prev-modes (cons (cons (car (car v)) |
40785 | 649 (symbol-value (car (car v)))) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
650 calc-embed-prev-modes))) |
40785 | 651 (set (car (car v)) value))) |
652 (setq v (cdr v))) | |
653 (and changed (not (eq temp t)) | |
654 (progn | |
655 (calc-embedded-set-justify the-display-just) | |
656 (calc-embedded-set-language the-language))) | |
657 (and changed (not temp) | |
658 (progn | |
659 (setq calc-full-float-format (list (if (eq (car calc-float-format) | |
660 'fix) | |
661 'float | |
662 (car calc-float-format)) | |
663 0)) | |
664 (calc-refresh))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
665 changed)) |
40785 | 666 |
667 (defun calc-embedded-language () | |
668 (if calc-language-option | |
669 (list calc-language calc-language-option) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
670 calc-language)) |
40785 | 671 |
672 (defun calc-embedded-set-language (lang) | |
673 (let ((option nil)) | |
674 (if (consp lang) | |
675 (setq option (nth 1 lang) | |
676 lang (car lang))) | |
677 (or (and (eq lang calc-language) | |
678 (equal option calc-language-option)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
679 (calc-set-language lang option t)))) |
40785 | 680 |
681 (defun calc-embedded-justify () | |
682 (if calc-display-origin | |
683 (list calc-display-just calc-display-origin) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
684 calc-display-just)) |
40785 | 685 |
686 (defun calc-embedded-set-justify (just) | |
687 (if (consp just) | |
688 (setq calc-display-origin (nth 1 just) | |
689 calc-display-just (car just)) | |
690 (setq calc-display-just just | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
691 calc-display-origin nil))) |
40785 | 692 |
693 | |
694 (defun calc-find-globals () | |
695 (interactive) | |
696 (and (eq major-mode 'calc-mode) | |
697 (error "This command should be used in a normal editing buffer")) | |
698 (make-local-variable 'calc-embedded-globals) | |
699 (let ((case-fold-search nil) | |
700 (modes nil) | |
701 (save-pt (point)) | |
702 found value) | |
703 (goto-char (point-min)) | |
704 (while (re-search-forward "\\[calc-global-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)\\]" nil t) | |
705 (and (setq found (assoc (buffer-substring (match-beginning 1) | |
706 (match-end 1)) | |
707 calc-embedded-mode-vars)) | |
708 (or (assq (cdr found) modes) | |
709 (setq modes (cons (cons (cdr found) | |
710 (car (read-from-string | |
711 (buffer-substring | |
712 (match-beginning 2) | |
713 (match-end 2))))) | |
714 modes))))) | |
715 (setq calc-embedded-globals (cons t modes)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
716 (goto-char save-pt))) |
40785 | 717 |
718 (defun calc-embedded-find-modes () | |
719 (let ((case-fold-search nil) | |
720 (save-pt (point)) | |
721 (no-defaults t) | |
722 (modes nil) | |
723 (emodes nil) | |
724 (pmodes nil) | |
725 found value) | |
726 (while (and no-defaults (search-backward "[calc-" nil t)) | |
727 (forward-char 6) | |
728 (or (and (looking-at "mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]") | |
729 (setq found (assoc (buffer-substring (match-beginning 1) | |
730 (match-end 1)) | |
731 calc-embedded-mode-vars)) | |
732 (or (assq (cdr found) modes) | |
733 (setq modes (cons (cons (cdr found) | |
734 (car (read-from-string | |
735 (buffer-substring | |
736 (match-beginning 2) | |
737 (match-end 2))))) | |
738 modes)))) | |
739 (and (looking-at "perm-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]") | |
740 (setq found (assoc (buffer-substring (match-beginning 1) | |
741 (match-end 1)) | |
742 calc-embedded-mode-vars)) | |
743 (or (assq (cdr found) pmodes) | |
744 (setq pmodes (cons (cons (cdr found) | |
745 (car (read-from-string | |
746 (buffer-substring | |
747 (match-beginning 2) | |
748 (match-end 2))))) | |
749 pmodes)))) | |
750 (and (looking-at "edit-mode: *\\([-a-z]+\\): *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]") | |
751 (setq found (assoc (buffer-substring (match-beginning 1) | |
752 (match-end 1)) | |
753 calc-embedded-mode-vars)) | |
754 (or (assq (cdr found) emodes) | |
755 (setq emodes (cons (cons (cdr found) | |
756 (car (read-from-string | |
757 (buffer-substring | |
758 (match-beginning 2) | |
759 (match-end 2))))) | |
760 emodes)))) | |
761 (and (looking-at "defaults]") | |
762 (setq no-defaults nil))) | |
763 (backward-char 6)) | |
764 (goto-char save-pt) | |
60507
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
765 (unless (assq 'the-language modes) |
60570
ddc2516ce1ec
(calc-embedded-language-alist): Remove.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60543
diff
changeset
|
766 (let ((lang (assoc major-mode calc-language-alist))) |
60507
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
767 (if lang |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
768 (setq modes (cons (cons 'the-language (cdr lang)) |
8df8779687e1
(calc-do-embedded): Set mode line when embedded mode begins.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59916
diff
changeset
|
769 modes))))) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
770 (list modes emodes pmodes))) |
40785 | 771 |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
772 ;; The variable calc-embed-vars-used is local to calc-embedded-make-info, |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
773 ;; calc-embedded-evaluate-expr and calc-embedded-update, but is |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
774 ;; used by calc-embedded-find-vars, which is called by the above functions. |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
775 (defvar calc-embed-vars-used) |
40785 | 776 |
777 (defun calc-embedded-make-info (point cbuf fresh &optional | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
778 calc-embed-top calc-embed-bot |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
779 calc-embed-outer-top calc-embed-outer-bot) |
40785 | 780 (let* ((bufentry (assq (current-buffer) calc-embedded-active)) |
781 (found bufentry) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
782 (force (and fresh calc-embed-top)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
783 (fixed calc-embed-top) |
40785 | 784 (new-info nil) |
785 info str) | |
786 (or found | |
787 (setq found (list (current-buffer)) | |
788 calc-embedded-active (cons found calc-embedded-active))) | |
789 (while (and (cdr found) | |
790 (> point (aref (car (cdr found)) 3))) | |
791 (setq found (cdr found))) | |
792 (if (and (cdr found) | |
793 (>= point (aref (nth 1 found) 2))) | |
794 (setq info (nth 1 found)) | |
795 (setq info (make-vector 16 nil) | |
796 new-info t | |
797 fresh t) | |
798 (aset info 0 (current-buffer)) | |
799 (aset info 1 (or cbuf (save-excursion | |
800 (calc-create-buffer) | |
801 (current-buffer))))) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
802 (if (and (integerp calc-embed-top) (not calc-embed-bot)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
803 ; started with a user-supplied argument |
40785 | 804 (progn |
805 (if (= (setq arg (prefix-numeric-value arg)) 0) | |
806 (progn | |
807 (aset info 2 (copy-marker (region-beginning))) | |
808 (aset info 3 (copy-marker (region-end)))) | |
809 (aset info (if (> arg 0) 2 3) (point-marker)) | |
810 (forward-line arg) | |
811 (aset info (if (> arg 0) 3 2) (point-marker))) | |
812 (aset info 4 (copy-marker (aref info 2))) | |
813 (aset info 5 (copy-marker (aref info 3)))) | |
814 (if (aref info 4) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
815 (setq calc-embed-top (aref info 2) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
816 fixed calc-embed-top) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
817 (if (consp calc-embed-top) |
40785 | 818 (let ((calc-embedded-open-formula calc-embedded-open-word) |
819 (calc-embedded-close-formula calc-embedded-close-word)) | |
820 (calc-embedded-find-bounds 'plain)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
821 (or calc-embed-top |
40785 | 822 (calc-embedded-find-bounds 'plain))) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
823 (aset info 2 (copy-marker (min calc-embed-top calc-embed-bot))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
824 (aset info 3 (copy-marker (max calc-embed-top calc-embed-bot))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
825 (aset info 4 (copy-marker (or calc-embed-outer-top (aref info 2)))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
826 (aset info 5 (copy-marker (or calc-embed-outer-bot (aref info 3)))))) |
40785 | 827 (goto-char (aref info 2)) |
828 (if new-info | |
829 (progn | |
830 (or (bolp) (aset info 7 t)) | |
831 (goto-char (aref info 3)) | |
832 (or (bolp) (eolp) (aset info 7 t)))) | |
833 (if fresh | |
834 (let ((modes (calc-embedded-find-modes))) | |
835 (aset info 12 (car modes)) | |
836 (aset info 13 (nth 1 modes)) | |
837 (aset info 14 (nth 2 modes)))) | |
838 (aset info 15 calc-embedded-globals) | |
839 (setq str (buffer-substring (aref info 2) (aref info 3))) | |
840 (if (or force | |
841 (not (equal str (aref info 6)))) | |
842 (if (and fixed (aref info 6)) | |
843 (progn | |
844 (aset info 4 nil) | |
845 (calc-embedded-make-info point cbuf nil) | |
846 (setq new-info nil)) | |
847 (let* ((open-plain calc-embedded-open-plain) | |
848 (close-plain calc-embedded-close-plain) | |
849 (pref-len (length open-plain)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
850 (calc-embed-vars-used nil) |
40785 | 851 suff-pos val temp) |
852 (save-excursion | |
853 (set-buffer (aref info 1)) | |
854 (calc-embedded-set-modes (aref info 15) | |
855 (aref info 12) (aref info 14)) | |
856 (if (and (> (length str) pref-len) | |
857 (equal (substring str 0 pref-len) open-plain) | |
858 (setq suff-pos (string-match (regexp-quote close-plain) | |
859 str pref-len))) | |
860 (setq val (math-read-plain-expr | |
861 (substring str pref-len suff-pos))) | |
862 (if (string-match "[^ \t\n]" str) | |
863 (setq pref-len 0 | |
864 val (math-read-big-expr str)) | |
865 (setq val nil)))) | |
866 (if (eq (car-safe val) 'error) | |
867 (setq val (list 'error | |
868 (+ (aref info 2) pref-len (nth 1 val)) | |
869 (nth 2 val)))) | |
870 (aset info 6 str) | |
871 (aset info 8 val) | |
872 (setq temp val) | |
873 (if (eq (car-safe temp) 'calcFunc-evalto) | |
874 (setq temp (nth 1 temp)) | |
875 (if (eq (car-safe temp) 'error) | |
876 (if new-info | |
877 (setq new-info nil) | |
878 (setcdr found (delq info (cdr found))) | |
879 (calc-embedded-active-state 'less)))) | |
880 (aset info 9 (and (eq (car-safe temp) 'calcFunc-assign) | |
881 (nth 1 temp))) | |
882 (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign)) | |
883 (calc-embedded-find-vars val)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
884 (aset info 10 calc-embed-vars-used) |
40785 | 885 (aset info 11 nil)))) |
886 (if new-info | |
887 (progn | |
888 (setcdr found (cons info (cdr found))) | |
889 (calc-embedded-active-state 'more))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
890 info)) |
40785 | 891 |
892 (defun calc-embedded-find-vars (x) | |
893 (cond ((Math-primp x) | |
894 (and (eq (car-safe x) 'var) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
895 (not (assoc x calc-embed-vars-used)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
896 (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used)))) |
40785 | 897 ((eq (car x) 'calcFunc-evalto) |
898 (calc-embedded-find-vars (nth 1 x))) | |
899 ((eq (car x) 'calcFunc-assign) | |
900 (calc-embedded-find-vars (nth 2 x))) | |
901 (t | |
902 (and (eq (car x) 'calcFunc-subscr) | |
903 (eq (car-safe (nth 1 x)) 'var) | |
904 (Math-primp (nth 2 x)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
905 (not (assoc x calc-embed-vars-used)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
906 (setq calc-embed-vars-used (cons (list x) calc-embed-vars-used))) |
40785 | 907 (while (setq x (cdr x)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
908 (calc-embedded-find-vars (car x)))))) |
40785 | 909 |
60543
a4928951c9f2
(math-ms-args): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60507
diff
changeset
|
910 (defvar math-ms-args) |
40785 | 911 (defun calc-embedded-evaluate-expr (x) |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
912 (let ((calc-embed-vars-used (aref calc-embedded-info 10))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
913 (or calc-embed-vars-used (calc-embedded-find-vars x)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
914 (if calc-embed-vars-used |
40785 | 915 (let ((active (assq (aref calc-embedded-info 0) calc-embedded-active)) |
60543
a4928951c9f2
(math-ms-args): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60507
diff
changeset
|
916 (math-ms-args nil)) |
40785 | 917 (save-excursion |
918 (calc-embedded-original-buffer t) | |
919 (or active | |
920 (progn | |
921 (calc-embedded-activate) | |
922 (setq active (assq (aref calc-embedded-info 0) | |
923 calc-embedded-active)))) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
924 (while calc-embed-vars-used |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
925 (calc-embedded-eval-get-var (car (car calc-embed-vars-used)) active) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
926 (setq calc-embed-vars-used (cdr calc-embed-vars-used)))) |
40785 | 927 (calc-embedded-subst x)) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
928 (calc-normalize (math-evaluate-expr-rec x))))) |
40785 | 929 |
930 (defun calc-embedded-subst (x) | |
931 (if (and (eq (car-safe x) 'calcFunc-evalto) (cdr x)) | |
932 (let ((rhs (calc-embedded-subst (nth 1 x)))) | |
933 (list 'calcFunc-evalto | |
934 (nth 1 x) | |
935 (if (eq (car-safe rhs) 'calcFunc-assign) (nth 2 rhs) rhs))) | |
936 (if (and (eq (car-safe x) 'calcFunc-assign) (= (length x) 3)) | |
937 (list 'calcFunc-assign | |
938 (nth 1 x) | |
939 (calc-embedded-subst (nth 2 x))) | |
60543
a4928951c9f2
(math-ms-args): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60507
diff
changeset
|
940 (calc-normalize (math-evaluate-expr-rec (math-multi-subst-rec x)))))) |
40785 | 941 |
942 (defun calc-embedded-eval-get-var (var base) | |
943 (let ((entry base) | |
944 (point (aref calc-embedded-info 2)) | |
945 (last nil) | |
946 val) | |
947 (while (and (setq entry (cdr entry)) | |
948 (or (not (equal var (aref (car entry) 9))) | |
949 (and (> point (aref (car entry) 3)) | |
950 (setq last entry))))) | |
951 (if last | |
952 (setq entry last)) | |
953 (if entry | |
954 (progn | |
955 (setq entry (car entry)) | |
956 (if (equal (buffer-substring (aref entry 2) (aref entry 3)) | |
957 (aref entry 6)) | |
958 (progn | |
959 (or (aref entry 11) | |
960 (save-excursion | |
961 (calc-embedded-update entry 14 t nil))) | |
962 (setq val (aref entry 11)) | |
963 (if (eq (car-safe val) 'calcFunc-evalto) | |
964 (setq val (nth 2 val))) | |
965 (if (eq (car-safe val) 'calcFunc-assign) | |
966 (setq val (nth 2 val))) | |
60543
a4928951c9f2
(math-ms-args): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60507
diff
changeset
|
967 (setq math-ms-args (cons (cons var val) math-ms-args))) |
40785 | 968 (calc-embedded-activate) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
969 (calc-embedded-eval-get-var var base)))))) |
40785 | 970 |
971 | |
972 (defun calc-embedded-update (info which need-eval need-display | |
973 &optional str entry old-val) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
974 (let* ((calc-embed-prev-modes nil) |
40785 | 975 (open-plain calc-embedded-open-plain) |
976 (close-plain calc-embedded-close-plain) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
977 (calc-embed-vars-used nil) |
40785 | 978 (evalled nil) |
979 (val (aref info 8)) | |
980 (old-eval (aref info 11))) | |
981 (or old-val (setq old-val val)) | |
982 (if (eq (car-safe val) 'calcFunc-evalto) | |
983 (setq need-display t)) | |
984 (unwind-protect | |
985 (progn | |
986 (set-buffer (aref info 1)) | |
987 (and which | |
988 (calc-embedded-set-modes (aref info 15) (aref info 12) | |
989 (aref info which) | |
990 (if need-display 'full t))) | |
991 (if (memq (car-safe val) '(calcFunc-evalto calcFunc-assign)) | |
992 (calc-embedded-find-vars val)) | |
993 (if need-eval | |
994 (let ((calc-embedded-info info)) | |
995 (setq val (math-evaluate-expr val) | |
996 evalled val))) | |
997 (if (or (eq need-eval 'eval) (eq (car-safe val) 'calcFunc-evalto)) | |
998 (aset info 8 val)) | |
999 (aset info 9 nil) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1000 (aset info 10 calc-embed-vars-used) |
40785 | 1001 (aset info 11 nil) |
1002 (if (or need-display (eq (car-safe val) 'calcFunc-evalto)) | |
1003 (let ((extra (if (eq calc-language 'big) 1 0))) | |
1004 (or entry (setq entry (list val 1 nil))) | |
1005 (or str (progn | |
1006 (setq str (let ((calc-line-numbering nil)) | |
1007 (math-format-stack-value entry))) | |
1008 (if (eq calc-language 'big) | |
1009 (setq str (substring str 0 -1))))) | |
1010 (and calc-show-plain | |
1011 (setq str (concat open-plain | |
1012 (math-showing-full-precision | |
1013 (math-format-flat-expr val 0)) | |
1014 close-plain | |
1015 str))) | |
1016 (save-excursion | |
1017 (calc-embedded-original-buffer t info) | |
1018 (or (equal str (aref info 6)) | |
1019 (let ((delta (- (aref info 5) (aref info 3))) | |
59916
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1020 (adjbot 0) |
40785 | 1021 (buffer-read-only nil)) |
1022 (goto-char (aref info 2)) | |
1023 (delete-region (point) (aref info 3)) | |
1024 (and (> (nth 1 entry) (1+ extra)) | |
1025 (aref info 7) | |
1026 (progn | |
1027 (delete-horizontal-space) | |
59916
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1028 (if (looking-at "\n") |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1029 ;; If there's a newline there, don't add one |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1030 (insert "\n") |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1031 (insert "\n\n") |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1032 (delete-horizontal-space) |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1033 (setq adjbot 1) |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1034 ; (setq delta (1+ delta)) |
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1035 (backward-char 1)))) |
40785 | 1036 (insert str) |
59916
7e83e55fbe19
(calc-embedded-update): Don't put in unnecessary newlines.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59840
diff
changeset
|
1037 (set-marker (aref info 3) (+ (point) adjbot)) |
40785 | 1038 (set-marker (aref info 5) (+ (point) delta)) |
1039 (aset info 6 str)))))) | |
1040 (if (eq (car-safe val) 'calcFunc-evalto) | |
1041 (progn | |
1042 (setq evalled (nth 2 val) | |
1043 val (nth 1 val)))) | |
1044 (if (eq (car-safe val) 'calcFunc-assign) | |
1045 (progn | |
1046 (aset info 9 (nth 1 val)) | |
1047 (aset info 11 (or evalled | |
1048 (let ((calc-embedded-info info)) | |
1049 (math-evaluate-expr (nth 2 val))))) | |
1050 (or (equal old-eval (aref info 11)) | |
1051 (calc-embedded-var-change (nth 1 val) (aref info 0)))) | |
1052 (if (eq (car-safe old-val) 'calcFunc-evalto) | |
1053 (setq old-val (nth 1 old-val))) | |
1054 (if (eq (car-safe old-val) 'calcFunc-assign) | |
1055 (calc-embedded-var-change (nth 1 old-val) (aref info 0))))) | |
1056 (set-buffer (aref info 1)) | |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1057 (while calc-embed-prev-modes |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1058 (cond ((eq (car (car calc-embed-prev-modes)) 'the-language) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1059 (if need-display |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1060 (calc-embedded-set-language (cdr (car calc-embed-prev-modes))))) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1061 ((eq (car (car calc-embed-prev-modes)) 'the-display-just) |
40785 | 1062 (if need-display |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1063 (calc-embedded-set-justify (cdr (car calc-embed-prev-modes))))) |
40785 | 1064 (t |
58552
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1065 (set (car (car calc-embed-prev-modes)) |
59f299fd62df
(calc-original-buffer): Declare it.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
57116
diff
changeset
|
1066 (cdr (car calc-embed-prev-modes))))) |
58557
e6a68eb6d5fb
(calc-embedded-update): Finish changing prev-mode to calc-embed-prev-mode.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58552
diff
changeset
|
1067 (setq calc-embed-prev-modes (cdr calc-embed-prev-modes)))))) |
40785 | 1068 |
1069 | |
1070 | |
1071 | |
1072 ;;; These are hooks called by the main part of Calc. | |
1073 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1074 (defvar calc-embedded-no-reselect nil) |
40785 | 1075 (defun calc-embedded-select-buffer () |
1076 (if (eq (current-buffer) (aref calc-embedded-info 0)) | |
1077 (let ((info calc-embedded-info) | |
1078 horiz vert) | |
1079 (if (and (or (< (point) (aref info 4)) | |
1080 (> (point) (aref info 5))) | |
1081 (not calc-embedded-no-reselect)) | |
1082 (let ((calc-embedded-quiet t)) | |
1083 (message "(Switching Calc Embedded mode to new formula.)") | |
1084 (calc-embedded nil) | |
1085 (calc-embedded nil))) | |
1086 (setq horiz (max (min (current-column) (- (point) (aref info 2))) 0) | |
1087 vert (if (<= (aref info 2) (point)) | |
1088 (- (count-lines (aref info 2) (point)) | |
1089 (if (bolp) 0 1)) | |
1090 0)) | |
1091 (set-buffer (aref info 1)) | |
1092 (if calc-show-plain | |
1093 (if (= vert 0) | |
1094 (setq horiz 0) | |
1095 (setq vert (1- vert)))) | |
1096 (calc-cursor-stack-index 1) | |
1097 (if calc-line-numbering | |
1098 (setq horiz (+ horiz 4))) | |
1099 (if (> vert 0) | |
1100 (forward-line vert)) | |
1101 (forward-char (min horiz | |
1102 (- (point-max) (point))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1103 (calc-select-buffer))) |
40785 | 1104 |
1105 (defun calc-embedded-finish-command () | |
1106 (let ((buf (current-buffer)) | |
1107 horiz vert) | |
1108 (save-excursion | |
1109 (set-buffer (aref calc-embedded-info 1)) | |
1110 (if (> (calc-stack-size) 0) | |
1111 (let ((pt (point)) | |
1112 (col (current-column)) | |
1113 (bol (bolp))) | |
1114 (calc-cursor-stack-index 0) | |
1115 (if (< pt (point)) | |
1116 (progn | |
1117 (calc-cursor-stack-index 1) | |
1118 (if (>= pt (point)) | |
1119 (progn | |
1120 (setq horiz (- col (if calc-line-numbering 4 0)) | |
1121 vert (- (count-lines (point) pt) | |
1122 (if bol 0 1))) | |
1123 (if calc-show-plain | |
1124 (setq vert (max 1 (1+ vert)))))))) | |
1125 (goto-char pt)))) | |
1126 (if horiz | |
1127 (progn | |
1128 (set-buffer (aref calc-embedded-info 0)) | |
1129 (goto-char (aref calc-embedded-info 2)) | |
1130 (if (> vert 0) | |
1131 (forward-line vert)) | |
1132 (forward-char (max horiz 0)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1133 (set-buffer buf))))) |
40785 | 1134 |
1135 (defun calc-embedded-stack-change () | |
1136 (or calc-executing-macro | |
1137 (save-excursion | |
1138 (set-buffer (aref calc-embedded-info 1)) | |
1139 (let* ((info calc-embedded-info) | |
1140 (extra-line (if (eq calc-language 'big) 1 0)) | |
1141 (the-point (point)) | |
1142 (empty (= (calc-stack-size) 0)) | |
1143 (entry (if empty | |
1144 (list '(var empty var-empty) 1 nil) | |
1145 (calc-top 1 'entry))) | |
1146 (old-val (aref info 8)) | |
1147 top bot str) | |
1148 (if empty | |
1149 (setq str "empty") | |
1150 (save-excursion | |
1151 (calc-cursor-stack-index 1) | |
1152 (setq top (point)) | |
1153 (calc-cursor-stack-index 0) | |
1154 (setq bot (- (point) extra-line)) | |
1155 (setq str (buffer-substring top (- bot 1)))) | |
1156 (if calc-line-numbering | |
1157 (let ((pos 0)) | |
1158 (setq str (substring str 4)) | |
1159 (while (setq pos (string-match "\n...." str pos)) | |
1160 (setq str (concat (substring str 0 (1+ pos)) | |
1161 (substring str (+ pos 5))) | |
1162 pos (1+ pos)))))) | |
1163 (calc-embedded-original-buffer t) | |
1164 (aset info 8 (car entry)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1165 (calc-embedded-update info 13 nil t str entry old-val))))) |
40785 | 1166 |
1167 (defun calc-embedded-mode-line-change () | |
1168 (let ((str mode-line-buffer-identification)) | |
1169 (save-excursion | |
1170 (calc-embedded-original-buffer t) | |
1171 (setq mode-line-buffer-identification str) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1172 (set-buffer-modified-p (buffer-modified-p))))) |
40785 | 1173 |
1174 (defun calc-embedded-modes-change (vars) | |
1175 (if (eq (car vars) 'calc-language) (setq vars '(the-language))) | |
1176 (if (eq (car vars) 'calc-display-just) (setq vars '(the-display-just))) | |
1177 (while (and vars | |
1178 (not (rassq (car vars) calc-embedded-mode-vars))) | |
1179 (setq vars (cdr vars))) | |
1180 (if (and vars calc-mode-save-mode (not (eq calc-mode-save-mode 'save))) | |
1181 (save-excursion | |
1182 (let* ((save-mode calc-mode-save-mode) | |
1183 (header (if (eq save-mode 'local) | |
1184 "calc-mode:" | |
1185 (format "calc-%s-mode:" save-mode))) | |
1186 (the-language (calc-embedded-language)) | |
1187 (the-display-just (calc-embedded-justify)) | |
1188 (values (mapcar 'symbol-value vars)) | |
1189 (num (cond ((eq save-mode 'local) 12) | |
1190 ((eq save-mode 'edit) 13) | |
1191 ((eq save-mode 'perm) 14) | |
1192 (t nil))) | |
1193 base limit mname mlist) | |
1194 (calc-embedded-original-buffer t) | |
1195 (save-excursion | |
1196 (if (eq save-mode 'global) | |
1197 (setq base (point-max) | |
1198 limit (point-min) | |
1199 mlist calc-embedded-globals) | |
1200 (goto-char (aref calc-embedded-info 4)) | |
1201 (beginning-of-line) | |
1202 (setq base (point) | |
1203 limit (max (- (point) 1000) (point-min)) | |
1204 mlist (and num (aref calc-embedded-info num))) | |
1205 (and (re-search-backward | |
1206 (format "\\(%s\\)[^\001]*\\(%s\\)\\|\\[calc-defaults]" | |
1207 calc-embedded-open-formula | |
1208 calc-embedded-close-formula) limit t) | |
1209 (setq limit (point)))) | |
1210 (while vars | |
1211 (goto-char base) | |
1212 (if (setq mname (car (rassq (car vars) | |
1213 calc-embedded-mode-vars))) | |
1214 (let ((buffer-read-only nil) | |
1215 (found (assq (car vars) mlist))) | |
1216 (if found | |
1217 (setcdr found (car values)) | |
1218 (setq mlist (cons (cons (car vars) (car values)) mlist)) | |
1219 (if num | |
1220 (aset calc-embedded-info num mlist) | |
1221 (if (eq save-mode 'global) | |
1222 (setq calc-embedded-globals mlist)))) | |
1223 (if (re-search-backward | |
1224 (format "\\[%s *%s: *\\(\"\\([^\"\n\\]\\|\\\\.\\)*\"\\|[- ()a-zA-Z0-9]+\\)]" | |
1225 header mname) | |
1226 limit t) | |
1227 (progn | |
1228 (goto-char (match-beginning 1)) | |
1229 (delete-region (point) (match-end 1)) | |
1230 (insert (prin1-to-string (car values)))) | |
1231 (goto-char base) | |
1232 (insert-before-markers | |
1233 calc-embedded-open-mode | |
1234 "[" header " " mname ": " | |
1235 (prin1-to-string (car values)) "]" | |
1236 calc-embedded-close-mode)))) | |
1237 (setq vars (cdr vars) | |
60816
f14d2a34da27
(calc-embedded-original-modes): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60770
diff
changeset
|
1238 values (cdr values)))))) |
60879
61f186efc434
(calc-embedded-mode-change): Save all relevant mode settings in
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60816
diff
changeset
|
1239 (when (and vars (eq calc-mode-save-mode 'save)) |
61f186efc434
(calc-embedded-mode-change): Save all relevant mode settings in
Jay Belanger <jay.p.belanger@gmail.com>
parents:
60816
diff
changeset
|
1240 (calc-embedded-save-original-modes)))) |
40785 | 1241 |
1242 (defun calc-embedded-var-change (var &optional buf) | |
1243 (if (symbolp var) | |
1244 (setq var (list 'var | |
1245 (if (string-match "\\`var-.+\\'" | |
1246 (symbol-name var)) | |
1247 (intern (substring (symbol-name var) 4)) | |
1248 var) | |
1249 var))) | |
1250 (save-excursion | |
1251 (let ((manual (not calc-auto-recompute)) | |
1252 (bp calc-embedded-active) | |
1253 (first t)) | |
1254 (if buf (setq bp (memq (assq buf bp) bp))) | |
1255 (while bp | |
1256 (let ((calc-embedded-no-reselect t) | |
1257 (p (and (buffer-name (car (car bp))) | |
1258 (cdr (car bp))))) | |
1259 (while p | |
1260 (if (assoc var (aref (car p) 10)) | |
1261 (if manual | |
1262 (if (aref (car p) 11) | |
1263 (progn | |
1264 (aset (car p) 11 nil) | |
1265 (if (aref (car p) 9) | |
1266 (calc-embedded-var-change (aref (car p) 9))))) | |
1267 (set-buffer (aref (car p) 0)) | |
1268 (if (equal (buffer-substring (aref (car p) 2) | |
1269 (aref (car p) 3)) | |
1270 (aref (car p) 6)) | |
1271 (let ((calc-embedded-info nil)) | |
1272 (or calc-embedded-quiet | |
1273 (message "Recomputing...")) | |
1274 (setq first nil) | |
1275 (calc-wrapper | |
1276 (set-buffer (aref (car p) 0)) | |
1277 (calc-embedded-update (car p) 14 t nil))) | |
1278 (setcdr (car bp) (delq (car p) (cdr (car bp)))) | |
1279 (message | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
1280 "(Tried to recompute but formula was changed or missing)")))) |
40785 | 1281 (setq p (cdr p)))) |
1282 (setq bp (if buf nil (cdr bp)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1283 (or first calc-embedded-quiet (message ""))))) |
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1284 |
58651
05765b6fc9cd
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58557
diff
changeset
|
1285 (provide 'calc-embed) |
05765b6fc9cd
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58557
diff
changeset
|
1286 |
52401 | 1287 ;;; arch-tag: 1b8f311e-fba1-40d3-b8c3-1d6f68fd26fc |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40996
diff
changeset
|
1288 ;;; calc-embed.el ends here |