Separate frame-local, tty-dependent parameters from tty-local parameters.
[bpt/emacs.git] / README.multi-tty
CommitLineData
28d440ab
KL
1 -*- coding: utf-8; -*-
2GOAL
3----
4
5The ultimate goal of this branch is to implement support for opening
6multiple, different tty devices and simultaneous X and tty frames from
7a single Emacs session.
8
9WHO IS DOING IT
10---------------
11
12I'm Károly Lőrentey. My address: lorentey@elte.hu.
13
14Patches or suggestions are welcome!
15
6548cf00 16Retrieving the latest version of the branch:
4f0359de
KL
17
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>
20
21(I use tla 1.1.)
22
28d440ab
KL
23
24STATUS
25------
26
52c2ee2a
KL
27Basic multi-tty support is there; there are some rough edges, but it
28already seems to be usable. Emacsclient has been extended to support
29opening a new terminal frame.
28d440ab 30
04c3243c
KL
31To try it out, compile the multi-tty branch with the following
32commands:
bc279d67
KL
33
34 mkdir +build
35 cd +build
36 ../configure --with-x-toolkit=no --without-x
37 make bootstrap
38
39then start up the emacs server (src/emacs, M-x server-start), and then
6548cf00 40(from a shell prompt on another terminal) start emacsclient with
28d440ab 41
16c290d8 42 lib-src/emacsclient -f /optional/file/names...
28d440ab 43
04c3243c
KL
44You'll hopefully have two fully working, independent frames on
45separate terminals. (This seems to be very useful, emacsclient starts
46up even faster than vi!) :-) You can close the newly opened frame and
47return to the shell without exiting Emacs by pressing C-x 5 0, i.e.,
819b8f00 48delete-frame. Creating new frames on the same tty with C-x 5 2
04c3243c
KL
49works exactly as before. Suspending Emacs is disabled at the moment.
50If you exit emacs, all terminals should be restored to their previous
51states.
52c2ee2a
KL
52
53X, Mac, Windows and DOS support is broken, probably doesn't even
819b8f00 54compile -- this will be solved later.
04c3243c
KL
55
56Only tested on my GNU/Linux box.
6548cf00 57
28d440ab
KL
58
59NEWS
60----
61
62For the NEWS file:
63
64** Support for multiple terminal devices has been added. You can
65 specify a terminal device (`tty' parameter) and a terminal type
6548cf00 66 (`tty-type' parameter) to `make-terminal-frame'. `tty' must be a
52c2ee2a 67 terminal device created by the updated emacsclient, or there will
0a125897 68 be problems with terminal input and window resizes.
6548cf00
KL
69
70 You can test for the presence of multiple terminal support by
71 testing for the `multi-tty' feature.
72
73** A make-frame-on-tty function has been added to make it easier to
74 create frames on new terminals.
28d440ab 75
819b8f00
KL
76** New functions: frame-tty-name, frame-tty-type for accessing
77 terminal parameters, and delete-tty for closing the terminal
78 device.
79
9628b887
KL
80** Emacsclient has been extended to support opening a new terminal
81 frame.
28d440ab
KL
82
83CHANGELOG
84---------
85
86See arch logs.
87
88
6548cf00
KL
89DIARY OF CHANGES
90----------------
91
92(ex-TODO items with explanations.)
28d440ab
KL
93
94-- Introduce a new abstraction for terminal devices.
95
96 (Done, see struct tty_output. The abstraction is not yet
97 complete.)
98
28d440ab
KL
99-- Change the bootstrap procedure to initialize tty_list.
100
101 (Done, but needs review.)
102
28d440ab
KL
103-- Change make-terminal-frame to support specifying another tty.
104
105 (Done, new frame parameters: `tty' and `tty-type'.)
106
9628b887
KL
107-- Implement support for reading from multiple terminals.
108
109 (Done, read_avail_input tries to read from each terminal, until one
28d7d09f 110 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
6548cf00 111 SIGIO!)
9628b887 112
819b8f00
KL
113 (Update: They do, now.)
114
9628b887 115-- other-frame should cycle through the frames on the `current'
6548cf00 116 terminal only.
9628b887 117
6548cf00 118 (Done, by trivially modifiying next_frame and prev_frame.)
9628b887
KL
119
120-- Support different terminal sizes.
121
122 (Done, no problem.)
123
124-- Make sure terminal resizes are handled gracefully. (Could be
125 problematic.)
126
6548cf00
KL
127 (Done. We don't get automatic SIGWINCH for additional ttys,
128 though.)
9628b887
KL
129
130-- Extend emacsclient to automatically open a new tty when it connects
131 to Emacs.
132
133 (Done. It's an ugly hack, needs more work.)
134
52c2ee2a
KL
135-- Redisplay must refresh the topmost frame on *all* terminals, not
136 just the initial terminal.
9628b887 137
52c2ee2a 138 (Done, but introduced an ugly redisplay problems. Ugh.)
9628b887 139
6548cf00
KL
140-- Fix redisplay problems.
141
52c2ee2a
KL
142 (Done; it turned out that the entire Wcm structure must be moved
143 inside tty_output. Why didn't I catch this earlier?)
6548cf00
KL
144
145-- Provide a way for emacsclient to tell Emacs that the tty has been
146 resized.
147
148 (Done, simply forward the SIGWINCH signal.)
149
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.
6548cf00 153
52c2ee2a
KL
154 (Done, it was quite simple, the input event system already
155 supported multiple frames.)
6548cf00
KL
156
157-- Fix SIGIO issue with secondary terminals.
158
159 (Done, emacsclient signals Emacs after writing to the proxy pseudo
52c2ee2a
KL
160 terminal. Note that this means that multi-tty does not work with
161 raw ttys!)
28d440ab 162
0a125897
KL
163 (Update: This is bullshit. There is a read_input_waiting function,
164 extend that somehow.)
165
819b8f00
KL
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.)
169
fca177d4
KL
170-- Make make-terminal-frame look up the `tty' and `tty-type' frame
171 parameters from the currently selected terminal before the global
172 default.
173
174 (Done.)
175
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.
179
52c2ee2a 180 (Done. It was not fun.)
fca177d4
KL
181
182-- Implement sane error handling after initialization. (Currently
6548cf00
KL
183 emacs exits if you specify a bad terminal type.) The helpful error
184 messages must still be provided when Emacs starts.
185
fca177d4
KL
186 (Done.)
187
188-- Implement terminal deletion, i.e., deleting local frames, closing
189 the tty device and restoring its previous state without exiting
190 Emacs.
9628b887 191
fca177d4
KL
192 (Done, but at the moment only called when an error happens during
193 initialization. There is a memory corruption error around this
194 somewhere.)
195
8303ba32
KL
196-- Implement automatic deletion of terminals when the last frame on
197 that terminal is closed.
198
199 (Done.)
200
0a125897
KL
201-- Restore tty screen after closing the terminal.
202
203 (Done, we do the same as Emacs 21.2 for all terminals.)
204
205-- 'TERM=dumb src/emacs' does not restore the terminal state.
206
207 (Done.)
fca177d4 208
b2af72d2
KL
209-- C-g should work on secondary terminals.
210
211 (Done, but the binding is not configurable.)
212
213-- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
214 server-frames may be removed from server.el.)
215
216 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
217 from secondary ttys.)
218
219-- Change emacsclient/server.el to support the -h argument better,
220 i.e. automatically close the socket when the frame is closed.
221
222 (Seems to be working OK.)
223
16c290d8 224-- Fix mysterious memory corruption error with tty deletion. To
fca177d4
KL
225 trigger it, try the following shell command:
226
227 while true; do TERM=no-such-terminal-definition emacsclient -h; done
228
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
9d9f1812
KL
231 tty_output.Wcm. Maybe there are outside references to struct Wcm?
232 Why were these vars collected into a struct before multi-tty
233 support?)
fca177d4 234
16c290d8
KL
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.)
241
819b8f00
KL
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.
fca177d4 245
819b8f00
KL
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
251 it.)
c1c63edb 252
819b8f00 253-- Find out why does Emacs abort when it wants to close its
0a125897 254 controlling tty. Hint: chan_process[] array. Hey, maybe
16c290d8
KL
255 noninterrupt-IO would work, too? Update: no, there is no process
256 for stdin/out.
c33d2d42 257
819b8f00
KL
258 (Done. Added add/delete_keyboard_wait_descriptor to
259 term_init/delete_tty. The hint was right, in a way.)
6548cf00 260
819b8f00 261-- Issue with SIGIO: it needs to be disabled during redisplay. See if
0a125897
KL
262 fcntl() kernel behaviour could be emulated by emacsclient.
263
819b8f00 264 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
22de1e79 265
819b8f00 266-- server.el: There are issues with saving files in buffers of closed
16c290d8
KL
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
270 frame.
271
819b8f00
KL
272 (Done. delete-frame now asks for confirmation if it still has
273 pending buffers, and modified buffers don't seem to be deleted.)
274
275-- emacsclient.el, server.el: Handle eval or file open errors when
16c290d8
KL
276 doing -f.
277
819b8f00 278 (Done.)
22de1e79 279
819b8f00
KL
280-- Make parts of struct tty_output accessible from Lisp. The device
281 name and the type is sufficient.
22de1e79 282
819b8f00
KL
283 (Done, see frame-tty-name and frame-tty-type.)
284
285-- Export delete_tty to the Lisp environment, for emacsclient.
22de1e79 286
819b8f00
KL
287 (Done, see delete-tty.)
288
289
290THINGS TO DO
291------------
28d440ab 292
c33d2d42 293** Find out the best way to support suspending Emacs with multiple
819b8f00
KL
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.)
298
299** Move baud_rate to tty_output.
300
301** Move device-specific parameters (like costs) commonly used by
302 device backends to a common, device-dependent structure.
c33d2d42 303
c1c63edb 304** Do tty output through term_hooks, like graphical display backends.
6548cf00 305
52c2ee2a
KL
306** Fix X support.
307
c1c63edb 308** Allow simultaneous X and tty frames. (Handling input could be
28d7d09f 309 tricky. Or maybe not.)
28d440ab 310
819b8f00
KL
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.
314
28d440ab
KL
315** Fix Mac support (I can't do this myself).
316
317** Fix W32 support (I can't do this myself).
318
319** Fix DOS support (I can't do this myself).
320
16c290d8 321** Do a grep on XXX and ?? for more issues.
28d440ab 322
819b8f00
KL
323** Get rid of the accessor macros in termchar.h, or define macros for
324 all members.
325
326** Understand Emacs's low-level input system (it seems complicated) :-)
327 and maybe rewrite multi-tty input in terms of MULTIKBOARD.
328
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.
331
332** Make sure C-g goes to the right frame. This is hard, as SIGINT
333 doesn't have a tty parameter. :-(
334
28d7d09f
KL
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:
819b8f00
KL
337
338
339 getpid() = 30284
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
351
352 I have not been able to reproduce this.
353
28d440ab 354;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d