Commit e1b79824 authored by Glenn Morris's avatar Glenn Morris
Browse files

Move to admin/notes/multi-tty, with some edits.

parent 24cdde13
......@@ -3,6 +3,12 @@
* (AH_BOTTOM): Copy some manual changes made to
src/ here so they are not lost when it regenerates.
* README.multi-tty: Move to admin/notes/multi-tty, with some edits.
2007-08-29 Karoly Lorentey <>
* README.multi-tty: New file.
2007-08-29 Glenn Morris <>
* README: Increase version to 23.0.50.
-*- coding: utf-8; mode: text; -*-
This branch implements support for opening multiple, different tty
devices and simultaneous X and tty frames from a single Emacs session.
Some use cases:
Emacs is notoriously slow at startup, so most people use another
editor or emacsclient for quick editing jobs from the console.
Unfortunately, emacsclient was very awkward to use, because it did not
support opening a new Emacs frame on the current virtual tty.
Now, with multi-tty support, it can do that. (Emacsclient starts up
faster than vi!)
Some Gnus users (including me) run Gnus in an X frame in its own Emacs
instance, which they typically leave running for weeks. It would be
nice if they could connect to this instance from a remote ssh session
and check their messages without opening a remote X frame or resorting
to gnus-slave.
The following is a (sadly incomplete) list of people who have
contributed to the project by testing, submitting patches, bug
reports, and suggestions. Thanks!
Bernard Adrian <>
ARISAWA Akihiro <>
Vincent Bernat <>
Han Boetes <>
Francisco Borges <>
Damien Cassou <>
Robert J. Chassell <>
Romain Francoise <>
Ami Fischman <>
Noah Friedman <>
Friedrich Delgado Friedrichs <>
Samium Gromoff <>
Mikhail Gusarov <>
Eric Hanchrow <>
IRIE Tetsuya <>
Yoshiaki Kasahara <>
Bas Kok <>
Jurej Kubelka <>
David Lichteblau <>
Richard Lewis <>
mace <>
Suresh Madhu <>
Xavier Mallard <>
Istvan Marko <>
Ted Morse <>
Gergely Nagy <>
Dan Nicolaescu <>
Kalle Olavi Niemitalo <>
Mark Plaksin <>
Frank Ruell <>
Tom Schutzer-Weissmann <>
Joakim Verona <>
Dan Waber <>
and many others.
Richard Stallman was kind enough to review an earlier version of my
The branch is now very stable and almost full-featured. All of the
major problems have been fixed, only a few minor issues remain. (It
still needs to be ported to Windows/Mac/DOS, though.) Both multiple
tty device support and simultaneous X and tty frame support works
fine. Emacsclient has been extended to support opening new tty and X
frames. It has been changed to open new Emacs frames by default.
The multi-tty branch has been scheduled for inclusion in the next
major release of Emacs (version 23). I expect the merge into the
development trunk to occur sometime during next year (2006), after the
merge of the Unicode branch.
Tested on GNU/Linux, Solaris 8, FreeBSD and OpenBSD. Please let me
know if you succeed or fail to use it on other platforms---I'll have a
few tricky test cases for you.
Known problems:
* GTK support. If you compile your Emacs with the GTK
toolkit, some functionality of multi-tty may be lost. In
particular, you may get crashes while working on multiple X
displays at once. Previous releases of GTK had limitations
and bugs that prevented full-blown multi-display support in
Emacs. (GTK crashed when Emacs tries to disconnect from an
X server.) Things are much improved in the current GTK
version, but if you do experience crashes in libgtk, try
compiling Emacs with the Lucid toolkit instead.
* The single-kboard mode.
If your multi-tty Emacs session seems to be frozen, you
probably have a recursive editing session or a pending
minibuffer prompt (which is a kind of recursive editing) on
another display. To unfreeze your session, switch to that
display and complete the recursive edit, for example by
pressing C-] (`abort-recursive-edit').
I am sorry to say that currently there is no way to break
out of this "single-kboard mode" from a frozen display. If
you are unable to switch to the display that locks the
others (for example because it is on a remote computer),
then you can use emacsclient to break out of all recursive
editing sessions:
emacsclient -e '(top-level)'
Note that this (perhaps) unintuitive behaviour is by design.
Single-kboard mode is required because of an intrinsic Emacs
limitation that is very hard to eliminate. (This limitation
is related to the single-threaded nature of Emacs.)
I plan to implement better user notification and support for
breaking out of single-kboard mode from locked displays.
* Mac and DOS support is broken, doesn't even
compile. Multiple display support will probably not provide
new Emacs features on these systems, but the multi-tty
branch changed a few low-level interfaces, and the
system-dependent source files need to be adapted
accordingly. The changes are mostly trivial, so almost
anyone can help, if only by compiling the branch and
reporting the compiler errors.
To get the branch, check out the "multi-tty" CVS branch from Emacs CVS.
Alternatively, you can use Bazaar version 1 (not 2) or tla:
baz register-archive
baz get <directory>
The multi-tty branch is compiled the same way as Emacs itself:
make maintainer-clean # (If you have compiled Emacs before)
./configure <your favourite options>
make bootstrap
make install
If you have strange compilation errors, they may be caused by old
*.elc files that are left over from an earlier bootstrap. The `make
maintainer-clean' target deletes them, so it is a good idea to run
that before reporting a bug. (Emacs requires a clean recompilation
after certain kinds of source code changes.)
To test the multi-tty branch, start up the Emacs server with the
following commands:
M-x server-start
and then (from a shell prompt on another terminal) start emacsclient
emacsclient -t /optional/file/names... (for a tty frame)
emacsclient /optional/file/names... (for an X frame)
(Make sure both emacs and emacsclient are multi-tty versions.)
You'll hopefully have two fully working, independent frames on
separate terminals. The new frame is closed automatically when you
finish editing the specified files (C-x #), but delete-frame (C-x 5 0)
also works. Of course, you can create frames on more than two tty
Creating new frames on the same tty with C-x 5 2 (make-frame-command)
works, and behaves the same way as in previous Emacs versions. If you
exit emacs, all terminals should be restored to their previous states.
This is work in progress, and probably full of bugs. It is a good
idea to run emacs from gdb, so that you'll have a live instance to
debug if something goes wrong. Please send your bug reports to Please don't forget to mention that you are
using the multi-tty branch.
I think the best way to use the new Emacs is to have it running inside
a disconnected GNU screen session, and always use emacsclient for
normal work. One advantage of this is that not a single keystroke of
your work will be lost if the display device that you are using
crashes, or the network connection times out, or whatever. (I had an
extremely unstable X server for some time while I was developing these
patches, and running Emacs this way has saved me a number of M-x
recover-session invocations.)
I use the following two bash scripts to handle my Emacs sessions:
# Usage: connect-emacs <name> <args>...
# Connects to the Emacs instance called NAME. Starts up the instance
# if it is not already running. The rest of the arguments are passed
# to emacsclient.
if [ -z "$name" ]; then
echo "Usage: connect_emacs <name> <args>..." >&2
exit 1
preload-emacs "$name" wait
/usr/bin/emacsclient.emacs-multi-tty -s "$name" "$@"
# Usage: preload-emacs <name> [<waitp>]
# Preloads the Emacs instance called NAME in a detached screen
# session. Does nothing if the instance is already running. If WAITP
# is non-empty, the function waits until the server starts up and
# creates its socket; otherwise it returns immediately.
emacs=/usr/bin/emacs-multi-tty # Or wherever you installed your multi-tty Emacs
if [ -z "$name" ]; then
echo "Usage: preload_emacs <name> [<waitp>]" >&2
exit 1
if [ ! -e "$screendir"/*."$name" ]; then
if [ -e "$serverdir/$name" ]; then
# Delete leftover socket (for the wait option)
rm "$serverdir/$name"
screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
if [ ! -z "$waitp" ]; then
while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
I have the following in my profile to have two instances automatically
preloaded for editing and email:
preload-emacs editor
preload-emacs gnus
It is useful to set up short aliases for connect-emacs. I use the
alias edit="connect-emacs editor"
alias e=edit
alias et="connect-emacs editor -t"
alias gnus="connect-emacs gnus"
See the ChangeLog.multi-tty files in the source tree.
For the NEWS file: (Needs much, much work)
** Support for multiple terminal devices and simultaneous graphical
and tty frames has been added. You can test for the presence of
this feature in your Lisp code by testing for the `multi-tty'
*** The `window-system' variable has been made frame-local. The new
`initial-window-system' variable contains the `window-system'
value for the first frame.
*** You can specify a terminal device (`tty' parameter) and a terminal
type (`tty-type' parameter) to `make-terminal-frame'.
*** The new function `make-frame-on-tty' allows you to create a new
frame on another tty device interactively.
*** The function `make-frame-on-display' now works during a tty
session, and `make-frame-on-tty' works during a graphical session.
*** Emacsclient has been extended to support opening a new terminal
frame. Its behaviour has been changed to open a new Emacs frame by
default. Use the -c option to get the old behavior of opening
files in the currently selected Emacs frame.
*** C-z now invokes `suspend-frame', C-x C-c now invokes
*** New functions: frame-tty-name, frame-tty-type, delete-tty,
suspend-tty, resume-tty, terminal-id, terminal-parameters,
terminal-parameter, set-terminal-parameter,
modify-terminal-parameters, environment, let-environment
*** New variables: local-key-translation-map, local-function-key-map
*** New frame parameters display-environment-variable and
*** The `keyboard-translate-table' variable and the terminal and
keyboard coding systems have been made terminal-local.
*** In addition to the global key-translation-map and
function-key-map, Emacs has terminal-local
local-key-translation-map and local-function-key-map variables,
and uses them instead of the global keymaps to set up translations
and function key sequences relevant to a specific terminal device.
*** talk.el has been extended for multiple tty support.
* * *
(The rest of this file consists of my development notes and as such it
is probably not very interesting for anyone else.)
** See if `tty-defined-color-alist' needs to be terminal-local.
Update: Dan says it should be, so convert it.
** Mikhail Gusarov suggest to add a hook akin to
`after-make-frame-functions' that is called whenever Emacs connects
to a new terminal. Good idea!
** emacsclient -t on the console does not work after su. You have to
use non-root accounts or start as root to see this.
Login: root
# su lorentey
$ emacsclient -t
*ERROR*: Could not open file: /dev/tty1
The tty can be opened as /dev/tty by emacsclient, but not by Emacs.
This seems to be a serious problem. Currently my only idea is to
bring back the ugly pty proxy hack from the initial versions of
multi-tty. Suggestions would be appreciated.
Update: we could change emacsclient to pass its open file
descriptor to the Emacs process. Unfortunately, this requires a
new Lisp-level Emacs API, and as file descriptors are not otherwise
exported to Lisp, this approach seems at least as ugly as the pty
proxy idea.
** lisp/vc.el depends on the terminal type during load time.
`vc-annotate-color-map' is one example that needs to be fixed.
** Understand how `quit_throw_to_read_char' works, and fix any bugs
that come to light.
** See if getcjmp can be eliminated somehow. Why does Emacs allow
asynchronous input processing while it's reading input anyway?
** `delete-frame' events are handled by `special-event-map'
immediately when read by `read_char'. This is fine but it prevents
higher-level keymaps from binding that event to get notified of the
deleted frame.
Sometimes it would be useful for Lisp code to be notified of frame
deletions after they have happened, usually because they want to
clean up after the deleted frame. Not all frame-local states can
be stored as a frame parameter. For example,
`display-splash-screen' uses `recursive-edit' with a special keymap
override to create its buffer---and it leads to all kinds of
nastiness if Emacs stays in this recursive edit mode after the
frame containing the splash screen is deleted. Basically, the
splash-screen implementation wants to throw out of the recursive
edit when the frame is deleted; however, it is not legal to throw
from `delete-frame-functions' because `delete-frame' must not fail.
(Introducing `delete-frame-after-functions' would not help either
because `delete-frame' may not fail at that time either.)
Currently `fancy-splash-screens' installs a
`delete-frame-functions' hook that sets up a timer to exit the
recursive edit. This is an adequate solution, but it would perhaps
be better to have something like a `frame-deleted' event that could
be bound in the normal way.
** Trouble: `setenv' doesn't actually set environment variables in the
Emacs process. This defeats the purpose of the elaborate
`server-with-environment' magic around the `tgetent' call in
`init_tty'. D'oh.
** (Possibly) create hooks in struct device for creating frames on a
specific terminal, and eliminate the hackish terminal-related frame
parameters (display, tty, tty-type).
** Decide whether to keep the C implementation of terminal parameters,
or revert to the previous, purely Lisp code. It turned out that
local environments do not need terminal parameters after all.
** Move Fsend_string_to_terminal to term.c, and declare get_named_tty
as static, removing it from dispextern.h.
Move fatal to emacs.c and declare it somewhere.
** Search for `suspend-emacs' references and replace them with
`suspend-frame', if necessary. Ditto for `save-buffers-kill-emacs'
vs. `save-buffers-kill-display'.
** Emacs crashes when a tty frame is resized so that there is no space
for all its windows. (Tom Schutzer-Weissmann)
** Report GTK multi-display problems to GTK maintainers. For extra
credit, fix them.
Currently you can not connect to new X displays when you compile
Emacs with GTK support. If you want to play around with GTK
multidisplay (and don't mind core dumps), you can edit src/config.h
and define HAVE_GTK_MULTIDISPLAY there by hand.
Update: Han reports that GTK+ version 2.8.9 almost gets display
disconnects right. GTK will probably be fully fixed by the time
multi-tty gets into the trunk.
Update: I am still having problems with GTK+ 2.8.10. I have the
impression that the various multidisplay fixes will only get
released in GTK+ 2.10.
** Audit `face-valid-attribute-values' usage in customize and
elsewhere. Its return value depends on the current window system.
Replace static initializers using it with runtime functions. For
example, custom's buttons are broken on non-initial device types.
** Possibly turn off the double C-g feature when there is an X frame.
C.f. (emacs)Emergency Escape.
** frames-on-display-list should also accept frames.
** Consider the `tty-type' frame parameter and the `display-tty-type'
function. They serve the exact same purpose. I think it may be
a good idea to eliminate one of them, preferably `tty-type'.
** The handling of lisp/term/*.el, and frame creation in general, is a
big, big mess. How come the terminal-specific file is loaded by
tty-create-frame-with-faces? I don't think it is necessary to load
these files for each frame; once per terminal should be enough.
Update: lisp/term/*.el is not loaded repeatedly anymore, but
faces.el still needs to be cleaned up.
** Fix frame-set-background-mode in this branch. It was recently
changed in CVS, and frame.el in multi-tty has not yet been adapted
for the changes. (It needs to look at
default-frame-background-mode.) (Update: maybe it is fixed now;
needs testing.) (Note that the byte compiler has this to say about
term/rxvt.el:309:17:Warning: assignment to free variable
** I think `(set-)terminal-local-value' and the terminal parameter
mechanism should be integrated into a single framework.
(Update: `(set-)terminal-local-value' is now eliminated, but the
terminal-local variables should still be accessible as terminal
parameters. This also applies to `display-name' and similar
** Add the following hooks: after-delete-frame-hook (for server.el,
instead of delete-frame-functions),
after-delete-terminal-functions, after-create-terminal-functions.
** BULK RENAME: The `display-' prefix of new Lisp-level functions
conflicts with stuff like `display-time-mode'. Use `device-'
or `terminal-' instead. I think I prefer `terminal-'.
It turns out that most of the offending Lisp functions were defined
in the trunk. Therefore, compatibility aliases should be defined
for the following names:
display-color-cells terminal-color-cells
display-color-p terminal-color-p
display-graphic-p terminal-graphic-p
display-grayscale-p terminal-grayscale-p
display-images-p terminal-images-p
display-mm-height terminal-mm-height
display-mm-width terminal-mm-width
display-mouse-p terminal-mouse-p
display-multi-font-p terminal-multi-font-p
display-multi-frame-p terminal-multi-frame-p
display-pixel-height terminal-pixel-height
display-pixel-width terminal-pixel-width
display-pixels-per-inch terminal-pixels-per-inch
display-planes terminal-planes
display-popup-menus-p terminal-popup-menus-p
display-save-under terminal-save-under
display-screens terminal-screens
display-supports-face-attributes-p terminal-supports-face-attributes-p
display-visual-class terminal-visual-class
framep-on-display framep-on-terminal
frames-on-display-list frames-on-terminal-list
The following functions were introduced in the multi-tty branch, and
were renamed without aliases:
delete-display delete-terminal
display-controlling-tty-p controlling-tty-p
display-list terminal-list
display-live-p terminal-live-p
display-name terminal-name
display-tty-type tty-type
frame-display frame-terminal
selected-display selected-terminal
** The single-keyboard mode of MULTI_KBOARD is extremely confusing
sometimes; Emacs does not respond to stimuli from other keyboards.
At least a beep or a message would be important, if the single-mode
is still required to prevent interference. (Reported by Dan
Update: selecting a region with the mouse enables single_kboard
under X. This is very confusing.
Update: After discussions with Richard Stallman, this will be
resolved by having locked displays warn the user to wait, and
introducing a complex protocol to remotely bail out of
single-kboard mode by pressing C-g.
Update: Warning the user is not trivial to implement, as Emacs has
only one echo area, shared by all frames. Ideally the warning
should not be displayed on the display that is locking the others.
Perhaps the high probability of user confusion caused by
single_kboard mode deserves a special case in the display code.
Alternatively, it might be good enough to signal single_kboard mode
by changing the modelines or some other frame-local display element
on the locked out displays.
Update: In fact struct kboard does have an echo_string slot.
** The session management module is prone to crashes when the X
connection is closed and then later I try to connect to a new X
#0 0xb7ebc806 in SmcGetIceConnection () from /usr/X11R6/lib/
#1 0x080e6641 in x_session_check_input (bufp=0xbf86c9c0) at xsmfns.c:144
#2 0x080d3bbc in XTread_socket (device=0xa722ff8, expected=1, hold_quit=0xbf86ca90) at xterm.c:7037
#3 0x080fa404 in read_avail_input (expected=1) at keyboard.c:6696
#4 0x080fa4ca in handle_async_input () at keyboard.c:6900
#5 0x080d51fa in x_term_init (display_name=162628899, xrm_option=0x0, resource_name=0x857068c "emacs") at xterm.c:10622
#6 0x080d920e in x_display_info_for_name (name=162628899) at xfns.c:3975
#7 0x080d92f9 in check_x_display_info (object=1) at xfns.c:274
#8 0x080d97b8 in Fx_create_frame (parms=151221485) at xfns.c:3016
#9 0x0815bf72 in Ffuncall (nargs=2, args=0xbf86ceec) at eval.c:2851
I installed a workaround to prevent this. The X session manager is
only contacted when the very first display in the Emacs session is
an X display. Also, x_delete_display() on this display aborts
session management, and XTread_socket only calls
x_session_check_input when it is called for the display that the
session was opened on. While this does not really fix the bug, it
makes it much less frequent, because session manager support will
not normally be enabled when Emacs can survive the shutdown of the
X server.
See if xsmfns.c should be updated.
** Hunt down display-related functions in frame.el and extend them all
to accept display ids.
** rif->flush_display_optional (NULL) calls should be replaced by a
new global function.
** The set-locale-environment hack (adding the DISPLAY option) should
be replaced with a clean design.
** standard-display-table should be display-local.
standard-display-european should be display-local.
** With iswitchb-default-method set to 'always-frame, only frames on
the current display should be considered. This might involve
extending `get-buffer-window'.
** Have a look at Vlocale_coding_system. Seems like it would be a
tedious job to localize it, although most references use it for
interfacing with libc and are therefore OK with the global
Exceptions found so far: x-select-text and
** Have a look at fatal_error_hook.
** Have a look at set_frame_matrix_frame.
** Check if we got term-setup-hook right.
** I think tip_frame should be display-local.
** Check display reference count handling in x_create_tip_frame.
** make-frame does not correctly handle extra parameters in its
(frame-parameter (make-frame (list (cons 'foobar 42))) 'foobar)
=> nil
(This is likely an error in the CVS trunk.)
** Dan Nicolaescu suggests that -nw should be added as an alias for -t
in emacsclient. Good idea. (Alas, implementing this is not
trivial, getopt_long does not seem to support two-letter ``short''
options. Patches are welcome.)
** Mark Plaksin suggests that emacsclient should accept the same
X-related command-line arguments as Emacs. Most of the X-related
argument-handling is done in Lisp, so this should be quite easy to
implement. (For example, Samium Gromoff wants emacsclient to
support --geometry; implementing this would add that support.)
** Gergely Nagy suggests that C-x # should only kill the current
frame, not any other emacsclient frame that may have the same file
opened for editing. I think I agree with him.
** Very strange bug: visible-bell does not work on secondary
terminals in xterm and konsole. The screen does flicker a bit,
but it's so quick it isn't noticable.
(Update: This is probably some problem with padding or whatnot on
the secondary terminals.)
** Move baud_rate to struct display.
** Implement support for starting an interactive Emacs session without
an initial frame. (The user would connect to it and open frames