🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #2067

GNU Emacs FAQ (4/5, 125-151): Keybindings/Output

#2067
From: Steven Byrnes
Date: Tue, 05 Jan 1993 17:19
1006 lines
47399 bytes
Archive-Name: GNU-Emacs-FAQ/part4
Last-Modified: Tue, 5 Jan 1993 14:29:28 GMT
Last-Posted: Tue, 5 Jan 1993 17:19:33 GMT

                    GNU Emacs FAQ: Keybindings/Output

If you are viewing this text in a GNU Emacs Buffer, you can type "M-2 C-x $" to
get an overview of just the questions.  Then, when you want to look at the text
of the answers, just type "C-x $".

To search for a question numbered XXX, type "M-C-s ^XXX:", followed by a C-r if
that doesn't work, then type ESC to end the search.

A `+' in the 78th column means something was inserted on the line.  A `-' means
something was deleted and a `!' means some combination of insertions and
deletions occurred.

Full instructions for getting the latest FAQ are in question 22.  Also see the
`Introduction to news.answers' posting in the `news.answers' newsgroup, or send
e-mail to `mail-server@rtfm.mit.edu' with `help' on a body line, or use FTP,
WAIS, or Prospero to rtfm.mit.edu.



Changing Key Bindings and Handling Key Binding Problems

125: How do I bind keys (including function keys) to commands?
  
  1. Find out what character sequence is generated by the keystroke sequence
     you wish to bind to a command.  See question 129 for how to do this.
     Keep in mind that the character sequences generated by a keystroke
     sequence varies from one terminal to another.  You may also get
     different results depending on what type of machine you are running on
     (see question 128).  For example, these keystrokes may generate these
     character sequences:
  
       F1        ---> ESC [ 2 2 4 z
       Shift-R10 ---> ESC O t
       L7        ---> ESC [ 3 1 ~
       Remove    ---> C-@
  
  2. Figure out what the Emacs Lisp syntax is for this character sequence.
     Inside an Emacs Lisp string, RET, LFD, DEL, ESC, SPC, and TAB are
     specified with `\r', `\n', `\C-?', `\e', ` ', and `\t'.  C-x is
     specified by `\C-x'.  M-x is specified the same was as "ESC x".
     (Control characters may also be specified as themselves, but I don't
     recommend it.)  An Emacs Lisp string begins and ends with the double
     quote character, `"'.  Here are some examples:
  
       ESC [ D       ---> "\e[D"
       ESC [ 2 2 7 z ---> "\e[227z"
       ESC [ 1 8 ~   ---> "\e[18~"
       C-M-r         ---> "\e\C-r"
  
  3. If some prefix of the character sequence is already bound, you must
     unbind it by binding it to `nil'.  For example:
  
       (global-set-key "\e[" nil)
  
  4. Pick a command to bind your key sequence to.  A command can be a
     "symbol" with a function definition, or a "lambda list", or a string
     (which is treated as a macro).  For example:
  
       (global-set-key "\e[D" 'backward-char)
       (global-set-key "\e[227~" "\exgoto-line\r") ; macro
  
  See `Key Bindings' and `Rebinding' in the online manual.
  
  In Emacs 19 (including Lucid Emacs), you can bind function key F24 like
  this:
  
    (global-set-key 'f24 'some-command)
  
126: Why does Emacs say `Key sequence XXX uses invalid prefix characters'?
  
  A prefix of the character sequence you were trying to bind was already
  bound.  Usually, the sequence is "ESC [", in which case you should
  evaluate this form first:
  
    (define-key esc-map "[" nil)
  
  NOTE: By default, "ESC [" is bound to backward-paragraph, and if you do
  this you will lose this key binding.  For most people, this is not a
  problem.
  
  See question 125.
  
127: Why doesn't this [terminal or window-system setup] code work in my
 .emacs file, but it works just fine after Emacs starts up?
  
  This is because you're trying to do something in your .emacs file that
  needs to be postponed until after the terminal/window-system setup code
  is loaded.  This is a result of the order in which things are done
  during the startup of Emacs.  For more details see question 135.
  
  In order to postpone the execution of Emacs Lisp code until after the
  terminal/window-system setup, set the value of the variable
  term-setup-hook or window-setup-hook to be a function which does what
  you want.
  
  See etc/OPTIONS for a complete explanation of what Emacs does every time
  it is started.
  
  Here is a simple example of how to set term-setup-hook:
  
    (setq term-setup-hook
	  (function
	   (lambda ()
	     (cond ((string-match "\\`vt220" (or (getenv "TERM") ""))
		    ;; Make vt220's "Do" key behave like M-x:
		    (define-key CSI-map "29~" 'execute-extended-command))
		   ))))
  
128: How do I use function keys under X Windows?
  
  This depends on whether you are running Emacs inside a terminal emulator
  window, or whether you are allowing Emacs to create its own X window.
  You can tell which you are doing by noticing whether Emacs creates a new
  window when you start it.
  
  If you are running Emacs inside a terminal emulator window, then it
  behaves exactly as it does on any other tty.  In this case, for function
  keys to be useful, they must generate character sequences that are sent
  to the programs running inside the window as input.  The `xterm' program
  has two different sets of character sequences that it generates when
  function keys are pressed, depending on the sunFunctionKeys X resource
  and the -sf and +sf command line options.  (To find out what these key
  sequences are, see question 129.)  In addition, with xterm,
  you can override what key sequence a specific function key (or any other
  key) will generate with the `translations' resource.  This, for example:
  
    XTerm.VT100.Translations: #override \
      <KeyPress>F1: string(0x1b) string("[xyzzy")
  
  makes the function key F1 generate the character sequence "ESC [xyzzy".
  
  On the other hand, if Emacs is managing its own X window, the following
  description applies.  Emacs receives `KeyPress' events from the X server
  when a key is pressed while the keyboard focus is in its window.  The
  KeyPress event contains an X "keysym" code, which is simply an arbitrary
  number corresponding to the name of the keysym, and information on which
  "modifiers" such as `control' and `shift' are active.  For example, the
  `Tab' keysym is 0xff09.  (Generally, a key on the keyboard will generate a
  keysym whose name is the same as the label on the key, ie. the `Tab' key
  will normally generate the `Tab' keysym.  This can be changed with the
  xmodmap program.)  Emacs recognizes all the keysyms that correspond to
  standard ASCII characters and internally uses the ASCII character instead.
  
  (WARNING: I am about to describe a gross, disgusting hack to you, have
  your barf bag ready.)
  
  When Emacs receives the X keysym of one of the arrow keys, it behaves
  the same as if it had received a letter key with the control modifier
  down as follows (this is hard-coded):
  
    Up    becomes C-p
    Down  becomes C-n
    Right becomes C-f
    Left  becomes C-b
  
  The way Emacs treats other keysyms depends on what kind of machine it was
  compiled on.  The type of the display machine is irrelevant!  Function
  keys are mapped internally to escape sequences, while other keys are
  completely ignored.
  
  1. If compiled on a Sun, Emacs recognizes these X keysyms that
     are normally on a Sun keyboard:
  
       F1 through F9
       L1 through L10 (same as F11 through F20)
       R1 through R15 (same as F21 through F35)
	 (The keys labelled R8, R10, R12, and R14 usually are mapped to the
	  X keysyms Up, Left, Right, and Down.)
       Break (the `Alternate' key is given this keysym)
  
     These keys work like Sun function keys.  When Emacs recieves the
     keysym, it will internally use character sequences that look like "ESC
     [ ### z", where ### is replaced by a number.  The character sequences
     are identical to those generated by Sun's keyboard under SunView.  Any
     function key not listed above generates "ESC [ - 1 z".
  
     In order to use these key sequences, they should be bound to commands
     using the standard key binding methods, just as if Emacs were running
     on a regular terminal.
  
     WARNING: F11 and L1 are the same keysym in X, as are F12 and L2, etc.
     {Yes, this is stupid.  Complain to the X consortium.}
  
  2. If not compiled on a Sun, the function keys will appear to Emacs in a
     way remarkably similar to the keys of a DEC LK201 keyboard (used on
     some VT series terminals).  These X keysyms will be recognized:
  
       F1 through F20
       Help (treated same as F15)
       Menu (treated same as F16, is the LK201 `Do' key)
       Find
       Insert (LK201 `Insert Here' key)
       Select
       Prior (LK201 `Prev Screen' key *** ONLY IN 18.58 AND LATER ***)
       Next (LK201 `Next Screen' key *** ONLY IN 18.58 AND LATER ***)
  
     And finally, the LK201 key labelled `Remove' (or `Delete') is often
     mapped to the Delete keysym which generates the DEL character (C-?)
     instead of the key sequence given by the LK201 `Remove' key.  It may
     also be mapped to some other keysym, such as `_Remove', in which case
     you can't use it from within Emacs at all.
  
     Each function key will be internally converted to a character sequence
     that looks like "ESC [ ## ~", where ## is replaced by a number.  The
     character sequences are identical to those generated by a LK201
     keyboard.  Any function key not listed above generates "ESC [ - 1 ~".
  
  For the complete list of the numbers which are generated by the function
  keys, look in the file src/x11term.c at the definitions of the function
  stringFuncVal.
  
  If you are running Emacs on a Sun machine, even if your X display is
  running on a non-Sun machine (eg., an X terminal), you get the setup
  described above for Suns.  The determining factor is what type of
  machine Emacs is running (was compiled) on, not what type of machine
  your X display is on.
  
  If you have function keys not listed above on your keyboard, you can use
  `xmodmap' to change their keysym assignments to get keys that Emacs will
  recognize, but that may screw up other programs.
  
  X resources are not used by Emacs to affect the key sequences generated.
  In particular, there are no X key "translations" for Emacs.
  
  If you have function keys not listed above and you don't want to use
  xmodmap to change their names, you might want to make a modification to
  your Emacs.  Johan Vromans <jv@mh.nl> has made available a patch for Emacs
  that adds the x-rebind-key function of Epoch to Emacs 18.58.  This allows
  another layer of key rebinding before Emacs even sees the keys, and in
  this layer you can rebind all of the keys and modifier combinations as
  well.
  
  Anonymous FTP:
    /ftp.eu.net:gnu/emacs/FP-Xfun.Z
    /ftp.urc.tue.nl:pub/tex/emacs/FP-Xfun
  
  Johan Vromans explains what this buys for you:
  
    After implementing this, all keyboard keys can be configured to send
    user definable sequences, eg.,
  
      (x-rebind-key "KP_F1" 0 "\033OP")
  
    This will have the keypad key PF1 send the sequence "ESC O P", just like
    an ordinary VT series terminal.
  
129: How do I tell what characters my function or arrow keys emit?
  
  Use this function by Randal L. Schwartz <merlyn@iwarp.intel.com>:
  
    (defun see-chars ()
      "Displays characters typed, terminated by a 3-second timeout."
      (interactive)
      (let ((chars "")
	    (inhibit-quit t))
	(message "Enter characters, terminated by 3-second timeout.")
	(while (not (sit-for 3))
	  (setq chars (concat chars (list (read-char)))
		quit-flag nil))		; quit-flag maybe set by C-g
	(message "Characters entered: %s" (key-description chars))))
  
  Alternatively, use the "C-h l" view-lossage command, which will display
  the last 100 characters Emacs has seen in its input stream.  Kevin
  Gallagher <kgallagh@digi.lonestar.org> suggests typing some unique string
  like "wxyz", typing the key in question, then typing "C-h l".  The
  characters that appear between "wxyz" and "C-h l" were generated by the
  key.
  
130: How do I set the X key "translations" for Emacs?
  
  Sorry, you can't; there are no "translations" to be set.  Emacs is not
  written using the Xt library.  The only way to affect the behavior of keys
  within Emacs is through `xmodmap' (outside Emacs) or `define-key' (inside
  Emacs).
  
131: How do I handle C-s and C-q being used for flow control?
  
  C-s and C-q are used in the XON/XOFF flow control protocol.  This screws
  up Emacs because it binds these characters to commands.  Also, by default
  Emacs will not honor them as flow control characters and may overwhelm
  output buffers.  Sometimes, intermediate software using XON/XOFF flow
  control will prevent Emacs from ever seeing C-s and C-q.
  
  Possible solutions:
  
  * Disable the use of C-s and C-q for flow control.
  
    You need to determine what is the cause of the flow control.
  
    * your terminal
  
      Your terminal may use XON/XOFF flow control to have time to display
      all the characters it receives.  For example, VT series terminals do
      this.  It may be possible to turn this off from a setup menu.  For
      example, on a VT220 you may select `No XOFF' in the setup menu.  This
      is also true for some terminal emulation programs on PCs.
  
      When you turn off flow control at the terminal, you will also need to
      turn it off at the other end, which might be at the computer you are
      logged in to or at some terminal server in between.
  
      If you turn off flow control, characters may be lost; using a printer
      connected to the terminal may fail.  You may be able to get around
      this problem by modifying the `termcap' entry for your terminal to
      include extra NUL padding characters. 
  
    * a modem
  
      If you are using a dialup connection, the modems may be using XON/XOFF
      flow control.  I don't know how to get around this.
  
    * a router or terminal server
  
      Some network box between the terminal and your computer may be using
      XON/XOFF flow control.  It may be possible to make it use some other
      kind of flow control.  You will probably have to ask your local
      network experts for help with this.
  
    * tty and/or pty devices
  
      If your connection to Emacs goes through multiple tty and/or pty
      devices, they may be using XON/XOFF flow control even when it is not
      necessary.
  
      Eirik Fuller <eirik@theory.tn.cornell.edu> writes:
  
        Some versions of `rlogin' (and possibly telnet) do not pass flow
        control characters to the remote system to which they connect.  On
        such systems, Emacs on the remote system cannot disable flow control
        on the local system.  Sometimes `rlogin -8' will avoid this problem.
  
        One way to cure this is to disable flow control on the local host
        (the one running rlogin, not the one running rlogind) using the stty
        command, before starting the rlogin process.  On many systems, `stty
        start u stop u' will do this.
  
        Some versions of `tcsh' will prevent even this from working.  One
        way around this is to start another shell before starting rlogin,
        and issue the stty command to disable flow control from that shell.
  
      Use `stty -ixon' instead of `stty start u stop u' on some systems.
  
  * Make Emacs speak the XON/XOFF flow control protocol.
  
    You can make Emacs treat C-s and C-q as flow control characters by
    evaluating this form:
  
      (set-input-mode nil t)
  
    If you are fixing this for yourself, simply put the form in your .emacs
    file.  If you are fixing this for your entire site, the best place to
    put it is unclear.  I don't know if this has any effect when used in
    lisp/site-init.el when building Emacs; I've never tried that.  {Can
    someone tell me whether it works?}  Putting things in users' .emacs files
    has a number of problems.
  
    Putting this form in lisp/default.el has the problem that if the user's
    .emacs file has an error, this will prevent lisp/default.el from being
    loaded and Emacs may be unusable for the user, even for correcting their
    .emacs file (unless they're smart enough to move it to another name).  A
    possible solution is to initially disable C-s and C-q by setting
    keyboard-translate-table in lisp/site-init.el, either with swap-keys
    (see question 136) or with the following form:
  
      ;; by Roger Crew <crew@cs.stanford.edu>:
      (setq keyboard-translate-table
            "\C-@\C-a\C-b\C-c\C-d\C-e\C-f\C-g\C-h\C-i\C-j\C-k\C-l\C-m\C-n\C-o\C-p\C-^\C-r\C-\\\C-t\C-u\C-v\C-w\C-x\C-y\C-z\C-[\C-s\C-]\C-q\C-_")
  
    This will at least prevent Emacs from being confused by the flow control
    characters, even if lisp/default.el cannot be loaded.  Then, in
    lisp/default.el, enable XON/XOFF flow control with set-input-mode.
  
  For further discussion of this issue, read the file PROBLEMS in the
  Emacs distribution.
  
132: How do I use commands bound to C-s and C-q (or any key) if these keys
 are filtered out?
  
  I suggest swapping C-s with C-\ and C-q with C-^:
  
    (swap-keys ?\C-s ?\C-\\)
    (swap-keys ?\C-q ?\C-^)
  
  See question 136 for the implementation of swap-keys.  This method
  has the advantage that it simultaneously swaps the characters everywhere
  throughout Emacs, while just switching the keybindings will miss important
  places where the character codes are stored (eg., the search-repeat-char
  variable, major mode keymaps, etc.).
  
  To do this for an entire site, you may want to swap the keys in
  lisp/default.el.  If only some of your users are connecting through
  XON/XOFF flow-controlled connections, you will want to do this
  conditionally.  I suggest pre-swapping them in lisp/site-init.el when
  Emacs is built, and then in lisp/default.el, if it is determined to be
  safe, they can be reenabled (being careful not to screw up any other key
  mappings users might have established using keyboard-translate-table).
  See question 131 for an easy way to pre-swap these keys.
  
  WARNING: If you do this for an entire site, the users will be confused by
  the disparity between what the documentation says and how Emacs actually
  behaves.
  
133: Why does the `BackSpace' key invoke help?
  
  The BackSpace key (on every keyboard I've used) generates ASCII code 8.
  C-h sends the same code.  In Emacs by default C-h invokes help-command.
  This is intended to be easy to remember since the first letter of "help"
  is "h".  The easiest solution to this problem is to use C-h (and
  BackSpace) for help and DEL (the Delete key) for deleting the previous
  character.
  
  For many people this solution may be problematic:
  
  * They normally use BackSpace outside of Emacs for deleting the previous
    character typed.  This can be solved by making DEL be the command for
    deleting the previous character outside of Emacs.  This command will do
    this on many Unix systems:
  
      stty erase '^?'
  
  * The person may prefer using the BackSpace key for deleting the previous
    character because it is more conveniently located on their keyboard or
    because they don't even have a separate Delete key.  In this case, the
    BackSpace key should be made to behave like Delete.  There are several
    methods.
  
    * Under X Windows, the easiest solution is to change the BackSpace key
      into a Delete key like this:
  
        xmodmap -e "keysym BackSpace = Delete"
  
    * Some terminals (eg., VT3## terminals) allow the character generated by
      the BackSpace key to be changed from a setup menu.
  
    * You may be able to get a keyboard that is completely programmable.
  
    * Under X or on a dumb terminal, it is possible to swap the BackSpace
      and Delete keys inside Emacs:
  
        (swap-keys ?\C-h ?\C-?)
  
      See question 136 for the implementation of swap-keys.
  
    * Another approach is to switch keybindings and put help on "C-x h"
      instead:
  
        (global-set-key "\C-h" 'delete-backward-char)
        (global-set-key "\C-xh" 'help-command) ; override mark-whole-buffer
  
      Other popular key bindings for help are M-? and "C-x ?".
  
      WARNING: Don't try to bind DEL to help-command, because there are many
      modes that have local bindings of DEL that will interfere.
  
134: Why doesn't Emacs look at the stty settings for Backspace vs. Delete?
  
  Good question!
  
135: Why don't the arrow keys work?
  
  When Emacs starts up, it doesn't know anything about arrow keys at all
  (except when running under X, see question 128).  During the process of
  starting up, Emacs will load a terminal-specific initialization file for
  your terminal type (as determined by the environment variable TERM), if
  one exists.  This file has the responsibility for enabling the arrow keys.
  
  There are several things that can go wrong:
  
  1. There is no initialization file for your terminal.
  
     You can determine this by looking in the lisp/term directory.  If your
     terminal type (as determined by the TERM environment variable) is
     xxx-yy-z, then the first of these files in the lisp/term directory will
     be loaded as the terminal-specific initialization file: xxx-yy-z.el,
     xxx-yy.el, or xxx.el.
  
     There are two major cases of this problem:
  
     * Your terminal type is very similar to one that has an init file.
  
       In this case, there are several techniques suggested by Colin Jensen
       <cjensen@ampex.com>, Ben Liblit <Liblit@cs.psu.edu>, and Marc
       Auslander <marc@watson.ibm.com>:
  
       A. Add a symbolic link in lisp/term for your terminal type that
          points to the similar type.  For example, you could make VT102
          terminals work with this command:
  
            ln -s vt100.el vt102.el
  
          This fixes things for everyone on the system who uses the terminal
          type.
  
       B. If you can't do the solution in part A, you can add code to your
          term-setup-hook that loads the correct file like this:
  
            (setq term-setup-hook
                  (function
                   (lambda ()
                     (cond ((equal "vt102" (or (getenv "TERM") ""))
                            (load (concat term-file-prefix "vt100")))
                           (;; Code for other terminal types goes here ...
                            )))))
  
       C. If you use `tset' to set your TERM environment variable when you
          login, you can use the `-m' switch to tell tset to use a terminal
          type known by Emacs instead of another similar one.  For example,
          specifying this:
  
            tset ... -m 'dec-vt220:vt220' ...
  
          will make tset say you are on a `vt220' instead of a `dec-vt220'.
  
       D. Interactively, you can type "M-x load-library RET term/vt100" to
          load the terminal-specific initialization files for VT100
          terminals.
  
     * Your terminal type is not similar to one that has an init file.
  
       One can be made for your terminal, or you can just add code to your
       own .emacs to handle this problem for yourself.  For example, if your
       terminal's arrow keys send these character sequences:
  
         Up:    ESC [ A
         Down:  ESC [ B
         Right: ESC [ C
         Left:  ESC [ D
  
       then you can bind these keys to the appropriate commands with code in
       your .emacs like this:
  
         (setq term-setup-hook
               (function
                (lambda ()
                  (cond ((string-match "\\`xyzzy" (or (getenv "TERM") ""))
                         ;; First, must unmap the binding for left bracket
                         (or (keymapp (lookup-key global-map "\e\["))
                             (define-key global-map "\e\[" nil))
                         ;; Enable terminal type xyzzy's arrow keys:
                         (define-key global-map "\e\[A" 'previous-line)
                         (define-key global-map "\e\[B" 'next-line)
                         (define-key global-map "\e\[C" 'forward-char)
                         (define-key global-map "\e\[D" 'backward-char))
                        ((string-match "\\`abcde" (or (getenv "TERM") ""))
                         ;; Do something different for terminal type abcde
                         ;; .....
                         )))))
  
     NOTE: You may have to restart Emacs to get changes to take effect.
  
     NOTE: Your arrow keys may send sequences beginning with "ESC O" when
     Emacs is running, even if they send sequences beginning with "ESC [" at
     all other times.  This is because Emacs uses any command there may be
     in your terminal's termcap entry for putting the terminal into
     "Application Keypad Mode".  Just map these sequences the same way as
     above.
  
  The next two cases are problems even if there is a initialization file for
  your terminal type.
  
  2. The initialization file for your terminal doesn't bind arrow keys.
  
     If your terminal type is `xterm', you will have to bind the arrow keys
     as in part 1 above, since the xterm.el file doesn't do anything useful.
     There may be other terminal types with the same problem.
  
  3. Your terminal's arrow keys send individual control characters.
  
     For example, the arrow keys on an ADM-3 send C-h, C-j, C-k, and C-l.
  
     There is not much Emacs can do in this situation, since all the control
     characters except for C-^ and C-\ are already used as Emacs commands.
     It may be possible to convince the terminal to send something else when
     you press the arrow keys; it is worth investigating.
  
     You have to make the hard choices of how to rebind keys to commands to
     make things work the way you want.  Another alternative is to start
     learning the standard Emacs keybindings for moving point around: C-b,
     C-f, C-p, and C-n.  Personally, I no longer use the arrow keys when
     editing because I have switched keyboards so many times.
  
  4. Your terminal's arrow keys send sequences beginning with "ESC [".
  
     Due to an extremely poor design decision (ie., these sequences are ANSI
     standard), none of the the terminal-specific initialization files that
     are distributed with Emacs will bind these character sequences to the
     appropriate commands by default.  (This also applies to any other
     function keys which generate character sequences starting with "ESC
     [".)  This is because it was deemed far more important to preserve the
     binding of M-[ to the backward-paragraph command.  It appears that this
     will change in Emacs 19.
  
     Some of the terminal-specific initialization files that come with Emacs
     provide a command enable-arrow-keys that will fix this problem.  To get
     this automatically invoked, put this in your .emacs:
  
       (setq term-setup-hook
	     (function
	      (lambda ()
		(if (fboundp 'enable-arrow-keys) (enable-arrow-keys)))))
  
     We put this in our lisp/default.el file, so users don't have to worry
     about it:
  
       ;; don't override a user's term-setup-hook
       (or term-setup-hook
	   (setq term-setup-hook
		 (function
		  (lambda ()
		    (and (fboundp 'enable-arrow-keys)
			 ;; don't override a user key mapping
			 (eq 'backward-paragraph (lookup-key esc-map "["))
			 (enable-arrow-keys))))))
  
     If your terminal type is `sun', you should put this in your .emacs
     instead (or in addition to the above):
  
       (setq sun-esc-bracket t)
  
     It is possible that the terminal-specific initialization file for your
     terminal type was written locally and does not follow the rule
     mentioned above.  In this case you may need to inspect it to find out
     how to enable the arrow keys.  (Actually, if it was written locally, it
     probably enables the arrow keys by default.)
  
136: How do I "swap" two keys?
  
  When Emacs receives a character, you can make Emacs behave as though it
  received another character by setting the value of
  keyboard-translate-table.  The following Emacs Lisp will do this for you,
  allowing you to "swap" keys.  After arranging for this Lisp to be
  evaluated by Emacs, you can evaluate `(swap-keys ?A ?B)' to swap A and B.
  
    (defun swap-keys (key1 key2)
      "Swap keys KEY1 and KEY2 using map-key."
      (map-key key1 key2)
      (map-key key2 key1))
  
    (defun map-key (from to)
      "Make key FROM behave as though key TO was typed instead."
      (setq keyboard-translate-table
	    (concat keyboard-translate-table
		    (let* ((i (length keyboard-translate-table))
			   (j from)
			   (k i)
			   (str (make-string (max 0 (- j (1- i))) ?X)))
		      (while (<= k j)
			(aset str (- k i) k)
			(setq k (1+ k)))
		      str)))
      (aset keyboard-translate-table from to)
      (let ((i (1- (length keyboard-translate-table))))
	(while (and (>= i 0) (eq (aref keyboard-translate-table i) i))
	  (setq i (1- i)))
	(setq keyboard-translate-table
	      (if (eq i -1)
		  nil
		(substring keyboard-translate-table 0 (1+ i))))))
  
  NOTE: You must evaluate the definition of these functions before calling
  them!  For example, list the function definitions before their use in your
  .emacs file.
  
  NOTE: These functions take two numbers as arguments.  The example above,
  `(swap-keys ?A ?B)' is actually `(swap-keys 65 66)', because `?A' is
  merely notation for 65, the ASCII value of `A'.
  
  NOTE: These functions only work for single characters.  You cannot swap
  two multi-character sequences.
  
137: How do I produce C-XXX with my keyboard?
  
  For C-@ and C-^, often you can just type Control-2 and Control-6.  For
  C-_, you may have to hold down the shift key, typing Control-Shift-Hyphen.
  C-@ can often be generated by typing Control-Space.  C-@ is often called
  the NUL character, and has ASCII value 0.  C-_ can often be generated by
  typing Control-7 or Control-/.  C-? (aka DEL) may be generated by typing
  Shift-BackSpace or Control-BackSpace or a key labelled Delete or Del.
  
  Try Control with all of the digits on your keyboard to see what gets
  generated.
  
138: What if I don't have a Meta key?
  
  Instead of typing M-a, you can type "ESC a" instead.  In fact, Emacs
  converts M-a internally into "ESC a" anyway (depending on the value of
  meta-prefix-char).
  
139: What if I don't have an Escape key?
  
  Type C-[ instead.  This should send ASCII code 27 just like an Escape
  key would.  Try also C-;.
  
140: How do I type DEL on PC terminal emulators?
  
  Some IBM PC compatibles do not have a key labeled `Del' or `Delete' {is
  this true?}.  Those that do generally have it in an inconvenient location.
  (Also, in some terminal emulators, the `Del' key does not transmit DEL.)
  The result is the standard "BackSpace invoking help" problem (see question
  133).
  
  The usual solution, suggested by Michael Covington
  <mcovingt@aisun1.ai.uga.edu>, is to somehow tell the terminal emulator
  program that BackSpace should transmit DEL.  Read the program's manual.
  Shift-BackSpace or Control-BackSpace may send DEL.  The `Del' key may only
  send DEL if the NumLock key hasn't been pressed.
  
141: Can I make my `Compose Character' key behave like a Meta key?
  
  On a dumb terminal such as a VT220, no.  It is rumored that certain VT220
  clones could have their Compose key configured this way.  If you're using
  X, you might be able to do this with the `xmodmap' program (this is
  what I do).
  
142: How do I bind a combination of modifier key and function key?
  
  Unless you're using Emacs under emacstool (or xvetool?), have a working
  version of x-rebind-key (see question 128), or are using Emacs 19 (Lucid
  Emacs), you can't do this with Emacs alone.
  
  If you are using emacstool, Emacs sees different character sequences for
  the combination of a modifier and a function key from what it sees for the
  function key alone.  See etc/emacstool.1 for more information.  Since
  Emacs sees different character sequences, you can bind these different
  sequences to different commands.
  
  If you are running Emacs inside a terminal emulator window like xterm, you
  can modify its translation tables to make it generate different character
  sequences for the combination of a modifier and a function key.  For
  example, this X resource setting:
  
    XTerm.VT100.Translations: #override \
      Shift<KeyPress>F1: string(0x1b) string("[xyzzy")
  
  makes Shift-F1 generate the character sequence "ESC [ xyzzy".  You can
  bind these character sequences in Emacs as normal.  Nick Ruprecht
  <ruprecht@informatik.uni-freiburg.de> has written an extensive X
  translation mapping for xterm that does this.  {Does this have an FTP
  site?}
  
  If you have x-rebind-key, you can have any arbitrary combination of
  modifiers with a key replaced by any sequence of "normal" characters.  For
  example, this makes Shift-Return behave as though you had typed "C-x C-e"
  (example from Jerry Graves):
  
    (x-rebind-key "Return" 'shift "\C-x\C-e")
  
  In Emacs 19 (Lucid Emacs), you can bind Meta-Left-Arrow like this (example
  from Jamie Zawinski):
  
    (global-set-key '(meta left) 'backward-word)
  
  With the last two methods, use `xmodmap' and `xev' to discover the keysym
  and modifier names.
  
143: Why doesn't my Meta key work in an xterm window?
  
  Try all of these methods before asking for further help:
  
  * You may have big problems using `mwm' as your window manager.  {Does
    anyone know a good generic solution to allow the use of the Meta key in
    Emacs with mwm?}
  
  * For X11R4: Make sure it really is a Meta key.  Use `xev' to find out
    what keysym your Meta key generates.  It should be either Meta_L or
    Meta_R.  If it isn't, use xmodmap to fix the situation.
  
  * Make sure the pty the xterm is using is passing 8 bit characters.
    `stty -a' (or `stty everything') should show `cs8' somewhere.  If it
    shows `cs7' instead, use `stty cs8 -istrip' (or `stty pass8') to fix
    it.
  
  * If there is an rlogin connection between the xterm and the Emacs, the
    `-8' argument may need to be given to rlogin to make it pass all 8
    bits of every character.
  
  * If the Emacs is running under Ultrix, it is reported that evaluating
    (set-input-mode t nil) helps.
  
  * If all else fails, you can make xterm generate "ESC W" when you type
    M-W, which is the same conversion Emacs would make if it got the M-W
    anyway.  In X11R4, the following resource specification will do this:
  
      XTerm.VT100.EightBitInput: false
  
    (This changes the behavior of the insert-eight-bit action.)
  
    With older xterms, you can specify this behavior with a translation:
  
      XTerm.VT100.Translations: #override \
        Meta<KeyPress>: string(0x1b) insert()
  
    You might have to replace `Meta' with `Alt'.
  
144: Why doesn't my ExtendChar key work as a Meta key under HP-UX 8.0?
  
  This is a result of an internationalization extension in X11R4 and the
  fact that HP is now using this extension.  Emacs assumes that
  XLookupString returns the same result regardless of the Meta key state
  which is no longer necessarily true.  Until Emacs is fixed, the temporary
  kludge is to run this command after each time the X server is started but
  preferably before any xterm clients are:
  
    xmodmap -e 'remove mod1 = Mode_switch'
  
  NOTE:  This will disable the use of the extra keysyms systemwide, which
  may be undesirable if you actually intend to use them.
  
145: Where can I get key bindings to make Emacs emulate WordStar?
  
  There is a package `wordstar' by Jim Frost <jimf@saber.com> and
  `ws-mode.el' by Juergen Nickelsen <nickel@cs.tu-berlin.de>.  Check in the
  Emacs Lisp Archive (see question 89).
  
146: Where can I get an XEDIT emulator for Emacs?
  
  This question comes up once every couple of months.  I have never seen a
  positive reply, so I presume no one has ever written one.
  


Using Emacs with Alternate Character Sets

147: How do I make Emacs display 8-bit characters?
  
  There is a patch called the `8-bit ctl-arrow patch' that allows Emacs to
  display characters with codes from 128 to 255.  {The original appears to
  have been by Kenneth Cline <cline@proof.ergo.cs.cmu.edu>.} Partially based
  on Johan Widen's earlier work, Johan Vromans <jv@mh.nl> has updated this
  patch for Emacs 18.58 along with some other 8-bit improvements.
  
  Anonymous FTP:
    /ftp.eu.net:gnu/emacs/FP-EightBit.Z
    /ftp.urc.tue.nl:/pub/tex/emacs/FP-EightBit                               +
    /cs.purdue.edu:pub/ygz/cemacs.tar.Z:cemacs/8bit-patch-18.57
    /sics.se:archive/emacs-18.55-8bit-diff
    /laas.laas.fr:pub/emacs/patch-8bit-18.55
    /laas.laas.fr:pub/emacs/patch-8bit-18.57
  
  Via e-mail:
    To: mail-server@sics.se
    body: send emacs-18.55-8bit-diff
  
  Anders Edenbrandt <anderse@dna.lth.se> has produced a more comprehensive
  patch for Emacs 18.59 that allows for 8-bit input and output.              !
  
  Anonymous FTP:
    /ftp.efd.lth.se:pub/gnu/emacs_8-bit.patch                                !
                                                                             !
  In the words of the author:                                                !
                                                                             !
    With these patches, Emacs becomes fully 8-bit operational.  There is     !
    support for displaying 8-bit characters, as well as for entering such    !
    characters from the keyboard.  In addition, upcase/lowcase tranlatsion   !
    is supported, accented characters are recognized as "letters" (important !
    when doing 'forward-word', for example), and text with 8-bit characters  !
    can be sorted correctly.                                                 !
                                                                             !
    A Meta-shift key can still be used, provided that you run in an          !
    environment where it is possible to distinguish between a character      !
    entered using the Meta-shift key and one entered directly. The diffs     !
    include patches to make this work under SunView (with emacstool) as      !
    well as under X.  If you can't use a Meta-shift key, you have to enter   !
    Meta-commands with the ESC-prefix.                                       !

  The most comprehensive patches for 8-bit output are by Howard Gayle
  (originally for Emacs 18.55.  These patches allow displaying any arbitrary
  string for a given 8-bit character (except TAB and C-j).  Also supported
  is defining the sorting order and the uppercase and lowercase
  translations.  It is reported that the 8-bit character support in Emacs 19
  is largely based on these patches.  Thomas Bellman
  <Bellman@lysator.liu.se> has updated these patches for Emacs 18.59.        !
  
  Anonymous FTP:
    /sics.se:archive/emacs-gayle.tar.Z  (patches for 18.55)
    /ftp.lysator.liu.se:pub/emacs/gayle-18.58.diff.tar.Z  (patches)          !
    /ftp.lysator.liu.se:pub/emacs/emacs-18.59-gayle.tar.Z  (patched Emacs)   !
  
  Epoch's 8-bit character support is based on Anders Edenbrandt's patches.   !
  Lucid Emacs has the ctl-arrow patch installed.  Nemacs displays 8-bit
  characters, and it may be useful for displaying the 8-bit ISO-8859
  alphabet, but I don't know for sure (see question 149).
  
148: How do I input 8-bit characters?
  
  Minor modes for ISO Latin-1 that allow one to easily input this character
  set have been written by several people.  Such modes have been written by
  Matthieu Herrb <matthieu@laas.fr> (laas.laas.fr:pub/emacs/iso-latin-1.el),
  Johan Vromans <jv@mh.nl> {FTP site??}, and Marc Shapiro
  <shapiro@sor.inria.fr> {FTP site??}.
  
  These approaches differ from the one taken by Anders Edenbrandt in that
  his method uses direct 8-bit input, while these methods use a compose
  sequence for 8-bit characters.  {I have heard conflicting reports on
  whether this results in losing the Meta key.  Perhaps this depends on
  whether Emacs is running under X.  Can someone resolve this?}
  
  Karl Heuer <karl@haddock.ima.isc.com> is said to have a patch to allow
  8-bit input.  Georg-Wilhelm Koltermann <gwk@crmunich0.cray.com> also has a
  patch for either 18.57 or 18.58 that allows 8-bit input.
  
  Epoch comes with a patch that allows it to input 8-bit characters, but it
  is not enabled by default.  {Is this right?}
  
  Jamie Zawinski says:
  
    Lucid GNU Emacs allows the input of any ISO-8859/1 keysyms that your
    keyboard generates (see xmodmap), and contains a package that implements
    a DEC/OpenWindows-like "Compose" key for systems which don't have one.
  
149: Where can I get an Emacs that can handle kanji characters?
  
  Nemacs 3.3.2 (Nihongo GNU Emacs) is a modified version of GNU Emacs 18.55
  that handles kanji characters.  It is available via anonymous FTP:
  
    /crl.nmsu.edu:pub/misc/nemacs-3.3.2.tar.Z
    /miki.cs.titech.ac.jp:JAPAN/nemacs/nemacs-3.3.2.tar.Z                    -
  
  You might also need files for "wnn", a kanji input method
  (wnn-4.0.3{-README,.tar.Z} {on which machine?}).  You need a terminal (or
  terminal emulator) that can display text encoded in JIS, Shift-JIS, or EUC
  (Extended Unix Code), or the ability to run Nemacs as a direct X Window
  client.
  
150: Where can I get an Emacs that can handle Chinese?
  
  `cemacs' by Stephen G. Simpson <simpson@math.psu.edu> is a patch to Emacs
  18.57 (the ctl-arrow patch) and some Emacs Lisp code that combined with
  Cxterm allows using Chinese characters.  It is available via anonymous
  FTP:
  
    /crl.nmsu.edu:pub/chinese/cemacs.tar.Z
    /cs.purdue.edu:pub/ygz/cemacs.tar.Z
  
  Cxterm is available from the same place:
  
    /cs.purdue.edu:pub/ygz/cxterm-11.5.1.tar.Z
  
151: Where is an Emacs that can handle Semitic (right-to-left) alphabets?
  
  Joel M. Hoffman <joel@wam.umd.edu> writes:
  
    A couple of years ago a wrote a hebrew.el file that allows right-to-left
    editing of Hebrew.  I relied on the hardware to display the Hebrew
    letters, given the right codes, but not for any right-to-left support;
    the hardware also doesn't have to send any specific char. codes.  Emacs
    keeps track of when the user is typing Hebrew vs. English.  (The VT-*
    terminals in Israel contain built-in support for Hebrew.)
  
    To get it to work I had to modify only a few lines of GNU Emacs's source
    code --- just enough to make it 8-bit clean.
  
    [and in a separate message:]
  
    It doesn't produce time-order ["sefer" format] (I wouldn't recommend
    trying that with emacs, because converting time-order to screen-order
    with arbitrarily long lines is a bit tricky), but I also concocted a
    quick filter to convert screen-order into time-order.  I'll be happy to
    send you the requisite files if you want them.  If you're using it for
    anything large, however, you'll want something that works better.
  
  Joel Hoffman has also written a "bi-directional bi-lingual Emacs-like"
  editor for MS-DOS named Ibelbe (Itty Bitty Emacs-Like Bidirectional
  Editor).  Ibelbe is written in Turbo Pascal and comes with source code.
  Here is the description:
  
    Ibelbe looks like emacs (it even has a minibuffer and filename
    completion), and fully supports both right-to-left and left-to-right
    editing.  Other than an EGA monitor or better, no special hardware is
    required.  You will need an EGA Hebrew font to use Ibelbe with Hebrew.
  
  Anonymous FTP:
    /israel.nysernet.org:israel/msdos/ibelbe.zip
    /israel.nysernet.org:israel/msdos/hebfont.zip
  
  Joseph Friedman <yossi@deshaw.com, yossi@Neon.Stanford.EDU> has written
  patches for Emacs 18.55 and 18.58 that provide Semitic language support
  under X Windows.
  
  Warren Burstein <warren@itex.jct.ac.il> says he has mapped 7-bit keys by
  modifying self-insert-command "for Hebrew input on 7-bit keyboards".
  
  A good suggestion is to query archie for files named with `hebrew'.
  


----------------------------------------------------------------------       +
Copyright (C) 1990, 1991, 1992 Joseph Brian Wells                            +
Copyright (C) 1992, 1993 Steven Byrnes                                       +
                                                                             +
This list of frequently asked questions about GNU Emacs with answers         +
("FAQ") may be translated into other languages, transformed into other       +
formats (e.g. Texinfo, Info, WWW, WAIS, etc.), and updated with new          +
information.  The same conditions apply to any derivative of the FAQ as      +
apply to the FAQ itself.  Every copy of the FAQ must include this notice     +
or an approved translation, information on who is currently maintaining      +
the FAQ and how to contact them (including their e-mail address), and        +
information on where the latest version of the FAQ is archived (including    +
FTP information).  The FAQ may be copied and redistributed under these       +
conditions, except that the FAQ may not be embedded in a larger literary     +
work unless that work itself allows free copying and redistribution.         +
Technical Details
Message-ID: <GNU-Emacs-FAQ-4.1993.01.05.171933@rice.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!uw-beaver!newsfeed.rice.edu!rice!sbyrnes
References: <GNU-Emacs-FAQ-0.1993.01.05.171933@rice.edu>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.help,comp.emacs,news.answers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!uw-beaver!newsfeed.rice.edu!rice!sbyrnes
From: sbyrnes@rice.edu (Steven Byrnes)
Subject: GNU Emacs FAQ (4/5, 125-151): Keybindings/Output
Message-ID: <GNU-Emacs-FAQ-4.1993.01.05.171933@rice.edu>
Followup-To: poster
Summary: READ BEFORE POSTING.  A regularly posted list of answers to frequently
         asked questions (FAQs) about GNU Emacs and many Emacs Lisp programs.
         Contains pointers to other resources.  Follow "References:" link for
         more metainfo.
Originator: sbyrnes@is.rice.edu
Keywords: gnu emacs faq answers frequently asked questions periodic
Sender: news@rice.edu (News)
Supersedes: <GNU-Emacs-FAQ-4.1992.09.22.011020@bigbird.bu.edu>
Reply-To: gnu-emacs-faq-maintainers@bigbird.bu.edu
Organization: GNU's Not UNIX
References: <GNU-Emacs-FAQ-0.1993.01.05.171933@rice.edu>
Date: Tue, 5 Jan 1993 17:19:33 GMT
Approved: news-answers-request@mit.edu
Lines: 1006