aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-05-14 20:30:55 +0000
committerKim F. Storm2002-05-14 20:30:55 +0000
commit6df44fac4b2117145b1bab2899cf9b34dffe6d0e (patch)
treedaf7a573903b6f4184b017dad3cf25c0424d2dcc
parent861a74f307a97b7abc725955a6d8b32b581090a6 (diff)
downloademacs-6df44fac4b2117145b1bab2899cf9b34dffe6d0e.tar.gz
emacs-6df44fac4b2117145b1bab2899cf9b34dffe6d0e.zip
Improved commentary.
(keypad-setup, keypad-shifted-setup): Added choice to setup Numeric keypad with decimal key; value is selected character. (keypad-decimal-key, keypad-shifted-decimal-key): Removed options. (keypad-numlock-setup, keypad-numlock-shifted-setup): New options. (keypad-setup): Arg list changed to support the new options.
-rw-r--r--lisp/emulation/keypad.el209
1 files changed, 142 insertions, 67 deletions
diff --git a/lisp/emulation/keypad.el b/lisp/emulation/keypad.el
index abbf511c95f..2f1d3e1f2a4 100644
--- a/lisp/emulation/keypad.el
+++ b/lisp/emulation/keypad.el
@@ -28,14 +28,15 @@
28;; various commonly used sets of commands. 28;; various commonly used sets of commands.
29;; 29;;
30;; With the following setup, the keypad can be used for numeric data 30;; With the following setup, the keypad can be used for numeric data
31;; entry, or to give numeric prefix arguments to emacs commands. 31;; entry when NumLock is off, and to give numeric prefix arguments to
32;; emacs commands, when NumLock on on.
32;; 33;;
33;; (keypad-setup 'numeric) 34;; keypad-setup => Plain Numeric Keypad
34;; (keypad-setup 'prefix t) 35;; keypad-numlock-setup => Prefix numeric args
35;; 36;;
36;; +--------+--------+--------+ 37;; +--------+--------+--------+
37;; | M-7 | M-8 | M-9 | 38;; | M-7 | M-8 | M-9 | <- numlock on
38;; | 7 | 8 | 9 | 39;; | 7 | 8 | 9 | <- numlock off
39;; +--------+--------+--------+ 40;; +--------+--------+--------+
40;; | M-4 | M-5 | M-6 | 41;; | M-4 | M-5 | M-6 |
41;; | 4 | 5 | 6 | 42;; | 4 | 5 | 6 |
@@ -47,14 +48,16 @@
47;; | 0 | . | 48;; | 0 | . |
48;; +-----------------+--------+ 49;; +-----------------+--------+
49 50
50;; The following keypad setup is used for navigation: 51;; The following keypad setup is used for navigation together with
52;; modes like cua-mode which uses shifted movement keys to extend the
53;; region.
51;; 54;;
52;; (keypad-setup 'cursor) 55;; keypad-setup => Cursor keys
53;; (keypad-setup 'S-cursor t) 56;; keypad-shifted-setup => Shifted cursor keys
54;; 57;;
55;; +--------+--------+--------+ 58;; +--------+--------+--------+
56;; | S-home | S-up | S-PgUp | 59;; | S-home | S-up | S-PgUp | <- shifted, numlock off
57;; | Home | up | PgUp | 60;; | Home | up | PgUp | <- unshifted, numlock off
58;; +--------+--------+--------+ 61;; +--------+--------+--------+
59;; | S-left |S-space |S-right | 62;; | S-left |S-space |S-right |
60;; | left | space | right | 63;; | left | space | right |
@@ -66,6 +69,28 @@
66;; | insert | delete | 69;; | insert | delete |
67;; +-----------------+--------+ 70;; +-----------------+--------+
68 71
72;; The following setup binds the unshifted keypad keys to plain
73;; numeric keys when NumLock is either on or off, but the decimal key
74;; produces either a . (NumLock off) or a , (NumLock on). This is
75;; useful for e.g. Danish users where the decimal separator is a
76;; comma.
77;;
78;; keypad-setup => Plain Numeric Keypad
79;; keypad-numlock-setup => Numeric Keypad with Decimal key: ,
80;;
81;; +--------+--------+--------+
82;; | 7 | 8 | 9 | <- numlock on
83;; | 7 | 8 | 9 | <- numlock off
84;; +--------+--------+--------+
85;; | 4 | 5 | 6 |
86;; | 4 | 5 | 6 |
87;; +--------+--------+--------+
88;; | 1 | 2 | 3 |
89;; | 1 | 2 | 3 |
90;; +--------+--------+--------+
91;; | 0 | , |
92;; | 0 | . |
93;; +-----------------+--------+
69 94
70;;; Code: 95;;; Code:
71 96
@@ -75,102 +100,152 @@
75 100
76;;;###autoload 101;;;###autoload
77(defcustom keypad-setup nil 102(defcustom keypad-setup nil
78 "Specifies the keypad setup for unshifted keypad keys. 103 "Specifies the keypad setup for unshifted keypad keys when NumLock is off.
79The options are: 104When selecting the plain numeric keypad setup, the character returned by the
80 'prefix Numeric prefix argument, i.e. M-0 .. M-9 and M-- 105decimal key must be specified."
81 'cursor Cursor movement keys.
82 'S-cursor Shifted cursor movement keys.
83 'numeric Plain numeric, i.e. 0 .. 9 and . (or DECIMAL arg)
84 'none Removes all bindings for keypad keys in function-key-map.
85 nil Keep existing bindings for the keypad keys."
86 :set (lambda (symbol value) 106 :set (lambda (symbol value)
87 (if value 107 (if value
88 (keypad-setup value nil keypad-decimal-key))) 108 (keypad-setup value nil nil value)))
89 :initialize 'custom-initialize-default 109 :initialize 'custom-initialize-default
90 :set-after '(keypad-decimal-key)
91 :require 'keypad
92 :link '(emacs-commentary-link "keypad.el") 110 :link '(emacs-commentary-link "keypad.el")
93 :version "21.4" 111 :version "21.4"
94 :type '(choice (const :tag "Numeric prefix arguments" prefix) 112 :type '(choice (const :tag "Plain numeric keypad" numeric)
113 (character :tag "Numeric Keypad with Decimal Key"
114 :match (lambda (widget value) (integerp value))
115 :value ?.)
116 (const :tag "Numeric prefix arguments" prefix)
95 (const :tag "Cursor keys" cursor) 117 (const :tag "Cursor keys" cursor)
96 (const :tag "Shifted cursor keys" S-cursor) 118 (const :tag "Shifted cursor keys" S-cursor)
97 (const :tag "Plain Numeric Keypad" numeric)
98 (const :tag "Remove bindings" none) 119 (const :tag "Remove bindings" none)
99 (other :tag "Keep existing bindings" :value nil)) 120 (other :tag "Keep existing bindings" nil))
100 :group 'keyboard) 121 :group 'keyboard)
101 122
102(defcustom keypad-decimal-key ?. 123;;;###autoload
103 "Character produced by the unshifted decimal key on the keypad." 124(defcustom keypad-numlock-setup nil
104 :type 'character 125 "Specifies the keypad setup for unshifted keypad keys when NumLock is on.
126When selecting the plain numeric keypad setup, the character returned by the
127decimal key must be specified."
128 :set (lambda (symbol value)
129 (if value
130 (keypad-setup value t nil value)))
131 :initialize 'custom-initialize-default
132 :link '(emacs-commentary-link "keypad.el")
133 :version "21.4"
134 :type '(choice (const :tag "Plain numeric keypad" numeric)
135 (character :tag "Numeric Keypad with Decimal Key"
136 :match (lambda (widget value) (integerp value))
137 :value ?.)
138 (const :tag "Numeric prefix arguments" prefix)
139 (const :tag "Cursor keys" cursor)
140 (const :tag "Shifted cursor keys" S-cursor)
141 (const :tag "Remove bindings" none)
142 (other :tag "Keep existing bindings" nil))
105 :group 'keyboard) 143 :group 'keyboard)
106 144
107;;;###autoload 145;;;###autoload
108(defcustom keypad-shifted-setup nil 146(defcustom keypad-shifted-setup nil
109 "Specifies the keypad setup for shifted keypad keys. 147 "Specifies the keypad setup for shifted keypad keys when NumLock is off.
110See `keypad-setup' for available options." 148When selecting the plain numeric keypad setup, the character returned by the
149decimal key must be specified."
111 :set (lambda (symbol value) 150 :set (lambda (symbol value)
112 (if value 151 (if value
113 (keypad-setup value t keypad-shifted-decimal-key))) 152 (keypad-setup value nil t value)))
114 :initialize 'custom-initialize-default 153 :initialize 'custom-initialize-default
115 :set-after '(keypad-shifted-decimal-key)
116 :require 'keypad
117 :link '(emacs-commentary-link "keypad.el") 154 :link '(emacs-commentary-link "keypad.el")
118 :version "21.4" 155 :version "21.4"
119 :type '(choice (const :tag "Numeric prefix arguments" prefix) 156 :type '(choice (const :tag "Plain numeric keypad" numeric)
157 (character :tag "Numeric Keypad with Decimal Key"
158 :match (lambda (widget value) (integerp value))
159 :value ?.)
160 (const :tag "Numeric prefix arguments" prefix)
120 (const :tag "Cursor keys" cursor) 161 (const :tag "Cursor keys" cursor)
121 (const :tag "Shifted cursor keys" S-cursor) 162 (const :tag "Shifted cursor keys" S-cursor)
122 (const :tag "Plain Numeric Keypad" numeric)
123 (const :tag "Remove bindings" none) 163 (const :tag "Remove bindings" none)
124 (other :tag "Keep existing bindings" :value nil)) 164 (other :tag "Keep existing bindings" nil))
125 :group 'keyboard) 165 :group 'keyboard)
126 166
127(defcustom keypad-shifted-decimal-key ?. 167;;;###autoload
128 "Character produced by the unshifted decimal key on the keypad." 168(defcustom keypad-numlock-shifted-setup nil
129 :type 'character 169 "Specifies the keypad setup for shifted keypad keys when NumLock is off.
170When selecting the plain numeric keypad setup, the character returned by the
171decimal key must be specified."
172 :set (lambda (symbol value)
173 (if value
174 (keypad-setup value t t value)))
175 :initialize 'custom-initialize-default
176 :link '(emacs-commentary-link "keypad.el")
177 :version "21.4"
178 :type '(choice (const :tag "Plain numeric keypad" numeric)
179 (character :tag "Numeric Keypad with Decimal Key"
180 :match (lambda (widget value) (integerp value))
181 :value ?.)
182 (const :tag "Numeric prefix arguments" prefix)
183 (const :tag "Cursor keys" cursor)
184 (const :tag "Shifted cursor keys" S-cursor)
185 (const :tag "Remove bindings" none)
186 (other :tag "Keep existing bindings" nil))
130 :group 'keyboard) 187 :group 'keyboard)
131 188
189
132;;;###autoload 190;;;###autoload
133(defun keypad-setup (setup &optional numlock decimal) 191(defun keypad-setup (setup &optional numlock shift decimal)
134 "Set keypad bindings in function-key-map according to SETUP. 192 "Set keypad bindings in function-key-map according to SETUP.
135If optional second argument NUMLOCK is non-nil, the NumLock On bindings 193If optional second argument NUMLOCK is non-nil, the NumLock On bindings
136are changed. Otherwise, the NumLock Off bindings are changed. 194are changed. Otherwise, the NumLock Off bindings are changed.
195If optional third argument SHIFT is non-nil, the shifted keypad
196keys are bound.
137 197
138 Setup Binding 198 Setup Binding
139 ------------------------------------------------------------- 199 -------------------------------------------------------------
140 'prefix Command prefix argument, i.e. M-0 .. M-9 and M-- 200 'prefix Command prefix argument, i.e. M-0 .. M-9 and M--
141 'S-cursor Bind shifted keypad keys to the shifted cursor movement keys. 201 'S-cursor Bind shifted keypad keys to the shifted cursor movement keys.
142 'cursor Bind keypad keys to the cursor movement keys. 202 'cursor Bind keypad keys to the cursor movement keys.
143 'numeric Plain numeric, i.e. 0 .. 9 and . (or DECIMAL arg) 203 'numeric Plain numeric keypad, i.e. 0 .. 9 and . (or DECIMAL arg)
144 'none Removes all bindings for keypad keys in function-key-map. 204 'none Removes all bindings for keypad keys in function-key-map.
145 205
146If SETUP is 'numeric and the optional third argument DECIMAL is non-nil, 206If SETUP is 'numeric and the optional fourth argument DECIMAL is non-nil,
147the decimal key on the keypad is mapped to DECIMAL instead of `.'" 207the decimal key on the keypad is mapped to DECIMAL instead of `.'"
148 (let ((i 0) 208 (let* ((i 0)
149 (kp 209 (var (cond
150 (cond 210 ((and (not numlock) (not shift)) 'keypad-setup)
151 (numlock 211 ((and (not numlock) shift) 'keypad-shifted-setup)
152 [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4 212 ((and numlock (not shift)) 'keypad-numlock-setup)
153 kp-5 kp-6 kp-7 kp-8 kp-9]) 213 ((and numlock shift) 'keypad-numlock-shifted-setup)))
154 (t 214 (kp (cond
155 [kp-delete kp-insert kp-end kp-down kp-next kp-left 215 ((eq var 'keypad-setup)
156 kp-space kp-right kp-home kp-up kp-prior]))) 216 [kp-delete kp-insert kp-end kp-down kp-next kp-left
157 (bind 217 kp-space kp-right kp-home kp-up kp-prior])
158 (cond 218 ((eq var 'keypad-shifted-setup)
159 ((eq setup 'numeric) 219 [S-kp-decimal S-kp-0 S-kp-1 S-kp-2 S-kp-3 S-kp-4
160 (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)) 220 S-kp-5 S-kp-6 S-kp-7 S-kp-8 S-kp-9])
161 ((eq setup 'prefix) 221 ((eq var 'keypad-numlock-setup)
162 [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4 222 [kp-decimal kp-0 kp-1 kp-2 kp-3 kp-4
163 ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9]) 223 kp-5 kp-6 kp-7 kp-8 kp-9])
164 ((eq setup 'cursor) 224 ((eq var 'keypad-numlock-shifted-setup)
165 [delete insert end down next left 225 [S-kp-delete S-kp-insert S-kp-end S-kp-down S-kp-next S-kp-left
166 space right home up prior]) 226 S-kp-space S-kp-right S-kp-home S-kp-up S-kp-prior])))
167 ((eq setup 'S-cursor) 227 (bind
168 [S-delete S-insert S-end S-down S-next S-left 228 (cond
169 S-space S-right S-home S-up S-prior]) 229 ((or (eq setup 'numeric)
170 ((eq setup 'none) 230 (char-valid-p setup))
171 nil) 231 (if (eq decimal 'numeric)
172 (t 232 (setq decimal nil))
173 (signal 'error (list "Unknown keypad setup: " setup)))))) 233 (vector (or decimal ?.) ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
234 ((eq setup 'prefix)
235 [?\M-- ?\M-0 ?\M-1 ?\M-2 ?\M-3 ?\M-4
236 ?\M-5 ?\M-6 ?\M-7 ?\M-8 ?\M-9])
237 ((eq setup 'cursor)
238 [delete insert end down next left
239 space right home up prior])
240 ((eq setup 'S-cursor)
241 [S-delete S-insert S-end S-down S-next S-left
242 S-space S-right S-home S-up S-prior])
243 ((eq setup 'none)
244 nil)
245 (t
246 (signal 'error (list "Unknown keypad setup: " setup))))))
247
248 (set var setup)
174 249
175 ;; Bind the keys in KP list to BIND list in function-key-map. 250 ;; Bind the keys in KP list to BIND list in function-key-map.
176 ;; If BIND is nil, all bindings for the keys are removed. 251 ;; If BIND is nil, all bindings for the keys are removed.