diff options
author | Jay Belanger <jay.p.belanger@gmail.com> | 2015-01-28 21:17:10 -0600 |
---|---|---|
committer | Jay Belanger <jay.p.belanger@gmail.com> | 2015-01-28 21:17:10 -0600 |
commit | d1cb2f785525ad717a1504f4762505086b390bad (patch) | |
tree | 41eca2ffb49d1d993c918f378f5ff9ca79a450b5 /lisp/calc/calc-units.el | |
parent | 212c818940c420d2ef36a31ccb2fc0a110b1588b (diff) | |
download | emacs-d1cb2f785525ad717a1504f4762505086b390bad.tar.gz |
* lisp/calc/calc-units.el (calc-convert-exact-units): New function.
(calc-convert-units): Check for missing units.
* lisp/calc/calc-ext.el (calc-init-extensions): Autoload
`calc-convert-exact-units' and assign it a keybinding.
* lisp/calc/calc-help (calc-u-prefix-help): Add help for the
"un" keybinding.
Diffstat (limited to 'lisp/calc/calc-units.el')
-rw-r--r-- | lisp/calc/calc-units.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index 05950864a52..8442cf9ff25 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el @@ -470,6 +470,8 @@ If COMP or STD is non-nil, put that in the units table instead." (if (string-match "\\` */" uoldname) (setq uoldname (concat "1" uoldname))) (math-read-expr uoldname)))))) + (unless (math-units-in-expr-p uold t) + (error "No units specified")) (when (eq (car-safe uold) 'error) (error "Bad format in units expression: %s" (nth 1 uold))) (setq expr (math-mul expr uold)))) @@ -514,6 +516,38 @@ If COMP or STD is non-nil, put that in the units table instead." (math-put-default-units (if noold units res) (if comp units))) (calc-enter-result 1 "cvun" res)))))) +(defun calc-convert-exact-units () + (interactive) + (calc-slow-wrapper + (let* ((expr (calc-top-n 1))) + (unless (math-units-in-expr-p expr t) + (error "No units in expression.")) + (let* ((old-units (math-extract-units expr)) + (defunits (math-get-default-units expr)) + units + (new-units + (read-string (concat "New units" + (if defunits + (concat + " (default " + defunits + "): ") + ": "))))) + (if (and + (string= new-units "") + defunits) + (setq new-units defunits)) + (setq units (math-read-expr new-units)) + (when (eq (car-safe units) 'error) + (error "Bad format in units expression: %s" (nth 2 units))) + (math-check-unit-consistency old-units units) + (let ((res + (list '* (math-mul (math-remove-units expr) + (math-simplify-units + (list '/ old-units units))) + units))) + (calc-enter-result 1 "cvxu" res)))))) + (defun calc-autorange-units (arg) (interactive "P") (calc-wrapper |