tpu-mapper.el 14 KB

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