]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-units.el
Merge from emacs-24; up to 2014-04-22T20:19:17Z!eggert@cs.ucla.edu
[gnu-emacs] / lisp / calc / calc-units.el
index 72d51d9241c929f258c51fa979b852cce2aa74a8..31efd4b4ab32742e8052e1f0309125add87524e7 100644 (file)
@@ -1,6 +1,6 @@
 ;;; calc-units.el --- unit conversion functions for Calc
 
-;; Copyright (C) 1990-1993, 2001-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2014 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
@@ -437,17 +437,24 @@ If COMP or STD is non-nil, put that in the units table instead."
                  (list new-units (car default-units))
                  math-default-units-table))))))
 
+(defvar calc-allow-units-as-numbers t)
+
 (defun calc-convert-units (&optional old-units new-units)
   (interactive)
   (calc-slow-wrapper
    (let ((expr (calc-top-n 1))
         (uoldname nil)
          (unitscancel nil)
+         (nouold nil)
         unew
          units
          defunits)
      (if (or (not (math-units-in-expr-p expr t))
-             (setq unitscancel (eq (math-get-standard-units expr) 1)))
+             (setq unitscancel (and
+                                (if (get 'calc-allow-units-as-numbers 'saved-value)
+                                    (car (get 'calc-allow-units-as-numbers 'saved-value))
+                                  calc-allow-units-as-numbers)
+                                (eq (math-get-standard-units expr) 1))))
        (let ((uold (or old-units
                       (progn
                         (setq uoldname 
@@ -457,6 +464,7 @@ If COMP or STD is non-nil, put that in the units table instead."
                                  (read-string "Old units: ")))
                         (if (equal uoldname "")
                             (progn
+                               (setq nouold unitscancel)
                               (setq uoldname "1")
                               1)
                           (if (string-match "\\` */" uoldname)
@@ -469,7 +477,7 @@ If COMP or STD is non-nil, put that in the units table instead."
      (unless new-units
        (setq new-units
              (read-string (concat
-                           (if uoldname
+                           (if (and uoldname (not nouold))
                                (concat "Old units: "
                                        uoldname
                                        ", new units")
@@ -497,11 +505,13 @@ If COMP or STD is non-nil, put that in the units table instead."
            (comp (eq (car-safe units) '+)))
        (unless (or unew std)
          (error "No units specified"))
-       (let ((res
-              (if std
-                  (math-simplify-units (math-to-standard-units expr (nth 1 std)))
-                (math-convert-units expr units (and uoldname (not (equal uoldname "1")))))))
-         (math-put-default-units res (if comp units))
+       (let* ((noold (and uoldname (not (equal uoldname "1"))))
+              (res
+               (if std
+                   (math-simplify-units (math-to-standard-units expr (nth 1 std)))
+                 (math-convert-units expr units noold))))
+         (unless std
+           (math-put-default-units (if noold units res) (if comp units)))
          (calc-enter-result 1 "cvun" res))))))
 
 (defun calc-autorange-units (arg)
@@ -1487,10 +1497,8 @@ If COMP or STD is non-nil, put that in the units table instead."
    ((memq (car-safe expr) '(* /))
     (cons (car expr)
           (mapcar 'math-extract-units (cdr expr))))
-   ((and
-     (eq (car-safe expr) '^)
-     (math-check-unit-name (nth 1 expr)))
-    expr)
+   ((eq (car-safe expr) '^)
+    (list '^ (math-extract-units (nth 1 expr)) (nth 2 expr)))
    ((math-check-unit-name expr) expr)
    (t 1)))