comparison lisp/emulators/edt-mapper.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children e45d5e7c476e
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
1 ;;; edt-mapper.el --- Create an EDT LK-201 Map File for X-Windows Emacs
2
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Author: Kevin Gallagher <kgallagh@spd.dsccc.com>
6 ;; Maintainer: Kevin Gallagher <kgallagh@spd.dsccc.com>
7 ;; Keywords: emulations
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; 02111-1307, USA.
25
26 ;;; Synched up with: FSF 19.34
27
28 ;;; Commentary:
29
30 ;; This emacs lisp program can be used to create an emacs lisp file
31 ;; that defines the mapping of the user's keyboard under X-Windows to
32 ;; the LK-201 keyboard function keys and keypad keys (around which
33 ;; EDT has been designed). Please read the "Usage" AND "Known
34 ;; Problems" sections before attempting to run this program. (The
35 ;; design of this file, edt-mapper.el, was heavily influenced by
36 ;; tpu-mapper.el.)
37
38 ;;; Usage:
39
40 ;; Simply load this file into the X-Windows version of emacs (version 19)
41 ;; using the following command.
42
43 ;; emacs -q -l edt-mapper.el
44
45 ;; The "-q" option prevents loading of your .emacs file (commands therein
46 ;; might confuse this program).
47
48 ;; An instruction screen showing the typical LK-201 terminal functions keys
49 ;; will be displayed, and you will be prompted to press the keys on your
50 ;; keyboard which you want to emulate the corresponding LK-201 keys.
51
52 ;; Finally, you will be prompted for the name of the file to store
53 ;; the key definitions. If you chose the default, it will be found
54 ;; and loaded automatically when the EDT emulation is started. If
55 ;; you specify a different file name, you will need to set the
56 ;; variable "edt-xkeys-file" before starting the EDT emulation.
57 ;; Here's how you might go about doing that in your .emacs file.
58
59 ;; (setq edt-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
60
61 ;;; Known Problems:
62
63 ;; Sometimes, edt-mapper will ignore a key you press, and just continue to
64 ;; prompt for the same key. This can happen when your window manager sucks
65 ;; up the key and doesn't pass it on to emacs, or it could be an emacs bug.
66 ;; Either way, there's nothing that edt-mapper can do about it. You must
67 ;; press RETURN, to skip the current key and continue. Later, you and/or
68 ;; your local X guru can try to figure out why the key is being ignored.
69
70 ;; ====================================================================
71
72 ;;;
73 ;;; Make sure we're running X-windows and Emacs version 19
74 ;;;
75 (cond
76 ((not (and window-system (not (string-lessp emacs-version "19"))))
77 (insert "
78
79 Whoa! This isn't going to work...
80
81 You must run edt-mapper.el under X-windows and Emacs version 19.
82
83 Press any key to exit. ")
84 (sit-for 600)
85 (kill-emacs t)))
86
87
88 ;;;
89 ;;; Decide whether we're running GNU or Lucid emacs.
90 ;;;
91 (defconst edt-lucid-emacs19-p (string-match "Lucid" emacs-version)
92 "Non-NIL if we are running Lucid Emacs version 19.")
93
94
95 ;;;
96 ;;; Key variables
97 ;;;
98 (defvar edt-key nil)
99 (defvar edt-enter nil)
100 (defvar edt-return nil)
101 (defvar edt-key-seq nil)
102 (defvar edt-enter-seq nil)
103 (defvar edt-return-seq nil)
104
105
106 ;;;
107 ;;; Make sure the window is big enough to display the instructions
108 ;;;
109 (if edt-lucid-emacs19-p (set-screen-size nil 80 36)
110 (set-frame-size (selected-frame) 80 36))
111
112
113 ;;;
114 ;;; Create buffers - Directions and Keys
115 ;;;
116 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
117 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
118
119 ;;;
120 ;;; Put header in the Keys buffer
121 ;;;
122 (set-buffer "Keys")
123 (insert "\
124 ;;
125 ;; Key definitions for the EDT emulation within GNU Emacs
126 ;;
127
128 (defconst *EDT-keys*
129 '(
130 ")
131
132 ;;;
133 ;;; Display directions
134 ;;;
135 (switch-to-buffer "Directions")
136 (insert "
137 EDT MAPPER
138
139 You will be asked to press keys to create a custom mapping (under
140 X-Windows) of your keypad keys and function keys so that they can emulate
141 the LK-201 keypad and function keys or the subset of keys found on a
142 VT-100 series terminal keyboard. (The LK-201 keyboard is the standard
143 keyboard attached to VT-200 series terminals, and above.)
144
145 Sometimes, edt-mapper will ignore a key you press, and just continue to
146 prompt for the same key. This can happen when your window manager sucks
147 up the key and doesn't pass it on to emacs, or it could be an emacs bug.
148 Either way, there's nothing that edt-mapper can do about it. You must
149 press RETURN, to skip the current key and continue. Later, you and/or
150 your local X guru can try to figure out why the key is being ignored.
151
152 Start by pressing the RETURN key, and continue by pressing the keys
153 specified in the mini-buffer. If you want to entirely omit a key,
154 because your keyboard does not have a corresponding key, for example,
155 just press RETURN at the prompt.
156
157 ")
158 (delete-other-windows)
159
160 ;;;
161 ;;; Save <CR> for future reference
162 ;;;
163 (cond
164 (edt-lucid-emacs19-p
165 (setq edt-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
166 (setq edt-return (concat "[" (format "%s" (event-key (aref edt-return-seq 0))) "]")))
167 (t
168 (message "Hit carriage-return <CR> to continue ")
169 (setq edt-return-seq (read-event))
170 (setq edt-return (concat "[" (format "%s" edt-return-seq) "]"))))
171
172 ;;;
173 ;;; Display Keypad Diagram and Begin Prompting for Keys
174 ;;;
175 (set-buffer "Directions")
176 (delete-region (point-min) (point-max))
177 (insert "
178
179
180
181 PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
182
183
184
185
186 Here's a picture of the standard LK-201 keypad for reference:
187
188 _______________________ _______________________________
189 | HELP | DO | | F17 | F18 | F19 | F20 |
190 | | | | | | | |
191 |_______|_______________| |_______|_______|_______|_______|
192 _______________________ _______________________________
193 | FIND |INSERT |REMOVE | | PF1 | PF2 | PF3 | PF4 |
194 | | | | | | | | |
195 |_______|_______|_______| |_______|_______|_______|_______|
196 |SELECT |PREVIOU| NEXT | | KP7 | KP8 | KP9 | KP- |
197 | | | | | | | | |
198 |_______|_______|_______| |_______|_______|_______|_______|
199 | UP | | KP4 | KP5 | KP6 | KP, |
200 | | | | | | |
201 _______|_______|_______ |_______|_______|_______|_______|
202 | LEFT | DOWN | RIGHT | | KP1 | KP2 | KP3 | |
203 | | | | | | | | |
204 |_______|_______|_______| |_______|_______|_______| KPE |
205 | KP0 | KPP | |
206 | | | |
207 |_______________|_______|_______|
208
209 ")
210
211 ;;;
212 ;;; Key mapping functions
213 ;;;
214 (defun edt-lucid-map-key (ident descrip)
215 (interactive)
216 (setq edt-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
217 (setq edt-key (concat "[" (format "%s" (event-key (aref edt-key-seq 0))) "]"))
218 (cond ((not (equal edt-key edt-return))
219 (set-buffer "Keys")
220 (insert (format " (\"%s\" . %s)\n" ident edt-key))
221 (set-buffer "Directions"))
222 ;; bogosity to get next prompt to come up, if the user hits <CR>!
223 ;; check periodically to see if this is still needed...
224 (t
225 (format "%s" edt-key)))
226 edt-key)
227
228 (defun edt-gnu-map-key (ident descrip)
229 (interactive)
230 (message "Press %s%s: " ident descrip)
231 (setq edt-key-seq (read-event))
232 (setq edt-key (concat "[" (format "%s" edt-key-seq) "]"))
233 (cond ((not (equal edt-key edt-return))
234 (set-buffer "Keys")
235 (insert (format " (\"%s\" . %s)\n" ident edt-key))
236 (set-buffer "Directions"))
237 ;; bogosity to get next prompt to come up, if the user hits <CR>!
238 ;; check periodically to see if this is still needed...
239 (t
240 (set-buffer "Keys")
241 (insert (format " (\"%s\" . \"\" )\n" ident))
242 (set-buffer "Directions")))
243 edt-key)
244
245 (fset 'edt-map-key (if edt-lucid-emacs19-p 'edt-lucid-map-key 'edt-gnu-map-key))
246 (set-buffer "Keys")
247 (insert "
248 ;;
249 ;; Arrows
250 ;;
251 ")
252 (set-buffer "Directions")
253
254 (edt-map-key "UP" " - The Up Arrow Key")
255 (edt-map-key "DOWN" " - The Down Arrow Key")
256 (edt-map-key "LEFT" " - The Left Arrow Key")
257 (edt-map-key "RIGHT" " - The Right Arrow Key")
258
259
260 (set-buffer "Keys")
261 (insert "
262 ;;
263 ;; PF keys
264 ;;
265 ")
266 (set-buffer "Directions")
267
268 (edt-map-key "PF1" " - The PF1 (GOLD) Key")
269 (edt-map-key "PF2" " - The Keypad PF2 Key")
270 (edt-map-key "PF3" " - The Keypad PF3 Key")
271 (edt-map-key "PF4" " - The Keypad PF4 Key")
272
273 (set-buffer "Keys")
274 (insert "
275 ;;
276 ;; KP0-9 KP- KP, KPP and KPE
277 ;;
278 ")
279 (set-buffer "Directions")
280
281 (edt-map-key "KP0" " - The Keypad 0 Key")
282 (edt-map-key "KP1" " - The Keypad 1 Key")
283 (edt-map-key "KP2" " - The Keypad 2 Key")
284 (edt-map-key "KP3" " - The Keypad 3 Key")
285 (edt-map-key "KP4" " - The Keypad 4 Key")
286 (edt-map-key "KP5" " - The Keypad 5 Key")
287 (edt-map-key "KP6" " - The Keypad 6 Key")
288 (edt-map-key "KP7" " - The Keypad 7 Key")
289 (edt-map-key "KP8" " - The Keypad 8 Key")
290 (edt-map-key "KP9" " - The Keypad 9 Key")
291 (edt-map-key "KP-" " - The Keypad - Key")
292 (edt-map-key "KP," " - The Keypad , Key")
293 (edt-map-key "KPP" " - The Keypad . Key")
294 (edt-map-key "KPE" " - The Keypad Enter Key")
295 ;; Save the enter key
296 (setq edt-enter edt-key)
297 (setq edt-enter-seq edt-key-seq)
298
299
300 (set-buffer "Keys")
301 (insert "
302 ;;
303 ;; Editing keypad (FIND, INSERT, REMOVE)
304 ;; (SELECT, PREVIOUS, NEXT)
305 ;;
306 ")
307 (set-buffer "Directions")
308
309 (edt-map-key "FIND" " - The Find key on the editing keypad")
310 (edt-map-key "INSERT" " - The Insert key on the editing keypad")
311 (edt-map-key "REMOVE" " - The Remove key on the editing keypad")
312 (edt-map-key "SELECT" " - The Select key on the editing keypad")
313 (edt-map-key "PREVIOUS" " - The Prev Scr key on the editing keypad")
314 (edt-map-key "NEXT" " - The Next Scr key on the editing keypad")
315
316 (set-buffer "Keys")
317 (insert "
318 ;;
319 ;; F1-14 Help Do F17-F20
320 ;;
321 ")
322 (set-buffer "Directions")
323
324 (edt-map-key "F1" " - F1 Function Key")
325 (edt-map-key "F2" " - F2 Function Key")
326 (edt-map-key "F3" " - F3 Function Key")
327 (edt-map-key "F4" " - F4 Function Key")
328 (edt-map-key "F5" " - F5 Function Key")
329 (edt-map-key "F6" " - F6 Function Key")
330 (edt-map-key "F7" " - F7 Function Key")
331 (edt-map-key "F8" " - F8 Function Key")
332 (edt-map-key "F9" " - F9 Function Key")
333 (edt-map-key "F10" " - F10 Function Key")
334 (edt-map-key "F11" " - F11 Function Key")
335 (edt-map-key "F12" " - F12 Function Key")
336 (edt-map-key "F13" " - F13 Function Key")
337 (edt-map-key "F14" " - F14 Function Key")
338 (edt-map-key "HELP" " - HELP Function Key")
339 (edt-map-key "DO" " - DO Function Key")
340 (edt-map-key "F17" " - F17 Function Key")
341 (edt-map-key "F18" " - F18 Function Key")
342 (edt-map-key "F19" " - F19 Function Key")
343 (edt-map-key "F20" " - F20 Function Key")
344
345 (set-buffer "Directions")
346 (delete-region (point-min) (point-max))
347 (insert "
348 ADDITIONAL FUNCTION KEYS
349
350 Your keyboard may have additional function keys which do not
351 correspond to any LK-201 keys. The EDT Emulation can be
352 configured to recognize those keys, since you may wish to add your
353 own key bindings to those keys.
354
355 For example, suppose your keyboard has a keycap marked \"Line Del\"
356 and you wish to add it to the list of keys which can be customized
357 by the EDT Emulation. First, assign a unique single-word name to
358 the key for use by the EDT Emulation, let's say \"linedel\", in this
359 example. Then, at the \"EDT Key Name:\" prompt, enter \"linedel\",
360 followed by a press of the RETURN key. Finally, when prompted,
361 press the \"Line Del\" key. You now will be able to bind functions
362 to \"linedel\" and \"Gold-linedel\" in edt-user.el in just the same way
363 you can customize bindings of the standard LK-201 keys.
364
365 When you have no additional function keys to specify, just press
366 RETURN at the \"EDT Key Name:\" prompt. (If you change your mind
367 AFTER you enter an EDT Key Name and before you press a key at the
368 \"Press\" prompt, you may omit the key by simply pressing RETURN at
369 the prompt.)
370 ")
371 (switch-to-buffer "Directions")
372 ;;;
373 ;;; Add support for extras keys
374 ;;;
375 (set-buffer "Keys")
376 (insert "\
377 ;;
378 ;; Extra Keys
379 ;;
380 ")
381 (setq EDT-key-name "")
382 (while (not
383 (string-equal (setq EDT-key-name (read-string "EDT Key Name: ")) ""))
384 (edt-map-key EDT-key-name ""))
385
386 ;
387 ; No more keys to add, so wrap up.
388 ;
389 (set-buffer "Keys")
390 (insert "\
391 )
392 )
393 ")
394
395 ;;;
396 ;;; Save the key mapping program and blow this pop stand
397 ;;;
398 (let ((file (if edt-lucid-emacs19-p "~/.edt-lucid-keys" "~/.edt-gnu-keys")))
399 (set-visited-file-name
400 (read-file-name (format "Save key mapping to file (default %s): " file) nil file)))
401 (save-buffer)
402
403 (message "That's it! Press any key to exit")
404 (sit-for 600)
405 (kill-emacs t)
406
407 ;;; edt-mapper.el ends here