Fixed X support, preliminary support for X-tty combo sessions.
[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/
daf01701 19 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
4f0359de
KL
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
daf01701 36 ../configure
bc279d67
KL
37 make bootstrap
38
daf01701
KL
39then start up the emacs server (src/emacs -nw, M-x server-start), and
40then (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 52
daf01701
KL
53X support is (I hope) working, but at the moment there are problems
54with simultaneous X and tty devices, so don't do that.
55
56Mac, Windows and DOS support is broken, probably doesn't even
819b8f00 57compile -- this will be solved later.
04c3243c
KL
58
59Only tested on my GNU/Linux box.
6548cf00 60
28d440ab
KL
61
62NEWS
63----
64
65For the NEWS file:
66
67** Support for multiple terminal devices has been added. You can
68 specify a terminal device (`tty' parameter) and a terminal type
6548cf00 69 (`tty-type' parameter) to `make-terminal-frame'. `tty' must be a
52c2ee2a 70 terminal device created by the updated emacsclient, or there will
0a125897 71 be problems with terminal input and window resizes.
6548cf00
KL
72
73 You can test for the presence of multiple terminal support by
74 testing for the `multi-tty' feature.
75
76** A make-frame-on-tty function has been added to make it easier to
77 create frames on new terminals.
28d440ab 78
819b8f00
KL
79** New functions: frame-tty-name, frame-tty-type for accessing
80 terminal parameters, and delete-tty for closing the terminal
81 device.
82
9628b887
KL
83** Emacsclient has been extended to support opening a new terminal
84 frame.
28d440ab
KL
85
86CHANGELOG
87---------
88
89See arch logs.
90
91
6548cf00
KL
92DIARY OF CHANGES
93----------------
94
95(ex-TODO items with explanations.)
28d440ab 96
daf01701 97-- Introduce a new struct for terminal devices.
28d440ab 98
daf01701 99 (Done, see struct tty_output. The list of members is not yet
28d440ab
KL
100 complete.)
101
28d440ab
KL
102-- Change the bootstrap procedure to initialize tty_list.
103
104 (Done, but needs review.)
105
28d440ab
KL
106-- Change make-terminal-frame to support specifying another tty.
107
108 (Done, new frame parameters: `tty' and `tty-type'.)
109
9628b887
KL
110-- Implement support for reading from multiple terminals.
111
112 (Done, read_avail_input tries to read from each terminal, until one
28d7d09f 113 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
6548cf00 114 SIGIO!)
9628b887 115
819b8f00
KL
116 (Update: They do, now.)
117
daf01701
KL
118 (Update2: After enabling X, they don't.)
119
9628b887 120-- other-frame should cycle through the frames on the `current'
6548cf00 121 terminal only.
9628b887 122
6548cf00 123 (Done, by trivially modifiying next_frame and prev_frame.)
9628b887
KL
124
125-- Support different terminal sizes.
126
127 (Done, no problem.)
128
129-- Make sure terminal resizes are handled gracefully. (Could be
130 problematic.)
131
6548cf00
KL
132 (Done. We don't get automatic SIGWINCH for additional ttys,
133 though.)
9628b887
KL
134
135-- Extend emacsclient to automatically open a new tty when it connects
136 to Emacs.
137
138 (Done. It's an ugly hack, needs more work.)
139
52c2ee2a
KL
140-- Redisplay must refresh the topmost frame on *all* terminals, not
141 just the initial terminal.
9628b887 142
52c2ee2a 143 (Done, but introduced an ugly redisplay problems. Ugh.)
9628b887 144
6548cf00
KL
145-- Fix redisplay problems.
146
52c2ee2a
KL
147 (Done; it turned out that the entire Wcm structure must be moved
148 inside tty_output. Why didn't I catch this earlier?)
6548cf00
KL
149
150-- Provide a way for emacsclient to tell Emacs that the tty has been
151 resized.
152
153 (Done, simply forward the SIGWINCH signal.)
154
155-- Each keypress should automatically select the frame corresponding
156 to the terminal that it was coming from. This means that Emacs
157 must know from which terminal the last keyboard event came from.
6548cf00 158
52c2ee2a
KL
159 (Done, it was quite simple, the input event system already
160 supported multiple frames.)
6548cf00
KL
161
162-- Fix SIGIO issue with secondary terminals.
163
164 (Done, emacsclient signals Emacs after writing to the proxy pseudo
52c2ee2a
KL
165 terminal. Note that this means that multi-tty does not work with
166 raw ttys!)
28d440ab 167
0a125897
KL
168 (Update: This is bullshit. There is a read_input_waiting function,
169 extend that somehow.)
170
819b8f00
KL
171 (Update of update: The first update was not right either, extending
172 read_input_waiting was not necessary. Secondary ttys do seem to
173 send signals on input.)
174
daf01701
KL
175 (Update^3: Not any more.)
176
fca177d4
KL
177-- Make make-terminal-frame look up the `tty' and `tty-type' frame
178 parameters from the currently selected terminal before the global
179 default.
180
181 (Done.)
182
183-- Put all cached terminal escape sequences into struct tty_output.
184 Currently, they are still stored in global variables, so we don't
185 really support multiple terminal types.
186
52c2ee2a 187 (Done. It was not fun.)
fca177d4
KL
188
189-- Implement sane error handling after initialization. (Currently
6548cf00
KL
190 emacs exits if you specify a bad terminal type.) The helpful error
191 messages must still be provided when Emacs starts.
192
fca177d4
KL
193 (Done.)
194
195-- Implement terminal deletion, i.e., deleting local frames, closing
196 the tty device and restoring its previous state without exiting
197 Emacs.
9628b887 198
fca177d4
KL
199 (Done, but at the moment only called when an error happens during
200 initialization. There is a memory corruption error around this
daf01701 201 somewhere.) (Update: now it is fully enabled.)
fca177d4 202
8303ba32
KL
203-- Implement automatic deletion of terminals when the last frame on
204 that terminal is closed.
205
206 (Done.)
207
0a125897
KL
208-- Restore tty screen after closing the terminal.
209
210 (Done, we do the same as Emacs 21.2 for all terminals.)
211
212-- 'TERM=dumb src/emacs' does not restore the terminal state.
213
214 (Done.)
fca177d4 215
b2af72d2
KL
216-- C-g should work on secondary terminals.
217
218 (Done, but the binding is not configurable.)
219
220-- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
221 server-frames may be removed from server.el.)
222
223 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
daf01701
KL
224 from secondary ttys, which is actually a good thing.) (Update: I
225 think it would be a bad idea to remove server-frames anyway.)
b2af72d2 226
daf01701 227-- Change emacsclient/server.el to support the -t argument better,
b2af72d2
KL
228 i.e. automatically close the socket when the frame is closed.
229
230 (Seems to be working OK.)
231
16c290d8 232-- Fix mysterious memory corruption error with tty deletion. To
fca177d4
KL
233 trigger it, try the following shell command:
234
235 while true; do TERM=no-such-terminal-definition emacsclient -h; done
236
237 Emacs usually dumps core after a few dozen iterations. (The bug
238 seems to be related to the xfree()ing or bzero()ing of
9d9f1812
KL
239 tty_output.Wcm. Maybe there are outside references to struct Wcm?
240 Why were these vars collected into a struct before multi-tty
241 support?)
fca177d4 242
16c290d8
KL
243 (Done. Whew. It turned out that the problem had nothing to do
244 with hypothetical external references to Wcm, or any other
245 tty_output component; it was simply that delete_tty closed the
246 filehandles of secondary ttys twice, resulting in fclose doubly
247 free()ing memory. Utterly trivial matter. I love the C's memory
248 management, it puts hair on your chest.)
249
819b8f00
KL
250-- Support raw secondary terminals. (Note that SIGIO works only on
251 the controlling terminal.) Hint: extend read_input_waiting() for
252 multiple ttys and hopefully this will be fixed.
fca177d4 253
819b8f00
KL
254 (Done, it seems to have been working already for some time. It
255 seems F_SETOWN does work, after all. Not sure what made it fail
256 earlier, but it seems to be fixed (there were several changes
257 around request_sigio, maybe one of them did it).
258 read_input_waiting() is only used in sys_select(), don't change
daf01701 259 it.) (Update: After adding X support, it's broken again.)
c1c63edb 260
819b8f00 261-- Find out why does Emacs abort when it wants to close its
0a125897 262 controlling tty. Hint: chan_process[] array. Hey, maybe
16c290d8
KL
263 noninterrupt-IO would work, too? Update: no, there is no process
264 for stdin/out.
c33d2d42 265
819b8f00
KL
266 (Done. Added add/delete_keyboard_wait_descriptor to
267 term_init/delete_tty. The hint was right, in a way.)
6548cf00 268
819b8f00 269-- Issue with SIGIO: it needs to be disabled during redisplay. See if
0a125897
KL
270 fcntl() kernel behaviour could be emulated by emacsclient.
271
819b8f00 272 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
daf01701 273 (Update: it was added back.)
22de1e79 274
819b8f00 275-- server.el: There are issues with saving files in buffers of closed
16c290d8
KL
276 clients. Try editing a file with emacsclient -f, and (without
277 saving it) do a delete-frame. The frame is closed without
278 question, and a surprising confirmation prompt appears in another
279 frame.
280
819b8f00
KL
281 (Done. delete-frame now asks for confirmation if it still has
282 pending buffers, and modified buffers don't seem to be deleted.)
283
284-- emacsclient.el, server.el: Handle eval or file open errors when
daf01701 285 doing -t.
16c290d8 286
819b8f00 287 (Done.)
22de1e79 288
819b8f00
KL
289-- Make parts of struct tty_output accessible from Lisp. The device
290 name and the type is sufficient.
22de1e79 291
819b8f00
KL
292 (Done, see frame-tty-name and frame-tty-type.)
293
294-- Export delete_tty to the Lisp environment, for emacsclient.
22de1e79 295
819b8f00
KL
296 (Done, see delete-tty.)
297
daf01701
KL
298-- Get rid of the accessor macros in termchar.h, or define macros for
299 all members.
300
301 (Done.)
302
303-- Move device-specific parameters (like costs) commonly used by
304 device backends to a common, device-dependent structure.
305
306 (Done. See struct display_method in termhooks.h.)
307
308-- Fix X support.
309
310 (Done. Well, it seems to be working.)
311
312-- Allow simultaneous X and tty frames. (Handling input could be
313 tricky. Or maybe not.)
314
315 (Done. Allowed, that is. It is currently extremely unstable, to
316 the point of being unusable. The rif variable causes constant
317 core dumps. Handling input is indeed tricky.)
819b8f00
KL
318
319THINGS TO DO
320------------
28d440ab 321
daf01701
KL
322** Fix rif issue with X-tty combo sessions. IMHO the best thing to do
323 is to get rid of that global variable (and use the value value in
324 display_method, which is guaranteed to be correct).
325
326** Fix faces on tty frames during X-tty combo sessions.
327
c33d2d42 328** Find out the best way to support suspending Emacs with multiple
daf01701
KL
329 ttys. My guess: disable it on the controlling tty, but from other
330 ttys pass it on to emacsclient somehow. (It is (I hope) trivial to
331 extend emacsclient to handle suspend/resume. A `kill -STOP' almost
332 works right now.)
819b8f00
KL
333
334** Move baud_rate to tty_output.
335
c1c63edb 336** Do tty output through term_hooks, like graphical display backends.
6548cf00 337
819b8f00
KL
338** Implement support for starting an interactive Emacs session without
339 an initial frame. (The user would connect to it and open frames
340 later, with emacsclient.) Not necessarily a good idea.
341
daf01701
KL
342** Fix input from raw ttys (again).
343
28d440ab
KL
344** Fix Mac support (I can't do this myself).
345
346** Fix W32 support (I can't do this myself).
347
348** Fix DOS support (I can't do this myself).
349
16c290d8 350** Do a grep on XXX and ?? for more issues.
28d440ab 351
daf01701
KL
352** Understand Emacs's low-level input system (it seems complicated)
353 :-) and maybe rewrite multi-tty input in terms of MULTI_KBOARD.
354 (Update: This backtrace from a tty-X combo session hints that this
355 may be necessary.)
819b8f00 356
daf01701
KL
357 #0 abort () at /home/lorentey/work/emacs/emacs--multi-tty/src/emacs.c:417
358 #1 0x081104fb in read_char (commandflag=0, nmaps=0, maps=0x0, prev_event=675499188, used_mouse_menu=0x0) at /home/lorentey/work/emacs/emacs--multi-tty/src/keyboard.c:2581
359 #2 0x0819f23e in read_filtered_event (no_switch_frame=1, ascii_required=0, error_nonascii=0, input_method=0) at /home/lorentey/work/emacs/emacs--multi-tty/src/lread.c:468
360 #3 0x0819387c in Fy_or_n_p (prompt=1759896324) at /home/lorentey/work/emacs/emacs--multi-tty/src/fns.c:3115
361 ...
819b8f00
KL
362
363** What does interrupt_input do? I tried to disable it for raw
364 secondary tty support, but it does not seem to do anything useful.
daf01701
KL
365 (Update: Look again. X unconditionally enables this, maybe that's
366 why raw terminal support is broken again. I really do need to
367 understand input.)
819b8f00
KL
368
369** Make sure C-g goes to the right frame. This is hard, as SIGINT
370 doesn't have a tty parameter. :-(
371
28d7d09f
KL
372** I have seen a case when Emacs with multiple ttys fell into a loop
373 eating 100% of CPU time. Strace showed this loop:
819b8f00 374
819b8f00
KL
375 getpid() = 30284
376 kill(30284, SIGIO) = 0
377 --- SIGIO (I/O possible) @ 0 (0) ---
378 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
379 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
380 ioctl(0, FIONREAD, [0]) = 0
381 sigreturn() = ? (mask now [])
382 gettimeofday({1072842297, 747760}, NULL) = 0
383 gettimeofday({1072842297, 747806}, NULL) = 0
384 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
385 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
386 gettimeofday({1072842297, 748245}, NULL) = 0
387
388 I have not been able to reproduce this.
389
28d440ab 390;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d