From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.bugs Subject: bug#19401: 25.0.50; metar.el (metar-convert-temperature) wrong type argument stringp nil Date: Fri, 19 Feb 2016 19:04:37 +0100 Message-ID: <85h9h4shje.fsf@iznogoud.viz> References: <87oar2x9is.fsf@udel.edu> <87egrx1162.fsf@web.de> <87egrxqaeb.fsf@udel.edu> <87a92k28rk.fsf@web.de> <85mw5m91um.fsf@iznogoud.viz> <871tmyftra.fsf@web.de> <85387ezbi6.fsf@iznogoud.viz> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1455905232 21820 80.91.229.3 (19 Feb 2016 18:07:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Feb 2016 18:07:12 +0000 (UTC) Cc: Mark Oteiza , 19401@debbugs.gnu.org To: Mario Lang Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 19 19:07:01 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aWpSG-0008Eq-4c for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Feb 2016 19:07:00 +0100 Original-Received: from localhost ([::1]:54367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWpSE-0001hj-RA for geb-bug-gnu-emacs@m.gmane.org; Fri, 19 Feb 2016 13:06:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWpQR-0000XB-Go for bug-gnu-emacs@gnu.org; Fri, 19 Feb 2016 13:05:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWpQM-0000UW-Pp for bug-gnu-emacs@gnu.org; Fri, 19 Feb 2016 13:05:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37127) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWpQM-0000UQ-Ld for bug-gnu-emacs@gnu.org; Fri, 19 Feb 2016 13:05:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aWpQM-0006dk-FM for bug-gnu-emacs@gnu.org; Fri, 19 Feb 2016 13:05:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Wolfgang Jenkner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 19 Feb 2016 18:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19401 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19401-submit@debbugs.gnu.org id=B19401.145590508425495 (code B ref 19401); Fri, 19 Feb 2016 18:05:02 +0000 Original-Received: (at 19401) by debbugs.gnu.org; 19 Feb 2016 18:04:44 +0000 Original-Received: from localhost ([127.0.0.1]:34254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWpQ4-0006d8-62 for submit@debbugs.gnu.org; Fri, 19 Feb 2016 13:04:44 -0500 Original-Received: from vie01a-dmta-at52-3.mx.upcmail.net ([62.179.121.144]:49948) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWpQ2-0006d0-MA for 19401@debbugs.gnu.org; Fri, 19 Feb 2016 13:04:43 -0500 Original-Received: from [172.31.216.41] (helo=vie01a-pemc-psmtp-at50) by vie01a-dmta-at52.mx.upcmail.net with esmtp (Exim 4.72) (envelope-from ) id 1aWpPz-0003I0-Ns for 19401@debbugs.gnu.org; Fri, 19 Feb 2016 19:04:39 +0100 Original-Received: from iznogoud.viz ([91.119.106.15]) by vie01a-pemc-psmtp-at50 with SMTP @ mailcloud.upcmail.net id LJ4e1s0030KxPDX0BJ4ex8; Fri, 19 Feb 2016 19:04:39 +0100 X-SourceIP: 91.119.106.15 X-CNFS-Analysis: v=2.1 cv=HobaYRnS c=1 sm=2 tr=0 a=2tOQdSoD+ooBew54+yCrJA==:117 a=2tOQdSoD+ooBew54+yCrJA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=jFJIQSaiL_oA:10 a=Gp3L3cVfUUPMnCBeLIIA:9 a=hTMqG6psAAAA:8 a=KuIW7ZMcve-9w3uxvxIA:9 a=kwPVFRpkBQdPyu1Q:21 a=xV_AMxlZFPjUsPQ0:21 Original-Received: from wolfgang by iznogoud.viz with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1aWpPy-0000vf-0P; Fri, 19 Feb 2016 19:04:38 +0100 In-Reply-To: <85387ezbi6.fsf@iznogoud.viz> (Wolfgang Jenkner's message of "Tue, 13 Jan 2015 21:11:45 +0100") User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (berkeley-unix) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:113305 Archived-At: --=-=-= Content-Type: text/plain On Tue, Jan 13 2015, Wolfgang Jenkner wrote: > However, it's up to the author to decide if he likes this approach at > all. Mario, Ping :-) Do you mind if I push yesteryear's patch to elpa? If you want to review it, I'll wait for your approval, of course. Otherwise, due to popular demand, I'd like to push it in a week or so. For easier reference, I've also attached it below. I also proposed a second patch as a work-around for a calc glitch, however that bug has been fixed in the last emacs release, so I think it can be omitted. Wolfgang --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-metar-Fix-the-case-where-the-metar-record-contains-M.patch Content-Description: metar patch >From bc778d9ac011e1f27cfc85055a8575f39f912d9b Mon Sep 17 00:00:00 2001 From: Wolfgang Jenkner Date: Sat, 3 Jan 2015 00:34:33 +0100 Subject: [PATCH 1/2] [metar] Fix the case where the metar record contains M01 (bug#19401). * packages/metar/metar.el (metar-convert-unit): New optional argument. (metar-convert-temperature): Use it to rewrite this function in terms of metar-convert-unit. Pass t as last argument to the underlying calc conversion functions so that they return only the number, not the unit, thereby fixing the bug in question. --- packages/metar/metar.el | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/metar/metar.el b/packages/metar/metar.el index 7b78f07..9575313 100644 --- a/packages/metar/metar.el +++ b/packages/metar/metar.el @@ -239,45 +239,43 @@ If no match if found, nil is returned." (when station-code (cons station-code (round best-distance)))))) -(defun metar-convert-unit (value new-unit) +(defun metar-convert-unit (value new-unit &optional convert-units-function) "Convert VALUE to NEW-UNIT. VALUE is a string with the value followed by the unit, like \"5 knot\" -and NEW-UNIT should be a unit name like \"kph\" or similar." +and NEW-UNIT should be a unit name like \"kph\" or similar. +CONVERT-UNITS-FUNCTION designates the function actually doing the conversion. +It must have the signature of `math-convert-units', which is the default." (cl-check-type value string) - (cl-check-type new-unit (or string symbol)) - (cl-multiple-value-bind (value unit) - (split-string - (math-format-value - (math-convert-units (math-simplify (math-read-expr value)) - (math-read-expr - (cl-etypecase new-unit - (string new-unit) - (symbol (symbol-name new-unit)))))) - " ") - (cons (string-to-number value) (intern unit)))) + (unless (symbolp new-unit) + (setq new-unit (intern new-unit))) + (let ((expr (math-simplify (math-read-expr value)))) + (cl-assert (or (math-zerop expr) + (not (memq (math-single-units-in-expr-p expr) '(nil wrong)))) + nil + "Metar: Not exactly one unit in expression: %S" expr) + (let ((res (math-simplify-units + (funcall (or convert-units-function 'math-convert-units) + expr + (math-build-var-name new-unit) + t)))) + (cl-assert (math-realp res) nil + "Metar: Not a Calc real number: %S" res) + (cons (string-to-number (math-format-value (if (integerp res) + res + (math-float res)))) + new-unit)))) (defun metar-convert-temperature (string &optional unit) - (let* ((value (concat (if (= (aref string 0) ?M) - (concat "-" (substring string 1)) - string) - "degC")) - (expr (math-read-expr value)) - (old-unit (math-single-units-in-expr-p expr)) - (new-unit (or unit (cdr (assq 'temperature metar-units))))) - (if old-unit - (cl-multiple-value-bind (value unit) - (split-string - (math-format-value - (math-simplify-units - (math-convert-temperature - expr - (list 'var - (car old-unit) - (intern (concat "var-" (symbol-name (car old-unit))))) - (math-read-expr (cl-etypecase new-unit - (string new-unit) - (symbol (symbol-name new-unit))))))) " ") - (cons (string-to-number value) (intern unit)))))) + (metar-convert-unit (concat (if (= (aref string 0) ?M) + (concat "-" (substring string 1)) + string) + "degC") + (or unit (cdr (assq 'temperature metar-units))) + (lambda (expr new-unit-var pure) + (math-convert-temperature expr + (math-build-var-name 'degC) + new-unit-var + pure)))) (defcustom metar-url "http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT" -- 2.7.0 --=-=-=--