5 The ultimate goal of this branch is to implement support for opening
6 multiple, different tty devices and simultaneous X and tty frames from
7 a single Emacs session.
12 I'm Károly Lőrentey. My address: lorentey@elte.hu.
14 Patches or suggestions are welcome!
16 Retrieving the latest version of the branch:
18 tla register-archive lorentey@elte.hu--2004 http://lorentey.web.elte.hu/arch/2004/
19 tla get lorentey@elte.hu--2004/emacs--multi-tty--0 <directory>
27 Basic multi-tty support is there; there are some rough edges, but it
28 already seems to be usable. Emacsclient has been extended to support
29 opening a new terminal frame.
31 To try it out, compile the multi-tty branch with the following
36 ../configure --with-x-toolkit=no --without-x
39 then start up the emacs server (src/emacs, M-x server-start), and then
40 (from a shell prompt on another terminal) start emacsclient with
42 lib-src/emacsclient -f /optional/file/names...
44 You'll hopefully have two fully working, independent frames on
45 separate terminals. (This seems to be very useful, emacsclient starts
46 up even faster than vi!) :-) You can close the newly opened frame and
47 return to the shell without exiting Emacs by pressing C-x 5 0, i.e.,
48 delete-frame. Creating new frames on the same tty with C-x 5 2
49 works exactly as before. Suspending Emacs is disabled at the moment.
50 If you exit emacs, all terminals should be restored to their previous
53 X, Mac, Windows and DOS support is broken, probably doesn't even
54 compile -- this will be solved later.
56 Only tested on my GNU/Linux box.
64 ** Support for multiple terminal devices has been added. You can
65 specify a terminal device (`tty' parameter) and a terminal type
66 (`tty-type' parameter) to `make-terminal-frame'. `tty' must be a
67 terminal device created by the updated emacsclient, or there will
68 be problems with terminal input and window resizes.
70 You can test for the presence of multiple terminal support by
71 testing for the `multi-tty' feature.
73 ** A make-frame-on-tty function has been added to make it easier to
74 create frames on new terminals.
76 ** New functions: frame-tty-name, frame-tty-type for accessing
77 terminal parameters, and delete-tty for closing the terminal
80 ** Emacsclient has been extended to support opening a new terminal
92 (ex-TODO items with explanations.)
94 -- Introduce a new abstraction for terminal devices.
96 (Done, see struct tty_output. The abstraction is not yet
99 -- Change the bootstrap procedure to initialize tty_list.
101 (Done, but needs review.)
103 -- Change make-terminal-frame to support specifying another tty.
105 (Done, new frame parameters: `tty' and `tty-type'.)
107 -- Implement support for reading from multiple terminals.
109 (Done, read_avail_input tries to read from each terminal, until one
110 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
113 (Update: They do, now.)
115 -- other-frame should cycle through the frames on the `current'
118 (Done, by trivially modifiying next_frame and prev_frame.)
120 -- Support different terminal sizes.
124 -- Make sure terminal resizes are handled gracefully. (Could be
127 (Done. We don't get automatic SIGWINCH for additional ttys,
130 -- Extend emacsclient to automatically open a new tty when it connects
133 (Done. It's an ugly hack, needs more work.)
135 -- Redisplay must refresh the topmost frame on *all* terminals, not
136 just the initial terminal.
138 (Done, but introduced an ugly redisplay problems. Ugh.)
140 -- Fix redisplay problems.
142 (Done; it turned out that the entire Wcm structure must be moved
143 inside tty_output. Why didn't I catch this earlier?)
145 -- Provide a way for emacsclient to tell Emacs that the tty has been
148 (Done, simply forward the SIGWINCH signal.)
150 -- Each keypress should automatically select the frame corresponding
151 to the terminal that it was coming from. This means that Emacs
152 must know from which terminal the last keyboard event came from.
154 (Done, it was quite simple, the input event system already
155 supported multiple frames.)
157 -- Fix SIGIO issue with secondary terminals.
159 (Done, emacsclient signals Emacs after writing to the proxy pseudo
160 terminal. Note that this means that multi-tty does not work with
163 (Update: This is bullshit. There is a read_input_waiting function,
164 extend that somehow.)
166 (Update of update: The first update was not right either, extending
167 read_input_waiting was not necessary. Secondary ttys do seem to
168 send signals on input.)
170 -- Make make-terminal-frame look up the `tty' and `tty-type' frame
171 parameters from the currently selected terminal before the global
176 -- Put all cached terminal escape sequences into struct tty_output.
177 Currently, they are still stored in global variables, so we don't
178 really support multiple terminal types.
180 (Done. It was not fun.)
182 -- Implement sane error handling after initialization. (Currently
183 emacs exits if you specify a bad terminal type.) The helpful error
184 messages must still be provided when Emacs starts.
188 -- Implement terminal deletion, i.e., deleting local frames, closing
189 the tty device and restoring its previous state without exiting
192 (Done, but at the moment only called when an error happens during
193 initialization. There is a memory corruption error around this
196 -- Implement automatic deletion of terminals when the last frame on
197 that terminal is closed.
201 -- Restore tty screen after closing the terminal.
203 (Done, we do the same as Emacs 21.2 for all terminals.)
205 -- 'TERM=dumb src/emacs' does not restore the terminal state.
209 -- C-g should work on secondary terminals.
211 (Done, but the binding is not configurable.)
213 -- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
214 server-frames may be removed from server.el.)
216 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
217 from secondary ttys.)
219 -- Change emacsclient/server.el to support the -h argument better,
220 i.e. automatically close the socket when the frame is closed.
222 (Seems to be working OK.)
224 -- Fix mysterious memory corruption error with tty deletion. To
225 trigger it, try the following shell command:
227 while true; do TERM=no-such-terminal-definition emacsclient -h; done
229 Emacs usually dumps core after a few dozen iterations. (The bug
230 seems to be related to the xfree()ing or bzero()ing of
231 tty_output.Wcm. Maybe there are outside references to struct Wcm?
232 Why were these vars collected into a struct before multi-tty
235 (Done. Whew. It turned out that the problem had nothing to do
236 with hypothetical external references to Wcm, or any other
237 tty_output component; it was simply that delete_tty closed the
238 filehandles of secondary ttys twice, resulting in fclose doubly
239 free()ing memory. Utterly trivial matter. I love the C's memory
240 management, it puts hair on your chest.)
242 -- Support raw secondary terminals. (Note that SIGIO works only on
243 the controlling terminal.) Hint: extend read_input_waiting() for
244 multiple ttys and hopefully this will be fixed.
246 (Done, it seems to have been working already for some time. It
247 seems F_SETOWN does work, after all. Not sure what made it fail
248 earlier, but it seems to be fixed (there were several changes
249 around request_sigio, maybe one of them did it).
250 read_input_waiting() is only used in sys_select(), don't change
253 -- Find out why does Emacs abort when it wants to close its
254 controlling tty. Hint: chan_process[] array. Hey, maybe
255 noninterrupt-IO would work, too? Update: no, there is no process
258 (Done. Added add/delete_keyboard_wait_descriptor to
259 term_init/delete_tty. The hint was right, in a way.)
261 -- Issue with SIGIO: it needs to be disabled during redisplay. See if
262 fcntl() kernel behaviour could be emulated by emacsclient.
264 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
266 -- server.el: There are issues with saving files in buffers of closed
267 clients. Try editing a file with emacsclient -f, and (without
268 saving it) do a delete-frame. The frame is closed without
269 question, and a surprising confirmation prompt appears in another
272 (Done. delete-frame now asks for confirmation if it still has
273 pending buffers, and modified buffers don't seem to be deleted.)
275 -- emacsclient.el, server.el: Handle eval or file open errors when
280 -- Make parts of struct tty_output accessible from Lisp. The device
281 name and the type is sufficient.
283 (Done, see frame-tty-name and frame-tty-type.)
285 -- Export delete_tty to the Lisp environment, for emacsclient.
287 (Done, see delete-tty.)
293 ** Find out the best way to support suspending Emacs with multiple
294 ttys. My guess: disable it on the controlling tty, but other ttys
295 should pass it on to emacsclient somehow. (It is (I hope) trivial
296 to extend emacsclient to handle suspend/resume. A `kill -STOP'
297 almost works right now.)
299 ** Move baud_rate to tty_output.
301 ** Move device-specific parameters (like costs) commonly used by
302 device backends to a common, device-dependent structure.
304 ** Do tty output through term_hooks, like graphical display backends.
308 ** Allow simultaneous X and tty frames. (Handling input could be
309 tricky. Or maybe not.)
311 ** Implement support for starting an interactive Emacs session without
312 an initial frame. (The user would connect to it and open frames
313 later, with emacsclient.) Not necessarily a good idea.
315 ** Fix Mac support (I can't do this myself).
317 ** Fix W32 support (I can't do this myself).
319 ** Fix DOS support (I can't do this myself).
321 ** Do a grep on XXX and ?? for more issues.
323 ** Get rid of the accessor macros in termchar.h, or define macros for
326 ** Understand Emacs's low-level input system (it seems complicated) :-)
327 and maybe rewrite multi-tty input in terms of MULTIKBOARD.
329 ** What does interrupt_input do? I tried to disable it for raw
330 secondary tty support, but it does not seem to do anything useful.
332 ** Make sure C-g goes to the right frame. This is hard, as SIGINT
333 doesn't have a tty parameter. :-(
335 ** I have seen a case when Emacs with multiple ttys fell into a loop
336 eating 100% of CPU time. Strace showed this loop:
340 kill(30284, SIGIO) = 0
341 --- SIGIO (I/O possible) @ 0 (0) ---
342 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
343 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
344 ioctl(0, FIONREAD, [0]) = 0
345 sigreturn() = ? (mask now [])
346 gettimeofday({1072842297, 747760}, NULL) = 0
347 gettimeofday({1072842297, 747806}, NULL) = 0
348 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
349 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
350 gettimeofday({1072842297, 748245}, NULL) = 0
352 I have not been able to reproduce this.
354 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d