summaryrefslogtreecommitdiff
path: root/lisp/calculator.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2013-08-29 15:55:58 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2013-08-29 15:55:58 -0400
commit40f7e0e853bf21003fdffeac35e47616f393055d (patch)
tree25770d0dcff8956a77b577d5467caffe37fb0e0f /lisp/calculator.el
parent7763d67c87ae050d4e7cc28f1e0c4b14df037d2e (diff)
downloademacs-40f7e0e853bf21003fdffeac35e47616f393055d.tar.gz
Misc changes to reduce use of `(lambda...); and other cleanups.
* lisp/cus-edit.el: Use lexical-binding. (customize-push-and-save, customize-apropos) (custom-buffer-create-internal): Use closures. * lisp/progmodes/bat-mode.el (bat-mode-syntax-table): "..." are strings. * lisp/progmodes/ada-xref.el: Use setq. * lisp/net/tramp.el (with-tramp-progress-reporter): Avoid setq. * lisp/dframe.el: Use lexical-binding. (dframe-frame-mode): Fix calling convention for hooks. Use a closure. * lisp/speedbar.el (speedbar-frame-mode): Adjust call accordingly. * lisp/descr-text.el: Use lexical-binding. (describe-text-widget, describe-text-sexp, describe-property-list): Use closures. * lisp/comint.el (comint-history-isearch-push-state): Use a closure. * lisp/calculator.el: Use lexical-binding. (calculator-number-to-string): Make it work with lexical-binding. (calculator-funcall): Same and use cl-letf.
Diffstat (limited to 'lisp/calculator.el')
-rw-r--r--lisp/calculator.el48
1 files changed, 22 insertions, 26 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el
index c9a73054712..c988b7e1088 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -1,4 +1,4 @@
-;;; calculator.el --- a [not so] simple calculator for Emacs
+;;; calculator.el --- a [not so] simple calculator for Emacs -*- lexical-binding: t -*-
;; Copyright (C) 1998, 2000-2013 Free Software Foundation, Inc.
@@ -131,8 +131,8 @@ The displayer is a symbol, a string or an expression. A symbol should
be the name of a one-argument function, a string is used with a single
argument and an expression will be evaluated with the variable `num'
bound to whatever should be displayed. If it is a function symbol, it
-should be able to handle special symbol arguments, currently 'left and
-'right which will be sent by special keys to modify display parameters
+should be able to handle special symbol arguments, currently `left' and
+`right' which will be sent by special keys to modify display parameters
associated with the displayer function (for example to change the number
of digits displayed).
@@ -241,6 +241,8 @@ Examples:
;;;=====================================================================
;;; Code:
+(eval-when-compile (require 'cl-lib))
+
;;;---------------------------------------------------------------------
;;; Variables
@@ -1124,11 +1126,10 @@ the 'left or 'right when one of the standard modes is used."
(format calculator-displayer num))
((symbolp calculator-displayer)
(funcall calculator-displayer num))
- ((and (consp calculator-displayer)
- (eq 'std (car calculator-displayer)))
+ ((eq 'std (car-safe calculator-displayer))
(calculator-standard-displayer num (cadr calculator-displayer)))
((listp calculator-displayer)
- (eval calculator-displayer))
+ (eval calculator-displayer `((num. ,num))))
(t (prin1-to-string num t))))
;; operators are printed here
(t (prin1-to-string (nth 1 num) t))))
@@ -1273,29 +1274,24 @@ arguments."
;; smaller than calculator-epsilon (1e-15). I don't think this is
;; necessary now.
(if (symbolp f)
- (cond ((and X Y) (funcall f X Y))
- (X (funcall f X))
- (t (funcall f)))
+ (cond ((and X Y) (funcall f X Y))
+ (X (funcall f X))
+ (t (funcall f)))
;; f is an expression
- (let* ((__f__ f) ; so we can get this value below...
- (TX (calculator-truncate X))
+ (let* ((TX (calculator-truncate X))
(TY (and Y (calculator-truncate Y)))
(DX (if calculator-deg (/ (* X pi) 180) X))
- (L calculator-saved-list)
- (Fbound (fboundp 'F))
- (Fsave (and Fbound (symbol-function 'F)))
- (Dbound (fboundp 'D))
- (Dsave (and Dbound (symbol-function 'D))))
- ;; a shortened version of flet
- (fset 'F (function
- (lambda (&optional x y)
- (calculator-funcall __f__ x y))))
- (fset 'D (function
- (lambda (x)
- (if calculator-deg (/ (* x 180) float-pi) x))))
- (unwind-protect (eval f)
- (if Fbound (fset 'F Fsave) (fmakunbound 'F))
- (if Dbound (fset 'D Dsave) (fmakunbound 'D)))))
+ (L calculator-saved-list))
+ (cl-letf (((symbol-function 'F)
+ (lambda (&optional x y) (calculator-funcall f x y)))
+ ((symbol-function 'D)
+ (lambda (x) (if calculator-deg (/ (* x 180) float-pi) x))))
+ (eval f `((X . ,X)
+ (Y . ,X)
+ (TX . ,TX)
+ (TY . ,TY)
+ (DX . ,DX)
+ (L . ,L))))))
(error 0)))
;;;---------------------------------------------------------------------