Mercurial > emacs
annotate lisp/calc/calc-store.el @ 83486:fc6efa09ea7a
Fix segfault by `C-x 5 2' on the controlling tty. (Reported by Suresh Madhu.)
* src/frame.c (Fmake_terminal_frame): Handle NULL tty names correctly.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-526
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Wed, 08 Mar 2006 16:47:48 +0000 |
parents | 6bf177f8065b |
children | 7a3f13e2dd57 c5406394f567 |
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-store.el --- value storage functions for Calc |
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:
62442
diff
changeset
|
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004, |
68636
6bf177f8065b
Update copyright year.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
66157
diff
changeset
|
4 ;; 2005, 2006 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> |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
7 ;; Maintainer: Jay Belanger <belanger@truman.edu> |
40785 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY. No author or distributor | |
13 ;; accepts responsibility to anyone for the consequences of using it | |
14 ;; or for whether it serves any particular purpose or works at all, | |
15 ;; unless he says so in writing. Refer to the GNU Emacs General Public | |
16 ;; License for full details. | |
17 | |
18 ;; Everyone is granted permission to copy, modify and redistribute | |
19 ;; GNU Emacs, but only under the conditions described in the | |
20 ;; GNU Emacs General Public License. A copy of this license is | |
21 ;; supposed to have been given to you along with GNU Emacs so you | |
22 ;; can know your rights and responsibilities. It should be in a | |
23 ;; file named COPYING. Among other things, the copyright notice | |
24 ;; and this notice must be preserved on all copies. | |
25 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
26 ;;; Commentary: |
40785 | 27 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
28 ;;; Code: |
40785 | 29 |
30 ;; This file is autoloaded from calc-ext.el. | |
58673
202eaef4ca19
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58547
diff
changeset
|
31 |
40785 | 32 (require 'calc-ext) |
33 (require 'calc-macs) | |
34 | |
35 ;;; Memory commands. | |
36 | |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
37 (defvar calc-store-keep nil) |
40785 | 38 (defun calc-store (&optional var) |
39 (interactive) | |
40 (let ((calc-store-keep t)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
41 (calc-store-into var))) |
40785 | 42 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
43 (defvar calc-given-value-flag nil) |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
44 (defvar calc-given-value) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
45 |
40785 | 46 (defun calc-store-into (&optional var) |
47 (interactive) | |
48 (calc-wrapper | |
49 (let ((calc-given-value nil) | |
50 (calc-given-value-flag 1)) | |
51 (or var (setq var (calc-read-var-name "Store: " t))) | |
52 (if var | |
53 (let ((found (assq var '( ( + . calc-store-plus ) | |
54 ( - . calc-store-minus ) | |
55 ( * . calc-store-times ) | |
56 ( / . calc-store-div ) | |
57 ( ^ . calc-store-power ) | |
58 ( | . calc-store-concat ) )))) | |
59 (if found | |
60 (funcall (cdr found)) | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
61 (let ((msg |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
62 (calc-store-value var (or calc-given-value (calc-top 1)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
63 "" calc-given-value-flag))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
64 (message (concat "Stored to variable \"%s\"" msg) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
65 (calc-var-name var))))) |
40785 | 66 (setq var (calc-is-assignments (calc-top 1))) |
67 (if var | |
68 (while var | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
69 (let ((msg |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
70 (calc-store-value (car (car var)) (cdr (car var)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
71 (if (not (cdr var)) "") |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
72 (if (not (cdr var)) 1)))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
73 (message (concat "Stored to variable \"%s\"" msg) |
66157
9b54a8bf0ecf
(calc-store-into): Get proper variable name to display in message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
65680
diff
changeset
|
74 (calc-var-name (car (car var))))) |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
75 (setq var (cdr var)))))))) |
40785 | 76 |
77 (defun calc-store-plus (&optional var) | |
78 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
79 (calc-store-binary var "+" '+)) |
40785 | 80 |
81 (defun calc-store-minus (&optional var) | |
82 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
83 (calc-store-binary var "-" '-)) |
40785 | 84 |
85 (defun calc-store-times (&optional var) | |
86 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
87 (calc-store-binary var "*" '*)) |
40785 | 88 |
89 (defun calc-store-div (&optional var) | |
90 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
91 (calc-store-binary var "/" '/)) |
40785 | 92 |
93 (defun calc-store-power (&optional var) | |
94 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
95 (calc-store-binary var "^" '^)) |
40785 | 96 |
97 (defun calc-store-concat (&optional var) | |
98 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
99 (calc-store-binary var "|" '|)) |
40785 | 100 |
101 (defun calc-store-neg (n &optional var) | |
102 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
103 (calc-store-binary var "n" '/ (- n))) |
40785 | 104 |
105 (defun calc-store-inv (n &optional var) | |
106 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
107 (calc-store-binary var "&" '^ (- n))) |
40785 | 108 |
109 (defun calc-store-incr (n &optional var) | |
110 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
111 (calc-store-binary var "n" '- (- n))) |
40785 | 112 |
113 (defun calc-store-decr (n &optional var) | |
114 (interactive "p") | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
115 (calc-store-binary var "n" '- n)) |
40785 | 116 |
117 (defun calc-store-value (var value tag &optional pop) | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
118 (let ((msg "")) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
119 (if var |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
120 (let ((old (calc-var-value var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
121 (set var value) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
122 (if pop (or calc-store-keep (calc-pop-stack pop))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
123 (calc-record-undo (list 'store (symbol-name var) old)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
124 (if tag |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
125 (let ((calc-full-trail-vectors nil)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
126 (calc-record value (format ">%s%s" tag (calc-var-name var))))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
127 (cond |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
128 ((and (memq var '(var-e var-i var-pi var-phi var-gamma)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
129 (eq (car-safe old) 'special-const)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
130 (setq msg (format " (Note: Built-in definition of %s has been lost)" |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
131 (calc-var-name var)))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
132 ((and (memq var '(var-inf var-uinf var-nan)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
133 (null old)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
134 (setq msg (format " (Note: %s has built-in meanings which may interfere)" |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
135 (calc-var-name var))))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
136 (calc-refresh-evaltos var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
137 msg)) |
40785 | 138 |
139 (defun calc-var-name (var) | |
140 (if (symbolp var) (setq var (symbol-name var))) | |
141 (if (string-match "\\`var-." var) | |
142 (substring var 4) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
143 var)) |
40785 | 144 |
145 (defun calc-store-binary (var tag func &optional val) | |
146 (calc-wrapper | |
147 (let ((calc-simplify-mode (if (eq calc-simplify-mode 'none) | |
148 'num calc-simplify-mode)) | |
149 (value (or val (calc-top 1)))) | |
150 (or var (setq var (calc-read-var-name (format "Store %s: " tag)))) | |
151 (if var | |
152 (let ((old (calc-var-value var))) | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
153 (if (eq (car-safe old) 'special-const) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
154 (error "\"%s\" is a special constant" (calc-var-name var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
155 (if (not old) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
156 (if (memq var '(var-inf var-uinf var-nan)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
157 (error "\"%s\" is a special variable" (calc-var-name var)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
158 (error "No such variable: \"%s\"" (calc-var-name var)))) |
40785 | 159 (if (stringp old) |
160 (setq old (math-read-expr old))) | |
161 (if (eq (car-safe old) 'error) | |
162 (error "Bad format in variable contents: %s" (nth 2 old))) | |
163 (calc-store-value var | |
164 (calc-normalize (if (calc-is-inverse) | |
165 (list func value old) | |
166 (list func old value))) | |
167 tag (and (not val) 1)) | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
168 (message "Variable \"%s\" changed" (calc-var-name var))))))) |
40785 | 169 |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
170 (defvar calc-var-name-map nil "Keymap for reading Calc variable names.") |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
171 (if calc-var-name-map |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
172 () |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
173 (setq calc-var-name-map (copy-keymap minibuffer-local-completion-map)) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
174 (define-key calc-var-name-map " " 'self-insert-command) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
175 (mapcar (function |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
176 (lambda (x) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
177 (define-key calc-var-name-map (char-to-string x) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
178 'calcVar-digit))) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
179 "0123456789") |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
180 (mapcar (function |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
181 (lambda (x) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
182 (define-key calc-var-name-map (char-to-string x) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
183 'calcVar-oper))) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
184 "+-*/^|")) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
185 |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
186 (defvar calc-store-opers) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
187 |
40785 | 188 (defun calc-read-var-name (prompt &optional calc-store-opers) |
189 (setq calc-given-value nil | |
190 calc-aborted-prefix nil) | |
59090
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
191 (let ((var (concat |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
192 "var-" |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
193 (let ((minibuffer-completion-table |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
194 (mapcar (lambda (x) (substring x 4)) |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
195 (all-completions "var-" obarray))) |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
196 (minibuffer-completion-predicate |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
197 (lambda (x) (boundp (intern (concat "var-" x))))) |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
198 (minibuffer-completion-confirm t)) |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
199 (read-from-minibuffer prompt nil calc-var-name-map nil))))) |
40785 | 200 (setq calc-aborted-prefix "") |
59090
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
201 (and (not (equal var "var-")) |
40785 | 202 (if (string-match "\\`\\([-a-zA-Z0-9]+\\) *:?=" var) |
203 (if (null calc-given-value-flag) | |
204 (error "Assignment is not allowed in this command") | |
205 (let ((svar (intern (substring var 0 (match-end 1))))) | |
206 (setq calc-given-value-flag 0 | |
207 calc-given-value (math-read-expr | |
208 (substring var (match-end 0)))) | |
209 (if (eq (car-safe calc-given-value) 'error) | |
210 (error "Bad format: %s" (nth 2 calc-given-value))) | |
211 (setq calc-given-value (math-evaluate-expr calc-given-value)) | |
212 svar)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
213 (intern var))))) |
40785 | 214 |
215 (defun calcVar-digit () | |
216 (interactive) | |
59265
eb45d1b6dbc3
(calcVar-digit, calcVar-oper): Remove need for "var-" at the
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59211
diff
changeset
|
217 (if (calc-minibuffer-contains "\\'") |
40785 | 218 (if (eq calc-store-opers 0) |
219 (beep) | |
220 (insert "q") | |
221 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
222 (self-insert-command 1))) |
40785 | 223 |
224 (defun calcVar-oper () | |
225 (interactive) | |
226 (if (and (eq calc-store-opers t) | |
59265
eb45d1b6dbc3
(calcVar-digit, calcVar-oper): Remove need for "var-" at the
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59211
diff
changeset
|
227 (calc-minibuffer-contains "\\'")) |
40785 | 228 (progn |
229 (erase-buffer) | |
230 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
231 (self-insert-command 1))) |
40785 | 232 |
233 (defun calc-store-map (&optional oper var) | |
234 (interactive) | |
235 (calc-wrapper | |
236 (let* ((sel-mode nil) | |
237 (calc-dollar-values (mapcar 'calc-get-stack-element | |
238 (nthcdr calc-stack-top calc-stack))) | |
239 (calc-dollar-used 0) | |
240 (oper (or oper (calc-get-operator "Store Mapping"))) | |
241 (nargs (car oper))) | |
242 (or var (setq var (calc-read-var-name (format "Store Mapping %s: " | |
243 (nth 2 oper))))) | |
244 (if var | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
245 (let ((old (calc-var-value var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
246 (if (eq (car-safe old) 'special-const) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
247 (error "\"%s\" is a special constant" (calc-var-name var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
248 (if (not old) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
249 (if (memq var '(var-inf var-uinf var-nan)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
250 (error "\"%s\" is a special variable" (calc-var-name var)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
251 (error "No such variable: \"%s\"" (calc-var-name var)))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
252 (let ((calc-simplify-mode (if (eq calc-simplify-mode 'none) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
253 'num calc-simplify-mode)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
254 (values (and (> nargs 1) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
255 (calc-top-list (1- nargs) (1+ calc-dollar-used))))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
256 (message "Working...") |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
257 (calc-set-command-flag 'clear-message) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
258 (if (stringp old) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
259 (setq old (math-read-expr old))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
260 (if (eq (car-safe old) 'error) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
261 (error "Bad format in variable contents: %s" (nth 2 old))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
262 (setq values (if (calc-is-inverse) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
263 (append values (list old)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
264 (append (list old) values))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
265 (calc-store-value var |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
266 (calc-normalize (cons (nth 1 oper) values)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
267 (nth 2 oper) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
268 (+ calc-dollar-used (1- nargs))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
269 (message "Variable \"%s\" changed" (calc-var-name var)))))))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
270 |
40785 | 271 |
272 (defun calc-store-exchange (&optional var) | |
273 (interactive) | |
274 (calc-wrapper | |
275 (let ((calc-given-value nil) | |
276 (calc-given-value-flag 1) | |
277 top) | |
278 (or var (setq var (calc-read-var-name "Exchange with: "))) | |
279 (if var | |
280 (let ((value (calc-var-value var))) | |
281 (if (eq (car-safe value) 'special-const) | |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
282 (error "\"%s\" is a special constant" (calc-var-name var))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
283 (if (not value) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
284 (if (memq var '(var-inf var-uinf var-nan)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
285 (error "\"%s\" is a special variable" (calc-var-name var)) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
286 (error "No such variable: \"%s\"" (calc-var-name var)))) |
40785 | 287 (setq top (or calc-given-value (calc-top 1))) |
288 (calc-store-value var top nil) | |
289 (calc-pop-push-record calc-given-value-flag | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
290 (concat "<>" (calc-var-name var)) value)))))) |
40785 | 291 |
292 (defun calc-unstore (&optional var) | |
293 (interactive) | |
294 (calc-wrapper | |
295 (or var (setq var (calc-read-var-name "Unstore: "))) | |
296 (if var | |
297 (progn | |
298 (and (memq var '(var-e var-i var-pi var-phi var-gamma)) | |
299 (eq (car-safe (calc-var-value var)) 'special-const) | |
300 (message "(Note: Built-in definition of %s has been lost)" var)) | |
301 (if (and (boundp var) (symbol-value var)) | |
302 (message "Unstored variable \"%s\"" (calc-var-name var)) | |
303 (message "Variable \"%s\" remains unstored" (calc-var-name var))) | |
304 (makunbound var) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
305 (calc-refresh-evaltos var))))) |
40785 | 306 |
307 (defun calc-let (&optional var) | |
308 (interactive) | |
309 (calc-wrapper | |
310 (let* ((calc-given-value nil) | |
311 (calc-given-value-flag 1) | |
312 thing value) | |
313 (or var (setq var (calc-read-var-name "Let variable: "))) | |
314 (if calc-given-value | |
315 (setq value calc-given-value | |
316 thing (calc-top 1)) | |
317 (setq value (calc-top 1) | |
318 thing (calc-top 2))) | |
319 (setq var (if var | |
320 (list (cons var value)) | |
321 (calc-is-assignments value))) | |
322 (if var | |
323 (calc-pop-push-record | |
324 (1+ calc-given-value-flag) | |
325 (concat "=" (calc-var-name (car (car var)))) | |
326 (let ((saved-val (mapcar (function | |
327 (lambda (v) | |
328 (and (boundp (car v)) | |
329 (symbol-value (car v))))) | |
330 var))) | |
331 (unwind-protect | |
332 (let ((vv var)) | |
333 (while vv | |
334 (set (car (car vv)) (calc-normalize (cdr (car vv)))) | |
335 (calc-refresh-evaltos (car (car vv))) | |
336 (setq vv (cdr vv))) | |
337 (math-evaluate-expr thing)) | |
338 (while saved-val | |
339 (if (car saved-val) | |
340 (set (car (car var)) (car saved-val)) | |
341 (makunbound (car (car var)))) | |
342 (setq saved-val (cdr saved-val) | |
343 var (cdr var))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
344 (calc-handle-whys)))))))) |
40785 | 345 |
346 (defun calc-is-assignments (value) | |
347 (if (memq (car-safe value) '(calcFunc-eq calcFunc-assign)) | |
348 (and (eq (car-safe (nth 1 value)) 'var) | |
349 (list (cons (nth 2 (nth 1 value)) (nth 2 value)))) | |
350 (if (eq (car-safe value) 'vec) | |
351 (let ((vv nil)) | |
352 (while (and (setq value (cdr value)) | |
353 (memq (car-safe (car value)) | |
354 '(calcFunc-eq calcFunc-assign)) | |
355 (eq (car-safe (nth 1 (car value))) 'var)) | |
356 (setq vv (cons (cons (nth 2 (nth 1 (car value))) | |
357 (nth 2 (car value))) | |
358 vv))) | |
359 (and (not value) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
360 vv))))) |
40785 | 361 |
362 (defun calc-recall (&optional var) | |
363 (interactive) | |
364 (calc-wrapper | |
365 (or var (setq var (calc-read-var-name "Recall: "))) | |
366 (if var | |
367 (let ((value (calc-var-value var))) | |
368 (or value | |
369 (error "No such variable: \"%s\"" (calc-var-name var))) | |
370 (if (stringp value) | |
371 (setq value (math-read-expr value))) | |
372 (if (eq (car-safe value) 'error) | |
373 (error "Bad format in variable contents: %s" (nth 2 value))) | |
374 (setq value (calc-normalize value)) | |
375 (let ((calc-full-trail-vectors nil)) | |
376 (calc-record value (concat "<" (calc-var-name var)))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
377 (calc-push value))))) |
40785 | 378 |
379 (defun calc-store-quick () | |
380 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
381 (calc-store (intern (format "var-q%c" last-command-char)))) |
40785 | 382 |
383 (defun calc-store-into-quick () | |
384 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
385 (calc-store-into (intern (format "var-q%c" last-command-char)))) |
40785 | 386 |
387 (defun calc-recall-quick () | |
388 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
389 (calc-recall (intern (format "var-q%c" last-command-char)))) |
40785 | 390 |
62392
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
391 (defun calc-copy-special-constant (&optional sconst var) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
392 (interactive) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
393 (let ((sc '(("") |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
394 ("e" . (special-const (math-e))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
395 ("pi" . (special-const (math-pi))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
396 ("i" . (special-const (math-imaginary 1))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
397 ("phi" . (special-const (math-phi))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
398 ("gamma" . (special-const (math-gamma-const)))))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
399 (calc-wrapper |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
400 (or sconst (setq sconst (completing-read "Special constant: " sc nil t))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
401 (unless (string= sconst "") |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
402 (let ((value (cdr (assoc sconst sc)))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
403 (or var (setq var (calc-read-var-name |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
404 (format "Copy special constant %s, to: " |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
405 sconst)))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
406 (if var |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
407 (let ((msg (calc-store-value var value ""))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
408 (message (concat "Special constant \"%s\" copied to \"%s\"" msg) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
409 sconst (calc-var-name var))))))))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
410 |
40785 | 411 (defun calc-copy-variable (&optional var1 var2) |
412 (interactive) | |
413 (calc-wrapper | |
414 (or var1 (setq var1 (calc-read-var-name "Copy variable: "))) | |
415 (if var1 | |
416 (let ((value (calc-var-value var1))) | |
417 (or value | |
59211
999144478c9a
(calc-copy-variable): Fix mistyped variable name. Display variable
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59090
diff
changeset
|
418 (error "No such variable: \"%s\"" (calc-var-name var1))) |
40785 | 419 (or var2 (setq var2 (calc-read-var-name |
59211
999144478c9a
(calc-copy-variable): Fix mistyped variable name. Display variable
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59090
diff
changeset
|
420 (format "Copy variable: %s, to: " |
999144478c9a
(calc-copy-variable): Fix mistyped variable name. Display variable
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59090
diff
changeset
|
421 (calc-var-name var1))))) |
40785 | 422 (if var2 |
62358
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
423 (let ((msg (calc-store-value var2 value ""))) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
424 (message (concat "Variable \"%s\" copied to \"%s\"" msg) |
75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62165
diff
changeset
|
425 (calc-var-name var1) (calc-var-name var2)))))))) |
40785 | 426 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
427 (defvar calc-last-edited-variable nil) |
40785 | 428 (defun calc-edit-variable (&optional var) |
429 (interactive) | |
430 (calc-wrapper | |
431 (or var (setq var (calc-read-var-name | |
432 (if calc-last-edited-variable | |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64325
diff
changeset
|
433 (format "Edit (default %s): " |
40785 | 434 (calc-var-name calc-last-edited-variable)) |
435 "Edit: ")))) | |
436 (or var (setq var calc-last-edited-variable)) | |
437 (if var | |
438 (let* ((value (calc-var-value var))) | |
439 (if (eq (car-safe value) 'special-const) | |
440 (error "%s is a special constant" var)) | |
441 (setq calc-last-edited-variable var) | |
442 (calc-edit-mode (list 'calc-finish-stack-edit (list 'quote var)) | |
443 t | |
59299
b851b98f8dc1
(calc-edit-variable): Change title to match new header.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59265
diff
changeset
|
444 (concat "Editing variable `" (calc-var-name var) "'. ")) |
40785 | 445 (and value |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
446 (insert (math-format-nice-expr value (frame-width)) "\n"))))) |
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
447 (calc-show-edit-buffer)) |
40785 | 448 |
449 (defun calc-edit-Decls () | |
450 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
451 (calc-edit-variable 'var-Decls)) |
40785 | 452 |
453 (defun calc-edit-EvalRules () | |
454 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
455 (calc-edit-variable 'var-EvalRules)) |
40785 | 456 |
457 (defun calc-edit-FitRules () | |
458 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
459 (calc-edit-variable 'var-FitRules)) |
40785 | 460 |
461 (defun calc-edit-GenCount () | |
462 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
463 (calc-edit-variable 'var-GenCount)) |
40785 | 464 |
465 (defun calc-edit-Holidays () | |
466 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
467 (calc-edit-variable 'var-Holidays)) |
40785 | 468 |
469 (defun calc-edit-IntegLimit () | |
470 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
471 (calc-edit-variable 'var-IntegLimit)) |
40785 | 472 |
473 (defun calc-edit-LineStyles () | |
474 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
475 (calc-edit-variable 'var-LineStyles)) |
40785 | 476 |
477 (defun calc-edit-PointStyles () | |
478 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
479 (calc-edit-variable 'var-PointStyles)) |
40785 | 480 |
481 (defun calc-edit-PlotRejects () | |
482 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
483 (calc-edit-variable 'var-PlotRejects)) |
40785 | 484 |
485 (defun calc-edit-AlgSimpRules () | |
486 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
487 (calc-edit-variable 'var-AlgSimpRules)) |
40785 | 488 |
489 (defun calc-edit-TimeZone () | |
490 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
491 (calc-edit-variable 'var-TimeZone)) |
40785 | 492 |
493 (defun calc-edit-Units () | |
494 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
495 (calc-edit-variable 'var-Units)) |
40785 | 496 |
497 (defun calc-edit-ExtSimpRules () | |
498 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
499 (calc-edit-variable 'var-ExtSimpRules)) |
40785 | 500 |
501 (defun calc-declare-variable (&optional var) | |
502 (interactive) | |
503 (calc-wrapper | |
504 (or var (setq var (calc-read-var-name "Declare: " 0))) | |
505 (or var (setq var 'var-All)) | |
506 (let* (dp decl def row rp) | |
507 (or (and (calc-var-value 'var-Decls) | |
508 (eq (car-safe var-Decls) 'vec)) | |
509 (setq var-Decls (list 'vec))) | |
510 (setq dp var-Decls) | |
511 (while (and (setq dp (cdr dp)) | |
512 (or (not (eq (car-safe (car dp)) 'vec)) | |
513 (/= (length (car dp)) 3) | |
514 (progn | |
515 (setq row (nth 1 (car dp)) | |
516 rp row) | |
517 (if (eq (car-safe row) 'vec) | |
518 (progn | |
519 (while | |
520 (and (setq rp (cdr rp)) | |
521 (or (not (eq (car-safe (car rp)) 'var)) | |
522 (not (eq (nth 2 (car rp)) var))))) | |
523 (setq rp (car rp))) | |
524 (if (or (not (eq (car-safe row) 'var)) | |
525 (not (eq (nth 2 row) var))) | |
526 (setq rp nil))) | |
527 (not rp))))) | |
528 (calc-unread-command ?\C-a) | |
59720
be3370bd02da
(calc-declare-variable): Use calc-var-name to display variable name.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59299
diff
changeset
|
529 (setq decl (read-string (format "Declare: %s to be: " (calc-var-name var)) |
40785 | 530 (and rp |
531 (math-format-flat-expr (nth 2 (car dp)) 0)))) | |
532 (setq decl (and (string-match "[^ \t]" decl) | |
533 (math-read-exprs decl))) | |
534 (if (eq (car-safe decl) 'error) | |
535 (error "Bad format in declaration: %s" (nth 2 decl))) | |
536 (if (cdr decl) | |
537 (setq decl (cons 'vec decl)) | |
538 (setq decl (car decl))) | |
539 (and (eq (car-safe decl) 'vec) | |
540 (= (length decl) 2) | |
541 (setq decl (nth 1 decl))) | |
542 (calc-record (append '(vec) (list (math-build-var-name var)) | |
543 (and decl (list decl))) | |
544 "decl") | |
545 (setq var-Decls (copy-sequence var-Decls)) | |
546 (if (eq (car-safe row) 'vec) | |
547 (progn | |
548 (setcdr row (delq rp (cdr row))) | |
549 (or (cdr row) | |
550 (setq var-Decls (delq (car dp) var-Decls)))) | |
551 (setq var-Decls (delq (car dp) var-Decls))) | |
552 (if decl | |
553 (progn | |
554 (setq dp (and (not (eq var 'var-All)) var-Decls)) | |
555 (while (and (setq dp (cdr dp)) | |
556 (or (not (eq (car-safe (car dp)) 'vec)) | |
557 (/= (length (car dp)) 3) | |
558 (not (equal (nth 2 (car dp)) decl))))) | |
559 (if dp | |
560 (setcar (cdr (car dp)) | |
561 (append (if (eq (car-safe (nth 1 (car dp))) 'vec) | |
562 (nth 1 (car dp)) | |
563 (list 'vec (nth 1 (car dp)))) | |
564 (list (math-build-var-name var)))) | |
565 (setq var-Decls (append var-Decls | |
566 (list (list 'vec | |
567 (math-build-var-name var) | |
568 decl))))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
569 (calc-refresh-evaltos 'var-Decls)))) |
40785 | 570 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
571 (defvar calc-dont-insert-variables '(var-FitRules var-FactorRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
572 var-CommuteRules var-JumpRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
573 var-DistribRules var-MergeRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
574 var-NegateRules var-InvertRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
575 var-IntegAfterRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
576 var-TimeZone var-PlotRejects |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
577 var-PlotData1 var-PlotData2 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
578 var-PlotData3 var-PlotData4 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
579 var-PlotData5 var-PlotData6 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
580 var-DUMMY)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
581 |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
582 ;; The variable calc-pv-pos is local to calc-permanent-variable, but |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
583 ;; used by calc-insert-permanent-variable, which is called by |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
584 ;; calc-permanent-variable. |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
585 (defvar calc-pv-pos) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
586 |
40785 | 587 (defun calc-permanent-variable (&optional var) |
588 (interactive) | |
589 (calc-wrapper | |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64325
diff
changeset
|
590 (or var (setq var (calc-read-var-name "Save variable (default all): "))) |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
591 (let (calc-pv-pos) |
40785 | 592 (and var (or (and (boundp var) (symbol-value var)) |
593 (error "No such variable"))) | |
594 (set-buffer (find-file-noselect (substitute-in-file-name | |
595 calc-settings-file))) | |
596 (if var | |
597 (calc-insert-permanent-variable var) | |
598 (mapatoms (function | |
599 (lambda (x) | |
600 (and (string-match "\\`var-" (symbol-name x)) | |
601 (not (memq x calc-dont-insert-variables)) | |
602 (calc-var-value x) | |
603 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
604 (calc-insert-permanent-variable x)))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
605 (save-buffer)))) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
606 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
607 |
40785 | 608 |
609 (defun calc-insert-permanent-variable (var) | |
610 (goto-char (point-min)) | |
611 (if (search-forward (concat "(setq " (symbol-name var) " '") nil t) | |
612 (progn | |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
613 (setq calc-pv-pos (point-marker)) |
40785 | 614 (forward-line -1) |
615 (if (looking-at ";;; Variable .* stored by Calc on ") | |
616 (progn | |
617 (delete-region (match-end 0) (progn (end-of-line) (point))) | |
618 (insert (current-time-string)))) | |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
619 (goto-char (- calc-pv-pos 8 (length (symbol-name var)))) |
40785 | 620 (forward-sexp 1) |
621 (backward-char 1) | |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
622 (delete-region calc-pv-pos (point))) |
40785 | 623 (goto-char (point-max)) |
624 (insert "\n;;; Variable \"" | |
625 (symbol-name var) | |
626 "\" stored by Calc on " | |
627 (current-time-string) | |
628 "\n(setq " | |
629 (symbol-name var) | |
630 " ')\n") | |
631 (backward-char 2)) | |
632 (insert (prin1-to-string (calc-var-value var))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
633 (forward-line 1)) |
40785 | 634 |
635 (defun calc-insert-variables (buf) | |
636 (interactive "bBuffer in which to save variable values: ") | |
637 (save-excursion | |
638 (set-buffer buf) | |
639 (mapatoms (function | |
640 (lambda (x) | |
641 (and (string-match "\\`var-" (symbol-name x)) | |
642 (not (memq x calc-dont-insert-variables)) | |
643 (calc-var-value x) | |
644 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
645 (or (not (eq x 'var-Decls)) | |
646 (not (equal var-Decls '(vec)))) | |
647 (or (not (eq x 'var-Holidays)) | |
648 (not (equal var-Holidays '(vec (var sat var-sat) | |
649 (var sun var-sun))))) | |
650 (insert "(setq " | |
651 (symbol-name x) | |
652 " " | |
653 (prin1-to-string | |
654 (let ((calc-language | |
655 (if (memq calc-language '(nil big)) | |
656 'flat | |
657 calc-language))) | |
658 (math-format-value (symbol-value x) 100000))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
659 ")\n"))))))) |
40785 | 660 |
661 (defun calc-assign (arg) | |
662 (interactive "P") | |
663 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
664 (calc-binary-op ":=" 'calcFunc-assign arg))) |
40785 | 665 |
666 (defun calc-evalto (arg) | |
667 (interactive "P") | |
668 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
669 (calc-unary-op "=>" 'calcFunc-evalto arg))) |
40785 | 670 |
671 (defun calc-subscript (arg) | |
672 (interactive "P") | |
673 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
674 (calc-binary-op "sub" 'calcFunc-subscr arg))) |
40785 | 675 |
58673
202eaef4ca19
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58547
diff
changeset
|
676 (provide 'calc-store) |
202eaef4ca19
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58547
diff
changeset
|
677 |
52401 | 678 ;;; arch-tag: 2fbfec82-a521-42ca-bcd8-4f254ae6313e |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
679 ;;; calc-store.el ends here |