HideIfDef mode bug fixes and enhancements. This is #2 of 3 patches based
[bpt/emacs.git] / lisp / obsolete / tpu-mapper.el
CommitLineData
e8af40ee 1;;; tpu-mapper.el --- create a TPU-edt X-windows keymap file
522f9216 2
ba318903 3;; Copyright (C) 1993-1995, 2001-2014 Free Software Foundation, Inc.
522f9216
RS
4
5;; Author: Rob Riepel <riepel@networking.stanford.edu>
6;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
b7f66977 7;; Keywords: emulations
bd78fa1d 8;; Package: tpu-edt
4982861a 9;; Obsolete-since: 24.5
522f9216 10
75993094
RS
11;; This file is part of GNU Emacs.
12
ed0f493f 13;; GNU Emacs is free software: you can redistribute it and/or modify
75993094 14;; it under the terms of the GNU General Public License as published by
ed0f493f
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
75993094 17
522f9216 18;; GNU Emacs is distributed in the hope that it will be useful,
75993094
RS
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
ed0f493f 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
522f9216 25
522f9216
RS
26;;; Commentary:
27
f33e2ef1
SM
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.
522f9216
RS
30
31;;; Code:
32
522f9216
RS
33;;;
34;;; Key variables
35;;;
18376c7c
RS
36(defvar tpu-kp4 nil)
37(defvar tpu-kp5 nil)
522f9216
RS
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
522f9216 45;;;
f33e2ef1 46;;; Key mapping function
522f9216 47;;;
f33e2ef1
SM
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)
522f9216 70
f33e2ef1
SM
71;;;###autoload
72(defun tpu-mapper ()
73 "Create an Emacs lisp file defining the TPU-edt keypad for X-windows.
74
75This command displays an instruction screen showing the TPU-edt keypad
76and asks you to press the TPU-edt editing keys. It uses the keys you
77press to create an Emacs Lisp file that will define a TPU-edt keypad
78for your X server. You can even re-arrange the standard EDT keypad to
79suit your tastes (or to cope with those silly Sun and PC keypads).
80
81Finally, you will be prompted for the name of the file to store the key
82definitions. If you chose the default, TPU-edt will find it and load it
83automatically. If you specify a different file name, you will need to
84set the variable ``tpu-xkeys-file'' before starting TPU-edt. Here's how
865fe16f 85you might go about doing that in your init file.
f33e2ef1
SM
86
87 (setq tpu-xkeys-file (expand-file-name \"~/.my-emacs-x-keys\"))
88 (tpu-edt)
89
90Known Problems:
91
92Sometimes, tpu-mapper will ignore a key you press, and just continue to
93prompt for the same key. This can happen when your window manager sucks
94up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
95Either way, there's nothing that tpu-mapper can do about it. You must
96press RETURN, to skip the current key and continue. Later, you and/or
97your local X guru can try to figure out why the key is being ignored."
98 (interactive)
522f9216 99
f33e2ef1 100 ;; Make sure we're running X-windows
522f9216 101
f33e2ef1
SM
102 (if (not window-system)
103 (error "tpu-mapper requires running Emacs with an X display"))
522f9216 104
f33e2ef1
SM
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 "\
522f9216
RS
120;; Key definitions for TPU-edt
121;;
122")
123
f33e2ef1 124 ;; Display directions
522f9216 125
f33e2ef1
SM
126 (switch-to-buffer "Directions")
127 (insert "
522f9216 128 This program prompts you to press keys to create a custom keymap file
23e16ac4 129 for use with the x-windows version of Emacs and TPU-edt.
522f9216
RS
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")
f33e2ef1
SM
161 (delete-other-windows)
162 (goto-char (point-min))
522f9216 163
f33e2ef1 164 ;; Save <CR> for future reference
522f9216 165
f33e2ef1
SM
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) "]"))))
522f9216 174
f33e2ef1 175 ;; Build the keymap file
522f9216 176
f33e2ef1
SM
177 (set-buffer "Keys")
178 (insert "
522f9216
RS
179;; Arrows
180;;
181")
f33e2ef1
SM
182 (set-buffer "Gold-Keys")
183 (insert "
522f9216
RS
184;; GOLD Arrows
185;;
186")
f33e2ef1 187 (set-buffer "Directions")
522f9216 188
f33e2ef1
SM
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")
522f9216 193
f33e2ef1
SM
194 (set-buffer "Keys")
195 (insert "
522f9216
RS
196;; PF keys
197;;
198")
f33e2ef1
SM
199 (set-buffer "Gold-Keys")
200 (insert "
522f9216
RS
201;; GOLD PF keys
202;;
203")
f33e2ef1 204 (set-buffer "Directions")
522f9216 205
f33e2ef1
SM
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")
522f9216 210
f33e2ef1
SM
211 (set-buffer "Keys")
212 (insert "
522f9216
RS
213;; KP0-9 KP- KP, KP. and KPenter
214;;
215")
f33e2ef1
SM
216 (set-buffer "Gold-Keys")
217 (insert "
522f9216
RS
218;; GOLD KP0-9 KP- KP, and KPenter
219;;
220")
f33e2ef1
SM
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 "
522f9216
RS
243;; Editing keypad (find, insert, remove)
244;; (select, prev, next)
245;;
246")
f33e2ef1
SM
247 (set-buffer "Gold-Keys")
248 (insert "
522f9216
RS
249;; GOLD Editing keypad (find, insert, remove)
250;; (select, prev, next)
251;;
252")
f33e2ef1 253 (set-buffer "Directions")
522f9216 254
f33e2ef1
SM
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")
522f9216 261
f33e2ef1
SM
262 (set-buffer "Keys")
263 (insert "
522f9216
RS
264;; F10-14 Help Do F17
265;;
266")
f33e2ef1
SM
267 (set-buffer "Gold-Keys")
268 (insert "
522f9216
RS
269;; GOLD F10-14 Help Do F17
270;;
271")
f33e2ef1
SM
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 "
522f9216
RS
287;; Minibuffer map additions to make KP_enter = RET
288;;
289")
290
f33e2ef1
SM
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))))
522f9216 296
f33e2ef1
SM
297 (cond
298 ((not (or (equal tpu-kp4 tpu-return) (equal tpu-kp5 tpu-return)))
299 (insert "
18376c7c
RS
300;; Minibuffer map additions to allow KP-4/5 termination of search strings.
301;;
302")
303
f33e2ef1
SM
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))))
18376c7c 306
f33e2ef1 307 (insert "
522f9216
RS
308;; Define the tpu-help-enter/return symbols
309;;
310")
311
f33e2ef1
SM
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))))
522f9216 321
f33e2ef1
SM
322 (append-to-buffer "Keys" 1 (point))
323 (set-buffer "Keys")
522f9216 324
f33e2ef1 325 ;; Save the key mapping program
522f9216 326
f33e2ef1
SM
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)
06bc58d8 333
f33e2ef1
SM
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 "
06bc58d8
RS
347 A custom TPU-edt keymap file has been created.
348
349 Press GOLD-k to remove this buffer and continue editing.
350")
f33e2ef1 351 (goto-char (point-min)))
522f9216
RS
352
353;;; tpu-mapper.el ends here