Mercurial > emacs
changeset 62358:75b110fa35a8
(calc-store-value): Return a string rather than display it as a message.
Use calc-var-name for variable name.
(calc-store-into): Add the result of calc-store-value to message.
(calc-copy-variable): Add a message.
(calc-store-exchange): Improve error messages.
(calc-store-binary, calc-store-map): Don't reset the values of special constants.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Sun, 15 May 2005 05:20:59 +0000 |
parents | 5f5acca0e152 |
children | f7fdfa8ffb34 |
files | lisp/calc/calc-store.el |
diffstat | 1 files changed, 72 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/calc/calc-store.el Sun May 15 04:12:31 2005 +0000 +++ b/lisp/calc/calc-store.el Sun May 15 05:20:59 2005 +0000 @@ -57,15 +57,20 @@ ( | . calc-store-concat ) )))) (if found (funcall (cdr found)) - (calc-store-value var (or calc-given-value (calc-top 1)) - "" calc-given-value-flag) - (message "Stored to variable \"%s\"" (calc-var-name var)))) + (let ((msg + (calc-store-value var (or calc-given-value (calc-top 1)) + "" calc-given-value-flag))) + (message (concat "Stored to variable \"%s\"" msg) + (calc-var-name var))))) (setq var (calc-is-assignments (calc-top 1))) (if var (while var - (calc-store-value (car (car var)) (cdr (car var)) - (if (not (cdr var)) "") - (if (not (cdr var)) 1)) + (let ((msg + (calc-store-value (car (car var)) (cdr (car var)) + (if (not (cdr var)) "") + (if (not (cdr var)) 1)))) + (message (concat "Stored to variable \"%s\"" msg) + (calc-var-name var))) (setq var (cdr var)))))))) (defun calc-store-plus (&optional var) @@ -109,22 +114,26 @@ (calc-store-binary var "n" '- n)) (defun calc-store-value (var value tag &optional pop) - (if var - (let ((old (calc-var-value var))) - (set var value) - (if pop (or calc-store-keep (calc-pop-stack pop))) - (calc-record-undo (list 'store (symbol-name var) old)) - (if tag - (let ((calc-full-trail-vectors nil)) - (calc-record value (format ">%s%s" tag (calc-var-name var))))) - (and (memq var '(var-e var-i var-pi var-phi var-gamma)) - (eq (car-safe old) 'special-const) - (message "(Note: Built-in definition of %s has been lost)" var)) - (and (memq var '(var-inf var-uinf var-nan)) - (null old) - (message "(Note: %s has built-in meanings which may interfere)" - var)) - (calc-refresh-evaltos var)))) + (let ((msg "")) + (if var + (let ((old (calc-var-value var))) + (set var value) + (if pop (or calc-store-keep (calc-pop-stack pop))) + (calc-record-undo (list 'store (symbol-name var) old)) + (if tag + (let ((calc-full-trail-vectors nil)) + (calc-record value (format ">%s%s" tag (calc-var-name var))))) + (cond + ((and (memq var '(var-e var-i var-pi var-phi var-gamma)) + (eq (car-safe old) 'special-const)) + (setq msg (format " (Note: Built-in definition of %s has been lost)" + (calc-var-name var)))) + ((and (memq var '(var-inf var-uinf var-nan)) + (null old)) + (setq msg (format " (Note: %s has built-in meanings which may interfere)" + (calc-var-name var))))) + (calc-refresh-evaltos var))) + msg)) (defun calc-var-name (var) (if (symbolp var) (setq var (symbol-name var))) @@ -140,8 +149,12 @@ (or var (setq var (calc-read-var-name (format "Store %s: " tag)))) (if var (let ((old (calc-var-value var))) - (or old - (error "No such variable: \"%s\"" (calc-var-name var))) + (if (eq (car-safe old) 'special-const) + (error "\"%s\" is a special constant" (calc-var-name var))) + (if (not old) + (if (memq var '(var-inf var-uinf var-nan)) + (error "\"%s\" is a special variable" (calc-var-name var)) + (error "No such variable: \"%s\"" (calc-var-name var)))) (if (stringp old) (setq old (math-read-expr old))) (if (eq (car-safe old) 'error) @@ -151,7 +164,7 @@ (list func value old) (list func old value))) tag (and (not val) 1)) - (message "Stored to variable \"%s\"" (calc-var-name var))))))) + (message "Variable \"%s\" changed" (calc-var-name var))))))) (defvar calc-var-name-map nil "Keymap for reading Calc variable names.") (if calc-var-name-map @@ -228,26 +241,32 @@ (or var (setq var (calc-read-var-name (format "Store Mapping %s: " (nth 2 oper))))) (if var - (let ((old (or (calc-var-value var) - (error "No such variable: \"%s\"" - (calc-var-name var)))) - (calc-simplify-mode (if (eq calc-simplify-mode 'none) - 'num calc-simplify-mode)) - (values (and (> nargs 1) - (calc-top-list (1- nargs) (1+ calc-dollar-used))))) - (message "Working...") - (calc-set-command-flag 'clear-message) - (if (stringp old) - (setq old (math-read-expr old))) - (if (eq (car-safe old) 'error) - (error "Bad format in variable contents: %s" (nth 2 old))) - (setq values (if (calc-is-inverse) - (append values (list old)) - (append (list old) values))) - (calc-store-value var - (calc-normalize (cons (nth 1 oper) values)) - (nth 2 oper) - (+ calc-dollar-used (1- nargs)))))))) + (let ((old (calc-var-value var))) + (if (eq (car-safe old) 'special-const) + (error "\"%s\" is a special constant" (calc-var-name var))) + (if (not old) + (if (memq var '(var-inf var-uinf var-nan)) + (error "\"%s\" is a special variable" (calc-var-name var)) + (error "No such variable: \"%s\"" (calc-var-name var)))) + (let ((calc-simplify-mode (if (eq calc-simplify-mode 'none) + 'num calc-simplify-mode)) + (values (and (> nargs 1) + (calc-top-list (1- nargs) (1+ calc-dollar-used))))) + (message "Working...") + (calc-set-command-flag 'clear-message) + (if (stringp old) + (setq old (math-read-expr old))) + (if (eq (car-safe old) 'error) + (error "Bad format in variable contents: %s" (nth 2 old))) + (setq values (if (calc-is-inverse) + (append values (list old)) + (append (list old) values))) + (calc-store-value var + (calc-normalize (cons (nth 1 oper) values)) + (nth 2 oper) + (+ calc-dollar-used (1- nargs))) + (message "Variable \"%s\" changed" (calc-var-name var)))))))) + (defun calc-store-exchange (&optional var) (interactive) @@ -258,10 +277,12 @@ (or var (setq var (calc-read-var-name "Exchange with: "))) (if var (let ((value (calc-var-value var))) - (or value - (error "No such variable: \"%s\"" (calc-var-name var))) (if (eq (car-safe value) 'special-const) - (error "%s is a special constant" var)) + (error "\"%s\" is a special constant" (calc-var-name var))) + (if (not value) + (if (memq var '(var-inf var-uinf var-nan)) + (error "\"%s\" is a special variable" (calc-var-name var)) + (error "No such variable: \"%s\"" (calc-var-name var)))) (setq top (or calc-given-value (calc-top 1))) (calc-store-value var top nil) (calc-pop-push-record calc-given-value-flag @@ -378,7 +399,9 @@ (format "Copy variable: %s, to: " (calc-var-name var1))))) (if var2 - (calc-store-value var2 value "")))))) + (let ((msg (calc-store-value var2 value ""))) + (message (concat "Variable \"%s\" copied to \"%s\"" msg) + (calc-var-name var1) (calc-var-name var2)))))))) (defvar calc-last-edited-variable nil) (defun calc-edit-variable (&optional var)