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