Fix longopts option name for --tty.
[emacs.git] / README.multi-tty
blobf395d3acbdcf35102feb006325143b47b3a309a6
1                         -*- coding: utf-8; -*-
2 GOAL
3 ----
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.
9 Some use cases:
11 Emacs is notoriously slow at startup, so most people use another
12 editor or emacsclient for quick editing jobs from the console.
13 Unfortunately, emacsclient was very awkward to use, because it did not
14 support opening a new Emacs frame on the current virtual console.
15 Now, with multi-tty support, it can do that.  (Emacsclient starts up
16 faster than vi!)
18 Some Gnus users (including me) run Gnus in an X frame in its own Emacs
19 instance, which they typically leave running for weeks.  It would be
20 nice if they could connect to this instance from a remote ssh session
21 and check their messages without opening a remote X frame or resorting
22 to gnus-slave.
25 WHO IS DOING IT
26 ---------------
28 I'm Károly Lőrentey.  My address: lorentey@elte.hu.
30 Patches or suggestions are welcome!
32 Retrieving the latest version of the branch:
34         tla register-archive lorentey@elte.hu--2004 http://lorentey.web.elte.hu/arch/2004/
35         tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
37 (I use a recent arch development snapshot, but any of the released
38 versions of arch will do fine, I think.)
40 If you don't have arch, the branch has a homepage from which you can
41 download conventional patches against Emacs CVS HEAD:
43         http://lorentey.web.elte.hu/project/emacs.html
45 STATUS
46 ------
48 Multi-tty support is stable, I think most of the problems were fixed.
49 (It still needs testing on other architectures, though.)  Please let
50 me know if you find any bugs in it.  Emacsclient has been extended to
51 support opening a new terminal frame.
53 To try it out, compile and run the multi-tty branch with the following
54 commands:
56         mkdir +build
57         cd +build
58         ../configure
59         make bootstrap
60         src/emacs -nw
61         M-x server-start
63 and then (from a shell prompt on another terminal) start emacsclient
64 with
66         lib-src/emacsclient -t /optional/file/names...
68 You'll hopefully have two fully working, independent frames on
69 separate terminals. The new frame is closed automatically when you
70 have finished editing the specified files (C-x #), but delete-frame
71 (C-x 5 0) also works.  Of course, you can create frames on more than
72 two tty devices.
74 Creating new frames on the same tty with C-x 5 2 works, and they
75 behave the same way as in previous Emacs versions.  If you exit emacs,
76 all terminals should be restored to their previous states.
78 This is work in progress, and probably full of bugs.  You should
79 always run emacs from gdb, so that you'll have a live instance to
80 debug if something goes wrong.  Please send me your reports.
82 Problems:
84         * Suspending Emacs is disabled if there are multiple tty
85           devices.  Also, there is no way to suspend emacsclient. This
86           will be fixed.
88         * X support is (I hope) working, but at the moment there are
89           problems with simultaneous X and tty devices, so don't do
90           that - start a separate Emacs with -nw and run the server
91           there.
93         * Mac, Windows and DOS support is broken, probably doesn't
94           even compile -- this will be solved later.
96         * Only tested on my GNU/Linux box.
98 NEWS
99 ----
101 For the NEWS file:
103 ** Support for multiple terminal devices has been added.  You can
104    specify a terminal device (`tty' parameter) and a terminal type
105    (`tty-type' parameter) to `make-terminal-frame'. `tty' must be a
106    terminal device created by the updated emacsclient, or there will
107    be problems with terminal input and window resizes.  
109    You can test for the presence of multiple terminal support by
110    testing for the `multi-tty' feature.
112 ** A make-frame-on-tty function has been added to make it easier to
113    create frames on new terminals.
115 ** New functions: frame-tty-name, frame-tty-type for accessing
116    terminal parameters, and delete-tty for closing the terminal
117    device.
119 ** Emacsclient has been extended to support opening a new terminal
120    frame.
122 CHANGELOG
123 ---------
125 See arch logs.
127 THINGS TO DO
128 ------------
130 ** Something with (maybe) multi-keyboard support broke function keys
131    and arrows on ttys during X+tty combo sessions.  Debug this.
133 ** Fix faces on tty frames during X-tty combo sessions.
135 ** During an X-tty combo session, a (message "Hello") from a tty frame
136    goes to the X frame.  Fix this.
138 ** Find out the best way to support suspending Emacs with multiple
139    ttys.  My guess: disable it on the controlling tty, but from other
140    ttys pass it on to emacsclient somehow.  (It is (I hope) trivial to
141    extend emacsclient to handle suspend/resume.  A `kill -STOP' almost
142    works right now.)
144 ** Move baud_rate to tty_output.
146 ** Do tty output through term_hooks, like graphical display backends.
148 ** Implement support for starting an interactive Emacs session without
149    an initial frame.  (The user would connect to it and open frames
150    later, with emacsclient.)  Not necessarily a good idea.
152 ** Fix input from raw ttys (again).
154 ** Fix Mac support (I can't do this myself).
156 ** Fix W32 support (I can't do this myself).
158 ** Fix DOS support (I can't do this myself).
160 ** Do a grep on XXX and ?? for more issues.
162 ** Understand Emacs's low-level input system (it seems complicated) :-)
164 ** What does interrupt_input do?  I tried to disable it for raw
165    secondary tty support, but it does not seem to do anything useful.
166    (Update: Look again. X unconditionally enables this, maybe that's
167    why raw terminal support is broken again.  I really do need to
168    understand input.)
170 ** Make sure C-g goes to the right frame.  This is hard, as SIGINT
171    doesn't have a tty parameter. :-(
173 ** I have seen a case when Emacs with multiple ttys fell into a loop
174    eating 100% of CPU time.  Strace showed this loop:
176         getpid()                                = 30284
177         kill(30284, SIGIO)                      = 0
178         --- SIGIO (I/O possible) @ 0 (0) ---
179         ioctl(6, FIONREAD, [0])                 = -1 EIO (Input/output error)
180         ioctl(5, FIONREAD, [0])                 = -1 EIO (Input/output error)
181         ioctl(0, FIONREAD, [0])                 = 0
182         sigreturn()                             = ? (mask now [])
183         gettimeofday({1072842297, 747760}, NULL) = 0
184         gettimeofday({1072842297, 747806}, NULL) = 0
185         select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
186         select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
187         gettimeofday({1072842297, 748245}, NULL) = 0
189    I have not been able to reproduce this.
191 ** Define a output_initial value for output_method for the initial
192    frame that is dumped with Emacs.  Checking for this frame (e.g. in
193    cmd_error_internal) is ugly.
195 ** emacsclient -t from an Emacs term buffer does not work, complains
196    about face problems.  This can even lock up Emacs (if the recursive
197    frame sets single_kboard).
199 DIARY OF CHANGES
200 ----------------
202 (ex-TODO items with explanations.)
204 -- Introduce a new struct for terminal devices.  
206    (Done, see struct tty_output.  The list of members is not yet
207    complete.)
209 -- Change the bootstrap procedure to initialize tty_list.
211    (Done, but needs review.)
213 -- Change make-terminal-frame to support specifying another tty.
215    (Done, new frame parameters: `tty' and `tty-type'.)
217 -- Implement support for reading from multiple terminals.
219    (Done, read_avail_input tries to read from each terminal, until one
220    succeeds.  MULTI_KBOARD is not used.  Secondary terminals don't send
221    SIGIO!)
223    (Update: They do, now.)
225    (Update2: After enabling X, they don't.)
227 -- other-frame should cycle through the frames on the `current'
228    terminal only.  
230    (Done, by trivially modifiying next_frame and prev_frame.)
232 -- Support different terminal sizes.
233    
234    (Done, no problem.)
236 -- Make sure terminal resizes are handled gracefully.  (Could be
237    problematic.)
239    (Done.  We don't get automatic SIGWINCH for additional ttys,
240    though.)
242 -- Extend emacsclient to automatically open a new tty when it connects
243    to Emacs.
244    
245    (Done.  It's an ugly hack, needs more work.)
247 -- Redisplay must refresh the topmost frame on *all* terminals, not
248    just the initial terminal.
249    
250    (Done, but introduced an ugly redisplay problems.  Ugh.)
252 -- Fix redisplay problems.
254    (Done; it turned out that the entire Wcm structure must be moved
255    inside tty_output.  Why didn't I catch this earlier?)
257 -- Provide a way for emacsclient to tell Emacs that the tty has been
258    resized.
260    (Done, simply forward the SIGWINCH signal.)
262 -- Each keypress should automatically select the frame corresponding
263    to the terminal that it was coming from.  This means that Emacs
264    must know from which terminal the last keyboard event came from.
266    (Done, it was quite simple, the input event system already
267    supported multiple frames.)
269 -- Fix SIGIO issue with secondary terminals.
271    (Done, emacsclient signals Emacs after writing to the proxy pseudo
272    terminal.  Note that this means that multi-tty does not work with
273    raw ttys!)
275    (Update: This is bullshit.  There is a read_input_waiting function,
276    extend that somehow.)
278    (Update of update: The first update was not right either, extending
279    read_input_waiting was not necessary.  Secondary ttys do seem to
280    send signals on input.)
282    (Update^3: Not any more.)
284 -- Make make-terminal-frame look up the `tty' and `tty-type' frame
285    parameters from the currently selected terminal before the global
286    default.
288    (Done.)
290 -- Put all cached terminal escape sequences into struct tty_output.
291    Currently, they are still stored in global variables, so we don't
292    really support multiple terminal types.
294    (Done.  It was not fun.)
296 -- Implement sane error handling after initialization.  (Currently
297    emacs exits if you specify a bad terminal type.)  The helpful error
298    messages must still be provided when Emacs starts.
300    (Done.)
302 -- Implement terminal deletion, i.e., deleting local frames, closing
303    the tty device and restoring its previous state without exiting
304    Emacs.
306    (Done, but at the moment only called when an error happens during
307    initialization.  There is a memory corruption error around this
308    somewhere.)  (Update: now it is fully enabled.)
310 -- Implement automatic deletion of terminals when the last frame on
311    that terminal is closed.
313    (Done.)
315 -- Restore tty screen after closing the terminal.
317    (Done, we do the same as Emacs 21.2 for all terminals.)
319 -- 'TERM=dumb src/emacs' does not restore the terminal state.
320    
321    (Done.)
323 -- C-g should work on secondary terminals.
325    (Done, but the binding is not configurable.)
327 -- Deal with SIGHUP in Emacs and in emacsclient.  (After this, the
328    server-frames may be removed from server.el.)
330    (Done, nothing to do.  It seems that Emacs does not receive SIGHUP
331    from secondary ttys, which is actually a good thing.)  (Update: I
332    think it would be a bad idea to remove server-frames.)
334 -- Change emacsclient/server.el to support the -t argument better,
335    i.e. automatically close the socket when the frame is closed.
337    (Seems to be working OK.)
339 -- Fix mysterious memory corruption error with tty deletion.  To
340    trigger it, try the following shell command:
342         while true; do TERM=no-such-terminal-definition emacsclient -h; done
344    Emacs usually dumps core after a few dozen iterations.  (The bug
345    seems to be related to the xfree()ing or bzero()ing of
346    tty_output.Wcm.  Maybe there are outside references to struct Wcm?
347    Why were these vars collected into a struct before multi-tty
348    support?)
350    (Done.  Whew.  It turned out that the problem had nothing to do
351    with hypothetical external references to Wcm, or any other
352    tty_output component; it was simply that delete_tty closed the
353    filehandles of secondary ttys twice, resulting in fclose doubly
354    free()ing memory.  Utterly trivial matter.  I love the C's memory
355    management, it puts hair on your chest.)
357 -- Support raw secondary terminals.  (Note that SIGIO works only on
358    the controlling terminal.) Hint: extend read_input_waiting() for
359    multiple ttys and hopefully this will be fixed.
361    (Done, it seems to have been working already for some time.  It
362    seems F_SETOWN does work, after all.  Not sure what made it fail
363    earlier, but it seems to be fixed (there were several changes
364    around request_sigio, maybe one of them did it).
365    read_input_waiting() is only used in sys_select(), don't change
366    it.)  (Update: After adding X support, it's broken again.)
368 -- Find out why does Emacs abort when it wants to close its
369    controlling tty.  Hint: chan_process[] array.  Hey, maybe
370    noninterrupt-IO would work, too?  Update: no, there is no process
371    for stdin/out.
373    (Done.  Added add/delete_keyboard_wait_descriptor to
374    term_init/delete_tty.  The hint was right, in a way.)
376 -- Issue with SIGIO: it needs to be disabled during redisplay.  See if
377    fcntl() kernel behaviour could be emulated by emacsclient.
379    (Done.  Simply disabled the SIGIO emulation hack in emacsclient.)
380    (Update: it was added back.)
382 -- server.el: There are issues with saving files in buffers of closed
383    clients.  Try editing a file with emacsclient -f, and (without
384    saving it) do a delete-frame.  The frame is closed without
385    question, and a surprising confirmation prompt appears in another
386    frame.
388    (Done.  delete-frame now asks for confirmation if it still has
389    pending buffers, and modified buffers don't seem to be deleted.)
391 -- emacsclient.el, server.el: Handle eval or file open errors when
392    doing -t.
394    (Done.)
396 -- Make parts of struct tty_output accessible from Lisp.  The device
397    name and the type is sufficient.
399    (Done, see frame-tty-name and frame-tty-type.)
401 -- Export delete_tty to the Lisp environment, for emacsclient.
403    (Done, see delete-tty.)
405 -- Get rid of the accessor macros in termchar.h, or define macros for
406    all members.
408    (Done.)
410 -- Move device-specific parameters (like costs) commonly used by
411    device backends to a common, device-dependent structure.
413    (Done.  See struct display_method in termhooks.h.)
415 -- Fix X support.
417    (Done.  Well, it seems to be working.)
419 -- Allow simultaneous X and tty frames.  (Handling input could be
420    tricky.  Or maybe not.)
422    (Done.  Allowed, that is.  It is currently extremely unstable, to
423    the point of being unusable.  The rif variable causes constant
424    core dumps.  Handling input is indeed tricky.)
426 -- Rewrite multi-tty input in terms of MULTI_KBOARD.
428    (Done.  In fact, there was no need to rewrite anything, I just
429    added a kboard member to tty_display_info, and initialized the
430    frame's kboard from there.)
432 -- Fix rif issue with X-tty combo sessions.  IMHO the best thing to do
433    is to get rid of that global variable (and use the value value in
434    display_method, which is guaranteed to be correct).
436    (Done, did exactly that.  Core dumps during combo sessions became
437    much rarer.  In fact, I have not yet met a single one.)
439 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d