TACKER: peabody (Sam Peterson)
SUBJECT: .. pesky ^H and emacs
DATE: 22-Jan-05 01:52:47
HOST: otaku

This is a historical problem with emacsen and terminals. emacs isn't the
only program effected by this, but with emacs it's particularly problematic
due to a number of reasons.

First, I recommend reading the ASCII page on Wikipedia, which is an
excellent resource to really illustrate some things:


The <BS> versus <DEL> problem is much like the LN vs CR vs CRLN line
ending issue you see in Ascii on different computers. Basically a long
time ago there were two characters used, since in hardware it was two
operations particularly with line printers, so you had <BS> for moving
backwards, and <DEL> for voiding the character on the tape reel. Well,
computers got better and decided they only needed to use one character to
do the same in software. Some used <DEL>, others went with <BS>.

Emacs historically was written on machines that used the <DEL> to erase
characters to the left of the cursor. Since <BS> (which is the sequence
Ctrl-H, or ^H) wasn't being used and C-h seemed like a good mnuemonic for
"help" it was used as the keyboard shortcut for the help system. Well, the
free *nix revolution took over and unix machines started running on intel
hardware, where <BS> was used instead of <DEL>. Now, when you run a *nix
yourself on your own machine, <BS> is often mapped to <DEL> on the terminal
(at least it is in Linux I believe), so this isn't a problem (and in X,
programs pretty much have direct control over the keyboard so they can tell
the difference between <BS> and ^H). However, when using a terminal
emulation program and logging into a remote machine, this can get fuddled.

Now the solution was a little program called `stty' which would program
terminal settings. You could use stty to set the `erase' character to
either ^H or ^? then the program can get this setting from the terminal
and use that Control sequence as its erase. This generally fixes the
problems with most programs.

Unfortunately not with Emacs.

Emacs takes much more control over your terminal. It's historically done
this because Emacs was programmed to be a bit of a Window environment for
the terminal. Back in the day when GUIs were uncommon (or non-existant)
all you had was the command prompt. Emacs quickly grew to fill the void of
a `desktop environment' for the CLI world. You'd load it, open multiple
windows, and run inferior processes to the shell when you need those unix
utilities. To do this, it would take direct control of the terminal, and
use it's own database for what terminal you were using to draw it's
environment. It can do a fairly good job about this, but seems to have an
odd quirk, in that if you set ^H as the `erase' character on your terminal,
it's mapped to <DELETE> instead of <DEL>. I'm not sure why, but the bottom
line is stty doesn't solve the problem.

So what does? A few different things.

The best way to solve the problem is to get your terminal emulator software
to send <DEL> instead of <BS> for your 'Backspace' key. I known that Putty
can do this in it its settings. Then just make sure stty is run like this
from your .profile (or whatever startup you use for your shell):

$ stty erase ^?

This is the most ideal situation, as it makes ^H work for the help system,
and deletes properly.

If making your term software send <DEL> instead of <BS> seems too
problematic, this command will always work to toggle the <DEL>/<BS>
problems from within Emacs:

ESC x normal-erase-is-backspace <RET>

This will map ^H to deleting properly, but now the help system will be
inaccesible from ^H on the keyboard. In which case:

ESC x help <RET>

will get you into the help system.

There are plenty of other ways to solve this, including various emacs-lisp
incantations in the .emacs startup file, but I won't go over them here.

Good luck. Let me know if you have any more emacs questions.