Replace uses of in-string-p; make it obsolete
[emacs.git] / lisp / calc / calc-keypd.el
blob18e900dc241a15f7ce2eeee67f8013a6f0025f9b
1 ;;; calc-keypd.el --- mouse-capable keypad input for Calc
3 ;; Copyright (C) 1990-1993, 2001-2015 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 (insert (make-string (/ (- cwid wid) 2) 32)
354 name
355 (make-string (/ (- cwid wid -1) 2) 32)
356 (if (equal name "MENU")
357 (int-to-string (1+ calc-keypad-menu))
358 "|")))
359 (or (setq col (cdr col))
360 (insert "\n")))
361 (insert (if (>= y 4)
362 "-----+-----+-----+-----+-----"
363 (if (= y 3)
364 "-----+---+-+--+--+-+---++----"
365 "----+----+----+----+----+----"))
366 (if (= y 7) "+\n" "|\n"))
367 (setq y (1+ y)
368 row (cdr row)))))
369 (setq calc-keypad-prev-input t)
370 (calc-keypad-show-input)
371 (goto-char (point-min)))
373 (defun calc-keypad-show-input ()
374 (or (equal calc-keypad-input calc-keypad-prev-input)
375 (let ((buffer-read-only nil))
376 (save-excursion
377 (goto-char (point-min))
378 (forward-line 1)
379 (delete-region (point-min) (point))
380 (if calc-keypad-input
381 (insert "Calc: " calc-keypad-input "\n")
382 (insert "----+----+--Calc---+----+----"
383 (int-to-string (1+ calc-keypad-menu))
384 "\n")))))
385 (setq calc-keypad-prev-input calc-keypad-input))
387 (defun calc-keypad-press ()
388 (interactive)
389 (unless (eq major-mode 'calc-keypad-mode)
390 (error "Must be in *Calc Keypad* buffer for this command"))
391 (let* ((row (count-lines (point-min) (point-at-bol)))
392 (y (/ row 2))
393 (x (/ (current-column) (if (>= y 4) 6 5)))
394 radix frac inv
395 (hyp (with-current-buffer calc-main-buffer
396 (setq radix calc-number-radix
397 frac calc-prefer-frac
398 inv calc-inverse-flag)
399 calc-hyperbolic-flag))
400 (invhyp t)
401 (input calc-keypad-input)
402 (iexpon (and input
403 (or (string-match "\\*[0-9]+\\.\\^" input)
404 (and (<= radix 14) (string-match "e" input)))
405 (match-end 0)))
406 (key (nth x (nth y calc-keypad-full-layout)))
407 (cmd (or (nth (if inv (if hyp 4 2) (if hyp 3 99)) key)
408 (setq invhyp nil)
409 (nth 1 key)))
410 (isstring (and (consp cmd) (stringp (car cmd))))
411 (calc-is-keypad-press t))
412 (if invhyp (calc-wrapper)) ; clear Inv and Hyp flags
413 (unwind-protect
414 (cond ((or (null cmd)
415 (= (% row 2) 0))
416 (beep))
417 ((and (> (minibuffer-depth) 0))
418 (cond (isstring
419 (push (aref (car cmd) 0) unread-command-events))
420 ((eq cmd 'calc-pop)
421 (push ?\177 unread-command-events))
422 ((eq cmd 'calc-enter)
423 (push 13 unread-command-events))
424 ((eq cmd 'calc-undo)
425 (push 7 unread-command-events))
427 (beep))))
428 ((and input (string-match "STO\\|RCL" input))
429 (cond ((and isstring (string-match "[0-9]" (car cmd)))
430 (setq calc-keypad-input nil)
431 (let ((var (intern (concat "var-q" (car cmd)))))
432 (cond ((equal input "STO+") (calc-store-plus var))
433 ((equal input "STO-") (calc-store-minus var))
434 ((equal input "STO*") (calc-store-times var))
435 ((equal input "STO/") (calc-store-div var))
436 ((equal input "STO^") (calc-store-power var))
437 ((equal input "STOn") (calc-store-neg 1 var))
438 ((equal input "STO&") (calc-store-inv 1 var))
439 ((equal input "STO") (calc-store-into var))
440 (t (calc-recall var)))))
441 ((memq cmd '(calc-pop calc-undo))
442 (setq calc-keypad-input nil))
443 ((and (equal input "STO")
444 (setq frac (assq cmd '( ( calc-plus . "+" )
445 ( calc-minus . "-" )
446 ( calc-times . "*" )
447 ( calc-divide . "/" )
448 ( calc-power . "^")
449 ( calc-change-sign . "n")
450 ( calc-inv . "&") ))))
451 (setq calc-keypad-input (concat input (cdr frac))))
453 (beep))))
454 (isstring
455 (setq cmd (car cmd))
456 (if (or (and (equal cmd ".")
457 input
458 (string-match "[.:e^]" input))
459 (and (equal cmd "e")
460 input
461 (or (and (<= radix 14) (string-match "e" input))
462 (string-match "\\^\\|[-.:]\\'" input)))
463 (and (not (equal cmd "."))
464 (let ((case-fold-search nil))
465 (string-match cmd "0123456789ABCDEF"
466 (if (string-match
467 "[e^]" (or input ""))
468 10 radix)))))
469 (beep)
470 (setq calc-keypad-input (concat
471 (and (/= radix 10)
472 (or (not input)
473 (equal input "-"))
474 (format "%d#" radix))
475 (and (or (not input)
476 (equal input "-"))
477 (or (and (equal cmd "e") "1")
478 (and (equal cmd ".")
479 (if frac "1" "0"))))
480 input
481 (if (and (equal cmd ".") frac)
483 (if (and (equal cmd "e")
484 (or (not input)
485 (string-match
486 "#" input))
487 (> radix 14))
488 (format "*%d.^" radix)
489 cmd))))))
490 ((and (eq cmd 'calc-change-sign)
491 input)
492 (let* ((epos (or iexpon 0))
493 (suffix (substring input epos)))
494 (setq calc-keypad-input (concat
495 (substring input 0 epos)
496 (if (string-match "\\`-" suffix)
497 (substring suffix 1)
498 (concat "-" suffix))))))
499 ((and (eq cmd 'calc-pop)
500 input)
501 (if (equal input "")
502 (beep)
503 (setq calc-keypad-input (substring input 0
504 (or (string-match
505 "\\*[0-9]+\\.\\^\\'"
506 input)
507 -1)))))
508 ((and (eq cmd 'calc-undo)
509 input)
510 (setq calc-keypad-input nil))
512 (if input
513 (let ((val (math-read-number input)))
514 (setq calc-keypad-input nil)
515 (if val
516 (calc-wrapper
517 (calc-push-list (list (calc-record
518 (calc-normalize val)))))
519 (or (equal input "")
520 (beep))
521 (setq cmd nil))
522 (if (eq cmd 'calc-enter) (setq cmd nil))))
523 (setq prefix-arg current-prefix-arg)
524 (if cmd
525 (if (and (consp cmd) (eq (car cmd) 'progn))
526 (while (setq cmd (cdr cmd))
527 (if (integerp (car cmd))
528 (setq prefix-arg (car cmd))
529 (command-execute (car cmd))))
530 (command-execute cmd)))))
531 (set-buffer calc-keypad-buffer)
532 (calc-keypad-show-input))))
534 (defun calc-keypad-left-click (event)
535 "Handle a left-button mouse click in Calc Keypad window."
536 ;; FIXME: Why not use "@e" instead to select the buffer?
537 (interactive "e")
538 (with-current-buffer calc-keypad-buffer
539 (goto-char (posn-point (event-start event)))
540 (calc-keypad-press)))
542 (defun calc-keypad-right-click (_event)
543 "Handle a right-button mouse click in Calc Keypad window."
544 ;; FIXME: Why not use "@e" instead to select the buffer?
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 ;; FIXME: Why not use "@e" instead to select the buffer?
552 (interactive "e")
553 (with-current-buffer calc-keypad-buffer
554 (calc-keypad-menu-back)))
556 (defun calc-keypad-menu ()
557 (interactive)
558 (unless (eq major-mode 'calc-keypad-mode)
559 (error "Must be in *Calc Keypad* buffer for this command"))
560 (while (progn (setq calc-keypad-menu (% (1+ calc-keypad-menu)
561 (length calc-keypad-menus)))
562 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
563 (calc-keypad-redraw))
565 (defun calc-keypad-menu-back ()
566 (interactive)
567 (or (eq major-mode 'calc-keypad-mode)
568 (error "Must be in *Calc Keypad* buffer for this command"))
569 (while (progn (setq calc-keypad-menu (% (1- (+ calc-keypad-menu
570 (length calc-keypad-menus)))
571 (length calc-keypad-menus)))
572 (not (symbol-value (nth calc-keypad-menu calc-keypad-menus)))))
573 (calc-keypad-redraw))
575 (defun calc-keypad-store ()
576 (interactive)
577 (setq calc-keypad-input "STO"))
579 (defun calc-keypad-recall ()
580 (interactive)
581 (setq calc-keypad-input "RCL"))
583 (defun calc-pack-interval (mode)
584 (interactive "p")
585 (if (or (< mode 0) (> mode 3))
586 (error "Open/close code should be in the range from 0 to 3"))
587 (calc-pack (- -6 mode)))
589 (defun calc-keypad-execute ()
590 (interactive)
591 (let* ((prompt "Calc keystrokes: ")
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 prefix t
609 prompt (concat prompt (key-description keys) " ")))
610 nil)))) ; skip mouse-up event
611 (message "")
612 (if (commandp cmd)
613 (command-execute cmd)
614 (error "Not a Calc command: %s" (key-description keys)))))
616 (provide 'calc-keypd)
618 ;;; calc-keypd.el ends here