]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/calc/calc-units.el (calc-convert-exact-units): New function.
authorJay Belanger <jay.p.belanger@gmail.com>
Thu, 29 Jan 2015 03:17:10 +0000 (21:17 -0600)
committerJay Belanger <jay.p.belanger@gmail.com>
Thu, 29 Jan 2015 03:17:10 +0000 (21:17 -0600)
(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.

lisp/ChangeLog
lisp/calc/calc-ext.el
lisp/calc/calc-help.el
lisp/calc/calc-units.el

index ddad9d430b8ba89b0aeba8a389085dad0c730089..4d7f2f75e5746c1490bc0717298495bbff76a14b 100644 (file)
@@ -1,3 +1,14 @@
+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.
index c3acb89e41747641226f029f0e6e7fac9766325c..67d0c2701d28523c599c1a36a89ee1f5cac79b31 100644 (file)
   (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
index 511e208ddeac67120943b71f3196e3148b2744a9..17e5b0fdead17e90373221c8cfd8ad05d33fac24 100644 (file)
@@ -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"
index 05950864a527c8e8ddff9b9041b9a0e22c510a5b..8442cf9ff25bec8f35fb1822018c1692a264f791 100644 (file)
@@ -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