changeset 35123:767b546e1676

Update to version 4.0. Provide support for detecting a keypress that generates an ASCII key sequence. (Previously, only a keypress that generates a vector was recognized.) Embed Window Manager name into name of the generated EDT Emulation initialization file since the initialization file is Window Manager specific. Add Commentary section to file header.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 08 Jan 2001 13:18:18 +0000
parents 19818763d299
children 0b78d7b101c2
files lisp/emulation/edt-mapper.el
diffstat 1 files changed, 218 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emulation/edt-mapper.el	Mon Jan 08 13:15:59 2001 +0000
+++ b/lisp/emulation/edt-mapper.el	Mon Jan 08 13:18:18 2001 +0000
@@ -1,6 +1,6 @@
 ;;; edt-mapper.el --- Create an EDT LK-201 Map File for X-Windows Emacs
 
-;; Copyright (C) 1994, 1995  Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 2000, 2001  Free Software Foundation, Inc.
 
 ;; Author: Kevin Gallagher <kevingal@onramp.net>
 ;; Maintainer: Kevin Gallagher <kevingal@onramp.net>
@@ -24,59 +24,90 @@
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
+;;
+
+;;  [Part of the GNU Emacs EDT Emulation.]
 
 ;;  This emacs lisp program can be used to create an emacs lisp file
-;;  that defines the mapping of the user's keyboard under X-Windows to
-;;  the LK-201 keyboard function keys and keypad keys (around which
-;;  EDT has been designed).  Please read the "Usage" AND "Known
-;;  Problems" sections before attempting to run this program.  (The
-;;  design of this file, edt-mapper.el, was heavily influenced by
-;;  tpu-mapper.el.) 
+;;  that defines the mapping of the user's keyboard to the LK-201
+;;  keyboard function keys and keypad keys (around which EDT has been
+;;  designed).  Please read the "Usage" AND "Known Problems" sections
+;;  below before attempting to run this program.  (The design of this
+;;  file, edt-mapper.el, was heavily influenced by tpu-mapper.el.)
+
+;;  Version 4.0 contains the following enhancements:
 
-;;; Usage:
+;;  1.  If you access a workstation using an X Server, note that the
+;;      initialization file generated by edt-mapper.el will now
+;;      contain the name of the X Server vendor.  This is a
+;;      convenience for those who have access to their Unix account
+;;      from more than one type of X Server.  Since different X
+;;      Servers typically require different EDT emulation
+;;      initialization files, edt-mapper.el will now generate these
+;;      different initialization files and save them with different
+;;      names.
 
-;;  Simply load this file into the X-Windows version of emacs (version 19)
+;;  2.  Also, edt-mapper.el is now capable of binding an ASCII key
+;;      sequence, providing the ASCII key sequence prefix is already
+;;      known by Emacs to be a prefix.  As a result, some
+;;      terminal/keyboard/window system configurations, which don't
+;;      have a complete set of sensible function key map bindings, can
+;;      still be configured for EDT Emulation.
+
+
+;;  Usage:
+
+;;  Simply load this file into emacs (version 19 or higher)
 ;;  using the following command.
 
 ;;    emacs -q -l edt-mapper.el
 
-;;  The "-q" option prevents loading of your .emacs file (commands therein
-;;  might confuse this program).
+;;  The "-q" option prevents loading of your .emacs file (commands
+;;  therein might confuse this program).
 
-;;  An instruction screen showing the typical LK-201 terminal functions keys
-;;  will be displayed, and you will be prompted to press the keys on your
-;;  keyboard which you want to emulate the corresponding LK-201 keys.
+;;  An instruction screen showing the typical LK-201 terminal
+;;  functions keys will be displayed, and you will be prompted to
+;;  press the keys on your keyboard which you want to emulate the
+;;  corresponding LK-201 keys.
 
 ;;  Finally, you will be prompted for the name of the file to store
 ;;  the key definitions.  If you chose the default, it will be found
 ;;  and loaded automatically when the EDT emulation is started.  If
 ;;  you specify a different file name, you will need to set the
-;;  variable "edt-xkeys-file" before starting the EDT emulation.
+;;  variable "edt-keys-file" before starting the EDT emulation.
 ;;  Here's how you might go about doing that in your .emacs file.
 
-;;    (setq edt-xkeys-file (expand-file-name "~/.my-emacs-x-keys"))
+;;    (setq edt-keys-file (expand-file-name "~/.my-emacs-keys"))
 
-;;; Known Problems:
+
+;;  Known Problems:
 
-;;  Sometimes, edt-mapper will ignore a key you press, and just continue to
-;;  prompt for the same key.  This can happen when your window manager sucks
-;;  up the key and doesn't pass it on to emacs, or it could be an emacs bug.
-;;  Either way, there's nothing that edt-mapper can do about it.  You must
-;;  press RETURN, to skip the current key and continue.  Later, you and/or
-;;  your local X guru can try to figure out why the key is being ignored.
+;;  Sometimes, edt-mapper will ignore a key you press, and just
+;;  continue to prompt for the same key.  This can happen when your
+;;  window manager sucks up the key and doesn't pass it on to emacs,
+;;  or it could be an emacs bug.  Either way, there's nothing that
+;;  edt-mapper can do about it.  You must press RETURN, to skip the
+;;  current key and continue.  Later, you and/or your local Emacs guru
+;;  can try to figure out why the key is being ignored.
 
-;; ====================================================================
+;;; History:
+;; 
+
+;;  Version 4.0    2000    Added 2 New Features
+
+;;; Code:
 
 ;;;
-;;;  Make sure we're running X-windows and Emacs version 19
+;;;  Make sure we're running Emacs version 19, or higher.
 ;;;
+
 (cond
- ((not (and window-system (not (string-lessp emacs-version "19"))))
+ ((string-lessp emacs-version "19")
   (insert "
 
     Whoa!  This isn't going to work...
 
-    You must run edt-mapper.el under X-windows and Emacs version 19.
+    You must run edt-mapper.el under Emacs version 19 or higher.
 
     Press any key to exit.  ")
   (sit-for 600)
@@ -84,10 +115,24 @@
 
 
 ;;;
-;;;  Decide whether we're running GNU or Lucid emacs.
+;;;  Decide Emacs Variant, GNU Emacs or XEmacs (aka Lucid Emacs).
+;;;  Determine Window System, and X Server Vendor (if appropriate).
 ;;;
-(defconst edt-lucid-emacs19-p (string-match "Lucid" emacs-version)
-  "Non-NIL if we are running Lucid Emacs version 19.")
+(defconst edt-x-emacs-p (string-match "XEmacs" emacs-version)
+  "Non-NIL if we are running XEmacs version 19, or higher.")
+
+(defconst edt-emacs-variant (if edt-x-emacs-p "xemacs" "gnu")
+  "Indicates Emacs variant:  GNU Emacs or XEmacs \(aka Lucid Emacs\).")
+
+(defconst edt-window-system (if edt-x-emacs-p (console-type) window-system)
+  "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
+
+(defconst edt-xserver (if (eq edt-window-system 'x)
+			  (if edt-x-emacs-p
+			      (replace-in-string (x-server-vendor) "[ _]" "-")
+			    (subst-char-in-string ?  ?- (x-server-vendor)))
+			nil)
+  "Indicates X server vendor name, if applicable.")
 
 
 ;;;
@@ -99,14 +144,23 @@
 (defvar edt-key-seq nil)
 (defvar edt-enter-seq nil)
 (defvar edt-return-seq nil)
+(defvar edt-term nil)
 
+;;;  
+;;;  Determine Terminal Type (if appropriate).
+;;;
+
+(if (and edt-window-system (not (eq edt-window-system 'tty)))
+    (setq edt-term nil)
+  (setq edt-term (getenv "TERM")))
 
 ;;;
-;;;  Make sure the window is big enough to display the instructions
-;;;
-(if edt-lucid-emacs19-p (set-screen-size nil 80 36)
-  (set-frame-size (selected-frame) 80 36))
+;;;  Make sure the window is big enough to display the instructions,
+;;;  except where window cannot be re-sized.
+;;;  
 
+(if (and edt-window-system (not (eq edt-window-system 'tty)))
+    (set-frame-size (selected-frame) 80 36))
 
 ;;;
 ;;;  Create buffers - Directions and Keys
@@ -131,56 +185,84 @@
 ;;;   Display directions
 ;;;
 (switch-to-buffer "Directions")
-(insert "
+(if (and edt-window-system (not (eq edt-window-system 'tty)))
+    (insert "
                                   EDT MAPPER
 
-    You will be asked to press keys to create a custom mapping (under
-    X-Windows) of your keypad keys and function keys so that they can emulate
-    the LK-201 keypad and function keys or the subset of keys found on a 
-    VT-100 series terminal keyboard.  (The LK-201 keyboard is the standard
-    keyboard attached to VT-200 series terminals, and above.)  
+    You will be asked to press keys to create a custom mapping (under a
+    Window Manager) of your keypad keys and function keys so that they can
+    emulate the LK-201 keypad and function keys or the subset of keys found
+    on a VT-100 series terminal keyboard.  (The LK-201 keyboard is the
+    standard keyboard attached to VT-200 series terminals, and above.)
 
     Sometimes, edt-mapper will ignore a key you press, and just continue to
     prompt for the same key.  This can happen when your window manager sucks
     up the key and doesn't pass it on to emacs, or it could be an emacs bug.
     Either way, there's nothing that edt-mapper can do about it.  You must
     press RETURN, to skip the current key and continue.  Later, you and/or
-    your local X guru can try to figure out why the key is being ignored.
+    your local system guru can try to figure out why the key is being ignored.
 
     Start by pressing the RETURN key, and continue by pressing the keys
-    specified in the mini-buffer.  If you want to entirely omit a key, 
-    because your keyboard does not have a corresponding key, for example, 
+    specified in the mini-buffer.  If you want to entirely omit a key,
+    because your keyboard does not have a corresponding key, for example,
     just press RETURN at the prompt.
 
 ")
+  (insert "
+                                  EDT MAPPER
+
+    You will be asked to press keys to create a custom mapping of your
+    keypad keys and function keys so that they can emulate the LK-201
+    keypad and function keys or the subset of keys found on a VT-100
+    series terminal keyboard.  (The LK-201 keyboard is the standard
+    keyboard attached to VT-200 series terminals, and above.)
+
+    If you are using an real LK-201 keyboard, you should map the keys
+    exactly as they are on the keyboard.
+
+    Start by pressing the RETURN key, and continue by pressing the keys
+    specified in the mini-buffer.  If you want to entirely omit a key,
+    because your keyboard does not have a corresponding key, for example,
+    just press RETURN at the prompt.
+
+"))
+
 (delete-other-windows)
 
 ;;;
-;;;  Save <CR> for future reference
+;;;  Save <CR> for future reference.
 ;;;
+;;;  For GNU Emacs, running in a Window System, first hide bindings in
+;;;  function-key-map.
+;;;  
 (cond
- (edt-lucid-emacs19-p
+ (edt-x-emacs-p
   (setq edt-return-seq (read-key-sequence "Hit carriage-return <CR> to continue "))
   (setq edt-return (concat "[" (format "%s" (event-key (aref edt-return-seq 0))) "]")))
  (t
-  (message "Hit carriage-return <CR> to continue ")
-  (setq edt-return-seq (read-event))
-  (setq edt-return (concat "[" (format "%s" edt-return-seq) "]")))) 
+  (if edt-window-system
+      (progn
+	(setq edt-save-function-key-map function-key-map)
+	(setq function-key-map (make-sparse-keymap))))
+  (setq edt-return (read-key-sequence "Hit carriage-return <CR> to continue "))))
 
 ;;;
+;;;  Remove prefix-key bindings to F1 and F2 in global-map so they can be
+;;;  bound in the EDT Emulation mode.
+;;;
+(global-unset-key [f1])
+(global-unset-key [f2])
+  
+;;;
 ;;;   Display Keypad Diagram and Begin Prompting for Keys
 ;;;
 (set-buffer "Directions")
 (delete-region (point-min) (point-max))
-(insert "
-
-
+(if (and edt-window-system (not (eq edt-window-system 'tty)))
+    (insert "
 
           PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
 
-
-
-
     Here's a picture of the standard LK-201 keypad for reference:
 
           _______________________    _______________________________
@@ -204,43 +286,72 @@
                                     |               |       |       |
                                     |_______________|_______|_______|
 
+         REMEMBER:  JUST PRESS RETURN TO SKIP MAPPING A KEY.
+
 ")
+  (progn
+    (insert "
+    GENERATING A CUSTOM CONFIGURATION FILE FOR TERMINAL TYPE:  ")
+    (insert (format "%s." edt-term))
+    (insert "
+
+          PRESS THE KEY SPECIFIED IN THE MINIBUFFER BELOW.
+
+          _______________________    _______________________________
+         | HELP  |      DO       |  |  F17  |  F18  |  F19  |  F20  |
+         |_______|_______________|  |_______|_______|_______|_______|
+          _______________________    _______________________________
+         | FIND  |INSERT |REMOVE |  |  PF1  |  PF2  |  PF3  |  PF4  |
+         |_______|_______|_______|  |_______|_______|_______|_______|
+         |SELECT |PREVIOU| NEXT  |  |  KP7  |  KP8  |  KP9  |  KP-  |
+         |_______|_______|_______|  |_______|_______|_______|_______|
+                 |   UP  |          |  KP4  |  KP5  |  KP6  |  KP,  |
+          _______|_______|_______   |_______|_______|_______|_______|
+         |  LEFT |  DOWN | RIGHT |  |  KP1  |  KP2  |  KP3  |       |
+         |_______|_______|_______|  |_______|_______|_______|  KPE  |
+                                    |      KP0      |  KPP  |       |
+                                    |_______________|_______|_______|
+
+         REMEMBER:  JUST PRESS RETURN TO SKIP MAPPING A KEY.")))
+
 
 ;;;
 ;;;  Key mapping functions
 ;;;
-(defun edt-lucid-map-key (ident descrip func gold-func)
+(defun edt-lucid-map-key (ident descrip)
   (interactive)
   (setq edt-key-seq (read-key-sequence (format "Press %s%s: " ident descrip)))
   (setq edt-key (concat "[" (format "%s" (event-key (aref edt-key-seq 0))) "]"))
   (cond ((not (equal edt-key edt-return))
-	 (set-buffer "Keys")
-	 (insert (format "    (\"%s\" . %s)\n" ident edt-key))
-	 (set-buffer "Directions"))
-	;; bogosity to get next prompt to come up, if the user hits <CR>!
-	;; check periodically to see if this is still needed...
-	(t
-	 (format "%s" edt-key)))
+         (set-buffer "Keys")
+         (insert (format "    (\"%s\" . %s)\n" ident edt-key))
+         (set-buffer "Directions"))
+        ;; bogosity to get next prompt to come up, if the user hits <CR>!
+        ;; check periodically to see if this is still needed...
+        (t
+         (set-buffer "Keys")
+         (insert (format "    (\"%s\" . \"\" )\n" ident))
+         (set-buffer "Directions")))
   edt-key)
 
 (defun edt-gnu-map-key (ident descrip)
   (interactive)
-  (message "Press %s%s: " ident descrip)
-  (setq edt-key-seq (read-event))
-  (setq edt-key (concat "[" (format "%s" edt-key-seq) "]"))
+  (setq edt-key (read-key-sequence (format "Press %s%s: " ident descrip)))
   (cond ((not (equal edt-key edt-return))
-	 (set-buffer "Keys")
-	 (insert (format "    (\"%s\" . %s)\n" ident edt-key))
-	 (set-buffer "Directions"))
-	;; bogosity to get next prompt to come up, if the user hits <CR>!
-	;; check periodically to see if this is still needed...
-	(t
-	 (set-buffer "Keys")
-	 (insert (format "    (\"%s\" . \"\" )\n" ident))
-	 (set-buffer "Directions")))
+         (set-buffer "Keys")
+         (insert (if (vectorp edt-key)
+                     (format "    (\"%s\" . %s)\n" ident edt-key)
+                   (format "    (\"%s\" . \"%s\")\n" ident edt-key)))
+         (set-buffer "Directions"))
+        ;; bogosity to get next prompt to come up, if the user hits <CR>!
+        ;; check periodically to see if this is still needed...
+        (t
+         (set-buffer "Keys")
+         (insert (format "    (\"%s\" . \"\" )\n" ident))
+         (set-buffer "Directions")))
   edt-key)
 
-(fset 'edt-map-key (if edt-lucid-emacs19-p 'edt-lucid-map-key 'edt-gnu-map-key))
+(fset 'edt-map-key (if edt-x-emacs-p 'edt-lucid-map-key 'edt-gnu-map-key))
 (set-buffer "Keys")
 (insert "
 ;;
@@ -343,28 +454,23 @@
 (set-buffer "Directions")
 (delete-region (point-min) (point-max))
 (insert "
-		       ADDITIONAL FUNCTION KEYS
+                       ADDITIONAL FUNCTION KEYS
 
-    Your keyboard may have additional function keys which do not
-    correspond to any LK-201 keys.  The EDT Emulation can be
-    configured to recognize those keys, since you may wish to add your
-    own key bindings to those keys.
+    Your keyboard may have additional function keys which do not correspond
+    to any LK-201 keys.  The EDT Emulation can be configured to recognize
+    those keys, since you may wish to add your own key bindings to those keys.
     
-    For example, suppose your keyboard has a keycap marked \"Line Del\"
-    and you wish to add it to the list of keys which can be customized
-    by the EDT Emulation.  First, assign a unique single-word name to
-    the key for use by the EDT Emulation, let's say \"linedel\", in this
-    example.  Then, at the \"EDT Key Name:\" prompt, enter \"linedel\",
-    followed by a press of the RETURN key.  Finally, when prompted,
-    press the \"Line Del\" key.  You now will be able to bind functions
-    to \"linedel\" and \"Gold-linedel\" in edt-user.el in just the same way
-    you can customize bindings of the standard LK-201 keys.
+    For example, suppose your keyboard has a keycap marked \"Line Del\" and
+    you wish to add it to the list of keys which can be customized by the EDT
+    Emulation.  First, assign a unique single-word name to the key for use by
+    the EDT Emulation, for example, \"linedel\".  Then, at the \"EDT Key
+    Name:\" prompt, enter \"linedel\", followed by a press of the RETURN key.
+    Finally, when prompted, press the \"Line Del\" key.  You now will be able
+    to bind functions to \"linedel\" and \"Gold-linedel\" in edt-user.el in
+    just the same way you can customize bindings of the LK-201 function and
+    keypad keys.
 
-    When you have no additional function keys to specify, just press
-    RETURN at the \"EDT Key Name:\" prompt.  (If you change your mind
-    AFTER you enter an EDT Key Name and before you press a key at the
-    \"Press\" prompt, you may omit the key by simply pressing RETURN at
-    the prompt.)
+    When you are done, just press RETURN at the \"EDT Key Name:\" prompt.
 ")
 (switch-to-buffer "Directions")
 ;;;
@@ -373,12 +479,17 @@
 (set-buffer "Keys")
 (insert "\
 ;;
-;;  Extra Keys 
+;;  Extra Keys
 ;;
 ")
+;;;
+;;;  Restore function-key-map.
+;;;  
+(if (and edt-window-system (not edt-x-emacs-p))
+    (setq function-key-map edt-save-function-key-map))
 (setq EDT-key-name "")
-(while (not 
-	(string-equal (setq EDT-key-name (read-string "EDT Key Name: ")) ""))
+(while (not
+        (string-equal (setq EDT-key-name (read-string "EDT Key Name: ")) ""))
   (edt-map-key EDT-key-name ""))
 
 ;
@@ -391,9 +502,17 @@
 ")
 
 ;;;
-;;;  Save the key mapping program and blow this pop stand
+;;;  Save the key mapping program
+;;;
+;;;
+;;;  Save the key mapping file
 ;;;
-(let ((file (if edt-lucid-emacs19-p "~/.edt-lucid-keys" "~/.edt-gnu-keys")))
+(let ((file (concat
+	     "~/.edt-" edt-emacs-variant
+	     (if edt-term (concat "-" edt-term))
+	     (if edt-xserver (concat "-" edt-xserver))
+	     (if edt-window-system (concat "-" (upcase (symbol-name edt-window-system))))
+	     "-keys")))
   (set-visited-file-name
    (read-file-name (format "Save key mapping to file (default %s): " file) nil file)))
 (save-buffer)