Cosmetic changes.
[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
4ca927b4
KL
176** Very strange bug: visible-bell does not work on secondary
177 terminals. This might be something xterm (konsole) specific.
178
7b00d185
KL
179** Find out the best way to support suspending Emacs with multiple
180 ttys. My guess: disable it on the controlling tty, but from other
181 ttys pass it on to emacsclient somehow. (It is (I hope) trivial to
182 extend emacsclient to handle suspend/resume. A `kill -STOP' almost
183 works right now.)
184
428a555e 185** Move baud_rate to struct display.
7b00d185 186
7b00d185
KL
187** Implement support for starting an interactive Emacs session without
188 an initial frame. (The user would connect to it and open frames
189 later, with emacsclient.) Not necessarily a good idea.
190
3224dac1
KL
191** Fix Mac support (I can't do this myself). Note that the current
192 state of Mac-specific source files in the multi-tty tree are not
193 useful; before starting work on Mac support, revert to pristine,
194 pre-multi-tty versions.
7b00d185 195
3224dac1
KL
196** Fix W32 support (I can't do this myself). Note that the current
197 state of W32-specific source files in the multi-tty tree are not
198 useful; before starting work on W32 support, revert to pristine,
199 pre-multi-tty versions.
7b00d185 200
3224dac1
KL
201** Fix DOS support (I can't do this myself). Note that the current
202 state of DOS-specific source files in the multi-tty tree are not
203 useful; before starting work on DOS support, revert to pristine,
204 pre-multi-tty versions.
7b00d185
KL
205
206** Do a grep on XXX and ?? for more issues.
207
208** Understand Emacs's low-level input system (it seems complicated) :-)
428a555e 209 What does interrupt_input do? I tried to disable it for raw
7b00d185
KL
210 secondary tty support, but it does not seem to do anything useful.
211 (Update: Look again. X unconditionally enables this, maybe that's
212 why raw terminal support is broken again. I really do need to
213 understand input.)
214
7b00d185
KL
215** emacsclient -t from an Emacs term buffer does not work, complains
216 about face problems. This can even lock up Emacs (if the recursive
428a555e
KL
217 frame sets single_kboard). Update: the face problems are caused by
218 bugs in term.el, not in multi-tty. The lockup is caused by
4ca927b4
KL
219 single_kboard mode, and is not easily solvable. The best thing to
220 do is to simply refuse to create a tty frame of type `eterm'.
4d553a13 221
2246281f
KL
222** Maybe standard-display-table should be display-local.
223
6548cf00
KL
224DIARY OF CHANGES
225----------------
226
227(ex-TODO items with explanations.)
28d440ab 228
114a8b8c 229-- Introduce a new struct for terminal devices.
28d440ab 230
daf01701 231 (Done, see struct tty_output. The list of members is not yet
28d440ab
KL
232 complete.)
233
28d440ab
KL
234-- Change the bootstrap procedure to initialize tty_list.
235
236 (Done, but needs review.)
237
28d440ab
KL
238-- Change make-terminal-frame to support specifying another tty.
239
240 (Done, new frame parameters: `tty' and `tty-type'.)
241
9628b887
KL
242-- Implement support for reading from multiple terminals.
243
244 (Done, read_avail_input tries to read from each terminal, until one
28d7d09f 245 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
6548cf00 246 SIGIO!)
9628b887 247
819b8f00
KL
248 (Update: They do, now.)
249
daf01701
KL
250 (Update2: After enabling X, they don't.)
251
9628b887 252-- other-frame should cycle through the frames on the `current'
114a8b8c 253 terminal only.
9628b887 254
6548cf00 255 (Done, by trivially modifiying next_frame and prev_frame.)
9628b887
KL
256
257-- Support different terminal sizes.
114a8b8c 258
9628b887
KL
259 (Done, no problem.)
260
261-- Make sure terminal resizes are handled gracefully. (Could be
262 problematic.)
263
6548cf00
KL
264 (Done. We don't get automatic SIGWINCH for additional ttys,
265 though.)
9628b887
KL
266
267-- Extend emacsclient to automatically open a new tty when it connects
268 to Emacs.
114a8b8c 269
9628b887
KL
270 (Done. It's an ugly hack, needs more work.)
271
52c2ee2a
KL
272-- Redisplay must refresh the topmost frame on *all* terminals, not
273 just the initial terminal.
114a8b8c 274
52c2ee2a 275 (Done, but introduced an ugly redisplay problems. Ugh.)
9628b887 276
6548cf00
KL
277-- Fix redisplay problems.
278
52c2ee2a
KL
279 (Done; it turned out that the entire Wcm structure must be moved
280 inside tty_output. Why didn't I catch this earlier?)
6548cf00
KL
281
282-- Provide a way for emacsclient to tell Emacs that the tty has been
283 resized.
284
285 (Done, simply forward the SIGWINCH signal.)
286
287-- Each keypress should automatically select the frame corresponding
288 to the terminal that it was coming from. This means that Emacs
289 must know from which terminal the last keyboard event came from.
6548cf00 290
52c2ee2a
KL
291 (Done, it was quite simple, the input event system already
292 supported multiple frames.)
6548cf00
KL
293
294-- Fix SIGIO issue with secondary terminals.
295
296 (Done, emacsclient signals Emacs after writing to the proxy pseudo
52c2ee2a
KL
297 terminal. Note that this means that multi-tty does not work with
298 raw ttys!)
28d440ab 299
0a125897
KL
300 (Update: This is bullshit. There is a read_input_waiting function,
301 extend that somehow.)
302
819b8f00
KL
303 (Update of update: The first update was not right either, extending
304 read_input_waiting was not necessary. Secondary ttys do seem to
305 send signals on input.)
306
daf01701
KL
307 (Update^3: Not any more.)
308
fca177d4
KL
309-- Make make-terminal-frame look up the `tty' and `tty-type' frame
310 parameters from the currently selected terminal before the global
311 default.
312
313 (Done.)
314
315-- Put all cached terminal escape sequences into struct tty_output.
316 Currently, they are still stored in global variables, so we don't
317 really support multiple terminal types.
318
52c2ee2a 319 (Done. It was not fun.)
fca177d4
KL
320
321-- Implement sane error handling after initialization. (Currently
6548cf00
KL
322 emacs exits if you specify a bad terminal type.) The helpful error
323 messages must still be provided when Emacs starts.
324
fca177d4
KL
325 (Done.)
326
327-- Implement terminal deletion, i.e., deleting local frames, closing
328 the tty device and restoring its previous state without exiting
329 Emacs.
9628b887 330
fca177d4
KL
331 (Done, but at the moment only called when an error happens during
332 initialization. There is a memory corruption error around this
daf01701 333 somewhere.) (Update: now it is fully enabled.)
fca177d4 334
8303ba32
KL
335-- Implement automatic deletion of terminals when the last frame on
336 that terminal is closed.
337
338 (Done.)
339
0a125897
KL
340-- Restore tty screen after closing the terminal.
341
342 (Done, we do the same as Emacs 21.2 for all terminals.)
343
344-- 'TERM=dumb src/emacs' does not restore the terminal state.
114a8b8c 345
0a125897 346 (Done.)
fca177d4 347
b2af72d2
KL
348-- C-g should work on secondary terminals.
349
350 (Done, but the binding is not configurable.)
351
352-- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
353 server-frames may be removed from server.el.)
354
355 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
daf01701 356 from secondary ttys, which is actually a good thing.) (Update: I
7b00d185 357 think it would be a bad idea to remove server-frames.)
b2af72d2 358
daf01701 359-- Change emacsclient/server.el to support the -t argument better,
b2af72d2
KL
360 i.e. automatically close the socket when the frame is closed.
361
362 (Seems to be working OK.)
363
16c290d8 364-- Fix mysterious memory corruption error with tty deletion. To
fca177d4
KL
365 trigger it, try the following shell command:
366
367 while true; do TERM=no-such-terminal-definition emacsclient -h; done
368
369 Emacs usually dumps core after a few dozen iterations. (The bug
3224dac1 370 seems to be related to the xfreeing or bzeroing of
9d9f1812
KL
371 tty_output.Wcm. Maybe there are outside references to struct Wcm?
372 Why were these vars collected into a struct before multi-tty
373 support?)
fca177d4 374
16c290d8
KL
375 (Done. Whew. It turned out that the problem had nothing to do
376 with hypothetical external references to Wcm, or any other
377 tty_output component; it was simply that delete_tty closed the
378 filehandles of secondary ttys twice, resulting in fclose doubly
3224dac1 379 freeing memory. Utterly trivial matter. I love the C's memory
16c290d8
KL
380 management, it puts hair on your chest.)
381
819b8f00 382-- Support raw secondary terminals. (Note that SIGIO works only on
3224dac1 383 the controlling terminal.) Hint: extend read_input_waiting for
819b8f00 384 multiple ttys and hopefully this will be fixed.
fca177d4 385
819b8f00
KL
386 (Done, it seems to have been working already for some time. It
387 seems F_SETOWN does work, after all. Not sure what made it fail
388 earlier, but it seems to be fixed (there were several changes
389 around request_sigio, maybe one of them did it).
3224dac1 390 read_input_waiting is only used in sys_select, don't change
daf01701 391 it.) (Update: After adding X support, it's broken again.)
c1c63edb 392
819b8f00 393-- Find out why does Emacs abort when it wants to close its
0a125897 394 controlling tty. Hint: chan_process[] array. Hey, maybe
16c290d8
KL
395 noninterrupt-IO would work, too? Update: no, there is no process
396 for stdin/out.
c33d2d42 397
819b8f00
KL
398 (Done. Added add/delete_keyboard_wait_descriptor to
399 term_init/delete_tty. The hint was right, in a way.)
6548cf00 400
819b8f00 401-- Issue with SIGIO: it needs to be disabled during redisplay. See if
3224dac1 402 fcntl kernel behaviour could be emulated by emacsclient.
0a125897 403
819b8f00 404 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
daf01701 405 (Update: it was added back.)
22de1e79 406
819b8f00 407-- server.el: There are issues with saving files in buffers of closed
16c290d8
KL
408 clients. Try editing a file with emacsclient -f, and (without
409 saving it) do a delete-frame. The frame is closed without
410 question, and a surprising confirmation prompt appears in another
411 frame.
412
819b8f00
KL
413 (Done. delete-frame now asks for confirmation if it still has
414 pending buffers, and modified buffers don't seem to be deleted.)
415
416-- emacsclient.el, server.el: Handle eval or file open errors when
daf01701 417 doing -t.
16c290d8 418
819b8f00 419 (Done.)
22de1e79 420
819b8f00
KL
421-- Make parts of struct tty_output accessible from Lisp. The device
422 name and the type is sufficient.
22de1e79 423
819b8f00
KL
424 (Done, see frame-tty-name and frame-tty-type.)
425
426-- Export delete_tty to the Lisp environment, for emacsclient.
22de1e79 427
819b8f00
KL
428 (Done, see delete-tty.)
429
daf01701
KL
430-- Get rid of the accessor macros in termchar.h, or define macros for
431 all members.
432
433 (Done.)
434
435-- Move device-specific parameters (like costs) commonly used by
436 device backends to a common, device-dependent structure.
437
438 (Done. See struct display_method in termhooks.h.)
439
440-- Fix X support.
441
442 (Done. Well, it seems to be working.)
443
444-- Allow simultaneous X and tty frames. (Handling input could be
445 tricky. Or maybe not.)
446
447 (Done. Allowed, that is. It is currently extremely unstable, to
448 the point of being unusable. The rif variable causes constant
449 core dumps. Handling input is indeed tricky.)
819b8f00 450
7b00d185 451-- Rewrite multi-tty input in terms of MULTI_KBOARD.
28d440ab 452
7b00d185
KL
453 (Done. In fact, there was no need to rewrite anything, I just
454 added a kboard member to tty_display_info, and initialized the
455 frame's kboard from there.)
819b8f00 456
fa971ac3
KL
457-- Fix rif issue with X-tty combo sessions. IMHO the best thing to do
458 is to get rid of that global variable (and use the value value in
459 display_method, which is guaranteed to be correct).
460
461 (Done, did exactly that. Core dumps during combo sessions became
462 much rarer. In fact, I have not yet met a single one.)
463
17086732
KL
464-- Add multi-tty support to talk.el.
465
466 (Done.)
467
428a555e
KL
468-- Clean up the source of emacsclient. It is a mess.
469
470 (Done, eliminated stupid proxy-pty kludge.)
471
472-- Fix faces on tty frames during X-tty combo sessions. There is an
473 init_frame_faces call in init_sys_modes, see if there is a problem
474 with it.
475
476 (Done, there was a stupid mistake in
477 Ftty_supports_face_attributes_p. Colors are broken, though.)
478
479-- C-x 5 2, C-x 5 o, C-x 5 0 on an emacsclient frame unexpectedly
480 exits emacsclient. This is a result of trying to be clever with
481 delete-frame-functions.
482
483 (Fixed, added delete-tty-after-functions, and changed server.el to
484 use it.)
485
486-- Something with (maybe) multi-keyboard support broke function keys
487 and arrows on ttys during X+tty combo sessions. Debug this.
488
489 (I can't reproduce it, maybe the terminal type was wrong.)
490
491-- Fix input from raw ttys (again).
492
493 (Now it seems to work all right.)
494
495-- During an X-tty combo session, a (message "Hello") from a tty frame
496 goes to the X frame. Fix this.
497
498 (Done. There was a safeguard against writing to the initial
499 terminal frame during bootstrap which prevented echo_area_display
500 from working correctly on a tty frame during a combo session.)
501
114a8b8c
KL
502-- If there are no frames on its controlling terminal, Emacs should
503 exit if the uses presses C-c there.
504
505 (Done, as far as possible. See the SIGTERM comment in
506 interrupt_signal on why this seems to be impossible to solve this
507 in general.)
508
509-- During an X session, Emacs seems to read from stdin. Also, Emacs
510 fails to start without a controlling tty.
511
512 (Fixed by replacing the troublesome termcap display with a dummy
513 bootstrap display during bootstrap.
514
515-- Do tty output through struct display, like graphical display
516 backends.
517
518 (Done.)
519
520-- Define an output_initial value for output_method for the initial
521 frame that is dumped with Emacs. Checking for this frame (e.g. in
522 cmd_error_internal) is ugly.
523
524 (Done, broking interactive temacs.)
525
526-- The command `emacsclient -t -e '(delete-frame)'' fails to exit.
527
528 (Fixed.)
529
4ca927b4
KL
530-- frame-creation-function should always create a frame that is on the
531 same display as the selected frame. Maybe frame-creation-function
532 should simply be removed and make-frame changed to do the right
533 thing.
534
535 (Done, with a nice hack. frame-creation-function is now frame-local.)
536
537-- Fix C-g on raw ttys.
538
539 (Done. I disabled the interrupt/quit keys on all secondary
540 terminals, so Emacs sees C-g as normal input. This looks like an
541 overkill, because emacsclient has extra code to pass SIGINT to
542 Emacs, so C-g should remain the interrupt/quit key on emacsclient
543 frames. See the next entry why implementing this distinction would
544 be a bad idea.)
545
546-- Make sure C-g goes to the right frame with ttys. This is hard, as
547 SIGINT doesn't have a tty parameter. :-(
548
549 (Done, the previous change fixes this as a pleasant side effect.)
550
c0707982
KL
551-- I have seen a case when Emacs with multiple ttys fell into a loop
552 eating 100% of CPU time. Strace showed this loop:
553
554 getpid() = 30284
555 kill(30284, SIGIO) = 0
556 --- SIGIO (I/O possible) @ 0 (0) ---
557 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
558 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
559 ioctl(0, FIONREAD, [0]) = 0
560 sigreturn() = ? (mask now [])
561 gettimeofday({1072842297, 747760}, NULL) = 0
562 gettimeofday({1072842297, 747806}, NULL) = 0
563 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
564 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
565 gettimeofday({1072842297, 748245}, NULL) = 0
566
567 I have seen something similar with a single X frame, but have not
568 been able to reproduce it for debugging.
569
570 Update: This may have been caused by checking for nread != 0
571 instead of nread > 0 after calling read_socket_hook in
572 read_avail_input.
573
574 (Fixed. This was caused by unconditionally including stdin in
575 input_wait_mask in init_process. The select call in
576 wait_reading_process_input always returned immediately, indicating
577 that there is pending input from stdin, which nobody read.
578
579 Note that the above strace output seems to be an unrelated but
580 similar bug. I think that is now fixed.)
4ca927b4 581
2246281f
KL
582-- Exiting Emacs while there are emacsclient frames doesn't restore the
583 ttys to their default states.
584
585 (This seems to be fixed by some previous change.)
586
587-- Allow opening an X session after -nw.
588
589 (Done.)
590
d448e982
KL
591-- Fix color handling during tty+X combo sessions. (It seems that tty
592 sessions automatically convert the face colors to terminal colors
593 when the face is loaded. This conversion must happen instead on
594 the fly in write_glyphs, which might be problematic, as color
595 approximation is currently done in lisp (term/tty-colors.el).)
596 (Update: hm, colors seem to work fine if I start emacs with -nw and
597 then create an X frame. Maybe it's just a small buglet somewhere.)
598
599 (Seems to be fixed. The problem was in startup.el, it did not
600 initialize tty colors when the initial window system was
601 graphical.)
2246281f 602
2441679b
KL
603-- emacs -nw --eval '(y-or-n-p "Foobar")' segfaults. (Reported by
604 Romain Francoise)
605
606 (Fixed, there was a keyboard initialization problem.)
607
3bbdbec9
KL
608-- Fix interactive use of temacs. There are face-related SEGVs, most
609 likely because of changes in realize_default_face, realize_face.
610
611 (Fixed.)
612
28d440ab 613;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d