]> code.delx.au - gnu-emacs/blob - lisp/emulation/edt-mapper.el
a94d182856cd969e3f949eca9c8fc4ff6878a229
[gnu-emacs] / lisp / emulation / edt-mapper.el
1 ;;; edt-mapper.el --- create an EDT LK-201 map file for X-Windows Emacs
2
3 ;; Copyright (C) 1994, 1995, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009 Free Software Foundation, Inc.
5
6 ;; Author: Kevin Gallagher <Kevin.Gallagher@boeing.com>
7 ;; Maintainer: Kevin Gallagher <Kevin.Gallagher@boeing.com>
8 ;; Keywords: emulations
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26 ;;
27
28 ;; [Part of the GNU Emacs EDT Emulation.]
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 to the LK-201
32 ;; keyboard function keys and keypad keys (around which EDT has been
33 ;; designed). Please read the "Usage" AND "Known Problems" sections
34 ;; below before attempting to run this program. (The design of this
35 ;; file, edt-mapper.el, was heavily influenced by tpu-mapper.el.)
36
37 ;; Version 4.0 contains the following enhancements:
38
39 ;; 1. If you access a workstation using an X Server, note that the
40 ;; initialization file generated by edt-mapper.el will now
41 ;; contain the name of the X Server vendor. This is a
42 ;; convenience for those who have access to their Unix account
43 ;; from more than one type of X Server. Since different X
44 ;; Servers typically require different EDT emulation
45 ;; initialization files, edt-mapper.el will now generate these
46 ;; different initialization files and save them with different
47 ;; names.
48
49 ;; 2. Also, edt-mapper.el is now capable of binding an ASCII key
50 ;; sequence, providing the ASCII key sequence prefix is already
51 ;; known by Emacs to be a prefix. As a result, some
52 ;; terminal/keyboard/window system configurations, which don't
53 ;; have a complete set of sensible function key map bindings, can
54 ;; still be configured for EDT Emulation.
55
56
57 ;; Usage:
58
59 ;; Simply load this file into emacs (version 19 or higher)
60 ;; using the following command.
61
62 ;; emacs -q -l edt-mapper.el
63
64 ;; The "-q" option prevents loading of your .emacs file (commands
65 ;; therein might confuse this program).
66
67 ;; An instruction screen showing the typical LK-201 terminal
68 ;; functions keys will be displayed, and you will be prompted to
69 ;; press the keys on your keyboard which you want to emulate the
70 ;; corresponding LK-201 keys.
71
72 ;; Finally, you will be prompted for the name of the file to store
73 ;; the key definitions. If you chose the default, it will be found
74 ;; and loaded automatically when the EDT emulation is started. If
75 ;; you specify a different file name, you will need to set the
76 ;; variable "edt-keys-file" before starting the EDT emulation.
77 ;; Here's how you might go about doing that in your .emacs file.
78
79 ;; (setq edt-keys-file (expand-file-name "~/.my-emacs-keys"))
80
81
82 ;; Known Problems:
83
84 ;; Sometimes, edt-mapper will ignore a key you press, and just
85 ;; continue to prompt for the same key. This can happen when your
86 ;; window manager sucks up the key and doesn't pass it on to emacs,
87 ;; or it could be an emacs bug. Either way, there's nothing that
88 ;; edt-mapper can do about it. You must press RETURN, to skip the
89 ;; current key and continue. Later, you and/or your local Emacs guru
90 ;; can try to figure out why the key is being ignored.
91
92 ;;; History:
93 ;;
94
95 ;; Version 4.0 2000 Added 2 New Features
96
97 ;;; Code:
98
99 ;;;
100 ;;; Decide Emacs Variant, GNU Emacs or XEmacs (aka Lucid Emacs).
101 ;;; Determine Window System, and X Server Vendor (if appropriate).
102 ;;;
103 (defconst edt-window-system (if (featurep 'xemacs) (console-type) window-system)
104 "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
105
106 (declare-function x-server-vendor "xfns.c" (&optional terminal))
107
108 (defconst edt-xserver (when (eq edt-window-system 'x)
109 ;; The Cygwin window manager has a `/' in its
110 ;; name, which breaks the generated file name of
111 ;; the custom key map file. Replace `/' with a
112 ;; `-' to work around that.
113 (if (featurep 'xemacs)
114 (replace-in-string (x-server-vendor) "[ /]" "-")
115 (replace-regexp-in-string "[ /]" "-"
116 (x-server-vendor))))
117 "Indicates X server vendor name, if applicable.")
118
119
120 ;;;
121 ;;; Key variables
122 ;;;
123 (defvar edt-key nil)
124 (defvar edt-enter nil)
125 (defvar edt-return nil)
126 (defvar edt-key-seq nil)
127 (defvar edt-enter-seq nil)
128 (defvar edt-return-seq nil)
129 (defvar edt-term nil)
130
131 ;; To silence the byte-compiler
132 (defvar EDT-key-name)
133 (defvar edt-save-function-key-map)
134
135 ;;;
136 ;;; Determine Terminal Type (if appropriate).
137 ;;;
138
139 (if (and edt-window-system (not (eq edt-window-system 'tty)))
140 (setq edt-term nil)
141 (setq edt-term (getenv "TERM")))
142
143 ;;;
144 ;;; Make sure the window is big enough to display the instructions,
145 ;;; except where window cannot be re-sized.
146 ;;;
147
148 (if (and edt-window-system (not (eq edt-window-system 'tty)))
149 (set-frame-size (selected-frame) 80 36))
150
151 ;;;
152 ;;; Create buffers - Directions and Keys
153 ;;;
154 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
155 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
156
157 ;;;
158 ;;; Put header in the Keys buffer
159 ;;;
160 (set-buffer "Keys")
161 (insert "\
162 ;;
163 ;; Key definitions for the EDT emulation within GNU Emacs
164 ;;
165
166 (defconst *EDT-keys*
167 '(
168 ")
169
170 ;;;
171 ;;; Display directions
172 ;;;
173 (switch-to-buffer "Directions")
174 (if (and edt-window-system (not (eq edt-window-system 'tty)))
175 (insert "
176 EDT MAPPER
177
178 You will be asked to press keys to create a custom mapping (under a
179 Window Manager) of your keypad keys and function keys so that they can
180 emulate the LK-201 keypad and function keys or the subset of keys found
181 on a VT-100 series terminal keyboard. (The LK-201 keyboard is the
182 standard keyboard attached to VT-200 series terminals, and above.)
183
184 Sometimes, edt-mapper will ignore a key you press, and just continue to
185 prompt for the same key. This can happen when your window manager sucks
186 up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
187 Either way, there's nothing that edt-mapper can do about it. You must
188 press RETURN, to skip the current key and continue. Later, you and/or
189 your local system guru can try to figure out why the key is being ignored.
190
191 Start by pressing the RETURN key, and continue by pressing the keys
192 specified in the mini-buffer. If you want to entirely omit a key,
193 because your keyboard does not have a corresponding key, for example,
194 just press RETURN at the prompt.
195
196 ")
197 (insert "
198 EDT MAPPER
199
200 You will be asked to press keys to create a custom mapping of your
201 keypad keys and function keys so that they can emulate the LK-201
202 keypad and function keys or the subset of keys found on a VT-100
203 series terminal keyboard. (The LK-201 keyboard is the standard
204 keyboard attached to VT-200 series terminals, and above.)
205
206 If you are using a real LK-201 keyboard, you should map the keys
207 exactly as they are on the keyboard.
208
209 Start by pressing the RETURN key, and continue by pressing the keys
210 specified in the mini-buffer. If you want to entirely omit a key,
211 because your keyboard does not have a corresponding key, for example,
212 just press RETURN at the prompt.
213
214 "))
215
216 (delete-other-windows)
217
218 ;;;
219 ;;; Save <CR> for future reference.
220 ;;;
221 ;;; For GNU Emacs, running in a Window System, first hide bindings in
222 ;;; function-key-map.
223 ;;;
224 (cond
225 ((featurep 'xemacs)
226 (setq edt-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
227 (setq edt-return (concat "[" (format "%s" (event-key (aref edt-return-seq 0))) "]")))
228 (t
229 (if edt-window-system
230 (progn
231 (setq edt-save-function-key-map function-key-map)
232 (setq function-key-map (make-sparse-keymap))))
233 (setq edt-return (read-key-sequence "Hit carriage-return <CR> to continue "))))
234
235 ;;;
236 ;;; Remove prefix-key bindings to F1 and F2 in global-map so they can be
237 ;;; bound in the EDT Emulation mode.
238 ;;;
239 (global-unset-key [f1])
240 (global-unset-key [f2])
241
242 ;;;
243 ;;; Display Keypad Diagram and Begin Prompting for Keys
244 ;;;
245 (set-buffer "Directions")
246 (delete-region (point-min) (point-max))
247 (if (and edt-window-system (not (eq edt-window-system 'tty)))
248 (insert "
249
250 PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
251
252 Here's a picture of the standard LK-201 keypad for reference:
253
254 _______________________ _______________________________
255 | HELP | DO | | F17 | F18 | F19 | F20 |
256 | | | | | | | |
257 |_______|_______________| |_______|_______|_______|_______|
258 _______________________ _______________________________
259 | FIND |INSERT |REMOVE | | PF1 | PF2 | PF3 | PF4 |
260 | | | | | | | | |
261 |_______|_______|_______| |_______|_______|_______|_______|
262 |SELECT |PREVIOU| NEXT | | KP7 | KP8 | KP9 | KP- |
263 | | | | | | | | |
264 |_______|_______|_______| |_______|_______|_______|_______|
265 | UP | | KP4 | KP5 | KP6 | KP, |
266 | | | | | | |
267 _______|_______|_______ |_______|_______|_______|_______|
268 | LEFT | DOWN | RIGHT | | KP1 | KP2 | KP3 | |
269 | | | | | | | | |
270 |_______|_______|_______| |_______|_______|_______| KPE |
271 | KP0 | KPP | |
272 | | | |
273 |_______________|_______|_______|
274
275 REMEMBER: JUST PRESS RETURN TO SKIP MAPPING A KEY.
276
277 ")
278 (progn
279 (insert "
280 GENERATING A CUSTOM CONFIGURATION FILE FOR TERMINAL TYPE: ")
281 (insert (format "%s." edt-term))
282 (insert "
283
284 PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
285
286 _______________________ _______________________________
287 | HELP | DO | | F17 | F18 | F19 | F20 |
288 |_______|_______________| |_______|_______|_______|_______|
289 _______________________ _______________________________
290 | FIND |INSERT |REMOVE | | PF1 | PF2 | PF3 | PF4 |
291 |_______|_______|_______| |_______|_______|_______|_______|
292 |SELECT |PREVIOU| NEXT | | KP7 | KP8 | KP9 | KP- |
293 |_______|_______|_______| |_______|_______|_______|_______|
294 | UP | | KP4 | KP5 | KP6 | KP, |
295 _______|_______|_______ |_______|_______|_______|_______|
296 | LEFT | DOWN | RIGHT | | KP1 | KP2 | KP3 | |
297 |_______|_______|_______| |_______|_______|_______| KPE |
298 | KP0 | KPP | |
299 |_______________|_______|_______|
300
301 REMEMBER: JUST PRESS RETURN TO SKIP MAPPING A KEY.")))
302
303
304 ;;;
305 ;;; Key mapping functions
306 ;;;
307 (defun edt-map-key (ident descrip)
308 (interactive)
309 (if (featurep 'xemacs)
310 (progn
311 (setq edt-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
312 (setq edt-key (concat "[" (format "%s" (event-key (aref edt-key-seq 0))) "]"))
313 (cond ((not (equal edt-key edt-return))
314 (set-buffer "Keys")
315 (insert (format " (\"%s\" . %s)\n" ident edt-key))
316 (set-buffer "Directions"))
317 ;; bogosity to get next prompt to come up, if the user hits <CR>!
318 ;; check periodically to see if this is still needed...
319 (t
320 (set-buffer "Keys")
321 (insert (format " (\"%s\" . \"\" )\n" ident))
322 (set-buffer "Directions"))))
323 (setq edt-key (read-key-sequence (format "Press %s%s: " ident descrip)))
324 (cond ((not (equal edt-key edt-return))
325 (set-buffer "Keys")
326 (insert (if (vectorp edt-key)
327 (format " (\"%s\" . %s)\n" ident edt-key)
328 (format " (\"%s\" . \"%s\")\n" ident edt-key)))
329 (set-buffer "Directions"))
330 ;; bogosity to get next prompt to come up, if the user hits <CR>!
331 ;; check periodically to see if this is still needed...
332 (t
333 (set-buffer "Keys")
334 (insert (format " (\"%s\" . \"\" )\n" ident))
335 (set-buffer "Directions"))))
336 edt-key)
337
338 (set-buffer "Keys")
339 (insert "
340 ;;
341 ;; Arrows
342 ;;
343 ")
344 (set-buffer "Directions")
345
346 (edt-map-key "UP" " - The Up Arrow Key")
347 (edt-map-key "DOWN" " - The Down Arrow Key")
348 (edt-map-key "LEFT" " - The Left Arrow Key")
349 (edt-map-key "RIGHT" " - The Right Arrow Key")
350
351
352 (set-buffer "Keys")
353 (insert "
354 ;;
355 ;; PF keys
356 ;;
357 ")
358 (set-buffer "Directions")
359
360 (edt-map-key "PF1" " - The PF1 (GOLD) Key")
361 (edt-map-key "PF2" " - The Keypad PF2 Key")
362 (edt-map-key "PF3" " - The Keypad PF3 Key")
363 (edt-map-key "PF4" " - The Keypad PF4 Key")
364
365 (set-buffer "Keys")
366 (insert "
367 ;;
368 ;; KP0-9 KP- KP, KPP and KPE
369 ;;
370 ")
371 (set-buffer "Directions")
372
373 (edt-map-key "KP0" " - The Keypad 0 Key")
374 (edt-map-key "KP1" " - The Keypad 1 Key")
375 (edt-map-key "KP2" " - The Keypad 2 Key")
376 (edt-map-key "KP3" " - The Keypad 3 Key")
377 (edt-map-key "KP4" " - The Keypad 4 Key")
378 (edt-map-key "KP5" " - The Keypad 5 Key")
379 (edt-map-key "KP6" " - The Keypad 6 Key")
380 (edt-map-key "KP7" " - The Keypad 7 Key")
381 (edt-map-key "KP8" " - The Keypad 8 Key")
382 (edt-map-key "KP9" " - The Keypad 9 Key")
383 (edt-map-key "KP-" " - The Keypad - Key")
384 (edt-map-key "KP," " - The Keypad , Key")
385 (edt-map-key "KPP" " - The Keypad . Key")
386 (edt-map-key "KPE" " - The Keypad Enter Key")
387 ;; Save the enter key
388 (setq edt-enter edt-key)
389 (setq edt-enter-seq edt-key-seq)
390
391
392 (set-buffer "Keys")
393 (insert "
394 ;;
395 ;; Editing keypad (FIND, INSERT, REMOVE)
396 ;; (SELECT, PREVIOUS, NEXT)
397 ;;
398 ")
399 (set-buffer "Directions")
400
401 (edt-map-key "FIND" " - The Find key on the editing keypad")
402 (edt-map-key "INSERT" " - The Insert key on the editing keypad")
403 (edt-map-key "REMOVE" " - The Remove key on the editing keypad")
404 (edt-map-key "SELECT" " - The Select key on the editing keypad")
405 (edt-map-key "PREVIOUS" " - The Prev Scr key on the editing keypad")
406 (edt-map-key "NEXT" " - The Next Scr key on the editing keypad")
407
408 (set-buffer "Keys")
409 (insert "
410 ;;
411 ;; F1-14 Help Do F17-F20
412 ;;
413 ")
414 (set-buffer "Directions")
415
416 (edt-map-key "F1" " - F1 Function Key")
417 (edt-map-key "F2" " - F2 Function Key")
418 (edt-map-key "F3" " - F3 Function Key")
419 (edt-map-key "F4" " - F4 Function Key")
420 (edt-map-key "F5" " - F5 Function Key")
421 (edt-map-key "F6" " - F6 Function Key")
422 (edt-map-key "F7" " - F7 Function Key")
423 (edt-map-key "F8" " - F8 Function Key")
424 (edt-map-key "F9" " - F9 Function Key")
425 (edt-map-key "F10" " - F10 Function Key")
426 (edt-map-key "F11" " - F11 Function Key")
427 (edt-map-key "F12" " - F12 Function Key")
428 (edt-map-key "F13" " - F13 Function Key")
429 (edt-map-key "F14" " - F14 Function Key")
430 (edt-map-key "HELP" " - HELP Function Key")
431 (edt-map-key "DO" " - DO Function Key")
432 (edt-map-key "F17" " - F17 Function Key")
433 (edt-map-key "F18" " - F18 Function Key")
434 (edt-map-key "F19" " - F19 Function Key")
435 (edt-map-key "F20" " - F20 Function Key")
436
437 (set-buffer "Directions")
438 (delete-region (point-min) (point-max))
439 (insert "
440 ADDITIONAL FUNCTION KEYS
441
442 Your keyboard may have additional function keys which do not correspond
443 to any LK-201 keys. The EDT Emulation can be configured to recognize
444 those keys, since you may wish to add your own key bindings to those keys.
445
446 For example, suppose your keyboard has a keycap marked \"Line Del\" and
447 you wish to add it to the list of keys which can be customized by the EDT
448 Emulation. First, assign a unique single-word name to the key for use by
449 the EDT Emulation, for example, \"linedel\". Then, at the \"EDT Key
450 Name:\" prompt, enter \"linedel\", followed by a press of the RETURN key.
451 Finally, when prompted, press the \"Line Del\" key. You now will be able
452 to bind functions to \"linedel\" and \"Gold-linedel\" in edt-user.el in
453 just the same way you can customize bindings of the LK-201 function and
454 keypad keys.
455
456 When you are done, just press RETURN at the \"EDT Key Name:\" prompt.
457 ")
458 (switch-to-buffer "Directions")
459 ;;;
460 ;;; Add support for extras keys
461 ;;;
462 (set-buffer "Keys")
463 (insert "\
464 ;;
465 ;; Extra Keys
466 ;;
467 ")
468 ;;;
469 ;;; Restore function-key-map.
470 ;;;
471 (if (and edt-window-system (not (featurep 'xemacs)))
472 (setq function-key-map edt-save-function-key-map))
473 (setq EDT-key-name "")
474 (while (not
475 (string-equal (setq EDT-key-name (read-string "EDT Key Name: ")) ""))
476 (edt-map-key EDT-key-name ""))
477
478 ;
479 ; No more keys to add, so wrap up.
480 ;
481 (set-buffer "Keys")
482 (insert "\
483 )
484 )
485 ")
486
487 ;;;
488 ;;; Save the key mapping program
489 ;;;
490 ;;;
491 ;;; Save the key mapping file
492 ;;;
493 (let ((file (concat
494 "~/.edt-" (if (featurep 'xemacs) "xemacs" "gnu")
495 (if edt-term (concat "-" edt-term))
496 (if edt-xserver (concat "-" edt-xserver))
497 (if edt-window-system (concat "-" (upcase (symbol-name edt-window-system))))
498 "-keys")))
499 (set-visited-file-name
500 (read-file-name (format "Save key mapping to file (default %s): " file) nil file)))
501 (save-buffer)
502
503 (message "That's it! Press any key to exit")
504 (sit-for 600)
505 (kill-emacs t)
506
507 ;; arch-tag: 9eea59c8-b8b7-4d66-b858-c8920624c518
508 ;;; edt-mapper.el ends here