]> code.delx.au - gnu-emacs/blob - lisp/obsolete/tpu-mapper.el
merge master
[gnu-emacs] / lisp / obsolete / tpu-mapper.el
1 ;;; tpu-mapper.el --- create a TPU-edt X-windows keymap file
2
3 ;; Copyright (C) 1993-1995, 2001-2015 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 ;; Package: tpu-edt
9 ;; Obsolete-since: 24.5
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This Emacs Lisp program can be used to create an Emacs Lisp file that
29 ;; defines the TPU-edt keypad for Emacs running on X-Windows.
30
31 ;;; Code:
32
33 ;;;
34 ;;; Key variables
35 ;;;
36 (defvar tpu-kp4 nil)
37 (defvar tpu-kp5 nil)
38 (defvar tpu-key nil)
39 (defvar tpu-enter nil)
40 (defvar tpu-return nil)
41 (defvar tpu-key-seq nil)
42 (defvar tpu-enter-seq nil)
43 (defvar tpu-return-seq nil)
44
45 ;;;
46 ;;; Key mapping function
47 ;;;
48 (defun tpu-map-key (ident descrip func gold-func)
49 (interactive)
50 (if (featurep 'xemacs)
51 (progn
52 (setq tpu-key-seq (read-key-sequence
53 (format "Press %s%s: " ident descrip))
54 tpu-key (format "[%s]" (event-key (aref tpu-key-seq 0))))
55 (unless (equal tpu-key tpu-return)
56 (set-buffer "Keys")
57 (insert (format"(global-set-key %s %s)\n" tpu-key func))
58 (set-buffer "Gold-Keys")
59 (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))))
60 (message "Press %s%s: " ident descrip)
61 (setq tpu-key-seq (read-event)
62 tpu-key (format "[%s]" tpu-key-seq))
63 (unless (equal tpu-key tpu-return)
64 (set-buffer "Keys")
65 (insert (format"(define-key tpu-global-map %s %s)\n" tpu-key func))
66 (set-buffer "Gold-Keys")
67 (insert (format "(define-key tpu-gold-map %s %s)\n" tpu-key gold-func))))
68 (set-buffer "Directions")
69 tpu-key)
70
71 ;;;###autoload
72 (defun tpu-mapper ()
73 "Create an Emacs lisp file defining the TPU-edt keypad for X-windows.
74
75 This command displays an instruction screen showing the TPU-edt keypad
76 and asks you to press the TPU-edt editing keys. It uses the keys you
77 press to create an Emacs Lisp file that will define a TPU-edt keypad
78 for your X server. You can even re-arrange the standard EDT keypad to
79 suit your tastes (or to cope with those silly Sun and PC keypads).
80
81 Finally, you will be prompted for the name of the file to store the key
82 definitions. If you chose the default, TPU-edt will find it and load it
83 automatically. If you specify a different file name, you will need to
84 set the variable ``tpu-xkeys-file'' before starting TPU-edt. Here's how
85 you might go about doing that in your init file.
86
87 (setq tpu-xkeys-file (expand-file-name \"~/.my-emacs-x-keys\"))
88 (tpu-edt)
89
90 Known Problems:
91
92 Sometimes, tpu-mapper will ignore a key you press, and just continue to
93 prompt for the same key. This can happen when your window manager sucks
94 up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
95 Either way, there's nothing that tpu-mapper can do about it. You must
96 press RETURN, to skip the current key and continue. Later, you and/or
97 your local X guru can try to figure out why the key is being ignored."
98 (interactive)
99
100 ;; Make sure we're running X-windows
101
102 (if (not window-system)
103 (error "tpu-mapper requires running Emacs with an X display"))
104
105 ;; Make sure the window is big enough to display the instructions
106
107 (if (featurep 'xemacs) (set-screen-size (selected-screen) 80 36)
108 (set-frame-size (selected-frame) 80 36))
109
110 ;; Create buffers - Directions, Keys, Gold-Keys
111
112 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
113 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
114 (if (not (get-buffer "Gold-Keys")) (generate-new-buffer "Gold-Keys"))
115
116 ;; Put headers in the Keys buffer
117
118 (set-buffer "Keys")
119 (insert "\
120 ;; Key definitions for TPU-edt
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 ;; Save <CR> for future reference
165
166 (cond
167 ((featurep 'xemacs)
168 (setq tpu-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
169 (setq tpu-return (concat "[" (format "%s" (event-key (aref tpu-return-seq 0))) "]")))
170 (t
171 (message "Hit carriage-return <CR> to continue ")
172 (setq tpu-return-seq (read-event))
173 (setq tpu-return (concat "[" (format "%s" tpu-return-seq) "]"))))
174
175 ;; Build the keymap file
176
177 (set-buffer "Keys")
178 (insert "
179 ;; Arrows
180 ;;
181 ")
182 (set-buffer "Gold-Keys")
183 (insert "
184 ;; GOLD Arrows
185 ;;
186 ")
187 (set-buffer "Directions")
188
189 (tpu-map-key "Up-Arrow" "" "'tpu-previous-line" "'tpu-move-to-beginning")
190 (tpu-map-key "Down-arrow" "" "'tpu-next-line" "'tpu-move-to-end")
191 (tpu-map-key "Right-arrow" "" "'tpu-forward-char" "'end-of-line")
192 (tpu-map-key "Left-arrow" "" "'tpu-backward-char" "'beginning-of-line")
193
194 (set-buffer "Keys")
195 (insert "
196 ;; PF keys
197 ;;
198 ")
199 (set-buffer "Gold-Keys")
200 (insert "
201 ;; GOLD PF keys
202 ;;
203 ")
204 (set-buffer "Directions")
205
206 (tpu-map-key "PF1" " - The GOLD key" "GOLD-map" "'keyboard-quit")
207 (tpu-map-key "PF2" " - The Keypad Help key" "'tpu-help" "'help-for-help")
208 (tpu-map-key "PF3" " - The Find/Find-Next key" "'tpu-search-again" "'tpu-search")
209 (tpu-map-key "PF4" " - The Del/Undelete Line key" "'tpu-delete-current-line" "'tpu-undelete-lines")
210
211 (set-buffer "Keys")
212 (insert "
213 ;; KP0-9 KP- KP, KP. and KPenter
214 ;;
215 ")
216 (set-buffer "Gold-Keys")
217 (insert "
218 ;; GOLD KP0-9 KP- KP, and KPenter
219 ;;
220 ")
221 (set-buffer "Directions")
222
223 (tpu-map-key "KP-0" " - The Line/Open-Line key" "'tpu-line" "'open-line")
224 (tpu-map-key "KP-1" " - The Word/Change-Case key" "'tpu-word" "'tpu-change-case")
225 (tpu-map-key "KP-2" " - The EOL/Delete-EOL key" "'tpu-end-of-line" "'tpu-delete-to-eol")
226 (tpu-map-key "KP-3" " - The Character/Special-Insert key" "'tpu-char" "'tpu-special-insert")
227 (setq tpu-kp4 (tpu-map-key "KP-4" " - The Forward/Bottom key" "'tpu-advance-direction" "'tpu-move-to-end"))
228 (setq tpu-kp5 (tpu-map-key "KP-5" " - The Reverse/Top key" "'tpu-backup-direction" "'tpu-move-to-beginning"))
229 (tpu-map-key "KP-6" " - The Remove/Insert key" "'tpu-cut" "'tpu-paste")
230 (tpu-map-key "KP-7" " - The Page/Do key" "'tpu-page" "'execute-extended-command")
231 (tpu-map-key "KP-8" " - The Section/Fill key" "'tpu-scroll-window" "'tpu-fill")
232 (tpu-map-key "KP-9" " - The Append/Replace key" "'tpu-append-region" "'tpu-replace")
233 (tpu-map-key "KP--" " - The Delete/Undelete Word key" "'tpu-delete-current-word" "'tpu-undelete-words")
234 (tpu-map-key "KP-," " - The Delete/Undelete Character key" "'tpu-delete-current-char" "'tpu-undelete-char")
235 (tpu-map-key "KP-." " - The Select/Reset key" "'tpu-select" "'tpu-unselect")
236 (tpu-map-key "KP-Enter" " - The Enter key on the numeric keypad" "'newline" "'tpu-substitute")
237 ;; Save the enter key
238 (setq tpu-enter tpu-key)
239 (setq tpu-enter-seq tpu-key-seq)
240
241 (set-buffer "Keys")
242 (insert "
243 ;; Editing keypad (find, insert, remove)
244 ;; (select, prev, next)
245 ;;
246 ")
247 (set-buffer "Gold-Keys")
248 (insert "
249 ;; GOLD Editing keypad (find, insert, remove)
250 ;; (select, prev, next)
251 ;;
252 ")
253 (set-buffer "Directions")
254
255 (tpu-map-key "Find" " - The Find key on the editing keypad" "'tpu-search" "'nil")
256 (tpu-map-key "Insert" " - The Insert key on the editing keypad" "'tpu-paste" "'nil")
257 (tpu-map-key "Remove" " - The Remove key on the editing keypad" "'tpu-cut" "'tpu-store-text")
258 (tpu-map-key "Select" " - The Select key on the editing keypad" "'tpu-select" "'tpu-unselect")
259 (tpu-map-key "Prev Scr" " - The Prev Scr key on the editing keypad" "'tpu-scroll-window-down" "'tpu-previous-window")
260 (tpu-map-key "Next Scr" " - The Next Scr key on the editing keypad" "'tpu-scroll-window-up" "'tpu-next-window")
261
262 (set-buffer "Keys")
263 (insert "
264 ;; F10-14 Help Do F17
265 ;;
266 ")
267 (set-buffer "Gold-Keys")
268 (insert "
269 ;; GOLD F10-14 Help Do F17
270 ;;
271 ")
272 (set-buffer "Directions")
273
274 (tpu-map-key "F10" " - Invokes the Exit function on VT200+ terminals" "'tpu-exit" "'nil")
275 (tpu-map-key "F11" " - Inserts an Escape character into the text" "'tpu-insert-escape" "'nil")
276 (tpu-map-key "Backspace" " - Not Delete nor ^H! Sometimes on the F12 key" "'tpu-next-beginning-of-line" "'nil")
277 (tpu-map-key "F13" " - Invokes the delete previous word function" "'tpu-delete-previous-word" "'nil")
278 (tpu-map-key "F14" " - Toggles insert/overstrike modes" "'tpu-toggle-overwrite-mode" "'nil")
279 (tpu-map-key "Help" " - Brings up the help screen, same as PF2" "'tpu-help" "'describe-bindings")
280 (tpu-map-key "Do" " - Invokes the COMMAND function" "'execute-extended-command" "'nil")
281 (tpu-map-key "F17" "" "'tpu-goto-breadcrumb" "'tpu-drop-breadcrumb")
282
283 (set-buffer "Gold-Keys")
284 (cond
285 ((not (equal tpu-enter tpu-return))
286 (insert "
287 ;; Minibuffer map additions to make KP_enter = RET
288 ;;
289 ")
290
291 (insert (format "(define-key minibuffer-local-map %s 'exit-minibuffer)\n" tpu-enter))
292 ;; These are not necessary because they are inherited.
293 ;; (insert (format "(define-key minibuffer-local-ns-map %s 'exit-minibuffer)\n" tpu-enter))
294 ;; (insert (format "(define-key minibuffer-local-completion-map %s 'exit-minibuffer)\n" tpu-enter))
295 (insert (format "(define-key minibuffer-local-must-match-map %s 'minibuffer-complete-and-exit)\n" tpu-enter))))
296
297 (cond
298 ((not (or (equal tpu-kp4 tpu-return) (equal tpu-kp5 tpu-return)))
299 (insert "
300 ;; Minibuffer map additions to allow KP-4/5 termination of search strings.
301 ;;
302 ")
303
304 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-forward-exit)\n" tpu-kp4))
305 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-backward-exit)\n" tpu-kp5))))
306
307 (insert "
308 ;; Define the tpu-help-enter/return symbols
309 ;;
310 ")
311
312 (cond ((featurep 'xemacs)
313 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter-seq))
314 (insert (format "(setq tpu-help-return \"%s\")\n" tpu-return-seq))
315 (insert "(setq tpu-help-N \"[#<keypress-event N>]\")\n")
316 (insert "(setq tpu-help-n \"[#<keypress-event n>]\")\n")
317 (insert "(setq tpu-help-P \"[#<keypress-event P>]\")\n")
318 (insert "(setq tpu-help-p \"[#<keypress-event p>]\")\n"))
319 (t
320 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter))))
321
322 (append-to-buffer "Keys" 1 (point))
323 (set-buffer "Keys")
324
325 ;; Save the key mapping program
326
327 (let ((file
328 (convert-standard-filename
329 (if (featurep 'xemacs) "~/.tpu-lucid-keys" "~/.tpu-keys"))))
330 (set-visited-file-name
331 (read-file-name (format "Save key mapping to file (default %s): " file) "" file)))
332 (save-buffer)
333
334 ;; Load the newly defined keys and clean up
335
336 (require 'tpu-edt)
337 (eval-buffer)
338 (kill-buffer (current-buffer))
339 (kill-buffer "*scratch*")
340 (kill-buffer "Gold-Keys")
341
342 ;; Let them know it worked.
343
344 (switch-to-buffer "Directions")
345 (erase-buffer)
346 (insert "
347 A custom TPU-edt keymap file has been created.
348
349 Press GOLD-k to remove this buffer and continue editing.
350 ")
351 (goto-char (point-min)))
352
353 ;;; tpu-mapper.el ends here