Fixed tty faces during combo sessions. Plus other assorted bugfixes.
[bpt/emacs.git] / README.multi-tty
CommitLineData
3224dac1 1 -*- coding: utf-8; mode: text; -*-
28d440ab
KL
2GOAL
3----
4
2246281f
KL
5The goal of this branch is to implement support for opening multiple,
6different tty devices and simultaneous X and tty frames from a single
7Emacs session.
28d440ab 8
7b00d185
KL
9Some use cases:
10
11Emacs is notoriously slow at startup, so most people use another
12editor or emacsclient for quick editing jobs from the console.
13Unfortunately, emacsclient was very awkward to use, because it did not
14support opening a new Emacs frame on the current virtual console.
15Now, with multi-tty support, it can do that. (Emacsclient starts up
16faster than vi!)
17
18Some Gnus users (including me) run Gnus in an X frame in its own Emacs
19instance, which they typically leave running for weeks. It would be
20nice if they could connect to this instance from a remote ssh session
21and check their messages without opening a remote X frame or resorting
22to gnus-slave.
23
24
28d440ab
KL
25WHO IS DOING IT
26---------------
27
28I'm Károly Lőrentey. My address: lorentey@elte.hu.
29
2246281f 30Comments, bug reports, suggestions and patches are welcome!
28d440ab 31
6548cf00 32Retrieving the latest version of the branch:
4f0359de
KL
33
34 tla register-archive lorentey@elte.hu--2004 http://lorentey.web.elte.hu/arch/2004/
daf01701 35 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
4f0359de 36
7b00d185
KL
37(I use a recent arch development snapshot, but any of the released
38versions of arch will do fine, I think.)
39
40If you don't have arch, the branch has a homepage from which you can
41download conventional patches against Emacs CVS HEAD:
4f0359de 42
7b00d185 43 http://lorentey.web.elte.hu/project/emacs.html
28d440ab 44
6c3d443b
KL
45If you want to be notified of new revisions, sign up to the
46multi-tty@listbox.elte.hu mailing list by visiting the
47below homepage and following its instructions.
48
49 https://listbox.elte.hu/mailman/listinfo/multi-tty
50
51Please note that the multi-tty mailing list is read-only, and is
52reserved for automatic commit messages. Discussion about the branch
53and bug reports should be sent directly to me (lorentey@elte.hu), or
54to the emacs-devel@gnu.org mailing list.
55
28d440ab
KL
56STATUS
57------
58
7b00d185 59Multi-tty support is stable, I think most of the problems were fixed.
2246281f
KL
60(It still needs testing on other architectures, though.) Simultaneous
61X and tty frame support works fine, although there are some small
62issues. Emacsclient has been extended to support opening a new
63terminal frame.
64
65
66Please let me know if you find any bugs in this branch.
28d440ab 67
7b00d185 68To try it out, compile and run the multi-tty branch with the following
04c3243c 69commands:
bc279d67
KL
70
71 mkdir +build
72 cd +build
daf01701 73 ../configure
bc279d67 74 make bootstrap
2246281f 75 src/emacs -nw # You can also try without -nw
7b00d185 76 M-x server-start
bc279d67 77
7b00d185
KL
78and then (from a shell prompt on another terminal) start emacsclient
79with
28d440ab 80
7b00d185 81 lib-src/emacsclient -t /optional/file/names...
28d440ab 82
04c3243c 83You'll hopefully have two fully working, independent frames on
7b00d185
KL
84separate terminals. The new frame is closed automatically when you
85have finished editing the specified files (C-x #), but delete-frame
86(C-x 5 0) also works. Of course, you can create frames on more than
87two tty devices.
52c2ee2a 88
7b00d185
KL
89Creating new frames on the same tty with C-x 5 2 works, and they
90behave the same way as in previous Emacs versions. If you exit emacs,
91all terminals should be restored to their previous states.
daf01701 92
7b00d185
KL
93This is work in progress, and probably full of bugs. You should
94always run emacs from gdb, so that you'll have a live instance to
2246281f 95debug if something goes wrong. Please send me your bug reports.
04c3243c 96
7b00d185 97Problems:
6548cf00 98
7b00d185
KL
99 * Suspending Emacs is disabled if there are multiple tty
100 devices. Also, there is no way to suspend emacsclient. This
101 will be fixed.
102
7b00d185
KL
103 * Mac, Windows and DOS support is broken, probably doesn't
104 even compile -- this will be solved later.
105
2246281f 106 * Only tested on my GNU/Linux box and on Solaris 8.
28d440ab
KL
107
108NEWS
109----
110
111For the NEWS file:
112
2246281f 113** Support for multiple terminal devices has been added.
6548cf00 114
2246281f
KL
115*** You can specify a terminal device (`tty' parameter) and a terminal
116 type (`tty-type' parameter) to `make-terminal-frame'.
6548cf00 117
2246281f
KL
118*** You can test for the presence of multiple terminal support by
119 testing for the `multi-tty' feature.
28d440ab 120
2246281f
KL
121*** Emacsclient has been extended to support opening a new terminal
122 frame (see -t option).
123
124*** A make-frame-on-tty function has been added to make it easier to
125 create frames on new terminals.
126
127*** New functions: frame-tty-name, frame-tty-type for accessing
128 terminal parameters, and delete-tty for closing the terminal
129 device.
130
131*** talk.el has been extended for multiple tty support.
132
133
134** Support for simultaneous graphical and terminal frames has been
135 added.
136
137*** The function `make-frame-on-display' now works during a terminal
138 session, and `make-frame-on-tty' works during a graphical session.
139
140*** The `window-system' variable has been made frame-local.
141
142*** The new `initial-window-system' variable contains the
143 `window-system' value for the first frame.
819b8f00 144
d448e982
KL
145THANKS
146------
147
148The following is an (incomplete) list of people who have contributed
149to the project by testing, bug reports, and suggestions. Thanks!
150
151Robert J. Chassel <bob@rattlesnake.com>
152Romain Francoise <romain@orekobech.com>
153Ami Fischman <ami@fischman.org>
154
28d440ab
KL
155
156CHANGELOG
157---------
158
159See arch logs.
160
7b00d185
KL
161THINGS TO DO
162------------
163
d448e982 164** Robert J. Chassell reports:
e9cda827 165
d448e982
KL
166 > * After starting the frame in the VC, I saw this message in the
167 > *Message* buffer
168 >
169 > error in process filter: server-process-filter: \
170 > Wrong type argument: sequencep,\
171 > framep
172 > error in process filter: Wrong type argument: sequencep, framep
173 >
174 > This also happens when I start a new frame in an xterm.
175
176** emacs -nw --eval '(y-or-n-p "Foobar")' segfaults.
3224dac1 177
114a8b8c
KL
178** Fix interactive use of temacs. There are face-related SEGVs, most
179 likely because of changes in realize_default_face, realize_face.
180
4ca927b4
KL
181** Very strange bug: visible-bell does not work on secondary
182 terminals. This might be something xterm (konsole) specific.
183
7b00d185
KL
184** Find out the best way to support suspending Emacs with multiple
185 ttys. My guess: disable it on the controlling tty, but from other
186 ttys pass it on to emacsclient somehow. (It is (I hope) trivial to
187 extend emacsclient to handle suspend/resume. A `kill -STOP' almost
188 works right now.)
189
428a555e 190** Move baud_rate to struct display.
7b00d185 191
7b00d185
KL
192** Implement support for starting an interactive Emacs session without
193 an initial frame. (The user would connect to it and open frames
194 later, with emacsclient.) Not necessarily a good idea.
195
3224dac1
KL
196** Fix Mac support (I can't do this myself). Note that the current
197 state of Mac-specific source files in the multi-tty tree are not
198 useful; before starting work on Mac support, revert to pristine,
199 pre-multi-tty versions.
7b00d185 200
3224dac1
KL
201** Fix W32 support (I can't do this myself). Note that the current
202 state of W32-specific source files in the multi-tty tree are not
203 useful; before starting work on W32 support, revert to pristine,
204 pre-multi-tty versions.
7b00d185 205
3224dac1
KL
206** Fix DOS support (I can't do this myself). Note that the current
207 state of DOS-specific source files in the multi-tty tree are not
208 useful; before starting work on DOS support, revert to pristine,
209 pre-multi-tty versions.
7b00d185
KL
210
211** Do a grep on XXX and ?? for more issues.
212
213** Understand Emacs's low-level input system (it seems complicated) :-)
428a555e 214 What does interrupt_input do? I tried to disable it for raw
7b00d185
KL
215 secondary tty support, but it does not seem to do anything useful.
216 (Update: Look again. X unconditionally enables this, maybe that's
217 why raw terminal support is broken again. I really do need to
218 understand input.)
219
7b00d185
KL
220** emacsclient -t from an Emacs term buffer does not work, complains
221 about face problems. This can even lock up Emacs (if the recursive
428a555e
KL
222 frame sets single_kboard). Update: the face problems are caused by
223 bugs in term.el, not in multi-tty. The lockup is caused by
4ca927b4
KL
224 single_kboard mode, and is not easily solvable. The best thing to
225 do is to simply refuse to create a tty frame of type `eterm'.
4d553a13 226
2246281f
KL
227** Maybe standard-display-table should be display-local.
228
6548cf00
KL
229DIARY OF CHANGES
230----------------
231
232(ex-TODO items with explanations.)
28d440ab 233
114a8b8c 234-- Introduce a new struct for terminal devices.
28d440ab 235
daf01701 236 (Done, see struct tty_output. The list of members is not yet
28d440ab
KL
237 complete.)
238
28d440ab
KL
239-- Change the bootstrap procedure to initialize tty_list.
240
241 (Done, but needs review.)
242
28d440ab
KL
243-- Change make-terminal-frame to support specifying another tty.
244
245 (Done, new frame parameters: `tty' and `tty-type'.)
246
9628b887
KL
247-- Implement support for reading from multiple terminals.
248
249 (Done, read_avail_input tries to read from each terminal, until one
28d7d09f 250 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
6548cf00 251 SIGIO!)
9628b887 252
819b8f00
KL
253 (Update: They do, now.)
254
daf01701
KL
255 (Update2: After enabling X, they don't.)
256
9628b887 257-- other-frame should cycle through the frames on the `current'
114a8b8c 258 terminal only.
9628b887 259
6548cf00 260 (Done, by trivially modifiying next_frame and prev_frame.)
9628b887
KL
261
262-- Support different terminal sizes.
114a8b8c 263
9628b887
KL
264 (Done, no problem.)
265
266-- Make sure terminal resizes are handled gracefully. (Could be
267 problematic.)
268
6548cf00
KL
269 (Done. We don't get automatic SIGWINCH for additional ttys,
270 though.)
9628b887
KL
271
272-- Extend emacsclient to automatically open a new tty when it connects
273 to Emacs.
114a8b8c 274
9628b887
KL
275 (Done. It's an ugly hack, needs more work.)
276
52c2ee2a
KL
277-- Redisplay must refresh the topmost frame on *all* terminals, not
278 just the initial terminal.
114a8b8c 279
52c2ee2a 280 (Done, but introduced an ugly redisplay problems. Ugh.)
9628b887 281
6548cf00
KL
282-- Fix redisplay problems.
283
52c2ee2a
KL
284 (Done; it turned out that the entire Wcm structure must be moved
285 inside tty_output. Why didn't I catch this earlier?)
6548cf00
KL
286
287-- Provide a way for emacsclient to tell Emacs that the tty has been
288 resized.
289
290 (Done, simply forward the SIGWINCH signal.)
291
292-- Each keypress should automatically select the frame corresponding
293 to the terminal that it was coming from. This means that Emacs
294 must know from which terminal the last keyboard event came from.
6548cf00 295
52c2ee2a
KL
296 (Done, it was quite simple, the input event system already
297 supported multiple frames.)
6548cf00
KL
298
299-- Fix SIGIO issue with secondary terminals.
300
301 (Done, emacsclient signals Emacs after writing to the proxy pseudo
52c2ee2a
KL
302 terminal. Note that this means that multi-tty does not work with
303 raw ttys!)
28d440ab 304
0a125897
KL
305 (Update: This is bullshit. There is a read_input_waiting function,
306 extend that somehow.)
307
819b8f00
KL
308 (Update of update: The first update was not right either, extending
309 read_input_waiting was not necessary. Secondary ttys do seem to
310 send signals on input.)
311
daf01701
KL
312 (Update^3: Not any more.)
313
fca177d4
KL
314-- Make make-terminal-frame look up the `tty' and `tty-type' frame
315 parameters from the currently selected terminal before the global
316 default.
317
318 (Done.)
319
320-- Put all cached terminal escape sequences into struct tty_output.
321 Currently, they are still stored in global variables, so we don't
322 really support multiple terminal types.
323
52c2ee2a 324 (Done. It was not fun.)
fca177d4
KL
325
326-- Implement sane error handling after initialization. (Currently
6548cf00
KL
327 emacs exits if you specify a bad terminal type.) The helpful error
328 messages must still be provided when Emacs starts.
329
fca177d4
KL
330 (Done.)
331
332-- Implement terminal deletion, i.e., deleting local frames, closing
333 the tty device and restoring its previous state without exiting
334 Emacs.
9628b887 335
fca177d4
KL
336 (Done, but at the moment only called when an error happens during
337 initialization. There is a memory corruption error around this
daf01701 338 somewhere.) (Update: now it is fully enabled.)
fca177d4 339
8303ba32
KL
340-- Implement automatic deletion of terminals when the last frame on
341 that terminal is closed.
342
343 (Done.)
344
0a125897
KL
345-- Restore tty screen after closing the terminal.
346
347 (Done, we do the same as Emacs 21.2 for all terminals.)
348
349-- 'TERM=dumb src/emacs' does not restore the terminal state.
114a8b8c 350
0a125897 351 (Done.)
fca177d4 352
b2af72d2
KL
353-- C-g should work on secondary terminals.
354
355 (Done, but the binding is not configurable.)
356
357-- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
358 server-frames may be removed from server.el.)
359
360 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
daf01701 361 from secondary ttys, which is actually a good thing.) (Update: I
7b00d185 362 think it would be a bad idea to remove server-frames.)
b2af72d2 363
daf01701 364-- Change emacsclient/server.el to support the -t argument better,
b2af72d2
KL
365 i.e. automatically close the socket when the frame is closed.
366
367 (Seems to be working OK.)
368
16c290d8 369-- Fix mysterious memory corruption error with tty deletion. To
fca177d4
KL
370 trigger it, try the following shell command:
371
372 while true; do TERM=no-such-terminal-definition emacsclient -h; done
373
374 Emacs usually dumps core after a few dozen iterations. (The bug
3224dac1 375 seems to be related to the xfreeing or bzeroing of
9d9f1812
KL
376 tty_output.Wcm. Maybe there are outside references to struct Wcm?
377 Why were these vars collected into a struct before multi-tty
378 support?)
fca177d4 379
16c290d8
KL
380 (Done. Whew. It turned out that the problem had nothing to do
381 with hypothetical external references to Wcm, or any other
382 tty_output component; it was simply that delete_tty closed the
383 filehandles of secondary ttys twice, resulting in fclose doubly
3224dac1 384 freeing memory. Utterly trivial matter. I love the C's memory
16c290d8
KL
385 management, it puts hair on your chest.)
386
819b8f00 387-- Support raw secondary terminals. (Note that SIGIO works only on
3224dac1 388 the controlling terminal.) Hint: extend read_input_waiting for
819b8f00 389 multiple ttys and hopefully this will be fixed.
fca177d4 390
819b8f00
KL
391 (Done, it seems to have been working already for some time. It
392 seems F_SETOWN does work, after all. Not sure what made it fail
393 earlier, but it seems to be fixed (there were several changes
394 around request_sigio, maybe one of them did it).
3224dac1 395 read_input_waiting is only used in sys_select, don't change
daf01701 396 it.) (Update: After adding X support, it's broken again.)
c1c63edb 397
819b8f00 398-- Find out why does Emacs abort when it wants to close its
0a125897 399 controlling tty. Hint: chan_process[] array. Hey, maybe
16c290d8
KL
400 noninterrupt-IO would work, too? Update: no, there is no process
401 for stdin/out.
c33d2d42 402
819b8f00
KL
403 (Done. Added add/delete_keyboard_wait_descriptor to
404 term_init/delete_tty. The hint was right, in a way.)
6548cf00 405
819b8f00 406-- Issue with SIGIO: it needs to be disabled during redisplay. See if
3224dac1 407 fcntl kernel behaviour could be emulated by emacsclient.
0a125897 408
819b8f00 409 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
daf01701 410 (Update: it was added back.)
22de1e79 411
819b8f00 412-- server.el: There are issues with saving files in buffers of closed
16c290d8
KL
413 clients. Try editing a file with emacsclient -f, and (without
414 saving it) do a delete-frame. The frame is closed without
415 question, and a surprising confirmation prompt appears in another
416 frame.
417
819b8f00
KL
418 (Done. delete-frame now asks for confirmation if it still has
419 pending buffers, and modified buffers don't seem to be deleted.)
420
421-- emacsclient.el, server.el: Handle eval or file open errors when
daf01701 422 doing -t.
16c290d8 423
819b8f00 424 (Done.)
22de1e79 425
819b8f00
KL
426-- Make parts of struct tty_output accessible from Lisp. The device
427 name and the type is sufficient.
22de1e79 428
819b8f00
KL
429 (Done, see frame-tty-name and frame-tty-type.)
430
431-- Export delete_tty to the Lisp environment, for emacsclient.
22de1e79 432
819b8f00
KL
433 (Done, see delete-tty.)
434
daf01701
KL
435-- Get rid of the accessor macros in termchar.h, or define macros for
436 all members.
437
438 (Done.)
439
440-- Move device-specific parameters (like costs) commonly used by
441 device backends to a common, device-dependent structure.
442
443 (Done. See struct display_method in termhooks.h.)
444
445-- Fix X support.
446
447 (Done. Well, it seems to be working.)
448
449-- Allow simultaneous X and tty frames. (Handling input could be
450 tricky. Or maybe not.)
451
452 (Done. Allowed, that is. It is currently extremely unstable, to
453 the point of being unusable. The rif variable causes constant
454 core dumps. Handling input is indeed tricky.)
819b8f00 455
7b00d185 456-- Rewrite multi-tty input in terms of MULTI_KBOARD.
28d440ab 457
7b00d185
KL
458 (Done. In fact, there was no need to rewrite anything, I just
459 added a kboard member to tty_display_info, and initialized the
460 frame's kboard from there.)
819b8f00 461
fa971ac3
KL
462-- Fix rif issue with X-tty combo sessions. IMHO the best thing to do
463 is to get rid of that global variable (and use the value value in
464 display_method, which is guaranteed to be correct).
465
466 (Done, did exactly that. Core dumps during combo sessions became
467 much rarer. In fact, I have not yet met a single one.)
468
17086732
KL
469-- Add multi-tty support to talk.el.
470
471 (Done.)
472
428a555e
KL
473-- Clean up the source of emacsclient. It is a mess.
474
475 (Done, eliminated stupid proxy-pty kludge.)
476
477-- Fix faces on tty frames during X-tty combo sessions. There is an
478 init_frame_faces call in init_sys_modes, see if there is a problem
479 with it.
480
481 (Done, there was a stupid mistake in
482 Ftty_supports_face_attributes_p. Colors are broken, though.)
483
484-- C-x 5 2, C-x 5 o, C-x 5 0 on an emacsclient frame unexpectedly
485 exits emacsclient. This is a result of trying to be clever with
486 delete-frame-functions.
487
488 (Fixed, added delete-tty-after-functions, and changed server.el to
489 use it.)
490
491-- Something with (maybe) multi-keyboard support broke function keys
492 and arrows on ttys during X+tty combo sessions. Debug this.
493
494 (I can't reproduce it, maybe the terminal type was wrong.)
495
496-- Fix input from raw ttys (again).
497
498 (Now it seems to work all right.)
499
500-- During an X-tty combo session, a (message "Hello") from a tty frame
501 goes to the X frame. Fix this.
502
503 (Done. There was a safeguard against writing to the initial
504 terminal frame during bootstrap which prevented echo_area_display
505 from working correctly on a tty frame during a combo session.)
506
114a8b8c
KL
507-- If there are no frames on its controlling terminal, Emacs should
508 exit if the uses presses C-c there.
509
510 (Done, as far as possible. See the SIGTERM comment in
511 interrupt_signal on why this seems to be impossible to solve this
512 in general.)
513
514-- During an X session, Emacs seems to read from stdin. Also, Emacs
515 fails to start without a controlling tty.
516
517 (Fixed by replacing the troublesome termcap display with a dummy
518 bootstrap display during bootstrap.
519
520-- Do tty output through struct display, like graphical display
521 backends.
522
523 (Done.)
524
525-- Define an output_initial value for output_method for the initial
526 frame that is dumped with Emacs. Checking for this frame (e.g. in
527 cmd_error_internal) is ugly.
528
529 (Done, broking interactive temacs.)
530
531-- The command `emacsclient -t -e '(delete-frame)'' fails to exit.
532
533 (Fixed.)
534
4ca927b4
KL
535-- frame-creation-function should always create a frame that is on the
536 same display as the selected frame. Maybe frame-creation-function
537 should simply be removed and make-frame changed to do the right
538 thing.
539
540 (Done, with a nice hack. frame-creation-function is now frame-local.)
541
542-- Fix C-g on raw ttys.
543
544 (Done. I disabled the interrupt/quit keys on all secondary
545 terminals, so Emacs sees C-g as normal input. This looks like an
546 overkill, because emacsclient has extra code to pass SIGINT to
547 Emacs, so C-g should remain the interrupt/quit key on emacsclient
548 frames. See the next entry why implementing this distinction would
549 be a bad idea.)
550
551-- Make sure C-g goes to the right frame with ttys. This is hard, as
552 SIGINT doesn't have a tty parameter. :-(
553
554 (Done, the previous change fixes this as a pleasant side effect.)
555
c0707982
KL
556-- I have seen a case when Emacs with multiple ttys fell into a loop
557 eating 100% of CPU time. Strace showed this loop:
558
559 getpid() = 30284
560 kill(30284, SIGIO) = 0
561 --- SIGIO (I/O possible) @ 0 (0) ---
562 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
563 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
564 ioctl(0, FIONREAD, [0]) = 0
565 sigreturn() = ? (mask now [])
566 gettimeofday({1072842297, 747760}, NULL) = 0
567 gettimeofday({1072842297, 747806}, NULL) = 0
568 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
569 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
570 gettimeofday({1072842297, 748245}, NULL) = 0
571
572 I have seen something similar with a single X frame, but have not
573 been able to reproduce it for debugging.
574
575 Update: This may have been caused by checking for nread != 0
576 instead of nread > 0 after calling read_socket_hook in
577 read_avail_input.
578
579 (Fixed. This was caused by unconditionally including stdin in
580 input_wait_mask in init_process. The select call in
581 wait_reading_process_input always returned immediately, indicating
582 that there is pending input from stdin, which nobody read.
583
584 Note that the above strace output seems to be an unrelated but
585 similar bug. I think that is now fixed.)
4ca927b4 586
2246281f
KL
587-- Exiting Emacs while there are emacsclient frames doesn't restore the
588 ttys to their default states.
589
590 (This seems to be fixed by some previous change.)
591
592-- Allow opening an X session after -nw.
593
594 (Done.)
595
d448e982
KL
596-- Fix color handling during tty+X combo sessions. (It seems that tty
597 sessions automatically convert the face colors to terminal colors
598 when the face is loaded. This conversion must happen instead on
599 the fly in write_glyphs, which might be problematic, as color
600 approximation is currently done in lisp (term/tty-colors.el).)
601 (Update: hm, colors seem to work fine if I start emacs with -nw and
602 then create an X frame. Maybe it's just a small buglet somewhere.)
603
604 (Seems to be fixed. The problem was in startup.el, it did not
605 initialize tty colors when the initial window system was
606 graphical.)
2246281f 607
28d440ab 608;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d