home *** CD-ROM | disk | FTP | other *** search
/ Danny Amor's Online Library / Danny Amor's Online Library - Volume 1.iso / html / faqs / faq / gnu-emacs-faq / part4 < prev    next >
Encoding:
Text File  |  1995-07-25  |  43.7 KB  |  1,013 lines

  1. Subject: GNU Emacs FAQ (4/5, 125-151): Keybindings/Output
  2. Newsgroups: gnu.emacs.help,comp.emacs,news.answers,comp.answers
  3. From: sbyrnes@rice.edu (Steven Byrnes)
  4. Date: Tue, 4 May 1993 02:52:18 GMT
  5.  
  6. Archive-Name: GNU-Emacs-FAQ/part4
  7. Last-Modified: Sat, 6 Mar 1993 21:13:32 GMT
  8. Last-Posted: Tue, 4 May 1993 02:52:18 GMT
  9.  
  10.                     GNU Emacs FAQ: Keybindings/Output
  11.  
  12. If you are viewing this text in a GNU Emacs Buffer, you can type "M-2 C-x $" to
  13. get an overview of just the questions.  Then, when you want to look at the text
  14. of the answers, just type "C-x $".
  15.  
  16. To search for a question numbered XXX, type "M-C-s ^XXX:", followed by a C-r if
  17. that doesn't work, then type ESC to end the search.
  18.  
  19. A `+' in the 78th column means something was inserted on the line.  A `-' means
  20. something was deleted and a `!' means some combination of insertions and
  21. deletions occurred.
  22.  
  23. Full instructions for getting the latest FAQ are in question 22.  Also see the
  24. `Introduction to news.answers' posting in the `news.answers' newsgroup, or send
  25. e-mail to `mail-server@rtfm.mit.edu' with `help' on a body line, or use FTP,
  26. WAIS, or Prospero to rtfm.mit.edu.
  27.  
  28.  
  29.  
  30. Changing Key Bindings and Handling Key Binding Problems
  31.  
  32. 125: How do I bind keys (including function keys) to commands?
  33.   
  34.   1. Find out what character sequence is generated by the keystroke sequence
  35.      you wish to bind to a command.  See question 129 for how to do this.
  36.      Keep in mind that the character sequences generated by a keystroke
  37.      sequence varies from one terminal to another.  You may also get
  38.      different results depending on what type of machine you are running on
  39.      (see question 128).  For example, these keystrokes may generate these
  40.      character sequences:
  41.   
  42.        F1        ---> ESC [ 2 2 4 z
  43.        Shift-R10 ---> ESC O t
  44.        L7        ---> ESC [ 3 1 ~
  45.        Remove    ---> C-@
  46.   
  47.   2. Figure out what the Emacs Lisp syntax is for this character sequence.
  48.      Inside an Emacs Lisp string, RET, LFD, DEL, ESC, SPC, and TAB are
  49.      specified with `\r', `\n', `\C-?', `\e', ` ', and `\t'.  C-x is
  50.      specified by `\C-x'.  M-x is specified the same was as "ESC x".
  51.      (Control characters may also be specified as themselves, but I don't
  52.      recommend it.)  An Emacs Lisp string begins and ends with the double
  53.      quote character, `"'.  Here are some examples:
  54.   
  55.        ESC [ D       ---> "\e[D"
  56.        ESC [ 2 2 7 z ---> "\e[227z"
  57.        ESC [ 1 8 ~   ---> "\e[18~"
  58.        C-M-r         ---> "\e\C-r"
  59.   
  60.   3. If some prefix of the character sequence is already bound, you must
  61.      unbind it by binding it to `nil'.  For example:
  62.   
  63.        (global-set-key "\e[" nil)
  64.   
  65.   4. Pick a command to bind your key sequence to.  A command can be a
  66.      "symbol" with a function definition, or a "lambda list", or a string
  67.      (which is treated as a macro).  For example:
  68.   
  69.        (global-set-key "\e[D" 'backward-char)
  70.        (global-set-key "\e[227~" "\exgoto-line\r") ; macro
  71.   
  72.   See `Key Bindings' and `Rebinding' in the online manual.
  73.   
  74.   In Emacs 19 (including Lucid Emacs), you can bind function key F24 like
  75.   this:
  76.   
  77.     (global-set-key 'f24 'some-command)
  78.   
  79. 126: Why does Emacs say `Key sequence XXX uses invalid prefix characters'?
  80.   
  81.   A prefix of the character sequence you were trying to bind was already
  82.   bound.  Usually, the sequence is "ESC [", in which case you should
  83.   evaluate this form first:
  84.   
  85.     (define-key esc-map "[" nil)
  86.   
  87.   NOTE: By default, "ESC [" is bound to backward-paragraph, and if you do
  88.   this you will lose this key binding.  For most people, this is not a
  89.   problem.
  90.   
  91.   See question 125.
  92.   
  93. 127: Why doesn't this [terminal or window-system setup] code work in my
  94.  .emacs file, but it works just fine after Emacs starts up?
  95.   
  96.   This is because you're trying to do something in your .emacs file that
  97.   needs to be postponed until after the terminal/window-system setup code
  98.   is loaded.  This is a result of the order in which things are done
  99.   during the startup of Emacs.  For more details see question 135.
  100.   
  101.   In order to postpone the execution of Emacs Lisp code until after the
  102.   terminal/window-system setup, set the value of the variable
  103.   term-setup-hook or window-setup-hook to be a function which does what
  104.   you want.
  105.   
  106.   See etc/OPTIONS for a complete explanation of what Emacs does every time
  107.   it is started.
  108.   
  109.   Here is a simple example of how to set term-setup-hook:
  110.   
  111.     (setq term-setup-hook
  112.       (function
  113.        (lambda ()
  114.          (cond ((string-match "\\`vt220" (or (getenv "TERM") ""))
  115.             ;; Make vt220's "Do" key behave like M-x:
  116.             (define-key CSI-map "29~" 'execute-extended-command))
  117.            ))))
  118.   
  119. 128: How do I use function keys under X Windows?
  120.   
  121.   This depends on whether you are running Emacs inside a terminal emulator
  122.   window, or whether you are allowing Emacs to create its own X window.
  123.   You can tell which you are doing by noticing whether Emacs creates a new
  124.   window when you start it.
  125.   
  126.   If you are running Emacs inside a terminal emulator window, then it
  127.   behaves exactly as it does on any other tty.  In this case, for function
  128.   keys to be useful, they must generate character sequences that are sent
  129.   to the programs running inside the window as input.  The `xterm' program
  130.   has two different sets of character sequences that it generates when
  131.   function keys are pressed, depending on the sunFunctionKeys X resource
  132.   and the -sf and +sf command line options.  (To find out what these key
  133.   sequences are, see question 129.)  In addition, with xterm,
  134.   you can override what key sequence a specific function key (or any other
  135.   key) will generate with the `translations' resource.  This, for example:
  136.   
  137.     XTerm.VT100.Translations: #override \
  138.       <KeyPress>F1: string(0x1b) string("[xyzzy")
  139.   
  140.   makes the function key F1 generate the character sequence "ESC [xyzzy".
  141.   
  142.   On the other hand, if Emacs is managing its own X window, the following
  143.   description applies.  Emacs receives `KeyPress' events from the X server
  144.   when a key is pressed while the keyboard focus is in its window.  The
  145.   KeyPress event contains an X "keysym" code, which is simply an arbitrary
  146.   number corresponding to the name of the keysym, and information on which
  147.   "modifiers" such as `control' and `shift' are active.  For example, the
  148.   `Tab' keysym is 0xff09.  (Generally, a key on the keyboard will generate a
  149.   keysym whose name is the same as the label on the key, ie. the `Tab' key
  150.   will normally generate the `Tab' keysym.  This can be changed with the
  151.   xmodmap program.)  Emacs recognizes all the keysyms that correspond to
  152.   standard ASCII characters and internally uses the ASCII character instead.
  153.   
  154.   (WARNING: I am about to describe a gross, disgusting hack to you, have
  155.   your barf bag ready.)
  156.   
  157.   When Emacs receives the X keysym of one of the arrow keys, it behaves
  158.   the same as if it had received a letter key with the control modifier
  159.   down as follows (this is hard-coded):
  160.   
  161.     Up    becomes C-p
  162.     Down  becomes C-n
  163.     Right becomes C-f
  164.     Left  becomes C-b
  165.   
  166.   The way Emacs treats other keysyms depends on what kind of machine it was
  167.   compiled on.  The type of the display machine is irrelevant!  Function
  168.   keys are mapped internally to escape sequences, while other keys are
  169.   completely ignored.
  170.   
  171.   1. If compiled on a Sun, Emacs recognizes these X keysyms that
  172.      are normally on a Sun keyboard:
  173.   
  174.        F1 through F9
  175.        L1 through L10 (same as F11 through F20)
  176.        R1 through R15 (same as F21 through F35)
  177.      (The keys labelled R8, R10, R12, and R14 usually are mapped to the
  178.       X keysyms Up, Left, Right, and Down.)
  179.        Break (the `Alternate' key is given this keysym)
  180.   
  181.      These keys work like Sun function keys.  When Emacs recieves the
  182.      keysym, it will internally use character sequences that look like "ESC
  183.      [ ### z", where ### is replaced by a number.  The character sequences
  184.      are identical to those generated by Sun's keyboard under SunView.  Any
  185.      function key not listed above generates "ESC [ - 1 z".
  186.   
  187.      In order to use these key sequences, they should be bound to commands
  188.      using the standard key binding methods, just as if Emacs were running
  189.      on a regular terminal.
  190.   
  191.      WARNING: F11 and L1 are the same keysym in X, as are F12 and L2, etc.
  192.      {Yes, this is stupid.  Complain to the X consortium.}
  193.   
  194.   2. If not compiled on a Sun, the function keys will appear to Emacs in a
  195.      way remarkably similar to the keys of a DEC LK201 keyboard (used on
  196.      some VT series terminals).  These X keysyms will be recognized:
  197.   
  198.        F1 through F20
  199.        Help (treated same as F15)
  200.        Menu (treated same as F16, is the LK201 `Do' key)
  201.        Find
  202.        Insert (LK201 `Insert Here' key)
  203.        Select
  204.        Prior (LK201 `Prev Screen' key *** ONLY IN 18.58 AND LATER ***)
  205.        Next (LK201 `Next Screen' key *** ONLY IN 18.58 AND LATER ***)
  206.   
  207.      And finally, the LK201 key labelled `Remove' (or `Delete') is often
  208.      mapped to the Delete keysym which generates the DEL character (C-?)
  209.      instead of the key sequence given by the LK201 `Remove' key.  It may
  210.      also be mapped to some other keysym, such as `_Remove', in which case
  211.      you can't use it from within Emacs at all.
  212.   
  213.      Each function key will be internally converted to a character sequence
  214.      that looks like "ESC [ ## ~", where ## is replaced by a number.  The
  215.      character sequences are identical to those generated by a LK201
  216.      keyboard.  Any function key not listed above generates "ESC [ - 1 ~".
  217.   
  218.   For the complete list of the numbers which are generated by the function
  219.   keys, look in the file src/x11term.c at the definitions of the function
  220.   stringFuncVal.
  221.   
  222.   If you are running Emacs on a Sun machine, even if your X display is
  223.   running on a non-Sun machine (eg., an X terminal), you get the setup
  224.   described above for Suns.  The determining factor is what type of
  225.   machine Emacs is running (was compiled) on, not what type of machine
  226.   your X display is on.
  227.   
  228.   If you have function keys not listed above on your keyboard, you can use
  229.   `xmodmap' to change their keysym assignments to get keys that Emacs will
  230.   recognize, but that may screw up other programs.
  231.   
  232.   X resources are not used by Emacs to affect the key sequences generated.
  233.   In particular, there are no X key "translations" for Emacs.
  234.   
  235.   If you have function keys not listed above and you don't want to use
  236.   xmodmap to change their names, you might want to make a modification to
  237.   your Emacs.  Johan Vromans <jv@mh.nl> has made available a patch for Emacs
  238.   that adds the x-rebind-key function of Epoch to Emacs 18.58.  This allows
  239.   another layer of key rebinding before Emacs even sees the keys, and in
  240.   this layer you can rebind all of the keys and modifier combinations as
  241.   well.
  242.   
  243.   Anonymous FTP:
  244.     /ftp.eu.net:gnu/emacs/FP-Xfun.Z
  245.     /ftp.urc.tue.nl:pub/tex/emacs/FP-Xfun
  246.   
  247.   Johan Vromans explains what this buys for you:
  248.   
  249.     After implementing this, all keyboard keys can be configured to send
  250.     user definable sequences, eg.,
  251.   
  252.       (x-rebind-key "KP_F1" 0 "\033OP")
  253.   
  254.     This will have the keypad key PF1 send the sequence "ESC O P", just like
  255.     an ordinary VT series terminal.
  256.   
  257. 129: How do I tell what characters my function or arrow keys emit?
  258.   
  259.   Use this function by Randal L. Schwartz <merlyn@iwarp.intel.com>:
  260.   
  261.     (defun see-chars ()
  262.       "Displays characters typed, terminated by a 3-second timeout."
  263.       (interactive)
  264.       (let ((chars "")
  265.         (inhibit-quit t))
  266.     (message "Enter characters, terminated by 3-second timeout.")
  267.     (while (not (sit-for 3))
  268.       (setq chars (concat chars (list (read-char)))
  269.         quit-flag nil))        ; quit-flag maybe set by C-g
  270.     (message "Characters entered: %s" (key-description chars))))
  271.   
  272.   Alternatively, use the "C-h l" view-lossage command, which will display
  273.   the last 100 characters Emacs has seen in its input stream.  Kevin
  274.   Gallagher <kgallagh@digi.lonestar.org> suggests typing some unique string
  275.   like "wxyz", typing the key in question, then typing "C-h l".  The
  276.   characters that appear between "wxyz" and "C-h l" were generated by the
  277.   key.
  278.   
  279. 130: How do I set the X key "translations" for Emacs?
  280.   
  281.   Sorry, you can't; there are no "translations" to be set.  Emacs is not
  282.   written using the Xt library.  The only way to affect the behavior of keys
  283.   within Emacs is through `xmodmap' (outside Emacs) or `define-key' (inside
  284.   Emacs).
  285.   
  286. 131: How do I handle C-s and C-q being used for flow control?
  287.   
  288.   C-s and C-q are used in the XON/XOFF flow control protocol.  This screws
  289.   up Emacs because it binds these characters to commands.  Also, by default
  290.   Emacs will not honor them as flow control characters and may overwhelm
  291.   output buffers.  Sometimes, intermediate software using XON/XOFF flow
  292.   control will prevent Emacs from ever seeing C-s and C-q.
  293.   
  294.   Possible solutions:
  295.   
  296.   * Disable the use of C-s and C-q for flow control.
  297.   
  298.     You need to determine what is the cause of the flow control.
  299.   
  300.     * your terminal
  301.   
  302.       Your terminal may use XON/XOFF flow control to have time to display
  303.       all the characters it receives.  For example, VT series terminals do
  304.       this.  It may be possible to turn this off from a setup menu.  For
  305.       example, on a VT220 you may select `No XOFF' in the setup menu.  This
  306.       is also true for some terminal emulation programs on PCs.
  307.   
  308.       When you turn off flow control at the terminal, you will also need to
  309.       turn it off at the other end, which might be at the computer you are
  310.       logged in to or at some terminal server in between.
  311.   
  312.       If you turn off flow control, characters may be lost; using a printer
  313.       connected to the terminal may fail.  You may be able to get around
  314.       this problem by modifying the `termcap' entry for your terminal to
  315.       include extra NUL padding characters. 
  316.   
  317.     * a modem
  318.   
  319.       If you are using a dialup connection, the modems may be using XON/XOFF
  320.       flow control.  I don't know how to get around this.
  321.   
  322.     * a router or terminal server
  323.   
  324.       Some network box between the terminal and your computer may be using
  325.       XON/XOFF flow control.  It may be possible to make it use some other
  326.       kind of flow control.  You will probably have to ask your local
  327.       network experts for help with this.
  328.   
  329.     * tty and/or pty devices
  330.   
  331.       If your connection to Emacs goes through multiple tty and/or pty
  332.       devices, they may be using XON/XOFF flow control even when it is not
  333.       necessary.
  334.   
  335.       Eirik Fuller <eirik@theory.tn.cornell.edu> writes:
  336.   
  337.         Some versions of `rlogin' (and possibly telnet) do not pass flow
  338.         control characters to the remote system to which they connect.  On
  339.         such systems, Emacs on the remote system cannot disable flow control
  340.         on the local system.  Sometimes `rlogin -8' will avoid this problem.
  341.   
  342.         One way to cure this is to disable flow control on the local host
  343.         (the one running rlogin, not the one running rlogind) using the stty
  344.         command, before starting the rlogin process.  On many systems, `stty
  345.         start u stop u' will do this.
  346.   
  347.         Some versions of `tcsh' will prevent even this from working.  One
  348.         way around this is to start another shell before starting rlogin,
  349.         and issue the stty command to disable flow control from that shell.
  350.   
  351.       Use `stty -ixon' instead of `stty start u stop u' on some systems.
  352.   
  353.   * Make Emacs speak the XON/XOFF flow control protocol.
  354.   
  355.     You can make Emacs treat C-s and C-q as flow control characters by
  356.     evaluating this form:
  357.   
  358.       (set-input-mode nil t)
  359.   
  360.     If you are fixing this for yourself, simply put the form in your .emacs
  361.     file.  If you are fixing this for your entire site, the best place to
  362.     put it is unclear.  I don't know if this has any effect when used in
  363.     lisp/site-init.el when building Emacs; I've never tried that.  {Can
  364.     someone tell me whether it works?}  Putting things in users' .emacs files
  365.     has a number of problems.
  366.   
  367.     Putting this form in lisp/default.el has the problem that if the user's
  368.     .emacs file has an error, this will prevent lisp/default.el from being
  369.     loaded and Emacs may be unusable for the user, even for correcting their
  370.     .emacs file (unless they're smart enough to move it to another name).  A
  371.     possible solution is to initially disable C-s and C-q by setting
  372.     keyboard-translate-table in lisp/site-init.el, either with swap-keys
  373.     (see question 136) or with the following form:
  374.   
  375.       ;; by Roger Crew <crew@cs.stanford.edu>:
  376.       (setq keyboard-translate-table
  377.             "\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-_")
  378.   
  379.     This will at least prevent Emacs from being confused by the flow control
  380.     characters, even if lisp/default.el cannot be loaded.  Then, in
  381.     lisp/default.el, enable XON/XOFF flow control with set-input-mode.
  382.   
  383.   For further discussion of this issue, read the file PROBLEMS in the
  384.   Emacs distribution.
  385.   
  386. 132: How do I use commands bound to C-s and C-q (or any key) if these keys
  387.  are filtered out?
  388.   
  389.   I suggest swapping C-s with C-\ and C-q with C-^:
  390.   
  391.     (swap-keys ?\C-s ?\C-\\)
  392.     (swap-keys ?\C-q ?\C-^)
  393.   
  394.   See question 136 for the implementation of swap-keys.  This method
  395.   has the advantage that it simultaneously swaps the characters everywhere
  396.   throughout Emacs, while just switching the keybindings will miss important
  397.   places where the character codes are stored (eg., the search-repeat-char
  398.   variable, major mode keymaps, etc.).
  399.   
  400.   To do this for an entire site, you may want to swap the keys in
  401.   lisp/default.el.  If only some of your users are connecting through
  402.   XON/XOFF flow-controlled connections, you will want to do this
  403.   conditionally.  I suggest pre-swapping them in lisp/site-init.el when
  404.   Emacs is built, and then in lisp/default.el, if it is determined to be
  405.   safe, they can be reenabled (being careful not to screw up any other key
  406.   mappings users might have established using keyboard-translate-table).
  407.   See question 131 for an easy way to pre-swap these keys.
  408.   
  409.   WARNING: If you do this for an entire site, the users will be confused by
  410.   the disparity between what the documentation says and how Emacs actually
  411.   behaves.
  412.   
  413. 133: Why does the `BackSpace' key invoke help?
  414.   
  415.   The BackSpace key (on every keyboard I've used) generates ASCII code 8.
  416.   C-h sends the same code.  In Emacs by default C-h invokes help-command.
  417.   This is intended to be easy to remember since the first letter of "help"
  418.   is "h".  The easiest solution to this problem is to use C-h (and
  419.   BackSpace) for help and DEL (the Delete key) for deleting the previous
  420.   character.
  421.   
  422.   For many people this solution may be problematic:
  423.   
  424.   * They normally use BackSpace outside of Emacs for deleting the previous
  425.     character typed.  This can be solved by making DEL be the command for
  426.     deleting the previous character outside of Emacs.  This command will do
  427.     this on many Unix systems:
  428.   
  429.       stty erase '^?'
  430.   
  431.   * The person may prefer using the BackSpace key for deleting the previous
  432.     character because it is more conveniently located on their keyboard or
  433.     because they don't even have a separate Delete key.  In this case, the
  434.     BackSpace key should be made to behave like Delete.  There are several
  435.     methods.
  436.   
  437.     * Under X Windows, the easiest solution is to change the BackSpace key
  438.       into a Delete key like this:
  439.   
  440.         xmodmap -e "keysym BackSpace = Delete"
  441.   
  442.     * Some terminals (eg., VT3## terminals) allow the character generated by
  443.       the BackSpace key to be changed from a setup menu.
  444.   
  445.     * You may be able to get a keyboard that is completely programmable.
  446.   
  447.     * Under X or on a dumb terminal, it is possible to swap the BackSpace
  448.       and Delete keys inside Emacs:
  449.   
  450.         (swap-keys ?\C-h ?\C-?)
  451.   
  452.       See question 136 for the implementation of swap-keys.
  453.   
  454.     * Another approach is to switch keybindings and put help on "C-x h"
  455.       instead:
  456.   
  457.         (global-set-key "\C-h" 'delete-backward-char)
  458.         (global-set-key "\C-xh" 'help-command) ; override mark-whole-buffer
  459.   
  460.       Other popular key bindings for help are M-? and "C-x ?".
  461.   
  462.       WARNING: Don't try to bind DEL to help-command, because there are many
  463.       modes that have local bindings of DEL that will interfere.
  464.   
  465. 134: Why doesn't Emacs look at the stty settings for Backspace vs. Delete?
  466.   
  467.   Good question!
  468.   
  469. 135: Why don't the arrow keys work?
  470.   
  471.   When Emacs starts up, it doesn't know anything about arrow keys at all
  472.   (except when running under X, see question 128).  During the process of
  473.   starting up, Emacs will load a terminal-specific initialization file for
  474.   your terminal type (as determined by the environment variable TERM), if
  475.   one exists.  This file has the responsibility for enabling the arrow keys.
  476.   
  477.   There are several things that can go wrong:
  478.   
  479.   1. There is no initialization file for your terminal.
  480.   
  481.      You can determine this by looking in the lisp/term directory.  If your
  482.      terminal type (as determined by the TERM environment variable) is
  483.      xxx-yy-z, then the first of these files in the lisp/term directory will
  484.      be loaded as the terminal-specific initialization file: xxx-yy-z.el,
  485.      xxx-yy.el, or xxx.el.
  486.   
  487.      There are two major cases of this problem:
  488.   
  489.      * Your terminal type is very similar to one that has an init file.
  490.   
  491.        In this case, there are several techniques suggested by Colin Jensen
  492.        <cjensen@ampex.com>, Ben Liblit <Liblit@cs.psu.edu>, and Marc
  493.        Auslander <marc@watson.ibm.com>:
  494.   
  495.        A. Add a symbolic link in lisp/term for your terminal type that
  496.           points to the similar type.  For example, you could make VT102
  497.           terminals work with this command:
  498.   
  499.             ln -s vt100.el vt102.el
  500.   
  501.           This fixes things for everyone on the system who uses the terminal
  502.           type.
  503.   
  504.        B. If you can't do the solution in part A, you can add code to your
  505.           term-setup-hook that loads the correct file like this:
  506.   
  507.             (setq term-setup-hook
  508.                   (function
  509.                    (lambda ()
  510.                      (cond ((equal "vt102" (or (getenv "TERM") ""))
  511.                             (load (concat term-file-prefix "vt100")))
  512.                            (;; Code for other terminal types goes here ...
  513.                             )))))
  514.   
  515.        C. If you use `tset' to set your TERM environment variable when you
  516.           login, you can use the `-m' switch to tell tset to use a terminal
  517.           type known by Emacs instead of another similar one.  For example,
  518.           specifying this:
  519.   
  520.             tset ... -m 'dec-vt220:vt220' ...
  521.   
  522.           will make tset say you are on a `vt220' instead of a `dec-vt220'.
  523.   
  524.        D. Interactively, you can type "M-x load-library RET term/vt100" to
  525.           load the terminal-specific initialization files for VT100
  526.           terminals.
  527.   
  528.      * Your terminal type is not similar to one that has an init file.
  529.   
  530.        One can be made for your terminal, or you can just add code to your
  531.        own .emacs to handle this problem for yourself.  For example, if your
  532.        terminal's arrow keys send these character sequences:
  533.   
  534.          Up:    ESC [ A
  535.          Down:  ESC [ B
  536.          Right: ESC [ C
  537.          Left:  ESC [ D
  538.   
  539.        then you can bind these keys to the appropriate commands with code in
  540.        your .emacs like this:
  541.   
  542.          (setq term-setup-hook
  543.                (function
  544.                 (lambda ()
  545.                   (cond ((string-match "\\`xyzzy" (or (getenv "TERM") ""))
  546.                          ;; First, must unmap the binding for left bracket
  547.                          (or (keymapp (lookup-key global-map "\e\["))
  548.                              (define-key global-map "\e\[" nil))
  549.                          ;; Enable terminal type xyzzy's arrow keys:
  550.                          (define-key global-map "\e\[A" 'previous-line)
  551.                          (define-key global-map "\e\[B" 'next-line)
  552.                          (define-key global-map "\e\[C" 'forward-char)
  553.                          (define-key global-map "\e\[D" 'backward-char))
  554.                         ((string-match "\\`abcde" (or (getenv "TERM") ""))
  555.                          ;; Do something different for terminal type abcde
  556.                          ;; .....
  557.                          )))))
  558.   
  559.      NOTE: You may have to restart Emacs to get changes to take effect.
  560.   
  561.      NOTE: Your arrow keys may send sequences beginning with "ESC O" when
  562.      Emacs is running, even if they send sequences beginning with "ESC [" at
  563.      all other times.  This is because Emacs uses any command there may be
  564.      in your terminal's termcap entry for putting the terminal into
  565.      "Application Keypad Mode".  Just map these sequences the same way as
  566.      above.
  567.   
  568.   The next two cases are problems even if there is a initialization file for
  569.   your terminal type.
  570.   
  571.   2. The initialization file for your terminal doesn't bind arrow keys.
  572.   
  573.      If your terminal type is `xterm', you will have to bind the arrow keys
  574.      as in part 1 above, since the xterm.el file doesn't do anything useful.
  575.      There may be other terminal types with the same problem.
  576.   
  577.   3. Your terminal's arrow keys send individual control characters.
  578.   
  579.      For example, the arrow keys on an ADM-3 send C-h, C-j, C-k, and C-l.
  580.   
  581.      There is not much Emacs can do in this situation, since all the control
  582.      characters except for C-^ and C-\ are already used as Emacs commands.
  583.      It may be possible to convince the terminal to send something else when
  584.      you press the arrow keys; it is worth investigating.
  585.   
  586.      You have to make the hard choices of how to rebind keys to commands to
  587.      make things work the way you want.  Another alternative is to start
  588.      learning the standard Emacs keybindings for moving point around: C-b,
  589.      C-f, C-p, and C-n.  Personally, I no longer use the arrow keys when
  590.      editing because I have switched keyboards so many times.
  591.   
  592.   4. Your terminal's arrow keys send sequences beginning with "ESC [".
  593.   
  594.      Due to an extremely poor design decision (ie., these sequences are ANSI
  595.      standard), none of the the terminal-specific initialization files that
  596.      are distributed with Emacs will bind these character sequences to the
  597.      appropriate commands by default.  (This also applies to any other
  598.      function keys which generate character sequences starting with "ESC
  599.      [".)  This is because it was deemed far more important to preserve the
  600.      binding of M-[ to the backward-paragraph command.  It appears that this
  601.      will change in Emacs 19.
  602.   
  603.      Some of the terminal-specific initialization files that come with Emacs
  604.      provide a command enable-arrow-keys that will fix this problem.  To get
  605.      this automatically invoked, put this in your .emacs:
  606.   
  607.        (setq term-setup-hook
  608.          (function
  609.           (lambda ()
  610.         (if (fboundp 'enable-arrow-keys) (enable-arrow-keys)))))
  611.   
  612.      We put this in our lisp/default.el file, so users don't have to worry
  613.      about it:
  614.   
  615.        ;; don't override a user's term-setup-hook
  616.        (or term-setup-hook
  617.        (setq term-setup-hook
  618.          (function
  619.           (lambda ()
  620.             (and (fboundp 'enable-arrow-keys)
  621.              ;; don't override a user key mapping
  622.              (eq 'backward-paragraph (lookup-key esc-map "["))
  623.              (enable-arrow-keys))))))
  624.   
  625.      If your terminal type is `sun', you should put this in your .emacs
  626.      instead (or in addition to the above):
  627.   
  628.        (setq sun-esc-bracket t)
  629.   
  630.      It is possible that the terminal-specific initialization file for your
  631.      terminal type was written locally and does not follow the rule
  632.      mentioned above.  In this case you may need to inspect it to find out
  633.      how to enable the arrow keys.  (Actually, if it was written locally, it
  634.      probably enables the arrow keys by default.)
  635.   
  636. 136: How do I "swap" two keys?
  637.   
  638.   When Emacs receives a character, you can make Emacs behave as though it
  639.   received another character by setting the value of
  640.   keyboard-translate-table.  The following Emacs Lisp will do this for you,
  641.   allowing you to "swap" keys.  After arranging for this Lisp to be
  642.   evaluated by Emacs, you can evaluate `(swap-keys ?A ?B)' to swap A and B.
  643.   
  644.     (defun swap-keys (key1 key2)
  645.       "Swap keys KEY1 and KEY2 using map-key."
  646.       (map-key key1 key2)
  647.       (map-key key2 key1))
  648.   
  649.     (defun map-key (from to)
  650.       "Make key FROM behave as though key TO was typed instead."
  651.       (setq keyboard-translate-table
  652.         (concat keyboard-translate-table
  653.             (let* ((i (length keyboard-translate-table))
  654.                (j from)
  655.                (k i)
  656.                (str (make-string (max 0 (- j (1- i))) ?X)))
  657.               (while (<= k j)
  658.             (aset str (- k i) k)
  659.             (setq k (1+ k)))
  660.               str)))
  661.       (aset keyboard-translate-table from to)
  662.       (let ((i (1- (length keyboard-translate-table))))
  663.     (while (and (>= i 0) (eq (aref keyboard-translate-table i) i))
  664.       (setq i (1- i)))
  665.     (setq keyboard-translate-table
  666.           (if (eq i -1)
  667.           nil
  668.         (substring keyboard-translate-table 0 (1+ i))))))
  669.   
  670.   NOTE: You must evaluate the definition of these functions before calling
  671.   them!  For example, list the function definitions before their use in your
  672.   .emacs file.
  673.   
  674.   NOTE: These functions take two numbers as arguments.  The example above,
  675.   `(swap-keys ?A ?B)' is actually `(swap-keys 65 66)', because `?A' is
  676.   merely notation for 65, the ASCII value of `A'.
  677.   
  678.   NOTE: These functions only work for single characters.  You cannot swap
  679.   two multi-character sequences.
  680.   
  681. 137: How do I produce C-XXX with my keyboard?
  682.   
  683.   For C-@ and C-^, often you can just type Control-2 and Control-6.  For
  684.   C-_, you may have to hold down the shift key, typing Control-Shift-Hyphen.
  685.   C-@ can often be generated by typing Control-Space.  C-@ is often called
  686.   the NUL character, and has ASCII value 0.  C-_ can often be generated by
  687.   typing Control-7 or Control-/.  C-? (aka DEL) may be generated by typing
  688.   Shift-BackSpace or Control-BackSpace or a key labelled Delete or Del.
  689.   
  690.   Try Control with all of the digits on your keyboard to see what gets
  691.   generated.
  692.   
  693. 138: What if I don't have a Meta key?
  694.   
  695.   Instead of typing M-a, you can type "ESC a" instead.  In fact, Emacs
  696.   converts M-a internally into "ESC a" anyway (depending on the value of
  697.   meta-prefix-char).
  698.   
  699. 139: What if I don't have an Escape key?
  700.   
  701.   Type C-[ instead.  This should send ASCII code 27 just like an Escape
  702.   key would.  Try also C-;.
  703.   
  704. 140: How do I type DEL on PC terminal emulators?
  705.   
  706.   Some IBM PC compatibles do not have a key labeled `Del' or `Delete' {is
  707.   this true?}.  Those that do generally have it in an inconvenient location.
  708.   (Also, in some terminal emulators, the `Del' key does not transmit DEL.)
  709.   The result is the standard "BackSpace invoking help" problem (see question
  710.   133).
  711.   
  712.   The usual solution, suggested by Michael Covington
  713.   <mcovingt@aisun1.ai.uga.edu>, is to somehow tell the terminal emulator
  714.   program that BackSpace should transmit DEL.  Read the program's manual.
  715.   Shift-BackSpace or Control-BackSpace may send DEL.  The `Del' key may only
  716.   send DEL if the NumLock key hasn't been pressed.
  717.   
  718. 141: Can I make my `Compose Character' key behave like a Meta key?
  719.   
  720.   On a dumb terminal such as a VT220, no.  It is rumored that certain VT220
  721.   clones could have their Compose key configured this way.  If you're using
  722.   X, you might be able to do this with the `xmodmap' program (this is
  723.   what I do).
  724.   
  725. 142: How do I bind a combination of modifier key and function key?
  726.   
  727.   Unless you're using Emacs under emacstool (or xvetool?), have a working
  728.   version of x-rebind-key (see question 128), or are using Emacs 19 (Lucid
  729.   Emacs), you can't do this with Emacs alone.
  730.   
  731.   If you are using emacstool, Emacs sees different character sequences for
  732.   the combination of a modifier and a function key from what it sees for the
  733.   function key alone.  See etc/emacstool.1 for more information.  Since
  734.   Emacs sees different character sequences, you can bind these different
  735.   sequences to different commands.
  736.   
  737.   If you are running Emacs inside a terminal emulator window like xterm, you
  738.   can modify its translation tables to make it generate different character
  739.   sequences for the combination of a modifier and a function key.  For
  740.   example, this X resource setting:
  741.   
  742.     XTerm.VT100.Translations: #override \
  743.       Shift<KeyPress>F1: string(0x1b) string("[xyzzy")
  744.   
  745.   makes Shift-F1 generate the character sequence "ESC [ xyzzy".  You can
  746.   bind these character sequences in Emacs as normal.  Nick Ruprecht
  747.   <ruprecht@informatik.uni-freiburg.de> has written an extensive X
  748.   translation mapping for xterm that does this.  {Does this have an FTP
  749.   site?}
  750.   
  751.   If you have x-rebind-key, you can have any arbitrary combination of
  752.   modifiers with a key replaced by any sequence of "normal" characters.  For
  753.   example, this makes Shift-Return behave as though you had typed "C-x C-e"
  754.   (example from Jerry Graves):
  755.   
  756.     (x-rebind-key "Return" 'shift "\C-x\C-e")
  757.   
  758.   In Emacs 19 (Lucid Emacs), you can bind Meta-Left-Arrow like this (example
  759.   from Jamie Zawinski):
  760.   
  761.     (global-set-key '(meta left) 'backward-word)
  762.   
  763.   With the last two methods, use `xmodmap' and `xev' to discover the keysym
  764.   and modifier names.
  765.   
  766. 143: Why doesn't my Meta key work in an xterm window?
  767.   
  768.   Try all of these methods before asking for further help:
  769.   
  770.   * You may have big problems using `mwm' as your window manager.  {Does
  771.     anyone know a good generic solution to allow the use of the Meta key in
  772.     Emacs with mwm?}
  773.   
  774.   * For X11R4: Make sure it really is a Meta key.  Use `xev' to find out
  775.     what keysym your Meta key generates.  It should be either Meta_L or
  776.     Meta_R.  If it isn't, use xmodmap to fix the situation.
  777.   
  778.   * Make sure the pty the xterm is using is passing 8 bit characters.
  779.     `stty -a' (or `stty everything') should show `cs8' somewhere.  If it
  780.     shows `cs7' instead, use `stty cs8 -istrip' (or `stty pass8') to fix
  781.     it.
  782.   
  783.   * If there is an rlogin connection between the xterm and the Emacs, the
  784.     `-8' argument may need to be given to rlogin to make it pass all 8
  785.     bits of every character.
  786.   
  787.   * If the Emacs is running under Ultrix, it is reported that evaluating
  788.     (set-input-mode t nil) helps.
  789.   
  790.   * If all else fails, you can make xterm generate "ESC W" when you type
  791.     M-W, which is the same conversion Emacs would make if it got the M-W
  792.     anyway.  In X11R4, the following resource specification will do this:
  793.   
  794.       XTerm.VT100.EightBitInput: false
  795.   
  796.     (This changes the behavior of the insert-eight-bit action.)
  797.   
  798.     With older xterms, you can specify this behavior with a translation:
  799.   
  800.       XTerm.VT100.Translations: #override \
  801.         Meta<KeyPress>: string(0x1b) insert()
  802.   
  803.     You might have to replace `Meta' with `Alt'.
  804.   
  805. 144: Why doesn't my ExtendChar key work as a Meta key under HP-UX 8.0?
  806.   
  807.   This is a result of an internationalization extension in X11R4 and the
  808.   fact that HP is now using this extension.  Emacs assumes that
  809.   XLookupString returns the same result regardless of the Meta key state
  810.   which is no longer necessarily true.  Until Emacs is fixed, the temporary
  811.   kludge is to run this command after each time the X server is started but
  812.   preferably before any xterm clients are:
  813.   
  814.     xmodmap -e 'remove mod1 = Mode_switch'
  815.   
  816.   NOTE:  This will disable the use of the extra keysyms systemwide, which
  817.   may be undesirable if you actually intend to use them.
  818.   
  819. 145: Where can I get key bindings to make Emacs emulate WordStar?
  820.   
  821.   There is a package `wordstar' by Jim Frost <jimf@saber.com> and
  822.   `ws-mode.el' by Juergen Nickelsen <nickel@cs.tu-berlin.de>.  Check in the
  823.   Emacs Lisp Archive (see question 89).
  824.   
  825. 146: Where can I get an XEDIT emulator for Emacs?
  826.   
  827.   This question comes up once every couple of months.  I have never seen a
  828.   positive reply, so I presume no one has ever written one.
  829.   
  830.  
  831.  
  832. Using Emacs with Alternate Character Sets
  833.  
  834. 147: How do I make Emacs display 8-bit characters?
  835.   
  836.   There is a patch called the `8-bit ctl-arrow patch' that allows Emacs to
  837.   display characters with codes from 128 to 255.  {The original appears to
  838.   have been by Kenneth Cline <cline@proof.ergo.cs.cmu.edu>.} Partially based
  839.   on Johan Widen's earlier work, Johan Vromans <jv@mh.nl> has updated this
  840.   patch for Emacs 18.58 along with some other 8-bit improvements.
  841.   
  842.   Anonymous FTP:
  843.     /ftp.eu.net:gnu/emacs/FP-EightBit.Z
  844.     /ftp.urc.tue.nl:/pub/tex/emacs/FP-EightBit
  845.     /cs.purdue.edu:pub/ygz/cemacs.tar.Z:cemacs/8bit-patch-18.57
  846.     /sics.se:archive/emacs-18.55-8bit-diff
  847.     /laas.laas.fr:pub/emacs/patch-8bit-18.55
  848.     /laas.laas.fr:pub/emacs/patch-8bit-18.57
  849.   
  850.   Via e-mail:
  851.     To: mail-server@sics.se
  852.     body: send emacs-18.55-8bit-diff
  853.   
  854.   Anders Edenbrandt <anderse@dna.lth.se> has produced a more comprehensive
  855.   patch for Emacs 18.59 that allows for 8-bit input and output.
  856.   
  857.   Anonymous FTP:
  858.     /ftp.efd.lth.se:pub/gnu/emacs_8-bit.patch
  859.  
  860.   In the words of the author:
  861.  
  862.     With these patches, Emacs becomes fully 8-bit operational.  There is
  863.     support for displaying 8-bit characters, as well as for entering such
  864.     characters from the keyboard.  In addition, upcase/lowcase tranlatsion
  865.     is supported, accented characters are recognized as "letters" (important
  866.     when doing 'forward-word', for example), and text with 8-bit characters
  867.     can be sorted correctly.
  868.  
  869.     A Meta-shift key can still be used, provided that you run in an
  870.     environment where it is possible to distinguish between a character
  871.     entered using the Meta-shift key and one entered directly. The diffs
  872.     include patches to make this work under SunView (with emacstool) as
  873.     well as under X.  If you can't use a Meta-shift key, you have to enter
  874.     Meta-commands with the ESC-prefix.
  875.  
  876.   The most comprehensive patches for 8-bit output are by Howard Gayle
  877.   (originally for Emacs 18.55.  These patches allow displaying any arbitrary
  878.   string for a given 8-bit character (except TAB and C-j).  Also supported
  879.   is defining the sorting order and the uppercase and lowercase
  880.   translations.  It is reported that the 8-bit character support in Emacs 19
  881.   is largely based on these patches.  Thomas Bellman
  882.   <Bellman@lysator.liu.se> has updated these patches for Emacs 18.59.
  883.   
  884.   Anonymous FTP:
  885.     /sics.se:archive/emacs-gayle.tar.Z  (patches for 18.55)
  886.     /ftp.lysator.liu.se:pub/emacs/gayle-18.58.diff.tar.Z  (patches)
  887.     /ftp.lysator.liu.se:pub/emacs/emacs-18.59-gayle.tar.Z  (patched Emacs)
  888.   
  889.   Epoch's 8-bit character support is based on Anders Edenbrandt's patches.
  890.   Lucid Emacs has the ctl-arrow patch installed.  Nemacs displays 8-bit
  891.   characters, and it may be useful for displaying the 8-bit ISO-8859
  892.   alphabet, but I don't know for sure (see question 149).
  893.   
  894. 148: How do I input 8-bit characters?
  895.   
  896.   Minor modes for ISO Latin-1 that allow one to easily input this character
  897.   set have been written by several people.  Such modes have been written by
  898.   Matthieu Herrb <matthieu@laas.fr> (laas.laas.fr:pub/emacs/iso-latin-1.el),
  899.   Johan Vromans <jv@mh.nl> {FTP site??}, and Marc Shapiro
  900.   <shapiro@sor.inria.fr> {FTP site??}.
  901.   
  902.   These approaches differ from the one taken by Anders Edenbrandt in that
  903.   his method uses direct 8-bit input, while these methods use a compose
  904.   sequence for 8-bit characters.  {I have heard conflicting reports on
  905.   whether this results in losing the Meta key.  Perhaps this depends on
  906.   whether Emacs is running under X.  Can someone resolve this?}
  907.   
  908.   Karl Heuer <karl@haddock.ima.isc.com> is said to have a patch to allow
  909.   8-bit input.  Georg-Wilhelm Koltermann <gwk@crmunich0.cray.com> also has a
  910.   patch for either 18.57 or 18.58 that allows 8-bit input.
  911.   
  912.   Epoch comes with a patch that allows it to input 8-bit characters, but it
  913.   is not enabled by default.  {Is this right?}
  914.   
  915.   Jamie Zawinski says:
  916.   
  917.     Lucid GNU Emacs allows the input of any ISO-8859/1 keysyms that your
  918.     keyboard generates (see xmodmap), and contains a package that implements
  919.     a DEC/OpenWindows-like "Compose" key for systems which don't have one.
  920.   
  921. 149: Where can I get an Emacs that can handle kanji characters?
  922.   
  923.   Nemacs 3.3.2 (Nihongo GNU Emacs) is a modified version of GNU Emacs 18.55
  924.   that handles kanji characters.  It is available via anonymous FTP:
  925.   
  926.     /crl.nmsu.edu:pub/misc/nemacs-3.3.2.tar.Z
  927.     /miki.cs.titech.ac.jp:JAPAN/nemacs/nemacs-3.3.2.tar.Z
  928.   
  929.   You might also need files for "wnn", a kanji input method
  930.   (wnn-4.0.3{-README,.tar.Z} {on which machine?}).  You need a terminal (or
  931.   terminal emulator) that can display text encoded in JIS, Shift-JIS, or EUC
  932.   (Extended Unix Code), or the ability to run Nemacs as a direct X Window
  933.   client.
  934.   
  935. 150: Where can I get an Emacs that can handle Chinese?
  936.   
  937.   `cemacs' by Stephen G. Simpson <simpson@math.psu.edu> is a patch to Emacs
  938.   18.57 (the ctl-arrow patch) and some Emacs Lisp code that combined with
  939.   Cxterm allows using Chinese characters.  It is available via anonymous
  940.   FTP:
  941.   
  942.     /crl.nmsu.edu:pub/chinese/cemacs.tar.Z
  943.     /cs.purdue.edu:pub/ygz/cemacs.tar.Z
  944.   
  945.   Cxterm is available from the same place:
  946.   
  947.     /cs.purdue.edu:pub/ygz/cxterm-11.5.1.tar.Z
  948.   
  949. 151: Where is an Emacs that can handle Semitic (right-to-left) alphabets?
  950.   
  951.   Joel M. Hoffman <joel@wam.umd.edu> writes:
  952.   
  953.     A couple of years ago a wrote a hebrew.el file that allows right-to-left
  954.     editing of Hebrew.  I relied on the hardware to display the Hebrew
  955.     letters, given the right codes, but not for any right-to-left support;
  956.     the hardware also doesn't have to send any specific char. codes.  Emacs
  957.     keeps track of when the user is typing Hebrew vs. English.  (The VT-*
  958.     terminals in Israel contain built-in support for Hebrew.)
  959.   
  960.     To get it to work I had to modify only a few lines of GNU Emacs's source
  961.     code --- just enough to make it 8-bit clean.
  962.   
  963.     [and in a separate message:]
  964.   
  965.     It doesn't produce time-order ["sefer" format] (I wouldn't recommend
  966.     trying that with emacs, because converting time-order to screen-order
  967.     with arbitrarily long lines is a bit tricky), but I also concocted a
  968.     quick filter to convert screen-order into time-order.  I'll be happy to
  969.     send you the requisite files if you want them.  If you're using it for
  970.     anything large, however, you'll want something that works better.
  971.   
  972.   Joel Hoffman has also written a "bi-directional bi-lingual Emacs-like"
  973.   editor for MS-DOS named Ibelbe (Itty Bitty Emacs-Like Bidirectional
  974.   Editor).  Ibelbe is written in Turbo Pascal and comes with source code.
  975.   Here is the description:
  976.   
  977.     Ibelbe looks like emacs (it even has a minibuffer and filename
  978.     completion), and fully supports both right-to-left and left-to-right
  979.     editing.  Other than an EGA monitor or better, no special hardware is
  980.     required.  You will need an EGA Hebrew font to use Ibelbe with Hebrew.
  981.   
  982.   Anonymous FTP:
  983.     /israel.nysernet.org:israel/msdos/ibelbe.zip
  984.     /israel.nysernet.org:israel/msdos/hebfont.zip
  985.   
  986.   Joseph Friedman <yossi@deshaw.com, yossi@Neon.Stanford.EDU> has written
  987.   patches for Emacs 18.55 and 18.58 that provide Semitic language support
  988.   under X Windows.
  989.   
  990.   Warren Burstein <warren@itex.jct.ac.il> says he has mapped 7-bit keys by
  991.   modifying self-insert-command "for Hebrew input on 7-bit keyboards".
  992.   
  993.   A good suggestion is to query archie for files named with `hebrew'.
  994.   
  995.  
  996.  
  997. ----------------------------------------------------------------------
  998. Copyright (C) 1990, 1991, 1992 Joseph Brian Wells
  999. Copyright (C) 1992, 1993 Steven Byrnes
  1000.  
  1001. This list of frequently asked questions about GNU Emacs with answers
  1002. ("FAQ") may be translated into other languages, transformed into other
  1003. formats (e.g. Texinfo, Info, WWW, WAIS, etc.), and updated with new
  1004. information.  The same conditions apply to any derivative of the FAQ as
  1005. apply to the FAQ itself.  Every copy of the FAQ must include this notice
  1006. or an approved translation, information on who is currently maintaining
  1007. the FAQ and how to contact them (including their e-mail address), and
  1008. information on where the latest version of the FAQ is archived (including
  1009. FTP information).  The FAQ may be copied and redistributed under these
  1010. conditions, except that the FAQ may not be embedded in a larger literary
  1011. work unless that work itself allows free copying and redistribution.
  1012.  
  1013.