I sometimes like to use
fire up shells in emacs. Recently I noticed a subtle problem with these
shells in OSX: in certain programs (such as
less), the backspace key will insert a string
instead of deleting.
The reason for this is that
stty erase is unset. You can check this
stty -a within these terminal emulators; in the output you will see that
...; erase = <undef>; ...
whereas we want
erase = ^?. (
^?, i.e. Control+Question mark,
is the raw key mapped to backspace).
The terminal emulator should be setting this key from the
terminfo file, but for some reason I couldn't get this to work properly
on OSX (other settings within the terminfo file appeared to be read, but for some reason
the setting of backspace was being ignored).
So to fix this, I instead wound up adding the following to my
.bashrc if you use
if [[ -n $INSIDE_EMACS && $(uname) == 'Darwin' ]]; then stty ek fi
This snippet checks if we are starting up a shell inside OSX emacs,
and if so, manually sets backspace to use the system defaults.
stty ek, you can also do
stty erase ^\?.