Merged from miles@gnu.org--gnu-2005 (patch 469)
[bpt/emacs.git] / README.multi-tty
1 -*- coding: utf-8; mode: text; -*-
2 GOAL
3 ----
4
5 This branch implements support for opening multiple, different tty
6 devices and simultaneous X and tty frames from a single Emacs session.
7
8 Some use cases:
9 Emacs is notoriously slow at startup, so most people use another
10 editor or emacsclient for quick editing jobs from the console.
11 Unfortunately, emacsclient was very awkward to use, because it did not
12 support opening a new Emacs frame on the current virtual console.
13 Now, with multi-tty support, it can do that. (Emacsclient starts up
14 faster than vi!)
15
16 Some Gnus users (including me) run Gnus in an X frame in its own Emacs
17 instance, which they typically leave running for weeks. It would be
18 nice if they could connect to this instance from a remote ssh session
19 and check their messages without opening a remote X frame or resorting
20 to gnus-slave.
21
22 WHO IS DOING IT
23 ---------------
24
25 I'm Károly Lőrentey. My address: lorentey@elte.hu.
26
27 Comments, bug reports, suggestions and patches are welcome; send them
28 to multi-tty@lists.fnord.hu.
29
30 The following is a (sadly incomplete) list of people who have
31 contributed to the project by testing, submitting patches, bug
32 reports, and suggestions. Thanks!
33
34 ARISAWA Akihiro <ari at mbf dot ocn dot ne dot jp>
35 Vincent Bernat <bernat at luffy dot cx>
36 Han Boetes <han at mijncomputer dot nl>
37 Robert J. Chassell <bob at rattlesnake dot com>
38 Romain Francoise <romain at orebokech dot com>
39 Ami Fischman <ami at fischman dot org>
40 Friedrich Delgado Friedrichs <friedel at nomaden dot org>
41 IRIE Tetsuya <irie at t dot email dot ne dot jp>
42 Yoshiaki Kasahara <kasahara at nc dot kyushu-u dot ac dot jp>
43 Jurej Kubelka <Juraj dot Kubelka at email dot cz>
44 David Lichteblau <david at lichteblau dot com>
45 Xavier Mallard <zedek at gnu-rox dot org>
46 Istvan Marko <mi-mtty at kismala dot com>
47 Ted Morse <morse at ciholas dot com>
48 Dan Nicolaescu <dann at ics dot uci dot edu>
49 Gergely Nagy <algernon at debian dot org>
50 Mark Plaksin <happy at mcplaksin dot org>
51 Francisco Borges <borges at let dot rug dot nl>
52 Frank Ruell <stoerte at dreamwarrior dot net>
53 Dan Waber <dwaber at logolalia dot com>
54 and many others.
55
56 Richard Stallman was kind enough to review an earlier version of my
57 patches.
58
59
60 MAILING LISTS
61 -------------
62
63 The multi-tty mailing list (discussion & bug reports):
64
65 Address: multi-tty@lists.fnord.hu
66 Signup: http://lists.fnord.hu/mailman/listinfo/multi-tty
67 Archive: http://news.gmane.org/gmane.emacs.multi-tty/
68
69 Commit notifications (read-only):
70
71 Address: multi-tty-commits@lists.fnord.hu
72 Signup: http://lists.fnord.hu/mailman/listinfo/multi-tty-commits
73
74
75 STATUS
76 ------
77
78 The branch is now very stable and almost full-featured. All of the
79 major problems have been fixed, only a few minor issues remain. (It
80 still needs to be ported to Windows/Mac/DOS, though.) Both multiple
81 tty device support and simultaneous X and tty frame support works
82 fine. Emacsclient has been extended to support opening new tty and X
83 frames. It has been changed open new Emacs frames by default.
84
85 The multi-tty branch has been scheduled for inclusion in the next
86 major release of Emacs (version 23). I expect the merge into the
87 development trunk to occur sometime during next year (2005), after the
88 merge of the Unicode branch.
89
90 Tested on GNU/Linux, Solaris 8, FreeBSD and OpenBSD. Please let me
91 know if you succeed or fail to use it on other platforms---I'll have a
92 few tricky test cases for you.
93
94 Known problems:
95
96 * GTK support. If you compile your Emacs with the GTK
97 toolkit, some functionality of multi-tty will be lost.
98 Current releases of GTK have limitations and bugs that
99 prevent full-blown multi-display support in Emacs. Use the
100 Lucid toolkit if you want to see a complete feature set.
101
102 * The single-kboard mode.
103
104 If your multi-tty Emacs session seems to be frozen, you
105 probably have a recursive editing session or a pending
106 minibuffer prompt (which is a kind of recursive editing) on
107 another display. To unfreeze your session, switch to that
108 display and complete the recursive edit, for example by
109 pressing C-] (`abort-recursive-edit').
110
111 I am sorry to say that currently there is no way to break
112 out of this "single-kboard mode" from a frozen display. If
113 you are unable to switch to the display that locks the
114 others (for example because it is on a remote computer),
115 then you can use emacsclient to break out of all recursive
116 editing sessions:
117
118 emacsclient -e '(top-level)'
119
120 Note that this (perhaps) unintuitive behaviour is by design.
121 Single-kboard mode is required because of an intrinsic Emacs
122 limitation that is very hard to eliminate. (This limitation
123 is related to the single-threaded nature of Emacs.)
124
125 I plan to implement better user notification and support for
126 breaking out of single-kboard mode from locked displays.
127
128 * Mac, Windows and DOS support is broken, doesn't even
129 compile. Multiple display support will probably not provide
130 new Emacs features on these systems, but the multi-tty
131 branch changed a few low-level interfaces, and the
132 system-dependent source files need to be adapted
133 accordingly. The changes are mostly trivial, so almost
134 anyone can help, if only by compiling the branch and
135 reporting the compiler errors. (It is not worth to do this
136 yet, though.)
137
138
139 HOW TO GET THE BRANCH
140 ---------------------
141
142 The branch uses GNU Arch (http://www.gnuarch.org) for version control.
143
144 Retrieving the latest version of the branch:
145
146 tla register-archive -f http://lorentey.hu/arch/2004/
147 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
148
149 This incantation uses my private archive mirror that is hosted on a
150 relatively low-bandwidth site; if you are outside Hungary, you will
151 probably want to you use my secondary mirror: (Note that the -f option
152 will overwrite the archive location if you have previously registered
153 the Hungarian one.)
154
155 tla register-archive -f http://aszt.inf.elte.hu/~lorentey/mirror/arch/2004
156 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
157
158 http://aszt.inf.elte.hu/~lorentey/mirror/arch/2004
159
160 The Arch supermirror provides mirroring services for all public Arch
161 repositories. We have a mirror there, too, if you prefer.
162
163 tla register-archive -f http://mirrors.sourcecontrol.net/lorentey%40elte.hu--2004
164 tla get lorentey@elte.hu--2004/emacs--multi-tty <directory>
165
166 My GPG key id is 0FB27A3F; it is available from
167 hkp://wwwkeys.eu.pgp.net/, or from my homepage at
168 http://lorentey.hu/rolam/gpg.html)
169
170 Don't worry if the above checkout takes a few minutes to complete;
171 once you have a source tree, updating it to the latest revision will
172 be _much_ faster. Use the following command for the update:
173
174 tla replay
175
176 You can find more information about Arch on http://wiki.gnuarch.org/.
177 It's a wonderful source control system, I highly recommend it.
178
179 If you don't have tla, the branch has a homepage from which you can
180 download conventional patches against Emacs CVS HEAD:
181
182 http://lorentey.hu/project/emacs.html
183
184 DEBIAN PACKAGES
185 ---------------
186
187 If you run Debian, or a distribution based on Debian, you are welcome
188 to use our binary packages; put these lines in your /etc/apt/sources.list:
189
190 # Multi-tty Emacs
191 deb http://aszt.inf.elte.hu/~lorentey/mirror/apt ./
192 deb-src http://aszt.inf.elte.hu/~lorentey/mirror/apt ./
193
194 Note that these packages are intended solely to provide an easy way to
195 test the new multi-tty features. They are not to be taken as Emacs
196 releases, and it's a mistake to expect robust operation or any kind of
197 timely support for them. Do not install them, unless you'd like to
198 have your editor crash on you.
199
200
201 COMPILATION
202 -----------
203
204 The multi-tty branch is compiled the same way as Emacs itself:
205
206 make maintainer-clean # (If you have compiled Emacs before)
207
208 ./configure <your favourite options>
209 make bootstrap
210 make install
211
212 If you have strange compilation errors, they may be caused by old
213 *.elc files that are left over from an earlier bootstrap. The `make
214 maintainer-clean' target deletes them, so it is a good idea to run
215 that before reporting a bug. (Emacs requires a clean recompilation
216 after certain kinds of source code changes.)
217
218 TESTING
219 -------
220
221 To test the multi-tty branch, start up the Emacs server with the
222 following commands:
223
224 emacs
225 M-x server-start
226
227 and then (from a shell prompt on another terminal) start emacsclient
228 with
229 emacsclient -t /optional/file/names... (for a tty frame)
230 emacsclient /optional/file/names... (for an X frame)
231
232 (Make sure both emacs and emacsclient are multi-tty versions.)
233 You'll hopefully have two fully working, independent frames on
234 separate terminals. The new frame is closed automatically when you
235 finish editing the specified files (C-x #), but delete-frame (C-x 5 0)
236 also works. Of course, you can create frames on more than two tty
237 devices.
238
239 Creating new frames on the same tty with C-x 5 2 works, and they
240 behave the same way as in previous Emacs versions. If you exit emacs,
241 all terminals should be restored to their previous states.
242
243 This is work in progress, and probably full of bugs. It is a good
244 idea to run emacs from gdb, so that you'll have a live instance to
245 debug if something goes wrong. Please send me your bug reports on our
246 mailing list: multi-tty@lists.fnord.hu
247
248 TIPS & TRICKS
249 -------------
250
251 I think the best way to use the new Emacs is to have it running inside
252 a disconnected GNU screen session, and always use emacsclient for
253 normal work. One advantage of this is that not a single keystroke of
254 your work will be lost if the display device that you are using
255 crashes, or the network connection times out, or whatever. (I had an
256 extremely unstable X server for some time while I was developing these
257 patches, and running Emacs this way has saved me a number of M-x
258 recover-session invocations.)
259
260 I use the following two bash scripts to handle my Emacs sessions:
261
262 -------------------------------------------------------connect-emacs--
263 #!/bin/bash
264 # Usage: connect-emacs <name> <args>...
265 #
266 # Connects to the Emacs instance called NAME. Starts up the instance
267 # if it is not already running. The rest of the arguments are passed
268 # to emacsclient.
269
270 name="$1"
271 shift
272
273 if [ -z "$name" ]; then
274 echo "Usage: connect_emacs <name> <args>..." >&2
275 exit 1
276 fi
277 preload-emacs "$name" wait
278 /usr/bin/emacsclient.emacs-multi-tty -s "$name" "$@"
279 ----------------------------------------------------------------------
280
281 -------------------------------------------------------preload-emacs--
282 #!/bin/bash
283 # Usage: preload-emacs <name> [<waitp>]
284 #
285 # Preloads the Emacs instance called NAME in a detached screen
286 # session. Does nothing if the instance is already running. If WAITP
287 # is non-empty, the function waits until the server starts up and
288 # creates its socket; otherwise it returns immediately.
289
290 name="$1"
291 waitp="$2"
292 screendir="/var/run/screen/S-$USER"
293 serverdir="/tmp/emacs$UID"
294 emacs=/usr/bin/emacs-multi-tty # Or wherever you installed your multi-tty Emacs
295
296 if [ -z "$name" ]; then
297 echo "Usage: preload_emacs <name> [<waitp>]" >&2
298 exit 1
299 fi
300
301 if [ ! -e "$screendir"/*."$name" ]; then
302 if [ -e "$serverdir/$name" ]; then
303 # Delete leftover socket (for the wait option)
304 rm "$serverdir/$name"
305 fi
306 screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
307 fi
308 if [ ! -z "$waitp" ]; then
309 while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
310 fi
311 ----------------------------------------------------------------------
312
313 I have the following in my profile to have two instances automatically
314 preloaded for editing and email:
315
316 preload-emacs editor
317 preload-emacs gnus
318
319 It is useful to set up short aliases for connect-emacs. I use the
320 following:
321
322 alias edit="connect-emacs editor"
323 alias e=edit
324 alias et="connect-emacs editor -t"
325 alias gnus="connect-emacs gnus"
326
327
328 CHANGELOG
329 ---------
330
331 See arch logs.
332
333
334 NEWS
335 ----
336
337 For the NEWS file: (Needs much, much work)
338
339 ** Support for multiple terminal devices has been added.
340
341 *** You can specify a terminal device (`tty' parameter) and a terminal
342 type (`tty-type' parameter) to `make-terminal-frame'.
343
344 *** You can test for the presence of multiple terminal support by
345 testing for the `multi-tty' feature.
346
347 *** Emacsclient has been extended to support opening a new terminal
348 frame. Its behaviour has been changed to open a new Emacs frame by
349 default. Use the -c option to get the old behavior of opening
350 files in the currently selected Emacs frame.
351
352 *** A make-frame-on-tty function has been added to make it easier to
353 create frames on new terminals.
354
355 *** New functions: frame-tty-name, frame-tty-type, delete-tty,
356 terminal-local-value, set-terminal-local-value
357
358 *** New variables: global-key-translation-map
359
360 *** The keymaps key-translation-map and function-key-map are now
361 terminal-local.
362
363 ** Support for simultaneous graphical and terminal frames has been
364 added.
365
366 *** The function `make-frame-on-display' now works during a terminal
367 session, and `make-frame-on-tty' works during a graphical session.
368
369 *** The `window-system' variable has been made frame-local.
370
371 *** The new `initial-window-system' variable contains the
372 `window-system' value for the first frame.
373
374 *** talk.el has been extended for multiple tty support.
375
376
377 * * *
378
379 (The rest of this file consists of my development notes and as such it
380 is probably not very interesting for anyone else.)
381
382 THINGS TO DO
383 ------------
384
385 ** Having {reset,init}_all_sys_modes in set-input-mode breaks arrow
386 keys on non-selected terminals under screen, and sometimes on other
387 terminal types as well. The other function keys continue to work
388 fine. Sometimes faces on these screens become garbled.
389
390 This only seems to affect displays that are of the same terminfo
391 type as the selected one. Interestingly, in screen Emacs normally
392 reports the up arrow key as `M-o A', but after the above SNAFU, it
393 complains about `M-[ a'. UNIX ttys are a complete mystery to me,
394 but it seems the reset-reinitialize cycle somehow leaves the
395 non-selected terminals in a different state than usual. I have no
396 idea how this could happen.
397
398 Currently set-input-mode resets only the currently selected
399 terminal, which seems to somehow work around the problem.
400
401 ** Fix set-input-mode for multi-tty. It's a truly horrible interface;
402 what if we'd blow it up into several separate functions (with a
403 compatibility definition)?
404
405 ** BULK RENAME: The `display-' prefix of new Lisp-level functions
406 conflicts with stuff like `display-time-mode'. Use `device-'
407 or `terminal-' instead. I think I prefer `terminal-'.
408
409 ** The semantics of terminal-local variables are confusing; it is not
410 clear what binding is in effect in any given time. See if
411 current_kboard (or at least the terminal-local bindings exported to
412 Lisp) might be changed to be tied to the selected frame instead.
413 Currently, `function-key-map' and `key-translation-map' may be
414 accessed reliably only using the hackish
415 `(set-)terminal-local-value' functions.
416
417 Perhaps there should be a difference between `last-command' &co.
418 and these more conventional configuration variables.
419 (E.g. `symbol-value' would use current_kboard to access
420 `last-command', but SELECTED_FRAME()->display->kboard to get the
421 value of `function-key-map'.
422
423 ** The single-keyboard mode of MULTI_KBOARD is extremely confusing
424 sometimes; Emacs does not respond to stimuli from other keyboards.
425 At least a beep or a message would be important, if the single-mode
426 is still required to prevent interference. (Reported by Dan
427 Nicolaescu.)
428
429 Update: selecting a region with the mouse enables single_kboard
430 under X. This is very confusing.
431
432 Update: After discussions with Richard Stallman, this will be
433 resolved by having locked displays warn the user to wait, and
434 introducing a complex protocol to remotely bail out of
435 single-kboard mode by pressing C-g.
436
437 Update: Warning the user is not trivial to implement, as Emacs has
438 only one echo area, shared by all frames. Ideally the warning
439 should not be displayed on the display that is locking the others.
440 Perhaps the high probability of user confusion caused by
441 single_kboard mode deserves a special case in the display code.
442 Alternatively, it might be good enough to signal single_kboard mode
443 by changing the modelines or some other frame-local display element
444 on the locked out displays.
445
446 ** normal-erase-is-backspace-mode in simple.el needs to be updated for
447 multi-tty (rep. by Dan Waber).
448
449 ** Hunt down display-related functions in frame.el and extend them all
450 to accept display ids.
451
452 ** rif->flush_display_optional (NULL) calls should be replaced by a
453 new global function.
454
455 ** The set-locale-environment hack (adding the DISPLAY option) should
456 be replaced with a clean design.
457
458 ** standard-display-table should be display-local.
459 standard-display-european should be display-local.
460
461 ** With iswitchb-default-method set to 'always-frame, only frames on
462 the current display should be considered. This might involve
463 extending `get-buffer-window'.
464
465 ** Have a look at Vlocale_coding_system. Seems like it would be a
466 tedious job to localize it, although most references use it for
467 interfacing with libc and are therefore OK with the global
468 definition.
469
470 Exceptions found so far: x-select-text and
471 x-cut-buffer-or-selection-value.
472
473 ** Have a look at fatal_error_hook.
474
475 ** Have a look at set_frame_matrix_frame.
476
477 ** Check if we got term-setup-hook right.
478
479 ** I think tip_frame should be display-local.
480
481 ** Check display reference count handling in x_create_tip_frame.
482
483 ** make-frame does not correctly handle extra parameters in its
484 argument:
485
486 (frame-parameter (make-frame (list (cons 'foobar 42))) 'foobar)
487 => nil
488
489 (This is likely an error in the CVS trunk.)
490
491 ** Dan Nicolaescu suggests that -nw should be added as an alias for -t
492 in emacsclient. Good idea. (Alas, implementing this is not
493 trivial, getopt_long does not seem to support two-letter ``short''
494 options. Patches are welcome.) :-)
495
496 ** Mark Plaksin suggests that emacsclient should accept the same
497 X-related command-line arguments as Emacs. Most of the X-related
498 argument-handling is done in Lisp, so this should be quite easy to
499 implement.
500
501 ** Gergely Nagy suggests that C-x # should only kill the current
502 frame, not any other emacsclient frame that may have the same file
503 opened for editing. I think I agree with him.
504
505 ** Very strange bug: visible-bell does not work on secondary
506 terminals in xterm and konsole. The screen does flicker a bit,
507 but it's so quick it isn't noticable.
508
509 ** Move baud_rate to struct display.
510
511 ** Implement support for starting an interactive Emacs session without
512 an initial frame. (The user would connect to it and open frames
513 later, with emacsclient.)
514
515 ** Fix Mac support (I can't do this entirely myself). Note that the
516 current state of Mac-specific source files in the multi-tty tree
517 are not useful; before starting work on Mac support, revert to
518 pristine, pre-multi-tty versions.
519
520 ** Fix W32 support (I can't do this entirely myself). Note that the
521 current state of W32-specific source files in the multi-tty tree
522 are not useful; before starting work on W32 support, revert to
523 pristine, pre-multi-tty versions.
524
525 ** Fix DOS support (I can't do this entirely myself). Note that the
526 current state of DOS-specific source files in the multi-tty tree
527 are not useful; before starting work on DOS support, revert to
528 pristine, pre-multi-tty versions.
529
530 ** Do a grep on XXX and ?? for more issues.
531
532 ** Understand Emacs's low-level input system (it's black magic) :-)
533 What exactly does interrupt_input do? I tried to disable it for
534 raw secondary tty support, but it does not seem to do anything
535 useful. (Update: Look again. X unconditionally enables this, maybe
536 that's why raw terminal support is broken again. I really do need
537 to understand input.)
538
539 ** Fix stuff_char for multi-tty. Doesn't seem to be of high priority.
540
541 DIARY OF CHANGES
542 ----------------
543
544 (ex-TODO items with explanations.)
545
546 -- Introduce a new struct for terminal devices.
547
548 (Done, see struct tty_output. The list of members is not yet
549 complete.)
550
551 -- Change the bootstrap procedure to initialize tty_list.
552
553 (Done, but needs review.)
554
555 -- Change make-terminal-frame to support specifying another tty.
556
557 (Done, new frame parameters: `tty' and `tty-type'.)
558
559 -- Implement support for reading from multiple terminals.
560
561 (Done, read_avail_input tries to read from each terminal, until one
562 succeeds. MULTI_KBOARD is not used. Secondary terminals don't send
563 SIGIO!)
564
565 (Update: They do, now.)
566
567 (Update2: After enabling X, they don't.)
568
569 -- other-frame should cycle through the frames on the `current'
570 terminal only.
571
572 (Done, by trivially modifiying next_frame and prev_frame.)
573
574 -- Support different terminal sizes.
575
576 (Done, no problem.)
577
578 -- Make sure terminal resizes are handled gracefully. (Could be
579 problematic.)
580
581 (Done. We don't get automatic SIGWINCH for additional ttys,
582 though.)
583
584 -- Extend emacsclient to automatically open a new tty when it connects
585 to Emacs.
586
587 (Done. It's an ugly hack, needs more work.)
588
589 -- Redisplay must refresh the topmost frame on *all* terminals, not
590 just the initial terminal.
591
592 (Done, but introduced an ugly redisplay problems. Ugh.)
593
594 -- Fix redisplay problems.
595
596 (Done; it turned out that the entire Wcm structure must be moved
597 inside tty_output. Why didn't I catch this earlier?)
598
599 -- Provide a way for emacsclient to tell Emacs that the tty has been
600 resized.
601
602 (Done, simply forward the SIGWINCH signal.)
603
604 -- Each keypress should automatically select the frame corresponding
605 to the terminal that it was coming from. This means that Emacs
606 must know from which terminal the last keyboard event came from.
607
608 (Done, it was quite simple, the input event system already
609 supported multiple frames.)
610
611 -- Fix SIGIO issue with secondary terminals.
612
613 (Done, emacsclient signals Emacs after writing to the proxy pseudo
614 terminal. Note that this means that multi-tty does not work with
615 raw ttys!)
616
617 (Update: This is bullshit. There is a read_input_waiting function,
618 extend that somehow.)
619
620 (Update of update: The first update was not right either, extending
621 read_input_waiting was not necessary. Secondary ttys do seem to
622 send signals on input.)
623
624 (Update^3: Not any more.)
625
626 -- Make make-terminal-frame look up the `tty' and `tty-type' frame
627 parameters from the currently selected terminal before the global
628 default.
629
630 (Done.)
631
632 -- Put all cached terminal escape sequences into struct tty_output.
633 Currently, they are still stored in global variables, so we don't
634 really support multiple terminal types.
635
636 (Done. It was not fun.)
637
638 -- Implement sane error handling after initialization. (Currently
639 emacs exits if you specify a bad terminal type.) The helpful error
640 messages must still be provided when Emacs starts.
641
642 (Done.)
643
644 -- Implement terminal deletion, i.e., deleting local frames, closing
645 the tty device and restoring its previous state without exiting
646 Emacs.
647
648 (Done, but at the moment only called when an error happens during
649 initialization. There is a memory corruption error around this
650 somewhere.) (Update: now it is fully enabled.)
651
652 -- Implement automatic deletion of terminals when the last frame on
653 that terminal is closed.
654
655 (Done.)
656
657 -- Restore tty screen after closing the terminal.
658
659 (Done, we do the same as Emacs 21.2 for all terminals.)
660
661 -- 'TERM=dumb src/emacs' does not restore the terminal state.
662
663 (Done.)
664
665 -- C-g should work on secondary terminals.
666
667 (Done, but the binding is not configurable.)
668
669 -- Deal with SIGHUP in Emacs and in emacsclient. (After this, the
670 server-frames may be removed from server.el.)
671
672 (Done, nothing to do. It seems that Emacs does not receive SIGHUP
673 from secondary ttys, which is actually a good thing.) (Update: I
674 think it would be a bad idea to remove server-frames.)
675
676 -- Change emacsclient/server.el to support the -t argument better,
677 i.e. automatically close the socket when the frame is closed.
678
679 (Seems to be working OK.)
680
681 -- Fix mysterious memory corruption error with tty deletion. To
682 trigger it, try the following shell command:
683
684 while true; do TERM=no-such-terminal-definition emacsclient -h; done
685
686 Emacs usually dumps core after a few dozen iterations. (The bug
687 seems to be related to the xfreeing or bzeroing of
688 tty_output.Wcm. Maybe there are outside references to struct Wcm?
689 Why were these vars collected into a struct before multi-tty
690 support?)
691
692 (Done. Whew. It turned out that the problem had nothing to do
693 with hypothetical external references to Wcm, or any other
694 tty_output component; it was simply that delete_tty closed the
695 filehandles of secondary ttys twice, resulting in fclose doubly
696 freeing memory. Utterly trivial matter. I love the C's memory
697 management, it puts hair on your chest.)
698
699 -- Support raw secondary terminals. (Note that SIGIO works only on
700 the controlling terminal.) Hint: extend read_input_waiting for
701 multiple ttys and hopefully this will be fixed.
702
703 (Done, it seems to have been working already for some time. It
704 seems F_SETOWN does work, after all. Not sure what made it fail
705 earlier, but it seems to be fixed (there were several changes
706 around request_sigio, maybe one of them did it).
707 read_input_waiting is only used in sys_select, don't change
708 it.) (Update: After adding X support, it's broken again.)
709 (Update^2: No it isn't.) :-)
710
711 -- Find out why does Emacs abort when it wants to close its
712 controlling tty. Hint: chan_process[] array. Hey, maybe
713 noninterrupt-IO would work, too? Update: no, there is no process
714 for stdin/out.
715
716 (Done. Added add/delete_keyboard_wait_descriptor to
717 term_init/delete_tty. The hint was right, in a way.)
718
719 -- Issue with SIGIO: it needs to be disabled during redisplay. See if
720 fcntl kernel behaviour could be emulated by emacsclient.
721
722 (Done. Simply disabled the SIGIO emulation hack in emacsclient.)
723 (Update: it was added back.) (Update^2: and removed again.)
724
725 -- server.el: There are issues with saving files in buffers of closed
726 clients. Try editing a file with emacsclient -f, and (without
727 saving it) do a delete-frame. The frame is closed without
728 question, and a surprising confirmation prompt appears in another
729 frame.
730
731 (Done. delete-frame now asks for confirmation if it still has
732 pending buffers, and modified buffers don't seem to be deleted.)
733
734 -- emacsclient.el, server.el: Handle eval or file open errors when
735 doing -t.
736
737 (Done.)
738
739 -- Make parts of struct tty_output accessible from Lisp. The device
740 name and the type is sufficient.
741
742 (Done, see frame-tty-name and frame-tty-type.)
743
744 -- Export delete_tty to the Lisp environment, for emacsclient.
745
746 (Done, see delete-tty.)
747
748 -- Get rid of the accessor macros in termchar.h, or define macros for
749 all members.
750
751 (Done.)
752
753 -- Move device-specific parameters (like costs) commonly used by
754 device backends to a common, device-dependent structure.
755
756 (Done. See struct display_method in termhooks.h.)
757
758 -- Fix X support.
759
760 (Done. Well, it seems to be working.)
761
762 -- Allow simultaneous X and tty frames. (Handling input could be
763 tricky. Or maybe not.)
764
765 (Done. Allowed, that is. It is currently extremely unstable, to
766 the point of being unusable. The rif variable causes constant
767 core dumps. Handling input is indeed tricky.)
768
769 -- Rewrite multi-tty input in terms of MULTI_KBOARD.
770
771 (Done. In fact, there was no need to rewrite anything, I just
772 added a kboard member to tty_display_info, and initialized the
773 frame's kboard from there.)
774
775 -- Fix rif issue with X-tty combo sessions. IMHO the best thing to do
776 is to get rid of that global variable (and use the value value in
777 display_method, which is guaranteed to be correct).
778
779 (Done, did exactly that. Core dumps during combo sessions became
780 much rarer. In fact, I have not yet met a single one.)
781
782 -- Add multi-tty support to talk.el.
783
784 (Done.)
785
786 -- Clean up the source of emacsclient. It is a mess.
787
788 (Done, eliminated stupid proxy-pty kludge.)
789
790 -- Fix faces on tty frames during X-tty combo sessions. There is an
791 init_frame_faces call in init_sys_modes, see if there is a problem
792 with it.
793
794 (Done, there was a stupid mistake in
795 Ftty_supports_face_attributes_p. Colors are broken, though.)
796
797 -- C-x 5 2, C-x 5 o, C-x 5 0 on an emacsclient frame unexpectedly
798 exits emacsclient. This is a result of trying to be clever with
799 delete-frame-functions.
800
801 (Fixed, added delete-tty-after-functions, and changed server.el to
802 use it.)
803
804 -- Something with (maybe) multi-keyboard support broke function keys
805 and arrows on ttys during X+tty combo sessions. Debug this.
806
807 (I can't reproduce it, maybe the terminal type was wrong.)
808
809 -- Fix input from raw ttys (again).
810
811 (Now it seems to work all right.)
812
813 -- During an X-tty combo session, a (message "Hello") from a tty frame
814 goes to the X frame. Fix this.
815
816 (Done. There was a safeguard against writing to the initial
817 terminal frame during bootstrap which prevented echo_area_display
818 from working correctly on a tty frame during a combo session.)
819
820 -- If there are no frames on its controlling terminal, Emacs should
821 exit if the user presses C-c there.
822
823 (Done, as far as possible. See the SIGTERM comment in
824 interrupt_signal on why this seems to be impossible to solve this
825 in general.)
826
827 -- During an X session, Emacs seems to read from stdin. Also, Emacs
828 fails to start without a controlling tty.
829
830 (Fixed by replacing the troublesome termcap display with a dummy
831 bootstrap display during bootstrap.
832
833 -- Do tty output through struct display, like graphical display
834 backends.
835
836 (Done.)
837
838 -- Define an output_initial value for output_method for the initial
839 frame that is dumped with Emacs. Checking for this frame (e.g. in
840 cmd_error_internal) is ugly.
841
842 (Done, broking interactive temacs.)
843
844 -- The command `emacsclient -t -e '(delete-frame)'' fails to exit.
845
846 (Fixed.)
847
848 -- frame-creation-function should always create a frame that is on the
849 same display as the selected frame. Maybe frame-creation-function
850 should simply be removed and make-frame changed to do the right
851 thing.
852
853 (Done, with a nice hack. frame-creation-function is now frame-local.)
854
855 -- Fix C-g on raw ttys.
856
857 (Done. I disabled the interrupt/quit keys on all secondary
858 terminals, so Emacs sees C-g as normal input. This looks like an
859 overkill, because emacsclient has extra code to pass SIGINT to
860 Emacs, so C-g should remain the interrupt/quit key on emacsclient
861 frames. See the next entry why implementing this distinction would
862 be a bad idea.)
863
864 -- Make sure C-g goes to the right frame with ttys. This is hard, as
865 SIGINT doesn't have a tty parameter. :-(
866
867 (Done, the previous change fixes this as a pleasant side effect.)
868
869 -- I have seen a case when Emacs with multiple ttys fell into a loop
870 eating 100% of CPU time. Strace showed this loop:
871
872 getpid() = 30284
873 kill(30284, SIGIO) = 0
874 --- SIGIO (I/O possible) @ 0 (0) ---
875 ioctl(6, FIONREAD, [0]) = -1 EIO (Input/output error)
876 ioctl(5, FIONREAD, [0]) = -1 EIO (Input/output error)
877 ioctl(0, FIONREAD, [0]) = 0
878 sigreturn() = ? (mask now [])
879 gettimeofday({1072842297, 747760}, NULL) = 0
880 gettimeofday({1072842297, 747806}, NULL) = 0
881 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
882 select(9, [0 3 5 6], NULL, NULL, {0, 0}) = 2 (in [5 6], left {0, 0})
883 gettimeofday({1072842297, 748245}, NULL) = 0
884
885 I have seen something similar with a single X frame, but have not
886 been able to reproduce it for debugging.
887
888 Update: This may have been caused by checking for nread != 0
889 instead of nread > 0 after calling read_socket_hook in
890 read_avail_input.
891
892 (Fixed. This was caused by unconditionally including stdin in
893 input_wait_mask in init_process. The select call in
894 wait_reading_process_input always returned immediately, indicating
895 that there is pending input from stdin, which nobody read.
896
897 Note that the above strace output seems to be an unrelated but
898 similar bug. I think that is now fixed.)
899
900 -- Exiting Emacs while there are emacsclient frames doesn't restore the
901 ttys to their default states.
902
903 (This seems to be fixed by some previous change.)
904
905 -- Allow opening an X session after -nw.
906
907 (Done.)
908
909 -- Fix color handling during tty+X combo sessions. (It seems that tty
910 sessions automatically convert the face colors to terminal colors
911 when the face is loaded. This conversion must happen instead on
912 the fly in write_glyphs, which might be problematic, as color
913 approximation is currently done in lisp (term/tty-colors.el).)
914 (Update: hm, colors seem to work fine if I start emacs with -nw and
915 then create an X frame. Maybe it's just a small buglet somewhere.)
916
917 (Seems to be fixed. The problem was in startup.el, it did not
918 initialize tty colors when the initial window system was
919 graphical.)
920
921 -- emacs -nw --eval '(y-or-n-p "Foobar")' segfaults. (Reported by
922 Romain Francoise)
923
924 (Fixed, there was a keyboard initialization problem.)
925
926 -- Fix interactive use of temacs. There are face-related SEGVs, most
927 likely because of changes in realize_default_face, realize_face.
928
929 (Fixed.)
930
931 -- Don't exit Emacs when the last X connection fails during a
932 multi-display session.
933
934 (Fixed.)
935
936 -- Dan Nicolaescu noticed that starting emacsclient on the same
937 terminal device that is the controlling tty of the Emacs process
938 gives unexpected results.
939
940 (Fixed.)
941
942 -- Istvan Marko reported that Emacs hang on ttys if it was started
943 from a shell script.
944
945 (Fixed. There was a bug in the multi-tty version of
946 narrow_foreground_group. tcsetpgrp blocks if it is called from a
947 process that is not in the same process group as the tty.)
948
949 -- emacsclient -t from an Emacs term buffer does not work, complains
950 about face problems. This can even lock up Emacs (if the recursive
951 frame sets single_kboard). Update: the face problems are caused by
952 bugs in term.el, not in multi-tty. The lockup is caused by
953 single_kboard mode, and is not easily resolvable. The best thing to
954 do is to simply refuse to create a tty frame of type `eterm'.
955
956 (Fixed, changed emacsclient to check for TERM=eterm. The face
957 complaints seem to be caused by bugs in term.el; they are not
958 related to multi-tty.)
959
960 -- Find out the best way to support suspending Emacs with multiple
961 ttys. My guess: disable it on the controlling tty, but from other
962 ttys pass it on to emacsclient somehow. (It is (I hope) trivial to
963 extend emacsclient to handle suspend/resume. A `kill -STOP' almost
964 works right now.)
965
966 (Done. I needed to play with signal handling and the server
967 protocol a bit to make emacsclient behave as a normal UNIX program
968 wrt foreground/background process groups.)
969
970 -- There is a flicker during the startup of `emacs -nw'; it's as if
971 the terminal is initialized, reset and then initialialized again.
972 Debug this. (Hint: narrow_foreground_group is called twice during
973 startup.)
974
975 (This is gone.)
976
977 -- Robert Chassell has found serious copy-paste bugs with the
978 multi-tty branch. There seem to be redisplay bugs while copying
979 from X to a terminal frame. Copying accented characters do not
980 work for me.
981
982 (Patch-124 should fix this, by changing the interprogram-*-function
983 variables to be frame-local, as suggested by Mark Plaksin
984 (thanks!). I think that the redisplay bugs are in fact not bugs,
985 but delays caused by single_kboard --> perhaps MULTI_KBOARD should
986 be removed.)
987
988 -- frame-creation-function was removed, which might be a bad idea.
989 Think up a compatible solution.
990
991 (It was an internal interface that may be changed when necessary.)
992
993 -- Change Lisp code not to (getenv "TERM"); use the `tty-type' frame
994 parameter or the frame-tty-type function instead. (M-x tags-search
995 "TERM" helps with this.) Update: Actually, all getenv invocations
996 should be checked for multi-tty compatibility, and an interface
997 must be implemented to get the remote client's environment.
998
999 (Done. Only getenv calls in lisp/term/*.el were changed; other
1000 calls should be mostly left as they are.)
1001
1002 -- Add an elaborate mechanism for display-local variables. (There are
1003 already a few of these; search for `terminal-local' in the Elisp
1004 manual.)
1005
1006 (Not needed. Display-local variables could be emulated by
1007 frame-local variables.)
1008
1009 -- Emacs assumes that all terminal frames have the same locale
1010 settings as Emacs itself. This may lead to bogus results in a
1011 multi-locale setup. (E.g., while logging in from a remote client
1012 with a different locale.)
1013 (Update after new bugreport by Friedrich Delgado Friedrichs:
1014 (at least) the structs terminal_coding and keyboard_coding in
1015 coding.c must be moved to struct display, and the Lisp interface
1016 [set-]keyboard-coding-system must be adapted for the change.)
1017
1018 (Fixed. Emacs now uses the locale settings as seen by the
1019 emacsclient process for server tty frames.)
1020 (Update: Not really; Vlocale_coding_system is still global.)
1021
1022 -- Make `struct display' accessible to Lisp programs. Accessor functions:
1023
1024 (displayp OBJECT): Returns t if OBJECT is a display.
1025 => Implemented as display-live-p.
1026
1027 (display-list): Returns list of currently active displays.
1028 => Implemented.
1029
1030 (selected-display): Returns the display object of the selected frame.
1031 => Not strictly necessary, but implemented anyway.
1032
1033 (frame-display FRAME): Returns the display object of FRAME.
1034 => Implemented.
1035
1036 (display-frames DISPLAY): Returns a list of frames on DISPLAY.
1037 => Already implemented, see frames-on-display-list.
1038
1039 (display-type DISPLAY): Returns the type of DISPLAY, as a
1040 symbol. (See `framep'.)
1041 => Implemented as display-live-p.
1042
1043 (display-device DISPLAY): Returns the name of the device that
1044 DISPLAY uses, as a string. (E.g: "/dev/pts/16", or
1045 ":0.0")
1046 => Implemented as display-name.
1047
1048 etc.
1049
1050 See next issue why this is necessary.
1051
1052 (Update: The consensus on emacs-devel seems to be to do this via
1053 integer identifiers. That's fine by me.)
1054
1055 (Done.)
1056
1057 -- The following needs to be supported:
1058
1059 $ emacsclient -t
1060 C-z
1061 $ emacsclient -t
1062 (This fails now.)
1063
1064 The cleanest way to solve this is to allow multiple displays on the
1065 same terminal device; each new emacsclient process should create
1066 its own display. As displays are currently identified by their
1067 device names, this is not possible until struct display becomes
1068 accessible as a Lisp-level object.
1069
1070 (Done.)
1071
1072 -- Miles Bader suggests that C-x C-c on an emacsclient frame should
1073 only close the frame, not exit the entire Emacs session. Update:
1074 see above for a function that does this. Maybe this should be the
1075 new default?
1076
1077 (Done. This is the new default. No complaints so far.)
1078
1079 -- Clean up the frame-local variable system. I think it's ugly and
1080 error-prone. But maybe I just haven't yet fully understood it.
1081
1082 (Nothing to do. It doesn't seem ugly any more. It's rather clever.)
1083
1084 -- Support multiple character locales. A version of
1085 `set-locale-environment' needs to be written for setting up
1086 display-local settings on ttys. I think calling
1087 set-display-table-and-terminal-coding-system and
1088 set-keyboard-coding-system would be enough. The language
1089 environment itself should remain a global setting.
1090
1091 (Done, by an ugly hack.)
1092
1093 -- The terminal customization files in term/*.el tend to change global
1094 parameters, which may confuse Emacs with multiple displays. Change
1095 them to tweak only frame-local settings, if possible. (They tend
1096 to call define-key to set function key sequences a lot.)
1097
1098 (Done, by making `function-key-map' terminal-local (i.e., part of
1099 struct kboard). This has probably covered all the remaining problems.)
1100
1101 -- Make `function-key-map' and `key-translation-map' terminal-local.
1102
1103 (Done.)
1104
1105 -- Implement `terminal-local-value' and `set-terminal-local-value' to
1106 allow deterministic access to terminal local bindings. The
1107 encode-kb package can not set up `key-translation-map' without
1108 these. The terminal-local bindings seem to be independent of what
1109 frame is selected.
1110
1111 (Done.)
1112
1113 ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
1114