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