From cc43334a3e3dd1937a9f43ebbdaa89297fc34a1c Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 23 Jun 2014 01:14:23 -0400 Subject: [PATCH] * calculator.el (calculator-standard-displayer): Fix bug in use of `calculator-groupize-number'. (calculator-funcall): Fix broken `cl-flet' use by moving it into the `eval' code, so it works in v24.3.1 too. (calculator-last-input): Comment to clarify purpose. Also add back a ChangeLog blurb for previous commit 2014-06-15T04:52:34Z!eli@barzilay.org. --- lisp/ChangeLog | 50 ++++++++++++++++++++++++++++++++++++++++++++++ lisp/calculator.el | 25 +++++++++++++---------- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 676635b0db..c3f74d8499 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2014-06-23 Eli Barzilay + + * calculator.el (calculator-standard-displayer): Fix bug in use of + `calculator-groupize-number'. + (calculator-funcall): Fix broken `cl-flet' use by moving it into the + `eval' code, so it works in v24.3.1 too. + (calculator-last-input): Comment to clarify purpose. + 2014-06-22 Mario Lang * textmodes/rst.el (rst-comment-region): From from -> from. @@ -194,6 +202,48 @@ rlogin is anymore. (dun-help): Bump version number; update contact info. +2014-06-15 Eli Barzilay + + * calculator.el (calculator-prompt, calculator-remove-zeros) + (calculator-mode-hook, calculator-operators, calculator-stack) + (calculator-mode): Tweak docstring. + (calculator-user-operators): Tweak docstring, fix a bug in the last + example. + (calculator-displayer): `std' case has an optional boolean. + (calculator-displayers): Use the new boolean to group in decimal mode. + (calculator-mode-map, calculator, calculator-message) + (calculator-op-arity, calculator-add-operators) + (calculator-string-to-number, calculator-displayer-prev) + (calculator-displayer-next, calculator-remove-zeros) + (calculator-eng-display, calculator-number-to-string) + (calculator-update-display, calculator-last-input) + (calculator-clear-fragile, calculator-digit, calculator-decimal) + (calculator-exp, calculator-saved-move, calculator-clear) + (calculator-copy, calculator-put-value, calculator-help) + (calculator-expt, calculator-truncate): Minor code improvements. + (calculator-need-3-lines): New function pulling out code from + `calculator'. + (calculator-get-display): Renamed from `calculator-get-prompt', and + improved. + (calculator-push-curnum): Renamed from `calculator-curnum-value', and + extended for all uses of it. All callers changed. + (calculator-groupize-number): New utility for splitting a number into + groups. + (calculator-standard-displayer): Improve code, new optional argument to + use comma-split groups, make second argument optional too to use with + 'left/'right inputs. All callers changed. + (calculator-reduce-stack-once): New utility, doing the meat of what + `calculator-reduce-stack' used to do, much improved (mostly using + `pcase' for conciseness and clarity). + (calculator-reduce-stack): Now doing just the reduction loop using + `calculator-reduce-stack-once'. + (calculator-funcall): Improved code, make it work in v24.3.1 too. + (calculator-last-input): Improved code, remove some old cruft. + (calculator-quit): Kill `calculator-buffer' in electric mode too. + (calculator-integer-p): Removed. + (calculator-fact): Improved code, make it work on non-integer values + too (using truncated numbers). + 2014-06-15 Michael Albinus Sync with Tramp 2.2.10. diff --git a/lisp/calculator.el b/lisp/calculator.el index 52dc8c5366..9ffa6b1a64 100644 --- a/lisp/calculator.el +++ b/lisp/calculator.el @@ -1019,8 +1019,9 @@ number of digits displayed (`calculator-number-digits')." (s (calculator-remove-zeros (format s num))) (s (if (or (not group-p) (string-match-p "[eE]" s)) s (replace-regexp-in-string - "\\([0-9]+\\)\\(?:\\.\\|$\\)" - (lambda (s) (calculator-groupize-number s 3 ",")) + "\\([0-9]+\\)\\(?:\\..*\\|$\\)" + (lambda (_) (calculator-groupize-number + (match-string 1 s) 3 ",")) s nil nil 1)))) s))) @@ -1197,12 +1198,13 @@ arguments." (let ((TX (and X (calculator-truncate X))) (TY (and Y (calculator-truncate Y))) (DX (if (and X calculator-deg) (/ (* X pi) 180) X)) - (L calculator-saved-list)) - (cl-flet ((F (&optional x y) (calculator-funcall f x y)) - (D (x) (if calculator-deg (/ (* x 180) float-pi) x))) - (eval `(let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L)) - ,f) - t))))) + (L calculator-saved-list) + (fF `(calculator-funcall ',f x y)) + (fD `(if calculator-deg (/ (* x 180) float-pi) x))) + (eval `(cl-flet ((F (&optional x y) ,fF) (D (x) ,fD)) + (let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L)) + ,f)) + t)))) ;;;--------------------------------------------------------------------- ;;; Input interaction @@ -1213,9 +1215,12 @@ Use KEYS if given, otherwise use `this-command-keys'." (let ((inp (or keys (this-command-keys)))) (if (or (stringp inp) (not (arrayp inp))) inp - ;; translates kp-x to x and [tries to] create a string to lookup + ;; Translates kp-x to x and [tries to] create a string to lookup ;; operators; assume all symbols are translatable via - ;; `function-key-map' or with an 'ascii-character property + ;; `function-key-map' or with an 'ascii-character property. This + ;; is needed because we have key bindings for kp-* (which might be + ;; the wrong thing to do) so they don't get translated in + ;; `this-command-keys'. (concat (mapcar (lambda (k) (if (numberp k) k (or (get k 'ascii-character) (error "??bad key??")))) -- 2.20.1