(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / emulation / tpu-mapper.el
blobdb2daf09093a4184537aafd4c3731d51d4469ee5
1 ;;; tpu-mapper.el --- create a TPU-edt X-windows keymap file
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
5 ;; Author: Rob Riepel <riepel@networking.stanford.edu>
6 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
7 ;; Keywords: emulations
9 ;; This file is part of GNU Emacs.
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.
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.
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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
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. Please read
30 ;; the "Usage" AND "Known Problems" sections before attempting to run this
31 ;; program.
33 ;;; Usage:
35 ;; Simply load this file into the X-windows version of emacs using the
36 ;; following command.
38 ;; emacs -q -l tpu-mapper
40 ;; The "-q" option prevents loading of your .emacs file (commands therein
41 ;; might confuse this program).
43 ;; An instruction screen showing the TPU-edt keypad will be displayed, and
44 ;; you will be prompted to press the TPU-edt editing keys. Tpu-mapper uses
45 ;; the keys you press to create an Emacs Lisp file that will define a
46 ;; TPU-edt keypad for your X server. You can even re-arrange the standard
47 ;; EDT keypad to suit your tastes (or to cope with those silly Sun and PC
48 ;; keypads).
50 ;; Finally, you will be prompted for the name of the file to store the key
51 ;; definitions. If you chose the default, TPU-edt will find it and load it
52 ;; automatically. If you specify a different file name, you will need to
53 ;; set the variable "tpu-xkeys-file" before starting TPU-edt. Here's how
54 ;; you might go about doing that in your .emacs file.
56 ;; (setq tpu-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
57 ;; (tpu-edt)
59 ;;; Known Problems:
61 ;; Sometimes, tpu-mapper will ignore a key you press, and just continue to
62 ;; prompt for the same key. This can happen when your window manager sucks
63 ;; up the key and doesn't pass it on to Emacs, or it could be an Emacs bug.
64 ;; Either way, there's nothing that tpu-mapper can do about it. You must
65 ;; press RETURN, to skip the current key and continue. Later, you and/or
66 ;; your local X guru can try to figure out why the key is being ignored.
68 ;;; Code:
71 ;;;
72 ;;; Make sure we're running X-windows and Emacs version 19
73 ;;;
74 (cond
75 ((not (and window-system (not (string-lessp emacs-version "19"))))
76 (error "tpu-mapper requires running in Emacs 19, with an X display")))
79 ;;;
80 ;;; Decide whether we're running Lucid Emacs or Emacs itself.
81 ;;;
82 (defconst tpu-lucid-emacs19-p (string-match "Lucid" emacs-version)
83 "Non-nil if we are running Lucid Emacs version 19.")
86 ;;;
87 ;;; Key variables
88 ;;;
89 (defvar tpu-kp4 nil)
90 (defvar tpu-kp5 nil)
91 (defvar tpu-key nil)
92 (defvar tpu-enter nil)
93 (defvar tpu-return nil)
94 (defvar tpu-key-seq nil)
95 (defvar tpu-enter-seq nil)
96 (defvar tpu-return-seq nil)
99 ;;;
100 ;;; Make sure the window is big enough to display the instructions
102 (if tpu-lucid-emacs19-p (set-screen-size (selected-screen) 80 36)
103 (set-frame-size (selected-frame) 80 36))
107 ;;; Create buffers - Directions, Keys, Gold-Keys
109 (if (not (get-buffer "Directions")) (generate-new-buffer "Directions"))
110 (if (not (get-buffer "Keys")) (generate-new-buffer "Keys"))
111 (if (not (get-buffer "Gold-Keys")) (generate-new-buffer "Gold-Keys"))
115 ;;; Put headers in the Keys buffer
117 (set-buffer "Keys")
118 (insert "\
119 ;; Key definitions for TPU-edt
125 ;;; Display directions
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.
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.
137 Here's a picture of the standard TPU/edt keypad for reference:
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 |_______________|_______|_______|
162 (delete-other-windows)
163 (goto-char (point-min))
166 ;;; Save <CR> for future reference
168 (cond
169 (tpu-lucid-emacs19-p
170 (setq tpu-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
171 (setq tpu-return (concat "[" (format "%s" (event-key (aref tpu-return-seq 0))) "]")))
173 (message "Hit carriage-return <CR> to continue ")
174 (setq tpu-return-seq (read-event))
175 (setq tpu-return (concat "[" (format "%s" tpu-return-seq) "]"))))
179 ;;; Key mapping functions
181 (defun tpu-lucid-map-key (ident descrip func gold-func)
182 (interactive)
183 (setq tpu-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
184 (setq tpu-key (concat "[" (format "%s" (event-key (aref tpu-key-seq 0))) "]"))
185 (cond ((not (equal tpu-key tpu-return))
186 (set-buffer "Keys")
187 (insert (format"(global-set-key %s %s)\n" tpu-key func))
188 (set-buffer "Gold-Keys")
189 (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
190 (set-buffer "Directions"))
191 ;; bogosity to get next prompt to come up, if the user hits <CR>!
192 ;; check periodically to see if this is still needed...
194 (format "%s" tpu-key)))
195 tpu-key)
197 (defun tpu-emacs-map-key (ident descrip func gold-func)
198 (interactive)
199 (message "Press %s%s: " ident descrip)
200 (setq tpu-key-seq (read-event))
201 (setq tpu-key (concat "[" (format "%s" tpu-key-seq) "]"))
202 (cond ((not (equal tpu-key tpu-return))
203 (set-buffer "Keys")
204 (insert (format"(global-set-key %s %s)\n" tpu-key func))
205 (set-buffer "Gold-Keys")
206 (insert (format "(define-key GOLD-map %s %s)\n" tpu-key gold-func))
207 (set-buffer "Directions"))
208 ;; bogosity to get next prompt to come up, if the user hits <CR>!
209 ;; check periodically to see if this is still needed...
211 (format "%s" tpu-key)))
212 tpu-key)
214 (fset 'tpu-map-key (if tpu-lucid-emacs19-p 'tpu-lucid-map-key 'tpu-emacs-map-key))
217 (set-buffer "Keys")
218 (insert "
219 ;; Arrows
222 (set-buffer "Gold-Keys")
223 (insert "
224 ;; GOLD Arrows
227 (set-buffer "Directions")
229 (tpu-map-key "Up-Arrow" "" "'tpu-previous-line" "'tpu-move-to-beginning")
230 (tpu-map-key "Down-arrow" "" "'tpu-next-line" "'tpu-move-to-end")
231 (tpu-map-key "Right-arrow" "" "'tpu-forward-char" "'end-of-line")
232 (tpu-map-key "Left-arrow" "" "'tpu-backward-char" "'beginning-of-line")
235 (set-buffer "Keys")
236 (insert "
237 ;; PF keys
240 (set-buffer "Gold-Keys")
241 (insert "
242 ;; GOLD PF keys
245 (set-buffer "Directions")
247 (tpu-map-key "PF1" " - The GOLD key" "GOLD-map" "'keyboard-quit")
248 (tpu-map-key "PF2" " - The Keypad Help key" "'tpu-help" "'help-for-help")
249 (tpu-map-key "PF3" " - The Find/Find-Next key" "'tpu-search-again" "'tpu-search")
250 (tpu-map-key "PF4" " - The Del/Undelete Line key" "'tpu-delete-current-line" "'tpu-undelete-lines")
252 (set-buffer "Keys")
253 (insert "
254 ;; KP0-9 KP- KP, KP. and KPenter
257 (set-buffer "Gold-Keys")
258 (insert "
259 ;; GOLD KP0-9 KP- KP, and KPenter
262 (set-buffer "Directions")
264 (tpu-map-key "KP-0" " - The Line/Open-Line key" "'tpu-line" "'open-line")
265 (tpu-map-key "KP-1" " - The Word/Change-Case key" "'tpu-word" "'tpu-change-case")
266 (tpu-map-key "KP-2" " - The EOL/Delete-EOL key" "'tpu-end-of-line" "'tpu-delete-to-eol")
267 (tpu-map-key "KP-3" " - The Character/Special-Insert key" "'tpu-char" "'tpu-special-insert")
268 (setq tpu-kp4 (tpu-map-key "KP-4" " - The Forward/Bottom key" "'tpu-advance-direction" "'tpu-move-to-end"))
269 (setq tpu-kp5 (tpu-map-key "KP-5" " - The Reverse/Top key" "'tpu-backup-direction" "'tpu-move-to-beginning"))
270 (tpu-map-key "KP-6" " - The Remove/Insert key" "'tpu-cut" "'tpu-paste")
271 (tpu-map-key "KP-7" " - The Page/Do key" "'tpu-page" "'execute-extended-command")
272 (tpu-map-key "KP-8" " - The Section/Fill key" "'tpu-scroll-window" "'tpu-fill")
273 (tpu-map-key "KP-9" " - The Append/Replace key" "'tpu-append-region" "'tpu-replace")
274 (tpu-map-key "KP--" " - The Delete/Undelete Word key" "'tpu-delete-current-word" "'tpu-undelete-words")
275 (tpu-map-key "KP-," " - The Delete/Undelete Character key" "'tpu-delete-current-char" "'tpu-undelete-char")
276 (tpu-map-key "KP-." " - The Select/Reset key" "'tpu-select" "'tpu-unselect")
277 (tpu-map-key "KP-Enter" " - The Enter key on the numeric keypad" "'newline" "'tpu-substitute")
278 ;; Save the enter key
279 (setq tpu-enter tpu-key)
280 (setq tpu-enter-seq tpu-key-seq)
282 (set-buffer "Keys")
283 (insert "
284 ;; Editing keypad (find, insert, remove)
285 ;; (select, prev, next)
288 (set-buffer "Gold-Keys")
289 (insert "
290 ;; GOLD Editing keypad (find, insert, remove)
291 ;; (select, prev, next)
294 (set-buffer "Directions")
296 (tpu-map-key "Find" " - The Find key on the editing keypad" "'tpu-search" "'nil")
297 (tpu-map-key "Insert" " - The Insert key on the editing keypad" "'tpu-paste" "'nil")
298 (tpu-map-key "Remove" " - The Remove key on the editing keypad" "'tpu-cut" "'tpu-store-text")
299 (tpu-map-key "Select" " - The Select key on the editing keypad" "'tpu-select" "'tpu-unselect")
300 (tpu-map-key "Prev Scr" " - The Prev Scr key on the editing keypad" "'tpu-scroll-window-down" "'tpu-previous-window")
301 (tpu-map-key "Next Scr" " - The Next Scr key on the editing keypad" "'tpu-scroll-window-up" "'tpu-next-window")
303 (set-buffer "Keys")
304 (insert "
305 ;; F10-14 Help Do F17
308 (set-buffer "Gold-Keys")
309 (insert "
310 ;; GOLD F10-14 Help Do F17
313 (set-buffer "Directions")
315 (tpu-map-key "F10" " - Invokes the Exit function on VT200+ terminals" "'tpu-exit" "'nil")
316 (tpu-map-key "F11" " - Inserts an Escape character into the text" "'tpu-insert-escape" "'nil")
317 (tpu-map-key "Backspace" " - Not Delete nor ^H! Sometimes on the F12 key" "'tpu-next-beginning-of-line" "'nil")
318 (tpu-map-key "F13" " - Invokes the delete previous word function" "'tpu-delete-previous-word" "'nil")
319 (tpu-map-key "F14" " - Toggles insert/overstrike modes" "'tpu-toggle-overwrite-mode" "'nil")
320 (tpu-map-key "Help" " - Brings up the help screen, same as PF2" "'tpu-help" "'describe-bindings")
321 (tpu-map-key "Do" " - Invokes the COMMAND function" "'execute-extended-command" "'nil")
322 (tpu-map-key "F17" "" "'tpu-goto-breadcrumb" "'tpu-drop-breadcrumb")
324 (set-buffer "Gold-Keys")
325 (cond
326 ((not (equal tpu-enter tpu-return))
327 (insert "
328 ;; Minibuffer map additions to make KP_enter = RET
332 (insert (format "(define-key minibuffer-local-map %s 'exit-minibuffer)\n" tpu-enter))
333 (insert (format "(define-key minibuffer-local-ns-map %s 'exit-minibuffer)\n" tpu-enter))
334 (insert (format "(define-key minibuffer-local-completion-map %s 'exit-minibuffer)\n" tpu-enter))
335 (insert (format "(define-key minibuffer-local-must-match-map %s 'minibuffer-complete-and-exit)\n" tpu-enter))))
337 (cond
338 ((not (or (equal tpu-kp4 tpu-return) (equal tpu-kp5 tpu-return)))
339 (insert "
340 ;; Minibuffer map additions to allow KP-4/5 termination of search strings.
344 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-forward-exit)\n" tpu-kp4))
345 (insert (format "(define-key minibuffer-local-map %s 'tpu-search-backward-exit)\n" tpu-kp5))))
347 (insert "
348 ;; Define the tpu-help-enter/return symbols
352 (cond (tpu-lucid-emacs19-p
353 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter-seq))
354 (insert (format "(setq tpu-help-return \"%s\")\n" tpu-return-seq))
355 (insert "(setq tpu-help-N \"[#<keypress-event N>]\")\n")
356 (insert "(setq tpu-help-n \"[#<keypress-event n>]\")\n")
357 (insert "(setq tpu-help-P \"[#<keypress-event P>]\")\n")
358 (insert "(setq tpu-help-p \"[#<keypress-event p>]\")\n"))
360 (insert (format "(setq tpu-help-enter \"%s\")\n" tpu-enter))))
362 (append-to-buffer "Keys" 1 (point))
363 (set-buffer "Keys")
366 ;;; Save the key mapping program
368 (let ((file
369 (convert-standard-filename
370 (if tpu-lucid-emacs19-p "~/.tpu-lucid-keys" "~/.tpu-keys"))))
371 (set-visited-file-name
372 (read-file-name (format "Save key mapping to file (default %s): " file) "" file)))
373 (save-buffer)
376 ;;; Load the newly defined keys and clean up
378 (eval-buffer)
379 (kill-buffer (current-buffer))
380 (kill-buffer "*scratch*")
381 (kill-buffer "Gold-Keys")
384 ;;; Let them know it worked.
386 (switch-to-buffer "Directions")
387 (erase-buffer)
388 (insert "
389 A custom TPU-edt keymap file has been created.
391 Press GOLD-k to remove this buffer and continue editing.
393 (goto-char (point-min))
395 ;;; arch-tag: bab5872f-cd3a-4c1c-aedb-047b67646f6c
396 ;;; tpu-mapper.el ends here