1 -*- coding: utf-8; mode: text; -*-
5 The goal of this branch is to implement support for opening multiple,
6 different tty devices and simultaneous X and tty frames from a single
10 Emacs is notoriously slow at startup, so most people use another
11 editor or emacsclient for quick editing jobs from the console.
12 Unfortunately, emacsclient was very awkward to use, because it did not
13 support opening a new Emacs frame on the current virtual console.
14 Now, with multi-tty support, it can do that. (Emacsclient starts up
17 Some Gnus users (including me) run Gnus in an X frame in its own Emacs
18 instance, which they typically leave running for weeks. It would be
19 nice if they could connect to this instance from a remote ssh session
20 and check their messages without opening a remote X frame or resorting
26 I'm Károly Lőrentey. My address: lorentey@elte.hu.
28 Comments, bug reports, suggestions and patches are welcome!
30 Retrieving the latest version of the branch:
32 tla register-archive lorentey@elte.hu--2004 http://lorentey.web.elte.hu/arch/2004/
33 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
35 (I use a recent arch development snapshot, but any of the released
36 versions of arch will do fine, I think.)
38 If you don't have arch, the branch has a homepage from which you can
39 download conventional patches against Emacs CVS HEAD:
41 http://lorentey.web.elte.hu/project/emacs.html
43 If you want to be notified of new revisions, sign up to the
44 multi-tty@listbox.elte.hu mailing list by visiting the
45 below homepage and following its instructions.
47 https://listbox.elte.hu/mailman/listinfo/multi-tty
49 Please note that the multi-tty mailing list is read-only, and is
50 reserved for automatic commit messages. Discussion about the branch
51 and bug reports should be sent directly to me (lorentey@elte.hu), or
52 to the emacs-devel@gnu.org mailing list.
57 The branch is now very stable and almost full-featured. I hope the
58 major problems were fixed. (It still needs testing on other
59 architectures, though.) Both multiple tty device support and
60 simultaneous X and tty frame support works fine. Emacsclient has been
61 extended to support opening a new terminal frame.
64 Please let me know if you find any bugs in this branch.
66 To try it out, compile and run the multi-tty branch with the following
73 src/emacs -nw # You can also try without -nw
76 and then (from a shell prompt on another terminal) start emacsclient
79 lib-src/emacsclient -t /optional/file/names...
81 You'll hopefully have two fully working, independent frames on
82 separate terminals. The new frame is closed automatically when you
83 have finished editing the specified files (C-x #), but delete-frame
84 (C-x 5 0) also works. Of course, you can create frames on more than
87 Creating new frames on the same tty with C-x 5 2 works, and they
88 behave the same way as in previous Emacs versions. If you exit emacs,
89 all terminals should be restored to their previous states.
91 This is work in progress, and probably full of bugs. You should
92 always run emacs from gdb, so that you'll have a live instance to
93 debug if something goes wrong. Please send me your bug reports.
95 I think the best way to use the new Emacs is to have it running inside
96 a disconnected GNU screen session, and always use emacsclient for
97 normal work. This way not a single keystroke of your work will be
98 lost if the display device that you are using crashes, or the network
99 connection times out, or whatever. As long as the server that runs
100 your Emacs remains up, all your buffers remain exactly as they were
101 before the crash, and you can continue working as if nothing had
102 happened. (I had an extremely unstable X server for some time while I
103 was developing these patches, and running Emacs this way has saved me
104 a number of M-x recover-session invocations.)
106 (I am thinking about introducing a --daemon option to get rid of the
107 above screen dependency.)
111 * Suspending Emacs is disabled if there are multiple tty
112 devices. Also, there is no way to suspend emacsclient. This
115 * Mac, Windows and DOS support is broken, probably doesn't
116 even compile -- this will be solved later.
118 * Only tested on my GNU/Linux box and on Solaris 8.
125 ** Support for multiple terminal devices has been added.
127 *** You can specify a terminal device (`tty' parameter) and a terminal
128 type (`tty-type' parameter) to `make-terminal-frame'.
130 *** You can test for the presence of multiple terminal support by
131 testing for the `multi-tty' feature.
133 *** Emacsclient has been extended to support opening a new terminal
134 frame (see -t option).
136 *** A make-frame-on-tty function has been added to make it easier to
137 create frames on new terminals.
139 *** New functions: frame-tty-name, frame-tty-type for accessing
140 terminal parameters, and delete-tty for closing the terminal
143 *** talk.el has been extended for multiple tty support.
146 ** Support for simultaneous graphical and terminal frames has been
149 *** The function `make-frame-on-display' now works during a terminal
150 session, and `make-frame-on-tty' works during a graphical session.
152 *** The `window-system' variable has been made frame-local.
154 *** The new `initial-window-system' variable contains the
155 `window-system' value for the first frame.
160 The following is an (incomplete) list of people who have contributed
161 to the project by testing, bug reports, and suggestions. Thanks!
163 Robert J. Chassel <bob@rattlesnake.com>
164 Romain Francoise <romain@orekobech.com>
165 Ami Fischman <ami@fischman.org>
176 ** Robert J. Chassell reports:
178 > * After starting the frame in the VC, I saw this message in the
181 > error in process filter: server-process-filter: \
182 > Wrong type argument: sequencep,\
184 > error in process filter: Wrong type argument: sequencep, framep
186 > This also happens when I start a new frame in an xterm.
188 ** Very strange bug: visible-bell does not work on secondary
189 terminals. This might be something xterm (konsole) specific.
191 ** Find out the best way to support suspending Emacs with multiple
192 ttys. My guess: disable it on the controlling tty, but from other
193 ttys pass it on to emacsclient somehow. (It is (I hope) trivial to
194 extend emacsclient to handle suspend/resume. A `kill -STOP' almost
197 ** Clean up the frame-local variable system. I think it's ugly and
198 error-prone. But maybe I just haven't yet fully understood it.
200 ** Add an elaborate mechanism for display-local variables. (There are
201 already a few of these; search for `terminal-local' in the Elisp
204 ** Move baud_rate to struct display.
206 ** Implement support for starting an interactive Emacs session without
207 an initial frame. (The user would connect to it and open frames
208 later, with emacsclient.) Not necessarily a good idea.
210 ** Fix Mac support (I can't do this myself). Note that the current
211 state of Mac-specific source files in the multi-tty tree are not
212 useful; before starting work on Mac support, revert to pristine,
213 pre-multi-tty versions.
215 ** Fix W32 support (I can't do this myself). Note that the current
216 state of W32-specific source files in the multi-tty tree are not
217 useful; before starting work on W32 support, revert to pristine,
218 pre-multi-tty versions.
220 ** Fix DOS support (I can't do this myself). Note that the current
221 state of DOS-specific source files in the multi-tty tree are not
222 useful; before starting work on DOS support, revert to pristine,
223 pre-multi-tty versions.
225 ** Do a grep on XXX and ?? for more issues.
227 ** Understand Emacs's low-level input system (it seems complicated) :-)
228 What does interrupt_input do? I tried to disable it for raw
229 secondary tty support, but it does not seem to do anything useful.
230 (Update: Look again. X unconditionally enables this, maybe that's
231 why raw terminal support is broken again. I really do need to
234 ** emacsclient -t from an Emacs term buffer does not work, complains
235 about face problems. This can even lock up Emacs (if the recursive
236 frame sets single_kboard). Update: the face problems are caused by
237 bugs in term.el, not in multi-tty. The lockup is caused by
238 single_kboard mode, and is not easily solvable. The best thing to
239 do is to simply refuse to create a tty frame of type `eterm'.
241 ** Maybe standard-display-table should be display-local.
246 (ex-TODO items with explanations.)
248 -- Introduce a new struct for terminal devices.
250 (Done, see struct tty_output. The list of members is not yet
253 -- Change the bootstrap procedure to initialize tty_list.
255 (Done, but needs review.)
257 -- Change make-terminal-frame to support specifying another tty.
259 (Done, new frame parameters: `tty' and `tty-type'.)
261 -- Implement support for reading from multiple terminals.
263 (Done, read_avail_input tries to read from each terminal, until one
264 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
267 (Update: They do, now.)
269 (Update2: After enabling X, they don't.)
271 -- other-frame should cycle through the frames on the `current'
274 (Done, by trivially modifiying next_frame and prev_frame.)
276 -- Support different terminal sizes.
280 -- Make sure terminal resizes are handled gracefully. (Could be
283 (Done. We don't get automatic SIGWINCH for additional ttys,
286 -- Extend emacsclient to automatically open a new tty when it connects
289 (Done. It's an ugly hack, needs more work.)
291 -- Redisplay must refresh the topmost frame on *all* terminals, not
292 just the initial terminal.
294 (Done, but introduced an ugly redisplay problems. Ugh.)
296 -- Fix redisplay problems.
298 (Done; it turned out that the entire Wcm structure must be moved
299 inside tty_output. Why didn't I catch this earlier?)
301 -- Provide a way for emacsclient to tell Emacs that the tty has been
304 (Done, simply forward the SIGWINCH signal.)
306 -- Each keypress should automatically select the frame corresponding
307 to the terminal that it was coming from. This means that Emacs
308 must know from which terminal the last keyboard event came from.
310 (Done, it was quite simple, the input event system already
311 supported multiple frames.)
313 -- Fix SIGIO issue with secondary terminals.
315 (Done, emacsclient signals Emacs after writing to the proxy pseudo
316 terminal. Note that this means that multi-tty does not work with
319 (Update: This is bullshit. There is a read_input_waiting function,
320 extend that somehow.)
322 (Update of update: The first update was not right either, extending
323 read_input_waiting was not necessary. Secondary ttys do seem to
324 send signals on input.)
326 (Update^3: Not any more.)
328 -- Make make-terminal-frame look up the `tty' and `tty-type' frame
329 parameters from the currently selected terminal before the global
334 -- Put all cached terminal escape sequences into struct tty_output.
335 Currently, they are still stored in global variables, so we don't
336 really support multiple terminal types.
338 (Done. It was not fun.)
340 -- Implement sane error handling after initialization. (Currently
341 emacs exits if you specify a bad terminal type.) The helpful error
342 messages must still be provided when Emacs starts.
346 -- Implement terminal deletion, i.e., deleting local frames, closing
347 the tty device and restoring its previous state without exiting
350 (Done, but at the moment only called when an error happens during
351 initialization. There is a memory corruption error around this
352 somewhere.) (Update: now it is fully enabled.)
354 -- Implement automatic deletion of terminals when the last frame on
355 that terminal is closed.
359 -- Restore tty screen after closing the terminal.
361 (Done, we do the same as Emacs 21.2 for all terminals.)
363 -- 'TERM=dumb src/emacs' does not restore the terminal state.
367 -- C-g should work on secondary terminals.
369 (Done, but the binding is not configurable.)
371 -- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
372 server-frames may be removed from server.el.)
374 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
375 from secondary ttys, which is actually a good thing.) (Update: I
376 think it would be a bad idea to remove server-frames.)
378 -- Change emacsclient/server.el to support the -t argument better,
379 i.e. automatically close the socket when the frame is closed.
381 (Seems to be working OK.)
383 -- Fix mysterious memory corruption error with tty deletion. To
384 trigger it, try the following shell command:
386 while true; do TERM=no-such-terminal-definition emacsclient -h; done
388 Emacs usually dumps core after a few dozen iterations. (The bug
389 seems to be related to the xfreeing or bzeroing of
390 tty_output.Wcm. Maybe there are outside references to struct Wcm?
391 Why were these vars collected into a struct before multi-tty
394 (Done. Whew. It turned out that the problem had nothing to do
395 with hypothetical external references to Wcm, or any other
396 tty_output component; it was simply that delete_tty closed the
397 filehandles of secondary ttys twice, resulting in fclose doubly
398 freeing memory. Utterly trivial matter. I love the C's memory
399 management, it puts hair on your chest.)
401 -- Support raw secondary terminals. (Note that SIGIO works only on
402 the controlling terminal.) Hint: extend read_input_waiting for
403 multiple ttys and hopefully this will be fixed.
405 (Done, it seems to have been working already for some time. It
406 seems F_SETOWN does work, after all. Not sure what made it fail
407 earlier, but it seems to be fixed (there were several changes
408 around request_sigio, maybe one of them did it).
409 read_input_waiting is only used in sys_select, don't change
410 it.) (Update: After adding X support, it's broken again.)
412 -- Find out why does Emacs abort when it wants to close its
413 controlling tty. Hint: chan_process[] array. Hey, maybe
414 noninterrupt-IO would work, too? Update: no, there is no process
417 (Done. Added add/delete_keyboard_wait_descriptor to
418 term_init/delete_tty. The hint was right, in a way.)
420 -- Issue with SIGIO: it needs to be disabled during redisplay. See if
421 fcntl kernel behaviour could be emulated by emacsclient.
423 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
424 (Update: it was added back.)
426 -- server.el: There are issues with saving files in buffers of closed
427 clients. Try editing a file with emacsclient -f, and (without
428 saving it) do a delete-frame. The frame is closed without
429 question, and a surprising confirmation prompt appears in another
432 (Done. delete-frame now asks for confirmation if it still has
433 pending buffers, and modified buffers don't seem to be deleted.)
435 -- emacsclient.el, server.el: Handle eval or file open errors when
440 -- Make parts of struct tty_output accessible from Lisp. The device
441 name and the type is sufficient.
443 (Done, see frame-tty-name and frame-tty-type.)
445 -- Export delete_tty to the Lisp environment, for emacsclient.
447 (Done, see delete-tty.)
449 -- Get rid of the accessor macros in termchar.h, or define macros for
454 -- Move device-specific parameters (like costs) commonly used by
455 device backends to a common, device-dependent structure.
457 (Done. See struct display_method in termhooks.h.)
461 (Done. Well, it seems to be working.)
463 -- Allow simultaneous X and tty frames. (Handling input could be
464 tricky. Or maybe not.)
466 (Done. Allowed, that is. It is currently extremely unstable, to
467 the point of being unusable. The rif variable causes constant
468 core dumps. Handling input is indeed tricky.)
470 -- Rewrite multi-tty input in terms of MULTI_KBOARD.
472 (Done. In fact, there was no need to rewrite anything, I just
473 added a kboard member to tty_display_info, and initialized the
474 frame's kboard from there.)
476 -- Fix rif issue with X-tty combo sessions. IMHO the best thing to do
477 is to get rid of that global variable (and use the value value in
478 display_method, which is guaranteed to be correct).
480 (Done, did exactly that. Core dumps during combo sessions became
481 much rarer. In fact, I have not yet met a single one.)
483 -- Add multi-tty support to talk.el.
487 -- Clean up the source of emacsclient. It is a mess.
489 (Done, eliminated stupid proxy-pty kludge.)
491 -- Fix faces on tty frames during X-tty combo sessions. There is an
492 init_frame_faces call in init_sys_modes, see if there is a problem
495 (Done, there was a stupid mistake in
496 Ftty_supports_face_attributes_p. Colors are broken, though.)
498 -- C-x 5 2, C-x 5 o, C-x 5 0 on an emacsclient frame unexpectedly
499 exits emacsclient. This is a result of trying to be clever with
500 delete-frame-functions.
502 (Fixed, added delete-tty-after-functions, and changed server.el to
505 -- Something with (maybe) multi-keyboard support broke function keys
506 and arrows on ttys during X+tty combo sessions. Debug this.
508 (I can't reproduce it, maybe the terminal type was wrong.)
510 -- Fix input from raw ttys (again).
512 (Now it seems to work all right.)
514 -- During an X-tty combo session, a (message "Hello") from a tty frame
515 goes to the X frame. Fix this.
517 (Done. There was a safeguard against writing to the initial
518 terminal frame during bootstrap which prevented echo_area_display
519 from working correctly on a tty frame during a combo session.)
521 -- If there are no frames on its controlling terminal, Emacs should
522 exit if the uses presses C-c there.
524 (Done, as far as possible. See the SIGTERM comment in
525 interrupt_signal on why this seems to be impossible to solve this
528 -- During an X session, Emacs seems to read from stdin. Also, Emacs
529 fails to start without a controlling tty.
531 (Fixed by replacing the troublesome termcap display with a dummy
532 bootstrap display during bootstrap.
534 -- Do tty output through struct display, like graphical display
539 -- Define an output_initial value for output_method for the initial
540 frame that is dumped with Emacs. Checking for this frame (e.g. in
541 cmd_error_internal) is ugly.
543 (Done, broking interactive temacs.)
545 -- The command `emacsclient -t -e '(delete-frame)'' fails to exit.
549 -- frame-creation-function should always create a frame that is on the
550 same display as the selected frame. Maybe frame-creation-function
551 should simply be removed and make-frame changed to do the right
554 (Done, with a nice hack. frame-creation-function is now frame-local.)
556 -- Fix C-g on raw ttys.
558 (Done. I disabled the interrupt/quit keys on all secondary
559 terminals, so Emacs sees C-g as normal input. This looks like an
560 overkill, because emacsclient has extra code to pass SIGINT to
561 Emacs, so C-g should remain the interrupt/quit key on emacsclient
562 frames. See the next entry why implementing this distinction would
565 -- Make sure C-g goes to the right frame with ttys. This is hard, as
566 SIGINT doesn't have a tty parameter. :-(
568 (Done, the previous change fixes this as a pleasant side effect.)
570 -- I have seen a case when Emacs with multiple ttys fell into a loop
571 eating 100% of CPU time. Strace showed this loop:
574 kill(30284, SIGIO) = 0
575 --- SIGIO (I/O possible) @ 0 (0) ---
576 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
577 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
578 ioctl(0, FIONREAD, [0]) = 0
579 sigreturn() = ? (mask now [])
580 gettimeofday({1072842297, 747760}, NULL) = 0
581 gettimeofday({1072842297, 747806}, NULL) = 0
582 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
583 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
584 gettimeofday({1072842297, 748245}, NULL) = 0
586 I have seen something similar with a single X frame, but have not
587 been able to reproduce it for debugging.
589 Update: This may have been caused by checking for nread != 0
590 instead of nread > 0 after calling read_socket_hook in
593 (Fixed. This was caused by unconditionally including stdin in
594 input_wait_mask in init_process. The select call in
595 wait_reading_process_input always returned immediately, indicating
596 that there is pending input from stdin, which nobody read.
598 Note that the above strace output seems to be an unrelated but
599 similar bug. I think that is now fixed.)
601 -- Exiting Emacs while there are emacsclient frames doesn't restore the
602 ttys to their default states.
604 (This seems to be fixed by some previous change.)
606 -- Allow opening an X session after -nw.
610 -- Fix color handling during tty+X combo sessions. (It seems that tty
611 sessions automatically convert the face colors to terminal colors
612 when the face is loaded. This conversion must happen instead on
613 the fly in write_glyphs, which might be problematic, as color
614 approximation is currently done in lisp (term/tty-colors.el).)
615 (Update: hm, colors seem to work fine if I start emacs with -nw and
616 then create an X frame. Maybe it's just a small buglet somewhere.)
618 (Seems to be fixed. The problem was in startup.el, it did not
619 initialize tty colors when the initial window system was
622 -- emacs -nw --eval '(y-or-n-p "Foobar")' segfaults. (Reported by
625 (Fixed, there was a keyboard initialization problem.)
627 -- Fix interactive use of temacs. There are face-related SEGVs, most
628 likely because of changes in realize_default_face, realize_face.
632 -- Don't exit Emacs when the last X connection fails during a
633 multi-display session.
637 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d