(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-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.
(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)
("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
(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"
(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))))
(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