aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.arch-inventory3
-rw-r--r--src/.gdbinit4
-rw-r--r--src/Makefile.in57
-rw-r--r--src/alloc.c8
-rw-r--r--src/buffer.c48
-rw-r--r--src/callint.c7
-rw-r--r--src/callproc.c221
-rw-r--r--src/cm.c216
-rw-r--r--src/cm.h118
-rw-r--r--src/coding.c62
-rw-r--r--src/coding.h10
-rw-r--r--src/config.in6
-rw-r--r--src/data.c67
-rw-r--r--src/dispextern.h92
-rw-r--r--src/dispnew.c389
-rw-r--r--src/emacs.c45
-rw-r--r--src/eval.c10
-rw-r--r--src/fileio.c6
-rw-r--r--src/fns.c7
-rw-r--r--src/fontset.c3
-rw-r--r--src/frame.c549
-rw-r--r--src/frame.h110
-rw-r--r--src/fringe.c8
-rw-r--r--src/gtkutil.c4
-rw-r--r--src/image.c4
-rw-r--r--src/indent.c2
-rw-r--r--src/intervals.h2
-rw-r--r--src/keyboard.c1048
-rw-r--r--src/keyboard.h39
-rw-r--r--src/keymap.c56
-rw-r--r--src/keymap.h1
-rw-r--r--src/lisp.h35
-rw-r--r--src/lread.c12
-rw-r--r--src/macfns.c8
-rw-r--r--src/macterm.c15
-rw-r--r--src/macterm.h3
-rw-r--r--src/minibuf.c12
-rw-r--r--src/msdos.c16
-rw-r--r--src/prefix-args.c1
-rw-r--r--src/print.c4
-rw-r--r--src/process.c26
-rw-r--r--src/puresize.h2
-rw-r--r--src/scroll.c52
-rw-r--r--src/sysdep.c712
-rw-r--r--src/syssignal.h1
-rw-r--r--src/term.c2449
-rw-r--r--src/termchar.h203
-rw-r--r--src/termhooks.h489
-rw-r--r--src/terminal.c628
-rw-r--r--src/termopts.h5
-rw-r--r--src/w32term.c17
-rw-r--r--src/w32term.h2
-rw-r--r--src/widget.c4
-rw-r--r--src/window.c4
-rw-r--r--src/window.h2
-rw-r--r--src/xdisp.c336
-rw-r--r--src/xfaces.c45
-rw-r--r--src/xfns.c384
-rw-r--r--src/xmenu.c60
-rw-r--r--src/xselect.c54
-rw-r--r--src/xsmfns.c9
-rw-r--r--src/xterm.c537
-rw-r--r--src/xterm.h11
63 files changed, 6061 insertions, 3279 deletions
diff --git a/src/.arch-inventory b/src/.arch-inventory
index fe99529135f..c21e38d47d7 100644
--- a/src/.arch-inventory
+++ b/src/.arch-inventory
@@ -3,7 +3,10 @@ source ^\.(gdbinit|dbxinit)$
3 3
4# Auto-generated files, which ignore 4# Auto-generated files, which ignore
5precious ^(config\.stamp|config\.h|epaths\.h|buildobj\.lst)$ 5precious ^(config\.stamp|config\.h|epaths\.h|buildobj\.lst)$
6precious ^(TAGS-LISP)$
7precious ^(buildobj\.lst)$
6 8
7backup ^(stamp-oldxmenu|prefix-args|temacs|emacs|emacs-[0-9.]*)$ 9backup ^(stamp-oldxmenu|prefix-args|temacs|emacs|emacs-[0-9.]*)$
10backup ^(bootstrap-emacs)$
8 11
9# arch-tag: 277cc7ae-b3f5-44af-abf1-84c073164543 12# arch-tag: 277cc7ae-b3f5-44af-abf1-84c073164543
diff --git a/src/.gdbinit b/src/.gdbinit
index 5a940e667dc..d3438a81e6a 100644
--- a/src/.gdbinit
+++ b/src/.gdbinit
@@ -1087,7 +1087,7 @@ set print sevenbit-strings
1087 1087
1088show environment DISPLAY 1088show environment DISPLAY
1089show environment TERM 1089show environment TERM
1090set args -geometry 80x40+0+0 1090#set args -geometry 80x40+0+0
1091 1091
1092# People get bothered when they see messages about non-existent functions... 1092# People get bothered when they see messages about non-existent functions...
1093xgetptr Vsystem_type 1093xgetptr Vsystem_type
@@ -1115,7 +1115,7 @@ end
1115tbreak init_sys_modes 1115tbreak init_sys_modes
1116commands 1116commands
1117 silent 1117 silent
1118 xgetptr Vwindow_system 1118 xgetptr Vinitial_window_system
1119 set $tem = (struct Lisp_Symbol *) $ptr 1119 set $tem = (struct Lisp_Symbol *) $ptr
1120 xgetptr $tem->xname 1120 xgetptr $tem->xname
1121 set $tem = (struct Lisp_String *) $ptr 1121 set $tem = (struct Lisp_String *) $ptr
diff --git a/src/Makefile.in b/src/Makefile.in
index 1ce3702336f..31fc7b5c23e 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -583,7 +583,7 @@ emacsappsrc = ${srcdir}/../mac/Emacs.app/
583 whose initialized data areas should be dumped as pure by dump-emacs. */ 583 whose initialized data areas should be dumped as pure by dump-emacs. */
584obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \ 584obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \
585 charset.o coding.o category.o ccl.o \ 585 charset.o coding.o category.o ccl.o \
586 cm.o term.o xfaces.o $(XOBJ) $(GTK_OBJ)\ 586 cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ)\
587 emacs.o keyboard.o macros.o keymap.o sysdep.o \ 587 emacs.o keyboard.o macros.o keymap.o sysdep.o \
588 buffer.o filelock.o insdel.o marker.o \ 588 buffer.o filelock.o insdel.o marker.o \
589 minibuf.o fileio.o dired.o filemode.o \ 589 minibuf.o fileio.o dired.o filemode.o \
@@ -725,6 +725,7 @@ otherobj= $(termcapobj) lastfile.o $(mallocobj) $(allocaobj) $(widgetobj) $(LIBO
725lisp= \ 725lisp= \
726 ${lispsource}abbrev.elc \ 726 ${lispsource}abbrev.elc \
727 ${lispsource}buff-menu.elc \ 727 ${lispsource}buff-menu.elc \
728 ${lispsource}server.elc \
728 ${lispsource}button.elc \ 729 ${lispsource}button.elc \
729 ${lispsource}emacs-lisp/byte-run.elc \ 730 ${lispsource}emacs-lisp/byte-run.elc \
730 ${lispsource}cus-face.elc \ 731 ${lispsource}cus-face.elc \
@@ -741,6 +742,7 @@ lisp= \
741 MOUSE_SUPPORT \ 742 MOUSE_SUPPORT \
742 ${lispsource}emacs-lisp/float-sup.elc \ 743 ${lispsource}emacs-lisp/float-sup.elc \
743 ${lispsource}frame.elc \ 744 ${lispsource}frame.elc \
745 ${lispsource}termdev.elc \
744 ${lispsource}help.elc \ 746 ${lispsource}help.elc \
745 ${lispsource}indent.elc \ 747 ${lispsource}indent.elc \
746 ${lispsource}isearch.elc \ 748 ${lispsource}isearch.elc \
@@ -824,6 +826,7 @@ lisp= \
824shortlisp= \ 826shortlisp= \
825 ../lisp/abbrev.elc \ 827 ../lisp/abbrev.elc \
826 ../lisp/buff-menu.elc \ 828 ../lisp/buff-menu.elc \
829 ../lisp/server.elc \
827 ../lisp/button.elc \ 830 ../lisp/button.elc \
828 ../lisp/emacs-lisp/byte-run.elc \ 831 ../lisp/emacs-lisp/byte-run.elc \
829 ../lisp/cus-face.elc \ 832 ../lisp/cus-face.elc \
@@ -838,6 +841,7 @@ shortlisp= \
838 ../lisp/emacs-lisp/float-sup.elc \ 841 ../lisp/emacs-lisp/float-sup.elc \
839 ../lisp/format.elc \ 842 ../lisp/format.elc \
840 ../lisp/frame.elc \ 843 ../lisp/frame.elc \
844 ../lisp/termdev.elc \
841 ../lisp/help.elc \ 845 ../lisp/help.elc \
842 ../lisp/indent.elc \ 846 ../lisp/indent.elc \
843 ../lisp/isearch.elc \ 847 ../lisp/isearch.elc \
@@ -927,7 +931,9 @@ SOME_MACHINE_LISP = ${dotdot}/lisp/mouse.elc \
927 ${dotdot}/lisp/x-dnd.elc \ 931 ${dotdot}/lisp/x-dnd.elc \
928 ${dotdot}/lisp/international/ccl.elc \ 932 ${dotdot}/lisp/international/ccl.elc \
929 ${dotdot}/lisp/international/codepage.elc \ 933 ${dotdot}/lisp/international/codepage.elc \
930 ${dotdot}/lisp/international/fontset.elc 934 ${dotdot}/lisp/international/fontset.elc \
935 ${dotdot}/lisp/mouse.elc \
936 ${dotdot}/lisp/term/x-win.elc
931 937
932/* Construct full set of libraries to be linked. 938/* Construct full set of libraries to be linked.
933 Note that SunOS needs -lm to come before -lc; otherwise, you get 939 Note that SunOS needs -lm to come before -lc; otherwise, you get
@@ -973,7 +979,7 @@ emacs${EXEEXT}: temacs${EXEEXT} ${etc}DOC ${lisp}
973 for the first time, this prevents any variation between configurations 979 for the first time, this prevents any variation between configurations
974 in the contents of the DOC file. 980 in the contents of the DOC file.
975 Likewise for ${SOME_MACHINE_LISP}. */ 981 Likewise for ${SOME_MACHINE_LISP}. */
976${etc}DOC: ${libsrc}make-docfile${EXEEXT} ${obj} ${shortlisp} ${SOME_MACHINE_LISP} 982${etc}DOC: ${libsrc}make-docfile ${obj} ${shortlisp} ${SOME_MACHINE_LISP}
977 -rm -f ${etc}DOC 983 -rm -f ${etc}DOC
978 ${libsrc}make-docfile -d ${srcdir} ${SOME_MACHINE_OBJECTS} ${obj} > ${etc}DOC 984 ${libsrc}make-docfile -d ${srcdir} ${SOME_MACHINE_OBJECTS} ${obj} > ${etc}DOC
979 ${libsrc}make-docfile -a ${etc}DOC -d ${srcdir} ${SOME_MACHINE_LISP} ${shortlisp} 985 ${libsrc}make-docfile -a ${etc}DOC -d ${srcdir} ${SOME_MACHINE_LISP} ${shortlisp}
@@ -1096,7 +1102,7 @@ callint.o: callint.c window.h commands.h buffer.h keymap.h \
1096 keyboard.h dispextern.h $(config_h) 1102 keyboard.h dispextern.h $(config_h)
1097callproc.o: callproc.c epaths.h buffer.h commands.h $(config_h) \ 1103callproc.o: callproc.c epaths.h buffer.h commands.h $(config_h) \
1098 process.h systty.h syssignal.h charset.h coding.h ccl.h msdos.h \ 1104 process.h systty.h syssignal.h charset.h coding.h ccl.h msdos.h \
1099 composite.h w32.h blockinput.h atimer.h systime.h 1105 composite.h w32.h blockinput.h atimer.h systime.h frame.h termhooks.h
1100casefiddle.o: casefiddle.c syntax.h commands.h buffer.h composite.h \ 1106casefiddle.o: casefiddle.c syntax.h commands.h buffer.h composite.h \
1101 charset.h keymap.h $(config_h) 1107 charset.h keymap.h $(config_h)
1102casetab.o: casetab.c buffer.h $(config_h) 1108casetab.o: casetab.c buffer.h $(config_h)
@@ -1105,8 +1111,8 @@ ccl.o: ccl.c ccl.h charset.h coding.h $(config_h)
1105charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \ 1111charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \
1106 $(config_h) 1112 $(config_h)
1107coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h \ 1113coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h \
1108 window.h dispextern.h $(config_h) 1114 window.h dispextern.h frame.h termhooks.h $(config_h)
1109cm.o: cm.c cm.h termhooks.h $(config_h) 1115cm.o: cm.c frame.h cm.h termhooks.h termchar.h $(config_h)
1110cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \ 1116cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
1111 msdos.h dispextern.h keyboard.h keymap.h 1117 msdos.h dispextern.h keyboard.h keymap.h
1112pre-crt0.o: pre-crt0.c 1118pre-crt0.o: pre-crt0.c
@@ -1114,7 +1120,7 @@ ecrt0.o: ecrt0.c $(config_h)
1114 CRT0_COMPILE ${srcdir}/ecrt0.c 1120 CRT0_COMPILE ${srcdir}/ecrt0.c
1115dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \ 1121dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \
1116 systime.h blockinput.h atimer.h 1122 systime.h blockinput.h atimer.h
1117dispnew.o: dispnew.c systty.h systime.h commands.h process.h frame.h \ 1123dispnew.o: dispnew.c systime.h commands.h process.h frame.h \
1118 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \ 1124 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \
1119 disptab.h indent.h intervals.h \ 1125 disptab.h indent.h intervals.h \
1120 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \ 1126 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \
@@ -1135,10 +1141,10 @@ filelock.o: filelock.c buffer.h charset.h coding.h systime.h epaths.h $(config_h
1135filemode.o: filemode.c $(config_h) 1141filemode.o: filemode.c $(config_h)
1136frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \ 1142frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \
1137 blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \ 1143 blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \
1138 msdos.h dosfns.h dispextern.h w32term.h macterm.h $(config_h) 1144 msdos.h dosfns.h dispextern.h w32term.h macterm.h termchar.h $(config_h)
1139fringe.o: fringe.c dispextern.h frame.h window.h buffer.h $(config_h) 1145fringe.o: fringe.c dispextern.h frame.h window.h buffer.h termhooks.h $(config_h)
1140fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \ 1146fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \
1141 keyboard.h $(config_h) 1147 keyboard.h termhooks.h $(config_h)
1142getloadavg.o: getloadavg.c $(config_h) 1148getloadavg.o: getloadavg.c $(config_h)
1143image.o: image.c frame.h window.h dispextern.h blockinput.h atimer.h \ 1149image.o: image.c frame.h window.h dispextern.h blockinput.h atimer.h \
1144 systime.h xterm.h w32term.h w32gui.h macterm.h macgui.h $(config_h) 1150 systime.h xterm.h w32term.h w32gui.h macterm.h macgui.h $(config_h)
@@ -1149,7 +1155,7 @@ insdel.o: insdel.c window.h buffer.h $(INTERVAL_SRC) blockinput.h charset.h \
1149 dispextern.h atimer.h systime.h region-cache.h $(config_h) 1155 dispextern.h atimer.h systime.h region-cache.h $(config_h)
1150keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \ 1156keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \
1151 commands.h frame.h window.h macros.h disptab.h keyboard.h syssignal.h \ 1157 commands.h frame.h window.h macros.h disptab.h keyboard.h syssignal.h \
1152 systty.h systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \ 1158 systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \
1153 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h) 1159 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h)
1154keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \ 1160keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \
1155 atimer.h systime.h puresize.h charset.h intervals.h keymap.h window.h \ 1161 atimer.h systime.h puresize.h charset.h intervals.h keymap.h window.h \
@@ -1164,7 +1170,8 @@ vm-limit.o: vm-limit.c mem-limits.h $(config_h)
1164marker.o: marker.c buffer.h charset.h $(config_h) 1170marker.o: marker.c buffer.h charset.h $(config_h)
1165md5.o: md5.c md5.h $(config_h) 1171md5.o: md5.c md5.h $(config_h)
1166minibuf.o: minibuf.c syntax.h dispextern.h frame.h window.h keyboard.h \ 1172minibuf.o: minibuf.c syntax.h dispextern.h frame.h window.h keyboard.h \
1167 buffer.h commands.h charset.h msdos.h $(INTERVAL_SRC) keymap.h $(config_h) 1173 buffer.h commands.h charset.h msdos.h $(INTERVAL_SRC) keymap.h \
1174 termhooks.h $(config_h)
1168mktime.o: mktime.c $(config_h) 1175mktime.o: mktime.c $(config_h)
1169msdos.o: msdos.c msdos.h dosfns.h systime.h termhooks.h dispextern.h frame.h \ 1176msdos.o: msdos.c msdos.h dosfns.h systime.h termhooks.h dispextern.h frame.h \
1170 termopts.h termchar.h charset.h coding.h ccl.h disptab.h window.h \ 1177 termopts.h termchar.h charset.h coding.h ccl.h disptab.h window.h \
@@ -1176,7 +1183,7 @@ process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \
1176regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h 1183regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h
1177region-cache.o: region-cache.c buffer.h region-cache.h $(config_h) 1184region-cache.o: region-cache.c buffer.h region-cache.h $(config_h)
1178scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ 1185scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \
1179 $(config_h) 1186 termhooks.h $(config_h)
1180search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \ 1187search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \
1181 blockinput.h atimer.h systime.h category.h charset.h composite.h \ 1188 blockinput.h atimer.h systime.h category.h charset.h composite.h \
1182 $(INTERVAL_SRC) $(config_h) 1189 $(INTERVAL_SRC) $(config_h)
@@ -1185,11 +1192,13 @@ syntax.o: syntax.c syntax.h buffer.h commands.h category.h charset.h \
1185 composite.h keymap.h regex.h $(INTERVAL_SRC) $(config_h) 1192 composite.h keymap.h regex.h $(INTERVAL_SRC) $(config_h)
1186sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ 1193sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \
1187 process.h dispextern.h termhooks.h termchar.h termopts.h \ 1194 process.h dispextern.h termhooks.h termchar.h termopts.h \
1188 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h $(config_h) 1195 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h cm.h $(config_h)
1189term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \ 1196term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \
1190 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h \ 1197 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h \
1191 window.h keymap.h blockinput.h atimer.h systime.h 1198 window.h keymap.h blockinput.h atimer.h systime.h
1192termcap.o: termcap.c $(config_h) 1199termcap.o: termcap.c $(config_h)
1200terminal.o: terminal.c frame.h termchar.h termhooks.h charset.h coding.h \
1201 keyboard.h $(config_h)
1193terminfo.o: terminfo.c $(config_h) 1202terminfo.o: terminfo.c $(config_h)
1194tparam.o: tparam.c $(config_h) 1203tparam.o: tparam.c $(config_h)
1195undo.o: undo.c buffer.h commands.h window.h $(config_h) 1204undo.o: undo.c buffer.h commands.h window.h $(config_h)
@@ -1202,7 +1211,7 @@ w16select.o: w16select.c dispextern.h frame.h blockinput.h atimer.h systime.h \
1202widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \ 1211widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \
1203 $(srcdir)/../lwlib/lwlib.h $(config_h) 1212 $(srcdir)/../lwlib/lwlib.h $(config_h)
1204window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \ 1213window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \
1205 termhooks.h disptab.h keyboard.h dispextern.h msdos.h composite.h \ 1214 disptab.h keyboard.h dispextern.h msdos.h composite.h \
1206 keymap.h blockinput.h atimer.h systime.h $(INTERVAL_SRC) \ 1215 keymap.h blockinput.h atimer.h systime.h $(INTERVAL_SRC) \
1207 xterm.h w32term.h macterm.h $(config_h) 1216 xterm.h w32term.h macterm.h $(config_h)
1208xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \ 1217xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \
@@ -1211,10 +1220,11 @@ xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h co
1211 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h 1220 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h
1212xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \ 1221xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \
1213 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \ 1222 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \
1214 keyboard.h fontset.h w32term.h macterm.h $(INTERVAL_SRC) $(config_h) 1223 keyboard.h fontset.h w32term.h macterm.h $(INTERVAL_SRC) termchar.h \
1224 termhooks.h $(config_h)
1215xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \ 1225xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \
1216 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \ 1226 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \
1217 charset.h gtkutil.h $(config_h) 1227 charset.h gtkutil.h termchar.h termhooks.h $(config_h)
1218xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \ 1228xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \
1219 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \ 1229 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \
1220 gtkutil.h msdos.h coding.h $(config_h) 1230 gtkutil.h msdos.h coding.h $(config_h)
@@ -1223,7 +1233,7 @@ xterm.o: xterm.c xterm.h termhooks.h termopts.h termchar.h window.h buffer.h \
1223 keyboard.h gnu.h charset.h ccl.h fontset.h composite.h \ 1233 keyboard.h gnu.h charset.h ccl.h fontset.h composite.h \
1224 coding.h process.h gtkutil.h $(config_h) 1234 coding.h process.h gtkutil.h $(config_h)
1225xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \ 1235xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \
1226 buffer.h atimer.h systime.h $(config_h) 1236 buffer.h atimer.h systime.h termhooks.h $(config_h)
1227xrdb.o: xrdb.c $(config_h) epaths.h 1237xrdb.o: xrdb.c $(config_h) epaths.h
1228xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \ 1238xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \
1229 lisp.h termopts.h 1239 lisp.h termopts.h
@@ -1241,19 +1251,18 @@ alloc.o: alloc.c process.h frame.h window.h buffer.h puresize.h syssignal.h key
1241 blockinput.h atimer.h systime.h charset.h dispextern.h $(config_h) $(INTERVAL_SRC) 1251 blockinput.h atimer.h systime.h charset.h dispextern.h $(config_h) $(INTERVAL_SRC)
1242bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h dispextern.h \ 1252bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h dispextern.h \
1243 frame.h xterm.h $(config_h) 1253 frame.h xterm.h $(config_h)
1244data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h frame.h $(config_h) 1254data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h frame.h termhooks.h $(config_h)
1245eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \ 1255eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \
1246 dispextern.h $(config_h) 1256 dispextern.h $(config_h)
1247floatfns.o: floatfns.c $(config_h) 1257floatfns.o: floatfns.c $(config_h)
1248fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \ 1258fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \
1249 keymap.h frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h \ 1259 keymap.h frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h \
1250 blockinput.h atimer.h systime.h xterm.h 1260 blockinput.h atimer.h systime.h xterm.h termhooks.h
1251print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \ 1261print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \
1252 $(config_h) dispextern.h termchar.h $(INTERVAL_SRC) msdos.h composite.h \ 1262 $(config_h) dispextern.h termchar.h $(INTERVAL_SRC) msdos.h composite.h \
1253 blockinput.h atimer.h systime.h 1263 blockinput.h atimer.h systime.h
1254lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h \ 1264lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h \
1255 $(config_h) $(INTERVAL_SRC) termhooks.h coding.h msdos.h blockinput.h \ 1265 $(config_h) $(INTERVAL_SRC) termhooks.h coding.h msdos.h
1256 atimer.h systime.h
1257 1266
1258/* Text properties support */ 1267/* Text properties support */
1259textprop.o: textprop.c buffer.h window.h dispextern.h $(INTERVAL_SRC) \ 1268textprop.o: textprop.c buffer.h window.h dispextern.h $(INTERVAL_SRC) \
@@ -1266,12 +1275,12 @@ composite.o: composite.c buffer.h charset.h $(INTERVAL_SRC) $(config_h)
1266 OTHER_FILES and OBJECTS_MACHINE 1275 OTHER_FILES and OBJECTS_MACHINE
1267 select which of these should be compiled. */ 1276 select which of these should be compiled. */
1268 1277
1269sunfns.o: sunfns.c buffer.h window.h dispextern.h $(config_h) 1278sunfns.o: sunfns.c buffer.h window.h dispextern.h termhooks.h $(config_h)
1270 1279
1271#ifdef HAVE_CARBON 1280#ifdef HAVE_CARBON
1272abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \ 1281abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
1273 fontset.o indent.o insdel.o keyboard.o macros.o minibuf.o msdos.o process.o \ 1282 fontset.o indent.o insdel.o keyboard.o macros.o minibuf.o msdos.o process.o \
1274 scroll.o sysdep.o term.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \ 1283 scroll.o sysdep.o term.o terminal.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \
1275 xterm.o xselect.o sound.o: macgui.h 1284 xterm.o xselect.o sound.o: macgui.h
1276mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \ 1285mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \
1277 coding.h ccl.h $(config_h) 1286 coding.h ccl.h $(config_h)
diff --git a/src/alloc.c b/src/alloc.c
index 68b490f98b5..574196059f8 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -341,7 +341,9 @@ Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */
341EMACS_INT gcs_done; /* accumulated GCs */ 341EMACS_INT gcs_done; /* accumulated GCs */
342 342
343static void mark_buffer P_ ((Lisp_Object)); 343static void mark_buffer P_ ((Lisp_Object));
344extern void mark_terminals P_ ((void));
344extern void mark_kboards P_ ((void)); 345extern void mark_kboards P_ ((void));
346extern void mark_ttys P_ ((void));
345extern void mark_backtrace P_ ((void)); 347extern void mark_backtrace P_ ((void));
346static void gc_sweep P_ ((void)); 348static void gc_sweep P_ ((void));
347static void mark_glyph_matrix P_ ((struct glyph_matrix *)); 349static void mark_glyph_matrix P_ ((struct glyph_matrix *));
@@ -1236,7 +1238,8 @@ emacs_blocked_malloc (size, ptr)
1236 BLOCK_INPUT_ALLOC; 1238 BLOCK_INPUT_ALLOC;
1237 __malloc_hook = old_malloc_hook; 1239 __malloc_hook = old_malloc_hook;
1238#ifdef DOUG_LEA_MALLOC 1240#ifdef DOUG_LEA_MALLOC
1239 mallopt (M_TOP_PAD, malloc_hysteresis * 4096); 1241 /* Segfaults on my system. --lorentey */
1242 /* mallopt (M_TOP_PAD, malloc_hysteresis * 4096); */
1240#else 1243#else
1241 __malloc_extra_blocks = malloc_hysteresis; 1244 __malloc_extra_blocks = malloc_hysteresis;
1242#endif 1245#endif
@@ -5160,7 +5163,9 @@ returns nil, because real GC can't be done. */)
5160 mark_object (bind->symbol); 5163 mark_object (bind->symbol);
5161 mark_object (bind->old_value); 5164 mark_object (bind->old_value);
5162 } 5165 }
5166 mark_terminals ();
5163 mark_kboards (); 5167 mark_kboards ();
5168 mark_ttys ();
5164 5169
5165#ifdef USE_GTK 5170#ifdef USE_GTK
5166 { 5171 {
@@ -5595,6 +5600,7 @@ mark_object (arg)
5595 mark_object (ptr->menu_bar_vector); 5600 mark_object (ptr->menu_bar_vector);
5596 mark_object (ptr->buffer_predicate); 5601 mark_object (ptr->buffer_predicate);
5597 mark_object (ptr->buffer_list); 5602 mark_object (ptr->buffer_list);
5603 mark_object (ptr->buried_buffer_list);
5598 mark_object (ptr->menu_bar_window); 5604 mark_object (ptr->menu_bar_window);
5599 mark_object (ptr->tool_bar_window); 5605 mark_object (ptr->tool_bar_window);
5600 mark_face_cache (ptr->face_cache); 5606 mark_face_cache (ptr->face_cache);
diff --git a/src/buffer.c b/src/buffer.c
index ba23cc6ae33..15cb9f29356 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -215,25 +215,38 @@ frame parameter come first, followed by the rest of the buffers. */)
215 (frame) 215 (frame)
216 Lisp_Object frame; 216 Lisp_Object frame;
217{ 217{
218 Lisp_Object framelist, general; 218 Lisp_Object general;
219 general = Fmapcar (Qcdr, Vbuffer_alist); 219 general = Fmapcar (Qcdr, Vbuffer_alist);
220 220
221 if (FRAMEP (frame)) 221 if (FRAMEP (frame))
222 { 222 {
223 Lisp_Object tail; 223 Lisp_Object framelist, prevlist, tail;
224 Lisp_Object args[3];
224 225
225 CHECK_FRAME (frame); 226 CHECK_FRAME (frame);
226 227
227 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); 228 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list);
229 prevlist = Fnreverse (Fcopy_sequence (XFRAME (frame)->buried_buffer_list));
228 230
229 /* Remove from GENERAL any buffer that duplicates one in FRAMELIST. */ 231 /* Remove from GENERAL any buffer that duplicates one in
232 FRAMELIST or PREVLIST. */
230 tail = framelist; 233 tail = framelist;
231 while (! NILP (tail)) 234 while (CONSP (tail))
232 { 235 {
233 general = Fdelq (XCAR (tail), general); 236 general = Fdelq (XCAR (tail), general);
234 tail = XCDR (tail); 237 tail = XCDR (tail);
235 } 238 }
236 return nconc2 (framelist, general); 239 tail = prevlist;
240 while (CONSP (tail))
241 {
242 general = Fdelq (XCAR (tail), general);
243 tail = XCDR (tail);
244 }
245
246 args[0] = framelist;
247 args[1] = general;
248 args[2] = prevlist;
249 return Fnconc (3, args);
237 } 250 }
238 251
239 return general; 252 return general;
@@ -1583,6 +1596,23 @@ record_buffer (buf)
1583 XSETCDR (link, Vbuffer_alist); 1596 XSETCDR (link, Vbuffer_alist);
1584 Vbuffer_alist = link; 1597 Vbuffer_alist = link;
1585 1598
1599 /* Effectively do a delq on buried_buffer_list. */
1600
1601 prev = Qnil;
1602 for (link = XFRAME (frame)->buried_buffer_list; CONSP (link);
1603 link = XCDR (link))
1604 {
1605 if (EQ (XCAR (link), buf))
1606 {
1607 if (NILP (prev))
1608 XFRAME (frame)->buried_buffer_list = XCDR (link);
1609 else
1610 XSETCDR (prev, XCDR (XCDR (prev)));
1611 break;
1612 }
1613 prev = link;
1614 }
1615
1586 /* Now move this buffer to the front of frame_buffer_list also. */ 1616 /* Now move this buffer to the front of frame_buffer_list also. */
1587 1617
1588 prev = Qnil; 1618 prev = Qnil;
@@ -2065,10 +2095,10 @@ selected window if it is displayed there. */)
2065 XSETCDR (link, Qnil); 2095 XSETCDR (link, Qnil);
2066 Vbuffer_alist = nconc2 (Vbuffer_alist, link); 2096 Vbuffer_alist = nconc2 (Vbuffer_alist, link);
2067 2097
2068 /* Removing BUFFER from frame-specific lists 2098 XFRAME (selected_frame)->buffer_list
2069 has the effect of putting BUFFER at the end 2099 = Fdelq (buffer, XFRAME (selected_frame)->buffer_list);
2070 of the combined list in each frame. */ 2100 XFRAME (selected_frame)->buried_buffer_list
2071 frames_discard_buffer (buffer); 2101 = Fcons (buffer, Fdelq (buffer, XFRAME (selected_frame)->buried_buffer_list));
2072 } 2102 }
2073 2103
2074 return Qnil; 2104 return Qnil;
diff --git a/src/callint.c b/src/callint.c
index 39b2046e8fc..84626031b3c 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -402,8 +402,8 @@ invoke it. If KEYS is omitted or nil, the return value of
402 real_this_command= save_real_this_command; 402 real_this_command= save_real_this_command;
403 current_kboard->Vlast_command = save_last_command; 403 current_kboard->Vlast_command = save_last_command;
404 404
405 single_kboard_state (); 405 temporarily_switch_to_single_kboard (NULL);
406 return apply1 (function, specs); 406 return unbind_to (speccount, apply1 (function, specs));
407 } 407 }
408 408
409 /* Here if function specifies a string to control parsing the defaults */ 409 /* Here if function specifies a string to control parsing the defaults */
@@ -851,12 +851,11 @@ invoke it. If KEYS is omitted or nil, the return value of
851 real_this_command= save_real_this_command; 851 real_this_command= save_real_this_command;
852 current_kboard->Vlast_command = save_last_command; 852 current_kboard->Vlast_command = save_last_command;
853 853
854 single_kboard_state ();
855
856 { 854 {
857 Lisp_Object val; 855 Lisp_Object val;
858 specbind (Qcommand_debug_status, Qnil); 856 specbind (Qcommand_debug_status, Qnil);
859 857
858 temporarily_switch_to_single_kboard (NULL);
860 val = Ffuncall (count + 1, args); 859 val = Ffuncall (count + 1, args);
861 UNGCPRO; 860 UNGCPRO;
862 return unbind_to (speccount, val); 861 return unbind_to (speccount, val);
diff --git a/src/callproc.c b/src/callproc.c
index 90e5b11a9a2..ce9eb73dd54 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -84,6 +84,8 @@ extern int errno;
84#include "syssignal.h" 84#include "syssignal.h"
85#include "systty.h" 85#include "systty.h"
86#include "blockinput.h" 86#include "blockinput.h"
87#include "frame.h"
88#include "termhooks.h"
87 89
88#ifdef MSDOS 90#ifdef MSDOS
89#include "msdos.h" 91#include "msdos.h"
@@ -130,6 +132,7 @@ int synch_process_termsig;
130/* If synch_process_death is zero, 132/* If synch_process_death is zero,
131 this is exit code of synchronous subprocess. */ 133 this is exit code of synchronous subprocess. */
132int synch_process_retcode; 134int synch_process_retcode;
135
133 136
134/* Clean up when exiting Fcall_process. 137/* Clean up when exiting Fcall_process.
135 On MSDOS, delete the temporary file on any kind of termination. 138 On MSDOS, delete the temporary file on any kind of termination.
@@ -1181,6 +1184,40 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1181 1184
1182static int relocate_fd (); 1185static int relocate_fd ();
1183 1186
1187static char **
1188add_env (char **env, char **new_env, char *string)
1189{
1190 char **ep;
1191 int ok = 1;
1192 if (string == NULL)
1193 return new_env;
1194
1195 /* See if this string duplicates any string already in the env.
1196 If so, don't put it in.
1197 When an env var has multiple definitions,
1198 we keep the definition that comes first in process-environment. */
1199 for (ep = env; ok && ep != new_env; ep++)
1200 {
1201 char *p = *ep, *q = string;
1202 while (ok)
1203 {
1204 if (*q != *p)
1205 break;
1206 if (*q == 0)
1207 /* The string is a lone variable name; keep it for now, we
1208 will remove it later. It is a placeholder for a
1209 variable that is not to be included in the environment. */
1210 break;
1211 if (*q == '=')
1212 ok = 0;
1213 p++, q++;
1214 }
1215 }
1216 if (ok)
1217 *new_env++ = string;
1218 return new_env;
1219}
1220
1184/* This is the last thing run in a newly forked inferior 1221/* This is the last thing run in a newly forked inferior
1185 either synchronous or asynchronous. 1222 either synchronous or asynchronous.
1186 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2. 1223 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
@@ -1282,14 +1319,23 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1282 temp[--i] = 0; 1319 temp[--i] = 0;
1283 } 1320 }
1284 1321
1285 /* Set `env' to a vector of the strings in Vprocess_environment. */ 1322 /* Set `env' to a vector of the strings in the environment. */
1286 { 1323 {
1287 register Lisp_Object tem; 1324 register Lisp_Object tem;
1288 register char **new_env; 1325 register char **new_env;
1326 char **p, **q;
1289 register int new_length; 1327 register int new_length;
1328 Lisp_Object local = get_frame_param (XFRAME (Fframe_with_environment (selected_frame)),
1329 Qenvironment);
1290 1330
1291 new_length = 0; 1331 new_length = 0;
1332
1292 for (tem = Vprocess_environment; 1333 for (tem = Vprocess_environment;
1334 CONSP (tem) && STRINGP (XCAR (tem));
1335 tem = XCDR (tem))
1336 new_length++;
1337
1338 for (tem = local;
1293 CONSP (tem) && STRINGP (XCAR (tem)); 1339 CONSP (tem) && STRINGP (XCAR (tem));
1294 tem = XCDR (tem)) 1340 tem = XCDR (tem))
1295 new_length++; 1341 new_length++;
@@ -1299,39 +1345,33 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1299 1345
1300 /* If we have a PWD envvar, pass one down, 1346 /* If we have a PWD envvar, pass one down,
1301 but with corrected value. */ 1347 but with corrected value. */
1302 if (getenv ("PWD")) 1348 if (egetenv ("PWD"))
1303 *new_env++ = pwd_var; 1349 *new_env++ = pwd_var;
1304 1350
1305 /* Copy the Vprocess_environment strings into new_env. */ 1351 /* Overrides. */
1306 for (tem = Vprocess_environment; 1352 for (tem = Vprocess_environment;
1307 CONSP (tem) && STRINGP (XCAR (tem)); 1353 CONSP (tem) && STRINGP (XCAR (tem));
1308 tem = XCDR (tem)) 1354 tem = XCDR (tem))
1355 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1356
1357 /* Local part of environment. */
1358 for (tem = local;
1359 CONSP (tem) && STRINGP (XCAR (tem));
1360 tem = XCDR (tem))
1361 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1362
1363 *new_env = 0;
1364
1365 /* Remove variable names without values. */
1366 p = q = env;
1367 while (*p != 0)
1309 { 1368 {
1310 char **ep = env; 1369 while (*q != 0 && strchr (*q, '=') == NULL)
1311 char *string = (char *) SDATA (XCAR (tem)); 1370 *q++;
1312 /* See if this string duplicates any string already in the env. 1371 *p = *q++;
1313 If so, don't put it in. 1372 if (*p != 0)
1314 When an env var has multiple definitions, 1373 p++;
1315 we keep the definition that comes first in process-environment. */
1316 for (; ep != new_env; ep++)
1317 {
1318 char *p = *ep, *q = string;
1319 while (1)
1320 {
1321 if (*q == 0)
1322 /* The string is malformed; might as well drop it. */
1323 goto duplicate;
1324 if (*q != *p)
1325 break;
1326 if (*q == '=')
1327 goto duplicate;
1328 p++, q++;
1329 }
1330 }
1331 *new_env++ = string;
1332 duplicate: ;
1333 } 1374 }
1334 *new_env = 0;
1335 } 1375 }
1336#ifdef WINDOWSNT 1376#ifdef WINDOWSNT
1337 prepare_standard_handles (in, out, err, handles); 1377 prepare_standard_handles (in, out, err, handles);
@@ -1446,29 +1486,69 @@ relocate_fd (fd, minfd)
1446} 1486}
1447 1487
1448static int 1488static int
1449getenv_internal (var, varlen, value, valuelen) 1489getenv_internal (var, varlen, value, valuelen, frame)
1450 char *var; 1490 char *var;
1451 int varlen; 1491 int varlen;
1452 char **value; 1492 char **value;
1453 int *valuelen; 1493 int *valuelen;
1494 Lisp_Object frame;
1454{ 1495{
1455 Lisp_Object scan; 1496 Lisp_Object scan;
1456 1497
1457 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) 1498 if (NILP (frame))
1499 {
1500 /* Try to find VAR in Vprocess_environment first. */
1501 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1502 {
1503 Lisp_Object entry = XCAR (scan);
1504 if (STRINGP (entry)
1505 && SBYTES (entry) >= varlen
1506#ifdef WINDOWSNT
1507 /* NT environment variables are case insensitive. */
1508 && ! strnicmp (SDATA (entry), var, varlen)
1509#else /* not WINDOWSNT */
1510 && ! bcmp (SDATA (entry), var, varlen)
1511#endif /* not WINDOWSNT */
1512 )
1513 {
1514 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1515 {
1516 *value = (char *) SDATA (entry) + (varlen + 1);
1517 *valuelen = SBYTES (entry) - (varlen + 1);
1518 return 1;
1519 }
1520 else if (SBYTES (entry) == varlen)
1521 {
1522 /* Lone variable names in Vprocess_environment mean that
1523 variable should be removed from the environment. */
1524 return 0;
1525 }
1526 }
1527 }
1528 frame = selected_frame;
1529 }
1530
1531 /* Find the environment in which to search the variable. */
1532 CHECK_FRAME (frame);
1533 frame = Fframe_with_environment (frame);
1534
1535 for (scan = get_frame_param (XFRAME (frame), Qenvironment);
1536 CONSP (scan);
1537 scan = XCDR (scan))
1458 { 1538 {
1459 Lisp_Object entry; 1539 Lisp_Object entry;
1460 1540
1461 entry = XCAR (scan); 1541 entry = XCAR (scan);
1462 if (STRINGP (entry) 1542 if (STRINGP (entry)
1463 && SBYTES (entry) > varlen 1543 && SBYTES (entry) > varlen
1464 && SREF (entry, varlen) == '=' 1544 && SREF (entry, varlen) == '='
1465#ifdef WINDOWSNT 1545#ifdef WINDOWSNT
1466 /* NT environment variables are case insensitive. */ 1546 /* NT environment variables are case insensitive. */
1467 && ! strnicmp (SDATA (entry), var, varlen) 1547 && ! strnicmp (SDATA (entry), var, varlen)
1468#else /* not WINDOWSNT */ 1548#else /* not WINDOWSNT */
1469 && ! bcmp (SDATA (entry), var, varlen) 1549 && ! bcmp (SDATA (entry), var, varlen)
1470#endif /* not WINDOWSNT */ 1550#endif /* not WINDOWSNT */
1471 ) 1551 )
1472 { 1552 {
1473 *value = (char *) SDATA (entry) + (varlen + 1); 1553 *value = (char *) SDATA (entry) + (varlen + 1);
1474 *valuelen = SBYTES (entry) - (varlen + 1); 1554 *valuelen = SBYTES (entry) - (varlen + 1);
@@ -1479,26 +1559,34 @@ getenv_internal (var, varlen, value, valuelen)
1479 return 0; 1559 return 0;
1480} 1560}
1481 1561
1482DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 1, 0, 1562DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 2, 0,
1483 doc: /* Return the value of environment variable VAR, as a string. 1563 doc: /* Get the value of environment variable VARIABLE.
1484VAR should be a string. Value is nil if VAR is undefined in the environment. 1564VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1485This function consults the variable `process-environment' for its value. */) 1565the environment. Otherwise, value is a string.
1486 (var) 1566
1487 Lisp_Object var; 1567This function searches `process-environment' for VARIABLE. If it is
1568not found there, then it continues the search in the environment list
1569of the selected frame.
1570
1571If optional parameter FRAME is non-nil, then this function will ignore
1572`process-environment' and will simply look up the variable in that
1573frame's environment. */)
1574 (variable, frame)
1575 Lisp_Object variable, frame;
1488{ 1576{
1489 char *value; 1577 char *value;
1490 int valuelen; 1578 int valuelen;
1491 1579
1492 CHECK_STRING (var); 1580 CHECK_STRING (variable);
1493 if (getenv_internal (SDATA (var), SBYTES (var), 1581 if (getenv_internal (SDATA (variable), SBYTES (variable),
1494 &value, &valuelen)) 1582 &value, &valuelen, frame))
1495 return make_string (value, valuelen); 1583 return make_string (value, valuelen);
1496 else 1584 else
1497 return Qnil; 1585 return Qnil;
1498} 1586}
1499 1587
1500/* A version of getenv that consults process_environment, easily 1588/* A version of getenv that consults the Lisp environment lists,
1501 callable from C. */ 1589 easily callable from C. */
1502char * 1590char *
1503egetenv (var) 1591egetenv (var)
1504 char *var; 1592 char *var;
@@ -1506,7 +1594,7 @@ egetenv (var)
1506 char *value; 1594 char *value;
1507 int valuelen; 1595 int valuelen;
1508 1596
1509 if (getenv_internal (var, strlen (var), &value, &valuelen)) 1597 if (getenv_internal (var, strlen (var), &value, &valuelen, Qnil))
1510 return value; 1598 return value;
1511 else 1599 else
1512 return 0; 1600 return 0;
@@ -1629,8 +1717,8 @@ init_callproc ()
1629 { 1717 {
1630 char *dir = getenv ("TMPDIR"); 1718 char *dir = getenv ("TMPDIR");
1631 Vtemp_file_name_pattern 1719 Vtemp_file_name_pattern
1632 = Fexpand_file_name (build_string ("emacsXXXXXX"), 1720 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1633 build_string (dir)); 1721 build_string (dir));
1634 } 1722 }
1635 else 1723 else
1636 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX"); 1724 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
@@ -1646,17 +1734,18 @@ init_callproc ()
1646} 1734}
1647 1735
1648void 1736void
1649set_process_environment () 1737set_initial_environment ()
1650{ 1738{
1651 register char **envp; 1739 register char **envp;
1652 1740 Lisp_Object env = Qnil;
1653 Vprocess_environment = Qnil;
1654#ifndef CANNOT_DUMP 1741#ifndef CANNOT_DUMP
1655 if (initialized) 1742 if (initialized)
1656#endif 1743#endif
1657 for (envp = environ; *envp; envp++) 1744 {
1658 Vprocess_environment = Fcons (build_string (*envp), 1745 for (envp = environ; *envp; envp++)
1659 Vprocess_environment); 1746 env = Fcons (build_string (*envp), env);
1747 store_frame_param (SELECTED_FRAME(), Qenvironment, env);
1748 }
1660} 1749}
1661 1750
1662void 1751void
@@ -1716,15 +1805,27 @@ This is used by `call-process-region'. */);
1716 /* This variable is initialized in init_callproc. */ 1805 /* This variable is initialized in init_callproc. */
1717 1806
1718 DEFVAR_LISP ("process-environment", &Vprocess_environment, 1807 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1719 doc: /* List of environment variables for subprocesses to inherit. 1808 doc: /* List of overridden environment variables for subprocesses to inherit.
1720Each element should be a string of the form ENVVARNAME=VALUE. 1809Each element should be a string of the form ENVVARNAME=VALUE.
1810
1811Entries in this list take precedence to those in the frame-local
1812environments. Therefore, let-binding `process-environment' is an easy
1813way to temporarily change the value of an environment variable,
1814irrespective of where it comes from. To use `process-environment' to
1815remove an environment variable, include only its name in the list,
1816without "=VALUE".
1817
1818This variable is set to nil when Emacs starts.
1819
1721If multiple entries define the same variable, the first one always 1820If multiple entries define the same variable, the first one always
1722takes precedence. 1821takes precedence.
1723The environment which Emacs inherits is placed in this variable 1822
1724when Emacs starts.
1725Non-ASCII characters are encoded according to the initial value of 1823Non-ASCII characters are encoded according to the initial value of
1726`locale-coding-system', i.e. the elements must normally be decoded for use. 1824`locale-coding-system', i.e. the elements must normally be decoded for
1825use.
1826
1727See `setenv' and `getenv'. */); 1827See `setenv' and `getenv'. */);
1828 Vprocess_environment = Qnil;
1728 1829
1729#ifndef VMS 1830#ifndef VMS
1730 defsubr (&Scall_process); 1831 defsubr (&Scall_process);
diff --git a/src/cm.c b/src/cm.c
index da984f0b82d..d520e740eb3 100644
--- a/src/cm.c
+++ b/src/cm.c
@@ -23,8 +23,13 @@ Boston, MA 02110-1301, USA. */
23 23
24#include <config.h> 24#include <config.h>
25#include <stdio.h> 25#include <stdio.h>
26
27#include "lisp.h"
28#include "frame.h"
26#include "cm.h" 29#include "cm.h"
27#include "termhooks.h" 30#include "termhooks.h"
31#include "termchar.h"
32
28 33
29/* For now, don't try to include termcap.h. On some systems, 34/* For now, don't try to include termcap.h. On some systems,
30 configure finds a non-standard termcap.h that the main build 35 configure finds a non-standard termcap.h that the main build
@@ -53,13 +58,16 @@ evalcost (c)
53 return c; 58 return c;
54} 59}
55 60
61/* The terminal to use for low-level output. */
62struct tty_display_info *current_tty;
63
56int 64int
57cmputc (c) 65cmputc (c)
58 char c; 66 char c;
59{ 67{
60 if (termscript) 68 if (current_tty->termscript)
61 fputc (c & 0177, termscript); 69 putc (c & 0177, current_tty->termscript);
62 putchar (c & 0177); 70 putc (c & 0177, current_tty->output);
63 return c; 71 return c;
64} 72}
65 73
@@ -72,9 +80,9 @@ cmputc (c)
72 */ 80 */
73 81
74static 82static
75at (row, col) { 83at (tty, row, col) {
76 curY = row; 84 curY (tty) = row;
77 curX = col; 85 curX (tty) = col;
78} 86}
79 87
80/* 88/*
@@ -82,8 +90,8 @@ at (row, col) {
82 */ 90 */
83 91
84static 92static
85addcol (n) { 93addcol (tty, n) {
86 curX += n; 94 curX (tty) += n;
87 95
88 /* 96 /*
89 * If cursor hit edge of screen, what happened? 97 * If cursor hit edge of screen, what happened?
@@ -93,21 +101,21 @@ addcol (n) {
93 * of the last line. 101 * of the last line.
94 */ 102 */
95 103
96 if (curX == Wcm.cm_cols) { 104 if (curX (tty) == tty->Wcm->cm_cols) {
97 /* 105 /*
98 * Well, if magicwrap, still there, past the edge of the 106 * Well, if magicwrap, still there, past the edge of the
99 * screen (!). If autowrap, on the col 0 of the next line. 107 * screen (!). If autowrap, on the col 0 of the next line.
100 * Otherwise on last column. 108 * Otherwise on last column.
101 */ 109 */
102 110
103 if (Wcm.cm_magicwrap) 111 if (tty->Wcm->cm_magicwrap)
104 ; /* "limbo" */ 112 ; /* "limbo" */
105 else if (Wcm.cm_autowrap) { 113 else if (tty->Wcm->cm_autowrap) {
106 curX = 0; 114 curX (tty) = 0;
107 curY++; /* Beware end of screen! */ 115 curY (tty) ++; /* Beware end of screen! */
108 } 116 }
109 else 117 else
110 curX--; 118 curX (tty)--;
111 } 119 }
112} 120}
113#endif 121#endif
@@ -123,20 +131,20 @@ addcol (n) {
123 * after we reach the last column; this takes us to a known state. 131 * after we reach the last column; this takes us to a known state.
124 */ 132 */
125void 133void
126cmcheckmagic () 134cmcheckmagic (struct tty_display_info *tty)
127{ 135{
128 if (curX == FrameCols) 136 if (curX (tty) == FrameCols (tty))
129 { 137 {
130 if (!MagicWrap || curY >= FrameRows - 1) 138 if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1)
131 abort (); 139 abort ();
132 if (termscript) 140 if (tty->termscript)
133 putc ('\r', termscript); 141 putc ('\r', tty->termscript);
134 putchar ('\r'); 142 putc ('\r', tty->output);
135 if (termscript) 143 if (tty->termscript)
136 putc ('\n', termscript); 144 putc ('\n', tty->termscript);
137 putchar ('\n'); 145 putc ('\n', tty->output);
138 curX = 0; 146 curX (tty) = 0;
139 curY++; 147 curY (tty)++;
140 } 148 }
141} 149}
142 150
@@ -148,21 +156,21 @@ cmcheckmagic ()
148 */ 156 */
149 157
150void 158void
151cmcostinit () 159cmcostinit (struct tty_display_info *tty)
152{ 160{
153 char *p; 161 char *p;
154 162
155#define COST(x,e) (x ? (cost = 0, tputs (x, 1, e), cost) : BIG) 163#define COST(x,e) (x ? (cost = 0, tputs (x, 1, e), cost) : BIG)
156#define CMCOST(x,e) ((x == 0) ? BIG : (p = tgoto(x, 0, 0), COST(p ,e))) 164#define CMCOST(x,e) ((x == 0) ? BIG : (p = tgoto(x, 0, 0), COST(p ,e)))
157 165
158 Wcm.cc_up = COST (Wcm.cm_up, evalcost); 166 tty->Wcm->cc_up = COST (tty->Wcm->cm_up, evalcost);
159 Wcm.cc_down = COST (Wcm.cm_down, evalcost); 167 tty->Wcm->cc_down = COST (tty->Wcm->cm_down, evalcost);
160 Wcm.cc_left = COST (Wcm.cm_left, evalcost); 168 tty->Wcm->cc_left = COST (tty->Wcm->cm_left, evalcost);
161 Wcm.cc_right = COST (Wcm.cm_right, evalcost); 169 tty->Wcm->cc_right = COST (tty->Wcm->cm_right, evalcost);
162 Wcm.cc_home = COST (Wcm.cm_home, evalcost); 170 tty->Wcm->cc_home = COST (tty->Wcm->cm_home, evalcost);
163 Wcm.cc_cr = COST (Wcm.cm_cr, evalcost); 171 tty->Wcm->cc_cr = COST (tty->Wcm->cm_cr, evalcost);
164 Wcm.cc_ll = COST (Wcm.cm_ll, evalcost); 172 tty->Wcm->cc_ll = COST (tty->Wcm->cm_ll, evalcost);
165 Wcm.cc_tab = Wcm.cm_tabwidth ? COST (Wcm.cm_tab, evalcost) : BIG; 173 tty->Wcm->cc_tab = tty->Wcm->cm_tabwidth ? COST (tty->Wcm->cm_tab, evalcost) : BIG;
166 174
167 /* 175 /*
168 * These last three are actually minimum costs. When (if) they are 176 * These last three are actually minimum costs. When (if) they are
@@ -173,9 +181,9 @@ cmcostinit ()
173 * cursor motion seem to take straight numeric values. --ACT) 181 * cursor motion seem to take straight numeric values. --ACT)
174 */ 182 */
175 183
176 Wcm.cc_abs = CMCOST (Wcm.cm_abs, evalcost); 184 tty->Wcm->cc_abs = CMCOST (tty->Wcm->cm_abs, evalcost);
177 Wcm.cc_habs = CMCOST (Wcm.cm_habs, evalcost); 185 tty->Wcm->cc_habs = CMCOST (tty->Wcm->cm_habs, evalcost);
178 Wcm.cc_vabs = CMCOST (Wcm.cm_vabs, evalcost); 186 tty->Wcm->cc_vabs = CMCOST (tty->Wcm->cm_vabs, evalcost);
179 187
180#undef CMCOST 188#undef CMCOST
181#undef COST 189#undef COST
@@ -188,8 +196,8 @@ cmcostinit ()
188 */ 196 */
189 197
190static int 198static int
191calccost (srcy, srcx, dsty, dstx, doit) 199calccost (struct tty_display_info *tty,
192 int srcy, srcx, dsty, dstx, doit; 200 int srcy, int srcx, int dsty, int dstx, int doit)
193{ 201{
194 register int deltay, 202 register int deltay,
195 deltax, 203 deltax,
@@ -206,16 +214,16 @@ calccost (srcy, srcx, dsty, dstx, doit)
206 don't believe the cursor position: give up here 214 don't believe the cursor position: give up here
207 and force use of absolute positioning. */ 215 and force use of absolute positioning. */
208 216
209 if (curX == Wcm.cm_cols) 217 if (curX (tty) == tty->Wcm->cm_cols)
210 goto fail; 218 goto fail;
211 219
212 totalcost = 0; 220 totalcost = 0;
213 if ((deltay = dsty - srcy) == 0) 221 if ((deltay = dsty - srcy) == 0)
214 goto x; 222 goto x;
215 if (deltay < 0) 223 if (deltay < 0)
216 p = Wcm.cm_up, c = Wcm.cc_up, deltay = -deltay; 224 p = tty->Wcm->cm_up, c = tty->Wcm->cc_up, deltay = -deltay;
217 else 225 else
218 p = Wcm.cm_down, c = Wcm.cc_down; 226 p = tty->Wcm->cm_down, c = tty->Wcm->cc_down;
219 if (c == BIG) { /* caint get thar from here */ 227 if (c == BIG) { /* caint get thar from here */
220 if (doit) 228 if (doit)
221 printf ("OOPS"); 229 printf ("OOPS");
@@ -224,16 +232,16 @@ calccost (srcy, srcx, dsty, dstx, doit)
224 totalcost = c * deltay; 232 totalcost = c * deltay;
225 if (doit) 233 if (doit)
226 while (--deltay >= 0) 234 while (--deltay >= 0)
227 tputs (p, 1, cmputc); 235 emacs_tputs (tty, p, 1, cmputc);
228x: 236x:
229 if ((deltax = dstx - srcx) == 0) 237 if ((deltax = dstx - srcx) == 0)
230 goto done; 238 goto done;
231 if (deltax < 0) { 239 if (deltax < 0) {
232 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax; 240 p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax;
233 goto dodelta; /* skip all the tab junk */ 241 goto dodelta; /* skip all the tab junk */
234 } 242 }
235 /* Tabs (the toughie) */ 243 /* Tabs (the toughie) */
236 if (Wcm.cc_tab >= BIG || !Wcm.cm_usetabs) 244 if (tty->Wcm->cc_tab >= BIG || !tty->Wcm->cm_usetabs)
237 goto olddelta; /* forget it! */ 245 goto olddelta; /* forget it! */
238 246
239 /* 247 /*
@@ -244,12 +252,12 @@ x:
244 * we will put into tabx (for ntabs) and tab2x (for n2tabs)). 252 * we will put into tabx (for ntabs) and tab2x (for n2tabs)).
245 */ 253 */
246 254
247 ntabs = (deltax + srcx % Wcm.cm_tabwidth) / Wcm.cm_tabwidth; 255 ntabs = (deltax + srcx % tty->Wcm->cm_tabwidth) / tty->Wcm->cm_tabwidth;
248 n2tabs = ntabs + 1; 256 n2tabs = ntabs + 1;
249 tabx = (srcx / Wcm.cm_tabwidth + ntabs) * Wcm.cm_tabwidth; 257 tabx = (srcx / tty->Wcm->cm_tabwidth + ntabs) * tty->Wcm->cm_tabwidth;
250 tab2x = tabx + Wcm.cm_tabwidth; 258 tab2x = tabx + tty->Wcm->cm_tabwidth;
251 259
252 if (tab2x >= Wcm.cm_cols) /* too far (past edge) */ 260 if (tab2x >= tty->Wcm->cm_cols) /* too far (past edge) */
253 n2tabs = 0; 261 n2tabs = 0;
254 262
255 /* 263 /*
@@ -257,12 +265,12 @@ x:
257 * for using n2tabs, then pick the minimum. 265 * for using n2tabs, then pick the minimum.
258 */ 266 */
259 267
260 /* cost for ntabs + cost for right motion */ 268 /* cost for ntabs + cost for right motion */
261 tabcost = ntabs ? ntabs * Wcm.cc_tab + (dstx - tabx) * Wcm.cc_right 269 tabcost = ntabs ? ntabs * tty->Wcm->cc_tab + (dstx - tabx) * tty->Wcm->cc_right
262 : BIG; 270 : BIG;
263 271
264 /* cost for n2tabs + cost for left motion */ 272 /* cost for n2tabs + cost for left motion */
265 c = n2tabs ? n2tabs * Wcm.cc_tab + (tab2x - dstx) * Wcm.cc_left 273 c = n2tabs ? n2tabs * tty->Wcm->cc_tab + (tab2x - dstx) * tty->Wcm->cc_left
266 : BIG; 274 : BIG;
267 275
268 if (c < tabcost) /* then cheaper to overshoot & back up */ 276 if (c < tabcost) /* then cheaper to overshoot & back up */
@@ -275,11 +283,11 @@ x:
275 * See if tabcost is less than just moving right 283 * See if tabcost is less than just moving right
276 */ 284 */
277 285
278 if (tabcost < (deltax * Wcm.cc_right)) { 286 if (tabcost < (deltax * tty->Wcm->cc_right)) {
279 totalcost += tabcost; /* use the tabs */ 287 totalcost += tabcost; /* use the tabs */
280 if (doit) 288 if (doit)
281 while (--ntabs >= 0) 289 while (--ntabs >= 0)
282 tputs (Wcm.cm_tab, 1, cmputc); 290 emacs_tputs (tty, tty->Wcm->cm_tab, 1, cmputc);
283 srcx = tabx; 291 srcx = tabx;
284 } 292 }
285 293
@@ -292,9 +300,9 @@ newdelta:
292 goto done; 300 goto done;
293olddelta: 301olddelta:
294 if (deltax > 0) 302 if (deltax > 0)
295 p = Wcm.cm_right, c = Wcm.cc_right; 303 p = tty->Wcm->cm_right, c = tty->Wcm->cc_right;
296 else 304 else
297 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax; 305 p = tty->Wcm->cm_left, c = tty->Wcm->cc_left, deltax = -deltax;
298 306
299dodelta: 307dodelta:
300 if (c == BIG) { /* caint get thar from here */ 308 if (c == BIG) { /* caint get thar from here */
@@ -306,7 +314,7 @@ fail:
306 totalcost += c * deltax; 314 totalcost += c * deltax;
307 if (doit) 315 if (doit)
308 while (--deltax >= 0) 316 while (--deltax >= 0)
309 tputs (p, 1, cmputc); 317 emacs_tputs (tty, p, 1, cmputc);
310done: 318done:
311 return totalcost; 319 return totalcost;
312} 320}
@@ -324,7 +332,8 @@ losecursor ()
324#define USECR 3 332#define USECR 3
325 333
326void 334void
327cmgoto (row, col) 335cmgoto (tty, row, col)
336 struct tty_display_info *tty;
328 int row, col; 337 int row, col;
329{ 338{
330 int homecost, 339 int homecost,
@@ -337,47 +346,47 @@ cmgoto (row, col)
337 *dcm; 346 *dcm;
338 347
339 /* First the degenerate case */ 348 /* First the degenerate case */
340 if (row == curY && col == curX) /* already there */ 349 if (row == curY (tty) && col == curX (tty)) /* already there */
341 return; 350 return;
342 351
343 if (curY >= 0 && curX >= 0) 352 if (curY (tty) >= 0 && curX (tty) >= 0)
344 { 353 {
345 /* We may have quick ways to go to the upper-left, bottom-left, 354 /* We may have quick ways to go to the upper-left, bottom-left,
346 * start-of-line, or start-of-next-line. Or it might be best to 355 * start-of-line, or start-of-next-line. Or it might be best to
347 * start where we are. Examine the options, and pick the cheapest. 356 * start where we are. Examine the options, and pick the cheapest.
348 */ 357 */
349 358
350 relcost = calccost (curY, curX, row, col, 0); 359 relcost = calccost (tty, curY (tty), curX (tty), row, col, 0);
351 use = USEREL; 360 use = USEREL;
352 if ((homecost = Wcm.cc_home) < BIG) 361 if ((homecost = tty->Wcm->cc_home) < BIG)
353 homecost += calccost (0, 0, row, col, 0); 362 homecost += calccost (tty, 0, 0, row, col, 0);
354 if (homecost < relcost) 363 if (homecost < relcost)
355 relcost = homecost, use = USEHOME; 364 relcost = homecost, use = USEHOME;
356 if ((llcost = Wcm.cc_ll) < BIG) 365 if ((llcost = tty->Wcm->cc_ll) < BIG)
357 llcost += calccost (Wcm.cm_rows - 1, 0, row, col, 0); 366 llcost += calccost (tty, tty->Wcm->cm_rows - 1, 0, row, col, 0);
358 if (llcost < relcost) 367 if (llcost < relcost)
359 relcost = llcost, use = USELL; 368 relcost = llcost, use = USELL;
360 if ((crcost = Wcm.cc_cr) < BIG) { 369 if ((crcost = tty->Wcm->cc_cr) < BIG) {
361 if (Wcm.cm_autolf) 370 if (tty->Wcm->cm_autolf)
362 if (curY + 1 >= Wcm.cm_rows) 371 if (curY (tty) + 1 >= tty->Wcm->cm_rows)
363 crcost = BIG; 372 crcost = BIG;
364 else 373 else
365 crcost += calccost (curY + 1, 0, row, col, 0); 374 crcost += calccost (tty, curY (tty) + 1, 0, row, col, 0);
366 else 375 else
367 crcost += calccost (curY, 0, row, col, 0); 376 crcost += calccost (tty, curY (tty), 0, row, col, 0);
368 } 377 }
369 if (crcost < relcost) 378 if (crcost < relcost)
370 relcost = crcost, use = USECR; 379 relcost = crcost, use = USECR;
371 directcost = Wcm.cc_abs, dcm = Wcm.cm_abs; 380 directcost = tty->Wcm->cc_abs, dcm = tty->Wcm->cm_abs;
372 if (row == curY && Wcm.cc_habs < BIG) 381 if (row == curY (tty) && tty->Wcm->cc_habs < BIG)
373 directcost = Wcm.cc_habs, dcm = Wcm.cm_habs; 382 directcost = tty->Wcm->cc_habs, dcm = tty->Wcm->cm_habs;
374 else if (col == curX && Wcm.cc_vabs < BIG) 383 else if (col == curX (tty) && tty->Wcm->cc_vabs < BIG)
375 directcost = Wcm.cc_vabs, dcm = Wcm.cm_vabs; 384 directcost = tty->Wcm->cc_vabs, dcm = tty->Wcm->cm_vabs;
376 } 385 }
377 else 386 else
378 { 387 {
379 directcost = 0, relcost = 100000; 388 directcost = 0, relcost = 100000;
380 dcm = Wcm.cm_abs; 389 dcm = tty->Wcm->cm_abs;
381 } 390 }
382 391
383 /* 392 /*
@@ -388,13 +397,14 @@ cmgoto (row, col)
388 { 397 {
389 /* compute REAL direct cost */ 398 /* compute REAL direct cost */
390 cost = 0; 399 cost = 0;
391 p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) : 400 p = (dcm == tty->Wcm->cm_habs
392 tgoto (dcm, col, row); 401 ? tgoto (dcm, row, col)
393 tputs (p, 1, evalcost); 402 : tgoto (dcm, col, row));
403 emacs_tputs (tty, p, 1, evalcost);
394 if (cost <= relcost) 404 if (cost <= relcost)
395 { /* really is cheaper */ 405 { /* really is cheaper */
396 tputs (p, 1, cmputc); 406 emacs_tputs (tty, p, 1, cmputc);
397 curY = row, curX = col; 407 curY (tty) = row, curX (tty) = col;
398 return; 408 return;
399 } 409 }
400 } 410 }
@@ -402,25 +412,25 @@ cmgoto (row, col)
402 switch (use) 412 switch (use)
403 { 413 {
404 case USEHOME: 414 case USEHOME:
405 tputs (Wcm.cm_home, 1, cmputc); 415 emacs_tputs (tty, tty->Wcm->cm_home, 1, cmputc);
406 curY = 0, curX = 0; 416 curY (tty) = 0, curX (tty) = 0;
407 break; 417 break;
408 418
409 case USELL: 419 case USELL:
410 tputs (Wcm.cm_ll, 1, cmputc); 420 emacs_tputs (tty, tty->Wcm->cm_ll, 1, cmputc);
411 curY = Wcm.cm_rows - 1, curX = 0; 421 curY (tty) = tty->Wcm->cm_rows - 1, curX (tty) = 0;
412 break; 422 break;
413 423
414 case USECR: 424 case USECR:
415 tputs (Wcm.cm_cr, 1, cmputc); 425 emacs_tputs (tty, tty->Wcm->cm_cr, 1, cmputc);
416 if (Wcm.cm_autolf) 426 if (tty->Wcm->cm_autolf)
417 curY++; 427 curY (tty)++;
418 curX = 0; 428 curX (tty) = 0;
419 break; 429 break;
420 } 430 }
421 431
422 (void) calccost (curY, curX, row, col, 1); 432 (void) calccost (tty, curY (tty), curX (tty), row, col, 1);
423 curY = row, curX = col; 433 curY (tty) = row, curX (tty) = col;
424} 434}
425 435
426/* Clear out all terminal info. 436/* Clear out all terminal info.
@@ -428,9 +438,9 @@ cmgoto (row, col)
428 */ 438 */
429 439
430void 440void
431Wcm_clear () 441Wcm_clear (struct tty_display_info *tty)
432{ 442{
433 bzero (&Wcm, sizeof Wcm); 443 bzero (tty->Wcm, sizeof (struct cm));
434 UP = 0; 444 UP = 0;
435 BC = 0; 445 BC = 0;
436} 446}
@@ -443,21 +453,21 @@ Wcm_clear ()
443 */ 453 */
444 454
445int 455int
446Wcm_init () 456Wcm_init (struct tty_display_info *tty)
447{ 457{
448#if 0 458#if 0
449 if (Wcm.cm_abs && !Wcm.cm_ds) 459 if (tty->Wcm->cm_abs && !tty->Wcm->cm_ds)
450 return 0; 460 return 0;
451#endif 461#endif
452 if (Wcm.cm_abs) 462 if (tty->Wcm->cm_abs)
453 return 0; 463 return 0;
454 /* Require up and left, and, if no absolute, down and right */ 464 /* Require up and left, and, if no absolute, down and right */
455 if (!Wcm.cm_up || !Wcm.cm_left) 465 if (!tty->Wcm->cm_up || !tty->Wcm->cm_left)
456 return - 1; 466 return - 1;
457 if (!Wcm.cm_abs && (!Wcm.cm_down || !Wcm.cm_right)) 467 if (!tty->Wcm->cm_abs && (!tty->Wcm->cm_down || !tty->Wcm->cm_right))
458 return - 1; 468 return - 1;
459 /* Check that we know the size of the screen.... */ 469 /* Check that we know the size of the screen.... */
460 if (Wcm.cm_rows <= 0 || Wcm.cm_cols <= 0) 470 if (tty->Wcm->cm_rows <= 0 || tty->Wcm->cm_cols <= 0)
461 return - 2; 471 return - 2;
462 return 0; 472 return 0;
463} 473}
diff --git a/src/cm.h b/src/cm.h
index d77ba582f74..a83a5bb090d 100644
--- a/src/cm.h
+++ b/src/cm.h
@@ -99,76 +99,78 @@ struct cm
99 int cc_vabs; 99 int cc_vabs;
100 }; 100 };
101 101
102extern struct cm Wcm; /* Terminal capabilities */
103extern char PC; /* Pad character */ 102extern char PC; /* Pad character */
104 103
105/* Shorthand */ 104/* Shorthand */
106#ifndef NoCMShortHand 105#ifndef NoCMShortHand
107#define curY Wcm.cm_curY 106#define curY(tty) (tty)->Wcm->cm_curY
108#define curX Wcm.cm_curX 107#define curX(tty) (tty)->Wcm->cm_curX
109#define Up Wcm.cm_up 108#define Up(tty) (tty)->Wcm->cm_up
110#define Down Wcm.cm_down 109#define Down(tty) (tty)->Wcm->cm_down
111#define Left Wcm.cm_left 110#define Left(tty) (tty)->Wcm->cm_left
112#define Right Wcm.cm_right 111#define Right(tty) (tty)->Wcm->cm_right
113#define Tab Wcm.cm_tab 112#define Tab(tty) (tty)->Wcm->cm_tab
114#define BackTab Wcm.cm_backtab 113#define BackTab(tty) (tty)->Wcm->cm_backtab
115#define TabWidth Wcm.cm_tabwidth 114#define TabWidth(tty) (tty)->Wcm->cm_tabwidth
116#define CR Wcm.cm_cr 115#define CR(tty) (tty)->Wcm->cm_cr
117#define Home Wcm.cm_home 116#define Home(tty) (tty)->Wcm->cm_home
118#define LastLine Wcm.cm_ll 117#define LastLine(tty) (tty)->Wcm->cm_ll
119#define AbsPosition Wcm.cm_abs 118#define AbsPosition(tty) (tty)->Wcm->cm_abs
120#define ColPosition Wcm.cm_habs 119#define ColPosition(tty) (tty)->Wcm->cm_habs
121#define RowPosition Wcm.cm_vabs 120#define RowPosition(tty) (tty)->Wcm->cm_vabs
122#define MultiUp Wcm.cm_multiup 121#define MultiUp(tty) (tty)->Wcm->cm_multiup
123#define MultiDown Wcm.cm_multidown 122#define MultiDown(tty) (tty)->Wcm->cm_multidown
124#define MultiLeft Wcm.cm_multileft 123#define MultiLeft(tty) (tty)->Wcm->cm_multileft
125#define MultiRight Wcm.cm_multiright 124#define MultiRight(tty) (tty)->Wcm->cm_multiright
126#define AutoWrap Wcm.cm_autowrap 125#define AutoWrap(tty) (tty)->Wcm->cm_autowrap
127#define MagicWrap Wcm.cm_magicwrap 126#define MagicWrap(tty) (tty)->Wcm->cm_magicwrap
128#define UseTabs Wcm.cm_usetabs 127#define UseTabs(tty) (tty)->Wcm->cm_usetabs
129#define FrameRows Wcm.cm_rows 128#define FrameRows(tty) (tty)->Wcm->cm_rows
130#define FrameCols Wcm.cm_cols 129#define FrameCols(tty) (tty)->Wcm->cm_cols
131 130
132#define UpCost Wcm.cc_up 131#define UpCost(tty) (tty)->Wcm->cc_up
133#define DownCost Wcm.cc_down 132#define DownCost(tty) (tty)->Wcm->cc_down
134#define LeftCost Wcm.cc_left 133#define LeftCost(tty) (tty)->Wcm->cc_left
135#define RightCost Wcm.cc_right 134#define RightCost(tty) (tty)->Wcm->cc_right
136#define HomeCost Wcm.cc_home 135#define HomeCost(tty) (tty)->Wcm->cc_home
137#define CRCost Wcm.cc_cr 136#define CRCost(tty) (tty)->Wcm->cc_cr
138#define LastLineCost Wcm.cc_ll 137#define LastLineCost(tty) (tty)->Wcm->cc_ll
139#define TabCost Wcm.cc_tab 138#define TabCost(tty) (tty)->Wcm->cc_tab
140#define BackTabCost Wcm.cc_backtab 139#define BackTabCost(tty) (tty)->Wcm->cc_backtab
141#define AbsPositionCost Wcm.cc_abs 140#define AbsPositionCost(tty) (tty)->Wcm->cc_abs
142#define ColPositionCost Wcm.cc_habs 141#define ColPositionCost(tty) (tty)->Wcm->cc_habs
143#define RowPositionCost Wcm.cc_vabs 142#define RowPositionCost(tty) (tty)->Wcm->cc_vabs
144#define MultiUpCost Wcm.cc_multiup 143#define MultiUpCost(tty) (tty)->Wcm->cc_multiup
145#define MultiDownCost Wcm.cc_multidown 144#define MultiDownCost(tty) (tty)->Wcm->cc_multidown
146#define MultiLeftCost Wcm.cc_multileft 145#define MultiLeftCost(tty) (tty)->Wcm->cc_multileft
147#define MultiRightCost Wcm.cc_multiright 146#define MultiRightCost(tty) (tty)->Wcm->cc_multiright
148#endif 147#endif
149 148
150#define cmat(row,col) (curY = (row), curX = (col)) 149#define cmat(tty,row,col) (curY(tty) = (row), curX(tty) = (col))
151#define cmplus(n) \ 150#define cmplus(tty,n) \
152 { \ 151 { \
153 if ((curX += (n)) >= FrameCols && !MagicWrap) \ 152 if ((curX (tty) += (n)) >= FrameCols (tty) && !MagicWrap (tty)) \
154 { \ 153 { \
155 if (Wcm.cm_losewrap) losecursor (); \ 154 if ((tty)->Wcm->cm_losewrap) losecursor (tty); \
156 else if (AutoWrap) curX = 0, curY++; \ 155 else if (AutoWrap (tty)) curX (tty) = 0, curY (tty)++; \
157 else curX--; \ 156 else curX (tty)--; \
158 } \ 157 } \
159 } 158 }
160 159
161#define losecursor() (curX = -1, curY = -1) 160#define losecursor(tty) (curX(tty) = -1, curY(tty) = -1)
162 161
163extern int cost; 162extern int cost;
164extern int evalcost (); 163extern int evalcost ();
165 164
166extern void cmcheckmagic (); 165#define emacs_tputs(tty, str, affcnt, putc) (current_tty = (tty), tputs (str, affcnt, putc))
167extern int cmputc (); 166
168extern void cmcostinit (); 167extern struct tty_display_info *current_tty;
169extern void cmgoto (); 168extern void cmcheckmagic P_ ((struct tty_display_info *));
170extern void Wcm_clear (); 169extern int cmputc P_ ((int));
171extern int Wcm_init (); 170extern void cmcostinit P_ ((struct tty_display_info *));
171extern void cmgoto P_ ((struct tty_display_info *, int, int));
172extern void Wcm_clear P_ ((struct tty_display_info *));
173extern int Wcm_init P_ ((struct tty_display_info *));
172 174
173/* arch-tag: acc1535a-7136-49d6-b22d-9bc85702251b 175/* arch-tag: acc1535a-7136-49d6-b22d-9bc85702251b
174 (do not change this comment) */ 176 (do not change this comment) */
diff --git a/src/coding.c b/src/coding.c
index 6bb9f8225c9..8dc20ef6a3a 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -351,6 +351,8 @@ encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes)
351#include "coding.h" 351#include "coding.h"
352#include "window.h" 352#include "window.h"
353#include "intervals.h" 353#include "intervals.h"
354#include "frame.h"
355#include "termhooks.h"
354 356
355#else /* not emacs */ 357#else /* not emacs */
356 358
@@ -436,16 +438,10 @@ int inhibit_iso_escape_detection;
436/* Flag to make buffer-file-coding-system inherit from process-coding. */ 438/* Flag to make buffer-file-coding-system inherit from process-coding. */
437int inherit_process_coding_system; 439int inherit_process_coding_system;
438 440
439/* Coding system to be used to encode text for terminal display. */
440struct coding_system terminal_coding;
441
442/* Coding system to be used to encode text for terminal display when 441/* Coding system to be used to encode text for terminal display when
443 terminal coding system is nil. */ 442 terminal coding system is nil. */
444struct coding_system safe_terminal_coding; 443struct coding_system safe_terminal_coding;
445 444
446/* Coding system of what is sent from terminal keyboard. */
447struct coding_system keyboard_coding;
448
449/* Default coding system to be used to write a file. */ 445/* Default coding system to be used to write a file. */
450struct coding_system default_buffer_file_coding; 446struct coding_system default_buffer_file_coding;
451 447
@@ -7368,21 +7364,23 @@ Return the corresponding character code in Big5. */)
7368} 7364}
7369 7365
7370DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_internal, 7366DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_internal,
7371 Sset_terminal_coding_system_internal, 1, 1, 0, 7367 Sset_terminal_coding_system_internal, 1, 2, 0,
7372 doc: /* Internal use only. */) 7368 doc: /* Internal use only. */)
7373 (coding_system) 7369 (coding_system, terminal)
7374 Lisp_Object coding_system; 7370 Lisp_Object coding_system;
7371 Lisp_Object terminal;
7375{ 7372{
7373 struct coding_system *terminal_coding = TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1));
7376 CHECK_SYMBOL (coding_system); 7374 CHECK_SYMBOL (coding_system);
7377 setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding); 7375 setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding);
7378 /* We had better not send unsafe characters to terminal. */ 7376 /* We had better not send unsafe characters to terminal. */
7379 terminal_coding.mode |= CODING_MODE_INHIBIT_UNENCODABLE_CHAR; 7377 terminal_coding->mode |= CODING_MODE_INHIBIT_UNENCODABLE_CHAR;
7380 /* Character composition should be disabled. */ 7378 /* Character composition should be disabled. */
7381 terminal_coding.composing = COMPOSITION_DISABLED; 7379 terminal_coding->composing = COMPOSITION_DISABLED;
7382 /* Error notification should be suppressed. */ 7380 /* Error notification should be suppressed. */
7383 terminal_coding.suppress_error = 1; 7381 terminal_coding->suppress_error = 1;
7384 terminal_coding.src_multibyte = 1; 7382 terminal_coding->src_multibyte = 1;
7385 terminal_coding.dst_multibyte = 0; 7383 terminal_coding->dst_multibyte = 0;
7386 return Qnil; 7384 return Qnil;
7387} 7385}
7388 7386
@@ -7405,32 +7403,42 @@ DEFUN ("set-safe-terminal-coding-system-internal", Fset_safe_terminal_coding_sys
7405} 7403}
7406 7404
7407DEFUN ("terminal-coding-system", Fterminal_coding_system, 7405DEFUN ("terminal-coding-system", Fterminal_coding_system,
7408 Sterminal_coding_system, 0, 0, 0, 7406 Sterminal_coding_system, 0, 1, 0,
7409 doc: /* Return coding system specified for terminal output. */) 7407 doc: /* Return coding system specified for terminal output on the given terminal.
7410 () 7408TERMINAL may be a terminal id, a frame, or nil for the selected
7409frame's terminal device. */)
7410 (terminal)
7411 Lisp_Object terminal;
7411{ 7412{
7412 return terminal_coding.symbol; 7413 return TERMINAL_TERMINAL_CODING (get_terminal (terminal, 1))->symbol;
7413} 7414}
7414 7415
7415DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_internal, 7416DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_internal,
7416 Sset_keyboard_coding_system_internal, 1, 1, 0, 7417 Sset_keyboard_coding_system_internal, 1, 2, 0,
7417 doc: /* Internal use only. */) 7418 doc: /* Internal use only. */)
7418 (coding_system) 7419 (coding_system, terminal)
7419 Lisp_Object coding_system; 7420 Lisp_Object coding_system;
7421 Lisp_Object terminal;
7420{ 7422{
7423 struct terminal *t = get_terminal (terminal, 1);
7421 CHECK_SYMBOL (coding_system); 7424 CHECK_SYMBOL (coding_system);
7422 setup_coding_system (Fcheck_coding_system (coding_system), &keyboard_coding); 7425
7426 setup_coding_system (Fcheck_coding_system (coding_system),
7427 TERMINAL_KEYBOARD_CODING (t));
7423 /* Character composition should be disabled. */ 7428 /* Character composition should be disabled. */
7424 keyboard_coding.composing = COMPOSITION_DISABLED; 7429 TERMINAL_KEYBOARD_CODING (t)->composing = COMPOSITION_DISABLED;
7425 return Qnil; 7430 return Qnil;
7426} 7431}
7427 7432
7428DEFUN ("keyboard-coding-system", Fkeyboard_coding_system, 7433DEFUN ("keyboard-coding-system", Fkeyboard_coding_system,
7429 Skeyboard_coding_system, 0, 0, 0, 7434 Skeyboard_coding_system, 0, 1, 0,
7430 doc: /* Return coding system specified for decoding keyboard input. */) 7435 doc: /* Return coding system for decoding keyboard input on TERMINAL.
7431 () 7436TERMINAL may be a terminal id, a frame, or nil for the selected
7437frame's terminal device. */)
7438 (terminal)
7439 Lisp_Object terminal;
7432{ 7440{
7433 return keyboard_coding.symbol; 7441 return TERMINAL_KEYBOARD_CODING (get_terminal (terminal, 1))->symbol;
7434} 7442}
7435 7443
7436 7444
@@ -7693,8 +7701,6 @@ init_coding_once ()
7693 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; 7701 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3;
7694 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; 7702 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer;
7695 7703
7696 setup_coding_system (Qnil, &keyboard_coding);
7697 setup_coding_system (Qnil, &terminal_coding);
7698 setup_coding_system (Qnil, &safe_terminal_coding); 7704 setup_coding_system (Qnil, &safe_terminal_coding);
7699 setup_coding_system (Qnil, &default_buffer_file_coding); 7705 setup_coding_system (Qnil, &default_buffer_file_coding);
7700 7706
diff --git a/src/coding.h b/src/coding.h
index b4e26686229..fc087ccb180 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -696,20 +696,10 @@ extern Lisp_Object Vlocale_coding_system;
696 the subprocess output. */ 696 the subprocess output. */
697extern int inherit_process_coding_system; 697extern int inherit_process_coding_system;
698 698
699/* Coding-system to be used for encoding terminal output. This
700 structure contains information of a coding-system specified by the
701 function `set-terminal-coding-system'. */
702extern struct coding_system terminal_coding;
703
704/* Coding system to be used to encode text for terminal display when 699/* Coding system to be used to encode text for terminal display when
705 terminal coding system is nil. */ 700 terminal coding system is nil. */
706extern struct coding_system safe_terminal_coding; 701extern struct coding_system safe_terminal_coding;
707 702
708/* Coding-system of what is sent from terminal keyboard. This
709 structure contains information of a coding-system specified by the
710 function `set-keyboard-coding-system'. */
711extern struct coding_system keyboard_coding;
712
713/* Default coding system to be used to write a file. */ 703/* Default coding system to be used to write a file. */
714extern struct coding_system default_buffer_file_coding; 704extern struct coding_system default_buffer_file_coding;
715 705
diff --git a/src/config.in b/src/config.in
index 43c1efac14f..71b4af0c839 100644
--- a/src/config.in
+++ b/src/config.in
@@ -926,6 +926,12 @@ Boston, MA 02110-1301, USA. */
926#define HAVE_MOUSE 926#define HAVE_MOUSE
927#endif 927#endif
928 928
929/* Multi-tty support relies on MULTI_KBOARD. It seems safe to turn it
930 on unconditionally. */
931#ifndef MULTI_KBOARD
932#define MULTI_KBOARD
933#endif
934
929/* Define USER_FULL_NAME to return a string 935/* Define USER_FULL_NAME to return a string
930 that is the user's full name. 936 that is the user's full name.
931 It can assume that the variable `pw' 937 It can assume that the variable `pw'
diff --git a/src/data.c b/src/data.c
index 49e1570c4c2..2f682450a16 100644
--- a/src/data.c
+++ b/src/data.c
@@ -30,6 +30,7 @@ Boston, MA 02110-1301, USA. */
30#include "keyboard.h" 30#include "keyboard.h"
31#include "frame.h" 31#include "frame.h"
32#include "syssignal.h" 32#include "syssignal.h"
33#include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
33 34
34#ifdef STDC_HEADERS 35#ifdef STDC_HEADERS
35#include <float.h> 36#include <float.h>
@@ -858,7 +859,18 @@ do_symval_forwarding (valcontents)
858 859
859 case Lisp_Misc_Kboard_Objfwd: 860 case Lisp_Misc_Kboard_Objfwd:
860 offset = XKBOARD_OBJFWD (valcontents)->offset; 861 offset = XKBOARD_OBJFWD (valcontents)->offset;
861 return *(Lisp_Object *)(offset + (char *)current_kboard); 862 /* We used to simply use current_kboard here, but from Lisp
863 code, it's value is often unexpected. It seems nicer to
864 allow constructions like this to work as intuitively expected:
865
866 (with-selected-frame frame
867 (define-key local-function-map "\eOP" [f1]))
868
869 On the other hand, this affects the semantics of
870 last-command and real-last-command, and people may rely on
871 that. I took a quick look at the Lisp codebase, and I
872 don't think anything will break. --lorentey */
873 return *(Lisp_Object *)(offset + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
862 } 874 }
863 return valcontents; 875 return valcontents;
864} 876}
@@ -946,7 +958,7 @@ store_symval_forwarding (symbol, valcontents, newval, buf)
946 958
947 case Lisp_Misc_Kboard_Objfwd: 959 case Lisp_Misc_Kboard_Objfwd:
948 { 960 {
949 char *base = (char *) current_kboard; 961 char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ());
950 char *p = base + XKBOARD_OBJFWD (valcontents)->offset; 962 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
951 *(Lisp_Object *) p = newval; 963 *(Lisp_Object *) p = newval;
952 } 964 }
@@ -1092,7 +1104,7 @@ find_symbol_value (symbol)
1092 1104
1093 case Lisp_Misc_Kboard_Objfwd: 1105 case Lisp_Misc_Kboard_Objfwd:
1094 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset 1106 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
1095 + (char *)current_kboard); 1107 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
1096 } 1108 }
1097 } 1109 }
1098 1110
@@ -1853,6 +1865,51 @@ If the current binding is global (the default), the value is nil. */)
1853 1865
1854 return Qnil; 1866 return Qnil;
1855} 1867}
1868
1869/* This code is disabled now that we use the selected frame to return
1870 keyboard-local-values. */
1871#if 0
1872extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
1873
1874DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
1875 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
1876If SYMBOL is not a terminal-local variable, then return its normal
1877value, like `symbol-value'.
1878
1879TERMINAL may be a terminal id, a frame, or nil (meaning the
1880selected frame's terminal device). */)
1881 (symbol, terminal)
1882 Lisp_Object symbol;
1883 Lisp_Object terminal;
1884{
1885 Lisp_Object result;
1886 struct terminal *t = get_terminal (terminal, 1);
1887 push_kboard (t->kboard);
1888 result = Fsymbol_value (symbol);
1889 pop_kboard ();
1890 return result;
1891}
1892
1893DEFUN ("set-terminal-local-value", Fset_terminal_local_value, Sset_terminal_local_value, 3, 3, 0,
1894 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
1895If VARIABLE is not a terminal-local variable, then set its normal
1896binding, like `set'.
1897
1898TERMINAL may be a terminal id, a frame, or nil (meaning the
1899selected frame's terminal device). */)
1900 (symbol, terminal, value)
1901 Lisp_Object symbol;
1902 Lisp_Object terminal;
1903 Lisp_Object value;
1904{
1905 Lisp_Object result;
1906 struct terminal *t = get_terminal (terminal, 1);
1907 push_kboard (d->kboard);
1908 result = Fset (symbol, value);
1909 pop_kboard ();
1910 return result;
1911}
1912#endif
1856 1913
1857/* Find the function at the end of a chain of symbol function indirections. */ 1914/* Find the function at the end of a chain of symbol function indirections. */
1858 1915
@@ -3310,6 +3367,10 @@ syms_of_data ()
3310 defsubr (&Slocal_variable_p); 3367 defsubr (&Slocal_variable_p);
3311 defsubr (&Slocal_variable_if_set_p); 3368 defsubr (&Slocal_variable_if_set_p);
3312 defsubr (&Svariable_binding_locus); 3369 defsubr (&Svariable_binding_locus);
3370#if 0 /* XXX Remove this. --lorentey */
3371 defsubr (&Sterminal_local_value);
3372 defsubr (&Sset_terminal_local_value);
3373#endif
3313 defsubr (&Saref); 3374 defsubr (&Saref);
3314 defsubr (&Saset); 3375 defsubr (&Saset);
3315 defsubr (&Snumber_to_string); 3376 defsubr (&Snumber_to_string);
diff --git a/src/dispextern.h b/src/dispextern.h
index 2dd0d91b111..4c3bd56e121 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1029,13 +1029,8 @@ extern int fonts_changed_p;
1029 1029
1030extern struct glyph space_glyph; 1030extern struct glyph space_glyph;
1031 1031
1032/* Frame being updated by update_window/update_frame. */
1033
1034extern struct frame *updating_frame;
1035
1036/* Window being updated by update_window. This is non-null as long as 1032/* Window being updated by update_window. This is non-null as long as
1037 update_window has not finished, and null otherwise. It's role is 1033 update_window has not finished, and null otherwise. */
1038 analogous to updating_frame. */
1039 1034
1040extern struct window *updated_window; 1035extern struct window *updated_window;
1041 1036
@@ -1355,7 +1350,7 @@ struct glyph_string
1355 DESCENT = FONT->descent 1350 DESCENT = FONT->descent
1356 HEIGHT = FONT_HEIGHT (FONT) 1351 HEIGHT = FONT_HEIGHT (FONT)
1357 F_DESCENT = (FRAME_FONT (F)->descent 1352 F_DESCENT = (FRAME_FONT (F)->descent
1358 - F->output_data.x->baseline_offset) 1353 - F->terminal->output_data.x->baseline_offset)
1359 F_HEIGHT = FRAME_LINE_HEIGHT (F) 1354 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1360*/ 1355*/
1361 1356
@@ -2184,16 +2179,16 @@ struct it
2184/* Call produce_glyphs or produce_glyphs_hook, if set. Shortcut to 2179/* Call produce_glyphs or produce_glyphs_hook, if set. Shortcut to
2185 avoid the function call overhead. */ 2180 avoid the function call overhead. */
2186 2181
2187#define PRODUCE_GLYPHS(IT) \ 2182#define PRODUCE_GLYPHS(IT) \
2188 do { \ 2183 do { \
2189 extern int inhibit_free_realized_faces; \ 2184 extern int inhibit_free_realized_faces; \
2190 if (rif != NULL) \ 2185 if (FRAME_RIF ((IT)->f) != NULL) \
2191 rif->produce_glyphs ((IT)); \ 2186 FRAME_RIF ((IT)->f)->produce_glyphs ((IT)); \
2192 else \ 2187 else \
2193 produce_glyphs ((IT)); \ 2188 produce_glyphs ((IT)); \
2194 if ((IT)->glyph_row != NULL) \ 2189 if ((IT)->glyph_row != NULL) \
2195 inhibit_free_realized_faces = 1; \ 2190 inhibit_free_realized_faces = 1; \
2196 } while (0) 2191 } while (0)
2197 2192
2198/* Bit-flags indicating what operation move_it_to should perform. */ 2193/* Bit-flags indicating what operation move_it_to should perform. */
2199 2194
@@ -2367,10 +2362,6 @@ struct redisplay_interface
2367#endif /* HAVE_WINDOW_SYSTEM */ 2362#endif /* HAVE_WINDOW_SYSTEM */
2368}; 2363};
2369 2364
2370/* The current interface for window-based redisplay. */
2371
2372extern struct redisplay_interface *rif;
2373
2374 2365
2375/*********************************************************************** 2366/***********************************************************************
2376 Images 2367 Images
@@ -2667,8 +2658,6 @@ void init_iterator_to_row_start P_ ((struct it *, struct window *,
2667 struct glyph_row *)); 2658 struct glyph_row *));
2668int get_next_display_element P_ ((struct it *)); 2659int get_next_display_element P_ ((struct it *));
2669void set_iterator_to_next P_ ((struct it *, int)); 2660void set_iterator_to_next P_ ((struct it *, int));
2670void produce_glyphs P_ ((struct it *));
2671void produce_special_glyphs P_ ((struct it *, enum display_element_type));
2672void start_display P_ ((struct it *, struct window *, struct text_pos)); 2661void start_display P_ ((struct it *, struct window *, struct text_pos));
2673void move_it_to P_ ((struct it *, int, int, int, int, int)); 2662void move_it_to P_ ((struct it *, int, int, int, int, int));
2674void move_it_vertically P_ ((struct it *, int)); 2663void move_it_vertically P_ ((struct it *, int));
@@ -2815,11 +2804,11 @@ int image_ascent P_ ((struct image *, struct face *, struct glyph_slice *));
2815 2804
2816/* Defined in sysdep.c */ 2805/* Defined in sysdep.c */
2817 2806
2818void get_frame_size P_ ((int *, int *)); 2807void get_tty_size P_ ((int, int *, int *));
2819void request_sigio P_ ((void)); 2808void request_sigio P_ ((void));
2820void unrequest_sigio P_ ((void)); 2809void unrequest_sigio P_ ((void));
2821int tabs_safe_p P_ ((void)); 2810int tabs_safe_p P_ ((int));
2822void init_baud_rate P_ ((void)); 2811void init_baud_rate P_ ((int));
2823void init_sigio P_ ((int)); 2812void init_sigio P_ ((int));
2824 2813
2825/* Defined in xfaces.c */ 2814/* Defined in xfaces.c */
@@ -2958,8 +2947,6 @@ void clear_glyph_row P_ ((struct glyph_row *));
2958void prepare_desired_row P_ ((struct glyph_row *)); 2947void prepare_desired_row P_ ((struct glyph_row *));
2959int line_hash_code P_ ((struct glyph_row *)); 2948int line_hash_code P_ ((struct glyph_row *));
2960void set_window_update_flags P_ ((struct window *, int)); 2949void set_window_update_flags P_ ((struct window *, int));
2961void write_glyphs P_ ((struct glyph *, int));
2962void insert_glyphs P_ ((struct glyph *, int));
2963void redraw_frame P_ ((struct frame *)); 2950void redraw_frame P_ ((struct frame *));
2964void redraw_garbaged_frames P_ ((void)); 2951void redraw_garbaged_frames P_ ((void));
2965int scroll_cost P_ ((struct frame *, int, int, int)); 2952int scroll_cost P_ ((struct frame *, int, int, int));
@@ -2976,31 +2963,44 @@ void syms_of_display P_ ((void));
2976extern Lisp_Object Qredisplay_dont_pause; 2963extern Lisp_Object Qredisplay_dont_pause;
2977GLYPH spec_glyph_lookup_face P_ ((struct window *, GLYPH)); 2964GLYPH spec_glyph_lookup_face P_ ((struct window *, GLYPH));
2978 2965
2979/* Defined in term.c */ 2966/* Defined in terminal.c */
2980 2967
2981extern void ring_bell P_ ((void)); 2968extern void ring_bell P_ ((struct frame *));
2982extern void set_terminal_modes P_ ((void));
2983extern void reset_terminal_modes P_ ((void));
2984extern void update_begin P_ ((struct frame *)); 2969extern void update_begin P_ ((struct frame *));
2985extern void update_end P_ ((struct frame *)); 2970extern void update_end P_ ((struct frame *));
2986extern void set_terminal_window P_ ((int)); 2971extern void set_terminal_window P_ ((struct frame *, int));
2987extern void set_scroll_region P_ ((int, int)); 2972extern void cursor_to P_ ((struct frame *, int, int));
2988extern void turn_off_insert P_ ((void)); 2973extern void raw_cursor_to P_ ((struct frame *, int, int));
2989extern void turn_off_highlight P_ ((void)); 2974extern void clear_to_end P_ ((struct frame *));
2990extern void background_highlight P_ ((void)); 2975extern void clear_frame P_ ((struct frame *));
2991extern void clear_frame P_ ((void)); 2976extern void clear_end_of_line P_ ((struct frame *, int));
2992extern void clear_end_of_line P_ ((int)); 2977extern void write_glyphs P_ ((struct frame *, struct glyph *, int));
2993extern void clear_end_of_line_raw P_ ((int)); 2978extern void insert_glyphs P_ ((struct frame *, struct glyph *, int));
2994extern void delete_glyphs P_ ((int)); 2979extern void delete_glyphs P_ ((struct frame *, int));
2995extern void ins_del_lines P_ ((int, int)); 2980extern void ins_del_lines P_ ((struct frame *, int, int));
2981
2982extern struct terminal *init_initial_terminal P_ ((void));
2983
2984
2985/* Defined in term.c */
2986
2987extern void tty_set_terminal_modes P_ ((struct terminal *));
2988extern void tty_reset_terminal_modes P_ ((struct terminal *));
2989extern void tty_turn_off_insert P_ ((struct tty_display_info *));
2990extern void tty_turn_off_highlight P_ ((struct tty_display_info *));
2996extern int string_cost P_ ((char *)); 2991extern int string_cost P_ ((char *));
2997extern int per_line_cost P_ ((char *)); 2992extern int per_line_cost P_ ((char *));
2998extern void calculate_costs P_ ((struct frame *)); 2993extern void calculate_costs P_ ((struct frame *));
2994extern void produce_glyphs P_ ((struct it *));
2995extern void produce_special_glyphs P_ ((struct it *, enum display_element_type));
2996extern int tty_capable_p P_ ((struct tty_display_info *, unsigned, unsigned long, unsigned long));
2999extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object)); 2997extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object));
3000extern void tty_setup_colors P_ ((int)); 2998extern struct terminal *get_tty_terminal P_ ((Lisp_Object, int));
3001extern void term_init P_ ((char *)); 2999extern struct terminal *get_named_tty P_ ((char *));
3002void cursor_to P_ ((int, int)); 3000EXFUN (Ftty_type, 1);
3003extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long)); 3001extern void create_tty_output P_ ((struct frame *));
3002extern struct terminal *init_tty P_ ((char *, char *, int));
3003
3004 3004
3005/* Defined in scroll.c */ 3005/* Defined in scroll.c */
3006 3006
diff --git a/src/dispnew.c b/src/dispnew.c
index bd63c473cf8..86e73da3848 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -32,7 +32,6 @@ Boston, MA 02110-1301, USA. */
32#include "lisp.h" 32#include "lisp.h"
33#include "termchar.h" 33#include "termchar.h"
34#include "termopts.h" 34#include "termopts.h"
35#include "termhooks.h"
36/* cm.h must come after dispextern.h on Windows. */ 35/* cm.h must come after dispextern.h on Windows. */
37#include "dispextern.h" 36#include "dispextern.h"
38#include "cm.h" 37#include "cm.h"
@@ -40,6 +39,7 @@ Boston, MA 02110-1301, USA. */
40#include "charset.h" 39#include "charset.h"
41#include "keyboard.h" 40#include "keyboard.h"
42#include "frame.h" 41#include "frame.h"
42#include "termhooks.h"
43#include "window.h" 43#include "window.h"
44#include "commands.h" 44#include "commands.h"
45#include "disptab.h" 45#include "disptab.h"
@@ -238,9 +238,9 @@ int inverse_video;
238EMACS_INT baud_rate; 238EMACS_INT baud_rate;
239 239
240/* Either nil or a symbol naming the window system under which Emacs 240/* Either nil or a symbol naming the window system under which Emacs
241 is running. */ 241 creates the first frame. */
242 242
243Lisp_Object Vwindow_system; 243Lisp_Object Vinitial_window_system;
244 244
245/* Version number of X windows: 10, 11 or nil. */ 245/* Version number of X windows: 10, 11 or nil. */
246 246
@@ -282,14 +282,6 @@ Lisp_Object selected_frame;
282 282
283struct frame *last_nonminibuf_frame; 283struct frame *last_nonminibuf_frame;
284 284
285/* Stdio stream being used for copy of all output. */
286
287FILE *termscript;
288
289/* Structure for info on cursor positioning. */
290
291struct cm Wcm;
292
293/* 1 means SIGWINCH happened when not safe. */ 285/* 1 means SIGWINCH happened when not safe. */
294 286
295int delayed_size_change; 287int delayed_size_change;
@@ -328,11 +320,6 @@ int glyph_pool_count;
328 320
329static struct frame *frame_matrix_frame; 321static struct frame *frame_matrix_frame;
330 322
331/* Current interface for window-based redisplay. Set from init_xterm.
332 A null value means we are not using window-based redisplay. */
333
334struct redisplay_interface *rif;
335
336/* Non-zero means that fonts have been loaded since the last glyph 323/* Non-zero means that fonts have been loaded since the last glyph
337 matrix adjustments. Redisplay must stop, and glyph matrices must 324 matrix adjustments. Redisplay must stop, and glyph matrices must
338 be adjusted when this flag becomes non-zero during display. The 325 be adjusted when this flag becomes non-zero during display. The
@@ -1423,7 +1410,7 @@ line_hash_code (row)
1423 { 1410 {
1424 int c = glyph->u.ch; 1411 int c = glyph->u.ch;
1425 int face_id = glyph->face_id; 1412 int face_id = glyph->face_id;
1426 if (must_write_spaces) 1413 if (FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1427 c -= SPACEGLYPH; 1414 c -= SPACEGLYPH;
1428 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c; 1415 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c;
1429 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id; 1416 hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + face_id;
@@ -1455,7 +1442,7 @@ line_draw_cost (matrix, vpos)
1455 int glyph_table_len = GLYPH_TABLE_LENGTH; 1442 int glyph_table_len = GLYPH_TABLE_LENGTH;
1456 1443
1457 /* Ignore trailing and leading spaces if we can. */ 1444 /* Ignore trailing and leading spaces if we can. */
1458 if (!must_write_spaces) 1445 if (!FRAME_MUST_WRITE_SPACES (SELECTED_FRAME ())) /* XXX Is SELECTED_FRAME OK here? */
1459 { 1446 {
1460 /* Skip from the end over trailing spaces. */ 1447 /* Skip from the end over trailing spaces. */
1461 while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1))) 1448 while (end > beg && CHAR_GLYPH_SPACE_P (*(end - 1)))
@@ -1671,8 +1658,10 @@ realloc_glyph_pool (pool, matrix_dim)
1671#if GLYPH_DEBUG 1658#if GLYPH_DEBUG
1672 1659
1673 1660
1674/* Flush standard output. This is sometimes useful to call from 1661/* Flush standard output. This is sometimes useful to call from the debugger.
1675 the debugger. */ 1662 XXX Maybe this should be changed to flush the current terminal instead of
1663 stdout.
1664*/
1676 1665
1677void 1666void
1678flush_stdout () 1667flush_stdout ()
@@ -3393,12 +3382,15 @@ DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0,
3393 return Qnil; 3382 return Qnil;
3394 3383
3395 update_begin (f); 3384 update_begin (f);
3385#ifdef MSDOS
3396 if (FRAME_MSDOS_P (f)) 3386 if (FRAME_MSDOS_P (f))
3397 set_terminal_modes (); 3387 set_terminal_modes (FRAME_TERMINAL (f));
3398 clear_frame (); 3388#endif
3389 clear_frame (f);
3399 clear_current_matrices (f); 3390 clear_current_matrices (f);
3400 update_end (f); 3391 update_end (f);
3401 fflush (stdout); 3392 if (FRAME_TERMCAP_P (f))
3393 fflush (FRAME_TTY (f)->output);
3402 windows_or_buffers_changed++; 3394 windows_or_buffers_changed++;
3403 /* Mark all windows as inaccurate, so that every window will have 3395 /* Mark all windows as inaccurate, so that every window will have
3404 its redisplay done. */ 3396 its redisplay done. */
@@ -3539,7 +3531,7 @@ direct_output_for_insert (g)
3539 3531
3540 /* If we can't insert glyphs, we can use this method only 3532 /* If we can't insert glyphs, we can use this method only
3541 at the end of a line. */ 3533 at the end of a line. */
3542 if (!char_ins_del_ok) 3534 if (!FRAME_CHAR_INS_DEL_OK (f))
3543 if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n') 3535 if (PT != ZV && FETCH_BYTE (PT_BYTE) != '\n')
3544 return 0; 3536 return 0;
3545 3537
@@ -3689,24 +3681,24 @@ direct_output_for_insert (g)
3689 updated_row = glyph_row; 3681 updated_row = glyph_row;
3690 updated_area = TEXT_AREA; 3682 updated_area = TEXT_AREA;
3691 update_begin (f); 3683 update_begin (f);
3692 if (rif) 3684 if (FRAME_RIF (f))
3693 { 3685 {
3694 rif->update_window_begin_hook (w); 3686 FRAME_RIF (f)->update_window_begin_hook (w);
3695 3687
3696 if (glyphs == end - n 3688 if (glyphs == end - n
3697 /* In front of a space added by append_space. */ 3689 /* In front of a space added by append_space. */
3698 || (glyphs == end - n - 1 3690 || (glyphs == end - n - 1
3699 && (end - n)->charpos <= 0)) 3691 && (end - n)->charpos <= 0))
3700 rif->write_glyphs (glyphs, n); 3692 FRAME_RIF (f)->write_glyphs (glyphs, n);
3701 else 3693 else
3702 rif->insert_glyphs (glyphs, n); 3694 FRAME_RIF (f)->insert_glyphs (glyphs, n);
3703 } 3695 }
3704 else 3696 else
3705 { 3697 {
3706 if (glyphs == end - n) 3698 if (glyphs == end - n)
3707 write_glyphs (glyphs, n); 3699 write_glyphs (f, glyphs, n);
3708 else 3700 else
3709 insert_glyphs (glyphs, n); 3701 insert_glyphs (f, glyphs, n);
3710 } 3702 }
3711 3703
3712 w->cursor.hpos += n; 3704 w->cursor.hpos += n;
@@ -3719,8 +3711,8 @@ direct_output_for_insert (g)
3719 a frame matrix is used, cursor_to expects frame coordinates, 3711 a frame matrix is used, cursor_to expects frame coordinates,
3720 and the X and Y parameters are not used. */ 3712 and the X and Y parameters are not used. */
3721 if (window_redisplay_p) 3713 if (window_redisplay_p)
3722 rif->cursor_to (w->cursor.vpos, w->cursor.hpos, 3714 FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos,
3723 w->cursor.y, w->cursor.x); 3715 w->cursor.y, w->cursor.x);
3724 else 3716 else
3725 { 3717 {
3726 int x, y; 3718 int x, y;
@@ -3729,18 +3721,19 @@ direct_output_for_insert (g)
3729 ? XFASTINT (w->left_margin_cols) 3721 ? XFASTINT (w->left_margin_cols)
3730 : 0)); 3722 : 0));
3731 y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos); 3723 y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
3732 cursor_to (y, x); 3724 cursor_to (f, y, x);
3733 } 3725 }
3734 3726
3735#ifdef HAVE_WINDOW_SYSTEM 3727#ifdef HAVE_WINDOW_SYSTEM
3736 update_window_fringes (w, 0); 3728 update_window_fringes (w, 0);
3737#endif 3729#endif
3738 3730
3739 if (rif) 3731 if (FRAME_RIF (f))
3740 rif->update_window_end_hook (w, 1, 0); 3732 FRAME_RIF (f)->update_window_end_hook (w, 1, 0);
3741 update_end (f); 3733 update_end (f);
3742 updated_row = NULL; 3734 updated_row = NULL;
3743 fflush (stdout); 3735 if (FRAME_TERMCAP_P (f))
3736 fflush (FRAME_TTY (f)->output);
3744 3737
3745 TRACE ((stderr, "direct output for insert\n")); 3738 TRACE ((stderr, "direct output for insert\n"));
3746 mark_window_display_accurate (it.window, 1); 3739 mark_window_display_accurate (it.window, 1);
@@ -3818,8 +3811,8 @@ direct_output_forward_char (n)
3818 && w->cursor.hpos < w->desired_matrix->matrix_w); 3811 && w->cursor.hpos < w->desired_matrix->matrix_w);
3819 3812
3820 if (FRAME_WINDOW_P (f)) 3813 if (FRAME_WINDOW_P (f))
3821 rif->cursor_to (w->cursor.vpos, w->cursor.hpos, 3814 FRAME_RIF (f)->cursor_to (w->cursor.vpos, w->cursor.hpos,
3822 w->cursor.y, w->cursor.x); 3815 w->cursor.y, w->cursor.x);
3823 else 3816 else
3824 { 3817 {
3825 int x, y; 3818 int x, y;
@@ -3828,10 +3821,11 @@ direct_output_forward_char (n)
3828 ? XFASTINT (w->left_margin_cols) 3821 ? XFASTINT (w->left_margin_cols)
3829 : 0)); 3822 : 0));
3830 y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos); 3823 y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
3831 cursor_to (y, x); 3824 cursor_to (f, y, x);
3832 } 3825 }
3833 3826
3834 fflush (stdout); 3827 if (FRAME_TERMCAP_P (f))
3828 fflush (FRAME_TTY (f)->output);
3835 redisplay_performed_directly_p = 1; 3829 redisplay_performed_directly_p = 1;
3836 return 1; 3830 return 1;
3837} 3831}
@@ -3930,14 +3924,14 @@ update_frame (f, force_p, inhibit_hairy_id_p)
3930 update_end (f); 3924 update_end (f);
3931 3925
3932 /* This flush is a performance bottleneck under X, 3926 /* This flush is a performance bottleneck under X,
3933 and it doesn't seem to be necessary anyway (in general). 3927 and it doesn't seem to be necessary anyway (in general).
3934 It is necessary when resizing the window with the mouse, or 3928 It is necessary when resizing the window with the mouse, or
3935 at least the fringes are not redrawn in a timely manner. ++kfs */ 3929 at least the fringes are not redrawn in a timely manner. ++kfs */
3936 if (f->force_flush_display_p) 3930 if (f->force_flush_display_p)
3937 { 3931 {
3938 rif->flush_display (f); 3932 FRAME_RIF (f)->flush_display (f);
3939 f->force_flush_display_p = 0; 3933 f->force_flush_display_p = 0;
3940 } 3934 }
3941 } 3935 }
3942 else 3936 else
3943 { 3937 {
@@ -3953,9 +3947,12 @@ update_frame (f, force_p, inhibit_hairy_id_p)
3953 paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p); 3947 paused_p = update_frame_1 (f, force_p, inhibit_hairy_id_p);
3954 update_end (f); 3948 update_end (f);
3955 3949
3956 if (termscript) 3950 if (FRAME_TERMCAP_P (f))
3957 fflush (termscript); 3951 {
3958 fflush (stdout); 3952 if (FRAME_TTY (f)->termscript)
3953 fflush (FRAME_TTY (f)->termscript);
3954 fflush (FRAME_TTY (f)->output);
3955 }
3959 3956
3960 /* Check window matrices for lost pointers. */ 3957 /* Check window matrices for lost pointers. */
3961#if GLYPH_DEBUG 3958#if GLYPH_DEBUG
@@ -4060,7 +4057,8 @@ redraw_overlapped_rows (w, yb)
4060 int yb; 4057 int yb;
4061{ 4058{
4062 int i; 4059 int i;
4063 4060 struct frame *f = XFRAME (WINDOW_FRAME (w));
4061
4064 /* If rows overlapping others have been changed, the rows being 4062 /* If rows overlapping others have been changed, the rows being
4065 overlapped have to be redrawn. This won't draw lines that have 4063 overlapped have to be redrawn. This won't draw lines that have
4066 already been drawn in update_window_line because overlapped_p in 4064 already been drawn in update_window_line because overlapped_p in
@@ -4083,10 +4081,12 @@ redraw_overlapped_rows (w, yb)
4083 { 4081 {
4084 updated_row = row; 4082 updated_row = row;
4085 updated_area = area; 4083 updated_area = area;
4086 rif->cursor_to (i, 0, row->y, area == TEXT_AREA ? row->x : 0); 4084 FRAME_RIF (f)->cursor_to (i, 0, row->y,
4085 area == TEXT_AREA ? row->x : 0);
4087 if (row->used[area]) 4086 if (row->used[area])
4088 rif->write_glyphs (row->glyphs[area], row->used[area]); 4087 FRAME_RIF (f)->write_glyphs (row->glyphs[area],
4089 rif->clear_end_of_line (-1); 4088 row->used[area]);
4089 FRAME_RIF (f)->clear_end_of_line (-1);
4090 } 4090 }
4091 4091
4092 row->overlapped_p = 0; 4092 row->overlapped_p = 0;
@@ -4108,7 +4108,8 @@ redraw_overlapping_rows (w, yb)
4108{ 4108{
4109 int i, bottom_y; 4109 int i, bottom_y;
4110 struct glyph_row *row; 4110 struct glyph_row *row;
4111 4111 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4112
4112 for (i = 0; i < w->current_matrix->nrows; ++i) 4113 for (i = 0; i < w->current_matrix->nrows; ++i)
4113 { 4114 {
4114 row = w->current_matrix->rows + i; 4115 row = w->current_matrix->rows + i;
@@ -4199,10 +4200,10 @@ update_window (w, force_p)
4199#endif 4200#endif
4200 extern int input_pending; 4201 extern int input_pending;
4201 extern Lisp_Object do_mouse_tracking; 4202 extern Lisp_Object do_mouse_tracking;
4203 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4202#if GLYPH_DEBUG 4204#if GLYPH_DEBUG
4203 /* Check that W's frame doesn't have glyph matrices. */ 4205 /* Check that W's frame doesn't have glyph matrices. */
4204 xassert (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w)))); 4206 xassert (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w))));
4205 xassert (updating_frame != NULL);
4206#endif 4207#endif
4207 4208
4208 /* Check pending input the first time so that we can quickly return. */ 4209 /* Check pending input the first time so that we can quickly return. */
@@ -4387,6 +4388,7 @@ update_marginal_area (w, area, vpos)
4387 int area, vpos; 4388 int area, vpos;
4388{ 4389{
4389 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); 4390 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos);
4391 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4390 4392
4391 /* Let functions in xterm.c know what area subsequent X positions 4393 /* Let functions in xterm.c know what area subsequent X positions
4392 will be relative to. */ 4394 will be relative to. */
@@ -4412,6 +4414,7 @@ update_text_area (w, vpos)
4412{ 4414{
4413 struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos); 4415 struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos);
4414 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); 4416 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos);
4417 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4415 int changed_p = 0; 4418 int changed_p = 0;
4416 4419
4417 /* Let functions in xterm.c know what area subsequent X positions 4420 /* Let functions in xterm.c know what area subsequent X positions
@@ -4647,6 +4650,7 @@ update_window_line (w, vpos, mouse_face_overwritten_p)
4647{ 4650{
4648 struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos); 4651 struct glyph_row *current_row = MATRIX_ROW (w->current_matrix, vpos);
4649 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos); 4652 struct glyph_row *desired_row = MATRIX_ROW (w->desired_matrix, vpos);
4653 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4650 int changed_p = 0; 4654 int changed_p = 0;
4651 4655
4652 /* Set the row being updated. This is important to let xterm.c 4656 /* Set the row being updated. This is important to let xterm.c
@@ -4715,6 +4719,7 @@ set_window_cursor_after_update (w)
4715 struct window *w; 4719 struct window *w;
4716{ 4720{
4717 struct frame *f = XFRAME (w->frame); 4721 struct frame *f = XFRAME (w->frame);
4722 struct redisplay_interface *rif = FRAME_RIF (f);
4718 int cx, cy, vpos, hpos; 4723 int cx, cy, vpos, hpos;
4719 4724
4720 /* Not intended for frame matrix updates. */ 4725 /* Not intended for frame matrix updates. */
@@ -4938,6 +4943,7 @@ scrolling_window (w, header_line_p)
4938 int i, j, first_old, first_new, last_old, last_new; 4943 int i, j, first_old, first_new, last_old, last_new;
4939 int nruns, nbytes, n, run_idx; 4944 int nruns, nbytes, n, run_idx;
4940 struct row_entry *entry; 4945 struct row_entry *entry;
4946 struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w)));
4941 4947
4942 /* Skip over rows equal at the start. */ 4948 /* Skip over rows equal at the start. */
4943 for (i = header_line_p ? 1 : 0; i < current_matrix->nrows - 1; ++i) 4949 for (i = header_line_p ? 1 : 0; i < current_matrix->nrows - 1; ++i)
@@ -5262,7 +5268,7 @@ update_frame_1 (f, force_p, inhibit_id_p)
5262#endif 5268#endif
5263 5269
5264 /* If we cannot insert/delete lines, it's no use trying it. */ 5270 /* If we cannot insert/delete lines, it's no use trying it. */
5265 if (!line_ins_del_ok) 5271 if (!FRAME_LINE_INS_DEL_OK (f))
5266 inhibit_id_p = 1; 5272 inhibit_id_p = 1;
5267 5273
5268 /* See if any of the desired lines are enabled; don't compute for 5274 /* See if any of the desired lines are enabled; don't compute for
@@ -5290,18 +5296,18 @@ update_frame_1 (f, force_p, inhibit_id_p)
5290 Also flush out if likely to have more than 1k buffered 5296 Also flush out if likely to have more than 1k buffered
5291 otherwise. I'm told that some telnet connections get 5297 otherwise. I'm told that some telnet connections get
5292 really screwed by more than 1k output at once. */ 5298 really screwed by more than 1k output at once. */
5293 int outq = PENDING_OUTPUT_COUNT (stdout); 5299 int outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f)->output);
5294 if (outq > 900 5300 if (outq > 900
5295 || (outq > 20 && ((i - 1) % preempt_count == 0))) 5301 || (outq > 20 && ((i - 1) % preempt_count == 0)))
5296 { 5302 {
5297 fflush (stdout); 5303 fflush (FRAME_TTY (f)->output);
5298 if (preempt_count == 1) 5304 if (preempt_count == 1)
5299 { 5305 {
5300#ifdef EMACS_OUTQSIZE 5306#ifdef EMACS_OUTQSIZE
5301 if (EMACS_OUTQSIZE (0, &outq) < 0) 5307 if (EMACS_OUTQSIZE (0, &outq) < 0)
5302 /* Probably not a tty. Ignore the error and reset 5308 /* Probably not a tty. Ignore the error and reset
5303 the outq count. */ 5309 the outq count. */
5304 outq = PENDING_OUTPUT_COUNT (stdout); 5310 outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output));
5305#endif 5311#endif
5306 outq *= 10; 5312 outq *= 10;
5307 if (baud_rate <= outq && baud_rate > 0) 5313 if (baud_rate <= outq && baud_rate > 0)
@@ -5404,7 +5410,7 @@ update_frame_1 (f, force_p, inhibit_id_p)
5404 } 5410 }
5405 } 5411 }
5406 5412
5407 cursor_to (row, col); 5413 cursor_to (f, row, col);
5408 } 5414 }
5409 else 5415 else
5410 { 5416 {
@@ -5426,7 +5432,7 @@ update_frame_1 (f, force_p, inhibit_id_p)
5426 x += XFASTINT (w->left_margin_cols); 5432 x += XFASTINT (w->left_margin_cols);
5427 5433
5428 /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */ 5434 /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */
5429 cursor_to (y, x); 5435 cursor_to (f, y, x);
5430 } 5436 }
5431 } 5437 }
5432 } 5438 }
@@ -5495,21 +5501,23 @@ scrolling (frame)
5495 } 5501 }
5496 5502
5497 /* If changed lines are few, don't allow preemption, don't scroll. */ 5503 /* If changed lines are few, don't allow preemption, don't scroll. */
5498 if ((!scroll_region_ok && changed_lines < baud_rate / 2400) 5504 if ((!FRAME_SCROLL_REGION_OK (frame)
5505 && changed_lines < baud_rate / 2400)
5499 || unchanged_at_bottom == FRAME_LINES (frame)) 5506 || unchanged_at_bottom == FRAME_LINES (frame))
5500 return 1; 5507 return 1;
5501 5508
5502 window_size = (FRAME_LINES (frame) - unchanged_at_top 5509 window_size = (FRAME_LINES (frame) - unchanged_at_top
5503 - unchanged_at_bottom); 5510 - unchanged_at_bottom);
5504 5511
5505 if (scroll_region_ok) 5512 if (FRAME_SCROLL_REGION_OK (frame))
5506 free_at_end_vpos -= unchanged_at_bottom; 5513 free_at_end_vpos -= unchanged_at_bottom;
5507 else if (memory_below_frame) 5514 else if (FRAME_MEMORY_BELOW_FRAME (frame))
5508 free_at_end_vpos = -1; 5515 free_at_end_vpos = -1;
5509 5516
5510 /* If large window, fast terminal and few lines in common between 5517 /* If large window, fast terminal and few lines in common between
5511 current frame and desired frame, don't bother with i/d calc. */ 5518 current frame and desired frame, don't bother with i/d calc. */
5512 if (!scroll_region_ok && window_size >= 18 && baud_rate > 2400 5519 if (!FRAME_SCROLL_REGION_OK (frame)
5520 && window_size >= 18 && baud_rate > 2400
5513 && (window_size >= 5521 && (window_size >=
5514 10 * scrolling_max_lines_saved (unchanged_at_top, 5522 10 * scrolling_max_lines_saved (unchanged_at_top,
5515 FRAME_LINES (frame) - unchanged_at_bottom, 5523 FRAME_LINES (frame) - unchanged_at_bottom,
@@ -5589,7 +5597,7 @@ update_frame_line (f, vpos)
5589 struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos); 5597 struct glyph_row *current_row = MATRIX_ROW (current_matrix, vpos);
5590 struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, vpos); 5598 struct glyph_row *desired_row = MATRIX_ROW (desired_matrix, vpos);
5591 int must_write_whole_line_p; 5599 int must_write_whole_line_p;
5592 int write_spaces_p = must_write_spaces; 5600 int write_spaces_p = FRAME_MUST_WRITE_SPACES (f);
5593 int colored_spaces_p = (FACE_FROM_ID (f, DEFAULT_FACE_ID)->background 5601 int colored_spaces_p = (FACE_FROM_ID (f, DEFAULT_FACE_ID)->background
5594 != FACE_TTY_DEFAULT_BG_COLOR); 5602 != FACE_TTY_DEFAULT_BG_COLOR);
5595 5603
@@ -5640,8 +5648,8 @@ update_frame_line (f, vpos)
5640 /* Write the contents of the desired line. */ 5648 /* Write the contents of the desired line. */
5641 if (nlen) 5649 if (nlen)
5642 { 5650 {
5643 cursor_to (vpos, 0); 5651 cursor_to (f, vpos, 0);
5644 write_glyphs (nbody, nlen); 5652 write_glyphs (f, nbody, nlen);
5645 } 5653 }
5646 5654
5647 /* Don't call clear_end_of_line if we already wrote the whole 5655 /* Don't call clear_end_of_line if we already wrote the whole
@@ -5649,13 +5657,13 @@ update_frame_line (f, vpos)
5649 case but in the line below. */ 5657 case but in the line below. */
5650 if (nlen < FRAME_TOTAL_COLS (f)) 5658 if (nlen < FRAME_TOTAL_COLS (f))
5651 { 5659 {
5652 cursor_to (vpos, nlen); 5660 cursor_to (f, vpos, nlen);
5653 clear_end_of_line (FRAME_TOTAL_COLS (f)); 5661 clear_end_of_line (f, FRAME_TOTAL_COLS (f));
5654 } 5662 }
5655 else 5663 else
5656 /* Make sure we are in the right row, otherwise cursor movement 5664 /* Make sure we are in the right row, otherwise cursor movement
5657 with cmgoto might use `ch' in the wrong row. */ 5665 with cmgoto might use `ch' in the wrong row. */
5658 cursor_to (vpos, 0); 5666 cursor_to (f, vpos, 0);
5659 5667
5660 make_current (desired_matrix, current_matrix, vpos); 5668 make_current (desired_matrix, current_matrix, vpos);
5661 return; 5669 return;
@@ -5668,7 +5676,7 @@ update_frame_line (f, vpos)
5668 nlen--; 5676 nlen--;
5669 5677
5670 /* If there's no i/d char, quickly do the best we can without it. */ 5678 /* If there's no i/d char, quickly do the best we can without it. */
5671 if (!char_ins_del_ok) 5679 if (!FRAME_CHAR_INS_DEL_OK (f))
5672 { 5680 {
5673 int i, j; 5681 int i, j;
5674 5682
@@ -5687,8 +5695,8 @@ update_frame_line (f, vpos)
5687 ++j; 5695 ++j;
5688 5696
5689 /* Output this run of non-matching chars. */ 5697 /* Output this run of non-matching chars. */
5690 cursor_to (vpos, i); 5698 cursor_to (f, vpos, i);
5691 write_glyphs (nbody + i, j - i); 5699 write_glyphs (f, nbody + i, j - i);
5692 i = j - 1; 5700 i = j - 1;
5693 5701
5694 /* Now find the next non-match. */ 5702 /* Now find the next non-match. */
@@ -5698,8 +5706,8 @@ update_frame_line (f, vpos)
5698 /* Clear the rest of the line, or the non-clear part of it. */ 5706 /* Clear the rest of the line, or the non-clear part of it. */
5699 if (olen > nlen) 5707 if (olen > nlen)
5700 { 5708 {
5701 cursor_to (vpos, nlen); 5709 cursor_to (f, vpos, nlen);
5702 clear_end_of_line (olen); 5710 clear_end_of_line (f, olen);
5703 } 5711 }
5704 5712
5705 /* Make current row = desired row. */ 5713 /* Make current row = desired row. */
@@ -5721,8 +5729,8 @@ update_frame_line (f, vpos)
5721 5729
5722 if (nlen > nsp) 5730 if (nlen > nsp)
5723 { 5731 {
5724 cursor_to (vpos, nsp); 5732 cursor_to (f, vpos, nsp);
5725 write_glyphs (nbody + nsp, nlen - nsp); 5733 write_glyphs (f, nbody + nsp, nlen - nsp);
5726 } 5734 }
5727 5735
5728 /* Exchange contents between current_frame and new_frame. */ 5736 /* Exchange contents between current_frame and new_frame. */
@@ -5771,7 +5779,8 @@ update_frame_line (f, vpos)
5771 5779
5772 tem = (nlen - nsp) - (olen - osp); 5780 tem = (nlen - nsp) - (olen - osp);
5773 if (endmatch && tem 5781 if (endmatch && tem
5774 && (!char_ins_del_ok || endmatch <= char_ins_del_cost (f)[tem])) 5782 && (!FRAME_CHAR_INS_DEL_OK (f)
5783 || endmatch <= char_ins_del_cost (f)[tem]))
5775 endmatch = 0; 5784 endmatch = 0;
5776 5785
5777 /* nsp - osp is the distance to insert or delete. 5786 /* nsp - osp is the distance to insert or delete.
@@ -5780,7 +5789,7 @@ update_frame_line (f, vpos)
5780 Is it worth it? */ 5789 Is it worth it? */
5781 5790
5782 if (nsp != osp 5791 if (nsp != osp
5783 && (!char_ins_del_ok 5792 && (!FRAME_CHAR_INS_DEL_OK (f)
5784 || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp])) 5793 || begmatch + endmatch <= char_ins_del_cost (f)[nsp - osp]))
5785 { 5794 {
5786 begmatch = 0; 5795 begmatch = 0;
@@ -5793,8 +5802,8 @@ update_frame_line (f, vpos)
5793 5802
5794 if (osp > nsp) 5803 if (osp > nsp)
5795 { 5804 {
5796 cursor_to (vpos, nsp); 5805 cursor_to (f, vpos, nsp);
5797 delete_glyphs (osp - nsp); 5806 delete_glyphs (f, osp - nsp);
5798 } 5807 }
5799 else if (nsp > osp) 5808 else if (nsp > osp)
5800 { 5809 {
@@ -5803,12 +5812,12 @@ update_frame_line (f, vpos)
5803 must delete first to avoid losing data in the insert */ 5812 must delete first to avoid losing data in the insert */
5804 if (endmatch && nlen < olen + nsp - osp) 5813 if (endmatch && nlen < olen + nsp - osp)
5805 { 5814 {
5806 cursor_to (vpos, nlen - endmatch + osp - nsp); 5815 cursor_to (f, vpos, nlen - endmatch + osp - nsp);
5807 delete_glyphs (olen + nsp - osp - nlen); 5816 delete_glyphs (f, olen + nsp - osp - nlen);
5808 olen = nlen - (nsp - osp); 5817 olen = nlen - (nsp - osp);
5809 } 5818 }
5810 cursor_to (vpos, osp); 5819 cursor_to (f, vpos, osp);
5811 insert_glyphs (0, nsp - osp); 5820 insert_glyphs (f, 0, nsp - osp);
5812 } 5821 }
5813 olen += nsp - osp; 5822 olen += nsp - osp;
5814 5823
@@ -5829,8 +5838,8 @@ update_frame_line (f, vpos)
5829 unnecessary cursor movement. */ 5838 unnecessary cursor movement. */
5830 if (nlen - tem > 0) 5839 if (nlen - tem > 0)
5831 { 5840 {
5832 cursor_to (vpos, nsp + begmatch); 5841 cursor_to (f, vpos, nsp + begmatch);
5833 write_glyphs (nbody + nsp + begmatch, nlen - tem); 5842 write_glyphs (f, nbody + nsp + begmatch, nlen - tem);
5834 } 5843 }
5835 } 5844 }
5836 else if (nlen > olen) 5845 else if (nlen > olen)
@@ -5845,27 +5854,27 @@ update_frame_line (f, vpos)
5845 int out = olen - tem; /* Columns to be overwritten originally. */ 5854 int out = olen - tem; /* Columns to be overwritten originally. */
5846 int del; 5855 int del;
5847 5856
5848 cursor_to (vpos, nsp + begmatch); 5857 cursor_to (f, vpos, nsp + begmatch);
5849 5858
5850 /* Calculate columns we can actually overwrite. */ 5859 /* Calculate columns we can actually overwrite. */
5851 while (CHAR_GLYPH_PADDING_P (nbody[nsp + begmatch + out])) 5860 while (CHAR_GLYPH_PADDING_P (nbody[nsp + begmatch + out]))
5852 out--; 5861 out--;
5853 write_glyphs (nbody + nsp + begmatch, out); 5862 write_glyphs (f, nbody + nsp + begmatch, out);
5854 5863
5855 /* If we left columns to be overwritten, we must delete them. */ 5864 /* If we left columns to be overwritten, we must delete them. */
5856 del = olen - tem - out; 5865 del = olen - tem - out;
5857 if (del > 0) 5866 if (del > 0)
5858 delete_glyphs (del); 5867 delete_glyphs (f, del);
5859 5868
5860 /* At last, we insert columns not yet written out. */ 5869 /* At last, we insert columns not yet written out. */
5861 insert_glyphs (nbody + nsp + begmatch + out, nlen - olen + del); 5870 insert_glyphs (f, nbody + nsp + begmatch + out, nlen - olen + del);
5862 olen = nlen; 5871 olen = nlen;
5863 } 5872 }
5864 else if (olen > nlen) 5873 else if (olen > nlen)
5865 { 5874 {
5866 cursor_to (vpos, nsp + begmatch); 5875 cursor_to (f, vpos, nsp + begmatch);
5867 write_glyphs (nbody + nsp + begmatch, nlen - tem); 5876 write_glyphs (f, nbody + nsp + begmatch, nlen - tem);
5868 delete_glyphs (olen - nlen); 5877 delete_glyphs (f, olen - nlen);
5869 olen = nlen; 5878 olen = nlen;
5870 } 5879 }
5871 } 5880 }
@@ -5874,8 +5883,8 @@ update_frame_line (f, vpos)
5874 /* If any unerased characters remain after the new line, erase them. */ 5883 /* If any unerased characters remain after the new line, erase them. */
5875 if (olen > nlen) 5884 if (olen > nlen)
5876 { 5885 {
5877 cursor_to (vpos, nlen); 5886 cursor_to (f, vpos, nlen);
5878 clear_end_of_line (olen); 5887 clear_end_of_line (f, olen);
5879 } 5888 }
5880 5889
5881 /* Exchange contents between current_frame and new_frame. */ 5890 /* Exchange contents between current_frame and new_frame. */
@@ -6172,31 +6181,34 @@ window_change_signal (signalnum) /* If we don't have an argument, */
6172#endif 6181#endif
6173 int old_errno = errno; 6182 int old_errno = errno;
6174 6183
6184 struct tty_display_info *tty;
6185
6175 signal (SIGWINCH, window_change_signal); 6186 signal (SIGWINCH, window_change_signal);
6176 SIGNAL_THREAD_CHECK (signalnum); 6187 SIGNAL_THREAD_CHECK (signalnum);
6177 6188
6178 get_frame_size (&width, &height); 6189 /* The frame size change obviously applies to a single
6179 6190 termcap-controlled terminal, but we can't decide which.
6180 /* The frame size change obviously applies to a termcap-controlled 6191 Therefore, we resize the frames corresponding to each tty.
6181 frame. Find such a frame in the list, and assume it's the only 6192 */
6182 one (since the redisplay code always writes to stdout, not a 6193 for (tty = tty_list; tty; tty = tty->next) {
6183 FILE * specified in the frame structure). Record the new size,
6184 but don't reallocate the data structures now. Let that be done
6185 later outside of the signal handler. */
6186 6194
6187 { 6195 if (! tty->term_initted)
6188 Lisp_Object tail, frame; 6196 continue;
6189 6197
6190 FOR_EACH_FRAME (tail, frame) 6198 get_tty_size (fileno (tty->input), &width, &height);
6191 { 6199
6192 if (FRAME_TERMCAP_P (XFRAME (frame))) 6200 if (width > 5 && height > 2) {
6193 { 6201 Lisp_Object tail, frame;
6194 change_frame_size (XFRAME (frame), height, width, 0, 1, 0); 6202
6195 break; 6203 FOR_EACH_FRAME (tail, frame)
6196 } 6204 if (FRAME_TERMCAP_P (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty)
6197 } 6205 /* Record the new sizes, but don't reallocate the data
6206 structures now. Let that be done later outside of the
6207 signal handler. */
6208 change_frame_size (XFRAME (frame), height, width, 0, 1, 0);
6209 }
6198 } 6210 }
6199 6211
6200 errno = old_errno; 6212 errno = old_errno;
6201} 6213}
6202#endif /* SIGWINCH */ 6214#endif /* SIGWINCH */
@@ -6250,10 +6262,11 @@ change_frame_size (f, newheight, newwidth, pretend, delay, safe)
6250{ 6262{
6251 Lisp_Object tail, frame; 6263 Lisp_Object tail, frame;
6252 6264
6253 if (! FRAME_WINDOW_P (f)) 6265 if (FRAME_MSDOS_P (f))
6254 { 6266 {
6255 /* When using termcap, or on MS-DOS, all frames use 6267 /* On MS-DOS, all frames use the same screen, so a change in
6256 the same screen, so a change in size affects all frames. */ 6268 size affects all frames. Termcap now supports multiple
6269 ttys. */
6257 FOR_EACH_FRAME (tail, frame) 6270 FOR_EACH_FRAME (tail, frame)
6258 if (! FRAME_WINDOW_P (XFRAME (frame))) 6271 if (! FRAME_WINDOW_P (XFRAME (frame)))
6259 change_frame_size_1 (XFRAME (frame), newheight, newwidth, 6272 change_frame_size_1 (XFRAME (frame), newheight, newwidth,
@@ -6333,7 +6346,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
6333 newheight - FRAME_TOP_MARGIN (f), 0); 6346 newheight - FRAME_TOP_MARGIN (f), 0);
6334 6347
6335 if (FRAME_TERMCAP_P (f) && !pretend) 6348 if (FRAME_TERMCAP_P (f) && !pretend)
6336 FrameRows = newheight; 6349 FrameRows (FRAME_TTY (f)) = newheight;
6337 } 6350 }
6338 6351
6339 if (new_frame_total_cols != FRAME_TOTAL_COLS (f)) 6352 if (new_frame_total_cols != FRAME_TOTAL_COLS (f))
@@ -6343,7 +6356,7 @@ change_frame_size_1 (f, newheight, newwidth, pretend, delay, safe)
6343 set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0); 6356 set_window_width (FRAME_MINIBUF_WINDOW (f), new_frame_total_cols, 0);
6344 6357
6345 if (FRAME_TERMCAP_P (f) && !pretend) 6358 if (FRAME_TERMCAP_P (f) && !pretend)
6346 FrameCols = newwidth; 6359 FrameCols (FRAME_TTY (f)) = newwidth;
6347 6360
6348 if (WINDOWP (f->tool_bar_window)) 6361 if (WINDOWP (f->tool_bar_window))
6349 XSETFASTINT (XWINDOW (f->tool_bar_window)->total_cols, newwidth); 6362 XSETFASTINT (XWINDOW (f->tool_bar_window)->total_cols, newwidth);
@@ -6393,19 +6406,26 @@ FILE = nil means just close any termscript file currently open. */)
6393 (file) 6406 (file)
6394 Lisp_Object file; 6407 Lisp_Object file;
6395{ 6408{
6396 if (termscript != 0) 6409 struct tty_display_info *tty;
6397 { 6410
6398 BLOCK_INPUT; 6411 if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
6399 fclose (termscript); 6412 error ("Current frame is not on a tty device");
6400 UNBLOCK_INPUT; 6413
6401 } 6414 tty = CURTTY ();
6402 termscript = 0; 6415
6416 if (tty->termscript != 0)
6417 {
6418 BLOCK_INPUT;
6419 fclose (tty->termscript);
6420 UNBLOCK_INPUT;
6421 }
6422 tty->termscript = 0;
6403 6423
6404 if (! NILP (file)) 6424 if (! NILP (file))
6405 { 6425 {
6406 file = Fexpand_file_name (file, Qnil); 6426 file = Fexpand_file_name (file, Qnil);
6407 termscript = fopen (SDATA (file), "w"); 6427 tty->termscript = fopen (SDATA (file), "w");
6408 if (termscript == 0) 6428 if (tty->termscript == 0)
6409 report_file_error ("Opening termscript", Fcons (file, Qnil)); 6429 report_file_error ("Opening termscript", Fcons (file, Qnil));
6410 } 6430 }
6411 return Qnil; 6431 return Qnil;
@@ -6413,23 +6433,36 @@ FILE = nil means just close any termscript file currently open. */)
6413 6433
6414 6434
6415DEFUN ("send-string-to-terminal", Fsend_string_to_terminal, 6435DEFUN ("send-string-to-terminal", Fsend_string_to_terminal,
6416 Ssend_string_to_terminal, 1, 1, 0, 6436 Ssend_string_to_terminal, 1, 2, 0,
6417 doc: /* Send STRING to the terminal without alteration. 6437 doc: /* Send STRING to the terminal without alteration.
6418Control characters in STRING will have terminal-dependent effects. */) 6438Control characters in STRING will have terminal-dependent effects.
6419 (string) 6439
6440Optional parameter TERMINAL specifies the tty terminal device to use.
6441It may be a terminal id, a frame, or nil for the terminal used by the
6442currently selected frame. */)
6443 (string, terminal)
6420 Lisp_Object string; 6444 Lisp_Object string;
6445 Lisp_Object terminal;
6421{ 6446{
6447 struct terminal *t = get_tty_terminal (terminal, 1);
6448 struct tty_display_info *tty;
6449
6422 /* ??? Perhaps we should do something special for multibyte strings here. */ 6450 /* ??? Perhaps we should do something special for multibyte strings here. */
6423 CHECK_STRING (string); 6451 CHECK_STRING (string);
6424 BLOCK_INPUT; 6452 BLOCK_INPUT;
6425 fwrite (SDATA (string), 1, SBYTES (string), stdout); 6453
6426 fflush (stdout); 6454 if (!t)
6427 if (termscript) 6455 error ("Unknown terminal device");
6456
6457 tty = t->display_info.tty;
6458
6459 if (tty->termscript)
6428 { 6460 {
6429 fwrite (SDATA (string), 1, SBYTES (string), 6461 fwrite (SDATA (string), 1, SBYTES (string), tty->termscript);
6430 termscript); 6462 fflush (tty->termscript);
6431 fflush (termscript);
6432 } 6463 }
6464 fwrite (SDATA (string), 1, SBYTES (string), tty->output);
6465 fflush (tty->output);
6433 UNBLOCK_INPUT; 6466 UNBLOCK_INPUT;
6434 return Qnil; 6467 return Qnil;
6435} 6468}
@@ -6447,8 +6480,7 @@ terminate any keyboard macro currently executing. */)
6447 if (noninteractive) 6480 if (noninteractive)
6448 putchar (07); 6481 putchar (07);
6449 else 6482 else
6450 ring_bell (); 6483 ring_bell (XFRAME (selected_frame));
6451 fflush (stdout);
6452 } 6484 }
6453 else 6485 else
6454 bitch_at_user (); 6486 bitch_at_user ();
@@ -6464,8 +6496,7 @@ bitch_at_user ()
6464 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */ 6496 else if (!INTERACTIVE) /* Stop executing a keyboard macro. */
6465 error ("Keyboard macro terminated by a command ringing the bell"); 6497 error ("Keyboard macro terminated by a command ringing the bell");
6466 else 6498 else
6467 ring_bell (); 6499 ring_bell (XFRAME (selected_frame));
6468 fflush (stdout);
6469} 6500}
6470 6501
6471 6502
@@ -6748,8 +6779,6 @@ pass nil for VARIABLE. */)
6748 Initialization 6779 Initialization
6749***********************************************************************/ 6780***********************************************************************/
6750 6781
6751char *terminal_type;
6752
6753/* Initialization done when Emacs fork is started, before doing stty. 6782/* Initialization done when Emacs fork is started, before doing stty.
6754 Determine terminal type and set terminal_driver. Then invoke its 6783 Determine terminal type and set terminal_driver. Then invoke its
6755 decoding routine to set up variables in the terminal package. */ 6784 decoding routine to set up variables in the terminal package. */
@@ -6757,6 +6786,8 @@ char *terminal_type;
6757void 6786void
6758init_display () 6787init_display ()
6759{ 6788{
6789 char *terminal_type;
6790
6760#ifdef HAVE_X_WINDOWS 6791#ifdef HAVE_X_WINDOWS
6761 extern int display_arg; 6792 extern int display_arg;
6762#endif 6793#endif
@@ -6766,14 +6797,23 @@ init_display ()
6766 SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' '); 6797 SET_CHAR_GLYPH_FROM_GLYPH (space_glyph, ' ');
6767 space_glyph.charpos = -1; 6798 space_glyph.charpos = -1;
6768 6799
6769 meta_key = 0;
6770 inverse_video = 0; 6800 inverse_video = 0;
6771 cursor_in_echo_area = 0; 6801 cursor_in_echo_area = 0;
6772 terminal_type = (char *) 0; 6802 terminal_type = (char *) 0;
6773 6803
6774 /* Now is the time to initialize this; it's used by init_sys_modes 6804 /* Now is the time to initialize this; it's used by init_sys_modes
6775 during startup. */ 6805 during startup. */
6776 Vwindow_system = Qnil; 6806 Vinitial_window_system = Qnil;
6807
6808 /* SIGWINCH needs to be handled no matter what display we start
6809 with. Otherwise newly opened tty frames will not resize
6810 automatically. */
6811#ifdef SIGWINCH
6812#ifndef CANNOT_DUMP
6813 if (initialized)
6814#endif /* CANNOT_DUMP */
6815 signal (SIGWINCH, window_change_signal);
6816#endif /* SIGWINCH */
6777 6817
6778 /* If the user wants to use a window system, we shouldn't bother 6818 /* If the user wants to use a window system, we shouldn't bother
6779 initializing the terminal. This is especially important when the 6819 initializing the terminal. This is especially important when the
@@ -6809,7 +6849,7 @@ init_display ()
6809#endif 6849#endif
6810 ) 6850 )
6811 { 6851 {
6812 Vwindow_system = intern ("x"); 6852 Vinitial_window_system = intern ("x");
6813#ifdef HAVE_X11 6853#ifdef HAVE_X11
6814 Vwindow_system_version = make_number (11); 6854 Vwindow_system_version = make_number (11);
6815#else 6855#else
@@ -6829,7 +6869,7 @@ init_display ()
6829#ifdef HAVE_NTGUI 6869#ifdef HAVE_NTGUI
6830 if (!inhibit_window_system) 6870 if (!inhibit_window_system)
6831 { 6871 {
6832 Vwindow_system = intern ("w32"); 6872 Vinitial_window_system = intern ("w32");
6833 Vwindow_system_version = make_number (1); 6873 Vwindow_system_version = make_number (1);
6834 adjust_frame_glyphs_initially (); 6874 adjust_frame_glyphs_initially ();
6835 return; 6875 return;
@@ -6839,7 +6879,7 @@ init_display ()
6839#ifdef MAC_OS 6879#ifdef MAC_OS
6840 if (!inhibit_window_system) 6880 if (!inhibit_window_system)
6841 { 6881 {
6842 Vwindow_system = intern ("mac"); 6882 Vinitial_window_system = intern ("mac");
6843 Vwindow_system_version = make_number (1); 6883 Vwindow_system_version = make_number (1);
6844 adjust_frame_glyphs_initially (); 6884 adjust_frame_glyphs_initially ();
6845 return; 6885 return;
@@ -6891,8 +6931,38 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6891 } 6931 }
6892#endif /* VMS */ 6932#endif /* VMS */
6893 6933
6894 term_init (terminal_type); 6934 {
6895 6935 struct terminal *t;
6936 struct frame *f = XFRAME (selected_frame);
6937
6938 /* Open a display on the controlling tty. */
6939 t = init_tty (0, terminal_type, 1); /* Errors are fatal. */
6940
6941 /* Convert the initial frame to use the new display. */
6942 if (f->output_method != output_initial)
6943 abort ();
6944 f->output_method = t->type;
6945 f->terminal = t;
6946
6947 t->reference_count++;
6948 t->display_info.tty->top_frame = selected_frame;
6949 change_frame_size (XFRAME (selected_frame),
6950 FrameRows (t->display_info.tty),
6951 FrameCols (t->display_info.tty), 0, 0, 1);
6952
6953 /* Delete the initial terminal. */
6954 if (--initial_terminal->reference_count == 0
6955 && initial_terminal->delete_terminal_hook)
6956 (*initial_terminal->delete_terminal_hook) (initial_terminal);
6957
6958 /* Update frame parameters to reflect the new type. */
6959 Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
6960 Fmodify_frame_parameters
6961 (selected_frame, Fcons (Fcons (Qtty_type,
6962 Ftty_type (selected_frame)), Qnil));
6963 Fmodify_frame_parameters (selected_frame, Fcons (Fcons (Qtty, Qnil), Qnil));
6964 }
6965
6896 { 6966 {
6897 struct frame *sf = SELECTED_FRAME (); 6967 struct frame *sf = SELECTED_FRAME ();
6898 int width = FRAME_TOTAL_COLS (sf); 6968 int width = FRAME_TOTAL_COLS (sf);
@@ -6909,13 +6979,6 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6909 adjust_frame_glyphs_initially (); 6979 adjust_frame_glyphs_initially ();
6910 calculate_costs (XFRAME (selected_frame)); 6980 calculate_costs (XFRAME (selected_frame));
6911 6981
6912#ifdef SIGWINCH
6913#ifndef CANNOT_DUMP
6914 if (initialized)
6915#endif /* CANNOT_DUMP */
6916 signal (SIGWINCH, window_change_signal);
6917#endif /* SIGWINCH */
6918
6919 /* Set up faces of the initial terminal frame of a dumped Emacs. */ 6982 /* Set up faces of the initial terminal frame of a dumped Emacs. */
6920 if (initialized 6983 if (initialized
6921 && !noninteractive 6984 && !noninteractive
@@ -6926,7 +6989,7 @@ For types not defined in VMS, use define emacs_term \"TYPE\".\n\
6926 and internal_terminal_init. */ 6989 and internal_terminal_init. */
6927 && (strcmp (terminal_type, "internal") != 0 || inhibit_window_system) 6990 && (strcmp (terminal_type, "internal") != 0 || inhibit_window_system)
6928#endif 6991#endif
6929 && NILP (Vwindow_system)) 6992 && NILP (Vinitial_window_system))
6930 { 6993 {
6931 /* For the initial frame, we don't have any way of knowing what 6994 /* For the initial frame, we don't have any way of knowing what
6932 are the foreground and background colors of the terminal. */ 6995 are the foreground and background colors of the terminal. */
@@ -7038,8 +7101,8 @@ A non-nil value is useful if the terminal can automatically preserve
7038Emacs's frame display when you reenter Emacs. 7101Emacs's frame display when you reenter Emacs.
7039It is up to you to set this variable if your terminal can do that. */); 7102It is up to you to set this variable if your terminal can do that. */);
7040 7103
7041 DEFVAR_LISP ("window-system", &Vwindow_system, 7104 DEFVAR_LISP ("initial-window-system", &Vinitial_window_system,
7042 doc: /* Name of window system that Emacs is displaying through. 7105 doc: /* Name of the window system that Emacs uses for the first frame.
7043The value is a symbol--for instance, `x' for X windows. 7106The value is a symbol--for instance, `x' for X windows.
7044The value is nil if Emacs is using a text-only terminal. */); 7107The value is nil if Emacs is using a text-only terminal. */);
7045 7108
@@ -7082,7 +7145,7 @@ If nil, never pre-empt redisplay. */);
7082 if (noninteractive) 7145 if (noninteractive)
7083#endif 7146#endif
7084 { 7147 {
7085 Vwindow_system = Qnil; 7148 Vinitial_window_system = Qnil;
7086 Vwindow_system_version = Qnil; 7149 Vwindow_system_version = Qnil;
7087 } 7150 }
7088} 7151}
diff --git a/src/emacs.c b/src/emacs.c
index 62b14a55388..1f8ec6a268f 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -57,6 +57,7 @@ Boston, MA 02110-1301, USA. */
57#include "blockinput.h" 57#include "blockinput.h"
58#include "syssignal.h" 58#include "syssignal.h"
59#include "process.h" 59#include "process.h"
60#include "frame.h"
60#include "termhooks.h" 61#include "termhooks.h"
61#include "keyboard.h" 62#include "keyboard.h"
62#include "keymap.h" 63#include "keymap.h"
@@ -214,7 +215,7 @@ static unsigned long heap_bss_diff;
214 215
215 216
216#ifdef HAVE_WINDOW_SYSTEM 217#ifdef HAVE_WINDOW_SYSTEM
217extern Lisp_Object Vwindow_system; 218extern Lisp_Object Vinitial_window_system;
218#endif /* HAVE_WINDOW_SYSTEM */ 219#endif /* HAVE_WINDOW_SYSTEM */
219 220
220extern Lisp_Object Vauto_save_list_file_name; 221extern Lisp_Object Vauto_save_list_file_name;
@@ -755,7 +756,7 @@ void (*__malloc_initialize_hook) () = malloc_initialize_hook;
755 756
756 757
757#define REPORT_EMACS_BUG_ADDRESS "bug-gnu-emacs@gnu.org" 758#define REPORT_EMACS_BUG_ADDRESS "bug-gnu-emacs@gnu.org"
758#define REPORT_EMACS_BUG_PRETEST_ADDRESS "emacs-pretest-bug@gnu.org" 759#define REPORT_EMACS_BUG_PRETEST_ADDRESS "multi-tty@lists.fnord.hu"
759 760
760/* This function is used to determine an address to which bug report should 761/* This function is used to determine an address to which bug report should
761 be sent. */ 762 be sent. */
@@ -1284,6 +1285,9 @@ main (argc, argv
1284 faces, and the face implementation uses some symbols as 1285 faces, and the face implementation uses some symbols as
1285 face names. */ 1286 face names. */
1286 syms_of_xfaces (); 1287 syms_of_xfaces ();
1288 /* XXX syms_of_keyboard uses some symbols in keymap.c. It would
1289 be better to arrange things not to have this dependency. */
1290 syms_of_keymap ();
1287 /* Call syms_of_keyboard before init_window_once because 1291 /* Call syms_of_keyboard before init_window_once because
1288 keyboard sets up symbols that include some face names that 1292 keyboard sets up symbols that include some face names that
1289 the X support will want to use. This can happen when 1293 the X support will want to use. This can happen when
@@ -1481,10 +1485,10 @@ main (argc, argv
1481 /* egetenv is a pretty low-level facility, which may get called in 1485 /* egetenv is a pretty low-level facility, which may get called in
1482 many circumstances; it seems flimsy to put off initializing it 1486 many circumstances; it seems flimsy to put off initializing it
1483 until calling init_callproc. */ 1487 until calling init_callproc. */
1484 set_process_environment (); 1488 set_initial_environment ();
1485 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4 1489 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1486 if this is not done. Do it after set_process_environment so that we 1490 if this is not done. Do it after set_global_environment so that we
1487 don't pollute Vprocess_environment. */ 1491 don't pollute Vglobal_environment. */
1488 /* Setting LANG here will defeat the startup locale processing... */ 1492 /* Setting LANG here will defeat the startup locale processing... */
1489#ifdef AIX3_2 1493#ifdef AIX3_2
1490 putenv ("LANG=C"); 1494 putenv ("LANG=C");
@@ -1555,7 +1559,7 @@ main (argc, argv
1555#endif /* CLASH_DETECTION */ 1559#endif /* CLASH_DETECTION */
1556 syms_of_indent (); 1560 syms_of_indent ();
1557 syms_of_insdel (); 1561 syms_of_insdel ();
1558 syms_of_keymap (); 1562 /* syms_of_keymap (); */
1559 syms_of_macros (); 1563 syms_of_macros ();
1560 syms_of_marker (); 1564 syms_of_marker ();
1561 syms_of_minibuf (); 1565 syms_of_minibuf ();
@@ -1566,6 +1570,7 @@ main (argc, argv
1566 syms_of_frame (); 1570 syms_of_frame ();
1567#endif 1571#endif
1568 syms_of_syntax (); 1572 syms_of_syntax ();
1573 syms_of_terminal ();
1569 syms_of_term (); 1574 syms_of_term ();
1570 syms_of_undo (); 1575 syms_of_undo ();
1571#ifdef HAVE_SOUND 1576#ifdef HAVE_SOUND
@@ -1650,13 +1655,7 @@ main (argc, argv
1650#endif /* HAVE_NTGUI */ 1655#endif /* HAVE_NTGUI */
1651 } 1656 }
1652 1657
1653 if (!noninteractive) 1658 init_process (); /* init_display uses add_keyboard_wait_descriptor. */
1654 {
1655#ifdef VMS
1656 init_vms_input ();/* init_display calls get_frame_size, that needs this. */
1657#endif /* VMS */
1658 init_display (); /* Determine terminal type. init_sys_modes uses results. */
1659 }
1660#ifndef MAC_OS8 1659#ifndef MAC_OS8
1661 /* Called before init_window_once for Mac OS Classic. */ 1660 /* Called before init_window_once for Mac OS Classic. */
1662 init_keyboard (); /* This too must precede init_sys_modes. */ 1661 init_keyboard (); /* This too must precede init_sys_modes. */
@@ -1664,7 +1663,13 @@ main (argc, argv
1664#ifdef VMS 1663#ifdef VMS
1665 init_vmsproc (); /* And this too. */ 1664 init_vmsproc (); /* And this too. */
1666#endif /* VMS */ 1665#endif /* VMS */
1667 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */ 1666 if (!noninteractive)
1667 {
1668#ifdef VMS
1669 init_vms_input ();/* init_display calls get_tty_size, that needs this. */
1670#endif /* VMS */
1671 init_display (); /* Determine terminal type. Calls init_sys_modes. */
1672 }
1668 init_fns (); 1673 init_fns ();
1669 init_xdisp (); 1674 init_xdisp ();
1670#ifdef HAVE_WINDOW_SYSTEM 1675#ifdef HAVE_WINDOW_SYSTEM
@@ -1677,7 +1682,6 @@ main (argc, argv
1677#ifdef VMS 1682#ifdef VMS
1678 init_vmsfns (); 1683 init_vmsfns ();
1679#endif /* VMS */ 1684#endif /* VMS */
1680 init_process ();
1681#ifdef HAVE_SOUND 1685#ifdef HAVE_SOUND
1682 init_sound (); 1686 init_sound ();
1683#endif 1687#endif
@@ -2090,15 +2094,14 @@ shut_down_emacs (sig, no_x, stuff)
2090 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 2094 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
2091 && tpgrp == pgrp) 2095 && tpgrp == pgrp)
2092 { 2096 {
2093 fflush (stdout); 2097 reset_all_sys_modes ();
2094 reset_sys_modes ();
2095 if (sig && sig != SIGTERM) 2098 if (sig && sig != SIGTERM)
2096 fprintf (stderr, "Fatal error (%d)", sig); 2099 fprintf (stderr, "Fatal error (%d)", sig);
2097 } 2100 }
2098 } 2101 }
2099#else 2102#else
2100 fflush (stdout); 2103 fflush (stdout);
2101 reset_sys_modes (); 2104 reset_all_sys_modes ();
2102#endif 2105#endif
2103 2106
2104 stuff_buffered_input (stuff); 2107 stuff_buffered_input (stuff);
@@ -2120,9 +2123,9 @@ shut_down_emacs (sig, no_x, stuff)
2120#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */ 2123#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
2121#ifdef HAVE_X_WINDOWS 2124#ifdef HAVE_X_WINDOWS
2122 /* It's not safe to call intern here. Maybe we are crashing. */ 2125 /* It's not safe to call intern here. Maybe we are crashing. */
2123 if (!noninteractive && SYMBOLP (Vwindow_system) 2126 if (!noninteractive && SYMBOLP (Vinitial_window_system)
2124 && SCHARS (SYMBOL_NAME (Vwindow_system)) == 1 2127 && SCHARS (SYMBOL_NAME (Vinitial_window_system)) == 1
2125 && SREF (SYMBOL_NAME (Vwindow_system), 0) == 'x' 2128 && SREF (SYMBOL_NAME (Vinitial_window_system), 0) == 'x'
2126 && ! no_x) 2129 && ! no_x)
2127 Fx_close_current_connection (); 2130 Fx_close_current_connection ();
2128#endif /* HAVE_X_WINDOWS */ 2131#endif /* HAVE_X_WINDOWS */
diff --git a/src/eval.c b/src/eval.c
index 6707849a840..b1bd3daef7a 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1273,8 +1273,12 @@ unwind_to_catch (catch, value)
1273#if HAVE_X_WINDOWS 1273#if HAVE_X_WINDOWS
1274 /* If x_catch_errors was done, turn it off now. 1274 /* If x_catch_errors was done, turn it off now.
1275 (First we give unbind_to a chance to do that.) */ 1275 (First we give unbind_to a chance to do that.) */
1276#if 0 /* This would disable x_catch_errors after x_connection_closed.
1277 * The catch must remain in effect during that delicate
1278 * state. --lorentey */
1276 x_fully_uncatch_errors (); 1279 x_fully_uncatch_errors ();
1277#endif 1280#endif
1281#endif
1278 1282
1279 byte_stack_list = catch->byte_stack; 1283 byte_stack_list = catch->byte_stack;
1280 gcprolist = catch->gcpro; 1284 gcprolist = catch->gcpro;
@@ -1451,10 +1455,12 @@ internal_condition_case (bfun, handlers, hfun)
1451 1455
1452 /* Since Fsignal will close off all calls to x_catch_errors, 1456 /* Since Fsignal will close off all calls to x_catch_errors,
1453 we will get the wrong results if some are not closed now. */ 1457 we will get the wrong results if some are not closed now. */
1458#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1454#if HAVE_X_WINDOWS 1459#if HAVE_X_WINDOWS
1455 if (x_catching_errors ()) 1460 if (x_catching_errors ())
1456 abort (); 1461 abort ();
1457#endif 1462#endif
1463#endif
1458 1464
1459 c.tag = Qnil; 1465 c.tag = Qnil;
1460 c.val = Qnil; 1466 c.val = Qnil;
@@ -1499,10 +1505,12 @@ internal_condition_case_1 (bfun, arg, handlers, hfun)
1499 1505
1500 /* Since Fsignal will close off all calls to x_catch_errors, 1506 /* Since Fsignal will close off all calls to x_catch_errors,
1501 we will get the wrong results if some are not closed now. */ 1507 we will get the wrong results if some are not closed now. */
1508#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1502#if HAVE_X_WINDOWS 1509#if HAVE_X_WINDOWS
1503 if (x_catching_errors ()) 1510 if (x_catching_errors ())
1504 abort (); 1511 abort ();
1505#endif 1512#endif
1513#endif
1506 1514
1507 c.tag = Qnil; 1515 c.tag = Qnil;
1508 c.val = Qnil; 1516 c.val = Qnil;
@@ -1550,10 +1558,12 @@ internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1550 1558
1551 /* Since Fsignal will close off all calls to x_catch_errors, 1559 /* Since Fsignal will close off all calls to x_catch_errors,
1552 we will get the wrong results if some are not closed now. */ 1560 we will get the wrong results if some are not closed now. */
1561#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1553#if HAVE_X_WINDOWS 1562#if HAVE_X_WINDOWS
1554 if (x_catching_errors ()) 1563 if (x_catching_errors ())
1555 abort (); 1564 abort ();
1556#endif 1565#endif
1566#endif
1557 1567
1558 c.tag = Qnil; 1568 c.tag = Qnil;
1559 c.val = Qnil; 1569 c.val = Qnil;
diff --git a/src/fileio.c b/src/fileio.c
index 7156f22f57e..b9f9334a062 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -78,6 +78,8 @@ extern int errno;
78#include "coding.h" 78#include "coding.h"
79#include "window.h" 79#include "window.h"
80#include "blockinput.h" 80#include "blockinput.h"
81#include "frame.h"
82#include "dispextern.h"
81 83
82#ifdef WINDOWSNT 84#ifdef WINDOWSNT
83#define NOMINMAX 1 85#define NOMINMAX 1
@@ -5746,7 +5748,7 @@ auto_save_error (error)
5746 char *msgbuf; 5748 char *msgbuf;
5747 USE_SAFE_ALLOCA; 5749 USE_SAFE_ALLOCA;
5748 5750
5749 ring_bell (); 5751 ring_bell (XFRAME (selected_frame));
5750 5752
5751 args[0] = build_string ("Auto-saving %s: %s"); 5753 args[0] = build_string ("Auto-saving %s: %s");
5752 args[1] = current_buffer->name; 5754 args[1] = current_buffer->name;
@@ -6308,7 +6310,7 @@ and `read-file-name-function'. */)
6308 /* If dir starts with user's homedir, change that to ~. */ 6310 /* If dir starts with user's homedir, change that to ~. */
6309 homedir = (char *) egetenv ("HOME"); 6311 homedir = (char *) egetenv ("HOME");
6310#ifdef DOS_NT 6312#ifdef DOS_NT
6311 /* homedir can be NULL in temacs, since Vprocess_environment is not 6313 /* homedir can be NULL in temacs, since Vglobal_environment is not
6312 yet set up. We shouldn't crash in that case. */ 6314 yet set up. We shouldn't crash in that case. */
6313 if (homedir != 0) 6315 if (homedir != 0)
6314 { 6316 {
diff --git a/src/fns.c b/src/fns.c
index 345aa0a35e0..c75c4d68cf3 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3236,7 +3236,8 @@ is nil and `use-dialog-box' is non-nil. */)
3236 { 3236 {
3237 3237
3238#ifdef HAVE_MENUS 3238#ifdef HAVE_MENUS
3239 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 3239 if (FRAME_WINDOW_P (SELECTED_FRAME ())
3240 && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
3240 && use_dialog_box 3241 && use_dialog_box
3241 && have_menus_p ()) 3242 && have_menus_p ())
3242 { 3243 {
@@ -3275,6 +3276,7 @@ is nil and `use-dialog-box' is non-nil. */)
3275 Fraise_frame (mini_frame); 3276 Fraise_frame (mini_frame);
3276 } 3277 }
3277 3278
3279 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
3278 obj = read_filtered_event (1, 0, 0, 0, Qnil); 3280 obj = read_filtered_event (1, 0, 0, 0, Qnil);
3279 cursor_in_echo_area = 0; 3281 cursor_in_echo_area = 0;
3280 /* If we need to quit, quit with cursor_in_echo_area = 0. */ 3282 /* If we need to quit, quit with cursor_in_echo_area = 0. */
@@ -3367,7 +3369,8 @@ is nil, and `use-dialog-box' is non-nil. */)
3367 CHECK_STRING (prompt); 3369 CHECK_STRING (prompt);
3368 3370
3369#ifdef HAVE_MENUS 3371#ifdef HAVE_MENUS
3370 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 3372 if (FRAME_WINDOW_P (SELECTED_FRAME ())
3373 && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
3371 && use_dialog_box 3374 && use_dialog_box
3372 && have_menus_p ()) 3375 && have_menus_p ())
3373 { 3376 {
diff --git a/src/fontset.c b/src/fontset.c
index 2df60a5afcc..7d227d8f43f 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -49,6 +49,7 @@ Boston, MA 02110-1301, USA. */
49#ifdef MAC_OS 49#ifdef MAC_OS
50#include "macterm.h" 50#include "macterm.h"
51#endif 51#endif
52#include "termhooks.h"
52 53
53#ifdef FONTSET_DEBUG 54#ifdef FONTSET_DEBUG
54#undef xassert 55#undef xassert
@@ -1347,7 +1348,7 @@ DEFUN ("internal-char-font", Finternal_char_font, Sinternal_char_font, 1, 2, 0,
1347 STORE_XCHAR2B (&char2b, c1, c2); 1348 STORE_XCHAR2B (&char2b, c1, c2);
1348 else 1349 else
1349 STORE_XCHAR2B (&char2b, 0, c1); 1350 STORE_XCHAR2B (&char2b, 0, c1);
1350 rif->encode_char (c, &char2b, fontp, NULL); 1351 FRAME_RIF (f)->encode_char (c, &char2b, fontp, NULL);
1351 code = (XCHAR2B_BYTE1 (&char2b) << 8) | XCHAR2B_BYTE2 (&char2b); 1352 code = (XCHAR2B_BYTE1 (&char2b) << 8) | XCHAR2B_BYTE2 (&char2b);
1352 } 1353 }
1353 return Fcons (build_string (face->font_name), make_number (code)); 1354 return Fcons (build_string (face->font_name), make_number (code));
diff --git a/src/frame.c b/src/frame.c
index 5990b9e0717..740dac812c2 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -42,6 +42,7 @@ Boston, MA 02110-1301, USA. */
42#include "fontset.h" 42#include "fontset.h"
43#endif 43#endif
44#include "blockinput.h" 44#include "blockinput.h"
45#include "termchar.h"
45#include "termhooks.h" 46#include "termhooks.h"
46#include "dispextern.h" 47#include "dispextern.h"
47#include "window.h" 48#include "window.h"
@@ -74,6 +75,8 @@ Lisp_Object Qbackground_mode;
74 75
75Lisp_Object Qx_frame_parameter; 76Lisp_Object Qx_frame_parameter;
76Lisp_Object Qx_resource_name; 77Lisp_Object Qx_resource_name;
78Lisp_Object Qterminal;
79Lisp_Object Qterminal_live_p;
77 80
78/* Frame parameters (set or reported). */ 81/* Frame parameters (set or reported). */
79 82
@@ -103,15 +106,17 @@ Lisp_Object Qtitle, Qname;
103Lisp_Object Qunsplittable; 106Lisp_Object Qunsplittable;
104Lisp_Object Qmenu_bar_lines, Qtool_bar_lines; 107Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
105Lisp_Object Qleft_fringe, Qright_fringe; 108Lisp_Object Qleft_fringe, Qright_fringe;
106Lisp_Object Qbuffer_predicate, Qbuffer_list; 109Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
107Lisp_Object Qtty_color_mode; 110Lisp_Object Qtty_color_mode;
111Lisp_Object Qtty, Qtty_type;
112Lisp_Object Qwindow_system;
113Lisp_Object Qenvironment;
108 114
109Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth; 115Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
110 116
111Lisp_Object Qinhibit_face_set_after_frame_default; 117Lisp_Object Qinhibit_face_set_after_frame_default;
112Lisp_Object Qface_set_after_frame_default; 118Lisp_Object Qface_set_after_frame_default;
113 119
114
115Lisp_Object Vterminal_frame; 120Lisp_Object Vterminal_frame;
116Lisp_Object Vdefault_frame_alist; 121Lisp_Object Vdefault_frame_alist;
117Lisp_Object Vdefault_frame_scroll_bars; 122Lisp_Object Vdefault_frame_scroll_bars;
@@ -121,8 +126,8 @@ Lisp_Object Vdelete_frame_functions;
121 126
122static void 127static void
123set_menu_bar_lines_1 (window, n) 128set_menu_bar_lines_1 (window, n)
124 Lisp_Object window; 129 Lisp_Object window;
125 int n; 130 int n;
126{ 131{
127 struct window *w = XWINDOW (window); 132 struct window *w = XWINDOW (window);
128 133
@@ -180,8 +185,6 @@ set_menu_bar_lines (f, value, oldval)
180Lisp_Object Vemacs_iconified; 185Lisp_Object Vemacs_iconified;
181Lisp_Object Vframe_list; 186Lisp_Object Vframe_list;
182 187
183struct x_output tty_display;
184
185extern Lisp_Object Vminibuffer_list; 188extern Lisp_Object Vminibuffer_list;
186extern Lisp_Object get_minibuffer (); 189extern Lisp_Object get_minibuffer ();
187extern Lisp_Object Fhandle_switch_frame (); 190extern Lisp_Object Fhandle_switch_frame ();
@@ -203,6 +206,7 @@ See also `frame-live-p'. */)
203 return Qnil; 206 return Qnil;
204 switch (XFRAME (object)->output_method) 207 switch (XFRAME (object)->output_method)
205 { 208 {
209 case output_initial: /* The initial frame is like a termcap frame. */
206 case output_termcap: 210 case output_termcap:
207 return Qt; 211 return Qt;
208 case output_x_window: 212 case output_x_window:
@@ -221,7 +225,7 @@ See also `frame-live-p'. */)
221DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0, 225DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
222 doc: /* Return non-nil if OBJECT is a frame which has not been deleted. 226 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
223Value is nil if OBJECT is not a live frame. If object is a live 227Value is nil if OBJECT is not a live frame. If object is a live
224frame, the return value indicates what sort of output device it is 228frame, the return value indicates what sort of terminal device it is
225displayed on. See the documentation of `framep' for possible 229displayed on. See the documentation of `framep' for possible
226return values. */) 230return values. */)
227 (object) 231 (object)
@@ -233,6 +237,30 @@ return values. */)
233 : Qnil); 237 : Qnil);
234} 238}
235 239
240DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
241 doc: /* The name of the window system that FRAME is displaying through.
242The value is a symbol---for instance, 'x' for X windows.
243The value is nil if Emacs is using a text-only terminal.
244
245FRAME defaults to the currently selected frame. */)
246 (frame)
247 Lisp_Object frame;
248{
249 Lisp_Object type;
250 if (NILP (frame))
251 frame = selected_frame;
252
253 type = Fframep (frame);
254
255 if (NILP (type))
256 wrong_type_argument (Qframep, frame);
257
258 if (EQ (type, Qt))
259 return Qnil;
260 else
261 return type;
262}
263
236struct frame * 264struct frame *
237make_frame (mini_p) 265make_frame (mini_p)
238 int mini_p; 266 int mini_p;
@@ -276,9 +304,7 @@ make_frame (mini_p)
276 f->menu_bar_items_used = 0; 304 f->menu_bar_items_used = 0;
277 f->buffer_predicate = Qnil; 305 f->buffer_predicate = Qnil;
278 f->buffer_list = Qnil; 306 f->buffer_list = Qnil;
279#ifdef MULTI_KBOARD 307 f->buried_buffer_list = Qnil;
280 f->kboard = initial_kboard;
281#endif
282 f->namebuf = 0; 308 f->namebuf = 0;
283 f->title = Qnil; 309 f->title = Qnil;
284 f->menu_bar_window = Qnil; 310 f->menu_bar_window = Qnil;
@@ -398,8 +424,8 @@ make_frame_without_minibuffer (mini_window, kb, display)
398 424
399#ifdef MULTI_KBOARD 425#ifdef MULTI_KBOARD
400 if (!NILP (mini_window) 426 if (!NILP (mini_window)
401 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb) 427 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
402 error ("Frame and minibuffer must be on the same display"); 428 error ("Frame and minibuffer must be on the same terminal");
403#endif 429#endif
404 430
405 /* Make a frame containing just a root window. */ 431 /* Make a frame containing just a root window. */
@@ -475,18 +501,19 @@ make_minibuffer_frame ()
475} 501}
476#endif /* HAVE_WINDOW_SYSTEM */ 502#endif /* HAVE_WINDOW_SYSTEM */
477 503
478/* Construct a frame that refers to the terminal (stdin and stdout). */ 504/* Construct a frame that refers to a terminal. */
479 505
480static int terminal_frame_count; 506static int tty_frame_count;
481 507
482struct frame * 508struct frame *
483make_terminal_frame () 509make_initial_frame (void)
484{ 510{
485 register struct frame *f; 511 struct frame *f;
512 struct terminal *terminal;
486 Lisp_Object frame; 513 Lisp_Object frame;
487 char name[20];
488 514
489#ifdef MULTI_KBOARD 515#ifdef MULTI_KBOARD
516 /* Create the initial keyboard. */
490 if (!initial_kboard) 517 if (!initial_kboard)
491 { 518 {
492 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); 519 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
@@ -500,13 +527,51 @@ make_terminal_frame ()
500 if (! (NILP (Vframe_list) || CONSP (Vframe_list))) 527 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
501 Vframe_list = Qnil; 528 Vframe_list = Qnil;
502 529
530 terminal = init_initial_terminal ();
531
532 f = make_frame (1);
533 XSETFRAME (frame, f);
534
535 Vframe_list = Fcons (frame, Vframe_list);
536
537 tty_frame_count = 1;
538 f->name = build_string ("F1");
539
540 f->visible = 1;
541 f->async_visible = 1;
542
543 f->output_method = terminal->type;
544 f->terminal = terminal;
545 f->terminal->reference_count++;
546 f->output_data.nothing = 0;
547
548 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
550
551 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
552 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
553
554 return f;
555}
556
557
558struct frame *
559make_terminal_frame (struct terminal *terminal)
560{
561 register struct frame *f;
562 Lisp_Object frame;
563 char name[20];
564
565 if (terminal->deleted)
566 error ("Terminal is being deleted, can't create new frames on it");
567
503 f = make_frame (1); 568 f = make_frame (1);
504 569
505 XSETFRAME (frame, f); 570 XSETFRAME (frame, f);
506 Vframe_list = Fcons (frame, Vframe_list); 571 Vframe_list = Fcons (frame, Vframe_list);
507 572
508 terminal_frame_count++; 573 tty_frame_count++;
509 sprintf (name, "F%d", terminal_frame_count); 574 sprintf (name, "F%d", tty_frame_count);
510 f->name = build_string (name); 575 f->name = build_string (name);
511 576
512 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ 577 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
@@ -526,11 +591,11 @@ make_terminal_frame ()
526 for the black color. Other frames all inherit their pixels 591 for the black color. Other frames all inherit their pixels
527 from what's already in the_only_x_display. */ 592 from what's already in the_only_x_display. */
528 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))) 593 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
529 && f->output_data.x->background_pixel == 0 594 && FRAME_BACKGROUND_PIXEL (f) == 0
530 && f->output_data.x->foreground_pixel == 0) 595 && FRAME_FOREGROUND_PIXEL (f) == 0)
531 { 596 {
532 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR; 597 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
533 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR; 598 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
534 } 599 }
535 } 600 }
536 else 601 else
@@ -538,12 +603,31 @@ make_terminal_frame ()
538#else 603#else
539#ifdef WINDOWSNT 604#ifdef WINDOWSNT
540 f->output_method = output_termcap; 605 f->output_method = output_termcap;
541 f->output_data.x = &tty_display; 606 f->output_data.x = &tty_display; /* XXX ??? */
542#else 607#else
543#ifdef MAC_OS8 608#ifdef MAC_OS8
544 make_mac_terminal_frame (f); 609 make_mac_terminal_frame (f);
545#else 610#else
546 f->output_data.x = &tty_display; 611 {
612 f->output_method = output_termcap;
613 f->terminal = terminal;
614 f->terminal->reference_count++;
615 create_tty_output (f);
616
617 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
618 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
619
620 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
621 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
622
623 /* Set the top frame to the newly created frame. */
624 if (FRAME_TTY (f)->top_frame
625 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
626 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
627
628 FRAME_TTY (f)->top_frame = frame;
629 }
630
547#ifdef CANNOT_DUMP 631#ifdef CANNOT_DUMP
548 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR; 632 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR; 633 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
@@ -558,18 +642,55 @@ make_terminal_frame ()
558 return f; 642 return f;
559} 643}
560 644
645/* Get a suitable value for frame parameter PARAMETER for a newly
646 created frame, based on (1) the user-supplied frame parameter
647 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
648 fails, (3) Vdefault_frame_alist. */
649
650static Lisp_Object
651get_future_frame_param (Lisp_Object parameter,
652 Lisp_Object supplied_parms,
653 char *current_value)
654{
655 Lisp_Object result;
656
657 result = Fassq (parameter, supplied_parms);
658 if (NILP (result))
659 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
660 if (NILP (result) && current_value != NULL)
661 result = build_string (current_value);
662 if (NILP (result))
663 result = Fassq (parameter, Vdefault_frame_alist);
664 if (!NILP (result) && !STRINGP (result))
665 result = XCDR (result);
666 if (NILP (result) || !STRINGP (result))
667 result = Qnil;
668
669 return result;
670}
671
561DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame, 672DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
562 1, 1, 0, 673 1, 1, 0,
563 doc: /* Create an additional terminal frame. 674 doc: /* Create an additional terminal frame, possibly on another terminal.
564You can create multiple frames on a text-only terminal in this way.
565Only the selected terminal frame is actually displayed.
566This function takes one argument, an alist specifying frame parameters. 675This function takes one argument, an alist specifying frame parameters.
567In practice, generally you don't need to specify any parameters. 676
568Note that changing the size of one terminal frame automatically affects all. */) 677You can create multiple frames on a single text-only terminal, but
678only one of them (the selected terminal frame) is actually displayed.
679
680In practice, generally you don't need to specify any parameters,
681except when you want to create a new frame on another terminal.
682In that case, the `tty' parameter specifies the device file to open,
683and the `tty-type' parameter specifies the terminal type. Example:
684
685 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
686
687Note that changing the size of one terminal frame automatically
688affects all frames on the same terminal device. */)
569 (parms) 689 (parms)
570 Lisp_Object parms; 690 Lisp_Object parms;
571{ 691{
572 struct frame *f; 692 struct frame *f;
693 struct terminal *t = NULL;
573 Lisp_Object frame, tem; 694 Lisp_Object frame, tem;
574 struct frame *sf = SELECTED_FRAME (); 695 struct frame *sf = SELECTED_FRAME ();
575 696
@@ -583,21 +704,78 @@ Note that changing the size of one terminal frame automatically affects all. */
583 if (sf->output_method != output_mac) 704 if (sf->output_method != output_mac)
584 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame"); 705 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
585#else 706#else
707#if 0 /* This should work now! */
586 if (sf->output_method != output_termcap) 708 if (sf->output_method != output_termcap)
587 error ("Not using an ASCII terminal now; cannot make a new ASCII frame"); 709 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
588#endif 710#endif
711#endif
589#endif /* not MSDOS */ 712#endif /* not MSDOS */
713
714 {
715 Lisp_Object terminal;
716
717 terminal = Fassq (Qterminal, parms);
718 if (!NILP (terminal))
719 {
720 terminal = XCDR (terminal);
721 t = get_terminal (terminal, 1);
722 }
723 }
724
725 if (!t)
726 {
727 char *name = 0, *type = 0;
728 Lisp_Object tty, tty_type;
729
730 tty = get_future_frame_param
731 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
732 ? FRAME_TTY (XFRAME (selected_frame))->name
733 : NULL));
734 if (!NILP (tty))
735 {
736 name = (char *) alloca (SBYTES (tty) + 1);
737 strncpy (name, SDATA (tty), SBYTES (tty));
738 name[SBYTES (tty)] = 0;
739 }
740
741 tty_type = get_future_frame_param
742 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
743 ? FRAME_TTY (XFRAME (selected_frame))->type
744 : NULL));
745 if (!NILP (tty_type))
746 {
747 type = (char *) alloca (SBYTES (tty_type) + 1);
748 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
749 type[SBYTES (tty_type)] = 0;
750 }
751
752 t = init_tty (name, type, 0); /* Errors are not fatal. */
753 }
590 754
591 f = make_terminal_frame (); 755 f = make_terminal_frame (t);
592 756
593 change_frame_size (f, FRAME_LINES (sf), 757 {
594 FRAME_COLS (sf), 0, 0, 0); 758 int width, height;
759 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
760 change_frame_size (f, height, width, 0, 0, 0);
761 }
762
595 adjust_glyphs (f); 763 adjust_glyphs (f);
596 calculate_costs (f); 764 calculate_costs (f);
597 XSETFRAME (frame, f); 765 XSETFRAME (frame, f);
598 Fmodify_frame_parameters (frame, Vdefault_frame_alist); 766 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
599 Fmodify_frame_parameters (frame, parms); 767 Fmodify_frame_parameters (frame, parms);
600 768 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
769 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
770 build_string (t->display_info.tty->type)),
771 Qnil));
772 if (t->display_info.tty->name != NULL)
773 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
774 build_string (t->display_info.tty->name)),
775 Qnil));
776 else
777 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
778
601 /* Make the frame face alist be frame-specific, so that each 779 /* Make the frame face alist be frame-specific, so that each
602 frame could change its face definitions independently. */ 780 frame could change its face definitions independently. */
603 f->face_alist = Fcopy_alist (sf->face_alist); 781 f->face_alist = Fcopy_alist (sf->face_alist);
@@ -620,7 +798,7 @@ Note that changing the size of one terminal frame automatically affects all. */
620 frame's focus to FRAME instead. 798 frame's focus to FRAME instead.
621 799
622 FOR_DELETION non-zero means that the selected frame is being 800 FOR_DELETION non-zero means that the selected frame is being
623 deleted, which includes the possibility that the frame's display 801 deleted, which includes the possibility that the frame's terminal
624 is dead. */ 802 is dead. */
625 803
626Lisp_Object 804Lisp_Object
@@ -695,6 +873,15 @@ do_switch_frame (frame, track, for_deletion)
695 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf)) 873 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
696 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1); 874 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
697 875
876 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
877 && FRAME_TERMCAP_P (XFRAME (frame))
878 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
879 {
880 XFRAME (selected_frame)->async_visible = 2; /* obscured */
881 XFRAME (frame)->async_visible = 1;
882 FRAME_TTY (XFRAME (frame))->top_frame = frame;
883 }
884
698 selected_frame = frame; 885 selected_frame = frame;
699 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) 886 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
700 last_nonminibuf_frame = XFRAME (selected_frame); 887 last_nonminibuf_frame = XFRAME (selected_frame);
@@ -878,6 +1065,7 @@ If FRAME is the selected frame, this makes WINDOW the selected window. */)
878 1065
879 return XFRAME (frame)->selected_window = window; 1066 return XFRAME (frame)->selected_window = window;
880} 1067}
1068
881 1069
882DEFUN ("frame-list", Fframe_list, Sframe_list, 1070DEFUN ("frame-list", Fframe_list, Sframe_list,
883 0, 0, 0, 1071 0, 0, 0,
@@ -925,7 +1113,10 @@ next_frame (frame, minibuf)
925 f = XCAR (tail); 1113 f = XCAR (tail);
926 1114
927 if (passed 1115 if (passed
928 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) 1116 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1117 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1118 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1119 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
929 { 1120 {
930 /* Decide whether this frame is eligible to be returned. */ 1121 /* Decide whether this frame is eligible to be returned. */
931 1122
@@ -1002,7 +1193,10 @@ prev_frame (frame, minibuf)
1002 if (EQ (frame, f) && !NILP (prev)) 1193 if (EQ (frame, f) && !NILP (prev))
1003 return prev; 1194 return prev;
1004 1195
1005 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) 1196 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1197 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1198 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1199 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1006 { 1200 {
1007 /* Decide whether this frame is eligible to be returned, 1201 /* Decide whether this frame is eligible to be returned,
1008 according to minibuf. */ 1202 according to minibuf. */
@@ -1136,6 +1330,14 @@ other_visible_frames (f)
1136 return 1; 1330 return 1;
1137} 1331}
1138 1332
1333/* Error handler for `delete-frame-functions'. */
1334static Lisp_Object
1335delete_frame_handler (Lisp_Object arg)
1336{
1337 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1338 return Qnil;
1339}
1340
1139DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", 1341DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1140 doc: /* Delete FRAME, permanently eliminating it from use. 1342 doc: /* Delete FRAME, permanently eliminating it from use.
1141If omitted, FRAME defaults to the selected frame. 1343If omitted, FRAME defaults to the selected frame.
@@ -1151,6 +1353,8 @@ The functions are run with one arg, the frame to be deleted. */)
1151{ 1353{
1152 struct frame *f; 1354 struct frame *f;
1153 struct frame *sf = SELECTED_FRAME (); 1355 struct frame *sf = SELECTED_FRAME ();
1356 struct kboard *kb;
1357
1154 int minibuffer_selected; 1358 int minibuffer_selected;
1155 1359
1156 if (EQ (frame, Qnil)) 1360 if (EQ (frame, Qnil))
@@ -1209,11 +1413,22 @@ The functions are run with one arg, the frame to be deleted. */)
1209 && NILP (Fframe_parameter (frame, intern ("tooltip")))) 1413 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1210 { 1414 {
1211 Lisp_Object args[2]; 1415 Lisp_Object args[2];
1416 struct gcpro gcpro1, gcpro2;
1417
1418 /* Don't let a rogue function in `delete-frame-functions'
1419 prevent the frame deletion. */
1420 GCPRO2 (args[0], args[1]);
1212 args[0] = intern ("delete-frame-functions"); 1421 args[0] = intern ("delete-frame-functions");
1213 args[1] = frame; 1422 args[1] = frame;
1214 Frun_hook_with_args (2, args); 1423 internal_condition_case_2 (Frun_hook_with_args, 2, args,
1424 Qt, delete_frame_handler);
1425 UNGCPRO;
1215 } 1426 }
1216 1427
1428 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1429 if (! FRAME_LIVE_P (f))
1430 return Qnil;
1431
1217 minibuffer_selected = EQ (minibuf_window, selected_window); 1432 minibuffer_selected = EQ (minibuf_window, selected_window);
1218 1433
1219 /* Don't let the frame remain selected. */ 1434 /* Don't let the frame remain selected. */
@@ -1229,7 +1444,7 @@ The functions are run with one arg, the frame to be deleted. */)
1229 { 1444 {
1230 FOR_EACH_FRAME (tail, frame1) 1445 FOR_EACH_FRAME (tail, frame1)
1231 { 1446 {
1232 if (! EQ (frame, frame1)) 1447 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1233 break; 1448 break;
1234 } 1449 }
1235 } 1450 }
@@ -1255,6 +1470,24 @@ The functions are run with one arg, the frame to be deleted. */)
1255 if (EQ (f->minibuffer_window, echo_area_window)) 1470 if (EQ (f->minibuffer_window, echo_area_window))
1256 echo_area_window = sf->minibuffer_window; 1471 echo_area_window = sf->minibuffer_window;
1257 1472
1473 /* Don't allow other frames to refer to a deleted frame in their
1474 'environment parameter. */
1475 {
1476 Lisp_Object tail, frame1;
1477 Lisp_Object env = get_frame_param (XFRAME (frame), Qenvironment);
1478 FOR_EACH_FRAME (tail, frame1)
1479 {
1480 if (EQ (frame, frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
1481 continue;
1482 if (EQ (frame, get_frame_param (XFRAME (frame1), Qenvironment)))
1483 {
1484 store_frame_param (XFRAME (frame1), Qenvironment, env);
1485 if (!FRAMEP (env))
1486 env = frame1;
1487 }
1488 }
1489 }
1490
1258 /* Clear any X selections for this frame. */ 1491 /* Clear any X selections for this frame. */
1259#ifdef HAVE_X_WINDOWS 1492#ifdef HAVE_X_WINDOWS
1260 if (FRAME_X_P (f)) 1493 if (FRAME_X_P (f))
@@ -1295,18 +1528,34 @@ The functions are run with one arg, the frame to be deleted. */)
1295 xfree (FRAME_MESSAGE_BUF (f)); 1528 xfree (FRAME_MESSAGE_BUF (f));
1296 1529
1297 /* Since some events are handled at the interrupt level, we may get 1530 /* Since some events are handled at the interrupt level, we may get
1298 an event for f at any time; if we zero out the frame's display 1531 an event for f at any time; if we zero out the frame's terminal
1299 now, then we may trip up the event-handling code. Instead, we'll 1532 now, then we may trip up the event-handling code. Instead, we'll
1300 promise that the display of the frame must be valid until we have 1533 promise that the terminal of the frame must be valid until we
1301 called the window-system-dependent frame destruction routine. */ 1534 have called the window-system-dependent frame destruction
1535 routine. */
1302 1536
1303 /* I think this should be done with a hook. */ 1537 if (FRAME_TERMINAL (f)->delete_frame_hook)
1304#ifdef HAVE_WINDOW_SYSTEM 1538 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1305 if (FRAME_WINDOW_P (f))
1306 x_destroy_window (f);
1307#endif
1308 1539
1309 f->output_data.nothing = 0; 1540 {
1541 struct terminal *terminal = FRAME_TERMINAL (f);
1542 f->output_data.nothing = 0;
1543 f->terminal = 0; /* Now the frame is dead. */
1544
1545 /* If needed, delete the terminal that this frame was on.
1546 (This must be done after the frame is killed.) */
1547 terminal->reference_count--;
1548 if (terminal->reference_count == 0)
1549 {
1550 kb = NULL;
1551 if (terminal->delete_terminal_hook)
1552 (*terminal->delete_terminal_hook) (terminal);
1553 else
1554 delete_terminal (terminal);
1555 }
1556 else
1557 kb = terminal->kboard;
1558 }
1310 1559
1311 /* If we've deleted the last_nonminibuf_frame, then try to find 1560 /* If we've deleted the last_nonminibuf_frame, then try to find
1312 another one. */ 1561 another one. */
@@ -1331,38 +1580,39 @@ The functions are run with one arg, the frame to be deleted. */)
1331 1580
1332 /* If there's no other frame on the same kboard, get out of 1581 /* If there's no other frame on the same kboard, get out of
1333 single-kboard state if we're in it for this kboard. */ 1582 single-kboard state if we're in it for this kboard. */
1334 { 1583 if (kb != NULL)
1335 Lisp_Object frames; 1584 {
1336 /* Some frame we found on the same kboard, or nil if there are none. */ 1585 Lisp_Object frames;
1337 Lisp_Object frame_on_same_kboard; 1586 /* Some frame we found on the same kboard, or nil if there are none. */
1587 Lisp_Object frame_on_same_kboard;
1338 1588
1339 frame_on_same_kboard = Qnil; 1589 frame_on_same_kboard = Qnil;
1340 1590
1341 for (frames = Vframe_list; 1591 for (frames = Vframe_list;
1342 CONSP (frames); 1592 CONSP (frames);
1343 frames = XCDR (frames)) 1593 frames = XCDR (frames))
1344 { 1594 {
1345 Lisp_Object this; 1595 Lisp_Object this;
1346 struct frame *f1; 1596 struct frame *f1;
1347 1597
1348 this = XCAR (frames); 1598 this = XCAR (frames);
1349 if (!FRAMEP (this)) 1599 if (!FRAMEP (this))
1350 abort (); 1600 abort ();
1351 f1 = XFRAME (this); 1601 f1 = XFRAME (this);
1352 1602
1353 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)) 1603 if (kb == FRAME_KBOARD (f1))
1354 frame_on_same_kboard = this; 1604 frame_on_same_kboard = this;
1355 } 1605 }
1356 1606
1357 if (NILP (frame_on_same_kboard)) 1607 if (NILP (frame_on_same_kboard))
1358 not_single_kboard_state (FRAME_KBOARD (f)); 1608 not_single_kboard_state (kb);
1359 } 1609 }
1360 1610
1361 1611
1362 /* If we've deleted this keyboard's default_minibuffer_frame, try to 1612 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1363 find another one. Prefer minibuffer-only frames, but also notice 1613 find another one. Prefer minibuffer-only frames, but also notice
1364 frames with other windows. */ 1614 frames with other windows. */
1365 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame)) 1615 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1366 { 1616 {
1367 Lisp_Object frames; 1617 Lisp_Object frames;
1368 1618
@@ -1388,7 +1638,7 @@ The functions are run with one arg, the frame to be deleted. */)
1388 1638
1389 /* Consider only frames on the same kboard 1639 /* Consider only frames on the same kboard
1390 and only those with minibuffers. */ 1640 and only those with minibuffers. */
1391 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1) 1641 if (kb == FRAME_KBOARD (f1)
1392 && FRAME_HAS_MINIBUF_P (f1)) 1642 && FRAME_HAS_MINIBUF_P (f1))
1393 { 1643 {
1394 frame_with_minibuf = this; 1644 frame_with_minibuf = this;
@@ -1396,7 +1646,7 @@ The functions are run with one arg, the frame to be deleted. */)
1396 break; 1646 break;
1397 } 1647 }
1398 1648
1399 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)) 1649 if (kb == FRAME_KBOARD (f1))
1400 frame_on_same_kboard = this; 1650 frame_on_same_kboard = this;
1401 } 1651 }
1402 1652
@@ -1411,11 +1661,11 @@ The functions are run with one arg, the frame to be deleted. */)
1411 if (NILP (frame_with_minibuf)) 1661 if (NILP (frame_with_minibuf))
1412 abort (); 1662 abort ();
1413 1663
1414 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf; 1664 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1415 } 1665 }
1416 else 1666 else
1417 /* No frames left on this kboard--say no minibuffer either. */ 1667 /* No frames left on this kboard--say no minibuffer either. */
1418 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil; 1668 kb->Vdefault_minibuffer_frame = Qnil;
1419 } 1669 }
1420 1670
1421 /* Cause frame titles to update--necessary if we now have just one frame. */ 1671 /* Cause frame titles to update--necessary if we now have just one frame. */
@@ -1452,11 +1702,11 @@ and returns whatever that function returns. */)
1452 1702
1453#ifdef HAVE_MOUSE 1703#ifdef HAVE_MOUSE
1454 /* It's okay for the hook to refrain from storing anything. */ 1704 /* It's okay for the hook to refrain from storing anything. */
1455 if (mouse_position_hook) 1705 if (FRAME_TERMINAL (f)->mouse_position_hook)
1456 (*mouse_position_hook) (&f, -1, 1706 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1457 &lispy_dummy, &party_dummy, 1707 &lispy_dummy, &party_dummy,
1458 &x, &y, 1708 &x, &y,
1459 &long_dummy); 1709 &long_dummy);
1460 if (! NILP (x)) 1710 if (! NILP (x))
1461 { 1711 {
1462 col = XINT (x); 1712 col = XINT (x);
@@ -1496,11 +1746,11 @@ and nil for X and Y. */)
1496 1746
1497#ifdef HAVE_MOUSE 1747#ifdef HAVE_MOUSE
1498 /* It's okay for the hook to refrain from storing anything. */ 1748 /* It's okay for the hook to refrain from storing anything. */
1499 if (mouse_position_hook) 1749 if (FRAME_TERMINAL (f)->mouse_position_hook)
1500 (*mouse_position_hook) (&f, -1, 1750 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1501 &lispy_dummy, &party_dummy, 1751 &lispy_dummy, &party_dummy,
1502 &x, &y, 1752 &x, &y,
1503 &long_dummy); 1753 &long_dummy);
1504#endif 1754#endif
1505 XSETFRAME (lispy_dummy, f); 1755 XSETFRAME (lispy_dummy, f);
1506 return Fcons (lispy_dummy, Fcons (x, y)); 1756 return Fcons (lispy_dummy, Fcons (x, y));
@@ -1773,16 +2023,19 @@ doesn't support multiple overlapping frames, this function does nothing. */)
1773 (frame) 2023 (frame)
1774 Lisp_Object frame; 2024 Lisp_Object frame;
1775{ 2025{
2026 struct frame *f;
1776 if (NILP (frame)) 2027 if (NILP (frame))
1777 frame = selected_frame; 2028 frame = selected_frame;
1778 2029
1779 CHECK_LIVE_FRAME (frame); 2030 CHECK_LIVE_FRAME (frame);
1780 2031
2032 f = XFRAME (frame);
2033
1781 /* Do like the documentation says. */ 2034 /* Do like the documentation says. */
1782 Fmake_frame_visible (frame); 2035 Fmake_frame_visible (frame);
1783 2036
1784 if (frame_raise_lower_hook) 2037 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1785 (*frame_raise_lower_hook) (XFRAME (frame), 1); 2038 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1786 2039
1787 return Qnil; 2040 return Qnil;
1788} 2041}
@@ -1796,13 +2049,17 @@ doesn't support multiple overlapping frames, this function does nothing. */)
1796 (frame) 2049 (frame)
1797 Lisp_Object frame; 2050 Lisp_Object frame;
1798{ 2051{
2052 struct frame *f;
2053
1799 if (NILP (frame)) 2054 if (NILP (frame))
1800 frame = selected_frame; 2055 frame = selected_frame;
1801 2056
1802 CHECK_LIVE_FRAME (frame); 2057 CHECK_LIVE_FRAME (frame);
1803 2058
1804 if (frame_raise_lower_hook) 2059 f = XFRAME (frame);
1805 (*frame_raise_lower_hook) (XFRAME (frame), 0); 2060
2061 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2062 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1806 2063
1807 return Qnil; 2064 return Qnil;
1808} 2065}
@@ -1836,6 +2093,8 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */)
1836 (frame, focus_frame) 2093 (frame, focus_frame)
1837 Lisp_Object frame, focus_frame; 2094 Lisp_Object frame, focus_frame;
1838{ 2095{
2096 struct frame *f;
2097
1839 /* Note that we don't check for a live frame here. It's reasonable 2098 /* Note that we don't check for a live frame here. It's reasonable
1840 to redirect the focus of a frame you're about to delete, if you 2099 to redirect the focus of a frame you're about to delete, if you
1841 know what other frame should receive those keystrokes. */ 2100 know what other frame should receive those keystrokes. */
@@ -1844,10 +2103,12 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */)
1844 if (! NILP (focus_frame)) 2103 if (! NILP (focus_frame))
1845 CHECK_LIVE_FRAME (focus_frame); 2104 CHECK_LIVE_FRAME (focus_frame);
1846 2105
1847 XFRAME (frame)->focus_frame = focus_frame; 2106 f = XFRAME (frame);
2107
2108 f->focus_frame = focus_frame;
1848 2109
1849 if (frame_rehighlight_hook) 2110 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1850 (*frame_rehighlight_hook) (XFRAME (frame)); 2111 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1851 2112
1852 return Qnil; 2113 return Qnil;
1853} 2114}
@@ -1909,7 +2170,7 @@ set_frame_buffer_list (frame, list)
1909 XFRAME (frame)->buffer_list = list; 2170 XFRAME (frame)->buffer_list = list;
1910} 2171}
1911 2172
1912/* Discard BUFFER from the buffer-list of each frame. */ 2173/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1913 2174
1914void 2175void
1915frames_discard_buffer (buffer) 2176frames_discard_buffer (buffer)
@@ -1921,6 +2182,8 @@ frames_discard_buffer (buffer)
1921 { 2182 {
1922 XFRAME (frame)->buffer_list 2183 XFRAME (frame)->buffer_list
1923 = Fdelq (buffer, XFRAME (frame)->buffer_list); 2184 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2185 XFRAME (frame)->buried_buffer_list
2186 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
1924 } 2187 }
1925} 2188}
1926 2189
@@ -1979,8 +2242,8 @@ set_term_frame_name (f, name)
1979 SBYTES (f->name))) 2242 SBYTES (f->name)))
1980 return; 2243 return;
1981 2244
1982 terminal_frame_count++; 2245 tty_frame_count++;
1983 sprintf (namebuf, "F%d", terminal_frame_count); 2246 sprintf (namebuf, "F%d", tty_frame_count);
1984 name = build_string (namebuf); 2247 name = build_string (namebuf);
1985 } 2248 }
1986 else 2249 else
@@ -2008,13 +2271,18 @@ store_frame_param (f, prop, val)
2008{ 2271{
2009 register Lisp_Object old_alist_elt; 2272 register Lisp_Object old_alist_elt;
2010 2273
2011 /* The buffer-alist parameter is stored in a special place and is 2274 /* The buffer-list parameters are stored in a special place and not
2012 not in the alist. */ 2275 in the alist. */
2013 if (EQ (prop, Qbuffer_list)) 2276 if (EQ (prop, Qbuffer_list))
2014 { 2277 {
2015 f->buffer_list = val; 2278 f->buffer_list = val;
2016 return; 2279 return;
2017 } 2280 }
2281 if (EQ (prop, Qburied_buffer_list))
2282 {
2283 f->buried_buffer_list = val;
2284 return;
2285 }
2018 2286
2019 /* If PROP is a symbol which is supposed to have frame-local values, 2287 /* If PROP is a symbol which is supposed to have frame-local values,
2020 and it is set up based on this frame, switch to the global 2288 and it is set up based on this frame, switch to the global
@@ -2027,6 +2295,7 @@ store_frame_param (f, prop, val)
2027 if ((BUFFER_LOCAL_VALUEP (valcontents) 2295 if ((BUFFER_LOCAL_VALUEP (valcontents)
2028 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 2296 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2029 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame 2297 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2298 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2030 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f) 2299 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2031 swap_in_global_binding (prop); 2300 swap_in_global_binding (prop);
2032 } 2301 }
@@ -2154,6 +2423,7 @@ If FRAME is omitted, return information on the currently selected frame. */)
2154 : FRAME_MINIBUF_WINDOW (f))); 2423 : FRAME_MINIBUF_WINDOW (f)));
2155 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); 2424 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2156 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame)); 2425 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2426 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2157 2427
2158 /* I think this should be done with a hook. */ 2428 /* I think this should be done with a hook. */
2159#ifdef HAVE_WINDOW_SYSTEM 2429#ifdef HAVE_WINDOW_SYSTEM
@@ -2321,9 +2591,44 @@ enabled such bindings for that variable with `make-variable-frame-local'. */)
2321 call1 (Qframe_set_background_mode, frame); 2591 call1 (Qframe_set_background_mode, frame);
2322 } 2592 }
2323 } 2593 }
2594}
2324 2595
2325 return Qnil; 2596DEFUN ("frame-with-environment", Fframe_with_environment, Sframe_with_environment, 0, 1, 0,
2597 doc: /* Return the frame that has the environment variable list for FRAME.
2598
2599The frame-local environment variable list is normally shared between
2600frames that were created in the same Emacsclient session. The
2601environment list is stored in a single frame's 'environment parameter;
2602the other frames' 'environment parameter is set to this frame. This
2603function follows the chain of 'environment references to reach the
2604frame that stores the actual local environment list, and returns that
2605frame. */)
2606 (frame)
2607 Lisp_Object frame;
2608{
2609 Lisp_Object hare, tortoise;
2610
2611 if (NILP (frame))
2612 frame = selected_frame;
2613 CHECK_FRAME (frame);
2614
2615 hare = tortoise = get_frame_param (XFRAME (frame), Qenvironment);
2616 while (!NILP (hare) && FRAMEP (hare))
2617 {
2618 frame = hare;
2619 hare = get_frame_param (XFRAME (hare), Qenvironment);
2620 if (NILP (hare) || !FRAMEP (hare))
2621 break;
2622 frame = hare;
2623 hare = get_frame_param (XFRAME (hare), Qenvironment);
2624 tortoise = get_frame_param (XFRAME (tortoise), Qenvironment);
2625 if (EQ (hare, tortoise))
2626 error ("Cyclic frame-local environment indirection");
2627 }
2628
2629 return frame;
2326} 2630}
2631
2327 2632
2328DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height, 2633DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2329 0, 1, 0, 2634 0, 1, 0,
@@ -2740,9 +3045,8 @@ x_set_frame_parameters (f, alist)
2740 if (NATNUMP (param_index) 3045 if (NATNUMP (param_index)
2741 && (XFASTINT (param_index) 3046 && (XFASTINT (param_index)
2742 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3047 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2743 && rif->frame_parm_handlers[XINT (param_index)]) 3048 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2744 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 3049 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2745
2746 unbind_to (count, Qnil); 3050 unbind_to (count, Qnil);
2747 } 3051 }
2748 } 3052 }
@@ -2786,8 +3090,8 @@ x_set_frame_parameters (f, alist)
2786 if (NATNUMP (param_index) 3090 if (NATNUMP (param_index)
2787 && (XFASTINT (param_index) 3091 && (XFASTINT (param_index)
2788 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3092 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2789 && rif->frame_parm_handlers[XINT (param_index)]) 3093 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2790 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 3094 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2791 } 3095 }
2792 } 3096 }
2793 3097
@@ -3025,8 +3329,8 @@ x_set_fullscreen (f, new_value, old_value)
3025 else if (EQ (new_value, Qfullheight)) 3329 else if (EQ (new_value, Qfullheight))
3026 f->want_fullscreen = FULLSCREEN_HEIGHT; 3330 f->want_fullscreen = FULLSCREEN_HEIGHT;
3027 3331
3028 if (fullscreen_hook != NULL) 3332 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3029 fullscreen_hook (f); 3333 FRAME_TERMINAL (f)->fullscreen_hook (f);
3030} 3334}
3031 3335
3032 3336
@@ -3075,9 +3379,9 @@ x_set_screen_gamma (f, new_value, old_value)
3075 if (NATNUMP (index) 3379 if (NATNUMP (index)
3076 && (XFASTINT (index) 3380 && (XFASTINT (index)
3077 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3381 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3078 && rif->frame_parm_handlers[XFASTINT (index)]) 3382 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3079 (*(rif->frame_parm_handlers[XFASTINT (index)])) 3383 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3080 (f, bgcolor, Qnil); 3384 (f, bgcolor, Qnil);
3081 } 3385 }
3082 3386
3083 Fclear_face_cache (Qnil); 3387 Fclear_face_cache (Qnil);
@@ -4013,13 +4317,23 @@ syms_of_frame ()
4013 staticpro (&Qbuffer_predicate); 4317 staticpro (&Qbuffer_predicate);
4014 Qbuffer_list = intern ("buffer-list"); 4318 Qbuffer_list = intern ("buffer-list");
4015 staticpro (&Qbuffer_list); 4319 staticpro (&Qbuffer_list);
4320 Qburied_buffer_list = intern ("buried-buffer-list");
4321 staticpro (&Qburied_buffer_list);
4016 Qdisplay_type = intern ("display-type"); 4322 Qdisplay_type = intern ("display-type");
4017 staticpro (&Qdisplay_type); 4323 staticpro (&Qdisplay_type);
4018 Qbackground_mode = intern ("background-mode"); 4324 Qbackground_mode = intern ("background-mode");
4019 staticpro (&Qbackground_mode); 4325 staticpro (&Qbackground_mode);
4020 Qtty_color_mode = intern ("tty-color-mode"); 4326 Qtty_color_mode = intern ("tty-color-mode");
4021 staticpro (&Qtty_color_mode); 4327 staticpro (&Qtty_color_mode);
4022 4328 Qtty = intern ("tty");
4329 staticpro (&Qtty);
4330 Qtty_type = intern ("tty-type");
4331 staticpro (&Qtty_type);
4332 Qwindow_system = intern ("window-system");
4333 staticpro (&Qwindow_system);
4334 Qenvironment = intern ("environment");
4335 staticpro (&Qenvironment);
4336
4023 Qface_set_after_frame_default = intern ("face-set-after-frame-default"); 4337 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4024 staticpro (&Qface_set_after_frame_default); 4338 staticpro (&Qface_set_after_frame_default);
4025 4339
@@ -4039,6 +4353,11 @@ syms_of_frame ()
4039 Qx_frame_parameter = intern ("x-frame-parameter"); 4353 Qx_frame_parameter = intern ("x-frame-parameter");
4040 staticpro (&Qx_frame_parameter); 4354 staticpro (&Qx_frame_parameter);
4041 4355
4356 Qterminal = intern ("terminal");
4357 staticpro (&Qterminal);
4358 Qterminal_live_p = intern ("terminal-live-p");
4359 staticpro (&Qterminal_live_p);
4360
4042 { 4361 {
4043 int i; 4362 int i;
4044 4363
@@ -4087,6 +4406,7 @@ These may be set in your init file, like this:
4087These override values given in window system configuration data, 4406These override values given in window system configuration data,
4088 including X Windows' defaults database. 4407 including X Windows' defaults database.
4089For values specific to the first Emacs frame, see `initial-frame-alist'. 4408For values specific to the first Emacs frame, see `initial-frame-alist'.
4409For window-system specific values, see `window-system-default-frame-alist'.
4090For values specific to the separate minibuffer frame, see 4410For values specific to the separate minibuffer frame, see
4091 `minibuffer-frame-alist'. 4411 `minibuffer-frame-alist'.
4092The `menu-bar-lines' element of the list controls whether new frames 4412The `menu-bar-lines' element of the list controls whether new frames
@@ -4108,7 +4428,7 @@ Setting this variable does not affect existing frames, only new ones. */);
4108#endif 4428#endif
4109 4429
4110 DEFVAR_LISP ("terminal-frame", &Vterminal_frame, 4430 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4111 doc: /* The initial frame-object, which represents Emacs's stdout. */); 4431 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4112 4432
4113 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified, 4433 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4114 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */); 4434 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
@@ -4133,7 +4453,14 @@ when the mouse is over clickable text. */);
4133 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions, 4453 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4134 doc: /* Functions to be run before deleting a frame. 4454 doc: /* Functions to be run before deleting a frame.
4135The functions are run with one arg, the frame to be deleted. 4455The functions are run with one arg, the frame to be deleted.
4136See `delete-frame'. */); 4456See `delete-frame'.
4457
4458Note that functions in this list may be called twice on the same
4459frame. In the second invocation, the frame is already deleted, and
4460the function should do nothing. (You can use `frame-live-p' to check
4461for this.) This wrinkle happens when an earlier function in
4462`delete-frame-functions' (indirectly) calls delete-frame
4463recursively. */);
4137 Vdelete_frame_functions = Qnil; 4464 Vdelete_frame_functions = Qnil;
4138 4465
4139 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame, 4466 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
@@ -4156,6 +4483,7 @@ This variable is local to the current terminal and cannot be buffer-local. */);
4156 defsubr (&Sactive_minibuffer_window); 4483 defsubr (&Sactive_minibuffer_window);
4157 defsubr (&Sframep); 4484 defsubr (&Sframep);
4158 defsubr (&Sframe_live_p); 4485 defsubr (&Sframe_live_p);
4486 defsubr (&Swindow_system);
4159 defsubr (&Smake_terminal_frame); 4487 defsubr (&Smake_terminal_frame);
4160 defsubr (&Shandle_switch_frame); 4488 defsubr (&Shandle_switch_frame);
4161 defsubr (&Sselect_frame); 4489 defsubr (&Sselect_frame);
@@ -4189,6 +4517,7 @@ This variable is local to the current terminal and cannot be buffer-local. */);
4189 defsubr (&Sframe_parameters); 4517 defsubr (&Sframe_parameters);
4190 defsubr (&Sframe_parameter); 4518 defsubr (&Sframe_parameter);
4191 defsubr (&Smodify_frame_parameters); 4519 defsubr (&Smodify_frame_parameters);
4520 defsubr (&Sframe_with_environment);
4192 defsubr (&Sframe_char_height); 4521 defsubr (&Sframe_char_height);
4193 defsubr (&Sframe_char_width); 4522 defsubr (&Sframe_char_width);
4194 defsubr (&Sframe_pixel_height); 4523 defsubr (&Sframe_pixel_height);
diff --git a/src/frame.h b/src/frame.h
index d09a0d1ae04..47f7483994e 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -29,9 +29,7 @@ Boston, MA 02110-1301, USA. */
29 29
30/* Miscellanea. */ 30/* Miscellanea. */
31 31
32/* Nonzero means don't assume anything about current contents of 32/* Nonzero means there is at least one garbaged frame. */
33 actual terminal frame */
34
35extern int frame_garbaged; 33extern int frame_garbaged;
36 34
37/* Nonzero means FRAME_MESSAGE_BUF (selected_frame) is being used by 35/* Nonzero means FRAME_MESSAGE_BUF (selected_frame) is being used by
@@ -44,6 +42,7 @@ extern int message_buf_print;
44 42
45enum output_method 43enum output_method
46{ 44{
45 output_initial,
47 output_termcap, 46 output_termcap,
48 output_x_window, 47 output_x_window,
49 output_msdos_raw, 48 output_msdos_raw,
@@ -68,30 +67,10 @@ enum text_cursor_kinds
68 HBAR_CURSOR 67 HBAR_CURSOR
69}; 68};
70 69
71#if !defined(MSDOS) && !defined(WINDOWSNT) && !defined(MAC_OS) 70#define FRAME_FOREGROUND_PIXEL(f) ((f)->foreground_pixel)
72 71#define FRAME_BACKGROUND_PIXEL(f) ((f)->background_pixel)
73#if !defined(HAVE_X_WINDOWS)
74
75#define PIX_TYPE unsigned long
76
77/* A (mostly empty) x_output structure definition for building Emacs
78 on Unix and GNU/Linux without X support. */
79struct x_output
80{
81 PIX_TYPE background_pixel;
82 PIX_TYPE foreground_pixel;
83};
84
85#endif /* ! HAVE_X_WINDOWS */
86
87 72
88#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) 73struct terminal;
89#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
90
91/* A structure describing a termcap frame display. */
92extern struct x_output tty_display;
93
94#endif /* ! MSDOS && ! WINDOWSNT && ! MAC_OS */
95 74
96struct frame 75struct frame
97{ 76{
@@ -153,7 +132,7 @@ struct frame
153 Actually, we don't specify exactly what is stored here at all; the 132 Actually, we don't specify exactly what is stored here at all; the
154 scroll bar implementation code can use it to store anything it likes. 133 scroll bar implementation code can use it to store anything it likes.
155 This field is marked by the garbage collector. It is here 134 This field is marked by the garbage collector. It is here
156 instead of in the `display' structure so that the garbage 135 instead of in the `device' structure so that the garbage
157 collector doesn't need to look inside the window-system-dependent 136 collector doesn't need to look inside the window-system-dependent
158 structure. */ 137 structure. */
159 Lisp_Object scroll_bars; 138 Lisp_Object scroll_bars;
@@ -182,6 +161,10 @@ struct frame
182 /* List of buffers viewed in this frame, for other-buffer. */ 161 /* List of buffers viewed in this frame, for other-buffer. */
183 Lisp_Object buffer_list; 162 Lisp_Object buffer_list;
184 163
164 /* List of buffers that were viewed, then buried in this frame. The
165 most recently buried buffer is first. For last-buffer. */
166 Lisp_Object buried_buffer_list;
167
185 /* A dummy window used to display menu bars under X when no X 168 /* A dummy window used to display menu bars under X when no X
186 toolkit support is available. */ 169 toolkit support is available. */
187 Lisp_Object menu_bar_window; 170 Lisp_Object menu_bar_window;
@@ -283,20 +266,24 @@ struct frame
283 /* Canonical Y unit. Height of a line, in pixels. */ 266 /* Canonical Y unit. Height of a line, in pixels. */
284 int line_height; 267 int line_height;
285 268
286 /* The output method says how the contents of this frame 269 /* The output method says how the contents of this frame are
287 are displayed. It could be using termcap, or using an X window. */ 270 displayed. It could be using termcap, or using an X window.
271 This must be the same as the terminal->type. */
288 enum output_method output_method; 272 enum output_method output_method;
289 273
290 /* A structure of auxiliary data used for displaying the contents. 274 /* The terminal device that this frame uses. If this is NULL, then
291 struct x_output is used for X window frames; 275 the frame has been deleted. */
292 it is defined in xterm.h. 276 struct terminal *terminal;
293 struct w32_output is used for W32 window frames; 277
294 it is defined in w32term.h. */ 278 /* Device-dependent, frame-local auxiliary data used for displaying
279 the contents. When the frame is deleted, this data is deleted as
280 well. */
295 union output_data 281 union output_data
296 { 282 {
297 struct x_output *x; 283 struct tty_output *tty; /* termchar.h */
298 struct w32_output *w32; 284 struct x_output *x; /* xterm.h */
299 struct mac_output *mac; 285 struct w32_output *w32; /* w32term.h */
286 struct mac_output *mac; /* macterm.h */
300 EMACS_INT nothing; 287 EMACS_INT nothing;
301 } 288 }
302 output_data; 289 output_data;
@@ -311,13 +298,6 @@ struct frame
311 /* The extra width (in pixels) currently allotted for fringes. */ 298 /* The extra width (in pixels) currently allotted for fringes. */
312 int left_fringe_width, right_fringe_width; 299 int left_fringe_width, right_fringe_width;
313 300
314#ifdef MULTI_KBOARD
315 /* A pointer to the kboard structure associated with this frame.
316 For termcap frames, this points to initial_kboard. For X frames,
317 it will be the same as display.x->display_info->kboard. */
318 struct kboard *kboard;
319#endif
320
321 /* See FULLSCREEN_ enum below */ 301 /* See FULLSCREEN_ enum below */
322 int want_fullscreen; 302 int want_fullscreen;
323 303
@@ -341,13 +321,13 @@ struct frame
341 frame becomes visible again, it must be marked as garbaged. The 321 frame becomes visible again, it must be marked as garbaged. The
342 FRAME_SAMPLE_VISIBILITY macro takes care of this. 322 FRAME_SAMPLE_VISIBILITY macro takes care of this.
343 323
344 On Windows NT/9X, to avoid wasting effort updating visible frames 324 On ttys and on Windows NT/9X, to avoid wasting effort updating
345 that are actually completely obscured by other windows on the 325 visible frames that are actually completely obscured by other
346 display, we bend the meaning of visible slightly: if greater than 326 windows on the display, we bend the meaning of visible slightly:
347 1, then the frame is obscured - we still consider it to be 327 if greater than 1, then the frame is obscured - we still consider
348 "visible" as seen from lisp, but we don't bother updating it. We 328 it to be "visible" as seen from lisp, but we don't bother
349 must take care to garbage the frame when it ceaces to be obscured 329 updating it. We must take care to garbage the frame when it
350 though. Note that these semantics are only used on NT/9X. 330 ceaces to be obscured though.
351 331
352 iconified is nonzero if the frame is currently iconified. 332 iconified is nonzero if the frame is currently iconified.
353 333
@@ -441,7 +421,7 @@ struct frame
441 /* The baud rate that was used to calculate costs for this frame. */ 421 /* The baud rate that was used to calculate costs for this frame. */
442 int cost_calculation_baud_rate; 422 int cost_calculation_baud_rate;
443 423
444 /* Nonzero if the mouse has moved on this display 424 /* Nonzero if the mouse has moved on this display device
445 since the last time we checked. */ 425 since the last time we checked. */
446 char mouse_moved; 426 char mouse_moved;
447 427
@@ -460,7 +440,11 @@ struct frame
460 /* Set to non-zero in when we want for force a flush_display in 440 /* Set to non-zero in when we want for force a flush_display in
461 update_frame, usually after resizing the frame. */ 441 update_frame, usually after resizing the frame. */
462 unsigned force_flush_display_p : 1; 442 unsigned force_flush_display_p : 1;
463 443
444 /* All display backends seem to need these two pixel values. */
445 unsigned long background_pixel;
446 unsigned long foreground_pixel;
447
464 /* Set to non-zero if the default face for the frame has been 448 /* Set to non-zero if the default face for the frame has been
465 realized. Reset to zero whenever the default face changes. 449 realized. Reset to zero whenever the default face changes.
466 Used to see the difference between a font change and face change. */ 450 Used to see the difference between a font change and face change. */
@@ -479,7 +463,7 @@ struct frame
479}; 463};
480 464
481#ifdef MULTI_KBOARD 465#ifdef MULTI_KBOARD
482#define FRAME_KBOARD(f) ((f)->kboard) 466#define FRAME_KBOARD(f) ((f)->terminal->kboard)
483#else 467#else
484#define FRAME_KBOARD(f) (&the_only_kboard) 468#define FRAME_KBOARD(f) (&the_only_kboard)
485#endif 469#endif
@@ -493,6 +477,7 @@ typedef struct frame *FRAME_PTR;
493#define WINDOW_FRAME(w) (w)->frame 477#define WINDOW_FRAME(w) (w)->frame
494 478
495/* Test a frame for particular kinds of display methods. */ 479/* Test a frame for particular kinds of display methods. */
480#define FRAME_INITIAL_P(f) ((f)->output_method == output_initial)
496#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap) 481#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap)
497#define FRAME_X_P(f) ((f)->output_method == output_x_window) 482#define FRAME_X_P(f) ((f)->output_method == output_x_window)
498#define FRAME_W32_P(f) ((f)->output_method == output_w32) 483#define FRAME_W32_P(f) ((f)->output_method == output_w32)
@@ -516,7 +501,7 @@ typedef struct frame *FRAME_PTR;
516#endif 501#endif
517 502
518/* Nonzero if frame F is still alive (not deleted). */ 503/* Nonzero if frame F is still alive (not deleted). */
519#define FRAME_LIVE_P(f) ((f)->output_data.nothing != 0) 504#define FRAME_LIVE_P(f) ((f)->terminal != 0)
520 505
521/* Nonzero if frame F is a minibuffer-only frame. */ 506/* Nonzero if frame F is a minibuffer-only frame. */
522#define FRAME_MINIBUF_ONLY_P(f) \ 507#define FRAME_MINIBUF_ONLY_P(f) \
@@ -756,7 +741,10 @@ typedef struct frame *FRAME_PTR;
756 741
757 Also, if a frame used to be invisible, but has just become visible, 742 Also, if a frame used to be invisible, but has just become visible,
758 it must be marked as garbaged, since redisplay hasn't been keeping 743 it must be marked as garbaged, since redisplay hasn't been keeping
759 up its contents. */ 744 up its contents.
745
746 Note that a tty frame is visible if and only if it is the topmost
747 frame. */
760 748
761#define FRAME_SAMPLE_VISIBILITY(f) \ 749#define FRAME_SAMPLE_VISIBILITY(f) \
762 (((f)->async_visible && (f)->visible != (f)->async_visible) ? \ 750 (((f)->async_visible && (f)->visible != (f)->async_visible) ? \
@@ -789,10 +777,14 @@ typedef struct frame *FRAME_PTR;
789 777
790 778
791extern Lisp_Object Qframep, Qframe_live_p; 779extern Lisp_Object Qframep, Qframe_live_p;
780extern Lisp_Object Qtty, Qtty_type;
781extern Lisp_Object Qterminal, Qterminal_live_p;
782extern Lisp_Object Qenvironment;
792 783
793extern struct frame *last_nonminibuf_frame; 784extern struct frame *last_nonminibuf_frame;
794 785
795extern struct frame *make_terminal_frame P_ ((void)); 786extern struct frame *make_initial_frame P_ ((void));
787extern struct frame *make_terminal_frame P_ ((struct terminal *));
796extern struct frame *make_frame P_ ((int)); 788extern struct frame *make_frame P_ ((int));
797#ifdef HAVE_WINDOW_SYSTEM 789#ifdef HAVE_WINDOW_SYSTEM
798extern struct frame *make_minibuffer_frame P_ ((void)); 790extern struct frame *make_minibuffer_frame P_ ((void));
@@ -992,7 +984,7 @@ extern Lisp_Object selected_frame;
992 984
993extern Lisp_Object Qauto_raise, Qauto_lower; 985extern Lisp_Object Qauto_raise, Qauto_lower;
994extern Lisp_Object Qborder_color, Qborder_width; 986extern Lisp_Object Qborder_color, Qborder_width;
995extern Lisp_Object Qbuffer_predicate, Qbuffer_list; 987extern Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
996extern Lisp_Object Qcursor_color, Qcursor_type; 988extern Lisp_Object Qcursor_color, Qcursor_type;
997extern Lisp_Object Qfont; 989extern Lisp_Object Qfont;
998extern Lisp_Object Qbackground_color, Qforeground_color; 990extern Lisp_Object Qbackground_color, Qforeground_color;
@@ -1024,6 +1016,8 @@ extern Lisp_Object Qx_resource_name;
1024extern Lisp_Object Qleft, Qright, Qtop, Qbox; 1016extern Lisp_Object Qleft, Qright, Qtop, Qbox;
1025extern Lisp_Object Qdisplay; 1017extern Lisp_Object Qdisplay;
1026 1018
1019extern Lisp_Object Qwindow_system;
1020
1027#ifdef HAVE_WINDOW_SYSTEM 1021#ifdef HAVE_WINDOW_SYSTEM
1028 1022
1029/* The class of this X application. */ 1023/* The class of this X application. */
diff --git a/src/fringe.c b/src/fringe.c
index a3a28ba987e..2fb88ce01e8 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -29,6 +29,7 @@ Boston, MA 02110-1301, USA. */
29#include "dispextern.h" 29#include "dispextern.h"
30#include "buffer.h" 30#include "buffer.h"
31#include "blockinput.h" 31#include "blockinput.h"
32#include "termhooks.h"
32 33
33#ifdef HAVE_WINDOW_SYSTEM 34#ifdef HAVE_WINDOW_SYSTEM
34 35
@@ -686,7 +687,7 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
686 break; 687 break;
687 } 688 }
688 689
689 rif->draw_fringe_bitmap (w, row, &p); 690 FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p);
690} 691}
691 692
692static int 693static int
@@ -1278,6 +1279,8 @@ destroy_fringe_bitmap (n)
1278 fbp = &fringe_bitmaps[n]; 1279 fbp = &fringe_bitmaps[n];
1279 if (*fbp && (*fbp)->dynamic) 1280 if (*fbp && (*fbp)->dynamic)
1280 { 1281 {
1282 /* XXX Is SELECTED_FRAME OK here? */
1283 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1281 if (rif && rif->destroy_fringe_bitmap) 1284 if (rif && rif->destroy_fringe_bitmap)
1282 rif->destroy_fringe_bitmap (n); 1285 rif->destroy_fringe_bitmap (n);
1283 xfree (*fbp); 1286 xfree (*fbp);
@@ -1383,6 +1386,9 @@ init_fringe_bitmap (which, fb, once_p)
1383 1386
1384 if (!once_p) 1387 if (!once_p)
1385 { 1388 {
1389 /* XXX Is SELECTED_FRAME OK here? */
1390 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1391
1386 destroy_fringe_bitmap (which); 1392 destroy_fringe_bitmap (which);
1387 1393
1388 if (rif && rif->define_fringe_bitmap) 1394 if (rif && rif->define_fringe_bitmap)
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 02e42f74852..24579d7a1d1 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -865,7 +865,7 @@ xg_create_frame_widgets (f)
865 865
866 /* Since GTK clears its window by filling with the background color, 866 /* Since GTK clears its window by filling with the background color,
867 we must keep X and GTK background in sync. */ 867 we must keep X and GTK background in sync. */
868 xg_pix_to_gcolor (wfixed, f->output_data.x->background_pixel, &bg); 868 xg_pix_to_gcolor (wfixed, FRAME_BACKGROUND_PIXEL (f), &bg);
869 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg); 869 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg);
870 870
871 /* Also, do not let any background pixmap to be set, this looks very 871 /* Also, do not let any background pixmap to be set, this looks very
@@ -2034,7 +2034,7 @@ xg_create_one_menuitem (item, f, select_cb, highlight_cb, cl_data, group)
2034 return w; 2034 return w;
2035} 2035}
2036 2036
2037/* Callback called when keyboard traversal (started by menu-bar-open) ends. 2037/* Callback called when keyboard traversal (started by x-menu-bar-open) ends.
2038 WMENU is the menu for which traversal has been done. DATA points to the 2038 WMENU is the menu for which traversal has been done. DATA points to the
2039 frame for WMENU. We must release grabs, some bad interaction between GTK 2039 frame for WMENU. We must release grabs, some bad interaction between GTK
2040 and Emacs makes the menus keep the grabs. */ 2040 and Emacs makes the menus keep the grabs. */
diff --git a/src/image.c b/src/image.c
index b8317b1e982..198ffaf4651 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1824,7 +1824,7 @@ lookup_image (f, spec)
1824 struct frame *f; 1824 struct frame *f;
1825 Lisp_Object spec; 1825 Lisp_Object spec;
1826{ 1826{
1827 struct image_cache *c = FRAME_X_IMAGE_CACHE (f); 1827 struct image_cache *c;
1828 struct image *img; 1828 struct image *img;
1829 int i; 1829 int i;
1830 unsigned hash; 1830 unsigned hash;
@@ -1836,6 +1836,8 @@ lookup_image (f, spec)
1836 xassert (FRAME_WINDOW_P (f)); 1836 xassert (FRAME_WINDOW_P (f));
1837 xassert (valid_image_p (spec)); 1837 xassert (valid_image_p (spec));
1838 1838
1839 c = FRAME_X_IMAGE_CACHE (f);
1840
1839 GCPRO1 (spec); 1841 GCPRO1 (spec);
1840 1842
1841 /* Look up SPEC in the hash table of the image cache. */ 1843 /* Look up SPEC in the hash table of the image cache. */
diff --git a/src/indent.c b/src/indent.c
index b43120ab560..8495d43cb9c 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -20,6 +20,8 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */ 20Boston, MA 02110-1301, USA. */
21 21
22#include <config.h> 22#include <config.h>
23#include <stdio.h>
24
23#include "lisp.h" 25#include "lisp.h"
24#include "buffer.h" 26#include "buffer.h"
25#include "charset.h" 27#include "charset.h"
diff --git a/src/intervals.h b/src/intervals.h
index 7e07a6b4f31..f89b748f2ff 100644
--- a/src/intervals.h
+++ b/src/intervals.h
@@ -88,7 +88,7 @@ struct interval
88 88
89#ifdef ENABLE_CHECKING 89#ifdef ENABLE_CHECKING
90#define NULL_INTERVAL_P(i) \ 90#define NULL_INTERVAL_P(i) \
91 (CHECK (!INT_LISPLIKE (i), "non-interval"), (i) == NULL_INTERVAL) 91 ((void)CHECK (!INT_LISPLIKE (i), "non-interval"), (i) == NULL_INTERVAL)
92/* old #define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL || INT_LISPLIKE (i)) */ 92/* old #define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL || INT_LISPLIKE (i)) */
93#else 93#else
94#define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL) 94#define NULL_INTERVAL_P(i) ((i) == NULL_INTERVAL)
diff --git a/src/keyboard.c b/src/keyboard.c
index bda07473ccf..3404c60a93a 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -23,13 +23,13 @@ Boston, MA 02110-1301, USA. */
23#include <config.h> 23#include <config.h>
24#include <signal.h> 24#include <signal.h>
25#include <stdio.h> 25#include <stdio.h>
26#include "lisp.h"
26#include "termchar.h" 27#include "termchar.h"
27#include "termopts.h" 28#include "termopts.h"
28#include "lisp.h" 29#include "frame.h"
29#include "termhooks.h" 30#include "termhooks.h"
30#include "macros.h" 31#include "macros.h"
31#include "keyboard.h" 32#include "keyboard.h"
32#include "frame.h"
33#include "window.h" 33#include "window.h"
34#include "commands.h" 34#include "commands.h"
35#include "buffer.h" 35#include "buffer.h"
@@ -59,7 +59,6 @@ Boston, MA 02110-1301, USA. */
59#endif /* not MSDOS */ 59#endif /* not MSDOS */
60 60
61#include "syssignal.h" 61#include "syssignal.h"
62#include "systty.h"
63 62
64#include <sys/types.h> 63#include <sys/types.h>
65#ifdef HAVE_UNISTD_H 64#ifdef HAVE_UNISTD_H
@@ -97,9 +96,6 @@ volatile int interrupt_input_blocked;
97int interrupt_input_pending; 96int interrupt_input_pending;
98 97
99 98
100/* File descriptor to use for input. */
101extern int input_fd;
102
103#ifdef HAVE_WINDOW_SYSTEM 99#ifdef HAVE_WINDOW_SYSTEM
104/* Make all keyboard buffers much bigger when using X windows. */ 100/* Make all keyboard buffers much bigger when using X windows. */
105#ifdef MAC_OS8 101#ifdef MAC_OS8
@@ -425,16 +421,6 @@ Lisp_Object Vecho_keystrokes;
425/* Form to evaluate (if non-nil) when Emacs is started. */ 421/* Form to evaluate (if non-nil) when Emacs is started. */
426Lisp_Object Vtop_level; 422Lisp_Object Vtop_level;
427 423
428/* User-supplied table to translate input characters. */
429Lisp_Object Vkeyboard_translate_table;
430
431/* Keymap mapping ASCII function key sequences onto their preferred forms. */
432extern Lisp_Object Vfunction_key_map;
433
434/* Another keymap that maps key sequences into key sequences.
435 This one takes precedence over ordinary definitions. */
436extern Lisp_Object Vkey_translation_map;
437
438/* If non-nil, this implements the current input method. */ 424/* If non-nil, this implements the current input method. */
439Lisp_Object Vinput_method_function; 425Lisp_Object Vinput_method_function;
440Lisp_Object Qinput_method_function; 426Lisp_Object Qinput_method_function;
@@ -458,6 +444,12 @@ Lisp_Object Qpre_command_hook, Vpre_command_hook;
458Lisp_Object Qpost_command_hook, Vpost_command_hook; 444Lisp_Object Qpost_command_hook, Vpost_command_hook;
459Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal; 445Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal;
460 446
447/* Parent keymap of terminal-local function-key-map instances. */
448Lisp_Object Vfunction_key_map;
449
450/* Parent keymap of terminal-local key-translation-map instances. */
451Lisp_Object Vkey_translation_map;
452
461/* List of deferred actions to be performed at a later time. 453/* List of deferred actions to be performed at a later time.
462 The precise format isn't relevant here; we just check whether it is nil. */ 454 The precise format isn't relevant here; we just check whether it is nil. */
463Lisp_Object Vdeferred_action_list; 455Lisp_Object Vdeferred_action_list;
@@ -475,11 +467,6 @@ FILE *dribble;
475/* Nonzero if input is available. */ 467/* Nonzero if input is available. */
476int input_pending; 468int input_pending;
477 469
478/* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
479 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
480
481int meta_key;
482
483extern char *pending_malloc_warning; 470extern char *pending_malloc_warning;
484 471
485/* Circular buffer for pre-read keyboard input. */ 472/* Circular buffer for pre-read keyboard input. */
@@ -609,9 +596,6 @@ int interrupt_input;
609/* Nonzero while interrupts are temporarily deferred during redisplay. */ 596/* Nonzero while interrupts are temporarily deferred during redisplay. */
610int interrupts_deferred; 597int interrupts_deferred;
611 598
612/* Nonzero means use ^S/^Q for flow control. */
613int flow_control;
614
615/* Allow m- file to inhibit use of FIONREAD. */ 599/* Allow m- file to inhibit use of FIONREAD. */
616#ifdef BROKEN_FIONREAD 600#ifdef BROKEN_FIONREAD
617#undef FIONREAD 601#undef FIONREAD
@@ -694,8 +678,9 @@ static void save_getcjmp ();
694static void restore_getcjmp P_ ((jmp_buf)); 678static void restore_getcjmp P_ ((jmp_buf));
695static Lisp_Object apply_modifiers P_ ((int, Lisp_Object)); 679static Lisp_Object apply_modifiers P_ ((int, Lisp_Object));
696static void clear_event P_ ((struct input_event *)); 680static void clear_event P_ ((struct input_event *));
697static void any_kboard_state P_ ((void)); 681static Lisp_Object restore_kboard_configuration P_ ((Lisp_Object));
698static SIGTYPE interrupt_signal P_ ((int signalnum)); 682static SIGTYPE interrupt_signal P_ ((int signalnum));
683static void handle_interrupt P_ ((void));
699static void timer_start_idle P_ ((void)); 684static void timer_start_idle P_ ((void));
700static void timer_stop_idle P_ ((void)); 685static void timer_stop_idle P_ ((void));
701static void timer_resume_idle P_ ((void)); 686static void timer_resume_idle P_ ((void));
@@ -1061,24 +1046,20 @@ This function is called by the editor initialization to begin editing. */)
1061 like it is done in the splash screen display, we have to 1046 like it is done in the splash screen display, we have to
1062 make sure that we restore single_kboard as command_loop_1 1047 make sure that we restore single_kboard as command_loop_1
1063 would have done if it were left normally. */ 1048 would have done if it were left normally. */
1064 record_unwind_protect (recursive_edit_unwind, 1049 if (command_loop_level > 0)
1065 Fcons (buffer, single_kboard ? Qt : Qnil)); 1050 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1051 record_unwind_protect (recursive_edit_unwind, buffer);
1066 1052
1067 recursive_edit_1 (); 1053 recursive_edit_1 ();
1068 return unbind_to (count, Qnil); 1054 return unbind_to (count, Qnil);
1069} 1055}
1070 1056
1071Lisp_Object 1057Lisp_Object
1072recursive_edit_unwind (info) 1058recursive_edit_unwind (buffer)
1073 Lisp_Object info; 1059 Lisp_Object buffer;
1074{ 1060{
1075 if (BUFFERP (XCAR (info))) 1061 if (BUFFERP (buffer))
1076 Fset_buffer (XCAR (info)); 1062 Fset_buffer (buffer);
1077
1078 if (NILP (XCDR (info)))
1079 any_kboard_state ();
1080 else
1081 single_kboard_state ();
1082 1063
1083 command_loop_level--; 1064 command_loop_level--;
1084 update_mode_lines = 1; 1065 update_mode_lines = 1;
@@ -1086,6 +1067,8 @@ recursive_edit_unwind (info)
1086} 1067}
1087 1068
1088 1069
1070#if 0 /* These two functions are now replaced with
1071 temporarily_switch_to_single_kboard. */
1089static void 1072static void
1090any_kboard_state () 1073any_kboard_state ()
1091{ 1074{
@@ -1116,6 +1099,7 @@ single_kboard_state ()
1116 single_kboard = 1; 1099 single_kboard = 1;
1117#endif 1100#endif
1118} 1101}
1102#endif
1119 1103
1120/* If we're in single_kboard state for kboard KBOARD, 1104/* If we're in single_kboard state for kboard KBOARD,
1121 get out of it. */ 1105 get out of it. */
@@ -1143,8 +1127,8 @@ struct kboard_stack
1143static struct kboard_stack *kboard_stack; 1127static struct kboard_stack *kboard_stack;
1144 1128
1145void 1129void
1146push_frame_kboard (f) 1130push_kboard (k)
1147 FRAME_PTR f; 1131 struct kboard *k;
1148{ 1132{
1149#ifdef MULTI_KBOARD 1133#ifdef MULTI_KBOARD
1150 struct kboard_stack *p 1134 struct kboard_stack *p
@@ -1154,20 +1138,107 @@ push_frame_kboard (f)
1154 p->kboard = current_kboard; 1138 p->kboard = current_kboard;
1155 kboard_stack = p; 1139 kboard_stack = p;
1156 1140
1157 current_kboard = FRAME_KBOARD (f); 1141 current_kboard = k;
1158#endif 1142#endif
1159} 1143}
1160 1144
1161void 1145void
1162pop_frame_kboard () 1146pop_kboard ()
1163{ 1147{
1164#ifdef MULTI_KBOARD 1148#ifdef MULTI_KBOARD
1149 struct terminal *t;
1165 struct kboard_stack *p = kboard_stack; 1150 struct kboard_stack *p = kboard_stack;
1166 current_kboard = p->kboard; 1151 int found = 0;
1152 for (t = terminal_list; t; t = t->next_terminal)
1153 {
1154 if (t->kboard == p->kboard)
1155 {
1156 current_kboard = p->kboard;
1157 found = 1;
1158 break;
1159 }
1160 }
1161 if (!found)
1162 {
1163 /* The terminal we remembered has been deleted. */
1164 current_kboard = FRAME_KBOARD (SELECTED_FRAME ());
1165 single_kboard = 0;
1166 }
1167 kboard_stack = p->next; 1167 kboard_stack = p->next;
1168 xfree (p); 1168 xfree (p);
1169#endif 1169#endif
1170} 1170}
1171
1172/* Switch to single_kboard mode, making current_kboard the only KBOARD
1173 from which further input is accepted. If F is non-nil, set its
1174 KBOARD as the current keyboard.
1175
1176 This function uses record_unwind_protect to return to the previous
1177 state later.
1178
1179 If Emacs is already in single_kboard mode, and F's keyboard is
1180 locked, then this function will throw an errow. */
1181
1182void
1183temporarily_switch_to_single_kboard (f)
1184 struct frame *f;
1185{
1186#ifdef MULTI_KBOARD
1187 int was_locked = single_kboard;
1188 if (was_locked)
1189 {
1190 if (f != NULL && FRAME_KBOARD (f) != current_kboard)
1191 /* We can not switch keyboards while in single_kboard mode.
1192 In rare cases, Lisp code may call `recursive-edit' (or
1193 `read-minibuffer' or `y-or-n-p') after it switched to a
1194 locked frame. For example, this is likely to happen
1195 when server.el connects to a new terminal while Emacs is in
1196 single_kboard mode. It is best to throw an error instead
1197 of presenting the user with a frozen screen. */
1198 error ("Terminal %d is locked, cannot read from it",
1199 FRAME_TERMINAL (f)->id);
1200 else
1201 /* This call is unnecessary, but helps
1202 `restore_kboard_configuration' discover if somebody changed
1203 `current_kboard' behind our back. */
1204 push_kboard (current_kboard);
1205 }
1206 else if (f != NULL)
1207 current_kboard = FRAME_KBOARD (f);
1208 single_kboard = 1;
1209 record_unwind_protect (restore_kboard_configuration,
1210 (was_locked ? Qt : Qnil));
1211#endif
1212}
1213
1214#if 0 /* This function is not needed anymore. */
1215void
1216record_single_kboard_state ()
1217{
1218 if (single_kboard)
1219 push_kboard (current_kboard);
1220 record_unwind_protect (restore_kboard_configuration,
1221 (single_kboard ? Qt : Qnil));
1222}
1223#endif
1224
1225static Lisp_Object
1226restore_kboard_configuration (was_locked)
1227 Lisp_Object was_locked;
1228{
1229 if (NILP (was_locked))
1230 single_kboard = 0;
1231 else
1232 {
1233 struct kboard *prev = current_kboard;
1234 single_kboard = 1;
1235 pop_kboard ();
1236 /* The pop should not change the kboard. */
1237 if (single_kboard && current_kboard != prev)
1238 abort ();
1239 }
1240 return Qnil;
1241}
1171 1242
1172/* Handle errors that are not handled at inner levels 1243/* Handle errors that are not handled at inner levels
1173 by printing an error message and returning to the editor command loop. */ 1244 by printing an error message and returning to the editor command loop. */
@@ -1215,10 +1286,12 @@ cmd_error (data)
1215 Vquit_flag = Qnil; 1286 Vquit_flag = Qnil;
1216 1287
1217 Vinhibit_quit = Qnil; 1288 Vinhibit_quit = Qnil;
1289#if 0 /* This shouldn't be necessary anymore. --lorentey */
1218#ifdef MULTI_KBOARD 1290#ifdef MULTI_KBOARD
1219 if (command_loop_level == 0 && minibuf_level == 0) 1291 if (command_loop_level == 0 && minibuf_level == 0)
1220 any_kboard_state (); 1292 any_kboard_state ();
1221#endif 1293#endif
1294#endif
1222 1295
1223 return make_number (0); 1296 return make_number (0);
1224} 1297}
@@ -1254,11 +1327,7 @@ cmd_error_internal (data, context)
1254 /* If the window system or terminal frame hasn't been initialized 1327 /* If the window system or terminal frame hasn't been initialized
1255 yet, or we're not interactive, write the message to stderr and exit. */ 1328 yet, or we're not interactive, write the message to stderr and exit. */
1256 else if (!sf->glyphs_initialized_p 1329 else if (!sf->glyphs_initialized_p
1257 /* This is the case of the frame dumped with Emacs, when we're 1330 || FRAME_INITIAL_P (sf)
1258 running under a window system. */
1259 || (!NILP (Vwindow_system)
1260 && !inhibit_window_system
1261 && FRAME_TERMCAP_P (sf))
1262 || noninteractive) 1331 || noninteractive)
1263 { 1332 {
1264 print_error_message (data, Qexternal_debugging_output, 1333 print_error_message (data, Qexternal_debugging_output,
@@ -1301,10 +1370,12 @@ command_loop ()
1301 while (1) 1370 while (1)
1302 { 1371 {
1303 internal_catch (Qtop_level, top_level_1, Qnil); 1372 internal_catch (Qtop_level, top_level_1, Qnil);
1304 /* Reset single_kboard in case top-level set it while 1373#if 0 /* This shouldn't be necessary anymore. --lorentey */
1305 evaluating an -f option, or we are stuck there for some 1374 /* Reset single_kboard in case top-level set it while
1306 other reason. */ 1375 evaluating an -f option, or we are stuck there for some
1307 any_kboard_state (); 1376 other reason. */
1377 any_kboard_state ();
1378#endif
1308 internal_catch (Qtop_level, command_loop_2, Qnil); 1379 internal_catch (Qtop_level, command_loop_2, Qnil);
1309 executing_kbd_macro = Qnil; 1380 executing_kbd_macro = Qnil;
1310 1381
@@ -1499,10 +1570,12 @@ command_loop_1 ()
1499 int no_direct; 1570 int no_direct;
1500 int prev_modiff = 0; 1571 int prev_modiff = 0;
1501 struct buffer *prev_buffer = NULL; 1572 struct buffer *prev_buffer = NULL;
1573#if 0 /* This shouldn't be necessary anymore. --lorentey */
1502#ifdef MULTI_KBOARD 1574#ifdef MULTI_KBOARD
1503 int was_locked = single_kboard; 1575 int was_locked = single_kboard;
1504#endif 1576#endif
1505 int already_adjusted; 1577#endif
1578 int already_adjusted = 0;
1506 1579
1507 current_kboard->Vprefix_arg = Qnil; 1580 current_kboard->Vprefix_arg = Qnil;
1508 current_kboard->Vlast_prefix_arg = Qnil; 1581 current_kboard->Vlast_prefix_arg = Qnil;
@@ -1961,10 +2034,11 @@ command_loop_1 ()
1961 if (!NILP (current_kboard->defining_kbd_macro) 2034 if (!NILP (current_kboard->defining_kbd_macro)
1962 && NILP (current_kboard->Vprefix_arg)) 2035 && NILP (current_kboard->Vprefix_arg))
1963 finalize_kbd_macro_chars (); 2036 finalize_kbd_macro_chars ();
1964 2037#if 0 /* This shouldn't be necessary anymore. --lorentey */
1965#ifdef MULTI_KBOARD 2038#ifdef MULTI_KBOARD
1966 if (!was_locked) 2039 if (!was_locked)
1967 any_kboard_state (); 2040 any_kboard_state ();
2041#endif
1968#endif 2042#endif
1969 } 2043 }
1970} 2044}
@@ -2203,7 +2277,10 @@ void
2203start_polling () 2277start_polling ()
2204{ 2278{
2205#ifdef POLL_FOR_INPUT 2279#ifdef POLL_FOR_INPUT
2206 if (read_socket_hook && !interrupt_input) 2280 /* XXX This condition was (read_socket_hook && !interrupt_input),
2281 but read_socket_hook is not global anymore. Let's pretend that
2282 it's always set. */
2283 if (!interrupt_input)
2207 { 2284 {
2208 /* Turn alarm handling on unconditionally. It might have 2285 /* Turn alarm handling on unconditionally. It might have
2209 been turned off in process.c. */ 2286 been turned off in process.c. */
@@ -2237,7 +2314,10 @@ int
2237input_polling_used () 2314input_polling_used ()
2238{ 2315{
2239#ifdef POLL_FOR_INPUT 2316#ifdef POLL_FOR_INPUT
2240 return read_socket_hook && !interrupt_input; 2317 /* XXX This condition was (read_socket_hook && !interrupt_input),
2318 but read_socket_hook is not global anymore. Let's pretend that
2319 it's always set. */
2320 return !interrupt_input;
2241#else 2321#else
2242 return 0; 2322 return 0;
2243#endif 2323#endif
@@ -2249,7 +2329,10 @@ void
2249stop_polling () 2329stop_polling ()
2250{ 2330{
2251#ifdef POLL_FOR_INPUT 2331#ifdef POLL_FOR_INPUT
2252 if (read_socket_hook && !interrupt_input) 2332 /* XXX This condition was (read_socket_hook && !interrupt_input),
2333 but read_socket_hook is not global anymore. Let's pretend that
2334 it's always set. */
2335 if (!interrupt_input)
2253 ++poll_suppress_count; 2336 ++poll_suppress_count;
2254#endif 2337#endif
2255} 2338}
@@ -2461,10 +2544,6 @@ read_char_help_form_unwind (arg)
2461 return Qnil; 2544 return Qnil;
2462} 2545}
2463 2546
2464#ifdef MULTI_KBOARD
2465static jmp_buf wrong_kboard_jmpbuf;
2466#endif
2467
2468#define STOP_POLLING \ 2547#define STOP_POLLING \
2469do { if (! polling_stopped_here) stop_polling (); \ 2548do { if (! polling_stopped_here) stop_polling (); \
2470 polling_stopped_here = 1; } while (0) 2549 polling_stopped_here = 1; } while (0)
@@ -2491,6 +2570,9 @@ do { if (polling_stopped_here) start_polling (); \
2491 if we used a mouse menu to read the input, or zero otherwise. If 2570 if we used a mouse menu to read the input, or zero otherwise. If
2492 USED_MOUSE_MENU is null, we don't dereference it. 2571 USED_MOUSE_MENU is null, we don't dereference it.
2493 2572
2573 Value is -2 when we find input on another keyboard. A second call
2574 to read_char will read it.
2575
2494 If END_TIME is non-null, it is a pointer to an EMACS_TIME 2576 If END_TIME is non-null, it is a pointer to an EMACS_TIME
2495 specifying the maximum time to wait until. If no input arrives by 2577 specifying the maximum time to wait until. If no input arrives by
2496 that time, stop waiting and return nil. 2578 that time, stop waiting and return nil.
@@ -2517,6 +2599,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2517 volatile int reread; 2599 volatile int reread;
2518 struct gcpro gcpro1, gcpro2; 2600 struct gcpro gcpro1, gcpro2;
2519 int polling_stopped_here = 0; 2601 int polling_stopped_here = 0;
2602 struct kboard *orig_kboard = current_kboard;
2520 2603
2521 also_record = Qnil; 2604 also_record = Qnil;
2522 2605
@@ -2731,6 +2814,10 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2731 && !detect_input_pending_run_timers (0)) 2814 && !detect_input_pending_run_timers (0))
2732 { 2815 {
2733 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); 2816 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps);
2817
2818 if (INTEGERP (c) && XINT (c) == -2)
2819 return c; /* wrong_kboard_jmpbuf */
2820
2734 if (! NILP (c)) 2821 if (! NILP (c))
2735 { 2822 {
2736 key_already_recorded = 1; 2823 key_already_recorded = 1;
@@ -2747,6 +2834,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2747 jmpcount = SPECPDL_INDEX (); 2834 jmpcount = SPECPDL_INDEX ();
2748 if (_setjmp (local_getcjmp)) 2835 if (_setjmp (local_getcjmp))
2749 { 2836 {
2837 /* Handle quits while reading the keyboard. */
2750 /* We must have saved the outer value of getcjmp here, 2838 /* We must have saved the outer value of getcjmp here,
2751 so restore it now. */ 2839 so restore it now. */
2752 restore_getcjmp (save_jump); 2840 restore_getcjmp (save_jump);
@@ -2784,7 +2872,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2784 /* This is going to exit from read_char 2872 /* This is going to exit from read_char
2785 so we had better get rid of this frame's stuff. */ 2873 so we had better get rid of this frame's stuff. */
2786 UNGCPRO; 2874 UNGCPRO;
2787 longjmp (wrong_kboard_jmpbuf, 1); 2875 return make_number (-2); /* wrong_kboard_jmpbuf */
2788 } 2876 }
2789 } 2877 }
2790#endif 2878#endif
@@ -2921,6 +3009,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2921 } 3009 }
2922 } 3010 }
2923 3011
3012 /* Notify the caller if an autosave hook, or a timer, sentinel or
3013 filter in the sit_for calls above have changed the current
3014 kboard. This could happen if they use the minibuffer or start a
3015 recursive edit, like the fancy splash screen in server.el's
3016 filter. If this longjmp wasn't here, read_key_sequence would
3017 interpret the next key sequence using the wrong translation
3018 tables and function keymaps. */
3019 if (NILP (c) && current_kboard != orig_kboard)
3020 {
3021 UNGCPRO;
3022 return make_number (-2); /* wrong_kboard_jmpbuf */
3023 }
3024
2924 /* If this has become non-nil here, it has been set by a timer 3025 /* If this has become non-nil here, it has been set by a timer
2925 or sentinel or filter. */ 3026 or sentinel or filter. */
2926 if (CONSP (Vunread_command_events)) 3027 if (CONSP (Vunread_command_events))
@@ -2969,7 +3070,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2969 /* This is going to exit from read_char 3070 /* This is going to exit from read_char
2970 so we had better get rid of this frame's stuff. */ 3071 so we had better get rid of this frame's stuff. */
2971 UNGCPRO; 3072 UNGCPRO;
2972 longjmp (wrong_kboard_jmpbuf, 1); 3073 return make_number (-2); /* wrong_kboard_jmpbuf */
2973 } 3074 }
2974 } 3075 }
2975#endif 3076#endif
@@ -3025,7 +3126,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3025 /* This is going to exit from read_char 3126 /* This is going to exit from read_char
3026 so we had better get rid of this frame's stuff. */ 3127 so we had better get rid of this frame's stuff. */
3027 UNGCPRO; 3128 UNGCPRO;
3028 longjmp (wrong_kboard_jmpbuf, 1); 3129 return make_number (-2);
3029 } 3130 }
3030#endif 3131#endif
3031 } 3132 }
@@ -3080,8 +3181,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3080 3181
3081 if (!NILP (tem)) 3182 if (!NILP (tem))
3082 { 3183 {
3184#if 0 /* This shouldn't be necessary anymore. --lorentey */
3083 int was_locked = single_kboard; 3185 int was_locked = single_kboard;
3084 3186 int count = SPECPDL_INDEX ();
3187 record_single_kboard_state ();
3188#endif
3189
3085 last_input_char = c; 3190 last_input_char = c;
3086 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); 3191 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt);
3087 3192
@@ -3092,9 +3197,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3092 example banishing the mouse under mouse-avoidance-mode. */ 3197 example banishing the mouse under mouse-avoidance-mode. */
3093 timer_resume_idle (); 3198 timer_resume_idle ();
3094 3199
3200#if 0 /* This shouldn't be necessary anymore. --lorentey */
3095 /* Resume allowing input from any kboard, if that was true before. */ 3201 /* Resume allowing input from any kboard, if that was true before. */
3096 if (!was_locked) 3202 if (!was_locked)
3097 any_kboard_state (); 3203 any_kboard_state ();
3204 unbind_to (count, Qnil);
3205#endif
3098 3206
3099 goto retry; 3207 goto retry;
3100 } 3208 }
@@ -3106,15 +3214,15 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3106 if (XINT (c) == -1) 3214 if (XINT (c) == -1)
3107 goto exit; 3215 goto exit;
3108 3216
3109 if ((STRINGP (Vkeyboard_translate_table) 3217 if ((STRINGP (current_kboard->Vkeyboard_translate_table)
3110 && SCHARS (Vkeyboard_translate_table) > (unsigned) XFASTINT (c)) 3218 && SCHARS (current_kboard->Vkeyboard_translate_table) > (unsigned) XFASTINT (c))
3111 || (VECTORP (Vkeyboard_translate_table) 3219 || (VECTORP (current_kboard->Vkeyboard_translate_table)
3112 && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) 3220 && XVECTOR (current_kboard->Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
3113 || (CHAR_TABLE_P (Vkeyboard_translate_table) 3221 || (CHAR_TABLE_P (current_kboard->Vkeyboard_translate_table)
3114 && CHAR_VALID_P (XINT (c), 0))) 3222 && CHAR_VALID_P (XINT (c), 0)))
3115 { 3223 {
3116 Lisp_Object d; 3224 Lisp_Object d;
3117 d = Faref (Vkeyboard_translate_table, c); 3225 d = Faref (current_kboard->Vkeyboard_translate_table, c);
3118 /* nil in keyboard-translate-table means no translation. */ 3226 /* nil in keyboard-translate-table means no translation. */
3119 if (!NILP (d)) 3227 if (!NILP (d))
3120 c = d; 3228 c = d;
@@ -3734,12 +3842,10 @@ kbd_buffer_store_event_hold (event, hold_quit)
3734 if (c == quit_char) 3842 if (c == quit_char)
3735 { 3843 {
3736#ifdef MULTI_KBOARD 3844#ifdef MULTI_KBOARD
3737 KBOARD *kb; 3845 KBOARD *kb = FRAME_KBOARD (XFRAME (event->frame_or_window));
3738 struct input_event *sp; 3846 struct input_event *sp;
3739 3847
3740 if (single_kboard 3848 if (single_kboard && kb != current_kboard)
3741 && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)),
3742 kb != current_kboard))
3743 { 3849 {
3744 kb->kbd_queue 3850 kb->kbd_queue
3745 = Fcons (make_lispy_switch_frame (event->frame_or_window), 3851 = Fcons (make_lispy_switch_frame (event->frame_or_window),
@@ -3782,7 +3888,7 @@ kbd_buffer_store_event_hold (event, hold_quit)
3782 } 3888 }
3783 3889
3784 last_event_timestamp = event->timestamp; 3890 last_event_timestamp = event->timestamp;
3785 interrupt_signal (0 /* dummy */); 3891 handle_interrupt ();
3786 return; 3892 return;
3787 } 3893 }
3788 3894
@@ -4261,11 +4367,15 @@ kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
4261 unsigned long time; 4367 unsigned long time;
4262 4368
4263 *kbp = current_kboard; 4369 *kbp = current_kboard;
4264 /* Note that this uses F to determine which display to look at. 4370 /* Note that this uses F to determine which terminal to look at.
4265 If there is no valid info, it does not store anything 4371 If there is no valid info, it does not store anything
4266 so x remains nil. */ 4372 so x remains nil. */
4267 x = Qnil; 4373 x = Qnil;
4268 (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); 4374
4375 /* XXX Can f or mouse_position_hook be NULL here? */
4376 if (f && FRAME_TERMINAL (f)->mouse_position_hook)
4377 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, 0, &bar_window,
4378 &part, &x, &y, &time);
4269 4379
4270 obj = Qnil; 4380 obj = Qnil;
4271 4381
@@ -4562,10 +4672,14 @@ timer_check (do_it_now)
4562 { 4672 {
4563 if (NILP (vector[0])) 4673 if (NILP (vector[0]))
4564 { 4674 {
4565 int was_locked = single_kboard;
4566 int count = SPECPDL_INDEX (); 4675 int count = SPECPDL_INDEX ();
4567 Lisp_Object old_deactivate_mark = Vdeactivate_mark; 4676 Lisp_Object old_deactivate_mark = Vdeactivate_mark;
4568 4677
4678#if 0 /* This shouldn't be necessary anymore. --lorentey */
4679 /* On unbind_to, resume allowing input from any kboard, if that
4680 was true before. */
4681 record_single_kboard_state ();
4682#endif
4569 /* Mark the timer as triggered to prevent problems if the lisp 4683 /* Mark the timer as triggered to prevent problems if the lisp
4570 code fails to reschedule it right. */ 4684 code fails to reschedule it right. */
4571 vector[0] = Qt; 4685 vector[0] = Qt;
@@ -4577,10 +4691,6 @@ timer_check (do_it_now)
4577 timers_run++; 4691 timers_run++;
4578 unbind_to (count, Qnil); 4692 unbind_to (count, Qnil);
4579 4693
4580 /* Resume allowing input from any kboard, if that was true before. */
4581 if (!was_locked)
4582 any_kboard_state ();
4583
4584 /* Since we have handled the event, 4694 /* Since we have handled the event,
4585 we don't need to tell the caller to wake up and do it. */ 4695 we don't need to tell the caller to wake up and do it. */
4586 } 4696 }
@@ -6481,8 +6591,8 @@ modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist_or_stem,
6481 { 6591 {
6482 int len = SBYTES (name_alist_or_stem); 6592 int len = SBYTES (name_alist_or_stem);
6483 char *buf = (char *) alloca (len + 50); 6593 char *buf = (char *) alloca (len + 50);
6484 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem), 6594 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem),
6485 (long) XINT (symbol_int) + 1); 6595 (long) XINT (symbol_int) + 1);
6486 value = intern (buf); 6596 value = intern (buf);
6487 } 6597 }
6488 else if (name_table != 0 && name_table[symbol_num]) 6598 else if (name_table != 0 && name_table[symbol_num])
@@ -6747,7 +6857,10 @@ gobble_input (expected)
6747 } 6857 }
6748 else 6858 else
6749#ifdef POLL_FOR_INPUT 6859#ifdef POLL_FOR_INPUT
6750 if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) 6860 /* XXX This condition was (read_socket_hook && !interrupt_input),
6861 but read_socket_hook is not global anymore. Let's pretend that
6862 it's always set. */
6863 if (!interrupt_input && poll_suppress_count == 0)
6751 { 6864 {
6752 SIGMASKTYPE mask; 6865 SIGMASKTYPE mask;
6753 mask = sigblock (sigmask (SIGALRM)); 6866 mask = sigblock (sigmask (SIGALRM));
@@ -6824,150 +6937,221 @@ static int
6824read_avail_input (expected) 6937read_avail_input (expected)
6825 int expected; 6938 int expected;
6826{ 6939{
6827 register int i;
6828 int nread = 0; 6940 int nread = 0;
6941 int err = 0;
6942 struct terminal *t;
6829 6943
6830 /* Store pending user signal events, if any. */ 6944 /* Store pending user signal events, if any. */
6831 if (store_user_signal_events ()) 6945 if (store_user_signal_events ())
6832 expected = 0; 6946 expected = 0;
6833 6947
6834 if (read_socket_hook) 6948 /* Loop through the available terminals, and call their input hooks. */
6949 t = terminal_list;
6950 while (t)
6835 { 6951 {
6836 int nr; 6952 struct terminal *next = t->next_terminal;
6837 struct input_event hold_quit;
6838 6953
6839 EVENT_INIT (hold_quit); 6954 if (t->read_socket_hook)
6840 hold_quit.kind = NO_EVENT; 6955 {
6956 int nr;
6957 struct input_event hold_quit;
6958
6959 EVENT_INIT (hold_quit);
6960 hold_quit.kind = NO_EVENT;
6961
6962 /* No need for FIONREAD or fcntl; just say don't wait. */
6963 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0)
6964 {
6965 nread += nr;
6966 expected = 0;
6967 }
6968
6969 if (nr == -1) /* Not OK to read input now. */
6970 {
6971 err = 1;
6972 }
6973 else if (nr == -2) /* Non-transient error. */
6974 {
6975 /* The terminal device terminated; it should be closed. */
6976
6977 /* Kill Emacs if this was our last terminal. */
6978 if (!terminal_list->next_terminal)
6979 /* Formerly simply reported no input, but that
6980 sometimes led to a failure of Emacs to terminate.
6981 SIGHUP seems appropriate if we can't reach the
6982 terminal. */
6983 /* ??? Is it really right to send the signal just to
6984 this process rather than to the whole process
6985 group? Perhaps on systems with FIONREAD Emacs is
6986 alone in its group. */
6987 kill (getpid (), SIGHUP);
6988
6989 /* XXX Is calling delete_terminal safe here? It calls Fdelete_frame. */
6990 if (t->delete_terminal_hook)
6991 (*t->delete_terminal_hook) (t);
6992 else
6993 delete_terminal (t);
6994 }
6995
6996 if (hold_quit.kind != NO_EVENT)
6997 kbd_buffer_store_event (&hold_quit);
6998 }
6841 6999
6842 /* No need for FIONREAD or fcntl; just say don't wait. */ 7000 t = next;
6843 while (nr = (*read_socket_hook) (input_fd, expected, &hold_quit), nr > 0)
6844 {
6845 nread += nr;
6846 expected = 0;
6847 }
6848 if (hold_quit.kind != NO_EVENT)
6849 kbd_buffer_store_event (&hold_quit);
6850 } 7001 }
6851 else
6852 {
6853 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6854 the kbd_buffer can really hold. That may prevent loss
6855 of characters on some systems when input is stuffed at us. */
6856 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6857 int n_to_read;
6858 7002
6859 /* Determine how many characters we should *try* to read. */ 7003 if (err && !nread)
7004 nread = -1;
7005
7006 return nread;
7007}
7008
7009/* This is the tty way of reading available input.
7010
7011 Note that each terminal device has its own `struct terminal' object,
7012 and so this function is called once for each individual termcap
7013 terminal. The first parameter indicates which terminal to read from. */
7014
7015int
7016tty_read_avail_input (struct terminal *terminal,
7017 int expected,
7018 struct input_event *hold_quit)
7019{
7020 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
7021 the kbd_buffer can really hold. That may prevent loss
7022 of characters on some systems when input is stuffed at us. */
7023 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
7024 int n_to_read, i;
7025 struct tty_display_info *tty = terminal->display_info.tty;
7026 int nread = 0;
7027
7028 if (terminal->deleted) /* Don't read from a deleted terminal. */
7029 return;
7030
7031 if (terminal->type != output_termcap)
7032 abort ();
7033
7034 /* XXX I think the following code should be moved to separate hook
7035 functions in system-dependent files. */
6860#ifdef WINDOWSNT 7036#ifdef WINDOWSNT
6861 return 0; 7037 return 0;
6862#else /* not WINDOWSNT */ 7038#else /* not WINDOWSNT */
6863#ifdef MSDOS 7039#ifdef MSDOS
6864 n_to_read = dos_keysns (); 7040 n_to_read = dos_keysns ();
6865 if (n_to_read == 0) 7041 if (n_to_read == 0)
6866 return 0; 7042 return 0;
7043
7044 cbuf[0] = dos_keyread ();
7045 nread = 1;
7046
6867#else /* not MSDOS */ 7047#else /* not MSDOS */
7048
7049 if (! tty->term_initted) /* In case we get called during bootstrap. */
7050 return 0;
7051
7052 if (! tty->input)
7053 return 0; /* The terminal is suspended. */
7054
7055 /* Determine how many characters we should *try* to read. */
6868#ifdef FIONREAD 7056#ifdef FIONREAD
6869 /* Find out how much input is available. */ 7057 /* Find out how much input is available. */
6870 if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) 7058 if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0)
6871 /* Formerly simply reported no input, but that sometimes led to 7059 {
6872 a failure of Emacs to terminate. 7060 if (! noninteractive)
6873 SIGHUP seems appropriate if we can't reach the terminal. */ 7061 return -2; /* Close this terminal. */
6874 /* ??? Is it really right to send the signal just to this process 7062 else
6875 rather than to the whole process group? 7063 n_to_read = 0;
6876 Perhaps on systems with FIONREAD Emacs is alone in its group. */ 7064 }
6877 { 7065 if (n_to_read == 0)
6878 if (! noninteractive) 7066 return 0;
6879 kill (getpid (), SIGHUP); 7067 if (n_to_read > sizeof cbuf)
6880 else 7068 n_to_read = sizeof cbuf;
6881 n_to_read = 0;
6882 }
6883 if (n_to_read == 0)
6884 return 0;
6885 if (n_to_read > sizeof cbuf)
6886 n_to_read = sizeof cbuf;
6887#else /* no FIONREAD */ 7069#else /* no FIONREAD */
6888#if defined (USG) || defined (DGUX) || defined(CYGWIN) 7070#if defined (USG) || defined (DGUX) || defined(CYGWIN)
6889 /* Read some input if available, but don't wait. */ 7071 /* Read some input if available, but don't wait. */
6890 n_to_read = sizeof cbuf; 7072 n_to_read = sizeof cbuf;
6891 fcntl (input_fd, F_SETFL, O_NDELAY); 7073 fcntl (fileno (tty->input), F_SETFL, O_NDELAY);
6892#else 7074#else
6893 you lose; 7075 you lose;
6894#endif 7076#endif
6895#endif 7077#endif
6896#endif /* not MSDOS */
6897#endif /* not WINDOWSNT */
6898 7078
6899 /* Now read; for one reason or another, this will not block. 7079 /* Now read; for one reason or another, this will not block.
6900 NREAD is set to the number of chars read. */ 7080 NREAD is set to the number of chars read. */
6901 do 7081 do
6902 { 7082 {
6903#ifdef MSDOS 7083 nread = emacs_read (fileno (tty->input), cbuf, n_to_read);
6904 cbuf[0] = dos_keyread (); 7084 /* POSIX infers that processes which are not in the session leader's
6905 nread = 1; 7085 process group won't get SIGHUP's at logout time. BSDI adheres to
6906#else 7086 this part standard and returns -1 from read (0) with errno==EIO
6907 nread = emacs_read (input_fd, cbuf, n_to_read); 7087 when the control tty is taken away.
6908#endif 7088 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6909 /* POSIX infers that processes which are not in the session leader's 7089 if (nread == -1 && errno == EIO)
6910 process group won't get SIGHUP's at logout time. BSDI adheres to 7090 return -2; /* Close this terminal. */
6911 this part standard and returns -1 from read (0) with errno==EIO
6912 when the control tty is taken away.
6913 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6914 if (nread == -1 && errno == EIO)
6915 kill (0, SIGHUP);
6916#if defined (AIX) && (! defined (aix386) && defined (_BSD)) 7091#if defined (AIX) && (! defined (aix386) && defined (_BSD))
6917 /* The kernel sometimes fails to deliver SIGHUP for ptys. 7092 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6918 This looks incorrect, but it isn't, because _BSD causes 7093 This looks incorrect, but it isn't, because _BSD causes
6919 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 7094 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6920 and that causes a value other than 0 when there is no input. */ 7095 and that causes a value other than 0 when there is no input. */
6921 if (nread == 0) 7096 if (nread == 0)
6922 kill (0, SIGHUP); 7097 return -2; /* Close this terminal. */
6923#endif 7098#endif
6924 } 7099 }
6925 while ( 7100 while (
6926 /* We used to retry the read if it was interrupted. 7101 /* We used to retry the read if it was interrupted.
6927 But this does the wrong thing when O_NDELAY causes 7102 But this does the wrong thing when O_NDELAY causes
6928 an EAGAIN error. Does anybody know of a situation 7103 an EAGAIN error. Does anybody know of a situation
6929 where a retry is actually needed? */ 7104 where a retry is actually needed? */
6930#if 0 7105#if 0
6931 nread < 0 && (errno == EAGAIN 7106 nread < 0 && (errno == EAGAIN
6932#ifdef EFAULT 7107#ifdef EFAULT
6933 || errno == EFAULT 7108 || errno == EFAULT
6934#endif 7109#endif
6935#ifdef EBADSLT 7110#ifdef EBADSLT
6936 || errno == EBADSLT 7111 || errno == EBADSLT
6937#endif 7112#endif
6938 ) 7113 )
6939#else 7114#else
6940 0 7115 0
6941#endif 7116#endif
6942 ); 7117 );
6943 7118
6944#ifndef FIONREAD 7119#ifndef FIONREAD
6945#if defined (USG) || defined (DGUX) || defined (CYGWIN) 7120#if defined (USG) || defined (DGUX) || defined (CYGWIN)
6946 fcntl (input_fd, F_SETFL, 0); 7121 fcntl (fileno (tty->input), F_SETFL, 0);
6947#endif /* USG or DGUX or CYGWIN */ 7122#endif /* USG or DGUX or CYGWIN */
6948#endif /* no FIONREAD */ 7123#endif /* no FIONREAD */
6949 for (i = 0; i < nread; i++) 7124
6950 { 7125 if (nread <= 0)
6951 struct input_event buf; 7126 return nread;
6952 EVENT_INIT (buf); 7127
6953 buf.kind = ASCII_KEYSTROKE_EVENT; 7128#endif /* not MSDOS */
6954 buf.modifiers = 0; 7129#endif /* not WINDOWSNT */
6955 if (meta_key == 1 && (cbuf[i] & 0x80)) 7130
6956 buf.modifiers = meta_modifier; 7131 for (i = 0; i < nread; i++)
6957 if (meta_key != 2) 7132 {
6958 cbuf[i] &= ~0x80; 7133 struct input_event buf;
6959 7134 EVENT_INIT (buf);
6960 buf.code = cbuf[i]; 7135 buf.kind = ASCII_KEYSTROKE_EVENT;
6961 buf.frame_or_window = selected_frame; 7136 buf.modifiers = 0;
6962 buf.arg = Qnil; 7137 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6963 7138 buf.modifiers = meta_modifier;
6964 kbd_buffer_store_event (&buf); 7139 if (tty->meta_key != 2)
6965 /* Don't look at input that follows a C-g too closely. 7140 cbuf[i] &= ~0x80;
6966 This reduces lossage due to autorepeat on C-g. */ 7141
6967 if (buf.kind == ASCII_KEYSTROKE_EVENT 7142 buf.code = cbuf[i];
6968 && buf.code == quit_char) 7143 /* Set the frame corresponding to the active tty. Note that the
6969 break; 7144 value of selected_frame is not reliable here, redisplay tends
6970 } 7145 to temporarily change it. */
7146 buf.frame_or_window = tty->top_frame;
7147 buf.arg = Qnil;
7148
7149 kbd_buffer_store_event (&buf);
7150 /* Don't look at input that follows a C-g too closely.
7151 This reduces lossage due to autorepeat on C-g. */
7152 if (buf.kind == ASCII_KEYSTROKE_EVENT
7153 && buf.code == quit_char)
7154 break;
6971 } 7155 }
6972 7156
6973 return nread; 7157 return nread;
@@ -8545,6 +8729,8 @@ read_char_minibuf_menu_prompt (commandflag, nmaps, maps)
8545 8729
8546 if (!INTEGERP (obj)) 8730 if (!INTEGERP (obj))
8547 return obj; 8731 return obj;
8732 else if (XINT (obj) == -2)
8733 return obj;
8548 else 8734 else
8549 ch = XINT (obj); 8735 ch = XINT (obj);
8550 8736
@@ -8891,11 +9077,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8891 last_nonmenu_event = Qnil; 9077 last_nonmenu_event = Qnil;
8892 9078
8893 delayed_switch_frame = Qnil; 9079 delayed_switch_frame = Qnil;
8894 fkey.map = fkey.parent = Vfunction_key_map; 9080
8895 keytran.map = keytran.parent = Vkey_translation_map;
8896 fkey.start = fkey.end = 0;
8897 keytran.start = keytran.end = 0;
8898
8899 if (INTERACTIVE) 9081 if (INTERACTIVE)
8900 { 9082 {
8901 if (!NILP (prompt)) 9083 if (!NILP (prompt))
@@ -8935,6 +9117,13 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8935 keybuf[0..mock_input] holds the sequence we should reread. */ 9117 keybuf[0..mock_input] holds the sequence we should reread. */
8936 replay_sequence: 9118 replay_sequence:
8937 9119
9120 /* We may switch keyboards between rescans, so we need to
9121 reinitialize fkey and keytran before each replay. */
9122 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
9123 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map;
9124 fkey.start = fkey.end = 0;
9125 keytran.start = keytran.end = 0;
9126
8938 starting_buffer = current_buffer; 9127 starting_buffer = current_buffer;
8939 first_unbound = bufsize + 1; 9128 first_unbound = bufsize + 1;
8940 9129
@@ -9099,8 +9288,28 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9099#ifdef MULTI_KBOARD 9288#ifdef MULTI_KBOARD
9100 KBOARD *interrupted_kboard = current_kboard; 9289 KBOARD *interrupted_kboard = current_kboard;
9101 struct frame *interrupted_frame = SELECTED_FRAME (); 9290 struct frame *interrupted_frame = SELECTED_FRAME ();
9102 if (setjmp (wrong_kboard_jmpbuf)) 9291#endif
9292 key = read_char (NILP (prompt), nmaps,
9293 (Lisp_Object *) submaps, last_nonmenu_event,
9294 &used_mouse_menu, NULL);
9295#ifdef MULTI_KBOARD
9296 if (INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9103 { 9297 {
9298 int found = 0;
9299 struct kboard *k;
9300
9301 for (k = all_kboards; k; k = k->next_kboard)
9302 if (k == interrupted_kboard)
9303 found = 1;
9304
9305 if (!found)
9306 {
9307 /* Don't touch interrupted_kboard when it's been
9308 deleted. */
9309 delayed_switch_frame = Qnil;
9310 goto replay_sequence;
9311 }
9312
9104 if (!NILP (delayed_switch_frame)) 9313 if (!NILP (delayed_switch_frame))
9105 { 9314 {
9106 interrupted_kboard->kbd_queue 9315 interrupted_kboard->kbd_queue
@@ -9108,6 +9317,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9108 interrupted_kboard->kbd_queue); 9317 interrupted_kboard->kbd_queue);
9109 delayed_switch_frame = Qnil; 9318 delayed_switch_frame = Qnil;
9110 } 9319 }
9320
9111 while (t > 0) 9321 while (t > 0)
9112 interrupted_kboard->kbd_queue 9322 interrupted_kboard->kbd_queue
9113 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); 9323 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue);
@@ -9132,9 +9342,6 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9132 goto replay_sequence; 9342 goto replay_sequence;
9133 } 9343 }
9134#endif 9344#endif
9135 key = read_char (NILP (prompt), nmaps,
9136 (Lisp_Object *) submaps, last_nonmenu_event,
9137 &used_mouse_menu, NULL);
9138 } 9345 }
9139 9346
9140 /* read_char returns t when it shows a menu and the user rejects it. 9347 /* read_char returns t when it shows a menu and the user rejects it.
@@ -10246,8 +10453,12 @@ detect_input_pending_run_timers (do_display)
10246 from an idle timer function. The symptom of the bug is that 10453 from an idle timer function. The symptom of the bug is that
10247 the cursor sometimes doesn't become visible until the next X 10454 the cursor sometimes doesn't become visible until the next X
10248 event is processed. --gerd. */ 10455 event is processed. --gerd. */
10249 if (rif) 10456 {
10250 rif->flush_display (NULL); 10457 Lisp_Object tail, frame;
10458 FOR_EACH_FRAME (tail, frame)
10459 if (FRAME_RIF (XFRAME (frame)))
10460 FRAME_RIF (XFRAME (frame))->flush_display (XFRAME (frame));
10461 }
10251 } 10462 }
10252 10463
10253 return input_pending; 10464 return input_pending;
@@ -10499,6 +10710,9 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10499 int width, height; 10710 int width, height;
10500 struct gcpro gcpro1; 10711 struct gcpro gcpro1;
10501 10712
10713 if (tty_list && tty_list->next)
10714 error ("There are other tty frames open; close them before suspending Emacs");
10715
10502 if (!NILP (stuffstring)) 10716 if (!NILP (stuffstring))
10503 CHECK_STRING (stuffstring); 10717 CHECK_STRING (stuffstring);
10504 10718
@@ -10507,11 +10721,11 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10507 call1 (Vrun_hooks, intern ("suspend-hook")); 10721 call1 (Vrun_hooks, intern ("suspend-hook"));
10508 10722
10509 GCPRO1 (stuffstring); 10723 GCPRO1 (stuffstring);
10510 get_frame_size (&old_width, &old_height); 10724 get_tty_size (fileno (CURTTY ()->input), &old_width, &old_height);
10511 reset_sys_modes (); 10725 reset_all_sys_modes ();
10512 /* sys_suspend can get an error if it tries to fork a subshell 10726 /* sys_suspend can get an error if it tries to fork a subshell
10513 and the system resources aren't available for that. */ 10727 and the system resources aren't available for that. */
10514 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, 10728 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_all_sys_modes,
10515 Qnil); 10729 Qnil);
10516 stuff_buffered_input (stuffstring); 10730 stuff_buffered_input (stuffstring);
10517 if (cannot_suspend) 10731 if (cannot_suspend)
@@ -10523,7 +10737,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10523 /* Check if terminal/window size has changed. 10737 /* Check if terminal/window size has changed.
10524 Note that this is not useful when we are running directly 10738 Note that this is not useful when we are running directly
10525 with a window system; but suspend should be disabled in that case. */ 10739 with a window system; but suspend should be disabled in that case. */
10526 get_frame_size (&width, &height); 10740 get_tty_size (fileno (CURTTY ()->input), &width, &height);
10527 if (width != old_width || height != old_height) 10741 if (width != old_width || height != old_height)
10528 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); 10742 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
10529 10743
@@ -10583,10 +10797,10 @@ set_waiting_for_input (time_to_clear)
10583{ 10797{
10584 input_available_clear_time = time_to_clear; 10798 input_available_clear_time = time_to_clear;
10585 10799
10586 /* Tell interrupt_signal to throw back to read_char, */ 10800 /* Tell handle_interrupt to throw back to read_char, */
10587 waiting_for_input = 1; 10801 waiting_for_input = 1;
10588 10802
10589 /* If interrupt_signal was called before and buffered a C-g, 10803 /* If handle_interrupt was called before and buffered a C-g,
10590 make it run again now, to avoid timing error. */ 10804 make it run again now, to avoid timing error. */
10591 if (!NILP (Vquit_flag)) 10805 if (!NILP (Vquit_flag))
10592 quit_throw_to_read_char (); 10806 quit_throw_to_read_char ();
@@ -10595,48 +10809,82 @@ set_waiting_for_input (time_to_clear)
10595void 10809void
10596clear_waiting_for_input () 10810clear_waiting_for_input ()
10597{ 10811{
10598 /* Tell interrupt_signal not to throw back to read_char, */ 10812 /* Tell handle_interrupt not to throw back to read_char, */
10599 waiting_for_input = 0; 10813 waiting_for_input = 0;
10600 input_available_clear_time = 0; 10814 input_available_clear_time = 0;
10601} 10815}
10602 10816
10603/* This routine is called at interrupt level in response to C-g. 10817/* The SIGINT handler.
10604
10605 If interrupt_input, this is the handler for SIGINT. Otherwise, it
10606 is called from kbd_buffer_store_event, in handling SIGIO or
10607 SIGTINT.
10608 10818
10609 If `waiting_for_input' is non zero, then unless `echoing' is 10819 If we have a frame on the controlling tty, we assume that the
10610 nonzero, immediately throw back to read_char. 10820 SIGINT was generated by C-g, so we call handle_interrupt.
10611 10821 Otherwise, the handler kills Emacs. */
10612 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10613 eval to throw, when it gets a chance. If quit-flag is already
10614 non-nil, it stops the job right away. */
10615 10822
10616static SIGTYPE 10823static SIGTYPE
10617interrupt_signal (signalnum) /* If we don't have an argument, */ 10824interrupt_signal (signalnum) /* If we don't have an argument, */
10618 int signalnum; /* some compilers complain in signal calls. */ 10825 int signalnum; /* some compilers complain in signal calls. */
10619{ 10826{
10620 char c;
10621 /* Must preserve main program's value of errno. */ 10827 /* Must preserve main program's value of errno. */
10622 int old_errno = errno; 10828 int old_errno = errno;
10623 struct frame *sf = SELECTED_FRAME (); 10829 struct terminal *terminal;
10624 10830
10625#if defined (USG) && !defined (POSIX_SIGNALS) 10831#if defined (USG) && !defined (POSIX_SIGNALS)
10626 if (!read_socket_hook && NILP (Vwindow_system)) 10832 /* USG systems forget handlers when they are used;
10627 { 10833 must reestablish each time */
10628 /* USG systems forget handlers when they are used; 10834 signal (SIGINT, interrupt_signal);
10629 must reestablish each time */ 10835 signal (SIGQUIT, interrupt_signal);
10630 signal (SIGINT, interrupt_signal);
10631 signal (SIGQUIT, interrupt_signal);
10632 }
10633#endif /* USG */ 10836#endif /* USG */
10634 10837
10635 SIGNAL_THREAD_CHECK (signalnum); 10838 SIGNAL_THREAD_CHECK (signalnum);
10839
10840 /* See if we have an active terminal on our controlling tty. */
10841 terminal = get_named_tty ("/dev/tty");
10842 if (!terminal)
10843 {
10844 /* If there are no frames there, let's pretend that we are a
10845 well-behaving UN*X program and quit. */
10846 Fkill_emacs (Qnil);
10847 }
10848 else
10849 {
10850 /* Otherwise, the SIGINT was probably generated by C-g. */
10851
10852 /* Set internal_last_event_frame to the top frame of the
10853 controlling tty, if we have a frame there. We disable the
10854 interrupt key on secondary ttys, so the SIGINT must have come
10855 from the controlling tty. */
10856 internal_last_event_frame = terminal->display_info.tty->top_frame;
10857
10858 handle_interrupt ();
10859 }
10860
10861 errno = old_errno;
10862}
10863
10864/* This routine is called at interrupt level in response to C-g.
10865
10866 It is called from the SIGINT handler or kbd_buffer_store_event.
10867
10868 If `waiting_for_input' is non zero, then unless `echoing' is
10869 nonzero, immediately throw back to read_char.
10870
10871 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10872 eval to throw, when it gets a chance. If quit-flag is already
10873 non-nil, it stops the job right away. */
10874
10875static void
10876handle_interrupt ()
10877{
10878 char c;
10879
10636 cancel_echoing (); 10880 cancel_echoing ();
10637 10881
10882 /* XXX This code needs to be revised for multi-tty support. */
10638 if (!NILP (Vquit_flag) 10883 if (!NILP (Vquit_flag)
10639 && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))) 10884#ifndef MSDOS
10885 && get_named_tty ("/dev/tty")
10886#endif
10887 )
10640 { 10888 {
10641 /* If SIGINT isn't blocked, don't let us be interrupted by 10889 /* If SIGINT isn't blocked, don't let us be interrupted by
10642 another SIGINT, it might be harmful due to non-reentrancy 10890 another SIGINT, it might be harmful due to non-reentrancy
@@ -10644,7 +10892,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10644 sigblock (sigmask (SIGINT)); 10892 sigblock (sigmask (SIGINT));
10645 10893
10646 fflush (stdout); 10894 fflush (stdout);
10647 reset_sys_modes (); 10895 reset_all_sys_modes ();
10648 10896
10649#ifdef SIGTSTP /* Support possible in later USG versions */ 10897#ifdef SIGTSTP /* Support possible in later USG versions */
10650/* 10898/*
@@ -10723,7 +10971,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10723 printf ("Continuing...\n"); 10971 printf ("Continuing...\n");
10724#endif /* not MSDOS */ 10972#endif /* not MSDOS */
10725 fflush (stdout); 10973 fflush (stdout);
10726 init_sys_modes (); 10974 init_all_sys_modes ();
10727 sigfree (); 10975 sigfree ();
10728 } 10976 }
10729 else 10977 else
@@ -10751,9 +10999,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10751 } 10999 }
10752 11000
10753 if (waiting_for_input && !echoing) 11001 if (waiting_for_input && !echoing)
10754 quit_throw_to_read_char (); 11002 quit_throw_to_read_char ();
10755
10756 errno = old_errno;
10757} 11003}
10758 11004
10759/* Handle a C-g by making read_char return C-g. */ 11005/* Handle a C-g by making read_char return C-g. */
@@ -10786,75 +11032,202 @@ quit_throw_to_read_char ()
10786 _longjmp (getcjmp, 1); 11032 _longjmp (getcjmp, 1);
10787} 11033}
10788 11034
10789DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, 11035DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode, Sset_input_interrupt_mode, 1, 1, 0,
10790 doc: /* Set mode of reading keyboard input. 11036 doc: /* Set interrupt mode of reading keyboard input.
10791First arg INTERRUPT non-nil means use input interrupts; 11037If INTERRUPT is non-nil, Emacs will use input interrupts;
10792 nil means use CBREAK mode. 11038otherwise Emacs uses CBREAK mode.
10793Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal 11039
10794 (no effect except in CBREAK mode).
10795Third arg META t means accept 8-bit input (for a Meta key).
10796 META nil means ignore the top bit, on the assumption it is parity.
10797 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10798Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10799See also `current-input-mode'. */) 11040See also `current-input-mode'. */)
10800 (interrupt, flow, meta, quit) 11041 (interrupt)
10801 Lisp_Object interrupt, flow, meta, quit; 11042 Lisp_Object interrupt;
10802{ 11043{
10803 if (!NILP (quit) 11044 int new_interrupt_input;
10804 && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400))
10805 error ("set-input-mode: QUIT must be an ASCII character");
10806
10807#ifdef POLL_FOR_INPUT
10808 stop_polling ();
10809#endif
10810
10811#ifndef DOS_NT
10812 /* this causes startup screen to be restored and messes with the mouse */
10813 reset_sys_modes ();
10814#endif
10815
10816#ifdef SIGIO 11045#ifdef SIGIO
10817/* Note SIGIO has been undef'd if FIONREAD is missing. */ 11046/* Note SIGIO has been undef'd if FIONREAD is missing. */
10818 if (read_socket_hook) 11047#ifdef HAVE_X_WINDOWS
11048 if (x_display_list != NULL)
10819 { 11049 {
10820 /* When using X, don't give the user a real choice, 11050 /* When using X, don't give the user a real choice,
10821 because we haven't implemented the mechanisms to support it. */ 11051 because we haven't implemented the mechanisms to support it. */
10822#ifdef NO_SOCK_SIGIO 11052#ifdef NO_SOCK_SIGIO
10823 interrupt_input = 0; 11053 new_interrupt_input = 0;
10824#else /* not NO_SOCK_SIGIO */ 11054#else /* not NO_SOCK_SIGIO */
10825 interrupt_input = 1; 11055 new_interrupt_input = 1;
10826#endif /* NO_SOCK_SIGIO */ 11056#endif /* NO_SOCK_SIGIO */
10827 } 11057 }
10828 else 11058 else
10829 interrupt_input = !NILP (interrupt); 11059#endif
11060 new_interrupt_input = !NILP (interrupt);
10830#else /* not SIGIO */ 11061#else /* not SIGIO */
10831 interrupt_input = 0; 11062 new_interrupt_input = 0;
10832#endif /* not SIGIO */ 11063#endif /* not SIGIO */
10833 11064
10834/* Our VMS input only works by interrupts, as of now. */ 11065/* Our VMS input only works by interrupts, as of now. */
10835#ifdef VMS 11066#ifdef VMS
10836 interrupt_input = 1; 11067 new_interrupt_input = 1;
11068#endif
11069
11070 if (new_interrupt_input != interrupt_input)
11071 {
11072#ifdef POLL_FOR_INPUT
11073 stop_polling ();
11074#endif
11075#ifndef DOS_NT
11076 /* this causes startup screen to be restored and messes with the mouse */
11077 reset_all_sys_modes ();
11078#endif
11079 interrupt_input = new_interrupt_input;
11080#ifndef DOS_NT
11081 init_all_sys_modes ();
11082#endif
11083
11084#ifdef POLL_FOR_INPUT
11085 poll_suppress_count = 1;
11086 start_polling ();
11087#endif
11088 }
11089 return Qnil;
11090}
11091
11092DEFUN ("set-output-flow-control", Fset_output_flow_control, Sset_output_flow_control, 1, 2, 0,
11093 doc: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
11094If FLOW is non-nil, flow control is enabled and you cannot use C-s or
11095C-q in key sequences.
11096
11097This setting only has an effect on tty terminals and only when
11098Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
11099
11100See also `current-input-mode'. */)
11101 (flow, terminal)
11102 Lisp_Object flow, terminal;
11103{
11104 struct terminal *t = get_terminal (terminal, 1);
11105 struct tty_display_info *tty;
11106 if (t == NULL || t->type != output_termcap)
11107 return Qnil;
11108 tty = t->display_info.tty;
11109
11110 if (tty->flow_control != !NILP (flow))
11111 {
11112#ifndef DOS_NT
11113 /* this causes startup screen to be restored and messes with the mouse */
11114 reset_sys_modes (tty);
10837#endif 11115#endif
10838 11116
10839 flow_control = !NILP (flow); 11117 tty->flow_control = !NILP (flow);
11118
11119#ifndef DOS_NT
11120 init_sys_modes (tty);
11121#endif
11122 }
11123 return Qnil;
11124}
11125
11126DEFUN ("set-input-meta-mode", Fset_input_meta_mode, Sset_input_meta_mode, 1, 2, 0,
11127 doc: /* Enable or disable 8-bit input on TERMINAL.
11128If META is t, Emacs will accept 8-bit input, and interpret the 8th
11129bit as the Meta modifier.
11130
11131If META is nil, Emacs will ignore the top bit, on the assumption it is
11132parity.
11133
11134Otherwise, Emacs will accept and pass through 8-bit input without
11135specially interpreting the top bit.
11136
11137This setting only has an effect on tty terminal devices.
11138
11139Optional parameter TERMINAL specifies the tty terminal device to use.
11140It may be a terminal id, a frame, or nil for the terminal used by the
11141currently selected frame.
11142
11143See also `current-input-mode'. */)
11144 (meta, terminal)
11145 Lisp_Object meta, terminal;
11146{
11147 struct terminal *t = get_terminal (terminal, 1);
11148 struct tty_display_info *tty;
11149 int new_meta;
11150
11151 if (t == NULL || t->type != output_termcap)
11152 return Qnil;
11153 tty = t->display_info.tty;
11154
10840 if (NILP (meta)) 11155 if (NILP (meta))
10841 meta_key = 0; 11156 new_meta = 0;
10842 else if (EQ (meta, Qt)) 11157 else if (EQ (meta, Qt))
10843 meta_key = 1; 11158 new_meta = 1;
10844 else 11159 else
10845 meta_key = 2; 11160 new_meta = 2;
10846 if (!NILP (quit))
10847 /* Don't let this value be out of range. */
10848 quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
10849 11161
11162 if (tty->meta_key != new_meta)
11163 {
10850#ifndef DOS_NT 11164#ifndef DOS_NT
10851 init_sys_modes (); 11165 /* this causes startup screen to be restored and messes with the mouse */
11166 reset_sys_modes (tty);
10852#endif 11167#endif
10853 11168
10854#ifdef POLL_FOR_INPUT 11169 tty->meta_key = new_meta;
10855 poll_suppress_count = 1; 11170
10856 start_polling (); 11171#ifndef DOS_NT
11172 init_sys_modes (tty);
11173#endif
11174 }
11175 return Qnil;
11176}
11177
11178DEFUN ("set-quit-char", Fset_quit_char, Sset_quit_char, 1, 1, 0,
11179 doc: /* Specify character used for quitting.
11180QUIT must be an ASCII character.
11181
11182This function only has an effect on the controlling tty of the Emacs
11183process.
11184
11185See also `current-input-mode'. */)
11186 (quit)
11187 Lisp_Object quit;
11188{
11189 struct terminal *t = get_named_tty ("/dev/tty");
11190 struct tty_display_info *tty;
11191 if (t == NULL || t->type != output_termcap)
11192 return Qnil;
11193 tty = t->display_info.tty;
11194
11195 if (NILP (quit) || !INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)
11196 error ("QUIT must be an ASCII character");
11197
11198#ifndef DOS_NT
11199 /* this causes startup screen to be restored and messes with the mouse */
11200 reset_sys_modes (tty);
10857#endif 11201#endif
11202
11203 /* Don't let this value be out of range. */
11204 quit_char = XINT (quit) & (tty->meta_key == 0 ? 0177 : 0377);
11205
11206#ifndef DOS_NT
11207 init_sys_modes (tty);
11208#endif
11209
11210 return Qnil;
11211}
11212
11213DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0,
11214 doc: /* Set mode of reading keyboard input.
11215First arg INTERRUPT non-nil means use input interrupts;
11216 nil means use CBREAK mode.
11217Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
11218 (no effect except in CBREAK mode).
11219Third arg META t means accept 8-bit input (for a Meta key).
11220 META nil means ignore the top bit, on the assumption it is parity.
11221 Otherwise, accept 8-bit input and don't use the top bit for Meta.
11222Optional fourth arg QUIT if non-nil specifies character to use for quitting.
11223See also `current-input-mode'. */)
11224 (interrupt, flow, meta, quit)
11225 Lisp_Object interrupt, flow, meta, quit;
11226{
11227 Fset_input_interrupt_mode (interrupt);
11228 Fset_output_flow_control (flow, Qnil);
11229 Fset_input_meta_mode (meta, Qnil);
11230 Fset_quit_char (quit);
10858 return Qnil; 11231 return Qnil;
10859} 11232}
10860 11233
@@ -10875,10 +11248,21 @@ The elements of this list correspond to the arguments of
10875 () 11248 ()
10876{ 11249{
10877 Lisp_Object val[4]; 11250 Lisp_Object val[4];
11251 struct frame *sf = XFRAME (selected_frame);
10878 11252
10879 val[0] = interrupt_input ? Qt : Qnil; 11253 val[0] = interrupt_input ? Qt : Qnil;
10880 val[1] = flow_control ? Qt : Qnil; 11254 if (FRAME_TERMCAP_P (sf))
10881 val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; 11255 {
11256 val[1] = FRAME_TTY (sf)->flow_control ? Qt : Qnil;
11257 val[2] = (FRAME_TTY (sf)->meta_key == 2
11258 ? make_number (0)
11259 : (CURTTY ()->meta_key == 1 ? Qt : Qnil));
11260 }
11261 else
11262 {
11263 val[1] = Qnil;
11264 val[2] = Qt;
11265 }
10882 XSETFASTINT (val[3], quit_char); 11266 XSETFASTINT (val[3], quit_char);
10883 11267
10884 return Flist (sizeof (val) / sizeof (val[0]), val); 11268 return Flist (sizeof (val) / sizeof (val[0]), val);
@@ -10970,6 +11354,7 @@ init_kboard (kb)
10970 kb->Voverriding_terminal_local_map = Qnil; 11354 kb->Voverriding_terminal_local_map = Qnil;
10971 kb->Vlast_command = Qnil; 11355 kb->Vlast_command = Qnil;
10972 kb->Vreal_last_command = Qnil; 11356 kb->Vreal_last_command = Qnil;
11357 kb->Vkeyboard_translate_table = Qnil;
10973 kb->Vprefix_arg = Qnil; 11358 kb->Vprefix_arg = Qnil;
10974 kb->Vlast_prefix_arg = Qnil; 11359 kb->Vlast_prefix_arg = Qnil;
10975 kb->kbd_queue = Qnil; 11360 kb->kbd_queue = Qnil;
@@ -10984,6 +11369,10 @@ init_kboard (kb)
10984 kb->reference_count = 0; 11369 kb->reference_count = 0;
10985 kb->Vsystem_key_alist = Qnil; 11370 kb->Vsystem_key_alist = Qnil;
10986 kb->system_key_syms = Qnil; 11371 kb->system_key_syms = Qnil;
11372 kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
11373 Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
11374 kb->Vlocal_key_translation_map = Fmake_sparse_keymap (Qnil);
11375 Fset_keymap_parent (kb->Vlocal_key_translation_map, Vkey_translation_map);
10987 kb->Vdefault_minibuffer_frame = Qnil; 11376 kb->Vdefault_minibuffer_frame = Qnil;
10988} 11377}
10989 11378
@@ -11020,7 +11409,8 @@ delete_kboard (kb)
11020 && FRAMEP (selected_frame) 11409 && FRAMEP (selected_frame)
11021 && FRAME_LIVE_P (XFRAME (selected_frame))) 11410 && FRAME_LIVE_P (XFRAME (selected_frame)))
11022 { 11411 {
11023 current_kboard = XFRAME (selected_frame)->kboard; 11412 current_kboard = FRAME_KBOARD (XFRAME (selected_frame));
11413 single_kboard = 0;
11024 if (current_kboard == kb) 11414 if (current_kboard == kb)
11025 abort (); 11415 abort ();
11026 } 11416 }
@@ -11063,8 +11453,14 @@ init_keyboard ()
11063 wipe_kboard (current_kboard); 11453 wipe_kboard (current_kboard);
11064 init_kboard (current_kboard); 11454 init_kboard (current_kboard);
11065 11455
11066 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) 11456 if (!noninteractive)
11067 { 11457 {
11458 /* Before multi-tty support, these handlers used to be installed
11459 only if the current session was a tty session. Now an Emacs
11460 session may have multiple display types, so we always handle
11461 SIGINT. There is special code in interrupt_signal to exit
11462 Emacs on SIGINT when there are no termcap frames on the
11463 controlling terminal. */
11068 signal (SIGINT, interrupt_signal); 11464 signal (SIGINT, interrupt_signal);
11069#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 11465#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11070 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and 11466 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
@@ -11386,6 +11782,10 @@ syms_of_keyboard ()
11386 defsubr (&Stop_level); 11782 defsubr (&Stop_level);
11387 defsubr (&Sdiscard_input); 11783 defsubr (&Sdiscard_input);
11388 defsubr (&Sopen_dribble_file); 11784 defsubr (&Sopen_dribble_file);
11785 defsubr (&Sset_input_interrupt_mode);
11786 defsubr (&Sset_output_flow_control);
11787 defsubr (&Sset_input_meta_mode);
11788 defsubr (&Sset_quit_char);
11389 defsubr (&Sset_input_mode); 11789 defsubr (&Sset_input_mode);
11390 defsubr (&Scurrent_input_mode); 11790 defsubr (&Scurrent_input_mode);
11391 defsubr (&Sexecute_extended_command); 11791 defsubr (&Sexecute_extended_command);
@@ -11452,7 +11852,10 @@ In other words, the present command is the event that made the previous
11452command exit. 11852command exit.
11453 11853
11454The value `kill-region' is special; it means that the previous command 11854The value `kill-region' is special; it means that the previous command
11455was a kill command. */); 11855was a kill command.
11856
11857`last-command' has a separate binding for each terminal device.
11858See Info node `(elisp)Multiple displays'. */);
11456 11859
11457 DEFVAR_KBOARD ("real-last-command", Vreal_last_command, 11860 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
11458 doc: /* Same as `last-command', but never altered by Lisp code. */); 11861 doc: /* Same as `last-command', but never altered by Lisp code. */);
@@ -11564,8 +11967,8 @@ for that character after that prefix key. */);
11564Useful to set before you dump a modified Emacs. */); 11967Useful to set before you dump a modified Emacs. */);
11565 Vtop_level = Qnil; 11968 Vtop_level = Qnil;
11566 11969
11567 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, 11970 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table,
11568 doc: /* Translate table for keyboard input, or nil. 11971 doc: /* Translate table for local keyboard input, or nil.
11569If non-nil, the value should be a char-table. Each character read 11972If non-nil, the value should be a char-table. Each character read
11570from the keyboard is looked up in this char-table. If the value found 11973from the keyboard is looked up in this char-table. If the value found
11571there is non-nil, then it is used instead of the actual input character. 11974there is non-nil, then it is used instead of the actual input character.
@@ -11575,8 +11978,10 @@ If it is a string or vector of length N, character codes N and up are left
11575untranslated. In a vector, an element which is nil means "no translation". 11978untranslated. In a vector, an element which is nil means "no translation".
11576 11979
11577This is applied to the characters supplied to input methods, not their 11980This is applied to the characters supplied to input methods, not their
11578output. See also `translation-table-for-input'. */); 11981output. See also `translation-table-for-input'.
11579 Vkeyboard_translate_table = Qnil; 11982
11983This variable has a separate binding for each terminal. See Info node
11984`(elisp)Multiple displays'. */);
11580 11985
11581 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, 11986 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend,
11582 doc: /* Non-nil means to always spawn a subshell instead of suspending. 11987 doc: /* Non-nil means to always spawn a subshell instead of suspending.
@@ -11661,7 +12066,11 @@ buffer's local map, and the minor mode keymaps and text property keymaps.
11661It also replaces `overriding-local-map'. 12066It also replaces `overriding-local-map'.
11662 12067
11663This variable is intended to let commands such as `universal-argument' 12068This variable is intended to let commands such as `universal-argument'
11664set up a different keymap for reading the next command. */); 12069set up a different keymap for reading the next command.
12070
12071`overriding-terminal-local-map' has a separate binding for each
12072terminal device.
12073See Info node `(elisp)Multiple displays'. */);
11665 12074
11666 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, 12075 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
11667 doc: /* Keymap that overrides all other local keymaps. 12076 doc: /* Keymap that overrides all other local keymaps.
@@ -11686,7 +12095,61 @@ and the minor mode maps regardless of `overriding-local-map'. */);
11686 doc: /* Alist of system-specific X windows key symbols. 12095 doc: /* Alist of system-specific X windows key symbols.
11687Each element should have the form (N . SYMBOL) where N is the 12096Each element should have the form (N . SYMBOL) where N is the
11688numeric keysym code (sans the \"system-specific\" bit 1<<28) 12097numeric keysym code (sans the \"system-specific\" bit 1<<28)
11689and SYMBOL is its name. */); 12098and SYMBOL is its name.
12099
12100`system-key-alist' has a separate binding for each terminal device.
12101See Info node `(elisp)Multiple displays'. */);
12102
12103 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map,
12104 doc: /* Keymap that translates key sequences to key sequences during input.
12105This is used mainly for mapping ASCII function key sequences into
12106real Emacs function key events (symbols).
12107
12108The `read-key-sequence' function replaces any subsequence bound by
12109`local-function-key-map' with its binding. More precisely, when the
12110active keymaps have no binding for the current key sequence but
12111`local-function-key-map' binds a suffix of the sequence to a vector or
12112string, `read-key-sequence' replaces the matching suffix with its
12113binding, and continues with the new sequence.
12114
12115If the binding is a function, it is called with one argument (the prompt)
12116and its return value (a key sequence) is used.
12117
12118The events that come from bindings in `local-function-key-map' are not
12119themselves looked up in `local-function-key-map'.
12120
12121For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
12122Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
12123`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
12124typing `ESC O P x' would return [f1 x].
12125
12126`local-function-key-map' has a separate binding for each terminal
12127device. See Info node `(elisp)Multiple displays'. If you need to
12128define a binding on all terminals, change `function-key-map'
12129instead. Initially, `local-function-key-map' is an empty keymap that
12130has `function-key-map' as its parent on all terminal devices. */);
12131
12132 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
12133 doc: /* The parent keymap of all `local-function-key-map' instances.
12134Function key definitions that apply to all terminal devices should go
12135here. If a mapping is defined in both the current
12136`local-function-key-map' binding and this variable, then the local
12137definition will take precendence. */);
12138 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
12139
12140 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map,
12141 doc: /* Keymap of key translations that can override keymaps.
12142This keymap works like `function-key-map', but comes after that,
12143and its non-prefix bindings override ordinary bindings.
12144
12145`key-translation-map' has a separate binding for each terminal device.
12146(See Info node `(elisp)Multiple displays'.) If you need to set a key
12147translation on all terminals, change `global-key-translation-map' instead. */);
12148
12149 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
12150 doc: /* The parent keymap of all `local-key-translation-map' instances.
12151Key translations that apply to all terminal devices should go here. */);
12152 Vkey_translation_map = Fmake_sparse_keymap (Qnil);
11690 12153
11691 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, 12154 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
11692 doc: /* List of deferred actions to be performed at a later time. 12155 doc: /* List of deferred actions to be performed at a later time.
@@ -11855,6 +12318,7 @@ mark_kboards ()
11855 mark_object (kb->Voverriding_terminal_local_map); 12318 mark_object (kb->Voverriding_terminal_local_map);
11856 mark_object (kb->Vlast_command); 12319 mark_object (kb->Vlast_command);
11857 mark_object (kb->Vreal_last_command); 12320 mark_object (kb->Vreal_last_command);
12321 mark_object (kb->Vkeyboard_translate_table);
11858 mark_object (kb->Vprefix_arg); 12322 mark_object (kb->Vprefix_arg);
11859 mark_object (kb->Vlast_prefix_arg); 12323 mark_object (kb->Vlast_prefix_arg);
11860 mark_object (kb->kbd_queue); 12324 mark_object (kb->kbd_queue);
@@ -11862,6 +12326,8 @@ mark_kboards ()
11862 mark_object (kb->Vlast_kbd_macro); 12326 mark_object (kb->Vlast_kbd_macro);
11863 mark_object (kb->Vsystem_key_alist); 12327 mark_object (kb->Vsystem_key_alist);
11864 mark_object (kb->system_key_syms); 12328 mark_object (kb->system_key_syms);
12329 mark_object (kb->Vlocal_function_key_map);
12330 mark_object (kb->Vlocal_key_translation_map);
11865 mark_object (kb->Vdefault_minibuffer_frame); 12331 mark_object (kb->Vdefault_minibuffer_frame);
11866 mark_object (kb->echo_string); 12332 mark_object (kb->echo_string);
11867 } 12333 }
diff --git a/src/keyboard.h b/src/keyboard.h
index 6fe76363064..0879bacc156 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -23,8 +23,9 @@ Boston, MA 02110-1301, USA. */
23 23
24/* Length of echobuf field in each KBOARD. */ 24/* Length of echobuf field in each KBOARD. */
25 25
26/* Each KBOARD represents one logical input stream from which Emacs gets input. 26/* Each KBOARD represents one logical input stream from which Emacs
27 If we are using an ordinary terminal, it has one KBOARD object. 27 gets input. If we are using ordinary terminals, it has one KBOARD
28 object for each terminal device.
28 Usually each X display screen has its own KBOARD, 29 Usually each X display screen has its own KBOARD,
29 but when two of them are on the same X server, 30 but when two of them are on the same X server,
30 we assume they share a keyboard and give them one KBOARD in common. 31 we assume they share a keyboard and give them one KBOARD in common.
@@ -83,6 +84,9 @@ struct kboard
83 other commands. */ 84 other commands. */
84 Lisp_Object Vreal_last_command; 85 Lisp_Object Vreal_last_command;
85 86
87 /* User-supplied table to translate input characters through. */
88 Lisp_Object Vkeyboard_translate_table;
89
86 /* The prefix argument for the next command, in raw form. */ 90 /* The prefix argument for the next command, in raw form. */
87 Lisp_Object Vprefix_arg; 91 Lisp_Object Vprefix_arg;
88 92
@@ -123,6 +127,14 @@ struct kboard
123 /* Cache for modify_event_symbol. */ 127 /* Cache for modify_event_symbol. */
124 Lisp_Object system_key_syms; 128 Lisp_Object system_key_syms;
125 129
130 /* Keymap mapping ASCII function key sequences onto their
131 preferred forms. Initialized by the terminal-specific lisp
132 files. See the DEFVAR for more documentation. */
133 Lisp_Object Vlocal_function_key_map;
134
135 /* Keymap of key translations that can override keymaps. */
136 Lisp_Object Vlocal_key_translation_map;
137
126 /* Minibufferless frames on this display use this frame's minibuffer. */ 138 /* Minibufferless frames on this display use this frame's minibuffer. */
127 Lisp_Object Vdefault_minibuffer_frame; 139 Lisp_Object Vdefault_minibuffer_frame;
128 140
@@ -155,7 +167,7 @@ struct kboard
155 }; 167 };
156 168
157#ifdef MULTI_KBOARD 169#ifdef MULTI_KBOARD
158/* Temporarily used before a frame has been opened, and for termcap frames */ 170/* Temporarily used before a frame has been opened. */
159extern KBOARD *initial_kboard; 171extern KBOARD *initial_kboard;
160 172
161/* In the single-kboard state, this is the kboard 173/* In the single-kboard state, this is the kboard
@@ -190,10 +202,6 @@ extern EMACS_INT num_nonmacro_input_events;
190/* Nonzero means polling for input is temporarily suppressed. */ 202/* Nonzero means polling for input is temporarily suppressed. */
191extern int poll_suppress_count; 203extern int poll_suppress_count;
192 204
193/* Keymap mapping ASCII function key sequences onto their preferred forms.
194 Initialized by the terminal-specific lisp files. */
195extern Lisp_Object Vfunction_key_map;
196
197/* Vector holding the key sequence that invoked the current command. 205/* Vector holding the key sequence that invoked the current command.
198 It is reused for each command, and it may be longer than the current 206 It is reused for each command, and it may be longer than the current
199 sequence; this_command_key_count indicates how many elements 207 sequence; this_command_key_count indicates how many elements
@@ -301,18 +309,24 @@ extern Lisp_Object parse_modifiers P_ ((Lisp_Object));
301extern Lisp_Object reorder_modifiers P_ ((Lisp_Object)); 309extern Lisp_Object reorder_modifiers P_ ((Lisp_Object));
302extern Lisp_Object read_char P_ ((int, int, Lisp_Object *, Lisp_Object, 310extern Lisp_Object read_char P_ ((int, int, Lisp_Object *, Lisp_Object,
303 int *, EMACS_TIME *)); 311 int *, EMACS_TIME *));
304/* User-supplied string to translate input characters through. */ 312
305extern Lisp_Object Vkeyboard_translate_table; 313
314/* Parent keymap of terminal-local function-key-map instances. */
315extern Lisp_Object Vfunction_key_map;
316
317/* Parent keymap of terminal-local key-translation-map instances. */
318extern Lisp_Object Vkey_translation_map;
306 319
307extern int parse_menu_item P_ ((Lisp_Object, int, int)); 320extern int parse_menu_item P_ ((Lisp_Object, int, int));
308 321
309extern void echo_now P_ ((void)); 322extern void echo_now P_ ((void));
310extern void init_kboard P_ ((KBOARD *)); 323extern void init_kboard P_ ((KBOARD *));
311extern void delete_kboard P_ ((KBOARD *)); 324extern void delete_kboard P_ ((KBOARD *));
312extern void single_kboard_state P_ ((void));
313extern void not_single_kboard_state P_ ((KBOARD *)); 325extern void not_single_kboard_state P_ ((KBOARD *));
326extern void push_kboard P_ ((struct kboard *));
314extern void push_frame_kboard P_ ((struct frame *)); 327extern void push_frame_kboard P_ ((struct frame *));
315extern void pop_frame_kboard P_ ((void)); 328extern void pop_kboard P_ ((void));
329extern void temporarily_switch_to_single_kboard P_ ((struct frame *));
316extern void record_asynch_buffer_change P_ ((void)); 330extern void record_asynch_buffer_change P_ ((void));
317extern SIGTYPE input_poll_signal P_ ((int)); 331extern SIGTYPE input_poll_signal P_ ((int));
318extern void start_polling P_ ((void)); 332extern void start_polling P_ ((void));
@@ -346,5 +360,8 @@ extern Lisp_Object menu_item_eval_property P_ ((Lisp_Object));
346extern int kbd_buffer_events_waiting P_ ((int)); 360extern int kbd_buffer_events_waiting P_ ((int));
347extern void add_user_signals P_ ((int, const char *)); 361extern void add_user_signals P_ ((int, const char *));
348 362
363extern int tty_read_avail_input P_ ((struct terminal *, int,
364 struct input_event *));
365
349/* arch-tag: 769cbade-1ba9-4950-b886-db265b061aa3 366/* arch-tag: 769cbade-1ba9-4950-b886-db265b061aa3
350 (do not change this comment) */ 367 (do not change this comment) */
diff --git a/src/keymap.c b/src/keymap.c
index dbcf1d6fcfd..47e3f50786b 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -31,6 +31,7 @@ Boston, MA 02110-1301, USA. */
31#include "buffer.h" 31#include "buffer.h"
32#include "charset.h" 32#include "charset.h"
33#include "keyboard.h" 33#include "keyboard.h"
34#include "frame.h"
34#include "termhooks.h" 35#include "termhooks.h"
35#include "blockinput.h" 36#include "blockinput.h"
36#include "puresize.h" 37#include "puresize.h"
@@ -90,14 +91,6 @@ Lisp_Object Vminor_mode_overriding_map_alist;
90/* List of emulation mode keymap alists. */ 91/* List of emulation mode keymap alists. */
91Lisp_Object Vemulation_mode_map_alists; 92Lisp_Object Vemulation_mode_map_alists;
92 93
93/* Keymap mapping ASCII function key sequences onto their preferred forms.
94 Initialized by the terminal-specific lisp files. See DEFVAR for more
95 documentation. */
96Lisp_Object Vfunction_key_map;
97
98/* Keymap mapping ASCII function key sequences onto their preferred forms. */
99Lisp_Object Vkey_translation_map;
100
101/* A list of all commands given new bindings since a certain time 94/* A list of all commands given new bindings since a certain time
102 when nil was stored here. 95 when nil was stored here.
103 This is used to speed up recomputation of menu key equivalents 96 This is used to speed up recomputation of menu key equivalents
@@ -3021,11 +3014,11 @@ You type Translation\n\
3021 outbuf = Fcurrent_buffer (); 3014 outbuf = Fcurrent_buffer ();
3022 3015
3023 /* Report on alternates for keys. */ 3016 /* Report on alternates for keys. */
3024 if (STRINGP (Vkeyboard_translate_table) && !NILP (prefix)) 3017 if (STRINGP (current_kboard->Vkeyboard_translate_table) && !NILP (prefix))
3025 { 3018 {
3026 int c; 3019 int c;
3027 const unsigned char *translate = SDATA (Vkeyboard_translate_table); 3020 const unsigned char *translate = SDATA (current_kboard->Vkeyboard_translate_table);
3028 int translate_len = SCHARS (Vkeyboard_translate_table); 3021 int translate_len = SCHARS (current_kboard->Vkeyboard_translate_table);
3029 3022
3030 for (c = 0; c < translate_len; c++) 3023 for (c = 0; c < translate_len; c++)
3031 if (translate[c] != c) 3024 if (translate[c] != c)
@@ -3048,14 +3041,14 @@ You type Translation\n\
3048 insert ("\n", 1); 3041 insert ("\n", 1);
3049 3042
3050 /* Insert calls signal_after_change which may GC. */ 3043 /* Insert calls signal_after_change which may GC. */
3051 translate = SDATA (Vkeyboard_translate_table); 3044 translate = SDATA (current_kboard->Vkeyboard_translate_table);
3052 } 3045 }
3053 3046
3054 insert ("\n", 1); 3047 insert ("\n", 1);
3055 } 3048 }
3056 3049
3057 if (!NILP (Vkey_translation_map)) 3050 if (!NILP (current_kboard->Vlocal_key_translation_map))
3058 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix, 3051 describe_map_tree (current_kboard->Vlocal_key_translation_map, 0, Qnil, prefix,
3059 "Key translations", nomenu, 1, 0, 0); 3052 "Key translations", nomenu, 1, 0, 0);
3060 3053
3061 3054
@@ -3144,8 +3137,8 @@ You type Translation\n\
3144 "\f\nGlobal Bindings", nomenu, 0, 1, 0); 3137 "\f\nGlobal Bindings", nomenu, 0, 1, 0);
3145 3138
3146 /* Print the function-key-map translations under this prefix. */ 3139 /* Print the function-key-map translations under this prefix. */
3147 if (!NILP (Vfunction_key_map)) 3140 if (!NILP (current_kboard->Vlocal_function_key_map))
3148 describe_map_tree (Vfunction_key_map, 0, Qnil, prefix, 3141 describe_map_tree (current_kboard->Vlocal_function_key_map, 0, Qnil, prefix,
3149 "\f\nFunction key map translations", nomenu, 1, 0, 0); 3142 "\f\nFunction key map translations", nomenu, 1, 0, 0);
3150 3143
3151 UNGCPRO; 3144 UNGCPRO;
@@ -4115,37 +4108,6 @@ the same way. The "active" keymaps in each alist are used before
4115`minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */); 4108`minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */);
4116 Vemulation_mode_map_alists = Qnil; 4109 Vemulation_mode_map_alists = Qnil;
4117 4110
4118
4119 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
4120 doc: /* Keymap that translates key sequences to key sequences during input.
4121This is used mainly for mapping ASCII function key sequences into
4122real Emacs function key events (symbols).
4123
4124The `read-key-sequence' function replaces any subsequence bound by
4125`function-key-map' with its binding. More precisely, when the active
4126keymaps have no binding for the current key sequence but
4127`function-key-map' binds a suffix of the sequence to a vector or string,
4128`read-key-sequence' replaces the matching suffix with its binding, and
4129continues with the new sequence.
4130
4131If the binding is a function, it is called with one argument (the prompt)
4132and its return value (a key sequence) is used.
4133
4134The events that come from bindings in `function-key-map' are not
4135themselves looked up in `function-key-map'.
4136
4137For example, suppose `function-key-map' binds `ESC O P' to [f1].
4138Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
4139`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix
4140key, typing `ESC O P x' would return [f1 x]. */);
4141 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
4142
4143 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
4144 doc: /* Keymap of key translations that can override keymaps.
4145This keymap works like `function-key-map', but comes after that,
4146and its non-prefix bindings override ordinary bindings. */);
4147 Vkey_translation_map = Qnil;
4148
4149 staticpro (&Vmouse_events); 4111 staticpro (&Vmouse_events);
4150 Vmouse_events = Fcons (intern ("menu-bar"), 4112 Vmouse_events = Fcons (intern ("menu-bar"),
4151 Fcons (intern ("tool-bar"), 4113 Fcons (intern ("tool-bar"),
diff --git a/src/keymap.h b/src/keymap.h
index f55f76d5005..b305a318944 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -38,6 +38,7 @@ EXFUN (Fcurrent_active_maps, 1);
38extern Lisp_Object access_keymap P_ ((Lisp_Object, Lisp_Object, int, int, int)); 38extern Lisp_Object access_keymap P_ ((Lisp_Object, Lisp_Object, int, int, int));
39extern Lisp_Object get_keyelt P_ ((Lisp_Object, int)); 39extern Lisp_Object get_keyelt P_ ((Lisp_Object, int));
40extern Lisp_Object get_keymap P_ ((Lisp_Object, int, int)); 40extern Lisp_Object get_keymap P_ ((Lisp_Object, int, int));
41EXFUN (Fset_keymap_parent, 2);
41extern void describe_map_tree P_ ((Lisp_Object, int, Lisp_Object, Lisp_Object, 42extern void describe_map_tree P_ ((Lisp_Object, int, Lisp_Object, Lisp_Object,
42 char *, int, int, int, int)); 43 char *, int, int, int, int));
43extern int current_minor_maps P_ ((Lisp_Object **, Lisp_Object **)); 44extern int current_minor_maps P_ ((Lisp_Object **, Lisp_Object **));
diff --git a/src/lisp.h b/src/lisp.h
index d92f4045742..4ae55c5519e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -84,14 +84,14 @@ extern void die P_((const char *, const char *, int)) NO_RETURN;
84 84
85#ifdef ENABLE_CHECKING 85#ifdef ENABLE_CHECKING
86 86
87#define CHECK(check,msg) (((check) || suppress_checking \ 87#define CHECK(check,msg) ((void)((check) || suppress_checking \
88 ? (void) 0 \ 88 ? (void) 0 \
89 : die ((msg), __FILE__, __LINE__)), \ 89 : die ((msg), __FILE__, __LINE__)), \
90 0) 90 0)
91#else 91#else
92 92
93/* Produce same side effects and result, but don't complain. */ 93/* Produce same side effects and result, but don't complain. */
94#define CHECK(check,msg) ((check),0) 94#define CHECK(check,msg) ((void)(check),0)
95 95
96#endif 96#endif
97 97
@@ -2989,6 +2989,10 @@ extern Lisp_Object Qvertical_scroll_bar;
2989extern void discard_mouse_events P_ ((void)); 2989extern void discard_mouse_events P_ ((void));
2990EXFUN (Fevent_convert_list, 1); 2990EXFUN (Fevent_convert_list, 1);
2991EXFUN (Fread_key_sequence, 5); 2991EXFUN (Fread_key_sequence, 5);
2992EXFUN (Fset_input_interrupt_mode, 1);
2993EXFUN (Fset_output_flow_control, 2);
2994EXFUN (Fset_input_meta_mode, 2);
2995EXFUN (Fset_quit_char, 1);
2992EXFUN (Fset_input_mode, 4); 2996EXFUN (Fset_input_mode, 4);
2993extern int detect_input_pending P_ ((void)); 2997extern int detect_input_pending P_ ((void));
2994extern int detect_input_pending_ignore_squeezables P_ ((void)); 2998extern int detect_input_pending_ignore_squeezables P_ ((void));
@@ -3044,6 +3048,7 @@ EXFUN (Fvisible_frame_list, 0);
3044EXFUN (Fframe_parameter, 2); 3048EXFUN (Fframe_parameter, 2);
3045EXFUN (Fframe_parameters, 1); 3049EXFUN (Fframe_parameters, 1);
3046EXFUN (Fmodify_frame_parameters, 2); 3050EXFUN (Fmodify_frame_parameters, 2);
3051EXFUN (Fframe_with_environment, 1);
3047EXFUN (Fset_frame_height, 3); 3052EXFUN (Fset_frame_height, 3);
3048EXFUN (Fset_frame_width, 3); 3053EXFUN (Fset_frame_width, 3);
3049EXFUN (Fset_frame_size, 3); 3054EXFUN (Fset_frame_size, 3);
@@ -3109,7 +3114,7 @@ EXFUN (Fcall_process, MANY);
3109extern int child_setup P_ ((int, int, int, char **, int, Lisp_Object)); 3114extern int child_setup P_ ((int, int, int, char **, int, Lisp_Object));
3110extern void init_callproc_1 P_ ((void)); 3115extern void init_callproc_1 P_ ((void));
3111extern void init_callproc P_ ((void)); 3116extern void init_callproc P_ ((void));
3112extern void set_process_environment P_ ((void)); 3117extern void set_global_environment P_ ((void));
3113extern void syms_of_callproc P_ ((void)); 3118extern void syms_of_callproc P_ ((void));
3114 3119
3115/* defined in doc.c */ 3120/* defined in doc.c */
@@ -3171,28 +3176,31 @@ EXFUN (Fx_popup_menu, 2);
3171EXFUN (Fx_popup_dialog, 3); 3176EXFUN (Fx_popup_dialog, 3);
3172extern void syms_of_xmenu P_ ((void)); 3177extern void syms_of_xmenu P_ ((void));
3173 3178
3179/* defined in termchar.h */
3180struct tty_display_info;
3181
3182/* defined in termhooks.h */
3183struct terminal;
3184
3174/* defined in sysdep.c */ 3185/* defined in sysdep.c */
3175#ifndef HAVE_GET_CURRENT_DIR_NAME 3186#ifndef HAVE_GET_CURRENT_DIR_NAME
3176extern char *get_current_dir_name P_ ((void)); 3187extern char *get_current_dir_name P_ ((void));
3177#endif 3188#endif
3178extern void stuff_char P_ ((char c)); 3189extern void stuff_char P_ ((char c));
3179extern void init_sigio P_ ((int)); 3190extern void init_sigio P_ ((int));
3180extern void request_sigio P_ ((void));
3181extern void unrequest_sigio P_ ((void));
3182extern void reset_sys_modes P_ ((void));
3183extern void sys_subshell P_ ((void)); 3191extern void sys_subshell P_ ((void));
3184extern void sys_suspend P_ ((void)); 3192extern void sys_suspend P_ ((void));
3185extern void discard_tty_input P_ ((void)); 3193extern void discard_tty_input P_ ((void));
3186extern void init_sys_modes P_ ((void)); 3194extern void init_sys_modes P_ ((struct tty_display_info *));
3187extern void get_frame_size P_ ((int *, int *)); 3195extern void reset_sys_modes P_ ((struct tty_display_info *));
3196extern void init_all_sys_modes P_ ((void));
3197extern void reset_all_sys_modes P_ ((void));
3188extern void wait_for_termination P_ ((int)); 3198extern void wait_for_termination P_ ((int));
3189extern void flush_pending_output P_ ((int)); 3199extern void flush_pending_output P_ ((int));
3190extern void child_setup_tty P_ ((int)); 3200extern void child_setup_tty P_ ((int));
3191extern void setup_pty P_ ((int)); 3201extern void setup_pty P_ ((int));
3192extern int set_window_size P_ ((int, int, int)); 3202extern int set_window_size P_ ((int, int, int));
3193extern void create_process P_ ((Lisp_Object, char **, Lisp_Object)); 3203extern void create_process P_ ((Lisp_Object, char **, Lisp_Object));
3194extern int tabs_safe_p P_ ((void));
3195extern void init_baud_rate P_ ((void));
3196extern int emacs_open P_ ((const char *, int, int)); 3204extern int emacs_open P_ ((const char *, int, int));
3197extern int emacs_close P_ ((int)); 3205extern int emacs_close P_ ((int));
3198extern int emacs_read P_ ((int, char *, unsigned int)); 3206extern int emacs_read P_ ((int, char *, unsigned int));
@@ -3227,6 +3235,9 @@ extern void syms_of_dired P_ ((void));
3227extern void syms_of_term P_ ((void)); 3235extern void syms_of_term P_ ((void));
3228extern void fatal () NO_RETURN; 3236extern void fatal () NO_RETURN;
3229 3237
3238/* Defined in terminal.c */
3239extern void syms_of_terminal P_ ((void));
3240
3230#ifdef HAVE_WINDOW_SYSTEM 3241#ifdef HAVE_WINDOW_SYSTEM
3231/* Defined in fontset.c */ 3242/* Defined in fontset.c */
3232extern void syms_of_fontset P_ ((void)); 3243extern void syms_of_fontset P_ ((void));
diff --git a/src/lread.c b/src/lread.c
index 088f729075d..49a56a0e935 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -27,6 +27,7 @@ Boston, MA 02110-1301, USA. */
27#include <sys/stat.h> 27#include <sys/stat.h>
28#include <sys/file.h> 28#include <sys/file.h>
29#include <errno.h> 29#include <errno.h>
30#include <setjmp.h>
30#include "lisp.h" 31#include "lisp.h"
31#include "intervals.h" 32#include "intervals.h"
32#include "buffer.h" 33#include "buffer.h"
@@ -34,6 +35,7 @@ Boston, MA 02110-1301, USA. */
34#include <epaths.h> 35#include <epaths.h>
35#include "commands.h" 36#include "commands.h"
36#include "keyboard.h" 37#include "keyboard.h"
38#include "frame.h"
37#include "termhooks.h" 39#include "termhooks.h"
38#include "coding.h" 40#include "coding.h"
39#include "blockinput.h" 41#include "blockinput.h"
@@ -446,8 +448,6 @@ static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
446 448
447/* Get a character from the tty. */ 449/* Get a character from the tty. */
448 450
449extern Lisp_Object read_char ();
450
451/* Read input events until we get one that's acceptable for our purposes. 451/* Read input events until we get one that's acceptable for our purposes.
452 452
453 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed 453 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
@@ -499,10 +499,12 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
499 EMACS_ADD_TIME (end_time, end_time, wait_time); 499 EMACS_ADD_TIME (end_time, end_time, wait_time);
500 } 500 }
501 501
502 /* Read until we get an acceptable event. */ 502/* Read until we get an acceptable event. */
503 retry: 503 retry:
504 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0, 504 do
505 NUMBERP (seconds) ? &end_time : NULL); 505 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
506 NUMBERP (seconds) ? &end_time : NULL);
507 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
506 508
507 if (BUFFERP (val)) 509 if (BUFFERP (val))
508 goto retry; 510 goto retry;
diff --git a/src/macfns.c b/src/macfns.c
index b7a8cd7e974..6ce4b66031e 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -1370,11 +1370,11 @@ x_set_mouse_color (f, arg, oldval)
1370 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; 1370 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
1371 Cursor hourglass_cursor, horizontal_drag_cursor; 1371 Cursor hourglass_cursor, horizontal_drag_cursor;
1372 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 1372 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1373 unsigned long mask_color = x->background_pixel; 1373 unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
1374 1374
1375 /* Don't let pointers be invisible. */ 1375 /* Don't let pointers be invisible. */
1376 if (mask_color == pixel) 1376 if (mask_color == pixel)
1377 pixel = x->foreground_pixel; 1377 pixel = FRAME_FOREGROUND_PIXEL (f);
1378 1378
1379 f->output_data.mac->mouse_pixel = pixel; 1379 f->output_data.mac->mouse_pixel = pixel;
1380 1380
@@ -2401,8 +2401,8 @@ x_make_gc (f)
2401 = (XCreatePixmapFromBitmapData 2401 = (XCreatePixmapFromBitmapData
2402 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, 2402 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2403 gray_bits, gray_width, gray_height, 2403 gray_bits, gray_width, gray_height,
2404 f->output_data.x->foreground_pixel, 2404 FRAME_FOREGROUND_PIXEL (f),
2405 f->output_data.x->background_pixel, 2405 FRAME_BACKGROUND_PIXEL (f),
2406 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); 2406 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2407#endif 2407#endif
2408 2408
diff --git a/src/macterm.c b/src/macterm.c
index bee1af5ab71..316e61cc537 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -11869,19 +11869,20 @@ mac_initialize ()
11869 redeem_scroll_bar_hook = XTredeem_scroll_bar; 11869 redeem_scroll_bar_hook = XTredeem_scroll_bar;
11870 judge_scroll_bars_hook = XTjudge_scroll_bars; 11870 judge_scroll_bars_hook = XTjudge_scroll_bars;
11871 11871
11872 scroll_region_ok = 1; /* we'll scroll partial frames */ 11872 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
11873 char_ins_del_ok = 1; 11873 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
11874 line_ins_del_ok = 1; /* we'll just blt 'em */ 11874 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
11875 fast_clear_end_of_line = 1; /* X does this well */ 11875 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
11876 memory_below_frame = 0; /* we don't remember what scrolls 11876 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
11877 off the bottom */ 11877 scrolls off the
11878 bottom */
11878 baud_rate = 19200; 11879 baud_rate = 19200;
11879 11880
11880 last_tool_bar_item = -1; 11881 last_tool_bar_item = -1;
11881 any_help_event_p = 0; 11882 any_help_event_p = 0;
11882 11883
11883 /* Try to use interrupt input; if we can't, then start polling. */ 11884 /* Try to use interrupt input; if we can't, then start polling. */
11884 Fset_input_mode (Qt, Qnil, Qt, Qnil); 11885 Fset_input_interrupt_mode (Qt);
11885 11886
11886 BLOCK_INPUT; 11887 BLOCK_INPUT;
11887 11888
diff --git a/src/macterm.h b/src/macterm.h
index b3826c5e7f7..f2d69b7821d 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -348,9 +348,6 @@ typedef struct mac_output mac_output;
348#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->window_desc) 348#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->window_desc)
349#define FRAME_X_WINDOW(f) ((f)->output_data.mac->window_desc) 349#define FRAME_X_WINDOW(f) ((f)->output_data.mac->window_desc)
350 350
351#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
352#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
353
354#define FRAME_FONT(f) ((f)->output_data.mac->font) 351#define FRAME_FONT(f) ((f)->output_data.mac->font)
355#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) 352#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset)
356 353
diff --git a/src/minibuf.c b/src/minibuf.c
index db069aaf29e..34caf2b430f 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -35,6 +35,7 @@ Boston, MA 02110-1301, USA. */
35#include "syntax.h" 35#include "syntax.h"
36#include "intervals.h" 36#include "intervals.h"
37#include "keymap.h" 37#include "keymap.h"
38#include "termhooks.h"
38 39
39extern int quit_char; 40extern int quit_char;
40 41
@@ -491,7 +492,6 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
491 if (EQ (Vminibuffer_completing_file_name, Qlambda)) 492 if (EQ (Vminibuffer_completing_file_name, Qlambda))
492 Vminibuffer_completing_file_name = Qnil; 493 Vminibuffer_completing_file_name = Qnil;
493 494
494 single_kboard_state ();
495#ifdef HAVE_X_WINDOWS 495#ifdef HAVE_X_WINDOWS
496 if (display_hourglass_p) 496 if (display_hourglass_p)
497 cancel_hourglass (); 497 cancel_hourglass ();
@@ -575,6 +575,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
575 if (minibuffer_auto_raise) 575 if (minibuffer_auto_raise)
576 Fraise_frame (mini_frame); 576 Fraise_frame (mini_frame);
577 577
578 temporarily_switch_to_single_kboard (XFRAME (mini_frame));
579
578 /* We have to do this after saving the window configuration 580 /* We have to do this after saving the window configuration
579 since that is what restores the current buffer. */ 581 since that is what restores the current buffer. */
580 582
@@ -758,8 +760,12 @@ read_minibuf (map, initial, prompt, backup_n, expflag,
758 XWINDOW (minibuf_window)->cursor.x = 0; 760 XWINDOW (minibuf_window)->cursor.x = 0;
759 XWINDOW (minibuf_window)->must_be_updated_p = 1; 761 XWINDOW (minibuf_window)->must_be_updated_p = 1;
760 update_frame (XFRAME (selected_frame), 1, 1); 762 update_frame (XFRAME (selected_frame), 1, 1);
761 if (rif && rif->flush_display) 763 {
762 rif->flush_display (XFRAME (XWINDOW (minibuf_window)->frame)); 764 struct frame *f = XFRAME (XWINDOW (minibuf_window)->frame);
765 struct redisplay_interface *rif = FRAME_RIF (f);
766 if (rif && rif->flush_display)
767 rif->flush_display (f);
768 }
763 } 769 }
764 770
765 /* Make minibuffer contents into a string. */ 771 /* Make minibuffer contents into a string. */
diff --git a/src/msdos.c b/src/msdos.c
index 8e920745f3f..f9ce739fd5b 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -508,8 +508,8 @@ ScreenVisualBell (void)
508{ 508{
509 /* This creates an xor-mask that will swap the default fore- and 509 /* This creates an xor-mask that will swap the default fore- and
510 background colors. */ 510 background colors. */
511 do_visible_bell (((the_only_x_display.foreground_pixel 511 do_visible_bell (((FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ())
512 ^ the_only_x_display.background_pixel) 512 ^ FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()))
513 * 0x11) & 0x7f); 513 * 0x11) & 0x7f);
514} 514}
515#endif 515#endif
@@ -2531,8 +2531,8 @@ internal_terminal_init ()
2531 initial_screen_colors[0] = initial_screen_colors[1] = -1; 2531 initial_screen_colors[0] = initial_screen_colors[1] = -1;
2532 2532
2533 bzero (&the_only_x_display, sizeof the_only_x_display); 2533 bzero (&the_only_x_display, sizeof the_only_x_display);
2534 the_only_x_display.background_pixel = 7; /* White */ 2534 FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = 7; /* White */
2535 the_only_x_display.foreground_pixel = 0; /* Black */ 2535 FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = 0; /* Black */
2536 bright_bg (); 2536 bright_bg ();
2537 colors = getenv ("EMACSCOLORS"); 2537 colors = getenv ("EMACSCOLORS");
2538 if (colors && strlen (colors) >= 2) 2538 if (colors && strlen (colors) >= 2)
@@ -2543,13 +2543,13 @@ internal_terminal_init ()
2543 else if (isxdigit (colors[0])) 2543 else if (isxdigit (colors[0]))
2544 colors[0] -= (isupper (colors[0]) ? 'A' : 'a') - 10; 2544 colors[0] -= (isupper (colors[0]) ? 'A' : 'a') - 10;
2545 if (colors[0] >= 0 && colors[0] < 16) 2545 if (colors[0] >= 0 && colors[0] < 16)
2546 the_only_x_display.foreground_pixel = colors[0]; 2546 FRAME_FOREGROUND_PIXEL (SELECTED_FRAME ()) = colors[0];
2547 if (isdigit (colors[1])) 2547 if (isdigit (colors[1]))
2548 colors[1] -= '0'; 2548 colors[1] -= '0';
2549 else if (isxdigit (colors[1])) 2549 else if (isxdigit (colors[1]))
2550 colors[1] -= (isupper (colors[1]) ? 'A' : 'a') - 10; 2550 colors[1] -= (isupper (colors[1]) ? 'A' : 'a') - 10;
2551 if (colors[1] >= 0 && colors[1] < 16) 2551 if (colors[1] >= 0 && colors[1] < 16)
2552 the_only_x_display.background_pixel = colors[1]; 2552 FRAME_BACKGROUND_PIXEL (SELECTED_FRAME ()) = colors[1];
2553 } 2553 }
2554 the_only_x_display.font = (XFontStruct *)1; /* must *not* be zero */ 2554 the_only_x_display.font = (XFontStruct *)1; /* must *not* be zero */
2555 the_only_x_display.display_info.mouse_face_mouse_frame = NULL; 2555 the_only_x_display.display_info.mouse_face_mouse_frame = NULL;
@@ -2583,7 +2583,7 @@ internal_terminal_init ()
2583 set_terminal_modes_hook = IT_set_terminal_modes; 2583 set_terminal_modes_hook = IT_set_terminal_modes;
2584 reset_terminal_modes_hook = IT_reset_terminal_modes; 2584 reset_terminal_modes_hook = IT_reset_terminal_modes;
2585 set_terminal_window_hook = IT_set_terminal_window; 2585 set_terminal_window_hook = IT_set_terminal_window;
2586 char_ins_del_ok = 0; 2586 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 0;
2587#endif 2587#endif
2588} 2588}
2589 2589
@@ -4880,7 +4880,7 @@ croak (badfunc)
4880 char *badfunc; 4880 char *badfunc;
4881{ 4881{
4882 fprintf (stderr, "%s not yet implemented\r\n", badfunc); 4882 fprintf (stderr, "%s not yet implemented\r\n", badfunc);
4883 reset_sys_modes (); 4883 reset_all_sys_modes ();
4884 exit (1); 4884 exit (1);
4885} 4885}
4886 4886
diff --git a/src/prefix-args.c b/src/prefix-args.c
index 50ab81c10c9..1fead09247d 100644
--- a/src/prefix-args.c
+++ b/src/prefix-args.c
@@ -53,6 +53,7 @@ Boston, MA 02110-1301, USA. */
53#endif 53#endif
54 54
55#include <stdio.h> 55#include <stdio.h>
56#include <stdlib.h>
56 57
57int 58int
58main (argc, argv) 59main (argc, argv)
diff --git a/src/print.c b/src/print.c
index 533d0a82cc4..250b62ec3a5 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1388,10 +1388,10 @@ print_preprocess (obj)
1388 for (i = 0; i < print_number_index; i++) 1388 for (i = 0; i < print_number_index; i++)
1389 if (EQ (PRINT_NUMBER_OBJECT (Vprint_number_table, i), obj)) 1389 if (EQ (PRINT_NUMBER_OBJECT (Vprint_number_table, i), obj))
1390 { 1390 {
1391 /* OBJ appears more than once. Let's remember that. */ 1391 /* OBJ appears more than once. Let's remember that. */
1392 PRINT_NUMBER_STATUS (Vprint_number_table, i) = Qt; 1392 PRINT_NUMBER_STATUS (Vprint_number_table, i) = Qt;
1393 print_depth--; 1393 print_depth--;
1394 return; 1394 return;
1395 } 1395 }
1396 1396
1397 /* OBJ is not yet recorded. Let's add to the table. */ 1397 /* OBJ is not yet recorded. Let's add to the table. */
diff --git a/src/process.c b/src/process.c
index a129195b415..bd12f3e1a68 100644
--- a/src/process.c
+++ b/src/process.c
@@ -138,11 +138,11 @@ Boston, MA 02110-1301, USA. */
138#include "charset.h" 138#include "charset.h"
139#include "coding.h" 139#include "coding.h"
140#include "process.h" 140#include "process.h"
141#include "frame.h"
141#include "termhooks.h" 142#include "termhooks.h"
142#include "termopts.h" 143#include "termopts.h"
143#include "commands.h" 144#include "commands.h"
144#include "keyboard.h" 145#include "keyboard.h"
145#include "frame.h"
146#include "blockinput.h" 146#include "blockinput.h"
147#include "dispextern.h" 147#include "dispextern.h"
148#include "composite.h" 148#include "composite.h"
@@ -328,11 +328,11 @@ extern int timers_run;
328 328
329static SELECT_TYPE input_wait_mask; 329static SELECT_TYPE input_wait_mask;
330 330
331/* Mask that excludes keyboard input descriptor (s). */ 331/* Mask that excludes keyboard input descriptor(s). */
332 332
333static SELECT_TYPE non_keyboard_wait_mask; 333static SELECT_TYPE non_keyboard_wait_mask;
334 334
335/* Mask that excludes process input descriptor (s). */ 335/* Mask that excludes process input descriptor(s). */
336 336
337static SELECT_TYPE non_process_wait_mask; 337static SELECT_TYPE non_process_wait_mask;
338 338
@@ -3158,6 +3158,10 @@ usage: (make-network-process &rest ARGS) */)
3158 3158
3159 open_socket: 3159 open_socket:
3160 3160
3161#ifdef __ultrix__
3162 /* Previously this was compiled unconditionally, but that seems
3163 unnecessary on modern systems, and `unrequest_sigio' was a noop
3164 under X anyway. --lorentey */
3161 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR) 3165 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
3162 when connect is interrupted. So let's not let it get interrupted. 3166 when connect is interrupted. So let's not let it get interrupted.
3163 Note we do not turn off polling, because polling is only used 3167 Note we do not turn off polling, because polling is only used
@@ -3174,6 +3178,7 @@ usage: (make-network-process &rest ARGS) */)
3174 record_unwind_protect (unwind_request_sigio, Qnil); 3178 record_unwind_protect (unwind_request_sigio, Qnil);
3175 unrequest_sigio (); 3179 unrequest_sigio ();
3176 } 3180 }
3181#endif
3177 3182
3178 /* Do this in case we never enter the for-loop below. */ 3183 /* Do this in case we never enter the for-loop below. */
3179 count1 = SPECPDL_INDEX (); 3184 count1 = SPECPDL_INDEX ();
@@ -6958,20 +6963,12 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6958 6963
6959 6964
6960 6965
6961/* The first time this is called, assume keyboard input comes from DESC 6966/* Add DESC to the set of keyboard input descriptors. */
6962 instead of from where we used to expect it.
6963 Subsequent calls mean assume input keyboard can come from DESC
6964 in addition to other places. */
6965
6966static int add_keyboard_wait_descriptor_called_flag;
6967 6967
6968void 6968void
6969add_keyboard_wait_descriptor (desc) 6969add_keyboard_wait_descriptor (desc)
6970 int desc; 6970 int desc;
6971{ 6971{
6972 if (! add_keyboard_wait_descriptor_called_flag)
6973 FD_CLR (0, &input_wait_mask);
6974 add_keyboard_wait_descriptor_called_flag = 1;
6975 FD_SET (desc, &input_wait_mask); 6972 FD_SET (desc, &input_wait_mask);
6976 FD_SET (desc, &non_process_wait_mask); 6973 FD_SET (desc, &non_process_wait_mask);
6977 if (desc > max_keyboard_desc) 6974 if (desc > max_keyboard_desc)
@@ -7043,7 +7040,12 @@ init_process ()
7043 process_output_skip = 0; 7040 process_output_skip = 0;
7044#endif 7041#endif
7045 7042
7043 /* Don't do this, it caused infinite select loops. The display
7044 method should call add_keyboard_wait_descriptor on stdin if it
7045 needs that. */
7046#if 0
7046 FD_SET (0, &input_wait_mask); 7047 FD_SET (0, &input_wait_mask);
7048#endif
7047 7049
7048 Vprocess_alist = Qnil; 7050 Vprocess_alist = Qnil;
7049#ifdef SIGCHLD 7051#ifdef SIGCHLD
diff --git a/src/puresize.h b/src/puresize.h
index 95f6ef6b620..733d63e5ca6 100644
--- a/src/puresize.h
+++ b/src/puresize.h
@@ -43,7 +43,7 @@ Boston, MA 02110-1301, USA. */
43#endif 43#endif
44 44
45#ifndef BASE_PURESIZE 45#ifndef BASE_PURESIZE
46#define BASE_PURESIZE (1120000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA) 46#define BASE_PURESIZE (1140000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA)
47#endif 47#endif
48 48
49/* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */ 49/* Increase BASE_PURESIZE by a ratio depending on the machine's word size. */
diff --git a/src/scroll.c b/src/scroll.c
index 3afc927c77f..964e7ba9037 100644
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -23,12 +23,13 @@ Boston, MA 02110-1301, USA. */
23#include <config.h> 23#include <config.h>
24#include <stdio.h> 24#include <stdio.h>
25#include <string.h> 25#include <string.h>
26#include "termchar.h"
27#include "lisp.h" 26#include "lisp.h"
27#include "termchar.h"
28#include "dispextern.h" 28#include "dispextern.h"
29#include "keyboard.h" 29#include "keyboard.h"
30#include "frame.h" 30#include "frame.h"
31#include "window.h" 31#include "window.h"
32#include "termhooks.h"
32 33
33/* All costs measured in characters. 34/* All costs measured in characters.
34 So no cost can exceed the area of a frame, measured in characters. 35 So no cost can exceed the area of a frame, measured in characters.
@@ -58,10 +59,12 @@ struct matrix_elt
58 unsigned char writecount; 59 unsigned char writecount;
59 }; 60 };
60 61
61static void do_direct_scrolling P_ ((struct glyph_matrix *, 62static void do_direct_scrolling P_ ((struct frame *,
63 struct glyph_matrix *,
62 struct matrix_elt *, 64 struct matrix_elt *,
63 int, int)); 65 int, int));
64static void do_scrolling P_ ((struct glyph_matrix *, 66static void do_scrolling P_ ((struct frame *,
67 struct glyph_matrix *,
65 struct matrix_elt *, 68 struct matrix_elt *,
66 int, int)); 69 int, int));
67 70
@@ -101,7 +104,8 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
101 register struct matrix_elt *p, *p1; 104 register struct matrix_elt *p, *p1;
102 register int cost, cost1; 105 register int cost, cost1;
103 106
104 int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below); 107 int lines_moved = window_size
108 + (FRAME_SCROLL_REGION_OK (frame) ? 0 : lines_below);
105 /* first_insert_cost[I] is the cost of doing the first insert-line 109 /* first_insert_cost[I] is the cost of doing the first insert-line
106 at the i'th line of the lines we are considering, 110 at the i'th line of the lines we are considering,
107 where I is origin 1 (as it is below). */ 111 where I is origin 1 (as it is below). */
@@ -241,7 +245,8 @@ calculate_scrolling (frame, matrix, window_size, lines_below,
241 of lines. */ 245 of lines. */
242 246
243static void 247static void
244do_scrolling (current_matrix, matrix, window_size, unchanged_at_top) 248do_scrolling (frame, current_matrix, matrix, window_size, unchanged_at_top)
249 struct frame *frame;
245 struct glyph_matrix *current_matrix; 250 struct glyph_matrix *current_matrix;
246 struct matrix_elt *matrix; 251 struct matrix_elt *matrix;
247 int window_size; 252 int window_size;
@@ -308,12 +313,12 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
308 /* Set the terminal window, if not done already. */ 313 /* Set the terminal window, if not done already. */
309 if (! terminal_window_p) 314 if (! terminal_window_p)
310 { 315 {
311 set_terminal_window (window_size + unchanged_at_top); 316 set_terminal_window (frame, window_size + unchanged_at_top);
312 terminal_window_p = 1; 317 terminal_window_p = 1;
313 } 318 }
314 319
315 /* Delete lines on the terminal. */ 320 /* Delete lines on the terminal. */
316 ins_del_lines (j + unchanged_at_top, - p->deletecount); 321 ins_del_lines (frame, j + unchanged_at_top, - p->deletecount);
317 } 322 }
318 else 323 else
319 { 324 {
@@ -338,7 +343,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
338 /* Set the terminal window if not yet done. */ 343 /* Set the terminal window if not yet done. */
339 if (!terminal_window_p) 344 if (!terminal_window_p)
340 { 345 {
341 set_terminal_window (window_size + unchanged_at_top); 346 set_terminal_window (frame, window_size + unchanged_at_top);
342 terminal_window_p = 1; 347 terminal_window_p = 1;
343 } 348 }
344 349
@@ -347,7 +352,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
347 --queue; 352 --queue;
348 353
349 /* Do the deletion on the terminal. */ 354 /* Do the deletion on the terminal. */
350 ins_del_lines (queue->pos, queue->count); 355 ins_del_lines (frame, queue->pos, queue->count);
351 356
352 /* All lines in the range deleted become empty in the glyph 357 /* All lines in the range deleted become empty in the glyph
353 matrix. Assign to them glyph rows that are not retained. 358 matrix. Assign to them glyph rows that are not retained.
@@ -380,7 +385,7 @@ do_scrolling (current_matrix, matrix, window_size, unchanged_at_top)
380 CHECK_MATRIX (current_matrix); 385 CHECK_MATRIX (current_matrix);
381 386
382 if (terminal_window_p) 387 if (terminal_window_p)
383 set_terminal_window (0); 388 set_terminal_window (frame, 0);
384} 389}
385 390
386 391
@@ -467,7 +472,8 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
467 /* Overhead of setting the scroll window, plus the extra cost 472 /* Overhead of setting the scroll window, plus the extra cost
468 cost of scrolling by a distance of one. The extra cost is 473 cost of scrolling by a distance of one. The extra cost is
469 added once for consistency with the cost vectors */ 474 added once for consistency with the cost vectors */
470 scroll_overhead = scroll_region_cost + extra_cost; 475 scroll_overhead
476 = FRAME_SCROLL_REGION_COST (frame) + extra_cost;
471 477
472 /* initialize the top left corner of the matrix */ 478 /* initialize the top left corner of the matrix */
473 matrix->writecost = 0; 479 matrix->writecost = 0;
@@ -650,8 +656,9 @@ calculate_direct_scrolling (frame, matrix, window_size, lines_below,
650 the cost matrix for this approach is constructed. */ 656 the cost matrix for this approach is constructed. */
651 657
652static void 658static void
653do_direct_scrolling (current_matrix, cost_matrix, window_size, 659do_direct_scrolling (frame, current_matrix, cost_matrix,
654 unchanged_at_top) 660 window_size, unchanged_at_top)
661 struct frame *frame;
655 struct glyph_matrix *current_matrix; 662 struct glyph_matrix *current_matrix;
656 struct matrix_elt *cost_matrix; 663 struct matrix_elt *cost_matrix;
657 int window_size; 664 int window_size;
@@ -742,9 +749,9 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
742 if (i > j) 749 if (i > j)
743 { 750 {
744 /* Immediately insert lines */ 751 /* Immediately insert lines */
745 set_terminal_window (i + unchanged_at_top); 752 set_terminal_window (frame, i + unchanged_at_top);
746 terminal_window_p = 1; 753 terminal_window_p = 1;
747 ins_del_lines (j - n_to_write + unchanged_at_top, i - j); 754 ins_del_lines (frame, j - n_to_write + unchanged_at_top, i - j);
748 } 755 }
749 else if (i < j) 756 else if (i < j)
750 { 757 {
@@ -774,9 +781,9 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
774 --queue; 781 --queue;
775 if (queue->count) 782 if (queue->count)
776 { 783 {
777 set_terminal_window (queue->window); 784 set_terminal_window (frame, queue->window);
778 terminal_window_p = 1; 785 terminal_window_p = 1;
779 ins_del_lines (queue->pos, queue->count); 786 ins_del_lines (frame, queue->pos, queue->count);
780 } 787 }
781 else 788 else
782 { 789 {
@@ -799,7 +806,7 @@ do_direct_scrolling (current_matrix, cost_matrix, window_size,
799 copy_from, retained_p); 806 copy_from, retained_p);
800 807
801 if (terminal_window_p) 808 if (terminal_window_p)
802 set_terminal_window (0); 809 set_terminal_window (frame, 0);
803} 810}
804 811
805 812
@@ -819,13 +826,13 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
819 matrix = ((struct matrix_elt *) 826 matrix = ((struct matrix_elt *)
820 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix)); 827 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
821 828
822 if (scroll_region_ok) 829 if (FRAME_SCROLL_REGION_OK (frame))
823 { 830 {
824 calculate_direct_scrolling (frame, matrix, window_size, 831 calculate_direct_scrolling (frame, matrix, window_size,
825 unchanged_at_bottom, 832 unchanged_at_bottom,
826 draw_cost, old_draw_cost, 833 draw_cost, old_draw_cost,
827 old_hash, new_hash, free_at_end); 834 old_hash, new_hash, free_at_end);
828 do_direct_scrolling (frame->current_matrix, 835 do_direct_scrolling (frame, frame->current_matrix,
829 matrix, window_size, unchanged_at_top); 836 matrix, window_size, unchanged_at_top);
830 } 837 }
831 else 838 else
@@ -833,7 +840,8 @@ scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
833 calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom, 840 calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom,
834 draw_cost, old_hash, new_hash, 841 draw_cost, old_hash, new_hash,
835 free_at_end); 842 free_at_end);
836 do_scrolling (frame->current_matrix, matrix, window_size, 843 do_scrolling (frame,
844 frame->current_matrix, matrix, window_size,
837 unchanged_at_top); 845 unchanged_at_top);
838 } 846 }
839} 847}
@@ -915,7 +923,7 @@ scroll_cost (frame, from, to, amount)
915 if (amount == 0) 923 if (amount == 0)
916 return 0; 924 return 0;
917 925
918 if (! scroll_region_ok) 926 if (! FRAME_SCROLL_REGION_OK (frame))
919 limit = height; 927 limit = height;
920 else if (amount > 0) 928 else if (amount > 0)
921 limit += amount; 929 limit += amount;
diff --git a/src/sysdep.c b/src/sysdep.c
index 27e90349cb6..bbaa09fbf27 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -46,6 +46,8 @@ extern void srandom P_ ((unsigned int));
46#endif 46#endif
47#endif 47#endif
48 48
49#include "sysselect.h"
50
49#include "blockinput.h" 51#include "blockinput.h"
50 52
51#ifdef MAC_OS8 53#ifdef MAC_OS8
@@ -176,6 +178,7 @@ extern int quit_char;
176#include "termopts.h" 178#include "termopts.h"
177#include "dispextern.h" 179#include "dispextern.h"
178#include "process.h" 180#include "process.h"
181#include "cm.h" /* for reset_sys_modes */
179 182
180#ifdef WINDOWSNT 183#ifdef WINDOWSNT
181#include <direct.h> 184#include <direct.h>
@@ -239,16 +242,11 @@ static int baud_convert[] =
239 242
240int emacs_ospeed; 243int emacs_ospeed;
241 244
242/* The file descriptor for Emacs's input terminal.
243 Under Unix, this is normally zero except when using X;
244 under VMS, we place the input channel number here. */
245int input_fd;
246
247void croak P_ ((char *)) NO_RETURN; 245void croak P_ ((char *)) NO_RETURN;
248 246
249#ifdef AIXHFT 247#ifdef AIXHFT
250void hft_init (); 248void hft_init P_ ((struct tty_display_info *));
251void hft_reset (); 249void hft_reset P_ ((struct tty_display_info *));
252#endif 250#endif
253 251
254/* Temporary used by `sigblock' when defined in terms of signprocmask. */ 252/* Temporary used by `sigblock' when defined in terms of signprocmask. */
@@ -331,16 +329,7 @@ get_current_dir_name ()
331#endif 329#endif
332 330
333 331
334/* Specify a different file descriptor for further input operations. */ 332/* Discard pending input on all input descriptors. */
335
336void
337change_input_fd (fd)
338 int fd;
339{
340 input_fd = fd;
341}
342
343/* Discard pending input on descriptor input_fd. */
344 333
345void 334void
346discard_tty_input () 335discard_tty_input ()
@@ -351,54 +340,61 @@ discard_tty_input ()
351 if (noninteractive) 340 if (noninteractive)
352 return; 341 return;
353 342
354 /* Discarding input is not safe when the input could contain
355 replies from the X server. So don't do it. */
356 if (read_socket_hook)
357 return;
358
359#ifdef VMS 343#ifdef VMS
360 end_kbd_input (); 344 end_kbd_input ();
361 SYS$QIOW (0, input_fd, IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0, 345 SYS$QIOW (0, fileno (CURTTY()->input), IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0,
362 &buf.main, 0, 0, terminator_mask, 0, 0); 346 &buf.main, 0, 0, terminator_mask, 0, 0);
363 queue_kbd_input (); 347 queue_kbd_input ();
364#else /* not VMS */ 348#else /* not VMS */
365#ifdef APOLLO 349#ifdef APOLLO
366 { 350 {
367 int zero = 0; 351 struct tty_display_info *tty;
368 ioctl (input_fd, TIOCFLUSH, &zero); 352 for (tty = tty_list; tty; tty = tty->next)
353 {
354 int zero = 0;
355 if (tty->input)
356 ioctl (fileno (tty->input), TIOCFLUSH, &zero);
357 }
369 } 358 }
370#else /* not Apollo */ 359#else /* not Apollo */
371#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 360#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
372 while (dos_keyread () != -1) 361 while (dos_keyread () != -1)
373 ; 362 ;
374#else /* not MSDOS */ 363#else /* not MSDOS */
375 EMACS_GET_TTY (input_fd, &buf); 364 {
376 EMACS_SET_TTY (input_fd, &buf, 0); 365 struct tty_display_info *tty;
366 for (tty = tty_list; tty; tty = tty->next)
367 {
368 if (tty->input) /* Is the device suspended? */
369 {
370 EMACS_GET_TTY (fileno (tty->input), &buf);
371 EMACS_SET_TTY (fileno (tty->input), &buf, 0);
372 }
373 }
374 }
377#endif /* not MSDOS */ 375#endif /* not MSDOS */
378#endif /* not Apollo */ 376#endif /* not Apollo */
379#endif /* not VMS */ 377#endif /* not VMS */
380#endif /* not WINDOWSNT */ 378#endif /* not WINDOWSNT */
381} 379}
382 380
381
383#ifdef SIGTSTP 382#ifdef SIGTSTP
384 383
385/* Arrange for character C to be read as the next input from 384/* Arrange for character C to be read as the next input from
386 the terminal. */ 385 the terminal.
386 XXX What if we have multiple ttys?
387*/
387 388
388void 389void
389#ifdef PROTOTYPES
390stuff_char (char c) 390stuff_char (char c)
391#else
392stuff_char (c)
393 char c;
394#endif
395{ 391{
396 if (read_socket_hook) 392 if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
397 return; 393 return;
398 394
399/* Should perhaps error if in batch mode */ 395/* Should perhaps error if in batch mode */
400#ifdef TIOCSTI 396#ifdef TIOCSTI
401 ioctl (input_fd, TIOCSTI, &c); 397 ioctl (fileno (CURTTY()->input), TIOCSTI, &c);
402#else /* no TIOCSTI */ 398#else /* no TIOCSTI */
403 error ("Cannot stuff terminal input characters in this version of Unix"); 399 error ("Cannot stuff terminal input characters in this version of Unix");
404#endif /* no TIOCSTI */ 400#endif /* no TIOCSTI */
@@ -407,7 +403,7 @@ stuff_char (c)
407#endif /* SIGTSTP */ 403#endif /* SIGTSTP */
408 404
409void 405void
410init_baud_rate () 406init_baud_rate (int fd)
411{ 407{
412 if (noninteractive) 408 if (noninteractive)
413 emacs_ospeed = 0; 409 emacs_ospeed = 0;
@@ -422,7 +418,7 @@ init_baud_rate ()
422#ifdef VMS 418#ifdef VMS
423 struct sensemode sg; 419 struct sensemode sg;
424 420
425 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0, 421 SYS$QIOW (0, fd, IO$_SENSEMODE, &sg, 0, 0,
426 &sg.class, 12, 0, 0, 0, 0 ); 422 &sg.class, 12, 0, 0, 0, 0 );
427 emacs_ospeed = sg.xmit_baud; 423 emacs_ospeed = sg.xmit_baud;
428#else /* not VMS */ 424#else /* not VMS */
@@ -430,7 +426,7 @@ init_baud_rate ()
430 struct termios sg; 426 struct termios sg;
431 427
432 sg.c_cflag = B9600; 428 sg.c_cflag = B9600;
433 tcgetattr (input_fd, &sg); 429 tcgetattr (fd, &sg);
434 emacs_ospeed = cfgetospeed (&sg); 430 emacs_ospeed = cfgetospeed (&sg);
435#if defined (USE_GETOBAUD) && defined (getobaud) 431#if defined (USE_GETOBAUD) && defined (getobaud)
436 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */ 432 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
@@ -443,16 +439,16 @@ init_baud_rate ()
443 439
444 sg.c_cflag = B9600; 440 sg.c_cflag = B9600;
445#ifdef HAVE_TCATTR 441#ifdef HAVE_TCATTR
446 tcgetattr (input_fd, &sg); 442 tcgetattr (fd, &sg);
447#else 443#else
448 ioctl (input_fd, TCGETA, &sg); 444 ioctl (fd, TCGETA, &sg);
449#endif 445#endif
450 emacs_ospeed = sg.c_cflag & CBAUD; 446 emacs_ospeed = sg.c_cflag & CBAUD;
451#else /* neither VMS nor TERMIOS nor TERMIO */ 447#else /* neither VMS nor TERMIOS nor TERMIO */
452 struct sgttyb sg; 448 struct sgttyb sg;
453 449
454 sg.sg_ospeed = B9600; 450 sg.sg_ospeed = B9600;
455 if (ioctl (input_fd, TIOCGETP, &sg) < 0) 451 if (ioctl (fd, TIOCGETP, &sg) < 0)
456 abort (); 452 abort ();
457 emacs_ospeed = sg.sg_ospeed; 453 emacs_ospeed = sg.sg_ospeed;
458#endif /* not HAVE_TERMIO */ 454#endif /* not HAVE_TERMIO */
@@ -468,6 +464,7 @@ init_baud_rate ()
468 baud_rate = 1200; 464 baud_rate = 1200;
469} 465}
470 466
467
471/*ARGSUSED*/ 468/*ARGSUSED*/
472void 469void
473set_exclusive_use (fd) 470set_exclusive_use (fd)
@@ -729,7 +726,7 @@ child_setup_tty (out)
729 726
730#ifdef BSD4_1 727#ifdef BSD4_1
731 if (interrupt_input) 728 if (interrupt_input)
732 reset_sigio (); 729 reset_sigio (0);
733#endif /* BSD4_1 */ 730#endif /* BSD4_1 */
734#ifdef RTU 731#ifdef RTU
735 { 732 {
@@ -986,53 +983,86 @@ restore_signal_handlers (saved_handlers)
986 } 983 }
987} 984}
988 985
986#ifndef SIGIO
987/* If SIGIO is broken, don't do anything. */
988void
989init_sigio (int fd)
990{
991}
992
993void
994reset_sigio (int fd)
995{
996}
997
998void
999request_sigio (void)
1000{
1001}
1002
1003void
1004unrequest_sigio (void)
1005{
1006}
1007
1008#else
989#ifdef F_SETFL 1009#ifdef F_SETFL
990 1010
991int old_fcntl_flags; 1011int old_fcntl_flags[MAXDESC];
992 1012
993void 1013void
994init_sigio (fd) 1014init_sigio (fd)
995 int fd; 1015 int fd;
996{ 1016{
997#ifdef FASYNC 1017#ifdef FASYNC
998 old_fcntl_flags = fcntl (fd, F_GETFL, 0) & ~FASYNC; 1018 old_fcntl_flags[fd] = fcntl (fd, F_GETFL, 0) & ~FASYNC;
999 fcntl (fd, F_SETFL, old_fcntl_flags | FASYNC); 1019 fcntl (fd, F_SETFL, old_fcntl_flags[fd] | FASYNC);
1000#endif 1020#endif
1001 interrupts_deferred = 0; 1021 interrupts_deferred = 0;
1002} 1022}
1003 1023
1004void 1024void
1005reset_sigio () 1025reset_sigio (fd)
1026 int fd;
1006{ 1027{
1007 unrequest_sigio (); 1028#ifdef FASYNC
1029 fcntl (fd, F_SETFL, old_fcntl_flags[fd]);
1030#endif
1008} 1031}
1009 1032
1010#ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */ 1033#ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
1034/* XXX Uhm, FASYNC is not used anymore here. */
1035/* XXX Yeah, but you need it for SIGIO, don't you? */
1011 1036
1012void 1037void
1013request_sigio () 1038request_sigio ()
1014{ 1039{
1015 if (noninteractive || read_socket_hook) 1040 if (noninteractive)
1016 return; 1041 return;
1017 1042
1018#ifdef SIGWINCH 1043#ifdef SIGWINCH
1019 sigunblock (sigmask (SIGWINCH)); 1044 sigunblock (sigmask (SIGWINCH));
1020#endif 1045#endif
1021 fcntl (input_fd, F_SETFL, old_fcntl_flags | FASYNC); 1046 sigunblock (sigmask (SIGIO));
1022 1047
1023 interrupts_deferred = 0; 1048 interrupts_deferred = 0;
1024} 1049}
1025 1050
1026void 1051void
1027unrequest_sigio () 1052unrequest_sigio (void)
1028{ 1053{
1029 if (noninteractive || read_socket_hook) 1054 if (noninteractive)
1030 return; 1055 return;
1031 1056
1057#if 0 /* XXX What's wrong with blocking SIGIO under X? */
1058 if (x_display_list)
1059 return;
1060#endif
1061
1032#ifdef SIGWINCH 1062#ifdef SIGWINCH
1033 sigblock (sigmask (SIGWINCH)); 1063 sigblock (sigmask (SIGWINCH));
1034#endif 1064#endif
1035 fcntl (input_fd, F_SETFL, old_fcntl_flags); 1065 sigblock (sigmask (SIGIO));
1036 interrupts_deferred = 1; 1066 interrupts_deferred = 1;
1037} 1067}
1038 1068
@@ -1047,7 +1077,8 @@ request_sigio ()
1047 if (noninteractive || read_socket_hook) 1077 if (noninteractive || read_socket_hook)
1048 return; 1078 return;
1049 1079
1050 ioctl (input_fd, FIOASYNC, &on); 1080 /* XXX CURTTY() is bogus here. */
1081 ioctl (fileno (CURTTY ()->input), FIOASYNC, &on);
1051 interrupts_deferred = 0; 1082 interrupts_deferred = 0;
1052} 1083}
1053 1084
@@ -1059,7 +1090,8 @@ unrequest_sigio ()
1059 if (noninteractive || read_socket_hook) 1090 if (noninteractive || read_socket_hook)
1060 return; 1091 return;
1061 1092
1062 ioctl (input_fd, FIOASYNC, &off); 1093 /* XXX CURTTY() is bogus here. */
1094 ioctl (fileno (CURTTY ()->input), FIOASYNC, &off);
1063 interrupts_deferred = 1; 1095 interrupts_deferred = 1;
1064} 1096}
1065 1097
@@ -1080,7 +1112,7 @@ request_sigio ()
1080 1112
1081 sigemptyset (&st); 1113 sigemptyset (&st);
1082 sigaddset (&st, SIGIO); 1114 sigaddset (&st, SIGIO);
1083 ioctl (input_fd, FIOASYNC, &on); 1115 ioctl (0, FIOASYNC, &on); /* XXX This fails for multiple ttys. */
1084 interrupts_deferred = 0; 1116 interrupts_deferred = 0;
1085 sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0); 1117 sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0);
1086} 1118}
@@ -1093,7 +1125,7 @@ unrequest_sigio ()
1093 if (noninteractive || read_socket_hook) 1125 if (noninteractive || read_socket_hook)
1094 return; 1126 return;
1095 1127
1096 ioctl (input_fd, FIOASYNC, &off); 1128 ioctl (0, FIOASYNC, &off); /* XXX This fails for multiple ttys. */
1097 interrupts_deferred = 1; 1129 interrupts_deferred = 1;
1098} 1130}
1099 1131
@@ -1123,6 +1155,7 @@ unrequest_sigio ()
1123#endif /* STRIDE */ 1155#endif /* STRIDE */
1124#endif /* FASYNC */ 1156#endif /* FASYNC */
1125#endif /* F_SETFL */ 1157#endif /* F_SETFL */
1158#endif /* SIGIO */
1126 1159
1127/* Saving and restoring the process group of Emacs's terminal. */ 1160/* Saving and restoring the process group of Emacs's terminal. */
1128 1161
@@ -1145,30 +1178,39 @@ unrequest_sigio ()
1145 the tty's pgroup just like any other terminal setting. If 1178 the tty's pgroup just like any other terminal setting. If
1146 inherited_group was not the tty's pgroup, then we'll get a 1179 inherited_group was not the tty's pgroup, then we'll get a
1147 SIGTTmumble when we try to change the tty's pgroup, and a CONT if 1180 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1148 it goes foreground in the future, which is what should happen. */ 1181 it goes foreground in the future, which is what should happen.
1182
1183 This variable is initialized in emacs.c. */
1149int inherited_pgroup; 1184int inherited_pgroup;
1150 1185
1151/* Split off the foreground process group to Emacs alone. 1186/* Split off the foreground process group to Emacs alone. When we are
1152 When we are in the foreground, but not started in our own process 1187 in the foreground, but not started in our own process group,
1153 group, redirect the TTY to point to our own process group. We need 1188 redirect the tty device handle FD to point to our own process
1154 to be in our own process group to receive SIGIO properly. */ 1189 group. We need to be in our own process group to receive SIGIO
1190 properly. */
1155void 1191void
1156narrow_foreground_group () 1192narrow_foreground_group (int fd)
1157{ 1193{
1158 int me = getpid (); 1194 int me = getpid ();
1159 1195
1160 setpgrp (0, inherited_pgroup); 1196 setpgrp (0, inherited_pgroup);
1197#if 0
1198 /* XXX inherited_pgroup should not be zero here, but GTK seems to
1199 mess this up. */
1200 if (! inherited_pgroup)
1201 abort (); /* Should not happen. */
1202#endif
1161 if (inherited_pgroup != me) 1203 if (inherited_pgroup != me)
1162 EMACS_SET_TTY_PGRP (input_fd, &me); 1204 EMACS_SET_TTY_PGRP (fd, &me); /* XXX This only works on the controlling tty. */
1163 setpgrp (0, me); 1205 setpgrp (0, me);
1164} 1206}
1165 1207
1166/* Set the tty to our original foreground group. */ 1208/* Set the tty to our original foreground group. */
1167void 1209void
1168widen_foreground_group () 1210widen_foreground_group (int fd)
1169{ 1211{
1170 if (inherited_pgroup != getpid ()) 1212 if (inherited_pgroup != getpid ())
1171 EMACS_SET_TTY_PGRP (input_fd, &inherited_pgroup); 1213 EMACS_SET_TTY_PGRP (fd, &inherited_pgroup);
1172 setpgrp (0, inherited_pgroup); 1214 setpgrp (0, inherited_pgroup);
1173} 1215}
1174 1216
@@ -1326,14 +1368,6 @@ emacs_set_tty (fd, settings, flushp)
1326} 1368}
1327 1369
1328 1370
1329/* The initial tty mode bits */
1330struct emacs_tty old_tty;
1331
1332/* 1 if we have been through init_sys_modes. */
1333int term_initted;
1334
1335/* 1 if outer tty status has been recorded. */
1336int old_tty_valid;
1337 1371
1338#ifdef BSD4_1 1372#ifdef BSD4_1
1339/* BSD 4.1 needs to keep track of the lmode bits in order to start 1373/* BSD 4.1 needs to keep track of the lmode bits in order to start
@@ -1343,7 +1377,7 @@ int lmode;
1343 1377
1344#ifndef F_SETOWN_BUG 1378#ifndef F_SETOWN_BUG
1345#ifdef F_SETOWN 1379#ifdef F_SETOWN
1346int old_fcntl_owner; 1380int old_fcntl_owner[MAXDESC];
1347#endif /* F_SETOWN */ 1381#endif /* F_SETOWN */
1348#endif /* F_SETOWN_BUG */ 1382#endif /* F_SETOWN_BUG */
1349 1383
@@ -1368,8 +1402,22 @@ static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
1368static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1}; 1402static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
1369#endif 1403#endif
1370 1404
1405/* Initialize the terminal mode on all tty devices that are currently
1406 open. */
1407
1371void 1408void
1372init_sys_modes () 1409init_all_sys_modes (void)
1410{
1411 struct tty_display_info *tty;
1412 for (tty = tty_list; tty; tty = tty->next)
1413 init_sys_modes (tty);
1414}
1415
1416/* Initialize the terminal mode on the given tty device. */
1417
1418void
1419init_sys_modes (tty_out)
1420 struct tty_display_info *tty_out;
1373{ 1421{
1374 struct emacs_tty tty; 1422 struct emacs_tty tty;
1375 1423
@@ -1385,6 +1433,9 @@ init_sys_modes ()
1385 if (noninteractive) 1433 if (noninteractive)
1386 return; 1434 return;
1387 1435
1436 if (!tty_out->output)
1437 return; /* The tty is suspended. */
1438
1388#ifdef VMS 1439#ifdef VMS
1389 if (!input_ef) 1440 if (!input_ef)
1390 input_ef = get_kbd_event_flag (); 1441 input_ef = get_kbd_event_flag ();
@@ -1415,266 +1466,287 @@ init_sys_modes ()
1415#ifndef VMS4_4 1466#ifndef VMS4_4
1416 sys_access_reinit (); 1467 sys_access_reinit ();
1417#endif 1468#endif
1418#endif /* not VMS */ 1469#endif /* VMS */
1419 1470
1420#ifdef BSD_PGRPS 1471#ifdef BSD_PGRPS
1421 if (! read_socket_hook && EQ (Vwindow_system, Qnil)) 1472#if 0
1422 narrow_foreground_group (); 1473 /* read_socket_hook is not global anymore. I think doing this
1474 unconditionally will not cause any problems. */
1475 if (! read_socket_hook && EQ (Vinitial_window_system, Qnil))
1423#endif 1476#endif
1424 1477 narrow_foreground_group (fileno (tty_out->input));
1425#ifdef HAVE_WINDOW_SYSTEM
1426 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1427 needs the initialization code below. */
1428 if (!read_socket_hook && EQ (Vwindow_system, Qnil))
1429#endif 1478#endif
1430 {
1431 EMACS_GET_TTY (input_fd, &old_tty);
1432 1479
1433 old_tty_valid = 1; 1480 if (! tty_out->old_tty)
1481 tty_out->old_tty = (struct emacs_tty *) xmalloc (sizeof (struct emacs_tty));
1482
1483 EMACS_GET_TTY (fileno (tty_out->input), tty_out->old_tty);
1434 1484
1435 tty = old_tty; 1485 tty = *tty_out->old_tty;
1436 1486
1437#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 1487#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1438 XSETINT (Vtty_erase_char, old_tty.main.c_cc[VERASE]); 1488 XSETINT (Vtty_erase_char, tty.main.c_cc[VERASE]);
1439 1489
1440#ifdef DGUX 1490#ifdef DGUX
1441 /* This allows meta to be sent on 8th bit. */ 1491 /* This allows meta to be sent on 8th bit. */
1442 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */ 1492 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
1443#endif 1493#endif
1444 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */ 1494 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
1445 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */ 1495 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
1446#ifdef INLCR /* I'm just being cautious, 1496#ifdef INLCR /* I'm just being cautious,
1447 since I can't check how widespread INLCR is--rms. */ 1497 since I can't check how widespread INLCR is--rms. */
1448 tty.main.c_iflag &= ~INLCR; /* Disable map of NL to CR on input */ 1498 tty.main.c_iflag &= ~INLCR; /* Disable map of NL to CR on input */
1449#endif 1499#endif
1450#ifdef ISTRIP 1500#ifdef ISTRIP
1451 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */ 1501 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
1452#endif 1502#endif
1453 tty.main.c_lflag &= ~ECHO; /* Disable echo */ 1503 tty.main.c_lflag &= ~ECHO; /* Disable echo */
1454 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */ 1504 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
1455#ifdef IEXTEN 1505#ifdef IEXTEN
1456 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */ 1506 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
1457#endif 1507#endif
1458 tty.main.c_lflag |= ISIG; /* Enable signals */ 1508 tty.main.c_lflag |= ISIG; /* Enable signals */
1459 if (flow_control) 1509 if (tty_out->flow_control)
1460 { 1510 {
1461 tty.main.c_iflag |= IXON; /* Enable start/stop output control */ 1511 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
1462#ifdef IXANY 1512#ifdef IXANY
1463 tty.main.c_iflag &= ~IXANY; 1513 tty.main.c_iflag &= ~IXANY;
1464#endif /* IXANY */ 1514#endif /* IXANY */
1465 } 1515 }
1466 else 1516 else
1467 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */ 1517 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
1468 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL 1518 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
1469 on output */ 1519 on output */
1470 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ 1520 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
1471#ifdef CS8 1521#ifdef CS8
1472 if (meta_key) 1522 if (tty_out->meta_key)
1473 { 1523 {
1474 tty.main.c_cflag |= CS8; /* allow 8th bit on input */ 1524 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
1475 tty.main.c_cflag &= ~PARENB;/* Don't check parity */ 1525 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
1476 } 1526 }
1477#endif 1527#endif
1528 if (tty_out->input == stdin)
1529 {
1478 tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ 1530 tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */
1479 /* Set up C-g for both SIGQUIT and SIGINT. 1531 /* Set up C-g for both SIGQUIT and SIGINT.
1480 We don't know which we will get, but we handle both alike 1532 We don't know which we will get, but we handle both alike
1481 so which one it really gives us does not matter. */ 1533 so which one it really gives us does not matter. */
1482 tty.main.c_cc[VQUIT] = quit_char; 1534 tty.main.c_cc[VQUIT] = quit_char;
1483 tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */ 1535 }
1484 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ 1536 else
1537 {
1538 /* We normally don't get interrupt or quit signals from tty
1539 devices other than our controlling terminal; therefore,
1540 we must handle C-g as normal input. Unfortunately, this
1541 means that the interrupt and quit feature must be
1542 disabled on secondary ttys, or we would not even see the
1543 keypress.
1544
1545 Note that even though emacsclient could have special code
1546 to pass SIGINT to Emacs, we should _not_ enable
1547 interrupt/quit keys for emacsclient frames. This means
1548 that we can't break out of loops in C code from a
1549 secondary tty frame, but we can always decide what
1550 display the C-g came from, which is more important from a
1551 usability point of view. (Consider the case when two
1552 people work together using the same Emacs instance.) */
1553 tty.main.c_cc[VINTR] = CDISABLE;
1554 tty.main.c_cc[VQUIT] = CDISABLE;
1555 }
1556 tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */
1557 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
1485#ifdef VSWTCH 1558#ifdef VSWTCH
1486 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use 1559 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use
1487 of C-z */ 1560 of C-z */
1488#endif /* VSWTCH */ 1561#endif /* VSWTCH */
1489 1562
1490#if defined (mips) || defined (HAVE_TCATTR) 1563#if defined (mips) || defined (HAVE_TCATTR)
1491#ifdef VSUSP 1564#ifdef VSUSP
1492 tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */ 1565 tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */
1493#endif /* VSUSP */ 1566#endif /* VSUSP */
1494#ifdef V_DSUSP 1567#ifdef V_DSUSP
1495 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ 1568 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */
1496#endif /* V_DSUSP */ 1569#endif /* V_DSUSP */
1497#ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */ 1570#ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1498 tty.main.c_cc[VDSUSP] = CDISABLE; 1571 tty.main.c_cc[VDSUSP] = CDISABLE;
1499#endif /* VDSUSP */ 1572#endif /* VDSUSP */
1500#ifdef VLNEXT 1573#ifdef VLNEXT
1501 tty.main.c_cc[VLNEXT] = CDISABLE; 1574 tty.main.c_cc[VLNEXT] = CDISABLE;
1502#endif /* VLNEXT */ 1575#endif /* VLNEXT */
1503#ifdef VREPRINT 1576#ifdef VREPRINT
1504 tty.main.c_cc[VREPRINT] = CDISABLE; 1577 tty.main.c_cc[VREPRINT] = CDISABLE;
1505#endif /* VREPRINT */ 1578#endif /* VREPRINT */
1506#ifdef VWERASE 1579#ifdef VWERASE
1507 tty.main.c_cc[VWERASE] = CDISABLE; 1580 tty.main.c_cc[VWERASE] = CDISABLE;
1508#endif /* VWERASE */ 1581#endif /* VWERASE */
1509#ifdef VDISCARD 1582#ifdef VDISCARD
1510 tty.main.c_cc[VDISCARD] = CDISABLE; 1583 tty.main.c_cc[VDISCARD] = CDISABLE;
1511#endif /* VDISCARD */ 1584#endif /* VDISCARD */
1512 1585
1513 if (flow_control) 1586 if (tty_out->flow_control)
1514 { 1587 {
1515#ifdef VSTART 1588#ifdef VSTART
1516 tty.main.c_cc[VSTART] = '\021'; 1589 tty.main.c_cc[VSTART] = '\021';
1517#endif /* VSTART */ 1590#endif /* VSTART */
1518#ifdef VSTOP 1591#ifdef VSTOP
1519 tty.main.c_cc[VSTOP] = '\023'; 1592 tty.main.c_cc[VSTOP] = '\023';
1520#endif /* VSTOP */ 1593#endif /* VSTOP */
1521 } 1594 }
1522 else 1595 else
1523 { 1596 {
1524#ifdef VSTART 1597#ifdef VSTART
1525 tty.main.c_cc[VSTART] = CDISABLE; 1598 tty.main.c_cc[VSTART] = CDISABLE;
1526#endif /* VSTART */ 1599#endif /* VSTART */
1527#ifdef VSTOP 1600#ifdef VSTOP
1528 tty.main.c_cc[VSTOP] = CDISABLE; 1601 tty.main.c_cc[VSTOP] = CDISABLE;
1529#endif /* VSTOP */ 1602#endif /* VSTOP */
1530 } 1603 }
1531#endif /* mips or HAVE_TCATTR */ 1604#endif /* mips or HAVE_TCATTR */
1532 1605
1533#ifdef SET_LINE_DISCIPLINE 1606#ifdef SET_LINE_DISCIPLINE
1534 /* Need to explicitly request TERMIODISC line discipline or 1607 /* Need to explicitly request TERMIODISC line discipline or
1535 Ultrix's termios does not work correctly. */ 1608 Ultrix's termios does not work correctly. */
1536 tty.main.c_line = SET_LINE_DISCIPLINE; 1609 tty.main.c_line = SET_LINE_DISCIPLINE;
1537#endif 1610#endif
1538#ifdef AIX 1611#ifdef AIX
1539#ifndef IBMR2AIX 1612#ifndef IBMR2AIX
1540 /* AIX enhanced edit loses NULs, so disable it. */ 1613 /* AIX enhanced edit loses NULs, so disable it. */
1541 tty.main.c_line = 0; 1614 tty.main.c_line = 0;
1542 tty.main.c_iflag &= ~ASCEDIT; 1615 tty.main.c_iflag &= ~ASCEDIT;
1543#else 1616#else
1544 tty.main.c_cc[VSTRT] = CDISABLE; 1617 tty.main.c_cc[VSTRT] = CDISABLE;
1545 tty.main.c_cc[VSTOP] = CDISABLE; 1618 tty.main.c_cc[VSTOP] = CDISABLE;
1546 tty.main.c_cc[VSUSP] = CDISABLE; 1619 tty.main.c_cc[VSUSP] = CDISABLE;
1547 tty.main.c_cc[VDSUSP] = CDISABLE; 1620 tty.main.c_cc[VDSUSP] = CDISABLE;
1548#endif /* IBMR2AIX */ 1621#endif /* IBMR2AIX */
1549 if (flow_control) 1622 if (tty_out->flow_control)
1550 { 1623 {
1551#ifdef VSTART 1624#ifdef VSTART
1552 tty.main.c_cc[VSTART] = '\021'; 1625 tty.main.c_cc[VSTART] = '\021';
1553#endif /* VSTART */ 1626#endif /* VSTART */
1554#ifdef VSTOP 1627#ifdef VSTOP
1555 tty.main.c_cc[VSTOP] = '\023'; 1628 tty.main.c_cc[VSTOP] = '\023';
1556#endif /* VSTOP */ 1629#endif /* VSTOP */
1557 } 1630 }
1558 /* Also, PTY overloads NUL and BREAK. 1631 /* Also, PTY overloads NUL and BREAK.
1559 don't ignore break, but don't signal either, so it looks like NUL. 1632 don't ignore break, but don't signal either, so it looks like NUL.
1560 This really serves a purpose only if running in an XTERM window 1633 This really serves a purpose only if running in an XTERM window
1561 or via TELNET or the like, but does no harm elsewhere. */ 1634 or via TELNET or the like, but does no harm elsewhere. */
1562 tty.main.c_iflag &= ~IGNBRK; 1635 tty.main.c_iflag &= ~IGNBRK;
1563 tty.main.c_iflag &= ~BRKINT; 1636 tty.main.c_iflag &= ~BRKINT;
1564#endif 1637#endif
1565#else /* if not HAVE_TERMIO */ 1638#else /* if not HAVE_TERMIO */
1566#ifdef VMS 1639#ifdef VMS
1567 tty.main.tt_char |= TT$M_NOECHO; 1640 tty.main.tt_char |= TT$M_NOECHO;
1568 if (meta_key) 1641 if (meta_key)
1569 tty.main.tt_char |= TT$M_EIGHTBIT; 1642 tty.main.tt_char |= TT$M_EIGHTBIT;
1570 if (flow_control) 1643 if (tty_out->flow_control)
1571 tty.main.tt_char |= TT$M_TTSYNC; 1644 tty.main.tt_char |= TT$M_TTSYNC;
1572 else 1645 else
1573 tty.main.tt_char &= ~TT$M_TTSYNC; 1646 tty.main.tt_char &= ~TT$M_TTSYNC;
1574 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; 1647 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON;
1575#else /* not VMS (BSD, that is) */ 1648#else /* not VMS (BSD, that is) */
1576#ifndef DOS_NT 1649#ifndef DOS_NT
1577 XSETINT (Vtty_erase_char, tty.main.sg_erase); 1650 XSETINT (Vtty_erase_char, tty.main.sg_erase);
1578 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); 1651 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
1579 if (meta_key) 1652 if (meta_key)
1580 tty.main.sg_flags |= ANYP; 1653 tty.main.sg_flags |= ANYP;
1581 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; 1654 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK;
1582#endif /* not DOS_NT */ 1655#endif /* not DOS_NT */
1583#endif /* not VMS (BSD, that is) */ 1656#endif /* not VMS (BSD, that is) */
1584#endif /* not HAVE_TERMIO */ 1657#endif /* not HAVE_TERMIO */
1585 1658
1586 /* If going to use CBREAK mode, we must request C-g to interrupt 1659 /* If going to use CBREAK mode, we must request C-g to interrupt
1587 and turn off start and stop chars, etc. If not going to use 1660 and turn off start and stop chars, etc. If not going to use
1588 CBREAK mode, do this anyway so as to turn off local flow 1661 CBREAK mode, do this anyway so as to turn off local flow
1589 control for user coming over network on 4.2; in this case, 1662 control for user coming over network on 4.2; in this case,
1590 only t_stopc and t_startc really matter. */ 1663 only t_stopc and t_startc really matter. */
1591#ifndef HAVE_TERMIO 1664#ifndef HAVE_TERMIO
1592#ifdef HAVE_TCHARS 1665#ifdef HAVE_TCHARS
1593 /* Note: if not using CBREAK mode, it makes no difference how we 1666 /* Note: if not using CBREAK mode, it makes no difference how we
1594 set this */ 1667 set this */
1595 tty.tchars = new_tchars; 1668 tty.tchars = new_tchars;
1596 tty.tchars.t_intrc = quit_char; 1669 tty.tchars.t_intrc = quit_char;
1597 if (flow_control) 1670 if (tty_out->flow_control)
1598 { 1671 {
1599 tty.tchars.t_startc = '\021'; 1672 tty.tchars.t_startc = '\021';
1600 tty.tchars.t_stopc = '\023'; 1673 tty.tchars.t_stopc = '\023';
1601 } 1674 }
1602 1675
1603 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode; 1676 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | tty_out->old_tty.lmode;
1604#ifdef ultrix 1677#ifdef ultrix
1605 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt 1678 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1606 anything, and leaving it in breaks the meta key. Go figure. */ 1679 anything, and leaving it in breaks the meta key. Go figure. */
1607 tty.lmode &= ~LLITOUT; 1680 tty.lmode &= ~LLITOUT;
1608#endif 1681#endif
1609 1682
1610#ifdef BSD4_1 1683#ifdef BSD4_1
1611 lmode = tty.lmode; 1684 lmode = tty.lmode;
1612#endif 1685#endif
1613 1686
1614#endif /* HAVE_TCHARS */ 1687#endif /* HAVE_TCHARS */
1615#endif /* not HAVE_TERMIO */ 1688#endif /* not HAVE_TERMIO */
1616 1689
1617#ifdef HAVE_LTCHARS 1690#ifdef HAVE_LTCHARS
1618 tty.ltchars = new_ltchars; 1691 tty.ltchars = new_ltchars;
1619#endif /* HAVE_LTCHARS */ 1692#endif /* HAVE_LTCHARS */
1620#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */ 1693#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1621 if (!term_initted) 1694 if (!tty_out->term_initted)
1622 internal_terminal_init (); 1695 internal_terminal_init ();
1623 dos_ttraw (); 1696 dos_ttraw ();
1624#endif 1697#endif
1625 1698
1626 EMACS_SET_TTY (input_fd, &tty, 0); 1699 EMACS_SET_TTY (fileno (tty_out->input), &tty, 0);
1627 1700
1628 /* This code added to insure that, if flow-control is not to be used, 1701 /* This code added to insure that, if flow-control is not to be used,
1629 we have an unlocked terminal at the start. */ 1702 we have an unlocked terminal at the start. */
1630 1703
1631#ifdef TCXONC 1704#ifdef TCXONC
1632 if (!flow_control) ioctl (input_fd, TCXONC, 1); 1705 if (!tty_out->flow_control) ioctl (fileno (tty_out->input), TCXONC, 1);
1633#endif 1706#endif
1634#ifndef APOLLO 1707#ifndef APOLLO
1635#ifdef TIOCSTART 1708#ifdef TIOCSTART
1636 if (!flow_control) ioctl (input_fd, TIOCSTART, 0); 1709 if (!tty_out->flow_control) ioctl (fileno (tty_out->input), TIOCSTART, 0);
1637#endif 1710#endif
1638#endif 1711#endif
1639 1712
1640#if defined (HAVE_TERMIOS) || defined (HPUX9) 1713#if defined (HAVE_TERMIOS) || defined (HPUX9)
1641#ifdef TCOON 1714#ifdef TCOON
1642 if (!flow_control) tcflow (input_fd, TCOON); 1715 if (!tty_out->flow_control) tcflow (fileno (tty_out->input), TCOON);
1643#endif 1716#endif
1644#endif 1717#endif
1645 1718
1646#ifdef AIXHFT 1719#ifdef AIXHFT
1647 hft_init (); 1720 hft_init (tty_out);
1648#ifdef IBMR2AIX 1721#ifdef IBMR2AIX
1649 { 1722 {
1650 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it 1723 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1651 to be only LF. This is the way that is done. */ 1724 to be only LF. This is the way that is done. */
1652 struct termio tty; 1725 struct termio tty;
1653 1726
1654 if (ioctl (1, HFTGETID, &tty) != -1) 1727 if (ioctl (1, HFTGETID, &tty) != -1)
1655 write (1, "\033[20l", 5); 1728 write (1, "\033[20l", 5);
1656 } 1729 }
1657#endif 1730#endif
1658#endif /* AIXHFT */ 1731#endif /* AIXHFT */
1659 1732
1660#ifdef VMS 1733#ifdef VMS
1661/* Appears to do nothing when in PASTHRU mode. 1734/* Appears to do nothing when in PASTHRU mode.
1662 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0, 1735 SYS$QIOW (0, fileno (tty_out->input), IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1663 interrupt_signal, oob_chars, 0, 0, 0, 0); 1736 interrupt_signal, oob_chars, 0, 0, 0, 0);
1664*/ 1737*/
1665 queue_kbd_input (0); 1738 queue_kbd_input (0);
1666#endif /* VMS */ 1739#endif /* VMS */
1667 }
1668 1740
1669#ifdef F_SETFL 1741#ifdef F_SETFL
1670#ifndef F_SETOWN_BUG 1742#ifndef F_SETOWN_BUG
1671#ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */ 1743#ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1672 if (interrupt_input 1744 if (interrupt_input)
1673 && ! read_socket_hook && EQ (Vwindow_system, Qnil))
1674 { 1745 {
1675 old_fcntl_owner = fcntl (input_fd, F_GETOWN, 0); 1746 old_fcntl_owner[fileno (tty_out->input)] =
1676 fcntl (input_fd, F_SETOWN, getpid ()); 1747 fcntl (fileno (tty_out->input), F_GETOWN, 0);
1677 init_sigio (input_fd); 1748 fcntl (fileno (tty_out->input), F_SETOWN, getpid ());
1749 init_sigio (fileno (tty_out->input));
1678 } 1750 }
1679#endif /* F_GETOWN */ 1751#endif /* F_GETOWN */
1680#endif /* F_SETOWN_BUG */ 1752#endif /* F_SETOWN_BUG */
@@ -1682,7 +1754,7 @@ init_sys_modes ()
1682 1754
1683#ifdef BSD4_1 1755#ifdef BSD4_1
1684 if (interrupt_input) 1756 if (interrupt_input)
1685 init_sigio (input_fd); 1757 init_sigio (fileno (tty_out->input));
1686#endif 1758#endif
1687 1759
1688#ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */ 1760#ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
@@ -1692,53 +1764,56 @@ init_sys_modes ()
1692 /* This symbol is defined on recent USG systems. 1764 /* This symbol is defined on recent USG systems.
1693 Someone says without this call USG won't really buffer the file 1765 Someone says without this call USG won't really buffer the file
1694 even with a call to setbuf. */ 1766 even with a call to setbuf. */
1695 setvbuf (stdout, (char *) _sobuf, _IOFBF, sizeof _sobuf); 1767 setvbuf (tty_out->output, (char *) _sobuf, _IOFBF, sizeof _sobuf);
1696#else 1768#else
1697 setbuf (stdout, (char *) _sobuf); 1769 setbuf (tty_out->output, (char *) _sobuf);
1698#endif
1699#ifdef HAVE_WINDOW_SYSTEM
1700 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1701 needs the initialization code below. */
1702 if (EQ (Vwindow_system, Qnil)
1703#ifndef WINDOWSNT
1704 /* When running in tty mode on NT/Win95, we have a read_socket
1705 hook, but still need the rest of the initialization code below. */
1706 && (! read_socket_hook)
1707#endif
1708 )
1709#endif 1770#endif
1710 set_terminal_modes ();
1711 1771
1712 if (!term_initted 1772 tty_set_terminal_modes (tty_out->terminal);
1713 && FRAMEP (Vterminal_frame) 1773
1714 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame))) 1774 if (!tty_out->term_initted)
1715 init_frame_faces (XFRAME (Vterminal_frame)); 1775 {
1776 Lisp_Object tail, frame;
1777 FOR_EACH_FRAME (tail, frame)
1778 {
1779 /* XXX This needs to be revised. */
1780 if (FRAME_TERMCAP_P (XFRAME (frame))
1781 && FRAME_TTY (XFRAME (frame)) == tty_out)
1782 init_frame_faces (XFRAME (frame));
1783 }
1784 }
1716 1785
1717 if (term_initted && no_redraw_on_reenter) 1786 if (tty_out->term_initted && no_redraw_on_reenter)
1718 { 1787 {
1788 /* XXX This seems wrong on multi-tty. */
1719 if (display_completed) 1789 if (display_completed)
1720 direct_output_forward_char (0); 1790 direct_output_forward_char (0);
1721 } 1791 }
1722 else 1792 else
1723 { 1793 {
1794 Lisp_Object tail, frame;
1724 frame_garbaged = 1; 1795 frame_garbaged = 1;
1725 if (FRAMEP (Vterminal_frame)) 1796 FOR_EACH_FRAME (tail, frame)
1726 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; 1797 {
1798 if (FRAME_TERMCAP_P (XFRAME (frame))
1799 && FRAME_TTY (XFRAME (frame)) == tty_out)
1800 FRAME_GARBAGED_P (XFRAME (frame)) = 1;
1801 }
1727 } 1802 }
1728 1803
1729 term_initted = 1; 1804 tty_out->term_initted = 1;
1730} 1805}
1731 1806
1732/* Return nonzero if safe to use tabs in output. 1807/* Return nonzero if safe to use tabs in output.
1733 At the time this is called, init_sys_modes has not been done yet. */ 1808 At the time this is called, init_sys_modes has not been done yet. */
1734 1809
1735int 1810int
1736tabs_safe_p () 1811tabs_safe_p (int fd)
1737{ 1812{
1738 struct emacs_tty tty; 1813 struct emacs_tty etty;
1739 1814
1740 EMACS_GET_TTY (input_fd, &tty); 1815 EMACS_GET_TTY (fd, &etty);
1741 return EMACS_TTY_TABS_OK (&tty); 1816 return EMACS_TTY_TABS_OK (&etty);
1742} 1817}
1743 1818
1744/* Get terminal size from system. 1819/* Get terminal size from system.
@@ -1746,8 +1821,7 @@ tabs_safe_p ()
1746 We store 0 if there's no valid information. */ 1821 We store 0 if there's no valid information. */
1747 1822
1748void 1823void
1749get_frame_size (widthp, heightp) 1824get_tty_size (int fd, int *widthp, int *heightp)
1750 int *widthp, *heightp;
1751{ 1825{
1752 1826
1753#ifdef TIOCGWINSZ 1827#ifdef TIOCGWINSZ
@@ -1755,7 +1829,7 @@ get_frame_size (widthp, heightp)
1755 /* BSD-style. */ 1829 /* BSD-style. */
1756 struct winsize size; 1830 struct winsize size;
1757 1831
1758 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1) 1832 if (ioctl (fd, TIOCGWINSZ, &size) == -1)
1759 *widthp = *heightp = 0; 1833 *widthp = *heightp = 0;
1760 else 1834 else
1761 { 1835 {
@@ -1769,7 +1843,7 @@ get_frame_size (widthp, heightp)
1769 /* SunOS - style. */ 1843 /* SunOS - style. */
1770 struct ttysize size; 1844 struct ttysize size;
1771 1845
1772 if (ioctl (input_fd, TIOCGSIZE, &size) == -1) 1846 if (ioctl (fd, TIOCGSIZE, &size) == -1)
1773 *widthp = *heightp = 0; 1847 *widthp = *heightp = 0;
1774 else 1848 else
1775 { 1849 {
@@ -1801,7 +1875,6 @@ get_frame_size (widthp, heightp)
1801 *widthp = 0; 1875 *widthp = 0;
1802 *heightp = 0; 1876 *heightp = 0;
1803#endif 1877#endif
1804
1805#endif /* not VMS */ 1878#endif /* not VMS */
1806#endif /* not SunOS-style */ 1879#endif /* not SunOS-style */
1807#endif /* not BSD-style */ 1880#endif /* not BSD-style */
@@ -1845,37 +1918,58 @@ set_window_size (fd, height, width)
1845} 1918}
1846 1919
1847 1920
1848/* Prepare the terminal for exiting Emacs; move the cursor to the 1921
1849 bottom of the frame, turn off interrupt-driven I/O, etc. */ 1922/* Prepare all terminal devices for exiting Emacs. */
1923
1850void 1924void
1851reset_sys_modes () 1925reset_all_sys_modes (void)
1852{ 1926{
1853 struct frame *sf; 1927 struct tty_display_info *tty;
1928 for (tty = tty_list; tty; tty = tty->next)
1929 reset_sys_modes (tty);
1930}
1931
1932/* Prepare the terminal for closing it; move the cursor to the
1933 bottom of the frame, turn off interrupt-driven I/O, etc. */
1854 1934
1935void
1936reset_sys_modes (tty_out)
1937 struct tty_display_info *tty_out;
1938{
1855 if (noninteractive) 1939 if (noninteractive)
1856 { 1940 {
1857 fflush (stdout); 1941 fflush (stdout);
1858 return; 1942 return;
1859 } 1943 }
1860 if (!term_initted) 1944 if (!tty_out->term_initted)
1861 return; 1945 return;
1862#ifdef HAVE_WINDOW_SYSTEM 1946
1863 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore 1947 if (!tty_out->output)
1864 needs the clean-up code below. */ 1948 return; /* The tty is suspended. */
1865 if (!EQ (Vwindow_system, Qnil) 1949
1866#ifndef WINDOWSNT 1950 /* Go to and clear the last line of the terminal. */
1867 /* When running in tty mode on NT/Win95, we have a read_socket 1951
1868 hook, but still need the rest of the clean-up code below. */ 1952 cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
1869 || read_socket_hook 1953
1870#endif 1954 /* Code adapted from tty_clear_end_of_line. */
1871 ) 1955 if (tty_out->TS_clr_line)
1872 return; 1956 {
1873#endif 1957 emacs_tputs (tty_out, tty_out->TS_clr_line, 1, cmputc);
1874 sf = SELECTED_FRAME (); 1958 }
1875 cursor_to (FRAME_LINES (sf) - 1, 0); 1959 else
1876 clear_end_of_line (FRAME_COLS (sf)); 1960 { /* have to do it the hard way */
1877 /* clear_end_of_line may move the cursor */ 1961 int i;
1878 cursor_to (FRAME_LINES (sf) - 1, 0); 1962 tty_turn_off_insert (tty_out);
1963
1964 for (i = curX (tty_out); i < FrameCols (tty_out) - 1; i++)
1965 {
1966 fputc (' ', tty_out->output);
1967 }
1968 }
1969
1970 cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
1971 fflush (tty_out->output);
1972
1879#if defined (IBMR2AIX) && defined (AIXHFT) 1973#if defined (IBMR2AIX) && defined (AIXHFT)
1880 { 1974 {
1881 /* HFT devices normally use ^J as a LF/CR. We forced it to 1975 /* HFT devices normally use ^J as a LF/CR. We forced it to
@@ -1887,12 +1981,12 @@ reset_sys_modes ()
1887 } 1981 }
1888#endif 1982#endif
1889 1983
1890 reset_terminal_modes (); 1984 tty_reset_terminal_modes (tty_out->terminal);
1891 fflush (stdout); 1985
1892#ifdef BSD_SYSTEM 1986#ifdef BSD_SYSTEM
1893#ifndef BSD4_1 1987#ifndef BSD4_1
1894 /* Avoid possible loss of output when changing terminal modes. */ 1988 /* Avoid possible loss of output when changing terminal modes. */
1895 fsync (fileno (stdout)); 1989 fsync (fileno (tty_out->output));
1896#endif 1990#endif
1897#endif 1991#endif
1898 1992
@@ -1901,22 +1995,25 @@ reset_sys_modes ()
1901#ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ 1995#ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1902 if (interrupt_input) 1996 if (interrupt_input)
1903 { 1997 {
1904 reset_sigio (); 1998 reset_sigio (fileno (tty_out->input));
1905 fcntl (input_fd, F_SETOWN, old_fcntl_owner); 1999 fcntl (fileno (tty_out->input), F_SETOWN,
2000 old_fcntl_owner[fileno (tty_out->input)]);
1906 } 2001 }
1907#endif /* F_SETOWN */ 2002#endif /* F_SETOWN */
1908#endif /* F_SETOWN_BUG */ 2003#endif /* F_SETOWN_BUG */
1909#ifdef O_NDELAY 2004#ifdef O_NDELAY
1910 fcntl (input_fd, F_SETFL, fcntl (input_fd, F_GETFL, 0) & ~O_NDELAY); 2005 fcntl (fileno (tty_out->input), F_SETFL,
2006 fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY);
1911#endif 2007#endif
1912#endif /* F_SETFL */ 2008#endif /* F_SETFL */
1913#ifdef BSD4_1 2009#ifdef BSD4_1
1914 if (interrupt_input) 2010 if (interrupt_input)
1915 reset_sigio (); 2011 reset_sigio (fileno (tty_out->input));
1916#endif /* BSD4_1 */ 2012#endif /* BSD4_1 */
1917 2013
1918 if (old_tty_valid) 2014 if (tty_out->old_tty)
1919 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) 2015 while (EMACS_SET_TTY (fileno (tty_out->input),
2016 tty_out->old_tty, 0) < 0 && errno == EINTR)
1920 ; 2017 ;
1921 2018
1922#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 2019#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
@@ -1927,7 +2024,7 @@ reset_sys_modes ()
1927 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. 2024 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1928 A different old line discipline is therefore not restored, yet. 2025 A different old line discipline is therefore not restored, yet.
1929 Restore the old line discipline by hand. */ 2026 Restore the old line discipline by hand. */
1930 ioctl (0, TIOCSETD, &old_tty.main.c_line); 2027 ioctl (0, TIOCSETD, &tty_out->old_tty.main.c_line);
1931#endif 2028#endif
1932 2029
1933#ifdef AIXHFT 2030#ifdef AIXHFT
@@ -1935,7 +2032,7 @@ reset_sys_modes ()
1935#endif 2032#endif
1936 2033
1937#ifdef BSD_PGRPS 2034#ifdef BSD_PGRPS
1938 widen_foreground_group (); 2035 widen_foreground_group (fileno (tty_out->input));
1939#endif 2036#endif
1940} 2037}
1941 2038
@@ -2000,9 +2097,9 @@ init_vms_input ()
2000{ 2097{
2001 int status; 2098 int status;
2002 2099
2003 if (input_fd == 0) 2100 if (fileno (CURTTY ()->input)) == 0)
2004 { 2101 {
2005 status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0); 2102 status = SYS$ASSIGN (&input_dsc, &fileno (CURTTY ()->input)), 0, 0);
2006 if (! (status & 1)) 2103 if (! (status & 1))
2007 LIB$STOP (status); 2104 LIB$STOP (status);
2008 } 2105 }
@@ -2013,7 +2110,7 @@ init_vms_input ()
2013void 2110void
2014stop_vms_input () 2111stop_vms_input ()
2015{ 2112{
2016 return SYS$DASSGN (input_fd); 2113 return SYS$DASSGN (fileno (CURTTY ()->input)));
2017} 2114}
2018 2115
2019short input_buffer; 2116short input_buffer;
@@ -2029,7 +2126,7 @@ queue_kbd_input ()
2029 2126
2030 waiting_for_ast = 0; 2127 waiting_for_ast = 0;
2031 stop_input = 0; 2128 stop_input = 0;
2032 status = SYS$QIO (0, input_fd, IO$_READVBLK, 2129 status = SYS$QIO (0, fileno (CURTTY()->input), IO$_READVBLK,
2033 &input_iosb, kbd_input_ast, 1, 2130 &input_iosb, kbd_input_ast, 1,
2034 &input_buffer, 1, 0, terminator_mask, 0, 0); 2131 &input_buffer, 1, 0, terminator_mask, 0, 0);
2035} 2132}
@@ -2146,7 +2243,7 @@ end_kbd_input ()
2146#endif 2243#endif
2147 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */ 2244 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2148 { 2245 {
2149 SYS$CANCEL (input_fd); 2246 SYS$CANCEL (fileno (CURTTY()->input));
2150 return; 2247 return;
2151 } 2248 }
2152 2249
@@ -2155,7 +2252,7 @@ end_kbd_input ()
2155 SYS$CLREF (input_ef); 2252 SYS$CLREF (input_ef);
2156 waiting_for_ast = 1; 2253 waiting_for_ast = 1;
2157 stop_input = 1; 2254 stop_input = 1;
2158 SYS$CANCEL (input_fd); 2255 SYS$CANCEL (fileno (CURTTY()->input));
2159 SYS$SETAST (1); 2256 SYS$SETAST (1);
2160 SYS$WAITFR (input_ef); 2257 SYS$WAITFR (input_ef);
2161 waiting_for_ast = 0; 2258 waiting_for_ast = 0;
@@ -2217,7 +2314,8 @@ init_sigio (fd)
2217 request_sigio (); 2314 request_sigio ();
2218} 2315}
2219 2316
2220reset_sigio () 2317reset_sigio (fd)
2318 int fd;
2221{ 2319{
2222 unrequest_sigio (); 2320 unrequest_sigio ();
2223} 2321}
@@ -2559,7 +2657,9 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2559 SELECT_TYPE *rfds, *wfds, *efds; 2657 SELECT_TYPE *rfds, *wfds, *efds;
2560 EMACS_TIME *timeout; 2658 EMACS_TIME *timeout;
2561{ 2659{
2562 int ravail = 0; 2660 /* XXX This needs to be updated for multi-tty support. Is there
2661 anybody who needs to emulate select these days? */
2662 int ravail = 0;
2563 SELECT_TYPE orfds; 2663 SELECT_TYPE orfds;
2564 int timeoutval; 2664 int timeoutval;
2565 int *local_timeout; 2665 int *local_timeout;
@@ -2574,7 +2674,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2574#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS) 2674#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2575 /* If we're using X, then the native select will work; we only need the 2675 /* If we're using X, then the native select will work; we only need the
2576 emulation for non-X usage. */ 2676 emulation for non-X usage. */
2577 if (!NILP (Vwindow_system)) 2677 if (!NILP (Vinitial_window_system))
2578 return select (nfds, rfds, wfds, efds, timeout); 2678 return select (nfds, rfds, wfds, efds, timeout);
2579#endif 2679#endif
2580 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000; 2680 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000;
@@ -2683,7 +2783,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2683 } 2783 }
2684 return ravail; 2784 return ravail;
2685} 2785}
2686#endif /* not WINDOWSNT */ 2786#endif not WINDOWSNT
2687 2787
2688/* Read keyboard input into the standard buffer, 2788/* Read keyboard input into the standard buffer,
2689 waiting for at least one character. */ 2789 waiting for at least one character. */
@@ -2691,6 +2791,8 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2691void 2791void
2692read_input_waiting () 2792read_input_waiting ()
2693{ 2793{
2794 /* XXX This needs to be updated for multi-tty support. Is there
2795 anybody who needs to emulate select these days? */
2694 int nread, i; 2796 int nread, i;
2695 extern int quit_char; 2797 extern int quit_char;
2696 2798
@@ -2744,6 +2846,10 @@ read_input_waiting ()
2744 } 2846 }
2745} 2847}
2746 2848
2849#if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2850#define select sys_select
2851#endif
2852
2747#endif /* not HAVE_SELECT */ 2853#endif /* not HAVE_SELECT */
2748#endif /* not VMS */ 2854#endif /* not VMS */
2749#endif /* not MSDOS */ 2855#endif /* not MSDOS */
@@ -2760,12 +2866,13 @@ init_sigio (fd)
2760} 2866}
2761 2867
2762void 2868void
2763reset_sigio () 2869reset_sigio (fd)
2870 int fd;
2764{ 2871{
2765 if (noninteractive) 2872 if (noninteractive)
2766 return; 2873 return;
2767 lmode = ~LINTRUP & lmode; 2874 lmode = ~LINTRUP & lmode;
2768 ioctl (0, TIOCLSET, &lmode); 2875 ioctl (fd, TIOCLSET, &lmode);
2769} 2876}
2770 2877
2771void 2878void
@@ -3221,7 +3328,7 @@ sys_getenv (name)
3221#undef abort 3328#undef abort
3222sys_abort () 3329sys_abort ()
3223{ 3330{
3224 reset_sys_modes (); 3331 reset_all_sys_modes ();
3225 LIB$SIGNAL (SS$_DEBUG); 3332 LIB$SIGNAL (SS$_DEBUG);
3226} 3333}
3227#endif /* abort */ 3334#endif /* abort */
@@ -3548,7 +3655,7 @@ croak (badfunc)
3548 char *badfunc; 3655 char *badfunc;
3549{ 3656{
3550 printf ("%s not yet implemented\r\n", badfunc); 3657 printf ("%s not yet implemented\r\n", badfunc);
3551 reset_sys_modes (); 3658 reset_all_sys_modes ();
3552 exit (1); 3659 exit (1);
3553} 3660}
3554 3661
@@ -5135,7 +5242,7 @@ croak (badfunc)
5135 char *badfunc; 5242 char *badfunc;
5136{ 5243{
5137 printf ("%s not yet implemented\r\n", badfunc); 5244 printf ("%s not yet implemented\r\n", badfunc);
5138 reset_sys_modes (); 5245 reset_all_sys_modes ();
5139 exit (1); 5246 exit (1);
5140} 5247}
5141 5248
@@ -5157,7 +5264,7 @@ srandom (seed)
5157 5264
5158/* Called from init_sys_modes. */ 5265/* Called from init_sys_modes. */
5159void 5266void
5160hft_init () 5267hft_init (struct tty_display_info *tty_out)
5161{ 5268{
5162 int junk; 5269 int junk;
5163 5270
@@ -5203,15 +5310,12 @@ hft_init ()
5203 keymap.hfkey[1].hf_char = 127; 5310 keymap.hfkey[1].hf_char = 127;
5204 hftctl (0, HFSKBD, &buf); 5311 hftctl (0, HFSKBD, &buf);
5205 } 5312 }
5206 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5207 at times. */
5208 line_ins_del_ok = char_ins_del_ok = 0;
5209} 5313}
5210 5314
5211/* Reset the rubout key to backspace. */ 5315/* Reset the rubout key to backspace. */
5212 5316
5213void 5317void
5214hft_reset () 5318hft_reset (struct tty_display_info *tty_out)
5215{ 5319{
5216 struct hfbuf buf; 5320 struct hfbuf buf;
5217 struct hfkeymap keymap; 5321 struct hfkeymap keymap;
diff --git a/src/syssignal.h b/src/syssignal.h
index 36292670bc6..69ff7a41bd1 100644
--- a/src/syssignal.h
+++ b/src/syssignal.h
@@ -33,6 +33,7 @@ extern pthread_t main_thread;
33 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file 33 indicate that SIGIO doesn't work by #undef-ing SIGIO. If this file
34 #includes <signal.h>, then that will re-#define SIGIO and confuse 34 #includes <signal.h>, then that will re-#define SIGIO and confuse
35 things. */ 35 things. */
36/* XXX This is not correct anymore, there is a BROKEN_SIGIO macro. */
36 37
37#define SIGMASKTYPE sigset_t 38#define SIGMASKTYPE sigset_t
38 39
diff --git a/src/term.c b/src/term.c
index 556ae9f65b1..dcbe3f88a16 100644
--- a/src/term.c
+++ b/src/term.c
@@ -25,10 +25,19 @@ Boston, MA 02110-1301, USA. */
25#include <stdio.h> 25#include <stdio.h>
26#include <ctype.h> 26#include <ctype.h>
27#include <string.h> 27#include <string.h>
28#include <errno.h>
29#include <sys/file.h>
30#include <unistd.h> /* For isatty. */
28 31
32#if HAVE_TERMIOS_H
33#include <termios.h> /* For TIOCNOTTY. */
34#endif
35
36#include <signal.h>
37
38#include "lisp.h"
29#include "termchar.h" 39#include "termchar.h"
30#include "termopts.h" 40#include "termopts.h"
31#include "lisp.h"
32#include "charset.h" 41#include "charset.h"
33#include "coding.h" 42#include "coding.h"
34#include "keyboard.h" 43#include "keyboard.h"
@@ -39,6 +48,8 @@ Boston, MA 02110-1301, USA. */
39#include "window.h" 48#include "window.h"
40#include "keymap.h" 49#include "keymap.h"
41#include "blockinput.h" 50#include "blockinput.h"
51#include "syssignal.h"
52#include "systty.h"
42 53
43/* For now, don't try to include termcap.h. On some systems, 54/* For now, don't try to include termcap.h. On some systems,
44 configure finds a non-standard termcap.h that the main build 55 configure finds a non-standard termcap.h that the main build
@@ -61,240 +72,68 @@ extern int tgetnum P_ ((char *id));
61#include "macterm.h" 72#include "macterm.h"
62#endif 73#endif
63 74
75#ifndef O_RDWR
76#define O_RDWR 2
77#endif
78
79#ifndef O_NOCTTY
80#define O_NOCTTY 0
81#endif
82
83static void tty_set_scroll_region P_ ((struct frame *f, int start, int stop));
64static void turn_on_face P_ ((struct frame *, int face_id)); 84static void turn_on_face P_ ((struct frame *, int face_id));
65static void turn_off_face P_ ((struct frame *, int face_id)); 85static void turn_off_face P_ ((struct frame *, int face_id));
66static void tty_show_cursor P_ ((void)); 86static void tty_show_cursor P_ ((struct tty_display_info *));
67static void tty_hide_cursor P_ ((void)); 87static void tty_hide_cursor P_ ((struct tty_display_info *));
88static void tty_background_highlight P_ ((struct tty_display_info *tty));
89static void clear_tty_hooks P_ ((struct terminal *terminal));
90static void set_tty_hooks P_ ((struct terminal *terminal));
91static void dissociate_if_controlling_tty P_ ((int fd));
92static void delete_tty P_ ((struct terminal *));
93
94#define OUTPUT(tty, a) \
95 emacs_tputs ((tty), a, \
96 (int) (FRAME_LINES (XFRAME (selected_frame)) \
97 - curY (tty)), \
98 cmputc)
99
100#define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
101#define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
102
103#define OUTPUT_IF(tty, a) \
104 do { \
105 if (a) \
106 emacs_tputs ((tty), a, \
107 (int) (FRAME_LINES (XFRAME (selected_frame)) \
108 - curY (tty) ), \
109 cmputc); \
110 } while (0)
111
112#define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
68 113
69#define OUTPUT(a) \ 114/* If true, use "vs", otherwise use "ve" to make the cursor visible. */
70 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc)
71#define OUTPUT1(a) tputs (a, 1, cmputc)
72#define OUTPUTL(a, lines) tputs (a, lines, cmputc)
73
74#define OUTPUT_IF(a) \
75 do { \
76 if (a) \
77 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) \
78 - curY), cmputc); \
79 } while (0)
80 115
81#define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0) 116static int visible_cursor;
82 117
83/* Display space properties */ 118/* Display space properties */
84 119
85extern Lisp_Object Qspace, QCalign_to, QCwidth; 120extern Lisp_Object Qspace, QCalign_to, QCwidth;
86 121
87/* Function to use to ring the bell. */ 122/* Functions to call after suspending a tty. */
123Lisp_Object Vsuspend_tty_functions;
88 124
89Lisp_Object Vring_bell_function; 125/* Functions to call after resuming a tty. */
126Lisp_Object Vresume_tty_functions;
90 127
91/* If true, use "vs", otherwise use "ve" to make the cursor visible. */ 128/* Chain of all tty device parameters. */
92 129struct tty_display_info *tty_list;
93static int visible_cursor;
94
95/* Terminal characteristics that higher levels want to look at.
96 These are all extern'd in termchar.h */
97
98int must_write_spaces; /* Nonzero means spaces in the text
99 must actually be output; can't just skip
100 over some columns to leave them blank. */
101int min_padding_speed; /* Speed below which no padding necessary */
102
103int line_ins_del_ok; /* Terminal can insert and delete lines */
104int char_ins_del_ok; /* Terminal can insert and delete chars */
105int scroll_region_ok; /* Terminal supports setting the
106 scroll window */
107int scroll_region_cost; /* Cost of setting a scroll window,
108 measured in characters */
109int memory_below_frame; /* Terminal remembers lines
110 scrolled off bottom */
111int fast_clear_end_of_line; /* Terminal has a `ce' string */
112
113/* Nonzero means no need to redraw the entire frame on resuming
114 a suspended Emacs. This is useful on terminals with multiple pages,
115 where one page is used for Emacs and another for all else. */
116 130
131/* Nonzero means no need to redraw the entire frame on resuming a
132 suspended Emacs. This is useful on terminals with multiple
133 pages, where one page is used for Emacs and another for all
134 else. */
117int no_redraw_on_reenter; 135int no_redraw_on_reenter;
118 136
119/* Hook functions that you can set to snap out the functions in this file.
120 These are all extern'd in termhooks.h */
121
122void (*cursor_to_hook) P_ ((int, int));
123void (*raw_cursor_to_hook) P_ ((int, int));
124void (*clear_to_end_hook) P_ ((void));
125void (*clear_frame_hook) P_ ((void));
126void (*clear_end_of_line_hook) P_ ((int));
127
128void (*ins_del_lines_hook) P_ ((int, int));
129
130void (*delete_glyphs_hook) P_ ((int));
131
132void (*ring_bell_hook) P_ ((void));
133
134void (*reset_terminal_modes_hook) P_ ((void));
135void (*set_terminal_modes_hook) P_ ((void));
136void (*update_begin_hook) P_ ((struct frame *));
137void (*update_end_hook) P_ ((struct frame *));
138void (*set_terminal_window_hook) P_ ((int));
139void (*insert_glyphs_hook) P_ ((struct glyph *, int));
140void (*write_glyphs_hook) P_ ((struct glyph *, int));
141void (*delete_glyphs_hook) P_ ((int));
142
143int (*read_socket_hook) P_ ((int, int, struct input_event *));
144
145void (*frame_up_to_date_hook) P_ ((struct frame *));
146
147/* Return the current position of the mouse.
148
149 Set *f to the frame the mouse is in, or zero if the mouse is in no
150 Emacs frame. If it is set to zero, all the other arguments are
151 garbage.
152
153 If the motion started in a scroll bar, set *bar_window to the
154 scroll bar's window, *part to the part the mouse is currently over,
155 *x to the position of the mouse along the scroll bar, and *y to the
156 overall length of the scroll bar.
157
158 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
159 row of the character cell the mouse is over.
160
161 Set *time to the time the mouse was at the returned position.
162
163 This should clear mouse_moved until the next motion
164 event arrives. */
165
166void (*mouse_position_hook) P_ ((FRAME_PTR *f, int insist,
167 Lisp_Object *bar_window,
168 enum scroll_bar_part *part,
169 Lisp_Object *x,
170 Lisp_Object *y,
171 unsigned long *time));
172
173/* When reading from a minibuffer in a different frame, Emacs wants
174 to shift the highlight from the selected frame to the mini-buffer's
175 frame; under X, this means it lies about where the focus is.
176 This hook tells the window system code to re-decide where to put
177 the highlight. */
178
179void (*frame_rehighlight_hook) P_ ((FRAME_PTR f));
180
181/* If we're displaying frames using a window system that can stack
182 frames on top of each other, this hook allows you to bring a frame
183 to the front, or bury it behind all the other windows. If this
184 hook is zero, that means the device we're displaying on doesn't
185 support overlapping frames, so there's no need to raise or lower
186 anything.
187
188 If RAISE is non-zero, F is brought to the front, before all other
189 windows. If RAISE is zero, F is sent to the back, behind all other
190 windows. */
191
192void (*frame_raise_lower_hook) P_ ((FRAME_PTR f, int raise));
193
194/* If the value of the frame parameter changed, whis hook is called.
195 For example, if going from fullscreen to not fullscreen this hook
196 may do something OS dependent, like extended window manager hints on X11. */
197void (*fullscreen_hook) P_ ((struct frame *f));
198
199/* Set the vertical scroll bar for WINDOW to have its upper left corner
200 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
201 indicate that we are displaying PORTION characters out of a total
202 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
203 have a scroll bar, create one for it. */
204
205void (*set_vertical_scroll_bar_hook)
206 P_ ((struct window *window,
207 int portion, int whole, int position));
208
209
210/* The following three hooks are used when we're doing a thorough
211 redisplay of the frame. We don't explicitly know which scroll bars
212 are going to be deleted, because keeping track of when windows go
213 away is a real pain - can you say set-window-configuration?
214 Instead, we just assert at the beginning of redisplay that *all*
215 scroll bars are to be removed, and then save scroll bars from the
216 fiery pit when we actually redisplay their window. */
217
218/* Arrange for all scroll bars on FRAME to be removed at the next call
219 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
220 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
221
222 This should be applied to each frame each time its window tree is
223 redisplayed, even if it is not displaying scroll bars at the moment;
224 if the HAS_SCROLL_BARS flag has just been turned off, only calling
225 this and the judge_scroll_bars_hook will get rid of them.
226
227 If non-zero, this hook should be safe to apply to any frame,
228 whether or not it can support scroll bars, and whether or not it is
229 currently displaying them. */
230
231void (*condemn_scroll_bars_hook) P_ ((FRAME_PTR frame));
232
233/* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
234 Note that it's okay to redeem a scroll bar that is not condemned. */
235
236void (*redeem_scroll_bar_hook) P_ ((struct window *window));
237
238/* Remove all scroll bars on FRAME that haven't been saved since the
239 last call to `*condemn_scroll_bars_hook'.
240
241 This should be applied to each frame after each time its window
242 tree is redisplayed, even if it is not displaying scroll bars at the
243 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
244 calling this and condemn_scroll_bars_hook will get rid of them.
245
246 If non-zero, this hook should be safe to apply to any frame,
247 whether or not it can support scroll bars, and whether or not it is
248 currently displaying them. */
249
250void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME));
251
252/* Strings, numbers and flags taken from the termcap entry. */
253
254char *TS_ins_line; /* "al" */
255char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
256char *TS_bell; /* "bl" */
257char *TS_clr_to_bottom; /* "cd" */
258char *TS_clr_line; /* "ce", clear to end of line */
259char *TS_clr_frame; /* "cl" */
260char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
261char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
262 lines above scroll region, lines below it,
263 total lines again) */
264char *TS_del_char; /* "dc" */
265char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
266char *TS_del_line; /* "dl" */
267char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
268char *TS_delete_mode; /* "dm", enter character-delete mode */
269char *TS_end_delete_mode; /* "ed", leave character-delete mode */
270char *TS_end_insert_mode; /* "ei", leave character-insert mode */
271char *TS_ins_char; /* "ic" */
272char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
273char *TS_insert_mode; /* "im", enter character-insert mode */
274char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
275char *TS_end_keypad_mode; /* "ke" */
276char *TS_keypad_mode; /* "ks" */
277char *TS_pad_char; /* "pc", char to use as padding */
278char *TS_repeat; /* "rp" (2 params, # times to repeat
279 and character to be repeated) */
280char *TS_end_standout_mode; /* "se" */
281char *TS_fwd_scroll; /* "sf" */
282char *TS_standout_mode; /* "so" */
283char *TS_rev_scroll; /* "sr" */
284char *TS_end_termcap_modes; /* "te" */
285char *TS_termcap_modes; /* "ti" */
286char *TS_visible_bell; /* "vb" */
287char *TS_cursor_normal; /* "ve" */
288char *TS_cursor_visible; /* "vs" */
289char *TS_cursor_invisible; /* "vi" */
290char *TS_set_window; /* "wi" (4 params, start and end of window,
291 each as vpos and hpos) */
292
293/* Value of the "NC" (no_color_video) capability, or 0 if not
294 present. */
295
296static int TN_no_color_video;
297
298/* Meaning of bits in no_color_video. Each bit set means that the 137/* Meaning of bits in no_color_video. Each bit set means that the
299 corresponding attribute cannot be combined with colors. */ 138 corresponding attribute cannot be combined with colors. */
300 139
@@ -311,68 +150,6 @@ enum no_color_bit
311 NC_ALT_CHARSET = 1 << 8 150 NC_ALT_CHARSET = 1 << 8
312}; 151};
313 152
314/* "md" -- turn on bold (extra bright mode). */
315
316char *TS_enter_bold_mode;
317
318/* "mh" -- turn on half-bright mode. */
319
320char *TS_enter_dim_mode;
321
322/* "mb" -- enter blinking mode. */
323
324char *TS_enter_blink_mode;
325
326/* "mr" -- enter reverse video mode. */
327
328char *TS_enter_reverse_mode;
329
330/* "us"/"ue" -- start/end underlining. */
331
332char *TS_exit_underline_mode, *TS_enter_underline_mode;
333
334/* "as"/"ae" -- start/end alternate character set. Not really
335 supported, yet. */
336
337char *TS_enter_alt_charset_mode, *TS_exit_alt_charset_mode;
338
339/* "me" -- switch appearances off. */
340
341char *TS_exit_attribute_mode;
342
343/* "Co" -- number of colors. */
344
345int TN_max_colors;
346
347/* "pa" -- max. number of color pairs on screen. Not handled yet.
348 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
349
350int TN_max_pairs;
351
352/* "op" -- SVr4 set default pair to its original value. */
353
354char *TS_orig_pair;
355
356/* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
357 1 param, the color index. */
358
359char *TS_set_foreground, *TS_set_background;
360
361int TF_hazeltine; /* termcap hz flag. */
362int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
363int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
364int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
365 non-blank position. Must clear before writing _. */
366int TF_teleray; /* termcap xt flag: many weird consequences.
367 For t1061. */
368
369static int RPov; /* # chars to start a TS_repeat */
370
371static int delete_in_insert_mode; /* delete mode == insert mode */
372
373static int se_is_so; /* 1 if same string both enters and leaves
374 standout mode */
375
376/* internal state */ 153/* internal state */
377 154
378/* The largest frame width in any call to calculate_costs. */ 155/* The largest frame width in any call to calculate_costs. */
@@ -383,33 +160,14 @@ int max_frame_cols;
383 160
384int max_frame_lines; 161int max_frame_lines;
385 162
386static int costs_set; /* Nonzero if costs have been calculated. */ 163/* Non-zero if we have dropped our controlling tty and therefore
387 164 should not open a frame on stdout. */
388int insert_mode; /* Nonzero when in insert mode. */ 165static int no_controlling_tty;
389int standout_mode; /* Nonzero when in standout mode. */
390
391/* Size of window specified by higher levels.
392 This is the number of lines, from the top of frame downwards,
393 which can participate in insert-line/delete-line operations.
394
395 Effectively it excludes the bottom frame_lines - specified_window_size
396 lines from those operations. */
397
398int specified_window;
399
400/* Frame currently being redisplayed; 0 if not currently redisplaying.
401 (Direct output does not count). */
402
403FRAME_PTR updating_frame;
404 166
405/* Provided for lisp packages. */ 167/* Provided for lisp packages. */
406 168
407static int system_uses_terminfo; 169static int system_uses_terminfo;
408 170
409/* Flag used in tty_show/hide_cursor. */
410
411static int tty_cursor_hidden;
412
413char *tparam (); 171char *tparam ();
414 172
415extern char *tgetstr (); 173extern char *tgetstr ();
@@ -426,192 +184,174 @@ extern char *tgetstr ();
426#define FRAME_TERMCAP_P(_f_) 0 184#define FRAME_TERMCAP_P(_f_) 0
427#endif /* WINDOWSNT */ 185#endif /* WINDOWSNT */
428 186
429void
430ring_bell ()
431{
432 if (!NILP (Vring_bell_function))
433 {
434 Lisp_Object function;
435
436 /* Temporarily set the global variable to nil
437 so that if we get an error, it stays nil
438 and we don't call it over and over.
439 187
440 We don't specbind it, because that would carefully 188/* Ring the bell on a tty. */
441 restore the bad value if there's an error
442 and make the loop of errors happen anyway. */
443 189
444 function = Vring_bell_function; 190static void
445 Vring_bell_function = Qnil; 191tty_ring_bell (struct frame *f)
446 192{
447 call0 (function); 193 struct tty_display_info *tty = FRAME_TTY (f);
448 194
449 Vring_bell_function = function; 195 if (tty->output)
196 {
197 OUTPUT (tty, (tty->TS_visible_bell && visible_bell
198 ? tty->TS_visible_bell
199 : tty->TS_bell));
200 fflush (tty->output);
450 } 201 }
451 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame)))
452 (*ring_bell_hook) ();
453 else
454 OUTPUT (TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell);
455} 202}
456 203
204/* Set up termcap modes for Emacs. */
205
457void 206void
458set_terminal_modes () 207tty_set_terminal_modes (struct terminal *terminal)
459{ 208{
460 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 209 struct tty_display_info *tty = terminal->display_info.tty;
210
211 if (tty->output)
461 { 212 {
462 if (TS_termcap_modes) 213 if (tty->TS_termcap_modes)
463 OUTPUT (TS_termcap_modes); 214 OUTPUT (tty, tty->TS_termcap_modes);
464 else 215 else
465 { 216 {
466 /* Output enough newlines to scroll all the old screen contents 217 /* Output enough newlines to scroll all the old screen contents
467 off the screen, so it won't be overwritten and lost. */ 218 off the screen, so it won't be overwritten and lost. */
468 int i; 219 int i;
469 for (i = 0; i < FRAME_LINES (XFRAME (selected_frame)); i++) 220 current_tty = tty;
470 putchar ('\n'); 221 for (i = 0; i < FRAME_LINES (XFRAME (selected_frame)); i++)
471 } 222 cmputc ('\n');
472 223 }
473 OUTPUT_IF (visible_cursor ? TS_cursor_visible : TS_cursor_normal); 224
474 OUTPUT_IF (TS_keypad_mode); 225 OUTPUT_IF (tty, tty->TS_termcap_modes);
475 losecursor (); 226 OUTPUT_IF (tty, visible_cursor ? tty->TS_cursor_visible : tty->TS_cursor_normal);
227 OUTPUT_IF (tty, tty->TS_keypad_mode);
228 losecursor (tty);
229 fflush (tty->output);
476 } 230 }
477 else
478 (*set_terminal_modes_hook) ();
479} 231}
480 232
233/* Reset termcap modes before exiting Emacs. */
234
481void 235void
482reset_terminal_modes () 236tty_reset_terminal_modes (struct terminal *terminal)
483{ 237{
484 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 238 struct tty_display_info *tty = terminal->display_info.tty;
239
240 if (tty->output)
485 { 241 {
486 turn_off_highlight (); 242 tty_turn_off_highlight (tty);
487 turn_off_insert (); 243 tty_turn_off_insert (tty);
488 OUTPUT_IF (TS_end_keypad_mode); 244 OUTPUT_IF (tty, tty->TS_end_keypad_mode);
489 OUTPUT_IF (TS_cursor_normal); 245 OUTPUT_IF (tty, tty->TS_cursor_normal);
490 OUTPUT_IF (TS_end_termcap_modes); 246 OUTPUT_IF (tty, tty->TS_end_termcap_modes);
491 OUTPUT_IF (TS_orig_pair); 247 OUTPUT_IF (tty, tty->TS_orig_pair);
492 /* Output raw CR so kernel can track the cursor hpos. */ 248 /* Output raw CR so kernel can track the cursor hpos. */
249 current_tty = tty;
493 cmputc ('\r'); 250 cmputc ('\r');
251 fflush (tty->output);
494 } 252 }
495 else if (reset_terminal_modes_hook)
496 (*reset_terminal_modes_hook) ();
497} 253}
498 254
499void 255/* Flag the end of a display update on a termcap terminal. */
500update_begin (f)
501 struct frame *f;
502{
503 updating_frame = f;
504 if (!FRAME_TERMCAP_P (f))
505 update_begin_hook (f);
506}
507 256
508void 257static void
509update_end (f) 258tty_update_end (struct frame *f)
510 struct frame *f;
511{ 259{
512 if (FRAME_TERMCAP_P (f)) 260 struct tty_display_info *tty = FRAME_TTY (f);
513 {
514 if (!XWINDOW (selected_window)->cursor_off_p)
515 tty_show_cursor ();
516 turn_off_insert ();
517 background_highlight ();
518 }
519 else
520 update_end_hook (f);
521 261
522 updating_frame = NULL; 262 if (!XWINDOW (selected_window)->cursor_off_p)
263 tty_show_cursor (tty);
264 tty_turn_off_insert (tty);
265 tty_background_highlight (tty);
523} 266}
524 267
525void 268/* The implementation of set_terminal_window for termcap frames. */
526set_terminal_window (size) 269
527 int size; 270static void
271tty_set_terminal_window (struct frame *f, int size)
528{ 272{
529 if (FRAME_TERMCAP_P (updating_frame)) 273 struct tty_display_info *tty = FRAME_TTY (f);
530 { 274
531 specified_window = size ? size : FRAME_LINES (updating_frame); 275 tty->specified_window = size ? size : FRAME_LINES (f);
532 if (scroll_region_ok) 276 if (FRAME_SCROLL_REGION_OK (f))
533 set_scroll_region (0, specified_window); 277 tty_set_scroll_region (f, 0, tty->specified_window);
534 }
535 else
536 set_terminal_window_hook (size);
537} 278}
538 279
539void 280static void
540set_scroll_region (start, stop) 281tty_set_scroll_region (struct frame *f, int start, int stop)
541 int start, stop;
542{ 282{
543 char *buf; 283 char *buf;
544 struct frame *sf = XFRAME (selected_frame); 284 struct tty_display_info *tty = FRAME_TTY (f);
545 285
546 if (TS_set_scroll_region) 286 if (tty->TS_set_scroll_region)
547 buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1); 287 buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1);
548 else if (TS_set_scroll_region_1) 288 else if (tty->TS_set_scroll_region_1)
549 buf = tparam (TS_set_scroll_region_1, 0, 0, 289 buf = tparam (tty->TS_set_scroll_region_1, 0, 0,
550 FRAME_LINES (sf), start, 290 FRAME_LINES (f), start,
551 FRAME_LINES (sf) - stop, 291 FRAME_LINES (f) - stop,
552 FRAME_LINES (sf)); 292 FRAME_LINES (f));
553 else 293 else
554 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (sf)); 294 buf = tparam (tty->TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f));
555 295
556 OUTPUT (buf); 296 OUTPUT (tty, buf);
557 xfree (buf); 297 xfree (buf);
558 losecursor (); 298 losecursor (tty);
559} 299}
560 300
561 301
562static void 302static void
563turn_on_insert () 303tty_turn_on_insert (struct tty_display_info *tty)
564{ 304{
565 if (!insert_mode) 305 if (!tty->insert_mode)
566 OUTPUT (TS_insert_mode); 306 OUTPUT (tty, tty->TS_insert_mode);
567 insert_mode = 1; 307 tty->insert_mode = 1;
568} 308}
569 309
570void 310void
571turn_off_insert () 311tty_turn_off_insert (struct tty_display_info *tty)
572{ 312{
573 if (insert_mode) 313 if (tty->insert_mode)
574 OUTPUT (TS_end_insert_mode); 314 OUTPUT (tty, tty->TS_end_insert_mode);
575 insert_mode = 0; 315 tty->insert_mode = 0;
576} 316}
577 317
578/* Handle highlighting. */ 318/* Handle highlighting. */
579 319
580void 320void
581turn_off_highlight () 321tty_turn_off_highlight (struct tty_display_info *tty)
582{ 322{
583 if (standout_mode) 323 if (tty->standout_mode)
584 OUTPUT_IF (TS_end_standout_mode); 324 OUTPUT_IF (tty, tty->TS_end_standout_mode);
585 standout_mode = 0; 325 tty->standout_mode = 0;
586} 326}
587 327
588static void 328static void
589turn_on_highlight () 329tty_turn_on_highlight (struct tty_display_info *tty)
590{ 330{
591 if (!standout_mode) 331 if (!tty->standout_mode)
592 OUTPUT_IF (TS_standout_mode); 332 OUTPUT_IF (tty, tty->TS_standout_mode);
593 standout_mode = 1; 333 tty->standout_mode = 1;
594} 334}
595 335
596static void 336static void
597toggle_highlight () 337tty_toggle_highlight (struct tty_display_info *tty)
598{ 338{
599 if (standout_mode) 339 if (tty->standout_mode)
600 turn_off_highlight (); 340 tty_turn_off_highlight (tty);
601 else 341 else
602 turn_on_highlight (); 342 tty_turn_on_highlight (tty);
603} 343}
604 344
605 345
606/* Make cursor invisible. */ 346/* Make cursor invisible. */
607 347
608static void 348static void
609tty_hide_cursor () 349tty_hide_cursor (struct tty_display_info *tty)
610{ 350{
611 if (tty_cursor_hidden == 0) 351 if (tty->cursor_hidden == 0)
612 { 352 {
613 tty_cursor_hidden = 1; 353 tty->cursor_hidden = 1;
614 OUTPUT_IF (TS_cursor_invisible); 354 OUTPUT_IF (tty, tty->TS_cursor_invisible);
615 } 355 }
616} 356}
617 357
@@ -619,14 +359,14 @@ tty_hide_cursor ()
619/* Ensure that cursor is visible. */ 359/* Ensure that cursor is visible. */
620 360
621static void 361static void
622tty_show_cursor () 362tty_show_cursor (struct tty_display_info *tty)
623{ 363{
624 if (tty_cursor_hidden) 364 if (tty->cursor_hidden)
625 { 365 {
626 tty_cursor_hidden = 0; 366 tty->cursor_hidden = 0;
627 OUTPUT_IF (TS_cursor_normal); 367 OUTPUT_IF (tty, tty->TS_cursor_normal);
628 if (visible_cursor) 368 if (visible_cursor)
629 OUTPUT_IF (TS_cursor_visible); 369 OUTPUT_IF (tty, tty->TS_cursor_visible);
630 } 370 }
631} 371}
632 372
@@ -635,180 +375,151 @@ tty_show_cursor ()
635 empty space inside windows. What this is, 375 empty space inside windows. What this is,
636 depends on the user option inverse-video. */ 376 depends on the user option inverse-video. */
637 377
638void 378static void
639background_highlight () 379tty_background_highlight (struct tty_display_info *tty)
640{ 380{
641 if (inverse_video) 381 if (inverse_video)
642 turn_on_highlight (); 382 tty_turn_on_highlight (tty);
643 else 383 else
644 turn_off_highlight (); 384 tty_turn_off_highlight (tty);
645} 385}
646 386
647/* Set standout mode to the mode specified for the text to be output. */ 387/* Set standout mode to the mode specified for the text to be output. */
648 388
649static void 389static void
650highlight_if_desired () 390tty_highlight_if_desired (struct tty_display_info *tty)
651{ 391{
652 if (inverse_video) 392 if (inverse_video)
653 turn_on_highlight (); 393 tty_turn_on_highlight (tty);
654 else 394 else
655 turn_off_highlight (); 395 tty_turn_off_highlight (tty);
656} 396}
657 397
658 398
659/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are 399/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
660 frame-relative coordinates. */ 400 frame-relative coordinates. */
661 401
662void 402static void
663cursor_to (vpos, hpos) 403tty_cursor_to (struct frame *f, int vpos, int hpos)
664 int vpos, hpos;
665{ 404{
666 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 405 struct tty_display_info *tty = FRAME_TTY (f);
667
668 if (! FRAME_TERMCAP_P (f) && cursor_to_hook)
669 {
670 (*cursor_to_hook) (vpos, hpos);
671 return;
672 }
673 406
674 /* Detect the case where we are called from reset_sys_modes 407 /* Detect the case where we are called from reset_sys_modes
675 and the costs have never been calculated. Do nothing. */ 408 and the costs have never been calculated. Do nothing. */
676 if (! costs_set) 409 if (! tty->costs_set)
677 return; 410 return;
678 411
679 if (curY == vpos && curX == hpos) 412 if (curY (tty) == vpos
413 && curX (tty) == hpos)
680 return; 414 return;
681 if (!TF_standout_motion) 415 if (!tty->TF_standout_motion)
682 background_highlight (); 416 tty_background_highlight (tty);
683 if (!TF_insmode_motion) 417 if (!tty->TF_insmode_motion)
684 turn_off_insert (); 418 tty_turn_off_insert (tty);
685 cmgoto (vpos, hpos); 419 cmgoto (tty, vpos, hpos);
686} 420}
687 421
688/* Similar but don't take any account of the wasted characters. */ 422/* Similar but don't take any account of the wasted characters. */
689 423
690void 424static void
691raw_cursor_to (row, col) 425tty_raw_cursor_to (struct frame *f, int row, int col)
692 int row, col;
693{ 426{
694 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 427 struct tty_display_info *tty = FRAME_TTY (f);
695 if (! FRAME_TERMCAP_P (f)) 428
696 { 429 if (curY (tty) == row
697 (*raw_cursor_to_hook) (row, col); 430 && curX (tty) == col)
698 return;
699 }
700 if (curY == row && curX == col)
701 return; 431 return;
702 if (!TF_standout_motion) 432 if (!tty->TF_standout_motion)
703 background_highlight (); 433 tty_background_highlight (tty);
704 if (!TF_insmode_motion) 434 if (!tty->TF_insmode_motion)
705 turn_off_insert (); 435 tty_turn_off_insert (tty);
706 cmgoto (row, col); 436 cmgoto (tty, row, col);
707} 437}
708 438
709/* Erase operations */ 439/* Erase operations */
710 440
711/* clear from cursor to end of frame */ 441/* Clear from cursor to end of frame on a termcap device. */
712void 442
713clear_to_end () 443static void
444tty_clear_to_end (struct frame *f)
714{ 445{
715 register int i; 446 register int i;
447 struct tty_display_info *tty = FRAME_TTY (f);
716 448
717 if (clear_to_end_hook && ! FRAME_TERMCAP_P (updating_frame)) 449 if (tty->TS_clr_to_bottom)
718 {
719 (*clear_to_end_hook) ();
720 return;
721 }
722 if (TS_clr_to_bottom)
723 { 450 {
724 background_highlight (); 451 tty_background_highlight (tty);
725 OUTPUT (TS_clr_to_bottom); 452 OUTPUT (tty, tty->TS_clr_to_bottom);
726 } 453 }
727 else 454 else
728 { 455 {
729 for (i = curY; i < FRAME_LINES (XFRAME (selected_frame)); i++) 456 for (i = curY (tty); i < FRAME_LINES (f); i++)
730 { 457 {
731 cursor_to (i, 0); 458 cursor_to (f, i, 0);
732 clear_end_of_line (FRAME_COLS (XFRAME (selected_frame))); 459 clear_end_of_line (f, FRAME_COLS (f));
733 } 460 }
734 } 461 }
735} 462}
736 463
737/* Clear entire frame */ 464/* Clear an entire termcap frame. */
738 465
739void 466static void
740clear_frame () 467tty_clear_frame (struct frame *f)
741{ 468{
742 struct frame *sf = XFRAME (selected_frame); 469 struct tty_display_info *tty = FRAME_TTY (f);
743 470
744 if (clear_frame_hook 471 if (tty->TS_clr_frame)
745 && ! FRAME_TERMCAP_P ((updating_frame ? updating_frame : sf)))
746 {
747 (*clear_frame_hook) ();
748 return;
749 }
750 if (TS_clr_frame)
751 { 472 {
752 background_highlight (); 473 tty_background_highlight (tty);
753 OUTPUT (TS_clr_frame); 474 OUTPUT (tty, tty->TS_clr_frame);
754 cmat (0, 0); 475 cmat (tty, 0, 0);
755 } 476 }
756 else 477 else
757 { 478 {
758 cursor_to (0, 0); 479 cursor_to (f, 0, 0);
759 clear_to_end (); 480 clear_to_end (f);
760 } 481 }
761} 482}
762 483
763/* Clear from cursor to end of line. 484/* An implementation of clear_end_of_line for termcap frames.
764 Assume that the line is already clear starting at column first_unused_hpos.
765 485
766 Note that the cursor may be moved, on terminals lacking a `ce' string. */ 486 Note that the cursor may be moved, on terminals lacking a `ce' string. */
767 487
768void 488static void
769clear_end_of_line (first_unused_hpos) 489tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
770 int first_unused_hpos;
771{ 490{
772 register int i; 491 register int i;
773 492 struct tty_display_info *tty = FRAME_TTY (f);
774 if (clear_end_of_line_hook
775 && ! FRAME_TERMCAP_P ((updating_frame
776 ? updating_frame
777 : XFRAME (selected_frame))))
778 {
779 (*clear_end_of_line_hook) (first_unused_hpos);
780 return;
781 }
782 493
783 /* Detect the case where we are called from reset_sys_modes 494 /* Detect the case where we are called from reset_sys_modes
784 and the costs have never been calculated. Do nothing. */ 495 and the costs have never been calculated. Do nothing. */
785 if (! costs_set) 496 if (! tty->costs_set)
786 return; 497 return;
787 498
788 if (curX >= first_unused_hpos) 499 if (curX (tty) >= first_unused_hpos)
789 return; 500 return;
790 background_highlight (); 501 tty_background_highlight (tty);
791 if (TS_clr_line) 502 if (tty->TS_clr_line)
792 { 503 {
793 OUTPUT1 (TS_clr_line); 504 OUTPUT1 (tty, tty->TS_clr_line);
794 } 505 }
795 else 506 else
796 { /* have to do it the hard way */ 507 { /* have to do it the hard way */
797 struct frame *sf = XFRAME (selected_frame); 508 tty_turn_off_insert (tty);
798 turn_off_insert ();
799 509
800 /* Do not write in last row last col with Auto-wrap on. */ 510 /* Do not write in last row last col with Auto-wrap on. */
801 if (AutoWrap && curY == FRAME_LINES (sf) - 1 511 if (AutoWrap (tty)
802 && first_unused_hpos == FRAME_COLS (sf)) 512 && curY (tty) == FrameRows (tty) - 1
513 && first_unused_hpos == FrameCols (tty))
803 first_unused_hpos--; 514 first_unused_hpos--;
804 515
805 for (i = curX; i < first_unused_hpos; i++) 516 for (i = curX (tty); i < first_unused_hpos; i++)
806 { 517 {
807 if (termscript) 518 if (tty->termscript)
808 fputc (' ', termscript); 519 fputc (' ', tty->termscript);
809 putchar (' '); 520 fputc (' ', tty->output);
810 } 521 }
811 cmplus (first_unused_hpos - curX); 522 cmplus (tty, first_unused_hpos - curX (tty));
812 } 523 }
813} 524}
814 525
@@ -930,43 +641,37 @@ encode_terminal_code (src, src_len, coding)
930 return encode_terminal_buf + nbytes; 641 return encode_terminal_buf + nbytes;
931} 642}
932 643
933void 644
934write_glyphs (string, len) 645/* An implementation of write_glyphs for termcap frames. */
935 register struct glyph *string; 646
936 register int len; 647static void
648tty_write_glyphs (struct frame *f, struct glyph *string, int len)
937{ 649{
938 struct frame *sf = XFRAME (selected_frame);
939 struct frame *f = updating_frame ? updating_frame : sf;
940 unsigned char *conversion_buffer; 650 unsigned char *conversion_buffer;
941 struct coding_system *coding; 651 struct coding_system *coding;
942 652
943 if (write_glyphs_hook 653 struct tty_display_info *tty = FRAME_TTY (f);
944 && ! FRAME_TERMCAP_P (f))
945 {
946 (*write_glyphs_hook) (string, len);
947 return;
948 }
949 654
950 turn_off_insert (); 655 tty_turn_off_insert (tty);
951 tty_hide_cursor (); 656 tty_hide_cursor (tty);
952 657
953 /* Don't dare write in last column of bottom line, if Auto-Wrap, 658 /* Don't dare write in last column of bottom line, if Auto-Wrap,
954 since that would scroll the whole frame on some terminals. */ 659 since that would scroll the whole frame on some terminals. */
955 660
956 if (AutoWrap 661 if (AutoWrap (tty)
957 && curY + 1 == FRAME_LINES (sf) 662 && curY (tty) + 1 == FRAME_LINES (f)
958 && (curX + len) == FRAME_COLS (sf)) 663 && (curX (tty) + len) == FRAME_COLS (f))
959 len --; 664 len --;
960 if (len <= 0) 665 if (len <= 0)
961 return; 666 return;
962 667
963 cmplus (len); 668 cmplus (tty, len);
964 669
965 /* If terminal_coding does any conversion, use it, otherwise use 670 /* If terminal_coding does any conversion, use it, otherwise use
966 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 671 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
967 because it always return 1 if the member src_multibyte is 1. */ 672 because it always return 1 if the member src_multibyte is 1. */
968 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 673 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
969 ? &terminal_coding : &safe_terminal_coding); 674 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
970 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 675 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
971 the tail. */ 676 the tail. */
972 coding->mode &= ~CODING_MODE_LAST_BLOCK; 677 coding->mode &= ~CODING_MODE_LAST_BLOCK;
@@ -982,7 +687,7 @@ write_glyphs (string, len)
982 break; 687 break;
983 688
984 /* Turn appearance modes of the face of the run on. */ 689 /* Turn appearance modes of the face of the run on. */
985 highlight_if_desired (); 690 tty_highlight_if_desired (tty);
986 turn_on_face (f, face_id); 691 turn_on_face (f, face_id);
987 692
988 if (n == len) 693 if (n == len)
@@ -992,11 +697,11 @@ write_glyphs (string, len)
992 if (coding->produced > 0) 697 if (coding->produced > 0)
993 { 698 {
994 BLOCK_INPUT; 699 BLOCK_INPUT;
995 fwrite (conversion_buffer, 1, coding->produced, stdout); 700 fwrite (conversion_buffer, 1, coding->produced, tty->output);
996 if (ferror (stdout)) 701 if (ferror (tty->output))
997 clearerr (stdout); 702 clearerr (tty->output);
998 if (termscript) 703 if (tty->termscript)
999 fwrite (conversion_buffer, 1, coding->produced, termscript); 704 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
1000 UNBLOCK_INPUT; 705 UNBLOCK_INPUT;
1001 } 706 }
1002 len -= n; 707 len -= n;
@@ -1004,50 +709,37 @@ write_glyphs (string, len)
1004 709
1005 /* Turn appearance modes off. */ 710 /* Turn appearance modes off. */
1006 turn_off_face (f, face_id); 711 turn_off_face (f, face_id);
1007 turn_off_highlight (); 712 tty_turn_off_highlight (tty);
1008 } 713 }
1009 714
1010 cmcheckmagic (); 715 cmcheckmagic (tty);
1011} 716}
1012 717
1013/* If start is zero, insert blanks instead of a string at start */ 718/* An implementation of insert_glyphs for termcap frames. */
1014 719
1015void 720static void
1016insert_glyphs (start, len) 721tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
1017 register struct glyph *start;
1018 register int len;
1019{ 722{
1020 char *buf; 723 char *buf;
1021 struct glyph *glyph = NULL; 724 struct glyph *glyph = NULL;
1022 struct frame *f, *sf;
1023 unsigned char *conversion_buffer; 725 unsigned char *conversion_buffer;
1024 unsigned char space[1]; 726 unsigned char space[1];
1025 struct coding_system *coding; 727 struct coding_system *coding;
1026 728
1027 if (len <= 0) 729 struct tty_display_info *tty = FRAME_TTY (f);
1028 return;
1029
1030 if (insert_glyphs_hook)
1031 {
1032 (*insert_glyphs_hook) (start, len);
1033 return;
1034 }
1035
1036 sf = XFRAME (selected_frame);
1037 f = updating_frame ? updating_frame : sf;
1038 730
1039 if (TS_ins_multi_chars) 731 if (tty->TS_ins_multi_chars)
1040 { 732 {
1041 buf = tparam (TS_ins_multi_chars, 0, 0, len); 733 buf = tparam (tty->TS_ins_multi_chars, 0, 0, len);
1042 OUTPUT1 (buf); 734 OUTPUT1 (tty, buf);
1043 xfree (buf); 735 xfree (buf);
1044 if (start) 736 if (start)
1045 write_glyphs (start, len); 737 write_glyphs (f, start, len);
1046 return; 738 return;
1047 } 739 }
1048 740
1049 turn_on_insert (); 741 tty_turn_on_insert (tty);
1050 cmplus (len); 742 cmplus (tty, len);
1051 743
1052 if (! start) 744 if (! start)
1053 space[0] = SPACEGLYPH; 745 space[0] = SPACEGLYPH;
@@ -1055,15 +747,15 @@ insert_glyphs (start, len)
1055 /* If terminal_coding does any conversion, use it, otherwise use 747 /* If terminal_coding does any conversion, use it, otherwise use
1056 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 748 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
1057 because it always return 1 if the member src_multibyte is 1. */ 749 because it always return 1 if the member src_multibyte is 1. */
1058 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 750 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
1059 ? &terminal_coding : &safe_terminal_coding); 751 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
1060 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 752 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
1061 the tail. */ 753 the tail. */
1062 coding->mode &= ~CODING_MODE_LAST_BLOCK; 754 coding->mode &= ~CODING_MODE_LAST_BLOCK;
1063 755
1064 while (len-- > 0) 756 while (len-- > 0)
1065 { 757 {
1066 OUTPUT1_IF (TS_ins_char); 758 OUTPUT1_IF (tty, tty->TS_ins_char);
1067 if (!start) 759 if (!start)
1068 { 760 {
1069 conversion_buffer = space; 761 conversion_buffer = space;
@@ -1071,7 +763,7 @@ insert_glyphs (start, len)
1071 } 763 }
1072 else 764 else
1073 { 765 {
1074 highlight_if_desired (); 766 tty_highlight_if_desired (tty);
1075 turn_on_face (f, start->face_id); 767 turn_on_face (f, start->face_id);
1076 glyph = start; 768 glyph = start;
1077 ++start; 769 ++start;
@@ -1079,7 +771,7 @@ insert_glyphs (start, len)
1079 occupies more than one column. */ 771 occupies more than one column. */
1080 while (len && CHAR_GLYPH_PADDING_P (*start)) 772 while (len && CHAR_GLYPH_PADDING_P (*start))
1081 { 773 {
1082 OUTPUT1_IF (TS_ins_char); 774 OUTPUT1_IF (tty, tty->TS_ins_char);
1083 start++, len--; 775 start++, len--;
1084 } 776 }
1085 777
@@ -1087,89 +779,77 @@ insert_glyphs (start, len)
1087 /* This is the last glyph. */ 779 /* This is the last glyph. */
1088 coding->mode |= CODING_MODE_LAST_BLOCK; 780 coding->mode |= CODING_MODE_LAST_BLOCK;
1089 781
1090 conversion_buffer = encode_terminal_code (glyph, 1, coding); 782 conversion_buffer = encode_terminal_code (glyph, 1, coding);
1091 } 783 }
1092 784
1093 if (coding->produced > 0) 785 if (coding->produced > 0)
1094 { 786 {
1095 BLOCK_INPUT; 787 BLOCK_INPUT;
1096 fwrite (conversion_buffer, 1, coding->produced, stdout); 788 fwrite (conversion_buffer, 1, coding->produced, tty->output);
1097 if (ferror (stdout)) 789 if (ferror (tty->output))
1098 clearerr (stdout); 790 clearerr (tty->output);
1099 if (termscript) 791 if (tty->termscript)
1100 fwrite (conversion_buffer, 1, coding->produced, termscript); 792 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
1101 UNBLOCK_INPUT; 793 UNBLOCK_INPUT;
1102 } 794 }
1103 795
1104 OUTPUT1_IF (TS_pad_inserted_char); 796 OUTPUT1_IF (tty, tty->TS_pad_inserted_char);
1105 if (start) 797 if (start)
1106 { 798 {
1107 turn_off_face (f, glyph->face_id); 799 turn_off_face (f, glyph->face_id);
1108 turn_off_highlight (); 800 tty_turn_off_highlight (tty);
1109 } 801 }
1110 } 802 }
1111 803
1112 cmcheckmagic (); 804 cmcheckmagic (tty);
1113} 805}
1114 806
1115void 807/* An implementation of delete_glyphs for termcap frames. */
1116delete_glyphs (n) 808
1117 register int n; 809static void
810tty_delete_glyphs (struct frame *f, int n)
1118{ 811{
1119 char *buf; 812 char *buf;
1120 register int i; 813 register int i;
1121 814
1122 if (delete_glyphs_hook && ! FRAME_TERMCAP_P (updating_frame)) 815 struct tty_display_info *tty = FRAME_TTY (f);
1123 {
1124 (*delete_glyphs_hook) (n);
1125 return;
1126 }
1127 816
1128 if (delete_in_insert_mode) 817 if (tty->delete_in_insert_mode)
1129 { 818 {
1130 turn_on_insert (); 819 tty_turn_on_insert (tty);
1131 } 820 }
1132 else 821 else
1133 { 822 {
1134 turn_off_insert (); 823 tty_turn_off_insert (tty);
1135 OUTPUT_IF (TS_delete_mode); 824 OUTPUT_IF (tty, tty->TS_delete_mode);
1136 } 825 }
1137 826
1138 if (TS_del_multi_chars) 827 if (tty->TS_del_multi_chars)
1139 { 828 {
1140 buf = tparam (TS_del_multi_chars, 0, 0, n); 829 buf = tparam (tty->TS_del_multi_chars, 0, 0, n);
1141 OUTPUT1 (buf); 830 OUTPUT1 (tty, buf);
1142 xfree (buf); 831 xfree (buf);
1143 } 832 }
1144 else 833 else
1145 for (i = 0; i < n; i++) 834 for (i = 0; i < n; i++)
1146 OUTPUT1 (TS_del_char); 835 OUTPUT1 (tty, tty->TS_del_char);
1147 if (!delete_in_insert_mode) 836 if (!tty->delete_in_insert_mode)
1148 OUTPUT_IF (TS_end_delete_mode); 837 OUTPUT_IF (tty, tty->TS_end_delete_mode);
1149} 838}
1150 839
1151/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */ 840/* An implementation of ins_del_lines for termcap frames. */
1152 841
1153void 842static void
1154ins_del_lines (vpos, n) 843tty_ins_del_lines (struct frame *f, int vpos, int n)
1155 int vpos, n;
1156{ 844{
1157 char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines; 845 struct tty_display_info *tty = FRAME_TTY (f);
1158 char *single = n > 0 ? TS_ins_line : TS_del_line; 846 char *multi = n > 0 ? tty->TS_ins_multi_lines : tty->TS_del_multi_lines;
1159 char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll; 847 char *single = n > 0 ? tty->TS_ins_line : tty->TS_del_line;
1160 struct frame *sf; 848 char *scroll = n > 0 ? tty->TS_rev_scroll : tty->TS_fwd_scroll;
1161 849
1162 register int i = n > 0 ? n : -n; 850 register int i = n > 0 ? n : -n;
1163 register char *buf; 851 register char *buf;
1164 852
1165 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (updating_frame))
1166 {
1167 (*ins_del_lines_hook) (vpos, n);
1168 return;
1169 }
1170
1171 sf = XFRAME (selected_frame);
1172
1173 /* If the lines below the insertion are being pushed 853 /* If the lines below the insertion are being pushed
1174 into the end of the window, this is the same as clearing; 854 into the end of the window, this is the same as clearing;
1175 and we know the lines are already clear, since the matching 855 and we know the lines are already clear, since the matching
@@ -1177,45 +857,49 @@ ins_del_lines (vpos, n)
1177 /* If the lines below the deletion are blank lines coming 857 /* If the lines below the deletion are blank lines coming
1178 out of the end of the window, don't bother, 858 out of the end of the window, don't bother,
1179 as there will be a matching inslines later that will flush them. */ 859 as there will be a matching inslines later that will flush them. */
1180 if (scroll_region_ok && vpos + i >= specified_window) 860 if (FRAME_SCROLL_REGION_OK (f)
861 && vpos + i >= tty->specified_window)
1181 return; 862 return;
1182 if (!memory_below_frame && vpos + i >= FRAME_LINES (sf)) 863 if (!FRAME_MEMORY_BELOW_FRAME (f)
864 && vpos + i >= FRAME_LINES (f))
1183 return; 865 return;
1184 866
1185 if (multi) 867 if (multi)
1186 { 868 {
1187 raw_cursor_to (vpos, 0); 869 raw_cursor_to (f, vpos, 0);
1188 background_highlight (); 870 tty_background_highlight (tty);
1189 buf = tparam (multi, 0, 0, i); 871 buf = tparam (multi, 0, 0, i);
1190 OUTPUT (buf); 872 OUTPUT (tty, buf);
1191 xfree (buf); 873 xfree (buf);
1192 } 874 }
1193 else if (single) 875 else if (single)
1194 { 876 {
1195 raw_cursor_to (vpos, 0); 877 raw_cursor_to (f, vpos, 0);
1196 background_highlight (); 878 tty_background_highlight (tty);
1197 while (--i >= 0) 879 while (--i >= 0)
1198 OUTPUT (single); 880 OUTPUT (tty, single);
1199 if (TF_teleray) 881 if (tty->TF_teleray)
1200 curX = 0; 882 curX (tty) = 0;
1201 } 883 }
1202 else 884 else
1203 { 885 {
1204 set_scroll_region (vpos, specified_window); 886 tty_set_scroll_region (f, vpos, tty->specified_window);
1205 if (n < 0) 887 if (n < 0)
1206 raw_cursor_to (specified_window - 1, 0); 888 raw_cursor_to (f, tty->specified_window - 1, 0);
1207 else 889 else
1208 raw_cursor_to (vpos, 0); 890 raw_cursor_to (f, vpos, 0);
1209 background_highlight (); 891 tty_background_highlight (tty);
1210 while (--i >= 0) 892 while (--i >= 0)
1211 OUTPUTL (scroll, specified_window - vpos); 893 OUTPUTL (tty, scroll, tty->specified_window - vpos);
1212 set_scroll_region (0, specified_window); 894 tty_set_scroll_region (f, 0, tty->specified_window);
1213 } 895 }
1214 896
1215 if (!scroll_region_ok && memory_below_frame && n < 0) 897 if (!FRAME_SCROLL_REGION_OK (f)
898 && FRAME_MEMORY_BELOW_FRAME (f)
899 && n < 0)
1216 { 900 {
1217 cursor_to (FRAME_LINES (sf) + n, 0); 901 cursor_to (f, FRAME_LINES (f) + n, 0);
1218 clear_to_end (); 902 clear_to_end (f);
1219 } 903 }
1220} 904}
1221 905
@@ -1223,8 +907,7 @@ ins_del_lines (vpos, n)
1223 not counting any line-dependent padding. */ 907 not counting any line-dependent padding. */
1224 908
1225int 909int
1226string_cost (str) 910string_cost (char *str)
1227 char *str;
1228{ 911{
1229 cost = 0; 912 cost = 0;
1230 if (str) 913 if (str)
@@ -1236,8 +919,7 @@ string_cost (str)
1236 counting any line-dependent padding at one line. */ 919 counting any line-dependent padding at one line. */
1237 920
1238static int 921static int
1239string_cost_one_line (str) 922string_cost_one_line (char *str)
1240 char *str;
1241{ 923{
1242 cost = 0; 924 cost = 0;
1243 if (str) 925 if (str)
@@ -1249,8 +931,7 @@ string_cost_one_line (str)
1249 in tenths of characters. */ 931 in tenths of characters. */
1250 932
1251int 933int
1252per_line_cost (str) 934per_line_cost (char *str)
1253 register char *str;
1254{ 935{
1255 cost = 0; 936 cost = 0;
1256 if (str) 937 if (str)
@@ -1273,26 +954,26 @@ int *char_ins_del_vector;
1273 954
1274/* ARGSUSED */ 955/* ARGSUSED */
1275static void 956static void
1276calculate_ins_del_char_costs (frame) 957calculate_ins_del_char_costs (struct frame *f)
1277 FRAME_PTR frame;
1278{ 958{
959 struct tty_display_info *tty = FRAME_TTY (f);
1279 int ins_startup_cost, del_startup_cost; 960 int ins_startup_cost, del_startup_cost;
1280 int ins_cost_per_char, del_cost_per_char; 961 int ins_cost_per_char, del_cost_per_char;
1281 register int i; 962 register int i;
1282 register int *p; 963 register int *p;
1283 964
1284 if (TS_ins_multi_chars) 965 if (tty->TS_ins_multi_chars)
1285 { 966 {
1286 ins_cost_per_char = 0; 967 ins_cost_per_char = 0;
1287 ins_startup_cost = string_cost_one_line (TS_ins_multi_chars); 968 ins_startup_cost = string_cost_one_line (tty->TS_ins_multi_chars);
1288 } 969 }
1289 else if (TS_ins_char || TS_pad_inserted_char 970 else if (tty->TS_ins_char || tty->TS_pad_inserted_char
1290 || (TS_insert_mode && TS_end_insert_mode)) 971 || (tty->TS_insert_mode && tty->TS_end_insert_mode))
1291 { 972 {
1292 ins_startup_cost = (30 * (string_cost (TS_insert_mode) 973 ins_startup_cost = (30 * (string_cost (tty->TS_insert_mode)
1293 + string_cost (TS_end_insert_mode))) / 100; 974 + string_cost (tty->TS_end_insert_mode))) / 100;
1294 ins_cost_per_char = (string_cost_one_line (TS_ins_char) 975 ins_cost_per_char = (string_cost_one_line (tty->TS_ins_char)
1295 + string_cost_one_line (TS_pad_inserted_char)); 976 + string_cost_one_line (tty->TS_pad_inserted_char));
1296 } 977 }
1297 else 978 else
1298 { 979 {
@@ -1300,18 +981,18 @@ calculate_ins_del_char_costs (frame)
1300 ins_cost_per_char = 0; 981 ins_cost_per_char = 0;
1301 } 982 }
1302 983
1303 if (TS_del_multi_chars) 984 if (tty->TS_del_multi_chars)
1304 { 985 {
1305 del_cost_per_char = 0; 986 del_cost_per_char = 0;
1306 del_startup_cost = string_cost_one_line (TS_del_multi_chars); 987 del_startup_cost = string_cost_one_line (tty->TS_del_multi_chars);
1307 } 988 }
1308 else if (TS_del_char) 989 else if (tty->TS_del_char)
1309 { 990 {
1310 del_startup_cost = (string_cost (TS_delete_mode) 991 del_startup_cost = (string_cost (tty->TS_delete_mode)
1311 + string_cost (TS_end_delete_mode)); 992 + string_cost (tty->TS_end_delete_mode));
1312 if (delete_in_insert_mode) 993 if (tty->delete_in_insert_mode)
1313 del_startup_cost /= 2; 994 del_startup_cost /= 2;
1314 del_cost_per_char = string_cost_one_line (TS_del_char); 995 del_cost_per_char = string_cost_one_line (tty->TS_del_char);
1315 } 996 }
1316 else 997 else
1317 { 998 {
@@ -1320,75 +1001,80 @@ calculate_ins_del_char_costs (frame)
1320 } 1001 }
1321 1002
1322 /* Delete costs are at negative offsets */ 1003 /* Delete costs are at negative offsets */
1323 p = &char_ins_del_cost (frame)[0]; 1004 p = &char_ins_del_cost (f)[0];
1324 for (i = FRAME_COLS (frame); --i >= 0;) 1005 for (i = FRAME_COLS (f); --i >= 0;)
1325 *--p = (del_startup_cost += del_cost_per_char); 1006 *--p = (del_startup_cost += del_cost_per_char);
1326 1007
1327 /* Doing nothing is free */ 1008 /* Doing nothing is free */
1328 p = &char_ins_del_cost (frame)[0]; 1009 p = &char_ins_del_cost (f)[0];
1329 *p++ = 0; 1010 *p++ = 0;
1330 1011
1331 /* Insert costs are at positive offsets */ 1012 /* Insert costs are at positive offsets */
1332 for (i = FRAME_COLS (frame); --i >= 0;) 1013 for (i = FRAME_COLS (f); --i >= 0;)
1333 *p++ = (ins_startup_cost += ins_cost_per_char); 1014 *p++ = (ins_startup_cost += ins_cost_per_char);
1334} 1015}
1335 1016
1336void 1017void
1337calculate_costs (frame) 1018calculate_costs (struct frame *frame)
1338 FRAME_PTR frame;
1339{ 1019{
1340 register char *f = (TS_set_scroll_region
1341 ? TS_set_scroll_region
1342 : TS_set_scroll_region_1);
1343
1344 FRAME_COST_BAUD_RATE (frame) = baud_rate; 1020 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1345 1021
1346 scroll_region_cost = string_cost (f); 1022 if (FRAME_TERMCAP_P (frame))
1023 {
1024 struct tty_display_info *tty = FRAME_TTY (frame);
1025 register char *f = (tty->TS_set_scroll_region
1026 ? tty->TS_set_scroll_region
1027 : tty->TS_set_scroll_region_1);
1347 1028
1348 /* These variables are only used for terminal stuff. They are allocated 1029 FRAME_SCROLL_REGION_COST (frame) = string_cost (f);
1349 once for the terminal frame of X-windows emacs, but not used afterwards.
1350 1030
1351 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because 1031 tty->costs_set = 1;
1352 X turns off char_ins_del_ok. */
1353 1032
1354 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); 1033 /* These variables are only used for terminal stuff. They are
1355 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); 1034 allocated once for the terminal frame of X-windows emacs, but not
1035 used afterwards.
1356 1036
1357 costs_set = 1; 1037 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1038 X turns off char_ins_del_ok. */
1358 1039
1359 if (char_ins_del_vector != 0) 1040 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1360 char_ins_del_vector 1041 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1361 = (int *) xrealloc (char_ins_del_vector,
1362 (sizeof (int)
1363 + 2 * max_frame_cols * sizeof (int)));
1364 else
1365 char_ins_del_vector
1366 = (int *) xmalloc (sizeof (int)
1367 + 2 * max_frame_cols * sizeof (int));
1368
1369 bzero (char_ins_del_vector, (sizeof (int)
1370 + 2 * max_frame_cols * sizeof (int)));
1371
1372 if (f && (!TS_ins_line && !TS_del_line))
1373 do_line_insertion_deletion_costs (frame,
1374 TS_rev_scroll, TS_ins_multi_lines,
1375 TS_fwd_scroll, TS_del_multi_lines,
1376 f, f, 1);
1377 else
1378 do_line_insertion_deletion_costs (frame,
1379 TS_ins_line, TS_ins_multi_lines,
1380 TS_del_line, TS_del_multi_lines,
1381 0, 0, 1);
1382 1042
1383 calculate_ins_del_char_costs (frame); 1043 if (char_ins_del_vector != 0)
1044 char_ins_del_vector
1045 = (int *) xrealloc (char_ins_del_vector,
1046 (sizeof (int)
1047 + 2 * max_frame_cols * sizeof (int)));
1048 else
1049 char_ins_del_vector
1050 = (int *) xmalloc (sizeof (int)
1051 + 2 * max_frame_cols * sizeof (int));
1052
1053 bzero (char_ins_del_vector, (sizeof (int)
1054 + 2 * max_frame_cols * sizeof (int)));
1384 1055
1385 /* Don't use TS_repeat if its padding is worse than sending the chars */
1386 if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000)
1387 RPov = string_cost (TS_repeat);
1388 else
1389 RPov = FRAME_COLS (frame) * 2;
1390 1056
1391 cmcostinit (); /* set up cursor motion costs */ 1057 if (f && (!tty->TS_ins_line && !tty->TS_del_line))
1058 do_line_insertion_deletion_costs (frame,
1059 tty->TS_rev_scroll, tty->TS_ins_multi_lines,
1060 tty->TS_fwd_scroll, tty->TS_del_multi_lines,
1061 f, f, 1);
1062 else
1063 do_line_insertion_deletion_costs (frame,
1064 tty->TS_ins_line, tty->TS_ins_multi_lines,
1065 tty->TS_del_line, tty->TS_del_multi_lines,
1066 0, 0, 1);
1067
1068 calculate_ins_del_char_costs (frame);
1069
1070 /* Don't use TS_repeat if its padding is worse than sending the chars */
1071 if (tty->TS_repeat && per_line_cost (tty->TS_repeat) * baud_rate < 9000)
1072 tty->RPov = string_cost (tty->TS_repeat);
1073 else
1074 tty->RPov = FRAME_COLS (frame) * 2;
1075
1076 cmcostinit (FRAME_TTY (frame)); /* set up cursor motion costs */
1077 }
1392} 1078}
1393 1079
1394struct fkey_table { 1080struct fkey_table {
@@ -1498,16 +1184,18 @@ static struct fkey_table keys[] =
1498 {"!3", "S-undo"} /*shifted undo key*/ 1184 {"!3", "S-undo"} /*shifted undo key*/
1499 }; 1185 };
1500 1186
1501static char **term_get_fkeys_arg; 1187static char **term_get_fkeys_address;
1188static KBOARD *term_get_fkeys_kboard;
1502static Lisp_Object term_get_fkeys_1 (); 1189static Lisp_Object term_get_fkeys_1 ();
1503 1190
1504/* Find the escape codes sent by the function keys for Vfunction_key_map. 1191/* Find the escape codes sent by the function keys for Vfunction_key_map.
1505 This function scans the termcap function key sequence entries, and 1192 This function scans the termcap function key sequence entries, and
1506 adds entries to Vfunction_key_map for each function key it finds. */ 1193 adds entries to Vfunction_key_map for each function key it finds. */
1507 1194
1508void 1195static void
1509term_get_fkeys (address) 1196term_get_fkeys (address, kboard)
1510 char **address; 1197 char **address;
1198 KBOARD *kboard;
1511{ 1199{
1512 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp 1200 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1513 errors during the call. The only errors should be from Fdefine_key 1201 errors during the call. The only errors should be from Fdefine_key
@@ -1518,7 +1206,8 @@ term_get_fkeys (address)
1518 refusing to run at all on such a terminal. */ 1206 refusing to run at all on such a terminal. */
1519 1207
1520 extern Lisp_Object Fidentity (); 1208 extern Lisp_Object Fidentity ();
1521 term_get_fkeys_arg = address; 1209 term_get_fkeys_address = address;
1210 term_get_fkeys_kboard = kboard;
1522 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity); 1211 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity);
1523} 1212}
1524 1213
@@ -1527,17 +1216,18 @@ term_get_fkeys_1 ()
1527{ 1216{
1528 int i; 1217 int i;
1529 1218
1530 char **address = term_get_fkeys_arg; 1219 char **address = term_get_fkeys_address;
1531 1220 KBOARD *kboard = term_get_fkeys_kboard;
1221
1532 /* This can happen if CANNOT_DUMP or with strange options. */ 1222 /* This can happen if CANNOT_DUMP or with strange options. */
1533 if (!initialized) 1223 if (!initialized)
1534 Vfunction_key_map = Fmake_sparse_keymap (Qnil); 1224 kboard->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
1535 1225
1536 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++) 1226 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
1537 { 1227 {
1538 char *sequence = tgetstr (keys[i].cap, address); 1228 char *sequence = tgetstr (keys[i].cap, address);
1539 if (sequence) 1229 if (sequence)
1540 Fdefine_key (Vfunction_key_map, build_string (sequence), 1230 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence),
1541 Fmake_vector (make_number (1), 1231 Fmake_vector (make_number (1),
1542 intern (keys[i].name))); 1232 intern (keys[i].name)));
1543 } 1233 }
@@ -1557,13 +1247,13 @@ term_get_fkeys_1 ()
1557 if (k0) 1247 if (k0)
1558 /* Define f0 first, so that f10 takes precedence in case the 1248 /* Define f0 first, so that f10 takes precedence in case the
1559 key sequences happens to be the same. */ 1249 key sequences happens to be the same. */
1560 Fdefine_key (Vfunction_key_map, build_string (k0), 1250 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
1561 Fmake_vector (make_number (1), intern ("f0"))); 1251 Fmake_vector (make_number (1), intern ("f0")));
1562 Fdefine_key (Vfunction_key_map, build_string (k_semi), 1252 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k_semi),
1563 Fmake_vector (make_number (1), intern ("f10"))); 1253 Fmake_vector (make_number (1), intern ("f10")));
1564 } 1254 }
1565 else if (k0) 1255 else if (k0)
1566 Fdefine_key (Vfunction_key_map, build_string (k0), 1256 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
1567 Fmake_vector (make_number (1), intern (k0_name))); 1257 Fmake_vector (make_number (1), intern (k0_name)));
1568 } 1258 }
1569 1259
@@ -1586,7 +1276,7 @@ term_get_fkeys_1 ()
1586 if (sequence) 1276 if (sequence)
1587 { 1277 {
1588 sprintf (fkey, "f%d", i); 1278 sprintf (fkey, "f%d", i);
1589 Fdefine_key (Vfunction_key_map, build_string (sequence), 1279 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence),
1590 Fmake_vector (make_number (1), 1280 Fmake_vector (make_number (1),
1591 intern (fkey))); 1281 intern (fkey)));
1592 } 1282 }
@@ -1602,10 +1292,10 @@ term_get_fkeys_1 ()
1602 if (!tgetstr (cap1, address)) \ 1292 if (!tgetstr (cap1, address)) \
1603 { \ 1293 { \
1604 char *sequence = tgetstr (cap2, address); \ 1294 char *sequence = tgetstr (cap2, address); \
1605 if (sequence) \ 1295 if (sequence) \
1606 Fdefine_key (Vfunction_key_map, build_string (sequence), \ 1296 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), \
1607 Fmake_vector (make_number (1), \ 1297 Fmake_vector (make_number (1), \
1608 intern (sym))); \ 1298 intern (sym))); \
1609 } 1299 }
1610 1300
1611 /* if there's no key_next keycap, map key_npage to `next' keysym */ 1301 /* if there's no key_next keycap, map key_npage to `next' keysym */
@@ -1961,10 +1651,10 @@ produce_special_glyphs (it, what)
1961 from them. Some display attributes may not be used together with 1651 from them. Some display attributes may not be used together with
1962 color; the termcap capability `NC' specifies which ones. */ 1652 color; the termcap capability `NC' specifies which ones. */
1963 1653
1964#define MAY_USE_WITH_COLORS_P(ATTR) \ 1654#define MAY_USE_WITH_COLORS_P(tty, ATTR) \
1965 (TN_max_colors > 0 \ 1655 (tty->TN_max_colors > 0 \
1966 ? (TN_no_color_video & (ATTR)) == 0 \ 1656 ? (tty->TN_no_color_video & (ATTR)) == 0 \
1967 : 1) 1657 : 1)
1968 1658
1969/* Turn appearances of face FACE_ID on tty frame F on. 1659/* Turn appearances of face FACE_ID on tty frame F on.
1970 FACE_ID is a realized face ID number, in the face cache. */ 1660 FACE_ID is a realized face ID number, in the face cache. */
@@ -1977,12 +1667,13 @@ turn_on_face (f, face_id)
1977 struct face *face = FACE_FROM_ID (f, face_id); 1667 struct face *face = FACE_FROM_ID (f, face_id);
1978 long fg = face->foreground; 1668 long fg = face->foreground;
1979 long bg = face->background; 1669 long bg = face->background;
1670 struct tty_display_info *tty = FRAME_TTY (f);
1980 1671
1981 /* Do this first because TS_end_standout_mode may be the same 1672 /* Do this first because TS_end_standout_mode may be the same
1982 as TS_exit_attribute_mode, which turns all appearances off. */ 1673 as TS_exit_attribute_mode, which turns all appearances off. */
1983 if (MAY_USE_WITH_COLORS_P (NC_REVERSE)) 1674 if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE))
1984 { 1675 {
1985 if (TN_max_colors > 0) 1676 if (tty->TN_max_colors > 0)
1986 { 1677 {
1987 if (fg >= 0 && bg >= 0) 1678 if (fg >= 0 && bg >= 0)
1988 { 1679 {
@@ -1996,13 +1687,13 @@ turn_on_face (f, face_id)
1996 { 1687 {
1997 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1688 if (fg == FACE_TTY_DEFAULT_FG_COLOR
1998 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1689 || bg == FACE_TTY_DEFAULT_BG_COLOR)
1999 toggle_highlight (); 1690 tty_toggle_highlight (tty);
2000 } 1691 }
2001 else 1692 else
2002 { 1693 {
2003 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1694 if (fg == FACE_TTY_DEFAULT_BG_COLOR
2004 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1695 || bg == FACE_TTY_DEFAULT_FG_COLOR)
2005 toggle_highlight (); 1696 tty_toggle_highlight (tty);
2006 } 1697 }
2007 } 1698 }
2008 else 1699 else
@@ -2013,55 +1704,55 @@ turn_on_face (f, face_id)
2013 { 1704 {
2014 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1705 if (fg == FACE_TTY_DEFAULT_FG_COLOR
2015 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1706 || bg == FACE_TTY_DEFAULT_BG_COLOR)
2016 toggle_highlight (); 1707 tty_toggle_highlight (tty);
2017 } 1708 }
2018 else 1709 else
2019 { 1710 {
2020 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1711 if (fg == FACE_TTY_DEFAULT_BG_COLOR
2021 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1712 || bg == FACE_TTY_DEFAULT_FG_COLOR)
2022 toggle_highlight (); 1713 tty_toggle_highlight (tty);
2023 } 1714 }
2024 } 1715 }
2025 } 1716 }
2026 1717
2027 if (face->tty_bold_p) 1718 if (face->tty_bold_p)
2028 { 1719 {
2029 if (MAY_USE_WITH_COLORS_P (NC_BOLD)) 1720 if (MAY_USE_WITH_COLORS_P (tty, NC_BOLD))
2030 OUTPUT1_IF (TS_enter_bold_mode); 1721 OUTPUT1_IF (tty, tty->TS_enter_bold_mode);
2031 } 1722 }
2032 else if (face->tty_dim_p) 1723 else if (face->tty_dim_p)
2033 if (MAY_USE_WITH_COLORS_P (NC_DIM)) 1724 if (MAY_USE_WITH_COLORS_P (tty, NC_DIM))
2034 OUTPUT1_IF (TS_enter_dim_mode); 1725 OUTPUT1_IF (tty, tty->TS_enter_dim_mode);
2035 1726
2036 /* Alternate charset and blinking not yet used. */ 1727 /* Alternate charset and blinking not yet used. */
2037 if (face->tty_alt_charset_p 1728 if (face->tty_alt_charset_p
2038 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET)) 1729 && MAY_USE_WITH_COLORS_P (tty, NC_ALT_CHARSET))
2039 OUTPUT1_IF (TS_enter_alt_charset_mode); 1730 OUTPUT1_IF (tty, tty->TS_enter_alt_charset_mode);
2040 1731
2041 if (face->tty_blinking_p 1732 if (face->tty_blinking_p
2042 && MAY_USE_WITH_COLORS_P (NC_BLINK)) 1733 && MAY_USE_WITH_COLORS_P (tty, NC_BLINK))
2043 OUTPUT1_IF (TS_enter_blink_mode); 1734 OUTPUT1_IF (tty, tty->TS_enter_blink_mode);
2044 1735
2045 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE)) 1736 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (tty, NC_UNDERLINE))
2046 OUTPUT1_IF (TS_enter_underline_mode); 1737 OUTPUT1_IF (tty, tty->TS_enter_underline_mode);
2047 1738
2048 if (TN_max_colors > 0) 1739 if (tty->TN_max_colors > 0)
2049 { 1740 {
2050 char *ts, *p; 1741 char *ts, *p;
2051 1742
2052 ts = standout_mode ? TS_set_background : TS_set_foreground; 1743 ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground;
2053 if (fg >= 0 && ts) 1744 if (fg >= 0 && ts)
2054 { 1745 {
2055 p = tparam (ts, NULL, 0, (int) fg); 1746 p = tparam (ts, NULL, 0, (int) fg);
2056 OUTPUT (p); 1747 OUTPUT (tty, p);
2057 xfree (p); 1748 xfree (p);
2058 } 1749 }
2059 1750
2060 ts = standout_mode ? TS_set_foreground : TS_set_background; 1751 ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background;
2061 if (bg >= 0 && ts) 1752 if (bg >= 0 && ts)
2062 { 1753 {
2063 p = tparam (ts, NULL, 0, (int) bg); 1754 p = tparam (ts, NULL, 0, (int) bg);
2064 OUTPUT (p); 1755 OUTPUT (tty, p);
2065 xfree (p); 1756 xfree (p);
2066 } 1757 }
2067 } 1758 }
@@ -2076,10 +1767,11 @@ turn_off_face (f, face_id)
2076 int face_id; 1767 int face_id;
2077{ 1768{
2078 struct face *face = FACE_FROM_ID (f, face_id); 1769 struct face *face = FACE_FROM_ID (f, face_id);
1770 struct tty_display_info *tty = FRAME_TTY (f);
2079 1771
2080 xassert (face != NULL); 1772 xassert (face != NULL);
2081 1773
2082 if (TS_exit_attribute_mode) 1774 if (tty->TS_exit_attribute_mode)
2083 { 1775 {
2084 /* Capability "me" will turn off appearance modes double-bright, 1776 /* Capability "me" will turn off appearance modes double-bright,
2085 half-bright, reverse-video, standout, underline. It may or 1777 half-bright, reverse-video, standout, underline. It may or
@@ -2091,32 +1783,32 @@ turn_off_face (f, face_id)
2091 || face->tty_blinking_p 1783 || face->tty_blinking_p
2092 || face->tty_underline_p) 1784 || face->tty_underline_p)
2093 { 1785 {
2094 OUTPUT1_IF (TS_exit_attribute_mode); 1786 OUTPUT1_IF (tty, tty->TS_exit_attribute_mode);
2095 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0) 1787 if (strcmp (tty->TS_exit_attribute_mode, tty->TS_end_standout_mode) == 0)
2096 standout_mode = 0; 1788 tty->standout_mode = 0;
2097 } 1789 }
2098 1790
2099 if (face->tty_alt_charset_p) 1791 if (face->tty_alt_charset_p)
2100 OUTPUT_IF (TS_exit_alt_charset_mode); 1792 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
2101 } 1793 }
2102 else 1794 else
2103 { 1795 {
2104 /* If we don't have "me" we can only have those appearances 1796 /* If we don't have "me" we can only have those appearances
2105 that have exit sequences defined. */ 1797 that have exit sequences defined. */
2106 if (face->tty_alt_charset_p) 1798 if (face->tty_alt_charset_p)
2107 OUTPUT_IF (TS_exit_alt_charset_mode); 1799 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
2108 1800
2109 if (face->tty_underline_p) 1801 if (face->tty_underline_p)
2110 OUTPUT_IF (TS_exit_underline_mode); 1802 OUTPUT_IF (tty, tty->TS_exit_underline_mode);
2111 } 1803 }
2112 1804
2113 /* Switch back to default colors. */ 1805 /* Switch back to default colors. */
2114 if (TN_max_colors > 0 1806 if (tty->TN_max_colors > 0
2115 && ((face->foreground != FACE_TTY_DEFAULT_COLOR 1807 && ((face->foreground != FACE_TTY_DEFAULT_COLOR
2116 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR) 1808 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
2117 || (face->background != FACE_TTY_DEFAULT_COLOR 1809 || (face->background != FACE_TTY_DEFAULT_COLOR
2118 && face->background != FACE_TTY_DEFAULT_BG_COLOR))) 1810 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
2119 OUTPUT1_IF (TS_orig_pair); 1811 OUTPUT1_IF (tty, tty->TS_orig_pair);
2120} 1812}
2121 1813
2122 1814
@@ -2125,46 +1817,61 @@ turn_off_face (f, face_id)
2125 colors FG and BG. */ 1817 colors FG and BG. */
2126 1818
2127int 1819int
2128tty_capable_p (f, caps, fg, bg) 1820tty_capable_p (tty, caps, fg, bg)
2129 struct frame *f; 1821 struct tty_display_info *tty;
2130 unsigned caps; 1822 unsigned caps;
2131 unsigned long fg, bg; 1823 unsigned long fg, bg;
2132{ 1824{
2133#define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \ 1825#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2134 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \ 1826 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2135 return 0; 1827 return 0;
2136 1828
2137 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE); 1829 TTY_CAPABLE_P_TRY (tty, TTY_CAP_INVERSE, tty->TS_standout_mode, NC_REVERSE);
2138 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE); 1830 TTY_CAPABLE_P_TRY (tty, TTY_CAP_UNDERLINE, tty->TS_enter_underline_mode, NC_UNDERLINE);
2139 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD); 1831 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BOLD, tty->TS_enter_bold_mode, NC_BOLD);
2140 TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM); 1832 TTY_CAPABLE_P_TRY (tty, TTY_CAP_DIM, tty->TS_enter_dim_mode, NC_DIM);
2141 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK); 1833 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BLINK, tty->TS_enter_blink_mode, NC_BLINK);
2142 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET); 1834 TTY_CAPABLE_P_TRY (tty, TTY_CAP_ALT_CHARSET, tty->TS_enter_alt_charset_mode, NC_ALT_CHARSET);
2143 1835
2144 /* We can do it! */ 1836 /* We can do it! */
2145 return 1; 1837 return 1;
2146} 1838}
2147 1839
2148
2149/* Return non-zero if the terminal is capable to display colors. */ 1840/* Return non-zero if the terminal is capable to display colors. */
2150 1841
2151DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p, 1842DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2152 0, 1, 0, 1843 0, 1, 0,
2153 doc: /* Return non-nil if TTY can display colors on DISPLAY. */) 1844 doc: /* Return non-nil if the tty device TERMINAL can display colors.
2154 (display) 1845
2155 Lisp_Object display; 1846TERMINAL can be a terminal id, a frame or nil (meaning the selected
1847frame's terminal). This function always returns nil if TERMINAL
1848is not on a tty device. */)
1849 (terminal)
1850 Lisp_Object terminal;
2156{ 1851{
2157 return TN_max_colors > 0 ? Qt : Qnil; 1852 struct terminal *t = get_tty_terminal (terminal, 0);
1853 if (!t)
1854 return Qnil;
1855 else
1856 return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
2158} 1857}
2159 1858
2160/* Return the number of supported colors. */ 1859/* Return the number of supported colors. */
2161DEFUN ("tty-display-color-cells", Ftty_display_color_cells, 1860DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2162 Stty_display_color_cells, 0, 1, 0, 1861 Stty_display_color_cells, 0, 1, 0,
2163 doc: /* Return the number of colors supported by TTY on DISPLAY. */) 1862 doc: /* Return the number of colors supported by the tty device TERMINAL.
2164 (display) 1863
2165 Lisp_Object display; 1864TERMINAL can be a terminal id, a frame or nil (meaning the selected
1865frame's terminal). This function always returns 0 if TERMINAL
1866is not on a tty device. */)
1867 (terminal)
1868 Lisp_Object terminal;
2166{ 1869{
2167 return make_number (TN_max_colors); 1870 struct terminal *t = get_tty_terminal (terminal, 0);
1871 if (!t)
1872 return make_number (0);
1873 else
1874 return make_number (t->display_info.tty->TN_max_colors);
2168} 1875}
2169 1876
2170#ifndef WINDOWSNT 1877#ifndef WINDOWSNT
@@ -2172,8 +1879,7 @@ DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2172/* Save or restore the default color-related capabilities of this 1879/* Save or restore the default color-related capabilities of this
2173 terminal. */ 1880 terminal. */
2174static void 1881static void
2175tty_default_color_capabilities (save) 1882tty_default_color_capabilities (struct tty_display_info *tty, int save)
2176 int save;
2177{ 1883{
2178 static char 1884 static char
2179 *default_orig_pair, *default_set_foreground, *default_set_background; 1885 *default_orig_pair, *default_set_foreground, *default_set_background;
@@ -2183,40 +1889,39 @@ tty_default_color_capabilities (save)
2183 { 1889 {
2184 if (default_orig_pair) 1890 if (default_orig_pair)
2185 xfree (default_orig_pair); 1891 xfree (default_orig_pair);
2186 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL; 1892 default_orig_pair = tty->TS_orig_pair ? xstrdup (tty->TS_orig_pair) : NULL;
2187 1893
2188 if (default_set_foreground) 1894 if (default_set_foreground)
2189 xfree (default_set_foreground); 1895 xfree (default_set_foreground);
2190 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground) 1896 default_set_foreground = tty->TS_set_foreground ? xstrdup (tty->TS_set_foreground)
2191 : NULL; 1897 : NULL;
2192 1898
2193 if (default_set_background) 1899 if (default_set_background)
2194 xfree (default_set_background); 1900 xfree (default_set_background);
2195 default_set_background = TS_set_background ? xstrdup (TS_set_background) 1901 default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background)
2196 : NULL; 1902 : NULL;
2197 1903
2198 default_max_colors = TN_max_colors; 1904 default_max_colors = tty->TN_max_colors;
2199 default_max_pairs = TN_max_pairs; 1905 default_max_pairs = tty->TN_max_pairs;
2200 default_no_color_video = TN_no_color_video; 1906 default_no_color_video = tty->TN_no_color_video;
2201 } 1907 }
2202 else 1908 else
2203 { 1909 {
2204 TS_orig_pair = default_orig_pair; 1910 tty->TS_orig_pair = default_orig_pair;
2205 TS_set_foreground = default_set_foreground; 1911 tty->TS_set_foreground = default_set_foreground;
2206 TS_set_background = default_set_background; 1912 tty->TS_set_background = default_set_background;
2207 TN_max_colors = default_max_colors; 1913 tty->TN_max_colors = default_max_colors;
2208 TN_max_pairs = default_max_pairs; 1914 tty->TN_max_pairs = default_max_pairs;
2209 TN_no_color_video = default_no_color_video; 1915 tty->TN_no_color_video = default_no_color_video;
2210 } 1916 }
2211} 1917}
2212 1918
2213/* Setup one of the standard tty color schemes according to MODE. 1919/* Setup one of the standard tty color schemes according to MODE.
2214 MODE's value is generally the number of colors which we want to 1920 MODE's value is generally the number of colors which we want to
2215 support; zero means set up for the default capabilities, the ones 1921 support; zero means set up for the default capabilities, the ones
2216 we saw at term_init time; -1 means turn off color support. */ 1922 we saw at init_tty time; -1 means turn off color support. */
2217void 1923static void
2218tty_setup_colors (mode) 1924tty_setup_colors (struct tty_display_info *tty, int mode)
2219 int mode;
2220{ 1925{
2221 /* Canonicalize all negative values of MODE. */ 1926 /* Canonicalize all negative values of MODE. */
2222 if (mode < -1) 1927 if (mode < -1)
@@ -2225,27 +1930,27 @@ tty_setup_colors (mode)
2225 switch (mode) 1930 switch (mode)
2226 { 1931 {
2227 case -1: /* no colors at all */ 1932 case -1: /* no colors at all */
2228 TN_max_colors = 0; 1933 tty->TN_max_colors = 0;
2229 TN_max_pairs = 0; 1934 tty->TN_max_pairs = 0;
2230 TN_no_color_video = 0; 1935 tty->TN_no_color_video = 0;
2231 TS_set_foreground = TS_set_background = TS_orig_pair = NULL; 1936 tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL;
2232 break; 1937 break;
2233 case 0: /* default colors, if any */ 1938 case 0: /* default colors, if any */
2234 default: 1939 default:
2235 tty_default_color_capabilities (0); 1940 tty_default_color_capabilities (tty, 0);
2236 break; 1941 break;
2237 case 8: /* 8 standard ANSI colors */ 1942 case 8: /* 8 standard ANSI colors */
2238 TS_orig_pair = "\033[0m"; 1943 tty->TS_orig_pair = "\033[0m";
2239#ifdef TERMINFO 1944#ifdef TERMINFO
2240 TS_set_foreground = "\033[3%p1%dm"; 1945 tty->TS_set_foreground = "\033[3%p1%dm";
2241 TS_set_background = "\033[4%p1%dm"; 1946 tty->TS_set_background = "\033[4%p1%dm";
2242#else 1947#else
2243 TS_set_foreground = "\033[3%dm"; 1948 tty->TS_set_foreground = "\033[3%dm";
2244 TS_set_background = "\033[4%dm"; 1949 tty->TS_set_background = "\033[4%dm";
2245#endif 1950#endif
2246 TN_max_colors = 8; 1951 tty->TN_max_colors = 8;
2247 TN_max_pairs = 64; 1952 tty->TN_max_pairs = 64;
2248 TN_no_color_video = 0; 1953 tty->TN_no_color_video = 0;
2249 break; 1954 break;
2250 } 1955 }
2251} 1956}
@@ -2296,7 +2001,7 @@ set_tty_color_mode (f, val)
2296 2001
2297 if (mode != old_mode) 2002 if (mode != old_mode)
2298 { 2003 {
2299 tty_setup_colors (mode); 2004 tty_setup_colors (FRAME_TTY (f), mode);
2300 /* This recomputes all the faces given the new color 2005 /* This recomputes all the faces given the new color
2301 definitions. */ 2006 definitions. */
2302 call0 (intern ("tty-set-up-initial-frame-faces")); 2007 call0 (intern ("tty-set-up-initial-frame-faces"));
@@ -2307,85 +2012,569 @@ set_tty_color_mode (f, val)
2307#endif /* !WINDOWSNT */ 2012#endif /* !WINDOWSNT */
2308 2013
2309 2014
2015
2016/* Return the tty display object specified by TERMINAL. */
2017
2018struct terminal *
2019get_tty_terminal (Lisp_Object terminal, int throw)
2020{
2021 struct terminal *t = get_terminal (terminal, throw);
2022
2023 if (t && t->type == output_initial)
2024 return NULL;
2025
2026 if (t && t->type != output_termcap)
2027 {
2028 if (throw)
2029 error ("Device %d is not a termcap terminal device", t->id);
2030 else
2031 return NULL;
2032 }
2033
2034 return t;
2035}
2036
2037/* Return an active termcap device that uses the tty device with the
2038 given name.
2039
2040 This function ignores suspended devices.
2041
2042 Returns NULL if the named terminal device is not opened. */
2043
2044struct terminal *
2045get_named_tty (name)
2046 char *name;
2047{
2048 struct terminal *t;
2049
2050 if (!name)
2051 abort ();
2052
2053 for (t = terminal_list; t; t = t->next_terminal)
2054 {
2055 if (t->type == output_termcap
2056 && !strcmp (t->display_info.tty->name, name)
2057 && TERMINAL_ACTIVE_P (t))
2058 return t;
2059 }
2060
2061 return 0;
2062}
2063
2064
2065DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
2066 doc: /* Return the type of the tty device that TERMINAL uses.
2067Returns nil if TERMINAL is not on a tty device.
2068
2069TERMINAL can be a terminal id, a frame or nil (meaning the selected
2070frame's terminal). */)
2071 (terminal)
2072 Lisp_Object terminal;
2073{
2074 struct terminal *t = get_terminal (terminal, 1);
2075
2076 if (t->type != output_termcap)
2077 return Qnil;
2078
2079 if (t->display_info.tty->type)
2080 return build_string (t->display_info.tty->type);
2081 else
2082 return Qnil;
2083}
2084
2085DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
2086 doc: /* Return non-nil if TERMINAL is on the controlling tty of the Emacs process.
2087
2088TERMINAL can be a terminal id, a frame or nil (meaning the selected
2089frame's terminal). This function always returns nil if TERMINAL
2090is not on a tty device. */)
2091 (terminal)
2092 Lisp_Object terminal;
2093{
2094 struct terminal *t = get_terminal (terminal, 1);
2095
2096 if (t->type != output_termcap || strcmp (t->display_info.tty->name, "/dev/tty"))
2097 return Qnil;
2098 else
2099 return Qt;
2100}
2101
2102DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
2103 doc: /* Declare that the tty used by TERMINAL does not handle underlining.
2104This is used to override the terminfo data, for certain terminals that
2105do not really do underlining, but say that they do. This function has
2106no effect if used on a non-tty terminal.
2107
2108TERMINAL can be a terminal id, a frame or nil (meaning the selected
2109frame's terminal). This function always returns nil if TERMINAL
2110is not on a tty device. */)
2111 (terminal)
2112 Lisp_Object terminal;
2113{
2114 struct terminal *t = get_terminal (terminal, 1);
2115
2116 if (t->type == output_termcap)
2117 t->display_info.tty->TS_enter_underline_mode = 0;
2118 return Qnil;
2119}
2120
2121
2122
2123DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,
2124 doc: /* Suspend the terminal device TTY.
2125
2126The device is restored to its default state, and Emacs ceases all
2127access to the tty device. Frames that use the device are not deleted,
2128but input is not read from them and if they change, their display is
2129not updated.
2130
2131TTY may be a terminal id, a frame, or nil for the terminal device of
2132the currently selected frame.
2133
2134This function runs `suspend-tty-functions' after suspending the
2135device. The functions are run with one arg, the id of the suspended
2136terminal device.
2137
2138`suspend-tty' does nothing if it is called on a device that is already
2139suspended.
2140
2141A suspended tty may be resumed by calling `resume-tty' on it. */)
2142 (tty)
2143 Lisp_Object tty;
2144{
2145 struct terminal *t = get_tty_terminal (tty, 1);
2146 FILE *f;
2147
2148 if (!t)
2149 error ("Unknown tty device");
2150
2151 f = t->display_info.tty->input;
2152
2153 if (f)
2154 {
2155 reset_sys_modes (t->display_info.tty);
2156
2157 delete_keyboard_wait_descriptor (fileno (f));
2158
2159 fclose (f);
2160 if (f != t->display_info.tty->output)
2161 fclose (t->display_info.tty->output);
2162
2163 t->display_info.tty->input = 0;
2164 t->display_info.tty->output = 0;
2165
2166 if (FRAMEP (t->display_info.tty->top_frame))
2167 FRAME_SET_VISIBLE (XFRAME (t->display_info.tty->top_frame), 0);
2168
2169 /* Run `suspend-tty-functions'. */
2170 if (!NILP (Vrun_hooks))
2171 {
2172 Lisp_Object args[2];
2173 args[0] = intern ("suspend-tty-functions");
2174 args[1] = make_number (t->id);
2175 Frun_hook_with_args (2, args);
2176 }
2177 }
2178
2179 /* Clear display hooks to prevent further output. */
2180 clear_tty_hooks (t);
2181
2182 return Qnil;
2183}
2184
2185DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0,
2186 doc: /* Resume the previously suspended terminal device TTY.
2187The terminal is opened and reinitialized. Frames that are on the
2188suspended terminal are revived.
2189
2190It is an error to resume a terminal while another terminal is active
2191on the same device.
2192
2193This function runs `resume-tty-functions' after resuming the terminal.
2194The functions are run with one arg, the id of the resumed terminal
2195device.
2196
2197`resume-tty' does nothing if it is called on a device that is not
2198suspended.
2199
2200TTY may be a terminal id, a frame, or nil for the terminal device of
2201the currently selected frame. */)
2202 (tty)
2203 Lisp_Object tty;
2204{
2205 struct terminal *t = get_tty_terminal (tty, 1);
2206 int fd;
2207
2208 if (!t)
2209 error ("Unknown tty device");
2210
2211 if (!t->display_info.tty->input)
2212 {
2213 if (get_named_tty (t->display_info.tty->name))
2214 error ("Cannot resume display while another display is active on the same device");
2215
2216 fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
2217
2218 if (fd == -1)
2219 error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno));
2220
2221 if (strcmp (t->display_info.tty->name, "/dev/tty"))
2222 dissociate_if_controlling_tty (fd);
2223
2224 t->display_info.tty->output = fdopen (fd, "w+");
2225 t->display_info.tty->input = t->display_info.tty->output;
2226
2227 add_keyboard_wait_descriptor (fd);
2228
2229 if (FRAMEP (t->display_info.tty->top_frame))
2230 FRAME_SET_VISIBLE (XFRAME (t->display_info.tty->top_frame), 1);
2231
2232 init_sys_modes (t->display_info.tty);
2233
2234 /* Run `suspend-tty-functions'. */
2235 if (!NILP (Vrun_hooks))
2236 {
2237 Lisp_Object args[2];
2238 args[0] = intern ("resume-tty-functions");
2239 args[1] = make_number (t->id);
2240 Frun_hook_with_args (2, args);
2241 }
2242 }
2243
2244 set_tty_hooks (t);
2245
2246 return Qnil;
2247}
2248
2249
2310/*********************************************************************** 2250/***********************************************************************
2311 Initialization 2251 Initialization
2312 ***********************************************************************/ 2252 ***********************************************************************/
2313 2253
2254/* Initialize the tty-dependent part of frame F. The frame must
2255 already have its device initialized. */
2256
2314void 2257void
2315term_init (terminal_type) 2258create_tty_output (struct frame *f)
2316 char *terminal_type; 2259{
2260 struct tty_output *t;
2261
2262 if (! FRAME_TERMCAP_P (f))
2263 abort ();
2264
2265 t = xmalloc (sizeof (struct tty_output));
2266 bzero (t, sizeof (struct tty_output));
2267
2268 t->display_info = FRAME_TERMINAL (f)->display_info.tty;
2269
2270 f->output_data.tty = t;
2271}
2272
2273/* Delete the tty-dependent part of frame F. */
2274
2275static void
2276delete_tty_output (struct frame *f)
2277{
2278 if (! FRAME_TERMCAP_P (f))
2279 abort ();
2280
2281 xfree (f->output_data.tty);
2282}
2283
2284
2285
2286static void
2287clear_tty_hooks (struct terminal *terminal)
2317{ 2288{
2318 char *area; 2289 terminal->rif = 0;
2290 terminal->cursor_to_hook = 0;
2291 terminal->raw_cursor_to_hook = 0;
2292 terminal->clear_to_end_hook = 0;
2293 terminal->clear_frame_hook = 0;
2294 terminal->clear_end_of_line_hook = 0;
2295 terminal->ins_del_lines_hook = 0;
2296 terminal->insert_glyphs_hook = 0;
2297 terminal->write_glyphs_hook = 0;
2298 terminal->delete_glyphs_hook = 0;
2299 terminal->ring_bell_hook = 0;
2300 terminal->reset_terminal_modes_hook = 0;
2301 terminal->set_terminal_modes_hook = 0;
2302 terminal->update_begin_hook = 0;
2303 terminal->update_end_hook = 0;
2304 terminal->set_terminal_window_hook = 0;
2305 terminal->mouse_position_hook = 0;
2306 terminal->frame_rehighlight_hook = 0;
2307 terminal->frame_raise_lower_hook = 0;
2308 terminal->fullscreen_hook = 0;
2309 terminal->set_vertical_scroll_bar_hook = 0;
2310 terminal->condemn_scroll_bars_hook = 0;
2311 terminal->redeem_scroll_bar_hook = 0;
2312 terminal->judge_scroll_bars_hook = 0;
2313 terminal->read_socket_hook = 0;
2314 terminal->frame_up_to_date_hook = 0;
2315
2316 /* Leave these two set, or suspended frames are not deleted
2317 correctly. */
2318 terminal->delete_frame_hook = &delete_tty_output;
2319 terminal->delete_terminal_hook = &delete_tty;
2320}
2321
2322static void
2323set_tty_hooks (struct terminal *terminal)
2324{
2325 terminal->rif = 0; /* ttys don't support window-based redisplay. */
2326
2327 terminal->cursor_to_hook = &tty_cursor_to;
2328 terminal->raw_cursor_to_hook = &tty_raw_cursor_to;
2329
2330 terminal->clear_to_end_hook = &tty_clear_to_end;
2331 terminal->clear_frame_hook = &tty_clear_frame;
2332 terminal->clear_end_of_line_hook = &tty_clear_end_of_line;
2333
2334 terminal->ins_del_lines_hook = &tty_ins_del_lines;
2335
2336 terminal->insert_glyphs_hook = &tty_insert_glyphs;
2337 terminal->write_glyphs_hook = &tty_write_glyphs;
2338 terminal->delete_glyphs_hook = &tty_delete_glyphs;
2339
2340 terminal->ring_bell_hook = &tty_ring_bell;
2341
2342 terminal->reset_terminal_modes_hook = &tty_reset_terminal_modes;
2343 terminal->set_terminal_modes_hook = &tty_set_terminal_modes;
2344 terminal->update_begin_hook = 0; /* Not needed. */
2345 terminal->update_end_hook = &tty_update_end;
2346 terminal->set_terminal_window_hook = &tty_set_terminal_window;
2347
2348 terminal->mouse_position_hook = 0; /* Not needed. */
2349 terminal->frame_rehighlight_hook = 0; /* Not needed. */
2350 terminal->frame_raise_lower_hook = 0; /* Not needed. */
2351
2352 terminal->set_vertical_scroll_bar_hook = 0; /* Not needed. */
2353 terminal->condemn_scroll_bars_hook = 0; /* Not needed. */
2354 terminal->redeem_scroll_bar_hook = 0; /* Not needed. */
2355 terminal->judge_scroll_bars_hook = 0; /* Not needed. */
2356
2357 terminal->read_socket_hook = &tty_read_avail_input; /* keyboard.c */
2358 terminal->frame_up_to_date_hook = 0; /* Not needed. */
2359
2360 terminal->delete_frame_hook = &delete_tty_output;
2361 terminal->delete_terminal_hook = &delete_tty;
2362}
2363
2364/* Drop the controlling terminal if fd is the same device. */
2365static void
2366dissociate_if_controlling_tty (int fd)
2367{
2368 int pgid;
2369 EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */
2370 if (pgid != -1)
2371 {
2372#if defined (USG) && !defined (BSD_PGRPS)
2373 setpgrp ();
2374 no_controlling_tty = 1;
2375#else
2376#ifdef TIOCNOTTY /* Try BSD ioctls. */
2377 sigblock (sigmask (SIGTTOU));
2378 fd = emacs_open ("/dev/tty", O_RDWR, 0);
2379 if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
2380 {
2381 no_controlling_tty = 1;
2382 }
2383 if (fd != -1)
2384 emacs_close (fd);
2385 sigunblock (sigmask (SIGTTOU));
2386#else
2387 /* Unknown system. */
2388 croak ();
2389#endif /* ! TIOCNOTTY */
2390#endif /* ! USG */
2391 }
2392}
2393
2394static void maybe_fatal();
2395
2396/* Create a termcap display on the tty device with the given name and
2397 type.
2398
2399 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
2400 Otherwise NAME should be a path to the tty device file,
2401 e.g. "/dev/pts/7".
2402
2403 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
2404
2405 If MUST_SUCCEED is true, then all errors are fatal. */
2406
2407struct terminal *
2408init_tty (char *name, char *terminal_type, int must_succeed)
2409{
2410 char *area = NULL;
2319 char **address = &area; 2411 char **address = &area;
2320 char *buffer = NULL; 2412 char *buffer = NULL;
2321 int buffer_size = 4096; 2413 int buffer_size = 4096;
2322 register char *p; 2414 register char *p = NULL;
2323 int status; 2415 int status;
2324 struct frame *sf = XFRAME (selected_frame); 2416 struct tty_display_info *tty = NULL;
2417 struct terminal *terminal = NULL;
2418 int ctty = 0; /* 1 if asked to open controlling tty. */
2419
2420 if (!terminal_type)
2421 maybe_fatal (must_succeed, 0, 0,
2422 "Unknown terminal type",
2423 "Unknown terminal type");
2424
2425 if (name == NULL)
2426 name = "/dev/tty";
2427 if (!strcmp (name, "/dev/tty"))
2428 ctty = 1;
2429
2430 /* If we already have a terminal on the given device, use that. If
2431 all such terminals are suspended, create a new one instead. */
2432 /* XXX Perhaps this should be made explicit by having init_tty
2433 always create a new terminal and separating terminal and frame
2434 creation on Lisp level. */
2435 terminal = get_named_tty (name);
2436 if (terminal)
2437 return terminal;
2438
2439 terminal = create_terminal ();
2440 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info));
2441 bzero (tty, sizeof (struct tty_display_info));
2442 tty->next = tty_list;
2443 tty_list = tty;
2444
2445 terminal->type = output_termcap;
2446 terminal->display_info.tty = tty;
2447 tty->terminal = terminal;
2448
2449 tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm));
2450 Wcm_clear (tty);
2451
2452 set_tty_hooks (terminal);
2453
2454 {
2455 int fd;
2456 FILE *file;
2457
2458#ifdef O_IGNORE_CTTY
2459 if (!ctty)
2460 /* Open the terminal device. Don't recognize it as our
2461 controlling terminal, and don't make it the controlling tty
2462 if we don't have one at the moment. */
2463 fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0);
2464 else
2465#else
2466 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
2467 defined on Hurd. On other systems, we need to explicitly
2468 dissociate ourselves from the controlling tty when we want to
2469 open a frame on the same terminal. */
2470 fd = emacs_open (name, O_RDWR | O_NOCTTY, 0);
2471#endif /* O_IGNORE_CTTY */
2472
2473 if (fd < 0)
2474 maybe_fatal (must_succeed, buffer, terminal,
2475 "Could not open file: %s",
2476 "Could not open file: %s",
2477 name);
2478 if (!isatty (fd))
2479 {
2480 close (fd);
2481 maybe_fatal (must_succeed, buffer, terminal,
2482 "Not a tty device: %s",
2483 "Not a tty device: %s",
2484 name);
2485 }
2486
2487#ifndef O_IGNORE_CTTY
2488 if (!ctty)
2489 dissociate_if_controlling_tty (fd);
2490#endif
2491
2492 file = fdopen (fd, "w+");
2493 tty->name = xstrdup (name);
2494 terminal->name = xstrdup (name);
2495 tty->input = file;
2496 tty->output = file;
2497 }
2498
2499 tty->type = xstrdup (terminal_type);
2500
2501 add_keyboard_wait_descriptor (fileno (tty->input));
2325 2502
2326 encode_terminal_bufsize = 0; 2503 encode_terminal_bufsize = 0;
2327 2504
2328#ifdef WINDOWSNT 2505#ifdef WINDOWSNT
2329 initialize_w32_display (); 2506 initialize_w32_display ();
2330 2507
2331 Wcm_clear (); 2508 Wcm_clear (tty);
2332 2509
2333 area = (char *) xmalloc (2044); 2510 area = (char *) xmalloc (2044);
2334 2511
2335 FrameRows = FRAME_LINES (sf); 2512 FrameRows (tty) = FRAME_LINES (f); /* XXX */
2336 FrameCols = FRAME_COLS (sf); 2513 FrameCols (tty) = FRAME_COLS (f); /* XXX */
2337 specified_window = FRAME_LINES (sf); 2514 tty->specified_window = FRAME_LINES (f); /* XXX */
2338 2515
2339 delete_in_insert_mode = 1; 2516 tty->terminal->delete_in_insert_mode = 1;
2340 2517
2341 UseTabs = 0; 2518 UseTabs (tty) = 0;
2342 scroll_region_ok = 0; 2519 terminal->scroll_region_ok = 0;
2343 2520
2344 /* Seems to insert lines when it's not supposed to, messing 2521 /* Seems to insert lines when it's not supposed to, messing up the
2345 up the display. In doing a trace, it didn't seem to be 2522 display. In doing a trace, it didn't seem to be called much, so I
2346 called much, so I don't think we're losing anything by 2523 don't think we're losing anything by turning it off. */
2347 turning it off. */ 2524 terminal->line_ins_del_ok = 0;
2348 2525 terminal->char_ins_del_ok = 1;
2349 line_ins_del_ok = 0;
2350 char_ins_del_ok = 1;
2351 2526
2352 baud_rate = 19200; 2527 baud_rate = 19200;
2353 2528
2354 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; 2529 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; /* XXX */
2355 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; 2530 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; /* XXX */
2356 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ 2531 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
2357 2532
2358 return; 2533 return terminal;
2359#else /* not WINDOWSNT */ 2534#else /* not WINDOWSNT */
2360 2535
2361 Wcm_clear (); 2536 Wcm_clear (tty);
2362 2537
2363 buffer = (char *) xmalloc (buffer_size); 2538 buffer = (char *) xmalloc (buffer_size);
2539
2540 /* On some systems, tgetent tries to access the controlling
2541 terminal. */
2542 sigblock (sigmask (SIGTTOU));
2364 status = tgetent (buffer, terminal_type); 2543 status = tgetent (buffer, terminal_type);
2544 sigunblock (sigmask (SIGTTOU));
2545
2365 if (status < 0) 2546 if (status < 0)
2366 { 2547 {
2367#ifdef TERMINFO 2548#ifdef TERMINFO
2368 fatal ("Cannot open terminfo database file"); 2549 maybe_fatal (must_succeed, buffer, terminal,
2550 "Cannot open terminfo database file",
2551 "Cannot open terminfo database file");
2369#else 2552#else
2370 fatal ("Cannot open termcap database file"); 2553 maybe_fatal (must_succeed, buffer, terminal,
2554 "Cannot open termcap database file",
2555 "Cannot open termcap database file");
2371#endif 2556#endif
2372 } 2557 }
2373 if (status == 0) 2558 if (status == 0)
2374 { 2559 {
2375#ifdef TERMINFO 2560#ifdef TERMINFO
2376 fatal ("Terminal type %s is not defined.\n\ 2561 maybe_fatal (must_succeed, buffer, terminal,
2562 "Terminal type %s is not defined",
2563 "Terminal type %s is not defined.\n\
2377If that is not the actual type of terminal you have,\n\ 2564If that is not the actual type of terminal you have,\n\
2378use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2565use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2379`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2566`setenv TERM ...') to specify the correct type. It may be necessary\n\
2380to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2567to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2381 terminal_type); 2568 terminal_type);
2382#else 2569#else
2383 fatal ("Terminal type %s is not defined.\n\ 2570 maybe_fatal (must_succeed, buffer, terminal,
2571 "Terminal type %s is not defined",
2572 "Terminal type %s is not defined.\n\
2384If that is not the actual type of terminal you have,\n\ 2573If that is not the actual type of terminal you have,\n\
2385use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2574use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2386`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2575`setenv TERM ...') to specify the correct type. It may be necessary\n\
2387to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2576to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2388 terminal_type); 2577 terminal_type);
2389#endif 2578#endif
2390 } 2579 }
2391 2580
@@ -2396,219 +2585,234 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2396#endif 2585#endif
2397 area = (char *) xmalloc (buffer_size); 2586 area = (char *) xmalloc (buffer_size);
2398 2587
2399 TS_ins_line = tgetstr ("al", address); 2588 tty->TS_ins_line = tgetstr ("al", address);
2400 TS_ins_multi_lines = tgetstr ("AL", address); 2589 tty->TS_ins_multi_lines = tgetstr ("AL", address);
2401 TS_bell = tgetstr ("bl", address); 2590 tty->TS_bell = tgetstr ("bl", address);
2402 BackTab = tgetstr ("bt", address); 2591 BackTab (tty) = tgetstr ("bt", address);
2403 TS_clr_to_bottom = tgetstr ("cd", address); 2592 tty->TS_clr_to_bottom = tgetstr ("cd", address);
2404 TS_clr_line = tgetstr ("ce", address); 2593 tty->TS_clr_line = tgetstr ("ce", address);
2405 TS_clr_frame = tgetstr ("cl", address); 2594 tty->TS_clr_frame = tgetstr ("cl", address);
2406 ColPosition = NULL; /* tgetstr ("ch", address); */ 2595 ColPosition (tty) = NULL; /* tgetstr ("ch", address); */
2407 AbsPosition = tgetstr ("cm", address); 2596 AbsPosition (tty) = tgetstr ("cm", address);
2408 CR = tgetstr ("cr", address); 2597 CR (tty) = tgetstr ("cr", address);
2409 TS_set_scroll_region = tgetstr ("cs", address); 2598 tty->TS_set_scroll_region = tgetstr ("cs", address);
2410 TS_set_scroll_region_1 = tgetstr ("cS", address); 2599 tty->TS_set_scroll_region_1 = tgetstr ("cS", address);
2411 RowPosition = tgetstr ("cv", address); 2600 RowPosition (tty) = tgetstr ("cv", address);
2412 TS_del_char = tgetstr ("dc", address); 2601 tty->TS_del_char = tgetstr ("dc", address);
2413 TS_del_multi_chars = tgetstr ("DC", address); 2602 tty->TS_del_multi_chars = tgetstr ("DC", address);
2414 TS_del_line = tgetstr ("dl", address); 2603 tty->TS_del_line = tgetstr ("dl", address);
2415 TS_del_multi_lines = tgetstr ("DL", address); 2604 tty->TS_del_multi_lines = tgetstr ("DL", address);
2416 TS_delete_mode = tgetstr ("dm", address); 2605 tty->TS_delete_mode = tgetstr ("dm", address);
2417 TS_end_delete_mode = tgetstr ("ed", address); 2606 tty->TS_end_delete_mode = tgetstr ("ed", address);
2418 TS_end_insert_mode = tgetstr ("ei", address); 2607 tty->TS_end_insert_mode = tgetstr ("ei", address);
2419 Home = tgetstr ("ho", address); 2608 Home (tty) = tgetstr ("ho", address);
2420 TS_ins_char = tgetstr ("ic", address); 2609 tty->TS_ins_char = tgetstr ("ic", address);
2421 TS_ins_multi_chars = tgetstr ("IC", address); 2610 tty->TS_ins_multi_chars = tgetstr ("IC", address);
2422 TS_insert_mode = tgetstr ("im", address); 2611 tty->TS_insert_mode = tgetstr ("im", address);
2423 TS_pad_inserted_char = tgetstr ("ip", address); 2612 tty->TS_pad_inserted_char = tgetstr ("ip", address);
2424 TS_end_keypad_mode = tgetstr ("ke", address); 2613 tty->TS_end_keypad_mode = tgetstr ("ke", address);
2425 TS_keypad_mode = tgetstr ("ks", address); 2614 tty->TS_keypad_mode = tgetstr ("ks", address);
2426 LastLine = tgetstr ("ll", address); 2615 LastLine (tty) = tgetstr ("ll", address);
2427 Right = tgetstr ("nd", address); 2616 Right (tty) = tgetstr ("nd", address);
2428 Down = tgetstr ("do", address); 2617 Down (tty) = tgetstr ("do", address);
2429 if (!Down) 2618 if (!Down (tty))
2430 Down = tgetstr ("nl", address); /* Obsolete name for "do" */ 2619 Down (tty) = tgetstr ("nl", address); /* Obsolete name for "do" */
2431#ifdef VMS 2620#ifdef VMS
2432 /* VMS puts a carriage return before each linefeed, 2621 /* VMS puts a carriage return before each linefeed,
2433 so it is not safe to use linefeeds. */ 2622 so it is not safe to use linefeeds. */
2434 if (Down && Down[0] == '\n' && Down[1] == '\0') 2623 if (Down (tty) && Down (tty)[0] == '\n' && Down (tty)[1] == '\0')
2435 Down = 0; 2624 Down (tty) = 0;
2436#endif /* VMS */ 2625#endif /* VMS */
2437 if (tgetflag ("bs")) 2626 if (tgetflag ("bs"))
2438 Left = "\b"; /* can't possibly be longer! */ 2627 Left (tty) = "\b"; /* can't possibly be longer! */
2439 else /* (Actually, "bs" is obsolete...) */ 2628 else /* (Actually, "bs" is obsolete...) */
2440 Left = tgetstr ("le", address); 2629 Left (tty) = tgetstr ("le", address);
2441 if (!Left) 2630 if (!Left (tty))
2442 Left = tgetstr ("bc", address); /* Obsolete name for "le" */ 2631 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */
2443 TS_pad_char = tgetstr ("pc", address); 2632 tty->TS_pad_char = tgetstr ("pc", address);
2444 TS_repeat = tgetstr ("rp", address); 2633 tty->TS_repeat = tgetstr ("rp", address);
2445 TS_end_standout_mode = tgetstr ("se", address); 2634 tty->TS_end_standout_mode = tgetstr ("se", address);
2446 TS_fwd_scroll = tgetstr ("sf", address); 2635 tty->TS_fwd_scroll = tgetstr ("sf", address);
2447 TS_standout_mode = tgetstr ("so", address); 2636 tty->TS_standout_mode = tgetstr ("so", address);
2448 TS_rev_scroll = tgetstr ("sr", address); 2637 tty->TS_rev_scroll = tgetstr ("sr", address);
2449 Wcm.cm_tab = tgetstr ("ta", address); 2638 tty->Wcm->cm_tab = tgetstr ("ta", address);
2450 TS_end_termcap_modes = tgetstr ("te", address); 2639 tty->TS_end_termcap_modes = tgetstr ("te", address);
2451 TS_termcap_modes = tgetstr ("ti", address); 2640 tty->TS_termcap_modes = tgetstr ("ti", address);
2452 Up = tgetstr ("up", address); 2641 Up (tty) = tgetstr ("up", address);
2453 TS_visible_bell = tgetstr ("vb", address); 2642 tty->TS_visible_bell = tgetstr ("vb", address);
2454 TS_cursor_normal = tgetstr ("ve", address); 2643 tty->TS_cursor_normal = tgetstr ("ve", address);
2455 TS_cursor_visible = tgetstr ("vs", address); 2644 tty->TS_cursor_visible = tgetstr ("vs", address);
2456 TS_cursor_invisible = tgetstr ("vi", address); 2645 tty->TS_cursor_invisible = tgetstr ("vi", address);
2457 TS_set_window = tgetstr ("wi", address); 2646 tty->TS_set_window = tgetstr ("wi", address);
2458 2647
2459 TS_enter_underline_mode = tgetstr ("us", address); 2648 tty->TS_enter_underline_mode = tgetstr ("us", address);
2460 TS_exit_underline_mode = tgetstr ("ue", address); 2649 tty->TS_exit_underline_mode = tgetstr ("ue", address);
2461 TS_enter_bold_mode = tgetstr ("md", address); 2650 tty->TS_enter_bold_mode = tgetstr ("md", address);
2462 TS_enter_dim_mode = tgetstr ("mh", address); 2651 tty->TS_enter_dim_mode = tgetstr ("mh", address);
2463 TS_enter_blink_mode = tgetstr ("mb", address); 2652 tty->TS_enter_blink_mode = tgetstr ("mb", address);
2464 TS_enter_reverse_mode = tgetstr ("mr", address); 2653 tty->TS_enter_reverse_mode = tgetstr ("mr", address);
2465 TS_enter_alt_charset_mode = tgetstr ("as", address); 2654 tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
2466 TS_exit_alt_charset_mode = tgetstr ("ae", address); 2655 tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
2467 TS_exit_attribute_mode = tgetstr ("me", address); 2656 tty->TS_exit_attribute_mode = tgetstr ("me", address);
2468 2657
2469 MultiUp = tgetstr ("UP", address); 2658 MultiUp (tty) = tgetstr ("UP", address);
2470 MultiDown = tgetstr ("DO", address); 2659 MultiDown (tty) = tgetstr ("DO", address);
2471 MultiLeft = tgetstr ("LE", address); 2660 MultiLeft (tty) = tgetstr ("LE", address);
2472 MultiRight = tgetstr ("RI", address); 2661 MultiRight (tty) = tgetstr ("RI", address);
2473 2662
2474 /* SVr4/ANSI color suppert. If "op" isn't available, don't support 2663 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2475 color because we can't switch back to the default foreground and 2664 color because we can't switch back to the default foreground and
2476 background. */ 2665 background. */
2477 TS_orig_pair = tgetstr ("op", address); 2666 tty->TS_orig_pair = tgetstr ("op", address);
2478 if (TS_orig_pair) 2667 if (tty->TS_orig_pair)
2479 { 2668 {
2480 TS_set_foreground = tgetstr ("AF", address); 2669 tty->TS_set_foreground = tgetstr ("AF", address);
2481 TS_set_background = tgetstr ("AB", address); 2670 tty->TS_set_background = tgetstr ("AB", address);
2482 if (!TS_set_foreground) 2671 if (!tty->TS_set_foreground)
2483 { 2672 {
2484 /* SVr4. */ 2673 /* SVr4. */
2485 TS_set_foreground = tgetstr ("Sf", address); 2674 tty->TS_set_foreground = tgetstr ("Sf", address);
2486 TS_set_background = tgetstr ("Sb", address); 2675 tty->TS_set_background = tgetstr ("Sb", address);
2487 } 2676 }
2488 2677
2489 TN_max_colors = tgetnum ("Co"); 2678 tty->TN_max_colors = tgetnum ("Co");
2490 TN_max_pairs = tgetnum ("pa"); 2679 tty->TN_max_pairs = tgetnum ("pa");
2491 2680
2492 TN_no_color_video = tgetnum ("NC"); 2681 tty->TN_no_color_video = tgetnum ("NC");
2493 if (TN_no_color_video == -1) 2682 if (tty->TN_no_color_video == -1)
2494 TN_no_color_video = 0; 2683 tty->TN_no_color_video = 0;
2495 } 2684 }
2496 2685
2497 tty_default_color_capabilities (1); 2686 tty_default_color_capabilities (tty, 1);
2498 2687
2499 MagicWrap = tgetflag ("xn"); 2688 MagicWrap (tty) = tgetflag ("xn");
2500 /* Since we make MagicWrap terminals look like AutoWrap, we need to have 2689 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2501 the former flag imply the latter. */ 2690 the former flag imply the latter. */
2502 AutoWrap = MagicWrap || tgetflag ("am"); 2691 AutoWrap (tty) = MagicWrap (tty) || tgetflag ("am");
2503 memory_below_frame = tgetflag ("db"); 2692 terminal->memory_below_frame = tgetflag ("db");
2504 TF_hazeltine = tgetflag ("hz"); 2693 tty->TF_hazeltine = tgetflag ("hz");
2505 must_write_spaces = tgetflag ("in"); 2694 terminal->must_write_spaces = tgetflag ("in");
2506 meta_key = tgetflag ("km") || tgetflag ("MT"); 2695 tty->meta_key = tgetflag ("km") || tgetflag ("MT");
2507 TF_insmode_motion = tgetflag ("mi"); 2696 tty->TF_insmode_motion = tgetflag ("mi");
2508 TF_standout_motion = tgetflag ("ms"); 2697 tty->TF_standout_motion = tgetflag ("ms");
2509 TF_underscore = tgetflag ("ul"); 2698 tty->TF_underscore = tgetflag ("ul");
2510 TF_teleray = tgetflag ("xt"); 2699 tty->TF_teleray = tgetflag ("xt");
2511 2700
2512 term_get_fkeys (address); 2701#ifdef MULTI_KBOARD
2702 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
2703 init_kboard (terminal->kboard);
2704 terminal->kboard->next_kboard = all_kboards;
2705 all_kboards = terminal->kboard;
2706 terminal->kboard->reference_count++;
2707 /* Don't let the initial kboard remain current longer than necessary.
2708 That would cause problems if a file loaded on startup tries to
2709 prompt in the mini-buffer. */
2710 if (current_kboard == initial_kboard)
2711 current_kboard = terminal->kboard;
2712#endif
2713
2714 term_get_fkeys (address, terminal->kboard);
2513 2715
2514 /* Get frame size from system, or else from termcap. */ 2716 /* Get frame size from system, or else from termcap. */
2515 { 2717 {
2516 int height, width; 2718 int height, width;
2517 get_frame_size (&width, &height); 2719 get_tty_size (fileno (tty->input), &width, &height);
2518 FRAME_COLS (sf) = width; 2720 FrameCols (tty) = width;
2519 FRAME_LINES (sf) = height; 2721 FrameRows (tty) = height;
2520 } 2722 }
2521 2723
2522 if (FRAME_COLS (sf) <= 0) 2724 if (FrameCols (tty) <= 0)
2523 SET_FRAME_COLS (sf, tgetnum ("co")); 2725 FrameCols (tty) = tgetnum ("co");
2524 else 2726 if (FrameRows (tty) <= 0)
2525 /* Keep width and external_width consistent */ 2727 FrameRows (tty) = tgetnum ("li");
2526 SET_FRAME_COLS (sf, FRAME_COLS (sf)); 2728
2527 if (FRAME_LINES (sf) <= 0) 2729 if (FrameRows (tty) < 3 || FrameCols (tty) < 3)
2528 FRAME_LINES (sf) = tgetnum ("li"); 2730 maybe_fatal (must_succeed, NULL, terminal,
2731 "Screen size %dx%d is too small"
2732 "Screen size %dx%d is too small",
2733 FrameCols (tty), FrameRows (tty));
2529 2734
2530 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3) 2735#if 0 /* This is not used anywhere. */
2531 fatal ("Screen size %dx%d is too small", 2736 tty->terminal->min_padding_speed = tgetnum ("pb");
2532 FRAME_LINES (sf), FRAME_COLS (sf)); 2737#endif
2533 2738
2534 min_padding_speed = tgetnum ("pb"); 2739 TabWidth (tty) = tgetnum ("tw");
2535 TabWidth = tgetnum ("tw");
2536 2740
2537#ifdef VMS 2741#ifdef VMS
2538 /* These capabilities commonly use ^J. 2742 /* These capabilities commonly use ^J.
2539 I don't know why, but sending them on VMS does not work; 2743 I don't know why, but sending them on VMS does not work;
2540 it causes following spaces to be lost, sometimes. 2744 it causes following spaces to be lost, sometimes.
2541 For now, the simplest fix is to avoid using these capabilities ever. */ 2745 For now, the simplest fix is to avoid using these capabilities ever. */
2542 if (Down && Down[0] == '\n') 2746 if (Down (tty) && Down (tty)[0] == '\n')
2543 Down = 0; 2747 Down (tty) = 0;
2544#endif /* VMS */ 2748#endif /* VMS */
2545 2749
2546 if (!TS_bell) 2750 if (!tty->TS_bell)
2547 TS_bell = "\07"; 2751 tty->TS_bell = "\07";
2548 2752
2549 if (!TS_fwd_scroll) 2753 if (!tty->TS_fwd_scroll)
2550 TS_fwd_scroll = Down; 2754 tty->TS_fwd_scroll = Down (tty);
2551 2755
2552 PC = TS_pad_char ? *TS_pad_char : 0; 2756 PC = tty->TS_pad_char ? *tty->TS_pad_char : 0;
2553 2757
2554 if (TabWidth < 0) 2758 if (TabWidth (tty) < 0)
2555 TabWidth = 8; 2759 TabWidth (tty) = 8;
2556 2760
2557/* Turned off since /etc/termcap seems to have :ta= for most terminals 2761/* Turned off since /etc/termcap seems to have :ta= for most terminals
2558 and newer termcap doc does not seem to say there is a default. 2762 and newer termcap doc does not seem to say there is a default.
2559 if (!Wcm.cm_tab) 2763 if (!tty->Wcm->cm_tab)
2560 Wcm.cm_tab = "\t"; 2764 tty->Wcm->cm_tab = "\t";
2561*/ 2765*/
2562 2766
2563 /* We don't support standout modes that use `magic cookies', so 2767 /* We don't support standout modes that use `magic cookies', so
2564 turn off any that do. */ 2768 turn off any that do. */
2565 if (TS_standout_mode && tgetnum ("sg") >= 0) 2769 if (tty->TS_standout_mode && tgetnum ("sg") >= 0)
2566 { 2770 {
2567 TS_standout_mode = 0; 2771 tty->TS_standout_mode = 0;
2568 TS_end_standout_mode = 0; 2772 tty->TS_end_standout_mode = 0;
2569 } 2773 }
2570 if (TS_enter_underline_mode && tgetnum ("ug") >= 0) 2774 if (tty->TS_enter_underline_mode && tgetnum ("ug") >= 0)
2571 { 2775 {
2572 TS_enter_underline_mode = 0; 2776 tty->TS_enter_underline_mode = 0;
2573 TS_exit_underline_mode = 0; 2777 tty->TS_exit_underline_mode = 0;
2574 } 2778 }
2575 2779
2576 /* If there's no standout mode, try to use underlining instead. */ 2780 /* If there's no standout mode, try to use underlining instead. */
2577 if (TS_standout_mode == 0) 2781 if (tty->TS_standout_mode == 0)
2578 { 2782 {
2579 TS_standout_mode = TS_enter_underline_mode; 2783 tty->TS_standout_mode = tty->TS_enter_underline_mode;
2580 TS_end_standout_mode = TS_exit_underline_mode; 2784 tty->TS_end_standout_mode = tty->TS_exit_underline_mode;
2581 } 2785 }
2582 2786
2583 /* If no `se' string, try using a `me' string instead. 2787 /* If no `se' string, try using a `me' string instead.
2584 If that fails, we can't use standout mode at all. */ 2788 If that fails, we can't use standout mode at all. */
2585 if (TS_end_standout_mode == 0) 2789 if (tty->TS_end_standout_mode == 0)
2586 { 2790 {
2587 char *s = tgetstr ("me", address); 2791 char *s = tgetstr ("me", address);
2588 if (s != 0) 2792 if (s != 0)
2589 TS_end_standout_mode = s; 2793 tty->TS_end_standout_mode = s;
2590 else 2794 else
2591 TS_standout_mode = 0; 2795 tty->TS_standout_mode = 0;
2592 } 2796 }
2593 2797
2594 if (TF_teleray) 2798 if (tty->TF_teleray)
2595 { 2799 {
2596 Wcm.cm_tab = 0; 2800 tty->Wcm->cm_tab = 0;
2597 /* We can't support standout mode, because it uses magic cookies. */ 2801 /* We can't support standout mode, because it uses magic cookies. */
2598 TS_standout_mode = 0; 2802 tty->TS_standout_mode = 0;
2599 /* But that means we cannot rely on ^M to go to column zero! */ 2803 /* But that means we cannot rely on ^M to go to column zero! */
2600 CR = 0; 2804 CR (tty) = 0;
2601 /* LF can't be trusted either -- can alter hpos */ 2805 /* LF can't be trusted either -- can alter hpos */
2602 /* if move at column 0 thru a line with TS_standout_mode */ 2806 /* if move at column 0 thru a line with TS_standout_mode */
2603 Down = 0; 2807 Down (tty) = 0;
2604 } 2808 }
2605 2809
2606 /* Special handling for certain terminal types known to need it */ 2810 /* Special handling for certain terminal types known to need it */
2607 2811
2608 if (!strcmp (terminal_type, "supdup")) 2812 if (!strcmp (terminal_type, "supdup"))
2609 { 2813 {
2610 memory_below_frame = 1; 2814 terminal->memory_below_frame = 1;
2611 Wcm.cm_losewrap = 1; 2815 tty->Wcm->cm_losewrap = 1;
2612 } 2816 }
2613 if (!strncmp (terminal_type, "c10", 3) 2817 if (!strncmp (terminal_type, "c10", 3)
2614 || !strcmp (terminal_type, "perq")) 2818 || !strcmp (terminal_type, "perq"))
@@ -2625,102 +2829,139 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2625 It would be simpler if the :wi string could go in the termcap 2829 It would be simpler if the :wi string could go in the termcap
2626 entry, but it can't because it is not fully valid. 2830 entry, but it can't because it is not fully valid.
2627 If it were in the termcap entry, it would confuse other programs. */ 2831 If it were in the termcap entry, it would confuse other programs. */
2628 if (!TS_set_window) 2832 if (!tty->TS_set_window)
2629 { 2833 {
2630 p = TS_termcap_modes; 2834 p = tty->TS_termcap_modes;
2631 while (*p && strcmp (p, "\033v ")) 2835 while (*p && strcmp (p, "\033v "))
2632 p++; 2836 p++;
2633 if (*p) 2837 if (*p)
2634 TS_set_window = "\033v%C %C %C %C "; 2838 tty->TS_set_window = "\033v%C %C %C %C ";
2635 } 2839 }
2636 /* Termcap entry often fails to have :in: flag */ 2840 /* Termcap entry often fails to have :in: flag */
2637 must_write_spaces = 1; 2841 terminal->must_write_spaces = 1;
2638 /* :ti string typically fails to have \E^G! in it */ 2842 /* :ti string typically fails to have \E^G! in it */
2639 /* This limits scope of insert-char to one line. */ 2843 /* This limits scope of insert-char to one line. */
2640 strcpy (area, TS_termcap_modes); 2844 strcpy (area, tty->TS_termcap_modes);
2641 strcat (area, "\033\007!"); 2845 strcat (area, "\033\007!");
2642 TS_termcap_modes = area; 2846 tty->TS_termcap_modes = area;
2643 area += strlen (area) + 1; 2847 area += strlen (area) + 1;
2644 p = AbsPosition; 2848 p = AbsPosition (tty);
2645 /* Change all %+ parameters to %C, to handle 2849 /* Change all %+ parameters to %C, to handle
2646 values above 96 correctly for the C100. */ 2850 values above 96 correctly for the C100. */
2647 while (*p) 2851 while (*p)
2648 { 2852 {
2649 if (p[0] == '%' && p[1] == '+') 2853 if (p[0] == '%' && p[1] == '+')
2650 p[1] = 'C'; 2854 p[1] = 'C';
2651 p++; 2855 p++;
2652 } 2856 }
2653 } 2857 }
2654 2858
2655 FrameRows = FRAME_LINES (sf); 2859 tty->specified_window = FrameRows (tty);
2656 FrameCols = FRAME_COLS (sf);
2657 specified_window = FRAME_LINES (sf);
2658 2860
2659 if (Wcm_init () == -1) /* can't do cursor motion */ 2861 if (Wcm_init (tty) == -1) /* can't do cursor motion */
2862 {
2863 maybe_fatal (must_succeed, NULL, terminal,
2864 "Terminal type \"%s\" is not powerful enough to run Emacs",
2660#ifdef VMS 2865#ifdef VMS
2661 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2866 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2662It lacks the ability to position the cursor.\n\ 2867It lacks the ability to position the cursor.\n\
2663If that is not the actual type of terminal you have, use either the\n\ 2868If that is not the actual type of terminal you have, use either the\n\
2664DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\ 2869DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2665or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.", 2870or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2666 terminal_type);
2667#else /* not VMS */ 2871#else /* not VMS */
2668# ifdef TERMINFO 2872# ifdef TERMINFO
2669 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2873 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2670It lacks the ability to position the cursor.\n\ 2874It lacks the ability to position the cursor.\n\
2671If that is not the actual type of terminal you have,\n\ 2875If that is not the actual type of terminal you have,\n\
2672use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2876use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2673`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2877`setenv TERM ...') to specify the correct type. It may be necessary\n\
2674to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 2878to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2675 terminal_type);
2676# else /* TERMCAP */ 2879# else /* TERMCAP */
2677 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 2880 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2678It lacks the ability to position the cursor.\n\ 2881It lacks the ability to position the cursor.\n\
2679If that is not the actual type of terminal you have,\n\ 2882If that is not the actual type of terminal you have,\n\
2680use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 2883use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2681`setenv TERM ...') to specify the correct type. It may be necessary\n\ 2884`setenv TERM ...') to specify the correct type. It may be necessary\n\
2682to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 2885to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2683 terminal_type);
2684# endif /* TERMINFO */ 2886# endif /* TERMINFO */
2685#endif /*VMS */ 2887#endif /*VMS */
2686 if (FRAME_LINES (sf) <= 0 2888 terminal_type);
2687 || FRAME_COLS (sf) <= 0) 2889 }
2688 fatal ("The frame size has not been specified");
2689 2890
2690 delete_in_insert_mode 2891 if (FrameRows (tty) <= 0 || FrameCols (tty) <= 0)
2691 = TS_delete_mode && TS_insert_mode 2892 maybe_fatal (must_succeed, NULL, terminal,
2692 && !strcmp (TS_delete_mode, TS_insert_mode); 2893 "Could not determine the frame size",
2894 "Could not determine the frame size");
2693 2895
2694 se_is_so = (TS_standout_mode 2896 tty->delete_in_insert_mode
2695 && TS_end_standout_mode 2897 = tty->TS_delete_mode && tty->TS_insert_mode
2696 && !strcmp (TS_standout_mode, TS_end_standout_mode)); 2898 && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode);
2697 2899
2698 UseTabs = tabs_safe_p () && TabWidth == 8; 2900 tty->se_is_so = (tty->TS_standout_mode
2901 && tty->TS_end_standout_mode
2902 && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode));
2699 2903
2700 scroll_region_ok 2904 UseTabs (tty) = tabs_safe_p (fileno (tty->input)) && TabWidth (tty) == 8;
2701 = (Wcm.cm_abs
2702 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1));
2703 2905
2704 line_ins_del_ok = (((TS_ins_line || TS_ins_multi_lines) 2906 terminal->scroll_region_ok
2705 && (TS_del_line || TS_del_multi_lines)) 2907 = (tty->Wcm->cm_abs
2706 || (scroll_region_ok && TS_fwd_scroll && TS_rev_scroll)); 2908 && (tty->TS_set_window || tty->TS_set_scroll_region || tty->TS_set_scroll_region_1));
2707 2909
2708 char_ins_del_ok = ((TS_ins_char || TS_insert_mode 2910 terminal->line_ins_del_ok
2709 || TS_pad_inserted_char || TS_ins_multi_chars) 2911 = (((tty->TS_ins_line || tty->TS_ins_multi_lines)
2710 && (TS_del_char || TS_del_multi_chars)); 2912 && (tty->TS_del_line || tty->TS_del_multi_lines))
2913 || (terminal->scroll_region_ok
2914 && tty->TS_fwd_scroll && tty->TS_rev_scroll));
2711 2915
2712 fast_clear_end_of_line = TS_clr_line != 0; 2916 terminal->char_ins_del_ok
2917 = ((tty->TS_ins_char || tty->TS_insert_mode
2918 || tty->TS_pad_inserted_char || tty->TS_ins_multi_chars)
2919 && (tty->TS_del_char || tty->TS_del_multi_chars));
2713 2920
2714 init_baud_rate (); 2921 terminal->fast_clear_end_of_line = tty->TS_clr_line != 0;
2715 if (read_socket_hook) /* Baudrate is somewhat */
2716 /* meaningless in this case */
2717 baud_rate = 9600;
2718 2922
2719 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; 2923 init_baud_rate (fileno (tty->input));
2720 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; 2924
2721#endif /* WINDOWSNT */ 2925#ifdef AIXHFT
2926 /* The HFT system on AIX doesn't optimize for scrolling, so it's
2927 really ugly at times. */
2928 terminal->line_ins_del_ok = 0;
2929 terminal->char_ins_del_ok = 0;
2930#endif
2931
2932 /* Don't do this. I think termcap may still need the buffer. */
2933 /* xfree (buffer); */
2934
2935 /* Init system terminal modes (RAW or CBREAK, etc.). */
2936 init_sys_modes (tty);
2937
2938 return terminal;
2939#endif /* not WINDOWSNT */
2940}
2722 2941
2723 xfree (buffer); 2942/* Auxiliary error-handling function for init_tty.
2943 Free BUFFER and delete TERMINAL, then call error or fatal
2944 with str1 or str2, respectively, according to MUST_SUCCEED. */
2945
2946static void
2947maybe_fatal (must_succeed, buffer, terminal, str1, str2, arg1, arg2)
2948 int must_succeed;
2949 char *buffer;
2950 struct terminal *terminal;
2951 char *str1, *str2, *arg1, *arg2;
2952{
2953 if (buffer)
2954 xfree (buffer);
2955
2956 if (terminal)
2957 delete_tty (terminal);
2958
2959 if (must_succeed)
2960 fatal (str2, arg1, arg2);
2961 else
2962 error (str1, arg1, arg2);
2963
2964 abort ();
2724} 2965}
2725 2966
2726/* VARARGS 1 */ 2967/* VARARGS 1 */
@@ -2735,16 +2976,108 @@ fatal (str, arg1, arg2)
2735 exit (1); 2976 exit (1);
2736} 2977}
2737 2978
2738DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 0, 0, 2979
2739 doc: /* Declare that this terminal does not handle underlining. 2980
2740This is used to override the terminfo data, for certain terminals that 2981/* Delete the given tty terminal, closing all frames on it. */
2741do not really do underlining, but say that they do. */) 2982
2742 () 2983static void
2984delete_tty (struct terminal *terminal)
2743{ 2985{
2744 TS_enter_underline_mode = 0; 2986 struct tty_display_info *tty;
2745 return Qnil; 2987 Lisp_Object tail, frame;
2988 int last_terminal;
2989
2990 /* Protect against recursive calls. Fdelete_frame in
2991 delete_terminal calls us back when it deletes our last frame. */
2992 if (terminal->deleted)
2993 return;
2994
2995 if (terminal->type != output_termcap)
2996 abort ();
2997
2998 tty = terminal->display_info.tty;
2999
3000 last_terminal = 1;
3001 FOR_EACH_FRAME (tail, frame)
3002 {
3003 struct frame *f = XFRAME (frame);
3004 if (FRAME_LIVE_P (f) && (!FRAME_TERMCAP_P (f) || FRAME_TTY (f) != tty))
3005 {
3006 last_terminal = 0;
3007 break;
3008 }
3009 }
3010 if (last_terminal)
3011 error ("Attempt to delete the sole terminal device with live frames");
3012
3013 if (tty == tty_list)
3014 tty_list = tty->next;
3015 else
3016 {
3017 struct tty_display_info *p;
3018 for (p = tty_list; p && p->next != tty; p = p->next)
3019 ;
3020
3021 if (! p)
3022 /* This should not happen. */
3023 abort ();
3024
3025 p->next = tty->next;
3026 tty->next = 0;
3027 }
3028
3029 /* reset_sys_modes needs a valid device, so this call needs to be
3030 before delete_terminal. */
3031 reset_sys_modes (tty);
3032
3033 delete_terminal (terminal);
3034
3035 if (tty->name)
3036 xfree (tty->name);
3037
3038 if (tty->type)
3039 xfree (tty->type);
3040
3041 if (tty->input)
3042 {
3043 delete_keyboard_wait_descriptor (fileno (tty->input));
3044 if (tty->input != stdin)
3045 fclose (tty->input);
3046 }
3047 if (tty->output && tty->output != stdout && tty->output != tty->input)
3048 fclose (tty->output);
3049 if (tty->termscript)
3050 fclose (tty->termscript);
3051
3052 if (tty->old_tty)
3053 xfree (tty->old_tty);
3054
3055 if (tty->Wcm)
3056 xfree (tty->Wcm);
3057
3058 bzero (tty, sizeof (struct tty_display_info));
3059 xfree (tty);
2746} 3060}
2747 3061
3062
3063
3064/* Mark the pointers in the tty_display_info objects.
3065 Called by the Fgarbage_collector. */
3066
3067void
3068mark_ttys (void)
3069{
3070 struct tty_display_info *tty;
3071
3072 for (tty = tty_list; tty; tty = tty->next)
3073 {
3074 if (tty->top_frame)
3075 mark_object (tty->top_frame);
3076 }
3077}
3078
3079
3080
2748void 3081void
2749syms_of_term () 3082syms_of_term ()
2750{ 3083{
@@ -2757,10 +3090,18 @@ This variable can be used by terminal emulator packages. */);
2757 system_uses_terminfo = 0; 3090 system_uses_terminfo = 0;
2758#endif 3091#endif
2759 3092
2760 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function, 3093 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
2761 doc: /* Non-nil means call this function to ring the bell. 3094 doc: /* Functions to be run after suspending a tty.
2762The function should accept no arguments. */); 3095The functions are run with one argument, the terminal id to be suspended.
2763 Vring_bell_function = Qnil; 3096See `suspend-tty'. */);
3097 Vsuspend_tty_functions = Qnil;
3098
3099
3100 DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions,
3101 doc: /* Functions to be run after resuming a tty.
3102The functions are run with one argument, the terminal id that was revived.
3103See `resume-tty'. */);
3104 Vresume_tty_functions = Qnil;
2764 3105
2765 DEFVAR_BOOL ("visible-cursor", &visible_cursor, 3106 DEFVAR_BOOL ("visible-cursor", &visible_cursor,
2766 doc: /* Non-nil means to make the cursor very visible. 3107 doc: /* Non-nil means to make the cursor very visible.
@@ -2772,9 +3113,13 @@ bigger, or it may make it blink, or it may do nothing at all. */);
2772 defsubr (&Stty_display_color_p); 3113 defsubr (&Stty_display_color_p);
2773 defsubr (&Stty_display_color_cells); 3114 defsubr (&Stty_display_color_cells);
2774 defsubr (&Stty_no_underline); 3115 defsubr (&Stty_no_underline);
2775 3116 defsubr (&Stty_type);
2776 fullscreen_hook = NULL; 3117 defsubr (&Scontrolling_tty_p);
3118 defsubr (&Ssuspend_tty);
3119 defsubr (&Sresume_tty);
2777} 3120}
2778 3121
3122
3123
2779/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 3124/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2780 (do not change this comment) */ 3125 (do not change this comment) */
diff --git a/src/termchar.h b/src/termchar.h
index d5843bcf659..9bc3e21d220 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -19,32 +19,185 @@ along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */ 20Boston, MA 02110-1301, USA. */
21 21
22/* Each termcap frame points to its own struct tty_output object in
23 the output_data.tty field. The tty_output structure contains the
24 information that is specific to termcap frames. */
22 25
23/* extern EMACS_INT baud_rate; */ /* Output speed in baud */ 26struct tty_output
24extern int must_write_spaces; /* Nonzero means spaces in the text 27{
25 must actually be output; can't just skip 28 /* The Emacs structure for the tty device this frame is on. */
26 over some columns to leave them blank. */ 29 struct tty_display_info *display_info;
27extern int min_padding_speed; /* Speed below which no padding necessary */ 30
28extern int fast_clear_end_of_line; /* Nonzero means terminal has 31 /* There is nothing else here at the moment... */
29 command for this */ 32};
30 33
31extern int line_ins_del_ok; /* Terminal can insert and delete lines */ 34/* Parameters that are shared between frames on the same tty device. */
32extern int char_ins_del_ok; /* Terminal can insert and delete chars */ 35
33extern int scroll_region_ok; /* Terminal supports setting the scroll 36struct tty_display_info
34 window */ 37{
35extern int scroll_region_cost; /* Cost of setting the scroll window, 38 struct tty_display_info *next; /* Chain of all tty devices. */
36 measured in characters */ 39
37extern int memory_below_frame; /* Terminal remembers lines scrolled 40 char *name; /* The name of the device file or 0 if
38 off bottom */ 41 stdin/stdout. */
39extern int fast_clear_end_of_line; /* Terminal has a `ce' string */ 42 char *type; /* The type of the tty. */
40 43
41extern int dont_calculate_costs; /* Nonzero means don't bother computing 44 /* Input/output */
42 various cost tables; we won't use them. */ 45
43 46 FILE *input; /* The stream to be used for terminal input.
44/* Nonzero means no need to redraw the entire frame on resuming 47 NULL if the terminal is suspended. */
45 a suspended Emacs. This is useful on terminals with multiple pages, 48 FILE *output; /* The stream to be used for terminal output.
46 where one page is used for Emacs and another for all else. */ 49 NULL if the terminal is suspended. */
47extern int no_redraw_on_reenter; 50
51 FILE *termscript; /* If nonzero, send all terminal output
52 characters to this stream also. */
53
54 struct emacs_tty *old_tty; /* The initial tty mode bits */
55
56 int term_initted; /* 1 if we have been through init_sys_modes. */
57
58
59 int reference_count; /* Number of frames that are on this display. */
60
61 struct terminal *terminal; /* Points back to the generic terminal
62 structure. This is sometimes handy. */
63
64 /* Info on cursor positioning. */
65 struct cm *Wcm;
66
67 /* Redisplay. */
68
69 Lisp_Object top_frame; /* The topmost frame on this tty. */
70
71 /* The previous frame we displayed on this tty. */
72 struct frame *previous_frame;
73
74 /* Strings, numbers and flags taken from the termcap entry. */
75
76 char *TS_ins_line; /* "al" */
77 char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
78 char *TS_bell; /* "bl" */
79 char *TS_clr_to_bottom; /* "cd" */
80 char *TS_clr_line; /* "ce", clear to end of line */
81 char *TS_clr_frame; /* "cl" */
82 char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
83 char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
84 lines above scroll region, lines below it,
85 total lines again) */
86 char *TS_del_char; /* "dc" */
87 char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
88 char *TS_del_line; /* "dl" */
89 char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
90 char *TS_delete_mode; /* "dm", enter character-delete mode */
91 char *TS_end_delete_mode; /* "ed", leave character-delete mode */
92 char *TS_end_insert_mode; /* "ei", leave character-insert mode */
93 char *TS_ins_char; /* "ic" */
94 char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
95 char *TS_insert_mode; /* "im", enter character-insert mode */
96 char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
97 char *TS_end_keypad_mode; /* "ke" */
98 char *TS_keypad_mode; /* "ks" */
99 char *TS_pad_char; /* "pc", char to use as padding */
100 char *TS_repeat; /* "rp" (2 params, # times to repeat
101 and character to be repeated) */
102 char *TS_end_standout_mode; /* "se" */
103 char *TS_fwd_scroll; /* "sf" */
104 char *TS_standout_mode; /* "so" */
105 char *TS_rev_scroll; /* "sr" */
106 char *TS_end_termcap_modes; /* "te" */
107 char *TS_termcap_modes; /* "ti" */
108 char *TS_visible_bell; /* "vb" */
109 char *TS_cursor_normal; /* "ve" */
110 char *TS_cursor_visible; /* "vs" */
111 char *TS_cursor_invisible; /* "vi" */
112 char *TS_set_window; /* "wi" (4 params, start and end of window,
113 each as vpos and hpos) */
114
115 char *TS_enter_bold_mode; /* "md" -- turn on bold (extra bright mode). */
116 char *TS_enter_dim_mode; /* "mh" -- turn on half-bright mode. */
117 char *TS_enter_blink_mode; /* "mb" -- enter blinking mode. */
118 char *TS_enter_reverse_mode; /* "mr" -- enter reverse video mode. */
119 char *TS_exit_underline_mode; /* "us" -- start underlining. */
120 char *TS_enter_underline_mode; /* "ue" -- end underlining. */
121
122 /* "as"/"ae" -- start/end alternate character set. Not really
123 supported, yet. */
124 char *TS_enter_alt_charset_mode;
125 char *TS_exit_alt_charset_mode;
126
127 char *TS_exit_attribute_mode; /* "me" -- switch appearances off. */
128
129 /* Value of the "NC" (no_color_video) capability, or 0 if not present. */
130 int TN_no_color_video;
131
132 int TN_max_colors; /* "Co" -- number of colors. */
133
134 /* "pa" -- max. number of color pairs on screen. Not handled yet.
135 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
136 int TN_max_pairs;
137
138 /* "op" -- SVr4 set default pair to its original value. */
139 char *TS_orig_pair;
140
141 /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
142 1 param, the color index. */
143 char *TS_set_foreground;
144 char *TS_set_background;
145
146 int TF_hazeltine; /* termcap hz flag. */
147 int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
148 int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
149 int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
150 non-blank position. Must clear before writing _. */
151 int TF_teleray; /* termcap xt flag: many weird consequences.
152 For t1061. */
153
154 int RPov; /* # chars to start a TS_repeat */
155
156 int delete_in_insert_mode; /* delete mode == insert mode */
157
158 int se_is_so; /* 1 if same string both enters and leaves
159 standout mode */
160
161 int costs_set; /* Nonzero if costs have been calculated. */
162
163 int insert_mode; /* Nonzero when in insert mode. */
164 int standout_mode; /* Nonzero when in standout mode. */
165
166
167
168 /* 1 if should obey 0200 bit in input chars as "Meta", 2 if should
169 keep 0200 bit in input chars. 0 to ignore the 0200 bit. */
170
171 int meta_key;
172
173 /* Size of window specified by higher levels.
174 This is the number of lines, from the top of frame downwards,
175 which can participate in insert-line/delete-line operations.
176
177 Effectively it excludes the bottom frame_lines - specified_window_size
178 lines from those operations. */
179
180 int specified_window;
181
182 /* Flag used in tty_show/hide_cursor. */
183
184 int cursor_hidden;
185
186 /* Nonzero means use ^S/^Q for flow control. */
187 int flow_control;
188
189};
190
191/* A chain of structures for all tty devices currently in use. */
192extern struct tty_display_info *tty_list;
193
194
195#define FRAME_TTY(f) \
196 ((f)->output_method == output_termcap \
197 ? (f)->terminal->display_info.tty \
198 : (abort(), (struct tty_display_info *) 0))
199
200#define CURTTY() FRAME_TTY (SELECTED_FRAME())
48 201
49/* arch-tag: bf9f0d49-842b-42fb-9348-ec8759b27193 202/* arch-tag: bf9f0d49-842b-42fb-9348-ec8759b27193
50 (do not change this comment) */ 203 (do not change this comment) */
diff --git a/src/termhooks.h b/src/termhooks.h
index 8aef23bc2a7..72e0940cea6 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -1,7 +1,6 @@
1/* Hooks by which low level terminal operations 1/* Parameters and display hooks for terminal devices.
2 can be made to call other routines. 2 Copyright (C) 1985, 1986, 1993, 1994, 2002, 2003, 2004,
3 Copyright (C) 1985, 1986, 1993, 1994, 2001, 2002, 2003, 2004, 3 2005, 2006, 2007 Free Software Foundation, Inc.
4 2005, 2006, 2007 Free Software Foundation, Inc.
5 4
6This file is part of GNU Emacs. 5This file is part of GNU Emacs.
7 6
@@ -26,40 +25,11 @@ Boston, MA 02110-1301, USA. */
26struct glyph; 25struct glyph;
27struct frame; 26struct frame;
28 27
29/* If nonzero, send all terminal output characters to this stream also. */
30extern FILE *termscript;
31
32/* Only use prototypes when lisp.h has been included. */ 28/* Only use prototypes when lisp.h has been included. */
33#ifndef P_ 29#ifndef P_
34#define P_(X) () 30#define P_(X) ()
35#endif 31#endif
36 32
37/* Text display hooks. */
38
39extern void (*cursor_to_hook) P_ ((int vpos, int hpos));
40extern void (*raw_cursor_to_hook) P_ ((int, int));
41
42extern void (*clear_to_end_hook) P_ ((void));
43extern void (*clear_frame_hook) P_ ((void));
44extern void (*clear_end_of_line_hook) P_ ((int));
45
46extern void (*ins_del_lines_hook) P_ ((int, int));
47
48extern void (*insert_glyphs_hook) P_ ((struct glyph *s, int n));
49extern void (*write_glyphs_hook) P_ ((struct glyph *s, int n));
50extern void (*delete_glyphs_hook) P_ ((int));
51
52extern void (*ring_bell_hook) P_ ((void));
53
54extern void (*reset_terminal_modes_hook) P_ ((void));
55extern void (*set_terminal_modes_hook) P_ ((void));
56extern void (*update_begin_hook) P_ ((struct frame *));
57extern void (*update_end_hook) P_ ((struct frame *));
58extern void (*set_terminal_window_hook) P_ ((int));
59
60
61
62/* Multi-frame and mouse support hooks. */
63 33
64enum scroll_bar_part { 34enum scroll_bar_part {
65 scroll_bar_above_handle, 35 scroll_bar_above_handle,
@@ -73,131 +43,12 @@ enum scroll_bar_part {
73 scroll_bar_move_ratio 43 scroll_bar_move_ratio
74}; 44};
75 45
76/* Return the current position of the mouse.
77
78 Set *f to the frame the mouse is in, or zero if the mouse is in no
79 Emacs frame. If it is set to zero, all the other arguments are
80 garbage.
81
82 If the motion started in a scroll bar, set *bar_window to the
83 scroll bar's window, *part to the part the mouse is currently over,
84 *x to the position of the mouse along the scroll bar, and *y to the
85 overall length of the scroll bar.
86
87 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
88 row of the character cell the mouse is over.
89
90 Set *time to the time the mouse was at the returned position.
91
92 This should clear mouse_moved until the next motion
93 event arrives. */
94extern void (*mouse_position_hook) P_ ((struct frame **f, int,
95 Lisp_Object *bar_window,
96 enum scroll_bar_part *part,
97 Lisp_Object *x,
98 Lisp_Object *y,
99 unsigned long *time));
100
101/* The window system handling code should set this if the mouse has
102 moved since the last call to the mouse_position_hook. Calling that
103 hook should clear this. */
104extern int mouse_moved;
105
106/* When a frame's focus redirection is changed, this hook tells the
107 window system code to re-decide where to put the highlight. Under
108 X, this means that Emacs lies about where the focus is. */
109extern void (*frame_rehighlight_hook) P_ ((struct frame *));
110
111/* If we're displaying frames using a window system that can stack
112 frames on top of each other, this hook allows you to bring a frame
113 to the front, or bury it behind all the other windows. If this
114 hook is zero, that means the device we're displaying on doesn't
115 support overlapping frames, so there's no need to raise or lower
116 anything.
117
118 If RAISE is non-zero, F is brought to the front, before all other
119 windows. If RAISE is zero, F is sent to the back, behind all other
120 windows. */
121extern void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise));
122
123/* If the value of the frame parameter changed, whis hook is called. 46/* If the value of the frame parameter changed, whis hook is called.
124 For example, if going from fullscreen to not fullscreen this hook 47 For example, if going from fullscreen to not fullscreen this hook
125 may do something OS dependent, like extended window manager hints on X11. */ 48 may do something OS dependent, like extended window manager hints on X11. */
126extern void (*fullscreen_hook) P_ ((struct frame *f)); 49extern void (*fullscreen_hook) P_ ((struct frame *f));
127 50
128 51
129/* Scroll bar hooks. */
130
131/* The representation of scroll bars is determined by the code which
132 implements them, except for one thing: they must be represented by
133 lisp objects. This allows us to place references to them in
134 Lisp_Windows without worrying about those references becoming
135 dangling references when the scroll bar is destroyed.
136
137 The window-system-independent portion of Emacs just refers to
138 scroll bars via their windows, and never looks inside the scroll bar
139 representation; it always uses hook functions to do all the
140 scroll bar manipulation it needs.
141
142 The `vertical_scroll_bar' field of a Lisp_Window refers to that
143 window's scroll bar, or is nil if the window doesn't have a
144 scroll bar.
145
146 The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame
147 are free for use by the scroll bar implementation in any way it sees
148 fit. They are marked by the garbage collector. */
149
150
151/* Set the vertical scroll bar for WINDOW to have its upper left corner
152 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
153 indicate that we are displaying PORTION characters out of a total
154 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
155 have a scroll bar, create one for it. */
156extern void (*set_vertical_scroll_bar_hook)
157 P_ ((struct window *window,
158 int portion, int whole, int position));
159
160
161/* The following three hooks are used when we're doing a thorough
162 redisplay of the frame. We don't explicitly know which scroll bars
163 are going to be deleted, because keeping track of when windows go
164 away is a real pain - can you say set-window-configuration?
165 Instead, we just assert at the beginning of redisplay that *all*
166 scroll bars are to be removed, and then save scroll bars from the
167 fiery pit when we actually redisplay their window. */
168
169/* Arrange for all scroll bars on FRAME to be removed at the next call
170 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
171 `*redeem_scroll_bar_hook' is applied to its window before the judgement.
172
173 This should be applied to each frame each time its window tree is
174 redisplayed, even if it is not displaying scroll bars at the moment;
175 if the HAS_SCROLL_BARS flag has just been turned off, only calling
176 this and the judge_scroll_bars_hook will get rid of them.
177
178 If non-zero, this hook should be safe to apply to any frame,
179 whether or not it can support scroll bars, and whether or not it is
180 currently displaying them. */
181extern void (*condemn_scroll_bars_hook) P_ ((struct frame *frame));
182
183/* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
184 Note that it's okay to redeem a scroll bar that is not condemned. */
185extern void (*redeem_scroll_bar_hook) P_ ((struct window *window));
186
187/* Remove all scroll bars on FRAME that haven't been saved since the
188 last call to `*condemn_scroll_bars_hook'.
189
190 This should be applied to each frame after each time its window
191 tree is redisplayed, even if it is not displaying scroll bars at the
192 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
193 calling this and condemn_scroll_bars_hook will get rid of them.
194
195 If non-zero, this hook should be safe to apply to any frame,
196 whether or not it can support scroll bars, and whether or not it is
197 currently displaying them. */
198extern void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME));
199
200
201/* Input queue declarations and hooks. */ 52/* Input queue declarations and hooks. */
202 53
203/* Expedient hack: only provide the below definitions to files that 54/* Expedient hack: only provide the below definitions to files that
@@ -390,13 +241,6 @@ struct input_event
390 241
391#define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event)) 242#define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event))
392 243
393/* Called to read input events. */
394extern int (*read_socket_hook) P_ ((int, int, struct input_event *));
395
396/* Called when a frame's display becomes entirely up to date. */
397extern void (*frame_up_to_date_hook) P_ ((struct frame *));
398
399
400/* Bits in the modifiers member of the input_event structure. 244/* Bits in the modifiers member of the input_event structure.
401 Note that reorder_modifiers assumes that the bits are in canonical 245 Note that reorder_modifiers assumes that the bits are in canonical
402 order. 246 order.
@@ -446,7 +290,334 @@ enum {
446 meta_modifier = CHAR_META /* Under X, the XK_Meta_[LR] keysyms. */ 290 meta_modifier = CHAR_META /* Under X, the XK_Meta_[LR] keysyms. */
447}; 291};
448 292
293#endif /* CONSP */
294
295
296/* Terminal-local parameters. */
297struct terminal
298{
299 /* Chain of all terminal devices. */
300 struct terminal *next_terminal;
301
302 /* Unique id for this terminal device. */
303 int id;
304
305 /* The number of frames that are on this terminal. */
306 int reference_count;
307
308 /* Nonzero while deleting this terminal. Used to protect against
309 recursive calls to delete_terminal_hook. */
310 int deleted;
311
312 /* The type of the terminal device. */
313 enum output_method type;
314
315 /* The name of the terminal device. Do not use this to uniquely
316 identify a terminal; the same device may be opened multiple
317 times. */
318 char *name;
319
320#ifdef MULTI_KBOARD
321 /* The terminal's keyboard object. */
322 struct kboard *kboard;
323#endif
324
325 /* Device-type dependent data shared amongst all frames on this terminal. */
326 union display_info
327 {
328 struct tty_display_info *tty; /* termchar.h */
329 struct x_display_info *x; /* xterm.h */
330 } display_info;
331
332
333 /* Coding-system to be used for encoding terminal output. This
334 structure contains information of a coding-system specified by
335 the function `set-terminal-coding-system'. Also see
336 `safe_terminal_coding' in coding.h. */
337 struct coding_system *terminal_coding;
338
339 /* Coding-system of what is sent from terminal keyboard. This
340 structure contains information of a coding-system specified by
341 the function `set-keyboard-coding-system'. */
342 struct coding_system *keyboard_coding;
343
344 /* Parameter alist of this terminal. */
345 Lisp_Object param_alist;
346
347 /* Terminal characteristics. */
348 /* XXX Are these really used on non-termcap displays? */
349
350 int must_write_spaces; /* Nonzero means spaces in the text must
351 actually be output; can't just skip over
352 some columns to leave them blank. */
353 int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */
354
355 int line_ins_del_ok; /* Terminal can insert and delete lines */
356 int char_ins_del_ok; /* Terminal can insert and delete chars */
357 int scroll_region_ok; /* Terminal supports setting the scroll
358 window */
359 int scroll_region_cost; /* Cost of setting the scroll window,
360 measured in characters. */
361 int memory_below_frame; /* Terminal remembers lines scrolled
362 off bottom */
363
364#if 0 /* These are not used anywhere. */
365 /* EMACS_INT baud_rate; */ /* Output speed in baud */
366 int min_padding_speed; /* Speed below which no padding necessary. */
367 int dont_calculate_costs; /* Nonzero means don't bother computing
368 various cost tables; we won't use them. */
369#endif
370
371
372 /* Window-based redisplay interface for this device (0 for tty
373 devices). */
374 struct redisplay_interface *rif;
375
376 /* Frame-based redisplay interface. */
377
378 /* Text display hooks. */
379
380 void (*cursor_to_hook) P_ ((struct frame *f, int vpos, int hpos));
381 void (*raw_cursor_to_hook) P_ ((struct frame *, int, int));
382
383 void (*clear_to_end_hook) P_ ((struct frame *));
384 void (*clear_frame_hook) P_ ((struct frame *));
385 void (*clear_end_of_line_hook) P_ ((struct frame *, int));
386
387 void (*ins_del_lines_hook) P_ ((struct frame *f, int, int));
388
389 void (*insert_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
390 void (*write_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
391 void (*delete_glyphs_hook) P_ ((struct frame *, int));
392
393 void (*ring_bell_hook) P_ ((struct frame *f));
394
395 void (*reset_terminal_modes_hook) P_ ((struct terminal *));
396 void (*set_terminal_modes_hook) P_ ((struct terminal *));
397
398 void (*update_begin_hook) P_ ((struct frame *));
399 void (*update_end_hook) P_ ((struct frame *));
400 void (*set_terminal_window_hook) P_ ((struct frame *, int));
401
402 /* Multi-frame and mouse support hooks. */
403
404 /* Return the current position of the mouse.
405
406 Set *f to the frame the mouse is in, or zero if the mouse is in no
407 Emacs frame. If it is set to zero, all the other arguments are
408 garbage.
409
410 If the motion started in a scroll bar, set *bar_window to the
411 scroll bar's window, *part to the part the mouse is currently over,
412 *x to the position of the mouse along the scroll bar, and *y to the
413 overall length of the scroll bar.
414
415 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
416 row of the character cell the mouse is over.
417
418 Set *time to the time the mouse was at the returned position.
419
420 This should clear mouse_moved until the next motion
421 event arrives. */
422 void (*mouse_position_hook) P_ ((struct frame **f, int,
423 Lisp_Object *bar_window,
424 enum scroll_bar_part *part,
425 Lisp_Object *x,
426 Lisp_Object *y,
427 unsigned long *time));
428
429 /* The window system handling code should set this if the mouse has
430 moved since the last call to the mouse_position_hook. Calling that
431 hook should clear this. */
432 int mouse_moved;
433
434 /* When a frame's focus redirection is changed, this hook tells the
435 window system code to re-decide where to put the highlight. Under
436 X, this means that Emacs lies about where the focus is. */
437 void (*frame_rehighlight_hook) P_ ((struct frame *));
438
439 /* If we're displaying frames using a window system that can stack
440 frames on top of each other, this hook allows you to bring a frame
441 to the front, or bury it behind all the other windows. If this
442 hook is zero, that means the terminal we're displaying on doesn't
443 support overlapping frames, so there's no need to raise or lower
444 anything.
445
446 If RAISE is non-zero, F is brought to the front, before all other
447 windows. If RAISE is zero, F is sent to the back, behind all other
448 windows. */
449 void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise));
450
451 /* If the value of the frame parameter changed, whis hook is called.
452 For example, if going from fullscreen to not fullscreen this hook
453 may do something OS dependent, like extended window manager hints on X11. */
454 void (*fullscreen_hook) P_ ((struct frame *f));
455
456
457 /* Scroll bar hooks. */
458
459 /* The representation of scroll bars is determined by the code which
460 implements them, except for one thing: they must be represented by
461 lisp objects. This allows us to place references to them in
462 Lisp_Windows without worrying about those references becoming
463 dangling references when the scroll bar is destroyed.
464
465 The window-system-independent portion of Emacs just refers to
466 scroll bars via their windows, and never looks inside the scroll bar
467 representation; it always uses hook functions to do all the
468 scroll bar manipulation it needs.
469
470 The `vertical_scroll_bar' field of a Lisp_Window refers to that
471 window's scroll bar, or is nil if the window doesn't have a
472 scroll bar.
473
474 The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame
475 are free for use by the scroll bar implementation in any way it sees
476 fit. They are marked by the garbage collector. */
477
478
479 /* Set the vertical scroll bar for WINDOW to have its upper left corner
480 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
481 indicate that we are displaying PORTION characters out of a total
482 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
483 have a scroll bar, create one for it. */
484 void (*set_vertical_scroll_bar_hook) P_ ((struct window *window,
485 int portion, int whole,
486 int position));
487
488
489 /* The following three hooks are used when we're doing a thorough
490 redisplay of the frame. We don't explicitly know which scroll bars
491 are going to be deleted, because keeping track of when windows go
492 away is a real pain - can you say set-window-configuration?
493 Instead, we just assert at the beginning of redisplay that *all*
494 scroll bars are to be removed, and then save scroll bars from the
495 fiery pit when we actually redisplay their window. */
496
497 /* Arrange for all scroll bars on FRAME to be removed at the next call
498 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
499 `*redeem_scroll_bar_hook' is applied to its window before the judgement.
500
501 This should be applied to each frame each time its window tree is
502 redisplayed, even if it is not displaying scroll bars at the moment;
503 if the HAS_SCROLL_BARS flag has just been turned off, only calling
504 this and the judge_scroll_bars_hook will get rid of them.
505
506 If non-zero, this hook should be safe to apply to any frame,
507 whether or not it can support scroll bars, and whether or not it is
508 currently displaying them. */
509 void (*condemn_scroll_bars_hook) P_ ((struct frame *frame));
510
511 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
512 Note that it's okay to redeem a scroll bar that is not condemned. */
513 void (*redeem_scroll_bar_hook) P_ ((struct window *window));
514
515 /* Remove all scroll bars on FRAME that haven't been saved since the
516 last call to `*condemn_scroll_bars_hook'.
517
518 This should be applied to each frame after each time its window
519 tree is redisplayed, even if it is not displaying scroll bars at the
520 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
521 calling this and condemn_scroll_bars_hook will get rid of them.
522
523 If non-zero, this hook should be safe to apply to any frame,
524 whether or not it can support scroll bars, and whether or not it is
525 currently displaying them. */
526 void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME));
527
528
529 /* Called to read input events.
530
531 TERMINAL indicates which terminal device to read from. Input
532 events should be read into BUF, the size of which is given in
533 SIZE. EXPECTED is non-zero if the caller suspects that new input
534 is available.
535
536 A positive return value indicates that that many input events
537 where read into BUF.
538 Zero means no events were immediately available.
539 A value of -1 means a transient read error, while -2 indicates
540 that the device was closed (hangup), and it should be deleted.
541
542 XXX Please note that a non-zero value of EXPECTED only means that
543 there is available input on at least one of the currently opened
544 terminal devices -- but not necessarily on this device.
545 Therefore, in most cases EXPECTED should be simply ignored.
546
547 XXX This documentation needs to be updated. */
548 int (*read_socket_hook) P_ ((struct terminal *terminal,
549 int expected,
550 struct input_event *hold_quit));
551
552 /* Called when a frame's display becomes entirely up to date. */
553 void (*frame_up_to_date_hook) P_ ((struct frame *));
554
555
556 /* Called to delete the device-specific portions of a frame that is
557 on this terminal device. */
558 void (*delete_frame_hook) P_ ((struct frame *));
559
560 /* Called after the last frame on this terminal is deleted, or when
561 the display device was closed (hangup).
562
563 If this is NULL, then the generic delete_terminal is called
564 instead. Otherwise the hook must call delete_terminal itself.
565
566 The hook must check for and close any live frames that are still
567 on the terminal. Fdelete_frame ensures that there are no live
568 frames on the terminal when it calls this hook, so infinite
569 recursion is prevented. */
570 void (*delete_terminal_hook) P_ ((struct terminal *));
571};
572
573
574/* Chain of all terminal devices currently in use. */
575extern struct terminal *terminal_list;
576
577#define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces)
578#define FRAME_FAST_CLEAR_END_OF_LINE(f) ((f)->terminal->fast_clear_end_of_line)
579#define FRAME_LINE_INS_DEL_OK(f) ((f)->terminal->line_ins_del_ok)
580#define FRAME_CHAR_INS_DEL_OK(f) ((f)->terminal->char_ins_del_ok)
581#define FRAME_SCROLL_REGION_OK(f) ((f)->terminal->scroll_region_ok)
582#define FRAME_SCROLL_REGION_COST(f) ((f)->terminal->scroll_region_cost)
583#define FRAME_MEMORY_BELOW_FRAME(f) ((f)->terminal->memory_below_frame)
584
585#define FRAME_TERMINAL_CODING(f) ((f)->terminal->terminal_coding)
586#define FRAME_KEYBOARD_CODING(f) ((f)->terminal->keyboard_coding)
587
588#define TERMINAL_TERMINAL_CODING(d) ((d)->terminal_coding)
589#define TERMINAL_KEYBOARD_CODING(d) ((d)->keyboard_coding)
590
591#define FRAME_RIF(f) ((f)->terminal->rif)
592
593#define FRAME_TERMINAL(f) ((f)->terminal)
594
595/* FRAME_WINDOW_P tests whether the frame is a window, and is
596 defined to be the predicate for the window system being used. */
597
598#ifdef HAVE_X_WINDOWS
599#define FRAME_WINDOW_P(f) FRAME_X_P (f)
449#endif 600#endif
601#ifdef HAVE_NTGUI
602#define FRAME_WINDOW_P(f) FRAME_W32_P (f)
603#endif
604#ifdef MAC_OS
605#define FRAME_WINDOW_P(f) FRAME_MAC_P (f)
606#endif
607#ifndef FRAME_WINDOW_P
608#define FRAME_WINDOW_P(f) (0)
609#endif
610
611/* Return true if the terminal device is not suspended. */
612#define TERMINAL_ACTIVE_P(d) ((d)->type != output_termcap || (d)->display_info.tty->input)
613
614extern Lisp_Object get_terminal_param P_ ((struct terminal *, Lisp_Object));
615extern struct terminal *get_terminal P_ ((Lisp_Object terminal, int));
616extern struct terminal *create_terminal P_ ((void));
617extern void delete_terminal P_ ((struct terminal *));
618
619/* The initial terminal device, created by initial_term_init. */
620extern struct terminal *initial_terminal;
450 621
451/* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d 622/* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d
452 (do not change this comment) */ 623 (do not change this comment) */
diff --git a/src/terminal.c b/src/terminal.c
new file mode 100644
index 00000000000..f3f0a178c8d
--- /dev/null
+++ b/src/terminal.c
@@ -0,0 +1,628 @@
1/* Functions related to terminal devices.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19Boston, MA 02110-1301, USA. */
20
21#include <config.h>
22#include <stdio.h>
23
24#include "lisp.h"
25#include "frame.h"
26#include "termchar.h"
27#include "termhooks.h"
28#include "charset.h"
29#include "coding.h"
30#include "keyboard.h"
31
32/* Chain of all terminals currently in use. */
33struct terminal *terminal_list;
34
35/* The first unallocated terminal id. */
36static int next_terminal_id;
37
38/* The initial terminal device, created by initial_term_init. */
39struct terminal *initial_terminal;
40
41/* Function to use to ring the bell. */
42Lisp_Object Vring_bell_function;
43
44static void delete_initial_terminal P_ ((struct terminal *));
45
46
47
48void
49ring_bell (struct frame *f)
50{
51 if (!NILP (Vring_bell_function))
52 {
53 Lisp_Object function;
54
55 /* Temporarily set the global variable to nil
56 so that if we get an error, it stays nil
57 and we don't call it over and over.
58
59 We don't specbind it, because that would carefully
60 restore the bad value if there's an error
61 and make the loop of errors happen anyway. */
62
63 function = Vring_bell_function;
64 Vring_bell_function = Qnil;
65
66 call0 (function);
67
68 Vring_bell_function = function;
69 }
70 else if (FRAME_TERMINAL (f)->ring_bell_hook)
71 (*FRAME_TERMINAL (f)->ring_bell_hook) (f);
72}
73
74void
75update_begin (struct frame *f)
76{
77 if (FRAME_TERMINAL (f)->update_begin_hook)
78 (*FRAME_TERMINAL (f)->update_begin_hook) (f);
79}
80
81void
82update_end (struct frame *f)
83{
84 if (FRAME_TERMINAL (f)->update_end_hook)
85 (*FRAME_TERMINAL (f)->update_end_hook) (f);
86}
87
88/* Specify how many text lines, from the top of the window,
89 should be affected by insert-lines and delete-lines operations.
90 This, and those operations, are used only within an update
91 that is bounded by calls to update_begin and update_end. */
92
93void
94set_terminal_window (struct frame *f, int size)
95{
96 if (FRAME_TERMINAL (f)->set_terminal_window_hook)
97 (*FRAME_TERMINAL (f)->set_terminal_window_hook) (f, size);
98}
99
100/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
101 frame-relative coordinates. */
102
103void
104cursor_to (struct frame *f, int vpos, int hpos)
105{
106 if (FRAME_TERMINAL (f)->cursor_to_hook)
107 (*FRAME_TERMINAL (f)->cursor_to_hook) (f, vpos, hpos);
108}
109
110/* Similar but don't take any account of the wasted characters. */
111
112void
113raw_cursor_to (struct frame *f, int row, int col)
114{
115 if (FRAME_TERMINAL (f)->raw_cursor_to_hook)
116 (*FRAME_TERMINAL (f)->raw_cursor_to_hook) (f, row, col);
117}
118
119/* Erase operations */
120
121/* Clear from cursor to end of frame. */
122void
123clear_to_end (struct frame *f)
124{
125 if (FRAME_TERMINAL (f)->clear_to_end_hook)
126 (*FRAME_TERMINAL (f)->clear_to_end_hook) (f);
127}
128
129/* Clear entire frame */
130
131void
132clear_frame (struct frame *f)
133{
134 if (FRAME_TERMINAL (f)->clear_frame_hook)
135 (*FRAME_TERMINAL (f)->clear_frame_hook) (f);
136}
137
138/* Clear from cursor to end of line.
139 Assume that the line is already clear starting at column first_unused_hpos.
140
141 Note that the cursor may be moved, on terminals lacking a `ce' string. */
142
143void
144clear_end_of_line (struct frame *f, int first_unused_hpos)
145{
146 if (FRAME_TERMINAL (f)->clear_end_of_line_hook)
147 (*FRAME_TERMINAL (f)->clear_end_of_line_hook) (f, first_unused_hpos);
148}
149
150/* Output LEN glyphs starting at STRING at the nominal cursor position.
151 Advance the nominal cursor over the text. */
152
153void
154write_glyphs (struct frame *f, struct glyph *string, int len)
155{
156 if (FRAME_TERMINAL (f)->write_glyphs_hook)
157 (*FRAME_TERMINAL (f)->write_glyphs_hook) (f, string, len);
158}
159
160/* Insert LEN glyphs from START at the nominal cursor position.
161
162 If start is zero, insert blanks instead of a string at start */
163
164void
165insert_glyphs (struct frame *f, struct glyph *start, int len)
166{
167 if (len <= 0)
168 return;
169
170 if (FRAME_TERMINAL (f)->insert_glyphs_hook)
171 (*FRAME_TERMINAL (f)->insert_glyphs_hook) (f, start, len);
172}
173
174/* Delete N glyphs at the nominal cursor position. */
175
176void
177delete_glyphs (struct frame *f, int n)
178{
179 if (FRAME_TERMINAL (f)->delete_glyphs_hook)
180 (*FRAME_TERMINAL (f)->delete_glyphs_hook) (f, n);
181}
182
183/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
184
185void
186ins_del_lines (struct frame *f, int vpos, int n)
187{
188 if (FRAME_TERMINAL (f)->ins_del_lines_hook)
189 (*FRAME_TERMINAL (f)->ins_del_lines_hook) (f, vpos, n);
190}
191
192
193
194
195/* Return the terminal object specified by TERMINAL. TERMINAL may be a
196 terminal id, a frame, or nil for the terminal device of the current
197 frame. If THROW is zero, return NULL for failure, otherwise throw
198 an error. */
199
200struct terminal *
201get_terminal (Lisp_Object terminal, int throw)
202{
203 struct terminal *result = NULL;
204
205 if (NILP (terminal))
206 terminal = selected_frame;
207
208 if (INTEGERP (terminal))
209 {
210 struct terminal *t;
211
212 for (t = terminal_list; t; t = t->next_terminal)
213 {
214 if (t->id == XINT (terminal))
215 {
216 result = t;
217 break;
218 }
219 }
220 }
221 else if (FRAMEP (terminal))
222 {
223 result = FRAME_TERMINAL (XFRAME (terminal));
224 }
225
226 if (result == NULL && throw)
227 wrong_type_argument (Qterminal_live_p, terminal);
228
229 return result;
230}
231
232
233
234/* Create a new terminal object and add it to the terminal list. */
235
236struct terminal *
237create_terminal (void)
238{
239 struct terminal *terminal = (struct terminal *) xmalloc (sizeof (struct terminal));
240
241 bzero (terminal, sizeof (struct terminal));
242 terminal->next_terminal = terminal_list;
243 terminal_list = terminal;
244
245 terminal->id = next_terminal_id++;
246
247 terminal->keyboard_coding =
248 (struct coding_system *) xmalloc (sizeof (struct coding_system));
249 terminal->terminal_coding =
250 (struct coding_system *) xmalloc (sizeof (struct coding_system));
251
252 setup_coding_system (Qnil, terminal->keyboard_coding);
253 setup_coding_system (Qnil, terminal->terminal_coding);
254
255 terminal->param_alist = Qnil;
256 return terminal;
257}
258
259/* Mark the Lisp pointers in the terminal objects.
260 Called by the Fgarbage_collector. */
261
262void
263mark_terminals (void)
264{
265 struct terminal *t;
266 for (t = terminal_list; t; t = t->next_terminal)
267 {
268 mark_object (t->param_alist);
269 }
270}
271
272
273/* Low-level function to close all frames on a terminal, remove it
274 from the terminal list and free its memory. */
275
276void
277delete_terminal (struct terminal *terminal)
278{
279 struct terminal **tp;
280 Lisp_Object tail, frame;
281
282 /* Protect against recursive calls. Fdelete_frame calls the
283 delete_terminal_hook when we delete our last frame. */
284 if (terminal->deleted)
285 return;
286 terminal->deleted = 1;
287
288 /* Check for live frames that are still on this terminal. */
289 FOR_EACH_FRAME (tail, frame)
290 {
291 struct frame *f = XFRAME (frame);
292 if (FRAME_LIVE_P (f) && f->terminal == terminal)
293 {
294 Fdelete_frame (frame, Qt);
295 }
296 }
297
298 for (tp = &terminal_list; *tp != terminal; tp = &(*tp)->next_terminal)
299 if (! *tp)
300 abort ();
301 *tp = terminal->next_terminal;
302
303 if (terminal->keyboard_coding)
304 xfree (terminal->keyboard_coding);
305 if (terminal->terminal_coding)
306 xfree (terminal->terminal_coding);
307 if (terminal->name)
308 xfree (terminal->name);
309
310#ifdef MULTI_KBOARD
311 if (terminal->kboard && --terminal->kboard->reference_count == 0)
312 delete_kboard (terminal->kboard);
313#endif
314
315 bzero (terminal, sizeof (struct terminal));
316 xfree (terminal);
317}
318
319DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0,
320 doc: /* Delete TERMINAL by deleting all frames on it and closing the terminal.
321TERMINAL may be a terminal id, a frame, or nil (meaning the selected
322frame's terminal).
323
324Normally, you may not delete a display if all other displays are suspended,
325but if the second argument FORCE is non-nil, you may do so. */)
326 (terminal, force)
327 Lisp_Object terminal, force;
328{
329 struct terminal *t, *p;
330
331 t = get_terminal (terminal, 0);
332
333 if (!t)
334 return Qnil;
335
336 p = terminal_list;
337 while (p && (p == t || !TERMINAL_ACTIVE_P (p)))
338 p = p->next_terminal;
339
340 if (NILP (force) && !p)
341 error ("Attempt to delete the sole active display terminal");
342
343 if (t->delete_terminal_hook)
344 (*t->delete_terminal_hook) (t);
345 else
346 delete_terminal (t);
347
348 return Qnil;
349}
350
351
352DEFUN ("frame-terminal", Fframe_terminal, Sframe_terminal, 0, 1, 0,
353 doc: /* Return the terminal that FRAME is displayed on.
354If FRAME is nil, the selected frame is used.
355
356The terminal device is represented by its integer identifier. */)
357 (frame)
358 Lisp_Object frame;
359{
360 struct terminal *t;
361
362 if (NILP (frame))
363 frame = selected_frame;
364
365 CHECK_LIVE_FRAME (frame);
366
367 t = get_terminal (frame, 0);
368
369 if (!t)
370 return Qnil;
371 else
372 return make_number (t->id);
373}
374
375DEFUN ("terminal-live-p", Fterminal_live_p, Sterminal_live_p, 1, 1, 0,
376 doc: /* Return non-nil if OBJECT is a terminal which has not been deleted.
377Value is nil if OBJECT is not a live display terminal.
378If object is a live display terminal, the return value indicates what
379sort of output terminal it uses. See the documentation of `framep' for
380possible return values.
381
382Display terminals are represented by their integer identifiers. */)
383 (object)
384 Lisp_Object object;
385{
386 struct terminal *t;
387
388 if (!INTEGERP (object))
389 return Qnil;
390
391 t = get_terminal (object, 0);
392
393 if (!t)
394 return Qnil;
395
396 switch (t->type)
397 {
398 case output_initial: /* The initial frame is like a termcap frame. */
399 case output_termcap:
400 return Qt;
401 case output_x_window:
402 return Qx;
403 case output_w32:
404 return Qw32;
405 case output_msdos_raw:
406 return Qpc;
407 case output_mac:
408 return Qmac;
409 default:
410 abort ();
411 }
412}
413
414DEFUN ("terminal-list", Fterminal_list, Sterminal_list, 0, 0, 0,
415 doc: /* Return a list of all terminal devices.
416Terminal devices are represented by their integer identifiers. */)
417 ()
418{
419 Lisp_Object terminals = Qnil;
420 struct terminal *t;
421
422 for (t = terminal_list; t; t = t->next_terminal)
423 terminals = Fcons (make_number (t->id), terminals);
424
425 return terminals;
426}
427
428DEFUN ("terminal-name", Fterminal_name, Sterminal_name, 0, 1, 0,
429 doc: /* Return the name of the terminal device TERMINAL.
430It is not guaranteed that the returned value is unique among opened devices.
431
432TERMINAL may be a terminal id, a frame, or nil (meaning the
433selected frame's terminal). */)
434 (terminal)
435 Lisp_Object terminal;
436{
437 struct terminal *t = get_terminal (terminal, 1);
438
439 if (t->name)
440 return build_string (t->name);
441 else
442 return Qnil;
443}
444
445
446
447/* Return the value of terminal parameter PARAM in terminal T. */
448Lisp_Object
449get_terminal_param (t, param)
450 struct terminal *t;
451 Lisp_Object param;
452{
453 Lisp_Object tem = Fassq (param, t->param_alist);
454 if (EQ (tem, Qnil))
455 return tem;
456 return Fcdr (tem);
457}
458
459/* Set the value of terminal parameter PARAMETER in terminal D to VALUE.
460 Return the previous value. */
461
462Lisp_Object
463store_terminal_param (t, parameter, value)
464 struct terminal *t;
465 Lisp_Object parameter;
466 Lisp_Object value;
467{
468 Lisp_Object old_alist_elt = Fassq (parameter, t->param_alist);
469 if (EQ (old_alist_elt, Qnil))
470 {
471 t->param_alist = Fcons (Fcons (parameter, value), t->param_alist);
472 return Qnil;
473 }
474 else
475 {
476 Lisp_Object result = Fcdr (old_alist_elt);
477 Fsetcdr (old_alist_elt, value);
478 return result;
479 }
480}
481
482
483DEFUN ("terminal-parameters", Fterminal_parameters, Sterminal_parameters, 0, 1, 0,
484 doc: /* Return the parameter-alist of terminal TERMINAL.
485The value is a list of elements of the form (PARM . VALUE), where PARM
486is a symbol.
487
488TERMINAL can be a terminal id, a frame or nil (meaning the selected
489frame's terminal). */)
490 (terminal)
491 Lisp_Object terminal;
492{
493 struct terminal *t = get_terminal (terminal, 1);
494 return Fcopy_alist (t->param_alist);
495}
496
497DEFUN ("terminal-parameter", Fterminal_parameter, Sterminal_parameter, 2, 2, 0,
498 doc: /* Return TERMINAL's value for parameter PARAMETER.
499TERMINAL can be a terminal id, a frame or nil (meaning the selected
500frame's terminal). */)
501 (terminal, parameter)
502 Lisp_Object terminal;
503 Lisp_Object parameter;
504{
505 Lisp_Object value;
506 struct terminal *t = get_terminal (terminal, 1);
507 CHECK_SYMBOL (parameter);
508 value = Fcdr (Fassq (parameter, t->param_alist));
509 return value;
510}
511
512DEFUN ("modify-terminal-parameters", Fmodify_terminal_parameters,
513 Smodify_terminal_parameters, 2, 2, 0,
514 doc: /* Modify the parameters of terminal TERMINAL according to ALIST.
515ALIST is an alist of parameters to change and their new values.
516Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
517
518TERMINAL can be a terminal id, a frame or nil (meaning the selected
519frame's terminal). */)
520 (terminal, alist)
521 Lisp_Object terminal;
522 Lisp_Object alist;
523{
524 Lisp_Object tail, prop, val;
525 struct terminal *t = get_terminal (terminal, 1);
526 int length = XINT (Fsafe_length (alist));
527 int i;
528 Lisp_Object *parms = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
529 Lisp_Object *values = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
530
531 /* Extract parm names and values into those vectors. */
532
533 i = 0;
534 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
535 {
536 Lisp_Object elt;
537
538 elt = Fcar (tail);
539 parms[i] = Fcar (elt);
540 values[i] = Fcdr (elt);
541 i++;
542 }
543
544 /* Now process them in reverse of specified order. */
545 for (i--; i >= 0; i--)
546 {
547 prop = parms[i];
548 val = values[i];
549 store_terminal_param (t, prop, val);
550 }
551 return Qnil;
552}
553
554DEFUN ("set-terminal-parameter", Fset_terminal_parameter,
555 Sset_terminal_parameter, 3, 3, 0,
556 doc: /* Set TERMINAL's value for parameter PARAMETER to VALUE.
557Return the previous value of PARAMETER.
558
559TERMINAL can be a terminal id, a frame or nil (meaning the selected
560frame's terminal). */)
561 (terminal, parameter, value)
562 Lisp_Object terminal;
563 Lisp_Object parameter;
564 Lisp_Object value;
565{
566 struct terminal *t = get_terminal (terminal, 1);
567 return store_terminal_param (t, parameter, value);
568}
569
570
571
572/* Create the bootstrap display terminal for the initial frame.
573 Returns a terminal of type output_initial. */
574
575struct terminal *
576init_initial_terminal (void)
577{
578 if (initialized || terminal_list || tty_list)
579 abort ();
580
581 initial_terminal = create_terminal ();
582 initial_terminal->type = output_initial;
583 initial_terminal->name = xstrdup ("initial_terminal");
584 initial_terminal->kboard = initial_kboard;
585
586 initial_terminal->delete_terminal_hook = &delete_initial_terminal;
587 /* All other hooks are NULL. */
588
589 return initial_terminal;
590}
591
592/* Deletes the bootstrap terminal device.
593 Called through delete_terminal_hook. */
594
595static void
596delete_initial_terminal (struct terminal *terminal)
597{
598 if (terminal != initial_terminal)
599 abort ();
600
601 delete_terminal (terminal);
602 initial_terminal = NULL;
603}
604
605void
606syms_of_terminal ()
607{
608
609 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function,
610 doc: /* Non-nil means call this function to ring the bell.
611The function should accept no arguments. */);
612 Vring_bell_function = Qnil;
613
614 defsubr (&Sdelete_terminal);
615 defsubr (&Sframe_terminal);
616 defsubr (&Sterminal_live_p);
617 defsubr (&Sterminal_list);
618 defsubr (&Sterminal_name);
619 defsubr (&Sterminal_parameters);
620 defsubr (&Sterminal_parameter);
621 defsubr (&Smodify_terminal_parameters);
622 defsubr (&Sset_terminal_parameter);
623
624 Fprovide (intern ("multi-tty"), Qnil);
625}
626
627/* arch-tag: e9af6f27-b483-47dc-bb1a-730c1c5cab03
628 (do not change this comment) */
diff --git a/src/termopts.h b/src/termopts.h
index dff634b5192..082f9b15af7 100644
--- a/src/termopts.h
+++ b/src/termopts.h
@@ -41,5 +41,10 @@ extern int meta_key;
41/* Nonzero means truncate lines in all windows less wide than the frame */ 41/* Nonzero means truncate lines in all windows less wide than the frame */
42extern int truncate_partial_width_windows; 42extern int truncate_partial_width_windows;
43 43
44/* Nonzero means no need to redraw the entire frame on resuming a suspended
45 Emacs. This is useful on terminals with multiple pages, where one page is
46 used for Emacs and another for all else. */
47extern int no_redraw_on_reenter;
48
44/* arch-tag: 35d4d284-dc1a-4fff-97fa-0154a21aebdb 49/* arch-tag: 35d4d284-dc1a-4fff-97fa-0154a21aebdb
45 (do not change this comment) */ 50 (do not change this comment) */
diff --git a/src/w32term.c b/src/w32term.c
index 77e85ca2274..e7118caa0d7 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -5870,8 +5870,8 @@ x_free_frame_resources (f)
5870 5870
5871 free_frame_menubar (f); 5871 free_frame_menubar (f);
5872 5872
5873 unload_color (f, f->output_data.x->foreground_pixel); 5873 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
5874 unload_color (f, f->output_data.x->background_pixel); 5874 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
5875 unload_color (f, f->output_data.w32->cursor_pixel); 5875 unload_color (f, f->output_data.w32->cursor_pixel);
5876 unload_color (f, f->output_data.w32->cursor_foreground_pixel); 5876 unload_color (f, f->output_data.w32->cursor_foreground_pixel);
5877 unload_color (f, f->output_data.w32->border_pixel); 5877 unload_color (f, f->output_data.w32->border_pixel);
@@ -6369,12 +6369,13 @@ w32_initialize ()
6369 redeem_scroll_bar_hook = w32_redeem_scroll_bar; 6369 redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6370 judge_scroll_bars_hook = w32_judge_scroll_bars; 6370 judge_scroll_bars_hook = w32_judge_scroll_bars;
6371 6371
6372 scroll_region_ok = 1; /* we'll scroll partial frames */ 6372 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
6373 char_ins_del_ok = 1; 6373 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
6374 line_ins_del_ok = 1; /* we'll just blt 'em */ 6374 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
6375 fast_clear_end_of_line = 1; /* X does this well */ 6375 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
6376 memory_below_frame = 0; /* we don't remember what scrolls 6376 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
6377 off the bottom */ 6377 scrolls off the
6378 bottom */
6378 baud_rate = 19200; 6379 baud_rate = 19200;
6379 6380
6380 w32_system_caret_hwnd = NULL; 6381 w32_system_caret_hwnd = NULL;
diff --git a/src/w32term.h b/src/w32term.h
index cac3e2f8997..ceb4f4e4b07 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -405,8 +405,6 @@ extern struct w32_output w32term_display;
405#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc) 405#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
406#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc) 406#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc)
407 407
408#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
409#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
410#define FRAME_FONT(f) ((f)->output_data.w32->font) 408#define FRAME_FONT(f) ((f)->output_data.w32->font)
411#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset) 409#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
412#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset) 410#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset)
diff --git a/src/widget.c b/src/widget.c
index e6388a7d158..bcb038340a5 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -659,10 +659,10 @@ update_from_various_frame_slots (ew)
659 struct x_output *x = f->output_data.x; 659 struct x_output *x = f->output_data.x;
660 ew->core.height = FRAME_PIXEL_HEIGHT (f) - x->menubar_height; 660 ew->core.height = FRAME_PIXEL_HEIGHT (f) - x->menubar_height;
661 ew->core.width = FRAME_PIXEL_WIDTH (f); 661 ew->core.width = FRAME_PIXEL_WIDTH (f);
662 ew->core.background_pixel = x->background_pixel; 662 ew->core.background_pixel = FRAME_BACKGROUND_PIXEL (f);
663 ew->emacs_frame.internal_border_width = f->internal_border_width; 663 ew->emacs_frame.internal_border_width = f->internal_border_width;
664 ew->emacs_frame.font = x->font; 664 ew->emacs_frame.font = x->font;
665 ew->emacs_frame.foreground_pixel = x->foreground_pixel; 665 ew->emacs_frame.foreground_pixel = FRAME_FOREGROUND_PIXEL (f);
666 ew->emacs_frame.cursor_color = x->cursor_pixel; 666 ew->emacs_frame.cursor_color = x->cursor_pixel;
667 ew->core.border_pixel = x->border_pixel; 667 ew->core.border_pixel = x->border_pixel;
668} 668}
diff --git a/src/window.c b/src/window.c
index 562f471de36..154743e5b5d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -21,6 +21,8 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21Boston, MA 02110-1301, USA. */ 21Boston, MA 02110-1301, USA. */
22 22
23#include <config.h> 23#include <config.h>
24#include <stdio.h>
25
24#include "lisp.h" 26#include "lisp.h"
25#include "buffer.h" 27#include "buffer.h"
26#include "keyboard.h" 28#include "keyboard.h"
@@ -7247,7 +7249,7 @@ and scrolling positions. */)
7247void 7249void
7248init_window_once () 7250init_window_once ()
7249{ 7251{
7250 struct frame *f = make_terminal_frame (); 7252 struct frame *f = make_initial_frame ();
7251 XSETFRAME (selected_frame, f); 7253 XSETFRAME (selected_frame, f);
7252 Vterminal_frame = selected_frame; 7254 Vterminal_frame = selected_frame;
7253 minibuf_window = f->minibuffer_window; 7255 minibuf_window = f->minibuffer_window;
diff --git a/src/window.h b/src/window.h
index d4f28034b19..51c0c8a58f6 100644
--- a/src/window.h
+++ b/src/window.h
@@ -744,7 +744,7 @@ extern Lisp_Object Vminibuf_scroll_window;
744/* Nil or a symbol naming the window system under which emacs is 744/* Nil or a symbol naming the window system under which emacs is
745 running ('x is the only current possibility) */ 745 running ('x is the only current possibility) */
746 746
747extern Lisp_Object Vwindow_system; 747extern Lisp_Object Vinitial_window_system;
748 748
749/* Version number of X windows: 10, 11 or nil. */ 749/* Version number of X windows: 10, 11 or nil. */
750 750
diff --git a/src/xdisp.c b/src/xdisp.c
index 82f24551f19..42c579f5cbb 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -580,21 +580,12 @@ Lisp_Object Vmessage_log_max;
580 580
581static Lisp_Object Vmessages_buffer_name; 581static Lisp_Object Vmessages_buffer_name;
582 582
583/* Index 0 is the buffer that holds the current (desired) echo area message, 583/* Current, index 0, and last displayed echo area message. Either
584 or nil if none is desired right now. 584 buffers from echo_buffers, or nil to indicate no message. */
585
586 Index 1 is the buffer that holds the previously displayed echo area message,
587 or nil to indicate no message. This is normally what's on the screen now.
588
589 These two can point to the same buffer. That happens when the last
590 message output by the user (or made by echoing) has been displayed. */
591 585
592Lisp_Object echo_area_buffer[2]; 586Lisp_Object echo_area_buffer[2];
593 587
594/* Permanent pointers to the two buffers that are used for echo area 588/* The buffers referenced from echo_area_buffer. */
595 purposes. Once the two buffers are made, and their pointers are
596 placed here, these two slots remain unchanged unless those buffers
597 need to be created afresh. */
598 589
599static Lisp_Object echo_buffer[2]; 590static Lisp_Object echo_buffer[2];
600 591
@@ -813,10 +804,6 @@ static int clear_face_cache_count;
813static int clear_image_cache_count; 804static int clear_image_cache_count;
814#endif 805#endif
815 806
816/* Record the previous terminal frame we displayed. */
817
818static struct frame *previous_terminal_frame;
819
820/* Non-zero while redisplay_internal is in progress. */ 807/* Non-zero while redisplay_internal is in progress. */
821 808
822int redisplaying_p; 809int redisplaying_p;
@@ -2508,7 +2495,7 @@ init_iterator (it, w, charpos, bytepos, row, base_face_id)
2508 XSETWINDOW (it->window, w); 2495 XSETWINDOW (it->window, w);
2509 it->w = w; 2496 it->w = w;
2510 it->f = XFRAME (w->frame); 2497 it->f = XFRAME (w->frame);
2511 2498
2512 /* Extra space between lines (on window systems only). */ 2499 /* Extra space between lines (on window systems only). */
2513 if (base_face_id == DEFAULT_FACE_ID 2500 if (base_face_id == DEFAULT_FACE_ID
2514 && FRAME_WINDOW_P (it->f)) 2501 && FRAME_WINDOW_P (it->f))
@@ -2525,9 +2512,9 @@ init_iterator (it, w, charpos, bytepos, row, base_face_id)
2525 2512
2526 /* If realized faces have been removed, e.g. because of face 2513 /* If realized faces have been removed, e.g. because of face
2527 attribute changes of named faces, recompute them. When running 2514 attribute changes of named faces, recompute them. When running
2528 in batch mode, the face cache of Vterminal_frame is null. If 2515 in batch mode, the face cache of the initial frame is null. If
2529 we happen to get called, make a dummy face cache. */ 2516 we happen to get called, make a dummy face cache. */
2530 if (noninteractive && FRAME_FACE_CACHE (it->f) == NULL) 2517 if (FRAME_FACE_CACHE (it->f) == NULL)
2531 init_frame_faces (it->f); 2518 init_frame_faces (it->f);
2532 if (FRAME_FACE_CACHE (it->f)->used == 0) 2519 if (FRAME_FACE_CACHE (it->f)->used == 0)
2533 recompute_basic_faces (it->f); 2520 recompute_basic_faces (it->f);
@@ -3952,7 +3939,7 @@ handle_single_display_spec (it, spec, object, position,
3952 && EQ (XCAR (spec), Qheight) 3939 && EQ (XCAR (spec), Qheight)
3953 && CONSP (XCDR (spec))) 3940 && CONSP (XCDR (spec)))
3954 { 3941 {
3955 if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) 3942 if (!FRAME_WINDOW_P (it->f))
3956 return 0; 3943 return 0;
3957 3944
3958 it->font_height = XCAR (XCDR (spec)); 3945 it->font_height = XCAR (XCDR (spec));
@@ -4018,7 +4005,7 @@ handle_single_display_spec (it, spec, object, position,
4018 && EQ (XCAR (spec), Qspace_width) 4005 && EQ (XCAR (spec), Qspace_width)
4019 && CONSP (XCDR (spec))) 4006 && CONSP (XCDR (spec)))
4020 { 4007 {
4021 if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) 4008 if (!FRAME_WINDOW_P (it->f))
4022 return 0; 4009 return 0;
4023 4010
4024 value = XCAR (XCDR (spec)); 4011 value = XCAR (XCDR (spec));
@@ -4034,7 +4021,7 @@ handle_single_display_spec (it, spec, object, position,
4034 { 4021 {
4035 Lisp_Object tem; 4022 Lisp_Object tem;
4036 4023
4037 if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) 4024 if (!FRAME_WINDOW_P (it->f))
4038 return 0; 4025 return 0;
4039 4026
4040 if (tem = XCDR (spec), CONSP (tem)) 4027 if (tem = XCDR (spec), CONSP (tem))
@@ -4060,7 +4047,7 @@ handle_single_display_spec (it, spec, object, position,
4060 && EQ (XCAR (spec), Qraise) 4047 && EQ (XCAR (spec), Qraise)
4061 && CONSP (XCDR (spec))) 4048 && CONSP (XCDR (spec)))
4062 { 4049 {
4063 if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) 4050 if (!FRAME_WINDOW_P (it->f))
4064 return 0; 4051 return 0;
4065 4052
4066#ifdef HAVE_WINDOW_SYSTEM 4053#ifdef HAVE_WINDOW_SYSTEM
@@ -4101,7 +4088,7 @@ handle_single_display_spec (it, spec, object, position,
4101 int face_id = DEFAULT_FACE_ID; 4088 int face_id = DEFAULT_FACE_ID;
4102 int fringe_bitmap; 4089 int fringe_bitmap;
4103 4090
4104 if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) 4091 if (!FRAME_WINDOW_P (it->f))
4105 /* If we return here, POSITION has been advanced 4092 /* If we return here, POSITION has been advanced
4106 across the text with this property. */ 4093 across the text with this property. */
4107 return 0; 4094 return 0;
@@ -4150,7 +4137,7 @@ handle_single_display_spec (it, spec, object, position,
4150 it->left_user_fringe_face_id = face_id; 4137 it->left_user_fringe_face_id = face_id;
4151 } 4138 }
4152 else 4139 else
4153 { 4140 {
4154 it->right_user_fringe_bitmap = fringe_bitmap; 4141 it->right_user_fringe_bitmap = fringe_bitmap;
4155 it->right_user_fringe_face_id = face_id; 4142 it->right_user_fringe_face_id = face_id;
4156 } 4143 }
@@ -4195,9 +4182,9 @@ handle_single_display_spec (it, spec, object, position,
4195 4182
4196 valid_p = (STRINGP (value) 4183 valid_p = (STRINGP (value)
4197#ifdef HAVE_WINDOW_SYSTEM 4184#ifdef HAVE_WINDOW_SYSTEM
4198 || (!FRAME_TERMCAP_P (it->f) && valid_image_p (value)) 4185 || (FRAME_WINDOW_P (it->f) && valid_image_p (value))
4199#endif /* not HAVE_WINDOW_SYSTEM */ 4186#endif /* not HAVE_WINDOW_SYSTEM */
4200 || (CONSP (value) && EQ (XCAR (value), Qspace))); 4187 || (CONSP (value) && EQ (XCAR (value), Qspace)));
4201 4188
4202 if (valid_p && !display_replaced_before_p) 4189 if (valid_p && !display_replaced_before_p)
4203 { 4190 {
@@ -4267,7 +4254,7 @@ handle_single_display_spec (it, spec, object, position,
4267} 4254}
4268 4255
4269 4256
4270/* Check if SPEC is a display specification value whose text should be 4257/* Check if SPEC is a display sub-property value whose text should be
4271 treated as intangible. */ 4258 treated as intangible. */
4272 4259
4273static int 4260static int
@@ -7524,8 +7511,8 @@ message2_nolog (m, nbytes, multibyte)
7524 do_pending_window_change (0); 7511 do_pending_window_change (0);
7525 echo_area_display (1); 7512 echo_area_display (1);
7526 do_pending_window_change (0); 7513 do_pending_window_change (0);
7527 if (frame_up_to_date_hook != 0 && ! gc_in_progress) 7514 if (FRAME_TERMINAL (f)->frame_up_to_date_hook != 0 && ! gc_in_progress)
7528 (*frame_up_to_date_hook) (f); 7515 (*FRAME_TERMINAL (f)->frame_up_to_date_hook) (f);
7529 } 7516 }
7530} 7517}
7531 7518
@@ -7628,8 +7615,8 @@ message3_nolog (m, nbytes, multibyte)
7628 do_pending_window_change (0); 7615 do_pending_window_change (0);
7629 echo_area_display (1); 7616 echo_area_display (1);
7630 do_pending_window_change (0); 7617 do_pending_window_change (0);
7631 if (frame_up_to_date_hook != 0 && ! gc_in_progress) 7618 if (FRAME_TERMINAL (f)->frame_up_to_date_hook != 0 && ! gc_in_progress)
7632 (*frame_up_to_date_hook) (f); 7619 (*FRAME_TERMINAL (f)->frame_up_to_date_hook) (f);
7633 } 7620 }
7634} 7621}
7635 7622
@@ -7867,6 +7854,10 @@ ensure_echo_area_buffers ()
7867 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a 7854 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7868 suitable buffer from echo_buffer[] and clear it. 7855 suitable buffer from echo_buffer[] and clear it.
7869 7856
7857 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7858 that the current message becomes the last displayed one, make
7859 choose a suitable buffer for echo_area_buffer[0], and clear it.
7860
7870 Value is what FN returns. */ 7861 Value is what FN returns. */
7871 7862
7872static int 7863static int
@@ -7891,6 +7882,17 @@ with_echo_area_buffer (w, which, fn, a1, a2, a3, a4)
7891 this_one = 0, the_other = 1; 7882 this_one = 0, the_other = 1;
7892 else if (which > 0) 7883 else if (which > 0)
7893 this_one = 1, the_other = 0; 7884 this_one = 1, the_other = 0;
7885 else
7886 {
7887 this_one = 0, the_other = 1;
7888 clear_buffer_p = 1;
7889
7890 /* We need a fresh one in case the current echo buffer equals
7891 the one containing the last displayed echo area message. */
7892 if (!NILP (echo_area_buffer[this_one])
7893 && EQ (echo_area_buffer[this_one], echo_area_buffer[the_other]))
7894 echo_area_buffer[this_one] = Qnil;
7895 }
7894 7896
7895 /* Choose a suitable buffer from echo_buffer[] is we don't 7897 /* Choose a suitable buffer from echo_buffer[] is we don't
7896 have one. */ 7898 have one. */
@@ -8528,7 +8530,7 @@ set_message (s, string, nbytes, multibyte_p)
8528 = ((s && multibyte_p) 8530 = ((s && multibyte_p)
8529 || (STRINGP (string) && STRING_MULTIBYTE (string))); 8531 || (STRINGP (string) && STRING_MULTIBYTE (string)));
8530 8532
8531 with_echo_area_buffer (0, 0, set_message_1, 8533 with_echo_area_buffer (0, -1, set_message_1,
8532 (EMACS_INT) s, string, nbytes, multibyte_p); 8534 (EMACS_INT) s, string, nbytes, multibyte_p);
8533 message_buf_print = 0; 8535 message_buf_print = 0;
8534 help_echo_showing_p = 0; 8536 help_echo_showing_p = 0;
@@ -8558,7 +8560,6 @@ set_message_1 (a1, a2, nbytes, multibyte_p)
8558 8560
8559 /* Insert new message at BEG. */ 8561 /* Insert new message at BEG. */
8560 TEMP_SET_PT_BOTH (BEG, BEG_BYTE); 8562 TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
8561 Ferase_buffer ();
8562 8563
8563 if (STRINGP (string)) 8564 if (STRINGP (string))
8564 { 8565 {
@@ -8654,11 +8655,11 @@ clear_garbaged_frames ()
8654 { 8655 {
8655 Lisp_Object tail, frame; 8656 Lisp_Object tail, frame;
8656 int changed_count = 0; 8657 int changed_count = 0;
8657 8658
8658 FOR_EACH_FRAME (tail, frame) 8659 FOR_EACH_FRAME (tail, frame)
8659 { 8660 {
8660 struct frame *f = XFRAME (frame); 8661 struct frame *f = XFRAME (frame);
8661 8662
8662 if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f)) 8663 if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f))
8663 { 8664 {
8664 if (f->resized_p) 8665 if (f->resized_p)
@@ -8672,7 +8673,7 @@ clear_garbaged_frames ()
8672 f->resized_p = 0; 8673 f->resized_p = 0;
8673 } 8674 }
8674 } 8675 }
8675 8676
8676 frame_garbaged = 0; 8677 frame_garbaged = 0;
8677 if (changed_count) 8678 if (changed_count)
8678 ++windows_or_buffers_changed; 8679 ++windows_or_buffers_changed;
@@ -8705,11 +8706,10 @@ echo_area_display (update_frame_p)
8705/* The terminal frame is used as the first Emacs frame on the Mac OS. */ 8706/* The terminal frame is used as the first Emacs frame on the Mac OS. */
8706#ifndef MAC_OS8 8707#ifndef MAC_OS8
8707#ifdef HAVE_WINDOW_SYSTEM 8708#ifdef HAVE_WINDOW_SYSTEM
8708 /* When Emacs starts, selected_frame may be a visible terminal 8709 /* When Emacs starts, selected_frame may be the initial terminal
8709 frame, even if we run under a window system. If we let this 8710 frame. If we let this through, a message would be displayed on
8710 through, a message would be displayed on the terminal. */ 8711 the terminal. */
8711 if (EQ (selected_frame, Vterminal_frame) 8712 if (FRAME_INITIAL_P (XFRAME (selected_frame)))
8712 && !NILP (Vwindow_system))
8713 return 0; 8713 return 0;
8714#endif /* HAVE_WINDOW_SYSTEM */ 8714#endif /* HAVE_WINDOW_SYSTEM */
8715#endif 8715#endif
@@ -8760,7 +8760,7 @@ echo_area_display (update_frame_p)
8760 Can do with a display update of the echo area, 8760 Can do with a display update of the echo area,
8761 unless we displayed some mode lines. */ 8761 unless we displayed some mode lines. */
8762 update_single_window (w, 1); 8762 update_single_window (w, 1);
8763 rif->flush_display (f); 8763 FRAME_RIF (f)->flush_display (f);
8764 } 8764 }
8765 else 8765 else
8766 update_frame (f, 1, 1); 8766 update_frame (f, 1, 1);
@@ -8775,8 +8775,10 @@ echo_area_display (update_frame_p)
8775 else if (!EQ (mini_window, selected_window)) 8775 else if (!EQ (mini_window, selected_window))
8776 windows_or_buffers_changed++; 8776 windows_or_buffers_changed++;
8777 8777
8778 /* The current message is now also the last one displayed. */ 8778 /* Last displayed message is now the current message. */
8779 echo_area_buffer[1] = echo_area_buffer[0]; 8779 echo_area_buffer[1] = echo_area_buffer[0];
8780 /* Inform read_char that we're not echoing. */
8781 echo_message_buffer = Qnil;
8780 8782
8781 /* Prevent redisplay optimization in redisplay_internal by resetting 8783 /* Prevent redisplay optimization in redisplay_internal by resetting
8782 this_line_start_pos. This is done because the mini-buffer now 8784 this_line_start_pos. This is done because the mini-buffer now
@@ -9330,8 +9332,8 @@ x_cursor_to (vpos, hpos, y, x)
9330 { 9332 {
9331 BLOCK_INPUT; 9333 BLOCK_INPUT;
9332 display_and_set_cursor (w, 1, hpos, vpos, x, y); 9334 display_and_set_cursor (w, 1, hpos, vpos, x, y);
9333 if (rif->flush_display_optional) 9335 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
9334 rif->flush_display_optional (SELECTED_FRAME ()); 9336 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9335 UNBLOCK_INPUT; 9337 UNBLOCK_INPUT;
9336 } 9338 }
9337} 9339}
@@ -10783,6 +10785,8 @@ select_frame_for_redisplay (frame)
10783 Lisp_Object tail, sym, val; 10785 Lisp_Object tail, sym, val;
10784 Lisp_Object old = selected_frame; 10786 Lisp_Object old = selected_frame;
10785 10787
10788 xassert (FRAMEP (frame) && FRAME_LIVE_P (XFRAME (frame)));
10789
10786 selected_frame = frame; 10790 selected_frame = frame;
10787 10791
10788 for (tail = XFRAME (frame)->param_alist; CONSP (tail); tail = XCDR (tail)) 10792 for (tail = XFRAME (frame)->param_alist; CONSP (tail); tail = XCDR (tail))
@@ -10920,17 +10924,16 @@ redisplay_internal (preserve_echo_area)
10920 if (face_change_count) 10924 if (face_change_count)
10921 ++windows_or_buffers_changed; 10925 ++windows_or_buffers_changed;
10922 10926
10923 if (! FRAME_WINDOW_P (sf) 10927 if (FRAME_TERMCAP_P (sf)
10924 && previous_terminal_frame != sf) 10928 && FRAME_TTY (sf)->previous_frame != sf)
10925 { 10929 {
10926 /* Since frames on an ASCII terminal share the same display 10930 /* Since frames on a single ASCII terminal share the same
10927 area, displaying a different frame means redisplay the whole 10931 display area, displaying a different frame means redisplay
10928 thing. */ 10932 the whole thing. */
10929 windows_or_buffers_changed++; 10933 windows_or_buffers_changed++;
10930 SET_FRAME_GARBAGED (sf); 10934 SET_FRAME_GARBAGED (sf);
10931 XSETFRAME (Vterminal_frame, sf); 10935 FRAME_TTY (sf)->previous_frame = sf;
10932 } 10936 }
10933 previous_terminal_frame = sf;
10934 10937
10935 /* Set the visible flags for all frames. Do this before checking 10938 /* Set the visible flags for all frames. Do this before checking
10936 for resized or garbaged frames; they want to know if their frames 10939 for resized or garbaged frames; they want to know if their frames
@@ -10952,6 +10955,7 @@ redisplay_internal (preserve_echo_area)
10952 } 10955 }
10953 } 10956 }
10954 10957
10958
10955 /* Notice any pending interrupt request to change frame size. */ 10959 /* Notice any pending interrupt request to change frame size. */
10956 do_pending_window_change (1); 10960 do_pending_window_change (1);
10957 10961
@@ -11307,7 +11311,7 @@ redisplay_internal (preserve_echo_area)
11307 { 11311 {
11308 struct frame *f = XFRAME (frame); 11312 struct frame *f = XFRAME (frame);
11309 11313
11310 if (FRAME_WINDOW_P (f) || f == sf) 11314 if (FRAME_WINDOW_P (f) || FRAME_TERMCAP_P (f) || f == sf)
11311 { 11315 {
11312 if (! EQ (frame, selected_frame)) 11316 if (! EQ (frame, selected_frame))
11313 /* Select the frame, for the sake of frame-local 11317 /* Select the frame, for the sake of frame-local
@@ -11316,16 +11320,16 @@ redisplay_internal (preserve_echo_area)
11316 11320
11317 /* Mark all the scroll bars to be removed; we'll redeem 11321 /* Mark all the scroll bars to be removed; we'll redeem
11318 the ones we want when we redisplay their windows. */ 11322 the ones we want when we redisplay their windows. */
11319 if (condemn_scroll_bars_hook) 11323 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
11320 condemn_scroll_bars_hook (f); 11324 FRAME_TERMINAL (f)->condemn_scroll_bars_hook (f);
11321 11325
11322 if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f)) 11326 if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f))
11323 redisplay_windows (FRAME_ROOT_WINDOW (f)); 11327 redisplay_windows (FRAME_ROOT_WINDOW (f));
11324 11328
11325 /* Any scroll bars which redisplay_windows should have 11329 /* Any scroll bars which redisplay_windows should have
11326 nuked should now go away. */ 11330 nuked should now go away. */
11327 if (judge_scroll_bars_hook) 11331 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
11328 judge_scroll_bars_hook (f); 11332 FRAME_TERMINAL (f)->judge_scroll_bars_hook (f);
11329 11333
11330 /* If fonts changed, display again. */ 11334 /* If fonts changed, display again. */
11331 /* ??? rms: I suspect it is a mistake to jump all the way 11335 /* ??? rms: I suspect it is a mistake to jump all the way
@@ -11372,12 +11376,12 @@ redisplay_internal (preserve_echo_area)
11372 FOR_EACH_FRAME (tail, frame) 11376 FOR_EACH_FRAME (tail, frame)
11373 { 11377 {
11374 struct frame *f = XFRAME (frame); 11378 struct frame *f = XFRAME (frame);
11375 if (f->updated_p) 11379 if (f->updated_p)
11376 { 11380 {
11377 mark_window_display_accurate (f->root_window, 1); 11381 mark_window_display_accurate (f->root_window, 1);
11378 if (frame_up_to_date_hook) 11382 if (FRAME_TERMINAL (f)->frame_up_to_date_hook)
11379 frame_up_to_date_hook (f); 11383 FRAME_TERMINAL (f)->frame_up_to_date_hook (f);
11380 } 11384 }
11381 } 11385 }
11382 } 11386 }
11383 } 11387 }
@@ -11462,8 +11466,8 @@ redisplay_internal (preserve_echo_area)
11462 /* Say overlay arrows are up to date. */ 11466 /* Say overlay arrows are up to date. */
11463 update_overlay_arrows (1); 11467 update_overlay_arrows (1);
11464 11468
11465 if (frame_up_to_date_hook != 0) 11469 if (FRAME_TERMINAL (sf)->frame_up_to_date_hook != 0)
11466 frame_up_to_date_hook (sf); 11470 FRAME_TERMINAL (sf)->frame_up_to_date_hook (sf);
11467 } 11471 }
11468 11472
11469 update_mode_lines = 0; 11473 update_mode_lines = 0;
@@ -11573,8 +11577,9 @@ redisplay_preserve_echo_area (from_where)
11573 else 11577 else
11574 redisplay_internal (1); 11578 redisplay_internal (1);
11575 11579
11576 if (rif != NULL && rif->flush_display_optional) 11580 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11577 rif->flush_display_optional (NULL); 11581 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
11582 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL);
11578} 11583}
11579 11584
11580 11585
@@ -11582,7 +11587,8 @@ redisplay_preserve_echo_area (from_where)
11582 redisplay_internal. Reset redisplaying_p to the value it had 11587 redisplay_internal. Reset redisplaying_p to the value it had
11583 before redisplay_internal was called, and clear 11588 before redisplay_internal was called, and clear
11584 prevent_freeing_realized_faces_p. It also selects the previously 11589 prevent_freeing_realized_faces_p. It also selects the previously
11585 selected frame. */ 11590 selected frame, unless it has been deleted (by an X connection
11591 failure during redisplay, for example). */
11586 11592
11587static Lisp_Object 11593static Lisp_Object
11588unwind_redisplay (val) 11594unwind_redisplay (val)
@@ -11593,7 +11599,8 @@ unwind_redisplay (val)
11593 old_redisplaying_p = XCAR (val); 11599 old_redisplaying_p = XCAR (val);
11594 redisplaying_p = XFASTINT (old_redisplaying_p); 11600 redisplaying_p = XFASTINT (old_redisplaying_p);
11595 old_frame = XCDR (val); 11601 old_frame = XCDR (val);
11596 if (! EQ (old_frame, selected_frame)) 11602 if (! EQ (old_frame, selected_frame)
11603 && FRAME_LIVE_P (XFRAME (old_frame)))
11597 select_frame_for_redisplay (old_frame); 11604 select_frame_for_redisplay (old_frame);
11598 return Qnil; 11605 return Qnil;
11599} 11606}
@@ -12742,7 +12749,9 @@ set_vertical_scroll_bar (w)
12742 start = end = whole = 0; 12749 start = end = whole = 0;
12743 12750
12744 /* Indicate what this scroll bar ought to be displaying now. */ 12751 /* Indicate what this scroll bar ought to be displaying now. */
12745 set_vertical_scroll_bar_hook (w, end - start, whole, start); 12752 if (FRAME_TERMINAL (XFRAME (w->frame))->set_vertical_scroll_bar_hook)
12753 (*FRAME_TERMINAL (XFRAME (w->frame))->set_vertical_scroll_bar_hook)
12754 (w, end - start, whole, start);
12746} 12755}
12747 12756
12748 12757
@@ -13483,20 +13492,22 @@ redisplay_window (window, just_this_one_p)
13483 display_menu_bar (w); 13492 display_menu_bar (w);
13484 13493
13485#ifdef HAVE_WINDOW_SYSTEM 13494#ifdef HAVE_WINDOW_SYSTEM
13495 if (FRAME_WINDOW_P (f))
13496 {
13486#ifdef USE_GTK 13497#ifdef USE_GTK
13487 redisplay_tool_bar_p = FRAME_EXTERNAL_TOOL_BAR (f); 13498 redisplay_tool_bar_p = FRAME_EXTERNAL_TOOL_BAR (f);
13488#else 13499#else
13489 redisplay_tool_bar_p = WINDOWP (f->tool_bar_window) 13500 redisplay_tool_bar_p = WINDOWP (f->tool_bar_window)
13490 && (FRAME_TOOL_BAR_LINES (f) > 0 13501 && (FRAME_TOOL_BAR_LINES (f) > 0
13491 || !NILP (Vauto_resize_tool_bars)); 13502 || !NILP (Vauto_resize_tool_bars));
13492
13493#endif 13503#endif
13494 13504
13495 if (redisplay_tool_bar_p && redisplay_tool_bar (f)) 13505 if (redisplay_tool_bar_p && redisplay_tool_bar (f))
13496 { 13506 {
13497 extern int ignore_mouse_drag_p; 13507 extern int ignore_mouse_drag_p;
13498 ignore_mouse_drag_p = 1; 13508 ignore_mouse_drag_p = 1;
13499 } 13509 }
13510 }
13500#endif 13511#endif
13501 } 13512 }
13502 13513
@@ -13530,7 +13541,8 @@ redisplay_window (window, just_this_one_p)
13530 13541
13531 /* Note that we actually used the scroll bar attached to this 13542 /* Note that we actually used the scroll bar attached to this
13532 window, so it shouldn't be deleted at the end of redisplay. */ 13543 window, so it shouldn't be deleted at the end of redisplay. */
13533 redeem_scroll_bar_hook (w); 13544 if (FRAME_TERMINAL (f)->redeem_scroll_bar_hook)
13545 (*FRAME_TERMINAL (f)->redeem_scroll_bar_hook) (w);
13534 } 13546 }
13535 13547
13536 /* Restore current_buffer and value of point in it. */ 13548 /* Restore current_buffer and value of point in it. */
@@ -13796,10 +13808,10 @@ try_window_reusing_current_matrix (w)
13796 if (run.height > 0 && run.current_y != run.desired_y) 13808 if (run.height > 0 && run.current_y != run.desired_y)
13797 { 13809 {
13798 update_begin (f); 13810 update_begin (f);
13799 rif->update_window_begin_hook (w); 13811 FRAME_RIF (f)->update_window_begin_hook (w);
13800 rif->clear_window_mouse_face (w); 13812 FRAME_RIF (f)->clear_window_mouse_face (w);
13801 rif->scroll_run_hook (w, &run); 13813 FRAME_RIF (f)->scroll_run_hook (w, &run);
13802 rif->update_window_end_hook (w, 0, 0); 13814 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
13803 update_end (f); 13815 update_end (f);
13804 } 13816 }
13805 13817
@@ -13968,10 +13980,10 @@ try_window_reusing_current_matrix (w)
13968 if (run.height) 13980 if (run.height)
13969 { 13981 {
13970 update_begin (f); 13982 update_begin (f);
13971 rif->update_window_begin_hook (w); 13983 FRAME_RIF (f)->update_window_begin_hook (w);
13972 rif->clear_window_mouse_face (w); 13984 FRAME_RIF (f)->clear_window_mouse_face (w);
13973 rif->scroll_run_hook (w, &run); 13985 FRAME_RIF (f)->scroll_run_hook (w, &run);
13974 rif->update_window_end_hook (w, 0, 0); 13986 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
13975 update_end (f); 13987 update_end (f);
13976 } 13988 }
13977 13989
@@ -14421,7 +14433,7 @@ try_window_id (w)
14421 14433
14422 /* Window must either use window-based redisplay or be full width. */ 14434 /* Window must either use window-based redisplay or be full width. */
14423 if (!FRAME_WINDOW_P (f) 14435 if (!FRAME_WINDOW_P (f)
14424 && (!line_ins_del_ok 14436 && (!FRAME_LINE_INS_DEL_OK (f)
14425 || !WINDOW_FULL_WIDTH_P (w))) 14437 || !WINDOW_FULL_WIDTH_P (w)))
14426 GIVE_UP (4); 14438 GIVE_UP (4);
14427 14439
@@ -14830,10 +14842,10 @@ try_window_id (w)
14830 14842
14831 if (FRAME_WINDOW_P (f)) 14843 if (FRAME_WINDOW_P (f))
14832 { 14844 {
14833 rif->update_window_begin_hook (w); 14845 FRAME_RIF (f)->update_window_begin_hook (w);
14834 rif->clear_window_mouse_face (w); 14846 FRAME_RIF (f)->clear_window_mouse_face (w);
14835 rif->scroll_run_hook (w, &run); 14847 FRAME_RIF (f)->scroll_run_hook (w, &run);
14836 rif->update_window_end_hook (w, 0, 0); 14848 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
14837 } 14849 }
14838 else 14850 else
14839 { 14851 {
@@ -14851,36 +14863,36 @@ try_window_id (w)
14851 { 14863 {
14852 /* Scroll last_unchanged_at_beg_row to the end of the 14864 /* Scroll last_unchanged_at_beg_row to the end of the
14853 window down dvpos lines. */ 14865 window down dvpos lines. */
14854 set_terminal_window (end); 14866 set_terminal_window (f, end);
14855 14867
14856 /* On dumb terminals delete dvpos lines at the end 14868 /* On dumb terminals delete dvpos lines at the end
14857 before inserting dvpos empty lines. */ 14869 before inserting dvpos empty lines. */
14858 if (!scroll_region_ok) 14870 if (!FRAME_SCROLL_REGION_OK (f))
14859 ins_del_lines (end - dvpos, -dvpos); 14871 ins_del_lines (f, end - dvpos, -dvpos);
14860 14872
14861 /* Insert dvpos empty lines in front of 14873 /* Insert dvpos empty lines in front of
14862 last_unchanged_at_beg_row. */ 14874 last_unchanged_at_beg_row. */
14863 ins_del_lines (from, dvpos); 14875 ins_del_lines (f, from, dvpos);
14864 } 14876 }
14865 else if (dvpos < 0) 14877 else if (dvpos < 0)
14866 { 14878 {
14867 /* Scroll up last_unchanged_at_beg_vpos to the end of 14879 /* Scroll up last_unchanged_at_beg_vpos to the end of
14868 the window to last_unchanged_at_beg_vpos - |dvpos|. */ 14880 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14869 set_terminal_window (end); 14881 set_terminal_window (f, end);
14870 14882
14871 /* Delete dvpos lines in front of 14883 /* Delete dvpos lines in front of
14872 last_unchanged_at_beg_vpos. ins_del_lines will set 14884 last_unchanged_at_beg_vpos. ins_del_lines will set
14873 the cursor to the given vpos and emit |dvpos| delete 14885 the cursor to the given vpos and emit |dvpos| delete
14874 line sequences. */ 14886 line sequences. */
14875 ins_del_lines (from + dvpos, dvpos); 14887 ins_del_lines (f, from + dvpos, dvpos);
14876 14888
14877 /* On a dumb terminal insert dvpos empty lines at the 14889 /* On a dumb terminal insert dvpos empty lines at the
14878 end. */ 14890 end. */
14879 if (!scroll_region_ok) 14891 if (!FRAME_SCROLL_REGION_OK (f))
14880 ins_del_lines (end + dvpos, -dvpos); 14892 ins_del_lines (f, end + dvpos, -dvpos);
14881 } 14893 }
14882 14894
14883 set_terminal_window (0); 14895 set_terminal_window (f, 0);
14884 } 14896 }
14885 14897
14886 update_end (f); 14898 update_end (f);
@@ -16685,10 +16697,10 @@ display_mode_line (w, face_id, format)
16685 /* Temporarily make frame's keyboard the current kboard so that 16697 /* Temporarily make frame's keyboard the current kboard so that
16686 kboard-local variables in the mode_line_format will get the right 16698 kboard-local variables in the mode_line_format will get the right
16687 values. */ 16699 values. */
16688 push_frame_kboard (it.f); 16700 push_kboard (FRAME_KBOARD (it.f));
16689 record_unwind_save_match_data (); 16701 record_unwind_save_match_data ();
16690 display_mode_element (&it, 0, 0, 0, format, Qnil, 0); 16702 display_mode_element (&it, 0, 0, 0, format, Qnil, 0);
16691 pop_frame_kboard (); 16703 pop_kboard ();
16692 16704
16693 unbind_to (count, Qnil); 16705 unbind_to (count, Qnil);
16694 16706
@@ -17403,9 +17415,9 @@ are the selected window and the window's buffer). */)
17403 = (NILP (face) ? Qnil : Fcons (Qface, Fcons (face, Qnil))); 17415 = (NILP (face) ? Qnil : Fcons (Qface, Fcons (face, Qnil)));
17404 } 17416 }
17405 17417
17406 push_frame_kboard (it.f); 17418 push_kboard (FRAME_KBOARD (it.f));
17407 display_mode_element (&it, 0, 0, 0, format, Qnil, 0); 17419 display_mode_element (&it, 0, 0, 0, format, Qnil, 0);
17408 pop_frame_kboard (); 17420 pop_kboard ();
17409 17421
17410 if (no_props) 17422 if (no_props)
17411 { 17423 {
@@ -18029,8 +18041,8 @@ decode_mode_spec (w, c, field_width, precision, multibyte)
18029 { 18041 {
18030 /* No need to mention EOL here--the terminal never needs 18042 /* No need to mention EOL here--the terminal never needs
18031 to do EOL conversion. */ 18043 to do EOL conversion. */
18032 p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0); 18044 p = decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f)->symbol, p, 0);
18033 p = decode_mode_spec_coding (terminal_coding.symbol, p, 0); 18045 p = decode_mode_spec_coding (FRAME_TERMINAL_CODING (f)->symbol, p, 0);
18034 } 18046 }
18035 p = decode_mode_spec_coding (b->buffer_file_coding_system, 18047 p = decode_mode_spec_coding (b->buffer_file_coding_system,
18036 p, eol_flag); 18048 p, eol_flag);
@@ -18522,6 +18534,8 @@ calc_pixel_width_or_height (res, it, prop, font, width_p, align_to)
18522 if (NILP (prop)) 18534 if (NILP (prop))
18523 return OK_PIXELS (0); 18535 return OK_PIXELS (0);
18524 18536
18537 xassert (FRAME_LIVE_P (it->f));
18538
18525 if (SYMBOLP (prop)) 18539 if (SYMBOLP (prop))
18526 { 18540 {
18527 if (SCHARS (SYMBOL_NAME (prop)) == 2) 18541 if (SCHARS (SYMBOL_NAME (prop)) == 2)
@@ -18638,7 +18652,8 @@ calc_pixel_width_or_height (res, it, prop, font, width_p, align_to)
18638 if (SYMBOLP (car)) 18652 if (SYMBOLP (car))
18639 { 18653 {
18640#ifdef HAVE_WINDOW_SYSTEM 18654#ifdef HAVE_WINDOW_SYSTEM
18641 if (valid_image_p (prop)) 18655 if (FRAME_WINDOW_P (it->f)
18656 && valid_image_p (prop))
18642 { 18657 {
18643 int id = lookup_image (it->f, prop); 18658 int id = lookup_image (it->f, prop);
18644 struct image *img = IMAGE_FROM_ID (it->f, id); 18659 struct image *img = IMAGE_FROM_ID (it->f, id);
@@ -18879,7 +18894,7 @@ get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p)
18879 = FONT_INFO_FROM_ID (f, face->font_info_id); 18894 = FONT_INFO_FROM_ID (f, face->font_info_id);
18880 if (font_info) 18895 if (font_info)
18881 glyph->font_type 18896 glyph->font_type
18882 = rif->encode_char (glyph->u.ch, char2b, font_info, two_byte_p); 18897 = FRAME_RIF (f)->encode_char (glyph->u.ch, char2b, font_info, two_byte_p);
18883 } 18898 }
18884 } 18899 }
18885 18900
@@ -19112,7 +19127,7 @@ x_get_glyph_overhangs (glyph, f, left, right)
19112 font = face->font; 19127 font = face->font;
19113 font_info = FONT_INFO_FROM_ID (f, face->font_info_id); 19128 font_info = FONT_INFO_FROM_ID (f, face->font_info_id);
19114 if (font /* ++KFS: Should this be font_info ? */ 19129 if (font /* ++KFS: Should this be font_info ? */
19115 && (pcm = rif->per_char_metric (font, &char2b, glyph->font_type))) 19130 && (pcm = FRAME_RIF (f)->per_char_metric (font, &char2b, glyph->font_type)))
19116 { 19131 {
19117 if (pcm->rbearing > pcm->width) 19132 if (pcm->rbearing > pcm->width)
19118 *right = pcm->rbearing - pcm->width; 19133 *right = pcm->rbearing - pcm->width;
@@ -19280,7 +19295,7 @@ get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p, display_p)
19280 struct font_info *font_info 19295 struct font_info *font_info
19281 = FONT_INFO_FROM_ID (f, face->font_info_id); 19296 = FONT_INFO_FROM_ID (f, face->font_info_id);
19282 if (font_info) 19297 if (font_info)
19283 rif->encode_char (c, char2b, font_info, 0); 19298 FRAME_RIF (f)->encode_char (c, char2b, font_info, 0);
19284 } 19299 }
19285 } 19300 }
19286 19301
@@ -19343,8 +19358,8 @@ compute_overhangs_and_x (s, x, backward_p)
19343 { 19358 {
19344 while (s) 19359 while (s)
19345 { 19360 {
19346 if (rif->compute_glyph_string_overhangs) 19361 if (FRAME_RIF (s->f)->compute_glyph_string_overhangs)
19347 rif->compute_glyph_string_overhangs (s); 19362 FRAME_RIF (s->f)->compute_glyph_string_overhangs (s);
19348 x -= s->width; 19363 x -= s->width;
19349 s->x = x; 19364 s->x = x;
19350 s = s->prev; 19365 s = s->prev;
@@ -19354,8 +19369,8 @@ compute_overhangs_and_x (s, x, backward_p)
19354 { 19369 {
19355 while (s) 19370 while (s)
19356 { 19371 {
19357 if (rif->compute_glyph_string_overhangs) 19372 if (FRAME_RIF (s->f)->compute_glyph_string_overhangs)
19358 rif->compute_glyph_string_overhangs (s); 19373 FRAME_RIF (s->f)->compute_glyph_string_overhangs (s);
19359 s->x = x; 19374 s->x = x;
19360 x += s->width; 19375 x += s->width;
19361 s = s->next; 19376 s = s->next;
@@ -19643,9 +19658,9 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps)
19643 struct glyph_string *h, *t; 19658 struct glyph_string *h, *t;
19644 19659
19645 /* Compute overhangs for all glyph strings. */ 19660 /* Compute overhangs for all glyph strings. */
19646 if (rif->compute_glyph_string_overhangs) 19661 if (FRAME_RIF (f)->compute_glyph_string_overhangs)
19647 for (s = head; s; s = s->next) 19662 for (s = head; s; s = s->next)
19648 rif->compute_glyph_string_overhangs (s); 19663 FRAME_RIF (f)->compute_glyph_string_overhangs (s);
19649 19664
19650 /* Prepend glyph strings for glyphs in front of the first glyph 19665 /* Prepend glyph strings for glyphs in front of the first glyph
19651 string that are overwritten because of the first glyph 19666 string that are overwritten because of the first glyph
@@ -19723,7 +19738,7 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps)
19723 19738
19724 /* Draw all strings. */ 19739 /* Draw all strings. */
19725 for (s = head; s; s = s->next) 19740 for (s = head; s; s = s->next)
19726 rif->draw_glyph_string (s); 19741 FRAME_RIF (f)->draw_glyph_string (s);
19727 19742
19728 if (area == TEXT_AREA 19743 if (area == TEXT_AREA
19729 && !row->full_width_p 19744 && !row->full_width_p
@@ -20418,20 +20433,20 @@ x_produce_glyphs (it)
20418 20433
20419 it->nglyphs = 1; 20434 it->nglyphs = 1;
20420 20435
20421 pcm = rif->per_char_metric (font, &char2b, 20436 pcm = FRAME_RIF (it->f)->per_char_metric
20422 FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display)); 20437 (font, &char2b, FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display));
20423 20438
20424 if (it->override_ascent >= 0) 20439 if (it->override_ascent >= 0)
20425 { 20440 {
20426 it->ascent = it->override_ascent; 20441 it->ascent = it->override_ascent;
20427 it->descent = it->override_descent; 20442 it->descent = it->override_descent;
20428 boff = it->override_boff; 20443 boff = it->override_boff;
20429 } 20444 }
20430 else 20445 else
20431 { 20446 {
20432 it->ascent = FONT_BASE (font) + boff; 20447 it->ascent = FONT_BASE (font) + boff;
20433 it->descent = FONT_DESCENT (font) - boff; 20448 it->descent = FONT_DESCENT (font) - boff;
20434 } 20449 }
20435 20450
20436 if (pcm) 20451 if (pcm)
20437 { 20452 {
@@ -20649,8 +20664,8 @@ x_produce_glyphs (it)
20649 from the charset width; this is what old redisplay code 20664 from the charset width; this is what old redisplay code
20650 did. */ 20665 did. */
20651 20666
20652 pcm = rif->per_char_metric (font, &char2b, 20667 pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20653 FONT_TYPE_FOR_MULTIBYTE (font, it->c)); 20668 FONT_TYPE_FOR_MULTIBYTE (font, it->c));
20654 20669
20655 if (font_not_found_p || !pcm) 20670 if (font_not_found_p || !pcm)
20656 { 20671 {
@@ -20781,8 +20796,8 @@ x_produce_glyphs (it)
20781 20796
20782 /* Initialize the bounding box. */ 20797 /* Initialize the bounding box. */
20783 if (font_info 20798 if (font_info
20784 && (pcm = rif->per_char_metric (font, &char2b, 20799 && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20785 FONT_TYPE_FOR_MULTIBYTE (font, it->c)))) 20800 FONT_TYPE_FOR_MULTIBYTE (font, it->c))))
20786 { 20801 {
20787 width = pcm->width; 20802 width = pcm->width;
20788 ascent = pcm->ascent; 20803 ascent = pcm->ascent;
@@ -20840,8 +20855,8 @@ x_produce_glyphs (it)
20840 } 20855 }
20841 20856
20842 if (font_info 20857 if (font_info
20843 && (pcm = rif->per_char_metric (font, &char2b, 20858 && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20844 FONT_TYPE_FOR_MULTIBYTE (font, ch)))) 20859 FONT_TYPE_FOR_MULTIBYTE (font, ch))))
20845 { 20860 {
20846 width = pcm->width; 20861 width = pcm->width;
20847 ascent = pcm->ascent; 20862 ascent = pcm->ascent;
@@ -21081,8 +21096,8 @@ x_insert_glyphs (start, len)
21081 frame_x = window_box_left (w, updated_area) + output_cursor.x; 21096 frame_x = window_box_left (w, updated_area) + output_cursor.x;
21082 frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); 21097 frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y);
21083 21098
21084 rif->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width, 21099 FRAME_RIF (f)->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width,
21085 line_height, shift_by_width); 21100 line_height, shift_by_width);
21086 21101
21087 /* Write the glyphs. */ 21102 /* Write the glyphs. */
21088 hpos = start - row->glyphs[updated_area]; 21103 hpos = start - row->glyphs[updated_area];
@@ -21164,8 +21179,8 @@ x_clear_end_of_line (to_x)
21164 if (to_x > from_x && to_y > from_y) 21179 if (to_x > from_x && to_y > from_y)
21165 { 21180 {
21166 BLOCK_INPUT; 21181 BLOCK_INPUT;
21167 rif->clear_frame_area (f, from_x, from_y, 21182 FRAME_RIF (f)->clear_frame_area (f, from_x, from_y,
21168 to_x - from_x, to_y - from_y); 21183 to_x - from_x, to_y - from_y);
21169 UNBLOCK_INPUT; 21184 UNBLOCK_INPUT;
21170 } 21185 }
21171} 21186}
@@ -21678,7 +21693,7 @@ erase_phys_cursor (w)
21678 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, max (x, left_x)); 21693 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, max (x, left_x));
21679 21694
21680 if (width > 0) 21695 if (width > 0)
21681 rif->clear_frame_area (f, x, y, width, cursor_row->visible_height); 21696 FRAME_RIF (f)->clear_frame_area (f, x, y, width, cursor_row->visible_height);
21682 } 21697 }
21683 21698
21684 /* Erase the cursor by redrawing the character underneath it. */ 21699 /* Erase the cursor by redrawing the character underneath it. */
@@ -21775,9 +21790,9 @@ display_and_set_cursor (w, on, hpos, vpos, x, y)
21775 w->phys_cursor.vpos = vpos; 21790 w->phys_cursor.vpos = vpos;
21776 } 21791 }
21777 21792
21778 rif->draw_window_cursor (w, glyph_row, x, y, 21793 FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y,
21779 new_cursor_type, new_cursor_width, 21794 new_cursor_type, new_cursor_width,
21780 on, active_cursor); 21795 on, active_cursor);
21781} 21796}
21782 21797
21783 21798
@@ -21926,11 +21941,11 @@ show_mouse_face (dpyinfo, draw)
21926 21941
21927 /* Change the mouse cursor. */ 21942 /* Change the mouse cursor. */
21928 if (draw == DRAW_NORMAL_TEXT && !EQ (dpyinfo->mouse_face_window, f->tool_bar_window)) 21943 if (draw == DRAW_NORMAL_TEXT && !EQ (dpyinfo->mouse_face_window, f->tool_bar_window))
21929 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor); 21944 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor);
21930 else if (draw == DRAW_MOUSE_FACE) 21945 else if (draw == DRAW_MOUSE_FACE)
21931 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor); 21946 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor);
21932 else 21947 else
21933 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor); 21948 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor);
21934} 21949}
21935 21950
21936/* EXPORT: 21951/* EXPORT:
@@ -22369,7 +22384,6 @@ on_hot_spot_p (hot_spot, x, y)
22369 return inside; 22384 return inside;
22370 } 22385 }
22371 } 22386 }
22372 /* If we don't understand the format, pretend we're not in the hot-spot. */
22373 return 0; 22387 return 0;
22374} 22388}
22375 22389
@@ -22449,7 +22463,7 @@ define_frame_cursor1 (f, cursor, pointer)
22449 } 22463 }
22450 22464
22451 if (cursor != No_Cursor) 22465 if (cursor != No_Cursor)
22452 rif->define_frame_cursor (f, cursor); 22466 FRAME_RIF (f)->define_frame_cursor (f, cursor);
22453} 22467}
22454 22468
22455/* Take proper action when mouse has moved to the mode or header line 22469/* Take proper action when mouse has moved to the mode or header line
@@ -23417,8 +23431,8 @@ phys_cursor_in_rect_p (w, r)
23417 I assume the effect is the same -- and this is portable. */ 23431 I assume the effect is the same -- and this is portable. */
23418 return x_intersect_rectangles (&cr, r, &result); 23432 return x_intersect_rectangles (&cr, r, &result);
23419 } 23433 }
23420 else 23434 /* If we don't understand the format, pretend we're not in the hot-spot. */
23421 return 0; 23435 return 0;
23422} 23436}
23423 23437
23424 23438
@@ -23430,6 +23444,8 @@ void
23430x_draw_vertical_border (w) 23444x_draw_vertical_border (w)
23431 struct window *w; 23445 struct window *w;
23432{ 23446{
23447 struct frame *f = XFRAME (WINDOW_FRAME (w));
23448
23433 /* We could do better, if we knew what type of scroll-bar the adjacent 23449 /* We could do better, if we knew what type of scroll-bar the adjacent
23434 windows (on either side) have... But we don't :-( 23450 windows (on either side) have... But we don't :-(
23435 However, I think this works ok. ++KFS 2003-04-25 */ 23451 However, I think this works ok. ++KFS 2003-04-25 */
@@ -23450,9 +23466,9 @@ x_draw_vertical_border (w)
23450 y1 -= 1; 23466 y1 -= 1;
23451 23467
23452 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0) 23468 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
23453 x1 -= 1; 23469 x1 -= 1;
23454 23470
23455 rif->draw_vertical_window_border (w, x1, y0, y1); 23471 FRAME_RIF (f)->draw_vertical_window_border (w, x1, y0, y1);
23456 } 23472 }
23457 else if (!WINDOW_LEFTMOST_P (w) 23473 else if (!WINDOW_LEFTMOST_P (w)
23458 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 23474 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
@@ -23463,9 +23479,9 @@ x_draw_vertical_border (w)
23463 y1 -= 1; 23479 y1 -= 1;
23464 23480
23465 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0) 23481 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
23466 x0 -= 1; 23482 x0 -= 1;
23467 23483
23468 rif->draw_vertical_window_border (w, x0, y0, y1); 23484 FRAME_RIF (f)->draw_vertical_window_border (w, x0, y0, y1);
23469 } 23485 }
23470} 23486}
23471 23487
diff --git a/src/xfaces.c b/src/xfaces.c
index b98d10764ce..ca55b82a9b2 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -195,11 +195,13 @@ Boston, MA 02110-1301, USA. */
195#include <stdio.h> 195#include <stdio.h>
196#include <sys/types.h> 196#include <sys/types.h>
197#include <sys/stat.h> 197#include <sys/stat.h>
198#include <stdio.h> /* This needs to be before termchar.h */
198 199
199#include "lisp.h" 200#include "lisp.h"
200#include "charset.h" 201#include "charset.h"
201#include "keyboard.h" 202#include "keyboard.h"
202#include "frame.h" 203#include "frame.h"
204#include "termhooks.h"
203 205
204#ifdef HAVE_WINDOW_SYSTEM 206#ifdef HAVE_WINDOW_SYSTEM
205#include "fontset.h" 207#include "fontset.h"
@@ -242,6 +244,7 @@ Boston, MA 02110-1301, USA. */
242#include "blockinput.h" 244#include "blockinput.h"
243#include "window.h" 245#include "window.h"
244#include "intervals.h" 246#include "intervals.h"
247#include "termchar.h"
245 248
246#ifdef HAVE_X_WINDOWS 249#ifdef HAVE_X_WINDOWS
247 250
@@ -3221,6 +3224,20 @@ push_named_merge_point (struct named_merge_point *new_named_merge_point,
3221 3224
3222 3225
3223 3226
3227static Lisp_Object
3228internal_resolve_face_name (nargs, args)
3229 int nargs;
3230 Lisp_Object *args;
3231{
3232 Fget (args[0], args[1]);
3233}
3234
3235static Lisp_Object
3236resolve_face_name_error (ignore)
3237 Lisp_Object ignore;
3238{
3239 return Qnil;
3240}
3224 3241
3225/* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it 3242/* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3226 to make it a symbol. If FACE_NAME is an alias for another face, 3243 to make it a symbol. If FACE_NAME is an alias for another face,
@@ -6145,7 +6162,7 @@ tty_supports_face_attributes_p (f, attrs, def_face)
6145 /* See if the capabilities we selected above are supported, with the 6162 /* See if the capabilities we selected above are supported, with the
6146 given colors. */ 6163 given colors. */
6147 if (test_caps != 0 && 6164 if (test_caps != 0 &&
6148 ! tty_capable_p (f, test_caps, fg_tty_color.pixel, bg_tty_color.pixel)) 6165 ! tty_capable_p (FRAME_TTY (f), test_caps, fg_tty_color.pixel, bg_tty_color.pixel))
6149 return 0; 6166 return 0;
6150 6167
6151 6168
@@ -6949,7 +6966,8 @@ realize_basic_faces (f)
6949 { 6966 {
6950 FRAME_FACE_CACHE (f)->menu_face_changed_p = 0; 6967 FRAME_FACE_CACHE (f)->menu_face_changed_p = 0;
6951#ifdef USE_X_TOOLKIT 6968#ifdef USE_X_TOOLKIT
6952 x_update_menu_appearance (f); 6969 if (FRAME_WINDOW_P (f))
6970 x_update_menu_appearance (f);
6953#endif 6971#endif
6954 } 6972 }
6955 6973
@@ -7036,7 +7054,7 @@ realize_default_face (f)
7036 LFACE_FOREGROUND (lface) = XCDR (color); 7054 LFACE_FOREGROUND (lface) = XCDR (color);
7037 else if (FRAME_WINDOW_P (f)) 7055 else if (FRAME_WINDOW_P (f))
7038 return 0; 7056 return 0;
7039 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) 7057 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
7040 LFACE_FOREGROUND (lface) = build_string (unspecified_fg); 7058 LFACE_FOREGROUND (lface) = build_string (unspecified_fg);
7041 else 7059 else
7042 abort (); 7060 abort ();
@@ -7051,7 +7069,7 @@ realize_default_face (f)
7051 LFACE_BACKGROUND (lface) = XCDR (color); 7069 LFACE_BACKGROUND (lface) = XCDR (color);
7052 else if (FRAME_WINDOW_P (f)) 7070 else if (FRAME_WINDOW_P (f))
7053 return 0; 7071 return 0;
7054 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) 7072 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
7055 LFACE_BACKGROUND (lface) = build_string (unspecified_bg); 7073 LFACE_BACKGROUND (lface) = build_string (unspecified_bg);
7056 else 7074 else
7057 abort (); 7075 abort ();
@@ -7068,17 +7086,17 @@ realize_default_face (f)
7068 7086
7069#ifdef HAVE_WINDOW_SYSTEM 7087#ifdef HAVE_WINDOW_SYSTEM
7070#ifdef HAVE_X_WINDOWS 7088#ifdef HAVE_X_WINDOWS
7071 if (face->font != FRAME_FONT (f)) 7089 if (FRAME_X_P (f) && face->font != FRAME_FONT (f))
7072 { 7090 {
7073 /* This can happen when making a frame on a display that does 7091 /* This can happen when making a frame on a display that does
7074 not support the default font. */ 7092 not support the default font. */
7075 if (!face->font) 7093 if (!face->font)
7076 return 0; 7094 return 0;
7077 7095
7078 /* Otherwise, the font specified for the frame was not 7096 /* Otherwise, the font specified for the frame was not
7079 acceptable as a font for the default face (perhaps because 7097 acceptable as a font for the default face (perhaps because
7080 auto-scaled fonts are rejected), so we must adjust the frame 7098 auto-scaled fonts are rejected), so we must adjust the frame
7081 font. */ 7099 font. */
7082 x_set_font (f, build_string (face->font_name), Qnil); 7100 x_set_font (f, build_string (face->font_name), Qnil);
7083 } 7101 }
7084#endif /* HAVE_X_WINDOWS */ 7102#endif /* HAVE_X_WINDOWS */
@@ -7158,6 +7176,11 @@ realize_face (cache, attrs, c, base_face, former_face_id)
7158 face = realize_x_face (cache, attrs, c, base_face); 7176 face = realize_x_face (cache, attrs, c, base_face);
7159 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) 7177 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
7160 face = realize_tty_face (cache, attrs, c); 7178 face = realize_tty_face (cache, attrs, c);
7179 else if (FRAME_INITIAL_P (cache->f))
7180 {
7181 /* Create a dummy face. */
7182 face = make_realized_face (attrs);
7183 }
7161 else 7184 else
7162 abort (); 7185 abort ();
7163 7186
diff --git a/src/xfns.c b/src/xfns.c
index 03cbaaec8e2..f2c85814847 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -47,6 +47,7 @@ Boston, MA 02110-1301, USA. */
47#include "systime.h" 47#include "systime.h"
48#include "termhooks.h" 48#include "termhooks.h"
49#include "atimer.h" 49#include "atimer.h"
50#include "termchar.h"
50 51
51#ifdef HAVE_X_WINDOWS 52#ifdef HAVE_X_WINDOWS
52 53
@@ -250,17 +251,18 @@ check_x_frame (frame)
250 return f; 251 return f;
251} 252}
252 253
253/* Let the user specify an X display with a frame. 254/* Let the user specify an X display with a Lisp object.
255 OBJECT may be nil, a frame or a terminal id.
254 nil stands for the selected frame--or, if that is not an X frame, 256 nil stands for the selected frame--or, if that is not an X frame,
255 the first X display on the list. */ 257 the first X display on the list. */
256 258
257struct x_display_info * 259struct x_display_info *
258check_x_display_info (frame) 260check_x_display_info (object)
259 Lisp_Object frame; 261 Lisp_Object object;
260{ 262{
261 struct x_display_info *dpyinfo = NULL; 263 struct x_display_info *dpyinfo = NULL;
262 264
263 if (NILP (frame)) 265 if (NILP (object))
264 { 266 {
265 struct frame *sf = XFRAME (selected_frame); 267 struct frame *sf = XFRAME (selected_frame);
266 268
@@ -271,11 +273,20 @@ check_x_display_info (frame)
271 else 273 else
272 error ("X windows are not in use or not initialized"); 274 error ("X windows are not in use or not initialized");
273 } 275 }
274 else if (STRINGP (frame)) 276 else if (INTEGERP (object))
275 dpyinfo = x_display_info_for_name (frame); 277 {
278 struct terminal *t = get_terminal (XINT (object), 1);
279
280 if (t->type != output_x_window)
281 error ("Terminal %d is not an X display", XINT (object));
282
283 dpyinfo = t->display_info.x;
284 }
285 else if (STRINGP (object))
286 dpyinfo = x_display_info_for_name (object);
276 else 287 else
277 { 288 {
278 FRAME_PTR f = check_x_frame (frame); 289 FRAME_PTR f = check_x_frame (object);
279 dpyinfo = FRAME_X_DISPLAY_INFO (f); 290 dpyinfo = FRAME_X_DISPLAY_INFO (f);
280 } 291 }
281 292
@@ -856,8 +867,8 @@ x_set_foreground_color (f, arg, oldval)
856 unsigned long fg, old_fg; 867 unsigned long fg, old_fg;
857 868
858 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 869 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
859 old_fg = x->foreground_pixel; 870 old_fg = FRAME_FOREGROUND_PIXEL (f);
860 x->foreground_pixel = fg; 871 FRAME_FOREGROUND_PIXEL (f) = fg;
861 872
862 if (FRAME_X_WINDOW (f) != 0) 873 if (FRAME_X_WINDOW (f) != 0)
863 { 874 {
@@ -894,8 +905,8 @@ x_set_background_color (f, arg, oldval)
894 unsigned long bg; 905 unsigned long bg;
895 906
896 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); 907 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
897 unload_color (f, x->background_pixel); 908 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
898 x->background_pixel = bg; 909 FRAME_BACKGROUND_PIXEL (f) = bg;
899 910
900 if (FRAME_X_WINDOW (f) != 0) 911 if (FRAME_X_WINDOW (f) != 0)
901 { 912 {
@@ -943,13 +954,13 @@ x_set_mouse_color (f, arg, oldval)
943 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; 954 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
944 Cursor hourglass_cursor, horizontal_drag_cursor; 955 Cursor hourglass_cursor, horizontal_drag_cursor;
945 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 956 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
946 unsigned long mask_color = x->background_pixel; 957 unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
947 958
948 /* Don't let pointers be invisible. */ 959 /* Don't let pointers be invisible. */
949 if (mask_color == pixel) 960 if (mask_color == pixel)
950 { 961 {
951 x_free_colors (f, &pixel, 1); 962 x_free_colors (f, &pixel, 1);
952 pixel = x_copy_color (f, x->foreground_pixel); 963 pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f));
953 } 964 }
954 965
955 unload_color (f, x->mouse_pixel); 966 unload_color (f, x->mouse_pixel);
@@ -1092,13 +1103,13 @@ x_set_cursor_color (f, arg, oldval)
1092 fore_pixel_allocated_p = 1; 1103 fore_pixel_allocated_p = 1;
1093 } 1104 }
1094 else 1105 else
1095 fore_pixel = x->background_pixel; 1106 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1096 1107
1097 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 1108 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1098 pixel_allocated_p = 1; 1109 pixel_allocated_p = 1;
1099 1110
1100 /* Make sure that the cursor color differs from the background color. */ 1111 /* Make sure that the cursor color differs from the background color. */
1101 if (pixel == x->background_pixel) 1112 if (pixel == FRAME_BACKGROUND_PIXEL (f))
1102 { 1113 {
1103 if (pixel_allocated_p) 1114 if (pixel_allocated_p)
1104 { 1115 {
@@ -1114,7 +1125,7 @@ x_set_cursor_color (f, arg, oldval)
1114 x_free_colors (f, &fore_pixel, 1); 1125 x_free_colors (f, &fore_pixel, 1);
1115 fore_pixel_allocated_p = 0; 1126 fore_pixel_allocated_p = 0;
1116 } 1127 }
1117 fore_pixel = x->background_pixel; 1128 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1118 } 1129 }
1119 } 1130 }
1120 1131
@@ -1399,10 +1410,8 @@ x_set_tool_bar_lines (f, value, oldval)
1399 below the menu bar. */ 1410 below the menu bar. */
1400 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) 1411 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1401 { 1412 {
1402 updating_frame = f; 1413 clear_frame (f);
1403 clear_frame ();
1404 clear_current_matrices (f); 1414 clear_current_matrices (f);
1405 updating_frame = NULL;
1406 } 1415 }
1407 1416
1408 /* If the tool bar gets smaller, the internal border below it 1417 /* If the tool bar gets smaller, the internal border below it
@@ -1453,10 +1462,10 @@ x_set_scroll_bar_foreground (f, value, oldval)
1453 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) 1462 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1454 { 1463 {
1455 /* Remove all scroll bars because they have wrong colors. */ 1464 /* Remove all scroll bars because they have wrong colors. */
1456 if (condemn_scroll_bars_hook) 1465 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1457 (*condemn_scroll_bars_hook) (f); 1466 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1458 if (judge_scroll_bars_hook) 1467 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1459 (*judge_scroll_bars_hook) (f); 1468 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1460 1469
1461 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); 1470 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
1462 redraw_frame (f); 1471 redraw_frame (f);
@@ -1502,10 +1511,10 @@ x_set_scroll_bar_background (f, value, oldval)
1502 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) 1511 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1503 { 1512 {
1504 /* Remove all scroll bars because they have wrong colors. */ 1513 /* Remove all scroll bars because they have wrong colors. */
1505 if (condemn_scroll_bars_hook) 1514 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1506 (*condemn_scroll_bars_hook) (f); 1515 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1507 if (judge_scroll_bars_hook) 1516 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1508 (*judge_scroll_bars_hook) (f); 1517 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1509 1518
1510 update_face_from_frame_parameter (f, Qscroll_bar_background, value); 1519 update_face_from_frame_parameter (f, Qscroll_bar_background, value);
1511 redraw_frame (f); 1520 redraw_frame (f);
@@ -2717,7 +2726,7 @@ x_window (f)
2717 XSetWindowAttributes attributes; 2726 XSetWindowAttributes attributes;
2718 unsigned long attribute_mask; 2727 unsigned long attribute_mask;
2719 2728
2720 attributes.background_pixel = f->output_data.x->background_pixel; 2729 attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f);
2721 attributes.border_pixel = f->output_data.x->border_pixel; 2730 attributes.border_pixel = f->output_data.x->border_pixel;
2722 attributes.bit_gravity = StaticGravity; 2731 attributes.bit_gravity = StaticGravity;
2723 attributes.backing_store = NotUseful; 2732 attributes.backing_store = NotUseful;
@@ -2905,8 +2914,8 @@ x_make_gc (f)
2905 2914
2906 /* Normal video */ 2915 /* Normal video */
2907 gc_values.font = FRAME_FONT (f)->fid; 2916 gc_values.font = FRAME_FONT (f)->fid;
2908 gc_values.foreground = f->output_data.x->foreground_pixel; 2917 gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
2909 gc_values.background = f->output_data.x->background_pixel; 2918 gc_values.background = FRAME_BACKGROUND_PIXEL (f);
2910 gc_values.line_width = 0; /* Means 1 using fast algorithm. */ 2919 gc_values.line_width = 0; /* Means 1 using fast algorithm. */
2911 f->output_data.x->normal_gc 2920 f->output_data.x->normal_gc
2912 = XCreateGC (FRAME_X_DISPLAY (f), 2921 = XCreateGC (FRAME_X_DISPLAY (f),
@@ -2915,8 +2924,8 @@ x_make_gc (f)
2915 &gc_values); 2924 &gc_values);
2916 2925
2917 /* Reverse video style. */ 2926 /* Reverse video style. */
2918 gc_values.foreground = f->output_data.x->background_pixel; 2927 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2919 gc_values.background = f->output_data.x->foreground_pixel; 2928 gc_values.background = FRAME_FOREGROUND_PIXEL (f);
2920 f->output_data.x->reverse_gc 2929 f->output_data.x->reverse_gc
2921 = XCreateGC (FRAME_X_DISPLAY (f), 2930 = XCreateGC (FRAME_X_DISPLAY (f),
2922 FRAME_X_WINDOW (f), 2931 FRAME_X_WINDOW (f),
@@ -2924,7 +2933,7 @@ x_make_gc (f)
2924 &gc_values); 2933 &gc_values);
2925 2934
2926 /* Cursor has cursor-color background, background-color foreground. */ 2935 /* Cursor has cursor-color background, background-color foreground. */
2927 gc_values.foreground = f->output_data.x->background_pixel; 2936 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2928 gc_values.background = f->output_data.x->cursor_pixel; 2937 gc_values.background = f->output_data.x->cursor_pixel;
2929 gc_values.fill_style = FillOpaqueStippled; 2938 gc_values.fill_style = FillOpaqueStippled;
2930 gc_values.stipple 2939 gc_values.stipple
@@ -2948,8 +2957,8 @@ x_make_gc (f)
2948 = (XCreatePixmapFromBitmapData 2957 = (XCreatePixmapFromBitmapData
2949 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, 2958 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2950 gray_bits, gray_width, gray_height, 2959 gray_bits, gray_width, gray_height,
2951 f->output_data.x->foreground_pixel, 2960 FRAME_FOREGROUND_PIXEL (f),
2952 f->output_data.x->background_pixel, 2961 FRAME_BACKGROUND_PIXEL (f),
2953 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); 2962 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2954 2963
2955 UNBLOCK_INPUT; 2964 UNBLOCK_INPUT;
@@ -3004,6 +3013,12 @@ unwind_create_frame (frame)
3004{ 3013{
3005 struct frame *f = XFRAME (frame); 3014 struct frame *f = XFRAME (frame);
3006 3015
3016 /* If frame is already dead, nothing to do. This can happen if the
3017 display is disconnected after the frame has become official, but
3018 before x_create_frame removes the unwind protect. */
3019 if (!FRAME_LIVE_P (f))
3020 return Qnil;
3021
3007 /* If frame is ``official'', nothing to do. */ 3022 /* If frame is ``official'', nothing to do. */
3008 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame)) 3023 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
3009 { 3024 {
@@ -3052,24 +3067,27 @@ This function is an internal primitive--use `make-frame' instead. */)
3052 Lisp_Object parent; 3067 Lisp_Object parent;
3053 struct kboard *kb; 3068 struct kboard *kb;
3054 3069
3055 check_x ();
3056
3057 parms = Fcopy_alist (parms); 3070 parms = Fcopy_alist (parms);
3058 3071
3059 /* Use this general default value to start with 3072 /* Use this general default value to start with
3060 until we know if this frame has a specified name. */ 3073 until we know if this frame has a specified name. */
3061 Vx_resource_name = Vinvocation_name; 3074 Vx_resource_name = Vinvocation_name;
3062 3075
3063 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); 3076 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
3077 if (EQ (display, Qunbound))
3078 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
3064 if (EQ (display, Qunbound)) 3079 if (EQ (display, Qunbound))
3065 display = Qnil; 3080 display = Qnil;
3066 dpyinfo = check_x_display_info (display); 3081 dpyinfo = check_x_display_info (display);
3067#ifdef MULTI_KBOARD 3082#ifdef MULTI_KBOARD
3068 kb = dpyinfo->kboard; 3083 kb = dpyinfo->terminal->kboard;
3069#else 3084#else
3070 kb = &the_only_kboard; 3085 kb = &the_only_kboard;
3071#endif 3086#endif
3072 3087
3088 if (dpyinfo->terminal->deleted)
3089 error ("Terminal is being deleted, can't create new frames on it");
3090
3073 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); 3091 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
3074 if (!STRINGP (name) 3092 if (!STRINGP (name)
3075 && ! EQ (name, Qunbound) 3093 && ! EQ (name, Qunbound)
@@ -3110,6 +3128,9 @@ This function is an internal primitive--use `make-frame' instead. */)
3110 /* Note that X Windows does support scroll bars. */ 3128 /* Note that X Windows does support scroll bars. */
3111 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; 3129 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
3112 3130
3131 f->terminal = dpyinfo->terminal;
3132 f->terminal->reference_count++;
3133
3113 f->output_method = output_x_window; 3134 f->output_method = output_x_window;
3114 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output)); 3135 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
3115 bzero (f->output_data.x, sizeof (struct x_output)); 3136 bzero (f->output_data.x, sizeof (struct x_output));
@@ -3136,9 +3157,6 @@ This function is an internal primitive--use `make-frame' instead. */)
3136 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; 3157 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
3137 dpyinfo_refcount = dpyinfo->reference_count; 3158 dpyinfo_refcount = dpyinfo->reference_count;
3138#endif /* GLYPH_DEBUG */ 3159#endif /* GLYPH_DEBUG */
3139#ifdef MULTI_KBOARD
3140 FRAME_KBOARD (f) = kb;
3141#endif
3142 3160
3143 /* These colors will be set anyway later, but it's important 3161 /* These colors will be set anyway later, but it's important
3144 to get the color reference counts right, so initialize them! */ 3162 to get the color reference counts right, so initialize them! */
@@ -3149,8 +3167,8 @@ This function is an internal primitive--use `make-frame' instead. */)
3149 /* Function x_decode_color can signal an error. Make 3167 /* Function x_decode_color can signal an error. Make
3150 sure to initialize color slots so that we won't try 3168 sure to initialize color slots so that we won't try
3151 to free colors we haven't allocated. */ 3169 to free colors we haven't allocated. */
3152 f->output_data.x->foreground_pixel = -1; 3170 FRAME_FOREGROUND_PIXEL (f) = -1;
3153 f->output_data.x->background_pixel = -1; 3171 FRAME_BACKGROUND_PIXEL (f) = -1;
3154 f->output_data.x->cursor_pixel = -1; 3172 f->output_data.x->cursor_pixel = -1;
3155 f->output_data.x->cursor_foreground_pixel = -1; 3173 f->output_data.x->cursor_foreground_pixel = -1;
3156 f->output_data.x->border_pixel = -1; 3174 f->output_data.x->border_pixel = -1;
@@ -3158,9 +3176,9 @@ This function is an internal primitive--use `make-frame' instead. */)
3158 3176
3159 black = build_string ("black"); 3177 black = build_string ("black");
3160 GCPRO1 (black); 3178 GCPRO1 (black);
3161 f->output_data.x->foreground_pixel 3179 FRAME_FOREGROUND_PIXEL (f)
3162 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3180 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3163 f->output_data.x->background_pixel 3181 FRAME_BACKGROUND_PIXEL (f)
3164 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3182 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3165 f->output_data.x->cursor_pixel 3183 f->output_data.x->cursor_pixel
3166 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3184 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
@@ -3427,7 +3445,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3427 } 3445 }
3428 3446
3429 /* Initialize `default-minibuffer-frame' in case this is the first 3447 /* Initialize `default-minibuffer-frame' in case this is the first
3430 frame on this display device. */ 3448 frame on this terminal. */
3431 if (FRAME_HAS_MINIBUF_P (f) 3449 if (FRAME_HAS_MINIBUF_P (f)
3432 && (!FRAMEP (kb->Vdefault_minibuffer_frame) 3450 && (!FRAMEP (kb->Vdefault_minibuffer_frame)
3433 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))) 3451 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
@@ -3439,6 +3457,8 @@ This function is an internal primitive--use `make-frame' instead. */)
3439 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) 3457 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
3440 f->param_alist = Fcons (XCAR (tem), f->param_alist); 3458 f->param_alist = Fcons (XCAR (tem), f->param_alist);
3441 3459
3460 store_frame_param (f, Qwindow_system, Qx);
3461
3442 UNGCPRO; 3462 UNGCPRO;
3443 3463
3444 /* Make sure windows on this frame appear in calls to next-window 3464 /* Make sure windows on this frame appear in calls to next-window
@@ -3532,10 +3552,10 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3532 3552
3533DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, 3553DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
3534 doc: /* Internal function called by `display-color-p', which see. */) 3554 doc: /* Internal function called by `display-color-p', which see. */)
3535 (display) 3555 (terminal)
3536 Lisp_Object display; 3556 Lisp_Object terminal;
3537{ 3557{
3538 struct x_display_info *dpyinfo = check_x_display_info (display); 3558 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3539 3559
3540 if (dpyinfo->n_planes <= 2) 3560 if (dpyinfo->n_planes <= 2)
3541 return Qnil; 3561 return Qnil;
@@ -3557,13 +3577,13 @@ DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
3557 0, 1, 0, 3577 0, 1, 0,
3558 doc: /* Return t if the X display supports shades of gray. 3578 doc: /* Return t if the X display supports shades of gray.
3559Note that color displays do support shades of gray. 3579Note that color displays do support shades of gray.
3560The optional argument DISPLAY specifies which display to ask about. 3580The optional argument TERMINAL specifies which display to ask about.
3561DISPLAY should be either a frame or a display name (a string). 3581TERMINAL should be a terminal id, a frame or a display name (a string).
3562If omitted or nil, that stands for the selected frame's display. */) 3582If omitted or nil, that stands for the selected frame's display. */)
3563 (display) 3583 (terminal)
3564 Lisp_Object display; 3584 Lisp_Object terminal;
3565{ 3585{
3566 struct x_display_info *dpyinfo = check_x_display_info (display); 3586 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3567 3587
3568 if (dpyinfo->n_planes <= 1) 3588 if (dpyinfo->n_planes <= 1)
3569 return Qnil; 3589 return Qnil;
@@ -3585,56 +3605,56 @@ If omitted or nil, that stands for the selected frame's display. */)
3585 3605
3586DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, 3606DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
3587 0, 1, 0, 3607 0, 1, 0,
3588 doc: /* Returns the width in pixels of the X display DISPLAY. 3608 doc: /* Returns the width in pixels of the X display TERMINAL.
3589The optional argument DISPLAY specifies which display to ask about. 3609The optional argument TERMINAL specifies which display to ask about.
3590DISPLAY should be either a frame or a display name (a string). 3610TERMINAL should be a terminal id, a frame or a display name (a string).
3591If omitted or nil, that stands for the selected frame's display. */) 3611If omitted or nil, that stands for the selected frame's display. */)
3592 (display) 3612 (terminal)
3593 Lisp_Object display; 3613 Lisp_Object terminal;
3594{ 3614{
3595 struct x_display_info *dpyinfo = check_x_display_info (display); 3615 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3596 3616
3597 return make_number (dpyinfo->width); 3617 return make_number (dpyinfo->width);
3598} 3618}
3599 3619
3600DEFUN ("x-display-pixel-height", Fx_display_pixel_height, 3620DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
3601 Sx_display_pixel_height, 0, 1, 0, 3621 Sx_display_pixel_height, 0, 1, 0,
3602 doc: /* Returns the height in pixels of the X display DISPLAY. 3622 doc: /* Returns the height in pixels of the X display TERMINAL.
3603The optional argument DISPLAY specifies which display to ask about. 3623The optional argument TERMINAL specifies which display to ask about.
3604DISPLAY should be either a frame or a display name (a string). 3624TERMINAL should be a terminal id, a frame or a display name (a string).
3605If omitted or nil, that stands for the selected frame's display. */) 3625If omitted or nil, that stands for the selected frame's display. */)
3606 (display) 3626 (terminal)
3607 Lisp_Object display; 3627 Lisp_Object terminal;
3608{ 3628{
3609 struct x_display_info *dpyinfo = check_x_display_info (display); 3629 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3610 3630
3611 return make_number (dpyinfo->height); 3631 return make_number (dpyinfo->height);
3612} 3632}
3613 3633
3614DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, 3634DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
3615 0, 1, 0, 3635 0, 1, 0,
3616 doc: /* Returns the number of bitplanes of the X display DISPLAY. 3636 doc: /* Returns the number of bitplanes of the X display TERMINAL.
3617The optional argument DISPLAY specifies which display to ask about. 3637The optional argument TERMINAL specifies which display to ask about.
3618DISPLAY should be either a frame or a display name (a string). 3638TERMINAL should be a terminal id, a frame or a display name (a string).
3619If omitted or nil, that stands for the selected frame's display. */) 3639If omitted or nil, that stands for the selected frame's display. */)
3620 (display) 3640 (terminal)
3621 Lisp_Object display; 3641 Lisp_Object terminal;
3622{ 3642{
3623 struct x_display_info *dpyinfo = check_x_display_info (display); 3643 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3624 3644
3625 return make_number (dpyinfo->n_planes); 3645 return make_number (dpyinfo->n_planes);
3626} 3646}
3627 3647
3628DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, 3648DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
3629 0, 1, 0, 3649 0, 1, 0,
3630 doc: /* Returns the number of color cells of the X display DISPLAY. 3650 doc: /* Returns the number of color cells of the X display TERMINAL.
3631The optional argument DISPLAY specifies which display to ask about. 3651The optional argument TERMINAL specifies which display to ask about.
3632DISPLAY should be either a frame or a display name (a string). 3652TERMINAL should be a terminal id, a frame or a display name (a string).
3633If omitted or nil, that stands for the selected frame's display. */) 3653If omitted or nil, that stands for the selected frame's display. */)
3634 (display) 3654 (terminal)
3635 Lisp_Object display; 3655 Lisp_Object terminal;
3636{ 3656{
3637 struct x_display_info *dpyinfo = check_x_display_info (display); 3657 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3638 3658
3639 int nr_planes = DisplayPlanes (dpyinfo->display, 3659 int nr_planes = DisplayPlanes (dpyinfo->display,
3640 XScreenNumberOfScreen (dpyinfo->screen)); 3660 XScreenNumberOfScreen (dpyinfo->screen));
@@ -3652,29 +3672,29 @@ If omitted or nil, that stands for the selected frame's display. */)
3652DEFUN ("x-server-max-request-size", Fx_server_max_request_size, 3672DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
3653 Sx_server_max_request_size, 3673 Sx_server_max_request_size,
3654 0, 1, 0, 3674 0, 1, 0,
3655 doc: /* Returns the maximum request size of the X server of display DISPLAY. 3675 doc: /* Returns the maximum request size of the X server of display TERMINAL.
3656The optional argument DISPLAY specifies which display to ask about. 3676The optional argument TERMINAL specifies which display to ask about.
3657DISPLAY should be either a frame or a display name (a string). 3677TERMINAL should be a terminal id, a frame or a display name (a string).
3658If omitted or nil, that stands for the selected frame's display. */) 3678If omitted or nil, that stands for the selected frame's display. */)
3659 (display) 3679 (terminal)
3660 Lisp_Object display; 3680 Lisp_Object terminal;
3661{ 3681{
3662 struct x_display_info *dpyinfo = check_x_display_info (display); 3682 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3663 3683
3664 return make_number (MAXREQUEST (dpyinfo->display)); 3684 return make_number (MAXREQUEST (dpyinfo->display));
3665} 3685}
3666 3686
3667DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, 3687DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
3668 doc: /* Returns the "vendor ID" string of the X server of display DISPLAY. 3688 doc: /* Returns the "vendor ID" string of the X server of display TERMINAL.
3669\(Labelling every distributor as a "vendor" embodies the false assumption 3689\(Labelling every distributor as a "vendor" embodies the false assumption
3670that operating systems cannot be developed and distributed noncommercially.) 3690that operating systems cannot be developed and distributed noncommercially.)
3671The optional argument DISPLAY specifies which display to ask about. 3691The optional argument TERMINAL specifies which display to ask about.
3672DISPLAY should be either a frame or a display name (a string). 3692TERMINAL should be a terminal id, a frame or a display name (a string).
3673If omitted or nil, that stands for the selected frame's display. */) 3693If omitted or nil, that stands for the selected frame's display. */)
3674 (display) 3694 (terminal)
3675 Lisp_Object display; 3695 Lisp_Object terminal;
3676{ 3696{
3677 struct x_display_info *dpyinfo = check_x_display_info (display); 3697 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3678 char *vendor = ServerVendor (dpyinfo->display); 3698 char *vendor = ServerVendor (dpyinfo->display);
3679 3699
3680 if (! vendor) vendor = ""; 3700 if (! vendor) vendor = "";
@@ -3682,18 +3702,18 @@ If omitted or nil, that stands for the selected frame's display. */)
3682} 3702}
3683 3703
3684DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, 3704DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
3685 doc: /* Returns the version numbers of the X server of display DISPLAY. 3705 doc: /* Returns the version numbers of the X server of display TERMINAL.
3686The value is a list of three integers: the major and minor 3706The value is a list of three integers: the major and minor
3687version numbers of the X Protocol in use, and the distributor-specific release 3707version numbers of the X Protocol in use, and the distributor-specific release
3688number. See also the function `x-server-vendor'. 3708number. See also the function `x-server-vendor'.
3689 3709
3690The optional argument DISPLAY specifies which display to ask about. 3710The optional argument TERMINAL specifies which display to ask about.
3691DISPLAY should be either a frame or a display name (a string). 3711TERMINAL should be a terminal id, a frame or a display name (a string).
3692If omitted or nil, that stands for the selected frame's display. */) 3712If omitted or nil, that stands for the selected frame's display. */)
3693 (display) 3713 (terminal)
3694 Lisp_Object display; 3714 Lisp_Object terminal;
3695{ 3715{
3696 struct x_display_info *dpyinfo = check_x_display_info (display); 3716 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3697 Display *dpy = dpyinfo->display; 3717 Display *dpy = dpyinfo->display;
3698 3718
3699 return Fcons (make_number (ProtocolVersion (dpy)), 3719 return Fcons (make_number (ProtocolVersion (dpy)),
@@ -3702,55 +3722,55 @@ If omitted or nil, that stands for the selected frame's display. */)
3702} 3722}
3703 3723
3704DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, 3724DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3705 doc: /* Return the number of screens on the X server of display DISPLAY. 3725 doc: /* Return the number of screens on the X server of display TERMINAL.
3706The optional argument DISPLAY specifies which display to ask about. 3726The optional argument TERMINAL specifies which display to ask about.
3707DISPLAY should be either a frame or a display name (a string). 3727TERMINAL should be a terminal id, a frame or a display name (a string).
3708If omitted or nil, that stands for the selected frame's display. */) 3728If omitted or nil, that stands for the selected frame's display. */)
3709 (display) 3729 (terminal)
3710 Lisp_Object display; 3730 Lisp_Object terminal;
3711{ 3731{
3712 struct x_display_info *dpyinfo = check_x_display_info (display); 3732 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3713 3733
3714 return make_number (ScreenCount (dpyinfo->display)); 3734 return make_number (ScreenCount (dpyinfo->display));
3715} 3735}
3716 3736
3717DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, 3737DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3718 doc: /* Return the height in millimeters of the X display DISPLAY. 3738 doc: /* Return the height in millimeters of the X display TERMINAL.
3719The optional argument DISPLAY specifies which display to ask about. 3739The optional argument TERMINAL specifies which display to ask about.
3720DISPLAY should be either a frame or a display name (a string). 3740TERMINAL should be a terminal id, a frame or a display name (a string).
3721If omitted or nil, that stands for the selected frame's display. */) 3741If omitted or nil, that stands for the selected frame's display. */)
3722 (display) 3742 (terminal)
3723 Lisp_Object display; 3743 Lisp_Object terminal;
3724{ 3744{
3725 struct x_display_info *dpyinfo = check_x_display_info (display); 3745 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3726 3746
3727 return make_number (HeightMMOfScreen (dpyinfo->screen)); 3747 return make_number (HeightMMOfScreen (dpyinfo->screen));
3728} 3748}
3729 3749
3730DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, 3750DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3731 doc: /* Return the width in millimeters of the X display DISPLAY. 3751 doc: /* Return the width in millimeters of the X display TERMINAL.
3732The optional argument DISPLAY specifies which display to ask about. 3752The optional argument TERMINAL specifies which display to ask about.
3733DISPLAY should be either a frame or a display name (a string). 3753TERMINAL should be a terminal id, a frame or a display name (a string).
3734If omitted or nil, that stands for the selected frame's display. */) 3754If omitted or nil, that stands for the selected frame's display. */)
3735 (display) 3755 (terminal)
3736 Lisp_Object display; 3756 Lisp_Object terminal;
3737{ 3757{
3738 struct x_display_info *dpyinfo = check_x_display_info (display); 3758 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3739 3759
3740 return make_number (WidthMMOfScreen (dpyinfo->screen)); 3760 return make_number (WidthMMOfScreen (dpyinfo->screen));
3741} 3761}
3742 3762
3743DEFUN ("x-display-backing-store", Fx_display_backing_store, 3763DEFUN ("x-display-backing-store", Fx_display_backing_store,
3744 Sx_display_backing_store, 0, 1, 0, 3764 Sx_display_backing_store, 0, 1, 0,
3745 doc: /* Returns an indication of whether X display DISPLAY does backing store. 3765 doc: /* Returns an indication of whether X display TERMINAL does backing store.
3746The value may be `always', `when-mapped', or `not-useful'. 3766The value may be `always', `when-mapped', or `not-useful'.
3747The optional argument DISPLAY specifies which display to ask about. 3767The optional argument TERMINAL specifies which display to ask about.
3748DISPLAY should be either a frame or a display name (a string). 3768TERMINAL should be a terminal id, a frame or a display name (a string).
3749If omitted or nil, that stands for the selected frame's display. */) 3769If omitted or nil, that stands for the selected frame's display. */)
3750 (display) 3770 (terminal)
3751 Lisp_Object display; 3771 Lisp_Object terminal;
3752{ 3772{
3753 struct x_display_info *dpyinfo = check_x_display_info (display); 3773 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3754 Lisp_Object result; 3774 Lisp_Object result;
3755 3775
3756 switch (DoesBackingStore (dpyinfo->screen)) 3776 switch (DoesBackingStore (dpyinfo->screen))
@@ -3777,17 +3797,17 @@ If omitted or nil, that stands for the selected frame's display. */)
3777 3797
3778DEFUN ("x-display-visual-class", Fx_display_visual_class, 3798DEFUN ("x-display-visual-class", Fx_display_visual_class,
3779 Sx_display_visual_class, 0, 1, 0, 3799 Sx_display_visual_class, 0, 1, 0,
3780 doc: /* Return the visual class of the X display DISPLAY. 3800 doc: /* Return the visual class of the X display TERMINAL.
3781The value is one of the symbols `static-gray', `gray-scale', 3801The value is one of the symbols `static-gray', `gray-scale',
3782`static-color', `pseudo-color', `true-color', or `direct-color'. 3802`static-color', `pseudo-color', `true-color', or `direct-color'.
3783 3803
3784The optional argument DISPLAY specifies which display to ask about. 3804The optional argument TERMINAL specifies which display to ask about.
3785DISPLAY should be either a frame or a display name (a string). 3805TERMINAL should a terminal id, a frame or a display name (a string).
3786If omitted or nil, that stands for the selected frame's display. */) 3806If omitted or nil, that stands for the selected frame's display. */)
3787 (display) 3807 (terminal)
3788 Lisp_Object display; 3808 Lisp_Object terminal;
3789{ 3809{
3790 struct x_display_info *dpyinfo = check_x_display_info (display); 3810 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3791 Lisp_Object result; 3811 Lisp_Object result;
3792 3812
3793 switch (dpyinfo->visual->class) 3813 switch (dpyinfo->visual->class)
@@ -3820,14 +3840,14 @@ If omitted or nil, that stands for the selected frame's display. */)
3820 3840
3821DEFUN ("x-display-save-under", Fx_display_save_under, 3841DEFUN ("x-display-save-under", Fx_display_save_under,
3822 Sx_display_save_under, 0, 1, 0, 3842 Sx_display_save_under, 0, 1, 0,
3823 doc: /* Returns t if the X display DISPLAY supports the save-under feature. 3843 doc: /* Returns t if the X display TERMINAL supports the save-under feature.
3824The optional argument DISPLAY specifies which display to ask about. 3844The optional argument TERMINAL specifies which display to ask about.
3825DISPLAY should be either a frame or a display name (a string). 3845TERMINAL should be a terminal id, a frame or a display name (a string).
3826If omitted or nil, that stands for the selected frame's display. */) 3846If omitted or nil, that stands for the selected frame's display. */)
3827 (display) 3847 (terminal)
3828 Lisp_Object display; 3848 Lisp_Object terminal;
3829{ 3849{
3830 struct x_display_info *dpyinfo = check_x_display_info (display); 3850 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3831 3851
3832 if (DoesSaveUnders (dpyinfo->screen) == True) 3852 if (DoesSaveUnders (dpyinfo->screen) == True)
3833 return Qt; 3853 return Qt;
@@ -4008,8 +4028,10 @@ x_display_info_for_name (name)
4008 4028
4009 CHECK_STRING (name); 4029 CHECK_STRING (name);
4010 4030
4011 if (! EQ (Vwindow_system, intern ("x"))) 4031#if 0
4012 error ("Not using X Windows"); 4032 if (! EQ (Vinitial_window_system, intern ("x")))
4033 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4034#endif
4013 4035
4014 for (dpyinfo = x_display_list, names = x_display_name_list; 4036 for (dpyinfo = x_display_list, names = x_display_name_list;
4015 dpyinfo; 4037 dpyinfo;
@@ -4056,8 +4078,10 @@ terminate Emacs if we can't open the connection. */)
4056 if (! NILP (xrm_string)) 4078 if (! NILP (xrm_string))
4057 CHECK_STRING (xrm_string); 4079 CHECK_STRING (xrm_string);
4058 4080
4059 if (! EQ (Vwindow_system, intern ("x"))) 4081#if 0
4060 error ("Not using X Windows"); 4082 if (! EQ (Vinitial_window_system, intern ("x")))
4083 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4084#endif
4061 4085
4062 if (! NILP (xrm_string)) 4086 if (! NILP (xrm_string))
4063 xrm_option = (unsigned char *) SDATA (xrm_string); 4087 xrm_option = (unsigned char *) SDATA (xrm_string);
@@ -4092,41 +4116,19 @@ An insecure way to solve the problem may be to use `xhost'.\n",
4092 4116
4093DEFUN ("x-close-connection", Fx_close_connection, 4117DEFUN ("x-close-connection", Fx_close_connection,
4094 Sx_close_connection, 1, 1, 0, 4118 Sx_close_connection, 1, 1, 0,
4095 doc: /* Close the connection to DISPLAY's X server. 4119 doc: /* Close the connection to TERMINAL's X server.
4096For DISPLAY, specify either a frame or a display name (a string). 4120For TERMINAL, specify a terminal id, a frame or a display name (a
4097If DISPLAY is nil, that stands for the selected frame's display. */) 4121string). If TERMINAL is nil, that stands for the selected frame's
4098 (display) 4122terminal. */)
4099 Lisp_Object display; 4123 (terminal)
4124 Lisp_Object terminal;
4100{ 4125{
4101 struct x_display_info *dpyinfo = check_x_display_info (display); 4126 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4102 int i;
4103 4127
4104 if (dpyinfo->reference_count > 0) 4128 if (dpyinfo->reference_count > 0)
4105 error ("Display still has frames on it"); 4129 error ("Display still has frames on it");
4106 4130
4107 BLOCK_INPUT; 4131 x_delete_terminal (dpyinfo->terminal);
4108 /* Free the fonts in the font table. */
4109 for (i = 0; i < dpyinfo->n_fonts; i++)
4110 if (dpyinfo->font_table[i].name)
4111 {
4112 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
4113 }
4114
4115 x_destroy_all_bitmaps (dpyinfo);
4116 XSetCloseDownMode (dpyinfo->display, DestroyAll);
4117
4118#ifdef USE_GTK
4119 xg_display_close (dpyinfo->display);
4120#else
4121#ifdef USE_X_TOOLKIT
4122 XtCloseDisplay (dpyinfo->display);
4123#else
4124 XCloseDisplay (dpyinfo->display);
4125#endif
4126#endif /* ! USE_GTK */
4127
4128 x_delete_display (dpyinfo);
4129 UNBLOCK_INPUT;
4130 4132
4131 return Qnil; 4133 return Qnil;
4132} 4134}
@@ -4150,13 +4152,13 @@ If ON is nil, allow buffering of requests.
4150Turning on synchronization prohibits the Xlib routines from buffering 4152Turning on synchronization prohibits the Xlib routines from buffering
4151requests and seriously degrades performance, but makes debugging much 4153requests and seriously degrades performance, but makes debugging much
4152easier. 4154easier.
4153The optional second argument DISPLAY specifies which display to act on. 4155The optional second argument TERMINAL specifies which display to act on.
4154DISPLAY should be either a frame or a display name (a string). 4156TERMINAL should be a terminal id, a frame or a display name (a string).
4155If DISPLAY is omitted or nil, that stands for the selected frame's display. */) 4157If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4156 (on, display) 4158 (on, terminal)
4157 Lisp_Object display, on; 4159 Lisp_Object terminal, on;
4158{ 4160{
4159 struct x_display_info *dpyinfo = check_x_display_info (display); 4161 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4160 4162
4161 XSynchronize (dpyinfo->display, !EQ (on, Qnil)); 4163 XSynchronize (dpyinfo->display, !EQ (on, Qnil));
4162 4164
@@ -4460,10 +4462,6 @@ start_hourglass ()
4460 EMACS_TIME delay; 4462 EMACS_TIME delay;
4461 int secs, usecs = 0; 4463 int secs, usecs = 0;
4462 4464
4463 /* Don't bother for ttys. */
4464 if (NILP (Vwindow_system))
4465 return;
4466
4467 cancel_hourglass (); 4465 cancel_hourglass ();
4468 4466
4469 if (INTEGERP (Vhourglass_delay) 4467 if (INTEGERP (Vhourglass_delay)
@@ -4675,20 +4673,16 @@ x_create_tip_frame (dpyinfo, parms, text)
4675 int width, height; 4673 int width, height;
4676 int count = SPECPDL_INDEX (); 4674 int count = SPECPDL_INDEX ();
4677 struct gcpro gcpro1, gcpro2, gcpro3; 4675 struct gcpro gcpro1, gcpro2, gcpro3;
4678 struct kboard *kb;
4679 int face_change_count_before = face_change_count; 4676 int face_change_count_before = face_change_count;
4680 Lisp_Object buffer; 4677 Lisp_Object buffer;
4681 struct buffer *old_buffer; 4678 struct buffer *old_buffer;
4682 4679
4683 check_x (); 4680 check_x ();
4684 4681
4685 parms = Fcopy_alist (parms); 4682 if (dpyinfo->terminal->deleted)
4683 error ("Terminal is being deleted, can't create new frames on it");
4686 4684
4687#ifdef MULTI_KBOARD 4685 parms = Fcopy_alist (parms);
4688 kb = dpyinfo->kboard;
4689#else
4690 kb = &the_only_kboard;
4691#endif
4692 4686
4693 /* Get the name of the frame to use for resource lookup. */ 4687 /* Get the name of the frame to use for resource lookup. */
4694 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); 4688 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
@@ -4716,6 +4710,9 @@ x_create_tip_frame (dpyinfo, parms, text)
4716 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; 4710 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
4717 record_unwind_protect (unwind_create_tip_frame, frame); 4711 record_unwind_protect (unwind_create_tip_frame, frame);
4718 4712
4713 f->terminal = dpyinfo->terminal;
4714 f->terminal->reference_count++;
4715
4719 /* By setting the output method, we're essentially saying that 4716 /* By setting the output method, we're essentially saying that
4720 the frame is live, as per FRAME_LIVE_P. If we get a signal 4717 the frame is live, as per FRAME_LIVE_P. If we get a signal
4721 from this point on, x_destroy_window might screw up reference 4718 from this point on, x_destroy_window might screw up reference
@@ -4737,9 +4734,6 @@ x_create_tip_frame (dpyinfo, parms, text)
4737 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; 4734 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
4738 dpyinfo_refcount = dpyinfo->reference_count; 4735 dpyinfo_refcount = dpyinfo->reference_count;
4739#endif /* GLYPH_DEBUG */ 4736#endif /* GLYPH_DEBUG */
4740#ifdef MULTI_KBOARD
4741 FRAME_KBOARD (f) = kb;
4742#endif
4743 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; 4737 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4744 f->output_data.x->explicit_parent = 0; 4738 f->output_data.x->explicit_parent = 0;
4745 4739
@@ -4749,11 +4743,21 @@ x_create_tip_frame (dpyinfo, parms, text)
4749 Lisp_Object black; 4743 Lisp_Object black;
4750 struct gcpro gcpro1; 4744 struct gcpro gcpro1;
4751 4745
4746 /* Function x_decode_color can signal an error. Make
4747 sure to initialize color slots so that we won't try
4748 to free colors we haven't allocated. */
4749 FRAME_FOREGROUND_PIXEL (f) = -1;
4750 FRAME_BACKGROUND_PIXEL (f) = -1;
4751 f->output_data.x->cursor_pixel = -1;
4752 f->output_data.x->cursor_foreground_pixel = -1;
4753 f->output_data.x->border_pixel = -1;
4754 f->output_data.x->mouse_pixel = -1;
4755
4752 black = build_string ("black"); 4756 black = build_string ("black");
4753 GCPRO1 (black); 4757 GCPRO1 (black);
4754 f->output_data.x->foreground_pixel 4758 FRAME_FOREGROUND_PIXEL (f)
4755 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4759 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4756 f->output_data.x->background_pixel 4760 FRAME_BACKGROUND_PIXEL (f)
4757 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4761 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4758 f->output_data.x->cursor_pixel 4762 f->output_data.x->cursor_pixel
4759 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4763 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
@@ -4939,6 +4943,8 @@ x_create_tip_frame (dpyinfo, parms, text)
4939 Qnil)); 4943 Qnil));
4940 } 4944 }
4941 4945
4946 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil));
4947
4942 f->no_split = 1; 4948 f->no_split = 1;
4943 4949
4944 UNGCPRO; 4950 UNGCPRO;
diff --git a/src/xmenu.c b/src/xmenu.c
index fd6fc960739..228c89f9aa4 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -41,10 +41,10 @@ Boston, MA 02110-1301, USA. */
41#include <stdio.h> 41#include <stdio.h>
42 42
43#include "lisp.h" 43#include "lisp.h"
44#include "termhooks.h"
45#include "keyboard.h" 44#include "keyboard.h"
46#include "keymap.h" 45#include "keymap.h"
47#include "frame.h" 46#include "frame.h"
47#include "termhooks.h"
48#include "window.h" 48#include "window.h"
49#include "blockinput.h" 49#include "blockinput.h"
50#include "buffer.h" 50#include "buffer.h"
@@ -741,6 +741,9 @@ mouse_position_for_popup (f, x, y)
741 Window root, dummy_window; 741 Window root, dummy_window;
742 int dummy; 742 int dummy;
743 743
744 if (! FRAME_X_P (f))
745 abort ();
746
744 BLOCK_INPUT; 747 BLOCK_INPUT;
745 748
746 XQueryPointer (FRAME_X_DISPLAY (f), 749 XQueryPointer (FRAME_X_DISPLAY (f),
@@ -936,6 +939,9 @@ no quit occurs and `x-popup-menu' returns nil. */)
936 xpos += XINT (x); 939 xpos += XINT (x);
937 ypos += XINT (y); 940 ypos += XINT (y);
938 941
942 if (! FRAME_X_P (f))
943 error ("Can not put X menu on non-X terminal");
944
939 XSETFRAME (Vmenu_updating_frame, f); 945 XSETFRAME (Vmenu_updating_frame, f);
940 } 946 }
941 else 947 else
@@ -1124,6 +1130,9 @@ for instance using the window manager, then this produces a quit and
1124 but I don't want to make one now. */ 1130 but I don't want to make one now. */
1125 CHECK_WINDOW (window); 1131 CHECK_WINDOW (window);
1126 1132
1133 if (! FRAME_X_P (f))
1134 error ("Can not put X dialog on non-X terminal");
1135
1127#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) 1136#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1128 /* Display a menu with these alternatives 1137 /* Display a menu with these alternatives
1129 in the middle of frame F. */ 1138 in the middle of frame F. */
@@ -1305,7 +1314,7 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers)
1305 } 1314 }
1306} 1315}
1307 1316
1308DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i", 1317DEFUN ("x-menu-bar-open-internal", Fx_menu_bar_open_internal, Sx_menu_bar_open_internal, 0, 1, "i",
1309 doc: /* Start key navigation of the menu bar in FRAME. 1318 doc: /* Start key navigation of the menu bar in FRAME.
1310This initially opens the first menu bar item and you can then navigate with the 1319This initially opens the first menu bar item and you can then navigate with the
1311arrow keys, select a menu entry with the return key or cancel with the 1320arrow keys, select a menu entry with the return key or cancel with the
@@ -1384,7 +1393,7 @@ If FRAME is nil or not given, use the selected frame. */)
1384 1393
1385 1394
1386#ifdef USE_GTK 1395#ifdef USE_GTK
1387DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i", 1396DEFUN ("x-menu-bar-open-internal", Fx_menu_bar_open_internal, Sx_menu_bar_open_internal, 0, 1, "i",
1388 doc: /* Start key navigation of the menu bar in FRAME. 1397 doc: /* Start key navigation of the menu bar in FRAME.
1389This initially opens the first menu bar item and you can then navigate with the 1398This initially opens the first menu bar item and you can then navigate with the
1390arrow keys, select a menu entry with the return key or cancel with the 1399arrow keys, select a menu entry with the return key or cancel with the
@@ -1460,6 +1469,9 @@ void
1460x_activate_menubar (f) 1469x_activate_menubar (f)
1461 FRAME_PTR f; 1470 FRAME_PTR f;
1462{ 1471{
1472 if (! FRAME_X_P (f))
1473 abort ();
1474
1463 if (!f->output_data.x->saved_menu_event->type) 1475 if (!f->output_data.x->saved_menu_event->type)
1464 return; 1476 return;
1465 1477
@@ -2094,9 +2106,14 @@ update_frame_menubar (f)
2094#ifdef USE_GTK 2106#ifdef USE_GTK
2095 return xg_update_frame_menubar (f); 2107 return xg_update_frame_menubar (f);
2096#else 2108#else
2097 struct x_output *x = f->output_data.x; 2109 struct x_output *x;
2098 int columns, rows; 2110 int columns, rows;
2099 2111
2112 if (! FRAME_X_P (f))
2113 abort ();
2114
2115 x = f->output_data.x;
2116
2100 if (!x->menubar_widget || XtIsManaged (x->menubar_widget)) 2117 if (!x->menubar_widget || XtIsManaged (x->menubar_widget))
2101 return 0; 2118 return 0;
2102 2119
@@ -2142,7 +2159,7 @@ set_frame_menubar (f, first_time, deep_p)
2142 int first_time; 2159 int first_time;
2143 int deep_p; 2160 int deep_p;
2144{ 2161{
2145 xt_or_gtk_widget menubar_widget = f->output_data.x->menubar_widget; 2162 xt_or_gtk_widget menubar_widget;
2146#ifdef USE_X_TOOLKIT 2163#ifdef USE_X_TOOLKIT
2147 LWLIB_ID id; 2164 LWLIB_ID id;
2148#endif 2165#endif
@@ -2152,6 +2169,10 @@ set_frame_menubar (f, first_time, deep_p)
2152 int *submenu_start, *submenu_end; 2169 int *submenu_start, *submenu_end;
2153 int *submenu_top_level_items, *submenu_n_panes; 2170 int *submenu_top_level_items, *submenu_n_panes;
2154 2171
2172 if (! FRAME_X_P (f))
2173 abort ();
2174
2175 menubar_widget = f->output_data.x->menubar_widget;
2155 2176
2156 XSETFRAME (Vmenu_updating_frame, f); 2177 XSETFRAME (Vmenu_updating_frame, f);
2157 2178
@@ -2504,6 +2525,9 @@ free_frame_menubar (f)
2504{ 2525{
2505 Widget menubar_widget; 2526 Widget menubar_widget;
2506 2527
2528 if (! FRAME_X_P (f))
2529 abort ();
2530
2507 menubar_widget = f->output_data.x->menubar_widget; 2531 menubar_widget = f->output_data.x->menubar_widget;
2508 2532
2509 f->output_data.x->menubar_height = 0; 2533 f->output_data.x->menubar_height = 0;
@@ -2656,6 +2680,9 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click)
2656 struct next_popup_x_y popup_x_y; 2680 struct next_popup_x_y popup_x_y;
2657 int specpdl_count = SPECPDL_INDEX (); 2681 int specpdl_count = SPECPDL_INDEX ();
2658 2682
2683 if (! FRAME_X_P (f))
2684 abort ();
2685
2659 xg_crazy_callback_abort = 1; 2686 xg_crazy_callback_abort = 1;
2660 menu = xg_create_widget ("popup", first_wv->name, f, first_wv, 2687 menu = xg_create_widget ("popup", first_wv->name, f, first_wv,
2661 G_CALLBACK (popup_selection_callback), 2688 G_CALLBACK (popup_selection_callback),
@@ -2764,6 +2791,9 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click)
2764 LWLIB_ID menu_id; 2791 LWLIB_ID menu_id;
2765 Widget menu; 2792 Widget menu;
2766 2793
2794 if (! FRAME_X_P (f))
2795 abort ();
2796
2767 menu_id = widget_id_tick++; 2797 menu_id = widget_id_tick++;
2768 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv, 2798 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv,
2769 f->output_data.x->widget, 1, 0, 2799 f->output_data.x->widget, 1, 0,
@@ -2840,6 +2870,9 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
2840 2870
2841 int first_pane; 2871 int first_pane;
2842 2872
2873 if (! FRAME_X_P (f))
2874 abort ();
2875
2843 *error = NULL; 2876 *error = NULL;
2844 2877
2845 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH) 2878 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
@@ -3122,6 +3155,9 @@ create_and_show_dialog (f, first_wv)
3122{ 3155{
3123 GtkWidget *menu; 3156 GtkWidget *menu;
3124 3157
3158 if (! FRAME_X_P (f))
3159 abort ();
3160
3125 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv, 3161 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv,
3126 G_CALLBACK (dialog_selection_callback), 3162 G_CALLBACK (dialog_selection_callback),
3127 G_CALLBACK (popup_deactivate_callback), 3163 G_CALLBACK (popup_deactivate_callback),
@@ -3171,6 +3207,9 @@ create_and_show_dialog (f, first_wv)
3171{ 3207{
3172 LWLIB_ID dialog_id; 3208 LWLIB_ID dialog_id;
3173 3209
3210 if (!FRAME_X_P (f))
3211 abort();
3212
3174 dialog_id = widget_id_tick++; 3213 dialog_id = widget_id_tick++;
3175 lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv, 3214 lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv,
3176 f->output_data.x->widget, 1, 0, 3215 f->output_data.x->widget, 1, 0,
@@ -3223,6 +3262,9 @@ xdialog_show (f, keymaps, title, header, error_name)
3223 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ 3262 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
3224 int boundary_seen = 0; 3263 int boundary_seen = 0;
3225 3264
3265 if (! FRAME_X_P (f))
3266 abort ();
3267
3226 *error_name = NULL; 3268 *error_name = NULL;
3227 3269
3228 if (menu_items_n_panes > 1) 3270 if (menu_items_n_panes > 1)
@@ -3498,6 +3540,9 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
3498 unsigned int dummy_uint; 3540 unsigned int dummy_uint;
3499 int specpdl_count = SPECPDL_INDEX (); 3541 int specpdl_count = SPECPDL_INDEX ();
3500 3542
3543 if (! FRAME_X_P (f))
3544 abort ();
3545
3501 *error = 0; 3546 *error = 0;
3502 if (menu_items_n_panes == 0) 3547 if (menu_items_n_panes == 0)
3503 return Qnil; 3548 return Qnil;
@@ -3802,8 +3847,9 @@ syms_of_xmenu ()
3802 defsubr (&Smenu_or_popup_active_p); 3847 defsubr (&Smenu_or_popup_active_p);
3803 3848
3804#if defined (USE_GTK) || defined (USE_X_TOOLKIT) 3849#if defined (USE_GTK) || defined (USE_X_TOOLKIT)
3805 defsubr (&Smenu_bar_open); 3850 defsubr (&Sx_menu_bar_open_internal);
3806 Ffset (intern ("accelerate-menu"), intern (Smenu_bar_open.symbol_name)); 3851 Ffset (intern ("accelerate-menu"),
3852 intern (Sx_menu_bar_open_internal.symbol_name));
3807#endif 3853#endif
3808 3854
3809#ifdef HAVE_MENUS 3855#ifdef HAVE_MENUS
diff --git a/src/xselect.c b/src/xselect.c
index 3fe109a5b85..cb00903c41e 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -398,12 +398,19 @@ x_own_selection (selection_name, selection_value)
398 Lisp_Object selection_name, selection_value; 398 Lisp_Object selection_name, selection_value;
399{ 399{
400 struct frame *sf = SELECTED_FRAME (); 400 struct frame *sf = SELECTED_FRAME ();
401 Window selecting_window = FRAME_X_WINDOW (sf); 401 Window selecting_window;
402 Display *display = FRAME_X_DISPLAY (sf); 402 Display *display;
403 Time time = last_event_timestamp; 403 Time time = last_event_timestamp;
404 Atom selection_atom; 404 Atom selection_atom;
405 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); 405 struct x_display_info *dpyinfo;
406
407 if (! FRAME_X_P (sf))
408 return;
406 409
410 selecting_window = FRAME_X_WINDOW (sf);
411 display = FRAME_X_DISPLAY (sf);
412 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
413
407 CHECK_SYMBOL (selection_name); 414 CHECK_SYMBOL (selection_name);
408 selection_atom = symbol_to_x_atom (dpyinfo, display, selection_name); 415 selection_atom = symbol_to_x_atom (dpyinfo, display, selection_name);
409 416
@@ -671,7 +678,8 @@ some_frame_on_display (dpyinfo)
671 678
672 FOR_EACH_FRAME (list, frame) 679 FOR_EACH_FRAME (list, frame)
673 { 680 {
674 if (FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) 681 if (FRAME_X_P (XFRAME (frame))
682 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
675 return frame; 683 return frame;
676 } 684 }
677 685
@@ -1021,7 +1029,7 @@ x_handle_selection_clear (event)
1021 to see if this Emacs job now owns the selection 1029 to see if this Emacs job now owns the selection
1022 through that display. */ 1030 through that display. */
1023 for (t_dpyinfo = x_display_list; t_dpyinfo; t_dpyinfo = t_dpyinfo->next) 1031 for (t_dpyinfo = x_display_list; t_dpyinfo; t_dpyinfo = t_dpyinfo->next)
1024 if (t_dpyinfo->kboard == dpyinfo->kboard) 1032 if (t_dpyinfo->terminal->kboard == dpyinfo->terminal->kboard)
1025 { 1033 {
1026 Window owner_window 1034 Window owner_window
1027 = XGetSelectionOwner (t_dpyinfo->display, selection); 1035 = XGetSelectionOwner (t_dpyinfo->display, selection);
@@ -1380,17 +1388,26 @@ x_get_foreign_selection (selection_symbol, target_type, time_stamp)
1380 Lisp_Object selection_symbol, target_type, time_stamp; 1388 Lisp_Object selection_symbol, target_type, time_stamp;
1381{ 1389{
1382 struct frame *sf = SELECTED_FRAME (); 1390 struct frame *sf = SELECTED_FRAME ();
1383 Window requestor_window = FRAME_X_WINDOW (sf); 1391 Window requestor_window;
1384 Display *display = FRAME_X_DISPLAY (sf); 1392 Display *display;
1385 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); 1393 struct x_display_info *dpyinfo;
1386 Time requestor_time = last_event_timestamp; 1394 Time requestor_time = last_event_timestamp;
1387 Atom target_property = dpyinfo->Xatom_EMACS_TMP; 1395 Atom target_property;
1388 Atom selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol); 1396 Atom selection_atom;
1389 Atom type_atom; 1397 Atom type_atom;
1390 int secs, usecs; 1398 int secs, usecs;
1391 int count = SPECPDL_INDEX (); 1399 int count = SPECPDL_INDEX ();
1392 Lisp_Object frame; 1400 Lisp_Object frame;
1393 1401
1402 if (! FRAME_X_P (sf))
1403 return Qnil;
1404
1405 requestor_window = FRAME_X_WINDOW (sf);
1406 display = FRAME_X_DISPLAY (sf);
1407 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
1408 target_property = dpyinfo->Xatom_EMACS_TMP;
1409 selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol);
1410
1394 if (CONSP (target_type)) 1411 if (CONSP (target_type))
1395 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type)); 1412 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type));
1396 else 1413 else
@@ -2206,6 +2223,9 @@ Disowning it means there is no such selection. */)
2206 struct frame *sf = SELECTED_FRAME (); 2223 struct frame *sf = SELECTED_FRAME ();
2207 2224
2208 check_x (); 2225 check_x ();
2226 if (! FRAME_X_P (sf))
2227 return Qnil;
2228
2209 display = FRAME_X_DISPLAY (sf); 2229 display = FRAME_X_DISPLAY (sf);
2210 dpyinfo = FRAME_X_DISPLAY_INFO (sf); 2230 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
2211 CHECK_SYMBOL (selection); 2231 CHECK_SYMBOL (selection);
@@ -2367,6 +2387,10 @@ DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal,
2367 struct frame *sf = SELECTED_FRAME (); 2387 struct frame *sf = SELECTED_FRAME ();
2368 2388
2369 check_x (); 2389 check_x ();
2390
2391 if (! FRAME_X_P (sf))
2392 return Qnil;
2393
2370 display = FRAME_X_DISPLAY (sf); 2394 display = FRAME_X_DISPLAY (sf);
2371 dpyinfo = FRAME_X_DISPLAY_INFO (sf); 2395 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
2372 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2396 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
@@ -2407,6 +2431,10 @@ DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal,
2407 struct frame *sf = SELECTED_FRAME (); 2431 struct frame *sf = SELECTED_FRAME ();
2408 2432
2409 check_x (); 2433 check_x ();
2434
2435 if (! FRAME_X_P (sf))
2436 return Qnil;
2437
2410 display = FRAME_X_DISPLAY (sf); 2438 display = FRAME_X_DISPLAY (sf);
2411 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2439 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2412 2440
@@ -2463,8 +2491,12 @@ Positive means shift the values forward, negative means backward. */)
2463 Atom props[8]; 2491 Atom props[8];
2464 Display *display; 2492 Display *display;
2465 struct frame *sf = SELECTED_FRAME (); 2493 struct frame *sf = SELECTED_FRAME ();
2466 2494
2467 check_x (); 2495 check_x ();
2496
2497 if (! FRAME_X_P (sf))
2498 return Qnil;
2499
2468 display = FRAME_X_DISPLAY (sf); 2500 display = FRAME_X_DISPLAY (sf);
2469 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2501 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2470 CHECK_NUMBER (n); 2502 CHECK_NUMBER (n);
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 5a3fdbb8812..7a78a8e60e6 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -48,6 +48,7 @@ Boston, MA 02110-1301, USA. */
48#include "lisp.h" 48#include "lisp.h"
49#include "systime.h" 49#include "systime.h"
50#include "sysselect.h" 50#include "sysselect.h"
51#include "frame.h"
51#include "termhooks.h" 52#include "termhooks.h"
52#include "termopts.h" 53#include "termopts.h"
53#include "xterm.h" 54#include "xterm.h"
@@ -510,6 +511,14 @@ x_session_initialize (dpyinfo)
510 } 511 }
511} 512}
512 513
514/* Ensure that the session manager is not contacted again. */
515
516void
517x_session_close ()
518{
519 ice_fd = -1;
520}
521
513 522
514DEFUN ("handle-save-session", Fhandle_save_session, 523DEFUN ("handle-save-session", Fhandle_save_session,
515 Shandle_save_session, 1, 1, "e", 524 Shandle_save_session, 1, 1, "e",
diff --git a/src/xterm.c b/src/xterm.c
index 4f77e22ac59..8b0078d6af6 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -54,7 +54,6 @@ Boston, MA 02110-1301, USA. */
54#include <sys/ioctl.h> 54#include <sys/ioctl.h>
55#endif /* ! defined (BSD_SYSTEM) */ 55#endif /* ! defined (BSD_SYSTEM) */
56 56
57#include "systty.h"
58#include "systime.h" 57#include "systime.h"
59 58
60#ifndef INCLUDED_FCNTL 59#ifndef INCLUDED_FCNTL
@@ -322,6 +321,10 @@ static Lisp_Object Qalt, Qhyper, Qmeta, Qsuper, Qmodifier_value;
322static Lisp_Object Qvendor_specific_keysyms; 321static Lisp_Object Qvendor_specific_keysyms;
323static Lisp_Object Qlatin_1; 322static Lisp_Object Qlatin_1;
324 323
324/* Used in x_flush. */
325
326extern Lisp_Object Vinhibit_redisplay;
327
325extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); 328extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
326extern int x_bitmap_mask P_ ((FRAME_PTR, int)); 329extern int x_bitmap_mask P_ ((FRAME_PTR, int));
327 330
@@ -331,13 +334,15 @@ static const XColor *x_color_cells P_ ((Display *, int *));
331static void x_update_window_end P_ ((struct window *, int, int)); 334static void x_update_window_end P_ ((struct window *, int, int));
332 335
333static int x_io_error_quitter P_ ((Display *)); 336static int x_io_error_quitter P_ ((Display *));
337static struct terminal *x_create_terminal P_ ((struct x_display_info *));
338void x_delete_terminal P_ ((struct terminal *));
334static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); 339static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
335static int x_compute_min_glyph_bounds P_ ((struct frame *)); 340static int x_compute_min_glyph_bounds P_ ((struct frame *));
336static void x_update_end P_ ((struct frame *)); 341static void x_update_end P_ ((struct frame *));
337static void XTframe_up_to_date P_ ((struct frame *)); 342static void XTframe_up_to_date P_ ((struct frame *));
338static void XTset_terminal_modes P_ ((void)); 343static void XTset_terminal_modes P_ ((struct terminal *));
339static void XTreset_terminal_modes P_ ((void)); 344static void XTreset_terminal_modes P_ ((struct terminal *));
340static void x_clear_frame P_ ((void)); 345static void x_clear_frame P_ ((struct frame *));
341static void frame_highlight P_ ((struct frame *)); 346static void frame_highlight P_ ((struct frame *));
342static void frame_unhighlight P_ ((struct frame *)); 347static void frame_unhighlight P_ ((struct frame *));
343static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); 348static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *));
@@ -375,12 +380,18 @@ static void
375x_flush (f) 380x_flush (f)
376 struct frame *f; 381 struct frame *f;
377{ 382{
383 /* Don't call XFlush when it is not safe to redisplay; the X
384 connection may be broken. */
385 if (!NILP (Vinhibit_redisplay))
386 return;
387
378 BLOCK_INPUT; 388 BLOCK_INPUT;
379 if (f == NULL) 389 if (f == NULL)
380 { 390 {
381 Lisp_Object rest, frame; 391 Lisp_Object rest, frame;
382 FOR_EACH_FRAME (rest, frame) 392 FOR_EACH_FRAME (rest, frame)
383 x_flush (XFRAME (frame)); 393 if (FRAME_X_P (XFRAME (frame)))
394 x_flush (XFRAME (frame));
384 } 395 }
385 else if (FRAME_X_P (f)) 396 else if (FRAME_X_P (f))
386 XFlush (FRAME_X_DISPLAY (f)); 397 XFlush (FRAME_X_DISPLAY (f));
@@ -792,7 +803,7 @@ x_draw_fringe_bitmap (w, row, p)
792 rarely happens). */ 803 rarely happens). */
793 804
794static void 805static void
795XTset_terminal_modes () 806XTset_terminal_modes (struct terminal *terminal)
796{ 807{
797} 808}
798 809
@@ -800,7 +811,7 @@ XTset_terminal_modes ()
800 the X-windows go away, and suspending requires no action. */ 811 the X-windows go away, and suspending requires no action. */
801 812
802static void 813static void
803XTreset_terminal_modes () 814XTreset_terminal_modes (struct terminal *terminal)
804{ 815{
805} 816}
806 817
@@ -1413,7 +1424,8 @@ x_frame_of_widget (widget)
1413 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) 1424 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
1414 if (GC_FRAMEP (XCAR (tail)) 1425 if (GC_FRAMEP (XCAR (tail))
1415 && (f = XFRAME (XCAR (tail)), 1426 && (f = XFRAME (XCAR (tail)),
1416 (f->output_data.nothing != 1 1427 (FRAME_X_P (f)
1428 && f->output_data.nothing != 1
1417 && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) 1429 && FRAME_X_DISPLAY_INFO (f) == dpyinfo))
1418 && f->output_data.x->widget == widget) 1430 && f->output_data.x->widget == widget)
1419 return f; 1431 return f;
@@ -2790,7 +2802,8 @@ x_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
2790 for X frames. */ 2802 for X frames. */
2791 2803
2792static void 2804static void
2793x_delete_glyphs (n) 2805x_delete_glyphs (f, n)
2806 struct frame *f;
2794 register int n; 2807 register int n;
2795{ 2808{
2796 abort (); 2809 abort ();
@@ -2813,19 +2826,11 @@ x_clear_area (dpy, window, x, y, width, height, exposures)
2813} 2826}
2814 2827
2815 2828
2816/* Clear entire frame. If updating_frame is non-null, clear that 2829/* Clear an entire frame. */
2817 frame. Otherwise clear the selected frame. */
2818 2830
2819static void 2831static void
2820x_clear_frame () 2832x_clear_frame (struct frame *f)
2821{ 2833{
2822 struct frame *f;
2823
2824 if (updating_frame)
2825 f = updating_frame;
2826 else
2827 f = SELECTED_FRAME ();
2828
2829 /* Clearing the frame will erase any cursor, so mark them all as no 2834 /* Clearing the frame will erase any cursor, so mark them all as no
2830 longer visible. */ 2835 longer visible. */
2831 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); 2836 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -2904,8 +2909,8 @@ XTflash (f)
2904 XGCValues values; 2909 XGCValues values;
2905 2910
2906 values.function = GXxor; 2911 values.function = GXxor;
2907 values.foreground = (f->output_data.x->foreground_pixel 2912 values.foreground = (FRAME_FOREGROUND_PIXEL (f)
2908 ^ f->output_data.x->background_pixel); 2913 ^ FRAME_BACKGROUND_PIXEL (f));
2909 2914
2910 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 2915 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2911 GCFunction | GCForeground, &values); 2916 GCFunction | GCForeground, &values);
@@ -3071,7 +3076,8 @@ XTset_terminal_window (n)
3071 lines or deleting -N lines at vertical position VPOS. */ 3076 lines or deleting -N lines at vertical position VPOS. */
3072 3077
3073static void 3078static void
3074x_ins_del_lines (vpos, n) 3079x_ins_del_lines (f, vpos, n)
3080 struct frame *f;
3075 int vpos, n; 3081 int vpos, n;
3076{ 3082{
3077 abort (); 3083 abort ();
@@ -3708,7 +3714,8 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3708 3714
3709 /* Clear the mouse-moved flag for every frame on this display. */ 3715 /* Clear the mouse-moved flag for every frame on this display. */
3710 FOR_EACH_FRAME (tail, frame) 3716 FOR_EACH_FRAME (tail, frame)
3711 if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) 3717 if (FRAME_X_P (XFRAME (frame))
3718 && FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp))
3712 XFRAME (frame)->mouse_moved = 0; 3719 XFRAME (frame)->mouse_moved = 0;
3713 3720
3714 last_mouse_scroll_bar = Qnil; 3721 last_mouse_scroll_bar = Qnil;
@@ -3897,6 +3904,9 @@ x_window_to_scroll_bar (display, window_id)
3897 if (! GC_FRAMEP (frame)) 3904 if (! GC_FRAMEP (frame))
3898 abort (); 3905 abort ();
3899 3906
3907 if (! FRAME_X_P (XFRAME (frame)))
3908 continue;
3909
3900 /* Scan this frame's scroll bar list for a scroll bar with the 3910 /* Scan this frame's scroll bar list for a scroll bar with the
3901 right window ID. */ 3911 right window ID. */
3902 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); 3912 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
@@ -3931,11 +3941,14 @@ x_window_to_menu_bar (window)
3931 XGCTYPE (tail) == Lisp_Cons; 3941 XGCTYPE (tail) == Lisp_Cons;
3932 tail = XCDR (tail)) 3942 tail = XCDR (tail))
3933 { 3943 {
3934 Lisp_Object frame = XCAR (tail); 3944 if (FRAME_X_P (XFRAME (XCAR (tail))))
3935 Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget; 3945 {
3946 Lisp_Object frame = XCAR (tail);
3947 Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget;
3936 3948
3937 if (menu_bar && xlwmenu_window_p (menu_bar, window)) 3949 if (menu_bar && xlwmenu_window_p (menu_bar, window))
3938 return menu_bar; 3950 return menu_bar;
3951 }
3939 } 3952 }
3940 3953
3941 return NULL; 3954 return NULL;
@@ -4743,7 +4756,7 @@ x_scroll_bar_create (w, top, left, width, height)
4743 4756
4744 a.background_pixel = f->output_data.x->scroll_bar_background_pixel; 4757 a.background_pixel = f->output_data.x->scroll_bar_background_pixel;
4745 if (a.background_pixel == -1) 4758 if (a.background_pixel == -1)
4746 a.background_pixel = f->output_data.x->background_pixel; 4759 a.background_pixel = FRAME_BACKGROUND_PIXEL (f);
4747 4760
4748 a.event_mask = (ButtonPressMask | ButtonReleaseMask 4761 a.event_mask = (ButtonPressMask | ButtonReleaseMask
4749 | ButtonMotionMask | PointerMotionHintMask 4762 | ButtonMotionMask | PointerMotionHintMask
@@ -4917,7 +4930,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
4917 /* Restore the foreground color of the GC if we changed it above. */ 4930 /* Restore the foreground color of the GC if we changed it above. */
4918 if (f->output_data.x->scroll_bar_foreground_pixel != -1) 4931 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
4919 XSetForeground (FRAME_X_DISPLAY (f), gc, 4932 XSetForeground (FRAME_X_DISPLAY (f), gc,
4920 f->output_data.x->foreground_pixel); 4933 FRAME_FOREGROUND_PIXEL (f));
4921 4934
4922 /* Draw the empty space below the handle. Note that we can't 4935 /* Draw the empty space below the handle. Note that we can't
4923 clear zero-height areas; that means "clear to end of window." */ 4936 clear zero-height areas; that means "clear to end of window." */
@@ -5295,7 +5308,7 @@ x_scroll_bar_expose (bar, event)
5295 /* Restore the foreground color of the GC if we changed it above. */ 5308 /* Restore the foreground color of the GC if we changed it above. */
5296 if (f->output_data.x->scroll_bar_foreground_pixel != -1) 5309 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
5297 XSetForeground (FRAME_X_DISPLAY (f), gc, 5310 XSetForeground (FRAME_X_DISPLAY (f), gc,
5298 f->output_data.x->foreground_pixel); 5311 FRAME_FOREGROUND_PIXEL (f));
5299 5312
5300 UNBLOCK_INPUT; 5313 UNBLOCK_INPUT;
5301 5314
@@ -5695,7 +5708,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
5695 int count = 0; 5708 int count = 0;
5696 int do_help = 0; 5709 int do_help = 0;
5697 int nbytes = 0; 5710 int nbytes = 0;
5698 struct frame *f; 5711 struct frame *f = NULL;
5699 struct coding_system coding; 5712 struct coding_system coding;
5700 XEvent event = *eventp; 5713 XEvent event = *eventp;
5701 5714
@@ -6271,19 +6284,19 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
6271 bzero (&compose_status, sizeof (compose_status)); 6284 bzero (&compose_status, sizeof (compose_status));
6272 orig_keysym = keysym; 6285 orig_keysym = keysym;
6273 6286
6274 /* Common for all keysym input events. */ 6287 /* Common for all keysym input events. */
6275 XSETFRAME (inev.ie.frame_or_window, f); 6288 XSETFRAME (inev.ie.frame_or_window, f);
6276 inev.ie.modifiers 6289 inev.ie.modifiers
6277 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers); 6290 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers);
6278 inev.ie.timestamp = event.xkey.time; 6291 inev.ie.timestamp = event.xkey.time;
6279 6292
6280 /* First deal with keysyms which have defined 6293 /* First deal with keysyms which have defined
6281 translations to characters. */ 6294 translations to characters. */
6282 if (keysym >= 32 && keysym < 128) 6295 if (keysym >= 32 && keysym < 128)
6283 /* Avoid explicitly decoding each ASCII character. */ 6296 /* Avoid explicitly decoding each ASCII character. */
6284 { 6297 {
6285 inev.ie.kind = ASCII_KEYSTROKE_EVENT; 6298 inev.ie.kind = ASCII_KEYSTROKE_EVENT;
6286 inev.ie.code = keysym; 6299 inev.ie.code = keysym;
6287 goto done_keysym; 6300 goto done_keysym;
6288 } 6301 }
6289 6302
@@ -6328,18 +6341,18 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
6328 /* Now non-ASCII. */ 6341 /* Now non-ASCII. */
6329 if (HASH_TABLE_P (Vx_keysym_table) 6342 if (HASH_TABLE_P (Vx_keysym_table)
6330 && (NATNUMP (c = Fgethash (make_number (keysym), 6343 && (NATNUMP (c = Fgethash (make_number (keysym),
6331 Vx_keysym_table, 6344 Vx_keysym_table,
6332 Qnil)))) 6345 Qnil))))
6333 { 6346 {
6334 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) 6347 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c))
6335 ? ASCII_KEYSTROKE_EVENT 6348 ? ASCII_KEYSTROKE_EVENT
6336 : MULTIBYTE_CHAR_KEYSTROKE_EVENT); 6349 : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
6337 inev.ie.code = XFASTINT (c); 6350 inev.ie.code = XFASTINT (c);
6338 goto done_keysym; 6351 goto done_keysym;
6339 } 6352 }
6340 6353
6341 /* Random non-modifier sorts of keysyms. */ 6354 /* Random non-modifier sorts of keysyms. */
6342 if (((keysym >= XK_BackSpace && keysym <= XK_Escape) 6355 if (((keysym >= XK_BackSpace && keysym <= XK_Escape)
6343 || keysym == XK_Delete 6356 || keysym == XK_Delete
6344#ifdef XK_ISO_Left_Tab 6357#ifdef XK_ISO_Left_Tab
6345 || (keysym >= XK_ISO_Left_Tab 6358 || (keysym >= XK_ISO_Left_Tab
@@ -6987,8 +7000,8 @@ x_dispatch_event (event, display)
6987 EXPECTED is nonzero if the caller knows input is available. */ 7000 EXPECTED is nonzero if the caller knows input is available. */
6988 7001
6989static int 7002static int
6990XTread_socket (sd, expected, hold_quit) 7003XTread_socket (terminal, expected, hold_quit)
6991 register int sd; 7004 struct terminal *terminal;
6992 int expected; 7005 int expected;
6993 struct input_event *hold_quit; 7006 struct input_event *hold_quit;
6994{ 7007{
@@ -7011,6 +7024,31 @@ XTread_socket (sd, expected, hold_quit)
7011 7024
7012 ++handling_signal; 7025 ++handling_signal;
7013 7026
7027#ifdef HAVE_X_SM
7028 /* Only check session manager input for the primary display. */
7029 if (terminal->id == 1 && x_session_have_connection ())
7030 {
7031 struct input_event inev;
7032 BLOCK_INPUT;
7033 /* We don't need to EVENT_INIT (inev) here, as
7034 x_session_check_input copies an entire input_event. */
7035 if (x_session_check_input (&inev))
7036 {
7037 kbd_buffer_store_event_hold (&inev, hold_quit);
7038 count++;
7039 }
7040 UNBLOCK_INPUT;
7041 }
7042#endif
7043
7044 /* For debugging, this gives a way to fake an I/O error. */
7045 if (terminal->display_info.x == XTread_socket_fake_io_error)
7046 {
7047 XTread_socket_fake_io_error = 0;
7048 x_io_error_quitter (dpyinfo->display);
7049 }
7050
7051#if 0 /* This loop is a noop now. */
7014 /* Find the display we are supposed to read input for. 7052 /* Find the display we are supposed to read input for.
7015 It's the one communicating on descriptor SD. */ 7053 It's the one communicating on descriptor SD. */
7016 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) 7054 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
@@ -7041,52 +7079,31 @@ XTread_socket (sd, expected, hold_quit)
7041#endif /* HAVE_SELECT */ 7079#endif /* HAVE_SELECT */
7042#endif /* SIGIO */ 7080#endif /* SIGIO */
7043#endif 7081#endif
7044 7082 }
7045 /* For debugging, this gives a way to fake an I/O error. */
7046 if (dpyinfo == XTread_socket_fake_io_error)
7047 {
7048 XTread_socket_fake_io_error = 0;
7049 x_io_error_quitter (dpyinfo->display);
7050 }
7051
7052#ifdef HAVE_X_SM
7053 {
7054 struct input_event inev;
7055 BLOCK_INPUT;
7056 /* We don't need to EVENT_INIT (inev) here, as
7057 x_session_check_input copies an entire input_event. */
7058 if (x_session_check_input (&inev))
7059 {
7060 kbd_buffer_store_event_hold (&inev, hold_quit);
7061 count++;
7062 }
7063 UNBLOCK_INPUT;
7064 }
7065#endif 7083#endif
7066 7084
7067#ifndef USE_GTK 7085#ifndef USE_GTK
7068 while (XPending (dpyinfo->display)) 7086 while (XPending (terminal->display_info.x->display))
7069 { 7087 {
7070 int finish; 7088 int finish;
7071 7089
7072 XNextEvent (dpyinfo->display, &event); 7090 XNextEvent (terminal->display_info.x->display, &event);
7073 7091
7074#ifdef HAVE_X_I18N 7092#ifdef HAVE_X_I18N
7075 /* Filter events for the current X input method. */ 7093 /* Filter events for the current X input method. */
7076 if (x_filter_event (dpyinfo, &event)) 7094 if (x_filter_event (terminal->display_info.x, &event))
7077 break; 7095 break;
7078#endif 7096#endif
7079 event_found = 1; 7097 event_found = 1;
7080 7098
7081 count += handle_one_xevent (dpyinfo, &event, &finish, hold_quit); 7099 count += handle_one_xevent (terminal->display_info.x,
7100 &event, &finish, hold_quit);
7082 7101
7083 if (finish == X_EVENT_GOTO_OUT) 7102 if (finish == X_EVENT_GOTO_OUT)
7084 goto out; 7103 goto out;
7085 }
7086#endif /* not USE_GTK */
7087 } 7104 }
7088 7105
7089#ifdef USE_GTK 7106#else /* USE_GTK */
7090 7107
7091 /* For GTK we must use the GTK event loop. But XEvents gets passed 7108 /* For GTK we must use the GTK event loop. But XEvents gets passed
7092 to our filter function above, and then to the big event switch. 7109 to our filter function above, and then to the big event switch.
@@ -7397,8 +7414,7 @@ x_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, activ
7397 } 7414 }
7398 7415
7399#ifndef XFlush 7416#ifndef XFlush
7400 if (updating_frame != f) 7417 XFlush (FRAME_X_DISPLAY (f));
7401 XFlush (FRAME_X_DISPLAY (f));
7402#endif 7418#endif
7403} 7419}
7404 7420
@@ -7636,6 +7652,8 @@ x_clear_errors (dpy)
7636 x_error_message->string[0] = 0; 7652 x_error_message->string[0] = 0;
7637} 7653}
7638 7654
7655#if 0 /* See comment in unwind_to_catch why calling this is a bad
7656 * idea. --lorentey */
7639/* Close off all unclosed x_catch_errors calls. */ 7657/* Close off all unclosed x_catch_errors calls. */
7640 7658
7641void 7659void
@@ -7644,6 +7662,7 @@ x_fully_uncatch_errors ()
7644 while (x_error_message) 7662 while (x_error_message)
7645 x_uncatch_errors (); 7663 x_uncatch_errors ();
7646} 7664}
7665#endif
7647 7666
7648/* Nonzero if x_catch_errors has been done and not yet canceled. */ 7667/* Nonzero if x_catch_errors has been done and not yet canceled. */
7649 7668
@@ -7709,6 +7728,7 @@ x_connection_closed (dpy, error_message)
7709{ 7728{
7710 struct x_display_info *dpyinfo = x_display_info_for_display (dpy); 7729 struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
7711 Lisp_Object frame, tail; 7730 Lisp_Object frame, tail;
7731 int index = SPECPDL_INDEX ();
7712 7732
7713 error_msg = (char *) alloca (strlen (error_message) + 1); 7733 error_msg = (char *) alloca (strlen (error_message) + 1);
7714 strcpy (error_msg, error_message); 7734 strcpy (error_msg, error_message);
@@ -7720,6 +7740,44 @@ x_connection_closed (dpy, error_message)
7720 the original message here. */ 7740 the original message here. */
7721 x_catch_errors (dpy); 7741 x_catch_errors (dpy);
7722 7742
7743 /* Inhibit redisplay while frames are being deleted. */
7744 specbind (Qinhibit_redisplay, Qt);
7745
7746 if (dpyinfo)
7747 {
7748 /* Protect display from being closed when we delete the last
7749 frame on it. */
7750 dpyinfo->reference_count++;
7751 dpyinfo->terminal->reference_count++;
7752 }
7753
7754 /* First delete frames whose mini-buffers are on frames
7755 that are on the dead display. */
7756 FOR_EACH_FRAME (tail, frame)
7757 {
7758 Lisp_Object minibuf_frame;
7759 minibuf_frame
7760 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
7761 if (FRAME_X_P (XFRAME (frame))
7762 && FRAME_X_P (XFRAME (minibuf_frame))
7763 && ! EQ (frame, minibuf_frame)
7764 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo)
7765 Fdelete_frame (frame, Qt);
7766 }
7767
7768 /* Now delete all remaining frames on the dead display.
7769 We are now sure none of these is used as the mini-buffer
7770 for another frame that we need to delete. */
7771 FOR_EACH_FRAME (tail, frame)
7772 if (FRAME_X_P (XFRAME (frame))
7773 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
7774 {
7775 /* Set this to t so that Fdelete_frame won't get confused
7776 trying to find a replacement. */
7777 FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt;
7778 Fdelete_frame (frame, Qt);
7779 }
7780
7723 /* We have to close the display to inform Xt that it doesn't 7781 /* We have to close the display to inform Xt that it doesn't
7724 exist anymore. If we don't, Xt will continue to wait for 7782 exist anymore. If we don't, Xt will continue to wait for
7725 events from the display. As a consequence, a sequence of 7783 events from the display. As a consequence, a sequence of
@@ -7752,43 +7810,23 @@ x_connection_closed (dpy, error_message)
7752 xg_display_close (dpyinfo->display); 7810 xg_display_close (dpyinfo->display);
7753#endif 7811#endif
7754 7812
7755 /* Indicate that this display is dead. */
7756 if (dpyinfo) 7813 if (dpyinfo)
7757 dpyinfo->display = 0;
7758
7759 /* First delete frames whose mini-buffers are on frames
7760 that are on the dead display. */
7761 FOR_EACH_FRAME (tail, frame)
7762 { 7814 {
7763 Lisp_Object minibuf_frame; 7815 /* Indicate that this display is dead. */
7764 minibuf_frame 7816 dpyinfo->display = 0;
7765 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
7766 if (FRAME_X_P (XFRAME (frame))
7767 && FRAME_X_P (XFRAME (minibuf_frame))
7768 && ! EQ (frame, minibuf_frame)
7769 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo)
7770 Fdelete_frame (frame, Qt);
7771 }
7772 7817
7773 /* Now delete all remaining frames on the dead display. 7818 dpyinfo->reference_count--;
7774 We are now sure none of these is used as the mini-buffer 7819 dpyinfo->terminal->reference_count--;
7775 for another frame that we need to delete. */ 7820 if (dpyinfo->reference_count != 0)
7776 FOR_EACH_FRAME (tail, frame) 7821 /* We have just closed all frames on this display. */
7777 if (FRAME_X_P (XFRAME (frame)) 7822 abort ();
7778 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
7779 {
7780 /* Set this to t so that Fdelete_frame won't get confused
7781 trying to find a replacement. */
7782 FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt;
7783 Fdelete_frame (frame, Qt);
7784 }
7785 7823
7786 if (dpyinfo) 7824 x_delete_display (dpyinfo);
7787 x_delete_display (dpyinfo); 7825 }
7788 7826
7789 x_uncatch_errors (); 7827 x_uncatch_errors ();
7790 7828
7791 if (x_display_list == 0) 7829 if (terminal_list == 0)
7792 { 7830 {
7793 fprintf (stderr, "%s\n", error_msg); 7831 fprintf (stderr, "%s\n", error_msg);
7794 shut_down_emacs (0, 0, Qnil); 7832 shut_down_emacs (0, 0, Qnil);
@@ -7802,6 +7840,7 @@ x_connection_closed (dpy, error_message)
7802 sigunblock (sigmask (SIGALRM)); 7840 sigunblock (sigmask (SIGALRM));
7803 TOTALLY_UNBLOCK_INPUT; 7841 TOTALLY_UNBLOCK_INPUT;
7804 7842
7843 unbind_to (index, Qnil);
7805 clear_waiting_for_input (); 7844 clear_waiting_for_input ();
7806 error ("%s", error_msg); 7845 error ("%s", error_msg);
7807} 7846}
@@ -8012,7 +8051,7 @@ xim_destroy_callback (xim, client_data, call_data)
8012 FOR_EACH_FRAME (tail, frame) 8051 FOR_EACH_FRAME (tail, frame)
8013 { 8052 {
8014 struct frame *f = XFRAME (frame); 8053 struct frame *f = XFRAME (frame);
8015 if (FRAME_X_DISPLAY_INFO (f) == dpyinfo) 8054 if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
8016 { 8055 {
8017 FRAME_XIC (f) = NULL; 8056 FRAME_XIC (f) = NULL;
8018 xic_free_xfontset (f); 8057 xic_free_xfontset (f);
@@ -8111,7 +8150,8 @@ xim_instantiate_callback (display, client_data, call_data)
8111 { 8150 {
8112 struct frame *f = XFRAME (frame); 8151 struct frame *f = XFRAME (frame);
8113 8152
8114 if (FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) 8153 if (FRAME_X_P (f)
8154 && FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo)
8115 if (FRAME_XIC (f) == NULL) 8155 if (FRAME_XIC (f) == NULL)
8116 { 8156 {
8117 create_frame_xic (f); 8157 create_frame_xic (f);
@@ -9328,8 +9368,8 @@ x_free_frame_resources (f)
9328 XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 9368 XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
9329#endif /* !USE_X_TOOLKIT */ 9369#endif /* !USE_X_TOOLKIT */
9330 9370
9331 unload_color (f, f->output_data.x->foreground_pixel); 9371 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
9332 unload_color (f, f->output_data.x->background_pixel); 9372 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
9333 unload_color (f, f->output_data.x->cursor_pixel); 9373 unload_color (f, f->output_data.x->cursor_pixel);
9334 unload_color (f, f->output_data.x->cursor_foreground_pixel); 9374 unload_color (f, f->output_data.x->cursor_foreground_pixel);
9335 unload_color (f, f->output_data.x->border_pixel); 9375 unload_color (f, f->output_data.x->border_pixel);
@@ -10495,6 +10535,7 @@ x_term_init (display_name, xrm_option, resource_name)
10495{ 10535{
10496 int connection; 10536 int connection;
10497 Display *dpy; 10537 Display *dpy;
10538 struct terminal *terminal;
10498 struct x_display_info *dpyinfo; 10539 struct x_display_info *dpyinfo;
10499 XrmDatabase xrdb; 10540 XrmDatabase xrdb;
10500 10541
@@ -10514,14 +10555,21 @@ x_term_init (display_name, xrm_option, resource_name)
10514 char **argv2 = argv; 10555 char **argv2 = argv;
10515 GdkAtom atom; 10556 GdkAtom atom;
10516 10557
10558#ifndef HAVE_GTK_MULTIDISPLAY
10559 if (!EQ (Vinitial_window_system, intern ("x")))
10560 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
10561#endif
10562
10517 if (x_initialized++ > 1) 10563 if (x_initialized++ > 1)
10518 { 10564 {
10565#ifdef HAVE_GTK_MULTIDISPLAY
10519 /* Opening another display. If xg_display_open returns less 10566 /* Opening another display. If xg_display_open returns less
10520 than zero, we are probably on GTK 2.0, which can only handle 10567 than zero, we are probably on GTK 2.0, which can only handle
10521 one display. GTK 2.2 or later can handle more than one. */ 10568 one display. GTK 2.2 or later can handle more than one. */
10522 if (xg_display_open (SDATA (display_name), &dpy) < 0) 10569 if (xg_display_open (SDATA (display_name), &dpy) < 0)
10570#endif
10523 error ("Sorry, this version of GTK can only handle one display"); 10571 error ("Sorry, this version of GTK can only handle one display");
10524 } 10572 }
10525 else 10573 else
10526 { 10574 {
10527 for (argc = 0; argc < NUM_ARGV; ++argc) 10575 for (argc = 0; argc < NUM_ARGV; ++argc)
@@ -10625,6 +10673,8 @@ x_term_init (display_name, xrm_option, resource_name)
10625 dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info)); 10673 dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info));
10626 bzero (dpyinfo, sizeof *dpyinfo); 10674 bzero (dpyinfo, sizeof *dpyinfo);
10627 10675
10676 terminal = x_create_terminal (dpyinfo);
10677
10628#ifdef MULTI_KBOARD 10678#ifdef MULTI_KBOARD
10629 { 10679 {
10630 struct x_display_info *share; 10680 struct x_display_info *share;
@@ -10636,30 +10686,30 @@ x_term_init (display_name, xrm_option, resource_name)
10636 SDATA (display_name))) 10686 SDATA (display_name)))
10637 break; 10687 break;
10638 if (share) 10688 if (share)
10639 dpyinfo->kboard = share->kboard; 10689 terminal->kboard = share->terminal->kboard;
10640 else 10690 else
10641 { 10691 {
10642 dpyinfo->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); 10692 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
10643 init_kboard (dpyinfo->kboard); 10693 init_kboard (terminal->kboard);
10644 if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound)) 10694 if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
10645 { 10695 {
10646 char *vendor = ServerVendor (dpy); 10696 char *vendor = ServerVendor (dpy);
10647 UNBLOCK_INPUT; 10697 UNBLOCK_INPUT;
10648 dpyinfo->kboard->Vsystem_key_alist 10698 terminal->kboard->Vsystem_key_alist
10649 = call1 (Qvendor_specific_keysyms, 10699 = call1 (Qvendor_specific_keysyms,
10650 build_string (vendor ? vendor : "")); 10700 build_string (vendor ? vendor : ""));
10651 BLOCK_INPUT; 10701 BLOCK_INPUT;
10652 } 10702 }
10653 10703
10654 dpyinfo->kboard->next_kboard = all_kboards; 10704 terminal->kboard->next_kboard = all_kboards;
10655 all_kboards = dpyinfo->kboard; 10705 all_kboards = terminal->kboard;
10656 /* Don't let the initial kboard remain current longer than necessary. 10706 /* Don't let the initial kboard remain current longer than necessary.
10657 That would cause problems if a file loaded on startup tries to 10707 That would cause problems if a file loaded on startup tries to
10658 prompt in the mini-buffer. */ 10708 prompt in the mini-buffer. */
10659 if (current_kboard == initial_kboard) 10709 if (current_kboard == initial_kboard)
10660 current_kboard = dpyinfo->kboard; 10710 current_kboard = terminal->kboard;
10661 } 10711 }
10662 dpyinfo->kboard->reference_count++; 10712 terminal->kboard->reference_count++;
10663 } 10713 }
10664#endif 10714#endif
10665 10715
@@ -10674,6 +10724,11 @@ x_term_init (display_name, xrm_option, resource_name)
10674 10724
10675 dpyinfo->display = dpy; 10725 dpyinfo->display = dpy;
10676 10726
10727 /* Set the name of the terminal. */
10728 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
10729 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
10730 terminal->name[SBYTES (display_name)] = 0;
10731
10677#if 0 10732#if 0
10678 XSetAfterFunction (x_current_display, x_trace_wire); 10733 XSetAfterFunction (x_current_display, x_trace_wire);
10679#endif /* ! 0 */ 10734#endif /* ! 0 */
@@ -10969,8 +11024,10 @@ x_term_init (display_name, xrm_option, resource_name)
10969 } 11024 }
10970 11025
10971#ifdef HAVE_X_SM 11026#ifdef HAVE_X_SM
10972 /* Only do this for the first display. */ 11027 /* Only do this for the very first display in the Emacs session.
10973 if (!x_session_initialized++) 11028 Ignore X session management when Emacs was first started on a
11029 tty. */
11030 if (terminal->id == 1)
10974 x_session_initialize (dpyinfo); 11031 x_session_initialize (dpyinfo);
10975#endif 11032#endif
10976 11033
@@ -10979,7 +11036,7 @@ x_term_init (display_name, xrm_option, resource_name)
10979 return dpyinfo; 11036 return dpyinfo;
10980} 11037}
10981 11038
10982/* Get rid of display DPYINFO, assuming all frames are already gone, 11039/* Get rid of display DPYINFO, deleting all frames on it,
10983 and without sending any more commands to the X server. */ 11040 and without sending any more commands to the X server. */
10984 11041
10985void 11042void
@@ -10987,6 +11044,20 @@ x_delete_display (dpyinfo)
10987 struct x_display_info *dpyinfo; 11044 struct x_display_info *dpyinfo;
10988{ 11045{
10989 int i; 11046 int i;
11047 struct terminal *t;
11048
11049 /* Close all frames and delete the generic struct terminal for this
11050 X display. */
11051 for (t = terminal_list; t; t = t->next_terminal)
11052 if (t->type == output_x_window && t->display_info.x == dpyinfo)
11053 {
11054 /* Close X session management when we close its display. */
11055 if (t->id == 1 && x_session_have_connection ())
11056 x_session_close();
11057
11058 delete_terminal (t);
11059 break;
11060 }
10990 11061
10991 delete_keyboard_wait_descriptor (dpyinfo->connection); 11062 delete_keyboard_wait_descriptor (dpyinfo->connection);
10992 11063
@@ -11030,10 +11101,6 @@ x_delete_display (dpyinfo)
11030 XrmDestroyDatabase (dpyinfo->xrdb); 11101 XrmDestroyDatabase (dpyinfo->xrdb);
11031#endif 11102#endif
11032#endif 11103#endif
11033#ifdef MULTI_KBOARD
11034 if (--dpyinfo->kboard->reference_count == 0)
11035 delete_kboard (dpyinfo->kboard);
11036#endif
11037#ifdef HAVE_X_I18N 11104#ifdef HAVE_X_I18N
11038 if (dpyinfo->xim) 11105 if (dpyinfo->xim)
11039 xim_close_dpy (dpyinfo); 11106 xim_close_dpy (dpyinfo);
@@ -11115,71 +11182,129 @@ x_activate_timeout_atimer ()
11115extern frame_parm_handler x_frame_parm_handlers[]; 11182extern frame_parm_handler x_frame_parm_handlers[];
11116 11183
11117static struct redisplay_interface x_redisplay_interface = 11184static struct redisplay_interface x_redisplay_interface =
11118{ 11185 {
11119 x_frame_parm_handlers, 11186 x_frame_parm_handlers,
11120 x_produce_glyphs, 11187 x_produce_glyphs,
11121 x_write_glyphs, 11188 x_write_glyphs,
11122 x_insert_glyphs, 11189 x_insert_glyphs,
11123 x_clear_end_of_line, 11190 x_clear_end_of_line,
11124 x_scroll_run, 11191 x_scroll_run,
11125 x_after_update_window_line, 11192 x_after_update_window_line,
11126 x_update_window_begin, 11193 x_update_window_begin,
11127 x_update_window_end, 11194 x_update_window_end,
11128 x_cursor_to, 11195 x_cursor_to,
11129 x_flush, 11196 x_flush,
11130#ifdef XFlush 11197#ifdef XFlush
11131 x_flush, 11198 x_flush,
11132#else 11199#else
11133 0, /* flush_display_optional */ 11200 0, /* flush_display_optional */
11134#endif 11201#endif
11135 x_clear_window_mouse_face, 11202 x_clear_window_mouse_face,
11136 x_get_glyph_overhangs, 11203 x_get_glyph_overhangs,
11137 x_fix_overlapping_area, 11204 x_fix_overlapping_area,
11138 x_draw_fringe_bitmap, 11205 x_draw_fringe_bitmap,
11139 0, /* define_fringe_bitmap */ 11206 0, /* define_fringe_bitmap */
11140 0, /* destroy_fringe_bitmap */ 11207 0, /* destroy_fringe_bitmap */
11141 x_per_char_metric, 11208 x_per_char_metric,
11142 x_encode_char, 11209 x_encode_char,
11143 x_compute_glyph_string_overhangs, 11210 x_compute_glyph_string_overhangs,
11144 x_draw_glyph_string, 11211 x_draw_glyph_string,
11145 x_define_frame_cursor, 11212 x_define_frame_cursor,
11146 x_clear_frame_area, 11213 x_clear_frame_area,
11147 x_draw_window_cursor, 11214 x_draw_window_cursor,
11148 x_draw_vertical_window_border, 11215 x_draw_vertical_window_border,
11149 x_shift_glyphs_for_insert 11216 x_shift_glyphs_for_insert
11150}; 11217 };
11218
11219
11220/* This function is called when the last frame on a display is deleted. */
11221void
11222x_delete_terminal (struct terminal *terminal)
11223{
11224 struct x_display_info *dpyinfo = terminal->display_info.x;
11225 int i;
11226
11227 /* Protect against recursive calls. Fdelete_frame in
11228 delete_terminal calls us back when it deletes our last frame. */
11229 if (terminal->deleted)
11230 return;
11231
11232 BLOCK_INPUT;
11233 /* Free the fonts in the font table. */
11234 for (i = 0; i < dpyinfo->n_fonts; i++)
11235 if (dpyinfo->font_table[i].name)
11236 {
11237 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
11238 }
11239
11240 x_destroy_all_bitmaps (dpyinfo);
11241 XSetCloseDownMode (dpyinfo->display, DestroyAll);
11242
11243#ifdef USE_GTK
11244 xg_display_close (dpyinfo->display);
11245#else
11246#ifdef USE_X_TOOLKIT
11247 XtCloseDisplay (dpyinfo->display);
11248#else
11249 XCloseDisplay (dpyinfo->display);
11250#endif
11251#endif /* ! USE_GTK */
11252
11253 x_delete_display (dpyinfo);
11254 UNBLOCK_INPUT;
11255}
11256
11257
11258static struct terminal *
11259x_create_terminal (struct x_display_info *dpyinfo)
11260{
11261 struct terminal *terminal;
11262
11263 terminal = create_terminal ();
11264
11265 terminal->type = output_x_window;
11266 terminal->display_info.x = dpyinfo;
11267 dpyinfo->terminal = terminal;
11268
11269 /* kboard is initialized in x_term_init. */
11270
11271 terminal->clear_frame_hook = x_clear_frame;
11272 terminal->ins_del_lines_hook = x_ins_del_lines;
11273 terminal->delete_glyphs_hook = x_delete_glyphs;
11274 terminal->ring_bell_hook = XTring_bell;
11275 terminal->reset_terminal_modes_hook = XTreset_terminal_modes;
11276 terminal->set_terminal_modes_hook = XTset_terminal_modes;
11277 terminal->update_begin_hook = x_update_begin;
11278 terminal->update_end_hook = x_update_end;
11279 terminal->set_terminal_window_hook = XTset_terminal_window;
11280 terminal->read_socket_hook = XTread_socket;
11281 terminal->frame_up_to_date_hook = XTframe_up_to_date;
11282 terminal->mouse_position_hook = XTmouse_position;
11283 terminal->frame_rehighlight_hook = XTframe_rehighlight;
11284 terminal->frame_raise_lower_hook = XTframe_raise_lower;
11285 terminal->fullscreen_hook = XTfullscreen_hook;
11286 terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
11287 terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
11288 terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
11289 terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
11290
11291 terminal->delete_frame_hook = x_destroy_window;
11292 terminal->delete_terminal_hook = x_delete_terminal;
11293
11294 terminal->rif = &x_redisplay_interface;
11295 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
11296 terminal->char_ins_del_ok = 1;
11297 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
11298 terminal->fast_clear_end_of_line = 1; /* X does this well. */
11299 terminal->memory_below_frame = 0; /* We don't remember what scrolls
11300 off the bottom. */
11301
11302 return terminal;
11303}
11151 11304
11152void 11305void
11153x_initialize () 11306x_initialize ()
11154{ 11307{
11155 rif = &x_redisplay_interface;
11156
11157 clear_frame_hook = x_clear_frame;
11158 ins_del_lines_hook = x_ins_del_lines;
11159 delete_glyphs_hook = x_delete_glyphs;
11160 ring_bell_hook = XTring_bell;
11161 reset_terminal_modes_hook = XTreset_terminal_modes;
11162 set_terminal_modes_hook = XTset_terminal_modes;
11163 update_begin_hook = x_update_begin;
11164 update_end_hook = x_update_end;
11165 set_terminal_window_hook = XTset_terminal_window;
11166 read_socket_hook = XTread_socket;
11167 frame_up_to_date_hook = XTframe_up_to_date;
11168 mouse_position_hook = XTmouse_position;
11169 frame_rehighlight_hook = XTframe_rehighlight;
11170 frame_raise_lower_hook = XTframe_raise_lower;
11171 set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
11172 condemn_scroll_bars_hook = XTcondemn_scroll_bars;
11173 redeem_scroll_bar_hook = XTredeem_scroll_bar;
11174 judge_scroll_bars_hook = XTjudge_scroll_bars;
11175 fullscreen_hook = XTfullscreen_hook;
11176
11177 scroll_region_ok = 1; /* we'll scroll partial frames */
11178 char_ins_del_ok = 1;
11179 line_ins_del_ok = 1; /* we'll just blt 'em */
11180 fast_clear_end_of_line = 1; /* X does this well */
11181 memory_below_frame = 0; /* we don't remember what scrolls
11182 off the bottom */
11183 baud_rate = 19200; 11308 baud_rate = 19200;
11184 11309
11185 x_noop_count = 0; 11310 x_noop_count = 0;
@@ -11195,7 +11320,7 @@ x_initialize ()
11195#endif 11320#endif
11196 11321
11197 /* Try to use interrupt input; if we can't, then start polling. */ 11322 /* Try to use interrupt input; if we can't, then start polling. */
11198 Fset_input_mode (Qt, Qnil, Qt, Qnil); 11323 Fset_input_interrupt_mode (Qt);
11199 11324
11200#ifdef USE_X_TOOLKIT 11325#ifdef USE_X_TOOLKIT
11201 XtToolkitInitialize (); 11326 XtToolkitInitialize ();
@@ -11226,9 +11351,11 @@ x_initialize ()
11226 XSetIOErrorHandler (x_io_error_quitter); 11351 XSetIOErrorHandler (x_io_error_quitter);
11227 11352
11228 /* Disable Window Change signals; they are handled by X events. */ 11353 /* Disable Window Change signals; they are handled by X events. */
11354#if 0 /* Don't. We may want to open tty frames later. */
11229#ifdef SIGWINCH 11355#ifdef SIGWINCH
11230 signal (SIGWINCH, SIG_DFL); 11356 signal (SIGWINCH, SIG_DFL);
11231#endif /* SIGWINCH */ 11357#endif /* SIGWINCH */
11358#endif
11232 11359
11233 signal (SIGPIPE, x_connection_signal); 11360 signal (SIGPIPE, x_connection_signal);
11234} 11361}
diff --git a/src/xterm.h b/src/xterm.h
index 13b0b4983ad..34583221ad3 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -149,6 +149,9 @@ struct x_display_info
149 /* Chain of all x_display_info structures. */ 149 /* Chain of all x_display_info structures. */
150 struct x_display_info *next; 150 struct x_display_info *next;
151 151
152 /* The generic display parameters corresponding to this X display. */
153 struct terminal *terminal;
154
152 /* Connection number (normally a file descriptor number). */ 155 /* Connection number (normally a file descriptor number). */
153 int connection; 156 int connection;
154 157
@@ -327,9 +330,6 @@ struct x_display_info
327 /* Atom used in toolkit scroll bar client messages. */ 330 /* Atom used in toolkit scroll bar client messages. */
328 Atom Xatom_Scrollbar; 331 Atom Xatom_Scrollbar;
329 332
330#ifdef MULTI_KBOARD
331 struct kboard *kboard;
332#endif
333 int cut_buffers_initialized; /* Whether we're sure they all exist */ 333 int cut_buffers_initialized; /* Whether we're sure they all exist */
334 334
335 /* The frame (if any) which has the X window that has keyboard focus. 335 /* The frame (if any) which has the X window that has keyboard focus.
@@ -532,8 +532,10 @@ struct x_output
532 532
533 /* Pixel values used for various purposes. 533 /* Pixel values used for various purposes.
534 border_pixel may be -1 meaning use a gray tile. */ 534 border_pixel may be -1 meaning use a gray tile. */
535#if 0 /* These are also defined in struct frame. Use that instead. */
535 unsigned long background_pixel; 536 unsigned long background_pixel;
536 unsigned long foreground_pixel; 537 unsigned long foreground_pixel;
538#endif
537 unsigned long cursor_pixel; 539 unsigned long cursor_pixel;
538 unsigned long border_pixel; 540 unsigned long border_pixel;
539 unsigned long mouse_pixel; 541 unsigned long mouse_pixel;
@@ -984,7 +986,6 @@ extern int x_had_errors_p P_ ((Display *));
984extern int x_catching_errors P_ ((void)); 986extern int x_catching_errors P_ ((void));
985extern void x_uncatch_errors P_ ((void)); 987extern void x_uncatch_errors P_ ((void));
986extern void x_clear_errors P_ ((Display *)); 988extern void x_clear_errors P_ ((Display *));
987extern void x_fully_uncatch_errors P_ ((void));
988extern void x_set_window_size P_ ((struct frame *, int, int, int)); 989extern void x_set_window_size P_ ((struct frame *, int, int, int));
989extern void x_set_mouse_position P_ ((struct frame *, int, int)); 990extern void x_set_mouse_position P_ ((struct frame *, int, int));
990extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int)); 991extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int));
@@ -999,6 +1000,7 @@ extern void x_wm_set_size_hint P_ ((struct frame *, long, int));
999extern void x_wm_set_window_state P_ ((struct frame *, int)); 1000extern void x_wm_set_window_state P_ ((struct frame *, int));
1000extern void x_wm_set_icon_pixmap P_ ((struct frame *, int)); 1001extern void x_wm_set_icon_pixmap P_ ((struct frame *, int));
1001extern void x_delete_display P_ ((struct x_display_info *)); 1002extern void x_delete_display P_ ((struct x_display_info *));
1003extern void x_delete_terminal P_ ((struct terminal *terminal));
1002extern void x_initialize P_ ((void)); 1004extern void x_initialize P_ ((void));
1003extern unsigned long x_copy_color P_ ((struct frame *, unsigned long)); 1005extern unsigned long x_copy_color P_ ((struct frame *, unsigned long));
1004#ifdef USE_X_TOOLKIT 1006#ifdef USE_X_TOOLKIT
@@ -1099,6 +1101,7 @@ extern void widget_store_internal_border P_ ((Widget));
1099extern void x_session_initialize P_ ((struct x_display_info *dpyinfo)); 1101extern void x_session_initialize P_ ((struct x_display_info *dpyinfo));
1100extern int x_session_check_input P_ ((struct input_event *bufp)); 1102extern int x_session_check_input P_ ((struct input_event *bufp));
1101extern int x_session_have_connection P_ ((void)); 1103extern int x_session_have_connection P_ ((void));
1104extern void x_session_close P_ ((void));
1102#endif 1105#endif
1103 1106
1104#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0 1107#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0