]> code.delx.au - gnu-emacs/blob - lisp/emulation/tpu-mapper.el
(rmail-forward): Delete trailing blank lines.
[gnu-emacs] / lisp / emulation / tpu-mapper.el
1 ;;; tpu-mapper.el --- Create a TPU-edt X-windows keymap file
2
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Author: Rob Riepel <riepel@networking.stanford.edu>
6 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
7 ;; Keywords: emulations
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it 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 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; This emacs lisp program can be used to create an emacs lisp file that
28 ;; defines the TPU-edt keypad for emacs running on x-windows. Please read
29 ;; the "Usage" AND "Known Problems" sections before attempting to run this
30 ;; program.
31
32 ;;; Usage:
33
34 ;; Simply load this file into the X-windows version of emacs using the
35 ;; following command.
36
37 ;; emacs -q -l tpu-mapper
38
39 ;; The "-q" option prevents loading of your .emacs file (commands therein
40 ;; might confuse this program).
41
42 ;; An instruction screen showing the TPU-edt keypad will be displayed, and
43 ;; you will be prompted to press the TPU-edt editing keys. Tpu-mapper uses
44 ;; the keys you press to create an Emacs Lisp file that will define a
45 ;; TPU-edt keypad for your X server. You can even re-arrange the standard
46 ;; EDT keypad to suit your tastes (or to cope with those silly Sun and PC
47 ;; keypads).
48
49 ;; Finally, you will be prompted for the name of the file to store the key
50 ;; definitions. If you chose the default, TPU-edt will find it and load it
51 ;; automatically. If you specify a different file name, you will need to
52 ;; set the variable "tpu-xkeys-file" before starting TPU-edt. Here's how
53 ;; you might go about doing that in your .emacs file.
54
55 ;; (setq tpu-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
56 ;; (tpu-edt)
57
58 ;;; Known Problems:
59
60 ;; Sometimes, tpu-mapper will ignore a key you press, and just continue to
61 ;; prompt for the same key. This can happen when your window manager sucks
62 ;; up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
63 ;; Either way, there's nothing that tpu-mapper can do about it. You must
64 ;; press RETURN, to skip the current key and continue. Later, you and/or
65 ;; your local X guru can try to figure out why the key is being ignored.
66
67 ;;; Code:
68
69
70 ;;;
71 ;;; Make sure we're running X-windows and Emacs version 19
72 ;;;
73 (cond
74 ((not (and window-system (not (string-lessp emacs-version "19"))))
75 (error "tpu-mapper requires running in Emacs 19, with an X display")))
76
77
78 ;;;
79 ;;; Decide whether we're running Lucid Emacs or Emacs itself.
80 ;;;
81 (defconst tpu-lucid-emacs19-p (string-match "Lucid" emacs-version)
82 "Non-NIL if we are running Lucid Emacs version 19.")
83
84
85 ;;;
86 ;;; Key variables
87 ;;;
88 (defvar tpu-kp4 nil)
89 (defvar tpu-kp5 nil)
90 (defvar tpu-key nil)
91 (defvar tpu-enter nil)
92 (defvar tpu-return nil)
93 (defvar tpu-key-seq nil)
94 (defvar tpu-enter-seq nil)
95 (defvar tpu-return-seq nil)
96
97
98 ;;;
99 ;;; Make sure the window is big enough to display the instructions
100 ;;;
101 (if tpu-lucid-emacs19-p (set-screen-size (selected-screen) 80 36)
102 (set-frame-size (selected-frame) 80 36))
103
104
105 ;;;
106 ;;; Create buffers - Directions, Keys, Gold-Keys
107 ;;;
108 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
109 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
110 (if (not (get-buffer "Gold-Keys")) (generate-new-buffer "Gold-Keys"))
111
112
113 ;;;
114 ;;; Put headers in the Keys buffer
115 ;;;
116 (set-buffer "Keys")
117 (insert "\
118 ;; Key definitions for TPU-edt
119 ;;
120 ")
121
122
123 ;;;
124 ;;; Display directions
125 ;;;
126 (switch-to-buffer "Directions")
127 (insert "
128 This program prompts you to press keys to create a custom keymap file
129 for use with the x-windows version of Emacs and TPU-edt.
130
131 Start by pressing the RETURN key, and continue by pressing the keys
132 specified in the mini-buffer. You can re-arrange the TPU-edt keypad
133 by pressing any key you want at any prompt. If you want to entirely
134 omit a key, just press RETURN at the prompt.
135
136 Here's a picture of the standard TPU/edt keypad for reference:
137
138 _______________________ _______________________________
139 | HELP | Do | | | | | |
140 |KeyDefs| | | | | | |
141 |_______|_______________| |_______|_______|_______|_______|
142 _______________________ _______________________________
143 | Find |Insert |Remove | | Gold | HELP |FndNxt | Del L |
144 | | |Sto Tex| | key |E-Help | Find |Undel L|
145 |_______|_______|_______| |_______|_______|_______|_______|
146 |Select |Pre Scr|Nex Scr| | Page | Sect |Append | Del W |
147 | Reset |Pre Win|Nex Win| | Do | Fill |Replace|Undel W|
148 |_______|_______|_______| |_______|_______|_______|_______|
149 |Move up| |Forward|Reverse|Remove | Del C |
150 | Top | |Bottom | Top |Insert |Undel C|
151 _______|_______|_______ |_______|_______|_______|_______|
152 |Mov Lef|Mov Dow|Mov Rig| | Word | EOL | Char | |
153 |StaOfLi|Bottom |EndOfLi| |ChngCas|Del EOL|SpecIns| Enter |
154 |_______|_______|_______| |_______|_______|_______| |
155 | Line |Select | Subs |
156 | Open Line | Reset | |
157 |_______________|_______|_______|
158
159
160 ")
161 (delete-other-windows)
162 (goto-char (point-min))
163
164 ;;;
165 ;;; Save <CR> for future reference
166 ;;;
167 (cond
168 (tpu-lucid-emacs19-p
169 (setq tpu-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
170 (setq tpu-return (concat "[" (format "%s" (event-key (aref tpu-return-seq 0))) "]")))
171 (t
172 (message "Hit carriage-return <CR> to continue ")
173 (setq tpu-return-seq (read-event))
174 (setq tpu-return (concat "[" (format "%s" tpu-return-seq) "]"))))
175
176
177 ;;;
178 ;;; Key mapping functions
179 ;;;
180 (defun tpu-lucid-map-key (ident descrip func gold-func)
181 (interactive)
182 (setq tpu-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
183 (setq tpu-key (concat "[" (format "%s" (event-key (aref tpu-key-seq 0))) "]"))
184 (cond ((not (equal tpu-key tpu-return))
185 (set-buffer "Keys")
186 (insert (format"(global-set-key %s %s)\n" tpu-key func))
187 (set-buffer "Gold-Keys")
188 (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
189 (set-buffer "Directions"))
190 ;; bogosity to get next prompt to come up, if the user hits <CR>!
191 ;; check periodically to see if this is still needed...
192 (t
193 (format "%s" tpu-key)))
194 tpu-key)
195
196 (defun tpu-emacs-map-key (ident descrip func gold-func)
197 (interactive)
198 (message "Press %s%s: " ident descrip)
199 (setq tpu-key-seq (read-event))
200 (setq tpu-key (concat "[" (format "%s" tpu-key-seq) "]"))
201 (cond ((not (equal tpu-key tpu-return))
202 (set-buffer "Keys")
203 (insert (format"(global-set-key %s %s)\n" tpu-key func))
204 (set-buffer "Gold-Keys")
205 (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
206 (set-buffer "Directions"))
207 ;; bogosity to get next prompt to come up, if the user hits <CR>!
208 ;; check periodically to see if this is still needed...
209 (t
210 (format "%s" tpu-key)))
211 tpu-key)
212
213 (fset 'tpu-map-key (if tpu-lucid-emacs19-p 'tpu-lucid-map-key 'tpu-emacs-map-key))
214
215
216 (set-buffer "Keys")
217 (insert "
218 ;; Arrows
219 ;;
220 ")
221 (set-buffer "Gold-Keys")
222 (insert "
223 ;; GOLD Arrows
224 ;;
225 ")
226 (set-buffer "Directions")
227
228 (tpu-map-key "Up-Arrow" "" "'tpu-previous-line" "'tpu-move-to-beginning")
229 (tpu-map-key "Down-arrow" "" "'tpu-next-line" "'tpu-move-to-end")
230 (tpu-map-key "Right-arrow" "" "'tpu-forward-char" "'end-of-line")
231 (tpu-map-key "Left-arrow" "" "'tpu-backward-char" "'beginning-of-line")
232
233
234 (set-buffer "Keys")
235 (insert "
236 ;; PF keys
237 ;;
238 ")
239 (set-buffer "Gold-Keys")
240 (insert "
241 ;; GOLD PF keys
242 ;;
243 ")
244 (set-buffer "Directions")
245
246 (tpu-map-key "PF1" " - The GOLD key" "GOLD-map" "'keyboard-quit")
247 (tpu-map-key "PF2" " - The Keypad Help key" "'tpu-help" "'help-for-help")
248 (tpu-map-key "PF3" " - The Find/Find-Next key" "'tpu-search-again" "'tpu-search")
249 (tpu-map-key "PF4" " - The Del/Undelete Line key" "'tpu-delete-current-line" "'tpu-undelete-lines")
250
251 (set-buffer "Keys")
252 (insert "
253 ;; KP0-9 KP- KP, KP. and KPenter
254 ;;
255 ")
256 (set-buffer "Gold-Keys")
257 (insert "
258 ;; GOLD KP0-9 KP- KP, and KPenter
259 ;;
260 ")
261 (set-buffer "Directions")
262
263 (tpu-map-key "KP-0" " - The Line/Open-Line key" "'tpu-line" "'open-line")
264 (tpu-map-key "KP-1" " - The Word/Change-Case key" "'tpu-word" "'tpu-change-case")
265 (tpu-map-key "KP-2" " - The EOL/Delete-EOL key" "'tpu-end-of-line" "'tpu-delete-to-eol")
266 (tpu-map-key "KP-3" " - The Character/Special-Insert key" "'tpu-char" "'tpu-special-insert")
267 (setq tpu-kp4 (tpu-map-key "KP-4" " - The Forward/Bottom key" "'tpu-advance-direction" "'tpu-move-to-end"))
268 (setq tpu-kp5 (tpu-map-key "KP-5" " - The Reverse/Top key" "'tpu-backup-direction" "'tpu-move-to-beginning"))
269 (tpu-map-key "KP-6" " - The Remove/Insert key" "'tpu-cut" "'tpu-paste")
270 (tpu-map-key "KP-7" " - The Page/Do key" "'tpu-page" "'execute-extended-command")
271 (tpu-map-key "KP-8" " - The Section/Fill key" "'tpu-scroll-window" "'tpu-fill")
272 (tpu-map-key "KP-9" " - The Append/Replace key" "'tpu-append-region" "'tpu-replace")
273 (tpu-map-key "KP--" " - The Delete/Undelete Word key" "'tpu-delete-current-word" "'tpu-undelete-words")
274 (tpu-map-key "KP-," " - The Delete/Undelete Character key" "'tpu-delete-current-char" "'tpu-undelete-char")
275 (tpu-map-key "KP-." " - The Select/Reset key" "'tpu-select" "'tpu-unselect")
276 (tpu-map-key "KP-Enter" " - The Enter key on the numeric keypad" "'newline" "'tpu-substitute")
277 ;; Save the enter key
278 (setq tpu-enter tpu-key)
279 (setq tpu-enter-seq tpu-key-seq)
280
281 (set-buffer "Keys")
282 (insert "
283 ;; Editing keypad (find, insert, remove)
284 ;; (select, prev, next)
285 ;;
286 ")
287 (set-buffer "Gold-Keys")
288 (insert "
289 ;; GOLD Editing keypad (find, insert, remove)
290 ;; (select, prev, next)
291 ;;
292 ")
293 (set-buffer "Directions")
294
295 (tpu-map-key "Find" " - The Find key on the editing keypad" "'tpu-search" "'nil")
296 (tpu-map-key "Insert" " - The Insert key on the editing keypad" "'tpu-paste" "'nil")
297 (tpu-map-key "Remove" " - The Remove key on the editing keypad" "'tpu-cut" "'tpu-store-text")
298 (tpu-map-key "Select" " - The Select key on the editing keypad" "'tpu-select" "'tpu-unselect")
299 (tpu-map-key "Prev Scr" " - The Prev Scr key on the editing keypad" "'tpu-scroll-window-down" "'tpu-previous-window")
300 (tpu-map-key "Next Scr" " - The Next Scr key on the editing keypad" "'tpu-scroll-window-up" "'tpu-next-window")
301
302 (set-buffer "Keys")
303 (insert "
304 ;; F10-14 Help Do F17
305 ;;
306 ")
307 (set-buffer "Gold-Keys")
308 (insert "
309 ;; GOLD F10-14 Help Do F17
310 ;;
311 ")
312 (set-buffer "Directions")
313
314 (tpu-map-key "F10" " - Invokes the Exit function on VT200+ terminals" "'tpu-exit" "'nil")
315 (tpu-map-key "F11" " - Inserts an Escape character into the text" "'tpu-insert-escape" "'nil")
316 (tpu-map-key "Backspace" " - Not Delete nor ^H! Sometimes on the F12 key" "'tpu-next-beginning-of-line" "'nil")
317 (tpu-map-key "F13" " - Invokes the delete previous word function" "'tpu-delete-previous-word" "'nil")
318 (tpu-map-key "F14" " - Toggles insert/overstrike modes" "'tpu-toggle-overwrite-mode" "'nil")
319 (tpu-map-key "Help" " - Brings up the help screen, same as PF2" "'tpu-help" "'describe-bindings")
320 (tpu-map-key "Do" " - Invokes the COMMAND function" "'execute-extended-command" "'nil")
321 (tpu-map-key "F17" "" "'tpu-goto-breadcrumb" "'tpu-drop-breadcrumb")
322
323 (set-buffer "Gold-Keys")
324 (cond
325 ((not (equal tpu-enter tpu-return))
326 (insert "
327 ;; Minibuffer map additions to make KP_enter = RET
328 ;;
329 ")
330
331 (insert (format "(define-key minibuffer-local-map %s 'exit-minibuffer)\n" tpu-enter))
332 (insert (format "(define-key minibuffer-local-ns-map %s 'exit-minibuffer)\n" tpu-enter))
333 (insert (format "(define-key minibuffer-local-completion-map %s 'exit-minibuffer)\n" tpu-enter))
334 (insert (format "(define-key minibuffer-local-must-match-map %s 'minibuffer-complete-and-exit)\n" tpu-enter))))
335
336 (cond
337 ((not (or (equal tpu-kp4 tpu-return) (equal tpu-kp5 tpu-return)))
338 (insert "
339 ;; Minibuffer map additions to allow KP-4/5 termination of search strings.
340 ;;
341 ")
342
343 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-forward-exit)\n" tpu-kp4))
344 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-backward-exit)\n" tpu-kp5))))
345
346 (insert "
347 ;; Define the tpu-help-enter/return symbols
348 ;;
349 ")
350
351 (cond (tpu-lucid-emacs19-p
352 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter-seq))
353 (insert (format "(setq tpu-help-return \"%s\")\n" tpu-return-seq))
354 (insert "(setq tpu-help-N \"[#<keypress-event N>]\")\n")
355 (insert "(setq tpu-help-n \"[#<keypress-event n>]\")\n")
356 (insert "(setq tpu-help-P \"[#<keypress-event P>]\")\n")
357 (insert "(setq tpu-help-p \"[#<keypress-event p>]\")\n"))
358 (t
359 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter))))
360
361 (append-to-buffer "Keys" 1 (point))
362 (set-buffer "Keys")
363
364 ;;;
365 ;;; Save the key mapping program
366 ;;;
367 (let ((file (if tpu-lucid-emacs19-p "~/.tpu-lucid-keys" "~/.tpu-keys")))
368 (set-visited-file-name
369 (read-file-name (format "Save key mapping to file (default %s): " file) "" file)))
370 (save-buffer)
371
372 ;;;
373 ;;; Load the newly defined keys and clean up
374 ;;;
375 (eval-current-buffer)
376 (kill-buffer (current-buffer))
377 (kill-buffer "*scratch*")
378 (kill-buffer "Gold-Keys")
379
380 ;;;
381 ;;; Let them know it worked.
382 ;;;
383 (switch-to-buffer "Directions")
384 (erase-buffer)
385 (insert "
386 A custom TPU-edt keymap file has been created.
387
388 Press GOLD-k to remove this buffer and continue editing.
389 ")
390 (goto-char (point-min))
391
392 ;;; tpu-mapper.el ends here