Mercurial > emacs
annotate lisp/calc/calc-store.el @ 93427:753ad51473c7
(xg_set_geometry): Fix indentation.
(xg_resize_outer_widget): Removed
(x_wm_size_hint_off): Fix indentation.
(xg_frame_set_char_size): Call flush_and_sync after
gtk_window_resize.
(x_wm_set_size_hint): Pass NULL as geometry window to
gtk_window_set_geometry_hints due to Gtk+ bug nr 68668.
Add menu bar and tool bar height to base height.
(xg_update_frame_menubar, free_frame_menubar)
(xg_tool_bar_detach_callback, xg_tool_bar_attach_callback)
(update_frame_tool_bar, free_frame_tool_bar): Change
xg_resize_outer_widget to xg_frame_set_char_size.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sun, 30 Mar 2008 17:37:59 +0000 |
parents | ed8741f16e51 |
children | 1e3a407766b9 |
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, |
79702 | 4 ;; 2005, 2006, 2007, 2008 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 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
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 |
78215
095d08e7d6bb
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
77465
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
76595
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
14 ;; any later version. |
40785 | 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 |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
497d17a80bb8
Change form of license text to match rest of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
40785 | 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)) |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
130 (setq msg (format " (Note: Built-in definition of %s has been lost)" |
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
|
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) |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
175 (mapc (function |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
176 (lambda (x) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
177 (define-key calc-var-name-map (char-to-string x) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
178 'calcVar-digit))) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
179 "0123456789") |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
180 (mapc (function |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
181 (lambda (x) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
182 (define-key calc-var-name-map (char-to-string x) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
183 'calcVar-oper))) |
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
184 "+-*/^|")) |
58547
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 |
93262
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
188 (defvar calc-read-var-name-history nil |
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
189 "History for reading variable names.") |
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
190 |
40785 | 191 (defun calc-read-var-name (prompt &optional calc-store-opers) |
192 (setq calc-given-value nil | |
193 calc-aborted-prefix nil) | |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
194 (let ((var (concat |
59090
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
195 "var-" |
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
196 (let ((minibuffer-completion-table |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
197 (mapcar (lambda (x) (substring x 4)) |
59090
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
198 (all-completions "var-" obarray))) |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
199 (minibuffer-completion-predicate |
59090
ce01a490300d
(calc-read-var-name): Remove initial "var-" from minibuffer.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58673
diff
changeset
|
200 (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
|
201 (minibuffer-completion-confirm t)) |
93262
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
202 (read-from-minibuffer |
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
203 prompt nil calc-var-name-map nil |
ed8741f16e51
(calc-read-var-name-history): New variable.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
87649
diff
changeset
|
204 'calc-read-var-name-history))))) |
40785 | 205 (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
|
206 (and (not (equal var "var-")) |
40785 | 207 (if (string-match "\\`\\([-a-zA-Z0-9]+\\) *:?=" var) |
208 (if (null calc-given-value-flag) | |
209 (error "Assignment is not allowed in this command") | |
210 (let ((svar (intern (substring var 0 (match-end 1))))) | |
211 (setq calc-given-value-flag 0 | |
212 calc-given-value (math-read-expr | |
213 (substring var (match-end 0)))) | |
214 (if (eq (car-safe calc-given-value) 'error) | |
215 (error "Bad format: %s" (nth 2 calc-given-value))) | |
216 (setq calc-given-value (math-evaluate-expr calc-given-value)) | |
217 svar)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
218 (intern var))))) |
40785 | 219 |
220 (defun calcVar-digit () | |
221 (interactive) | |
59265
eb45d1b6dbc3
(calcVar-digit, calcVar-oper): Remove need for "var-" at the
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59211
diff
changeset
|
222 (if (calc-minibuffer-contains "\\'") |
40785 | 223 (if (eq calc-store-opers 0) |
224 (beep) | |
225 (insert "q") | |
226 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
227 (self-insert-command 1))) |
40785 | 228 |
229 (defun calcVar-oper () | |
230 (interactive) | |
231 (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
|
232 (calc-minibuffer-contains "\\'")) |
40785 | 233 (progn |
234 (erase-buffer) | |
235 (self-insert-and-exit)) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
236 (self-insert-command 1))) |
40785 | 237 |
238 (defun calc-store-map (&optional oper var) | |
239 (interactive) | |
240 (calc-wrapper | |
241 (let* ((sel-mode nil) | |
242 (calc-dollar-values (mapcar 'calc-get-stack-element | |
243 (nthcdr calc-stack-top calc-stack))) | |
244 (calc-dollar-used 0) | |
245 (oper (or oper (calc-get-operator "Store Mapping"))) | |
246 (nargs (car oper))) | |
247 (or var (setq var (calc-read-var-name (format "Store Mapping %s: " | |
248 (nth 2 oper))))) | |
249 (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
|
250 (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
|
251 (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
|
252 (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
|
253 (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
|
254 (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
|
255 (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
|
256 (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
|
257 (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
|
258 '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
|
259 (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
|
260 (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
|
261 (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
|
262 (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
|
263 (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
|
264 (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
|
265 (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
|
266 (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
|
267 (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
|
268 (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
|
269 (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
|
270 (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
|
271 (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
|
272 (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
|
273 (+ 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
|
274 (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
|
275 |
40785 | 276 |
277 (defun calc-store-exchange (&optional var) | |
278 (interactive) | |
279 (calc-wrapper | |
280 (let ((calc-given-value nil) | |
281 (calc-given-value-flag 1) | |
282 top) | |
283 (or var (setq var (calc-read-var-name "Exchange with: "))) | |
284 (if var | |
285 (let ((value (calc-var-value var))) | |
286 (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
|
287 (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
|
288 (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
|
289 (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
|
290 (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
|
291 (error "No such variable: \"%s\"" (calc-var-name var)))) |
40785 | 292 (setq top (or calc-given-value (calc-top 1))) |
293 (calc-store-value var top nil) | |
294 (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
|
295 (concat "<>" (calc-var-name var)) value)))))) |
40785 | 296 |
297 (defun calc-unstore (&optional var) | |
298 (interactive) | |
299 (calc-wrapper | |
300 (or var (setq var (calc-read-var-name "Unstore: "))) | |
301 (if var | |
302 (progn | |
303 (and (memq var '(var-e var-i var-pi var-phi var-gamma)) | |
304 (eq (car-safe (calc-var-value var)) 'special-const) | |
305 (message "(Note: Built-in definition of %s has been lost)" var)) | |
306 (if (and (boundp var) (symbol-value var)) | |
307 (message "Unstored variable \"%s\"" (calc-var-name var)) | |
308 (message "Variable \"%s\" remains unstored" (calc-var-name var))) | |
309 (makunbound var) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
310 (calc-refresh-evaltos var))))) |
40785 | 311 |
312 (defun calc-let (&optional var) | |
313 (interactive) | |
314 (calc-wrapper | |
315 (let* ((calc-given-value nil) | |
316 (calc-given-value-flag 1) | |
317 thing value) | |
318 (or var (setq var (calc-read-var-name "Let variable: "))) | |
319 (if calc-given-value | |
320 (setq value calc-given-value | |
321 thing (calc-top 1)) | |
322 (setq value (calc-top 1) | |
323 thing (calc-top 2))) | |
324 (setq var (if var | |
325 (list (cons var value)) | |
326 (calc-is-assignments value))) | |
327 (if var | |
328 (calc-pop-push-record | |
329 (1+ calc-given-value-flag) | |
330 (concat "=" (calc-var-name (car (car var)))) | |
331 (let ((saved-val (mapcar (function | |
332 (lambda (v) | |
333 (and (boundp (car v)) | |
334 (symbol-value (car v))))) | |
335 var))) | |
336 (unwind-protect | |
337 (let ((vv var)) | |
338 (while vv | |
339 (set (car (car vv)) (calc-normalize (cdr (car vv)))) | |
340 (calc-refresh-evaltos (car (car vv))) | |
341 (setq vv (cdr vv))) | |
342 (math-evaluate-expr thing)) | |
343 (while saved-val | |
344 (if (car saved-val) | |
345 (set (car (car var)) (car saved-val)) | |
346 (makunbound (car (car var)))) | |
347 (setq saved-val (cdr saved-val) | |
348 var (cdr var))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
349 (calc-handle-whys)))))))) |
40785 | 350 |
351 (defun calc-is-assignments (value) | |
352 (if (memq (car-safe value) '(calcFunc-eq calcFunc-assign)) | |
353 (and (eq (car-safe (nth 1 value)) 'var) | |
354 (list (cons (nth 2 (nth 1 value)) (nth 2 value)))) | |
355 (if (eq (car-safe value) 'vec) | |
356 (let ((vv nil)) | |
357 (while (and (setq value (cdr value)) | |
358 (memq (car-safe (car value)) | |
359 '(calcFunc-eq calcFunc-assign)) | |
360 (eq (car-safe (nth 1 (car value))) 'var)) | |
361 (setq vv (cons (cons (nth 2 (nth 1 (car value))) | |
362 (nth 2 (car value))) | |
363 vv))) | |
364 (and (not value) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
365 vv))))) |
40785 | 366 |
367 (defun calc-recall (&optional var) | |
368 (interactive) | |
369 (calc-wrapper | |
370 (or var (setq var (calc-read-var-name "Recall: "))) | |
371 (if var | |
372 (let ((value (calc-var-value var))) | |
373 (or value | |
374 (error "No such variable: \"%s\"" (calc-var-name var))) | |
375 (if (stringp value) | |
376 (setq value (math-read-expr value))) | |
377 (if (eq (car-safe value) 'error) | |
378 (error "Bad format in variable contents: %s" (nth 2 value))) | |
379 (setq value (calc-normalize value)) | |
380 (let ((calc-full-trail-vectors nil)) | |
381 (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
|
382 (calc-push value))))) |
40785 | 383 |
384 (defun calc-store-quick () | |
385 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
386 (calc-store (intern (format "var-q%c" last-command-char)))) |
40785 | 387 |
388 (defun calc-store-into-quick () | |
389 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
390 (calc-store-into (intern (format "var-q%c" last-command-char)))) |
40785 | 391 |
392 (defun calc-recall-quick () | |
393 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
394 (calc-recall (intern (format "var-q%c" last-command-char)))) |
40785 | 395 |
62392
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
396 (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
|
397 (interactive) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
398 (let ((sc '(("") |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
399 ("e" . (special-const (math-e))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
400 ("pi" . (special-const (math-pi))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
401 ("i" . (special-const (math-imaginary 1))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
402 ("phi" . (special-const (math-phi))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
403 ("gamma" . (special-const (math-gamma-const)))))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
404 (calc-wrapper |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
405 (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
|
406 (unless (string= sconst "") |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
407 (let ((value (cdr (assoc sconst sc)))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
408 (or var (setq var (calc-read-var-name |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
409 (format "Copy special constant %s, to: " |
62392
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
410 sconst)))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
411 (if var |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
412 (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
|
413 (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
|
414 sconst (calc-var-name var))))))))) |
0476ffde9ab3
(calc-copy-special-constant): New function.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
62358
diff
changeset
|
415 |
40785 | 416 (defun calc-copy-variable (&optional var1 var2) |
417 (interactive) | |
418 (calc-wrapper | |
419 (or var1 (setq var1 (calc-read-var-name "Copy variable: "))) | |
420 (if var1 | |
421 (let ((value (calc-var-value var1))) | |
422 (or value | |
59211
999144478c9a
(calc-copy-variable): Fix mistyped variable name. Display variable
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59090
diff
changeset
|
423 (error "No such variable: \"%s\"" (calc-var-name var1))) |
40785 | 424 (or var2 (setq var2 (calc-read-var-name |
84889
fa8470bb9f1a
(calc-var-name-map): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
parents:
78215
diff
changeset
|
425 (format "Copy variable: %s, to: " |
59211
999144478c9a
(calc-copy-variable): Fix mistyped variable name. Display variable
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59090
diff
changeset
|
426 (calc-var-name var1))))) |
40785 | 427 (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
|
428 (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
|
429 (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
|
430 (calc-var-name var1) (calc-var-name var2)))))))) |
40785 | 431 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
432 (defvar calc-last-edited-variable nil) |
40785 | 433 (defun calc-edit-variable (&optional var) |
434 (interactive) | |
435 (calc-wrapper | |
436 (or var (setq var (calc-read-var-name | |
437 (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
|
438 (format "Edit (default %s): " |
40785 | 439 (calc-var-name calc-last-edited-variable)) |
440 "Edit: ")))) | |
441 (or var (setq var calc-last-edited-variable)) | |
442 (if var | |
443 (let* ((value (calc-var-value var))) | |
444 (if (eq (car-safe value) 'special-const) | |
445 (error "%s is a special constant" var)) | |
446 (setq calc-last-edited-variable var) | |
447 (calc-edit-mode (list 'calc-finish-stack-edit (list 'quote var)) | |
448 t | |
59299
b851b98f8dc1
(calc-edit-variable): Change title to match new header.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
59265
diff
changeset
|
449 (concat "Editing variable `" (calc-var-name var) "'. ")) |
40785 | 450 (and value |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
451 (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
|
452 (calc-show-edit-buffer)) |
40785 | 453 |
454 (defun calc-edit-Decls () | |
455 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
456 (calc-edit-variable 'var-Decls)) |
40785 | 457 |
458 (defun calc-edit-EvalRules () | |
459 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
460 (calc-edit-variable 'var-EvalRules)) |
40785 | 461 |
462 (defun calc-edit-FitRules () | |
463 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
464 (calc-edit-variable 'var-FitRules)) |
40785 | 465 |
466 (defun calc-edit-GenCount () | |
467 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
468 (calc-edit-variable 'var-GenCount)) |
40785 | 469 |
470 (defun calc-edit-Holidays () | |
471 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
472 (calc-edit-variable 'var-Holidays)) |
40785 | 473 |
474 (defun calc-edit-IntegLimit () | |
475 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
476 (calc-edit-variable 'var-IntegLimit)) |
40785 | 477 |
478 (defun calc-edit-LineStyles () | |
479 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
480 (calc-edit-variable 'var-LineStyles)) |
40785 | 481 |
482 (defun calc-edit-PointStyles () | |
483 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
484 (calc-edit-variable 'var-PointStyles)) |
40785 | 485 |
486 (defun calc-edit-PlotRejects () | |
487 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
488 (calc-edit-variable 'var-PlotRejects)) |
40785 | 489 |
490 (defun calc-edit-AlgSimpRules () | |
491 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
492 (calc-edit-variable 'var-AlgSimpRules)) |
40785 | 493 |
494 (defun calc-edit-TimeZone () | |
495 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
496 (calc-edit-variable 'var-TimeZone)) |
40785 | 497 |
498 (defun calc-edit-Units () | |
499 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
500 (calc-edit-variable 'var-Units)) |
40785 | 501 |
502 (defun calc-edit-ExtSimpRules () | |
503 (interactive) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
504 (calc-edit-variable 'var-ExtSimpRules)) |
40785 | 505 |
506 (defun calc-declare-variable (&optional var) | |
507 (interactive) | |
508 (calc-wrapper | |
509 (or var (setq var (calc-read-var-name "Declare: " 0))) | |
510 (or var (setq var 'var-All)) | |
511 (let* (dp decl def row rp) | |
512 (or (and (calc-var-value 'var-Decls) | |
513 (eq (car-safe var-Decls) 'vec)) | |
514 (setq var-Decls (list 'vec))) | |
515 (setq dp var-Decls) | |
516 (while (and (setq dp (cdr dp)) | |
517 (or (not (eq (car-safe (car dp)) 'vec)) | |
518 (/= (length (car dp)) 3) | |
519 (progn | |
520 (setq row (nth 1 (car dp)) | |
521 rp row) | |
522 (if (eq (car-safe row) 'vec) | |
523 (progn | |
524 (while | |
525 (and (setq rp (cdr rp)) | |
526 (or (not (eq (car-safe (car rp)) 'var)) | |
527 (not (eq (nth 2 (car rp)) var))))) | |
528 (setq rp (car rp))) | |
529 (if (or (not (eq (car-safe row) 'var)) | |
530 (not (eq (nth 2 row) var))) | |
531 (setq rp nil))) | |
532 (not rp))))) | |
533 (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
|
534 (setq decl (read-string (format "Declare: %s to be: " (calc-var-name var)) |
40785 | 535 (and rp |
536 (math-format-flat-expr (nth 2 (car dp)) 0)))) | |
537 (setq decl (and (string-match "[^ \t]" decl) | |
538 (math-read-exprs decl))) | |
539 (if (eq (car-safe decl) 'error) | |
540 (error "Bad format in declaration: %s" (nth 2 decl))) | |
541 (if (cdr decl) | |
542 (setq decl (cons 'vec decl)) | |
543 (setq decl (car decl))) | |
544 (and (eq (car-safe decl) 'vec) | |
545 (= (length decl) 2) | |
546 (setq decl (nth 1 decl))) | |
547 (calc-record (append '(vec) (list (math-build-var-name var)) | |
548 (and decl (list decl))) | |
549 "decl") | |
550 (setq var-Decls (copy-sequence var-Decls)) | |
551 (if (eq (car-safe row) 'vec) | |
552 (progn | |
553 (setcdr row (delq rp (cdr row))) | |
554 (or (cdr row) | |
555 (setq var-Decls (delq (car dp) var-Decls)))) | |
556 (setq var-Decls (delq (car dp) var-Decls))) | |
557 (if decl | |
558 (progn | |
559 (setq dp (and (not (eq var 'var-All)) var-Decls)) | |
560 (while (and (setq dp (cdr dp)) | |
561 (or (not (eq (car-safe (car dp)) 'vec)) | |
562 (/= (length (car dp)) 3) | |
563 (not (equal (nth 2 (car dp)) decl))))) | |
564 (if dp | |
565 (setcar (cdr (car dp)) | |
566 (append (if (eq (car-safe (nth 1 (car dp))) 'vec) | |
567 (nth 1 (car dp)) | |
568 (list 'vec (nth 1 (car dp)))) | |
569 (list (math-build-var-name var)))) | |
570 (setq var-Decls (append var-Decls | |
571 (list (list 'vec | |
572 (math-build-var-name var) | |
573 decl))))))) | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
574 (calc-refresh-evaltos 'var-Decls)))) |
40785 | 575 |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
576 (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
|
577 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
|
578 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
|
579 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
|
580 var-IntegAfterRules |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
581 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
|
582 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
|
583 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
|
584 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
|
585 var-DUMMY)) |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
586 |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
587 ;; 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
|
588 ;; 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
|
589 ;; calc-permanent-variable. |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
590 (defvar calc-pv-pos) |
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
591 |
40785 | 592 (defun calc-permanent-variable (&optional var) |
593 (interactive) | |
594 (calc-wrapper | |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64325
diff
changeset
|
595 (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
|
596 (let (calc-pv-pos) |
40785 | 597 (and var (or (and (boundp var) (symbol-value var)) |
598 (error "No such variable"))) | |
599 (set-buffer (find-file-noselect (substitute-in-file-name | |
600 calc-settings-file))) | |
601 (if var | |
602 (calc-insert-permanent-variable var) | |
603 (mapatoms (function | |
604 (lambda (x) | |
605 (and (string-match "\\`var-" (symbol-name x)) | |
606 (not (memq x calc-dont-insert-variables)) | |
607 (calc-var-value x) | |
608 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
609 (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
|
610 (save-buffer)))) |
41271
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
611 |
fcd507927105
Change all toplevel `setq' forms to `defvar' forms, and move them
Colin Walters <walters@gnu.org>
parents:
41047
diff
changeset
|
612 |
40785 | 613 |
614 (defun calc-insert-permanent-variable (var) | |
615 (goto-char (point-min)) | |
616 (if (search-forward (concat "(setq " (symbol-name var) " '") nil t) | |
617 (progn | |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
618 (setq calc-pv-pos (point-marker)) |
40785 | 619 (forward-line -1) |
620 (if (looking-at ";;; Variable .* stored by Calc on ") | |
621 (progn | |
622 (delete-region (match-end 0) (progn (end-of-line) (point))) | |
623 (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
|
624 (goto-char (- calc-pv-pos 8 (length (symbol-name var)))) |
40785 | 625 (forward-sexp 1) |
626 (backward-char 1) | |
58547
1e95f60dbab4
(calc-given-value, calc-store-opers): Declare them.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
52401
diff
changeset
|
627 (delete-region calc-pv-pos (point))) |
40785 | 628 (goto-char (point-max)) |
629 (insert "\n;;; Variable \"" | |
630 (symbol-name var) | |
631 "\" stored by Calc on " | |
632 (current-time-string) | |
633 "\n(setq " | |
634 (symbol-name var) | |
635 " ')\n") | |
636 (backward-char 2)) | |
637 (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
|
638 (forward-line 1)) |
40785 | 639 |
640 (defun calc-insert-variables (buf) | |
641 (interactive "bBuffer in which to save variable values: ") | |
642 (save-excursion | |
643 (set-buffer buf) | |
644 (mapatoms (function | |
645 (lambda (x) | |
646 (and (string-match "\\`var-" (symbol-name x)) | |
647 (not (memq x calc-dont-insert-variables)) | |
648 (calc-var-value x) | |
649 (not (eq (car-safe (symbol-value x)) 'special-const)) | |
650 (or (not (eq x 'var-Decls)) | |
651 (not (equal var-Decls '(vec)))) | |
652 (or (not (eq x 'var-Holidays)) | |
653 (not (equal var-Holidays '(vec (var sat var-sat) | |
654 (var sun var-sun))))) | |
655 (insert "(setq " | |
656 (symbol-name x) | |
657 " " | |
658 (prin1-to-string | |
659 (let ((calc-language | |
660 (if (memq calc-language '(nil big)) | |
661 'flat | |
662 calc-language))) | |
663 (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
|
664 ")\n"))))))) |
40785 | 665 |
666 (defun calc-assign (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-binary-op ":=" 'calcFunc-assign arg))) |
40785 | 670 |
671 (defun calc-evalto (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-unary-op "=>" 'calcFunc-evalto arg))) |
40785 | 675 |
676 (defun calc-subscript (arg) | |
677 (interactive "P") | |
678 (calc-slow-wrapper | |
41047
73f364fd8aaa
Style cleanup; don't put closing parens on their
Colin Walters <walters@gnu.org>
parents:
40785
diff
changeset
|
679 (calc-binary-op "sub" 'calcFunc-subscr arg))) |
40785 | 680 |
58673
202eaef4ca19
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58547
diff
changeset
|
681 (provide 'calc-store) |
202eaef4ca19
Add a provide statement.
Jay Belanger <jay.p.belanger@gmail.com>
parents:
58547
diff
changeset
|
682 |
52401 | 683 ;;; 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
|
684 ;;; calc-store.el ends here |