emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master d1cb2f7: * lisp/calc/calc-units.el (calc-convert-ex


From: Jay Belanger
Subject: [Emacs-diffs] master d1cb2f7: * lisp/calc/calc-units.el (calc-convert-exact-units): New function.
Date: Thu, 29 Jan 2015 03:18:22 +0000

branch: master
commit d1cb2f785525ad717a1504f4762505086b390bad
Author: Jay Belanger <address@hidden>
Commit: Jay Belanger <address@hidden>

    * 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.
---
 lisp/ChangeLog          |   11 +++++++++++
 lisp/calc/calc-ext.el   |    4 +++-
 lisp/calc/calc-help.el  |    2 +-
 lisp/calc/calc-units.el |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ddad9d4..4d7f2f7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
+2015-01-29  Jay Belanger  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/cl.el (cl--function-convert): Simplify.
diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index c3acb89..67d0c27 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -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
diff --git a/lisp/calc/calc-help.el b/lisp/calc/calc-help.el
index 511e208..17e5b0f 100644
--- a/lisp/calc/calc-help.el
+++ b/lisp/calc/calc-help.el
@@ -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"
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index 0595086..8442cf9 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]