[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r108299: * calc/calc.el (calc-ensure-
From: |
Jay Belanger |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r108299: * calc/calc.el (calc-ensure-consistent-units): New variable. |
Date: |
Fri, 18 May 2012 22:00:48 -0500 |
User-agent: |
Bazaar (2.3.1) |
------------------------------------------------------------
revno: 108299
committer: Jay Belanger <address@hidden>
branch nick: trunk
timestamp: Fri 2012-05-18 22:00:48 -0500
message:
* calc/calc.el (calc-ensure-consistent-units): New variable.
* calc/calc-units.el (math-consistent-units-p, math-check-unit-consistency):
New functions.
(calc-quick-units, calc-convert-units): Use `math-check-unit-consistency'
when
`calc-ensure-consistent-units' is non-nil.
(calc-extract-units): Fix typo.
* doc/misc/calc.texi
(Basic Operations on Units, Customizing Calc):
Mention `calc-ensure-consistent-units'.
modified:
doc/misc/ChangeLog
doc/misc/calc.texi
lisp/ChangeLog
lisp/calc/calc-units.el
lisp/calc/calc.el
=== modified file 'doc/misc/ChangeLog'
--- a/doc/misc/ChangeLog 2012-05-14 16:11:24 +0000
+++ b/doc/misc/ChangeLog 2012-05-19 03:00:48 +0000
@@ -1,3 +1,9 @@
+2012-05-19 Jay Belanger <address@hidden>
+
+ * doc/misc/calc.texi
+ (Basic Operations on Units, Customizing Calc):
+ Mention `calc-ensure-consistent-units'.
+
2012-05-14 Andreas Schwab <address@hidden>
* cc-mode.texi: Avoid space before macro in 4th argument of cross
=== modified file 'doc/misc/calc.texi'
--- a/doc/misc/calc.texi 2012-02-28 08:17:21 +0000
+++ b/doc/misc/calc.texi 2012-05-19 03:00:48 +0000
@@ -27778,6 +27778,11 @@
``fundamental'' units like @samp{m} and @samp{s}, regardless of the
input units.
+If you want to disallow using inconsistent units, you can set the customizable
variable
address@hidden to @code{t} (@pxref{Customizing Calc}). In this case,
+if you request units which are inconsistent with the original units, you will
be warned about
+it and no conversion will occur.
+
One special exception is that if you specify a single unit name, and
a compatible unit appears somewhere in the units expression, then
that compatible unit will be converted to the new unit and the
@@ -35591,6 +35596,19 @@
of @code{calc-multiplication-has-precedence} is @code{t}.
@end defvar
address@hidden calc-ensure-consistent-units
+When converting units, the variable @code{calc-ensure-consistent-units}
+determines whether or not the target units need to be consistent with the
+original units. If @code{calc-ensure-consistent-units} is @code{nil}, then
+the target units don't need to have the same dimensions as the original units;
+for example, converting @samp{100 ft/s} to @samp{m} will produce @samp{30.48
m/s}.
+If @code{calc-ensure-consistent-units} is address@hidden, then the target
units
+need to have the same dimensions as the original units; for example,
converting
address@hidden ft/s} to @samp{m} will result in an error, since @samp{ft/s} and
@samp{m}
+have different dimensions. The default value of
@code{calc-ensure-consistent-units}
+is @code{nil}.
address@hidden defvar
+
@defvar calc-undo-length
The variable @code{calc-undo-length} determines the number of undo
steps that Calc will keep track of when @code{calc-quit} is called.
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2012-05-18 20:38:37 +0000
+++ b/lisp/ChangeLog 2012-05-19 03:00:48 +0000
@@ -1,3 +1,13 @@
+2012-05-19 Jay Belanger <address@hidden>
+
+ * calc/calc.el (calc-ensure-consistent-units): New variable.
+
+ * calc/calc-units.el (math-consistent-units-p,
math-check-unit-consistency):
+ New functions.
+ (calc-quick-units, calc-convert-units): Use
`math-check-unit-consistency' when
+ `calc-ensure-consistent-units' is non-nil.
+ (calc-extract-units): Fix typo.
+
2012-05-18 Stefan Monnier <address@hidden>
* vc/vc-bzr.el (vc-bzr-state-heuristic): Save match-data around sha1.
=== modified file 'lisp/calc/calc-units.el'
--- a/lisp/calc/calc-units.el 2012-04-09 13:05:48 +0000
+++ b/lisp/calc/calc-units.el 2012-05-19 03:00:48 +0000
@@ -370,8 +370,11 @@
(unless (< pos (length units))
(error "Unit number %d not defined" pos))
(if (math-units-in-expr-p expr nil)
- (calc-enter-result 1 (format "cun%d" num)
- (math-convert-units expr (nth pos units)))
+ (progn
+ (if calc-ensure-consistent-units
+ (math-check-unit-consistency expr units))
+ (calc-enter-result 1 (format "cun%d" num)
+ (math-convert-units expr (nth pos units))))
(calc-enter-result 1 (format "*un%d" num)
(math-simplify-units
(math-mul expr (nth pos units))))))))
@@ -477,6 +480,8 @@
(setq units (math-read-expr new-units))
(when (eq (car-safe units) 'error)
(error "Bad format in units expression: %s" (nth 2 units)))
+ (if calc-ensure-consistent-units
+ (math-check-unit-consistency expr units))
(math-put-default-units units)
(let ((unew (math-units-in-expr-p units t))
(std (and (eq (car-safe units) 'var)
@@ -560,7 +565,7 @@
(defun calc-extract-units ()
(interactive)
(calc-slow-wrapper
- (calc-enter-result 1 "rmun" (math-simplify-units
+ (calc-enter-result 1 "exun" (math-simplify-units
(math-extract-units (calc-top-n 1))))))
;; The variables calc-num-units and calc-den-units are local to
@@ -914,6 +919,17 @@
(math-single-units-in-expr-p (nth 1 expr))))
(t 'wrong)))
+(defun math-consistent-units-p (expr1 expr2)
+ "Non-nil if EXPR1 and EXPR2 have consistent units."
+ (math-numberp (math-get-units (list '/ expr1 expr2))))
+
+(defun math-check-unit-consistency (expr units)
+ "Give an error if EXPR and UNITS do not have consistent units."
+ (unless (math-consistent-units-p expr units)
+ (error "New units (%s) are inconsistent with current units (%s)"
+ (math-format-value units)
+ (math-format-value (math-get-units expr)))))
+
(defun math-check-unit-name (v)
(and (eq (car-safe v) 'var)
(or (assq (nth 1 v) (or math-units-table (math-build-units-table)))
=== modified file 'lisp/calc/calc.el'
--- a/lisp/calc/calc.el 2012-04-22 13:58:00 +0000
+++ b/lisp/calc/calc.el 2012-05-19 03:00:48 +0000
@@ -418,6 +418,13 @@
:group 'calc
:type 'boolean)
+(defcustom calc-ensure-consistent-units
+ nil
+ "If non-nil, make sure new units are consistent with current units
+when converting units."
+ :group 'calc
+ :type 'boolean)
+
(defcustom calc-undo-length
100
"The number of undo steps that will be preserved when Calc is quit."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r108299: * calc/calc.el (calc-ensure-consistent-units): New variable.,
Jay Belanger <=