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