Commit d1cb2f78 authored by Jay Belanger's avatar Jay Belanger

* 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.
parent 212c8189
2015-01-29 Jay Belanger <jay.p.belanger@gmail.com>
* 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.
2015-01-28 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/cl.el (cl--function-convert): Simplify.
......
......@@ -561,6 +561,7 @@
(define-key calc-mode-map "ud" 'calc-define-unit)
(define-key calc-mode-map "ue" 'calc-explain-units)
(define-key calc-mode-map "ug" 'calc-get-unit-definition)
(define-key calc-mode-map "un" 'calc-convert-exact-units)
(define-key calc-mode-map "up" 'calc-permanent-units)
(define-key calc-mode-map "ur" 'calc-remove-units)
(define-key calc-mode-map "us" 'calc-simplify-units)
......@@ -1176,7 +1177,8 @@ calc-trail-scroll-right calc-trail-yank)
("calc-undo" calc-last-args calc-redo)
("calc-units" calc-autorange-units calc-base-units
calc-convert-temperature calc-convert-units calc-define-unit
calc-convert-temperature calc-convert-units
calc-convert-exact-units calc-define-unit
calc-enter-units-table calc-explain-units calc-extract-units
calc-get-unit-definition calc-permanent-units calc-quick-units
calc-remove-units calc-simplify-units calc-undefine-unit
......
......@@ -647,7 +647,7 @@ C-w Describe how there is no warranty for Calc."
(defun calc-u-prefix-help ()
(interactive)
(calc-do-prefix-help
'("Simplify, Convert, Temperature-convert, Base-units"
'("Simplify, Convert, coNvert exact, Temperature-convert, Base-units"
"Autorange; Remove, eXtract; Explain; View-table; 0-9"
"Define, Undefine, Get-defn, Permanent"
"SHIFT + View-table-other-window"
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment