1 ;;; edt-mapper.el --- create an EDT LK-201 map file for X-Windows Emacs
3 ;; Copyright (C) 1994-1995, 2000-2012 Free Software Foundation, Inc.
5 ;; Author: Kevin Gallagher <Kevin.Gallagher@boeing.com>
6 ;; Maintainer: Kevin Gallagher <Kevin.Gallagher@boeing.com>
7 ;; Keywords: emulations
10 ;; This file is part of GNU Emacs.
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.
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.
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/>.
28 ;; [Part of the GNU Emacs EDT Emulation.]
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.)
37 ;; Version 4.0 contains the following enhancements:
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
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.
59 ;; Simply load this file into emacs (version 19 or higher)
60 ;; using the following command.
62 ;; emacs -q -l edt-mapper.el
64 ;; The "-q" option prevents loading of your .emacs file (commands
65 ;; therein might confuse this program).
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.
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.
79 ;; (setq edt-keys-file (expand-file-name "~/.my-emacs-keys"))
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.
95 ;; Version 4.0 2000 Added 2 New Features
100 ;;; Decide Emacs Variant, GNU Emacs or XEmacs (aka Lucid Emacs).
101 ;;; Determine Window System, and X Server Vendor (if appropriate).
103 (defconst edt-window-system
(if (featurep 'xemacs
) (console-type) window-system
)
104 "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
106 (declare-function x-server-vendor
"xfns.c" (&optional terminal
))
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 "[ /]" "-"
117 "Indicates X server vendor name, if applicable.")
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
)
131 ;; To silence the byte-compiler
132 (defvar EDT-key-name
)
133 (defvar edt-save-function-key-map
)
136 ;;; Determine Terminal Type (if appropriate).
139 (if (and edt-window-system
(not (eq edt-window-system
'tty
)))
141 (setq edt-term
(getenv "TERM")))
144 ;;; Implements a workaround for a feature that was added to simple.el.
146 ;;; Many function keys have no Emacs functions assigned to them by
147 ;;; default. A subset of these are typically assigned functions in the
148 ;;; EDT emulation. This includes all the keypad keys and a some others
151 ;;; Logic in simple.el maps some of these unassigned function keys to
152 ;;; ordinary typing keys. Where this is the case, a call to
153 ;;; read-key-sequence, below, does not return the name of the function
154 ;;; key pressed by the user but, instead, it returns the name of the
155 ;;; key to which it has been mapped. It needs to know the name of the
156 ;;; key pressed by the user. As a workaround, we assign a function to
157 ;;; each of the unassigned function keys of interest, here. These
158 ;;; assignments override the mapping to other keys and are only
159 ;;; temporary since, when edt-mapper is finished executing, it causes
164 (lambda (function-key)
165 (if (not (lookup-key (current-global-map) function-key
))
166 (define-key (current-global-map) function-key
'forward-char
)))
167 '([kp-0
] [kp-1
] [kp-2
] [kp-3
] [kp-4
]
168 [kp-5
] [kp-6
] [kp-7
] [kp-8
] [kp-9
]
186 ;;; Make sure the window is big enough to display the instructions,
187 ;;; except where window cannot be re-sized.
190 (if (and edt-window-system (not (eq edt-window-system 'tty)))
191 (set-frame-size (selected-frame) 80 36))
194 ;;; Create buffers - Directions and Keys
196 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
197 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
200 ;;; Put header in the Keys buffer
205 ;; Key definitions for the EDT emulation within GNU Emacs
213 ;;; Display directions
215 (switch-to-buffer "Directions")
216 (if (and edt-window-system (not (eq edt-window-system 'tty)))
220 You will be asked to press keys to create a custom mapping (under a
221 Window Manager) of your keypad keys and function keys so that they can
222 emulate the LK-201 keypad and function keys or the subset of keys found
223 on a VT-100 series terminal keyboard. (The LK-201 keyboard is the
224 standard keyboard attached to VT-200 series terminals, and above.)
226 Sometimes, edt-mapper will ignore a key you press, and just continue to
227 prompt for the same key. This can happen when your window manager sucks
228 up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
229 Either way, there's nothing that edt-mapper can do about it. You must
230 press RETURN, to skip the current key and continue. Later, you and/or
231 your local system guru can try to figure out why the key is being ignored.
233 Start by pressing the RETURN key, and continue by pressing the keys
234 specified in the mini-buffer. If you want to entirely omit a key,
235 because your keyboard does not have a corresponding key, for example,
236 just press RETURN at the prompt.
242 You will be asked to press keys to create a custom mapping of your
243 keypad keys and function keys so that they can emulate the LK-201
244 keypad and function keys or the subset of keys found on a VT-100
245 series terminal keyboard. (The LK-201 keyboard is the standard
246 keyboard attached to VT-200 series terminals, and above.)
248 If you are using a real LK-201 keyboard, you should map the keys
249 exactly as they are on the keyboard.
251 Start by pressing the RETURN key, and continue by pressing the keys
252 specified in the mini-buffer. If you want to entirely omit a key,
253 because your keyboard does not have a corresponding key, for example,
254 just press RETURN at the prompt.
258 (delete-other-windows)
261 ;;; Save <CR> for future reference.
263 ;;; For GNU Emacs, running in a Window System, first hide bindings in
264 ;;; function-key-map.
268 (setq edt-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
269 (setq edt-return (concat "[" (format "%s" (event-key (aref edt-return-seq 0))) "]")))
271 (if edt-window-system
273 (setq edt-save-function-key-map function-key-map)
274 (setq function-key-map (make-sparse-keymap))))
275 (setq edt-return (read-key-sequence "Hit carriage-return <CR> to continue "))))
278 ;;; Remove prefix-key bindings to F1 and F2 in global-map so they can be
279 ;;; bound in the EDT Emulation mode.
281 (global-unset-key [f1])
282 (global-unset-key [f2])
285 ;;; Display Keypad Diagram and Begin Prompting for Keys
287 (set-buffer "Directions")
288 (delete-region (point-min) (point-max))
289 (if (and edt-window-system (not (eq edt-window-system 'tty)))
292 PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
294 Here's a picture of the standard LK-201 keypad for reference:
296 _______________________ _______________________________
297 | HELP | DO | | F17 | F18 | F19 | F20 |
299 |_______|_______________| |_______|_______|_______|_______|
300 _______________________ _______________________________
301 | FIND |INSERT |REMOVE | | PF1 | PF2 | PF3 | PF4 |
303 |_______|_______|_______| |_______|_______|_______|_______|
304 |SELECT |PREVIOU| NEXT | | KP7 | KP8 | KP9 | KP- |
306 |_______|_______|_______| |_______|_______|_______|_______|
307 | UP | | KP4 | KP5 | KP6 | KP, |
309 _______|_______|_______ |_______|_______|_______|_______|
310 | LEFT | DOWN | RIGHT | | KP1 | KP2 | KP3 | |
312 |_______|_______|_______| |_______|_______|_______| KPE |
315 |_______________|_______|_______|
317 REMEMBER: JUST PRESS RETURN TO SKIP MAPPING A KEY.
322 GENERATING A CUSTOM CONFIGURATION FILE FOR TERMINAL TYPE: ")
323 (insert (format "%s." edt-term))
326 PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
328 _______________________ _______________________________
329 | HELP | DO | | F17 | F18 | F19 | F20 |
330 |_______|_______________| |_______|_______|_______|_______|
331 _______________________ _______________________________
332 | FIND |INSERT |REMOVE | | PF1 | PF2 | PF3 | PF4 |
333 |_______|_______|_______| |_______|_______|_______|_______|
334 |SELECT |PREVIOU| NEXT | | KP7 | KP8 | KP9 | KP- |
335 |_______|_______|_______| |_______|_______|_______|_______|
336 | UP | | KP4 | KP5 | KP6 | KP, |
337 _______|_______|_______ |_______|_______|_______|_______|
338 | LEFT | DOWN | RIGHT | | KP1 | KP2 | KP3 | |
339 |_______|_______|_______| |_______|_______|_______| KPE |
341 |_______________|_______|_______|
343 REMEMBER: JUST PRESS RETURN TO SKIP MAPPING A KEY.")))
347 ;;; Key mapping functions
349 (defun edt-map-key (ident descrip)
351 (if (featurep 'xemacs)
353 (setq edt-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
354 (setq edt-key (concat "[" (format "%s" (event-key (aref edt-key-seq 0))) "]"))
355 (cond ((not (equal edt-key edt-return))
357 (insert (format " (\"%s\" . %s)\n" ident edt-key))
358 (set-buffer "Directions"))
359 ;; bogosity to get next prompt to come up, if the user hits <CR>!
360 ;; check periodically to see if this is still needed...
363 (insert (format " (\"%s\" . \"\" )\n" ident))
364 (set-buffer "Directions"))))
365 (setq edt-key (read-key-sequence (format "Press %s%s: " ident descrip)))
366 (cond ((not (equal edt-key edt-return))
368 (insert (if (vectorp edt-key)
369 (format " (\"%s\" . %s)\n" ident edt-key)
370 (format " (\"%s\" . \"%s\")\n" ident edt-key)))
371 (set-buffer "Directions"))
372 ;; bogosity to get next prompt to come up, if the user hits <CR>!
373 ;; check periodically to see if this is still needed...
376 (insert (format " (\"%s\" . \"\" )\n" ident))
377 (set-buffer "Directions"))))
386 (set-buffer "Directions")
388 (edt-map-key "UP" " - The Up Arrow Key")
389 (edt-map-key "DOWN" " - The Down Arrow Key")
390 (edt-map-key "LEFT" " - The Left Arrow Key")
391 (edt-map-key "RIGHT" " - The Right Arrow Key")
400 (set-buffer "Directions")
402 (edt-map-key "PF1" " - The PF1 (GOLD) Key")
403 (edt-map-key "PF2" " - The Keypad PF2 Key")
404 (edt-map-key "PF3" " - The Keypad PF3 Key")
405 (edt-map-key "PF4" " - The Keypad PF4 Key")
410 ;; KP0-9 KP- KP, KPP and KPE
413 (set-buffer "Directions")
415 (edt-map-key "KP0" " - The Keypad 0 Key")
416 (edt-map-key "KP1" " - The Keypad 1 Key")
417 (edt-map-key "KP2" " - The Keypad 2 Key")
418 (edt-map-key "KP3" " - The Keypad 3 Key")
419 (edt-map-key "KP4" " - The Keypad 4 Key")
420 (edt-map-key "KP5" " - The Keypad 5 Key")
421 (edt-map-key "KP6" " - The Keypad 6 Key")
422 (edt-map-key "KP7" " - The Keypad 7 Key")
423 (edt-map-key "KP8" " - The Keypad 8 Key")
424 (edt-map-key "KP9" " - The Keypad 9 Key")
425 (edt-map-key "KP-" " - The Keypad - Key")
426 (edt-map-key "KP," " - The Keypad , Key")
427 (edt-map-key "KPP" " - The Keypad . Key")
428 (edt-map-key "KPE" " - The Keypad Enter Key")
429 ;; Save the enter key
430 (setq edt-enter edt-key)
431 (setq edt-enter-seq edt-key-seq)
437 ;; Editing keypad (FIND, INSERT, REMOVE)
438 ;; (SELECT, PREVIOUS, NEXT)
441 (set-buffer "Directions")
443 (edt-map-key "FIND" " - The Find key on the editing keypad")
444 (edt-map-key "INSERT" " - The Insert key on the editing keypad")
445 (edt-map-key "REMOVE" " - The Remove key on the editing keypad")
446 (edt-map-key "SELECT" " - The Select key on the editing keypad")
447 (edt-map-key "PREVIOUS" " - The Prev Scr key on the editing keypad")
448 (edt-map-key "NEXT" " - The Next Scr key on the editing keypad")
453 ;; F1-14 Help Do F17-F20
456 (set-buffer "Directions")
458 (edt-map-key "F1" " - F1 Function Key")
459 (edt-map-key "F2" " - F2 Function Key")
460 (edt-map-key "F3" " - F3 Function Key")
461 (edt-map-key "F4" " - F4 Function Key")
462 (edt-map-key "F5" " - F5 Function Key")
463 (edt-map-key "F6" " - F6 Function Key")
464 (edt-map-key "F7" " - F7 Function Key")
465 (edt-map-key "F8" " - F8 Function Key")
466 (edt-map-key "F9" " - F9 Function Key")
467 (edt-map-key "F10" " - F10 Function Key")
468 (edt-map-key "F11" " - F11 Function Key")
469 (edt-map-key "F12" " - F12 Function Key")
470 (edt-map-key "F13" " - F13 Function Key")
471 (edt-map-key "F14" " - F14 Function Key")
472 (edt-map-key "HELP" " - HELP Function Key")
473 (edt-map-key "DO" " - DO Function Key")
474 (edt-map-key "F17" " - F17 Function Key")
475 (edt-map-key "F18" " - F18 Function Key")
476 (edt-map-key "F19" " - F19 Function Key")
477 (edt-map-key "F20" " - F20 Function Key")
479 (set-buffer "Directions")
480 (delete-region (point-min) (point-max))
482 ADDITIONAL FUNCTION KEYS
484 Your keyboard may have additional function keys which do not correspond
485 to any LK-201 keys. The EDT Emulation can be configured to recognize
486 those keys, since you may wish to add your own key bindings to those keys.
488 For example, suppose your keyboard has a keycap marked \"Line Del\" and
489 you wish to add it to the list of keys which can be customized by the EDT
490 Emulation. First, assign a unique single-word name to the key for use by
491 the EDT Emulation, for example, \"linedel\". Then, at the \"EDT Key
492 Name:\" prompt, enter \"linedel\", followed by a press of the RETURN key.
493 Finally, when prompted, press the \"Line Del\" key. You now will be able
494 to bind functions to \"linedel\" and \"Gold-linedel\" in edt-user.el in
495 just the same way you can customize bindings of the LK-201 function and
498 When you are done, just press RETURN at the \"EDT Key Name:\" prompt.
500 (switch-to-buffer "Directions")
502 ;;; Add support for extras keys
511 ;;; Restore function-key-map.
513 (if (and edt-window-system (not (featurep 'xemacs)))
514 (setq function-key-map edt-save-function-key-map))
515 (setq EDT-key-name "")
517 (string-equal (setq EDT-key-name (read-string "EDT Key Name: ")) ""))
518 (edt-map-key EDT-key-name ""))
521 ; No more keys to add, so wrap up.
530 ;;; Save the key mapping program
533 ;;; Save the key mapping file
536 "~/.edt-" (if (featurep 'xemacs) "xemacs" "gnu")
537 (if edt-term (concat "-" edt-term))
538 (if edt-xserver (concat "-" edt-xserver))
539 (if edt-window-system (concat "-" (upcase (symbol-name edt-window-system))))
541 (set-visited-file-name
542 (read-file-name (format "Save key mapping to file (default %s): " file) nil file)))
545 (message "That's it! Press any key to exit")
549 ;;; edt-mapper.el ends here