Backspace

Christopher Hilton chris at vindaloo.com
Fri Aug 17 12:46:30 PDT 2007


d.Z. wrote:
> Thanks for helping everybody.
> 
> But actually I'm using Bourne shell on FreeBSD 6.1 just like the
> Solaris in lab, and the FreeBSD is freshly installed, I have checked
> .shrc and .profile, but nothing related to key bindings or stty's
> there, so what I thought it should be is:
> 
> after I login -> [press backspace] -> ^H appears -> [press DEL] -> ^? appears
> in emacs -> [press backspace] -> oops, help appears
> 

stty can translate a small set of keystrokes into functions and gets 
used by the shell. In stty you can set the erase character to Ctrl-H. 
The shell uses the stty definitions for the keys.

For historical reasons emacs uses it's own keybindings and they don't 
work well with the default keystrokes emitted by the syscons driver in 
FreeBSD. In particular emacs want's Ctrl-H to start the help system, "H" 
for help... But, CTRL-H is also the default ASCII code sent by the 
Backspace key. That's why backspace works fine in your shell and brings 
up help in emacs. There are at least three solutions to this problem.

In the distant past some old terminals sent the ASCII code DEL (^? , or 
0x7f) when the backspace key was pressed. Most modern terminals and 
terminal emulators can be setup to have this behaviour. In this case you 
can have stty use ^? as your erase character and have emacs respond to 
DEL by deleting the character before the point in the buffer. Then you 
can have FreeBSD send DEL when you press backspace by changing the keymap.

      $ man syscons
      $ man 1 kbdmap
      $ man 5 kbdmap
      $ ls -l /usr/share/syscons/keymaps | grep emacs

To make the change permanent you would modify /etc/rc.conf

      $ grep keymap /etc/defaults/rc.conf

will show you the variable you need to change.

Disclaimer: I've never done it this way.

Another method which involves changing the function of ^H in emacs but 
that makes it difficult to get the help system going. A short search of 
google for "emacs ^h backspace" will probably yield fruit. I used to do 
it this way and it was okay. I t really depends on how much you need the 
help system.

As a long time Gnu Emacs users I can say that the best way to solve this 
problem is to an X11 aware emacs under X-Windows. In this state emacs 
completely bypasses the terminal, catching and interpreting the 
keystroke events from the X window system. Since X can say 'The user 
pressed "KeyBackspace" which has an ASCII code of 0x08 (Ctrl-H)' emacs 
can see that as a Backspace attempt and delete the appropriate 
character. Further more X can differentiate that keypress from "The user 
pressed 'H' while holding down Ctrl which gives an ASCII code of 0x08". 
Emacs gets complete information from the X-Windows system and can take 
the right action, starting the help system.

-- Chris

-- 
       __o          "All I was doing was trying to get home from work."
     _`\<,_           -Rosa Parks
___(*)/_(*)___________________________________________________________
Christopher Sean Hilton                    <chris | at | vindaloo.com>
         pgp key: D0957A2D/f5 30 0a e1 55 76 9b 1f 47 0b 07 e9 75 0e 14


More information about the freebsd-questions mailing list