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