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