; Minor copyedits in manuals.
[emacs.git] / lisp / calc / calc-keypd.el
blobdc49f2888cfd6c8f4f33bdbfd700aacd66e2085e
1 ;;; calc-keypd.el --- mouse-capable keypad input for Calc
3 ;; Copyright (C) 1990-1993, 2001-2017 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;;; Code:
26 ;; This file is autoloaded from calc-ext.el.
28 (require 'calc-ext)
29 (require 'calc-macs)
31 (defvar calc-keypad-buffer nil)
32 (defvar calc-keypad-menu 0)
33 (defvar calc-keypad-full-layout nil)
34 (defvar calc-keypad-input nil)
35 (defvar calc-keypad-prev-input nil)
36 (defvar calc-keypad-said-hello nil)
38 ;;; |----+----+----+----+----+----|
39 ;;; | ENTER |+/- |EEX |UNDO| <- |
40 ;;; |-----+---+-+--+--+-+---++----|
41 ;;; | INV | 7 | 8 | 9 | / |
42 ;;; |-----+-----+-----+-----+-----|
43 ;;; | HYP | 4 | 5 | 6 | * |
44 ;;; |-----+-----+-----+-----+-----|
45 ;;; |EXEC | 1 | 2 | 3 | - |
46 ;;; |-----+-----+-----+-----+-----|
47 ;;; | OFF | 0 | . | PI | + |
48 ;;; |-----+-----+-----+-----+-----|
49 (defvar calc-keypad-layout
50 '( ( ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over )
51 ( "ENTER" calc-enter calc-roll-down calc-roll-up calc-over )
52 ( "+/-" calc-change-sign calc-inv (progn -4 calc-pack) )
53 ( "EEX" ("e") (progn calc-num-prefix calc-pack-interval)
54 (progn -5 calc-pack) )
55 ( "UNDO" calc-undo calc-redo calc-last-args )
56 ( "<-" calc-pop (progn 0 calc-pop)
57 (progn calc-num-prefix calc-pop) ) )
58 ( ( "INV" calc-inverse )
59 ( "7" ("7") calc-round )
60 ( "8" ("8") (progn 2 calc-clean-num) )
61 ( "9" ("9") calc-float )
62 ( "/" calc-divide (progn calc-inverse calc-power) ) )
63 ( ( "HYP" calc-hyperbolic )
64 ( "4" ("4") calc-ln calc-log10 )
65 ( "5" ("5") calc-exp calc-exp10 )
66 ( "6" ("6") calc-abs )
67 ( "*" calc-times calc-power ) )
68 ( ( "EXEC" calc-keypad-execute )
69 ( "1" ("1") calc-arcsin calc-sin )
70 ( "2" ("2") calc-arccos calc-cos )
71 ( "3" ("3") calc-arctan calc-tan )
72 ( "-" calc-minus calc-conj ) )
73 ( ( "OFF" calc-keypad-off )
74 ( "0" ("0") calc-imaginary )
75 ( "." (".") calc-precision )
76 ( "PI" calc-pi )
77 ( "+" calc-plus calc-sqrt ) ) ))
79 (defvar calc-keypad-menus '( calc-keypad-math-menu
80 calc-keypad-funcs-menu
81 calc-keypad-binary-menu
82 calc-keypad-vector-menu
83 calc-keypad-modes-menu
84 calc-keypad-user-menu ) )
86 ;;; |----+----+----+----+----+----|
87 ;;; |FLR |CEIL|RND |TRNC|CLN2|FLT |
88 ;;; |----+----+----+----+----+----|
89 ;;; | LN |EXP | |ABS |IDIV|MOD |
90 ;;; |----+----+----+----+----+----|
91 ;;; |SIN |COS |TAN |SQRT|y^x |1/x |
93 (defvar calc-keypad-math-menu
94 '( ( ( "FLR" calc-floor )
95 ( "CEIL" calc-ceiling )
96 ( "RND" calc-round )
97 ( "TRNC" calc-trunc )
98 ( "CLN2" (progn 2 calc-clean-num) )
99 ( "FLT" calc-float ) )
100 ( ( "LN" calc-ln )
101 ( "EXP" calc-exp )
102 ( "" nil )
103 ( "ABS" calc-abs )
104 ( "IDIV" calc-idiv )
105 ( "MOD" calc-mod ) )
106 ( ( "SIN" calc-sin )
107 ( "COS" calc-cos )
108 ( "TAN" calc-tan )
109 ( "SQRT" calc-sqrt )
110 ( "y^x" calc-power )
111 ( "1/x" calc-inv ) ) ))
113 ;;; |----+----+----+----+----+----|
114 ;;; |IGAM|BETA|IBET|ERF |BESJ|BESY|
115 ;;; |----+----+----+----+----+----|
116 ;;; |IMAG|CONJ| RE |ATN2|RAND|RAGN|
117 ;;; |----+----+----+----+----+----|
118 ;;; |GCD |FACT|DFCT|BNOM|PERM|NXTP|
120 (defvar calc-keypad-funcs-menu
121 '( ( ( "IGAM" calc-inc-gamma )
122 ( "BETA" calc-beta )
123 ( "IBET" calc-inc-beta )
124 ( "ERF" calc-erf )
125 ( "BESJ" calc-bessel-J )
126 ( "BESY" calc-bessel-Y ) )
127 ( ( "IMAG" calc-imaginary )
128 ( "CONJ" calc-conj )
129 ( "RE" calc-re calc-im )
130 ( "ATN2" calc-arctan2 )
131 ( "RAND" calc-random )
132 ( "RAGN" calc-random-again ) )
133 ( ( "GCD" calc-gcd calc-lcm )
134 ( "FACT" calc-factorial calc-gamma )
135 ( "DFCT" calc-double-factorial )
136 ( "BNOM" calc-choose )
137 ( "PERM" calc-perm )
138 ( "NXTP" calc-next-prime calc-prev-prime ) ) ))
140 ;;; |----+----+----+----+----+----|
141 ;;; |AND | OR |XOR |NOT |LSH |RSH |
142 ;;; |----+----+----+----+----+----|
143 ;;; |DEC |HEX |OCT |BIN |WSIZ|ARSH|
144 ;;; |----+----+----+----+----+----|
145 ;;; | A | B | C | D | E | F |
147 (defvar calc-keypad-binary-menu
148 '( ( ( "AND" calc-and calc-diff )
149 ( "OR" calc-or )
150 ( "XOR" calc-xor )
151 ( "NOT" calc-not calc-clip )
152 ( "LSH" calc-lshift-binary calc-rotate-binary )
153 ( "RSH" calc-rshift-binary ) )
154 ( ( "DEC" calc-decimal-radix )
155 ( "HEX" calc-hex-radix )
156 ( "OCT" calc-octal-radix )
157 ( "BIN" calc-binary-radix )
158 ( "WSIZ" calc-word-size )
159 ( "ARSH" calc-rshift-arith ) )
160 ( ( "A" ("A") )
161 ( "B" ("B") )
162 ( "C" ("C") )
163 ( "D" ("D") )
164 ( "E" ("E") )
165 ( "F" ("F") ) ) ))
167 ;;; |----+----+----+----+----+----|
168 ;;; |SUM |PROD|MAX |MAP*|MAP^|MAP$|
169 ;;; |----+----+----+----+----+----|
170 ;;; |INV |DET |TRN |IDNT|CRSS|"x" |
171 ;;; |----+----+----+----+----+----|
172 ;;; |PACK|UNPK|INDX|BLD |LEN |... |
174 (defvar calc-keypad-vector-menu
175 '( ( ( "SUM" calc-vector-sum calc-vector-alt-sum calc-vector-mean )
176 ( "PROD" calc-vector-product nil calc-vector-sdev )
177 ( "MAX" calc-vector-max calc-vector-min calc-vector-median )
178 ( "MAP*" (lambda () (interactive)
179 (calc-map '(2 calcFunc-mul "*"))) )
180 ( "MAP^" (lambda () (interactive)
181 (calc-map '(2 calcFunc-pow "^"))) )
182 ( "MAP$" calc-map-stack ) )
183 ( ( "MINV" calc-inv )
184 ( "MDET" calc-mdet )
185 ( "MTRN" calc-transpose calc-conj-transpose )
186 ( "IDNT" (progn calc-num-prefix calc-ident) )
187 ( "CRSS" calc-cross )
188 ( "\"x\"" "\excalc-algebraic-entry\rx\r"
189 "\excalc-algebraic-entry\ry\r"
190 "\excalc-algebraic-entry\rz\r"
191 "\excalc-algebraic-entry\rt\r") )
192 ( ( "PACK" calc-pack )
193 ( "UNPK" calc-unpack )
194 ( "INDX" (progn calc-num-prefix calc-index) "\C-u\excalc-index\r" )
195 ( "BLD" (progn calc-num-prefix calc-build-vector) )
196 ( "LEN" calc-vlength )
197 ( "..." calc-full-vectors ) ) ))
199 ;;; |----+----+----+----+----+----|
200 ;;; |FLT |FIX |SCI |ENG |GRP | |
201 ;;; |----+----+----+----+----+----|
202 ;;; |RAD |DEG |FRAC|POLR|SYMB|PREC|
203 ;;; |----+----+----+----+----+----|
204 ;;; |SWAP|RLL3|RLL4|OVER|STO |RCL |
206 (defvar calc-keypad-modes-menu
207 '( ( ( "FLT" calc-normal-notation
208 (progn calc-num-prefix calc-normal-notation) )
209 ( "FIX" (progn 2 calc-fix-notation)
210 (progn calc-num-prefix calc-fix-notation) )
211 ( "SCI" calc-sci-notation
212 (progn calc-num-prefix calc-sci-notation) )
213 ( "ENG" calc-eng-notation
214 (progn calc-num-prefix calc-eng-notation) )
215 ( "GRP" calc-group-digits "\C-u-3\excalc-group-digits\r" )
216 ( "" nil ) )
217 ( ( "RAD" calc-radians-mode )
218 ( "DEG" calc-degrees-mode )
219 ( "FRAC" calc-frac-mode )
220 ( "POLR" calc-polar-mode )
221 ( "SYMB" calc-symbolic-mode )
222 ( "PREC" calc-precision ) )
223 ( ( "SWAP" calc-roll-down )
224 ( "RLL3" (progn 3 calc-roll-up) (progn 3 calc-roll-down) )
225 ( "RLL4" (progn 4 calc-roll-up) (progn 4 calc-roll-down) )
226 ( "OVER" calc-over )
227 ( "STO" calc-keypad-store )
228 ( "RCL" calc-keypad-recall ) ) ))
230 (define-derived-mode calc-keypad-mode fundamental-mode "Calculator"
231 "Major mode for Calc keypad input."
232 (define-key calc-keypad-mode-map " " 'calc-keypad-press)
233 (define-key calc-keypad-mode-map (kbd "RET") 'calc-keypad-press)
234 (define-key calc-keypad-mode-map (kbd "TAB") 'calc-keypad-menu)
235 (define-key calc-keypad-mode-map "q" 'calc-keypad-off)
236 (define-key calc-keypad-mode-map [down-mouse-1] 'ignore)
237 (define-key calc-keypad-mode-map [drag-mouse-1] 'ignore)
238 (define-key calc-keypad-mode-map [double-mouse-1] 'ignore)
239 (define-key calc-keypad-mode-map [triple-mouse-1] 'ignore)
240 (define-key calc-keypad-mode-map [down-mouse-2] 'ignore)
241 (define-key calc-keypad-mode-map [drag-mouse-2] 'ignore)
242 (define-key calc-keypad-mode-map [double-mouse-2] 'ignore)
243 (define-key calc-keypad-mode-map [triple-mouse-2] 'ignore)
244 (define-key calc-keypad-mode-map [down-mouse-3] 'ignore)
245 (define-key calc-keypad-mode-map [drag-mouse-3] 'ignore)
246 (define-key calc-keypad-mode-map [double-mouse-3] 'ignore)
247 (define-key calc-keypad-mode-map [triple-mouse-3] 'ignore)
248 (define-key calc-keypad-mode-map [mouse-3] 'calc-keypad-right-click)
249 (define-key calc-keypad-mode-map [mouse-2] 'calc-keypad-middle-click)
250 (define-key calc-keypad-mode-map [mouse-1] 'calc-keypad-left-click)
251 (put 'calc-keypad-mode 'mode-class 'special)
252 (make-local-variable 'calc-main-buffer))
254 (defun calc-do-keypad (&optional full-display interactive)
255 (calc-create-buffer)
256 (let ((calcbuf (current-buffer)))
257 (unless (bufferp calc-keypad-buffer)
258 (set-buffer (setq calc-keypad-buffer (get-buffer-create "*Calc Keypad*")))
259 (calc-keypad-mode)
260 (setq calc-main-buffer calcbuf)
261 (calc-keypad-redraw)
262 (calc-trail-buffer))
263 (let ((width 29)
264 (height 17)
265 win old-win)
266 (if (setq win (get-buffer-window "*Calculator*"))
267 (delete-window win))
268 (if (setq win (get-buffer-window "*Calc Trail*"))
269 (if (one-window-p)
270 (switch-to-buffer (other-buffer))
271 (delete-window win)))
272 (if (setq win (get-buffer-window calc-keypad-buffer))
273 (progn
274 (bury-buffer "*Calculator*")
275 (bury-buffer "*Calc Trail*")
276 (bury-buffer calc-keypad-buffer)
277 (if (one-window-p)
278 (switch-to-buffer (other-buffer))
279 (delete-window win)))
280 (setq calc-was-keypad-mode t
281 old-win (get-largest-window))
282 (if (or (< (window-height old-win) (+ height 6))
283 (< (window-width old-win) (+ width 15))
284 full-display)
285 (delete-other-windows old-win))
286 (if (< (window-height old-win) (+ height 4))
287 (error "Screen is not tall enough for this mode"))
288 (if full-display
289 (progn
290 (setq win (split-window old-win (- (window-height old-win)
291 height 1)))
292 (set-window-buffer old-win (calc-trail-buffer))
293 (set-window-buffer win calc-keypad-buffer)
294 (set-window-start win 1)
295 (setq win (split-window win (+ width 7) t))
296 (set-window-buffer win calcbuf))
297 (if (or t ; left-side keypad not yet fully implemented
298 (< (with-current-buffer (window-buffer old-win)
299 (current-column))
300 (/ (window-width) 2)))
301 (setq win (split-window old-win (- (window-width old-win)
302 width 2)
304 (setq old-win (split-window old-win (+ width 2) t)))
305 (set-window-buffer win calc-keypad-buffer)
306 (set-window-start win 1)
307 (split-window win (- (window-height win) height 1))
308 (set-window-buffer win calcbuf))
309 (select-window old-win)
310 (message "Welcome to GNU Emacs Calc! Use the left and right mouse buttons")
311 (run-hooks 'calc-keypad-start-hook)
312 (and calc-keypad-said-hello interactive
313 (progn
314 (sit-for 2)
315 (message "")))
316 (setq calc-keypad-said-hello t)))
317 (setq calc-keypad-input nil)))
319 (defun calc-keypad-off ()
320 (interactive)
321 (if calc-standalone-flag
322 (save-buffers-kill-emacs nil)
323 (calc-keypad)))
325 (defun calc-keypad-redraw ()
326 (set-buffer calc-keypad-buffer)
327 (setq buffer-read-only t)
328 (setq calc-keypad-full-layout (append (symbol-value (nth calc-keypad-menu
329 calc-keypad-menus))
330 calc-keypad-layout))
331 (let ((buffer-read-only nil)
332 (row calc-keypad-full-layout)
333 (y 0))
334 (erase-buffer)
335 (insert "\n")
336 (while row
337 (let ((col (car row)))
338 (while col
339 (let* ((key (car col))
340 (cwid (if (>= y 4)
342 (if (and (= y 3) (eq col (car row)))
343 (progn (setq col (cdr col)) 9)
344 4)))
345 (name (if (and calc-standalone-flag
346 (eq (nth 1 key) 'calc-keypad-off))
347 "EXIT"
348 (if (> (length (car key)) cwid)
349 (substring (car key) 0 cwid)
350 (car key))))
351 (wid (length name)))
352 (insert (make-string (/ (- cwid wid) 2) 32)
353 name
354 (make-string (/ (- cwid wid -1) 2) 32)
355 (if (equal name "MENU")
356 (int-to-string (1+ calc-keypad-menu))
357 "|")))
358 (or (setq col (cdr col))
359 (insert "\n")))
360 (insert (if (>= y 4)
361 "-----+-----+-----+-----+-----"
362 (if (= y 3)
363 "-----+---+-+--+--+-+---++----"
364 "----+----+----+----+----+----"))
365 (if (= y 7) "+\n" "|\n"))
366 (setq y (1+ y)
367 row (cdr row)))))
368 (setq calc-keypad-prev-input t)
369 (calc-keypad-show-input)
370 (goto-char (point-min)))
372 (defun calc-keypad-show-input ()
373 (or (equal calc-keypad-input calc-keypad-prev-input)
374 (let ((buffer-read-only nil))
375 (save-excursion
376 (goto-char (point-min))
377 (forward-line 1)
378 (delete-region (point-min) (point))
379 (if calc-keypad-input
380 (insert "Calc: " calc-keypad-input "\n")
381 (insert "----+----+--Calc---+----+----"
382 (int-to-string (1+ calc-keypad-menu))
383 "\n")))))
384 (setq calc-keypad-prev-input calc-keypad-input))
386 (defun calc-keypad-press ()
387 (interactive)
388 (unless (eq major-mode 'calc-keypad-mode)
389 (error "Must be in *Calc Keypad* buffer for this command"))
390 (let* ((row (count-lines (point-min) (point-at-bol)))
391 (y (/ row 2))
392 (x (/ (current-column) (if (>= y 4) 6 5)))
393 radix frac inv
394 (hyp (with-current-buffer calc-main-buffer
395 (setq radix calc-number-radix
396 frac calc-prefer-frac
397 inv calc-inverse-flag)
398 calc-hyperbolic-flag))
399 (invhyp t)
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 ;; FIXME: Why not use "@e" instead to select the buffer?
536 (interactive "e")
537 (with-current-buffer calc-keypad-buffer
538 (goto-char (posn-point (event-start event)))
539 (calc-keypad-press)))
541 (defun calc-keypad-right-click (_event)
542 "Handle a right-button mouse click in Calc Keypad window."
543 ;; FIXME: Why not use "@e" instead to select the buffer?
544 (interactive "e")
545 (with-current-buffer calc-keypad-buffer
546 (calc-keypad-menu)))
548 (defun calc-keypad-middle-click (_event)
549 "Handle a middle-button mouse click in Calc Keypad window."
550 ;; FIXME: Why not use "@e" instead to select the buffer?
551 (interactive "e")
552 (with-current-buffer calc-keypad-buffer
553 (calc-keypad-menu-back)))
555 (defun calc-keypad-menu ()
556 (interactive)
557 (unless (eq major-mode 'calc-keypad-mode)
558 (error "Must be in *Calc Keypad* buffer for this command"))
559 (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu)
560 (length calc-keypad-menus)))
561 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
562 (calc-keypad-redraw))
564 (defun calc-keypad-menu-back ()
565 (interactive)
566 (or (eq major-mode 'calc-keypad-mode)
567 (error "Must be in *Calc Keypad* buffer for this command"))
568 (while (progn (setq calc-keypad-menu (% (1- (+ calc-keypad-menu
569 (length calc-keypad-menus)))
570 (length calc-keypad-menus)))
571 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
572 (calc-keypad-redraw))
574 (defun calc-keypad-store ()
575 (interactive)
576 (setq calc-keypad-input "STO"))
578 (defun calc-keypad-recall ()
579 (interactive)
580 (setq calc-keypad-input "RCL"))
582 (defun calc-pack-interval (mode)
583 (interactive "p")
584 (if (or (< mode 0) (> mode 3))
585 (error "Open/close code should be in the range from 0 to 3"))
586 (calc-pack (- -6 mode)))
588 (defun calc-keypad-execute ()
589 (interactive)
590 (let* ((prompt "Calc keystrokes: ")
591 (prefix nil)
592 keys cmd)
593 (save-excursion
594 (calc-select-buffer)
595 (while (progn
596 (setq keys (read-key-sequence prompt))
597 (setq cmd (key-binding keys))
598 (if (or (memq cmd '(calc-inverse
599 calc-hyperbolic
600 universal-argument
601 digit-argument
602 negative-argument))
603 (and prefix (string-match "\\`\e?[-0-9]\\'" keys)))
604 (progn
605 (setq last-command-event (aref keys (1- (length keys))))
606 (command-execute cmd)
607 (setq prefix t
608 prompt (concat prompt (key-description keys) " ")))
609 nil)))) ; skip mouse-up event
610 (message "")
611 (if (commandp cmd)
612 (command-execute cmd)
613 (error "Not a Calc command: %s" (key-description keys)))))
615 (provide 'calc-keypd)
617 ;;; calc-keypd.el ends here