If you’re as crazy as I am and want to run GNU Emacs in GNU/Linux without X11 or Wayland, but your Backspace key isn’t working as epxected, then you’ll want the following in your Emacs config file:
(setq term-setup-hook
'(lambda ()
(setq keyboard-translate-table "\C-@\C-a\C-b\C-c\C-d\C-e\C-f\C-g\C-?")
(global-set-key "\M-h" 'help-command)))
This bit of Lisp will force Emacs to interpret the Backspace and Delete keys in a manner consistent with X11 and Wayland.
It will also cause Emacs to not treat C-h as the help key, which is why I remapped the help-command function to M-h.
Why am I doing this? There is a method to my madness, or at least a story behind it. I didn’t want to make you — Occasional Reader — scroll through an old man’s maunderings to get to the good shit. But if you have a moment to spare, here’s the deal.
Back in the day, the only computers that let you boot directly into a GUI were the Mac and the Amiga. My school didn’t have any Amigas. Only teachers were allowed to touch the Macs. Kids like me had to make do with Commodore 64s, or — later on — IBM clones running MS-DOS.
Admittedly, some of the IBM clones had DOS configured so that it would immediately start Windows 3.1, but remember: this is Microsoft Windows. Bill Gates insisted that Windows was the future, but Mel Brooks taught me that even in the future nothing works. And when Windows 3.1 failed, it usually dumped you right back at a DOS prompt, where you were shit out of luck if you didn’t know how to work a command line.
I learned how.
Then I found that I liked it.
Damn good thing I did, since the first computer I was able to buy with my own money only had DOS.
And in college, all of the SPARCstations running SunOS started in text mode, and if you wanted a GUI you would type startx instead of win.
Somewhere along the way I lost my taste for a plain text interface.
I’d still use a shell, but in a terminal emulator that ran within the X Window System like xterm.
Or, if I was on a Mac, I’d run terminal.app.
Once I got into using GNU Emacs and trying to do more with Emacs than merely editing text, I found myself wanting to use Emacs on GNU/Linux without the X Window System. I wanted to party like it was 1979. There was just one thing stopping me. I had never figured out how to make the Backspace key work properly in Emacs when running it in a virtual terminal in Linux. I don’t think I had ever figured out how to make it work on a BSD, either.
What bugged me was that other editors did not have this problem.
It worked in vim (in insert mode),
nano,
joe,
jove,
mg,
zile,
and ne.
It even worked in ed(1) (in insert mode, at least).
But not in GNU Emacs.
It was infuriating.
Nonetheless, it was a self-inflicted First World Problem. Nobody was holding a knife to my throat and forcing me to use Emacs, let alone use it in a virtual terminal. So I’d go back to using Emacs in X11 and forget about it for a while.
Not this time, though. This time, I finally figured it out. Maybe because I had already spent some time on the cusp of the new year tinkering with my setup. It doesn’t really matter.
What matters is that I finally got what I wanted. I can now run Emacs without X11 any time I want to. Which is how I wrote this post, incidentally.
I recommend that you try it. It’s actually quite pleasant. But if it’s not for you, I understand. Life in a 16-color text console isn’t for everyone. But it works for me.