EmacsOnTerminal

This is a node about running Emacs on serial text terminals, often erroneously called “dumb terminals”. These type of terminals were primarily manufactured from the mid-70s to the mid-90s. The protocols used by the most popular of these terminals, DEC vt100 and vt220 are emulated by all modern Unix-like operating systems, such as GnuIsNotUnix and the BSDs. This node is not about running Emacs on these terminal emulators, but about running it on actual, physical serial terminals. Emacs includes support for not only vt100 and vt220 but many other terminal types.

Most of this applies to Unix-like systems, like the GnuIsNotUnix and the BSDs. EmacsOnVMS is also a candidate topic here, and perhaps EmacsForOSTwo, but other systems are not likely to be accessed via a serial terminal. A lot of reference information for terminals, especially DEC and compatible terminals, is located at http://vt100.net.

The most basic environment variable on the Unix-like operating systems that affects serial terminals is TERM. Under most circumstances, it gets its setting from the program that first launches the serial connection for the terminal. For xterm and other graphical terminal emulators, it is set by the emulator program itself. For actual serial terminals, it is set by the getty program (usually agetty on GnuIsNotUnix systems) that controls the serial socket. On sysvinit-based systems, this is usually controlled by the init process and configured in /etc/inittab, while on newer systemd-based systems, it is configured by a serial console unit file (usually stored in /lib/systemd/system/serial-getty@.service, but this varies depening on the distribution). Note that, contrary to advice found throughout the Internet, in most circumstances you should not set TERM in your .profile because under most circumstances, it should be set for you by either your terminal emulator software or by the getty process that controls your terminal.

The value of the TERM variable will be used by command line programs to look up terminal capabilities in the terminfo database on your system. Therefore, its value should be set carefully to match the capabilities of your terminal. Consult your operating system’s terminfo database for a full list of supported terminal types. When in doubt, many terminals are compatible with vt220, and most are compatible with vt100, although using these as fallbacks may result in some of the capabilities of a more advanced terminal being disabled. Other relevant environment variables for shells of the sh-family are COLUMNS and LINES. These should match your terminal configuration, but in most cases you won’t have to set them yourself.

When Emacs starts in a terminal, it tries to load terminal-specific lisp code at “term/${TERM}.el”, for example, “term/vt420.el”. These libraries usually set reasonable defaults for keybindings and other aspects of the terminal.

You will want to have hardware flow control, and you must turn it on for both the terminal itself, and for the getty process. Alternatively, you can use stty(1) command, to tweak your serial line parameters.

Flow control is crucial at speeds above 9600bps. The software flow control protocol (XON/XOFF) will interfere with Emacs’ C-s and C-q events, so you’ll want hardware flow control (DTR/DSR or RTS/CTS). If you must use software flow control, the Emacs library flow-ctrl provides some convenience features, most notably the command enable-flow-control which remaps the C-s and C-q keys. Other ways to handle use of XON/XOFF include using the unix command stty -ixon or (set-input-mode t nil t) from Emacs.

If the Emacs display does end up glitching out, use the command recenter to re-draw the screen. By default it’s bound to C-l.

Notes about certain terminals

DEC's VT-series of terminals

Terminals by Digital Equipment Corporation, or |d|i|g|i|t|a|l| are common, and often emulated. Perhaps the most common terminal mode of all is the vt100, followed closely by vt220. Emacs handles these terminals fairly well, although there is room for improvement.

Make sure you use the “vt200/300/400 mode”, 7-bit, space parity in your terminal communication settings; do not use the 8-bit controls. (This is per etc/TERMS which is admittedly over 20 years old, so perhaps 8-bit controls work now.) Don’t try to open files containing Unicode characters; no VT terminal supports Unicode.

The VT200-400 series cannot process more than 9600bps (regardless of the serial connection speeds of which they’re capable) and have no hardware flow control. The software flow control protocol (XON/XOFF) will wreak havoc with Emacs keybindings, as discussed above, so the best advice for a local connection is to set the terminal to 9600bps or lower.

Note that modern versions of Emacs provide only two compatibility files for DEC terminals, vt100 and vt200. Aliases in the variable term-file-alias are provided by default, including vt102, vt125, vt220, vt240, vt300, vt320, vt400, vt420. However, this is not an exhaustive list of DEC terminal models supported by the terminfo database. If you are using another supported DEC terminal, e.g. a vt131, vt132, vt330, or vt340, you will need to add an alias for that to your term-file-alias, otherwise Emacs won’t properly recognize your terminal, and you’ll encounter all manner of keyboard and display glitches.

Most of the special keys of the VT200-400 series keyboard, the LK201 (and its nearly identical successor the LK401), work by default, though some quirks exist.

Certain values for the keyboard type from the terminal’s menus (f.ex. “Finnish keyboard”) make the S-3 produce section-symbol “§”, and not the hash-symbol “#” one expects. The compose character -key is used to compensate this, by compose + +.

The terminal’s keyboard also has two modes, “typewriting keys” and “data processing keys”. For instance the former allow the keys left of RET to be used for scandinavian chars with a finnish keyboard, the latter enables the curly braces, brackets and others on the same keys. This is a bit of a nuisance, but again, can be compensated for with the compose key.

Success stories

tekonivel's DEC VT420

tekonivel occasionally uses a DEC VT420 over a null-modem cable to a GnuIsNotUnix system, and it works just fine. Though the speed is set quite low, to 9600, it’s still usable, as Emacs wisely updates only the parts of screen that have changed. The VT420 is used in a mode with 132 columns and 48 rows, page-length also set to 48 to get fullscreen pages. The cable is simple, and doesn’t provide hardware flowcontrol. There’s actually none in use, because the speed is low enough.

Actually the terminal is used in VT220 emulation mode, because the “vt420” termcap entry doesn’t happen to be installed on one of the machines it’s used for. vt220 mode is the default for the line in /etc/inittab of the host computer, as well as for the terminal itself.

The Alt key doesn’t work at all, which is a bit of a pain in the neck.