unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Complete temperature units in calc-convert-temperature
@ 2016-02-19 17:42 Mark Oteiza
  2016-02-19 23:41 ` zv
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Oteiza @ 2016-02-19 17:42 UTC (permalink / raw)
  To: emacs-devel

---
IIUC, user defined units cannot be temperatures, so deriving
a collection of temperature units from math-standard-units as opposed to
the generated math-units-tables should be fine.

diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index 07d9ac9..525e3e2 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -565,7 +565,12 @@ If COMP or STD is non-nil, put that in the units table instead."
 (defun calc-convert-temperature (&optional old-units new-units)
   (interactive)
   (calc-slow-wrapper
-   (let ((expr (calc-top-n 1))
+   (let ((tempunits (delq nil
+                          (mapcar
+                           (lambda (x)
+                             (if (nth 3 x) (car x)))
+                           math-standard-units)))
+         (expr (calc-top-n 1))
 	 (uold nil)
 	 (uoldname nil)
 	 unew
@@ -580,15 +585,16 @@ If COMP or STD is non-nil, put that in the units table instead."
 						     (car units)))))
 			    (error "Not a pure temperature expression"))
 			(math-read-expr
-			 (setq uoldname (read-string
-					 "Old temperature units: ")))))))
+			 (setq uoldname (completing-read
+					 "Old temperature units: "
+                                         tempunits)))))))
      (when (eq (car-safe uold) 'error)
        (error "Bad format in units expression: %s" (nth 2 uold)))
      (or (math-units-in-expr-p expr nil)
 	 (setq expr (math-mul expr uold)))
      (setq defunits (math-get-default-units expr))
      (setq unew (or new-units
-                    (read-string
+                    (completing-read
                      (concat
                       (if uoldname
                           (concat "Old temperature units: "
@@ -599,7 +605,8 @@ If COMP or STD is non-nil, put that in the units table instead."
                           (concat " (default "
                                   defunits
                                   "): ")
-                        ": ")))))
+                        ": "))
+                     tempunits)))
      (setq unew (math-read-expr (if (string= unew "") defunits unew)))
      (when (eq (car-safe unew) 'error)
        (error "Bad format in units expression: %s" (nth 2 unew)))



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Complete temperature units in calc-convert-temperature
  2016-02-19 17:42 [PATCH] Complete temperature units in calc-convert-temperature Mark Oteiza
@ 2016-02-19 23:41 ` zv
  0 siblings, 0 replies; 2+ messages in thread
From: zv @ 2016-02-19 23:41 UTC (permalink / raw)
  To: emacs-devel

On 02/19/2016 09:42 AM, Mark Oteiza wrote:
> ---
> IIUC, user defined units cannot be temperatures, so deriving
> a collection of temperature units from math-standard-units as opposed to
> the generated math-units-tables should be fine.
> 
> diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
> index 07d9ac9..525e3e2 100644
> --- a/lisp/calc/calc-units.el
> +++ b/lisp/calc/calc-units.el
> @@ -565,7 +565,12 @@ If COMP or STD is non-nil, put that in the units table instead."
>  (defun calc-convert-temperature (&optional old-units new-units)
>    (interactive)
>    (calc-slow-wrapper
> -   (let ((expr (calc-top-n 1))
> +   (let ((tempunits (delq nil
> +                          (mapcar
> +                           (lambda (x)
> +                             (if (nth 3 x) (car x)))
> +                           math-standard-units)))
> +         (expr (calc-top-n 1))
>  	 (uold nil)
>  	 (uoldname nil)
>  	 unew
> @@ -580,15 +585,16 @@ If COMP or STD is non-nil, put that in the units table instead."
>  						     (car units)))))
>  			    (error "Not a pure temperature expression"))
>  			(math-read-expr
> -			 (setq uoldname (read-string
> -					 "Old temperature units: ")))))))
> +			 (setq uoldname (completing-read
> +					 "Old temperature units: "
> +                                         tempunits)))))))
>       (when (eq (car-safe uold) 'error)
>         (error "Bad format in units expression: %s" (nth 2 uold)))
>       (or (math-units-in-expr-p expr nil)
>  	 (setq expr (math-mul expr uold)))
>       (setq defunits (math-get-default-units expr))
>       (setq unew (or new-units
> -                    (read-string
> +                    (completing-read
>                       (concat
>                        (if uoldname
>                            (concat "Old temperature units: "
> @@ -599,7 +605,8 @@ If COMP or STD is non-nil, put that in the units table instead."
>                            (concat " (default "
>                                    defunits
>                                    "): ")
> -                        ": ")))))
> +                        ": "))
> +                     tempunits)))
>       (setq unew (math-read-expr (if (string= unew "") defunits unew)))
>       (when (eq (car-safe unew) 'error)
>         (error "Bad format in units expression: %s" (nth 2 unew)))
> 
> 
Synchronicity! Too weird, I was just working on a patch for this.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-19 23:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 17:42 [PATCH] Complete temperature units in calc-convert-temperature Mark Oteiza
2016-02-19 23:41 ` zv

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).