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