aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Barzilay2015-11-22 22:11:15 -0500
committerEli Barzilay2015-11-29 12:49:06 -0500
commitfb9ed79c396ed6040a0def1a6da93809a31b6ebf (patch)
treeb8d3fa27af7cdb6fe7401c2c3b7ca281dd01c225
parentf4ded42cf84ba349a7187d0f27ed8a9025b9b54c (diff)
downloademacs-fb9ed79c396ed6040a0def1a6da93809a31b6ebf.tar.gz
emacs-fb9ed79c396ed6040a0def1a6da93809a31b6ebf.zip
* lisp/calculator.el: General improvements
Use things like `when', `unless', and `push'. Improve `calculator-last-input' so it doesn't barf when hitting `F1' in non-electric mode.
-rw-r--r--lisp/calculator.el209
1 files changed, 100 insertions, 109 deletions
diff --git a/lisp/calculator.el b/lisp/calculator.el
index 80b7c070f1f..7ff1a337d58 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -65,7 +65,7 @@ Note that this requires easymenu. Must be set before loading."
65 :group 'calculator) 65 :group 'calculator)
66 66
67(defcustom calculator-unary-style 'postfix 67(defcustom calculator-unary-style 'postfix
68 "Value is either 'prefix or 'postfix. 68 "Value is either `prefix' or `postfix'.
69This determines the default behavior of unary operators." 69This determines the default behavior of unary operators."
70 :type '(choice (const prefix) (const postfix)) 70 :type '(choice (const prefix) (const postfix))
71 :group 'calculator) 71 :group 'calculator)
@@ -195,9 +195,9 @@ For example, use this to define the golden ratio number:
195before you load calculator." 195before you load calculator."
196 :type '(repeat (cons character number)) 196 :type '(repeat (cons character number))
197 :set (lambda (_ val) 197 :set (lambda (_ val)
198 (and (boundp 'calculator-registers) 198 (when (boundp 'calculator-registers)
199 (setq calculator-registers 199 (setq calculator-registers
200 (append val calculator-registers))) 200 (append val calculator-registers)))
201 (setq calculator-user-registers val)) 201 (setq calculator-user-registers val))
202 :group 'calculator) 202 :group 'calculator)
203 203
@@ -221,10 +221,10 @@ Examples:
221 (\"tF\" mt-to-ft (/ X 0.3048) 1) 221 (\"tF\" mt-to-ft (/ X 0.3048) 1)
222 (\"tM\" ft-to-mt (* X 0.3048) 1))) 222 (\"tM\" ft-to-mt (* X 0.3048) 1)))
223 223
224* Using a function-like form is very simple: use `X' for the argument 224* Using a function-like form is simple: use `X' for the argument (`Y'
225 (`Y' for the second in case of a binary operator), `TX' is a truncated 225 for a second one in case of a binary operator), `TX' is a truncated
226 version of `X' and `F' for a recursive call. Here is a [very 226 version of `X' and `F' for a recursive call. Here is a [very
227 inefficient] Fibonacci number calculation: 227 inefficient] Fibonacci number operator:
228 228
229 (add-to-list \\='calculator-user-operators 229 (add-to-list \\='calculator-user-operators
230 \\='(\"F\" fib 230 \\='(\"F\" fib
@@ -290,7 +290,8 @@ user-defined operators, use `calculator-user-operators' instead.")
290(defvar calculator-operators nil 290(defvar calculator-operators nil
291 "The calculator operators, each a list with: 291 "The calculator operators, each a list with:
292 292
2931. The key that is bound to for this operation (usually a string); 2931. The key that is bound to for this operation, a string that is
294 used with `kbd';
294 295
2952. The displayed symbol for this function; 2962. The displayed symbol for this function;
296 297
@@ -332,10 +333,10 @@ documentation for an example.")
332 "A table to convert input characters to corresponding radix symbols.") 333 "A table to convert input characters to corresponding radix symbols.")
333 334
334(defvar calculator-output-radix nil 335(defvar calculator-output-radix nil
335 "The mode for display, one of: nil (decimal), 'bin, 'oct or 'hex.") 336 "The mode for display, one of: nil (decimal), `bin', `oct' or `hex'.")
336 337
337(defvar calculator-input-radix nil 338(defvar calculator-input-radix nil
338 "The mode for input, one of: nil (decimal), 'bin, 'oct or 'hex.") 339 "The mode for input, one of: nil (decimal), `bin', `oct' or `hex'.")
339 340
340(defvar calculator-deg nil 341(defvar calculator-deg nil
341 "Non-nil if trig functions operate on degrees instead of radians.") 342 "Non-nil if trig functions operate on degrees instead of radians.")
@@ -436,7 +437,8 @@ Used for repeating operations in calculator-repR/L.")
436 (define-key map [escape] 'calculator-quit)) 437 (define-key map [escape] 'calculator-quit))
437 (define-key map [?\e ?\e ?\e] 'calculator-quit)) 438 (define-key map [?\e ?\e ?\e] 'calculator-quit))
438 ;; make C-h work in text-mode 439 ;; make C-h work in text-mode
439 (or window-system (define-key map [?\C-h] 'calculator-backspace)) 440 (unless window-system
441 (define-key map [?\C-h] 'calculator-backspace))
440 ;; set up a menu 442 ;; set up a menu
441 (when (and calculator-use-menu (not (boundp 'calculator-menu))) 443 (when (and calculator-use-menu (not (boundp 'calculator-menu)))
442 (let ((radix-selectors 444 (let ((radix-selectors
@@ -530,9 +532,9 @@ Used for repeating operations in calculator-repR/L.")
530 ("Modes" 532 ("Modes"
531 ["Radians" 533 ["Radians"
532 (progn 534 (progn
533 (and (or calculator-input-radix calculator-output-radix) 535 (when (or calculator-input-radix calculator-output-radix)
534 (calculator-radix-mode "D")) 536 (calculator-radix-mode "D"))
535 (and calculator-deg (calculator-dec/deg-mode))) 537 (when calculator-deg (calculator-dec/deg-mode)))
536 :keys "D" 538 :keys "D"
537 :style radio 539 :style radio
538 :selected (not (or calculator-input-radix 540 :selected (not (or calculator-input-radix
@@ -540,9 +542,9 @@ Used for repeating operations in calculator-repR/L.")
540 calculator-deg))] 542 calculator-deg))]
541 ["Degrees" 543 ["Degrees"
542 (progn 544 (progn
543 (and (or calculator-input-radix calculator-output-radix) 545 (when (or calculator-input-radix calculator-output-radix)
544 (calculator-radix-mode "D")) 546 (calculator-radix-mode "D"))
545 (or calculator-deg (calculator-dec/deg-mode))) 547 (unless calculator-deg (calculator-dec/deg-mode)))
546 :keys "D" 548 :keys "D"
547 :style radio 549 :style radio
548 :selected (and calculator-deg 550 :selected (and calculator-deg
@@ -696,9 +698,9 @@ See the documentation for `calculator-mode' for more information."
696 (select-window (minibuffer-window)) 698 (select-window (minibuffer-window))
697 (calculator-reset) 699 (calculator-reset)
698 (calculator-update-display) 700 (calculator-update-display)
699 (setq old-l-map (current-local-map)) 701 (setq old-l-map (current-local-map)
700 (setq old-g-map (current-global-map)) 702 old-g-map (current-global-map)
701 (setq calculator-saved-global-map (current-global-map)) 703 calculator-saved-global-map (current-global-map))
702 (use-local-map nil) 704 (use-local-map nil)
703 (use-global-map calculator-mode-map) 705 (use-global-map calculator-mode-map)
704 (run-hooks 'calculator-mode-hook) 706 (run-hooks 'calculator-mode-hook)
@@ -781,23 +783,21 @@ Adds MORE-OPS to `calculator-operator', called initially to handle
781`calculator-initial-operators' and `calculator-user-operators'." 783`calculator-initial-operators' and `calculator-user-operators'."
782 (let ((added-ops nil)) 784 (let ((added-ops nil))
783 (while more-ops 785 (while more-ops
784 (or (eq (caar more-ops) 'nobind) 786 (unless (eq (caar more-ops) 'nobind)
785 (let ((i -1) (key (caar more-ops))) 787 (let ((i -1) (key (caar more-ops)))
786 ;; make sure the key is undefined, so it's easy to define 788 ;; make sure the key is undefined, so it's easy to define
787 ;; prefix keys 789 ;; prefix keys
788 (while (< (setq i (1+ i)) (length key)) 790 (while (< (setq i (1+ i)) (length key))
789 (or (keymapp 791 (unless (keymapp (lookup-key calculator-mode-map
790 (lookup-key calculator-mode-map 792 (substring key 0 (1+ i))))
791 (substring key 0 (1+ i)))) 793 (define-key calculator-mode-map (substring key 0 (1+ i))
792 (progn 794 nil)
793 (define-key 795 (setq i (length key))))
794 calculator-mode-map (substring key 0 (1+ i)) nil) 796 (define-key calculator-mode-map key 'calculator-op)))
795 (setq i (length key))))) 797 (push (if (eq (caar more-ops) 'nobind)
796 (define-key calculator-mode-map key 'calculator-op))) 798 (cdar more-ops)
797 (setq added-ops (cons (if (eq (caar more-ops) 'nobind) 799 (car more-ops))
798 (cdar more-ops) 800 added-ops)
799 (car more-ops))
800 added-ops))
801 (setq more-ops (cdr more-ops))) 801 (setq more-ops (cdr more-ops)))
802 ;; added-ops come first, but in correct order 802 ;; added-ops come first, but in correct order
803 (setq calculator-operators 803 (setq calculator-operators
@@ -808,11 +808,11 @@ Adds MORE-OPS to `calculator-operator', called initially to handle
808 808
809(defun calculator-reset () 809(defun calculator-reset ()
810 "Reset calculator variables." 810 "Reset calculator variables."
811 (or calculator-restart-other-mode 811 (unless calculator-restart-other-mode
812 (setq calculator-stack nil 812 (setq calculator-stack nil
813 calculator-curnum nil 813 calculator-curnum nil
814 calculator-stack-display nil 814 calculator-stack-display nil
815 calculator-display-fragile nil)) 815 calculator-display-fragile nil))
816 (setq calculator-restart-other-mode nil) 816 (setq calculator-restart-other-mode nil)
817 (calculator-update-display)) 817 (calculator-update-display))
818 818
@@ -911,9 +911,7 @@ If radix output mode is active, toggle digit grouping."
911 (if (and new-disp (memq new-disp calculator-displayers)) 911 (if (and new-disp (memq new-disp calculator-displayers))
912 (let ((tmp nil)) 912 (let ((tmp nil))
913 (while (not (eq (car calculator-displayers) new-disp)) 913 (while (not (eq (car calculator-displayers) new-disp))
914 (setq tmp (cons (car calculator-displayers) tmp)) 914 (push (pop calculator-displayers) tmp))
915 (setq calculator-displayers
916 (cdr calculator-displayers)))
917 (setq calculator-displayers 915 (setq calculator-displayers
918 (nconc calculator-displayers (nreverse tmp)))) 916 (nconc calculator-displayers (nreverse tmp))))
919 (nconc (cdr calculator-displayers) 917 (nconc (cdr calculator-displayers)
@@ -938,11 +936,11 @@ If radix output mode is active, increase the grouping size."
938 (progn (setq calculator-radix-grouping-digits 936 (progn (setq calculator-radix-grouping-digits
939 (1+ calculator-radix-grouping-digits)) 937 (1+ calculator-radix-grouping-digits))
940 (calculator-enter)) 938 (calculator-enter))
941 (and (car calculator-displayers) 939 (when (car calculator-displayers)
942 (let ((disp (caar calculator-displayers))) 940 (let ((disp (caar calculator-displayers)))
943 (cond ((symbolp disp) (funcall disp 'left)) 941 (cond ((symbolp disp) (funcall disp 'left))
944 ((and (consp disp) (eq 'std (car disp))) 942 ((and (consp disp) (eq 'std (car disp)))
945 (calculator-standard-displayer 'left))))))) 943 (calculator-standard-displayer 'left)))))))
946 944
947(defun calculator-displayer-next () 945(defun calculator-displayer-next ()
948 "Send the current displayer function a `right' argument. 946 "Send the current displayer function a `right' argument.
@@ -954,11 +952,11 @@ If radix output mode is active, decrease the grouping size."
954 (progn (setq calculator-radix-grouping-digits 952 (progn (setq calculator-radix-grouping-digits
955 (max 2 (1- calculator-radix-grouping-digits))) 953 (max 2 (1- calculator-radix-grouping-digits)))
956 (calculator-enter)) 954 (calculator-enter))
957 (and (car calculator-displayers) 955 (when (car calculator-displayers)
958 (let ((disp (caar calculator-displayers))) 956 (let ((disp (caar calculator-displayers)))
959 (cond ((symbolp disp) (funcall disp 'right)) 957 (cond ((symbolp disp) (funcall disp 'right))
960 ((and (consp disp) (eq 'std (car disp))) 958 ((and (consp disp) (eq 'std (car disp)))
961 (calculator-standard-displayer 'right))))))) 959 (calculator-standard-displayer 'right)))))))
962 960
963(defun calculator-remove-zeros (numstr) 961(defun calculator-remove-zeros (numstr)
964 "Get a number string NUMSTR and remove unnecessary zeros. 962 "Get a number string NUMSTR and remove unnecessary zeros.
@@ -1003,10 +1001,10 @@ The special `left' and `right' symbols will make it change the current
1003number of digits displayed (`calculator-number-digits')." 1001number of digits displayed (`calculator-number-digits')."
1004 (if (symbolp num) 1002 (if (symbolp num)
1005 (cond ((eq num 'left) 1003 (cond ((eq num 'left)
1006 (and (> calculator-number-digits 0) 1004 (when (> calculator-number-digits 0)
1007 (setq calculator-number-digits 1005 (setq calculator-number-digits
1008 (1- calculator-number-digits)) 1006 (1- calculator-number-digits))
1009 (calculator-enter))) 1007 (calculator-enter)))
1010 ((eq num 'right) 1008 ((eq num 'right)
1011 (setq calculator-number-digits 1009 (setq calculator-number-digits
1012 (1+ calculator-number-digits)) 1010 (1+ calculator-number-digits))
@@ -1054,7 +1052,7 @@ the `left' or `right' when one of the standard modes is used."
1054 (while (< i 0) 1052 (while (< i 0)
1055 (setq num (/ num 1000.0)) (setq exp (+ exp 3)) 1053 (setq num (/ num 1000.0)) (setq exp (+ exp 3))
1056 (setq i (1+ i)))))) 1054 (setq i (1+ i))))))
1057 (or calculator-eng-tmp-show (setq calculator-eng-extra nil)) 1055 (unless calculator-eng-tmp-show (setq calculator-eng-extra nil))
1058 (let ((str (format (format "%%.%sf" calculator-number-digits) 1056 (let ((str (format (format "%%.%sf" calculator-number-digits)
1059 num))) 1057 num)))
1060 (concat (let ((calculator-remove-zeros 1058 (concat (let ((calculator-remove-zeros
@@ -1206,7 +1204,7 @@ arguments."
1206 (DX (if (and X calculator-deg) (degrees-to-radians X) X)) 1204 (DX (if (and X calculator-deg) (degrees-to-radians X) X))
1207 (L calculator-saved-list) 1205 (L calculator-saved-list)
1208 (fF `(calculator-funcall ',f x y)) 1206 (fF `(calculator-funcall ',f x y))
1209 (fD `(if calculator-deg (* radians-to-degrees x) x))) 1207 (fD `(if calculator-deg (radians-to-degrees x) x)))
1210 (eval `(cl-flet ((F (&optional x y) ,fF) (D (x) ,fD)) 1208 (eval `(cl-flet ((F (&optional x y) ,fF) (D (x) ,fD))
1211 (let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L)) 1209 (let ((X ,X) (Y ,Y) (DX ,DX) (TX ,TX) (TY ,TY) (L ',L))
1212 ,f)) 1210 ,f))
@@ -1216,19 +1214,20 @@ arguments."
1216;;; Input interaction 1214;;; Input interaction
1217 1215
1218(defun calculator-last-input (&optional keys) 1216(defun calculator-last-input (&optional keys)
1219 "Last char (or event or event sequence) that was read. 1217 "Return the last key sequence that was used to invoke this command, or
1220Use KEYS if given, otherwise use `this-command-keys'." 1218the input KEYS. Uses the `function-key-map' translate keypad numbers to
1221 (let ((inp (or keys (this-command-keys)))) 1219plain ones."
1222 (if (or (stringp inp) (not (arrayp inp))) 1220 (let* ((inp (or keys (this-command-keys)))
1221 (inp (or (and (arrayp inp) (not (stringp inp))
1222 (lookup-key function-key-map inp))
1223 inp)))
1224 (if (or (not inp) (stringp inp) (not (arrayp inp))
1225 (catch 'done ; any non-chars?
1226 (dotimes (i (length inp))
1227 (unless (characterp (aref inp i)) (throw 'done t)))
1228 nil))
1223 inp 1229 inp
1224 ;; Translates kp-x to x and [tries to] create a string to lookup 1230 (concat inp))))
1225 ;; operators; assume all symbols are translatable via
1226 ;; `function-key-map'. This is needed because we have key
1227 ;; bindings for kp-* (which might be the wrong thing to do) so
1228 ;; they don't get translated in `this-command-keys'.
1229 (concat (mapcar (lambda (k)
1230 (if (numberp k) k (error "??bad key?? (%S)" k)))
1231 (or (lookup-key function-key-map inp) inp))))))
1232 1231
1233(defun calculator-clear-fragile (&optional op) 1232(defun calculator-clear-fragile (&optional op)
1234 "Clear the fragile flag if it was set, then maybe reset all. 1233 "Clear the fragile flag if it was set, then maybe reset all.
@@ -1270,7 +1269,7 @@ OP is the operator (if any) that caused this call."
1270 (calculator-update-display))) 1269 (calculator-update-display)))
1271 1270
1272(defun calculator-exp () 1271(defun calculator-exp ()
1273 "Enter an `E' exponent character, or a digit in hex input mode." 1272 "Enter an exponent, or an \"E\" digit in hex input mode."
1274 (interactive) 1273 (interactive)
1275 (cond 1274 (cond
1276 (calculator-input-radix (calculator-digit)) 1275 (calculator-input-radix (calculator-digit))
@@ -1312,18 +1311,13 @@ Optional string argument KEYS will force using it as the keys entered."
1312 (throw 'op-error nil)) 1311 (throw 'op-error nil))
1313 (push op calculator-stack) 1312 (push op calculator-stack)
1314 (calculator-reduce-stack (calculator-op-prec op)) 1313 (calculator-reduce-stack (calculator-op-prec op))
1315 (and (= (length calculator-stack) 1) 1314 (when (and (= (length calculator-stack) 1)
1316 (numberp (car calculator-stack)) 1315 (numberp (car calculator-stack)))
1317 ;; the display is fragile if it contains only one number 1316 ;; the display is fragile if it contains only one number
1318 (setq calculator-display-fragile t) 1317 (setq calculator-display-fragile t)
1319 ;; add number to the saved-list 1318 (when calculator-add-saved ; add number to the saved-list
1320 calculator-add-saved 1319 (push (car calculator-stack)
1321 (if (= 0 calculator-saved-ptr) 1320 (nthcdr calculator-saved-ptr calculator-saved-list))))
1322 (setq calculator-saved-list
1323 (cons (car calculator-stack) calculator-saved-list))
1324 (let ((p (nthcdr (1- calculator-saved-ptr)
1325 calculator-saved-list)))
1326 (setcdr p (cons (car calculator-stack) (cdr p))))))
1327 (calculator-update-display)))) 1321 (calculator-update-display))))
1328 1322
1329(defun calculator-op-or-exp () 1323(defun calculator-op-or-exp ()
@@ -1346,8 +1340,8 @@ operators)."
1346 (interactive) 1340 (interactive)
1347 (calculator-push-curnum) 1341 (calculator-push-curnum)
1348 (if (or calculator-input-radix calculator-output-radix) 1342 (if (or calculator-input-radix calculator-output-radix)
1349 (progn (setq calculator-input-radix nil) 1343 (setq calculator-input-radix nil
1350 (setq calculator-output-radix nil)) 1344 calculator-output-radix nil)
1351 ;; already decimal -- toggle degrees mode 1345 ;; already decimal -- toggle degrees mode
1352 (setq calculator-deg (not calculator-deg))) 1346 (setq calculator-deg (not calculator-deg)))
1353 (calculator-update-display t)) 1347 (calculator-update-display t))
@@ -1393,8 +1387,8 @@ Optional string argument KEYS will force using it as the keys entered."
1393(defun calculator-clear-saved () 1387(defun calculator-clear-saved ()
1394 "Clear the list of saved values in `calculator-saved-list'." 1388 "Clear the list of saved values in `calculator-saved-list'."
1395 (interactive) 1389 (interactive)
1396 (setq calculator-saved-list nil) 1390 (setq calculator-saved-list nil
1397 (setq calculator-saved-ptr 0) 1391 calculator-saved-ptr 0)
1398 (calculator-update-display t)) 1392 (calculator-update-display t))
1399 1393
1400(defun calculator-saved-move (n) 1394(defun calculator-saved-move (n)
@@ -1503,8 +1497,7 @@ Optional string argument KEYS will force using it as the keys entered."
1503 (val (progn (calculator-enter) (car calculator-stack)))) 1497 (val (progn (calculator-enter) (car calculator-stack))))
1504 (if as 1498 (if as
1505 (setcdr as val) 1499 (setcdr as val)
1506 (setq calculator-registers 1500 (push (cons reg val) calculator-registers))
1507 (cons (cons reg val) calculator-registers)))
1508 (calculator-message "[%c] := %S" reg val))) 1501 (calculator-message "[%c] := %S" reg val)))
1509 1502
1510(defun calculator-put-value (val) 1503(defun calculator-put-value (val)
@@ -1525,16 +1518,14 @@ Used by `calculator-paste' and `get-register'."
1525 (calculator-put-value 1518 (calculator-put-value
1526 (let ((str (replace-regexp-in-string 1519 (let ((str (replace-regexp-in-string
1527 "^ *\\(.+[^ ]\\) *$" "\\1" (current-kill 0)))) 1520 "^ *\\(.+[^ ]\\) *$" "\\1" (current-kill 0))))
1528 (and (not calculator-input-radix) 1521 (when (and (not calculator-input-radix)
1529 calculator-paste-decimals 1522 calculator-paste-decimals
1530 (string-match "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?" 1523 (string-match
1531 str) 1524 "\\([0-9]+\\)\\(\\.[0-9]+\\)?\\(e[0-9]+\\)?"
1532 (or (match-string 1 str) 1525 str))
1533 (match-string 2 str) 1526 (setq str (concat (or (match-string 1 str) "0")
1534 (match-string 3 str)) 1527 (or (match-string 2 str) ".0")
1535 (setq str (concat (or (match-string 1 str) "0") 1528 (or (match-string 3 str) ""))))
1536 (or (match-string 2 str) ".0")
1537 (or (match-string 3 str) ""))))
1538 (ignore-errors (calculator-string-to-number str))))) 1529 (ignore-errors (calculator-string-to-number str)))))
1539 1530
1540(defun calculator-get-register (reg) 1531(defun calculator-get-register (reg)
@@ -1551,7 +1542,8 @@ Used by `calculator-paste' and `get-register'."
1551 + - * / \\(div) %(rem) _(-X,postfix) ;(1/X,postfix) ^(exp) L(og) 1542 + - * / \\(div) %(rem) _(-X,postfix) ;(1/X,postfix) ^(exp) L(og)
1552 Q(sqrt) !(fact) S(in) C(os) T(an) |(or) #(xor) &(and) ~(not) 1543 Q(sqrt) !(fact) S(in) C(os) T(an) |(or) #(xor) &(and) ~(not)
1553* >/< repeats last binary operation with its 2nd (1st) arg as postfix op 1544* >/< repeats last binary operation with its 2nd (1st) arg as postfix op
1554* I inverses next trig function * \\='/\"/{} - display/display args 1545* I inverse the next trig function \
1546* \\='/\"/{/} - display/display args
1555* D - switch to all-decimal, or toggle deg/rad mode 1547* D - switch to all-decimal, or toggle deg/rad mode
1556* B/O/H/X - binary/octal/hex mode for i/o (X is a shortcut for H) 1548* B/O/H/X - binary/octal/hex mode for i/o (X is a shortcut for H)
1557* i/o - prefix for d/b/o/x - set only input/output modes 1549* i/o - prefix for d/b/o/x - set only input/output modes
@@ -1569,12 +1561,11 @@ Used by `calculator-paste' and `get-register'."
1569 (g-map (current-global-map)) 1561 (g-map (current-global-map))
1570 (win (selected-window))) 1562 (win (selected-window)))
1571 (require 'ehelp) 1563 (require 'ehelp)
1572 (when calculator-electric-mode 1564 (if (not calculator-electric-mode)
1573 (use-global-map calculator-saved-global-map)) 1565 (describe-mode)
1574 (if calculator-electric-mode 1566 (progn (use-global-map calculator-saved-global-map)
1575 (electric-describe-mode) 1567 (electric-describe-mode)
1576 (describe-mode)) 1568 (use-global-map g-map)))
1577 (when calculator-electric-mode (use-global-map g-map))
1578 (select-window win) 1569 (select-window win)
1579 (message nil)) 1570 (message nil))
1580 (let ((one (one-window-p t)) 1571 (let ((one (one-window-p t))