(defcustom): Doc fix.
[emacs.git] / lisp / calc / calc-keypd.el
blob834736a3cf1f57813db1214e31e72fec04bfdf50
1 ;;; calc-keypd.el --- mouse-capable keypad input for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Colin Walters <walters@debian.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY. No author or distributor
12 ;; accepts responsibility to anyone for the consequences of using it
13 ;; or for whether it serves any particular purpose or works at all,
14 ;; unless he says so in writing. Refer to the GNU Emacs General Public
15 ;; License for full details.
17 ;; Everyone is granted permission to copy, modify and redistribute
18 ;; GNU Emacs, but only under the conditions described in the
19 ;; GNU Emacs General Public License. A copy of this license is
20 ;; supposed to have been given to you along with GNU Emacs so you
21 ;; can know your rights and responsibilities. It should be in a
22 ;; file named COPYING. Among other things, the copyright notice
23 ;; and this notice must be preserved on all copies.
25 ;;; Commentary:
27 ;;; Code:
30 ;; This file is autoloaded from calc-ext.el.
31 (require 'calc-ext)
33 (require 'calc-macs)
35 (defun calc-Need-calc-keypd () nil)
38 (defvar calc-keypad-buffer nil)
39 (defvar calc-keypad-menu 0)
40 (defvar calc-keypad-full-layout nil)
41 (defvar calc-keypad-input nil)
42 (defvar calc-keypad-prev-input nil)
43 (defvar calc-keypad-said-hello nil)
45 ;;; |----+----+----+----+----+----|
46 ;;; | ENTER |+/- |EEX |UNDO| <- |
47 ;;; |-----+---+-+--+--+-+---++----|
48 ;;; | INV | 7 | 8 | 9 | / |
49 ;;; |-----+-----+-----+-----+-----|
50 ;;; | HYP | 4 | 5 | 6 | * |
51 ;;; |-----+-----+-----+-----+-----|
52 ;;; |EXEC | 1 | 2 | 3 | - |
53 ;;; |-----+-----+-----+-----+-----|
54 ;;; | OFF | 0 | . | PI | + |
55 ;;; |-----+-----+-----+-----+-----|
56 (defvar calc-keypad-layout
57 '( ( ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over )
58 ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over )
59 ( "+/-" calc-change-sign calc-inv (progn -4 calc-pack) )
60 ( "EEX" ("e") (progn calc-num-prefix calc-pack-interval)
61 (progn -5 calc-pack) )
62 ( "UNDO" calc-undo calc-redo calc-last-args )
63 ( "<-" calc-pop (progn 0 calc-pop)
64 (progn calc-num-prefix calc-pop) ) )
65 ( ( "INV" calc-inverse )
66 ( "7" ("7") calc-round )
67 ( "8" ("8") (progn 2 calc-clean-num) )
68 ( "9" ("9") calc-float )
69 ( "/" calc-divide (progn calc-inverse calc-power) ) )
70 ( ( "HYP" calc-hyperbolic )
71 ( "4" ("4") calc-ln calc-log10 )
72 ( "5" ("5") calc-exp calc-exp10 )
73 ( "6" ("6") calc-abs )
74 ( "*" calc-times calc-power ) )
75 ( ( "EXEC" calc-keypad-execute )
76 ( "1" ("1") calc-arcsin calc-sin )
77 ( "2" ("2") calc-arccos calc-cos )
78 ( "3" ("3") calc-arctan calc-tan )
79 ( "-" calc-minus calc-conj ) )
80 ( ( "OFF" calc-keypad-off )
81 ( "0" ("0") calc-imaginary )
82 ( "." (".") calc-precision )
83 ( "PI" calc-pi )
84 ( "+" calc-plus calc-sqrt ) ) ))
86 (defvar calc-keypad-menus '( calc-keypad-math-menu
87 calc-keypad-funcs-menu
88 calc-keypad-binary-menu
89 calc-keypad-vector-menu
90 calc-keypad-modes-menu
91 calc-keypad-user-menu ) )
93 ;;; |----+----+----+----+----+----|
94 ;;; |FLR |CEIL|RND |TRNC|CLN2|FLT |
95 ;;; |----+----+----+----+----+----|
96 ;;; | LN |EXP | |ABS |IDIV|MOD |
97 ;;; |----+----+----+----+----+----|
98 ;;; |SIN |COS |TAN |SQRT|y^x |1/x |
100 (defvar calc-keypad-math-menu
101 '( ( ( "FLR" calc-floor )
102 ( "CEIL" calc-ceiling )
103 ( "RND" calc-round )
104 ( "TRNC" calc-trunc )
105 ( "CLN2" (progn 2 calc-clean-num) )
106 ( "FLT" calc-float ) )
107 ( ( "LN" calc-ln )
108 ( "EXP" calc-exp )
109 ( "" nil )
110 ( "ABS" calc-abs )
111 ( "IDIV" calc-idiv )
112 ( "MOD" calc-mod ) )
113 ( ( "SIN" calc-sin )
114 ( "COS" calc-cos )
115 ( "TAN" calc-tan )
116 ( "SQRT" calc-sqrt )
117 ( "y^x" calc-power )
118 ( "1/x" calc-inv ) ) ))
120 ;;; |----+----+----+----+----+----|
121 ;;; |IGAM|BETA|IBET|ERF |BESJ|BESY|
122 ;;; |----+----+----+----+----+----|
123 ;;; |IMAG|CONJ| RE |ATN2|RAND|RAGN|
124 ;;; |----+----+----+----+----+----|
125 ;;; |GCD |FACT|DFCT|BNOM|PERM|NXTP|
127 (defvar calc-keypad-funcs-menu
128 '( ( ( "IGAM" calc-inc-gamma )
129 ( "BETA" calc-beta )
130 ( "IBET" calc-inc-beta )
131 ( "ERF" calc-erf )
132 ( "BESJ" calc-bessel-J )
133 ( "BESY" calc-bessel-Y ) )
134 ( ( "IMAG" calc-imaginary )
135 ( "CONJ" calc-conj )
136 ( "RE" calc-re calc-im )
137 ( "ATN2" calc-arctan2 )
138 ( "RAND" calc-random )
139 ( "RAGN" calc-random-again ) )
140 ( ( "GCD" calc-gcd calc-lcm )
141 ( "FACT" calc-factorial calc-gamma )
142 ( "DFCT" calc-double-factorial )
143 ( "BNOM" calc-choose )
144 ( "PERM" calc-perm )
145 ( "NXTP" calc-next-prime calc-prev-prime ) ) ))
147 ;;; |----+----+----+----+----+----|
148 ;;; |AND | OR |XOR |NOT |LSH |RSH |
149 ;;; |----+----+----+----+----+----|
150 ;;; |DEC |HEX |OCT |BIN |WSIZ|ARSH|
151 ;;; |----+----+----+----+----+----|
152 ;;; | A | B | C | D | E | F |
154 (defvar calc-keypad-binary-menu
155 '( ( ( "AND" calc-and calc-diff )
156 ( "OR" calc-or )
157 ( "XOR" calc-xor )
158 ( "NOT" calc-not calc-clip )
159 ( "LSH" calc-lshift-binary calc-rotate-binary )
160 ( "RSH" calc-rshift-binary ) )
161 ( ( "DEC" calc-decimal-radix )
162 ( "HEX" calc-hex-radix )
163 ( "OCT" calc-octal-radix )
164 ( "BIN" calc-binary-radix )
165 ( "WSIZ" calc-word-size )
166 ( "ARSH" calc-rshift-arith ) )
167 ( ( "A" ("A") )
168 ( "B" ("B") )
169 ( "C" ("C") )
170 ( "D" ("D") )
171 ( "E" ("E") )
172 ( "F" ("F") ) ) ))
174 ;;; |----+----+----+----+----+----|
175 ;;; |SUM |PROD|MAX |MAP*|MAP^|MAP$|
176 ;;; |----+----+----+----+----+----|
177 ;;; |INV |DET |TRN |IDNT|CRSS|"x" |
178 ;;; |----+----+----+----+----+----|
179 ;;; |PACK|UNPK|INDX|BLD |LEN |... |
181 (defvar calc-keypad-vector-menu
182 '( ( ( "SUM" calc-vector-sum calc-vector-alt-sum calc-vector-mean )
183 ( "PROD" calc-vector-product nil calc-vector-sdev )
184 ( "MAX" calc-vector-max calc-vector-min calc-vector-median )
185 ( "MAP*" (lambda () (interactive)
186 (calc-map '(2 calcFunc-mul "*"))) )
187 ( "MAP^" (lambda () (interactive)
188 (calc-map '(2 calcFunc-pow "^"))) )
189 ( "MAP$" calc-map-stack ) )
190 ( ( "MINV" calc-inv )
191 ( "MDET" calc-mdet )
192 ( "MTRN" calc-transpose calc-conj-transpose )
193 ( "IDNT" (progn calc-num-prefix calc-ident) )
194 ( "CRSS" calc-cross )
195 ( "\"x\"" "\excalc-algebraic-entry\rx\r"
196 "\excalc-algebraic-entry\ry\r"
197 "\excalc-algebraic-entry\rz\r"
198 "\excalc-algebraic-entry\rt\r") )
199 ( ( "PACK" calc-pack )
200 ( "UNPK" calc-unpack )
201 ( "INDX" (progn calc-num-prefix calc-index) "\C-u\excalc-index\r" )
202 ( "BLD" (progn calc-num-prefix calc-build-vector) )
203 ( "LEN" calc-vlength )
204 ( "..." calc-full-vectors ) ) ))
206 ;;; |----+----+----+----+----+----|
207 ;;; |FLT |FIX |SCI |ENG |GRP | |
208 ;;; |----+----+----+----+----+----|
209 ;;; |RAD |DEG |FRAC|POLR|SYMB|PREC|
210 ;;; |----+----+----+----+----+----|
211 ;;; |SWAP|RLL3|RLL4|OVER|STO |RCL |
213 (defvar calc-keypad-modes-menu
214 '( ( ( "FLT" calc-normal-notation
215 (progn calc-num-prefix calc-normal-notation) )
216 ( "FIX" (progn 2 calc-fix-notation)
217 (progn calc-num-prefix calc-fix-notation) )
218 ( "SCI" calc-sci-notation
219 (progn calc-num-prefix calc-sci-notation) )
220 ( "ENG" calc-eng-notation
221 (progn calc-num-prefix calc-eng-notation) )
222 ( "GRP" calc-group-digits "\C-u-3\excalc-group-digits\r" )
223 ( "" nil ) )
224 ( ( "RAD" calc-radians-mode )
225 ( "DEG" calc-degrees-mode )
226 ( "FRAC" calc-frac-mode )
227 ( "POLR" calc-polar-mode )
228 ( "SYMB" calc-symbolic-mode )
229 ( "PREC" calc-precision ) )
230 ( ( "SWAP" calc-roll-down )
231 ( "RLL3" (progn 3 calc-roll-up) (progn 3 calc-roll-down) )
232 ( "RLL4" (progn 4 calc-roll-up) (progn 4 calc-roll-down) )
233 ( "OVER" calc-over )
234 ( "STO" calc-keypad-store )
235 ( "RCL" calc-keypad-recall ) ) ))
237 (define-derived-mode calc-keypad-mode fundamental-mode "Calculator"
238 "Major mode for Calc keypad input."
239 (define-key calc-keypad-mode-map " " 'calc-keypad-press)
240 (define-key calc-keypad-mode-map (kbd "RET") 'calc-keypad-press)
241 (define-key calc-keypad-mode-map (kbd "TAB") 'calc-keypad-menu)
242 (define-key calc-keypad-mode-map "q" 'calc-keypad-off)
243 (define-key calc-keypad-mode-map [(mouse-3)] 'calc-keypad-right-click)
244 (define-key calc-keypad-mode-map [(mouse-2)] 'calc-keypad-middle-click)
245 (define-key calc-keypad-mode-map [(mouse-1)] 'calc-keypad-left-click)
246 (put 'calc-keypad-mode 'mode-class 'special)
247 (make-local-variable 'calc-main-buffer))
249 (defun calc-do-keypad (&optional full-display interactive)
250 (calc-create-buffer)
251 (let ((calcbuf (current-buffer)))
252 (unless (bufferp calc-keypad-buffer)
253 (set-buffer (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*")))
254 (calc-keypad-mode)
255 (setq calc-main-buffer calcbuf)
256 (calc-keypad-redraw)
257 (calc-trail-buffer))
258 (let ((width 29)
259 (height 17)
260 win old-win)
261 (if (setq win (get-buffer-window "*Calculator*"))
262 (delete-window win))
263 (if (setq win (get-buffer-window "*Calc Trail*"))
264 (if (one-window-p)
265 (switch-to-buffer (other-buffer))
266 (delete-window win)))
267 (if (setq win (get-buffer-window calc-keypad-buffer))
268 (progn
269 (bury-buffer "*Calculator*")
270 (bury-buffer "*Calc Trail*")
271 (bury-buffer calc-keypad-buffer)
272 (if (one-window-p)
273 (switch-to-buffer (other-buffer))
274 (delete-window win)))
275 (setq calc-was-keypad-mode t
276 old-win (get-largest-window))
277 (if (or (< (window-height old-win) (+ height 6))
278 (< (window-width old-win) (+ width 15))
279 full-display)
280 (delete-other-windows old-win))
281 (if (< (window-height old-win) (+ height 4))
282 (error "Screen is not tall enough for this mode"))
283 (if full-display
284 (progn
285 (setq win (split-window old-win (- (window-height old-win)
286 height 1)))
287 (set-window-buffer old-win (calc-trail-buffer))
288 (set-window-buffer win calc-keypad-buffer)
289 (set-window-start win 1)
290 (setq win (split-window win (+ width 3) t))
291 (set-window-buffer win calcbuf))
292 (if (or t ; left-side keypad not yet fully implemented
293 (< (save-excursion
294 (set-buffer (window-buffer old-win))
295 (current-column))
296 (/ (window-width) 2)))
297 (setq win (split-window old-win (- (window-width old-win)
298 width 2)
300 (setq old-win (split-window old-win (+ width 2) t)))
301 (set-window-buffer win calc-keypad-buffer)
302 (set-window-start win 1)
303 (split-window win (- (window-height win) height 1))
304 (set-window-buffer win calcbuf))
305 (select-window old-win)
306 (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons")
307 (run-hooks 'calc-keypad-start-hook)
308 (and calc-keypad-said-hello interactive
309 (progn
310 (sit-for 2)
311 (message "")))
312 (setq calc-keypad-said-hello t)))
313 (setq calc-keypad-input nil)))
315 (defun calc-keypad-off ()
316 (interactive)
317 (if calc-standalone-flag
318 (save-buffers-kill-emacs nil)
319 (calc-keypad)))
321 (defun calc-keypad-redraw ()
322 (set-buffer calc-keypad-buffer)
323 (setq buffer-read-only t)
324 (setq calc-keypad-full-layout (append (symbol-value (nth calc-keypad-menu
325 calc-keypad-menus))
326 calc-keypad-layout))
327 (let ((buffer-read-only nil)
328 (row calc-keypad-full-layout)
329 (y 0))
330 (erase-buffer)
331 (insert "\n")
332 (while row
333 (let ((col (car row)))
334 (while col
335 (let* ((key (car col))
336 (cwid (if (>= y 4)
338 (if (and (= y 3) (eq col (car row)))
339 (progn (setq col (cdr col)) 9)
340 4)))
341 (name (if (and calc-standalone-flag
342 (eq (nth 1 key) 'calc-keypad-off))
343 "EXIT"
344 (if (> (length (car key)) cwid)
345 (substring (car key) 0 cwid)
346 (car key))))
347 (wid (length name))
348 (pad (- cwid (/ wid 2))))
349 (insert (make-string (/ (- cwid wid) 2) 32)
350 name
351 (make-string (/ (- cwid wid -1) 2) 32)
352 (if (equal name "MENU")
353 (int-to-string (1+ calc-keypad-menu))
354 "|")))
355 (or (setq col (cdr col))
356 (insert "\n")))
357 (insert (if (>= y 4)
358 "-----+-----+-----+-----+-----"
359 (if (= y 3)
360 "-----+---+-+--+--+-+---++----"
361 "----+----+----+----+----+----"))
362 (if (= y 7) "+\n" "|\n"))
363 (setq y (1+ y)
364 row (cdr row)))))
365 (setq calc-keypad-prev-input t)
366 (calc-keypad-show-input)
367 (goto-char (point-min)))
369 (defun calc-keypad-show-input ()
370 (or (equal calc-keypad-input calc-keypad-prev-input)
371 (let ((buffer-read-only nil))
372 (save-excursion
373 (goto-char (point-min))
374 (forward-line 1)
375 (delete-region (point-min) (point))
376 (if calc-keypad-input
377 (insert "Calc: " calc-keypad-input "\n")
378 (insert "----+-----Calc " calc-version "-----+----"
379 (int-to-string (1+ calc-keypad-menu))
380 "\n")))))
381 (setq calc-keypad-prev-input calc-keypad-input))
383 (defun calc-keypad-press ()
384 (interactive)
385 (unless (eq major-mode 'calc-keypad-mode)
386 (error "Must be in *Calc Keypad* buffer for this command"))
387 (let* ((row (save-excursion
388 (beginning-of-line)
389 (count-lines (point-min) (point))))
390 (y (/ row 2))
391 (x (/ (current-column) (if (>= y 4) 6 5)))
392 radix frac inv
393 (hyp (with-current-buffer calc-main-buffer
394 (setq radix calc-number-radix
395 frac calc-prefer-frac
396 inv calc-inverse-flag)
397 calc-hyperbolic-flag))
398 (invhyp t)
399 (menu (symbol-value (nth calc-keypad-menu calc-keypad-menus)))
400 (input calc-keypad-input)
401 (iexpon (and input
402 (or (string-match "\\*[0-9]+\\.\\^" input)
403 (and (<= radix 14) (string-match "e" input)))
404 (match-end 0)))
405 (key (nth x (nth y calc-keypad-full-layout)))
406 (cmd (or (nth (if inv (if hyp 4 2) (if hyp 3 99)) key)
407 (setq invhyp nil)
408 (nth 1 key)))
409 (isstring (and (consp cmd) (stringp (car cmd))))
410 (calc-is-keypad-press t))
411 (if invhyp (calc-wrapper)) ; clear Inv and Hyp flags
412 (unwind-protect
413 (cond ((or (null cmd)
414 (= (% row 2) 0))
415 (beep))
416 ((and (> (minibuffer-depth) 0))
417 (cond (isstring
418 (push (aref (car cmd) 0) unread-command-events))
419 ((eq cmd 'calc-pop)
420 (push ?\177 unread-command-events))
421 ((eq cmd 'calc-enter)
422 (push 13 unread-command-events))
423 ((eq cmd 'calc-undo)
424 (push 7 unread-command-events))
426 (beep))))
427 ((and input (string-match "STO\\|RCL" input))
428 (cond ((and isstring (string-match "[0-9]" (car cmd)))
429 (setq calc-keypad-input nil)
430 (let ((var (intern (concat "var-q" (car cmd)))))
431 (cond ((equal input "STO+") (calc-store-plus var))
432 ((equal input "STO-") (calc-store-minus var))
433 ((equal input "STO*") (calc-store-times var))
434 ((equal input "STO/") (calc-store-div var))
435 ((equal input "STO^") (calc-store-power var))
436 ((equal input "STOn") (calc-store-neg 1 var))
437 ((equal input "STO&") (calc-store-inv 1 var))
438 ((equal input "STO") (calc-store-into var))
439 (t (calc-recall var)))))
440 ((memq cmd '(calc-pop calc-undo))
441 (setq calc-keypad-input nil))
442 ((and (equal input "STO")
443 (setq frac (assq cmd '( ( calc-plus . "+" )
444 ( calc-minus . "-" )
445 ( calc-times . "*" )
446 ( calc-divide . "/" )
447 ( calc-power . "^")
448 ( calc-change-sign . "n")
449 ( calc-inv . "&") ))))
450 (setq calc-keypad-input (concat input (cdr frac))))
452 (beep))))
453 (isstring
454 (setq cmd (car cmd))
455 (if (or (and (equal cmd ".")
456 input
457 (string-match "[.:e^]" input))
458 (and (equal cmd "e")
459 input
460 (or (and (<= radix 14) (string-match "e" input))
461 (string-match "\\^\\|[-.:]\\'" input)))
462 (and (not (equal cmd "."))
463 (let ((case-fold-search nil))
464 (string-match cmd "0123456789ABCDEF"
465 (if (string-match
466 "[e^]" (or input ""))
467 10 radix)))))
468 (beep)
469 (setq calc-keypad-input (concat
470 (and (/= radix 10)
471 (or (not input)
472 (equal input "-"))
473 (format "%d#" radix))
474 (and (or (not input)
475 (equal input "-"))
476 (or (and (equal cmd "e") "1")
477 (and (equal cmd ".")
478 (if frac "1" "0"))))
479 input
480 (if (and (equal cmd ".") frac)
482 (if (and (equal cmd "e")
483 (or (not input)
484 (string-match
485 "#" input))
486 (> radix 14))
487 (format "*%d.^" radix)
488 cmd))))))
489 ((and (eq cmd 'calc-change-sign)
490 input)
491 (let* ((epos (or iexpon 0))
492 (suffix (substring input epos)))
493 (setq calc-keypad-input (concat
494 (substring input 0 epos)
495 (if (string-match "\\`-" suffix)
496 (substring suffix 1)
497 (concat "-" suffix))))))
498 ((and (eq cmd 'calc-pop)
499 input)
500 (if (equal input "")
501 (beep)
502 (setq calc-keypad-input (substring input 0
503 (or (string-match
504 "\\*[0-9]+\\.\\^\\'"
505 input)
506 -1)))))
507 ((and (eq cmd 'calc-undo)
508 input)
509 (setq calc-keypad-input nil))
511 (if input
512 (let ((val (math-read-number input)))
513 (setq calc-keypad-input nil)
514 (if val
515 (calc-wrapper
516 (calc-push-list (list (calc-record
517 (calc-normalize val)))))
518 (or (equal input "")
519 (beep))
520 (setq cmd nil))
521 (if (eq cmd 'calc-enter) (setq cmd nil))))
522 (setq prefix-arg current-prefix-arg)
523 (if cmd
524 (if (and (consp cmd) (eq (car cmd) 'progn))
525 (while (setq cmd (cdr cmd))
526 (if (integerp (car cmd))
527 (setq prefix-arg (car cmd))
528 (command-execute (car cmd))))
529 (command-execute cmd)))))
530 (set-buffer calc-keypad-buffer)
531 (calc-keypad-show-input))))
533 (defun calc-keypad-left-click (event)
534 "Handle a left-button mouse click in Calc Keypad window."
535 (interactive "e")
536 (goto-char (posn-point (event-start event)))
537 (calc-keypad-press))
539 (defun calc-keypad-right-click (event)
540 "Handle a right-button mouse click in Calc Keypad window."
541 (interactive "e")
542 (save-excursion
543 (set-buffer calc-keypad-buffer)
544 (calc-keypad-menu)))
546 (defun calc-keypad-middle-click (event)
547 "Handle a middle-button mouse click in Calc Keypad window."
548 (interactive "e")
549 (with-current-buffer calc-keypad-buffer
550 (calc-keypad-menu-back)))
552 (defun calc-keypad-menu ()
553 (interactive)
554 (unless (eq major-mode 'calc-keypad-mode)
555 (error "Must be in *Calc Keypad* buffer for this command"))
556 (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu)
557 (length calc-keypad-menus)))
558 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
559 (calc-keypad-redraw))
561 (defun calc-keypad-menu-back ()
562 (interactive)
563 (or (eq major-mode 'calc-keypad-mode)
564 (error "Must be in *Calc Keypad* buffer for this command"))
565 (while (progn (setq calc-keypad-menu (% (1- (+ calc-keypad-menu
566 (length calc-keypad-menus)))
567 (length calc-keypad-menus)))
568 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
569 (calc-keypad-redraw))
571 (defun calc-keypad-store ()
572 (interactive)
573 (setq calc-keypad-input "STO"))
575 (defun calc-keypad-recall ()
576 (interactive)
577 (setq calc-keypad-input "RCL"))
579 (defun calc-pack-interval (mode)
580 (interactive "p")
581 (if (or (< mode 0) (> mode 3))
582 (error "Open/close code should be in the range from 0 to 3"))
583 (calc-pack (- -6 mode)))
585 (defun calc-keypad-execute ()
586 (interactive)
587 (let* ((prompt "Calc keystrokes: ")
588 (flush 'x-flush-mouse-queue)
589 (prefix nil)
590 keys cmd)
591 (save-excursion
592 (calc-select-buffer)
593 (while (progn
594 (setq keys (read-key-sequence prompt))
595 (setq cmd (key-binding keys))
596 (if (or (memq cmd '(calc-inverse
597 calc-hyperbolic
598 universal-argument
599 digit-argument
600 negative-argument))
601 (and prefix (string-match "\\`\e?[-0-9]\\'" keys)))
602 (progn
603 (setq last-command-char (aref keys (1- (length keys))))
604 (command-execute cmd)
605 (setq flush 'not-any-more
606 prefix t
607 prompt (concat prompt (key-description keys) " ")))
608 (eq cmd flush))))) ; skip mouse-up event
609 (message "")
610 (if (commandp cmd)
611 (command-execute cmd)
612 (error "Not a Calc command: %s" (key-description keys)))))
615 ;;; calc-keypd.el ends here