annotate lisp/calc/calc-embed.el @ 105643:062d17ee6c05

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