aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiles Bader2007-08-29 05:28:10 +0000
committerMiles Bader2007-08-29 05:28:10 +0000
commit8d9cc0b7ea1893059df8788129998e9a71ec07f3 (patch)
tree4caa326ed8de37c8c0a859c7071593362832d37e /src
parentcb5b9015b372175f1fc90cb7ba3f43298c621509 (diff)
parent5142de65ce179e846514ec7355274ab22822a85c (diff)
downloademacs-8d9cc0b7ea1893059df8788129998e9a71ec07f3.tar.gz
emacs-8d9cc0b7ea1893059df8788129998e9a71ec07f3.zip
Merge multi-tty branch
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-866
Diffstat (limited to 'src')
-rw-r--r--src/.arch-inventory3
-rw-r--r--src/.gdbinit2
-rw-r--r--src/ChangeLog606
-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.c316
-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.in8
-rw-r--r--src/data.c67
-rw-r--r--src/dispextern.h92
-rw-r--r--src/dispnew.c389
-rw-r--r--src/emacs.c43
-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.c562
-rw-r--r--src/frame.h112
-rw-r--r--src/fringe.c10
-rw-r--r--src/gtkutil.c4
-rw-r--r--src/image.c3
-rw-r--r--src/indent.c2
-rw-r--r--src/keyboard.c1085
-rw-r--r--src/keyboard.h39
-rw-r--r--src/keymap.c56
-rw-r--r--src/keymap.h1
-rw-r--r--src/lisp.h27
-rw-r--r--src/lread.c12
-rw-r--r--src/macfns.c145
-rw-r--r--src/macmenu.c6
-rw-r--r--src/macterm.c121
-rw-r--r--src/macterm.h6
-rw-r--r--src/makefile.w32-in31
-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.c22
-rw-r--r--src/puresize.h2
-rw-r--r--src/s/darwin.h2
-rw-r--r--src/s/ms-w32.h2
-rw-r--r--src/scroll.c52
-rw-r--r--src/sysdep.c710
-rw-r--r--src/syssignal.h1
-rw-r--r--src/term.c2532
-rw-r--r--src/termchar.h203
-rw-r--r--src/termhooks.h499
-rw-r--r--src/terminal.c629
-rw-r--r--src/termopts.h5
-rw-r--r--src/w32.c12
-rw-r--r--src/w32console.c171
-rw-r--r--src/w32fns.c31
-rw-r--r--src/w32inevt.c4
-rw-r--r--src/w32inevt.h2
-rw-r--r--src/w32menu.c9
-rw-r--r--src/w32term.c241
-rw-r--r--src/w32term.h14
-rw-r--r--src/widget.c4
-rw-r--r--src/window.c4
-rw-r--r--src/window.h2
-rw-r--r--src/xdisp.c338
-rw-r--r--src/xfaces.c45
-rw-r--r--src/xfns.c384
-rw-r--r--src/xmenu.c60
-rw-r--r--src/xselect.c58
-rw-r--r--src/xsmfns.c9
-rw-r--r--src/xterm.c537
-rw-r--r--src/xterm.h11
73 files changed, 7309 insertions, 3619 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 851322059a8..be91a100f49 100644
--- a/src/.gdbinit
+++ b/src/.gdbinit
@@ -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/ChangeLog b/src/ChangeLog
index 231f18dd312..029f84945d5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,609 @@
12007-08-29 Dan Nicolaescu <dann@ics.uci.edu>
2
3 * callproc.c (child_setup, getenv_internal): Use the
4 display-environment-variable and term-environment-variable frame
5 params.
6 (set_initial_environment): Initialise Vprocess_environment.
7
8 * config.in: Disable multi-keyboard support on a mac.
9
10 * frame.c (Qterm_environment_variable)
11 (Qdisplay_environment_variable): New variables.
12 (syms_of_frame): Intern and staticpro them.
13 (Fmake_terminal_frame): Disable output method test.
14
15 * frame.h: Declare them here.
16
17 * macfns.c (x_set_mouse_color): Get rif from the frame.
18 (x_set_tool_bar_lines): Don't use updating_frame.
19 (mac_window): Add 2 new parameters for consistency with other systems.
20 (Fx_create_frame): Fix doc string. Rename the parameter. Set the
21 frame parameters following what is done in X11 and w32. Don't use
22 FRAME_MAC_DISPLAY_INFO.
23 (Fx_open_connection, start_hourglass): Remove window-system check.
24 (x_create_tip_frame): Get the keyboard from the terminal.
25
26 * macmenu.c: Reorder includes.
27 (Fx_popup_menu): Use terminal specific mouse_position_hook.
28
29 * macterm.c (XTset_terminal_modes, XTreset_terminal_modes): Add a
30 terminal parameter.
31 (x_clear_frame): Add a frame parameter.
32 (note_mouse_movement): Get rif from the frame.
33 (mac_term_init): Initialize the terminal.
34 (mac_initialize): Make static and move terminal initialization ...
35 (mac_create_terminal): ... to this new function.
36
37 * macterm.h (struct mac_display_info): Add terminal.
38
39 * puresize.h (BASE_PURESIZE): Increase base value to 1158000.
40
41 * sysdep.c: Comment out text after #endif.
42
43 * term.c (init_tty): Only use terminal->kboard when MULTI_KBOARD
44 is defined. Better initialize ttys in windows. Use terminal
45 specific mouse_position_hook.
46
47 * termhooks.h (union display_info): Add mac_display_info.
48
49 * w32fns.c (Fx_create_frame): Use kboard from the terminal. Set
50 the default minibuffer frame, window_system and the rest of the
51 frame parameters following what is done in X11.
52
53 * w32term.c (w32_initialize): Make static.
54
55 * xselect.c (x_handle_selection_clear): Only access
56 terminal->kboard when MULTI_KBOARD is defined.
57
58 * s/darwin.h (SYSTEM_PURESIZE_EXTRA): Define here.
59 (SYSTEM_PURESIZE_EXTRA): Only define on Carbon.
60
612007-08-29 Jason Rumney <jasonr@gnu.org>
62
63 * frame.c (Fdelete_frame): Only get kboard when MULTI_KBOARD defined.
64 (make_terminal_frame) [WINDOWSNT]: Initialize terminal.
65
66 * fringe.c (w32_init_fringe w32_reset_fringes) [HAVE_NTGUI]:
67 (mac_init_fringe) [MAC_OS]: Get rif from selected_frame.
68
69 * keyboard.c (restore_kboard_configuration): Only define when
70 MULTI_KBOARD defined.
71
72 * makefile.w32-in: Update dependancies from Makefile.in
73 (OBJ1): Add terminal.$(O)
74
75 * term.c (dissociate_if_controlling_tty) [WINDOWSNT]: Don't
76 define function body.
77 (init_tty) [WINDOWSNT]: Use selected_frame for initializing.
78
79 * termhooks.h (display_info) [WINDOWSNT]: Add w32.
80
81 * w32.c (request_sigio, unrequest_sigio): Remove.
82
83 * w32console.c (w32con_move_cursor, w32con_clear_to_end)
84 (w32con_clear_frame, w32con_clear_end_of_line)
85 (w32con_ins_del_lines, w32con_insert_glyphs, w32con_write_glyphs)
86 (w32con_delete_glyphs, w32con_set_terminal_window)
87 (scroll_line, w32_sys_ring_bell): Add frame arg.
88 (w32con_set_terminal_modes, w32con_reset_terminal_modes): Add
89 terminal arg.
90 (PICK_FRAME): Remove.
91 (w32con_write_glyphs): Use frame specific terminal coding.
92 (one_and_only_w32cons): New global variable.
93 (initialize_w32_display): Use it for storing hooks.
94 (create_w32cons_output): New function.
95
96 * w32inevt.c, w32inevt.h (w32_console_read_socket): Make first
97 arg a frame.
98
99 * w32fns.c (x_create_tip_frame): Set terminal and ref count. Set
100 window_system.
101 (x_set_tool_bar_lines): Don't use updating_frame.
102 (Fx_create_frame): Set terminal and ref count.
103 (Fx_open_connection): Remove window-system check.
104
105 * w32menu.c (Fx_popup_menu): Use terminal specific mouse_position_hook.
106
107 * w32term.c (w32_term_init): Call add_keyboard_wait_descriptor.
108 (w32_set_terminal_modes, w32_reset_terminal_modes): Add terminal arg.
109 (x_clear_frame, x_delete_glyphs, w32_ring_bell, x_ins_del_lines):
110 Add frame arg.
111 (x_delete_terminal, w32_create_terminal): New functions.
112 (w32_term_init): Create a terminal.
113 (w32_initialize): Move terminal specific initialization to
114 w32_create_terminal.
115
116 * w32term.h (x_output): Remove foreground_pixel and
117 background_pixel.
118 (w32_clear_rect, w32_clear_area): Use background from frame.
119 (w32_display_info): Add terminal.
120 (w32_sys_ring_bell, x_delete_display): Declare here.
121
122 * xdisp.c (display_menu_bar) [HAVE_NTGUI]: Check frame type.
123
124 * s/ms-w32.h (SYSTEM_PURESIZE_EXTRA): Bump to 50k.
125
1262007-08-29 Kalle Olavi Niemitalo <kon@iki.fi> (tiny change)
127
128 * keyboard.c (interrupt_signal, handle_interrupt, Fset_quit_char):
129 Fix get_named_tty calls for the controlling tty.
130
1312007-08-29 ARISAWA Akihiro <ari@mbf.ocn.ne.jp> (tiny change)
132
133 * term.c (dissociate_if_controlling_tty)[USG]: Fix parse error.
134
1352007-08-29 Yoshiaki Kasahara <kasahara@nc.kyushu-u.ac.jp> (tiny change)
136
137 * term.c (tty_insert_glyphs): Add missing first parameter.
138
1392007-08-29 Karoly Lorentey <karoly@lorentey.hu>
140
141 * buffer.c (Fbuffer_list, Fbury_buffer): Take
142 frame->buried_buffer_list into account.
143
144 * cm.c (current_tty): New variable, for cmputc().
145 (cmputc): Use it.
146 (cmcheckmagic): Add tty parameter, look up terminal streams there.
147 (calccost): Add tty parameter. Use emacs_tputs() instead of tputs().
148 (cmgoto): Add tty parameter. Pass it on to calccost(). Use
149 emacs_tputs() instead of tputs().
150
151 * cm.h (emacs_tputs): New macro to set current_tty, and then call
152 tputs().
153 (current_tty): New variable, for cmputc().
154 (cmcheckmagic, cmputc, cmgoto): Add prototypes.
155
156 * eval.c (unwind_to_catch): Don't call x_fully_uncatch_errors.
157 (internal_condition_case, internal_condition_case_1)
158 (internal_condition_case_2): Don't abort when x_catching_errors.
159
160 * fns.c (Fyes_or_no_p): Don't try to open an X dialog on tty terminals.
161 (Fy_or_n_p): Likewise. Use temporarily_switch_to_single_kboard to
162 prevent crashes caused by bogus longjmps in read_char.
163
164 * keymap.h (Fset_keymap_parent): Add EXFUN.
165
166 * macterm.h (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL)
167 * w32term.h (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL):
168 Remove redundant definition.
169
170 * macfns.c (x_set_mouse_color,x_make_gc): Use
171 FRAME_BACKGROUND_PIXEL and FRAME_FOREGROUND_PIXEL.
172
173 * w32term.c (x_free_frame_resources): Use
174 FRAME_BACKGROUND_PIXEL and FRAME_FOREGROUND_PIXEL.
175 (w32_initialize): Use the accessor macros for terminal characteristics.
176
177 * macterm.c (mac_initialize): Use Fset_input_interrupt_mode.
178 Use the accessor macros for terminal characteristics.
179 * msdos.c (internal_terminal_init): Use the accessor macros for
180 terminal characteristics.
181 (ScreenVisualBell,internal_terminal_init): Use
182 FRAME_BACKGROUND_PIXEL and FRAME_FOREGROUND_PIXEL.
183
184 * termopts.h (no_redraw_on_reenter): Declare.
185
186 * alloc.c (emacs_blocked_malloc): Disable mallopt call.
187 (mark_terminals,mark_ttys): Declare.
188 (Fgarbage_collect): Call them.
189 (mark_object): Mark buried_buffer_list;
190
191 * prefix-args.c: Include stdlib.h for exit.
192
193 * syssignal.h: Add comment.
194
195 * indent.c: Include stdio.h.
196
197 * window.h (Vinitial_window_system): Declare.
198 (Vwindow_system): Delete declaration.
199
200 * fontset.c (Finternal_char_font): Use FRAME_RIF.
201
202 * image.c (lookup_image): Don't initialize `c' until the xasserts
203 have been run.
204
205 * gtkutil.c (xg_create_frame_widgets): Use FRAME_BACKGROUND_PIXEL and
206 FRAME_FOREGROUND_PIXEL.
207
208 * print.c (print_preprocess): Don't lose print_depth levels while
209 iterating.
210
211 * widget.c (update_from_various_frame_slots): Use
212 FRAME_BACKGROUND_PIXEL and FRAME_FOREGROUND_PIXEL.
213
214 * window.c (set_window_buffer): Don't call clear_mouse_face on tty
215 frames.
216 (window_internal_height): Remove bogus make_number call.
217 (init_window_once): Call make_terminal_frame with two zero
218 parameters.
219
220 * fileio.c (Fread_file_name): Update comment.
221
222 * callint.c (Fcall_interactively): Use
223 temporarily_switch_to_single_kboard instead of single_kboard_state.
224 Make sure it is correctly unwound.
225
226 * xsmfns.c (x_session_close): New function.
227
228 * coding.h (terminal_coding,safe_terminal_coding,keyboard_coding):
229 Delete declarations.
230
231 * xterm.h: Remove declaration for x_fully_uncatch_errors.
232 (x_output): Remove background_pixel and foreground_pixel fields.
233 (x_display_info): Add new field TERMINAL. Remove KBOARD field.
234 (x_delete_device):
235 (x_session_close): Declare.
236
237 * lread.c: Include setjmp.h. Update declaration of `read_char'.
238 (read_filtered_event): Call `read_char' with a local
239 `wrong_kboard_jmpbuf'.
240
241 * minibuf.c (read_minibuf): Call
242 temporarily_switch_to_single_kboard. Don't call
243 single_kboard_state. Use FRAME_RIF.
244
245 * process.c (Fmake_network_process): Don't unrequest_sigio on modern
246 systems.
247
248 * lisp.h (set_process_environment): Rename to
249 `set_global_environment'.
250 (Fframe_with_environment,Fset_input_meta_mode)
251 (Fset_quit_char): EXFUN.
252 (x_create_device,tty_output,terminal,tty_display_info): Declare.
253 (init_sys_modes, reset_sys_modes): Update prototypes.
254 (init_all_sys_modes, reset_all_sys_modes): New prototypes.
255
256 * keyboard.h (struct kboard): Add new fields:
257 Vlocal_function_key_map, Vlocal_key_translation_map,
258 Vkeyboard_translate_table.
259 (Vfunction_key_map,Vkeyboard_translate_table,single_kboard_state):
260 Delete declarations.
261 (Vfunction_key_map,Vkey_translation_map,push_kboard,pop_kboard)
262 (temporarily_switch_to_single_kboard,tty_read_avail_input):
263 New declarations.
264
265 * emacs.c (main): Don't call init_sys_modes(), the new term_init()
266 already does that during init_display(). Call syms_of_keymap
267 before syms_of_keyboard. Call `syms_of_terminal'. Call
268 set_initial_environment, not set_process_environment.
269 (shut_down_emacs): Call reset_all_sys_modes() instead of
270 reset_sys_modes().
271
272 * xfaces.c (x_free_gc): Protect xassert with GLYPH_DEBUG.
273 (internal_resolve_face_name, resolve_face_name_error): New
274 functions.
275 (resolve_face_name): Protect against loops and errors thrown by
276 Fget.
277 (realize_default_face): Don't use FRAME_FONT unless frame is an X
278 frame.
279 (Ftty_supports_face_attributes_p): Update tty_capable_p call.
280
281 * scroll.c: Replace CURTTY() with local variables throughout the
282 file (where applicable).
283 (calculate_scrolling, calculate_direct_scrolling)
284 (scrolling_1, scroll_cost): Use the accessor macros for terminal
285 characteristics.
286
287 * keymap.c (Vfunction_key_map): Remove.
288 (Fdescribe_buffer_bindings): Update references to
289 Vfunction_key_map.
290 (syms_of_keymap): Remove DEFVAR for Vfunction_key_map.
291 (Vkey_translation_map): Remove.
292 (syms_of_keymap): Remove DEFVAR for key-translation-map.
293 (Fdescribe_buffer_bindings):
294 (read_key_sequence, init_kboard, syms_of_keyboard, mark_kboards):
295 Update for terminal-local key-translation-map.
296
297 * Makefile.in (callproc.o): Update dependencies.
298 (lisp, shortlisp): Add termdev.elc.
299 (obj): Add terminal.o.
300 (terminal.o): Add dependencies.
301 [HAVE_CARBON]: Make terminal.o depend on macgui.h.
302 (data.o, fns.o): Add termhooks.h dependency.
303 (SOME_MACHINE_LISP): Add dnd.elc.
304 (minibuf.o): Fix typo.
305 Update dependencies.
306
307 * data.c (do_symval_forwarding, store_symval_forwarding)
308 (find_symbol_value): Use the selected frame's keyboard, not
309 current_kboard.
310
311 * .gdbinit (init_sys_modes): Use Vinitial_window_system instead of
312 Vwindow_system.
313
314 * xmenu.c (Fx_menu_bar_open) [USE_X_TOOLKIT, USE_GTK]: Rename from
315 Fmenu_bar_open.
316 (syms_of_xmenu): Update defsubr.
317 (mouse_position_for_popup, Fx_popup_menu)
318 (Fx_popup_dialog, x_activate_menubar, update_frame_menubar)
319 (set_frame_menubar, free_frame_menubar)
320 (create_and_show_popup_menu, xmenu_show, )
321 (create_and_show_dialog, xdialog_show, xmenu_show): Abort if not
322 an X frame.
323
324 * xselect.c (x_own_selection): Abort if not an X frame.
325 (some_frame_on_display): Check if it is an X frame.
326 (x_handle_selection_clear): Deal with MULTI_KBOARD.
327
328 * coding.c: Include frame.h and termhooks.h.
329 (terminal_coding,keyboard_coding): Delete.
330 (Fset_terminal_coding_system_internal):
331 (Fset_keyboard_coding_system_internal):
332 (Fkeyboard_coding_system):
333 (Fterminal_coding_system): Add a terminal parameter. Get
334 terminal_coding from the terminal.
335 (init_coding_once): Don't call setup_coding_system here.
336
337 * dispextern.h (set_scroll_region, turn_off_insert)
338 (turn_off_highlight, background_highlight, clear_end_of_line_raw)
339 (tty_clear_end_of_line, tty_setup_colors)
340 (delete_tty,updating_frame)
341 (produce_special_glyphs, produce_glyphs, write_glyphs)
342 (insert_glyphs): Remove.
343 (raw_cursor_to, clear_to_end, tty_turn_off_insert)
344 (tty_turn_off_highlight,get_tty_size): Add declaration.
345 (tabs_safe_p, init_baud_rate, get_tty_terminal): Update
346 prototypes.
347
348 * frame.h (enum output_method): Add output_initial.
349 (struct x_output): Delete.
350 (FRAME_FOREGROUND_PIXEL, FRAME_BACKGROUND_PIXEL): Access
351 foreground_pixel and background_pixel directly from the frame.
352 (tty_display): Delete.
353 (struct frame): Add buried_buffer_list, foreground_pixel,
354 background_pixel and terminal. Delete kboard
355 (union output_data): Add tty.
356 (FRAME_KBOARD): Get the kboard from the terminal.
357 (FRAME_INITIAL_P): New macro.
358 (Qtty, Qtty_type, Qterminal, Qterminal_live_p, Qenvironment)
359 (Qterm_environment_variable, Qdisplay_environment_variable)
360 (make_terminal_frame, Qburied_buffer_list, Qwindow_system): New
361 declarations.
362
363 * termchar.h (tty_output, tty_display_info): New structures.
364 (tty_list): Declare.
365 (FRAME_TTY, CURTTY): New macros.
366 (must_write_spaces, min_padding_speed, fast_clear_end_of_line)
367 (line_ins_del_ok, char_ins_del_ok, scroll_region_ok)
368 (scroll_region_cost, memory_below_frame, fast_clear_end_of_line)
369 (dont_calculate_costs, no_redraw_on_reenter): Remove declarations.
370
371 * callproc.c: Include frame.h and termhooks.h, for terminal
372 parameters.
373 (add_env): New function.
374 (child_setup): Use it.
375 (child_setup, getenv_internal): Handle the new
376 Vprocess_environment.
377 (getenv_internal): Fix get_terminal_param call.
378 (Fgetenv_internal, egetenv): Update doc.
379 (syms_of_callproc): Initialize Vprocess_environment to nil.
380 Register and initialize them. Remove obsolete defvars. Update doc
381 strings.
382 (child_setup): Handle Vlocal_environment_variables.
383 (getenv_internal): Add terminal parameter. Handle
384 Vlocal_environment_variables.
385 (Fgetenv_internal): Add terminal parameter.
386 (child_setup, getenv_internal, Fgetenv_internal): Store the local
387 environment in a frame (not terminal) parameter. Update doc
388 strings.
389 (set_initial_environment): Rename from set_global_environment.
390 Store Emacs environment in initial frame parameter.
391
392 * xdisp.c (redisplay_internal): Update references to
393 `previous_terminal_frame'.
394 (display_mode_line, Fformat_mode_line): Replace calls to
395 `push_frame_kboard' with `push_kboard'.
396 (get_glyph_string_clip_rects): Add extra parentheses and
397 braces to prevent compiler warnings.
398 (calc_pixel_width_or_height): Add xassert to check that the
399 frame is alive. Don't call `lookup_image' on a termcap frame.
400 (message2_nolog, message3_nolog, redisplay_internal)
401 (set_vertical_scroll_bar, redisplay_window, check_x_display_info)
402 (x_set_scroll_bar_foreground, x_set_scroll_bar_background)
403 (Fx_create_frame, Fxw_display_color_p, Fx_display_grayscale_p)
404 (Fx_display_pixel_width, Fx_display_pixel_height)
405 (Fx_display_planes, Fx_display_color_cells)
406 (Fx_server_max_request_size, Fx_server_vendor, Fx_server_version)
407 (Fx_display_screens, Fx_display_mm_height, Fx_display_mm_width)
408 (Fx_display_backing_store, Fx_display_visual_class)
409 (Fx_display_save_under, Fx_close_connection, x_create_tip_frame):
410 Use FRAME_TERMINAL_P, FRAME_WINDOW_P, FRAME_TTY and FRAME_RIF.
411
412 * xfns.c (x_set_foreground_color x_set_background_color)
413 (x_set_mouse_color, x_set_cursor_color, x_make_gc): Use
414 FRAME_BACKGROUND_PIXEL and FRAME_FOREGROUND_PIXEL.
415 (Fx_create_frame, x_create_tip_frame, build_string, x_window)
416 (Fx_create_frame, x_create_tip_frame): Don't create frames on a
417 terminal that is being deleted.
418 (Fx_create_frame): Use `store_frame_param' to set `window-system'
419 frame parameter, and make sure it overrides any user-supplied
420 setting.
421 (Fx_close_connection, Fx_synchronize): Unify argument names with
422 the rest of the DEFUNs.
423
424 * dispnew.c (Fsend_string_to_terminal): Update call to
425 `get_tty_terminal'.
426 (Fredraw_frame, Fsend_string_to_terminal)
427 (Fsend_string_to_terminal, init_display): User FRAME_RIF,
428 FRAME_TERMCAP_P and FRAME_TTY.
429 (window_change_signal): Don't believe width/height values that are
430 impossibly small.
431 (Vinitial_window_system): Rename from Vwindow_system.
432 (termscript, Wcm, rif): Delete.
433
434 * termhooks.h (struct terminal): New struct containing the
435 previously global text display hooks and new members NAME,
436 DELETED and PARAM_ALIST.
437 (FRAME_TERMINAL, TERMINAL_TERMINAL_CODING)
438 (TERMINAL_KEYBOARD_CODING, TERMINAL_ACTIVE_P, FRAME_WINDOW_P)
439 (FRAME_RIF): New macros.
440 (get_terminal_param, get_device): New declarations.
441 (termscript): Delete declaration.
442
443 * xterm.c (x_initialize): Use Fset_input_interrupt_mode.
444 (XTflash, x_free_frame_resources, x_scroll_bar_create)
445 (x_scroll_bar_set_handle): Use FRAME_BACKGROUND_PIXEL and
446 FRAME_FOREGROUND_PIXEL.
447 (x_fully_uncatch_errors): Disable definition.
448 (x_scroll_bar_expose): Fix reference to foreground pixel.
449 (XTread_socket): Disable loop on all X displays.
450 (x_delete_terminal): Don't set terminal->deleted and let
451 delete_terminal delete the frames on the terminal.
452 (x_delete_display): Doc update to reflect changes in
453 delete_terminal.
454 (x_display_info) <terminal>: Move member earlier in the struct.
455 (x_delete_terminal): Use terminal->deleted. Delete all frames on
456 the display explicitly.
457 (deleting_tty): Remove old variable.
458 (Fsuspend_tty): Call clear_tty_hooks.
459 (Fresume_tty, init_tty): Call set_tty_hooks.
460 (clear_tty_hooks, set_tty_hooks): New functions.
461 (Ftty_display_color_p, Ftty_display_color_cells): Don't throw
462 errors on X frames.
463 (x_catch_errors_unwind): Abort if x_error_message is NULL.
464 (handle_one_xevent): Initialize `f' to NULL.
465 (x_delete_device, x_create_device): New functions.
466 (XTset_terminal_modes, XTreset_terminal_modes)
467 (XTread_socket, x_connection_closed, x_term_init)
468 (x_term_init, x_delete_display): Add terminal parameter.
469 (x_term_init) [!HAVE_GTK_MULTIDISPLAY]: Refuse to create secondary
470 X connections.
471
472 * frame.c (Fframep): Deal with output_initial.
473 (Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list, Qtty)
474 (Qtty_type, Qwindow_system, Qenvironment)
475 (Qterm_environment_variable, Qdisplay_environment_variable): New
476 variables.
477 (x_set_screen_gamma, store_frame_param): Fix compilation errors.
478 (make_terminal_frame): Don't create frames on a terminal that is
479 being deleted.
480 (make_terminal_frame): Use FRAME_BACKGROUND_PIXEL and
481 FRAME_FOREGROUND_PIXEL.
482 (store_frame_param): Check for found_for_frame before calling
483 XFRAME.
484 (Fmake_terminal_frame): Handle NULL tty names correctly.
485 (syms_of_frame): Enhance doc string of `default-frame-alist'.
486 (Fdelete_frame): Remove unused variable `count'.
487 (Qenvironment): New variable.
488 (Fdelete_frame): Don't allow other frames to refer to a deleted
489 frame in their 'environment parameter.
490 (Fframe_with_environment): New function.
491 (syms_of_frame): Defsubr it. Initialize and staticpro
492 Qenvironment.
493 (get_future_frame_param): New function.
494 (Fmake_terminal_frame): Use it.
495
496 * sysdep.c (init_sys_modes, reset_sys_modes): Update for renames.
497 * sysdep.c (reset_sys_modes): Update for renames.
498
499 * keyboard.c (tty_read_avail_input): New function.
500 (Fset_input_interrupt_mode,Fset_output_flow_control): New
501 functions.
502 (syms_of_keyboard): Defsubr them.
503 (Fset_input_meta_mode, Fset_quit_char): New functions.
504 (Fset_input_mode): Split to above functions.
505
506 (read_char_minibuf_menu_prompt): Add wrong_kboard_jmpbuf
507 parameter. Use it in call to `read_char'.
508 (read_char): Declare. Update call to
509 `read_char_minibuf_menu_prompt'. Set wrong_kboard_jmpbuf
510 correctly in recursive calls. Use current_kboard to access
511 Vkeyboard_translate_table. Enhance comment before extra longjmp
512 to wrong_kboard_jmpbuf. Add wrong_kboard_jmpbuf parameter to
513 allow for recursive calls. Update longjmp invocations. Remember
514 the original current_kboard, and longjmp to `wrong_kboard_jmpbuf'
515 when a filter, timer or sentinel changes it. Comment out
516 unnecessary calls to `record_single_kboard_state' and
517 `any_kboard_state'. Update recursive calls.
518 (wrong_kboard_jmpbuf): Remove global variable.
519 (read_key_sequence): Remove unused variable wrong_kboard_jmpbuf.
520 Handle deleted interrupted_kboards correctly; that is a legal
521 case. Add `wrong_kboard_jmpbuf' local variable. Update setjmp
522 and read_char calls. Abort if interrupted_kboard died in
523 read_char.
524 (any_kboard_state, single_kboard_state)
525 (push_frame_kboard): Remove function.
526 (pop_kboard): Switch out of single_kboard mode if the kboard has
527 been deleted. Remove unused variable. Help debugging by not
528 changing current_kboard unnecessarily. Set current_kboard to the
529 kboard of the selected frame when the stored kboard object has
530 been deleted before pop_kboard.
531 (temporarily_switch_to_single_kboard): Change first parameter to a
532 frame pointer. Throw an error when caller wants to change kboards
533 while in single_kboard mode. Don't push_kboard if we weren't in
534 single kboard state. Don't pop_kboard if we popped into any
535 kboard state.
536 (restore_kboard_configuration): Abort if pop_kboard changed the
537 kboard in single_kboard mode. Call pop_kboard only after setting
538 up single_kboard mode.
539 (Frecursive_edit): Switch to single_kboard mode only in nested
540 command loops.
541 (cmd_error, command_loop, command_loop_1, timer_check): Comment
542 out unnecessary call to `any_kboard_state' and
543 `record_single_kboard_state'.
544 (delete_kboard): Exit single_kboard mode if we have just deleted
545 that kboard. Use FRAME_KBOARD.
546 (interrupt_signal): Use `Fkill_emacs' to exit Emacs, not
547 `fatal_error_signal'.
548 (record_single_kboard_state): Don't push_kboard if we weren't in
549 single kboard state. Don't pop_kboard if we popped into any
550 kboard state.
551 (push_frame_kboard): Rename to push_kboard.
552 (kbd_buffer_get_event): Use FRAME_TERMINAL.
553 (read_avail_input): Read input from all terminals.
554 (mark_kboards): Also mark Vkeyboard_translate_table.
555 (kbd_buffer_store_event_hold): Simplify condition.
556 (read_key_sequence): Reinitialize fkey and keytran at each replay.
557 (Vkeyboard_translate_table): Move to struct kboard.
558 (init_kboard): Initialize Vkeyboard_translate_table.
559 (syms_of_keyboard): Use DEFVAR_KBOARD to define
560 Vkeyboard_translate_table. Update doc strings. Update docs of
561 local-function-key-map and function-key-map.
562
563 * terminal.c: New file.
564
565 * term.c: Include errno.h.
566 (Vring_bell_function, device_list, initial_device)
567 (next_device_id, ring_bell, update_begin, update_end)
568 (set_terminal_window, cursor_to, raw_cursor_to)
569 (clear_to_end, clear_frame, clear_end_of_line)
570 (write_glyphs, insert_glyphs, delete_glyphs, ins_del_lines)
571 (Fdisplay_name, create_device, delete_device): Move to terminal.c.
572 (syms_of_term): Move their initialization to terminal.c.
573 (get_tty_terminal, Fdisplay_tty_type, Ftty_display_color_p)
574 (Ftty_display_color_cells)
575 (Ftty_no_underline, Fsuspend_tty, Fresume_tty, create_tty_output)
576 (init_tty, maybe_fatal): New functions.
577 (Ftty_type): Return nil if terminal is not on a tty instead of
578 throwing an error. Doc update.
579 (syms_of_term) <Vsuspend_tty_functions, Vresume_tty_functions>:
580 Doc update. Initialize new subrs and variables.
581 (delete_tty): Use terminal->deleted.
582 (tty_set_terminal_modes): Rename from set_terminal_modes.
583 (tty_reset_terminal_modes): Rename from reset_terminal_modes.
584 (set_scroll_region): Rename to `tty_set_scroll_region'.
585 (turn_on_insert): Rename to `tty_turn_on_insert'.
586 (turn_off_insert): Rename to `tty_turn_off_insert'.
587 (turn_off_highlight): Rename to `tty_turn_off_highlight'.
588 (turn_on_highlight): Rename to `tty_turn_on_highlight'.
589 (toggle_highligh): Rename to `tty_toggle_highlight'.
590 (background_highlight): Rename to `tty_background_highlight'.
591 (highlight_if_desired): Rename to `tty_highlight_if_desired'.
592 (tty_ring_bell, tty_update_end, tty_set_terminal_window)
593 (tty_set_scroll_region, tty_background_highlight)
594 (tty_cursor_to, tty_raw_cursor_to, tty_clear_to_end)
595 (tty_clear_frame, tty_clear_end_of_line, tty_write_glyphs)
596 (tty_insert_glyphs, tty_delete_glyphs, tty_ins_del_lines)
597 (term_get_fkeys, tty_setup_colors, dissociate_if_controlling_tty):
598 Add static modifier.
599 (tty_reset_terminal_modes, tty_set_terminal_window)
600 (tty_set_scroll_region, tty_background_highlight)
601 (tty_highlight_if_desired, tty_cursor_to)
602 (tty_raw_cursor_to, tty_clear_to_end, tty_clear_frame)
603 (tty_clear_end_of_line, tty_write_glyphs, tty_insert_glyphs)
604 (tty_delete_glyphs, tty_ins_del_lines, turn_on_face): Update for
605 renames.
606
12007-08-28 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> 6072007-08-28 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2 608
3 * keyboard.c: Qrtl is new. 609 * keyboard.c: Qrtl is new.
diff --git a/src/Makefile.in b/src/Makefile.in
index d34c272faa4..86c394f7bb2 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -595,7 +595,7 @@ emacsappsrc = ${srcdir}/../mac/Emacs.app/
595 whose initialized data areas should be dumped as pure by dump-emacs. */ 595 whose initialized data areas should be dumped as pure by dump-emacs. */
596obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \ 596obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \
597 charset.o coding.o category.o ccl.o \ 597 charset.o coding.o category.o ccl.o \
598 cm.o term.o xfaces.o $(XOBJ) $(GTK_OBJ)\ 598 cm.o term.o terminal.o xfaces.o $(XOBJ) $(GTK_OBJ)\
599 emacs.o keyboard.o macros.o keymap.o sysdep.o \ 599 emacs.o keyboard.o macros.o keymap.o sysdep.o \
600 buffer.o filelock.o insdel.o marker.o \ 600 buffer.o filelock.o insdel.o marker.o \
601 minibuf.o fileio.o dired.o filemode.o \ 601 minibuf.o fileio.o dired.o filemode.o \
@@ -741,6 +741,7 @@ otherobj= $(termcapobj) lastfile.o $(mallocobj) $(allocaobj) $(widgetobj) $(LIBO
741lisp= \ 741lisp= \
742 ${lispsource}abbrev.elc \ 742 ${lispsource}abbrev.elc \
743 ${lispsource}buff-menu.elc \ 743 ${lispsource}buff-menu.elc \
744 ${lispsource}server.elc \
744 ${lispsource}button.elc \ 745 ${lispsource}button.elc \
745 ${lispsource}emacs-lisp/byte-run.elc \ 746 ${lispsource}emacs-lisp/byte-run.elc \
746 ${lispsource}cus-face.elc \ 747 ${lispsource}cus-face.elc \
@@ -757,6 +758,7 @@ lisp= \
757 MOUSE_SUPPORT \ 758 MOUSE_SUPPORT \
758 ${lispsource}emacs-lisp/float-sup.elc \ 759 ${lispsource}emacs-lisp/float-sup.elc \
759 ${lispsource}frame.elc \ 760 ${lispsource}frame.elc \
761 ${lispsource}termdev.elc \
760 ${lispsource}help.elc \ 762 ${lispsource}help.elc \
761 ${lispsource}indent.elc \ 763 ${lispsource}indent.elc \
762 ${lispsource}isearch.elc \ 764 ${lispsource}isearch.elc \
@@ -840,6 +842,7 @@ lisp= \
840shortlisp= \ 842shortlisp= \
841 ../lisp/abbrev.elc \ 843 ../lisp/abbrev.elc \
842 ../lisp/buff-menu.elc \ 844 ../lisp/buff-menu.elc \
845 ../lisp/server.elc \
843 ../lisp/button.elc \ 846 ../lisp/button.elc \
844 ../lisp/emacs-lisp/byte-run.elc \ 847 ../lisp/emacs-lisp/byte-run.elc \
845 ../lisp/cus-face.elc \ 848 ../lisp/cus-face.elc \
@@ -854,6 +857,7 @@ shortlisp= \
854 ../lisp/emacs-lisp/float-sup.elc \ 857 ../lisp/emacs-lisp/float-sup.elc \
855 ../lisp/format.elc \ 858 ../lisp/format.elc \
856 ../lisp/frame.elc \ 859 ../lisp/frame.elc \
860 ../lisp/termdev.elc \
857 ../lisp/help.elc \ 861 ../lisp/help.elc \
858 ../lisp/indent.elc \ 862 ../lisp/indent.elc \
859 ../lisp/isearch.elc \ 863 ../lisp/isearch.elc \
@@ -943,7 +947,9 @@ SOME_MACHINE_LISP = ${dotdot}/lisp/mouse.elc \
943 ${dotdot}/lisp/x-dnd.elc \ 947 ${dotdot}/lisp/x-dnd.elc \
944 ${dotdot}/lisp/international/ccl.elc \ 948 ${dotdot}/lisp/international/ccl.elc \
945 ${dotdot}/lisp/international/codepage.elc \ 949 ${dotdot}/lisp/international/codepage.elc \
946 ${dotdot}/lisp/international/fontset.elc 950 ${dotdot}/lisp/international/fontset.elc \
951 ${dotdot}/lisp/mouse.elc \
952 ${dotdot}/lisp/term/x-win.elc
947 953
948/* Construct full set of libraries to be linked. 954/* Construct full set of libraries to be linked.
949 Note that SunOS needs -lm to come before -lc; otherwise, you get 955 Note that SunOS needs -lm to come before -lc; otherwise, you get
@@ -989,7 +995,7 @@ emacs${EXEEXT}: temacs${EXEEXT} ${etc}DOC ${lisp}
989 for the first time, this prevents any variation between configurations 995 for the first time, this prevents any variation between configurations
990 in the contents of the DOC file. 996 in the contents of the DOC file.
991 Likewise for ${SOME_MACHINE_LISP}. */ 997 Likewise for ${SOME_MACHINE_LISP}. */
992${etc}DOC: ${libsrc}make-docfile${EXEEXT} ${obj} ${shortlisp} ${SOME_MACHINE_LISP} 998${etc}DOC: ${libsrc}make-docfile ${obj} ${shortlisp} ${SOME_MACHINE_LISP}
993 -rm -f ${etc}DOC 999 -rm -f ${etc}DOC
994 ${libsrc}make-docfile -d ${srcdir} ${SOME_MACHINE_OBJECTS} ${obj} > ${etc}DOC 1000 ${libsrc}make-docfile -d ${srcdir} ${SOME_MACHINE_OBJECTS} ${obj} > ${etc}DOC
995 ${libsrc}make-docfile -a ${etc}DOC -d ${srcdir} ${SOME_MACHINE_LISP} ${shortlisp} 1001 ${libsrc}make-docfile -a ${etc}DOC -d ${srcdir} ${SOME_MACHINE_LISP} ${shortlisp}
@@ -1112,7 +1118,7 @@ callint.o: callint.c window.h commands.h buffer.h keymap.h \
1112 keyboard.h dispextern.h $(config_h) 1118 keyboard.h dispextern.h $(config_h)
1113callproc.o: callproc.c epaths.h buffer.h commands.h $(config_h) \ 1119callproc.o: callproc.c epaths.h buffer.h commands.h $(config_h) \
1114 process.h systty.h syssignal.h charset.h coding.h ccl.h msdos.h \ 1120 process.h systty.h syssignal.h charset.h coding.h ccl.h msdos.h \
1115 composite.h w32.h blockinput.h atimer.h systime.h 1121 composite.h w32.h blockinput.h atimer.h systime.h frame.h termhooks.h
1116casefiddle.o: casefiddle.c syntax.h commands.h buffer.h composite.h \ 1122casefiddle.o: casefiddle.c syntax.h commands.h buffer.h composite.h \
1117 charset.h keymap.h $(config_h) 1123 charset.h keymap.h $(config_h)
1118casetab.o: casetab.c buffer.h $(config_h) 1124casetab.o: casetab.c buffer.h $(config_h)
@@ -1121,8 +1127,8 @@ ccl.o: ccl.c ccl.h charset.h coding.h $(config_h)
1121charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \ 1127charset.o: charset.c charset.h buffer.h coding.h composite.h disptab.h \
1122 $(config_h) 1128 $(config_h)
1123coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h \ 1129coding.o: coding.c coding.h ccl.h buffer.h charset.h intervals.h composite.h \
1124 window.h dispextern.h $(config_h) 1130 window.h dispextern.h frame.h termhooks.h $(config_h)
1125cm.o: cm.c cm.h termhooks.h $(config_h) 1131cm.o: cm.c frame.h cm.h termhooks.h termchar.h $(config_h)
1126cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \ 1132cmds.o: cmds.c syntax.h buffer.h charset.h commands.h window.h $(config_h) \
1127 msdos.h dispextern.h keyboard.h keymap.h 1133 msdos.h dispextern.h keyboard.h keymap.h
1128pre-crt0.o: pre-crt0.c 1134pre-crt0.o: pre-crt0.c
@@ -1130,7 +1136,7 @@ ecrt0.o: ecrt0.c $(config_h)
1130 CRT0_COMPILE ${srcdir}/ecrt0.c 1136 CRT0_COMPILE ${srcdir}/ecrt0.c
1131dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \ 1137dired.o: dired.c commands.h buffer.h $(config_h) charset.h coding.h regex.h \
1132 systime.h blockinput.h atimer.h 1138 systime.h blockinput.h atimer.h
1133dispnew.o: dispnew.c systty.h systime.h commands.h process.h frame.h \ 1139dispnew.o: dispnew.c systime.h commands.h process.h frame.h \
1134 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \ 1140 window.h buffer.h dispextern.h termchar.h termopts.h termhooks.h cm.h \
1135 disptab.h indent.h intervals.h \ 1141 disptab.h indent.h intervals.h \
1136 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \ 1142 xterm.h blockinput.h atimer.h charset.h msdos.h composite.h keyboard.h \
@@ -1151,10 +1157,10 @@ filelock.o: filelock.c buffer.h charset.h coding.h systime.h epaths.h $(config_h
1151filemode.o: filemode.c $(config_h) 1157filemode.o: filemode.c $(config_h)
1152frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \ 1158frame.o: frame.c xterm.h window.h frame.h termhooks.h commands.h keyboard.h \
1153 blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \ 1159 blockinput.h atimer.h systime.h buffer.h charset.h fontset.h \
1154 msdos.h dosfns.h dispextern.h w32term.h macterm.h $(config_h) 1160 msdos.h dosfns.h dispextern.h w32term.h macterm.h termchar.h $(config_h)
1155fringe.o: fringe.c dispextern.h frame.h window.h buffer.h $(config_h) 1161fringe.o: fringe.c dispextern.h frame.h window.h buffer.h termhooks.h $(config_h)
1156fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \ 1162fontset.o: dispextern.h fontset.h fontset.c ccl.h buffer.h charset.h frame.h \
1157 keyboard.h $(config_h) 1163 keyboard.h termhooks.h $(config_h)
1158getloadavg.o: getloadavg.c $(config_h) 1164getloadavg.o: getloadavg.c $(config_h)
1159image.o: image.c frame.h window.h dispextern.h blockinput.h atimer.h \ 1165image.o: image.c frame.h window.h dispextern.h blockinput.h atimer.h \
1160 systime.h xterm.h w32term.h w32gui.h macterm.h macgui.h $(config_h) 1166 systime.h xterm.h w32term.h w32gui.h macterm.h macgui.h $(config_h)
@@ -1165,7 +1171,7 @@ insdel.o: insdel.c window.h buffer.h $(INTERVAL_SRC) blockinput.h charset.h \
1165 dispextern.h atimer.h systime.h region-cache.h $(config_h) 1171 dispextern.h atimer.h systime.h region-cache.h $(config_h)
1166keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \ 1172keyboard.o: keyboard.c termchar.h termhooks.h termopts.h buffer.h charset.h \
1167 commands.h frame.h window.h macros.h disptab.h keyboard.h syssignal.h \ 1173 commands.h frame.h window.h macros.h disptab.h keyboard.h syssignal.h \
1168 systty.h systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \ 1174 systime.h dispextern.h syntax.h $(INTERVAL_SRC) blockinput.h \
1169 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h) 1175 atimer.h xterm.h puresize.h msdos.h keymap.h w32term.h macterm.h $(config_h)
1170keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \ 1176keymap.o: keymap.c buffer.h commands.h keyboard.h termhooks.h blockinput.h \
1171 atimer.h systime.h puresize.h charset.h intervals.h keymap.h window.h \ 1177 atimer.h systime.h puresize.h charset.h intervals.h keymap.h window.h \
@@ -1180,7 +1186,8 @@ vm-limit.o: vm-limit.c mem-limits.h $(config_h)
1180marker.o: marker.c buffer.h charset.h $(config_h) 1186marker.o: marker.c buffer.h charset.h $(config_h)
1181md5.o: md5.c md5.h $(config_h) 1187md5.o: md5.c md5.h $(config_h)
1182minibuf.o: minibuf.c syntax.h dispextern.h frame.h window.h keyboard.h \ 1188minibuf.o: minibuf.c syntax.h dispextern.h frame.h window.h keyboard.h \
1183 buffer.h commands.h charset.h msdos.h $(INTERVAL_SRC) keymap.h $(config_h) 1189 buffer.h commands.h charset.h msdos.h $(INTERVAL_SRC) keymap.h \
1190 termhooks.h $(config_h)
1184mktime.o: mktime.c $(config_h) 1191mktime.o: mktime.c $(config_h)
1185msdos.o: msdos.c msdos.h dosfns.h systime.h termhooks.h dispextern.h frame.h \ 1192msdos.o: msdos.c msdos.h dosfns.h systime.h termhooks.h dispextern.h frame.h \
1186 termopts.h termchar.h charset.h coding.h ccl.h disptab.h window.h \ 1193 termopts.h termchar.h charset.h coding.h ccl.h disptab.h window.h \
@@ -1192,7 +1199,7 @@ process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \
1192regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h 1199regex.o: regex.c syntax.h buffer.h $(config_h) regex.h category.h charset.h
1193region-cache.o: region-cache.c buffer.h region-cache.h $(config_h) 1200region-cache.o: region-cache.c buffer.h region-cache.h $(config_h)
1194scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \ 1201scroll.o: scroll.c termchar.h dispextern.h frame.h msdos.h keyboard.h \
1195 $(config_h) 1202 termhooks.h $(config_h)
1196search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \ 1203search.o: search.c regex.h commands.h buffer.h region-cache.h syntax.h \
1197 blockinput.h atimer.h systime.h category.h charset.h composite.h \ 1204 blockinput.h atimer.h systime.h category.h charset.h composite.h \
1198 $(INTERVAL_SRC) $(config_h) 1205 $(INTERVAL_SRC) $(config_h)
@@ -1201,11 +1208,13 @@ syntax.o: syntax.c syntax.h buffer.h commands.h category.h charset.h \
1201 composite.h keymap.h regex.h $(INTERVAL_SRC) $(config_h) 1208 composite.h keymap.h regex.h $(INTERVAL_SRC) $(config_h)
1202sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \ 1209sysdep.o: sysdep.c syssignal.h systty.h systime.h syswait.h blockinput.h \
1203 process.h dispextern.h termhooks.h termchar.h termopts.h \ 1210 process.h dispextern.h termhooks.h termchar.h termopts.h \
1204 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h $(config_h) 1211 frame.h atimer.h window.h msdos.h dosfns.h keyboard.h cm.h $(config_h)
1205term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \ 1212term.o: term.c termchar.h termhooks.h termopts.h $(config_h) cm.h frame.h \
1206 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h \ 1213 disptab.h dispextern.h keyboard.h charset.h coding.h ccl.h msdos.h \
1207 window.h keymap.h blockinput.h atimer.h systime.h 1214 window.h keymap.h blockinput.h atimer.h systime.h
1208termcap.o: termcap.c $(config_h) 1215termcap.o: termcap.c $(config_h)
1216terminal.o: terminal.c frame.h termchar.h termhooks.h charset.h coding.h \
1217 keyboard.h $(config_h)
1209terminfo.o: terminfo.c $(config_h) 1218terminfo.o: terminfo.c $(config_h)
1210tparam.o: tparam.c $(config_h) 1219tparam.o: tparam.c $(config_h)
1211undo.o: undo.c buffer.h commands.h window.h $(config_h) 1220undo.o: undo.c buffer.h commands.h window.h $(config_h)
@@ -1218,7 +1227,7 @@ w16select.o: w16select.c dispextern.h frame.h blockinput.h atimer.h systime.h \
1218widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \ 1227widget.o: widget.c xterm.h frame.h dispextern.h widgetprv.h \
1219 $(srcdir)/../lwlib/lwlib.h $(config_h) 1228 $(srcdir)/../lwlib/lwlib.h $(config_h)
1220window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \ 1229window.o: window.c indent.h commands.h frame.h window.h buffer.h termchar.h \
1221 termhooks.h disptab.h keyboard.h dispextern.h msdos.h composite.h \ 1230 disptab.h keyboard.h dispextern.h msdos.h composite.h \
1222 keymap.h blockinput.h atimer.h systime.h $(INTERVAL_SRC) \ 1231 keymap.h blockinput.h atimer.h systime.h $(INTERVAL_SRC) \
1223 xterm.h w32term.h macterm.h $(config_h) 1232 xterm.h w32term.h macterm.h $(config_h)
1224xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \ 1233xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h coding.h \
@@ -1227,10 +1236,11 @@ xdisp.o: xdisp.c macros.h commands.h process.h indent.h buffer.h dispextern.h co
1227 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h 1236 msdos.h composite.h fontset.h blockinput.h atimer.h systime.h keymap.h
1228xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \ 1237xfaces.o: xfaces.c dispextern.h frame.h xterm.h buffer.h blockinput.h \
1229 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \ 1238 window.h charset.h msdos.h dosfns.h composite.h atimer.h systime.h \
1230 keyboard.h fontset.h w32term.h macterm.h $(INTERVAL_SRC) $(config_h) 1239 keyboard.h fontset.h w32term.h macterm.h $(INTERVAL_SRC) termchar.h \
1240 termhooks.h $(config_h)
1231xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \ 1241xfns.o: xfns.c buffer.h frame.h window.h keyboard.h xterm.h dispextern.h \
1232 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \ 1242 $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h epaths.h \
1233 charset.h gtkutil.h $(config_h) 1243 charset.h gtkutil.h termchar.h termhooks.h $(config_h)
1234xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \ 1244xmenu.o: xmenu.c xterm.h termhooks.h window.h dispextern.h frame.h buffer.h \
1235 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \ 1245 keyboard.h $(srcdir)/../lwlib/lwlib.h blockinput.h atimer.h systime.h \
1236 gtkutil.h msdos.h coding.h $(config_h) 1246 gtkutil.h msdos.h coding.h $(config_h)
@@ -1239,7 +1249,7 @@ xterm.o: xterm.c xterm.h termhooks.h termopts.h termchar.h window.h buffer.h \
1239 keyboard.h gnu.h charset.h ccl.h fontset.h composite.h \ 1249 keyboard.h gnu.h charset.h ccl.h fontset.h composite.h \
1240 coding.h process.h gtkutil.h $(config_h) 1250 coding.h process.h gtkutil.h $(config_h)
1241xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \ 1251xselect.o: xselect.c process.h dispextern.h frame.h xterm.h blockinput.h \
1242 buffer.h atimer.h systime.h $(config_h) 1252 buffer.h atimer.h systime.h termhooks.h $(config_h)
1243xrdb.o: xrdb.c $(config_h) epaths.h 1253xrdb.o: xrdb.c $(config_h) epaths.h
1244xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \ 1254xsmfns.o: xsmfns.c $(config_h) systime.h sysselect.h termhooks.h xterm.h \
1245 lisp.h termopts.h 1255 lisp.h termopts.h
@@ -1257,19 +1267,18 @@ alloc.o: alloc.c process.h frame.h window.h buffer.h puresize.h syssignal.h key
1257 blockinput.h atimer.h systime.h charset.h dispextern.h $(config_h) $(INTERVAL_SRC) 1267 blockinput.h atimer.h systime.h charset.h dispextern.h $(config_h) $(INTERVAL_SRC)
1258bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h dispextern.h \ 1268bytecode.o: bytecode.c buffer.h syntax.h charset.h window.h dispextern.h \
1259 frame.h xterm.h $(config_h) 1269 frame.h xterm.h $(config_h)
1260data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h frame.h $(config_h) 1270data.o: data.c buffer.h puresize.h charset.h syssignal.h keyboard.h frame.h termhooks.h $(config_h)
1261eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \ 1271eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h \
1262 dispextern.h $(config_h) 1272 dispextern.h $(config_h)
1263floatfns.o: floatfns.c $(config_h) 1273floatfns.o: floatfns.c $(config_h)
1264fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \ 1274fns.o: fns.c commands.h $(config_h) frame.h buffer.h charset.h keyboard.h \
1265 keymap.h frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h \ 1275 keymap.h frame.h window.h dispextern.h $(INTERVAL_SRC) coding.h md5.h \
1266 blockinput.h atimer.h systime.h xterm.h 1276 blockinput.h atimer.h systime.h xterm.h termhooks.h
1267print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \ 1277print.o: print.c process.h frame.h window.h buffer.h keyboard.h charset.h \
1268 $(config_h) dispextern.h termchar.h $(INTERVAL_SRC) msdos.h composite.h \ 1278 $(config_h) dispextern.h termchar.h $(INTERVAL_SRC) msdos.h composite.h \
1269 blockinput.h atimer.h systime.h 1279 blockinput.h atimer.h systime.h
1270lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h \ 1280lread.o: lread.c commands.h keyboard.h buffer.h epaths.h charset.h \
1271 $(config_h) $(INTERVAL_SRC) termhooks.h coding.h msdos.h blockinput.h \ 1281 $(config_h) $(INTERVAL_SRC) termhooks.h coding.h msdos.h
1272 atimer.h systime.h
1273 1282
1274/* Text properties support */ 1283/* Text properties support */
1275textprop.o: textprop.c buffer.h window.h dispextern.h $(INTERVAL_SRC) \ 1284textprop.o: textprop.c buffer.h window.h dispextern.h $(INTERVAL_SRC) \
@@ -1282,12 +1291,12 @@ composite.o: composite.c buffer.h charset.h $(INTERVAL_SRC) $(config_h)
1282 OTHER_FILES and OBJECTS_MACHINE 1291 OTHER_FILES and OBJECTS_MACHINE
1283 select which of these should be compiled. */ 1292 select which of these should be compiled. */
1284 1293
1285sunfns.o: sunfns.c buffer.h window.h dispextern.h $(config_h) 1294sunfns.o: sunfns.c buffer.h window.h dispextern.h termhooks.h $(config_h)
1286 1295
1287#ifdef HAVE_CARBON 1296#ifdef HAVE_CARBON
1288abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \ 1297abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
1289 fontset.o indent.o insdel.o keyboard.o macros.o minibuf.o msdos.o process.o \ 1298 fontset.o indent.o insdel.o keyboard.o macros.o minibuf.o msdos.o process.o \
1290 scroll.o sysdep.o term.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \ 1299 scroll.o sysdep.o term.o terminal.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \
1291 xterm.o xselect.o sound.o: macgui.h 1300 xterm.o xselect.o sound.o: macgui.h
1292mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \ 1301mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \
1293 coding.h ccl.h $(config_h) 1302 coding.h ccl.h $(config_h)
diff --git a/src/alloc.c b/src/alloc.c
index 2947e48f815..8aea81a0f72 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 *));
@@ -1234,7 +1236,8 @@ emacs_blocked_malloc (size, ptr)
1234 BLOCK_INPUT_ALLOC; 1236 BLOCK_INPUT_ALLOC;
1235 __malloc_hook = old_malloc_hook; 1237 __malloc_hook = old_malloc_hook;
1236#ifdef DOUG_LEA_MALLOC 1238#ifdef DOUG_LEA_MALLOC
1237 mallopt (M_TOP_PAD, malloc_hysteresis * 4096); 1239 /* Segfaults on my system. --lorentey */
1240 /* mallopt (M_TOP_PAD, malloc_hysteresis * 4096); */
1238#else 1241#else
1239 __malloc_extra_blocks = malloc_hysteresis; 1242 __malloc_extra_blocks = malloc_hysteresis;
1240#endif 1243#endif
@@ -5170,7 +5173,9 @@ returns nil, because real GC can't be done. */)
5170 mark_object (bind->symbol); 5173 mark_object (bind->symbol);
5171 mark_object (bind->old_value); 5174 mark_object (bind->old_value);
5172 } 5175 }
5176 mark_terminals ();
5173 mark_kboards (); 5177 mark_kboards ();
5178 mark_ttys ();
5174 5179
5175#ifdef USE_GTK 5180#ifdef USE_GTK
5176 { 5181 {
@@ -5605,6 +5610,7 @@ mark_object (arg)
5605 mark_object (ptr->menu_bar_vector); 5610 mark_object (ptr->menu_bar_vector);
5606 mark_object (ptr->buffer_predicate); 5611 mark_object (ptr->buffer_predicate);
5607 mark_object (ptr->buffer_list); 5612 mark_object (ptr->buffer_list);
5613 mark_object (ptr->buried_buffer_list);
5608 mark_object (ptr->menu_bar_window); 5614 mark_object (ptr->menu_bar_window);
5609 mark_object (ptr->tool_bar_window); 5615 mark_object (ptr->tool_bar_window);
5610 mark_face_cache (ptr->face_cache); 5616 mark_face_cache (ptr->face_cache);
diff --git a/src/buffer.c b/src/buffer.c
index 127bfba44e0..8cd13b07855 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 9b3535474c0..57c86f0a633 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 */
@@ -854,12 +854,11 @@ invoke it. If KEYS is omitted or nil, the return value of
854 real_this_command= save_real_this_command; 854 real_this_command= save_real_this_command;
855 current_kboard->Vlast_command = save_last_command; 855 current_kboard->Vlast_command = save_last_command;
856 856
857 single_kboard_state ();
858
859 { 857 {
860 Lisp_Object val; 858 Lisp_Object val;
861 specbind (Qcommand_debug_status, Qnil); 859 specbind (Qcommand_debug_status, Qnil);
862 860
861 temporarily_switch_to_single_kboard (NULL);
863 val = Ffuncall (count + 1, args); 862 val = Ffuncall (count + 1, args);
864 UNGCPRO; 863 UNGCPRO;
865 return unbind_to (speccount, val); 864 return unbind_to (speccount, val);
diff --git a/src/callproc.c b/src/callproc.c
index bf7ea43b868..5bd4cee9cfa 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.
@@ -1208,6 +1245,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1208{ 1245{
1209 char **env; 1246 char **env;
1210 char *pwd_var; 1247 char *pwd_var;
1248 char *term_var;
1249 char *display_var;
1211#ifdef WINDOWSNT 1250#ifdef WINDOWSNT
1212 int cpid; 1251 int cpid;
1213 HANDLE handles[3]; 1252 HANDLE handles[3];
@@ -1282,57 +1321,101 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1282 temp[--i] = 0; 1321 temp[--i] = 0;
1283 } 1322 }
1284 1323
1285 /* Set `env' to a vector of the strings in Vprocess_environment. */ 1324 /* Set `env' to a vector of the strings in the environment. */
1286 { 1325 {
1287 register Lisp_Object tem; 1326 register Lisp_Object tem;
1288 register char **new_env; 1327 register char **new_env;
1328 char **p, **q;
1289 register int new_length; 1329 register int new_length;
1330 Lisp_Object local = selected_frame; /* get_frame_param (XFRAME (Fframe_with_environment (selected_frame)), */
1331/* Qenvironment); */
1290 1332
1333 Lisp_Object term;
1334 Lisp_Object display;
1335
1291 new_length = 0; 1336 new_length = 0;
1337
1292 for (tem = Vprocess_environment; 1338 for (tem = Vprocess_environment;
1339 CONSP (tem) && STRINGP (XCAR (tem));
1340 tem = XCDR (tem))
1341 new_length++;
1342
1343#if 0
1344 for (tem = local;
1293 CONSP (tem) && STRINGP (XCAR (tem)); 1345 CONSP (tem) && STRINGP (XCAR (tem));
1294 tem = XCDR (tem)) 1346 tem = XCDR (tem))
1295 new_length++; 1347 new_length++;
1348#endif
1349
1350 /* Add TERM and DISPLAY from the frame local values. */
1351 term = get_frame_param (XFRAME (local), Qterm_environment_variable);
1352 if (! NILP (term))
1353 new_length++;
1354
1355 display = get_frame_param (XFRAME (local), Qdisplay_environment_variable);
1356 if (! NILP (display))
1357 new_length++;
1296 1358
1297 /* new_length + 2 to include PWD and terminating 0. */ 1359 /* new_length + 2 to include PWD and terminating 0. */
1298 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *)); 1360 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
1299 1361
1300 /* If we have a PWD envvar, pass one down, 1362 /* If we have a PWD envvar, pass one down,
1301 but with corrected value. */ 1363 but with corrected value. */
1302 if (getenv ("PWD")) 1364 if (egetenv ("PWD"))
1303 *new_env++ = pwd_var; 1365 *new_env++ = pwd_var;
1366
1367 if (! NILP (term))
1368 {
1369 int vlen = strlen ("TERM=") + strlen (SDATA (term)) + 1;
1370 char *vdata = (char *) alloca (vlen);
1371 strcpy (vdata, "TERM=");
1372 strcat (vdata, SDATA (term));
1373 new_env = add_env (env, new_env, vdata);
1374 }
1375
1376 if (! NILP (display))
1377 {
1378 int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1;
1379 char *vdata = (char *) alloca (vlen);
1380 strcpy (vdata, "DISPLAY=");
1381 strcat (vdata, SDATA (display));
1382 new_env = add_env (env, new_env, vdata);
1383 }
1304 1384
1305 /* Copy the Vprocess_environment strings into new_env. */ 1385 /* Overrides. */
1306 for (tem = Vprocess_environment; 1386 for (tem = Vprocess_environment;
1307 CONSP (tem) && STRINGP (XCAR (tem)); 1387 CONSP (tem) && STRINGP (XCAR (tem));
1308 tem = XCDR (tem)) 1388 tem = XCDR (tem))
1309 { 1389 {
1310 char **ep = env; 1390 if ((strcmp (SDATA (XCAR (tem)), "TERM") != 0)
1311 char *string = (char *) SDATA (XCAR (tem)); 1391 && (strcmp (SDATA (XCAR (tem)), "DISPLAY") != 0))
1312 /* See if this string duplicates any string already in the env. 1392 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1313 If so, don't put it in.
1314 When an env var has multiple definitions,
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 } 1393 }
1394
1395
1396#if 0
1397 /* Local part of environment. */
1398 for (tem = local;
1399 CONSP (tem) && STRINGP (XCAR (tem));
1400 tem = XCDR (tem))
1401 new_env = add_env (env, new_env, SDATA (XCAR (tem)));
1402#endif
1403
1334 *new_env = 0; 1404 *new_env = 0;
1405
1406 /* Remove variable names without values. */
1407 p = q = env;
1408 while (*p != 0)
1409 {
1410 while (*q != 0 && strchr (*q, '=') == NULL)
1411 *q++;
1412 *p = *q++;
1413 if (*p != 0)
1414 p++;
1415 }
1335 } 1416 }
1417
1418
1336#ifdef WINDOWSNT 1419#ifdef WINDOWSNT
1337 prepare_standard_handles (in, out, err, handles); 1420 prepare_standard_handles (in, out, err, handles);
1338 set_process_dir (SDATA (current_dir)); 1421 set_process_dir (SDATA (current_dir));
@@ -1446,59 +1529,160 @@ relocate_fd (fd, minfd)
1446} 1529}
1447 1530
1448static int 1531static int
1449getenv_internal (var, varlen, value, valuelen) 1532getenv_internal (var, varlen, value, valuelen, frame)
1450 char *var; 1533 char *var;
1451 int varlen; 1534 int varlen;
1452 char **value; 1535 char **value;
1453 int *valuelen; 1536 int *valuelen;
1537 Lisp_Object frame;
1454{ 1538{
1455 Lisp_Object scan; 1539 Lisp_Object scan;
1540 Lisp_Object term;
1541 Lisp_Object display;
1542
1543
1544 if (NILP (frame))
1545 {
1546 /* Try to find VAR in Vprocess_environment first. */
1547 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1548 {
1549 Lisp_Object entry = XCAR (scan);
1550 if (STRINGP (entry)
1551 && SBYTES (entry) >= varlen
1552#ifdef WINDOWSNT
1553 /* NT environment variables are case insensitive. */
1554 && ! strnicmp (SDATA (entry), var, varlen)
1555#else /* not WINDOWSNT */
1556 && ! bcmp (SDATA (entry), var, varlen)
1557#endif /* not WINDOWSNT */
1558 )
1559 {
1560 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1561 {
1562 *value = (char *) SDATA (entry) + (varlen + 1);
1563 *valuelen = SBYTES (entry) - (varlen + 1);
1564 return 1;
1565 }
1566 else if (SBYTES (entry) == varlen)
1567 {
1568 /* Lone variable names in Vprocess_environment mean that
1569 variable should be removed from the environment. */
1570 return 0;
1571 }
1572 }
1573 }
1574 frame = selected_frame;
1575 }
1576
1577 /* For TERM and DISPLAY first try to get the values from the frame. */
1578 term = get_frame_param (XFRAME (frame), Qterm_environment_variable);
1579 if (strcmp (var, "TERM") == 0)
1580 if (! NILP (term))
1581 {
1582 *value = (char *) SDATA (term);
1583 *valuelen = SBYTES (term);
1584 return 1;
1585 }
1586 display = get_frame_param (XFRAME (frame), Qdisplay_environment_variable);
1587 if (strcmp (var, "DISPLAY") == 0)
1588 if (! NILP (display))
1589 {
1590 *value = (char *) SDATA (display);
1591 *valuelen = SBYTES (display);
1592 return 1;
1593 }
1594
1595 {
1596 /* Try to find VAR in Vprocess_environment. */
1597 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1598 {
1599 Lisp_Object entry = XCAR (scan);
1600 if (STRINGP (entry)
1601 && SBYTES (entry) >= varlen
1602#ifdef WINDOWSNT
1603 /* NT environment variables are case insensitive. */
1604 && ! strnicmp (SDATA (entry), var, varlen)
1605#else /* not WINDOWSNT */
1606 && ! bcmp (SDATA (entry), var, varlen)
1607#endif /* not WINDOWSNT */
1608 )
1609 {
1610 if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=')
1611 {
1612 *value = (char *) SDATA (entry) + (varlen + 1);
1613 *valuelen = SBYTES (entry) - (varlen + 1);
1614 return 1;
1615 }
1616 else if (SBYTES (entry) == varlen)
1617 {
1618 /* Lone variable names in Vprocess_environment mean that
1619 variable should be removed from the environment. */
1620 return 0;
1621 }
1622 }
1623 }
1624 }
1456 1625
1457 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) 1626#if 0
1627 /* Find the environment in which to search the variable. */
1628 CHECK_FRAME (frame);
1629 frame = Fframe_with_environment (frame);
1630
1631 for (scan = get_frame_param (XFRAME (frame), Qenvironment);
1632 CONSP (scan);
1633 scan = XCDR (scan))
1458 { 1634 {
1459 Lisp_Object entry; 1635 Lisp_Object entry;
1460 1636
1461 entry = XCAR (scan); 1637 entry = XCAR (scan);
1462 if (STRINGP (entry) 1638 if (STRINGP (entry)
1463 && SBYTES (entry) > varlen 1639 && SBYTES (entry) > varlen
1464 && SREF (entry, varlen) == '=' 1640 && SREF (entry, varlen) == '='
1465#ifdef WINDOWSNT 1641#ifdef WINDOWSNT
1466 /* NT environment variables are case insensitive. */ 1642 /* NT environment variables are case insensitive. */
1467 && ! strnicmp (SDATA (entry), var, varlen) 1643 && ! strnicmp (SDATA (entry), var, varlen)
1468#else /* not WINDOWSNT */ 1644#else /* not WINDOWSNT */
1469 && ! bcmp (SDATA (entry), var, varlen) 1645 && ! bcmp (SDATA (entry), var, varlen)
1470#endif /* not WINDOWSNT */ 1646#endif /* not WINDOWSNT */
1471 ) 1647 )
1472 { 1648 {
1473 *value = (char *) SDATA (entry) + (varlen + 1); 1649 *value = (char *) SDATA (entry) + (varlen + 1);
1474 *valuelen = SBYTES (entry) - (varlen + 1); 1650 *valuelen = SBYTES (entry) - (varlen + 1);
1475 return 1; 1651 return 1;
1476 } 1652 }
1477 } 1653 }
1478 1654#endif
1479 return 0; 1655 return 0;
1480} 1656}
1481 1657
1482DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 1, 0, 1658DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 2, 0,
1483 doc: /* Return the value of environment variable VAR, as a string. 1659 doc: /* Get the value of environment variable VARIABLE.
1484VAR should be a string. Value is nil if VAR is undefined in the environment. 1660VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1485This function consults the variable `process-environment' for its value. */) 1661the environment. Otherwise, value is a string.
1486 (var) 1662
1487 Lisp_Object var; 1663This function searches `process-environment' for VARIABLE. If it is
1664not found there, then it continues the search in the environment list
1665of the selected frame.
1666
1667If optional parameter FRAME is non-nil, then this function will ignore
1668`process-environment' and will simply look up the variable in that
1669frame's environment. */)
1670 (variable, frame)
1671 Lisp_Object variable, frame;
1488{ 1672{
1489 char *value; 1673 char *value;
1490 int valuelen; 1674 int valuelen;
1491 1675
1492 CHECK_STRING (var); 1676 CHECK_STRING (variable);
1493 if (getenv_internal (SDATA (var), SBYTES (var), 1677 if (getenv_internal (SDATA (variable), SBYTES (variable),
1494 &value, &valuelen)) 1678 &value, &valuelen, frame))
1495 return make_string (value, valuelen); 1679 return make_string (value, valuelen);
1496 else 1680 else
1497 return Qnil; 1681 return Qnil;
1498} 1682}
1499 1683
1500/* A version of getenv that consults process_environment, easily 1684/* A version of getenv that consults the Lisp environment lists,
1501 callable from C. */ 1685 easily callable from C. */
1502char * 1686char *
1503egetenv (var) 1687egetenv (var)
1504 char *var; 1688 char *var;
@@ -1506,7 +1690,7 @@ egetenv (var)
1506 char *value; 1690 char *value;
1507 int valuelen; 1691 int valuelen;
1508 1692
1509 if (getenv_internal (var, strlen (var), &value, &valuelen)) 1693 if (getenv_internal (var, strlen (var), &value, &valuelen, Qnil))
1510 return value; 1694 return value;
1511 else 1695 else
1512 return 0; 1696 return 0;
@@ -1629,8 +1813,8 @@ init_callproc ()
1629 { 1813 {
1630 char *dir = getenv ("TMPDIR"); 1814 char *dir = getenv ("TMPDIR");
1631 Vtemp_file_name_pattern 1815 Vtemp_file_name_pattern
1632 = Fexpand_file_name (build_string ("emacsXXXXXX"), 1816 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1633 build_string (dir)); 1817 build_string (dir));
1634 } 1818 }
1635 else 1819 else
1636 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX"); 1820 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
@@ -1646,17 +1830,19 @@ init_callproc ()
1646} 1830}
1647 1831
1648void 1832void
1649set_process_environment () 1833set_initial_environment ()
1650{ 1834{
1651 register char **envp; 1835 register char **envp;
1652 1836 Lisp_Object env = Vprocess_environment;
1653 Vprocess_environment = Qnil;
1654#ifndef CANNOT_DUMP 1837#ifndef CANNOT_DUMP
1655 if (initialized) 1838 if (initialized)
1656#endif 1839#endif
1657 for (envp = environ; *envp; envp++) 1840 {
1658 Vprocess_environment = Fcons (build_string (*envp), 1841 for (envp = environ; *envp; envp++)
1659 Vprocess_environment); 1842 Vprocess_environment = Fcons (build_string (*envp),
1843 Vprocess_environment);
1844 store_frame_param (SELECTED_FRAME(), Qenvironment, Vprocess_environment);
1845 }
1660} 1846}
1661 1847
1662void 1848void
@@ -1716,15 +1902,27 @@ This is used by `call-process-region'. */);
1716 /* This variable is initialized in init_callproc. */ 1902 /* This variable is initialized in init_callproc. */
1717 1903
1718 DEFVAR_LISP ("process-environment", &Vprocess_environment, 1904 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1719 doc: /* List of environment variables for subprocesses to inherit. 1905 doc: /* List of overridden environment variables for subprocesses to inherit.
1720Each element should be a string of the form ENVVARNAME=VALUE. 1906Each element should be a string of the form ENVVARNAME=VALUE.
1907
1908Entries in this list take precedence to those in the frame-local
1909environments. Therefore, let-binding `process-environment' is an easy
1910way to temporarily change the value of an environment variable,
1911irrespective of where it comes from. To use `process-environment' to
1912remove an environment variable, include only its name in the list,
1913without "=VALUE".
1914
1915This variable is set to nil when Emacs starts.
1916
1721If multiple entries define the same variable, the first one always 1917If multiple entries define the same variable, the first one always
1722takes precedence. 1918takes precedence.
1723The environment which Emacs inherits is placed in this variable 1919
1724when Emacs starts.
1725Non-ASCII characters are encoded according to the initial value of 1920Non-ASCII characters are encoded according to the initial value of
1726`locale-coding-system', i.e. the elements must normally be decoded for use. 1921`locale-coding-system', i.e. the elements must normally be decoded for
1922use.
1923
1727See `setenv' and `getenv'. */); 1924See `setenv' and `getenv'. */);
1925 Vprocess_environment = Qnil;
1728 1926
1729#ifndef VMS 1927#ifndef VMS
1730 defsubr (&Scall_process); 1928 defsubr (&Scall_process);
diff --git a/src/cm.c b/src/cm.c
index 18331216776..ad8ec080c9d 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 7c26a9ce66a..36413703a92 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 7359f0214ba..e2ce0c9f8de 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
@@ -7695,8 +7703,6 @@ init_coding_once ()
7695 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3; 7703 iso_code_class[ISO_CODE_SS3] = ISO_single_shift_3;
7696 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer; 7704 iso_code_class[ISO_CODE_CSI] = ISO_control_sequence_introducer;
7697 7705
7698 setup_coding_system (Qnil, &keyboard_coding);
7699 setup_coding_system (Qnil, &terminal_coding);
7700 setup_coding_system (Qnil, &safe_terminal_coding); 7706 setup_coding_system (Qnil, &safe_terminal_coding);
7701 setup_coding_system (Qnil, &default_buffer_file_coding); 7707 setup_coding_system (Qnil, &default_buffer_file_coding);
7702 7708
diff --git a/src/coding.h b/src/coding.h
index 2efcd4f47e2..a53a74ec161 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 e050ceae44f..59d4b91ed31 100644
--- a/src/config.in
+++ b/src/config.in
@@ -929,11 +929,19 @@ Boston, MA 02110-1301, USA. */
929#define HAVE_MOUSE 929#define HAVE_MOUSE
930#endif 930#endif
931 931
932/* Multi-tty support relies on MULTI_KBOARD. It seems safe to turn it
933 on unconditionally. */
934#ifndef MULTI_KBOARD
935#define MULTI_KBOARD
936#endif
937
932/* If we're using the Carbon API on Mac OS X, define a few more 938/* If we're using the Carbon API on Mac OS X, define a few more
933 variables as well. */ 939 variables as well. */
934#ifdef HAVE_CARBON 940#ifdef HAVE_CARBON
935#define HAVE_WINDOW_SYSTEM 941#define HAVE_WINDOW_SYSTEM
936#define HAVE_MOUSE 942#define HAVE_MOUSE
943/* XXX The MULTI_KBOARD support does not work yet on this platform. */
944#undef MULTI_KBOARD
937#endif 945#endif
938 946
939/* Define USER_FULL_NAME to return a string 947/* Define USER_FULL_NAME to return a string
diff --git a/src/data.c b/src/data.c
index 3f27e387350..1f82f929281 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>
@@ -873,7 +874,18 @@ do_symval_forwarding (valcontents)
873 874
874 case Lisp_Misc_Kboard_Objfwd: 875 case Lisp_Misc_Kboard_Objfwd:
875 offset = XKBOARD_OBJFWD (valcontents)->offset; 876 offset = XKBOARD_OBJFWD (valcontents)->offset;
876 return *(Lisp_Object *)(offset + (char *)current_kboard); 877 /* We used to simply use current_kboard here, but from Lisp
878 code, it's value is often unexpected. It seems nicer to
879 allow constructions like this to work as intuitively expected:
880
881 (with-selected-frame frame
882 (define-key local-function-map "\eOP" [f1]))
883
884 On the other hand, this affects the semantics of
885 last-command and real-last-command, and people may rely on
886 that. I took a quick look at the Lisp codebase, and I
887 don't think anything will break. --lorentey */
888 return *(Lisp_Object *)(offset + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
877 } 889 }
878 return valcontents; 890 return valcontents;
879} 891}
@@ -961,7 +973,7 @@ store_symval_forwarding (symbol, valcontents, newval, buf)
961 973
962 case Lisp_Misc_Kboard_Objfwd: 974 case Lisp_Misc_Kboard_Objfwd:
963 { 975 {
964 char *base = (char *) current_kboard; 976 char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ());
965 char *p = base + XKBOARD_OBJFWD (valcontents)->offset; 977 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
966 *(Lisp_Object *) p = newval; 978 *(Lisp_Object *) p = newval;
967 } 979 }
@@ -1107,7 +1119,7 @@ find_symbol_value (symbol)
1107 1119
1108 case Lisp_Misc_Kboard_Objfwd: 1120 case Lisp_Misc_Kboard_Objfwd:
1109 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset 1121 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
1110 + (char *)current_kboard); 1122 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
1111 } 1123 }
1112 } 1124 }
1113 1125
@@ -1868,6 +1880,51 @@ If the current binding is global (the default), the value is nil. */)
1868 1880
1869 return Qnil; 1881 return Qnil;
1870} 1882}
1883
1884/* This code is disabled now that we use the selected frame to return
1885 keyboard-local-values. */
1886#if 0
1887extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
1888
1889DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
1890 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
1891If SYMBOL is not a terminal-local variable, then return its normal
1892value, like `symbol-value'.
1893
1894TERMINAL may be a terminal id, a frame, or nil (meaning the
1895selected frame's terminal device). */)
1896 (symbol, terminal)
1897 Lisp_Object symbol;
1898 Lisp_Object terminal;
1899{
1900 Lisp_Object result;
1901 struct terminal *t = get_terminal (terminal, 1);
1902 push_kboard (t->kboard);
1903 result = Fsymbol_value (symbol);
1904 pop_kboard ();
1905 return result;
1906}
1907
1908DEFUN ("set-terminal-local-value", Fset_terminal_local_value, Sset_terminal_local_value, 3, 3, 0,
1909 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
1910If VARIABLE is not a terminal-local variable, then set its normal
1911binding, like `set'.
1912
1913TERMINAL may be a terminal id, a frame, or nil (meaning the
1914selected frame's terminal device). */)
1915 (symbol, terminal, value)
1916 Lisp_Object symbol;
1917 Lisp_Object terminal;
1918 Lisp_Object value;
1919{
1920 Lisp_Object result;
1921 struct terminal *t = get_terminal (terminal, 1);
1922 push_kboard (d->kboard);
1923 result = Fset (symbol, value);
1924 pop_kboard ();
1925 return result;
1926}
1927#endif
1871 1928
1872/* Find the function at the end of a chain of symbol function indirections. */ 1929/* Find the function at the end of a chain of symbol function indirections. */
1873 1930
@@ -3327,6 +3384,10 @@ syms_of_data ()
3327 defsubr (&Slocal_variable_p); 3384 defsubr (&Slocal_variable_p);
3328 defsubr (&Slocal_variable_if_set_p); 3385 defsubr (&Slocal_variable_if_set_p);
3329 defsubr (&Svariable_binding_locus); 3386 defsubr (&Svariable_binding_locus);
3387#if 0 /* XXX Remove this. --lorentey */
3388 defsubr (&Sterminal_local_value);
3389 defsubr (&Sset_terminal_local_value);
3390#endif
3330 defsubr (&Saref); 3391 defsubr (&Saref);
3331 defsubr (&Saset); 3392 defsubr (&Saset);
3332 defsubr (&Snumber_to_string); 3393 defsubr (&Snumber_to_string);
diff --git a/src/dispextern.h b/src/dispextern.h
index 9e899f9ccb2..de9dadec6bc 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
@@ -2674,8 +2665,6 @@ void init_iterator_to_row_start P_ ((struct it *, struct window *,
2674 struct glyph_row *)); 2665 struct glyph_row *));
2675int get_next_display_element P_ ((struct it *)); 2666int get_next_display_element P_ ((struct it *));
2676void set_iterator_to_next P_ ((struct it *, int)); 2667void set_iterator_to_next P_ ((struct it *, int));
2677void produce_glyphs P_ ((struct it *));
2678void produce_special_glyphs P_ ((struct it *, enum display_element_type));
2679void start_display P_ ((struct it *, struct window *, struct text_pos)); 2668void start_display P_ ((struct it *, struct window *, struct text_pos));
2680void move_it_to P_ ((struct it *, int, int, int, int, int)); 2669void move_it_to P_ ((struct it *, int, int, int, int, int));
2681void move_it_vertically P_ ((struct it *, int)); 2670void move_it_vertically P_ ((struct it *, int));
@@ -2822,11 +2811,11 @@ int image_ascent P_ ((struct image *, struct face *, struct glyph_slice *));
2822 2811
2823/* Defined in sysdep.c */ 2812/* Defined in sysdep.c */
2824 2813
2825void get_frame_size P_ ((int *, int *)); 2814void get_tty_size P_ ((int, int *, int *));
2826void request_sigio P_ ((void)); 2815void request_sigio P_ ((void));
2827void unrequest_sigio P_ ((void)); 2816void unrequest_sigio P_ ((void));
2828int tabs_safe_p P_ ((void)); 2817int tabs_safe_p P_ ((int));
2829void init_baud_rate P_ ((void)); 2818void init_baud_rate P_ ((int));
2830void init_sigio P_ ((int)); 2819void init_sigio P_ ((int));
2831 2820
2832/* Defined in xfaces.c */ 2821/* Defined in xfaces.c */
@@ -2965,8 +2954,6 @@ void clear_glyph_row P_ ((struct glyph_row *));
2965void prepare_desired_row P_ ((struct glyph_row *)); 2954void prepare_desired_row P_ ((struct glyph_row *));
2966int line_hash_code P_ ((struct glyph_row *)); 2955int line_hash_code P_ ((struct glyph_row *));
2967void set_window_update_flags P_ ((struct window *, int)); 2956void set_window_update_flags P_ ((struct window *, int));
2968void write_glyphs P_ ((struct glyph *, int));
2969void insert_glyphs P_ ((struct glyph *, int));
2970void redraw_frame P_ ((struct frame *)); 2957void redraw_frame P_ ((struct frame *));
2971void redraw_garbaged_frames P_ ((void)); 2958void redraw_garbaged_frames P_ ((void));
2972int scroll_cost P_ ((struct frame *, int, int, int)); 2959int scroll_cost P_ ((struct frame *, int, int, int));
@@ -2983,31 +2970,44 @@ void syms_of_display P_ ((void));
2983extern Lisp_Object Qredisplay_dont_pause; 2970extern Lisp_Object Qredisplay_dont_pause;
2984GLYPH spec_glyph_lookup_face P_ ((struct window *, GLYPH)); 2971GLYPH spec_glyph_lookup_face P_ ((struct window *, GLYPH));
2985 2972
2986/* Defined in term.c */ 2973/* Defined in terminal.c */
2987 2974
2988extern void ring_bell P_ ((void)); 2975extern void ring_bell P_ ((struct frame *));
2989extern void set_terminal_modes P_ ((void));
2990extern void reset_terminal_modes P_ ((void));
2991extern void update_begin P_ ((struct frame *)); 2976extern void update_begin P_ ((struct frame *));
2992extern void update_end P_ ((struct frame *)); 2977extern void update_end P_ ((struct frame *));
2993extern void set_terminal_window P_ ((int)); 2978extern void set_terminal_window P_ ((struct frame *, int));
2994extern void set_scroll_region P_ ((int, int)); 2979extern void cursor_to P_ ((struct frame *, int, int));
2995extern void turn_off_insert P_ ((void)); 2980extern void raw_cursor_to P_ ((struct frame *, int, int));
2996extern void turn_off_highlight P_ ((void)); 2981extern void clear_to_end P_ ((struct frame *));
2997extern void background_highlight P_ ((void)); 2982extern void clear_frame P_ ((struct frame *));
2998extern void clear_frame P_ ((void)); 2983extern void clear_end_of_line P_ ((struct frame *, int));
2999extern void clear_end_of_line P_ ((int)); 2984extern void write_glyphs P_ ((struct frame *, struct glyph *, int));
3000extern void clear_end_of_line_raw P_ ((int)); 2985extern void insert_glyphs P_ ((struct frame *, struct glyph *, int));
3001extern void delete_glyphs P_ ((int)); 2986extern void delete_glyphs P_ ((struct frame *, int));
3002extern void ins_del_lines P_ ((int, int)); 2987extern void ins_del_lines P_ ((struct frame *, int, int));
2988
2989extern struct terminal *init_initial_terminal P_ ((void));
2990
2991
2992/* Defined in term.c */
2993
2994extern void tty_set_terminal_modes P_ ((struct terminal *));
2995extern void tty_reset_terminal_modes P_ ((struct terminal *));
2996extern void tty_turn_off_insert P_ ((struct tty_display_info *));
2997extern void tty_turn_off_highlight P_ ((struct tty_display_info *));
3003extern int string_cost P_ ((char *)); 2998extern int string_cost P_ ((char *));
3004extern int per_line_cost P_ ((char *)); 2999extern int per_line_cost P_ ((char *));
3005extern void calculate_costs P_ ((struct frame *)); 3000extern void calculate_costs P_ ((struct frame *));
3001extern void produce_glyphs P_ ((struct it *));
3002extern void produce_special_glyphs P_ ((struct it *, enum display_element_type));
3003extern int tty_capable_p P_ ((struct tty_display_info *, unsigned, unsigned long, unsigned long));
3006extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object)); 3004extern void set_tty_color_mode P_ ((struct frame *, Lisp_Object));
3007extern void tty_setup_colors P_ ((int)); 3005extern struct terminal *get_tty_terminal P_ ((Lisp_Object, int));
3008extern void term_init P_ ((char *)); 3006extern struct terminal *get_named_tty P_ ((char *));
3009void cursor_to P_ ((int, int)); 3007EXFUN (Ftty_type, 1);
3010extern int tty_capable_p P_ ((struct frame *, unsigned, unsigned long, unsigned long)); 3008extern void create_tty_output P_ ((struct frame *));
3009extern struct terminal *init_tty P_ ((char *, char *, int));
3010
3011 3011
3012/* Defined in scroll.c */ 3012/* Defined in scroll.c */
3013 3013
diff --git a/src/dispnew.c b/src/dispnew.c
index 1502ffd753c..7a80a8a618a 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 5dacafc9b3e..55475e57799 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;
@@ -1296,6 +1297,9 @@ main (argc, argv
1296 faces, and the face implementation uses some symbols as 1297 faces, and the face implementation uses some symbols as
1297 face names. */ 1298 face names. */
1298 syms_of_xfaces (); 1299 syms_of_xfaces ();
1300 /* XXX syms_of_keyboard uses some symbols in keymap.c. It would
1301 be better to arrange things not to have this dependency. */
1302 syms_of_keymap ();
1299 /* Call syms_of_keyboard before init_window_once because 1303 /* Call syms_of_keyboard before init_window_once because
1300 keyboard sets up symbols that include some face names that 1304 keyboard sets up symbols that include some face names that
1301 the X support will want to use. This can happen when 1305 the X support will want to use. This can happen when
@@ -1493,10 +1497,10 @@ main (argc, argv
1493 /* egetenv is a pretty low-level facility, which may get called in 1497 /* egetenv is a pretty low-level facility, which may get called in
1494 many circumstances; it seems flimsy to put off initializing it 1498 many circumstances; it seems flimsy to put off initializing it
1495 until calling init_callproc. */ 1499 until calling init_callproc. */
1496 set_process_environment (); 1500 set_initial_environment ();
1497 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4 1501 /* AIX crashes are reported in system versions 3.2.3 and 3.2.4
1498 if this is not done. Do it after set_process_environment so that we 1502 if this is not done. Do it after set_global_environment so that we
1499 don't pollute Vprocess_environment. */ 1503 don't pollute Vglobal_environment. */
1500 /* Setting LANG here will defeat the startup locale processing... */ 1504 /* Setting LANG here will defeat the startup locale processing... */
1501#ifdef AIX3_2 1505#ifdef AIX3_2
1502 putenv ("LANG=C"); 1506 putenv ("LANG=C");
@@ -1567,7 +1571,7 @@ main (argc, argv
1567#endif /* CLASH_DETECTION */ 1571#endif /* CLASH_DETECTION */
1568 syms_of_indent (); 1572 syms_of_indent ();
1569 syms_of_insdel (); 1573 syms_of_insdel ();
1570 syms_of_keymap (); 1574 /* syms_of_keymap (); */
1571 syms_of_macros (); 1575 syms_of_macros ();
1572 syms_of_marker (); 1576 syms_of_marker ();
1573 syms_of_minibuf (); 1577 syms_of_minibuf ();
@@ -1578,6 +1582,7 @@ main (argc, argv
1578 syms_of_frame (); 1582 syms_of_frame ();
1579#endif 1583#endif
1580 syms_of_syntax (); 1584 syms_of_syntax ();
1585 syms_of_terminal ();
1581 syms_of_term (); 1586 syms_of_term ();
1582 syms_of_undo (); 1587 syms_of_undo ();
1583#ifdef HAVE_SOUND 1588#ifdef HAVE_SOUND
@@ -1662,13 +1667,7 @@ main (argc, argv
1662#endif /* HAVE_NTGUI */ 1667#endif /* HAVE_NTGUI */
1663 } 1668 }
1664 1669
1665 if (!noninteractive) 1670 init_process (); /* init_display uses add_keyboard_wait_descriptor. */
1666 {
1667#ifdef VMS
1668 init_vms_input ();/* init_display calls get_frame_size, that needs this. */
1669#endif /* VMS */
1670 init_display (); /* Determine terminal type. init_sys_modes uses results. */
1671 }
1672#ifndef MAC_OS8 1671#ifndef MAC_OS8
1673 /* Called before init_window_once for Mac OS Classic. */ 1672 /* Called before init_window_once for Mac OS Classic. */
1674 init_keyboard (); /* This too must precede init_sys_modes. */ 1673 init_keyboard (); /* This too must precede init_sys_modes. */
@@ -1676,7 +1675,13 @@ main (argc, argv
1676#ifdef VMS 1675#ifdef VMS
1677 init_vmsproc (); /* And this too. */ 1676 init_vmsproc (); /* And this too. */
1678#endif /* VMS */ 1677#endif /* VMS */
1679 init_sys_modes (); /* Init system terminal modes (RAW or CBREAK, etc.). */ 1678 if (!noninteractive)
1679 {
1680#ifdef VMS
1681 init_vms_input ();/* init_display calls get_tty_size, that needs this. */
1682#endif /* VMS */
1683 init_display (); /* Determine terminal type. Calls init_sys_modes. */
1684 }
1680 init_fns (); 1685 init_fns ();
1681 init_xdisp (); 1686 init_xdisp ();
1682#ifdef HAVE_WINDOW_SYSTEM 1687#ifdef HAVE_WINDOW_SYSTEM
@@ -1689,7 +1694,6 @@ main (argc, argv
1689#ifdef VMS 1694#ifdef VMS
1690 init_vmsfns (); 1695 init_vmsfns ();
1691#endif /* VMS */ 1696#endif /* VMS */
1692 init_process ();
1693#ifdef HAVE_SOUND 1697#ifdef HAVE_SOUND
1694 init_sound (); 1698 init_sound ();
1695#endif 1699#endif
@@ -2102,15 +2106,14 @@ shut_down_emacs (sig, no_x, stuff)
2102 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 2106 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1
2103 && tpgrp == pgrp) 2107 && tpgrp == pgrp)
2104 { 2108 {
2105 fflush (stdout); 2109 reset_all_sys_modes ();
2106 reset_sys_modes ();
2107 if (sig && sig != SIGTERM) 2110 if (sig && sig != SIGTERM)
2108 fprintf (stderr, "Fatal error (%d)", sig); 2111 fprintf (stderr, "Fatal error (%d)", sig);
2109 } 2112 }
2110 } 2113 }
2111#else 2114#else
2112 fflush (stdout); 2115 fflush (stdout);
2113 reset_sys_modes (); 2116 reset_all_sys_modes ();
2114#endif 2117#endif
2115 2118
2116 stuff_buffered_input (stuff); 2119 stuff_buffered_input (stuff);
@@ -2132,9 +2135,9 @@ shut_down_emacs (sig, no_x, stuff)
2132#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */ 2135#if 0 /* This triggers a bug in XCloseDisplay and is not needed. */
2133#ifdef HAVE_X_WINDOWS 2136#ifdef HAVE_X_WINDOWS
2134 /* It's not safe to call intern here. Maybe we are crashing. */ 2137 /* It's not safe to call intern here. Maybe we are crashing. */
2135 if (!noninteractive && SYMBOLP (Vwindow_system) 2138 if (!noninteractive && SYMBOLP (Vinitial_window_system)
2136 && SCHARS (SYMBOL_NAME (Vwindow_system)) == 1 2139 && SCHARS (SYMBOL_NAME (Vinitial_window_system)) == 1
2137 && SREF (SYMBOL_NAME (Vwindow_system), 0) == 'x' 2140 && SREF (SYMBOL_NAME (Vinitial_window_system), 0) == 'x'
2138 && ! no_x) 2141 && ! no_x)
2139 Fx_close_current_connection (); 2142 Fx_close_current_connection ();
2140#endif /* HAVE_X_WINDOWS */ 2143#endif /* HAVE_X_WINDOWS */
diff --git a/src/eval.c b/src/eval.c
index 20be847f273..830476a61bc 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1280,8 +1280,12 @@ unwind_to_catch (catch, value)
1280#if HAVE_X_WINDOWS 1280#if HAVE_X_WINDOWS
1281 /* If x_catch_errors was done, turn it off now. 1281 /* If x_catch_errors was done, turn it off now.
1282 (First we give unbind_to a chance to do that.) */ 1282 (First we give unbind_to a chance to do that.) */
1283#if 0 /* This would disable x_catch_errors after x_connection_closed.
1284 * The catch must remain in effect during that delicate
1285 * state. --lorentey */
1283 x_fully_uncatch_errors (); 1286 x_fully_uncatch_errors ();
1284#endif 1287#endif
1288#endif
1285 1289
1286 byte_stack_list = catch->byte_stack; 1290 byte_stack_list = catch->byte_stack;
1287 gcprolist = catch->gcpro; 1291 gcprolist = catch->gcpro;
@@ -1458,10 +1462,12 @@ internal_condition_case (bfun, handlers, hfun)
1458 1462
1459 /* Since Fsignal will close off all calls to x_catch_errors, 1463 /* Since Fsignal will close off all calls to x_catch_errors,
1460 we will get the wrong results if some are not closed now. */ 1464 we will get the wrong results if some are not closed now. */
1465#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1461#if HAVE_X_WINDOWS 1466#if HAVE_X_WINDOWS
1462 if (x_catching_errors ()) 1467 if (x_catching_errors ())
1463 abort (); 1468 abort ();
1464#endif 1469#endif
1470#endif
1465 1471
1466 c.tag = Qnil; 1472 c.tag = Qnil;
1467 c.val = Qnil; 1473 c.val = Qnil;
@@ -1506,10 +1512,12 @@ internal_condition_case_1 (bfun, arg, handlers, hfun)
1506 1512
1507 /* Since Fsignal will close off all calls to x_catch_errors, 1513 /* Since Fsignal will close off all calls to x_catch_errors,
1508 we will get the wrong results if some are not closed now. */ 1514 we will get the wrong results if some are not closed now. */
1515#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1509#if HAVE_X_WINDOWS 1516#if HAVE_X_WINDOWS
1510 if (x_catching_errors ()) 1517 if (x_catching_errors ())
1511 abort (); 1518 abort ();
1512#endif 1519#endif
1520#endif
1513 1521
1514 c.tag = Qnil; 1522 c.tag = Qnil;
1515 c.val = Qnil; 1523 c.val = Qnil;
@@ -1557,10 +1565,12 @@ internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1557 1565
1558 /* Since Fsignal will close off all calls to x_catch_errors, 1566 /* Since Fsignal will close off all calls to x_catch_errors,
1559 we will get the wrong results if some are not closed now. */ 1567 we will get the wrong results if some are not closed now. */
1568#if 0 /* Fsignal doesn't do that anymore. --lorentey */
1560#if HAVE_X_WINDOWS 1569#if HAVE_X_WINDOWS
1561 if (x_catching_errors ()) 1570 if (x_catching_errors ())
1562 abort (); 1571 abort ();
1563#endif 1572#endif
1573#endif
1564 1574
1565 c.tag = Qnil; 1575 c.tag = Qnil;
1566 c.val = Qnil; 1576 c.val = Qnil;
diff --git a/src/fileio.c b/src/fileio.c
index 62331122a24..2a0e93ebe18 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
@@ -5825,7 +5827,7 @@ auto_save_error (error)
5825 char *msgbuf; 5827 char *msgbuf;
5826 USE_SAFE_ALLOCA; 5828 USE_SAFE_ALLOCA;
5827 5829
5828 ring_bell (); 5830 ring_bell (XFRAME (selected_frame));
5829 5831
5830 args[0] = build_string ("Auto-saving %s: %s"); 5832 args[0] = build_string ("Auto-saving %s: %s");
5831 args[1] = current_buffer->name; 5833 args[1] = current_buffer->name;
@@ -6387,7 +6389,7 @@ and `read-file-name-function'. */)
6387 /* If dir starts with user's homedir, change that to ~. */ 6389 /* If dir starts with user's homedir, change that to ~. */
6388 homedir = (char *) egetenv ("HOME"); 6390 homedir = (char *) egetenv ("HOME");
6389#ifdef DOS_NT 6391#ifdef DOS_NT
6390 /* homedir can be NULL in temacs, since Vprocess_environment is not 6392 /* homedir can be NULL in temacs, since Vglobal_environment is not
6391 yet set up. We shouldn't crash in that case. */ 6393 yet set up. We shouldn't crash in that case. */
6392 if (homedir != 0) 6394 if (homedir != 0)
6393 { 6395 {
diff --git a/src/fns.c b/src/fns.c
index eef67551b48..d37b9d2c281 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 9056e2da6ec..1d6e73517b6 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 b29e20ab0ca..091abfdbf31 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,19 @@ 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;
114Lisp_Object Qterm_environment_variable;
115Lisp_Object Qdisplay_environment_variable;
108 116
109Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth; 117Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
110 118
111Lisp_Object Qinhibit_face_set_after_frame_default; 119Lisp_Object Qinhibit_face_set_after_frame_default;
112Lisp_Object Qface_set_after_frame_default; 120Lisp_Object Qface_set_after_frame_default;
113 121
114
115Lisp_Object Vterminal_frame; 122Lisp_Object Vterminal_frame;
116Lisp_Object Vdefault_frame_alist; 123Lisp_Object Vdefault_frame_alist;
117Lisp_Object Vdefault_frame_scroll_bars; 124Lisp_Object Vdefault_frame_scroll_bars;
@@ -121,8 +128,8 @@ Lisp_Object Vdelete_frame_functions;
121 128
122static void 129static void
123set_menu_bar_lines_1 (window, n) 130set_menu_bar_lines_1 (window, n)
124 Lisp_Object window; 131 Lisp_Object window;
125 int n; 132 int n;
126{ 133{
127 struct window *w = XWINDOW (window); 134 struct window *w = XWINDOW (window);
128 135
@@ -180,8 +187,6 @@ set_menu_bar_lines (f, value, oldval)
180Lisp_Object Vemacs_iconified; 187Lisp_Object Vemacs_iconified;
181Lisp_Object Vframe_list; 188Lisp_Object Vframe_list;
182 189
183struct x_output tty_display;
184
185extern Lisp_Object Vminibuffer_list; 190extern Lisp_Object Vminibuffer_list;
186extern Lisp_Object get_minibuffer (); 191extern Lisp_Object get_minibuffer ();
187extern Lisp_Object Fhandle_switch_frame (); 192extern Lisp_Object Fhandle_switch_frame ();
@@ -203,6 +208,7 @@ See also `frame-live-p'. */)
203 return Qnil; 208 return Qnil;
204 switch (XFRAME (object)->output_method) 209 switch (XFRAME (object)->output_method)
205 { 210 {
211 case output_initial: /* The initial frame is like a termcap frame. */
206 case output_termcap: 212 case output_termcap:
207 return Qt; 213 return Qt;
208 case output_x_window: 214 case output_x_window:
@@ -221,7 +227,7 @@ See also `frame-live-p'. */)
221DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0, 227DEFUN ("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. 228 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 229Value 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 230frame, the return value indicates what sort of terminal device it is
225displayed on. See the documentation of `framep' for possible 231displayed on. See the documentation of `framep' for possible
226return values. */) 232return values. */)
227 (object) 233 (object)
@@ -233,6 +239,30 @@ return values. */)
233 : Qnil); 239 : Qnil);
234} 240}
235 241
242DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
243 doc: /* The name of the window system that FRAME is displaying through.
244The value is a symbol---for instance, 'x' for X windows.
245The value is nil if Emacs is using a text-only terminal.
246
247FRAME defaults to the currently selected frame. */)
248 (frame)
249 Lisp_Object frame;
250{
251 Lisp_Object type;
252 if (NILP (frame))
253 frame = selected_frame;
254
255 type = Fframep (frame);
256
257 if (NILP (type))
258 wrong_type_argument (Qframep, frame);
259
260 if (EQ (type, Qt))
261 return Qnil;
262 else
263 return type;
264}
265
236struct frame * 266struct frame *
237make_frame (mini_p) 267make_frame (mini_p)
238 int mini_p; 268 int mini_p;
@@ -276,9 +306,7 @@ make_frame (mini_p)
276 f->menu_bar_items_used = 0; 306 f->menu_bar_items_used = 0;
277 f->buffer_predicate = Qnil; 307 f->buffer_predicate = Qnil;
278 f->buffer_list = Qnil; 308 f->buffer_list = Qnil;
279#ifdef MULTI_KBOARD 309 f->buried_buffer_list = Qnil;
280 f->kboard = initial_kboard;
281#endif
282 f->namebuf = 0; 310 f->namebuf = 0;
283 f->title = Qnil; 311 f->title = Qnil;
284 f->menu_bar_window = Qnil; 312 f->menu_bar_window = Qnil;
@@ -398,8 +426,8 @@ make_frame_without_minibuffer (mini_window, kb, display)
398 426
399#ifdef MULTI_KBOARD 427#ifdef MULTI_KBOARD
400 if (!NILP (mini_window) 428 if (!NILP (mini_window)
401 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb) 429 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
402 error ("Frame and minibuffer must be on the same display"); 430 error ("Frame and minibuffer must be on the same terminal");
403#endif 431#endif
404 432
405 /* Make a frame containing just a root window. */ 433 /* Make a frame containing just a root window. */
@@ -475,18 +503,19 @@ make_minibuffer_frame ()
475} 503}
476#endif /* HAVE_WINDOW_SYSTEM */ 504#endif /* HAVE_WINDOW_SYSTEM */
477 505
478/* Construct a frame that refers to the terminal (stdin and stdout). */ 506/* Construct a frame that refers to a terminal. */
479 507
480static int terminal_frame_count; 508static int tty_frame_count;
481 509
482struct frame * 510struct frame *
483make_terminal_frame () 511make_initial_frame (void)
484{ 512{
485 register struct frame *f; 513 struct frame *f;
514 struct terminal *terminal;
486 Lisp_Object frame; 515 Lisp_Object frame;
487 char name[20];
488 516
489#ifdef MULTI_KBOARD 517#ifdef MULTI_KBOARD
518 /* Create the initial keyboard. */
490 if (!initial_kboard) 519 if (!initial_kboard)
491 { 520 {
492 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); 521 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
@@ -500,13 +529,51 @@ make_terminal_frame ()
500 if (! (NILP (Vframe_list) || CONSP (Vframe_list))) 529 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
501 Vframe_list = Qnil; 530 Vframe_list = Qnil;
502 531
532 terminal = init_initial_terminal ();
533
534 f = make_frame (1);
535 XSETFRAME (frame, f);
536
537 Vframe_list = Fcons (frame, Vframe_list);
538
539 tty_frame_count = 1;
540 f->name = build_string ("F1");
541
542 f->visible = 1;
543 f->async_visible = 1;
544
545 f->output_method = terminal->type;
546 f->terminal = terminal;
547 f->terminal->reference_count++;
548 f->output_data.nothing = 0;
549
550 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
551 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
552
553 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
554 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
555
556 return f;
557}
558
559
560struct frame *
561make_terminal_frame (struct terminal *terminal)
562{
563 register struct frame *f;
564 Lisp_Object frame;
565 char name[20];
566
567 if (terminal->deleted)
568 error ("Terminal is being deleted, can't create new frames on it");
569
503 f = make_frame (1); 570 f = make_frame (1);
504 571
505 XSETFRAME (frame, f); 572 XSETFRAME (frame, f);
506 Vframe_list = Fcons (frame, Vframe_list); 573 Vframe_list = Fcons (frame, Vframe_list);
507 574
508 terminal_frame_count++; 575 tty_frame_count++;
509 sprintf (name, "F%d", terminal_frame_count); 576 sprintf (name, "F%d", tty_frame_count);
510 f->name = build_string (name); 577 f->name = build_string (name);
511 578
512 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */ 579 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
@@ -526,11 +593,11 @@ make_terminal_frame ()
526 for the black color. Other frames all inherit their pixels 593 for the black color. Other frames all inherit their pixels
527 from what's already in the_only_x_display. */ 594 from what's already in the_only_x_display. */
528 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))) 595 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
529 && f->output_data.x->background_pixel == 0 596 && FRAME_BACKGROUND_PIXEL (f) == 0
530 && f->output_data.x->foreground_pixel == 0) 597 && FRAME_FOREGROUND_PIXEL (f) == 0)
531 { 598 {
532 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR; 599 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
533 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR; 600 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
534 } 601 }
535 } 602 }
536 else 603 else
@@ -538,12 +605,33 @@ make_terminal_frame ()
538#else 605#else
539#ifdef WINDOWSNT 606#ifdef WINDOWSNT
540 f->output_method = output_termcap; 607 f->output_method = output_termcap;
541 f->output_data.x = &tty_display; 608 f->terminal = terminal;
609 f->terminal->reference_count++;
610 create_w32cons_output (f);
542#else 611#else
543#ifdef MAC_OS8 612#ifdef MAC_OS8
544 make_mac_terminal_frame (f); 613 make_mac_terminal_frame (f);
545#else 614#else
546 f->output_data.x = &tty_display; 615 {
616 f->output_method = output_termcap;
617 f->terminal = terminal;
618 f->terminal->reference_count++;
619 create_tty_output (f);
620
621 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
622 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
623
624 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
625 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
626
627 /* Set the top frame to the newly created frame. */
628 if (FRAME_TTY (f)->top_frame
629 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
630 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
631
632 FRAME_TTY (f)->top_frame = frame;
633 }
634
547#ifdef CANNOT_DUMP 635#ifdef CANNOT_DUMP
548 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR; 636 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
549 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR; 637 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
@@ -558,18 +646,55 @@ make_terminal_frame ()
558 return f; 646 return f;
559} 647}
560 648
649/* Get a suitable value for frame parameter PARAMETER for a newly
650 created frame, based on (1) the user-supplied frame parameter
651 alist SUPPLIED_PARMS, (2) CURRENT_VALUE, and finally, if all else
652 fails, (3) Vdefault_frame_alist. */
653
654static Lisp_Object
655get_future_frame_param (Lisp_Object parameter,
656 Lisp_Object supplied_parms,
657 char *current_value)
658{
659 Lisp_Object result;
660
661 result = Fassq (parameter, supplied_parms);
662 if (NILP (result))
663 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
664 if (NILP (result) && current_value != NULL)
665 result = build_string (current_value);
666 if (NILP (result))
667 result = Fassq (parameter, Vdefault_frame_alist);
668 if (!NILP (result) && !STRINGP (result))
669 result = XCDR (result);
670 if (NILP (result) || !STRINGP (result))
671 result = Qnil;
672
673 return result;
674}
675
561DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame, 676DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
562 1, 1, 0, 677 1, 1, 0,
563 doc: /* Create an additional terminal frame. 678 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. 679This function takes one argument, an alist specifying frame parameters.
567In practice, generally you don't need to specify any parameters. 680
568Note that changing the size of one terminal frame automatically affects all. */) 681You can create multiple frames on a single text-only terminal, but
682only one of them (the selected terminal frame) is actually displayed.
683
684In practice, generally you don't need to specify any parameters,
685except when you want to create a new frame on another terminal.
686In that case, the `tty' parameter specifies the device file to open,
687and the `tty-type' parameter specifies the terminal type. Example:
688
689 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
690
691Note that changing the size of one terminal frame automatically
692affects all frames on the same terminal device. */)
569 (parms) 693 (parms)
570 Lisp_Object parms; 694 Lisp_Object parms;
571{ 695{
572 struct frame *f; 696 struct frame *f;
697 struct terminal *t = NULL;
573 Lisp_Object frame, tem; 698 Lisp_Object frame, tem;
574 struct frame *sf = SELECTED_FRAME (); 699 struct frame *sf = SELECTED_FRAME ();
575 700
@@ -579,25 +704,84 @@ Note that changing the size of one terminal frame automatically affects all. */
579 abort (); 704 abort ();
580#else /* not MSDOS */ 705#else /* not MSDOS */
581 706
582#ifdef MAC_OS 707#if 0 /* #ifdef MAC_OS */
708 /* This can happen for multi-tty when using both terminal frames and
709 Carbon frames. */
583 if (sf->output_method != output_mac) 710 if (sf->output_method != output_mac)
584 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame"); 711 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
585#else 712#else
713#if 0 /* This should work now! */
586 if (sf->output_method != output_termcap) 714 if (sf->output_method != output_termcap)
587 error ("Not using an ASCII terminal now; cannot make a new ASCII frame"); 715 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
588#endif 716#endif
717#endif
589#endif /* not MSDOS */ 718#endif /* not MSDOS */
719
720 {
721 Lisp_Object terminal;
722
723 terminal = Fassq (Qterminal, parms);
724 if (!NILP (terminal))
725 {
726 terminal = XCDR (terminal);
727 t = get_terminal (terminal, 1);
728 }
729 }
730
731 if (!t)
732 {
733 char *name = 0, *type = 0;
734 Lisp_Object tty, tty_type;
735
736 tty = get_future_frame_param
737 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
738 ? FRAME_TTY (XFRAME (selected_frame))->name
739 : NULL));
740 if (!NILP (tty))
741 {
742 name = (char *) alloca (SBYTES (tty) + 1);
743 strncpy (name, SDATA (tty), SBYTES (tty));
744 name[SBYTES (tty)] = 0;
745 }
746
747 tty_type = get_future_frame_param
748 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
749 ? FRAME_TTY (XFRAME (selected_frame))->type
750 : NULL));
751 if (!NILP (tty_type))
752 {
753 type = (char *) alloca (SBYTES (tty_type) + 1);
754 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
755 type[SBYTES (tty_type)] = 0;
756 }
757
758 t = init_tty (name, type, 0); /* Errors are not fatal. */
759 }
590 760
591 f = make_terminal_frame (); 761 f = make_terminal_frame (t);
592 762
593 change_frame_size (f, FRAME_LINES (sf), 763 {
594 FRAME_COLS (sf), 0, 0, 0); 764 int width, height;
765 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
766 change_frame_size (f, height, width, 0, 0, 0);
767 }
768
595 adjust_glyphs (f); 769 adjust_glyphs (f);
596 calculate_costs (f); 770 calculate_costs (f);
597 XSETFRAME (frame, f); 771 XSETFRAME (frame, f);
598 Fmodify_frame_parameters (frame, Vdefault_frame_alist); 772 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
599 Fmodify_frame_parameters (frame, parms); 773 Fmodify_frame_parameters (frame, parms);
600 774 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
775 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
776 build_string (t->display_info.tty->type)),
777 Qnil));
778 if (t->display_info.tty->name != NULL)
779 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
780 build_string (t->display_info.tty->name)),
781 Qnil));
782 else
783 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
784
601 /* Make the frame face alist be frame-specific, so that each 785 /* Make the frame face alist be frame-specific, so that each
602 frame could change its face definitions independently. */ 786 frame could change its face definitions independently. */
603 f->face_alist = Fcopy_alist (sf->face_alist); 787 f->face_alist = Fcopy_alist (sf->face_alist);
@@ -620,7 +804,7 @@ Note that changing the size of one terminal frame automatically affects all. */
620 frame's focus to FRAME instead. 804 frame's focus to FRAME instead.
621 805
622 FOR_DELETION non-zero means that the selected frame is being 806 FOR_DELETION non-zero means that the selected frame is being
623 deleted, which includes the possibility that the frame's display 807 deleted, which includes the possibility that the frame's terminal
624 is dead. */ 808 is dead. */
625 809
626Lisp_Object 810Lisp_Object
@@ -695,6 +879,15 @@ do_switch_frame (frame, track, for_deletion)
695 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf)) 879 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
696 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1); 880 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
697 881
882 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
883 && FRAME_TERMCAP_P (XFRAME (frame))
884 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
885 {
886 XFRAME (selected_frame)->async_visible = 2; /* obscured */
887 XFRAME (frame)->async_visible = 1;
888 FRAME_TTY (XFRAME (frame))->top_frame = frame;
889 }
890
698 selected_frame = frame; 891 selected_frame = frame;
699 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) 892 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
700 last_nonminibuf_frame = XFRAME (selected_frame); 893 last_nonminibuf_frame = XFRAME (selected_frame);
@@ -878,6 +1071,7 @@ If FRAME is the selected frame, this makes WINDOW the selected window. */)
878 1071
879 return XFRAME (frame)->selected_window = window; 1072 return XFRAME (frame)->selected_window = window;
880} 1073}
1074
881 1075
882DEFUN ("frame-list", Fframe_list, Sframe_list, 1076DEFUN ("frame-list", Fframe_list, Sframe_list,
883 0, 0, 0, 1077 0, 0, 0,
@@ -925,7 +1119,10 @@ next_frame (frame, minibuf)
925 f = XCAR (tail); 1119 f = XCAR (tail);
926 1120
927 if (passed 1121 if (passed
928 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) 1122 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1123 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1124 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1125 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
929 { 1126 {
930 /* Decide whether this frame is eligible to be returned. */ 1127 /* Decide whether this frame is eligible to be returned. */
931 1128
@@ -1002,7 +1199,10 @@ prev_frame (frame, minibuf)
1002 if (EQ (frame, f) && !NILP (prev)) 1199 if (EQ (frame, f) && !NILP (prev))
1003 return prev; 1200 return prev;
1004 1201
1005 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame))) 1202 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1203 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1204 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1205 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1006 { 1206 {
1007 /* Decide whether this frame is eligible to be returned, 1207 /* Decide whether this frame is eligible to be returned,
1008 according to minibuf. */ 1208 according to minibuf. */
@@ -1136,6 +1336,14 @@ other_visible_frames (f)
1136 return 1; 1336 return 1;
1137} 1337}
1138 1338
1339/* Error handler for `delete-frame-functions'. */
1340static Lisp_Object
1341delete_frame_handler (Lisp_Object arg)
1342{
1343 add_to_log ("Error during `delete-frame': %s", arg, Qnil);
1344 return Qnil;
1345}
1346
1139DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", 1347DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1140 doc: /* Delete FRAME, permanently eliminating it from use. 1348 doc: /* Delete FRAME, permanently eliminating it from use.
1141If omitted, FRAME defaults to the selected frame. 1349If omitted, FRAME defaults to the selected frame.
@@ -1151,6 +1359,8 @@ The functions are run with one arg, the frame to be deleted. */)
1151{ 1359{
1152 struct frame *f; 1360 struct frame *f;
1153 struct frame *sf = SELECTED_FRAME (); 1361 struct frame *sf = SELECTED_FRAME ();
1362 struct kboard *kb;
1363
1154 int minibuffer_selected; 1364 int minibuffer_selected;
1155 1365
1156 if (EQ (frame, Qnil)) 1366 if (EQ (frame, Qnil))
@@ -1209,11 +1419,22 @@ The functions are run with one arg, the frame to be deleted. */)
1209 && NILP (Fframe_parameter (frame, intern ("tooltip")))) 1419 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1210 { 1420 {
1211 Lisp_Object args[2]; 1421 Lisp_Object args[2];
1422 struct gcpro gcpro1, gcpro2;
1423
1424 /* Don't let a rogue function in `delete-frame-functions'
1425 prevent the frame deletion. */
1426 GCPRO2 (args[0], args[1]);
1212 args[0] = intern ("delete-frame-functions"); 1427 args[0] = intern ("delete-frame-functions");
1213 args[1] = frame; 1428 args[1] = frame;
1214 Frun_hook_with_args (2, args); 1429 internal_condition_case_2 (Frun_hook_with_args, 2, args,
1430 Qt, delete_frame_handler);
1431 UNGCPRO;
1215 } 1432 }
1216 1433
1434 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1435 if (! FRAME_LIVE_P (f))
1436 return Qnil;
1437
1217 minibuffer_selected = EQ (minibuf_window, selected_window); 1438 minibuffer_selected = EQ (minibuf_window, selected_window);
1218 1439
1219 /* Don't let the frame remain selected. */ 1440 /* Don't let the frame remain selected. */
@@ -1229,7 +1450,7 @@ The functions are run with one arg, the frame to be deleted. */)
1229 { 1450 {
1230 FOR_EACH_FRAME (tail, frame1) 1451 FOR_EACH_FRAME (tail, frame1)
1231 { 1452 {
1232 if (! EQ (frame, frame1)) 1453 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1233 break; 1454 break;
1234 } 1455 }
1235 } 1456 }
@@ -1255,6 +1476,24 @@ The functions are run with one arg, the frame to be deleted. */)
1255 if (EQ (f->minibuffer_window, echo_area_window)) 1476 if (EQ (f->minibuffer_window, echo_area_window))
1256 echo_area_window = sf->minibuffer_window; 1477 echo_area_window = sf->minibuffer_window;
1257 1478
1479 /* Don't allow other frames to refer to a deleted frame in their
1480 'environment parameter. */
1481 {
1482 Lisp_Object tail, frame1;
1483 Lisp_Object env = get_frame_param (XFRAME (frame), Qenvironment);
1484 FOR_EACH_FRAME (tail, frame1)
1485 {
1486 if (EQ (frame, frame1) || !FRAME_LIVE_P (XFRAME (frame1)))
1487 continue;
1488 if (EQ (frame, get_frame_param (XFRAME (frame1), Qenvironment)))
1489 {
1490 store_frame_param (XFRAME (frame1), Qenvironment, env);
1491 if (!FRAMEP (env))
1492 env = frame1;
1493 }
1494 }
1495 }
1496
1258 /* Clear any X selections for this frame. */ 1497 /* Clear any X selections for this frame. */
1259#ifdef HAVE_X_WINDOWS 1498#ifdef HAVE_X_WINDOWS
1260 if (FRAME_X_P (f)) 1499 if (FRAME_X_P (f))
@@ -1295,18 +1534,36 @@ The functions are run with one arg, the frame to be deleted. */)
1295 xfree (FRAME_MESSAGE_BUF (f)); 1534 xfree (FRAME_MESSAGE_BUF (f));
1296 1535
1297 /* Since some events are handled at the interrupt level, we may get 1536 /* 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 1537 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 1538 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 1539 promise that the terminal of the frame must be valid until we
1301 called the window-system-dependent frame destruction routine. */ 1540 have called the window-system-dependent frame destruction
1541 routine. */
1302 1542
1303 /* I think this should be done with a hook. */ 1543 if (FRAME_TERMINAL (f)->delete_frame_hook)
1304#ifdef HAVE_WINDOW_SYSTEM 1544 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1305 if (FRAME_WINDOW_P (f))
1306 x_destroy_window (f);
1307#endif
1308 1545
1309 f->output_data.nothing = 0; 1546 {
1547 struct terminal *terminal = FRAME_TERMINAL (f);
1548 f->output_data.nothing = 0;
1549 f->terminal = 0; /* Now the frame is dead. */
1550
1551 /* If needed, delete the terminal that this frame was on.
1552 (This must be done after the frame is killed.) */
1553 terminal->reference_count--;
1554 if (terminal->reference_count == 0)
1555 {
1556 kb = NULL;
1557 if (terminal->delete_terminal_hook)
1558 (*terminal->delete_terminal_hook) (terminal);
1559 else
1560 delete_terminal (terminal);
1561 }
1562#ifdef MULTI_KBOARD
1563 else
1564 kb = terminal->kboard;
1565#endif
1566 }
1310 1567
1311 /* If we've deleted the last_nonminibuf_frame, then try to find 1568 /* If we've deleted the last_nonminibuf_frame, then try to find
1312 another one. */ 1569 another one. */
@@ -1331,38 +1588,39 @@ The functions are run with one arg, the frame to be deleted. */)
1331 1588
1332 /* If there's no other frame on the same kboard, get out of 1589 /* 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. */ 1590 single-kboard state if we're in it for this kboard. */
1334 { 1591 if (kb != NULL)
1335 Lisp_Object frames; 1592 {
1336 /* Some frame we found on the same kboard, or nil if there are none. */ 1593 Lisp_Object frames;
1337 Lisp_Object frame_on_same_kboard; 1594 /* Some frame we found on the same kboard, or nil if there are none. */
1595 Lisp_Object frame_on_same_kboard;
1338 1596
1339 frame_on_same_kboard = Qnil; 1597 frame_on_same_kboard = Qnil;
1340 1598
1341 for (frames = Vframe_list; 1599 for (frames = Vframe_list;
1342 CONSP (frames); 1600 CONSP (frames);
1343 frames = XCDR (frames)) 1601 frames = XCDR (frames))
1344 { 1602 {
1345 Lisp_Object this; 1603 Lisp_Object this;
1346 struct frame *f1; 1604 struct frame *f1;
1347 1605
1348 this = XCAR (frames); 1606 this = XCAR (frames);
1349 if (!FRAMEP (this)) 1607 if (!FRAMEP (this))
1350 abort (); 1608 abort ();
1351 f1 = XFRAME (this); 1609 f1 = XFRAME (this);
1352 1610
1353 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)) 1611 if (kb == FRAME_KBOARD (f1))
1354 frame_on_same_kboard = this; 1612 frame_on_same_kboard = this;
1355 } 1613 }
1356 1614
1357 if (NILP (frame_on_same_kboard)) 1615 if (NILP (frame_on_same_kboard))
1358 not_single_kboard_state (FRAME_KBOARD (f)); 1616 not_single_kboard_state (kb);
1359 } 1617 }
1360 1618
1361 1619
1362 /* If we've deleted this keyboard's default_minibuffer_frame, try to 1620 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1363 find another one. Prefer minibuffer-only frames, but also notice 1621 find another one. Prefer minibuffer-only frames, but also notice
1364 frames with other windows. */ 1622 frames with other windows. */
1365 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame)) 1623 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1366 { 1624 {
1367 Lisp_Object frames; 1625 Lisp_Object frames;
1368 1626
@@ -1388,7 +1646,7 @@ The functions are run with one arg, the frame to be deleted. */)
1388 1646
1389 /* Consider only frames on the same kboard 1647 /* Consider only frames on the same kboard
1390 and only those with minibuffers. */ 1648 and only those with minibuffers. */
1391 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1) 1649 if (kb == FRAME_KBOARD (f1)
1392 && FRAME_HAS_MINIBUF_P (f1)) 1650 && FRAME_HAS_MINIBUF_P (f1))
1393 { 1651 {
1394 frame_with_minibuf = this; 1652 frame_with_minibuf = this;
@@ -1396,7 +1654,7 @@ The functions are run with one arg, the frame to be deleted. */)
1396 break; 1654 break;
1397 } 1655 }
1398 1656
1399 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)) 1657 if (kb == FRAME_KBOARD (f1))
1400 frame_on_same_kboard = this; 1658 frame_on_same_kboard = this;
1401 } 1659 }
1402 1660
@@ -1411,11 +1669,11 @@ The functions are run with one arg, the frame to be deleted. */)
1411 if (NILP (frame_with_minibuf)) 1669 if (NILP (frame_with_minibuf))
1412 abort (); 1670 abort ();
1413 1671
1414 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf; 1672 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1415 } 1673 }
1416 else 1674 else
1417 /* No frames left on this kboard--say no minibuffer either. */ 1675 /* No frames left on this kboard--say no minibuffer either. */
1418 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil; 1676 kb->Vdefault_minibuffer_frame = Qnil;
1419 } 1677 }
1420 1678
1421 /* Cause frame titles to update--necessary if we now have just one frame. */ 1679 /* Cause frame titles to update--necessary if we now have just one frame. */
@@ -1452,11 +1710,11 @@ and returns whatever that function returns. */)
1452 1710
1453#if defined (HAVE_MOUSE) || defined (HAVE_GPM) 1711#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1454 /* It's okay for the hook to refrain from storing anything. */ 1712 /* It's okay for the hook to refrain from storing anything. */
1455 if (mouse_position_hook) 1713 if (FRAME_TERMINAL (f)->mouse_position_hook)
1456 (*mouse_position_hook) (&f, -1, 1714 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1457 &lispy_dummy, &party_dummy, 1715 &lispy_dummy, &party_dummy,
1458 &x, &y, 1716 &x, &y,
1459 &long_dummy); 1717 &long_dummy);
1460 if (! NILP (x)) 1718 if (! NILP (x))
1461 { 1719 {
1462 col = XINT (x); 1720 col = XINT (x);
@@ -1496,11 +1754,11 @@ and nil for X and Y. */)
1496 1754
1497#if defined (HAVE_MOUSE) || defined (HAVE_GPM) 1755#if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1498 /* It's okay for the hook to refrain from storing anything. */ 1756 /* It's okay for the hook to refrain from storing anything. */
1499 if (mouse_position_hook) 1757 if (FRAME_TERMINAL (f)->mouse_position_hook)
1500 (*mouse_position_hook) (&f, -1, 1758 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1501 &lispy_dummy, &party_dummy, 1759 &lispy_dummy, &party_dummy,
1502 &x, &y, 1760 &x, &y,
1503 &long_dummy); 1761 &long_dummy);
1504#endif 1762#endif
1505 XSETFRAME (lispy_dummy, f); 1763 XSETFRAME (lispy_dummy, f);
1506 return Fcons (lispy_dummy, Fcons (x, y)); 1764 return Fcons (lispy_dummy, Fcons (x, y));
@@ -1787,16 +2045,19 @@ doesn't support multiple overlapping frames, this function does nothing. */)
1787 (frame) 2045 (frame)
1788 Lisp_Object frame; 2046 Lisp_Object frame;
1789{ 2047{
2048 struct frame *f;
1790 if (NILP (frame)) 2049 if (NILP (frame))
1791 frame = selected_frame; 2050 frame = selected_frame;
1792 2051
1793 CHECK_LIVE_FRAME (frame); 2052 CHECK_LIVE_FRAME (frame);
1794 2053
2054 f = XFRAME (frame);
2055
1795 /* Do like the documentation says. */ 2056 /* Do like the documentation says. */
1796 Fmake_frame_visible (frame); 2057 Fmake_frame_visible (frame);
1797 2058
1798 if (frame_raise_lower_hook) 2059 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1799 (*frame_raise_lower_hook) (XFRAME (frame), 1); 2060 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1800 2061
1801 return Qnil; 2062 return Qnil;
1802} 2063}
@@ -1810,13 +2071,17 @@ doesn't support multiple overlapping frames, this function does nothing. */)
1810 (frame) 2071 (frame)
1811 Lisp_Object frame; 2072 Lisp_Object frame;
1812{ 2073{
2074 struct frame *f;
2075
1813 if (NILP (frame)) 2076 if (NILP (frame))
1814 frame = selected_frame; 2077 frame = selected_frame;
1815 2078
1816 CHECK_LIVE_FRAME (frame); 2079 CHECK_LIVE_FRAME (frame);
1817 2080
1818 if (frame_raise_lower_hook) 2081 f = XFRAME (frame);
1819 (*frame_raise_lower_hook) (XFRAME (frame), 0); 2082
2083 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2084 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1820 2085
1821 return Qnil; 2086 return Qnil;
1822} 2087}
@@ -1850,6 +2115,8 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */)
1850 (frame, focus_frame) 2115 (frame, focus_frame)
1851 Lisp_Object frame, focus_frame; 2116 Lisp_Object frame, focus_frame;
1852{ 2117{
2118 struct frame *f;
2119
1853 /* Note that we don't check for a live frame here. It's reasonable 2120 /* Note that we don't check for a live frame here. It's reasonable
1854 to redirect the focus of a frame you're about to delete, if you 2121 to redirect the focus of a frame you're about to delete, if you
1855 know what other frame should receive those keystrokes. */ 2122 know what other frame should receive those keystrokes. */
@@ -1858,10 +2125,12 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */)
1858 if (! NILP (focus_frame)) 2125 if (! NILP (focus_frame))
1859 CHECK_LIVE_FRAME (focus_frame); 2126 CHECK_LIVE_FRAME (focus_frame);
1860 2127
1861 XFRAME (frame)->focus_frame = focus_frame; 2128 f = XFRAME (frame);
2129
2130 f->focus_frame = focus_frame;
1862 2131
1863 if (frame_rehighlight_hook) 2132 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1864 (*frame_rehighlight_hook) (XFRAME (frame)); 2133 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1865 2134
1866 return Qnil; 2135 return Qnil;
1867} 2136}
@@ -1923,7 +2192,7 @@ set_frame_buffer_list (frame, list)
1923 XFRAME (frame)->buffer_list = list; 2192 XFRAME (frame)->buffer_list = list;
1924} 2193}
1925 2194
1926/* Discard BUFFER from the buffer-list of each frame. */ 2195/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1927 2196
1928void 2197void
1929frames_discard_buffer (buffer) 2198frames_discard_buffer (buffer)
@@ -1935,6 +2204,8 @@ frames_discard_buffer (buffer)
1935 { 2204 {
1936 XFRAME (frame)->buffer_list 2205 XFRAME (frame)->buffer_list
1937 = Fdelq (buffer, XFRAME (frame)->buffer_list); 2206 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2207 XFRAME (frame)->buried_buffer_list
2208 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
1938 } 2209 }
1939} 2210}
1940 2211
@@ -1993,8 +2264,8 @@ set_term_frame_name (f, name)
1993 SBYTES (f->name))) 2264 SBYTES (f->name)))
1994 return; 2265 return;
1995 2266
1996 terminal_frame_count++; 2267 tty_frame_count++;
1997 sprintf (namebuf, "F%d", terminal_frame_count); 2268 sprintf (namebuf, "F%d", tty_frame_count);
1998 name = build_string (namebuf); 2269 name = build_string (namebuf);
1999 } 2270 }
2000 else 2271 else
@@ -2022,13 +2293,18 @@ store_frame_param (f, prop, val)
2022{ 2293{
2023 register Lisp_Object old_alist_elt; 2294 register Lisp_Object old_alist_elt;
2024 2295
2025 /* The buffer-alist parameter is stored in a special place and is 2296 /* The buffer-list parameters are stored in a special place and not
2026 not in the alist. */ 2297 in the alist. */
2027 if (EQ (prop, Qbuffer_list)) 2298 if (EQ (prop, Qbuffer_list))
2028 { 2299 {
2029 f->buffer_list = val; 2300 f->buffer_list = val;
2030 return; 2301 return;
2031 } 2302 }
2303 if (EQ (prop, Qburied_buffer_list))
2304 {
2305 f->buried_buffer_list = val;
2306 return;
2307 }
2032 2308
2033 /* If PROP is a symbol which is supposed to have frame-local values, 2309 /* If PROP is a symbol which is supposed to have frame-local values,
2034 and it is set up based on this frame, switch to the global 2310 and it is set up based on this frame, switch to the global
@@ -2041,6 +2317,7 @@ store_frame_param (f, prop, val)
2041 if ((BUFFER_LOCAL_VALUEP (valcontents) 2317 if ((BUFFER_LOCAL_VALUEP (valcontents)
2042 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 2318 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2043 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame 2319 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2320 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame
2044 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f) 2321 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2045 swap_in_global_binding (prop); 2322 swap_in_global_binding (prop);
2046 } 2323 }
@@ -2168,6 +2445,7 @@ If FRAME is omitted, return information on the currently selected frame. */)
2168 : FRAME_MINIBUF_WINDOW (f))); 2445 : FRAME_MINIBUF_WINDOW (f)));
2169 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); 2446 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2170 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame)); 2447 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2448 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2171 2449
2172 /* I think this should be done with a hook. */ 2450 /* I think this should be done with a hook. */
2173#ifdef HAVE_WINDOW_SYSTEM 2451#ifdef HAVE_WINDOW_SYSTEM
@@ -2335,9 +2613,44 @@ enabled such bindings for that variable with `make-variable-frame-local'. */)
2335 call1 (Qframe_set_background_mode, frame); 2613 call1 (Qframe_set_background_mode, frame);
2336 } 2614 }
2337 } 2615 }
2616}
2338 2617
2339 return Qnil; 2618DEFUN ("frame-with-environment", Fframe_with_environment, Sframe_with_environment, 0, 1, 0,
2619 doc: /* Return the frame that has the environment variable list for FRAME.
2620
2621The frame-local environment variable list is normally shared between
2622frames that were created in the same Emacsclient session. The
2623environment list is stored in a single frame's 'environment parameter;
2624the other frames' 'environment parameter is set to this frame. This
2625function follows the chain of 'environment references to reach the
2626frame that stores the actual local environment list, and returns that
2627frame. */)
2628 (frame)
2629 Lisp_Object frame;
2630{
2631 Lisp_Object hare, tortoise;
2632
2633 if (NILP (frame))
2634 frame = selected_frame;
2635 CHECK_FRAME (frame);
2636
2637 hare = tortoise = get_frame_param (XFRAME (frame), Qenvironment);
2638 while (!NILP (hare) && FRAMEP (hare))
2639 {
2640 frame = hare;
2641 hare = get_frame_param (XFRAME (hare), Qenvironment);
2642 if (NILP (hare) || !FRAMEP (hare))
2643 break;
2644 frame = hare;
2645 hare = get_frame_param (XFRAME (hare), Qenvironment);
2646 tortoise = get_frame_param (XFRAME (tortoise), Qenvironment);
2647 if (EQ (hare, tortoise))
2648 error ("Cyclic frame-local environment indirection");
2649 }
2650
2651 return frame;
2340} 2652}
2653
2341 2654
2342DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height, 2655DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2343 0, 1, 0, 2656 0, 1, 0,
@@ -2754,9 +3067,8 @@ x_set_frame_parameters (f, alist)
2754 if (NATNUMP (param_index) 3067 if (NATNUMP (param_index)
2755 && (XFASTINT (param_index) 3068 && (XFASTINT (param_index)
2756 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3069 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2757 && rif->frame_parm_handlers[XINT (param_index)]) 3070 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2758 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 3071 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2759
2760 unbind_to (count, Qnil); 3072 unbind_to (count, Qnil);
2761 } 3073 }
2762 } 3074 }
@@ -2800,8 +3112,8 @@ x_set_frame_parameters (f, alist)
2800 if (NATNUMP (param_index) 3112 if (NATNUMP (param_index)
2801 && (XFASTINT (param_index) 3113 && (XFASTINT (param_index)
2802 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3114 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2803 && rif->frame_parm_handlers[XINT (param_index)]) 3115 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2804 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); 3116 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2805 } 3117 }
2806 } 3118 }
2807 3119
@@ -3039,8 +3351,8 @@ x_set_fullscreen (f, new_value, old_value)
3039 else if (EQ (new_value, Qfullheight)) 3351 else if (EQ (new_value, Qfullheight))
3040 f->want_fullscreen = FULLSCREEN_HEIGHT; 3352 f->want_fullscreen = FULLSCREEN_HEIGHT;
3041 3353
3042 if (fullscreen_hook != NULL) 3354 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3043 fullscreen_hook (f); 3355 FRAME_TERMINAL (f)->fullscreen_hook (f);
3044} 3356}
3045 3357
3046 3358
@@ -3089,9 +3401,9 @@ x_set_screen_gamma (f, new_value, old_value)
3089 if (NATNUMP (index) 3401 if (NATNUMP (index)
3090 && (XFASTINT (index) 3402 && (XFASTINT (index)
3091 < sizeof (frame_parms)/sizeof (frame_parms[0])) 3403 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3092 && rif->frame_parm_handlers[XFASTINT (index)]) 3404 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3093 (*(rif->frame_parm_handlers[XFASTINT (index)])) 3405 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3094 (f, bgcolor, Qnil); 3406 (f, bgcolor, Qnil);
3095 } 3407 }
3096 3408
3097 Fclear_face_cache (Qnil); 3409 Fclear_face_cache (Qnil);
@@ -4027,12 +4339,27 @@ syms_of_frame ()
4027 staticpro (&Qbuffer_predicate); 4339 staticpro (&Qbuffer_predicate);
4028 Qbuffer_list = intern ("buffer-list"); 4340 Qbuffer_list = intern ("buffer-list");
4029 staticpro (&Qbuffer_list); 4341 staticpro (&Qbuffer_list);
4342 Qburied_buffer_list = intern ("buried-buffer-list");
4343 staticpro (&Qburied_buffer_list);
4030 Qdisplay_type = intern ("display-type"); 4344 Qdisplay_type = intern ("display-type");
4031 staticpro (&Qdisplay_type); 4345 staticpro (&Qdisplay_type);
4032 Qbackground_mode = intern ("background-mode"); 4346 Qbackground_mode = intern ("background-mode");
4033 staticpro (&Qbackground_mode); 4347 staticpro (&Qbackground_mode);
4034 Qtty_color_mode = intern ("tty-color-mode"); 4348 Qtty_color_mode = intern ("tty-color-mode");
4035 staticpro (&Qtty_color_mode); 4349 staticpro (&Qtty_color_mode);
4350 Qtty = intern ("tty");
4351 staticpro (&Qtty);
4352 Qtty_type = intern ("tty-type");
4353 staticpro (&Qtty_type);
4354 Qwindow_system = intern ("window-system");
4355 staticpro (&Qwindow_system);
4356 Qenvironment = intern ("environment");
4357 staticpro (&Qenvironment);
4358
4359 Qterm_environment_variable = intern ("term-environment-variable");
4360 staticpro (&Qterm_environment_variable);
4361 Qdisplay_environment_variable = intern ("display-environment-variable");
4362 staticpro (&Qdisplay_environment_variable);
4036 4363
4037 Qface_set_after_frame_default = intern ("face-set-after-frame-default"); 4364 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4038 staticpro (&Qface_set_after_frame_default); 4365 staticpro (&Qface_set_after_frame_default);
@@ -4053,6 +4380,11 @@ syms_of_frame ()
4053 Qx_frame_parameter = intern ("x-frame-parameter"); 4380 Qx_frame_parameter = intern ("x-frame-parameter");
4054 staticpro (&Qx_frame_parameter); 4381 staticpro (&Qx_frame_parameter);
4055 4382
4383 Qterminal = intern ("terminal");
4384 staticpro (&Qterminal);
4385 Qterminal_live_p = intern ("terminal-live-p");
4386 staticpro (&Qterminal_live_p);
4387
4056 { 4388 {
4057 int i; 4389 int i;
4058 4390
@@ -4101,6 +4433,7 @@ These may be set in your init file, like this:
4101These override values given in window system configuration data, 4433These override values given in window system configuration data,
4102 including X Windows' defaults database. 4434 including X Windows' defaults database.
4103For values specific to the first Emacs frame, see `initial-frame-alist'. 4435For values specific to the first Emacs frame, see `initial-frame-alist'.
4436For window-system specific values, see `window-system-default-frame-alist'.
4104For values specific to the separate minibuffer frame, see 4437For values specific to the separate minibuffer frame, see
4105 `minibuffer-frame-alist'. 4438 `minibuffer-frame-alist'.
4106The `menu-bar-lines' element of the list controls whether new frames 4439The `menu-bar-lines' element of the list controls whether new frames
@@ -4122,7 +4455,7 @@ Setting this variable does not affect existing frames, only new ones. */);
4122#endif 4455#endif
4123 4456
4124 DEFVAR_LISP ("terminal-frame", &Vterminal_frame, 4457 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4125 doc: /* The initial frame-object, which represents Emacs's stdout. */); 4458 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4126 4459
4127 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified, 4460 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4128 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */); 4461 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
@@ -4147,7 +4480,14 @@ when the mouse is over clickable text. */);
4147 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions, 4480 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4148 doc: /* Functions to be run before deleting a frame. 4481 doc: /* Functions to be run before deleting a frame.
4149The functions are run with one arg, the frame to be deleted. 4482The functions are run with one arg, the frame to be deleted.
4150See `delete-frame'. */); 4483See `delete-frame'.
4484
4485Note that functions in this list may be called twice on the same
4486frame. In the second invocation, the frame is already deleted, and
4487the function should do nothing. (You can use `frame-live-p' to check
4488for this.) This wrinkle happens when an earlier function in
4489`delete-frame-functions' (indirectly) calls delete-frame
4490recursively. */);
4151 Vdelete_frame_functions = Qnil; 4491 Vdelete_frame_functions = Qnil;
4152 4492
4153 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame, 4493 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
@@ -4170,6 +4510,7 @@ This variable is local to the current terminal and cannot be buffer-local. */);
4170 defsubr (&Sactive_minibuffer_window); 4510 defsubr (&Sactive_minibuffer_window);
4171 defsubr (&Sframep); 4511 defsubr (&Sframep);
4172 defsubr (&Sframe_live_p); 4512 defsubr (&Sframe_live_p);
4513 defsubr (&Swindow_system);
4173 defsubr (&Smake_terminal_frame); 4514 defsubr (&Smake_terminal_frame);
4174 defsubr (&Shandle_switch_frame); 4515 defsubr (&Shandle_switch_frame);
4175 defsubr (&Sselect_frame); 4516 defsubr (&Sselect_frame);
@@ -4203,6 +4544,7 @@ This variable is local to the current terminal and cannot be buffer-local. */);
4203 defsubr (&Sframe_parameters); 4544 defsubr (&Sframe_parameters);
4204 defsubr (&Sframe_parameter); 4545 defsubr (&Sframe_parameter);
4205 defsubr (&Smodify_frame_parameters); 4546 defsubr (&Smodify_frame_parameters);
4547 defsubr (&Sframe_with_environment);
4206 defsubr (&Sframe_char_height); 4548 defsubr (&Sframe_char_height);
4207 defsubr (&Sframe_char_width); 4549 defsubr (&Sframe_char_width);
4208 defsubr (&Sframe_pixel_height); 4550 defsubr (&Sframe_pixel_height);
diff --git a/src/frame.h b/src/frame.h
index d5e9f21ed10..9c00e319a57 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,16 @@ 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;
783extern Lisp_Object Qterm_environment_variable;
784extern Lisp_Object Qdisplay_environment_variable;
792 785
793extern struct frame *last_nonminibuf_frame; 786extern struct frame *last_nonminibuf_frame;
794 787
795extern struct frame *make_terminal_frame P_ ((void)); 788extern struct frame *make_initial_frame P_ ((void));
789extern struct frame *make_terminal_frame P_ ((struct terminal *));
796extern struct frame *make_frame P_ ((int)); 790extern struct frame *make_frame P_ ((int));
797#ifdef HAVE_WINDOW_SYSTEM 791#ifdef HAVE_WINDOW_SYSTEM
798extern struct frame *make_minibuffer_frame P_ ((void)); 792extern struct frame *make_minibuffer_frame P_ ((void));
@@ -992,7 +986,7 @@ extern Lisp_Object selected_frame;
992 986
993extern Lisp_Object Qauto_raise, Qauto_lower; 987extern Lisp_Object Qauto_raise, Qauto_lower;
994extern Lisp_Object Qborder_color, Qborder_width; 988extern Lisp_Object Qborder_color, Qborder_width;
995extern Lisp_Object Qbuffer_predicate, Qbuffer_list; 989extern Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
996extern Lisp_Object Qcursor_color, Qcursor_type; 990extern Lisp_Object Qcursor_color, Qcursor_type;
997extern Lisp_Object Qfont; 991extern Lisp_Object Qfont;
998extern Lisp_Object Qbackground_color, Qforeground_color; 992extern Lisp_Object Qbackground_color, Qforeground_color;
@@ -1024,6 +1018,8 @@ extern Lisp_Object Qx_resource_name;
1024extern Lisp_Object Qleft, Qright, Qtop, Qbox; 1018extern Lisp_Object Qleft, Qright, Qtop, Qbox;
1025extern Lisp_Object Qdisplay; 1019extern Lisp_Object Qdisplay;
1026 1020
1021extern Lisp_Object Qwindow_system;
1022
1027#ifdef HAVE_WINDOW_SYSTEM 1023#ifdef HAVE_WINDOW_SYSTEM
1028 1024
1029/* The class of this X application. */ 1025/* The class of this X application. */
diff --git a/src/fringe.c b/src/fringe.c
index 3241786a115..a39e729cfde 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)
@@ -1699,6 +1705,7 @@ mac_init_fringe ()
1699#endif 1705#endif
1700{ 1706{
1701 int bt; 1707 int bt;
1708 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1702 1709
1703 if (!rif) 1710 if (!rif)
1704 return; 1711 return;
@@ -1717,6 +1724,7 @@ w32_reset_fringes ()
1717{ 1724{
1718 /* Destroy row bitmaps. */ 1725 /* Destroy row bitmaps. */
1719 int bt; 1726 int bt;
1727 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1720 1728
1721 if (!rif) 1729 if (!rif)
1722 return; 1730 return;
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 9fb011de919..2af1e03cc28 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -874,7 +874,7 @@ xg_create_frame_widgets (f)
874 874
875 /* Since GTK clears its window by filling with the background color, 875 /* Since GTK clears its window by filling with the background color,
876 we must keep X and GTK background in sync. */ 876 we must keep X and GTK background in sync. */
877 xg_pix_to_gcolor (wfixed, f->output_data.x->background_pixel, &bg); 877 xg_pix_to_gcolor (wfixed, FRAME_BACKGROUND_PIXEL (f), &bg);
878 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg); 878 gtk_widget_modify_bg (wfixed, GTK_STATE_NORMAL, &bg);
879 879
880 /* Also, do not let any background pixmap to be set, this looks very 880 /* Also, do not let any background pixmap to be set, this looks very
@@ -2043,7 +2043,7 @@ xg_create_one_menuitem (item, f, select_cb, highlight_cb, cl_data, group)
2043 return w; 2043 return w;
2044} 2044}
2045 2045
2046/* Callback called when keyboard traversal (started by menu-bar-open) ends. 2046/* Callback called when keyboard traversal (started by x-menu-bar-open) ends.
2047 WMENU is the menu for which traversal has been done. DATA points to the 2047 WMENU is the menu for which traversal has been done. DATA points to the
2048 frame for WMENU. We must release grabs, some bad interaction between GTK 2048 frame for WMENU. We must release grabs, some bad interaction between GTK
2049 and Emacs makes the menus keep the grabs. */ 2049 and Emacs makes the menus keep the grabs. */
diff --git a/src/image.c b/src/image.c
index 54c01cf36b3..db50d94d4c1 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1905,6 +1905,7 @@ lookup_image (f, spec)
1905 struct frame *f; 1905 struct frame *f;
1906 Lisp_Object spec; 1906 Lisp_Object spec;
1907{ 1907{
1908 struct image_cache *c;
1908 struct image *img; 1909 struct image *img;
1909 unsigned hash; 1910 unsigned hash;
1910 struct gcpro gcpro1; 1911 struct gcpro gcpro1;
@@ -1915,6 +1916,8 @@ lookup_image (f, spec)
1915 xassert (FRAME_WINDOW_P (f)); 1916 xassert (FRAME_WINDOW_P (f));
1916 xassert (valid_image_p (spec)); 1917 xassert (valid_image_p (spec));
1917 1918
1919 c = FRAME_X_IMAGE_CACHE (f);
1920
1918 GCPRO1 (spec); 1921 GCPRO1 (spec);
1919 1922
1920 /* Look up SPEC in the hash table of the image cache. */ 1923 /* Look up SPEC in the hash table of the image cache. */
diff --git a/src/indent.c b/src/indent.c
index b3c1d0cf81a..88856814279 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/keyboard.c b/src/keyboard.c
index adbbbcf85dd..95a4aecfe39 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,11 @@ 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)); 681#ifdef MULTI_KBOARD
682static Lisp_Object restore_kboard_configuration P_ ((Lisp_Object));
683#endif
698static SIGTYPE interrupt_signal P_ ((int signalnum)); 684static SIGTYPE interrupt_signal P_ ((int signalnum));
685static void handle_interrupt P_ ((void));
699static void timer_start_idle P_ ((void)); 686static void timer_start_idle P_ ((void));
700static void timer_stop_idle P_ ((void)); 687static void timer_stop_idle P_ ((void));
701static void timer_resume_idle P_ ((void)); 688static void timer_resume_idle P_ ((void));
@@ -1061,24 +1048,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 1048 like it is done in the splash screen display, we have to
1062 make sure that we restore single_kboard as command_loop_1 1049 make sure that we restore single_kboard as command_loop_1
1063 would have done if it were left normally. */ 1050 would have done if it were left normally. */
1064 record_unwind_protect (recursive_edit_unwind, 1051 if (command_loop_level > 0)
1065 Fcons (buffer, single_kboard ? Qt : Qnil)); 1052 temporarily_switch_to_single_kboard (SELECTED_FRAME ());
1053 record_unwind_protect (recursive_edit_unwind, buffer);
1066 1054
1067 recursive_edit_1 (); 1055 recursive_edit_1 ();
1068 return unbind_to (count, Qnil); 1056 return unbind_to (count, Qnil);
1069} 1057}
1070 1058
1071Lisp_Object 1059Lisp_Object
1072recursive_edit_unwind (info) 1060recursive_edit_unwind (buffer)
1073 Lisp_Object info; 1061 Lisp_Object buffer;
1074{ 1062{
1075 if (BUFFERP (XCAR (info))) 1063 if (BUFFERP (buffer))
1076 Fset_buffer (XCAR (info)); 1064 Fset_buffer (buffer);
1077
1078 if (NILP (XCDR (info)))
1079 any_kboard_state ();
1080 else
1081 single_kboard_state ();
1082 1065
1083 command_loop_level--; 1066 command_loop_level--;
1084 update_mode_lines = 1; 1067 update_mode_lines = 1;
@@ -1086,6 +1069,8 @@ recursive_edit_unwind (info)
1086} 1069}
1087 1070
1088 1071
1072#if 0 /* These two functions are now replaced with
1073 temporarily_switch_to_single_kboard. */
1089static void 1074static void
1090any_kboard_state () 1075any_kboard_state ()
1091{ 1076{
@@ -1116,6 +1101,7 @@ single_kboard_state ()
1116 single_kboard = 1; 1101 single_kboard = 1;
1117#endif 1102#endif
1118} 1103}
1104#endif
1119 1105
1120/* If we're in single_kboard state for kboard KBOARD, 1106/* If we're in single_kboard state for kboard KBOARD,
1121 get out of it. */ 1107 get out of it. */
@@ -1143,8 +1129,8 @@ struct kboard_stack
1143static struct kboard_stack *kboard_stack; 1129static struct kboard_stack *kboard_stack;
1144 1130
1145void 1131void
1146push_frame_kboard (f) 1132push_kboard (k)
1147 FRAME_PTR f; 1133 struct kboard *k;
1148{ 1134{
1149#ifdef MULTI_KBOARD 1135#ifdef MULTI_KBOARD
1150 struct kboard_stack *p 1136 struct kboard_stack *p
@@ -1154,20 +1140,110 @@ push_frame_kboard (f)
1154 p->kboard = current_kboard; 1140 p->kboard = current_kboard;
1155 kboard_stack = p; 1141 kboard_stack = p;
1156 1142
1157 current_kboard = FRAME_KBOARD (f); 1143 current_kboard = k;
1158#endif 1144#endif
1159} 1145}
1160 1146
1161void 1147void
1162pop_frame_kboard () 1148pop_kboard ()
1163{ 1149{
1164#ifdef MULTI_KBOARD 1150#ifdef MULTI_KBOARD
1151 struct terminal *t;
1165 struct kboard_stack *p = kboard_stack; 1152 struct kboard_stack *p = kboard_stack;
1166 current_kboard = p->kboard; 1153 int found = 0;
1154 for (t = terminal_list; t; t = t->next_terminal)
1155 {
1156 if (t->kboard == p->kboard)
1157 {
1158 current_kboard = p->kboard;
1159 found = 1;
1160 break;
1161 }
1162 }
1163 if (!found)
1164 {
1165 /* The terminal we remembered has been deleted. */
1166 current_kboard = FRAME_KBOARD (SELECTED_FRAME ());
1167 single_kboard = 0;
1168 }
1167 kboard_stack = p->next; 1169 kboard_stack = p->next;
1168 xfree (p); 1170 xfree (p);
1169#endif 1171#endif
1170} 1172}
1173
1174/* Switch to single_kboard mode, making current_kboard the only KBOARD
1175 from which further input is accepted. If F is non-nil, set its
1176 KBOARD as the current keyboard.
1177
1178 This function uses record_unwind_protect to return to the previous
1179 state later.
1180
1181 If Emacs is already in single_kboard mode, and F's keyboard is
1182 locked, then this function will throw an errow. */
1183
1184void
1185temporarily_switch_to_single_kboard (f)
1186 struct frame *f;
1187{
1188#ifdef MULTI_KBOARD
1189 int was_locked = single_kboard;
1190 if (was_locked)
1191 {
1192 if (f != NULL && FRAME_KBOARD (f) != current_kboard)
1193 /* We can not switch keyboards while in single_kboard mode.
1194 In rare cases, Lisp code may call `recursive-edit' (or
1195 `read-minibuffer' or `y-or-n-p') after it switched to a
1196 locked frame. For example, this is likely to happen
1197 when server.el connects to a new terminal while Emacs is in
1198 single_kboard mode. It is best to throw an error instead
1199 of presenting the user with a frozen screen. */
1200 error ("Terminal %d is locked, cannot read from it",
1201 FRAME_TERMINAL (f)->id);
1202 else
1203 /* This call is unnecessary, but helps
1204 `restore_kboard_configuration' discover if somebody changed
1205 `current_kboard' behind our back. */
1206 push_kboard (current_kboard);
1207 }
1208 else if (f != NULL)
1209 current_kboard = FRAME_KBOARD (f);
1210 single_kboard = 1;
1211 record_unwind_protect (restore_kboard_configuration,
1212 (was_locked ? Qt : Qnil));
1213#endif
1214}
1215
1216#if 0 /* This function is not needed anymore. */
1217void
1218record_single_kboard_state ()
1219{
1220 if (single_kboard)
1221 push_kboard (current_kboard);
1222 record_unwind_protect (restore_kboard_configuration,
1223 (single_kboard ? Qt : Qnil));
1224}
1225#endif
1226
1227#ifdef MULTI_KBOARD
1228static Lisp_Object
1229restore_kboard_configuration (was_locked)
1230 Lisp_Object was_locked;
1231{
1232 if (NILP (was_locked))
1233 single_kboard = 0;
1234 else
1235 {
1236 struct kboard *prev = current_kboard;
1237 single_kboard = 1;
1238 pop_kboard ();
1239 /* The pop should not change the kboard. */
1240 if (single_kboard && current_kboard != prev)
1241 abort ();
1242 }
1243 return Qnil;
1244}
1245#endif
1246
1171 1247
1172/* Handle errors that are not handled at inner levels 1248/* Handle errors that are not handled at inner levels
1173 by printing an error message and returning to the editor command loop. */ 1249 by printing an error message and returning to the editor command loop. */
@@ -1215,10 +1291,12 @@ cmd_error (data)
1215 Vquit_flag = Qnil; 1291 Vquit_flag = Qnil;
1216 1292
1217 Vinhibit_quit = Qnil; 1293 Vinhibit_quit = Qnil;
1294#if 0 /* This shouldn't be necessary anymore. --lorentey */
1218#ifdef MULTI_KBOARD 1295#ifdef MULTI_KBOARD
1219 if (command_loop_level == 0 && minibuf_level == 0) 1296 if (command_loop_level == 0 && minibuf_level == 0)
1220 any_kboard_state (); 1297 any_kboard_state ();
1221#endif 1298#endif
1299#endif
1222 1300
1223 return make_number (0); 1301 return make_number (0);
1224} 1302}
@@ -1254,11 +1332,7 @@ cmd_error_internal (data, context)
1254 /* If the window system or terminal frame hasn't been initialized 1332 /* 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. */ 1333 yet, or we're not interactive, write the message to stderr and exit. */
1256 else if (!sf->glyphs_initialized_p 1334 else if (!sf->glyphs_initialized_p
1257 /* This is the case of the frame dumped with Emacs, when we're 1335 || 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) 1336 || noninteractive)
1263 { 1337 {
1264 print_error_message (data, Qexternal_debugging_output, 1338 print_error_message (data, Qexternal_debugging_output,
@@ -1301,10 +1375,12 @@ command_loop ()
1301 while (1) 1375 while (1)
1302 { 1376 {
1303 internal_catch (Qtop_level, top_level_1, Qnil); 1377 internal_catch (Qtop_level, top_level_1, Qnil);
1304 /* Reset single_kboard in case top-level set it while 1378#if 0 /* This shouldn't be necessary anymore. --lorentey */
1305 evaluating an -f option, or we are stuck there for some 1379 /* Reset single_kboard in case top-level set it while
1306 other reason. */ 1380 evaluating an -f option, or we are stuck there for some
1307 any_kboard_state (); 1381 other reason. */
1382 any_kboard_state ();
1383#endif
1308 internal_catch (Qtop_level, command_loop_2, Qnil); 1384 internal_catch (Qtop_level, command_loop_2, Qnil);
1309 executing_kbd_macro = Qnil; 1385 executing_kbd_macro = Qnil;
1310 1386
@@ -1499,10 +1575,12 @@ command_loop_1 ()
1499 int no_direct; 1575 int no_direct;
1500 int prev_modiff = 0; 1576 int prev_modiff = 0;
1501 struct buffer *prev_buffer = NULL; 1577 struct buffer *prev_buffer = NULL;
1578#if 0 /* This shouldn't be necessary anymore. --lorentey */
1502#ifdef MULTI_KBOARD 1579#ifdef MULTI_KBOARD
1503 int was_locked = single_kboard; 1580 int was_locked = single_kboard;
1504#endif 1581#endif
1505 int already_adjusted; 1582#endif
1583 int already_adjusted = 0;
1506 1584
1507 current_kboard->Vprefix_arg = Qnil; 1585 current_kboard->Vprefix_arg = Qnil;
1508 current_kboard->Vlast_prefix_arg = Qnil; 1586 current_kboard->Vlast_prefix_arg = Qnil;
@@ -1961,10 +2039,11 @@ command_loop_1 ()
1961 if (!NILP (current_kboard->defining_kbd_macro) 2039 if (!NILP (current_kboard->defining_kbd_macro)
1962 && NILP (current_kboard->Vprefix_arg)) 2040 && NILP (current_kboard->Vprefix_arg))
1963 finalize_kbd_macro_chars (); 2041 finalize_kbd_macro_chars ();
1964 2042#if 0 /* This shouldn't be necessary anymore. --lorentey */
1965#ifdef MULTI_KBOARD 2043#ifdef MULTI_KBOARD
1966 if (!was_locked) 2044 if (!was_locked)
1967 any_kboard_state (); 2045 any_kboard_state ();
2046#endif
1968#endif 2047#endif
1969 } 2048 }
1970} 2049}
@@ -2203,7 +2282,10 @@ void
2203start_polling () 2282start_polling ()
2204{ 2283{
2205#ifdef POLL_FOR_INPUT 2284#ifdef POLL_FOR_INPUT
2206 if (read_socket_hook && !interrupt_input) 2285 /* XXX This condition was (read_socket_hook && !interrupt_input),
2286 but read_socket_hook is not global anymore. Let's pretend that
2287 it's always set. */
2288 if (!interrupt_input)
2207 { 2289 {
2208 /* Turn alarm handling on unconditionally. It might have 2290 /* Turn alarm handling on unconditionally. It might have
2209 been turned off in process.c. */ 2291 been turned off in process.c. */
@@ -2237,7 +2319,10 @@ int
2237input_polling_used () 2319input_polling_used ()
2238{ 2320{
2239#ifdef POLL_FOR_INPUT 2321#ifdef POLL_FOR_INPUT
2240 return read_socket_hook && !interrupt_input; 2322 /* XXX This condition was (read_socket_hook && !interrupt_input),
2323 but read_socket_hook is not global anymore. Let's pretend that
2324 it's always set. */
2325 return !interrupt_input;
2241#else 2326#else
2242 return 0; 2327 return 0;
2243#endif 2328#endif
@@ -2249,7 +2334,10 @@ void
2249stop_polling () 2334stop_polling ()
2250{ 2335{
2251#ifdef POLL_FOR_INPUT 2336#ifdef POLL_FOR_INPUT
2252 if (read_socket_hook && !interrupt_input) 2337 /* XXX This condition was (read_socket_hook && !interrupt_input),
2338 but read_socket_hook is not global anymore. Let's pretend that
2339 it's always set. */
2340 if (!interrupt_input)
2253 ++poll_suppress_count; 2341 ++poll_suppress_count;
2254#endif 2342#endif
2255} 2343}
@@ -2461,10 +2549,6 @@ read_char_help_form_unwind (arg)
2461 return Qnil; 2549 return Qnil;
2462} 2550}
2463 2551
2464#ifdef MULTI_KBOARD
2465static jmp_buf wrong_kboard_jmpbuf;
2466#endif
2467
2468#define STOP_POLLING \ 2552#define STOP_POLLING \
2469do { if (! polling_stopped_here) stop_polling (); \ 2553do { if (! polling_stopped_here) stop_polling (); \
2470 polling_stopped_here = 1; } while (0) 2554 polling_stopped_here = 1; } while (0)
@@ -2491,6 +2575,9 @@ do { if (polling_stopped_here) start_polling (); \
2491 if we used a mouse menu to read the input, or zero otherwise. If 2575 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. 2576 USED_MOUSE_MENU is null, we don't dereference it.
2493 2577
2578 Value is -2 when we find input on another keyboard. A second call
2579 to read_char will read it.
2580
2494 If END_TIME is non-null, it is a pointer to an EMACS_TIME 2581 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 2582 specifying the maximum time to wait until. If no input arrives by
2496 that time, stop waiting and return nil. 2583 that time, stop waiting and return nil.
@@ -2517,6 +2604,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2517 volatile int reread; 2604 volatile int reread;
2518 struct gcpro gcpro1, gcpro2; 2605 struct gcpro gcpro1, gcpro2;
2519 int polling_stopped_here = 0; 2606 int polling_stopped_here = 0;
2607 struct kboard *orig_kboard = current_kboard;
2520 2608
2521 also_record = Qnil; 2609 also_record = Qnil;
2522 2610
@@ -2731,6 +2819,10 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2731 && !detect_input_pending_run_timers (0)) 2819 && !detect_input_pending_run_timers (0))
2732 { 2820 {
2733 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps); 2821 c = read_char_minibuf_menu_prompt (commandflag, nmaps, maps);
2822
2823 if (INTEGERP (c) && XINT (c) == -2)
2824 return c; /* wrong_kboard_jmpbuf */
2825
2734 if (! NILP (c)) 2826 if (! NILP (c))
2735 { 2827 {
2736 key_already_recorded = 1; 2828 key_already_recorded = 1;
@@ -2747,6 +2839,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2747 jmpcount = SPECPDL_INDEX (); 2839 jmpcount = SPECPDL_INDEX ();
2748 if (_setjmp (local_getcjmp)) 2840 if (_setjmp (local_getcjmp))
2749 { 2841 {
2842 /* Handle quits while reading the keyboard. */
2750 /* We must have saved the outer value of getcjmp here, 2843 /* We must have saved the outer value of getcjmp here,
2751 so restore it now. */ 2844 so restore it now. */
2752 restore_getcjmp (save_jump); 2845 restore_getcjmp (save_jump);
@@ -2784,7 +2877,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2784 /* This is going to exit from read_char 2877 /* This is going to exit from read_char
2785 so we had better get rid of this frame's stuff. */ 2878 so we had better get rid of this frame's stuff. */
2786 UNGCPRO; 2879 UNGCPRO;
2787 longjmp (wrong_kboard_jmpbuf, 1); 2880 return make_number (-2); /* wrong_kboard_jmpbuf */
2788 } 2881 }
2789 } 2882 }
2790#endif 2883#endif
@@ -2921,6 +3014,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2921 } 3014 }
2922 } 3015 }
2923 3016
3017 /* Notify the caller if an autosave hook, or a timer, sentinel or
3018 filter in the sit_for calls above have changed the current
3019 kboard. This could happen if they use the minibuffer or start a
3020 recursive edit, like the fancy splash screen in server.el's
3021 filter. If this longjmp wasn't here, read_key_sequence would
3022 interpret the next key sequence using the wrong translation
3023 tables and function keymaps. */
3024 if (NILP (c) && current_kboard != orig_kboard)
3025 {
3026 UNGCPRO;
3027 return make_number (-2); /* wrong_kboard_jmpbuf */
3028 }
3029
2924 /* If this has become non-nil here, it has been set by a timer 3030 /* If this has become non-nil here, it has been set by a timer
2925 or sentinel or filter. */ 3031 or sentinel or filter. */
2926 if (CONSP (Vunread_command_events)) 3032 if (CONSP (Vunread_command_events))
@@ -2969,7 +3075,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
2969 /* This is going to exit from read_char 3075 /* This is going to exit from read_char
2970 so we had better get rid of this frame's stuff. */ 3076 so we had better get rid of this frame's stuff. */
2971 UNGCPRO; 3077 UNGCPRO;
2972 longjmp (wrong_kboard_jmpbuf, 1); 3078 return make_number (-2); /* wrong_kboard_jmpbuf */
2973 } 3079 }
2974 } 3080 }
2975#endif 3081#endif
@@ -3025,7 +3131,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3025 /* This is going to exit from read_char 3131 /* This is going to exit from read_char
3026 so we had better get rid of this frame's stuff. */ 3132 so we had better get rid of this frame's stuff. */
3027 UNGCPRO; 3133 UNGCPRO;
3028 longjmp (wrong_kboard_jmpbuf, 1); 3134 return make_number (-2);
3029 } 3135 }
3030#endif 3136#endif
3031 } 3137 }
@@ -3080,8 +3186,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3080 3186
3081 if (!NILP (tem)) 3187 if (!NILP (tem))
3082 { 3188 {
3189#if 0 /* This shouldn't be necessary anymore. --lorentey */
3083 int was_locked = single_kboard; 3190 int was_locked = single_kboard;
3084 3191 int count = SPECPDL_INDEX ();
3192 record_single_kboard_state ();
3193#endif
3194
3085 last_input_char = c; 3195 last_input_char = c;
3086 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt); 3196 Fcommand_execute (tem, Qnil, Fvector (1, &last_input_char), Qt);
3087 3197
@@ -3092,9 +3202,12 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3092 example banishing the mouse under mouse-avoidance-mode. */ 3202 example banishing the mouse under mouse-avoidance-mode. */
3093 timer_resume_idle (); 3203 timer_resume_idle ();
3094 3204
3205#if 0 /* This shouldn't be necessary anymore. --lorentey */
3095 /* Resume allowing input from any kboard, if that was true before. */ 3206 /* Resume allowing input from any kboard, if that was true before. */
3096 if (!was_locked) 3207 if (!was_locked)
3097 any_kboard_state (); 3208 any_kboard_state ();
3209 unbind_to (count, Qnil);
3210#endif
3098 3211
3099 goto retry; 3212 goto retry;
3100 } 3213 }
@@ -3106,15 +3219,15 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu, end_time)
3106 if (XINT (c) == -1) 3219 if (XINT (c) == -1)
3107 goto exit; 3220 goto exit;
3108 3221
3109 if ((STRINGP (Vkeyboard_translate_table) 3222 if ((STRINGP (current_kboard->Vkeyboard_translate_table)
3110 && SCHARS (Vkeyboard_translate_table) > (unsigned) XFASTINT (c)) 3223 && SCHARS (current_kboard->Vkeyboard_translate_table) > (unsigned) XFASTINT (c))
3111 || (VECTORP (Vkeyboard_translate_table) 3224 || (VECTORP (current_kboard->Vkeyboard_translate_table)
3112 && XVECTOR (Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c)) 3225 && XVECTOR (current_kboard->Vkeyboard_translate_table)->size > (unsigned) XFASTINT (c))
3113 || (CHAR_TABLE_P (Vkeyboard_translate_table) 3226 || (CHAR_TABLE_P (current_kboard->Vkeyboard_translate_table)
3114 && CHAR_VALID_P (XINT (c), 0))) 3227 && CHAR_VALID_P (XINT (c), 0)))
3115 { 3228 {
3116 Lisp_Object d; 3229 Lisp_Object d;
3117 d = Faref (Vkeyboard_translate_table, c); 3230 d = Faref (current_kboard->Vkeyboard_translate_table, c);
3118 /* nil in keyboard-translate-table means no translation. */ 3231 /* nil in keyboard-translate-table means no translation. */
3119 if (!NILP (d)) 3232 if (!NILP (d))
3120 c = d; 3233 c = d;
@@ -3734,12 +3847,10 @@ kbd_buffer_store_event_hold (event, hold_quit)
3734 if (c == quit_char) 3847 if (c == quit_char)
3735 { 3848 {
3736#ifdef MULTI_KBOARD 3849#ifdef MULTI_KBOARD
3737 KBOARD *kb; 3850 KBOARD *kb = FRAME_KBOARD (XFRAME (event->frame_or_window));
3738 struct input_event *sp; 3851 struct input_event *sp;
3739 3852
3740 if (single_kboard 3853 if (single_kboard && kb != current_kboard)
3741 && (kb = FRAME_KBOARD (XFRAME (event->frame_or_window)),
3742 kb != current_kboard))
3743 { 3854 {
3744 kb->kbd_queue 3855 kb->kbd_queue
3745 = Fcons (make_lispy_switch_frame (event->frame_or_window), 3856 = Fcons (make_lispy_switch_frame (event->frame_or_window),
@@ -3782,7 +3893,7 @@ kbd_buffer_store_event_hold (event, hold_quit)
3782 } 3893 }
3783 3894
3784 last_event_timestamp = event->timestamp; 3895 last_event_timestamp = event->timestamp;
3785 interrupt_signal (0 /* dummy */); 3896 handle_interrupt ();
3786 return; 3897 return;
3787 } 3898 }
3788 3899
@@ -4264,11 +4375,15 @@ kbd_buffer_get_event (kbp, used_mouse_menu, end_time)
4264 unsigned long time; 4375 unsigned long time;
4265 4376
4266 *kbp = current_kboard; 4377 *kbp = current_kboard;
4267 /* Note that this uses F to determine which display to look at. 4378 /* Note that this uses F to determine which terminal to look at.
4268 If there is no valid info, it does not store anything 4379 If there is no valid info, it does not store anything
4269 so x remains nil. */ 4380 so x remains nil. */
4270 x = Qnil; 4381 x = Qnil;
4271 (*mouse_position_hook) (&f, 0, &bar_window, &part, &x, &y, &time); 4382
4383 /* XXX Can f or mouse_position_hook be NULL here? */
4384 if (f && FRAME_TERMINAL (f)->mouse_position_hook)
4385 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, 0, &bar_window,
4386 &part, &x, &y, &time);
4272 4387
4273 obj = Qnil; 4388 obj = Qnil;
4274 4389
@@ -4565,10 +4680,14 @@ timer_check (do_it_now)
4565 { 4680 {
4566 if (NILP (vector[0])) 4681 if (NILP (vector[0]))
4567 { 4682 {
4568 int was_locked = single_kboard;
4569 int count = SPECPDL_INDEX (); 4683 int count = SPECPDL_INDEX ();
4570 Lisp_Object old_deactivate_mark = Vdeactivate_mark; 4684 Lisp_Object old_deactivate_mark = Vdeactivate_mark;
4571 4685
4686#if 0 /* This shouldn't be necessary anymore. --lorentey */
4687 /* On unbind_to, resume allowing input from any kboard, if that
4688 was true before. */
4689 record_single_kboard_state ();
4690#endif
4572 /* Mark the timer as triggered to prevent problems if the lisp 4691 /* Mark the timer as triggered to prevent problems if the lisp
4573 code fails to reschedule it right. */ 4692 code fails to reschedule it right. */
4574 vector[0] = Qt; 4693 vector[0] = Qt;
@@ -4580,10 +4699,6 @@ timer_check (do_it_now)
4580 timers_run++; 4699 timers_run++;
4581 unbind_to (count, Qnil); 4700 unbind_to (count, Qnil);
4582 4701
4583 /* Resume allowing input from any kboard, if that was true before. */
4584 if (!was_locked)
4585 any_kboard_state ();
4586
4587 /* Since we have handled the event, 4702 /* Since we have handled the event,
4588 we don't need to tell the caller to wake up and do it. */ 4703 we don't need to tell the caller to wake up and do it. */
4589 } 4704 }
@@ -6544,8 +6659,8 @@ modify_event_symbol (symbol_num, modifiers, symbol_kind, name_alist_or_stem,
6544 { 6659 {
6545 int len = SBYTES (name_alist_or_stem); 6660 int len = SBYTES (name_alist_or_stem);
6546 char *buf = (char *) alloca (len + 50); 6661 char *buf = (char *) alloca (len + 50);
6547 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem), 6662 sprintf (buf, "%s-%ld", SDATA (name_alist_or_stem),
6548 (long) XINT (symbol_int) + 1); 6663 (long) XINT (symbol_int) + 1);
6549 value = intern (buf); 6664 value = intern (buf);
6550 } 6665 }
6551 else if (name_table != 0 && name_table[symbol_num]) 6666 else if (name_table != 0 && name_table[symbol_num])
@@ -6810,7 +6925,10 @@ gobble_input (expected)
6810 } 6925 }
6811 else 6926 else
6812#ifdef POLL_FOR_INPUT 6927#ifdef POLL_FOR_INPUT
6813 if (read_socket_hook && !interrupt_input && poll_suppress_count == 0) 6928 /* XXX This condition was (read_socket_hook && !interrupt_input),
6929 but read_socket_hook is not global anymore. Let's pretend that
6930 it's always set. */
6931 if (!interrupt_input && poll_suppress_count == 0)
6814 { 6932 {
6815 SIGMASKTYPE mask; 6933 SIGMASKTYPE mask;
6816 mask = sigblock (sigmask (SIGALRM)); 6934 mask = sigblock (sigmask (SIGALRM));
@@ -6887,170 +7005,241 @@ static int
6887read_avail_input (expected) 7005read_avail_input (expected)
6888 int expected; 7006 int expected;
6889{ 7007{
6890 register int i;
6891 int nread = 0; 7008 int nread = 0;
7009 int err = 0;
7010 struct terminal *t;
6892 7011
6893 /* Store pending user signal events, if any. */ 7012 /* Store pending user signal events, if any. */
6894 if (store_user_signal_events ()) 7013 if (store_user_signal_events ())
6895 expected = 0; 7014 expected = 0;
6896 7015
6897 if (read_socket_hook) 7016 /* Loop through the available terminals, and call their input hooks. */
7017 t = terminal_list;
7018 while (t)
6898 { 7019 {
6899 int nr; 7020 struct terminal *next = t->next_terminal;
6900 struct input_event hold_quit;
6901 7021
6902 EVENT_INIT (hold_quit); 7022 if (t->read_socket_hook)
6903 hold_quit.kind = NO_EVENT; 7023 {
7024 int nr;
7025 struct input_event hold_quit;
7026
7027 EVENT_INIT (hold_quit);
7028 hold_quit.kind = NO_EVENT;
7029
7030 /* No need for FIONREAD or fcntl; just say don't wait. */
7031 while (nr = (*t->read_socket_hook) (t, expected, &hold_quit), nr > 0)
7032 {
7033 nread += nr;
7034 expected = 0;
7035 }
7036
7037 if (nr == -1) /* Not OK to read input now. */
7038 {
7039 err = 1;
7040 }
7041 else if (nr == -2) /* Non-transient error. */
7042 {
7043 /* The terminal device terminated; it should be closed. */
7044
7045 /* Kill Emacs if this was our last terminal. */
7046 if (!terminal_list->next_terminal)
7047 /* Formerly simply reported no input, but that
7048 sometimes led to a failure of Emacs to terminate.
7049 SIGHUP seems appropriate if we can't reach the
7050 terminal. */
7051 /* ??? Is it really right to send the signal just to
7052 this process rather than to the whole process
7053 group? Perhaps on systems with FIONREAD Emacs is
7054 alone in its group. */
7055 kill (getpid (), SIGHUP);
7056
7057 /* XXX Is calling delete_terminal safe here? It calls Fdelete_frame. */
7058 if (t->delete_terminal_hook)
7059 (*t->delete_terminal_hook) (t);
7060 else
7061 delete_terminal (t);
7062 }
7063
7064 if (hold_quit.kind != NO_EVENT)
7065 kbd_buffer_store_event (&hold_quit);
7066 }
6904 7067
6905 /* No need for FIONREAD or fcntl; just say don't wait. */ 7068 t = next;
6906 while (nr = (*read_socket_hook) (input_fd, expected, &hold_quit), nr > 0)
6907 {
6908 nread += nr;
6909 expected = 0;
6910 }
6911 if (hold_quit.kind != NO_EVENT)
6912 kbd_buffer_store_event (&hold_quit);
6913 } 7069 }
6914 else
6915 {
6916 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
6917 the kbd_buffer can really hold. That may prevent loss
6918 of characters on some systems when input is stuffed at us. */
6919 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6920 int n_to_read;
6921 7070
6922 /* Determine how many characters we should *try* to read. */ 7071 if (err && !nread)
7072 nread = -1;
7073
7074 return nread;
7075}
7076
7077/* This is the tty way of reading available input.
7078
7079 Note that each terminal device has its own `struct terminal' object,
7080 and so this function is called once for each individual termcap
7081 terminal. The first parameter indicates which terminal to read from. */
7082
7083int
7084tty_read_avail_input (struct terminal *terminal,
7085 int expected,
7086 struct input_event *hold_quit)
7087{
7088 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
7089 the kbd_buffer can really hold. That may prevent loss
7090 of characters on some systems when input is stuffed at us. */
7091 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
7092 int n_to_read, i;
7093 struct tty_display_info *tty = terminal->display_info.tty;
7094 int nread = 0;
7095
7096 if (terminal->deleted) /* Don't read from a deleted terminal. */
7097 return;
7098
7099 if (terminal->type != output_termcap)
7100 abort ();
7101
7102 /* XXX I think the following code should be moved to separate hook
7103 functions in system-dependent files. */
6923#ifdef WINDOWSNT 7104#ifdef WINDOWSNT
6924 return 0; 7105 return 0;
6925#else /* not WINDOWSNT */ 7106#else /* not WINDOWSNT */
6926#ifdef MSDOS 7107#ifdef MSDOS
6927 n_to_read = dos_keysns (); 7108 n_to_read = dos_keysns ();
6928 if (n_to_read == 0) 7109 if (n_to_read == 0)
6929 return 0; 7110 return 0;
7111
7112 cbuf[0] = dos_keyread ();
7113 nread = 1;
7114
6930#else /* not MSDOS */ 7115#else /* not MSDOS */
7116
7117 if (! tty->term_initted) /* In case we get called during bootstrap. */
7118 return 0;
7119
7120 if (! tty->input)
7121 return 0; /* The terminal is suspended. */
7122
6931#ifdef HAVE_GPM 7123#ifdef HAVE_GPM
6932 if (term_gpm) 7124 if (term_gpm && gpm_tty == tty->terminal->id)
6933 { 7125 {
6934 Gpm_Event event; 7126 Gpm_Event event;
6935 struct input_event hold_quit; 7127 struct input_event hold_quit;
6936 int gpm; 7128 int gpm;
6937 7129
6938 EVENT_INIT (hold_quit); 7130 EVENT_INIT (hold_quit);
6939 hold_quit.kind = NO_EVENT; 7131 hold_quit.kind = NO_EVENT;
6940 7132
6941 while (gpm = Gpm_GetEvent (&event), gpm == 1) { 7133 while (gpm = Gpm_GetEvent (&event), gpm == 1) {
6942 nread += handle_one_term_event (&event, &hold_quit); 7134 nread += handle_one_term_event (tty, &event, &hold_quit);
6943 } 7135 }
6944 if (hold_quit.kind != NO_EVENT) 7136 if (hold_quit.kind != NO_EVENT)
6945 kbd_buffer_store_event (&hold_quit); 7137 kbd_buffer_store_event (&hold_quit);
6946 if (nread) 7138 if (nread)
6947 return nread; 7139 return nread;
6948 } 7140 }
6949#endif /* HAVE_GPM */ 7141#endif /* HAVE_GPM */
6950#ifdef FIONREAD
6951 7142
6952 /* Find out how much input is available. */ 7143/* Determine how many characters we should *try* to read. */
6953 if (ioctl (input_fd, FIONREAD, &n_to_read) < 0) 7144#ifdef FIONREAD
6954 /* Formerly simply reported no input, but that sometimes led to 7145 /* Find out how much input is available. */
6955 a failure of Emacs to terminate. 7146 if (ioctl (fileno (tty->input), FIONREAD, &n_to_read) < 0)
6956 SIGHUP seems appropriate if we can't reach the terminal. */ 7147 {
6957 /* ??? Is it really right to send the signal just to this process 7148 if (! noninteractive)
6958 rather than to the whole process group? 7149 return -2; /* Close this terminal. */
6959 Perhaps on systems with FIONREAD Emacs is alone in its group. */ 7150 else
6960 { 7151 n_to_read = 0;
6961 if (! noninteractive) 7152 }
6962 kill (getpid (), SIGHUP); 7153 if (n_to_read == 0)
6963 else 7154 return 0;
6964 n_to_read = 0; 7155 if (n_to_read > sizeof cbuf)
6965 } 7156 n_to_read = sizeof cbuf;
6966 if (n_to_read == 0)
6967 return 0;
6968 if (n_to_read > sizeof cbuf)
6969 n_to_read = sizeof cbuf;
6970#else /* no FIONREAD */ 7157#else /* no FIONREAD */
6971#if defined (USG) || defined (DGUX) || defined(CYGWIN) 7158#if defined (USG) || defined (DGUX) || defined(CYGWIN)
6972 /* Read some input if available, but don't wait. */ 7159 /* Read some input if available, but don't wait. */
6973 n_to_read = sizeof cbuf; 7160 n_to_read = sizeof cbuf;
6974 fcntl (input_fd, F_SETFL, O_NDELAY); 7161 fcntl (fileno (tty->input), F_SETFL, O_NDELAY);
6975#else 7162#else
6976 you lose; 7163 you lose;
6977#endif 7164#endif
6978#endif 7165#endif
6979#endif /* not MSDOS */
6980#endif /* not WINDOWSNT */
6981 7166
6982 /* Now read; for one reason or another, this will not block. 7167 /* Now read; for one reason or another, this will not block.
6983 NREAD is set to the number of chars read. */ 7168 NREAD is set to the number of chars read. */
6984 do 7169 do
6985 { 7170 {
6986#ifdef MSDOS 7171 nread = emacs_read (fileno (tty->input), cbuf, n_to_read);
6987 cbuf[0] = dos_keyread (); 7172 /* POSIX infers that processes which are not in the session leader's
6988 nread = 1; 7173 process group won't get SIGHUP's at logout time. BSDI adheres to
6989#else 7174 this part standard and returns -1 from read (0) with errno==EIO
6990 nread = emacs_read (input_fd, cbuf, n_to_read); 7175 when the control tty is taken away.
6991#endif 7176 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6992 /* POSIX infers that processes which are not in the session leader's 7177 if (nread == -1 && errno == EIO)
6993 process group won't get SIGHUP's at logout time. BSDI adheres to 7178 return -2; /* Close this terminal. */
6994 this part standard and returns -1 from read (0) with errno==EIO
6995 when the control tty is taken away.
6996 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6997 if (nread == -1 && errno == EIO)
6998 kill (0, SIGHUP);
6999#if defined (AIX) && (! defined (aix386) && defined (_BSD)) 7179#if defined (AIX) && (! defined (aix386) && defined (_BSD))
7000 /* The kernel sometimes fails to deliver SIGHUP for ptys. 7180 /* The kernel sometimes fails to deliver SIGHUP for ptys.
7001 This looks incorrect, but it isn't, because _BSD causes 7181 This looks incorrect, but it isn't, because _BSD causes
7002 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 7182 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
7003 and that causes a value other than 0 when there is no input. */ 7183 and that causes a value other than 0 when there is no input. */
7004 if (nread == 0) 7184 if (nread == 0)
7005 kill (0, SIGHUP); 7185 return -2; /* Close this terminal. */
7006#endif 7186#endif
7007 } 7187 }
7008 while ( 7188 while (
7009 /* We used to retry the read if it was interrupted. 7189 /* We used to retry the read if it was interrupted.
7010 But this does the wrong thing when O_NDELAY causes 7190 But this does the wrong thing when O_NDELAY causes
7011 an EAGAIN error. Does anybody know of a situation 7191 an EAGAIN error. Does anybody know of a situation
7012 where a retry is actually needed? */ 7192 where a retry is actually needed? */
7013#if 0 7193#if 0
7014 nread < 0 && (errno == EAGAIN 7194 nread < 0 && (errno == EAGAIN
7015#ifdef EFAULT 7195#ifdef EFAULT
7016 || errno == EFAULT 7196 || errno == EFAULT
7017#endif 7197#endif
7018#ifdef EBADSLT 7198#ifdef EBADSLT
7019 || errno == EBADSLT 7199 || errno == EBADSLT
7020#endif 7200#endif
7021 ) 7201 )
7022#else 7202#else
7023 0 7203 0
7024#endif 7204#endif
7025 ); 7205 );
7026 7206
7027#ifndef FIONREAD 7207#ifndef FIONREAD
7028#if defined (USG) || defined (DGUX) || defined (CYGWIN) 7208#if defined (USG) || defined (DGUX) || defined (CYGWIN)
7029 fcntl (input_fd, F_SETFL, 0); 7209 fcntl (fileno (tty->input), F_SETFL, 0);
7030#endif /* USG or DGUX or CYGWIN */ 7210#endif /* USG or DGUX or CYGWIN */
7031#endif /* no FIONREAD */ 7211#endif /* no FIONREAD */
7032 for (i = 0; i < nread; i++) 7212
7033 { 7213 if (nread <= 0)
7034 struct input_event buf; 7214 return nread;
7035 EVENT_INIT (buf); 7215
7036 buf.kind = ASCII_KEYSTROKE_EVENT; 7216#endif /* not MSDOS */
7037 buf.modifiers = 0; 7217#endif /* not WINDOWSNT */
7038 if (meta_key == 1 && (cbuf[i] & 0x80)) 7218
7039 buf.modifiers = meta_modifier; 7219 for (i = 0; i < nread; i++)
7040 if (meta_key != 2) 7220 {
7041 cbuf[i] &= ~0x80; 7221 struct input_event buf;
7042 7222 EVENT_INIT (buf);
7043 buf.code = cbuf[i]; 7223 buf.kind = ASCII_KEYSTROKE_EVENT;
7044 buf.frame_or_window = selected_frame; 7224 buf.modifiers = 0;
7045 buf.arg = Qnil; 7225 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
7046 7226 buf.modifiers = meta_modifier;
7047 kbd_buffer_store_event (&buf); 7227 if (tty->meta_key != 2)
7048 /* Don't look at input that follows a C-g too closely. 7228 cbuf[i] &= ~0x80;
7049 This reduces lossage due to autorepeat on C-g. */ 7229
7050 if (buf.kind == ASCII_KEYSTROKE_EVENT 7230 buf.code = cbuf[i];
7051 && buf.code == quit_char) 7231 /* Set the frame corresponding to the active tty. Note that the
7052 break; 7232 value of selected_frame is not reliable here, redisplay tends
7053 } 7233 to temporarily change it. */
7234 buf.frame_or_window = tty->top_frame;
7235 buf.arg = Qnil;
7236
7237 kbd_buffer_store_event (&buf);
7238 /* Don't look at input that follows a C-g too closely.
7239 This reduces lossage due to autorepeat on C-g. */
7240 if (buf.kind == ASCII_KEYSTROKE_EVENT
7241 && buf.code == quit_char)
7242 break;
7054 } 7243 }
7055 7244
7056 return nread; 7245 return nread;
@@ -8632,6 +8821,8 @@ read_char_minibuf_menu_prompt (commandflag, nmaps, maps)
8632 8821
8633 if (!INTEGERP (obj)) 8822 if (!INTEGERP (obj))
8634 return obj; 8823 return obj;
8824 else if (XINT (obj) == -2)
8825 return obj;
8635 else 8826 else
8636 ch = XINT (obj); 8827 ch = XINT (obj);
8637 8828
@@ -8978,11 +9169,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
8978 last_nonmenu_event = Qnil; 9169 last_nonmenu_event = Qnil;
8979 9170
8980 delayed_switch_frame = Qnil; 9171 delayed_switch_frame = Qnil;
8981 fkey.map = fkey.parent = Vfunction_key_map; 9172
8982 keytran.map = keytran.parent = Vkey_translation_map;
8983 fkey.start = fkey.end = 0;
8984 keytran.start = keytran.end = 0;
8985
8986 if (INTERACTIVE) 9173 if (INTERACTIVE)
8987 { 9174 {
8988 if (!NILP (prompt)) 9175 if (!NILP (prompt))
@@ -9022,6 +9209,13 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9022 keybuf[0..mock_input] holds the sequence we should reread. */ 9209 keybuf[0..mock_input] holds the sequence we should reread. */
9023 replay_sequence: 9210 replay_sequence:
9024 9211
9212 /* We may switch keyboards between rescans, so we need to
9213 reinitialize fkey and keytran before each replay. */
9214 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
9215 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map;
9216 fkey.start = fkey.end = 0;
9217 keytran.start = keytran.end = 0;
9218
9025 starting_buffer = current_buffer; 9219 starting_buffer = current_buffer;
9026 first_unbound = bufsize + 1; 9220 first_unbound = bufsize + 1;
9027 9221
@@ -9186,8 +9380,28 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9186#ifdef MULTI_KBOARD 9380#ifdef MULTI_KBOARD
9187 KBOARD *interrupted_kboard = current_kboard; 9381 KBOARD *interrupted_kboard = current_kboard;
9188 struct frame *interrupted_frame = SELECTED_FRAME (); 9382 struct frame *interrupted_frame = SELECTED_FRAME ();
9189 if (setjmp (wrong_kboard_jmpbuf)) 9383#endif
9384 key = read_char (NILP (prompt), nmaps,
9385 (Lisp_Object *) submaps, last_nonmenu_event,
9386 &used_mouse_menu, NULL);
9387#ifdef MULTI_KBOARD
9388 if (INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9190 { 9389 {
9390 int found = 0;
9391 struct kboard *k;
9392
9393 for (k = all_kboards; k; k = k->next_kboard)
9394 if (k == interrupted_kboard)
9395 found = 1;
9396
9397 if (!found)
9398 {
9399 /* Don't touch interrupted_kboard when it's been
9400 deleted. */
9401 delayed_switch_frame = Qnil;
9402 goto replay_sequence;
9403 }
9404
9191 if (!NILP (delayed_switch_frame)) 9405 if (!NILP (delayed_switch_frame))
9192 { 9406 {
9193 interrupted_kboard->kbd_queue 9407 interrupted_kboard->kbd_queue
@@ -9195,6 +9409,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9195 interrupted_kboard->kbd_queue); 9409 interrupted_kboard->kbd_queue);
9196 delayed_switch_frame = Qnil; 9410 delayed_switch_frame = Qnil;
9197 } 9411 }
9412
9198 while (t > 0) 9413 while (t > 0)
9199 interrupted_kboard->kbd_queue 9414 interrupted_kboard->kbd_queue
9200 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue); 9415 = Fcons (keybuf[--t], interrupted_kboard->kbd_queue);
@@ -9219,9 +9434,6 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9219 goto replay_sequence; 9434 goto replay_sequence;
9220 } 9435 }
9221#endif 9436#endif
9222 key = read_char (NILP (prompt), nmaps,
9223 (Lisp_Object *) submaps, last_nonmenu_event,
9224 &used_mouse_menu, NULL);
9225 } 9437 }
9226 9438
9227 /* read_char returns t when it shows a menu and the user rejects it. 9439 /* read_char returns t when it shows a menu and the user rejects it.
@@ -10333,8 +10545,12 @@ detect_input_pending_run_timers (do_display)
10333 from an idle timer function. The symptom of the bug is that 10545 from an idle timer function. The symptom of the bug is that
10334 the cursor sometimes doesn't become visible until the next X 10546 the cursor sometimes doesn't become visible until the next X
10335 event is processed. --gerd. */ 10547 event is processed. --gerd. */
10336 if (rif) 10548 {
10337 rif->flush_display (NULL); 10549 Lisp_Object tail, frame;
10550 FOR_EACH_FRAME (tail, frame)
10551 if (FRAME_RIF (XFRAME (frame)))
10552 FRAME_RIF (XFRAME (frame))->flush_display (XFRAME (frame));
10553 }
10338 } 10554 }
10339 10555
10340 return input_pending; 10556 return input_pending;
@@ -10586,6 +10802,9 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10586 int width, height; 10802 int width, height;
10587 struct gcpro gcpro1; 10803 struct gcpro gcpro1;
10588 10804
10805 if (tty_list && tty_list->next)
10806 error ("There are other tty frames open; close them before suspending Emacs");
10807
10589 if (!NILP (stuffstring)) 10808 if (!NILP (stuffstring))
10590 CHECK_STRING (stuffstring); 10809 CHECK_STRING (stuffstring);
10591 10810
@@ -10594,11 +10813,11 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10594 call1 (Vrun_hooks, intern ("suspend-hook")); 10813 call1 (Vrun_hooks, intern ("suspend-hook"));
10595 10814
10596 GCPRO1 (stuffstring); 10815 GCPRO1 (stuffstring);
10597 get_frame_size (&old_width, &old_height); 10816 get_tty_size (fileno (CURTTY ()->input), &old_width, &old_height);
10598 reset_sys_modes (); 10817 reset_all_sys_modes ();
10599 /* sys_suspend can get an error if it tries to fork a subshell 10818 /* sys_suspend can get an error if it tries to fork a subshell
10600 and the system resources aren't available for that. */ 10819 and the system resources aren't available for that. */
10601 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_sys_modes, 10820 record_unwind_protect ((Lisp_Object (*) P_ ((Lisp_Object))) init_all_sys_modes,
10602 Qnil); 10821 Qnil);
10603 stuff_buffered_input (stuffstring); 10822 stuff_buffered_input (stuffstring);
10604 if (cannot_suspend) 10823 if (cannot_suspend)
@@ -10610,7 +10829,7 @@ On such systems, Emacs starts a subshell instead of suspending. */)
10610 /* Check if terminal/window size has changed. 10829 /* Check if terminal/window size has changed.
10611 Note that this is not useful when we are running directly 10830 Note that this is not useful when we are running directly
10612 with a window system; but suspend should be disabled in that case. */ 10831 with a window system; but suspend should be disabled in that case. */
10613 get_frame_size (&width, &height); 10832 get_tty_size (fileno (CURTTY ()->input), &width, &height);
10614 if (width != old_width || height != old_height) 10833 if (width != old_width || height != old_height)
10615 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0); 10834 change_frame_size (SELECTED_FRAME (), height, width, 0, 0, 0);
10616 10835
@@ -10670,10 +10889,10 @@ set_waiting_for_input (time_to_clear)
10670{ 10889{
10671 input_available_clear_time = time_to_clear; 10890 input_available_clear_time = time_to_clear;
10672 10891
10673 /* Tell interrupt_signal to throw back to read_char, */ 10892 /* Tell handle_interrupt to throw back to read_char, */
10674 waiting_for_input = 1; 10893 waiting_for_input = 1;
10675 10894
10676 /* If interrupt_signal was called before and buffered a C-g, 10895 /* If handle_interrupt was called before and buffered a C-g,
10677 make it run again now, to avoid timing error. */ 10896 make it run again now, to avoid timing error. */
10678 if (!NILP (Vquit_flag)) 10897 if (!NILP (Vquit_flag))
10679 quit_throw_to_read_char (); 10898 quit_throw_to_read_char ();
@@ -10682,48 +10901,82 @@ set_waiting_for_input (time_to_clear)
10682void 10901void
10683clear_waiting_for_input () 10902clear_waiting_for_input ()
10684{ 10903{
10685 /* Tell interrupt_signal not to throw back to read_char, */ 10904 /* Tell handle_interrupt not to throw back to read_char, */
10686 waiting_for_input = 0; 10905 waiting_for_input = 0;
10687 input_available_clear_time = 0; 10906 input_available_clear_time = 0;
10688} 10907}
10689 10908
10690/* This routine is called at interrupt level in response to C-g. 10909/* The SIGINT handler.
10691
10692 If interrupt_input, this is the handler for SIGINT. Otherwise, it
10693 is called from kbd_buffer_store_event, in handling SIGIO or
10694 SIGTINT.
10695 10910
10696 If `waiting_for_input' is non zero, then unless `echoing' is 10911 If we have a frame on the controlling tty, we assume that the
10697 nonzero, immediately throw back to read_char. 10912 SIGINT was generated by C-g, so we call handle_interrupt.
10698 10913 Otherwise, the handler kills Emacs. */
10699 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10700 eval to throw, when it gets a chance. If quit-flag is already
10701 non-nil, it stops the job right away. */
10702 10914
10703static SIGTYPE 10915static SIGTYPE
10704interrupt_signal (signalnum) /* If we don't have an argument, */ 10916interrupt_signal (signalnum) /* If we don't have an argument, */
10705 int signalnum; /* some compilers complain in signal calls. */ 10917 int signalnum; /* some compilers complain in signal calls. */
10706{ 10918{
10707 char c;
10708 /* Must preserve main program's value of errno. */ 10919 /* Must preserve main program's value of errno. */
10709 int old_errno = errno; 10920 int old_errno = errno;
10710 struct frame *sf = SELECTED_FRAME (); 10921 struct terminal *terminal;
10711 10922
10712#if defined (USG) && !defined (POSIX_SIGNALS) 10923#if defined (USG) && !defined (POSIX_SIGNALS)
10713 if (!read_socket_hook && NILP (Vwindow_system)) 10924 /* USG systems forget handlers when they are used;
10714 { 10925 must reestablish each time */
10715 /* USG systems forget handlers when they are used; 10926 signal (SIGINT, interrupt_signal);
10716 must reestablish each time */ 10927 signal (SIGQUIT, interrupt_signal);
10717 signal (SIGINT, interrupt_signal);
10718 signal (SIGQUIT, interrupt_signal);
10719 }
10720#endif /* USG */ 10928#endif /* USG */
10721 10929
10722 SIGNAL_THREAD_CHECK (signalnum); 10930 SIGNAL_THREAD_CHECK (signalnum);
10931
10932 /* See if we have an active terminal on our controlling tty. */
10933 terminal = get_named_tty ("/dev/tty");
10934 if (!terminal)
10935 {
10936 /* If there are no frames there, let's pretend that we are a
10937 well-behaving UN*X program and quit. */
10938 Fkill_emacs (Qnil);
10939 }
10940 else
10941 {
10942 /* Otherwise, the SIGINT was probably generated by C-g. */
10943
10944 /* Set internal_last_event_frame to the top frame of the
10945 controlling tty, if we have a frame there. We disable the
10946 interrupt key on secondary ttys, so the SIGINT must have come
10947 from the controlling tty. */
10948 internal_last_event_frame = terminal->display_info.tty->top_frame;
10949
10950 handle_interrupt ();
10951 }
10952
10953 errno = old_errno;
10954}
10955
10956/* This routine is called at interrupt level in response to C-g.
10957
10958 It is called from the SIGINT handler or kbd_buffer_store_event.
10959
10960 If `waiting_for_input' is non zero, then unless `echoing' is
10961 nonzero, immediately throw back to read_char.
10962
10963 Otherwise it sets the Lisp variable quit-flag not-nil. This causes
10964 eval to throw, when it gets a chance. If quit-flag is already
10965 non-nil, it stops the job right away. */
10966
10967static void
10968handle_interrupt ()
10969{
10970 char c;
10971
10723 cancel_echoing (); 10972 cancel_echoing ();
10724 10973
10974 /* XXX This code needs to be revised for multi-tty support. */
10725 if (!NILP (Vquit_flag) 10975 if (!NILP (Vquit_flag)
10726 && (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf))) 10976#ifndef MSDOS
10977 && get_named_tty ("/dev/tty")
10978#endif
10979 )
10727 { 10980 {
10728 /* If SIGINT isn't blocked, don't let us be interrupted by 10981 /* If SIGINT isn't blocked, don't let us be interrupted by
10729 another SIGINT, it might be harmful due to non-reentrancy 10982 another SIGINT, it might be harmful due to non-reentrancy
@@ -10731,7 +10984,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10731 sigblock (sigmask (SIGINT)); 10984 sigblock (sigmask (SIGINT));
10732 10985
10733 fflush (stdout); 10986 fflush (stdout);
10734 reset_sys_modes (); 10987 reset_all_sys_modes ();
10735 10988
10736#ifdef SIGTSTP /* Support possible in later USG versions */ 10989#ifdef SIGTSTP /* Support possible in later USG versions */
10737/* 10990/*
@@ -10810,7 +11063,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10810 printf ("Continuing...\n"); 11063 printf ("Continuing...\n");
10811#endif /* not MSDOS */ 11064#endif /* not MSDOS */
10812 fflush (stdout); 11065 fflush (stdout);
10813 init_sys_modes (); 11066 init_all_sys_modes ();
10814 sigfree (); 11067 sigfree ();
10815 } 11068 }
10816 else 11069 else
@@ -10838,9 +11091,7 @@ interrupt_signal (signalnum) /* If we don't have an argument, */
10838 } 11091 }
10839 11092
10840 if (waiting_for_input && !echoing) 11093 if (waiting_for_input && !echoing)
10841 quit_throw_to_read_char (); 11094 quit_throw_to_read_char ();
10842
10843 errno = old_errno;
10844} 11095}
10845 11096
10846/* Handle a C-g by making read_char return C-g. */ 11097/* Handle a C-g by making read_char return C-g. */
@@ -10873,75 +11124,202 @@ quit_throw_to_read_char ()
10873 _longjmp (getcjmp, 1); 11124 _longjmp (getcjmp, 1);
10874} 11125}
10875 11126
10876DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0, 11127DEFUN ("set-input-interrupt-mode", Fset_input_interrupt_mode, Sset_input_interrupt_mode, 1, 1, 0,
10877 doc: /* Set mode of reading keyboard input. 11128 doc: /* Set interrupt mode of reading keyboard input.
10878First arg INTERRUPT non-nil means use input interrupts; 11129If INTERRUPT is non-nil, Emacs will use input interrupts;
10879 nil means use CBREAK mode. 11130otherwise Emacs uses CBREAK mode.
10880Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal 11131
10881 (no effect except in CBREAK mode).
10882Third arg META t means accept 8-bit input (for a Meta key).
10883 META nil means ignore the top bit, on the assumption it is parity.
10884 Otherwise, accept 8-bit input and don't use the top bit for Meta.
10885Optional fourth arg QUIT if non-nil specifies character to use for quitting.
10886See also `current-input-mode'. */) 11132See also `current-input-mode'. */)
10887 (interrupt, flow, meta, quit) 11133 (interrupt)
10888 Lisp_Object interrupt, flow, meta, quit; 11134 Lisp_Object interrupt;
10889{ 11135{
10890 if (!NILP (quit) 11136 int new_interrupt_input;
10891 && (!INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400))
10892 error ("set-input-mode: QUIT must be an ASCII character");
10893
10894#ifdef POLL_FOR_INPUT
10895 stop_polling ();
10896#endif
10897
10898#ifndef DOS_NT
10899 /* this causes startup screen to be restored and messes with the mouse */
10900 reset_sys_modes ();
10901#endif
10902
10903#ifdef SIGIO 11137#ifdef SIGIO
10904/* Note SIGIO has been undef'd if FIONREAD is missing. */ 11138/* Note SIGIO has been undef'd if FIONREAD is missing. */
10905 if (read_socket_hook) 11139#ifdef HAVE_X_WINDOWS
11140 if (x_display_list != NULL)
10906 { 11141 {
10907 /* When using X, don't give the user a real choice, 11142 /* When using X, don't give the user a real choice,
10908 because we haven't implemented the mechanisms to support it. */ 11143 because we haven't implemented the mechanisms to support it. */
10909#ifdef NO_SOCK_SIGIO 11144#ifdef NO_SOCK_SIGIO
10910 interrupt_input = 0; 11145 new_interrupt_input = 0;
10911#else /* not NO_SOCK_SIGIO */ 11146#else /* not NO_SOCK_SIGIO */
10912 interrupt_input = 1; 11147 new_interrupt_input = 1;
10913#endif /* NO_SOCK_SIGIO */ 11148#endif /* NO_SOCK_SIGIO */
10914 } 11149 }
10915 else 11150 else
10916 interrupt_input = !NILP (interrupt); 11151#endif
11152 new_interrupt_input = !NILP (interrupt);
10917#else /* not SIGIO */ 11153#else /* not SIGIO */
10918 interrupt_input = 0; 11154 new_interrupt_input = 0;
10919#endif /* not SIGIO */ 11155#endif /* not SIGIO */
10920 11156
10921/* Our VMS input only works by interrupts, as of now. */ 11157/* Our VMS input only works by interrupts, as of now. */
10922#ifdef VMS 11158#ifdef VMS
10923 interrupt_input = 1; 11159 new_interrupt_input = 1;
10924#endif 11160#endif
10925 11161
10926 flow_control = !NILP (flow); 11162 if (new_interrupt_input != interrupt_input)
11163 {
11164#ifdef POLL_FOR_INPUT
11165 stop_polling ();
11166#endif
11167#ifndef DOS_NT
11168 /* this causes startup screen to be restored and messes with the mouse */
11169 reset_all_sys_modes ();
11170#endif
11171 interrupt_input = new_interrupt_input;
11172#ifndef DOS_NT
11173 init_all_sys_modes ();
11174#endif
11175
11176#ifdef POLL_FOR_INPUT
11177 poll_suppress_count = 1;
11178 start_polling ();
11179#endif
11180 }
11181 return Qnil;
11182}
11183
11184DEFUN ("set-output-flow-control", Fset_output_flow_control, Sset_output_flow_control, 1, 2, 0,
11185 doc: /* Enable or disable ^S/^Q flow control for output to TERMINAL.
11186If FLOW is non-nil, flow control is enabled and you cannot use C-s or
11187C-q in key sequences.
11188
11189This setting only has an effect on tty terminals and only when
11190Emacs reads input in CBREAK mode; see `set-input-interrupt-mode'.
11191
11192See also `current-input-mode'. */)
11193 (flow, terminal)
11194 Lisp_Object flow, terminal;
11195{
11196 struct terminal *t = get_terminal (terminal, 1);
11197 struct tty_display_info *tty;
11198 if (t == NULL || t->type != output_termcap)
11199 return Qnil;
11200 tty = t->display_info.tty;
11201
11202 if (tty->flow_control != !NILP (flow))
11203 {
11204#ifndef DOS_NT
11205 /* this causes startup screen to be restored and messes with the mouse */
11206 reset_sys_modes (tty);
11207#endif
11208
11209 tty->flow_control = !NILP (flow);
11210
11211#ifndef DOS_NT
11212 init_sys_modes (tty);
11213#endif
11214 }
11215 return Qnil;
11216}
11217
11218DEFUN ("set-input-meta-mode", Fset_input_meta_mode, Sset_input_meta_mode, 1, 2, 0,
11219 doc: /* Enable or disable 8-bit input on TERMINAL.
11220If META is t, Emacs will accept 8-bit input, and interpret the 8th
11221bit as the Meta modifier.
11222
11223If META is nil, Emacs will ignore the top bit, on the assumption it is
11224parity.
11225
11226Otherwise, Emacs will accept and pass through 8-bit input without
11227specially interpreting the top bit.
11228
11229This setting only has an effect on tty terminal devices.
11230
11231Optional parameter TERMINAL specifies the tty terminal device to use.
11232It may be a terminal id, a frame, or nil for the terminal used by the
11233currently selected frame.
11234
11235See also `current-input-mode'. */)
11236 (meta, terminal)
11237 Lisp_Object meta, terminal;
11238{
11239 struct terminal *t = get_terminal (terminal, 1);
11240 struct tty_display_info *tty;
11241 int new_meta;
11242
11243 if (t == NULL || t->type != output_termcap)
11244 return Qnil;
11245 tty = t->display_info.tty;
11246
10927 if (NILP (meta)) 11247 if (NILP (meta))
10928 meta_key = 0; 11248 new_meta = 0;
10929 else if (EQ (meta, Qt)) 11249 else if (EQ (meta, Qt))
10930 meta_key = 1; 11250 new_meta = 1;
10931 else 11251 else
10932 meta_key = 2; 11252 new_meta = 2;
10933 if (!NILP (quit))
10934 /* Don't let this value be out of range. */
10935 quit_char = XINT (quit) & (meta_key ? 0377 : 0177);
10936 11253
11254 if (tty->meta_key != new_meta)
11255 {
10937#ifndef DOS_NT 11256#ifndef DOS_NT
10938 init_sys_modes (); 11257 /* this causes startup screen to be restored and messes with the mouse */
11258 reset_sys_modes (tty);
10939#endif 11259#endif
10940 11260
10941#ifdef POLL_FOR_INPUT 11261 tty->meta_key = new_meta;
10942 poll_suppress_count = 1; 11262
10943 start_polling (); 11263#ifndef DOS_NT
11264 init_sys_modes (tty);
10944#endif 11265#endif
11266 }
11267 return Qnil;
11268}
11269
11270DEFUN ("set-quit-char", Fset_quit_char, Sset_quit_char, 1, 1, 0,
11271 doc: /* Specify character used for quitting.
11272QUIT must be an ASCII character.
11273
11274This function only has an effect on the controlling tty of the Emacs
11275process.
11276
11277See also `current-input-mode'. */)
11278 (quit)
11279 Lisp_Object quit;
11280{
11281 struct terminal *t = get_named_tty ("/dev/tty");
11282 struct tty_display_info *tty;
11283 if (t == NULL || t->type != output_termcap)
11284 return Qnil;
11285 tty = t->display_info.tty;
11286
11287 if (NILP (quit) || !INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)
11288 error ("QUIT must be an ASCII character");
11289
11290#ifndef DOS_NT
11291 /* this causes startup screen to be restored and messes with the mouse */
11292 reset_sys_modes (tty);
11293#endif
11294
11295 /* Don't let this value be out of range. */
11296 quit_char = XINT (quit) & (tty->meta_key == 0 ? 0177 : 0377);
11297
11298#ifndef DOS_NT
11299 init_sys_modes (tty);
11300#endif
11301
11302 return Qnil;
11303}
11304
11305DEFUN ("set-input-mode", Fset_input_mode, Sset_input_mode, 3, 4, 0,
11306 doc: /* Set mode of reading keyboard input.
11307First arg INTERRUPT non-nil means use input interrupts;
11308 nil means use CBREAK mode.
11309Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal
11310 (no effect except in CBREAK mode).
11311Third arg META t means accept 8-bit input (for a Meta key).
11312 META nil means ignore the top bit, on the assumption it is parity.
11313 Otherwise, accept 8-bit input and don't use the top bit for Meta.
11314Optional fourth arg QUIT if non-nil specifies character to use for quitting.
11315See also `current-input-mode'. */)
11316 (interrupt, flow, meta, quit)
11317 Lisp_Object interrupt, flow, meta, quit;
11318{
11319 Fset_input_interrupt_mode (interrupt);
11320 Fset_output_flow_control (flow, Qnil);
11321 Fset_input_meta_mode (meta, Qnil);
11322 Fset_quit_char (quit);
10945 return Qnil; 11323 return Qnil;
10946} 11324}
10947 11325
@@ -10962,10 +11340,21 @@ The elements of this list correspond to the arguments of
10962 () 11340 ()
10963{ 11341{
10964 Lisp_Object val[4]; 11342 Lisp_Object val[4];
11343 struct frame *sf = XFRAME (selected_frame);
10965 11344
10966 val[0] = interrupt_input ? Qt : Qnil; 11345 val[0] = interrupt_input ? Qt : Qnil;
10967 val[1] = flow_control ? Qt : Qnil; 11346 if (FRAME_TERMCAP_P (sf))
10968 val[2] = meta_key == 2 ? make_number (0) : meta_key == 1 ? Qt : Qnil; 11347 {
11348 val[1] = FRAME_TTY (sf)->flow_control ? Qt : Qnil;
11349 val[2] = (FRAME_TTY (sf)->meta_key == 2
11350 ? make_number (0)
11351 : (CURTTY ()->meta_key == 1 ? Qt : Qnil));
11352 }
11353 else
11354 {
11355 val[1] = Qnil;
11356 val[2] = Qt;
11357 }
10969 XSETFASTINT (val[3], quit_char); 11358 XSETFASTINT (val[3], quit_char);
10970 11359
10971 return Flist (sizeof (val) / sizeof (val[0]), val); 11360 return Flist (sizeof (val) / sizeof (val[0]), val);
@@ -11057,6 +11446,7 @@ init_kboard (kb)
11057 kb->Voverriding_terminal_local_map = Qnil; 11446 kb->Voverriding_terminal_local_map = Qnil;
11058 kb->Vlast_command = Qnil; 11447 kb->Vlast_command = Qnil;
11059 kb->Vreal_last_command = Qnil; 11448 kb->Vreal_last_command = Qnil;
11449 kb->Vkeyboard_translate_table = Qnil;
11060 kb->Vprefix_arg = Qnil; 11450 kb->Vprefix_arg = Qnil;
11061 kb->Vlast_prefix_arg = Qnil; 11451 kb->Vlast_prefix_arg = Qnil;
11062 kb->kbd_queue = Qnil; 11452 kb->kbd_queue = Qnil;
@@ -11071,6 +11461,10 @@ init_kboard (kb)
11071 kb->reference_count = 0; 11461 kb->reference_count = 0;
11072 kb->Vsystem_key_alist = Qnil; 11462 kb->Vsystem_key_alist = Qnil;
11073 kb->system_key_syms = Qnil; 11463 kb->system_key_syms = Qnil;
11464 kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
11465 Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
11466 kb->Vlocal_key_translation_map = Fmake_sparse_keymap (Qnil);
11467 Fset_keymap_parent (kb->Vlocal_key_translation_map, Vkey_translation_map);
11074 kb->Vdefault_minibuffer_frame = Qnil; 11468 kb->Vdefault_minibuffer_frame = Qnil;
11075} 11469}
11076 11470
@@ -11107,7 +11501,8 @@ delete_kboard (kb)
11107 && FRAMEP (selected_frame) 11501 && FRAMEP (selected_frame)
11108 && FRAME_LIVE_P (XFRAME (selected_frame))) 11502 && FRAME_LIVE_P (XFRAME (selected_frame)))
11109 { 11503 {
11110 current_kboard = XFRAME (selected_frame)->kboard; 11504 current_kboard = FRAME_KBOARD (XFRAME (selected_frame));
11505 single_kboard = 0;
11111 if (current_kboard == kb) 11506 if (current_kboard == kb)
11112 abort (); 11507 abort ();
11113 } 11508 }
@@ -11150,8 +11545,14 @@ init_keyboard ()
11150 wipe_kboard (current_kboard); 11545 wipe_kboard (current_kboard);
11151 init_kboard (current_kboard); 11546 init_kboard (current_kboard);
11152 11547
11153 if (!noninteractive && !read_socket_hook && NILP (Vwindow_system)) 11548 if (!noninteractive)
11154 { 11549 {
11550 /* Before multi-tty support, these handlers used to be installed
11551 only if the current session was a tty session. Now an Emacs
11552 session may have multiple display types, so we always handle
11553 SIGINT. There is special code in interrupt_signal to exit
11554 Emacs on SIGINT when there are no termcap frames on the
11555 controlling terminal. */
11155 signal (SIGINT, interrupt_signal); 11556 signal (SIGINT, interrupt_signal);
11156#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) 11557#if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
11157 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and 11558 /* For systems with SysV TERMIO, C-g is set up for both SIGINT and
@@ -11476,6 +11877,10 @@ syms_of_keyboard ()
11476 defsubr (&Stop_level); 11877 defsubr (&Stop_level);
11477 defsubr (&Sdiscard_input); 11878 defsubr (&Sdiscard_input);
11478 defsubr (&Sopen_dribble_file); 11879 defsubr (&Sopen_dribble_file);
11880 defsubr (&Sset_input_interrupt_mode);
11881 defsubr (&Sset_output_flow_control);
11882 defsubr (&Sset_input_meta_mode);
11883 defsubr (&Sset_quit_char);
11479 defsubr (&Sset_input_mode); 11884 defsubr (&Sset_input_mode);
11480 defsubr (&Scurrent_input_mode); 11885 defsubr (&Scurrent_input_mode);
11481 defsubr (&Sexecute_extended_command); 11886 defsubr (&Sexecute_extended_command);
@@ -11542,7 +11947,10 @@ In other words, the present command is the event that made the previous
11542command exit. 11947command exit.
11543 11948
11544The value `kill-region' is special; it means that the previous command 11949The value `kill-region' is special; it means that the previous command
11545was a kill command. */); 11950was a kill command.
11951
11952`last-command' has a separate binding for each terminal device.
11953See Info node `(elisp)Multiple displays'. */);
11546 11954
11547 DEFVAR_KBOARD ("real-last-command", Vreal_last_command, 11955 DEFVAR_KBOARD ("real-last-command", Vreal_last_command,
11548 doc: /* Same as `last-command', but never altered by Lisp code. */); 11956 doc: /* Same as `last-command', but never altered by Lisp code. */);
@@ -11654,8 +12062,8 @@ for that character after that prefix key. */);
11654Useful to set before you dump a modified Emacs. */); 12062Useful to set before you dump a modified Emacs. */);
11655 Vtop_level = Qnil; 12063 Vtop_level = Qnil;
11656 12064
11657 DEFVAR_LISP ("keyboard-translate-table", &Vkeyboard_translate_table, 12065 DEFVAR_KBOARD ("keyboard-translate-table", Vkeyboard_translate_table,
11658 doc: /* Translate table for keyboard input, or nil. 12066 doc: /* Translate table for local keyboard input, or nil.
11659If non-nil, the value should be a char-table. Each character read 12067If non-nil, the value should be a char-table. Each character read
11660from the keyboard is looked up in this char-table. If the value found 12068from the keyboard is looked up in this char-table. If the value found
11661there is non-nil, then it is used instead of the actual input character. 12069there is non-nil, then it is used instead of the actual input character.
@@ -11665,8 +12073,10 @@ If it is a string or vector of length N, character codes N and up are left
11665untranslated. In a vector, an element which is nil means "no translation". 12073untranslated. In a vector, an element which is nil means "no translation".
11666 12074
11667This is applied to the characters supplied to input methods, not their 12075This is applied to the characters supplied to input methods, not their
11668output. See also `translation-table-for-input'. */); 12076output. See also `translation-table-for-input'.
11669 Vkeyboard_translate_table = Qnil; 12077
12078This variable has a separate binding for each terminal. See Info node
12079`(elisp)Multiple displays'. */);
11670 12080
11671 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend, 12081 DEFVAR_BOOL ("cannot-suspend", &cannot_suspend,
11672 doc: /* Non-nil means to always spawn a subshell instead of suspending. 12082 doc: /* Non-nil means to always spawn a subshell instead of suspending.
@@ -11751,7 +12161,11 @@ buffer's local map, and the minor mode keymaps and text property keymaps.
11751It also replaces `overriding-local-map'. 12161It also replaces `overriding-local-map'.
11752 12162
11753This variable is intended to let commands such as `universal-argument' 12163This variable is intended to let commands such as `universal-argument'
11754set up a different keymap for reading the next command. */); 12164set up a different keymap for reading the next command.
12165
12166`overriding-terminal-local-map' has a separate binding for each
12167terminal device.
12168See Info node `(elisp)Multiple displays'. */);
11755 12169
11756 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map, 12170 DEFVAR_LISP ("overriding-local-map", &Voverriding_local_map,
11757 doc: /* Keymap that overrides all other local keymaps. 12171 doc: /* Keymap that overrides all other local keymaps.
@@ -11776,7 +12190,61 @@ and the minor mode maps regardless of `overriding-local-map'. */);
11776 doc: /* Alist of system-specific X windows key symbols. 12190 doc: /* Alist of system-specific X windows key symbols.
11777Each element should have the form (N . SYMBOL) where N is the 12191Each element should have the form (N . SYMBOL) where N is the
11778numeric keysym code (sans the \"system-specific\" bit 1<<28) 12192numeric keysym code (sans the \"system-specific\" bit 1<<28)
11779and SYMBOL is its name. */); 12193and SYMBOL is its name.
12194
12195`system-key-alist' has a separate binding for each terminal device.
12196See Info node `(elisp)Multiple displays'. */);
12197
12198 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map,
12199 doc: /* Keymap that translates key sequences to key sequences during input.
12200This is used mainly for mapping ASCII function key sequences into
12201real Emacs function key events (symbols).
12202
12203The `read-key-sequence' function replaces any subsequence bound by
12204`local-function-key-map' with its binding. More precisely, when the
12205active keymaps have no binding for the current key sequence but
12206`local-function-key-map' binds a suffix of the sequence to a vector or
12207string, `read-key-sequence' replaces the matching suffix with its
12208binding, and continues with the new sequence.
12209
12210If the binding is a function, it is called with one argument (the prompt)
12211and its return value (a key sequence) is used.
12212
12213The events that come from bindings in `local-function-key-map' are not
12214themselves looked up in `local-function-key-map'.
12215
12216For example, suppose `local-function-key-map' binds `ESC O P' to [f1].
12217Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
12218`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix key,
12219typing `ESC O P x' would return [f1 x].
12220
12221`local-function-key-map' has a separate binding for each terminal
12222device. See Info node `(elisp)Multiple displays'. If you need to
12223define a binding on all terminals, change `function-key-map'
12224instead. Initially, `local-function-key-map' is an empty keymap that
12225has `function-key-map' as its parent on all terminal devices. */);
12226
12227 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
12228 doc: /* The parent keymap of all `local-function-key-map' instances.
12229Function key definitions that apply to all terminal devices should go
12230here. If a mapping is defined in both the current
12231`local-function-key-map' binding and this variable, then the local
12232definition will take precendence. */);
12233 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
12234
12235 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map,
12236 doc: /* Keymap of key translations that can override keymaps.
12237This keymap works like `function-key-map', but comes after that,
12238and its non-prefix bindings override ordinary bindings.
12239
12240`key-translation-map' has a separate binding for each terminal device.
12241(See Info node `(elisp)Multiple displays'.) If you need to set a key
12242translation on all terminals, change `global-key-translation-map' instead. */);
12243
12244 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
12245 doc: /* The parent keymap of all `local-key-translation-map' instances.
12246Key translations that apply to all terminal devices should go here. */);
12247 Vkey_translation_map = Fmake_sparse_keymap (Qnil);
11780 12248
11781 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, 12249 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
11782 doc: /* List of deferred actions to be performed at a later time. 12250 doc: /* List of deferred actions to be performed at a later time.
@@ -11945,6 +12413,7 @@ mark_kboards ()
11945 mark_object (kb->Voverriding_terminal_local_map); 12413 mark_object (kb->Voverriding_terminal_local_map);
11946 mark_object (kb->Vlast_command); 12414 mark_object (kb->Vlast_command);
11947 mark_object (kb->Vreal_last_command); 12415 mark_object (kb->Vreal_last_command);
12416 mark_object (kb->Vkeyboard_translate_table);
11948 mark_object (kb->Vprefix_arg); 12417 mark_object (kb->Vprefix_arg);
11949 mark_object (kb->Vlast_prefix_arg); 12418 mark_object (kb->Vlast_prefix_arg);
11950 mark_object (kb->kbd_queue); 12419 mark_object (kb->kbd_queue);
@@ -11952,6 +12421,8 @@ mark_kboards ()
11952 mark_object (kb->Vlast_kbd_macro); 12421 mark_object (kb->Vlast_kbd_macro);
11953 mark_object (kb->Vsystem_key_alist); 12422 mark_object (kb->Vsystem_key_alist);
11954 mark_object (kb->system_key_syms); 12423 mark_object (kb->system_key_syms);
12424 mark_object (kb->Vlocal_function_key_map);
12425 mark_object (kb->Vlocal_key_translation_map);
11955 mark_object (kb->Vdefault_minibuffer_frame); 12426 mark_object (kb->Vdefault_minibuffer_frame);
11956 mark_object (kb->echo_string); 12427 mark_object (kb->echo_string);
11957 } 12428 }
diff --git a/src/keyboard.h b/src/keyboard.h
index 15e55ad4e67..a65bf8cfa02 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 2c760050c1d..181d43a4f48 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
@@ -3001,11 +2994,11 @@ You type Translation\n\
3001 outbuf = Fcurrent_buffer (); 2994 outbuf = Fcurrent_buffer ();
3002 2995
3003 /* Report on alternates for keys. */ 2996 /* Report on alternates for keys. */
3004 if (STRINGP (Vkeyboard_translate_table) && !NILP (prefix)) 2997 if (STRINGP (current_kboard->Vkeyboard_translate_table) && !NILP (prefix))
3005 { 2998 {
3006 int c; 2999 int c;
3007 const unsigned char *translate = SDATA (Vkeyboard_translate_table); 3000 const unsigned char *translate = SDATA (current_kboard->Vkeyboard_translate_table);
3008 int translate_len = SCHARS (Vkeyboard_translate_table); 3001 int translate_len = SCHARS (current_kboard->Vkeyboard_translate_table);
3009 3002
3010 for (c = 0; c < translate_len; c++) 3003 for (c = 0; c < translate_len; c++)
3011 if (translate[c] != c) 3004 if (translate[c] != c)
@@ -3028,14 +3021,14 @@ You type Translation\n\
3028 insert ("\n", 1); 3021 insert ("\n", 1);
3029 3022
3030 /* Insert calls signal_after_change which may GC. */ 3023 /* Insert calls signal_after_change which may GC. */
3031 translate = SDATA (Vkeyboard_translate_table); 3024 translate = SDATA (current_kboard->Vkeyboard_translate_table);
3032 } 3025 }
3033 3026
3034 insert ("\n", 1); 3027 insert ("\n", 1);
3035 } 3028 }
3036 3029
3037 if (!NILP (Vkey_translation_map)) 3030 if (!NILP (current_kboard->Vlocal_key_translation_map))
3038 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix, 3031 describe_map_tree (current_kboard->Vlocal_key_translation_map, 0, Qnil, prefix,
3039 "Key translations", nomenu, 1, 0, 0); 3032 "Key translations", nomenu, 1, 0, 0);
3040 3033
3041 3034
@@ -3124,8 +3117,8 @@ You type Translation\n\
3124 "\f\nGlobal Bindings", nomenu, 0, 1, 0); 3117 "\f\nGlobal Bindings", nomenu, 0, 1, 0);
3125 3118
3126 /* Print the function-key-map translations under this prefix. */ 3119 /* Print the function-key-map translations under this prefix. */
3127 if (!NILP (Vfunction_key_map)) 3120 if (!NILP (current_kboard->Vlocal_function_key_map))
3128 describe_map_tree (Vfunction_key_map, 0, Qnil, prefix, 3121 describe_map_tree (current_kboard->Vlocal_function_key_map, 0, Qnil, prefix,
3129 "\f\nFunction key map translations", nomenu, 1, 0, 0); 3122 "\f\nFunction key map translations", nomenu, 1, 0, 0);
3130 3123
3131 UNGCPRO; 3124 UNGCPRO;
@@ -4095,37 +4088,6 @@ the same way. The "active" keymaps in each alist are used before
4095`minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */); 4088`minor-mode-map-alist' and `minor-mode-overriding-map-alist'. */);
4096 Vemulation_mode_map_alists = Qnil; 4089 Vemulation_mode_map_alists = Qnil;
4097 4090
4098
4099 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
4100 doc: /* Keymap that translates key sequences to key sequences during input.
4101This is used mainly for mapping ASCII function key sequences into
4102real Emacs function key events (symbols).
4103
4104The `read-key-sequence' function replaces any subsequence bound by
4105`function-key-map' with its binding. More precisely, when the active
4106keymaps have no binding for the current key sequence but
4107`function-key-map' binds a suffix of the sequence to a vector or string,
4108`read-key-sequence' replaces the matching suffix with its binding, and
4109continues with the new sequence.
4110
4111If the binding is a function, it is called with one argument (the prompt)
4112and its return value (a key sequence) is used.
4113
4114The events that come from bindings in `function-key-map' are not
4115themselves looked up in `function-key-map'.
4116
4117For example, suppose `function-key-map' binds `ESC O P' to [f1].
4118Typing `ESC O P' to `read-key-sequence' would return [f1]. Typing
4119`C-x ESC O P' would return [?\\C-x f1]. If [f1] were a prefix
4120key, typing `ESC O P x' would return [f1 x]. */);
4121 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
4122
4123 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
4124 doc: /* Keymap of key translations that can override keymaps.
4125This keymap works like `function-key-map', but comes after that,
4126and its non-prefix bindings override ordinary bindings. */);
4127 Vkey_translation_map = Qnil;
4128
4129 staticpro (&Vmouse_events); 4091 staticpro (&Vmouse_events);
4130 Vmouse_events = Fcons (intern ("menu-bar"), 4092 Vmouse_events = Fcons (intern ("menu-bar"),
4131 Fcons (intern ("tool-bar"), 4093 Fcons (intern ("tool-bar"),
diff --git a/src/keymap.h b/src/keymap.h
index 1a51de705be..3268967089a 100644
--- a/src/keymap.h
+++ b/src/keymap.h
@@ -38,6 +38,7 @@ EXFUN (Fcurrent_active_maps, 2);
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 c5d9724e96c..b2bca426431 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2992,6 +2992,10 @@ extern Lisp_Object Qvertical_scroll_bar;
2992extern void discard_mouse_events P_ ((void)); 2992extern void discard_mouse_events P_ ((void));
2993EXFUN (Fevent_convert_list, 1); 2993EXFUN (Fevent_convert_list, 1);
2994EXFUN (Fread_key_sequence, 5); 2994EXFUN (Fread_key_sequence, 5);
2995EXFUN (Fset_input_interrupt_mode, 1);
2996EXFUN (Fset_output_flow_control, 2);
2997EXFUN (Fset_input_meta_mode, 2);
2998EXFUN (Fset_quit_char, 1);
2995EXFUN (Fset_input_mode, 4); 2999EXFUN (Fset_input_mode, 4);
2996extern int detect_input_pending P_ ((void)); 3000extern int detect_input_pending P_ ((void));
2997extern int detect_input_pending_ignore_squeezables P_ ((void)); 3001extern int detect_input_pending_ignore_squeezables P_ ((void));
@@ -3047,6 +3051,7 @@ EXFUN (Fvisible_frame_list, 0);
3047EXFUN (Fframe_parameter, 2); 3051EXFUN (Fframe_parameter, 2);
3048EXFUN (Fframe_parameters, 1); 3052EXFUN (Fframe_parameters, 1);
3049EXFUN (Fmodify_frame_parameters, 2); 3053EXFUN (Fmodify_frame_parameters, 2);
3054EXFUN (Fframe_with_environment, 1);
3050EXFUN (Fset_frame_height, 3); 3055EXFUN (Fset_frame_height, 3);
3051EXFUN (Fset_frame_width, 3); 3056EXFUN (Fset_frame_width, 3);
3052EXFUN (Fset_frame_size, 3); 3057EXFUN (Fset_frame_size, 3);
@@ -3115,7 +3120,7 @@ EXFUN (Fcall_process, MANY);
3115extern int child_setup P_ ((int, int, int, char **, int, Lisp_Object)); 3120extern int child_setup P_ ((int, int, int, char **, int, Lisp_Object));
3116extern void init_callproc_1 P_ ((void)); 3121extern void init_callproc_1 P_ ((void));
3117extern void init_callproc P_ ((void)); 3122extern void init_callproc P_ ((void));
3118extern void set_process_environment P_ ((void)); 3123extern void set_global_environment P_ ((void));
3119extern void syms_of_callproc P_ ((void)); 3124extern void syms_of_callproc P_ ((void));
3120 3125
3121/* defined in doc.c */ 3126/* defined in doc.c */
@@ -3177,28 +3182,31 @@ EXFUN (Fx_popup_menu, 2);
3177EXFUN (Fx_popup_dialog, 3); 3182EXFUN (Fx_popup_dialog, 3);
3178extern void syms_of_xmenu P_ ((void)); 3183extern void syms_of_xmenu P_ ((void));
3179 3184
3185/* defined in termchar.h */
3186struct tty_display_info;
3187
3188/* defined in termhooks.h */
3189struct terminal;
3190
3180/* defined in sysdep.c */ 3191/* defined in sysdep.c */
3181#ifndef HAVE_GET_CURRENT_DIR_NAME 3192#ifndef HAVE_GET_CURRENT_DIR_NAME
3182extern char *get_current_dir_name P_ ((void)); 3193extern char *get_current_dir_name P_ ((void));
3183#endif 3194#endif
3184extern void stuff_char P_ ((char c)); 3195extern void stuff_char P_ ((char c));
3185extern void init_sigio P_ ((int)); 3196extern void init_sigio P_ ((int));
3186extern void request_sigio P_ ((void));
3187extern void unrequest_sigio P_ ((void));
3188extern void reset_sys_modes P_ ((void));
3189extern void sys_subshell P_ ((void)); 3197extern void sys_subshell P_ ((void));
3190extern void sys_suspend P_ ((void)); 3198extern void sys_suspend P_ ((void));
3191extern void discard_tty_input P_ ((void)); 3199extern void discard_tty_input P_ ((void));
3192extern void init_sys_modes P_ ((void)); 3200extern void init_sys_modes P_ ((struct tty_display_info *));
3193extern void get_frame_size P_ ((int *, int *)); 3201extern void reset_sys_modes P_ ((struct tty_display_info *));
3202extern void init_all_sys_modes P_ ((void));
3203extern void reset_all_sys_modes P_ ((void));
3194extern void wait_for_termination P_ ((int)); 3204extern void wait_for_termination P_ ((int));
3195extern void flush_pending_output P_ ((int)); 3205extern void flush_pending_output P_ ((int));
3196extern void child_setup_tty P_ ((int)); 3206extern void child_setup_tty P_ ((int));
3197extern void setup_pty P_ ((int)); 3207extern void setup_pty P_ ((int));
3198extern int set_window_size P_ ((int, int, int)); 3208extern int set_window_size P_ ((int, int, int));
3199extern void create_process P_ ((Lisp_Object, char **, Lisp_Object)); 3209extern void create_process P_ ((Lisp_Object, char **, Lisp_Object));
3200extern int tabs_safe_p P_ ((void));
3201extern void init_baud_rate P_ ((void));
3202extern int emacs_open P_ ((const char *, int, int)); 3210extern int emacs_open P_ ((const char *, int, int));
3203extern int emacs_close P_ ((int)); 3211extern int emacs_close P_ ((int));
3204extern int emacs_read P_ ((int, char *, unsigned int)); 3212extern int emacs_read P_ ((int, char *, unsigned int));
@@ -3233,6 +3241,9 @@ extern void syms_of_dired P_ ((void));
3233extern void syms_of_term P_ ((void)); 3241extern void syms_of_term P_ ((void));
3234extern void fatal () NO_RETURN; 3242extern void fatal () NO_RETURN;
3235 3243
3244/* Defined in terminal.c */
3245extern void syms_of_terminal P_ ((void));
3246
3236#ifdef HAVE_WINDOW_SYSTEM 3247#ifdef HAVE_WINDOW_SYSTEM
3237/* Defined in fontset.c */ 3248/* Defined in fontset.c */
3238extern void syms_of_fontset P_ ((void)); 3249extern void syms_of_fontset P_ ((void));
diff --git a/src/lread.c b/src/lread.c
index a67fff1fc92..e8ff0ee63df 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"
@@ -447,8 +449,6 @@ static void substitute_in_interval P_ ((INTERVAL, Lisp_Object));
447 449
448/* Get a character from the tty. */ 450/* Get a character from the tty. */
449 451
450extern Lisp_Object read_char ();
451
452/* Read input events until we get one that's acceptable for our purposes. 452/* Read input events until we get one that's acceptable for our purposes.
453 453
454 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed 454 If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
@@ -500,10 +500,12 @@ read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
500 EMACS_ADD_TIME (end_time, end_time, wait_time); 500 EMACS_ADD_TIME (end_time, end_time, wait_time);
501 } 501 }
502 502
503 /* Read until we get an acceptable event. */ 503/* Read until we get an acceptable event. */
504 retry: 504 retry:
505 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0, 505 do
506 NUMBERP (seconds) ? &end_time : NULL); 506 val = read_char (0, 0, 0, (input_method ? Qnil : Qt), 0,
507 NUMBERP (seconds) ? &end_time : NULL);
508 while (INTEGERP (val) && XINT (val) == -2); /* wrong_kboard_jmpbuf */
507 509
508 if (BUFFERP (val)) 510 if (BUFFERP (val))
509 goto retry; 511 goto retry;
diff --git a/src/macfns.c b/src/macfns.c
index 34f80943497..d447ee90a4f 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -107,7 +107,6 @@ extern Lisp_Object Vwindow_system_version;
107int image_cache_refcount, dpyinfo_refcount; 107int image_cache_refcount, dpyinfo_refcount;
108#endif 108#endif
109 109
110
111#if 0 /* Use xstricmp instead. */ 110#if 0 /* Use xstricmp instead. */
112/* compare two strings ignoring case */ 111/* compare two strings ignoring case */
113 112
@@ -1367,11 +1366,11 @@ x_set_mouse_color (f, arg, oldval)
1367 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; 1366 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
1368 Cursor hourglass_cursor, horizontal_drag_cursor; 1367 Cursor hourglass_cursor, horizontal_drag_cursor;
1369 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 1368 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1370 unsigned long mask_color = x->background_pixel; 1369 unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
1371 1370
1372 /* Don't let pointers be invisible. */ 1371 /* Don't let pointers be invisible. */
1373 if (mask_color == pixel) 1372 if (mask_color == pixel)
1374 pixel = x->foreground_pixel; 1373 pixel = FRAME_FOREGROUND_PIXEL (f);
1375 1374
1376 f->output_data.mac->mouse_pixel = pixel; 1375 f->output_data.mac->mouse_pixel = pixel;
1377 1376
@@ -1444,7 +1443,7 @@ x_set_mouse_color (f, arg, oldval)
1444 BLOCK_INPUT; 1443 BLOCK_INPUT;
1445 1444
1446 if (FRAME_MAC_WINDOW (f) != 0) 1445 if (FRAME_MAC_WINDOW (f) != 0)
1447 rif->define_frame_cursor (f, cursor); 1446 FRAME_TERMINAL (f)->rif->define_frame_cursor (f, cursor);
1448 1447
1449 f->output_data.mac->text_cursor = cursor; 1448 f->output_data.mac->text_cursor = cursor;
1450 f->output_data.mac->nontext_cursor = nontext_cursor; 1449 f->output_data.mac->nontext_cursor = nontext_cursor;
@@ -1724,10 +1723,8 @@ x_set_tool_bar_lines (f, value, oldval)
1724 below the menu bar. */ 1723 below the menu bar. */
1725 if (FRAME_MAC_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) 1724 if (FRAME_MAC_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1726 { 1725 {
1727 updating_frame = f; 1726 clear_frame (f);
1728 clear_frame ();
1729 clear_current_matrices (f); 1727 clear_current_matrices (f);
1730 updating_frame = NULL;
1731 } 1728 }
1732 1729
1733 /* If the tool bar gets smaller, the internal border below it 1730 /* If the tool bar gets smaller, the internal border below it
@@ -2253,8 +2250,10 @@ XParseGeometry (string, x, y, width, height)
2253/* Create and set up the Mac window for frame F. */ 2250/* Create and set up the Mac window for frame F. */
2254 2251
2255static void 2252static void
2256mac_window (f) 2253mac_window (f, window_prompting, minibuffer_only)
2257 struct frame *f; 2254 struct frame *f;
2255 long window_prompting;
2256 int minibuffer_only;
2258{ 2257{
2259 Rect r; 2258 Rect r;
2260 2259
@@ -2427,8 +2426,8 @@ x_make_gc (f)
2427 = (XCreatePixmapFromBitmapData 2426 = (XCreatePixmapFromBitmapData
2428 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, 2427 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2429 gray_bits, gray_width, gray_height, 2428 gray_bits, gray_width, gray_height,
2430 f->output_data.x->foreground_pixel, 2429 FRAME_FOREGROUND_PIXEL (f),
2431 f->output_data.x->background_pixel, 2430 FRAME_BACKGROUND_PIXEL (f),
2432 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); 2431 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2433#endif 2432#endif
2434 2433
@@ -2523,15 +2522,15 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
2523 1, 1, 0, 2522 1, 1, 0,
2524 doc: /* Make a new window, which is called a "frame" in Emacs terms. 2523 doc: /* Make a new window, which is called a "frame" in Emacs terms.
2525Returns an Emacs frame object. 2524Returns an Emacs frame object.
2526ALIST is an alist of frame parameters. 2525PARAMETERS is an alist of frame parameters.
2527If the parameters specify that the frame should not have a minibuffer, 2526If the parameters specify that the frame should not have a minibuffer,
2528and do not specify a specific minibuffer window to use, 2527and do not specify a specific minibuffer window to use,
2529then `default-minibuffer-frame' must be a frame whose minibuffer can 2528then `default-minibuffer-frame' must be a frame whose minibuffer can
2530be shared by the new frame. 2529be shared by the new frame.
2531 2530
2532This function is an internal primitive--use `make-frame' instead. */) 2531This function is an internal primitive--use `make-frame' instead. */)
2533 (parms) 2532 (parameters)
2534 Lisp_Object parms; 2533 Lisp_Object parameters;
2535{ 2534{
2536 struct frame *f; 2535 struct frame *f;
2537 Lisp_Object frame, tem; 2536 Lisp_Object frame, tem;
@@ -2548,23 +2547,21 @@ This function is an internal primitive--use `make-frame' instead. */)
2548 2547
2549 check_mac (); 2548 check_mac ();
2550 2549
2551 parms = Fcopy_alist (parms);
2552
2553 /* Use this general default value to start with 2550 /* Use this general default value to start with
2554 until we know if this frame has a specified name. */ 2551 until we know if this frame has a specified name. */
2555 Vx_resource_name = Vinvocation_name; 2552 Vx_resource_name = Vinvocation_name;
2556 2553
2557 display = mac_get_arg (parms, Qdisplay, 0, 0, RES_TYPE_STRING); 2554 display = mac_get_arg (parameters, Qdisplay, 0, 0, RES_TYPE_STRING);
2558 if (EQ (display, Qunbound)) 2555 if (EQ (display, Qunbound))
2559 display = Qnil; 2556 display = Qnil;
2560 dpyinfo = check_x_display_info (display); 2557 dpyinfo = check_x_display_info (display);
2561#ifdef MULTI_KBOARD 2558#ifdef MULTI_KBOARD
2562 kb = dpyinfo->kboard; 2559 kb = dpyinfo->terminal->kboard;
2563#else 2560#else
2564 kb = &the_only_kboard; 2561 kb = &the_only_kboard;
2565#endif 2562#endif
2566 2563
2567 name = mac_get_arg (parms, Qname, "name", "Name", RES_TYPE_STRING); 2564 name = mac_get_arg (parameters, Qname, "name", "Name", RES_TYPE_STRING);
2568 if (!STRINGP (name) 2565 if (!STRINGP (name)
2569 && ! EQ (name, Qunbound) 2566 && ! EQ (name, Qunbound)
2570 && ! NILP (name)) 2567 && ! NILP (name))
@@ -2574,7 +2571,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2574 Vx_resource_name = name; 2571 Vx_resource_name = name;
2575 2572
2576 /* See if parent window is specified. */ 2573 /* See if parent window is specified. */
2577 parent = mac_get_arg (parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); 2574 parent = mac_get_arg (parameters, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
2578 if (EQ (parent, Qunbound)) 2575 if (EQ (parent, Qunbound))
2579 parent = Qnil; 2576 parent = Qnil;
2580 if (! NILP (parent)) 2577 if (! NILP (parent))
@@ -2584,8 +2581,8 @@ This function is an internal primitive--use `make-frame' instead. */)
2584 /* No need to protect DISPLAY because that's not used after passing 2581 /* No need to protect DISPLAY because that's not used after passing
2585 it to make_frame_without_minibuffer. */ 2582 it to make_frame_without_minibuffer. */
2586 frame = Qnil; 2583 frame = Qnil;
2587 GCPRO4 (parms, parent, name, frame); 2584 GCPRO4 (parameters, parent, name, frame);
2588 tem = mac_get_arg (parms, Qminibuffer, "minibuffer", "Minibuffer", 2585 tem = mac_get_arg (parameters, Qminibuffer, "minibuffer", "Minibuffer",
2589 RES_TYPE_SYMBOL); 2586 RES_TYPE_SYMBOL);
2590 if (EQ (tem, Qnone) || NILP (tem)) 2587 if (EQ (tem, Qnone) || NILP (tem))
2591 f = make_frame_without_minibuffer (Qnil, kb, display); 2588 f = make_frame_without_minibuffer (Qnil, kb, display);
@@ -2604,20 +2601,24 @@ This function is an internal primitive--use `make-frame' instead. */)
2604 /* Note that X Windows does support scroll bars. */ 2601 /* Note that X Windows does support scroll bars. */
2605 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; 2602 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
2606 2603
2604 f->terminal = dpyinfo->terminal;
2605 f->terminal->reference_count++;
2606
2607 f->output_method = output_mac; 2607 f->output_method = output_mac;
2608 f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output)); 2608 f->output_data.mac = (struct mac_output *) xmalloc (sizeof (struct mac_output));
2609 bzero (f->output_data.mac, sizeof (struct mac_output)); 2609 bzero (f->output_data.mac, sizeof (struct mac_output));
2610 FRAME_FONTSET (f) = -1; 2610 FRAME_FONTSET (f) = -1;
2611 record_unwind_protect (unwind_create_frame, frame);
2611 2612
2612 f->icon_name 2613 f->icon_name
2613 = mac_get_arg (parms, Qicon_name, "iconName", "Title", RES_TYPE_STRING); 2614 = mac_get_arg (parameters, Qicon_name, "iconName", "Title", RES_TYPE_STRING);
2614 if (! STRINGP (f->icon_name)) 2615 if (! STRINGP (f->icon_name))
2615 f->icon_name = Qnil; 2616 f->icon_name = Qnil;
2616 2617
2617/* FRAME_MAC_DISPLAY_INFO (f) = dpyinfo; */ 2618 /* XXX Is this needed? */
2619 /*FRAME_MAC_DISPLAY_INFO (f) = dpyinfo;*/
2618 2620
2619 /* With FRAME_MAC_DISPLAY_INFO set up, this unwind-protect is safe. */ 2621 /* With FRAME_MAC_DISPLAY_INFO set up, this unwind-protect is safe. */
2620 record_unwind_protect (unwind_create_frame, frame);
2621#if GLYPH_DEBUG 2622#if GLYPH_DEBUG
2622 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; 2623 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
2623 dpyinfo_refcount = dpyinfo->reference_count; 2624 dpyinfo_refcount = dpyinfo->reference_count;
@@ -2659,7 +2660,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2659 { 2660 {
2660 Lisp_Object font; 2661 Lisp_Object font;
2661 2662
2662 font = mac_get_arg (parms, Qfont, "font", "Font", RES_TYPE_STRING); 2663 font = mac_get_arg (parameters, Qfont, "font", "Font", RES_TYPE_STRING);
2663 2664
2664 BLOCK_INPUT; 2665 BLOCK_INPUT;
2665 /* First, try whatever font the caller has specified. */ 2666 /* First, try whatever font the caller has specified. */
@@ -2671,7 +2672,6 @@ This function is an internal primitive--use `make-frame' instead. */)
2671 else 2672 else
2672 font = x_new_font (f, SDATA (font)); 2673 font = x_new_font (f, SDATA (font));
2673 } 2674 }
2674
2675 /* Try out a font which we hope has bold and italic variations. */ 2675 /* Try out a font which we hope has bold and italic variations. */
2676#if USE_ATSUI 2676#if USE_ATSUI
2677 if (! STRINGP (font)) 2677 if (! STRINGP (font))
@@ -2690,48 +2690,50 @@ This function is an internal primitive--use `make-frame' instead. */)
2690 error ("Cannot find any usable font"); 2690 error ("Cannot find any usable font");
2691 UNBLOCK_INPUT; 2691 UNBLOCK_INPUT;
2692 2692
2693 x_set_frame_parameters (f, Fcons (Fcons (Qfont, font), Qnil)); 2693 x_default_parameter (f, parameters, Qfont, font,
2694 "font", "Font", RES_TYPE_STRING);
2694 } 2695 }
2695 2696
2696 x_default_parameter (f, parms, Qborder_width, make_number (0), 2697 /* XXX Shouldn't this be borderWidth, not borderwidth ?*/
2698 x_default_parameter (f, parameters, Qborder_width, make_number (0),
2697 "borderwidth", "BorderWidth", RES_TYPE_NUMBER); 2699 "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
2698 /* This defaults to 2 in order to match xterm. We recognize either 2700 /* This defaults to 2 in order to match xterm. We recognize either
2699 internalBorderWidth or internalBorder (which is what xterm calls 2701 internalBorderWidth or internalBorder (which is what xterm calls
2700 it). */ 2702 it). */
2701 if (NILP (Fassq (Qinternal_border_width, parms))) 2703 if (NILP (Fassq (Qinternal_border_width, parameters)))
2702 { 2704 {
2703 Lisp_Object value; 2705 Lisp_Object value;
2704 2706
2705 value = mac_get_arg (parms, Qinternal_border_width, 2707 value = mac_get_arg (parameters, Qinternal_border_width,
2706 "internalBorder", "InternalBorder", RES_TYPE_NUMBER); 2708 "internalBorder", "InternalBorder", RES_TYPE_NUMBER);
2707 if (! EQ (value, Qunbound)) 2709 if (! EQ (value, Qunbound))
2708 parms = Fcons (Fcons (Qinternal_border_width, value), 2710 parameters = Fcons (Fcons (Qinternal_border_width, value),
2709 parms); 2711 parameters);
2710 } 2712 }
2711 /* Default internalBorderWidth to 0 on Windows to match other programs. */ 2713 /* Default internalBorderWidth to 0 on Windows to match other programs. */
2712 x_default_parameter (f, parms, Qinternal_border_width, make_number (0), 2714 x_default_parameter (f, parameters, Qinternal_border_width, make_number (0),
2713 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER); 2715 "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER);
2714 x_default_parameter (f, parms, Qvertical_scroll_bars, Qright, 2716 x_default_parameter (f, parameters, Qvertical_scroll_bars, Qright,
2715 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL); 2717 "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
2716 2718
2717 /* Also do the stuff which must be set before the window exists. */ 2719 /* Also do the stuff which must be set before the window exists. */
2718 x_default_parameter (f, parms, Qforeground_color, build_string ("black"), 2720 x_default_parameter (f, parameters, Qforeground_color, build_string ("black"),
2719 "foreground", "Foreground", RES_TYPE_STRING); 2721 "foreground", "Foreground", RES_TYPE_STRING);
2720 x_default_parameter (f, parms, Qbackground_color, build_string ("white"), 2722 x_default_parameter (f, parameters, Qbackground_color, build_string ("white"),
2721 "background", "Background", RES_TYPE_STRING); 2723 "background", "Background", RES_TYPE_STRING);
2722 x_default_parameter (f, parms, Qmouse_color, build_string ("black"), 2724 x_default_parameter (f, parameters, Qmouse_color, build_string ("black"),
2723 "pointerColor", "Foreground", RES_TYPE_STRING); 2725 "pointerColor", "Foreground", RES_TYPE_STRING);
2724 x_default_parameter (f, parms, Qcursor_color, build_string ("black"), 2726 x_default_parameter (f, parameters, Qcursor_color, build_string ("black"),
2725 "cursorColor", "Foreground", RES_TYPE_STRING); 2727 "cursorColor", "Foreground", RES_TYPE_STRING);
2726 x_default_parameter (f, parms, Qborder_color, build_string ("black"), 2728 x_default_parameter (f, parameters, Qborder_color, build_string ("black"),
2727 "borderColor", "BorderColor", RES_TYPE_STRING); 2729 "borderColor", "BorderColor", RES_TYPE_STRING);
2728 x_default_parameter (f, parms, Qscreen_gamma, Qnil, 2730 x_default_parameter (f, parameters, Qscreen_gamma, Qnil,
2729 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); 2731 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
2730 x_default_parameter (f, parms, Qline_spacing, Qnil, 2732 x_default_parameter (f, parameters, Qline_spacing, Qnil,
2731 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); 2733 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
2732 x_default_parameter (f, parms, Qleft_fringe, Qnil, 2734 x_default_parameter (f, parameters, Qleft_fringe, Qnil,
2733 "leftFringe", "LeftFringe", RES_TYPE_NUMBER); 2735 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
2734 x_default_parameter (f, parms, Qright_fringe, Qnil, 2736 x_default_parameter (f, parameters, Qright_fringe, Qnil,
2735 "rightFringe", "RightFringe", RES_TYPE_NUMBER); 2737 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
2736 2738
2737 2739
@@ -2743,29 +2745,29 @@ This function is an internal primitive--use `make-frame' instead. */)
2743 happen. */ 2745 happen. */
2744 init_frame_faces (f); 2746 init_frame_faces (f);
2745 2747
2746 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1), 2748 x_default_parameter (f, parameters, Qmenu_bar_lines, make_number (1),
2747 "menuBar", "MenuBar", RES_TYPE_NUMBER); 2749 "menuBar", "MenuBar", RES_TYPE_NUMBER);
2748 x_default_parameter (f, parms, Qtool_bar_lines, make_number (1), 2750 x_default_parameter (f, parameters, Qtool_bar_lines, make_number (1),
2749 "toolBar", "ToolBar", RES_TYPE_NUMBER); 2751 "toolBar", "ToolBar", RES_TYPE_NUMBER);
2750 x_default_parameter (f, parms, Qbuffer_predicate, Qnil, 2752
2751 "bufferPredicate", "BufferPredicate", 2753 x_default_parameter (f, parameters, Qbuffer_predicate, Qnil,
2752 RES_TYPE_SYMBOL); 2754 "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
2753 x_default_parameter (f, parms, Qtitle, Qnil, 2755 x_default_parameter (f, parameters, Qtitle, Qnil,
2754 "title", "Title", RES_TYPE_STRING); 2756 "title", "Title", RES_TYPE_STRING);
2755 x_default_parameter (f, parms, Qfullscreen, Qnil, 2757 x_default_parameter (f, parameters, Qfullscreen, Qnil,
2756 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); 2758 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
2757 2759
2758 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window; 2760 f->output_data.mac->parent_desc = FRAME_MAC_DISPLAY_INFO (f)->root_window;
2759 2761
2760 /* Compute the size of the window. */ 2762 /* Compute the size of the window. */
2761 window_prompting = x_figure_window_size (f, parms, 1); 2763 window_prompting = x_figure_window_size (f, parameters, 1);
2762 2764
2763 tem = mac_get_arg (parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); 2765 tem = mac_get_arg (parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
2764 f->no_split = minibuffer_only || EQ (tem, Qt); 2766 f->no_split = minibuffer_only || EQ (tem, Qt);
2765 2767
2766 mac_window (f); 2768 mac_window (f, window_prompting, minibuffer_only);
2769 x_icon (f, parameters);
2767 2770
2768 x_icon (f, parms);
2769 x_make_gc (f); 2771 x_make_gc (f);
2770 2772
2771 /* Now consider the frame official. */ 2773 /* Now consider the frame official. */
@@ -2774,18 +2776,17 @@ This function is an internal primitive--use `make-frame' instead. */)
2774 2776
2775 /* We need to do this after creating the window, so that the 2777 /* We need to do this after creating the window, so that the
2776 icon-creation functions can say whose icon they're describing. */ 2778 icon-creation functions can say whose icon they're describing. */
2777 x_default_parameter (f, parms, Qicon_type, Qnil, 2779 x_default_parameter (f, parameters, Qicon_type, Qnil,
2778 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL); 2780 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
2779 2781
2780 x_default_parameter (f, parms, Qauto_raise, Qnil, 2782 x_default_parameter (f, parameters, Qauto_raise, Qnil,
2781 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); 2783 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
2782 x_default_parameter (f, parms, Qauto_lower, Qnil, 2784 x_default_parameter (f, parameters, Qauto_lower, Qnil,
2783 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); 2785 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
2784 x_default_parameter (f, parms, Qcursor_type, Qbox, 2786 x_default_parameter (f, parameters, Qcursor_type, Qbox,
2785 "cursorType", "CursorType", RES_TYPE_SYMBOL); 2787 "cursorType", "CursorType", RES_TYPE_SYMBOL);
2786 x_default_parameter (f, parms, Qscroll_bar_width, Qnil, 2788 x_default_parameter (f, parameters, Qscroll_bar_width, Qnil,
2787 "scrollBarWidth", "ScrollBarWidth", 2789 "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER);
2788 RES_TYPE_NUMBER);
2789 2790
2790 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. 2791 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
2791 Change will not be effected unless different from the current 2792 Change will not be effected unless different from the current
@@ -2793,8 +2794,8 @@ This function is an internal primitive--use `make-frame' instead. */)
2793 width = FRAME_COLS (f); 2794 width = FRAME_COLS (f);
2794 height = FRAME_LINES (f); 2795 height = FRAME_LINES (f);
2795 2796
2796 SET_FRAME_COLS (f, 0);
2797 FRAME_LINES (f) = 0; 2797 FRAME_LINES (f) = 0;
2798 SET_FRAME_COLS (f, 0);
2798 change_frame_size (f, height, width, 1, 0, 0); 2799 change_frame_size (f, height, width, 1, 0, 0);
2799 2800
2800 /* Tell the server what size and position, etc, we want, and how 2801 /* Tell the server what size and position, etc, we want, and how
@@ -2811,7 +2812,7 @@ This function is an internal primitive--use `make-frame' instead. */)
2811 { 2812 {
2812 Lisp_Object visibility; 2813 Lisp_Object visibility;
2813 2814
2814 visibility = mac_get_arg (parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL); 2815 visibility = mac_get_arg (parameters, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
2815 if (EQ (visibility, Qunbound)) 2816 if (EQ (visibility, Qunbound))
2816 visibility = Qt; 2817 visibility = Qt;
2817 2818
@@ -2833,10 +2834,12 @@ This function is an internal primitive--use `make-frame' instead. */)
2833 2834
2834 /* All remaining specified parameters, which have not been "used" 2835 /* All remaining specified parameters, which have not been "used"
2835 by x_get_arg and friends, now go in the misc. alist of the frame. */ 2836 by x_get_arg and friends, now go in the misc. alist of the frame. */
2836 for (tem = parms; !NILP (tem); tem = XCDR (tem)) 2837 for (tem = parameters; !NILP (tem); tem = XCDR (tem))
2837 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) 2838 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
2838 f->param_alist = Fcons (XCAR (tem), f->param_alist); 2839 f->param_alist = Fcons (XCAR (tem), f->param_alist);
2839 2840
2841 store_frame_param (f, Qwindow_system, Qmac);
2842
2840 UNGCPRO; 2843 UNGCPRO;
2841 2844
2842 /* Make sure windows on this frame appear in calls to next-window 2845 /* Make sure windows on this frame appear in calls to next-window
@@ -3299,9 +3302,6 @@ x_display_info_for_name (name)
3299 3302
3300 CHECK_STRING (name); 3303 CHECK_STRING (name);
3301 3304
3302 if (! EQ (Vwindow_system, intern ("mac")))
3303 error ("Not using Mac native windows");
3304
3305 for (dpyinfo = &one_mac_display_info, names = x_display_name_list; 3305 for (dpyinfo = &one_mac_display_info, names = x_display_name_list;
3306 dpyinfo; 3306 dpyinfo;
3307 dpyinfo = dpyinfo->next, names = XCDR (names)) 3307 dpyinfo = dpyinfo->next, names = XCDR (names))
@@ -3346,9 +3346,6 @@ terminate Emacs if we can't open the connection. */)
3346 if (! NILP (xrm_string)) 3346 if (! NILP (xrm_string))
3347 CHECK_STRING (xrm_string); 3347 CHECK_STRING (xrm_string);
3348 3348
3349 if (! EQ (Vwindow_system, intern ("mac")))
3350 error ("Not using Mac native windows");
3351
3352 if (! NILP (xrm_string)) 3349 if (! NILP (xrm_string))
3353 xrm_option = (unsigned char *) SDATA (xrm_string); 3350 xrm_option = (unsigned char *) SDATA (xrm_string);
3354 else 3351 else
@@ -3611,10 +3608,6 @@ start_hourglass ()
3611 EMACS_TIME delay; 3608 EMACS_TIME delay;
3612 int secs, usecs = 0; 3609 int secs, usecs = 0;
3613 3610
3614 /* Don't bother for ttys. */
3615 if (NILP (Vwindow_system))
3616 return;
3617
3618 cancel_hourglass (); 3611 cancel_hourglass ();
3619 3612
3620 if (INTEGERP (Vhourglass_delay) 3613 if (INTEGERP (Vhourglass_delay)
@@ -3827,7 +3820,7 @@ x_create_tip_frame (dpyinfo, parms, text)
3827 parms = Fcopy_alist (parms); 3820 parms = Fcopy_alist (parms);
3828 3821
3829#ifdef MULTI_KBOARD 3822#ifdef MULTI_KBOARD
3830 kb = dpyinfo->kboard; 3823 kb = dpyinfo->terminal->kboard;
3831#else 3824#else
3832 kb = &the_only_kboard; 3825 kb = &the_only_kboard;
3833#endif 3826#endif
diff --git a/src/macmenu.c b/src/macmenu.c
index 883a8463c2d..8305c89ee68 100644
--- a/src/macmenu.c
+++ b/src/macmenu.c
@@ -26,10 +26,10 @@ Boston, MA 02110-1301, USA. */
26#include <stdio.h> 26#include <stdio.h>
27 27
28#include "lisp.h" 28#include "lisp.h"
29#include "frame.h"
29#include "termhooks.h" 30#include "termhooks.h"
30#include "keyboard.h" 31#include "keyboard.h"
31#include "keymap.h" 32#include "keymap.h"
32#include "frame.h"
33#include "window.h" 33#include "window.h"
34#include "blockinput.h" 34#include "blockinput.h"
35#include "buffer.h" 35#include "buffer.h"
@@ -720,8 +720,8 @@ no quit occurs and `x-popup-menu' returns nil. */)
720 enum scroll_bar_part part; 720 enum scroll_bar_part part;
721 unsigned long time; 721 unsigned long time;
722 722
723 if (mouse_position_hook) 723 if (FRAME_TERMINAL (new_f)->mouse_position_hook)
724 (*mouse_position_hook) (&new_f, 1, &bar_window, 724 (*FRAME_TERMINAL (new_f)->mouse_position_hook) (&new_f, 1, &bar_window,
725 &part, &x, &y, &time); 725 &part, &x, &y, &time);
726 if (new_f != 0) 726 if (new_f != 0)
727 XSETFRAME (window, new_f); 727 XSETFRAME (window, new_f);
diff --git a/src/macterm.c b/src/macterm.c
index 0f2b053853d..8b3cee42f5c 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -226,14 +226,14 @@ void x_raise_frame P_ ((struct frame *));
226void x_set_window_size P_ ((struct frame *, int, int, int)); 226void x_set_window_size P_ ((struct frame *, int, int, int));
227void x_wm_set_window_state P_ ((struct frame *, int)); 227void x_wm_set_window_state P_ ((struct frame *, int));
228void x_wm_set_icon_pixmap P_ ((struct frame *, int)); 228void x_wm_set_icon_pixmap P_ ((struct frame *, int));
229void mac_initialize P_ ((void)); 229static void mac_initialize P_ ((void));
230static void x_font_min_bounds P_ ((XFontStruct *, int *, int *)); 230static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
231static int x_compute_min_glyph_bounds P_ ((struct frame *)); 231static int x_compute_min_glyph_bounds P_ ((struct frame *));
232static void x_update_end P_ ((struct frame *)); 232static void x_update_end P_ ((struct frame *));
233static void XTframe_up_to_date P_ ((struct frame *)); 233static void XTframe_up_to_date P_ ((struct frame *));
234static void XTset_terminal_modes P_ ((void)); 234static void XTset_terminal_modes P_ ((struct terminal *));
235static void XTreset_terminal_modes P_ ((void)); 235static void XTreset_terminal_modes P_ ((struct terminal *));
236static void x_clear_frame P_ ((void)); 236static void x_clear_frame P_ ((struct frame *));
237static void frame_highlight P_ ((struct frame *)); 237static void frame_highlight P_ ((struct frame *));
238static void frame_unhighlight P_ ((struct frame *)); 238static void frame_unhighlight P_ ((struct frame *));
239static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *)); 239static void x_new_focus_frame P_ ((struct x_display_info *, struct frame *));
@@ -261,6 +261,8 @@ static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
261static int is_emacs_window P_ ((WindowRef)); 261static int is_emacs_window P_ ((WindowRef));
262static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int)); 262static XCharStruct *mac_per_char_metric P_ ((XFontStruct *, XChar2b *, int));
263static void XSetFont P_ ((Display *, GC, XFontStruct *)); 263static void XSetFont P_ ((Display *, GC, XFontStruct *));
264static struct terminal *mac_create_terminal P_ ((struct mac_display_info *dpyinfo));
265
264 266
265#define GC_FORE_COLOR(gc) (&(gc)->fore_color) 267#define GC_FORE_COLOR(gc) (&(gc)->fore_color)
266#define GC_BACK_COLOR(gc) (&(gc)->back_color) 268#define GC_BACK_COLOR(gc) (&(gc)->back_color)
@@ -2389,7 +2391,7 @@ mac_destroy_fringe_bitmap (which)
2389 rarely happens). */ 2391 rarely happens). */
2390 2392
2391static void 2393static void
2392XTset_terminal_modes () 2394XTset_terminal_modes (struct terminal *t)
2393{ 2395{
2394} 2396}
2395 2397
@@ -2397,7 +2399,7 @@ XTset_terminal_modes ()
2397 the windows go away, and suspending requires no action. */ 2399 the windows go away, and suspending requires no action. */
2398 2400
2399static void 2401static void
2400XTreset_terminal_modes () 2402XTreset_terminal_modes (struct terminal *t)
2401{ 2403{
2402} 2404}
2403 2405
@@ -4047,15 +4049,8 @@ x_delete_glyphs (n)
4047 frame. Otherwise clear the selected frame. */ 4049 frame. Otherwise clear the selected frame. */
4048 4050
4049static void 4051static void
4050x_clear_frame () 4052x_clear_frame (struct frame *f)
4051{ 4053{
4052 struct frame *f;
4053
4054 if (updating_frame)
4055 f = updating_frame;
4056 else
4057 f = SELECTED_FRAME ();
4058
4059 /* Clearing the frame will erase any cursor, so mark them all as no 4054 /* Clearing the frame will erase any cursor, so mark them all as no
4060 longer visible. */ 4055 longer visible. */
4061 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); 4056 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -4573,7 +4568,7 @@ note_mouse_movement (frame, pos)
4573 clear_mouse_face (dpyinfo); 4568 clear_mouse_face (dpyinfo);
4574 dpyinfo->mouse_face_mouse_frame = 0; 4569 dpyinfo->mouse_face_mouse_frame = 0;
4575 if (!dpyinfo->grabbed) 4570 if (!dpyinfo->grabbed)
4576 rif->define_frame_cursor (frame, 4571 FRAME_RIF (frame)->define_frame_cursor (frame,
4577 frame->output_data.mac->nontext_cursor); 4572 frame->output_data.mac->nontext_cursor);
4578 } 4573 }
4579 4574
@@ -12531,6 +12526,7 @@ mac_term_init (display_name, xrm_option, resource_name)
12531 char *resource_name; 12526 char *resource_name;
12532{ 12527{
12533 struct mac_display_info *dpyinfo; 12528 struct mac_display_info *dpyinfo;
12529 struct terminal *terminal;
12534 12530
12535 BLOCK_INPUT; 12531 BLOCK_INPUT;
12536 12532
@@ -12546,6 +12542,13 @@ mac_term_init (display_name, xrm_option, resource_name)
12546 dpyinfo = &one_mac_display_info; 12542 dpyinfo = &one_mac_display_info;
12547 bzero (dpyinfo, sizeof (*dpyinfo)); 12543 bzero (dpyinfo, sizeof (*dpyinfo));
12548 12544
12545 terminal = mac_create_terminal (dpyinfo);
12546
12547 /* Set the name of the terminal. */
12548 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
12549 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
12550 terminal->name[SBYTES (display_name)] = 0;
12551
12549#ifdef MAC_OSX 12552#ifdef MAC_OSX
12550 dpyinfo->mac_id_name 12553 dpyinfo->mac_id_name
12551 = (char *) xmalloc (SCHARS (Vinvocation_name) 12554 = (char *) xmalloc (SCHARS (Vinvocation_name)
@@ -12747,44 +12750,71 @@ static struct redisplay_interface x_redisplay_interface =
12747 mac_shift_glyphs_for_insert 12750 mac_shift_glyphs_for_insert
12748}; 12751};
12749 12752
12750void 12753static struct terminal *
12754mac_create_terminal (struct mac_display_info *dpyinfo)
12755{
12756 struct terminal *terminal;
12757
12758 terminal = create_terminal ();
12759
12760 terminal->type = output_mac;
12761 terminal->display_info.mac = dpyinfo;
12762 dpyinfo->terminal = terminal;
12763
12764 terminal->clear_frame_hook = x_clear_frame;
12765 terminal->ins_del_lines_hook = x_ins_del_lines;
12766 terminal->delete_glyphs_hook = x_delete_glyphs;
12767 terminal->ring_bell_hook = XTring_bell;
12768 terminal->reset_terminal_modes_hook = XTreset_terminal_modes;
12769 terminal->set_terminal_modes_hook = XTset_terminal_modes;
12770 terminal->update_begin_hook = x_update_begin;
12771 terminal->update_end_hook = x_update_end;
12772 terminal->set_terminal_window_hook = XTset_terminal_window;
12773 terminal->read_socket_hook = XTread_socket;
12774 terminal->frame_up_to_date_hook = XTframe_up_to_date;
12775 terminal->mouse_position_hook = XTmouse_position;
12776 terminal->frame_rehighlight_hook = XTframe_rehighlight;
12777 terminal->frame_raise_lower_hook = XTframe_raise_lower;
12778 /* terminal->fullscreen_hook = XTfullscreen_hook; */
12779 terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
12780 terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
12781 terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
12782 terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
12783 terminal->delete_frame_hook = x_destroy_window;
12784 /* terminal->delete_terminal_hook = x_delete_terminal; */
12785
12786 terminal->rif = &x_redisplay_interface;
12787#if 0
12788 TTY_SCROLL_REGION_OK (CURTTY ()) = 1; /* we'll scroll partial frames */
12789 TTY_CHAR_INS_DEL_OK (CURTTY ()) = 1;
12790 TTY_LINE_INS_DEL_OK (CURTTY ()) = 1; /* we'll just blt 'em */
12791 TTY_FAST_CLEAR_END_OF_LINE (CURTTY ()) = 1; /* X does this well */
12792 TTY_MEMORY_BELOW_FRAME (CURTTY ()) = 0; /* we don't remember what
12793 scrolls off the
12794 bottom */
12795#else
12796 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
12797 terminal->char_ins_del_ok = 1;
12798 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
12799 terminal->fast_clear_end_of_line = 1; /* X does this well. */
12800 terminal->memory_below_frame = 0; /* We don't remember what scrolls
12801 off the bottom. */
12802
12803#endif
12804 return terminal;
12805}
12806
12807static void
12751mac_initialize () 12808mac_initialize ()
12752{ 12809{
12753 rif = &x_redisplay_interface; 12810
12754
12755 clear_frame_hook = x_clear_frame;
12756 ins_del_lines_hook = x_ins_del_lines;
12757 delete_glyphs_hook = x_delete_glyphs;
12758 ring_bell_hook = XTring_bell;
12759 reset_terminal_modes_hook = XTreset_terminal_modes;
12760 set_terminal_modes_hook = XTset_terminal_modes;
12761 update_begin_hook = x_update_begin;
12762 update_end_hook = x_update_end;
12763 set_terminal_window_hook = XTset_terminal_window;
12764 read_socket_hook = XTread_socket;
12765 frame_up_to_date_hook = XTframe_up_to_date;
12766 mouse_position_hook = XTmouse_position;
12767 frame_rehighlight_hook = XTframe_rehighlight;
12768 frame_raise_lower_hook = XTframe_raise_lower;
12769
12770 set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
12771 condemn_scroll_bars_hook = XTcondemn_scroll_bars;
12772 redeem_scroll_bar_hook = XTredeem_scroll_bar;
12773 judge_scroll_bars_hook = XTjudge_scroll_bars;
12774
12775 scroll_region_ok = 1; /* we'll scroll partial frames */
12776 char_ins_del_ok = 1;
12777 line_ins_del_ok = 1; /* we'll just blt 'em */
12778 fast_clear_end_of_line = 1; /* X does this well */
12779 memory_below_frame = 0; /* we don't remember what scrolls
12780 off the bottom */
12781 baud_rate = 19200; 12811 baud_rate = 19200;
12782 12812
12783 last_tool_bar_item = -1; 12813 last_tool_bar_item = -1;
12784 any_help_event_p = 0; 12814 any_help_event_p = 0;
12785 12815
12786 /* Try to use interrupt input; if we can't, then start polling. */ 12816 /* Try to use interrupt input; if we can't, then start polling. */
12787 Fset_input_mode (Qt, Qnil, Qt, Qnil); 12817 Fset_input_interrupt_mode (Qt);
12788 12818
12789 BLOCK_INPUT; 12819 BLOCK_INPUT;
12790 12820
@@ -12821,6 +12851,7 @@ mac_initialize ()
12821#endif 12851#endif
12822 12852
12823 UNBLOCK_INPUT; 12853 UNBLOCK_INPUT;
12854
12824} 12855}
12825 12856
12826 12857
diff --git a/src/macterm.h b/src/macterm.h
index 8a85e714ab5..9df9b1abcdb 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -64,6 +64,9 @@ struct mac_display_info
64 /* Chain of all mac_display_info structures. */ 64 /* Chain of all mac_display_info structures. */
65 struct mac_display_info *next; 65 struct mac_display_info *next;
66 66
67 /* The generic display parameters corresponding to this X display. */
68 struct terminal *terminal;
69
67 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). 70 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
68 The same cons cell also appears in x_display_name_list. */ 71 The same cons cell also appears in x_display_name_list. */
69 Lisp_Object name_list_element; 72 Lisp_Object name_list_element;
@@ -358,9 +361,6 @@ typedef struct mac_output mac_output;
358#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->window_desc) 361#define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->window_desc)
359#define FRAME_X_WINDOW(f) ((f)->output_data.mac->window_desc) 362#define FRAME_X_WINDOW(f) ((f)->output_data.mac->window_desc)
360 363
361#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
362#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
363
364#define FRAME_FONT(f) ((f)->output_data.mac->font) 364#define FRAME_FONT(f) ((f)->output_data.mac->font)
365#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) 365#define FRAME_FONTSET(f) ((f)->output_data.mac->fontset)
366 366
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 6611efbe3b2..d1ac66f7771 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -123,7 +123,8 @@ OBJ1 = $(BLD)/abbrev.$(O) \
123 $(BLD)/ccl.$(O) \ 123 $(BLD)/ccl.$(O) \
124 $(BLD)/fontset.$(O) \ 124 $(BLD)/fontset.$(O) \
125 $(BLD)/fringe.$(O) \ 125 $(BLD)/fringe.$(O) \
126 $(BLD)/image.$(O) 126 $(BLD)/image.$(O) \
127 $(BLD)/terminal.$(O)
127 128
128WIN32OBJ = $(BLD)/w32term.$(O) \ 129WIN32OBJ = $(BLD)/w32term.$(O) \
129 $(BLD)/w32xfns.$(O) \ 130 $(BLD)/w32xfns.$(O) \
@@ -380,6 +381,8 @@ $(BLD)/callproc.$(O) : \
380 $(SRC)/process.h \ 381 $(SRC)/process.h \
381 $(SRC)/syssignal.h \ 382 $(SRC)/syssignal.h \
382 $(SRC)/systty.h \ 383 $(SRC)/systty.h \
384 $(SRC)/frame.h \
385 $(SRC)/termhooks.h \
383 $(SRC)/w32.h 386 $(SRC)/w32.h
384 387
385$(BLD)/casefiddle.$(O) : \ 388$(BLD)/casefiddle.$(O) : \
@@ -469,6 +472,8 @@ $(BLD)/coding.$(O) : \
469 $(SRC)/composite.h \ 472 $(SRC)/composite.h \
470 $(SRC)/dispextern.h \ 473 $(SRC)/dispextern.h \
471 $(SRC)/intervals.h \ 474 $(SRC)/intervals.h \
475 $(SRC)/frame.h \
476 $(SRC)/termhooks.h \
472 $(SRC)/w32bdf.h \ 477 $(SRC)/w32bdf.h \
473 $(SRC)/w32gui.h \ 478 $(SRC)/w32gui.h \
474 $(SRC)/window.h 479 $(SRC)/window.h
@@ -496,7 +501,8 @@ $(BLD)/data.$(O) : \
496 $(SRC)/frame.h \ 501 $(SRC)/frame.h \
497 $(SRC)/keyboard.h \ 502 $(SRC)/keyboard.h \
498 $(SRC)/puresize.h \ 503 $(SRC)/puresize.h \
499 $(SRC)/syssignal.h 504 $(SRC)/syssignal.h \
505 $(SRC)/termhooks.h
500 506
501$(BLD)/dired.$(O) : \ 507$(BLD)/dired.$(O) : \
502 $(SRC)/dired.c \ 508 $(SRC)/dired.c \
@@ -699,6 +705,7 @@ $(BLD)/fns.$(O) : \
699 $(SRC)/keymap.h \ 705 $(SRC)/keymap.h \
700 $(SRC)/md5.h \ 706 $(SRC)/md5.h \
701 $(SRC)/systime.h \ 707 $(SRC)/systime.h \
708 $(SRC)/termhooks.h \
702 $(SRC)/w32bdf.h \ 709 $(SRC)/w32bdf.h \
703 $(SRC)/w32gui.h \ 710 $(SRC)/w32gui.h \
704 $(SRC)/window.h 711 $(SRC)/window.h
@@ -715,6 +722,7 @@ $(BLD)/fontset.$(O) : \
715 $(SRC)/fontset.h \ 722 $(SRC)/fontset.h \
716 $(SRC)/frame.h \ 723 $(SRC)/frame.h \
717 $(SRC)/keyboard.h \ 724 $(SRC)/keyboard.h \
725 $(SRC)/termhooks.h \
718 $(SRC)/w32bdf.h \ 726 $(SRC)/w32bdf.h \
719 $(SRC)/w32gui.h \ 727 $(SRC)/w32gui.h \
720 $(SRC)/window.h 728 $(SRC)/window.h
@@ -734,6 +742,7 @@ $(BLD)/frame.$(O) : \
734 $(SRC)/frame.h \ 742 $(SRC)/frame.h \
735 $(SRC)/keyboard.h \ 743 $(SRC)/keyboard.h \
736 $(SRC)/systime.h \ 744 $(SRC)/systime.h \
745 $(SRC)/termchar.h \
737 $(SRC)/termhooks.h \ 746 $(SRC)/termhooks.h \
738 $(SRC)/w32bdf.h \ 747 $(SRC)/w32bdf.h \
739 $(SRC)/w32gui.h \ 748 $(SRC)/w32gui.h \
@@ -903,6 +912,7 @@ $(BLD)/lread.$(O) : \
903 $(EMACS_ROOT)/src/config.h \ 912 $(EMACS_ROOT)/src/config.h \
904 $(EMACS_ROOT)/nt/inc/sys/file.h \ 913 $(EMACS_ROOT)/nt/inc/sys/file.h \
905 $(EMACS_ROOT)/src/epaths.h \ 914 $(EMACS_ROOT)/src/epaths.h \
915 $(SRC)/blockinput.h \
906 $(SRC)/buffer.h \ 916 $(SRC)/buffer.h \
907 $(SRC)/ccl.h \ 917 $(SRC)/ccl.h \
908 $(SRC)/charset.h \ 918 $(SRC)/charset.h \
@@ -957,6 +967,7 @@ $(BLD)/minibuf.$(O) : \
957 $(SRC)/keyboard.h \ 967 $(SRC)/keyboard.h \
958 $(SRC)/keymap.h \ 968 $(SRC)/keymap.h \
959 $(SRC)/syntax.h \ 969 $(SRC)/syntax.h \
970 $(SRC)/termhooks.h \
960 $(SRC)/w32bdf.h \ 971 $(SRC)/w32bdf.h \
961 $(SRC)/w32gui.h \ 972 $(SRC)/w32gui.h \
962 $(SRC)/window.h 973 $(SRC)/window.h
@@ -1118,6 +1129,7 @@ $(BLD)/scroll.$(O) : \
1118 $(SRC)/frame.h \ 1129 $(SRC)/frame.h \
1119 $(SRC)/keyboard.h \ 1130 $(SRC)/keyboard.h \
1120 $(SRC)/termchar.h \ 1131 $(SRC)/termchar.h \
1132 $(SRC)/termhooks.h \
1121 $(SRC)/w32bdf.h \ 1133 $(SRC)/w32bdf.h \
1122 $(SRC)/w32gui.h \ 1134 $(SRC)/w32gui.h \
1123 $(SRC)/window.h 1135 $(SRC)/window.h
@@ -1184,6 +1196,7 @@ $(BLD)/sysdep.$(O) : \
1184 $(EMACS_ROOT)/nt/inc/sys/file.h \ 1196 $(EMACS_ROOT)/nt/inc/sys/file.h \
1185 $(SRC)/atimer.h \ 1197 $(SRC)/atimer.h \
1186 $(SRC)/blockinput.h \ 1198 $(SRC)/blockinput.h \
1199 $(SRC)/cm.h \
1187 $(SRC)/dispextern.h \ 1200 $(SRC)/dispextern.h \
1188 $(SRC)/frame.h \ 1201 $(SRC)/frame.h \
1189 $(SRC)/keyboard.h \ 1202 $(SRC)/keyboard.h \
@@ -1229,6 +1242,18 @@ $(BLD)/termcap.$(O) : \
1229 $(EMACS_ROOT)/src/config.h \ 1242 $(EMACS_ROOT)/src/config.h \
1230 $(EMACS_ROOT)/nt/inc/sys/file.h 1243 $(EMACS_ROOT)/nt/inc/sys/file.h
1231 1244
1245$(BLD)/terminal.$(O) : \
1246 $(SRC)/terminal.c \
1247 $(EMACS_ROOT)/src/s/ms-w32.h \
1248 $(EMACS_ROOT)/src/m/intel386.h \
1249 $(EMACS_ROOT)/src/config.h \
1250 $(SRC)/charset.h \
1251 $(SRC)/coding.h \
1252 $(SRC)/frame.h \
1253 $(SRC)/keyboard.h \
1254 $(SRC)/termchar.h \
1255 $(SRC)/termhooks.h
1256
1232$(BLD)/textprop.$(O) : \ 1257$(BLD)/textprop.$(O) : \
1233 $(SRC)/textprop.c \ 1258 $(SRC)/textprop.c \
1234 $(EMACS_ROOT)/src/s/ms-w32.h \ 1259 $(EMACS_ROOT)/src/s/ms-w32.h \
@@ -1342,6 +1367,8 @@ $(BLD)/xfaces.$(O): \
1342 $(SRC)/intervals.h \ 1367 $(SRC)/intervals.h \
1343 $(SRC)/keyboard.h \ 1368 $(SRC)/keyboard.h \
1344 $(SRC)/systime.h \ 1369 $(SRC)/systime.h \
1370 $(SRC)/termchar.h \
1371 $(SRC)/termhooks.h \
1345 $(SRC)/w32bdf.h \ 1372 $(SRC)/w32bdf.h \
1346 $(SRC)/w32gui.h \ 1373 $(SRC)/w32gui.h \
1347 $(SRC)/w32term.h \ 1374 $(SRC)/w32term.h \
diff --git a/src/minibuf.c b/src/minibuf.c
index 863528819f8..489c714fcb4 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 ef65597f7e7..fc14be2705c 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 adf2743ba21..16d7b7dba17 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 cae80d1acfe..cd3d6438bff 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 4515b7a2c86..dfb97b8d615 100644
--- a/src/process.c
+++ b/src/process.c
@@ -130,11 +130,11 @@ Boston, MA 02110-1301, USA. */
130#include "charset.h" 130#include "charset.h"
131#include "coding.h" 131#include "coding.h"
132#include "process.h" 132#include "process.h"
133#include "frame.h"
133#include "termhooks.h" 134#include "termhooks.h"
134#include "termopts.h" 135#include "termopts.h"
135#include "commands.h" 136#include "commands.h"
136#include "keyboard.h" 137#include "keyboard.h"
137#include "frame.h"
138#include "blockinput.h" 138#include "blockinput.h"
139#include "dispextern.h" 139#include "dispextern.h"
140#include "composite.h" 140#include "composite.h"
@@ -3157,6 +3157,10 @@ usage: (make-network-process &rest ARGS) */)
3157 3157
3158 open_socket: 3158 open_socket:
3159 3159
3160#ifdef __ultrix__
3161 /* Previously this was compiled unconditionally, but that seems
3162 unnecessary on modern systems, and `unrequest_sigio' was a noop
3163 under X anyway. --lorentey */
3160 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR) 3164 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
3161 when connect is interrupted. So let's not let it get interrupted. 3165 when connect is interrupted. So let's not let it get interrupted.
3162 Note we do not turn off polling, because polling is only used 3166 Note we do not turn off polling, because polling is only used
@@ -3173,6 +3177,7 @@ usage: (make-network-process &rest ARGS) */)
3173 record_unwind_protect (unwind_request_sigio, Qnil); 3177 record_unwind_protect (unwind_request_sigio, Qnil);
3174 unrequest_sigio (); 3178 unrequest_sigio ();
3175 } 3179 }
3180#endif
3176 3181
3177 /* Do this in case we never enter the for-loop below. */ 3182 /* Do this in case we never enter the for-loop below. */
3178 count1 = SPECPDL_INDEX (); 3183 count1 = SPECPDL_INDEX ();
@@ -6956,20 +6961,12 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6956 6961
6957 6962
6958 6963
6959/* The first time this is called, assume keyboard input comes from DESC 6964/* Add DESC to the set of keyboard input descriptors. */
6960 instead of from where we used to expect it.
6961 Subsequent calls mean assume input keyboard can come from DESC
6962 in addition to other places. */
6963
6964static int add_keyboard_wait_descriptor_called_flag;
6965 6965
6966void 6966void
6967add_keyboard_wait_descriptor (desc) 6967add_keyboard_wait_descriptor (desc)
6968 int desc; 6968 int desc;
6969{ 6969{
6970 if (! add_keyboard_wait_descriptor_called_flag)
6971 FD_CLR (0, &input_wait_mask);
6972 add_keyboard_wait_descriptor_called_flag = 1;
6973 FD_SET (desc, &input_wait_mask); 6970 FD_SET (desc, &input_wait_mask);
6974 FD_SET (desc, &non_process_wait_mask); 6971 FD_SET (desc, &non_process_wait_mask);
6975 if (desc > max_keyboard_desc) 6972 if (desc > max_keyboard_desc)
@@ -7075,7 +7072,12 @@ init_process ()
7075 process_output_skip = 0; 7072 process_output_skip = 0;
7076#endif 7073#endif
7077 7074
7075 /* Don't do this, it caused infinite select loops. The display
7076 method should call add_keyboard_wait_descriptor on stdin if it
7077 needs that. */
7078#if 0
7078 FD_SET (0, &input_wait_mask); 7079 FD_SET (0, &input_wait_mask);
7080#endif
7079 7081
7080 Vprocess_alist = Qnil; 7082 Vprocess_alist = Qnil;
7081#ifdef SIGCHLD 7083#ifdef SIGCHLD
diff --git a/src/puresize.h b/src/puresize.h
index 8ce51dbfd8b..5f72dfb04cc 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 (1140000 + SYSTEM_PURESIZE_EXTRA + SITELOAD_PURESIZE_EXTRA) 46#define BASE_PURESIZE (1161000 + 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/s/darwin.h b/src/s/darwin.h
index 183aecaf5d8..a2a3d862f80 100644
--- a/src/s/darwin.h
+++ b/src/s/darwin.h
@@ -50,6 +50,8 @@ Boston, MA 02110-1301, USA. */
50#ifdef MAC_OSX 50#ifdef MAC_OSX
51#ifdef HAVE_CARBON 51#ifdef HAVE_CARBON
52#define MAC_OS 52#define MAC_OS
53/* We need a little extra space, see ../../lisp/loadup.el. */
54#define SYSTEM_PURESIZE_EXTRA 30000
53#endif 55#endif
54#endif 56#endif
55 57
diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h
index a5898410b3b..e4f5cc119e0 100644
--- a/src/s/ms-w32.h
+++ b/src/s/ms-w32.h
@@ -480,7 +480,7 @@ extern char *get_emacs_configuration_options (void);
480/* We need a little extra space, see ../../lisp/loadup.el. 480/* We need a little extra space, see ../../lisp/loadup.el.
481 The number below comes from 23923 bytes worth (as of 2006-04) 481 The number below comes from 23923 bytes worth (as of 2006-04)
482 of w32-specific files loaded by loadup.el, plus 1K spare. */ 482 of w32-specific files loaded by loadup.el, plus 1K spare. */
483#define SYSTEM_PURESIZE_EXTRA 25000 483#define SYSTEM_PURESIZE_EXTRA 50000
484 484
485/* For unexec to work on Alpha systems, we need to put Emacs' 485/* For unexec to work on Alpha systems, we need to put Emacs'
486 initialized data into a separate section from the CRT initialized 486 initialized data into a separate section from the CRT initialized
diff --git a/src/scroll.c b/src/scroll.c
index 48a40fe23d2..5a59c69003e 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 f2170dabed7..ff7a4f5f42c 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#ifdef HAVE_GPM 1750#ifdef HAVE_GPM
1679 if (term_gpm) 1751 if (term_gpm)
1680 { 1752 {
@@ -1690,7 +1762,7 @@ init_sys_modes ()
1690 1762
1691#ifdef BSD4_1 1763#ifdef BSD4_1
1692 if (interrupt_input) 1764 if (interrupt_input)
1693 init_sigio (input_fd); 1765 init_sigio (fileno (tty_out->input));
1694#endif 1766#endif
1695 1767
1696#ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */ 1768#ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
@@ -1700,53 +1772,56 @@ init_sys_modes ()
1700 /* This symbol is defined on recent USG systems. 1772 /* This symbol is defined on recent USG systems.
1701 Someone says without this call USG won't really buffer the file 1773 Someone says without this call USG won't really buffer the file
1702 even with a call to setbuf. */ 1774 even with a call to setbuf. */
1703 setvbuf (stdout, (char *) _sobuf, _IOFBF, sizeof _sobuf); 1775 setvbuf (tty_out->output, (char *) _sobuf, _IOFBF, sizeof _sobuf);
1704#else 1776#else
1705 setbuf (stdout, (char *) _sobuf); 1777 setbuf (tty_out->output, (char *) _sobuf);
1706#endif
1707#ifdef HAVE_WINDOW_SYSTEM
1708 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1709 needs the initialization code below. */
1710 if (EQ (Vwindow_system, Qnil)
1711#ifndef WINDOWSNT
1712 /* When running in tty mode on NT/Win95, we have a read_socket
1713 hook, but still need the rest of the initialization code below. */
1714 && (! read_socket_hook)
1715#endif 1778#endif
1716 )
1717#endif
1718 set_terminal_modes ();
1719 1779
1720 if (!term_initted 1780 tty_set_terminal_modes (tty_out->terminal);
1721 && FRAMEP (Vterminal_frame)
1722 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame)))
1723 init_frame_faces (XFRAME (Vterminal_frame));
1724 1781
1725 if (term_initted && no_redraw_on_reenter) 1782 if (!tty_out->term_initted)
1726 { 1783 {
1784 Lisp_Object tail, frame;
1785 FOR_EACH_FRAME (tail, frame)
1786 {
1787 /* XXX This needs to be revised. */
1788 if (FRAME_TERMCAP_P (XFRAME (frame))
1789 && FRAME_TTY (XFRAME (frame)) == tty_out)
1790 init_frame_faces (XFRAME (frame));
1791 }
1792 }
1793
1794 if (tty_out->term_initted && no_redraw_on_reenter)
1795 {
1796 /* XXX This seems wrong on multi-tty. */
1727 if (display_completed) 1797 if (display_completed)
1728 direct_output_forward_char (0); 1798 direct_output_forward_char (0);
1729 } 1799 }
1730 else 1800 else
1731 { 1801 {
1802 Lisp_Object tail, frame;
1732 frame_garbaged = 1; 1803 frame_garbaged = 1;
1733 if (FRAMEP (Vterminal_frame)) 1804 FOR_EACH_FRAME (tail, frame)
1734 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; 1805 {
1806 if (FRAME_TERMCAP_P (XFRAME (frame))
1807 && FRAME_TTY (XFRAME (frame)) == tty_out)
1808 FRAME_GARBAGED_P (XFRAME (frame)) = 1;
1809 }
1735 } 1810 }
1736 1811
1737 term_initted = 1; 1812 tty_out->term_initted = 1;
1738} 1813}
1739 1814
1740/* Return nonzero if safe to use tabs in output. 1815/* Return nonzero if safe to use tabs in output.
1741 At the time this is called, init_sys_modes has not been done yet. */ 1816 At the time this is called, init_sys_modes has not been done yet. */
1742 1817
1743int 1818int
1744tabs_safe_p () 1819tabs_safe_p (int fd)
1745{ 1820{
1746 struct emacs_tty tty; 1821 struct emacs_tty etty;
1747 1822
1748 EMACS_GET_TTY (input_fd, &tty); 1823 EMACS_GET_TTY (fd, &etty);
1749 return EMACS_TTY_TABS_OK (&tty); 1824 return EMACS_TTY_TABS_OK (&etty);
1750} 1825}
1751 1826
1752/* Get terminal size from system. 1827/* Get terminal size from system.
@@ -1754,8 +1829,7 @@ tabs_safe_p ()
1754 We store 0 if there's no valid information. */ 1829 We store 0 if there's no valid information. */
1755 1830
1756void 1831void
1757get_frame_size (widthp, heightp) 1832get_tty_size (int fd, int *widthp, int *heightp)
1758 int *widthp, *heightp;
1759{ 1833{
1760 1834
1761#ifdef TIOCGWINSZ 1835#ifdef TIOCGWINSZ
@@ -1763,7 +1837,7 @@ get_frame_size (widthp, heightp)
1763 /* BSD-style. */ 1837 /* BSD-style. */
1764 struct winsize size; 1838 struct winsize size;
1765 1839
1766 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1) 1840 if (ioctl (fd, TIOCGWINSZ, &size) == -1)
1767 *widthp = *heightp = 0; 1841 *widthp = *heightp = 0;
1768 else 1842 else
1769 { 1843 {
@@ -1777,7 +1851,7 @@ get_frame_size (widthp, heightp)
1777 /* SunOS - style. */ 1851 /* SunOS - style. */
1778 struct ttysize size; 1852 struct ttysize size;
1779 1853
1780 if (ioctl (input_fd, TIOCGSIZE, &size) == -1) 1854 if (ioctl (fd, TIOCGSIZE, &size) == -1)
1781 *widthp = *heightp = 0; 1855 *widthp = *heightp = 0;
1782 else 1856 else
1783 { 1857 {
@@ -1809,7 +1883,6 @@ get_frame_size (widthp, heightp)
1809 *widthp = 0; 1883 *widthp = 0;
1810 *heightp = 0; 1884 *heightp = 0;
1811#endif 1885#endif
1812
1813#endif /* not VMS */ 1886#endif /* not VMS */
1814#endif /* not SunOS-style */ 1887#endif /* not SunOS-style */
1815#endif /* not BSD-style */ 1888#endif /* not BSD-style */
@@ -1853,37 +1926,58 @@ set_window_size (fd, height, width)
1853} 1926}
1854 1927
1855 1928
1856/* Prepare the terminal for exiting Emacs; move the cursor to the 1929
1857 bottom of the frame, turn off interrupt-driven I/O, etc. */ 1930/* Prepare all terminal devices for exiting Emacs. */
1931
1858void 1932void
1859reset_sys_modes () 1933reset_all_sys_modes (void)
1860{ 1934{
1861 struct frame *sf; 1935 struct tty_display_info *tty;
1936 for (tty = tty_list; tty; tty = tty->next)
1937 reset_sys_modes (tty);
1938}
1862 1939
1940/* Prepare the terminal for closing it; move the cursor to the
1941 bottom of the frame, turn off interrupt-driven I/O, etc. */
1942
1943void
1944reset_sys_modes (tty_out)
1945 struct tty_display_info *tty_out;
1946{
1863 if (noninteractive) 1947 if (noninteractive)
1864 { 1948 {
1865 fflush (stdout); 1949 fflush (stdout);
1866 return; 1950 return;
1867 } 1951 }
1868 if (!term_initted) 1952 if (!tty_out->term_initted)
1869 return; 1953 return;
1870#ifdef HAVE_WINDOW_SYSTEM 1954
1871 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore 1955 if (!tty_out->output)
1872 needs the clean-up code below. */ 1956 return; /* The tty is suspended. */
1873 if (!EQ (Vwindow_system, Qnil) 1957
1874#ifndef WINDOWSNT 1958 /* Go to and clear the last line of the terminal. */
1875 /* When running in tty mode on NT/Win95, we have a read_socket 1959
1876 hook, but still need the rest of the clean-up code below. */ 1960 cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
1877 || read_socket_hook 1961
1878#endif 1962 /* Code adapted from tty_clear_end_of_line. */
1879 ) 1963 if (tty_out->TS_clr_line)
1880 return; 1964 {
1881#endif 1965 emacs_tputs (tty_out, tty_out->TS_clr_line, 1, cmputc);
1882 sf = SELECTED_FRAME (); 1966 }
1883 cursor_to (FRAME_LINES (sf) - 1, 0); 1967 else
1884 clear_end_of_line (FRAME_COLS (sf)); 1968 { /* have to do it the hard way */
1885 /* clear_end_of_line may move the cursor */ 1969 int i;
1886 cursor_to (FRAME_LINES (sf) - 1, 0); 1970 tty_turn_off_insert (tty_out);
1971
1972 for (i = curX (tty_out); i < FrameCols (tty_out) - 1; i++)
1973 {
1974 fputc (' ', tty_out->output);
1975 }
1976 }
1977
1978 cmgoto (tty_out, FrameRows (tty_out) - 1, 0);
1979 fflush (tty_out->output);
1980
1887#if defined (IBMR2AIX) && defined (AIXHFT) 1981#if defined (IBMR2AIX) && defined (AIXHFT)
1888 { 1982 {
1889 /* HFT devices normally use ^J as a LF/CR. We forced it to 1983 /* HFT devices normally use ^J as a LF/CR. We forced it to
@@ -1895,12 +1989,12 @@ reset_sys_modes ()
1895 } 1989 }
1896#endif 1990#endif
1897 1991
1898 reset_terminal_modes (); 1992 tty_reset_terminal_modes (tty_out->terminal);
1899 fflush (stdout); 1993
1900#ifdef BSD_SYSTEM 1994#ifdef BSD_SYSTEM
1901#ifndef BSD4_1 1995#ifndef BSD4_1
1902 /* Avoid possible loss of output when changing terminal modes. */ 1996 /* Avoid possible loss of output when changing terminal modes. */
1903 fsync (fileno (stdout)); 1997 fsync (fileno (tty_out->output));
1904#endif 1998#endif
1905#endif 1999#endif
1906 2000
@@ -1909,22 +2003,25 @@ reset_sys_modes ()
1909#ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ 2003#ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1910 if (interrupt_input) 2004 if (interrupt_input)
1911 { 2005 {
1912 reset_sigio (); 2006 reset_sigio (fileno (tty_out->input));
1913 fcntl (input_fd, F_SETOWN, old_fcntl_owner); 2007 fcntl (fileno (tty_out->input), F_SETOWN,
2008 old_fcntl_owner[fileno (tty_out->input)]);
1914 } 2009 }
1915#endif /* F_SETOWN */ 2010#endif /* F_SETOWN */
1916#endif /* F_SETOWN_BUG */ 2011#endif /* F_SETOWN_BUG */
1917#ifdef O_NDELAY 2012#ifdef O_NDELAY
1918 fcntl (input_fd, F_SETFL, fcntl (input_fd, F_GETFL, 0) & ~O_NDELAY); 2013 fcntl (fileno (tty_out->input), F_SETFL,
2014 fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY);
1919#endif 2015#endif
1920#endif /* F_SETFL */ 2016#endif /* F_SETFL */
1921#ifdef BSD4_1 2017#ifdef BSD4_1
1922 if (interrupt_input) 2018 if (interrupt_input)
1923 reset_sigio (); 2019 reset_sigio (fileno (tty_out->input));
1924#endif /* BSD4_1 */ 2020#endif /* BSD4_1 */
1925 2021
1926 if (old_tty_valid) 2022 if (tty_out->old_tty)
1927 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) 2023 while (EMACS_SET_TTY (fileno (tty_out->input),
2024 tty_out->old_tty, 0) < 0 && errno == EINTR)
1928 ; 2025 ;
1929 2026
1930#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */ 2027#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
@@ -1935,7 +2032,7 @@ reset_sys_modes ()
1935 /* Ultrix's termios *ignores* any line discipline except TERMIODISC. 2032 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1936 A different old line discipline is therefore not restored, yet. 2033 A different old line discipline is therefore not restored, yet.
1937 Restore the old line discipline by hand. */ 2034 Restore the old line discipline by hand. */
1938 ioctl (0, TIOCSETD, &old_tty.main.c_line); 2035 ioctl (0, TIOCSETD, &tty_out->old_tty.main.c_line);
1939#endif 2036#endif
1940 2037
1941#ifdef AIXHFT 2038#ifdef AIXHFT
@@ -1943,7 +2040,7 @@ reset_sys_modes ()
1943#endif 2040#endif
1944 2041
1945#ifdef BSD_PGRPS 2042#ifdef BSD_PGRPS
1946 widen_foreground_group (); 2043 widen_foreground_group (fileno (tty_out->input));
1947#endif 2044#endif
1948} 2045}
1949 2046
@@ -2008,9 +2105,9 @@ init_vms_input ()
2008{ 2105{
2009 int status; 2106 int status;
2010 2107
2011 if (input_fd == 0) 2108 if (fileno (CURTTY ()->input)) == 0)
2012 { 2109 {
2013 status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0); 2110 status = SYS$ASSIGN (&input_dsc, &fileno (CURTTY ()->input)), 0, 0);
2014 if (! (status & 1)) 2111 if (! (status & 1))
2015 LIB$STOP (status); 2112 LIB$STOP (status);
2016 } 2113 }
@@ -2021,7 +2118,7 @@ init_vms_input ()
2021void 2118void
2022stop_vms_input () 2119stop_vms_input ()
2023{ 2120{
2024 return SYS$DASSGN (input_fd); 2121 return SYS$DASSGN (fileno (CURTTY ()->input)));
2025} 2122}
2026 2123
2027short input_buffer; 2124short input_buffer;
@@ -2037,7 +2134,7 @@ queue_kbd_input ()
2037 2134
2038 waiting_for_ast = 0; 2135 waiting_for_ast = 0;
2039 stop_input = 0; 2136 stop_input = 0;
2040 status = SYS$QIO (0, input_fd, IO$_READVBLK, 2137 status = SYS$QIO (0, fileno (CURTTY()->input), IO$_READVBLK,
2041 &input_iosb, kbd_input_ast, 1, 2138 &input_iosb, kbd_input_ast, 1,
2042 &input_buffer, 1, 0, terminator_mask, 0, 0); 2139 &input_buffer, 1, 0, terminator_mask, 0, 0);
2043} 2140}
@@ -2154,7 +2251,7 @@ end_kbd_input ()
2154#endif 2251#endif
2155 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */ 2252 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2156 { 2253 {
2157 SYS$CANCEL (input_fd); 2254 SYS$CANCEL (fileno (CURTTY()->input));
2158 return; 2255 return;
2159 } 2256 }
2160 2257
@@ -2163,7 +2260,7 @@ end_kbd_input ()
2163 SYS$CLREF (input_ef); 2260 SYS$CLREF (input_ef);
2164 waiting_for_ast = 1; 2261 waiting_for_ast = 1;
2165 stop_input = 1; 2262 stop_input = 1;
2166 SYS$CANCEL (input_fd); 2263 SYS$CANCEL (fileno (CURTTY()->input));
2167 SYS$SETAST (1); 2264 SYS$SETAST (1);
2168 SYS$WAITFR (input_ef); 2265 SYS$WAITFR (input_ef);
2169 waiting_for_ast = 0; 2266 waiting_for_ast = 0;
@@ -2225,7 +2322,8 @@ init_sigio (fd)
2225 request_sigio (); 2322 request_sigio ();
2226} 2323}
2227 2324
2228reset_sigio () 2325reset_sigio (fd)
2326 int fd;
2229{ 2327{
2230 unrequest_sigio (); 2328 unrequest_sigio ();
2231} 2329}
@@ -2567,7 +2665,9 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2567 SELECT_TYPE *rfds, *wfds, *efds; 2665 SELECT_TYPE *rfds, *wfds, *efds;
2568 EMACS_TIME *timeout; 2666 EMACS_TIME *timeout;
2569{ 2667{
2570 int ravail = 0; 2668 /* XXX This needs to be updated for multi-tty support. Is there
2669 anybody who needs to emulate select these days? */
2670 int ravail = 0;
2571 SELECT_TYPE orfds; 2671 SELECT_TYPE orfds;
2572 int timeoutval; 2672 int timeoutval;
2573 int *local_timeout; 2673 int *local_timeout;
@@ -2582,7 +2682,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2582#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS) 2682#if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2583 /* If we're using X, then the native select will work; we only need the 2683 /* If we're using X, then the native select will work; we only need the
2584 emulation for non-X usage. */ 2684 emulation for non-X usage. */
2585 if (!NILP (Vwindow_system)) 2685 if (!NILP (Vinitial_window_system))
2586 return select (nfds, rfds, wfds, efds, timeout); 2686 return select (nfds, rfds, wfds, efds, timeout);
2587#endif 2687#endif
2588 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000; 2688 timeoutval = timeout ? EMACS_SECS (*timeout) : 100000;
@@ -2699,6 +2799,8 @@ sys_select (nfds, rfds, wfds, efds, timeout)
2699void 2799void
2700read_input_waiting () 2800read_input_waiting ()
2701{ 2801{
2802 /* XXX This needs to be updated for multi-tty support. Is there
2803 anybody who needs to emulate select these days? */
2702 int nread, i; 2804 int nread, i;
2703 extern int quit_char; 2805 extern int quit_char;
2704 2806
@@ -2752,6 +2854,10 @@ read_input_waiting ()
2752 } 2854 }
2753} 2855}
2754 2856
2857#if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2858#define select sys_select
2859#endif
2860
2755#endif /* not HAVE_SELECT */ 2861#endif /* not HAVE_SELECT */
2756#endif /* not VMS */ 2862#endif /* not VMS */
2757#endif /* not MSDOS */ 2863#endif /* not MSDOS */
@@ -2768,12 +2874,13 @@ init_sigio (fd)
2768} 2874}
2769 2875
2770void 2876void
2771reset_sigio () 2877reset_sigio (fd)
2878 int fd;
2772{ 2879{
2773 if (noninteractive) 2880 if (noninteractive)
2774 return; 2881 return;
2775 lmode = ~LINTRUP & lmode; 2882 lmode = ~LINTRUP & lmode;
2776 ioctl (0, TIOCLSET, &lmode); 2883 ioctl (fd, TIOCLSET, &lmode);
2777} 2884}
2778 2885
2779void 2886void
@@ -3229,7 +3336,7 @@ sys_getenv (name)
3229#undef abort 3336#undef abort
3230sys_abort () 3337sys_abort ()
3231{ 3338{
3232 reset_sys_modes (); 3339 reset_all_sys_modes ();
3233 LIB$SIGNAL (SS$_DEBUG); 3340 LIB$SIGNAL (SS$_DEBUG);
3234} 3341}
3235#endif /* abort */ 3342#endif /* abort */
@@ -3556,7 +3663,7 @@ croak (badfunc)
3556 char *badfunc; 3663 char *badfunc;
3557{ 3664{
3558 printf ("%s not yet implemented\r\n", badfunc); 3665 printf ("%s not yet implemented\r\n", badfunc);
3559 reset_sys_modes (); 3666 reset_all_sys_modes ();
3560 exit (1); 3667 exit (1);
3561} 3668}
3562 3669
@@ -5143,7 +5250,7 @@ croak (badfunc)
5143 char *badfunc; 5250 char *badfunc;
5144{ 5251{
5145 printf ("%s not yet implemented\r\n", badfunc); 5252 printf ("%s not yet implemented\r\n", badfunc);
5146 reset_sys_modes (); 5253 reset_all_sys_modes ();
5147 exit (1); 5254 exit (1);
5148} 5255}
5149 5256
@@ -5165,7 +5272,7 @@ srandom (seed)
5165 5272
5166/* Called from init_sys_modes. */ 5273/* Called from init_sys_modes. */
5167void 5274void
5168hft_init () 5275hft_init (struct tty_display_info *tty_out)
5169{ 5276{
5170 int junk; 5277 int junk;
5171 5278
@@ -5211,15 +5318,12 @@ hft_init ()
5211 keymap.hfkey[1].hf_char = 127; 5318 keymap.hfkey[1].hf_char = 127;
5212 hftctl (0, HFSKBD, &buf); 5319 hftctl (0, HFSKBD, &buf);
5213 } 5320 }
5214 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5215 at times. */
5216 line_ins_del_ok = char_ins_del_ok = 0;
5217} 5321}
5218 5322
5219/* Reset the rubout key to backspace. */ 5323/* Reset the rubout key to backspace. */
5220 5324
5221void 5325void
5222hft_reset () 5326hft_reset (struct tty_display_info *tty_out)
5223{ 5327{
5224 struct hfbuf buf; 5328 struct hfbuf buf;
5225 struct hfkeymap keymap; 5329 struct hfkeymap keymap;
diff --git a/src/syssignal.h b/src/syssignal.h
index b52e2dd4b95..72ac1ed7f62 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 63455f525da..c906e1eb15a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -25,13 +25,22 @@ 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
28#ifdef HAVE_UNISTD_H 31#ifdef HAVE_UNISTD_H
29#include <unistd.h> 32#include <unistd.h>
30#endif 33#endif
31 34
35#if HAVE_TERMIOS_H
36#include <termios.h> /* For TIOCNOTTY. */
37#endif
38
39#include <signal.h>
40
41#include "lisp.h"
32#include "termchar.h" 42#include "termchar.h"
33#include "termopts.h" 43#include "termopts.h"
34#include "lisp.h"
35#include "charset.h" 44#include "charset.h"
36#include "coding.h" 45#include "coding.h"
37#include "keyboard.h" 46#include "keyboard.h"
@@ -42,6 +51,8 @@ Boston, MA 02110-1301, USA. */
42#include "window.h" 51#include "window.h"
43#include "keymap.h" 52#include "keymap.h"
44#include "blockinput.h" 53#include "blockinput.h"
54#include "syssignal.h"
55#include "systty.h"
45#include "intervals.h" 56#include "intervals.h"
46 57
47/* For now, don't try to include termcap.h. On some systems, 58/* For now, don't try to include termcap.h. On some systems,
@@ -65,221 +76,68 @@ extern int tgetnum P_ ((char *id));
65#include "macterm.h" 76#include "macterm.h"
66#endif 77#endif
67 78
79#ifndef O_RDWR
80#define O_RDWR 2
81#endif
82
83#ifndef O_NOCTTY
84#define O_NOCTTY 0
85#endif
86
87static void tty_set_scroll_region P_ ((struct frame *f, int start, int stop));
68static void turn_on_face P_ ((struct frame *, int face_id)); 88static void turn_on_face P_ ((struct frame *, int face_id));
69static void turn_off_face P_ ((struct frame *, int face_id)); 89static void turn_off_face P_ ((struct frame *, int face_id));
70static void tty_show_cursor P_ ((void)); 90static void tty_show_cursor P_ ((struct tty_display_info *));
71static void tty_hide_cursor P_ ((void)); 91static void tty_hide_cursor P_ ((struct tty_display_info *));
72 92static void tty_background_highlight P_ ((struct tty_display_info *tty));
73#define OUTPUT(a) \ 93static void clear_tty_hooks P_ ((struct terminal *terminal));
74 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc) 94static void set_tty_hooks P_ ((struct terminal *terminal));
75#define OUTPUT1(a) tputs (a, 1, cmputc) 95static void dissociate_if_controlling_tty P_ ((int fd));
76#define OUTPUTL(a, lines) tputs (a, lines, cmputc) 96static void delete_tty P_ ((struct terminal *));
97
98#define OUTPUT(tty, a) \
99 emacs_tputs ((tty), a, \
100 (int) (FRAME_LINES (XFRAME (selected_frame)) \
101 - curY (tty)), \
102 cmputc)
103
104#define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
105#define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
106
107#define OUTPUT_IF(tty, a) \
108 do { \
109 if (a) \
110 emacs_tputs ((tty), a, \
111 (int) (FRAME_LINES (XFRAME (selected_frame)) \
112 - curY (tty) ), \
113 cmputc); \
114 } while (0)
115
116#define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
77 117
78#define OUTPUT_IF(a) \ 118/* If true, use "vs", otherwise use "ve" to make the cursor visible. */
79 do { \
80 if (a) \
81 tputs (a, (int) (FRAME_LINES (XFRAME (selected_frame)) \
82 - curY), cmputc); \
83 } while (0)
84 119
85#define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0) 120static int visible_cursor;
86 121
87/* Display space properties */ 122/* Display space properties */
88 123
89extern Lisp_Object Qspace, QCalign_to, QCwidth; 124extern Lisp_Object Qspace, QCalign_to, QCwidth;
90 125
91/* Function to use to ring the bell. */ 126/* Functions to call after suspending a tty. */
92 127Lisp_Object Vsuspend_tty_functions;
93Lisp_Object Vring_bell_function;
94 128
95/* If true, use "vs", otherwise use "ve" to make the cursor visible. */ 129/* Functions to call after resuming a tty. */
96 130Lisp_Object Vresume_tty_functions;
97static int visible_cursor;
98
99/* Terminal characteristics that higher levels want to look at.
100 These are all extern'd in termchar.h */
101 131
102int must_write_spaces; /* Nonzero means spaces in the text 132/* Chain of all tty device parameters. */
103 must actually be output; can't just skip 133struct tty_display_info *tty_list;
104 over some columns to leave them blank. */
105int min_padding_speed; /* Speed below which no padding necessary */
106
107int line_ins_del_ok; /* Terminal can insert and delete lines */
108int char_ins_del_ok; /* Terminal can insert and delete chars */
109int scroll_region_ok; /* Terminal supports setting the
110 scroll window */
111int scroll_region_cost; /* Cost of setting a scroll window,
112 measured in characters */
113int memory_below_frame; /* Terminal remembers lines
114 scrolled off bottom */
115int fast_clear_end_of_line; /* Terminal has a `ce' string */
116
117/* Nonzero means no need to redraw the entire frame on resuming
118 a suspended Emacs. This is useful on terminals with multiple pages,
119 where one page is used for Emacs and another for all else. */
120 134
135/* Nonzero means no need to redraw the entire frame on resuming a
136 suspended Emacs. This is useful on terminals with multiple
137 pages, where one page is used for Emacs and another for all
138 else. */
121int no_redraw_on_reenter; 139int no_redraw_on_reenter;
122 140
123/* Hook functions that you can set to snap out the functions in this file.
124 These are all extern'd in termhooks.h */
125
126void (*cursor_to_hook) P_ ((int, int));
127void (*raw_cursor_to_hook) P_ ((int, int));
128void (*clear_to_end_hook) P_ ((void));
129void (*clear_frame_hook) P_ ((void));
130void (*clear_end_of_line_hook) P_ ((int));
131
132void (*ins_del_lines_hook) P_ ((int, int));
133
134void (*delete_glyphs_hook) P_ ((int));
135
136void (*ring_bell_hook) P_ ((void));
137
138void (*reset_terminal_modes_hook) P_ ((void));
139void (*set_terminal_modes_hook) P_ ((void));
140void (*update_begin_hook) P_ ((struct frame *));
141void (*update_end_hook) P_ ((struct frame *));
142void (*set_terminal_window_hook) P_ ((int));
143void (*insert_glyphs_hook) P_ ((struct glyph *, int));
144void (*write_glyphs_hook) P_ ((struct glyph *, int));
145void (*delete_glyphs_hook) P_ ((int));
146
147int (*read_socket_hook) P_ ((int, int, struct input_event *));
148
149void (*frame_up_to_date_hook) P_ ((struct frame *));
150
151void (*mouse_position_hook) P_ ((FRAME_PTR *f, int insist,
152 Lisp_Object *bar_window,
153 enum scroll_bar_part *part,
154 Lisp_Object *x,
155 Lisp_Object *y,
156 unsigned long *time));
157
158/* When reading from a minibuffer in a different frame, Emacs wants
159 to shift the highlight from the selected frame to the mini-buffer's
160 frame; under X, this means it lies about where the focus is.
161 This hook tells the window system code to re-decide where to put
162 the highlight. */
163
164void (*frame_rehighlight_hook) P_ ((FRAME_PTR f));
165
166/* If we're displaying frames using a window system that can stack
167 frames on top of each other, this hook allows you to bring a frame
168 to the front, or bury it behind all the other windows. If this
169 hook is zero, that means the device we're displaying on doesn't
170 support overlapping frames, so there's no need to raise or lower
171 anything.
172
173 If RAISE is non-zero, F is brought to the front, before all other
174 windows. If RAISE is zero, F is sent to the back, behind all other
175 windows. */
176
177void (*frame_raise_lower_hook) P_ ((FRAME_PTR f, int raise));
178
179/* If the value of the frame parameter changed, whis hook is called.
180 For example, if going from fullscreen to not fullscreen this hook
181 may do something OS dependent, like extended window manager hints on X11. */
182void (*fullscreen_hook) P_ ((struct frame *f));
183
184/* Set the vertical scroll bar for WINDOW to have its upper left corner
185 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
186 indicate that we are displaying PORTION characters out of a total
187 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
188 have a scroll bar, create one for it. */
189
190void (*set_vertical_scroll_bar_hook)
191 P_ ((struct window *window,
192 int portion, int whole, int position));
193
194
195/* The following three hooks are used when we're doing a thorough
196 redisplay of the frame. We don't explicitly know which scroll bars
197 are going to be deleted, because keeping track of when windows go
198 away is a real pain - can you say set-window-configuration?
199 Instead, we just assert at the beginning of redisplay that *all*
200 scroll bars are to be removed, and then save scroll bars from the
201 fiery pit when we actually redisplay their window. */
202
203/* Arrange for all scroll bars on FRAME to be removed at the next call
204 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
205 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
206
207 This should be applied to each frame each time its window tree is
208 redisplayed, even if it is not displaying scroll bars at the moment;
209 if the HAS_SCROLL_BARS flag has just been turned off, only calling
210 this and the judge_scroll_bars_hook will get rid of them.
211
212 If non-zero, this hook should be safe to apply to any frame,
213 whether or not it can support scroll bars, and whether or not it is
214 currently displaying them. */
215
216void (*condemn_scroll_bars_hook) P_ ((FRAME_PTR frame));
217
218/* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
219 Note that it's okay to redeem a scroll bar that is not condemned. */
220
221void (*redeem_scroll_bar_hook) P_ ((struct window *window));
222
223/* Remove all scroll bars on FRAME that haven't been saved since the
224 last call to `*condemn_scroll_bars_hook'.
225
226 This should be applied to each frame after each time its window
227 tree is redisplayed, even if it is not displaying scroll bars at the
228 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
229 calling this and condemn_scroll_bars_hook will get rid of them.
230
231 If non-zero, this hook should be safe to apply to any frame,
232 whether or not it can support scroll bars, and whether or not it is
233 currently displaying them. */
234
235void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME));
236
237/* Strings, numbers and flags taken from the termcap entry. */
238
239char *TS_ins_line; /* "al" */
240char *TS_ins_multi_lines; /* "AL" (one parameter, # lines to insert) */
241char *TS_bell; /* "bl" */
242char *TS_clr_to_bottom; /* "cd" */
243char *TS_clr_line; /* "ce", clear to end of line */
244char *TS_clr_frame; /* "cl" */
245char *TS_set_scroll_region; /* "cs" (2 params, first line and last line) */
246char *TS_set_scroll_region_1; /* "cS" (4 params: total lines,
247 lines above scroll region, lines below it,
248 total lines again) */
249char *TS_del_char; /* "dc" */
250char *TS_del_multi_chars; /* "DC" (one parameter, # chars to delete) */
251char *TS_del_line; /* "dl" */
252char *TS_del_multi_lines; /* "DL" (one parameter, # lines to delete) */
253char *TS_delete_mode; /* "dm", enter character-delete mode */
254char *TS_end_delete_mode; /* "ed", leave character-delete mode */
255char *TS_end_insert_mode; /* "ei", leave character-insert mode */
256char *TS_ins_char; /* "ic" */
257char *TS_ins_multi_chars; /* "IC" (one parameter, # chars to insert) */
258char *TS_insert_mode; /* "im", enter character-insert mode */
259char *TS_pad_inserted_char; /* "ip". Just padding, no commands. */
260char *TS_end_keypad_mode; /* "ke" */
261char *TS_keypad_mode; /* "ks" */
262char *TS_pad_char; /* "pc", char to use as padding */
263char *TS_repeat; /* "rp" (2 params, # times to repeat
264 and character to be repeated) */
265char *TS_end_standout_mode; /* "se" */
266char *TS_fwd_scroll; /* "sf" */
267char *TS_standout_mode; /* "so" */
268char *TS_rev_scroll; /* "sr" */
269char *TS_end_termcap_modes; /* "te" */
270char *TS_termcap_modes; /* "ti" */
271char *TS_visible_bell; /* "vb" */
272char *TS_cursor_normal; /* "ve" */
273char *TS_cursor_visible; /* "vs" */
274char *TS_cursor_invisible; /* "vi" */
275char *TS_set_window; /* "wi" (4 params, start and end of window,
276 each as vpos and hpos) */
277
278/* Value of the "NC" (no_color_video) capability, or 0 if not
279 present. */
280
281static int TN_no_color_video;
282
283/* Meaning of bits in no_color_video. Each bit set means that the 141/* Meaning of bits in no_color_video. Each bit set means that the
284 corresponding attribute cannot be combined with colors. */ 142 corresponding attribute cannot be combined with colors. */
285 143
@@ -296,68 +154,6 @@ enum no_color_bit
296 NC_ALT_CHARSET = 1 << 8 154 NC_ALT_CHARSET = 1 << 8
297}; 155};
298 156
299/* "md" -- turn on bold (extra bright mode). */
300
301char *TS_enter_bold_mode;
302
303/* "mh" -- turn on half-bright mode. */
304
305char *TS_enter_dim_mode;
306
307/* "mb" -- enter blinking mode. */
308
309char *TS_enter_blink_mode;
310
311/* "mr" -- enter reverse video mode. */
312
313char *TS_enter_reverse_mode;
314
315/* "us"/"ue" -- start/end underlining. */
316
317char *TS_exit_underline_mode, *TS_enter_underline_mode;
318
319/* "as"/"ae" -- start/end alternate character set. Not really
320 supported, yet. */
321
322char *TS_enter_alt_charset_mode, *TS_exit_alt_charset_mode;
323
324/* "me" -- switch appearances off. */
325
326char *TS_exit_attribute_mode;
327
328/* "Co" -- number of colors. */
329
330int TN_max_colors;
331
332/* "pa" -- max. number of color pairs on screen. Not handled yet.
333 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
334
335int TN_max_pairs;
336
337/* "op" -- SVr4 set default pair to its original value. */
338
339char *TS_orig_pair;
340
341/* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
342 1 param, the color index. */
343
344char *TS_set_foreground, *TS_set_background;
345
346int TF_hazeltine; /* termcap hz flag. */
347int TF_insmode_motion; /* termcap mi flag: can move while in insert mode. */
348int TF_standout_motion; /* termcap mi flag: can move while in standout mode. */
349int TF_underscore; /* termcap ul flag: _ underlines if over-struck on
350 non-blank position. Must clear before writing _. */
351int TF_teleray; /* termcap xt flag: many weird consequences.
352 For t1061. */
353
354static int RPov; /* # chars to start a TS_repeat */
355
356static int delete_in_insert_mode; /* delete mode == insert mode */
357
358static int se_is_so; /* 1 if same string both enters and leaves
359 standout mode */
360
361/* internal state */ 157/* internal state */
362 158
363/* The largest frame width in any call to calculate_costs. */ 159/* The largest frame width in any call to calculate_costs. */
@@ -368,33 +164,14 @@ int max_frame_cols;
368 164
369int max_frame_lines; 165int max_frame_lines;
370 166
371static int costs_set; /* Nonzero if costs have been calculated. */ 167/* Non-zero if we have dropped our controlling tty and therefore
372 168 should not open a frame on stdout. */
373int insert_mode; /* Nonzero when in insert mode. */ 169static int no_controlling_tty;
374int standout_mode; /* Nonzero when in standout mode. */
375
376/* Size of window specified by higher levels.
377 This is the number of lines, from the top of frame downwards,
378 which can participate in insert-line/delete-line operations.
379
380 Effectively it excludes the bottom frame_lines - specified_window_size
381 lines from those operations. */
382
383int specified_window;
384
385/* Frame currently being redisplayed; 0 if not currently redisplaying.
386 (Direct output does not count). */
387
388FRAME_PTR updating_frame;
389 170
390/* Provided for lisp packages. */ 171/* Provided for lisp packages. */
391 172
392static int system_uses_terminfo; 173static int system_uses_terminfo;
393 174
394/* Flag used in tty_show/hide_cursor. */
395
396static int tty_cursor_hidden;
397
398char *tparam (); 175char *tparam ();
399 176
400extern char *tgetstr (); 177extern char *tgetstr ();
@@ -421,6 +198,9 @@ static void term_mouse_highlight (struct frame *f, int x, int y);
421/* Nonzero means mouse is enabled on Linux console. */ 198/* Nonzero means mouse is enabled on Linux console. */
422int term_gpm = 0; 199int term_gpm = 0;
423 200
201/* The id of the terminal device for which we have gpm support. */
202int gpm_tty;
203
424/* These variables describe the range of text currently shown in its 204/* These variables describe the range of text currently shown in its
425 mouse-face, together with the window they apply to. As long as 205 mouse-face, together with the window they apply to. As long as
426 the mouse stays within this range, we need not redraw anything on 206 the mouse stays within this range, we need not redraw anything on
@@ -436,192 +216,173 @@ static int pos_x, pos_y;
436static int last_mouse_x, last_mouse_y; 216static int last_mouse_x, last_mouse_y;
437#endif /* HAVE_GPM */ 217#endif /* HAVE_GPM */
438 218
439void 219/* Ring the bell on a tty. */
440ring_bell ()
441{
442 if (!NILP (Vring_bell_function))
443 {
444 Lisp_Object function;
445
446 /* Temporarily set the global variable to nil
447 so that if we get an error, it stays nil
448 and we don't call it over and over.
449
450 We don't specbind it, because that would carefully
451 restore the bad value if there's an error
452 and make the loop of errors happen anyway. */
453
454 function = Vring_bell_function;
455 Vring_bell_function = Qnil;
456 220
457 call0 (function); 221static void
222tty_ring_bell (struct frame *f)
223{
224 struct tty_display_info *tty = FRAME_TTY (f);
458 225
459 Vring_bell_function = function; 226 if (tty->output)
227 {
228 OUTPUT (tty, (tty->TS_visible_bell && visible_bell
229 ? tty->TS_visible_bell
230 : tty->TS_bell));
231 fflush (tty->output);
460 } 232 }
461 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame)))
462 (*ring_bell_hook) ();
463 else
464 OUTPUT (TS_visible_bell && visible_bell ? TS_visible_bell : TS_bell);
465} 233}
466 234
235/* Set up termcap modes for Emacs. */
236
467void 237void
468set_terminal_modes () 238tty_set_terminal_modes (struct terminal *terminal)
469{ 239{
470 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 240 struct tty_display_info *tty = terminal->display_info.tty;
241
242 if (tty->output)
471 { 243 {
472 if (TS_termcap_modes) 244 if (tty->TS_termcap_modes)
473 OUTPUT (TS_termcap_modes); 245 OUTPUT (tty, tty->TS_termcap_modes);
474 else 246 else
475 { 247 {
476 /* Output enough newlines to scroll all the old screen contents 248 /* Output enough newlines to scroll all the old screen contents
477 off the screen, so it won't be overwritten and lost. */ 249 off the screen, so it won't be overwritten and lost. */
478 int i; 250 int i;
479 for (i = 0; i < FRAME_LINES (XFRAME (selected_frame)); i++) 251 current_tty = tty;
480 putchar ('\n'); 252 for (i = 0; i < FRAME_LINES (XFRAME (selected_frame)); i++)
481 } 253 cmputc ('\n');
482 254 }
483 OUTPUT_IF (visible_cursor ? TS_cursor_visible : TS_cursor_normal); 255
484 OUTPUT_IF (TS_keypad_mode); 256 OUTPUT_IF (tty, tty->TS_termcap_modes);
485 losecursor (); 257 OUTPUT_IF (tty, visible_cursor ? tty->TS_cursor_visible : tty->TS_cursor_normal);
258 OUTPUT_IF (tty, tty->TS_keypad_mode);
259 losecursor (tty);
260 fflush (tty->output);
486 } 261 }
487 else
488 (*set_terminal_modes_hook) ();
489} 262}
490 263
264/* Reset termcap modes before exiting Emacs. */
265
491void 266void
492reset_terminal_modes () 267tty_reset_terminal_modes (struct terminal *terminal)
493{ 268{
494 if (FRAME_TERMCAP_P (XFRAME (selected_frame))) 269 struct tty_display_info *tty = terminal->display_info.tty;
270
271 if (tty->output)
495 { 272 {
496 turn_off_highlight (); 273 tty_turn_off_highlight (tty);
497 turn_off_insert (); 274 tty_turn_off_insert (tty);
498 OUTPUT_IF (TS_end_keypad_mode); 275 OUTPUT_IF (tty, tty->TS_end_keypad_mode);
499 OUTPUT_IF (TS_cursor_normal); 276 OUTPUT_IF (tty, tty->TS_cursor_normal);
500 OUTPUT_IF (TS_end_termcap_modes); 277 OUTPUT_IF (tty, tty->TS_end_termcap_modes);
501 OUTPUT_IF (TS_orig_pair); 278 OUTPUT_IF (tty, tty->TS_orig_pair);
502 /* Output raw CR so kernel can track the cursor hpos. */ 279 /* Output raw CR so kernel can track the cursor hpos. */
280 current_tty = tty;
503 cmputc ('\r'); 281 cmputc ('\r');
282 fflush (tty->output);
504 } 283 }
505 else if (reset_terminal_modes_hook)
506 (*reset_terminal_modes_hook) ();
507} 284}
508 285
509void 286/* Flag the end of a display update on a termcap terminal. */
510update_begin (f)
511 struct frame *f;
512{
513 updating_frame = f;
514 if (!FRAME_TERMCAP_P (f))
515 update_begin_hook (f);
516}
517 287
518void 288static void
519update_end (f) 289tty_update_end (struct frame *f)
520 struct frame *f;
521{ 290{
522 if (FRAME_TERMCAP_P (f)) 291 struct tty_display_info *tty = FRAME_TTY (f);
523 {
524 if (!XWINDOW (selected_window)->cursor_off_p)
525 tty_show_cursor ();
526 turn_off_insert ();
527 background_highlight ();
528 }
529 else
530 update_end_hook (f);
531 292
532 updating_frame = NULL; 293 if (!XWINDOW (selected_window)->cursor_off_p)
294 tty_show_cursor (tty);
295 tty_turn_off_insert (tty);
296 tty_background_highlight (tty);
533} 297}
534 298
535void 299/* The implementation of set_terminal_window for termcap frames. */
536set_terminal_window (size) 300
537 int size; 301static void
302tty_set_terminal_window (struct frame *f, int size)
538{ 303{
539 if (FRAME_TERMCAP_P (updating_frame)) 304 struct tty_display_info *tty = FRAME_TTY (f);
540 { 305
541 specified_window = size ? size : FRAME_LINES (updating_frame); 306 tty->specified_window = size ? size : FRAME_LINES (f);
542 if (scroll_region_ok) 307 if (FRAME_SCROLL_REGION_OK (f))
543 set_scroll_region (0, specified_window); 308 tty_set_scroll_region (f, 0, tty->specified_window);
544 }
545 else
546 set_terminal_window_hook (size);
547} 309}
548 310
549void 311static void
550set_scroll_region (start, stop) 312tty_set_scroll_region (struct frame *f, int start, int stop)
551 int start, stop;
552{ 313{
553 char *buf; 314 char *buf;
554 struct frame *sf = XFRAME (selected_frame); 315 struct tty_display_info *tty = FRAME_TTY (f);
555 316
556 if (TS_set_scroll_region) 317 if (tty->TS_set_scroll_region)
557 buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1); 318 buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1);
558 else if (TS_set_scroll_region_1) 319 else if (tty->TS_set_scroll_region_1)
559 buf = tparam (TS_set_scroll_region_1, 0, 0, 320 buf = tparam (tty->TS_set_scroll_region_1, 0, 0,
560 FRAME_LINES (sf), start, 321 FRAME_LINES (f), start,
561 FRAME_LINES (sf) - stop, 322 FRAME_LINES (f) - stop,
562 FRAME_LINES (sf)); 323 FRAME_LINES (f));
563 else 324 else
564 buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (sf)); 325 buf = tparam (tty->TS_set_window, 0, 0, start, 0, stop, FRAME_COLS (f));
565 326
566 OUTPUT (buf); 327 OUTPUT (tty, buf);
567 xfree (buf); 328 xfree (buf);
568 losecursor (); 329 losecursor (tty);
569} 330}
570 331
571 332
572static void 333static void
573turn_on_insert () 334tty_turn_on_insert (struct tty_display_info *tty)
574{ 335{
575 if (!insert_mode) 336 if (!tty->insert_mode)
576 OUTPUT (TS_insert_mode); 337 OUTPUT (tty, tty->TS_insert_mode);
577 insert_mode = 1; 338 tty->insert_mode = 1;
578} 339}
579 340
580void 341void
581turn_off_insert () 342tty_turn_off_insert (struct tty_display_info *tty)
582{ 343{
583 if (insert_mode) 344 if (tty->insert_mode)
584 OUTPUT (TS_end_insert_mode); 345 OUTPUT (tty, tty->TS_end_insert_mode);
585 insert_mode = 0; 346 tty->insert_mode = 0;
586} 347}
587 348
588/* Handle highlighting. */ 349/* Handle highlighting. */
589 350
590void 351void
591turn_off_highlight () 352tty_turn_off_highlight (struct tty_display_info *tty)
592{ 353{
593 if (standout_mode) 354 if (tty->standout_mode)
594 OUTPUT_IF (TS_end_standout_mode); 355 OUTPUT_IF (tty, tty->TS_end_standout_mode);
595 standout_mode = 0; 356 tty->standout_mode = 0;
596} 357}
597 358
598static void 359static void
599turn_on_highlight () 360tty_turn_on_highlight (struct tty_display_info *tty)
600{ 361{
601 if (!standout_mode) 362 if (!tty->standout_mode)
602 OUTPUT_IF (TS_standout_mode); 363 OUTPUT_IF (tty, tty->TS_standout_mode);
603 standout_mode = 1; 364 tty->standout_mode = 1;
604} 365}
605 366
606static void 367static void
607toggle_highlight () 368tty_toggle_highlight (struct tty_display_info *tty)
608{ 369{
609 if (standout_mode) 370 if (tty->standout_mode)
610 turn_off_highlight (); 371 tty_turn_off_highlight (tty);
611 else 372 else
612 turn_on_highlight (); 373 tty_turn_on_highlight (tty);
613} 374}
614 375
615 376
616/* Make cursor invisible. */ 377/* Make cursor invisible. */
617 378
618static void 379static void
619tty_hide_cursor () 380tty_hide_cursor (struct tty_display_info *tty)
620{ 381{
621 if (tty_cursor_hidden == 0) 382 if (tty->cursor_hidden == 0)
622 { 383 {
623 tty_cursor_hidden = 1; 384 tty->cursor_hidden = 1;
624 OUTPUT_IF (TS_cursor_invisible); 385 OUTPUT_IF (tty, tty->TS_cursor_invisible);
625 } 386 }
626} 387}
627 388
@@ -629,14 +390,14 @@ tty_hide_cursor ()
629/* Ensure that cursor is visible. */ 390/* Ensure that cursor is visible. */
630 391
631static void 392static void
632tty_show_cursor () 393tty_show_cursor (struct tty_display_info *tty)
633{ 394{
634 if (tty_cursor_hidden) 395 if (tty->cursor_hidden)
635 { 396 {
636 tty_cursor_hidden = 0; 397 tty->cursor_hidden = 0;
637 OUTPUT_IF (TS_cursor_normal); 398 OUTPUT_IF (tty, tty->TS_cursor_normal);
638 if (visible_cursor) 399 if (visible_cursor)
639 OUTPUT_IF (TS_cursor_visible); 400 OUTPUT_IF (tty, tty->TS_cursor_visible);
640 } 401 }
641} 402}
642 403
@@ -645,180 +406,151 @@ tty_show_cursor ()
645 empty space inside windows. What this is, 406 empty space inside windows. What this is,
646 depends on the user option inverse-video. */ 407 depends on the user option inverse-video. */
647 408
648void 409static void
649background_highlight () 410tty_background_highlight (struct tty_display_info *tty)
650{ 411{
651 if (inverse_video) 412 if (inverse_video)
652 turn_on_highlight (); 413 tty_turn_on_highlight (tty);
653 else 414 else
654 turn_off_highlight (); 415 tty_turn_off_highlight (tty);
655} 416}
656 417
657/* Set standout mode to the mode specified for the text to be output. */ 418/* Set standout mode to the mode specified for the text to be output. */
658 419
659static void 420static void
660highlight_if_desired () 421tty_highlight_if_desired (struct tty_display_info *tty)
661{ 422{
662 if (inverse_video) 423 if (inverse_video)
663 turn_on_highlight (); 424 tty_turn_on_highlight (tty);
664 else 425 else
665 turn_off_highlight (); 426 tty_turn_off_highlight (tty);
666} 427}
667 428
668 429
669/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are 430/* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
670 frame-relative coordinates. */ 431 frame-relative coordinates. */
671 432
672void 433static void
673cursor_to (vpos, hpos) 434tty_cursor_to (struct frame *f, int vpos, int hpos)
674 int vpos, hpos;
675{ 435{
676 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 436 struct tty_display_info *tty = FRAME_TTY (f);
677
678 if (! FRAME_TERMCAP_P (f) && cursor_to_hook)
679 {
680 (*cursor_to_hook) (vpos, hpos);
681 return;
682 }
683 437
684 /* Detect the case where we are called from reset_sys_modes 438 /* Detect the case where we are called from reset_sys_modes
685 and the costs have never been calculated. Do nothing. */ 439 and the costs have never been calculated. Do nothing. */
686 if (! costs_set) 440 if (! tty->costs_set)
687 return; 441 return;
688 442
689 if (curY == vpos && curX == hpos) 443 if (curY (tty) == vpos
444 && curX (tty) == hpos)
690 return; 445 return;
691 if (!TF_standout_motion) 446 if (!tty->TF_standout_motion)
692 background_highlight (); 447 tty_background_highlight (tty);
693 if (!TF_insmode_motion) 448 if (!tty->TF_insmode_motion)
694 turn_off_insert (); 449 tty_turn_off_insert (tty);
695 cmgoto (vpos, hpos); 450 cmgoto (tty, vpos, hpos);
696} 451}
697 452
698/* Similar but don't take any account of the wasted characters. */ 453/* Similar but don't take any account of the wasted characters. */
699 454
700void 455static void
701raw_cursor_to (row, col) 456tty_raw_cursor_to (struct frame *f, int row, int col)
702 int row, col;
703{ 457{
704 struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame); 458 struct tty_display_info *tty = FRAME_TTY (f);
705 if (! FRAME_TERMCAP_P (f)) 459
706 { 460 if (curY (tty) == row
707 (*raw_cursor_to_hook) (row, col); 461 && curX (tty) == col)
708 return;
709 }
710 if (curY == row && curX == col)
711 return; 462 return;
712 if (!TF_standout_motion) 463 if (!tty->TF_standout_motion)
713 background_highlight (); 464 tty_background_highlight (tty);
714 if (!TF_insmode_motion) 465 if (!tty->TF_insmode_motion)
715 turn_off_insert (); 466 tty_turn_off_insert (tty);
716 cmgoto (row, col); 467 cmgoto (tty, row, col);
717} 468}
718 469
719/* Erase operations */ 470/* Erase operations */
720 471
721/* clear from cursor to end of frame */ 472/* Clear from cursor to end of frame on a termcap device. */
722void 473
723clear_to_end () 474static void
475tty_clear_to_end (struct frame *f)
724{ 476{
725 register int i; 477 register int i;
478 struct tty_display_info *tty = FRAME_TTY (f);
726 479
727 if (clear_to_end_hook && ! FRAME_TERMCAP_P (updating_frame)) 480 if (tty->TS_clr_to_bottom)
728 { 481 {
729 (*clear_to_end_hook) (); 482 tty_background_highlight (tty);
730 return; 483 OUTPUT (tty, tty->TS_clr_to_bottom);
731 }
732 if (TS_clr_to_bottom)
733 {
734 background_highlight ();
735 OUTPUT (TS_clr_to_bottom);
736 } 484 }
737 else 485 else
738 { 486 {
739 for (i = curY; i < FRAME_LINES (XFRAME (selected_frame)); i++) 487 for (i = curY (tty); i < FRAME_LINES (f); i++)
740 { 488 {
741 cursor_to (i, 0); 489 cursor_to (f, i, 0);
742 clear_end_of_line (FRAME_COLS (XFRAME (selected_frame))); 490 clear_end_of_line (f, FRAME_COLS (f));
743 } 491 }
744 } 492 }
745} 493}
746 494
747/* Clear entire frame */ 495/* Clear an entire termcap frame. */
748 496
749void 497static void
750clear_frame () 498tty_clear_frame (struct frame *f)
751{ 499{
752 struct frame *sf = XFRAME (selected_frame); 500 struct tty_display_info *tty = FRAME_TTY (f);
753 501
754 if (clear_frame_hook 502 if (tty->TS_clr_frame)
755 && ! FRAME_TERMCAP_P ((updating_frame ? updating_frame : sf)))
756 { 503 {
757 (*clear_frame_hook) (); 504 tty_background_highlight (tty);
758 return; 505 OUTPUT (tty, tty->TS_clr_frame);
759 } 506 cmat (tty, 0, 0);
760 if (TS_clr_frame)
761 {
762 background_highlight ();
763 OUTPUT (TS_clr_frame);
764 cmat (0, 0);
765 } 507 }
766 else 508 else
767 { 509 {
768 cursor_to (0, 0); 510 cursor_to (f, 0, 0);
769 clear_to_end (); 511 clear_to_end (f);
770 } 512 }
771} 513}
772 514
773/* Clear from cursor to end of line. 515/* An implementation of clear_end_of_line for termcap frames.
774 Assume that the line is already clear starting at column first_unused_hpos.
775 516
776 Note that the cursor may be moved, on terminals lacking a `ce' string. */ 517 Note that the cursor may be moved, on terminals lacking a `ce' string. */
777 518
778void 519static void
779clear_end_of_line (first_unused_hpos) 520tty_clear_end_of_line (struct frame *f, int first_unused_hpos)
780 int first_unused_hpos;
781{ 521{
782 register int i; 522 register int i;
783 523 struct tty_display_info *tty = FRAME_TTY (f);
784 if (clear_end_of_line_hook
785 && ! FRAME_TERMCAP_P ((updating_frame
786 ? updating_frame
787 : XFRAME (selected_frame))))
788 {
789 (*clear_end_of_line_hook) (first_unused_hpos);
790 return;
791 }
792 524
793 /* Detect the case where we are called from reset_sys_modes 525 /* Detect the case where we are called from reset_sys_modes
794 and the costs have never been calculated. Do nothing. */ 526 and the costs have never been calculated. Do nothing. */
795 if (! costs_set) 527 if (! tty->costs_set)
796 return; 528 return;
797 529
798 if (curX >= first_unused_hpos) 530 if (curX (tty) >= first_unused_hpos)
799 return; 531 return;
800 background_highlight (); 532 tty_background_highlight (tty);
801 if (TS_clr_line) 533 if (tty->TS_clr_line)
802 { 534 {
803 OUTPUT1 (TS_clr_line); 535 OUTPUT1 (tty, tty->TS_clr_line);
804 } 536 }
805 else 537 else
806 { /* have to do it the hard way */ 538 { /* have to do it the hard way */
807 struct frame *sf = XFRAME (selected_frame); 539 tty_turn_off_insert (tty);
808 turn_off_insert ();
809 540
810 /* Do not write in last row last col with Auto-wrap on. */ 541 /* Do not write in last row last col with Auto-wrap on. */
811 if (AutoWrap && curY == FRAME_LINES (sf) - 1 542 if (AutoWrap (tty)
812 && first_unused_hpos == FRAME_COLS (sf)) 543 && curY (tty) == FrameRows (tty) - 1
544 && first_unused_hpos == FrameCols (tty))
813 first_unused_hpos--; 545 first_unused_hpos--;
814 546
815 for (i = curX; i < first_unused_hpos; i++) 547 for (i = curX (tty); i < first_unused_hpos; i++)
816 { 548 {
817 if (termscript) 549 if (tty->termscript)
818 fputc (' ', termscript); 550 fputc (' ', tty->termscript);
819 putchar (' '); 551 fputc (' ', tty->output);
820 } 552 }
821 cmplus (first_unused_hpos - curX); 553 cmplus (tty, first_unused_hpos - curX (tty));
822 } 554 }
823} 555}
824 556
@@ -940,43 +672,37 @@ encode_terminal_code (src, src_len, coding)
940 return encode_terminal_buf + nbytes; 672 return encode_terminal_buf + nbytes;
941} 673}
942 674
943void 675
944write_glyphs (string, len) 676/* An implementation of write_glyphs for termcap frames. */
945 register struct glyph *string; 677
946 register int len; 678static void
679tty_write_glyphs (struct frame *f, struct glyph *string, int len)
947{ 680{
948 struct frame *sf = XFRAME (selected_frame);
949 struct frame *f = updating_frame ? updating_frame : sf;
950 unsigned char *conversion_buffer; 681 unsigned char *conversion_buffer;
951 struct coding_system *coding; 682 struct coding_system *coding;
952 683
953 if (write_glyphs_hook 684 struct tty_display_info *tty = FRAME_TTY (f);
954 && ! FRAME_TERMCAP_P (f))
955 {
956 (*write_glyphs_hook) (string, len);
957 return;
958 }
959 685
960 turn_off_insert (); 686 tty_turn_off_insert (tty);
961 tty_hide_cursor (); 687 tty_hide_cursor (tty);
962 688
963 /* Don't dare write in last column of bottom line, if Auto-Wrap, 689 /* Don't dare write in last column of bottom line, if Auto-Wrap,
964 since that would scroll the whole frame on some terminals. */ 690 since that would scroll the whole frame on some terminals. */
965 691
966 if (AutoWrap 692 if (AutoWrap (tty)
967 && curY + 1 == FRAME_LINES (sf) 693 && curY (tty) + 1 == FRAME_LINES (f)
968 && (curX + len) == FRAME_COLS (sf)) 694 && (curX (tty) + len) == FRAME_COLS (f))
969 len --; 695 len --;
970 if (len <= 0) 696 if (len <= 0)
971 return; 697 return;
972 698
973 cmplus (len); 699 cmplus (tty, len);
974 700
975 /* If terminal_coding does any conversion, use it, otherwise use 701 /* If terminal_coding does any conversion, use it, otherwise use
976 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 702 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
977 because it always return 1 if the member src_multibyte is 1. */ 703 because it always return 1 if the member src_multibyte is 1. */
978 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 704 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
979 ? &terminal_coding : &safe_terminal_coding); 705 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
980 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 706 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
981 the tail. */ 707 the tail. */
982 coding->mode &= ~CODING_MODE_LAST_BLOCK; 708 coding->mode &= ~CODING_MODE_LAST_BLOCK;
@@ -992,7 +718,7 @@ write_glyphs (string, len)
992 break; 718 break;
993 719
994 /* Turn appearance modes of the face of the run on. */ 720 /* Turn appearance modes of the face of the run on. */
995 highlight_if_desired (); 721 tty_highlight_if_desired (tty);
996 turn_on_face (f, face_id); 722 turn_on_face (f, face_id);
997 723
998 if (n == len) 724 if (n == len)
@@ -1002,11 +728,11 @@ write_glyphs (string, len)
1002 if (coding->produced > 0) 728 if (coding->produced > 0)
1003 { 729 {
1004 BLOCK_INPUT; 730 BLOCK_INPUT;
1005 fwrite (conversion_buffer, 1, coding->produced, stdout); 731 fwrite (conversion_buffer, 1, coding->produced, tty->output);
1006 if (ferror (stdout)) 732 if (ferror (tty->output))
1007 clearerr (stdout); 733 clearerr (tty->output);
1008 if (termscript) 734 if (tty->termscript)
1009 fwrite (conversion_buffer, 1, coding->produced, termscript); 735 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
1010 UNBLOCK_INPUT; 736 UNBLOCK_INPUT;
1011 } 737 }
1012 len -= n; 738 len -= n;
@@ -1014,49 +740,49 @@ write_glyphs (string, len)
1014 740
1015 /* Turn appearance modes off. */ 741 /* Turn appearance modes off. */
1016 turn_off_face (f, face_id); 742 turn_off_face (f, face_id);
1017 turn_off_highlight (); 743 tty_turn_off_highlight (tty);
1018 } 744 }
1019 745
1020 cmcheckmagic (); 746 cmcheckmagic (tty);
1021} 747}
1022 748
1023void 749static void
1024write_glyphs_with_face (string, len, face_id) 750tty_write_glyphs_with_face (f, string, len, face_id)
751 register struct frame *f;
1025 register struct glyph *string; 752 register struct glyph *string;
1026 register int len, face_id; 753 register int len, face_id;
1027{ 754{
1028 struct frame *sf = XFRAME (selected_frame);
1029 struct frame *f = updating_frame ? updating_frame : sf;
1030 unsigned char *conversion_buffer; 755 unsigned char *conversion_buffer;
1031 struct coding_system *coding; 756 struct coding_system *coding;
1032 757
1033 turn_off_insert (); 758 struct tty_display_info *tty = FRAME_TTY (f);
1034 tty_hide_cursor (); 759
760 tty_turn_off_insert (tty);
761 tty_hide_cursor (tty);
1035 762
1036 /* Don't dare write in last column of bottom line, if Auto-Wrap, 763 /* Don't dare write in last column of bottom line, if Auto-Wrap,
1037 since that would scroll the whole frame on some terminals. */ 764 since that would scroll the whole frame on some terminals. */
1038 765
1039 if (AutoWrap 766 if (AutoWrap (tty)
1040 && curY + 1 == FRAME_LINES (sf) 767 && curY (tty) + 1 == FRAME_LINES (f)
1041 && (curX + len) == FRAME_COLS (sf)) 768 && (curX (tty) + len) == FRAME_COLS (f))
1042 len --; 769 len --;
1043 if (len <= 0) 770 if (len <= 0)
1044 return; 771 return;
1045 772
1046 cmplus (len); 773 cmplus (tty, len);
1047 774
1048 /* If terminal_coding does any conversion, use it, otherwise use 775 /* If terminal_coding does any conversion, use it, otherwise use
1049 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 776 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
1050 because it always return 1 if the member src_multibyte is 1. */ 777 because it always return 1 if the member src_multibyte is 1. */
1051 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 778 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
1052 ? &terminal_coding : &safe_terminal_coding); 779 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
1053 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 780 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
1054 the tail. */ 781 the tail. */
1055 coding->mode &= ~CODING_MODE_LAST_BLOCK; 782 coding->mode &= ~CODING_MODE_LAST_BLOCK;
1056 783
1057
1058 /* Turn appearance modes of the face. */ 784 /* Turn appearance modes of the face. */
1059 highlight_if_desired (); 785 tty_highlight_if_desired (tty);
1060 turn_on_face (f, face_id); 786 turn_on_face (f, face_id);
1061 787
1062 coding->mode |= CODING_MODE_LAST_BLOCK; 788 coding->mode |= CODING_MODE_LAST_BLOCK;
@@ -1064,59 +790,47 @@ write_glyphs_with_face (string, len, face_id)
1064 if (coding->produced > 0) 790 if (coding->produced > 0)
1065 { 791 {
1066 BLOCK_INPUT; 792 BLOCK_INPUT;
1067 fwrite (conversion_buffer, 1, coding->produced, stdout); 793 fwrite (conversion_buffer, 1, coding->produced, tty->output);
1068 if (ferror (stdout)) 794 if (ferror (tty->output))
1069 clearerr (stdout); 795 clearerr (tty->output);
1070 if (termscript) 796 if (tty->termscript)
1071 fwrite (conversion_buffer, 1, coding->produced, termscript); 797 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
1072 UNBLOCK_INPUT; 798 UNBLOCK_INPUT;
1073 } 799 }
1074 800
1075 /* Turn appearance modes off. */ 801 /* Turn appearance modes off. */
1076 turn_off_face (f, face_id); 802 turn_off_face (f, face_id);
1077 turn_off_highlight (); 803 tty_turn_off_highlight (tty);
1078 804
1079 cmcheckmagic (); 805 cmcheckmagic (tty);
1080} 806}
1081 807
1082/* If start is zero, insert blanks instead of a string at start */
1083 808
1084void 809/* An implementation of insert_glyphs for termcap frames. */
1085insert_glyphs (start, len) 810
1086 register struct glyph *start; 811static void
1087 register int len; 812tty_insert_glyphs (struct frame *f, struct glyph *start, int len)
1088{ 813{
1089 char *buf; 814 char *buf;
1090 struct glyph *glyph = NULL; 815 struct glyph *glyph = NULL;
1091 struct frame *f, *sf;
1092 unsigned char *conversion_buffer; 816 unsigned char *conversion_buffer;
1093 unsigned char space[1]; 817 unsigned char space[1];
1094 struct coding_system *coding; 818 struct coding_system *coding;
1095 819
1096 if (len <= 0) 820 struct tty_display_info *tty = FRAME_TTY (f);
1097 return;
1098 821
1099 if (insert_glyphs_hook) 822 if (tty->TS_ins_multi_chars)
1100 { 823 {
1101 (*insert_glyphs_hook) (start, len); 824 buf = tparam (tty->TS_ins_multi_chars, 0, 0, len);
1102 return; 825 OUTPUT1 (tty, buf);
1103 }
1104
1105 sf = XFRAME (selected_frame);
1106 f = updating_frame ? updating_frame : sf;
1107
1108 if (TS_ins_multi_chars)
1109 {
1110 buf = tparam (TS_ins_multi_chars, 0, 0, len);
1111 OUTPUT1 (buf);
1112 xfree (buf); 826 xfree (buf);
1113 if (start) 827 if (start)
1114 write_glyphs (start, len); 828 write_glyphs (f, start, len);
1115 return; 829 return;
1116 } 830 }
1117 831
1118 turn_on_insert (); 832 tty_turn_on_insert (tty);
1119 cmplus (len); 833 cmplus (tty, len);
1120 834
1121 if (! start) 835 if (! start)
1122 space[0] = SPACEGLYPH; 836 space[0] = SPACEGLYPH;
@@ -1124,15 +838,15 @@ insert_glyphs (start, len)
1124 /* If terminal_coding does any conversion, use it, otherwise use 838 /* If terminal_coding does any conversion, use it, otherwise use
1125 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 839 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
1126 because it always return 1 if the member src_multibyte is 1. */ 840 because it always return 1 if the member src_multibyte is 1. */
1127 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 841 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
1128 ? &terminal_coding : &safe_terminal_coding); 842 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
1129 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 843 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
1130 the tail. */ 844 the tail. */
1131 coding->mode &= ~CODING_MODE_LAST_BLOCK; 845 coding->mode &= ~CODING_MODE_LAST_BLOCK;
1132 846
1133 while (len-- > 0) 847 while (len-- > 0)
1134 { 848 {
1135 OUTPUT1_IF (TS_ins_char); 849 OUTPUT1_IF (tty, tty->TS_ins_char);
1136 if (!start) 850 if (!start)
1137 { 851 {
1138 conversion_buffer = space; 852 conversion_buffer = space;
@@ -1140,7 +854,7 @@ insert_glyphs (start, len)
1140 } 854 }
1141 else 855 else
1142 { 856 {
1143 highlight_if_desired (); 857 tty_highlight_if_desired (tty);
1144 turn_on_face (f, start->face_id); 858 turn_on_face (f, start->face_id);
1145 glyph = start; 859 glyph = start;
1146 ++start; 860 ++start;
@@ -1148,7 +862,7 @@ insert_glyphs (start, len)
1148 occupies more than one column. */ 862 occupies more than one column. */
1149 while (len && CHAR_GLYPH_PADDING_P (*start)) 863 while (len && CHAR_GLYPH_PADDING_P (*start))
1150 { 864 {
1151 OUTPUT1_IF (TS_ins_char); 865 OUTPUT1_IF (tty, tty->TS_ins_char);
1152 start++, len--; 866 start++, len--;
1153 } 867 }
1154 868
@@ -1156,89 +870,77 @@ insert_glyphs (start, len)
1156 /* This is the last glyph. */ 870 /* This is the last glyph. */
1157 coding->mode |= CODING_MODE_LAST_BLOCK; 871 coding->mode |= CODING_MODE_LAST_BLOCK;
1158 872
1159 conversion_buffer = encode_terminal_code (glyph, 1, coding); 873 conversion_buffer = encode_terminal_code (glyph, 1, coding);
1160 } 874 }
1161 875
1162 if (coding->produced > 0) 876 if (coding->produced > 0)
1163 { 877 {
1164 BLOCK_INPUT; 878 BLOCK_INPUT;
1165 fwrite (conversion_buffer, 1, coding->produced, stdout); 879 fwrite (conversion_buffer, 1, coding->produced, tty->output);
1166 if (ferror (stdout)) 880 if (ferror (tty->output))
1167 clearerr (stdout); 881 clearerr (tty->output);
1168 if (termscript) 882 if (tty->termscript)
1169 fwrite (conversion_buffer, 1, coding->produced, termscript); 883 fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
1170 UNBLOCK_INPUT; 884 UNBLOCK_INPUT;
1171 } 885 }
1172 886
1173 OUTPUT1_IF (TS_pad_inserted_char); 887 OUTPUT1_IF (tty, tty->TS_pad_inserted_char);
1174 if (start) 888 if (start)
1175 { 889 {
1176 turn_off_face (f, glyph->face_id); 890 turn_off_face (f, glyph->face_id);
1177 turn_off_highlight (); 891 tty_turn_off_highlight (tty);
1178 } 892 }
1179 } 893 }
1180 894
1181 cmcheckmagic (); 895 cmcheckmagic (tty);
1182} 896}
1183 897
1184void 898/* An implementation of delete_glyphs for termcap frames. */
1185delete_glyphs (n) 899
1186 register int n; 900static void
901tty_delete_glyphs (struct frame *f, int n)
1187{ 902{
1188 char *buf; 903 char *buf;
1189 register int i; 904 register int i;
1190 905
1191 if (delete_glyphs_hook && ! FRAME_TERMCAP_P (updating_frame)) 906 struct tty_display_info *tty = FRAME_TTY (f);
1192 {
1193 (*delete_glyphs_hook) (n);
1194 return;
1195 }
1196 907
1197 if (delete_in_insert_mode) 908 if (tty->delete_in_insert_mode)
1198 { 909 {
1199 turn_on_insert (); 910 tty_turn_on_insert (tty);
1200 } 911 }
1201 else 912 else
1202 { 913 {
1203 turn_off_insert (); 914 tty_turn_off_insert (tty);
1204 OUTPUT_IF (TS_delete_mode); 915 OUTPUT_IF (tty, tty->TS_delete_mode);
1205 } 916 }
1206 917
1207 if (TS_del_multi_chars) 918 if (tty->TS_del_multi_chars)
1208 { 919 {
1209 buf = tparam (TS_del_multi_chars, 0, 0, n); 920 buf = tparam (tty->TS_del_multi_chars, 0, 0, n);
1210 OUTPUT1 (buf); 921 OUTPUT1 (tty, buf);
1211 xfree (buf); 922 xfree (buf);
1212 } 923 }
1213 else 924 else
1214 for (i = 0; i < n; i++) 925 for (i = 0; i < n; i++)
1215 OUTPUT1 (TS_del_char); 926 OUTPUT1 (tty, tty->TS_del_char);
1216 if (!delete_in_insert_mode) 927 if (!tty->delete_in_insert_mode)
1217 OUTPUT_IF (TS_end_delete_mode); 928 OUTPUT_IF (tty, tty->TS_end_delete_mode);
1218} 929}
1219 930
1220/* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */ 931/* An implementation of ins_del_lines for termcap frames. */
1221 932
1222void 933static void
1223ins_del_lines (vpos, n) 934tty_ins_del_lines (struct frame *f, int vpos, int n)
1224 int vpos, n;
1225{ 935{
1226 char *multi = n > 0 ? TS_ins_multi_lines : TS_del_multi_lines; 936 struct tty_display_info *tty = FRAME_TTY (f);
1227 char *single = n > 0 ? TS_ins_line : TS_del_line; 937 char *multi = n > 0 ? tty->TS_ins_multi_lines : tty->TS_del_multi_lines;
1228 char *scroll = n > 0 ? TS_rev_scroll : TS_fwd_scroll; 938 char *single = n > 0 ? tty->TS_ins_line : tty->TS_del_line;
1229 struct frame *sf; 939 char *scroll = n > 0 ? tty->TS_rev_scroll : tty->TS_fwd_scroll;
1230 940
1231 register int i = n > 0 ? n : -n; 941 register int i = n > 0 ? n : -n;
1232 register char *buf; 942 register char *buf;
1233 943
1234 if (ins_del_lines_hook && ! FRAME_TERMCAP_P (updating_frame))
1235 {
1236 (*ins_del_lines_hook) (vpos, n);
1237 return;
1238 }
1239
1240 sf = XFRAME (selected_frame);
1241
1242 /* If the lines below the insertion are being pushed 944 /* If the lines below the insertion are being pushed
1243 into the end of the window, this is the same as clearing; 945 into the end of the window, this is the same as clearing;
1244 and we know the lines are already clear, since the matching 946 and we know the lines are already clear, since the matching
@@ -1246,45 +948,49 @@ ins_del_lines (vpos, n)
1246 /* If the lines below the deletion are blank lines coming 948 /* If the lines below the deletion are blank lines coming
1247 out of the end of the window, don't bother, 949 out of the end of the window, don't bother,
1248 as there will be a matching inslines later that will flush them. */ 950 as there will be a matching inslines later that will flush them. */
1249 if (scroll_region_ok && vpos + i >= specified_window) 951 if (FRAME_SCROLL_REGION_OK (f)
952 && vpos + i >= tty->specified_window)
1250 return; 953 return;
1251 if (!memory_below_frame && vpos + i >= FRAME_LINES (sf)) 954 if (!FRAME_MEMORY_BELOW_FRAME (f)
955 && vpos + i >= FRAME_LINES (f))
1252 return; 956 return;
1253 957
1254 if (multi) 958 if (multi)
1255 { 959 {
1256 raw_cursor_to (vpos, 0); 960 raw_cursor_to (f, vpos, 0);
1257 background_highlight (); 961 tty_background_highlight (tty);
1258 buf = tparam (multi, 0, 0, i); 962 buf = tparam (multi, 0, 0, i);
1259 OUTPUT (buf); 963 OUTPUT (tty, buf);
1260 xfree (buf); 964 xfree (buf);
1261 } 965 }
1262 else if (single) 966 else if (single)
1263 { 967 {
1264 raw_cursor_to (vpos, 0); 968 raw_cursor_to (f, vpos, 0);
1265 background_highlight (); 969 tty_background_highlight (tty);
1266 while (--i >= 0) 970 while (--i >= 0)
1267 OUTPUT (single); 971 OUTPUT (tty, single);
1268 if (TF_teleray) 972 if (tty->TF_teleray)
1269 curX = 0; 973 curX (tty) = 0;
1270 } 974 }
1271 else 975 else
1272 { 976 {
1273 set_scroll_region (vpos, specified_window); 977 tty_set_scroll_region (f, vpos, tty->specified_window);
1274 if (n < 0) 978 if (n < 0)
1275 raw_cursor_to (specified_window - 1, 0); 979 raw_cursor_to (f, tty->specified_window - 1, 0);
1276 else 980 else
1277 raw_cursor_to (vpos, 0); 981 raw_cursor_to (f, vpos, 0);
1278 background_highlight (); 982 tty_background_highlight (tty);
1279 while (--i >= 0) 983 while (--i >= 0)
1280 OUTPUTL (scroll, specified_window - vpos); 984 OUTPUTL (tty, scroll, tty->specified_window - vpos);
1281 set_scroll_region (0, specified_window); 985 tty_set_scroll_region (f, 0, tty->specified_window);
1282 } 986 }
1283 987
1284 if (!scroll_region_ok && memory_below_frame && n < 0) 988 if (!FRAME_SCROLL_REGION_OK (f)
989 && FRAME_MEMORY_BELOW_FRAME (f)
990 && n < 0)
1285 { 991 {
1286 cursor_to (FRAME_LINES (sf) + n, 0); 992 cursor_to (f, FRAME_LINES (f) + n, 0);
1287 clear_to_end (); 993 clear_to_end (f);
1288 } 994 }
1289} 995}
1290 996
@@ -1292,8 +998,7 @@ ins_del_lines (vpos, n)
1292 not counting any line-dependent padding. */ 998 not counting any line-dependent padding. */
1293 999
1294int 1000int
1295string_cost (str) 1001string_cost (char *str)
1296 char *str;
1297{ 1002{
1298 cost = 0; 1003 cost = 0;
1299 if (str) 1004 if (str)
@@ -1305,8 +1010,7 @@ string_cost (str)
1305 counting any line-dependent padding at one line. */ 1010 counting any line-dependent padding at one line. */
1306 1011
1307static int 1012static int
1308string_cost_one_line (str) 1013string_cost_one_line (char *str)
1309 char *str;
1310{ 1014{
1311 cost = 0; 1015 cost = 0;
1312 if (str) 1016 if (str)
@@ -1318,8 +1022,7 @@ string_cost_one_line (str)
1318 in tenths of characters. */ 1022 in tenths of characters. */
1319 1023
1320int 1024int
1321per_line_cost (str) 1025per_line_cost (char *str)
1322 register char *str;
1323{ 1026{
1324 cost = 0; 1027 cost = 0;
1325 if (str) 1028 if (str)
@@ -1342,26 +1045,26 @@ int *char_ins_del_vector;
1342 1045
1343/* ARGSUSED */ 1046/* ARGSUSED */
1344static void 1047static void
1345calculate_ins_del_char_costs (frame) 1048calculate_ins_del_char_costs (struct frame *f)
1346 FRAME_PTR frame;
1347{ 1049{
1050 struct tty_display_info *tty = FRAME_TTY (f);
1348 int ins_startup_cost, del_startup_cost; 1051 int ins_startup_cost, del_startup_cost;
1349 int ins_cost_per_char, del_cost_per_char; 1052 int ins_cost_per_char, del_cost_per_char;
1350 register int i; 1053 register int i;
1351 register int *p; 1054 register int *p;
1352 1055
1353 if (TS_ins_multi_chars) 1056 if (tty->TS_ins_multi_chars)
1354 { 1057 {
1355 ins_cost_per_char = 0; 1058 ins_cost_per_char = 0;
1356 ins_startup_cost = string_cost_one_line (TS_ins_multi_chars); 1059 ins_startup_cost = string_cost_one_line (tty->TS_ins_multi_chars);
1357 } 1060 }
1358 else if (TS_ins_char || TS_pad_inserted_char 1061 else if (tty->TS_ins_char || tty->TS_pad_inserted_char
1359 || (TS_insert_mode && TS_end_insert_mode)) 1062 || (tty->TS_insert_mode && tty->TS_end_insert_mode))
1360 { 1063 {
1361 ins_startup_cost = (30 * (string_cost (TS_insert_mode) 1064 ins_startup_cost = (30 * (string_cost (tty->TS_insert_mode)
1362 + string_cost (TS_end_insert_mode))) / 100; 1065 + string_cost (tty->TS_end_insert_mode))) / 100;
1363 ins_cost_per_char = (string_cost_one_line (TS_ins_char) 1066 ins_cost_per_char = (string_cost_one_line (tty->TS_ins_char)
1364 + string_cost_one_line (TS_pad_inserted_char)); 1067 + string_cost_one_line (tty->TS_pad_inserted_char));
1365 } 1068 }
1366 else 1069 else
1367 { 1070 {
@@ -1369,18 +1072,18 @@ calculate_ins_del_char_costs (frame)
1369 ins_cost_per_char = 0; 1072 ins_cost_per_char = 0;
1370 } 1073 }
1371 1074
1372 if (TS_del_multi_chars) 1075 if (tty->TS_del_multi_chars)
1373 { 1076 {
1374 del_cost_per_char = 0; 1077 del_cost_per_char = 0;
1375 del_startup_cost = string_cost_one_line (TS_del_multi_chars); 1078 del_startup_cost = string_cost_one_line (tty->TS_del_multi_chars);
1376 } 1079 }
1377 else if (TS_del_char) 1080 else if (tty->TS_del_char)
1378 { 1081 {
1379 del_startup_cost = (string_cost (TS_delete_mode) 1082 del_startup_cost = (string_cost (tty->TS_delete_mode)
1380 + string_cost (TS_end_delete_mode)); 1083 + string_cost (tty->TS_end_delete_mode));
1381 if (delete_in_insert_mode) 1084 if (tty->delete_in_insert_mode)
1382 del_startup_cost /= 2; 1085 del_startup_cost /= 2;
1383 del_cost_per_char = string_cost_one_line (TS_del_char); 1086 del_cost_per_char = string_cost_one_line (tty->TS_del_char);
1384 } 1087 }
1385 else 1088 else
1386 { 1089 {
@@ -1389,75 +1092,80 @@ calculate_ins_del_char_costs (frame)
1389 } 1092 }
1390 1093
1391 /* Delete costs are at negative offsets */ 1094 /* Delete costs are at negative offsets */
1392 p = &char_ins_del_cost (frame)[0]; 1095 p = &char_ins_del_cost (f)[0];
1393 for (i = FRAME_COLS (frame); --i >= 0;) 1096 for (i = FRAME_COLS (f); --i >= 0;)
1394 *--p = (del_startup_cost += del_cost_per_char); 1097 *--p = (del_startup_cost += del_cost_per_char);
1395 1098
1396 /* Doing nothing is free */ 1099 /* Doing nothing is free */
1397 p = &char_ins_del_cost (frame)[0]; 1100 p = &char_ins_del_cost (f)[0];
1398 *p++ = 0; 1101 *p++ = 0;
1399 1102
1400 /* Insert costs are at positive offsets */ 1103 /* Insert costs are at positive offsets */
1401 for (i = FRAME_COLS (frame); --i >= 0;) 1104 for (i = FRAME_COLS (f); --i >= 0;)
1402 *p++ = (ins_startup_cost += ins_cost_per_char); 1105 *p++ = (ins_startup_cost += ins_cost_per_char);
1403} 1106}
1404 1107
1405void 1108void
1406calculate_costs (frame) 1109calculate_costs (struct frame *frame)
1407 FRAME_PTR frame;
1408{ 1110{
1409 register char *f = (TS_set_scroll_region
1410 ? TS_set_scroll_region
1411 : TS_set_scroll_region_1);
1412
1413 FRAME_COST_BAUD_RATE (frame) = baud_rate; 1111 FRAME_COST_BAUD_RATE (frame) = baud_rate;
1414 1112
1415 scroll_region_cost = string_cost (f); 1113 if (FRAME_TERMCAP_P (frame))
1114 {
1115 struct tty_display_info *tty = FRAME_TTY (frame);
1116 register char *f = (tty->TS_set_scroll_region
1117 ? tty->TS_set_scroll_region
1118 : tty->TS_set_scroll_region_1);
1416 1119
1417 /* These variables are only used for terminal stuff. They are allocated 1120 FRAME_SCROLL_REGION_COST (frame) = string_cost (f);
1418 once for the terminal frame of X-windows emacs, but not used afterwards.
1419 1121
1420 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because 1122 tty->costs_set = 1;
1421 X turns off char_ins_del_ok. */
1422 1123
1423 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame)); 1124 /* These variables are only used for terminal stuff. They are
1424 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame)); 1125 allocated once for the terminal frame of X-windows emacs, but not
1126 used afterwards.
1425 1127
1426 costs_set = 1; 1128 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1129 X turns off char_ins_del_ok. */
1427 1130
1428 if (char_ins_del_vector != 0) 1131 max_frame_lines = max (max_frame_lines, FRAME_LINES (frame));
1429 char_ins_del_vector 1132 max_frame_cols = max (max_frame_cols, FRAME_COLS (frame));
1430 = (int *) xrealloc (char_ins_del_vector,
1431 (sizeof (int)
1432 + 2 * max_frame_cols * sizeof (int)));
1433 else
1434 char_ins_del_vector
1435 = (int *) xmalloc (sizeof (int)
1436 + 2 * max_frame_cols * sizeof (int));
1437
1438 bzero (char_ins_del_vector, (sizeof (int)
1439 + 2 * max_frame_cols * sizeof (int)));
1440
1441 if (f && (!TS_ins_line && !TS_del_line))
1442 do_line_insertion_deletion_costs (frame,
1443 TS_rev_scroll, TS_ins_multi_lines,
1444 TS_fwd_scroll, TS_del_multi_lines,
1445 f, f, 1);
1446 else
1447 do_line_insertion_deletion_costs (frame,
1448 TS_ins_line, TS_ins_multi_lines,
1449 TS_del_line, TS_del_multi_lines,
1450 0, 0, 1);
1451 1133
1452 calculate_ins_del_char_costs (frame); 1134 if (char_ins_del_vector != 0)
1135 char_ins_del_vector
1136 = (int *) xrealloc (char_ins_del_vector,
1137 (sizeof (int)
1138 + 2 * max_frame_cols * sizeof (int)));
1139 else
1140 char_ins_del_vector
1141 = (int *) xmalloc (sizeof (int)
1142 + 2 * max_frame_cols * sizeof (int));
1453 1143
1454 /* Don't use TS_repeat if its padding is worse than sending the chars */ 1144 bzero (char_ins_del_vector, (sizeof (int)
1455 if (TS_repeat && per_line_cost (TS_repeat) * baud_rate < 9000) 1145 + 2 * max_frame_cols * sizeof (int)));
1456 RPov = string_cost (TS_repeat);
1457 else
1458 RPov = FRAME_COLS (frame) * 2;
1459 1146
1460 cmcostinit (); /* set up cursor motion costs */ 1147
1148 if (f && (!tty->TS_ins_line && !tty->TS_del_line))
1149 do_line_insertion_deletion_costs (frame,
1150 tty->TS_rev_scroll, tty->TS_ins_multi_lines,
1151 tty->TS_fwd_scroll, tty->TS_del_multi_lines,
1152 f, f, 1);
1153 else
1154 do_line_insertion_deletion_costs (frame,
1155 tty->TS_ins_line, tty->TS_ins_multi_lines,
1156 tty->TS_del_line, tty->TS_del_multi_lines,
1157 0, 0, 1);
1158
1159 calculate_ins_del_char_costs (frame);
1160
1161 /* Don't use TS_repeat if its padding is worse than sending the chars */
1162 if (tty->TS_repeat && per_line_cost (tty->TS_repeat) * baud_rate < 9000)
1163 tty->RPov = string_cost (tty->TS_repeat);
1164 else
1165 tty->RPov = FRAME_COLS (frame) * 2;
1166
1167 cmcostinit (FRAME_TTY (frame)); /* set up cursor motion costs */
1168 }
1461} 1169}
1462 1170
1463struct fkey_table { 1171struct fkey_table {
@@ -1567,16 +1275,18 @@ static struct fkey_table keys[] =
1567 {"!3", "S-undo"} /*shifted undo key*/ 1275 {"!3", "S-undo"} /*shifted undo key*/
1568 }; 1276 };
1569 1277
1570static char **term_get_fkeys_arg; 1278static char **term_get_fkeys_address;
1279static KBOARD *term_get_fkeys_kboard;
1571static Lisp_Object term_get_fkeys_1 (); 1280static Lisp_Object term_get_fkeys_1 ();
1572 1281
1573/* Find the escape codes sent by the function keys for Vfunction_key_map. 1282/* Find the escape codes sent by the function keys for Vfunction_key_map.
1574 This function scans the termcap function key sequence entries, and 1283 This function scans the termcap function key sequence entries, and
1575 adds entries to Vfunction_key_map for each function key it finds. */ 1284 adds entries to Vfunction_key_map for each function key it finds. */
1576 1285
1577void 1286static void
1578term_get_fkeys (address) 1287term_get_fkeys (address, kboard)
1579 char **address; 1288 char **address;
1289 KBOARD *kboard;
1580{ 1290{
1581 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp 1291 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1582 errors during the call. The only errors should be from Fdefine_key 1292 errors during the call. The only errors should be from Fdefine_key
@@ -1587,7 +1297,8 @@ term_get_fkeys (address)
1587 refusing to run at all on such a terminal. */ 1297 refusing to run at all on such a terminal. */
1588 1298
1589 extern Lisp_Object Fidentity (); 1299 extern Lisp_Object Fidentity ();
1590 term_get_fkeys_arg = address; 1300 term_get_fkeys_address = address;
1301 term_get_fkeys_kboard = kboard;
1591 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity); 1302 internal_condition_case (term_get_fkeys_1, Qerror, Fidentity);
1592} 1303}
1593 1304
@@ -1596,17 +1307,18 @@ term_get_fkeys_1 ()
1596{ 1307{
1597 int i; 1308 int i;
1598 1309
1599 char **address = term_get_fkeys_arg; 1310 char **address = term_get_fkeys_address;
1600 1311 KBOARD *kboard = term_get_fkeys_kboard;
1312
1601 /* This can happen if CANNOT_DUMP or with strange options. */ 1313 /* This can happen if CANNOT_DUMP or with strange options. */
1602 if (!initialized) 1314 if (!initialized)
1603 Vfunction_key_map = Fmake_sparse_keymap (Qnil); 1315 kboard->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
1604 1316
1605 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++) 1317 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
1606 { 1318 {
1607 char *sequence = tgetstr (keys[i].cap, address); 1319 char *sequence = tgetstr (keys[i].cap, address);
1608 if (sequence) 1320 if (sequence)
1609 Fdefine_key (Vfunction_key_map, build_string (sequence), 1321 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence),
1610 Fmake_vector (make_number (1), 1322 Fmake_vector (make_number (1),
1611 intern (keys[i].name))); 1323 intern (keys[i].name)));
1612 } 1324 }
@@ -1626,13 +1338,13 @@ term_get_fkeys_1 ()
1626 if (k0) 1338 if (k0)
1627 /* Define f0 first, so that f10 takes precedence in case the 1339 /* Define f0 first, so that f10 takes precedence in case the
1628 key sequences happens to be the same. */ 1340 key sequences happens to be the same. */
1629 Fdefine_key (Vfunction_key_map, build_string (k0), 1341 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
1630 Fmake_vector (make_number (1), intern ("f0"))); 1342 Fmake_vector (make_number (1), intern ("f0")));
1631 Fdefine_key (Vfunction_key_map, build_string (k_semi), 1343 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k_semi),
1632 Fmake_vector (make_number (1), intern ("f10"))); 1344 Fmake_vector (make_number (1), intern ("f10")));
1633 } 1345 }
1634 else if (k0) 1346 else if (k0)
1635 Fdefine_key (Vfunction_key_map, build_string (k0), 1347 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0),
1636 Fmake_vector (make_number (1), intern (k0_name))); 1348 Fmake_vector (make_number (1), intern (k0_name)));
1637 } 1349 }
1638 1350
@@ -1655,7 +1367,7 @@ term_get_fkeys_1 ()
1655 if (sequence) 1367 if (sequence)
1656 { 1368 {
1657 sprintf (fkey, "f%d", i); 1369 sprintf (fkey, "f%d", i);
1658 Fdefine_key (Vfunction_key_map, build_string (sequence), 1370 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence),
1659 Fmake_vector (make_number (1), 1371 Fmake_vector (make_number (1),
1660 intern (fkey))); 1372 intern (fkey)));
1661 } 1373 }
@@ -1671,10 +1383,10 @@ term_get_fkeys_1 ()
1671 if (!tgetstr (cap1, address)) \ 1383 if (!tgetstr (cap1, address)) \
1672 { \ 1384 { \
1673 char *sequence = tgetstr (cap2, address); \ 1385 char *sequence = tgetstr (cap2, address); \
1674 if (sequence) \ 1386 if (sequence) \
1675 Fdefine_key (Vfunction_key_map, build_string (sequence), \ 1387 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), \
1676 Fmake_vector (make_number (1), \ 1388 Fmake_vector (make_number (1), \
1677 intern (sym))); \ 1389 intern (sym))); \
1678 } 1390 }
1679 1391
1680 /* if there's no key_next keycap, map key_npage to `next' keysym */ 1392 /* if there's no key_next keycap, map key_npage to `next' keysym */
@@ -2030,10 +1742,10 @@ produce_special_glyphs (it, what)
2030 from them. Some display attributes may not be used together with 1742 from them. Some display attributes may not be used together with
2031 color; the termcap capability `NC' specifies which ones. */ 1743 color; the termcap capability `NC' specifies which ones. */
2032 1744
2033#define MAY_USE_WITH_COLORS_P(ATTR) \ 1745#define MAY_USE_WITH_COLORS_P(tty, ATTR) \
2034 (TN_max_colors > 0 \ 1746 (tty->TN_max_colors > 0 \
2035 ? (TN_no_color_video & (ATTR)) == 0 \ 1747 ? (tty->TN_no_color_video & (ATTR)) == 0 \
2036 : 1) 1748 : 1)
2037 1749
2038/* Turn appearances of face FACE_ID on tty frame F on. 1750/* Turn appearances of face FACE_ID on tty frame F on.
2039 FACE_ID is a realized face ID number, in the face cache. */ 1751 FACE_ID is a realized face ID number, in the face cache. */
@@ -2046,12 +1758,13 @@ turn_on_face (f, face_id)
2046 struct face *face = FACE_FROM_ID (f, face_id); 1758 struct face *face = FACE_FROM_ID (f, face_id);
2047 long fg = face->foreground; 1759 long fg = face->foreground;
2048 long bg = face->background; 1760 long bg = face->background;
1761 struct tty_display_info *tty = FRAME_TTY (f);
2049 1762
2050 /* Do this first because TS_end_standout_mode may be the same 1763 /* Do this first because TS_end_standout_mode may be the same
2051 as TS_exit_attribute_mode, which turns all appearances off. */ 1764 as TS_exit_attribute_mode, which turns all appearances off. */
2052 if (MAY_USE_WITH_COLORS_P (NC_REVERSE)) 1765 if (MAY_USE_WITH_COLORS_P (tty, NC_REVERSE))
2053 { 1766 {
2054 if (TN_max_colors > 0) 1767 if (tty->TN_max_colors > 0)
2055 { 1768 {
2056 if (fg >= 0 && bg >= 0) 1769 if (fg >= 0 && bg >= 0)
2057 { 1770 {
@@ -2065,13 +1778,13 @@ turn_on_face (f, face_id)
2065 { 1778 {
2066 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1779 if (fg == FACE_TTY_DEFAULT_FG_COLOR
2067 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1780 || bg == FACE_TTY_DEFAULT_BG_COLOR)
2068 toggle_highlight (); 1781 tty_toggle_highlight (tty);
2069 } 1782 }
2070 else 1783 else
2071 { 1784 {
2072 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1785 if (fg == FACE_TTY_DEFAULT_BG_COLOR
2073 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1786 || bg == FACE_TTY_DEFAULT_FG_COLOR)
2074 toggle_highlight (); 1787 tty_toggle_highlight (tty);
2075 } 1788 }
2076 } 1789 }
2077 else 1790 else
@@ -2082,55 +1795,55 @@ turn_on_face (f, face_id)
2082 { 1795 {
2083 if (fg == FACE_TTY_DEFAULT_FG_COLOR 1796 if (fg == FACE_TTY_DEFAULT_FG_COLOR
2084 || bg == FACE_TTY_DEFAULT_BG_COLOR) 1797 || bg == FACE_TTY_DEFAULT_BG_COLOR)
2085 toggle_highlight (); 1798 tty_toggle_highlight (tty);
2086 } 1799 }
2087 else 1800 else
2088 { 1801 {
2089 if (fg == FACE_TTY_DEFAULT_BG_COLOR 1802 if (fg == FACE_TTY_DEFAULT_BG_COLOR
2090 || bg == FACE_TTY_DEFAULT_FG_COLOR) 1803 || bg == FACE_TTY_DEFAULT_FG_COLOR)
2091 toggle_highlight (); 1804 tty_toggle_highlight (tty);
2092 } 1805 }
2093 } 1806 }
2094 } 1807 }
2095 1808
2096 if (face->tty_bold_p) 1809 if (face->tty_bold_p)
2097 { 1810 {
2098 if (MAY_USE_WITH_COLORS_P (NC_BOLD)) 1811 if (MAY_USE_WITH_COLORS_P (tty, NC_BOLD))
2099 OUTPUT1_IF (TS_enter_bold_mode); 1812 OUTPUT1_IF (tty, tty->TS_enter_bold_mode);
2100 } 1813 }
2101 else if (face->tty_dim_p) 1814 else if (face->tty_dim_p)
2102 if (MAY_USE_WITH_COLORS_P (NC_DIM)) 1815 if (MAY_USE_WITH_COLORS_P (tty, NC_DIM))
2103 OUTPUT1_IF (TS_enter_dim_mode); 1816 OUTPUT1_IF (tty, tty->TS_enter_dim_mode);
2104 1817
2105 /* Alternate charset and blinking not yet used. */ 1818 /* Alternate charset and blinking not yet used. */
2106 if (face->tty_alt_charset_p 1819 if (face->tty_alt_charset_p
2107 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET)) 1820 && MAY_USE_WITH_COLORS_P (tty, NC_ALT_CHARSET))
2108 OUTPUT1_IF (TS_enter_alt_charset_mode); 1821 OUTPUT1_IF (tty, tty->TS_enter_alt_charset_mode);
2109 1822
2110 if (face->tty_blinking_p 1823 if (face->tty_blinking_p
2111 && MAY_USE_WITH_COLORS_P (NC_BLINK)) 1824 && MAY_USE_WITH_COLORS_P (tty, NC_BLINK))
2112 OUTPUT1_IF (TS_enter_blink_mode); 1825 OUTPUT1_IF (tty, tty->TS_enter_blink_mode);
2113 1826
2114 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE)) 1827 if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (tty, NC_UNDERLINE))
2115 OUTPUT1_IF (TS_enter_underline_mode); 1828 OUTPUT1_IF (tty, tty->TS_enter_underline_mode);
2116 1829
2117 if (TN_max_colors > 0) 1830 if (tty->TN_max_colors > 0)
2118 { 1831 {
2119 char *ts, *p; 1832 char *ts, *p;
2120 1833
2121 ts = standout_mode ? TS_set_background : TS_set_foreground; 1834 ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground;
2122 if (fg >= 0 && ts) 1835 if (fg >= 0 && ts)
2123 { 1836 {
2124 p = tparam (ts, NULL, 0, (int) fg); 1837 p = tparam (ts, NULL, 0, (int) fg);
2125 OUTPUT (p); 1838 OUTPUT (tty, p);
2126 xfree (p); 1839 xfree (p);
2127 } 1840 }
2128 1841
2129 ts = standout_mode ? TS_set_foreground : TS_set_background; 1842 ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background;
2130 if (bg >= 0 && ts) 1843 if (bg >= 0 && ts)
2131 { 1844 {
2132 p = tparam (ts, NULL, 0, (int) bg); 1845 p = tparam (ts, NULL, 0, (int) bg);
2133 OUTPUT (p); 1846 OUTPUT (tty, p);
2134 xfree (p); 1847 xfree (p);
2135 } 1848 }
2136 } 1849 }
@@ -2145,10 +1858,11 @@ turn_off_face (f, face_id)
2145 int face_id; 1858 int face_id;
2146{ 1859{
2147 struct face *face = FACE_FROM_ID (f, face_id); 1860 struct face *face = FACE_FROM_ID (f, face_id);
1861 struct tty_display_info *tty = FRAME_TTY (f);
2148 1862
2149 xassert (face != NULL); 1863 xassert (face != NULL);
2150 1864
2151 if (TS_exit_attribute_mode) 1865 if (tty->TS_exit_attribute_mode)
2152 { 1866 {
2153 /* Capability "me" will turn off appearance modes double-bright, 1867 /* Capability "me" will turn off appearance modes double-bright,
2154 half-bright, reverse-video, standout, underline. It may or 1868 half-bright, reverse-video, standout, underline. It may or
@@ -2160,32 +1874,32 @@ turn_off_face (f, face_id)
2160 || face->tty_blinking_p 1874 || face->tty_blinking_p
2161 || face->tty_underline_p) 1875 || face->tty_underline_p)
2162 { 1876 {
2163 OUTPUT1_IF (TS_exit_attribute_mode); 1877 OUTPUT1_IF (tty, tty->TS_exit_attribute_mode);
2164 if (strcmp (TS_exit_attribute_mode, TS_end_standout_mode) == 0) 1878 if (strcmp (tty->TS_exit_attribute_mode, tty->TS_end_standout_mode) == 0)
2165 standout_mode = 0; 1879 tty->standout_mode = 0;
2166 } 1880 }
2167 1881
2168 if (face->tty_alt_charset_p) 1882 if (face->tty_alt_charset_p)
2169 OUTPUT_IF (TS_exit_alt_charset_mode); 1883 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
2170 } 1884 }
2171 else 1885 else
2172 { 1886 {
2173 /* If we don't have "me" we can only have those appearances 1887 /* If we don't have "me" we can only have those appearances
2174 that have exit sequences defined. */ 1888 that have exit sequences defined. */
2175 if (face->tty_alt_charset_p) 1889 if (face->tty_alt_charset_p)
2176 OUTPUT_IF (TS_exit_alt_charset_mode); 1890 OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode);
2177 1891
2178 if (face->tty_underline_p) 1892 if (face->tty_underline_p)
2179 OUTPUT_IF (TS_exit_underline_mode); 1893 OUTPUT_IF (tty, tty->TS_exit_underline_mode);
2180 } 1894 }
2181 1895
2182 /* Switch back to default colors. */ 1896 /* Switch back to default colors. */
2183 if (TN_max_colors > 0 1897 if (tty->TN_max_colors > 0
2184 && ((face->foreground != FACE_TTY_DEFAULT_COLOR 1898 && ((face->foreground != FACE_TTY_DEFAULT_COLOR
2185 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR) 1899 && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
2186 || (face->background != FACE_TTY_DEFAULT_COLOR 1900 || (face->background != FACE_TTY_DEFAULT_COLOR
2187 && face->background != FACE_TTY_DEFAULT_BG_COLOR))) 1901 && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
2188 OUTPUT1_IF (TS_orig_pair); 1902 OUTPUT1_IF (tty, tty->TS_orig_pair);
2189} 1903}
2190 1904
2191 1905
@@ -2194,46 +1908,61 @@ turn_off_face (f, face_id)
2194 colors FG and BG. */ 1908 colors FG and BG. */
2195 1909
2196int 1910int
2197tty_capable_p (f, caps, fg, bg) 1911tty_capable_p (tty, caps, fg, bg)
2198 struct frame *f; 1912 struct tty_display_info *tty;
2199 unsigned caps; 1913 unsigned caps;
2200 unsigned long fg, bg; 1914 unsigned long fg, bg;
2201{ 1915{
2202#define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \ 1916#define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2203 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \ 1917 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2204 return 0; 1918 return 0;
2205 1919
2206 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE); 1920 TTY_CAPABLE_P_TRY (tty, TTY_CAP_INVERSE, tty->TS_standout_mode, NC_REVERSE);
2207 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE); 1921 TTY_CAPABLE_P_TRY (tty, TTY_CAP_UNDERLINE, tty->TS_enter_underline_mode, NC_UNDERLINE);
2208 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD); 1922 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BOLD, tty->TS_enter_bold_mode, NC_BOLD);
2209 TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM); 1923 TTY_CAPABLE_P_TRY (tty, TTY_CAP_DIM, tty->TS_enter_dim_mode, NC_DIM);
2210 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK); 1924 TTY_CAPABLE_P_TRY (tty, TTY_CAP_BLINK, tty->TS_enter_blink_mode, NC_BLINK);
2211 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET); 1925 TTY_CAPABLE_P_TRY (tty, TTY_CAP_ALT_CHARSET, tty->TS_enter_alt_charset_mode, NC_ALT_CHARSET);
2212 1926
2213 /* We can do it! */ 1927 /* We can do it! */
2214 return 1; 1928 return 1;
2215} 1929}
2216 1930
2217
2218/* Return non-zero if the terminal is capable to display colors. */ 1931/* Return non-zero if the terminal is capable to display colors. */
2219 1932
2220DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p, 1933DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
2221 0, 1, 0, 1934 0, 1, 0,
2222 doc: /* Return non-nil if TTY can display colors on DISPLAY. */) 1935 doc: /* Return non-nil if the tty device TERMINAL can display colors.
2223 (display) 1936
2224 Lisp_Object display; 1937TERMINAL can be a terminal id, a frame or nil (meaning the selected
1938frame's terminal). This function always returns nil if TERMINAL
1939is not on a tty device. */)
1940 (terminal)
1941 Lisp_Object terminal;
2225{ 1942{
2226 return TN_max_colors > 0 ? Qt : Qnil; 1943 struct terminal *t = get_tty_terminal (terminal, 0);
1944 if (!t)
1945 return Qnil;
1946 else
1947 return t->display_info.tty->TN_max_colors > 0 ? Qt : Qnil;
2227} 1948}
2228 1949
2229/* Return the number of supported colors. */ 1950/* Return the number of supported colors. */
2230DEFUN ("tty-display-color-cells", Ftty_display_color_cells, 1951DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
2231 Stty_display_color_cells, 0, 1, 0, 1952 Stty_display_color_cells, 0, 1, 0,
2232 doc: /* Return the number of colors supported by TTY on DISPLAY. */) 1953 doc: /* Return the number of colors supported by the tty device TERMINAL.
2233 (display) 1954
2234 Lisp_Object display; 1955TERMINAL can be a terminal id, a frame or nil (meaning the selected
1956frame's terminal). This function always returns 0 if TERMINAL
1957is not on a tty device. */)
1958 (terminal)
1959 Lisp_Object terminal;
2235{ 1960{
2236 return make_number (TN_max_colors); 1961 struct terminal *t = get_tty_terminal (terminal, 0);
1962 if (!t)
1963 return make_number (0);
1964 else
1965 return make_number (t->display_info.tty->TN_max_colors);
2237} 1966}
2238 1967
2239#ifndef WINDOWSNT 1968#ifndef WINDOWSNT
@@ -2251,48 +1980,46 @@ static char *default_set_background;
2251/* Save or restore the default color-related capabilities of this 1980/* Save or restore the default color-related capabilities of this
2252 terminal. */ 1981 terminal. */
2253static void 1982static void
2254tty_default_color_capabilities (save) 1983tty_default_color_capabilities (struct tty_display_info *tty, int save)
2255 int save;
2256{ 1984{
2257 1985
2258 if (save) 1986 if (save)
2259 { 1987 {
2260 if (default_orig_pair) 1988 if (default_orig_pair)
2261 xfree (default_orig_pair); 1989 xfree (default_orig_pair);
2262 default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL; 1990 default_orig_pair = tty->TS_orig_pair ? xstrdup (tty->TS_orig_pair) : NULL;
2263 1991
2264 if (default_set_foreground) 1992 if (default_set_foreground)
2265 xfree (default_set_foreground); 1993 xfree (default_set_foreground);
2266 default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground) 1994 default_set_foreground = tty->TS_set_foreground ? xstrdup (tty->TS_set_foreground)
2267 : NULL; 1995 : NULL;
2268 1996
2269 if (default_set_background) 1997 if (default_set_background)
2270 xfree (default_set_background); 1998 xfree (default_set_background);
2271 default_set_background = TS_set_background ? xstrdup (TS_set_background) 1999 default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background)
2272 : NULL; 2000 : NULL;
2273 2001
2274 default_max_colors = TN_max_colors; 2002 default_max_colors = tty->TN_max_colors;
2275 default_max_pairs = TN_max_pairs; 2003 default_max_pairs = tty->TN_max_pairs;
2276 default_no_color_video = TN_no_color_video; 2004 default_no_color_video = tty->TN_no_color_video;
2277 } 2005 }
2278 else 2006 else
2279 { 2007 {
2280 TS_orig_pair = default_orig_pair; 2008 tty->TS_orig_pair = default_orig_pair;
2281 TS_set_foreground = default_set_foreground; 2009 tty->TS_set_foreground = default_set_foreground;
2282 TS_set_background = default_set_background; 2010 tty->TS_set_background = default_set_background;
2283 TN_max_colors = default_max_colors; 2011 tty->TN_max_colors = default_max_colors;
2284 TN_max_pairs = default_max_pairs; 2012 tty->TN_max_pairs = default_max_pairs;
2285 TN_no_color_video = default_no_color_video; 2013 tty->TN_no_color_video = default_no_color_video;
2286 } 2014 }
2287} 2015}
2288 2016
2289/* Setup one of the standard tty color schemes according to MODE. 2017/* Setup one of the standard tty color schemes according to MODE.
2290 MODE's value is generally the number of colors which we want to 2018 MODE's value is generally the number of colors which we want to
2291 support; zero means set up for the default capabilities, the ones 2019 support; zero means set up for the default capabilities, the ones
2292 we saw at term_init time; -1 means turn off color support. */ 2020 we saw at init_tty time; -1 means turn off color support. */
2293void 2021static void
2294tty_setup_colors (mode) 2022tty_setup_colors (struct tty_display_info *tty, int mode)
2295 int mode;
2296{ 2023{
2297 /* Canonicalize all negative values of MODE. */ 2024 /* Canonicalize all negative values of MODE. */
2298 if (mode < -1) 2025 if (mode < -1)
@@ -2301,27 +2028,27 @@ tty_setup_colors (mode)
2301 switch (mode) 2028 switch (mode)
2302 { 2029 {
2303 case -1: /* no colors at all */ 2030 case -1: /* no colors at all */
2304 TN_max_colors = 0; 2031 tty->TN_max_colors = 0;
2305 TN_max_pairs = 0; 2032 tty->TN_max_pairs = 0;
2306 TN_no_color_video = 0; 2033 tty->TN_no_color_video = 0;
2307 TS_set_foreground = TS_set_background = TS_orig_pair = NULL; 2034 tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL;
2308 break; 2035 break;
2309 case 0: /* default colors, if any */ 2036 case 0: /* default colors, if any */
2310 default: 2037 default:
2311 tty_default_color_capabilities (0); 2038 tty_default_color_capabilities (tty, 0);
2312 break; 2039 break;
2313 case 8: /* 8 standard ANSI colors */ 2040 case 8: /* 8 standard ANSI colors */
2314 TS_orig_pair = "\033[0m"; 2041 tty->TS_orig_pair = "\033[0m";
2315#ifdef TERMINFO 2042#ifdef TERMINFO
2316 TS_set_foreground = "\033[3%p1%dm"; 2043 tty->TS_set_foreground = "\033[3%p1%dm";
2317 TS_set_background = "\033[4%p1%dm"; 2044 tty->TS_set_background = "\033[4%p1%dm";
2318#else 2045#else
2319 TS_set_foreground = "\033[3%dm"; 2046 tty->TS_set_foreground = "\033[3%dm";
2320 TS_set_background = "\033[4%dm"; 2047 tty->TS_set_background = "\033[4%dm";
2321#endif 2048#endif
2322 TN_max_colors = 8; 2049 tty->TN_max_colors = 8;
2323 TN_max_pairs = 64; 2050 tty->TN_max_pairs = 64;
2324 TN_no_color_video = 0; 2051 tty->TN_no_color_video = 0;
2325 break; 2052 break;
2326 } 2053 }
2327} 2054}
@@ -2372,7 +2099,7 @@ set_tty_color_mode (f, val)
2372 2099
2373 if (mode != old_mode) 2100 if (mode != old_mode)
2374 { 2101 {
2375 tty_setup_colors (mode); 2102 tty_setup_colors (FRAME_TTY (f), mode);
2376 /* This recomputes all the faces given the new color 2103 /* This recomputes all the faces given the new color
2377 definitions. */ 2104 definitions. */
2378 call0 (intern ("tty-set-up-initial-frame-faces")); 2105 call0 (intern ("tty-set-up-initial-frame-faces"));
@@ -2383,6 +2110,241 @@ set_tty_color_mode (f, val)
2383#endif /* !WINDOWSNT */ 2110#endif /* !WINDOWSNT */
2384 2111
2385 2112
2113
2114/* Return the tty display object specified by TERMINAL. */
2115
2116struct terminal *
2117get_tty_terminal (Lisp_Object terminal, int throw)
2118{
2119 struct terminal *t = get_terminal (terminal, throw);
2120
2121 if (t && t->type == output_initial)
2122 return NULL;
2123
2124 if (t && t->type != output_termcap)
2125 {
2126 if (throw)
2127 error ("Device %d is not a termcap terminal device", t->id);
2128 else
2129 return NULL;
2130 }
2131
2132 return t;
2133}
2134
2135/* Return an active termcap device that uses the tty device with the
2136 given name.
2137
2138 This function ignores suspended devices.
2139
2140 Returns NULL if the named terminal device is not opened. */
2141
2142struct terminal *
2143get_named_tty (name)
2144 char *name;
2145{
2146 struct terminal *t;
2147
2148 if (!name)
2149 abort ();
2150
2151 for (t = terminal_list; t; t = t->next_terminal)
2152 {
2153 if (t->type == output_termcap
2154 && !strcmp (t->display_info.tty->name, name)
2155 && TERMINAL_ACTIVE_P (t))
2156 return t;
2157 }
2158
2159 return 0;
2160}
2161
2162
2163DEFUN ("tty-type", Ftty_type, Stty_type, 0, 1, 0,
2164 doc: /* Return the type of the tty device that TERMINAL uses.
2165Returns nil if TERMINAL is not on a tty device.
2166
2167TERMINAL can be a terminal id, a frame or nil (meaning the selected
2168frame's terminal). */)
2169 (terminal)
2170 Lisp_Object terminal;
2171{
2172 struct terminal *t = get_terminal (terminal, 1);
2173
2174 if (t->type != output_termcap)
2175 return Qnil;
2176
2177 if (t->display_info.tty->type)
2178 return build_string (t->display_info.tty->type);
2179 else
2180 return Qnil;
2181}
2182
2183DEFUN ("controlling-tty-p", Fcontrolling_tty_p, Scontrolling_tty_p, 0, 1, 0,
2184 doc: /* Return non-nil if TERMINAL is on the controlling tty of the Emacs process.
2185
2186TERMINAL can be a terminal id, a frame or nil (meaning the selected
2187frame's terminal). This function always returns nil if TERMINAL
2188is not on a tty device. */)
2189 (terminal)
2190 Lisp_Object terminal;
2191{
2192 struct terminal *t = get_terminal (terminal, 1);
2193
2194 if (t->type != output_termcap || strcmp (t->display_info.tty->name, "/dev/tty"))
2195 return Qnil;
2196 else
2197 return Qt;
2198}
2199
2200DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 1, 0,
2201 doc: /* Declare that the tty used by TERMINAL does not handle underlining.
2202This is used to override the terminfo data, for certain terminals that
2203do not really do underlining, but say that they do. This function has
2204no effect if used on a non-tty terminal.
2205
2206TERMINAL can be a terminal id, a frame or nil (meaning the selected
2207frame's terminal). This function always returns nil if TERMINAL
2208is not on a tty device. */)
2209 (terminal)
2210 Lisp_Object terminal;
2211{
2212 struct terminal *t = get_terminal (terminal, 1);
2213
2214 if (t->type == output_termcap)
2215 t->display_info.tty->TS_enter_underline_mode = 0;
2216 return Qnil;
2217}
2218
2219
2220
2221DEFUN ("suspend-tty", Fsuspend_tty, Ssuspend_tty, 0, 1, 0,
2222 doc: /* Suspend the terminal device TTY.
2223
2224The device is restored to its default state, and Emacs ceases all
2225access to the tty device. Frames that use the device are not deleted,
2226but input is not read from them and if they change, their display is
2227not updated.
2228
2229TTY may be a terminal id, a frame, or nil for the terminal device of
2230the currently selected frame.
2231
2232This function runs `suspend-tty-functions' after suspending the
2233device. The functions are run with one arg, the id of the suspended
2234terminal device.
2235
2236`suspend-tty' does nothing if it is called on a device that is already
2237suspended.
2238
2239A suspended tty may be resumed by calling `resume-tty' on it. */)
2240 (tty)
2241 Lisp_Object tty;
2242{
2243 struct terminal *t = get_tty_terminal (tty, 1);
2244 FILE *f;
2245
2246 if (!t)
2247 error ("Unknown tty device");
2248
2249 f = t->display_info.tty->input;
2250
2251 if (f)
2252 {
2253 reset_sys_modes (t->display_info.tty);
2254
2255 delete_keyboard_wait_descriptor (fileno (f));
2256
2257 fclose (f);
2258 if (f != t->display_info.tty->output)
2259 fclose (t->display_info.tty->output);
2260
2261 t->display_info.tty->input = 0;
2262 t->display_info.tty->output = 0;
2263
2264 if (FRAMEP (t->display_info.tty->top_frame))
2265 FRAME_SET_VISIBLE (XFRAME (t->display_info.tty->top_frame), 0);
2266
2267 /* Run `suspend-tty-functions'. */
2268 if (!NILP (Vrun_hooks))
2269 {
2270 Lisp_Object args[2];
2271 args[0] = intern ("suspend-tty-functions");
2272 args[1] = make_number (t->id);
2273 Frun_hook_with_args (2, args);
2274 }
2275 }
2276
2277 /* Clear display hooks to prevent further output. */
2278 clear_tty_hooks (t);
2279
2280 return Qnil;
2281}
2282
2283DEFUN ("resume-tty", Fresume_tty, Sresume_tty, 0, 1, 0,
2284 doc: /* Resume the previously suspended terminal device TTY.
2285The terminal is opened and reinitialized. Frames that are on the
2286suspended terminal are revived.
2287
2288It is an error to resume a terminal while another terminal is active
2289on the same device.
2290
2291This function runs `resume-tty-functions' after resuming the terminal.
2292The functions are run with one arg, the id of the resumed terminal
2293device.
2294
2295`resume-tty' does nothing if it is called on a device that is not
2296suspended.
2297
2298TTY may be a terminal id, a frame, or nil for the terminal device of
2299the currently selected frame. */)
2300 (tty)
2301 Lisp_Object tty;
2302{
2303 struct terminal *t = get_tty_terminal (tty, 1);
2304 int fd;
2305
2306 if (!t)
2307 error ("Unknown tty device");
2308
2309 if (!t->display_info.tty->input)
2310 {
2311 if (get_named_tty (t->display_info.tty->name))
2312 error ("Cannot resume display while another display is active on the same device");
2313
2314 fd = emacs_open (t->display_info.tty->name, O_RDWR | O_NOCTTY, 0);
2315
2316 if (fd == -1)
2317 error ("Can not reopen tty device %s: %s", t->display_info.tty->name, strerror (errno));
2318
2319 if (strcmp (t->display_info.tty->name, "/dev/tty"))
2320 dissociate_if_controlling_tty (fd);
2321
2322 t->display_info.tty->output = fdopen (fd, "w+");
2323 t->display_info.tty->input = t->display_info.tty->output;
2324
2325 add_keyboard_wait_descriptor (fd);
2326
2327 if (FRAMEP (t->display_info.tty->top_frame))
2328 FRAME_SET_VISIBLE (XFRAME (t->display_info.tty->top_frame), 1);
2329
2330 init_sys_modes (t->display_info.tty);
2331
2332 /* Run `suspend-tty-functions'. */
2333 if (!NILP (Vrun_hooks))
2334 {
2335 Lisp_Object args[2];
2336 args[0] = intern ("resume-tty-functions");
2337 args[1] = make_number (t->id);
2338 Frun_hook_with_args (2, args);
2339 }
2340 }
2341
2342 set_tty_hooks (t);
2343
2344 return Qnil;
2345}
2346
2347
2386/*********************************************************************** 2348/***********************************************************************
2387 Mouse 2349 Mouse
2388 ***********************************************************************/ 2350 ***********************************************************************/
@@ -2409,6 +2371,9 @@ term_show_mouse_face (enum draw_glyphs_face draw)
2409 int save_x, save_y; 2371 int save_x, save_y;
2410 int i; 2372 int i;
2411 2373
2374 struct frame *f = XFRAME (w->frame);
2375 struct tty_display_info *tty = FRAME_TTY (f);
2376
2412 if (/* If window is in the process of being destroyed, don't bother 2377 if (/* If window is in the process of being destroyed, don't bother
2413 to do anything. */ 2378 to do anything. */
2414 w->current_matrix != NULL 2379 w->current_matrix != NULL
@@ -2421,8 +2386,8 @@ term_show_mouse_face (enum draw_glyphs_face draw)
2421 the highlight region. */ 2386 the highlight region. */
2422 2387
2423 /* Save current cursor co-ordinates */ 2388 /* Save current cursor co-ordinates */
2424 save_y = curY; 2389 save_y = curY (tty);
2425 save_x = curX; 2390 save_x = curX (tty);
2426 2391
2427 /* Note that mouse_face_beg_row etc. are window relative. */ 2392 /* Note that mouse_face_beg_row etc. are window relative. */
2428 for (i = mouse_face_beg_row; i <= mouse_face_end_row; i++) 2393 for (i = mouse_face_beg_row; i <= mouse_face_end_row; i++)
@@ -2464,17 +2429,17 @@ term_show_mouse_face (enum draw_glyphs_face draw)
2464 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos 2429 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos
2465 + WINDOW_LEFT_EDGE_X (w); 2430 + WINDOW_LEFT_EDGE_X (w);
2466 2431
2467 cursor_to (pos_y, pos_x); 2432 cursor_to (f, pos_y, pos_x);
2468 2433
2469 if (draw == DRAW_MOUSE_FACE) 2434 if (draw == DRAW_MOUSE_FACE)
2470 { 2435 {
2471 write_glyphs_with_face (row->glyphs[TEXT_AREA] + start_hpos, 2436 tty_write_glyphs_with_face (f, row->glyphs[TEXT_AREA] + start_hpos,
2472 nglyphs, mouse_face_face_id); 2437 nglyphs, mouse_face_face_id);
2473 } 2438 }
2474 else /* draw == DRAW_NORMAL_TEXT */ 2439 else /* draw == DRAW_NORMAL_TEXT */
2475 write_glyphs (row->glyphs[TEXT_AREA] + start_hpos, nglyphs); 2440 write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
2476 } 2441 }
2477 cursor_to (save_y, save_x); 2442 cursor_to (f, save_y, save_x);
2478 } 2443 }
2479} 2444}
2480 2445
@@ -2924,9 +2889,9 @@ term_mouse_click (struct input_event *result, Gpm_Event *event,
2924} 2889}
2925 2890
2926int 2891int
2927handle_one_term_event (Gpm_Event *event, struct input_event* hold_quit) 2892handle_one_term_event (struct tty_display_info *tty, Gpm_Event *event, struct input_event* hold_quit)
2928{ 2893{
2929 struct frame *f = SELECTED_FRAME (); 2894 struct frame *f = XFRAME (tty->top_frame);
2930 int fd; 2895 int fd;
2931 struct input_event ie; 2896 struct input_event ie;
2932 int do_help = 0; 2897 int do_help = 0;
@@ -3002,6 +2967,7 @@ DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
3002 doc: /* Open a connection to Gpm. */) 2967 doc: /* Open a connection to Gpm. */)
3003 () 2968 ()
3004{ 2969{
2970 struct tty_display_info *tty = FRAME_TTY (SELECTED_FRAME ());
3005 Gpm_Connect connection; 2971 Gpm_Connect connection;
3006 2972
3007 connection.eventMask = ~0; 2973 connection.eventMask = ~0;
@@ -3010,13 +2976,16 @@ DEFUN ("term-open-connection", Fterm_open_connection, Sterm_open_connection,
3010 connection.minMod = 0; 2976 connection.minMod = 0;
3011 gpm_zerobased = 1; 2977 gpm_zerobased = 1;
3012 2978
3013 if (Gpm_Open (&connection, 0) < 0) 2979 /* We only support GPM on the controlling tty. */
2980 if (term_gpm || tty->terminal->id > 1
2981 || Gpm_Open (&connection, 0) < 0)
3014 return Qnil; 2982 return Qnil;
3015 else 2983 else
3016 { 2984 {
3017 term_gpm = 1; 2985 term_gpm = 1;
3018 reset_sys_modes (); 2986 gpm_tty = tty->terminal->id;
3019 init_sys_modes (); 2987 reset_sys_modes (tty);
2988 init_sys_modes (tty);
3020 add_gpm_wait_descriptor (gpm_fd); 2989 add_gpm_wait_descriptor (gpm_fd);
3021 return Qt; 2990 return Qt;
3022 } 2991 }
@@ -3039,86 +3008,358 @@ DEFUN ("term-close-connection", Fterm_close_connection, Sterm_close_connection,
3039 Initialization 3008 Initialization
3040 ***********************************************************************/ 3009 ***********************************************************************/
3041 3010
3011/* Initialize the tty-dependent part of frame F. The frame must
3012 already have its device initialized. */
3013
3042void 3014void
3043term_init (terminal_type) 3015create_tty_output (struct frame *f)
3044 char *terminal_type; 3016{
3017 struct tty_output *t;
3018
3019 if (! FRAME_TERMCAP_P (f))
3020 abort ();
3021
3022 t = xmalloc (sizeof (struct tty_output));
3023 bzero (t, sizeof (struct tty_output));
3024
3025 t->display_info = FRAME_TERMINAL (f)->display_info.tty;
3026
3027 f->output_data.tty = t;
3028}
3029
3030/* Delete the tty-dependent part of frame F. */
3031
3032static void
3033delete_tty_output (struct frame *f)
3034{
3035 if (! FRAME_TERMCAP_P (f))
3036 abort ();
3037
3038 xfree (f->output_data.tty);
3039}
3040
3041
3042
3043static void
3044clear_tty_hooks (struct terminal *terminal)
3045{
3046 terminal->rif = 0;
3047 terminal->cursor_to_hook = 0;
3048 terminal->raw_cursor_to_hook = 0;
3049 terminal->clear_to_end_hook = 0;
3050 terminal->clear_frame_hook = 0;
3051 terminal->clear_end_of_line_hook = 0;
3052 terminal->ins_del_lines_hook = 0;
3053 terminal->insert_glyphs_hook = 0;
3054 terminal->write_glyphs_hook = 0;
3055 terminal->delete_glyphs_hook = 0;
3056 terminal->ring_bell_hook = 0;
3057 terminal->reset_terminal_modes_hook = 0;
3058 terminal->set_terminal_modes_hook = 0;
3059 terminal->update_begin_hook = 0;
3060 terminal->update_end_hook = 0;
3061 terminal->set_terminal_window_hook = 0;
3062 terminal->mouse_position_hook = 0;
3063 terminal->frame_rehighlight_hook = 0;
3064 terminal->frame_raise_lower_hook = 0;
3065 terminal->fullscreen_hook = 0;
3066 terminal->set_vertical_scroll_bar_hook = 0;
3067 terminal->condemn_scroll_bars_hook = 0;
3068 terminal->redeem_scroll_bar_hook = 0;
3069 terminal->judge_scroll_bars_hook = 0;
3070 terminal->read_socket_hook = 0;
3071 terminal->frame_up_to_date_hook = 0;
3072
3073 /* Leave these two set, or suspended frames are not deleted
3074 correctly. */
3075 terminal->delete_frame_hook = &delete_tty_output;
3076 terminal->delete_terminal_hook = &delete_tty;
3077}
3078
3079static void
3080set_tty_hooks (struct terminal *terminal)
3081{
3082 terminal->rif = 0; /* ttys don't support window-based redisplay. */
3083
3084 terminal->cursor_to_hook = &tty_cursor_to;
3085 terminal->raw_cursor_to_hook = &tty_raw_cursor_to;
3086
3087 terminal->clear_to_end_hook = &tty_clear_to_end;
3088 terminal->clear_frame_hook = &tty_clear_frame;
3089 terminal->clear_end_of_line_hook = &tty_clear_end_of_line;
3090
3091 terminal->ins_del_lines_hook = &tty_ins_del_lines;
3092
3093 terminal->insert_glyphs_hook = &tty_insert_glyphs;
3094 terminal->write_glyphs_hook = &tty_write_glyphs;
3095 terminal->delete_glyphs_hook = &tty_delete_glyphs;
3096
3097 terminal->ring_bell_hook = &tty_ring_bell;
3098
3099 terminal->reset_terminal_modes_hook = &tty_reset_terminal_modes;
3100 terminal->set_terminal_modes_hook = &tty_set_terminal_modes;
3101 terminal->update_begin_hook = 0; /* Not needed. */
3102 terminal->update_end_hook = &tty_update_end;
3103 terminal->set_terminal_window_hook = &tty_set_terminal_window;
3104
3105 terminal->mouse_position_hook = 0; /* Not needed. */
3106 terminal->frame_rehighlight_hook = 0; /* Not needed. */
3107 terminal->frame_raise_lower_hook = 0; /* Not needed. */
3108
3109 terminal->set_vertical_scroll_bar_hook = 0; /* Not needed. */
3110 terminal->condemn_scroll_bars_hook = 0; /* Not needed. */
3111 terminal->redeem_scroll_bar_hook = 0; /* Not needed. */
3112 terminal->judge_scroll_bars_hook = 0; /* Not needed. */
3113
3114 terminal->read_socket_hook = &tty_read_avail_input; /* keyboard.c */
3115 terminal->frame_up_to_date_hook = 0; /* Not needed. */
3116
3117 terminal->delete_frame_hook = &delete_tty_output;
3118 terminal->delete_terminal_hook = &delete_tty;
3119}
3120
3121/* Drop the controlling terminal if fd is the same device. */
3122static void
3123dissociate_if_controlling_tty (int fd)
3045{ 3124{
3046 char *area; 3125#ifndef WINDOWSNT
3126 int pgid;
3127 EMACS_GET_TTY_PGRP (fd, &pgid); /* If tcgetpgrp succeeds, fd is the ctty. */
3128 if (pgid != -1)
3129 {
3130#if defined (USG) && !defined (BSD_PGRPS)
3131 setpgrp ();
3132 no_controlling_tty = 1;
3133#else
3134#ifdef TIOCNOTTY /* Try BSD ioctls. */
3135 sigblock (sigmask (SIGTTOU));
3136 fd = emacs_open ("/dev/tty", O_RDWR, 0);
3137 if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
3138 {
3139 no_controlling_tty = 1;
3140 }
3141 if (fd != -1)
3142 emacs_close (fd);
3143 sigunblock (sigmask (SIGTTOU));
3144#else
3145 /* Unknown system. */
3146 croak ();
3147#endif /* ! TIOCNOTTY */
3148#endif /* ! USG */
3149 }
3150#endif
3151}
3152
3153static void maybe_fatal();
3154
3155/* Create a termcap display on the tty device with the given name and
3156 type.
3157
3158 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
3159 Otherwise NAME should be a path to the tty device file,
3160 e.g. "/dev/pts/7".
3161
3162 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
3163
3164 If MUST_SUCCEED is true, then all errors are fatal. */
3165
3166struct terminal *
3167init_tty (char *name, char *terminal_type, int must_succeed)
3168{
3169 char *area = NULL;
3047 char **address = &area; 3170 char **address = &area;
3048 char *buffer = NULL; 3171 char *buffer = NULL;
3049 int buffer_size = 4096; 3172 int buffer_size = 4096;
3050 register char *p; 3173 register char *p = NULL;
3051 int status; 3174 int status;
3052 struct frame *sf = XFRAME (selected_frame); 3175 struct tty_display_info *tty = NULL;
3176 struct terminal *terminal = NULL;
3177 int ctty = 0; /* 1 if asked to open controlling tty. */
3178
3179 if (!terminal_type)
3180 maybe_fatal (must_succeed, 0, 0,
3181 "Unknown terminal type",
3182 "Unknown terminal type");
3183
3184#ifndef WINDOWSNT
3185 if (name == NULL)
3186 name = "/dev/tty";
3187 if (!strcmp (name, "/dev/tty"))
3188 ctty = 1;
3189
3190 /* If we already have a terminal on the given device, use that. If
3191 all such terminals are suspended, create a new one instead. */
3192 /* XXX Perhaps this should be made explicit by having init_tty
3193 always create a new terminal and separating terminal and frame
3194 creation on Lisp level. */
3195 terminal = get_named_tty (name);
3196 if (terminal)
3197 return terminal;
3198#endif
3199
3200 terminal = create_terminal ();
3201 tty = (struct tty_display_info *) xmalloc (sizeof (struct tty_display_info));
3202 bzero (tty, sizeof (struct tty_display_info));
3203 tty->next = tty_list;
3204 tty_list = tty;
3205
3206 terminal->type = output_termcap;
3207 terminal->display_info.tty = tty;
3208 tty->terminal = terminal;
3209
3210 tty->Wcm = (struct cm *) xmalloc (sizeof (struct cm));
3211 Wcm_clear (tty);
3212
3213#ifndef WINDOWSNT
3214 set_tty_hooks (terminal);
3215
3216 {
3217 int fd;
3218 FILE *file;
3219
3220#ifdef O_IGNORE_CTTY
3221 if (!ctty)
3222 /* Open the terminal device. Don't recognize it as our
3223 controlling terminal, and don't make it the controlling tty
3224 if we don't have one at the moment. */
3225 fd = emacs_open (name, O_RDWR | O_IGNORE_CTTY | O_NOCTTY, 0);
3226 else
3227#else
3228 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
3229 defined on Hurd. On other systems, we need to explicitly
3230 dissociate ourselves from the controlling tty when we want to
3231 open a frame on the same terminal. */
3232 fd = emacs_open (name, O_RDWR | O_NOCTTY, 0);
3233#endif /* O_IGNORE_CTTY */
3234
3235 if (fd < 0)
3236 maybe_fatal (must_succeed, buffer, terminal,
3237 "Could not open file: %s",
3238 "Could not open file: %s",
3239 name);
3240 if (!isatty (fd))
3241 {
3242 close (fd);
3243 maybe_fatal (must_succeed, buffer, terminal,
3244 "Not a tty device: %s",
3245 "Not a tty device: %s",
3246 name);
3247 }
3248
3249#ifndef O_IGNORE_CTTY
3250 if (!ctty)
3251 dissociate_if_controlling_tty (fd);
3252#endif
3253
3254 file = fdopen (fd, "w+");
3255 tty->name = xstrdup (name);
3256 terminal->name = xstrdup (name);
3257 tty->input = file;
3258 tty->output = file;
3259 }
3260
3261 tty->type = xstrdup (terminal_type);
3262
3263 add_keyboard_wait_descriptor (fileno (tty->input));
3264
3265#endif
3053 3266
3054 encode_terminal_bufsize = 0; 3267 encode_terminal_bufsize = 0;
3055 3268
3056#ifdef HAVE_GPM 3269#ifdef HAVE_GPM
3057 mouse_position_hook = term_mouse_position; 3270 terminal->mouse_position_hook = term_mouse_position;
3058 Qmouse_face_window = Qnil; 3271 Qmouse_face_window = Qnil;
3059#endif 3272#endif
3060 3273
3061#ifdef WINDOWSNT 3274#ifdef WINDOWSNT
3062 initialize_w32_display (); 3275 initialize_w32_display ();
3063 3276
3064 Wcm_clear (); 3277 /* XXX Can this be non-null? */
3278 if (name)
3279 {
3280 tty->name = xstrdup (name);
3281 terminal->name = xstrdup (name);
3282 }
3283 tty->type = xstrdup (terminal_type);
3284
3285 /* XXX not sure if this line is correct. If it is not set then we
3286 crash in update_display_1. */
3287 tty->output = stdout;
3288
3289 Wcm_clear (tty);
3065 3290
3066 area = (char *) xmalloc (2044); 3291 area = (char *) xmalloc (2044); /* XXX this seems unused. */
3067 3292
3068 FrameRows = FRAME_LINES (sf); 3293 {
3069 FrameCols = FRAME_COLS (sf); 3294 struct frame *f = XFRAME (selected_frame);
3070 specified_window = FRAME_LINES (sf);
3071 3295
3072 delete_in_insert_mode = 1; 3296 FrameRows (tty) = FRAME_LINES (f); /* XXX */
3297 FrameCols (tty) = FRAME_COLS (f); /* XXX */
3298 tty->specified_window = FRAME_LINES (f); /* XXX */
3073 3299
3074 UseTabs = 0; 3300 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; /* XXX */
3075 scroll_region_ok = 0; 3301 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; /* XXX */
3302 }
3303 tty->delete_in_insert_mode = 1;
3076 3304
3077 /* Seems to insert lines when it's not supposed to, messing 3305 UseTabs (tty) = 0;
3078 up the display. In doing a trace, it didn't seem to be 3306 terminal->scroll_region_ok = 0;
3079 called much, so I don't think we're losing anything by
3080 turning it off. */
3081 3307
3082 line_ins_del_ok = 0; 3308 /* Seems to insert lines when it's not supposed to, messing up the
3083 char_ins_del_ok = 1; 3309 display. In doing a trace, it didn't seem to be called much, so I
3310 don't think we're losing anything by turning it off. */
3311 terminal->line_ins_del_ok = 0;
3312 terminal->char_ins_del_ok = 1;
3084 3313
3085 baud_rate = 19200; 3314 baud_rate = 19200;
3086 3315
3087 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; 3316 tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
3088 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
3089 TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
3090 3317
3091 return; 3318 return terminal;
3092#else /* not WINDOWSNT */ 3319#else /* not WINDOWSNT */
3093 3320
3094 Wcm_clear (); 3321 Wcm_clear (tty);
3095 3322
3096 buffer = (char *) xmalloc (buffer_size); 3323 buffer = (char *) xmalloc (buffer_size);
3324
3325 /* On some systems, tgetent tries to access the controlling
3326 terminal. */
3327 sigblock (sigmask (SIGTTOU));
3097 status = tgetent (buffer, terminal_type); 3328 status = tgetent (buffer, terminal_type);
3329 sigunblock (sigmask (SIGTTOU));
3330
3098 if (status < 0) 3331 if (status < 0)
3099 { 3332 {
3100#ifdef TERMINFO 3333#ifdef TERMINFO
3101 fatal ("Cannot open terminfo database file"); 3334 maybe_fatal (must_succeed, buffer, terminal,
3335 "Cannot open terminfo database file",
3336 "Cannot open terminfo database file");
3102#else 3337#else
3103 fatal ("Cannot open termcap database file"); 3338 maybe_fatal (must_succeed, buffer, terminal,
3339 "Cannot open termcap database file",
3340 "Cannot open termcap database file");
3104#endif 3341#endif
3105 } 3342 }
3106 if (status == 0) 3343 if (status == 0)
3107 { 3344 {
3108#ifdef TERMINFO 3345#ifdef TERMINFO
3109 fatal ("Terminal type %s is not defined.\n\ 3346 maybe_fatal (must_succeed, buffer, terminal,
3347 "Terminal type %s is not defined",
3348 "Terminal type %s is not defined.\n\
3110If that is not the actual type of terminal you have,\n\ 3349If that is not the actual type of terminal you have,\n\
3111use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 3350use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3112`setenv TERM ...') to specify the correct type. It may be necessary\n\ 3351`setenv TERM ...') to specify the correct type. It may be necessary\n\
3113to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 3352to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3114 terminal_type); 3353 terminal_type);
3115#else 3354#else
3116 fatal ("Terminal type %s is not defined.\n\ 3355 maybe_fatal (must_succeed, buffer, terminal,
3356 "Terminal type %s is not defined",
3357 "Terminal type %s is not defined.\n\
3117If that is not the actual type of terminal you have,\n\ 3358If that is not the actual type of terminal you have,\n\
3118use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 3359use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3119`setenv TERM ...') to specify the correct type. It may be necessary\n\ 3360`setenv TERM ...') to specify the correct type. It may be necessary\n\
3120to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 3361to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3121 terminal_type); 3362 terminal_type);
3122#endif 3363#endif
3123 } 3364 }
3124 3365
@@ -3129,219 +3370,233 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3129#endif 3370#endif
3130 area = (char *) xmalloc (buffer_size); 3371 area = (char *) xmalloc (buffer_size);
3131 3372
3132 TS_ins_line = tgetstr ("al", address); 3373 tty->TS_ins_line = tgetstr ("al", address);
3133 TS_ins_multi_lines = tgetstr ("AL", address); 3374 tty->TS_ins_multi_lines = tgetstr ("AL", address);
3134 TS_bell = tgetstr ("bl", address); 3375 tty->TS_bell = tgetstr ("bl", address);
3135 BackTab = tgetstr ("bt", address); 3376 BackTab (tty) = tgetstr ("bt", address);
3136 TS_clr_to_bottom = tgetstr ("cd", address); 3377 tty->TS_clr_to_bottom = tgetstr ("cd", address);
3137 TS_clr_line = tgetstr ("ce", address); 3378 tty->TS_clr_line = tgetstr ("ce", address);
3138 TS_clr_frame = tgetstr ("cl", address); 3379 tty->TS_clr_frame = tgetstr ("cl", address);
3139 ColPosition = NULL; /* tgetstr ("ch", address); */ 3380 ColPosition (tty) = NULL; /* tgetstr ("ch", address); */
3140 AbsPosition = tgetstr ("cm", address); 3381 AbsPosition (tty) = tgetstr ("cm", address);
3141 CR = tgetstr ("cr", address); 3382 CR (tty) = tgetstr ("cr", address);
3142 TS_set_scroll_region = tgetstr ("cs", address); 3383 tty->TS_set_scroll_region = tgetstr ("cs", address);
3143 TS_set_scroll_region_1 = tgetstr ("cS", address); 3384 tty->TS_set_scroll_region_1 = tgetstr ("cS", address);
3144 RowPosition = tgetstr ("cv", address); 3385 RowPosition (tty) = tgetstr ("cv", address);
3145 TS_del_char = tgetstr ("dc", address); 3386 tty->TS_del_char = tgetstr ("dc", address);
3146 TS_del_multi_chars = tgetstr ("DC", address); 3387 tty->TS_del_multi_chars = tgetstr ("DC", address);
3147 TS_del_line = tgetstr ("dl", address); 3388 tty->TS_del_line = tgetstr ("dl", address);
3148 TS_del_multi_lines = tgetstr ("DL", address); 3389 tty->TS_del_multi_lines = tgetstr ("DL", address);
3149 TS_delete_mode = tgetstr ("dm", address); 3390 tty->TS_delete_mode = tgetstr ("dm", address);
3150 TS_end_delete_mode = tgetstr ("ed", address); 3391 tty->TS_end_delete_mode = tgetstr ("ed", address);
3151 TS_end_insert_mode = tgetstr ("ei", address); 3392 tty->TS_end_insert_mode = tgetstr ("ei", address);
3152 Home = tgetstr ("ho", address); 3393 Home (tty) = tgetstr ("ho", address);
3153 TS_ins_char = tgetstr ("ic", address); 3394 tty->TS_ins_char = tgetstr ("ic", address);
3154 TS_ins_multi_chars = tgetstr ("IC", address); 3395 tty->TS_ins_multi_chars = tgetstr ("IC", address);
3155 TS_insert_mode = tgetstr ("im", address); 3396 tty->TS_insert_mode = tgetstr ("im", address);
3156 TS_pad_inserted_char = tgetstr ("ip", address); 3397 tty->TS_pad_inserted_char = tgetstr ("ip", address);
3157 TS_end_keypad_mode = tgetstr ("ke", address); 3398 tty->TS_end_keypad_mode = tgetstr ("ke", address);
3158 TS_keypad_mode = tgetstr ("ks", address); 3399 tty->TS_keypad_mode = tgetstr ("ks", address);
3159 LastLine = tgetstr ("ll", address); 3400 LastLine (tty) = tgetstr ("ll", address);
3160 Right = tgetstr ("nd", address); 3401 Right (tty) = tgetstr ("nd", address);
3161 Down = tgetstr ("do", address); 3402 Down (tty) = tgetstr ("do", address);
3162 if (!Down) 3403 if (!Down (tty))
3163 Down = tgetstr ("nl", address); /* Obsolete name for "do" */ 3404 Down (tty) = tgetstr ("nl", address); /* Obsolete name for "do" */
3164#ifdef VMS 3405#ifdef VMS
3165 /* VMS puts a carriage return before each linefeed, 3406 /* VMS puts a carriage return before each linefeed,
3166 so it is not safe to use linefeeds. */ 3407 so it is not safe to use linefeeds. */
3167 if (Down && Down[0] == '\n' && Down[1] == '\0') 3408 if (Down (tty) && Down (tty)[0] == '\n' && Down (tty)[1] == '\0')
3168 Down = 0; 3409 Down (tty) = 0;
3169#endif /* VMS */ 3410#endif /* VMS */
3170 if (tgetflag ("bs")) 3411 if (tgetflag ("bs"))
3171 Left = "\b"; /* can't possibly be longer! */ 3412 Left (tty) = "\b"; /* can't possibly be longer! */
3172 else /* (Actually, "bs" is obsolete...) */ 3413 else /* (Actually, "bs" is obsolete...) */
3173 Left = tgetstr ("le", address); 3414 Left (tty) = tgetstr ("le", address);
3174 if (!Left) 3415 if (!Left (tty))
3175 Left = tgetstr ("bc", address); /* Obsolete name for "le" */ 3416 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */
3176 TS_pad_char = tgetstr ("pc", address); 3417 tty->TS_pad_char = tgetstr ("pc", address);
3177 TS_repeat = tgetstr ("rp", address); 3418 tty->TS_repeat = tgetstr ("rp", address);
3178 TS_end_standout_mode = tgetstr ("se", address); 3419 tty->TS_end_standout_mode = tgetstr ("se", address);
3179 TS_fwd_scroll = tgetstr ("sf", address); 3420 tty->TS_fwd_scroll = tgetstr ("sf", address);
3180 TS_standout_mode = tgetstr ("so", address); 3421 tty->TS_standout_mode = tgetstr ("so", address);
3181 TS_rev_scroll = tgetstr ("sr", address); 3422 tty->TS_rev_scroll = tgetstr ("sr", address);
3182 Wcm.cm_tab = tgetstr ("ta", address); 3423 tty->Wcm->cm_tab = tgetstr ("ta", address);
3183 TS_end_termcap_modes = tgetstr ("te", address); 3424 tty->TS_end_termcap_modes = tgetstr ("te", address);
3184 TS_termcap_modes = tgetstr ("ti", address); 3425 tty->TS_termcap_modes = tgetstr ("ti", address);
3185 Up = tgetstr ("up", address); 3426 Up (tty) = tgetstr ("up", address);
3186 TS_visible_bell = tgetstr ("vb", address); 3427 tty->TS_visible_bell = tgetstr ("vb", address);
3187 TS_cursor_normal = tgetstr ("ve", address); 3428 tty->TS_cursor_normal = tgetstr ("ve", address);
3188 TS_cursor_visible = tgetstr ("vs", address); 3429 tty->TS_cursor_visible = tgetstr ("vs", address);
3189 TS_cursor_invisible = tgetstr ("vi", address); 3430 tty->TS_cursor_invisible = tgetstr ("vi", address);
3190 TS_set_window = tgetstr ("wi", address); 3431 tty->TS_set_window = tgetstr ("wi", address);
3191 3432
3192 TS_enter_underline_mode = tgetstr ("us", address); 3433 tty->TS_enter_underline_mode = tgetstr ("us", address);
3193 TS_exit_underline_mode = tgetstr ("ue", address); 3434 tty->TS_exit_underline_mode = tgetstr ("ue", address);
3194 TS_enter_bold_mode = tgetstr ("md", address); 3435 tty->TS_enter_bold_mode = tgetstr ("md", address);
3195 TS_enter_dim_mode = tgetstr ("mh", address); 3436 tty->TS_enter_dim_mode = tgetstr ("mh", address);
3196 TS_enter_blink_mode = tgetstr ("mb", address); 3437 tty->TS_enter_blink_mode = tgetstr ("mb", address);
3197 TS_enter_reverse_mode = tgetstr ("mr", address); 3438 tty->TS_enter_reverse_mode = tgetstr ("mr", address);
3198 TS_enter_alt_charset_mode = tgetstr ("as", address); 3439 tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
3199 TS_exit_alt_charset_mode = tgetstr ("ae", address); 3440 tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
3200 TS_exit_attribute_mode = tgetstr ("me", address); 3441 tty->TS_exit_attribute_mode = tgetstr ("me", address);
3201 3442
3202 MultiUp = tgetstr ("UP", address); 3443 MultiUp (tty) = tgetstr ("UP", address);
3203 MultiDown = tgetstr ("DO", address); 3444 MultiDown (tty) = tgetstr ("DO", address);
3204 MultiLeft = tgetstr ("LE", address); 3445 MultiLeft (tty) = tgetstr ("LE", address);
3205 MultiRight = tgetstr ("RI", address); 3446 MultiRight (tty) = tgetstr ("RI", address);
3206 3447
3207 /* SVr4/ANSI color suppert. If "op" isn't available, don't support 3448 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
3208 color because we can't switch back to the default foreground and 3449 color because we can't switch back to the default foreground and
3209 background. */ 3450 background. */
3210 TS_orig_pair = tgetstr ("op", address); 3451 tty->TS_orig_pair = tgetstr ("op", address);
3211 if (TS_orig_pair) 3452 if (tty->TS_orig_pair)
3212 { 3453 {
3213 TS_set_foreground = tgetstr ("AF", address); 3454 tty->TS_set_foreground = tgetstr ("AF", address);
3214 TS_set_background = tgetstr ("AB", address); 3455 tty->TS_set_background = tgetstr ("AB", address);
3215 if (!TS_set_foreground) 3456 if (!tty->TS_set_foreground)
3216 { 3457 {
3217 /* SVr4. */ 3458 /* SVr4. */
3218 TS_set_foreground = tgetstr ("Sf", address); 3459 tty->TS_set_foreground = tgetstr ("Sf", address);
3219 TS_set_background = tgetstr ("Sb", address); 3460 tty->TS_set_background = tgetstr ("Sb", address);
3220 } 3461 }
3221 3462
3222 TN_max_colors = tgetnum ("Co"); 3463 tty->TN_max_colors = tgetnum ("Co");
3223 TN_max_pairs = tgetnum ("pa"); 3464 tty->TN_max_pairs = tgetnum ("pa");
3224 3465
3225 TN_no_color_video = tgetnum ("NC"); 3466 tty->TN_no_color_video = tgetnum ("NC");
3226 if (TN_no_color_video == -1) 3467 if (tty->TN_no_color_video == -1)
3227 TN_no_color_video = 0; 3468 tty->TN_no_color_video = 0;
3228 } 3469 }
3229 3470
3230 tty_default_color_capabilities (1); 3471 tty_default_color_capabilities (tty, 1);
3231 3472
3232 MagicWrap = tgetflag ("xn"); 3473 MagicWrap (tty) = tgetflag ("xn");
3233 /* Since we make MagicWrap terminals look like AutoWrap, we need to have 3474 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
3234 the former flag imply the latter. */ 3475 the former flag imply the latter. */
3235 AutoWrap = MagicWrap || tgetflag ("am"); 3476 AutoWrap (tty) = MagicWrap (tty) || tgetflag ("am");
3236 memory_below_frame = tgetflag ("db"); 3477 terminal->memory_below_frame = tgetflag ("db");
3237 TF_hazeltine = tgetflag ("hz"); 3478 tty->TF_hazeltine = tgetflag ("hz");
3238 must_write_spaces = tgetflag ("in"); 3479 terminal->must_write_spaces = tgetflag ("in");
3239 meta_key = tgetflag ("km") || tgetflag ("MT"); 3480 tty->meta_key = tgetflag ("km") || tgetflag ("MT");
3240 TF_insmode_motion = tgetflag ("mi"); 3481 tty->TF_insmode_motion = tgetflag ("mi");
3241 TF_standout_motion = tgetflag ("ms"); 3482 tty->TF_standout_motion = tgetflag ("ms");
3242 TF_underscore = tgetflag ("ul"); 3483 tty->TF_underscore = tgetflag ("ul");
3243 TF_teleray = tgetflag ("xt"); 3484 tty->TF_teleray = tgetflag ("xt");
3244 3485
3245 term_get_fkeys (address); 3486#ifdef MULTI_KBOARD
3487 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
3488 init_kboard (terminal->kboard);
3489 terminal->kboard->next_kboard = all_kboards;
3490 all_kboards = terminal->kboard;
3491 terminal->kboard->reference_count++;
3492 /* Don't let the initial kboard remain current longer than necessary.
3493 That would cause problems if a file loaded on startup tries to
3494 prompt in the mini-buffer. */
3495 if (current_kboard == initial_kboard)
3496 current_kboard = terminal->kboard;
3497 term_get_fkeys (address, terminal->kboard);
3498#endif
3246 3499
3247 /* Get frame size from system, or else from termcap. */ 3500 /* Get frame size from system, or else from termcap. */
3248 { 3501 {
3249 int height, width; 3502 int height, width;
3250 get_frame_size (&width, &height); 3503 get_tty_size (fileno (tty->input), &width, &height);
3251 FRAME_COLS (sf) = width; 3504 FrameCols (tty) = width;
3252 FRAME_LINES (sf) = height; 3505 FrameRows (tty) = height;
3253 } 3506 }
3254 3507
3255 if (FRAME_COLS (sf) <= 0) 3508 if (FrameCols (tty) <= 0)
3256 SET_FRAME_COLS (sf, tgetnum ("co")); 3509 FrameCols (tty) = tgetnum ("co");
3257 else 3510 if (FrameRows (tty) <= 0)
3258 /* Keep width and external_width consistent */ 3511 FrameRows (tty) = tgetnum ("li");
3259 SET_FRAME_COLS (sf, FRAME_COLS (sf));
3260 if (FRAME_LINES (sf) <= 0)
3261 FRAME_LINES (sf) = tgetnum ("li");
3262 3512
3263 if (FRAME_LINES (sf) < 3 || FRAME_COLS (sf) < 3) 3513 if (FrameRows (tty) < 3 || FrameCols (tty) < 3)
3264 fatal ("Screen size %dx%d is too small", 3514 maybe_fatal (must_succeed, NULL, terminal,
3265 FRAME_LINES (sf), FRAME_COLS (sf)); 3515 "Screen size %dx%d is too small"
3516 "Screen size %dx%d is too small",
3517 FrameCols (tty), FrameRows (tty));
3518
3519#if 0 /* This is not used anywhere. */
3520 tty->terminal->min_padding_speed = tgetnum ("pb");
3521#endif
3266 3522
3267 min_padding_speed = tgetnum ("pb"); 3523 TabWidth (tty) = tgetnum ("tw");
3268 TabWidth = tgetnum ("tw");
3269 3524
3270#ifdef VMS 3525#ifdef VMS
3271 /* These capabilities commonly use ^J. 3526 /* These capabilities commonly use ^J.
3272 I don't know why, but sending them on VMS does not work; 3527 I don't know why, but sending them on VMS does not work;
3273 it causes following spaces to be lost, sometimes. 3528 it causes following spaces to be lost, sometimes.
3274 For now, the simplest fix is to avoid using these capabilities ever. */ 3529 For now, the simplest fix is to avoid using these capabilities ever. */
3275 if (Down && Down[0] == '\n') 3530 if (Down (tty) && Down (tty)[0] == '\n')
3276 Down = 0; 3531 Down (tty) = 0;
3277#endif /* VMS */ 3532#endif /* VMS */
3278 3533
3279 if (!TS_bell) 3534 if (!tty->TS_bell)
3280 TS_bell = "\07"; 3535 tty->TS_bell = "\07";
3281 3536
3282 if (!TS_fwd_scroll) 3537 if (!tty->TS_fwd_scroll)
3283 TS_fwd_scroll = Down; 3538 tty->TS_fwd_scroll = Down (tty);
3284 3539
3285 PC = TS_pad_char ? *TS_pad_char : 0; 3540 PC = tty->TS_pad_char ? *tty->TS_pad_char : 0;
3286 3541
3287 if (TabWidth < 0) 3542 if (TabWidth (tty) < 0)
3288 TabWidth = 8; 3543 TabWidth (tty) = 8;
3289 3544
3290/* Turned off since /etc/termcap seems to have :ta= for most terminals 3545/* Turned off since /etc/termcap seems to have :ta= for most terminals
3291 and newer termcap doc does not seem to say there is a default. 3546 and newer termcap doc does not seem to say there is a default.
3292 if (!Wcm.cm_tab) 3547 if (!tty->Wcm->cm_tab)
3293 Wcm.cm_tab = "\t"; 3548 tty->Wcm->cm_tab = "\t";
3294*/ 3549*/
3295 3550
3296 /* We don't support standout modes that use `magic cookies', so 3551 /* We don't support standout modes that use `magic cookies', so
3297 turn off any that do. */ 3552 turn off any that do. */
3298 if (TS_standout_mode && tgetnum ("sg") >= 0) 3553 if (tty->TS_standout_mode && tgetnum ("sg") >= 0)
3299 { 3554 {
3300 TS_standout_mode = 0; 3555 tty->TS_standout_mode = 0;
3301 TS_end_standout_mode = 0; 3556 tty->TS_end_standout_mode = 0;
3302 } 3557 }
3303 if (TS_enter_underline_mode && tgetnum ("ug") >= 0) 3558 if (tty->TS_enter_underline_mode && tgetnum ("ug") >= 0)
3304 { 3559 {
3305 TS_enter_underline_mode = 0; 3560 tty->TS_enter_underline_mode = 0;
3306 TS_exit_underline_mode = 0; 3561 tty->TS_exit_underline_mode = 0;
3307 } 3562 }
3308 3563
3309 /* If there's no standout mode, try to use underlining instead. */ 3564 /* If there's no standout mode, try to use underlining instead. */
3310 if (TS_standout_mode == 0) 3565 if (tty->TS_standout_mode == 0)
3311 { 3566 {
3312 TS_standout_mode = TS_enter_underline_mode; 3567 tty->TS_standout_mode = tty->TS_enter_underline_mode;
3313 TS_end_standout_mode = TS_exit_underline_mode; 3568 tty->TS_end_standout_mode = tty->TS_exit_underline_mode;
3314 } 3569 }
3315 3570
3316 /* If no `se' string, try using a `me' string instead. 3571 /* If no `se' string, try using a `me' string instead.
3317 If that fails, we can't use standout mode at all. */ 3572 If that fails, we can't use standout mode at all. */
3318 if (TS_end_standout_mode == 0) 3573 if (tty->TS_end_standout_mode == 0)
3319 { 3574 {
3320 char *s = tgetstr ("me", address); 3575 char *s = tgetstr ("me", address);
3321 if (s != 0) 3576 if (s != 0)
3322 TS_end_standout_mode = s; 3577 tty->TS_end_standout_mode = s;
3323 else 3578 else
3324 TS_standout_mode = 0; 3579 tty->TS_standout_mode = 0;
3325 } 3580 }
3326 3581
3327 if (TF_teleray) 3582 if (tty->TF_teleray)
3328 { 3583 {
3329 Wcm.cm_tab = 0; 3584 tty->Wcm->cm_tab = 0;
3330 /* We can't support standout mode, because it uses magic cookies. */ 3585 /* We can't support standout mode, because it uses magic cookies. */
3331 TS_standout_mode = 0; 3586 tty->TS_standout_mode = 0;
3332 /* But that means we cannot rely on ^M to go to column zero! */ 3587 /* But that means we cannot rely on ^M to go to column zero! */
3333 CR = 0; 3588 CR (tty) = 0;
3334 /* LF can't be trusted either -- can alter hpos */ 3589 /* LF can't be trusted either -- can alter hpos */
3335 /* if move at column 0 thru a line with TS_standout_mode */ 3590 /* if move at column 0 thru a line with TS_standout_mode */
3336 Down = 0; 3591 Down (tty) = 0;
3337 } 3592 }
3338 3593
3339 /* Special handling for certain terminal types known to need it */ 3594 /* Special handling for certain terminal types known to need it */
3340 3595
3341 if (!strcmp (terminal_type, "supdup")) 3596 if (!strcmp (terminal_type, "supdup"))
3342 { 3597 {
3343 memory_below_frame = 1; 3598 terminal->memory_below_frame = 1;
3344 Wcm.cm_losewrap = 1; 3599 tty->Wcm->cm_losewrap = 1;
3345 } 3600 }
3346 if (!strncmp (terminal_type, "c10", 3) 3601 if (!strncmp (terminal_type, "c10", 3)
3347 || !strcmp (terminal_type, "perq")) 3602 || !strcmp (terminal_type, "perq"))
@@ -3358,102 +3613,139 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3358 It would be simpler if the :wi string could go in the termcap 3613 It would be simpler if the :wi string could go in the termcap
3359 entry, but it can't because it is not fully valid. 3614 entry, but it can't because it is not fully valid.
3360 If it were in the termcap entry, it would confuse other programs. */ 3615 If it were in the termcap entry, it would confuse other programs. */
3361 if (!TS_set_window) 3616 if (!tty->TS_set_window)
3362 { 3617 {
3363 p = TS_termcap_modes; 3618 p = tty->TS_termcap_modes;
3364 while (*p && strcmp (p, "\033v ")) 3619 while (*p && strcmp (p, "\033v "))
3365 p++; 3620 p++;
3366 if (*p) 3621 if (*p)
3367 TS_set_window = "\033v%C %C %C %C "; 3622 tty->TS_set_window = "\033v%C %C %C %C ";
3368 } 3623 }
3369 /* Termcap entry often fails to have :in: flag */ 3624 /* Termcap entry often fails to have :in: flag */
3370 must_write_spaces = 1; 3625 terminal->must_write_spaces = 1;
3371 /* :ti string typically fails to have \E^G! in it */ 3626 /* :ti string typically fails to have \E^G! in it */
3372 /* This limits scope of insert-char to one line. */ 3627 /* This limits scope of insert-char to one line. */
3373 strcpy (area, TS_termcap_modes); 3628 strcpy (area, tty->TS_termcap_modes);
3374 strcat (area, "\033\007!"); 3629 strcat (area, "\033\007!");
3375 TS_termcap_modes = area; 3630 tty->TS_termcap_modes = area;
3376 area += strlen (area) + 1; 3631 area += strlen (area) + 1;
3377 p = AbsPosition; 3632 p = AbsPosition (tty);
3378 /* Change all %+ parameters to %C, to handle 3633 /* Change all %+ parameters to %C, to handle
3379 values above 96 correctly for the C100. */ 3634 values above 96 correctly for the C100. */
3380 while (*p) 3635 while (*p)
3381 { 3636 {
3382 if (p[0] == '%' && p[1] == '+') 3637 if (p[0] == '%' && p[1] == '+')
3383 p[1] = 'C'; 3638 p[1] = 'C';
3384 p++; 3639 p++;
3385 } 3640 }
3386 } 3641 }
3387 3642
3388 FrameRows = FRAME_LINES (sf); 3643 tty->specified_window = FrameRows (tty);
3389 FrameCols = FRAME_COLS (sf);
3390 specified_window = FRAME_LINES (sf);
3391 3644
3392 if (Wcm_init () == -1) /* can't do cursor motion */ 3645 if (Wcm_init (tty) == -1) /* can't do cursor motion */
3646 {
3647 maybe_fatal (must_succeed, NULL, terminal,
3648 "Terminal type \"%s\" is not powerful enough to run Emacs",
3393#ifdef VMS 3649#ifdef VMS
3394 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 3650 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
3395It lacks the ability to position the cursor.\n\ 3651It lacks the ability to position the cursor.\n\
3396If that is not the actual type of terminal you have, use either the\n\ 3652If that is not the actual type of terminal you have, use either the\n\
3397DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\ 3653DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
3398or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.", 3654or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
3399 terminal_type);
3400#else /* not VMS */ 3655#else /* not VMS */
3401# ifdef TERMINFO 3656# ifdef TERMINFO
3402 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 3657 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
3403It lacks the ability to position the cursor.\n\ 3658It lacks the ability to position the cursor.\n\
3404If that is not the actual type of terminal you have,\n\ 3659If that is not the actual type of terminal you have,\n\
3405use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 3660use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3406`setenv TERM ...') to specify the correct type. It may be necessary\n\ 3661`setenv TERM ...') to specify the correct type. It may be necessary\n\
3407to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", 3662to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3408 terminal_type);
3409# else /* TERMCAP */ 3663# else /* TERMCAP */
3410 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\ 3664 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
3411It lacks the ability to position the cursor.\n\ 3665It lacks the ability to position the cursor.\n\
3412If that is not the actual type of terminal you have,\n\ 3666If that is not the actual type of terminal you have,\n\
3413use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ 3667use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3414`setenv TERM ...') to specify the correct type. It may be necessary\n\ 3668`setenv TERM ...') to specify the correct type. It may be necessary\n\
3415to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", 3669to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3416 terminal_type);
3417# endif /* TERMINFO */ 3670# endif /* TERMINFO */
3418#endif /*VMS */ 3671#endif /*VMS */
3419 if (FRAME_LINES (sf) <= 0 3672 terminal_type);
3420 || FRAME_COLS (sf) <= 0) 3673 }
3421 fatal ("The frame size has not been specified");
3422 3674
3423 delete_in_insert_mode 3675 if (FrameRows (tty) <= 0 || FrameCols (tty) <= 0)
3424 = TS_delete_mode && TS_insert_mode 3676 maybe_fatal (must_succeed, NULL, terminal,
3425 && !strcmp (TS_delete_mode, TS_insert_mode); 3677 "Could not determine the frame size",
3678 "Could not determine the frame size");
3426 3679
3427 se_is_so = (TS_standout_mode 3680 tty->delete_in_insert_mode
3428 && TS_end_standout_mode 3681 = tty->TS_delete_mode && tty->TS_insert_mode
3429 && !strcmp (TS_standout_mode, TS_end_standout_mode)); 3682 && !strcmp (tty->TS_delete_mode, tty->TS_insert_mode);
3430 3683
3431 UseTabs = tabs_safe_p () && TabWidth == 8; 3684 tty->se_is_so = (tty->TS_standout_mode
3685 && tty->TS_end_standout_mode
3686 && !strcmp (tty->TS_standout_mode, tty->TS_end_standout_mode));
3432 3687
3433 scroll_region_ok 3688 UseTabs (tty) = tabs_safe_p (fileno (tty->input)) && TabWidth (tty) == 8;
3434 = (Wcm.cm_abs
3435 && (TS_set_window || TS_set_scroll_region || TS_set_scroll_region_1));
3436 3689
3437 line_ins_del_ok = (((TS_ins_line || TS_ins_multi_lines) 3690 terminal->scroll_region_ok
3438 && (TS_del_line || TS_del_multi_lines)) 3691 = (tty->Wcm->cm_abs
3439 || (scroll_region_ok && TS_fwd_scroll && TS_rev_scroll)); 3692 && (tty->TS_set_window || tty->TS_set_scroll_region || tty->TS_set_scroll_region_1));
3440 3693
3441 char_ins_del_ok = ((TS_ins_char || TS_insert_mode 3694 terminal->line_ins_del_ok
3442 || TS_pad_inserted_char || TS_ins_multi_chars) 3695 = (((tty->TS_ins_line || tty->TS_ins_multi_lines)
3443 && (TS_del_char || TS_del_multi_chars)); 3696 && (tty->TS_del_line || tty->TS_del_multi_lines))
3697 || (terminal->scroll_region_ok
3698 && tty->TS_fwd_scroll && tty->TS_rev_scroll));
3444 3699
3445 fast_clear_end_of_line = TS_clr_line != 0; 3700 terminal->char_ins_del_ok
3701 = ((tty->TS_ins_char || tty->TS_insert_mode
3702 || tty->TS_pad_inserted_char || tty->TS_ins_multi_chars)
3703 && (tty->TS_del_char || tty->TS_del_multi_chars));
3446 3704
3447 init_baud_rate (); 3705 terminal->fast_clear_end_of_line = tty->TS_clr_line != 0;
3448 if (read_socket_hook) /* Baudrate is somewhat */
3449 /* meaningless in this case */
3450 baud_rate = 9600;
3451 3706
3452 FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0; 3707 init_baud_rate (fileno (tty->input));
3453 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none; 3708
3454#endif /* WINDOWSNT */ 3709#ifdef AIXHFT
3710 /* The HFT system on AIX doesn't optimize for scrolling, so it's
3711 really ugly at times. */
3712 terminal->line_ins_del_ok = 0;
3713 terminal->char_ins_del_ok = 0;
3714#endif
3715
3716 /* Don't do this. I think termcap may still need the buffer. */
3717 /* xfree (buffer); */
3718
3719 /* Init system terminal modes (RAW or CBREAK, etc.). */
3720 init_sys_modes (tty);
3455 3721
3456 xfree (buffer); 3722 return terminal;
3723#endif /* not WINDOWSNT */
3724}
3725
3726/* Auxiliary error-handling function for init_tty.
3727 Free BUFFER and delete TERMINAL, then call error or fatal
3728 with str1 or str2, respectively, according to MUST_SUCCEED. */
3729
3730static void
3731maybe_fatal (must_succeed, buffer, terminal, str1, str2, arg1, arg2)
3732 int must_succeed;
3733 char *buffer;
3734 struct terminal *terminal;
3735 char *str1, *str2, *arg1, *arg2;
3736{
3737 if (buffer)
3738 xfree (buffer);
3739
3740 if (terminal)
3741 delete_tty (terminal);
3742
3743 if (must_succeed)
3744 fatal (str2, arg1, arg2);
3745 else
3746 error (str1, arg1, arg2);
3747
3748 abort ();
3457} 3749}
3458 3750
3459/* VARARGS 1 */ 3751/* VARARGS 1 */
@@ -3468,16 +3760,108 @@ fatal (str, arg1, arg2)
3468 exit (1); 3760 exit (1);
3469} 3761}
3470 3762
3471DEFUN ("tty-no-underline", Ftty_no_underline, Stty_no_underline, 0, 0, 0, 3763
3472 doc: /* Declare that this terminal does not handle underlining. 3764
3473This is used to override the terminfo data, for certain terminals that 3765/* Delete the given tty terminal, closing all frames on it. */
3474do not really do underlining, but say that they do. */) 3766
3475 () 3767static void
3768delete_tty (struct terminal *terminal)
3476{ 3769{
3477 TS_enter_underline_mode = 0; 3770 struct tty_display_info *tty;
3478 return Qnil; 3771 Lisp_Object tail, frame;
3772 int last_terminal;
3773
3774 /* Protect against recursive calls. Fdelete_frame in
3775 delete_terminal calls us back when it deletes our last frame. */
3776 if (terminal->deleted)
3777 return;
3778
3779 if (terminal->type != output_termcap)
3780 abort ();
3781
3782 tty = terminal->display_info.tty;
3783
3784 last_terminal = 1;
3785 FOR_EACH_FRAME (tail, frame)
3786 {
3787 struct frame *f = XFRAME (frame);
3788 if (FRAME_LIVE_P (f) && (!FRAME_TERMCAP_P (f) || FRAME_TTY (f) != tty))
3789 {
3790 last_terminal = 0;
3791 break;
3792 }
3793 }
3794 if (last_terminal)
3795 error ("Attempt to delete the sole terminal device with live frames");
3796
3797 if (tty == tty_list)
3798 tty_list = tty->next;
3799 else
3800 {
3801 struct tty_display_info *p;
3802 for (p = tty_list; p && p->next != tty; p = p->next)
3803 ;
3804
3805 if (! p)
3806 /* This should not happen. */
3807 abort ();
3808
3809 p->next = tty->next;
3810 tty->next = 0;
3811 }
3812
3813 /* reset_sys_modes needs a valid device, so this call needs to be
3814 before delete_terminal. */
3815 reset_sys_modes (tty);
3816
3817 delete_terminal (terminal);
3818
3819 if (tty->name)
3820 xfree (tty->name);
3821
3822 if (tty->type)
3823 xfree (tty->type);
3824
3825 if (tty->input)
3826 {
3827 delete_keyboard_wait_descriptor (fileno (tty->input));
3828 if (tty->input != stdin)
3829 fclose (tty->input);
3830 }
3831 if (tty->output && tty->output != stdout && tty->output != tty->input)
3832 fclose (tty->output);
3833 if (tty->termscript)
3834 fclose (tty->termscript);
3835
3836 if (tty->old_tty)
3837 xfree (tty->old_tty);
3838
3839 if (tty->Wcm)
3840 xfree (tty->Wcm);
3841
3842 bzero (tty, sizeof (struct tty_display_info));
3843 xfree (tty);
3479} 3844}
3480 3845
3846
3847
3848/* Mark the pointers in the tty_display_info objects.
3849 Called by the Fgarbage_collector. */
3850
3851void
3852mark_ttys (void)
3853{
3854 struct tty_display_info *tty;
3855
3856 for (tty = tty_list; tty; tty = tty->next)
3857 {
3858 if (tty->top_frame)
3859 mark_object (tty->top_frame);
3860 }
3861}
3862
3863
3864
3481void 3865void
3482syms_of_term () 3866syms_of_term ()
3483{ 3867{
@@ -3490,10 +3874,18 @@ This variable can be used by terminal emulator packages. */);
3490 system_uses_terminfo = 0; 3874 system_uses_terminfo = 0;
3491#endif 3875#endif
3492 3876
3493 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function, 3877 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions,
3494 doc: /* Non-nil means call this function to ring the bell. 3878 doc: /* Functions to be run after suspending a tty.
3495The function should accept no arguments. */); 3879The functions are run with one argument, the terminal id to be suspended.
3496 Vring_bell_function = Qnil; 3880See `suspend-tty'. */);
3881 Vsuspend_tty_functions = Qnil;
3882
3883
3884 DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions,
3885 doc: /* Functions to be run after resuming a tty.
3886The functions are run with one argument, the terminal id that was revived.
3887See `resume-tty'. */);
3888 Vresume_tty_functions = Qnil;
3497 3889
3498 DEFVAR_BOOL ("visible-cursor", &visible_cursor, 3890 DEFVAR_BOOL ("visible-cursor", &visible_cursor,
3499 doc: /* Non-nil means to make the cursor very visible. 3891 doc: /* Non-nil means to make the cursor very visible.
@@ -3505,15 +3897,19 @@ bigger, or it may make it blink, or it may do nothing at all. */);
3505 defsubr (&Stty_display_color_p); 3897 defsubr (&Stty_display_color_p);
3506 defsubr (&Stty_display_color_cells); 3898 defsubr (&Stty_display_color_cells);
3507 defsubr (&Stty_no_underline); 3899 defsubr (&Stty_no_underline);
3900 defsubr (&Stty_type);
3901 defsubr (&Scontrolling_tty_p);
3902 defsubr (&Ssuspend_tty);
3903 defsubr (&Sresume_tty);
3508#ifdef HAVE_GPM 3904#ifdef HAVE_GPM
3509 defsubr (&Sterm_open_connection); 3905 defsubr (&Sterm_open_connection);
3510 defsubr (&Sterm_close_connection); 3906 defsubr (&Sterm_close_connection);
3511 3907
3512 staticpro (&Qmouse_face_window); 3908 staticpro (&Qmouse_face_window);
3513#endif /* HAVE_GPM */ 3909#endif /* HAVE_GPM */
3514
3515 fullscreen_hook = NULL;
3516} 3910}
3517 3911
3912
3913
3518/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193 3914/* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
3519 (do not change this comment) */ 3915 (do not change this comment) */
diff --git a/src/termchar.h b/src/termchar.h
index c4bf2adb0bd..381210fd658 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 eb074608e19..4124e37586b 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
@@ -394,13 +245,6 @@ struct input_event
394 245
395#define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event)) 246#define EVENT_INIT(event) bzero (&(event), sizeof (struct input_event))
396 247
397/* Called to read input events. */
398extern int (*read_socket_hook) P_ ((int, int, struct input_event *));
399
400/* Called when a frame's display becomes entirely up to date. */
401extern void (*frame_up_to_date_hook) P_ ((struct frame *));
402
403
404/* Bits in the modifiers member of the input_event structure. 248/* Bits in the modifiers member of the input_event structure.
405 Note that reorder_modifiers assumes that the bits are in canonical 249 Note that reorder_modifiers assumes that the bits are in canonical
406 order. 250 order.
@@ -452,14 +296,349 @@ enum {
452 296
453#ifdef HAVE_GPM 297#ifdef HAVE_GPM
454#include <gpm.h> 298#include <gpm.h>
455extern int handle_one_term_event (Gpm_Event *, struct input_event *); 299extern int handle_one_term_event (struct tty_display_info *, Gpm_Event *, struct input_event *);
456extern void term_mouse_moveto (int, int); 300extern void term_mouse_moveto (int, int);
457 301
458/* Nonzero means mouse is enabled on Linux console */ 302/* Nonzero means mouse is enabled on Linux console */
459extern int term_gpm; 303extern int term_gpm;
304
305/* The id of the terminal device for which we have gpm support. */
306extern int gpm_tty;
307#endif
308
309#endif /* CONSP */
310
311
312struct mac_display_info;
313struct w32_display_info;
314
315/* Terminal-local parameters. */
316struct terminal
317{
318 /* Chain of all terminal devices. */
319 struct terminal *next_terminal;
320
321 /* Unique id for this terminal device. */
322 int id;
323
324 /* The number of frames that are on this terminal. */
325 int reference_count;
326
327 /* Nonzero while deleting this terminal. Used to protect against
328 recursive calls to delete_terminal_hook. */
329 int deleted;
330
331 /* The type of the terminal device. */
332 enum output_method type;
333
334 /* The name of the terminal device. Do not use this to uniquely
335 identify a terminal; the same device may be opened multiple
336 times. */
337 char *name;
338
339#ifdef MULTI_KBOARD
340 /* The terminal's keyboard object. */
341 struct kboard *kboard;
342#endif
343
344 /* Device-type dependent data shared amongst all frames on this terminal. */
345 union display_info
346 {
347 struct tty_display_info *tty; /* termchar.h */
348 struct x_display_info *x; /* xterm.h */
349 struct w32_display_info *w32; /* w32term.h */
350 struct mac_display_info *mac; /* macterm.h */
351 } display_info;
352
353
354 /* Coding-system to be used for encoding terminal output. This
355 structure contains information of a coding-system specified by
356 the function `set-terminal-coding-system'. Also see
357 `safe_terminal_coding' in coding.h. */
358 struct coding_system *terminal_coding;
359
360 /* Coding-system of what is sent from terminal keyboard. This
361 structure contains information of a coding-system specified by
362 the function `set-keyboard-coding-system'. */
363 struct coding_system *keyboard_coding;
364
365 /* Parameter alist of this terminal. */
366 Lisp_Object param_alist;
367
368 /* Terminal characteristics. */
369 /* XXX Are these really used on non-termcap displays? */
370
371 int must_write_spaces; /* Nonzero means spaces in the text must
372 actually be output; can't just skip over
373 some columns to leave them blank. */
374 int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */
375
376 int line_ins_del_ok; /* Terminal can insert and delete lines */
377 int char_ins_del_ok; /* Terminal can insert and delete chars */
378 int scroll_region_ok; /* Terminal supports setting the scroll
379 window */
380 int scroll_region_cost; /* Cost of setting the scroll window,
381 measured in characters. */
382 int memory_below_frame; /* Terminal remembers lines scrolled
383 off bottom */
384
385#if 0 /* These are not used anywhere. */
386 /* EMACS_INT baud_rate; */ /* Output speed in baud */
387 int min_padding_speed; /* Speed below which no padding necessary. */
388 int dont_calculate_costs; /* Nonzero means don't bother computing
389 various cost tables; we won't use them. */
460#endif 390#endif
461 391
392
393 /* Window-based redisplay interface for this device (0 for tty
394 devices). */
395 struct redisplay_interface *rif;
396
397 /* Frame-based redisplay interface. */
398
399 /* Text display hooks. */
400
401 void (*cursor_to_hook) P_ ((struct frame *f, int vpos, int hpos));
402 void (*raw_cursor_to_hook) P_ ((struct frame *, int, int));
403
404 void (*clear_to_end_hook) P_ ((struct frame *));
405 void (*clear_frame_hook) P_ ((struct frame *));
406 void (*clear_end_of_line_hook) P_ ((struct frame *, int));
407
408 void (*ins_del_lines_hook) P_ ((struct frame *f, int, int));
409
410 void (*insert_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
411 void (*write_glyphs_hook) P_ ((struct frame *f, struct glyph *s, int n));
412 void (*delete_glyphs_hook) P_ ((struct frame *, int));
413
414 void (*ring_bell_hook) P_ ((struct frame *f));
415
416 void (*reset_terminal_modes_hook) P_ ((struct terminal *));
417 void (*set_terminal_modes_hook) P_ ((struct terminal *));
418
419 void (*update_begin_hook) P_ ((struct frame *));
420 void (*update_end_hook) P_ ((struct frame *));
421 void (*set_terminal_window_hook) P_ ((struct frame *, int));
422
423 /* Multi-frame and mouse support hooks. */
424
425 /* Return the current position of the mouse.
426
427 Set *f to the frame the mouse is in, or zero if the mouse is in no
428 Emacs frame. If it is set to zero, all the other arguments are
429 garbage.
430
431 If the motion started in a scroll bar, set *bar_window to the
432 scroll bar's window, *part to the part the mouse is currently over,
433 *x to the position of the mouse along the scroll bar, and *y to the
434 overall length of the scroll bar.
435
436 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
437 row of the character cell the mouse is over.
438
439 Set *time to the time the mouse was at the returned position.
440
441 This should clear mouse_moved until the next motion
442 event arrives. */
443 void (*mouse_position_hook) P_ ((struct frame **f, int,
444 Lisp_Object *bar_window,
445 enum scroll_bar_part *part,
446 Lisp_Object *x,
447 Lisp_Object *y,
448 unsigned long *time));
449
450 /* The window system handling code should set this if the mouse has
451 moved since the last call to the mouse_position_hook. Calling that
452 hook should clear this. */
453 int mouse_moved;
454
455 /* When a frame's focus redirection is changed, this hook tells the
456 window system code to re-decide where to put the highlight. Under
457 X, this means that Emacs lies about where the focus is. */
458 void (*frame_rehighlight_hook) P_ ((struct frame *));
459
460 /* If we're displaying frames using a window system that can stack
461 frames on top of each other, this hook allows you to bring a frame
462 to the front, or bury it behind all the other windows. If this
463 hook is zero, that means the terminal we're displaying on doesn't
464 support overlapping frames, so there's no need to raise or lower
465 anything.
466
467 If RAISE is non-zero, F is brought to the front, before all other
468 windows. If RAISE is zero, F is sent to the back, behind all other
469 windows. */
470 void (*frame_raise_lower_hook) P_ ((struct frame *f, int raise));
471
472 /* If the value of the frame parameter changed, whis hook is called.
473 For example, if going from fullscreen to not fullscreen this hook
474 may do something OS dependent, like extended window manager hints on X11. */
475 void (*fullscreen_hook) P_ ((struct frame *f));
476
477
478 /* Scroll bar hooks. */
479
480 /* The representation of scroll bars is determined by the code which
481 implements them, except for one thing: they must be represented by
482 lisp objects. This allows us to place references to them in
483 Lisp_Windows without worrying about those references becoming
484 dangling references when the scroll bar is destroyed.
485
486 The window-system-independent portion of Emacs just refers to
487 scroll bars via their windows, and never looks inside the scroll bar
488 representation; it always uses hook functions to do all the
489 scroll bar manipulation it needs.
490
491 The `vertical_scroll_bar' field of a Lisp_Window refers to that
492 window's scroll bar, or is nil if the window doesn't have a
493 scroll bar.
494
495 The `scroll_bars' and `condemned_scroll_bars' fields of a Lisp_Frame
496 are free for use by the scroll bar implementation in any way it sees
497 fit. They are marked by the garbage collector. */
498
499
500 /* Set the vertical scroll bar for WINDOW to have its upper left corner
501 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
502 indicate that we are displaying PORTION characters out of a total
503 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
504 have a scroll bar, create one for it. */
505 void (*set_vertical_scroll_bar_hook) P_ ((struct window *window,
506 int portion, int whole,
507 int position));
508
509
510 /* The following three hooks are used when we're doing a thorough
511 redisplay of the frame. We don't explicitly know which scroll bars
512 are going to be deleted, because keeping track of when windows go
513 away is a real pain - can you say set-window-configuration?
514 Instead, we just assert at the beginning of redisplay that *all*
515 scroll bars are to be removed, and then save scroll bars from the
516 fiery pit when we actually redisplay their window. */
517
518 /* Arrange for all scroll bars on FRAME to be removed at the next call
519 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
520 `*redeem_scroll_bar_hook' is applied to its window before the judgement.
521
522 This should be applied to each frame each time its window tree is
523 redisplayed, even if it is not displaying scroll bars at the moment;
524 if the HAS_SCROLL_BARS flag has just been turned off, only calling
525 this and the judge_scroll_bars_hook will get rid of them.
526
527 If non-zero, this hook should be safe to apply to any frame,
528 whether or not it can support scroll bars, and whether or not it is
529 currently displaying them. */
530 void (*condemn_scroll_bars_hook) P_ ((struct frame *frame));
531
532 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
533 Note that it's okay to redeem a scroll bar that is not condemned. */
534 void (*redeem_scroll_bar_hook) P_ ((struct window *window));
535
536 /* Remove all scroll bars on FRAME that haven't been saved since the
537 last call to `*condemn_scroll_bars_hook'.
538
539 This should be applied to each frame after each time its window
540 tree is redisplayed, even if it is not displaying scroll bars at the
541 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
542 calling this and condemn_scroll_bars_hook will get rid of them.
543
544 If non-zero, this hook should be safe to apply to any frame,
545 whether or not it can support scroll bars, and whether or not it is
546 currently displaying them. */
547 void (*judge_scroll_bars_hook) P_ ((struct frame *FRAME));
548
549
550 /* Called to read input events.
551
552 TERMINAL indicates which terminal device to read from. Input
553 events should be read into BUF, the size of which is given in
554 SIZE. EXPECTED is non-zero if the caller suspects that new input
555 is available.
556
557 A positive return value indicates that that many input events
558 where read into BUF.
559 Zero means no events were immediately available.
560 A value of -1 means a transient read error, while -2 indicates
561 that the device was closed (hangup), and it should be deleted.
562
563 XXX Please note that a non-zero value of EXPECTED only means that
564 there is available input on at least one of the currently opened
565 terminal devices -- but not necessarily on this device.
566 Therefore, in most cases EXPECTED should be simply ignored.
567
568 XXX This documentation needs to be updated. */
569 int (*read_socket_hook) P_ ((struct terminal *terminal,
570 int expected,
571 struct input_event *hold_quit));
572
573 /* Called when a frame's display becomes entirely up to date. */
574 void (*frame_up_to_date_hook) P_ ((struct frame *));
575
576
577 /* Called to delete the device-specific portions of a frame that is
578 on this terminal device. */
579 void (*delete_frame_hook) P_ ((struct frame *));
580
581 /* Called after the last frame on this terminal is deleted, or when
582 the display device was closed (hangup).
583
584 If this is NULL, then the generic delete_terminal is called
585 instead. Otherwise the hook must call delete_terminal itself.
586
587 The hook must check for and close any live frames that are still
588 on the terminal. Fdelete_frame ensures that there are no live
589 frames on the terminal when it calls this hook, so infinite
590 recursion is prevented. */
591 void (*delete_terminal_hook) P_ ((struct terminal *));
592};
593
594
595/* Chain of all terminal devices currently in use. */
596extern struct terminal *terminal_list;
597
598#define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces)
599#define FRAME_FAST_CLEAR_END_OF_LINE(f) ((f)->terminal->fast_clear_end_of_line)
600#define FRAME_LINE_INS_DEL_OK(f) ((f)->terminal->line_ins_del_ok)
601#define FRAME_CHAR_INS_DEL_OK(f) ((f)->terminal->char_ins_del_ok)
602#define FRAME_SCROLL_REGION_OK(f) ((f)->terminal->scroll_region_ok)
603#define FRAME_SCROLL_REGION_COST(f) ((f)->terminal->scroll_region_cost)
604#define FRAME_MEMORY_BELOW_FRAME(f) ((f)->terminal->memory_below_frame)
605
606#define FRAME_TERMINAL_CODING(f) ((f)->terminal->terminal_coding)
607#define FRAME_KEYBOARD_CODING(f) ((f)->terminal->keyboard_coding)
608
609#define TERMINAL_TERMINAL_CODING(d) ((d)->terminal_coding)
610#define TERMINAL_KEYBOARD_CODING(d) ((d)->keyboard_coding)
611
612#define FRAME_RIF(f) ((f)->terminal->rif)
613
614#define FRAME_TERMINAL(f) ((f)->terminal)
615
616/* FRAME_WINDOW_P tests whether the frame is a window, and is
617 defined to be the predicate for the window system being used. */
618
619#ifdef HAVE_X_WINDOWS
620#define FRAME_WINDOW_P(f) FRAME_X_P (f)
462#endif 621#endif
622#ifdef HAVE_NTGUI
623#define FRAME_WINDOW_P(f) FRAME_W32_P (f)
624#endif
625#ifdef MAC_OS
626#define FRAME_WINDOW_P(f) FRAME_MAC_P (f)
627#endif
628#ifndef FRAME_WINDOW_P
629#define FRAME_WINDOW_P(f) (0)
630#endif
631
632/* Return true if the terminal device is not suspended. */
633#define TERMINAL_ACTIVE_P(d) ((d)->type != output_termcap || (d)->display_info.tty->input)
634
635extern Lisp_Object get_terminal_param P_ ((struct terminal *, Lisp_Object));
636extern struct terminal *get_terminal P_ ((Lisp_Object terminal, int));
637extern struct terminal *create_terminal P_ ((void));
638extern void delete_terminal P_ ((struct terminal *));
639
640/* The initial terminal device, created by initial_term_init. */
641extern struct terminal *initial_terminal;
463 642
464/* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d 643/* arch-tag: 33a00ecc-52b5-4186-a410-8801ac9f087d
465 (do not change this comment) */ 644 (do not change this comment) */
diff --git a/src/terminal.c b/src/terminal.c
new file mode 100644
index 00000000000..a02e65cd65a
--- /dev/null
+++ b/src/terminal.c
@@ -0,0 +1,629 @@
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#ifdef MULTI_KBOARD
585 initial_terminal->kboard = initial_kboard;
586#endif
587 initial_terminal->delete_terminal_hook = &delete_initial_terminal;
588 /* All other hooks are NULL. */
589
590 return initial_terminal;
591}
592
593/* Deletes the bootstrap terminal device.
594 Called through delete_terminal_hook. */
595
596static void
597delete_initial_terminal (struct terminal *terminal)
598{
599 if (terminal != initial_terminal)
600 abort ();
601
602 delete_terminal (terminal);
603 initial_terminal = NULL;
604}
605
606void
607syms_of_terminal ()
608{
609
610 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function,
611 doc: /* Non-nil means call this function to ring the bell.
612The function should accept no arguments. */);
613 Vring_bell_function = Qnil;
614
615 defsubr (&Sdelete_terminal);
616 defsubr (&Sframe_terminal);
617 defsubr (&Sterminal_live_p);
618 defsubr (&Sterminal_list);
619 defsubr (&Sterminal_name);
620 defsubr (&Sterminal_parameters);
621 defsubr (&Sterminal_parameter);
622 defsubr (&Smodify_terminal_parameters);
623 defsubr (&Sset_terminal_parameter);
624
625 Fprovide (intern ("multi-tty"), Qnil);
626}
627
628/* arch-tag: e9af6f27-b483-47dc-bb1a-730c1c5cab03
629 (do not change this comment) */
diff --git a/src/termopts.h b/src/termopts.h
index 210236017d5..5946666654c 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/w32.c b/src/w32.c
index d7e95aac7d1..dd87ef62fab 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -904,18 +904,6 @@ alarm (int seconds)
904 return 0; 904 return 0;
905} 905}
906 906
907void
908unrequest_sigio (void)
909{
910 return;
911}
912
913void
914request_sigio (void)
915{
916 return;
917}
918
919#define REG_ROOT "SOFTWARE\\GNU\\Emacs" 907#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
920 908
921LPBYTE 909LPBYTE
diff --git a/src/w32console.c b/src/w32console.c
index 3afa5fb392a..d5056217bf2 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -35,11 +35,12 @@ Boston, MA 02110-1301, USA.
35#include "charset.h" 35#include "charset.h"
36#include "coding.h" 36#include "coding.h"
37#include "disptab.h" 37#include "disptab.h"
38#include "termhooks.h"
39#include "dispextern.h"
40/* Disable features in frame.h that require a Window System. */ 38/* Disable features in frame.h that require a Window System. */
41#undef HAVE_WINDOW_SYSTEM 39#undef HAVE_WINDOW_SYSTEM
42#include "frame.h" 40#include "frame.h"
41#include "termhooks.h"
42#include "termchar.h"
43#include "dispextern.h"
43#include "w32inevt.h" 44#include "w32inevt.h"
44 45
45/* from window.c */ 46/* from window.c */
@@ -51,21 +52,17 @@ extern int detect_input_pending ();
51/* from sysdep.c */ 52/* from sysdep.c */
52extern int read_input_pending (); 53extern int read_input_pending ();
53 54
54extern struct frame * updating_frame; 55static void w32con_move_cursor (struct frame *f, int row, int col);
55extern int meta_key; 56static void w32con_clear_to_end (struct frame *f);
56 57static void w32con_clear_frame (struct frame *f);
57static void w32con_move_cursor (int row, int col); 58static void w32con_clear_end_of_line (struct frame *f, int);
58static void w32con_clear_to_end (void); 59static void w32con_ins_del_lines (struct frame *f, int vpos, int n);
59static void w32con_clear_frame (void); 60static void w32con_insert_glyphs (struct frame *f, struct glyph *start, int len);
60static void w32con_clear_end_of_line (int); 61static void w32con_write_glyphs (struct frame *f, struct glyph *string, int len);
61static void w32con_ins_del_lines (int vpos, int n); 62static void w32con_delete_glyphs (struct frame *f, int n);
62static void w32con_insert_glyphs (struct glyph *start, int len); 63static void w32con_reset_terminal_modes (struct terminal *t);
63static void w32con_write_glyphs (struct glyph *string, int len); 64static void w32con_set_terminal_modes (struct terminal *t);
64static void w32con_delete_glyphs (int n); 65static void w32con_set_terminal_window (struct frame *f, int size);
65void w32_sys_ring_bell (void);
66static void w32con_reset_terminal_modes (void);
67static void w32con_set_terminal_modes (void);
68static void w32con_set_terminal_window (int size);
69static void w32con_update_begin (struct frame * f); 66static void w32con_update_begin (struct frame * f);
70static void w32con_update_end (struct frame * f); 67static void w32con_update_end (struct frame * f);
71static WORD w32_face_attributes (struct frame *f, int face_id); 68static WORD w32_face_attributes (struct frame *f, int face_id);
@@ -99,38 +96,31 @@ ctrl_c_handler (unsigned long type)
99 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT)); 96 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
100} 97}
101 98
102/* If we're updating a frame, use it as the current frame
103 Otherwise, use the selected frame. */
104#define PICK_FRAME() (updating_frame ? updating_frame : SELECTED_FRAME ())
105 99
106/* Move the cursor to (row, col). */ 100/* Move the cursor to (ROW, COL) on FRAME. */
107static void 101static void
108w32con_move_cursor (int row, int col) 102w32con_move_cursor (struct frame *f, int row, int col)
109{ 103{
110 cursor_coords.X = col; 104 cursor_coords.X = col;
111 cursor_coords.Y = row; 105 cursor_coords.Y = row;
112 106
113 if (updating_frame == (struct frame *) NULL) 107 /* TODO: for multi-tty support, cur_screen should be replaced with a
114 { 108 reference to the terminal for this frame. */
115 SetConsoleCursorPosition (cur_screen, cursor_coords); 109 SetConsoleCursorPosition (cur_screen, cursor_coords);
116 }
117} 110}
118 111
119/* Clear from cursor to end of screen. */ 112/* Clear from cursor to end of screen. */
120static void 113static void
121w32con_clear_to_end (void) 114w32con_clear_to_end (struct frame *f)
122{ 115{
123 struct frame * f = PICK_FRAME (); 116 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
124 117 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
125 w32con_clear_end_of_line (FRAME_COLS (f) - 1);
126 w32con_ins_del_lines (cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
127} 118}
128 119
129/* Clear the frame. */ 120/* Clear the frame. */
130static void 121static void
131w32con_clear_frame (void) 122w32con_clear_frame (struct frame *f)
132{ 123{
133 struct frame * f = PICK_FRAME ();
134 COORD dest; 124 COORD dest;
135 int n; 125 int n;
136 DWORD r; 126 DWORD r;
@@ -145,7 +135,7 @@ w32con_clear_frame (void)
145 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r); 135 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
146 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r); 136 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
147 137
148 w32con_move_cursor (0, 0); 138 w32con_move_cursor (f, 0, 0);
149} 139}
150 140
151 141
@@ -154,7 +144,7 @@ static BOOL ceol_initialized = FALSE;
154 144
155/* Clear from Cursor to end (what's "standout marker"?). */ 145/* Clear from Cursor to end (what's "standout marker"?). */
156static void 146static void
157w32con_clear_end_of_line (int end) 147w32con_clear_end_of_line (struct frame *f, int end)
158{ 148{
159 if (!ceol_initialized) 149 if (!ceol_initialized)
160 { 150 {
@@ -165,18 +155,17 @@ w32con_clear_end_of_line (int end)
165 } 155 }
166 ceol_initialized = TRUE; 156 ceol_initialized = TRUE;
167 } 157 }
168 w32con_write_glyphs (glyph_base, end - cursor_coords.X); /* fencepost ? */ 158 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
169} 159}
170 160
171/* Insert n lines at vpos. if n is negative delete -n lines. */ 161/* Insert n lines at vpos. if n is negative delete -n lines. */
172static void 162static void
173w32con_ins_del_lines (int vpos, int n) 163w32con_ins_del_lines (struct frame *f, int vpos, int n)
174{ 164{
175 int i, nb; 165 int i, nb;
176 SMALL_RECT scroll; 166 SMALL_RECT scroll;
177 COORD dest; 167 COORD dest;
178 CHAR_INFO fill; 168 CHAR_INFO fill;
179 struct frame * f = PICK_FRAME ();
180 169
181 if (n < 0) 170 if (n < 0)
182 { 171 {
@@ -213,8 +202,8 @@ w32con_ins_del_lines (int vpos, int n)
213 { 202 {
214 for (i = scroll.Bottom; i < dest.Y; i++) 203 for (i = scroll.Bottom; i < dest.Y; i++)
215 { 204 {
216 w32con_move_cursor (i, 0); 205 w32con_move_cursor (f, i, 0);
217 w32con_clear_end_of_line (FRAME_COLS (f)); 206 w32con_clear_end_of_line (f, FRAME_COLS (f));
218 } 207 }
219 } 208 }
220 } 209 }
@@ -226,8 +215,8 @@ w32con_ins_del_lines (int vpos, int n)
226 { 215 {
227 for (i = nb; i < scroll.Top; i++) 216 for (i = nb; i < scroll.Top; i++)
228 { 217 {
229 w32con_move_cursor (i, 0); 218 w32con_move_cursor (f, i, 0);
230 w32con_clear_end_of_line (FRAME_COLS (f)); 219 w32con_clear_end_of_line (f, FRAME_COLS (f));
231 } 220 }
232 } 221 }
233 } 222 }
@@ -242,14 +231,13 @@ w32con_ins_del_lines (int vpos, int n)
242#define RIGHT 0 231#define RIGHT 0
243 232
244static void 233static void
245scroll_line (int dist, int direction) 234scroll_line (struct frame *f, int dist, int direction)
246{ 235{
247 /* The idea here is to implement a horizontal scroll in one line to 236 /* The idea here is to implement a horizontal scroll in one line to
248 implement delete and half of insert. */ 237 implement delete and half of insert. */
249 SMALL_RECT scroll; 238 SMALL_RECT scroll;
250 COORD dest; 239 COORD dest;
251 CHAR_INFO fill; 240 CHAR_INFO fill;
252 struct frame * f = PICK_FRAME ();
253 241
254 scroll.Top = cursor_coords.Y; 242 scroll.Top = cursor_coords.Y;
255 scroll.Bottom = cursor_coords.Y; 243 scroll.Bottom = cursor_coords.Y;
@@ -277,9 +265,9 @@ scroll_line (int dist, int direction)
277 265
278/* If start is zero insert blanks instead of a string at start ?. */ 266/* If start is zero insert blanks instead of a string at start ?. */
279static void 267static void
280w32con_insert_glyphs (register struct glyph *start, register int len) 268w32con_insert_glyphs (struct frame *f, register struct glyph *start, register int len)
281{ 269{
282 scroll_line (len, RIGHT); 270 scroll_line (f, len, RIGHT);
283 271
284 /* Move len chars to the right starting at cursor_coords, fill with blanks */ 272 /* Move len chars to the right starting at cursor_coords, fill with blanks */
285 if (start) 273 if (start)
@@ -287,11 +275,11 @@ w32con_insert_glyphs (register struct glyph *start, register int len)
287 /* Print the first len characters of start, cursor_coords.X adjusted 275 /* Print the first len characters of start, cursor_coords.X adjusted
288 by write_glyphs. */ 276 by write_glyphs. */
289 277
290 w32con_write_glyphs (start, len); 278 w32con_write_glyphs (f, start, len);
291 } 279 }
292 else 280 else
293 { 281 {
294 w32con_clear_end_of_line (cursor_coords.X + len); 282 w32con_clear_end_of_line (f, cursor_coords.X + len);
295 } 283 }
296} 284}
297 285
@@ -299,11 +287,11 @@ extern unsigned char *encode_terminal_code P_ ((struct glyph *, int,
299 struct coding_system *)); 287 struct coding_system *));
300 288
301static void 289static void
302w32con_write_glyphs (register struct glyph *string, register int len) 290w32con_write_glyphs (struct frame *f, register struct glyph *string,
291 register int len)
303{ 292{
304 int produced, consumed; 293 int produced, consumed;
305 DWORD r; 294 DWORD r;
306 struct frame * f = PICK_FRAME ();
307 WORD char_attr; 295 WORD char_attr;
308 unsigned char *conversion_buffer; 296 unsigned char *conversion_buffer;
309 struct coding_system *coding; 297 struct coding_system *coding;
@@ -314,11 +302,11 @@ w32con_write_glyphs (register struct glyph *string, register int len)
314 /* If terminal_coding does any conversion, use it, otherwise use 302 /* If terminal_coding does any conversion, use it, otherwise use
315 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here 303 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
316 because it always return 1 if the member src_multibyte is 1. */ 304 because it always return 1 if the member src_multibyte is 1. */
317 coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK 305 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
318 ? &terminal_coding : &safe_terminal_coding); 306 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
319 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at 307 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
320 the tail. */ 308 the tail. */
321 terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK; 309 coding->mode &= ~CODING_MODE_LAST_BLOCK;
322 310
323 while (len > 0) 311 while (len > 0)
324 { 312 {
@@ -360,7 +348,7 @@ w32con_write_glyphs (register struct glyph *string, register int len)
360 } 348 }
361 349
362 cursor_coords.X += coding->produced; 350 cursor_coords.X += coding->produced;
363 w32con_move_cursor (cursor_coords.Y, cursor_coords.X); 351 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
364 } 352 }
365 len -= n; 353 len -= n;
366 string += n; 354 string += n;
@@ -369,20 +357,20 @@ w32con_write_glyphs (register struct glyph *string, register int len)
369 357
370 358
371static void 359static void
372w32con_delete_glyphs (int n) 360w32con_delete_glyphs (struct frame *f, int n)
373{ 361{
374 /* delete chars means scroll chars from cursor_coords.X + n to 362 /* delete chars means scroll chars from cursor_coords.X + n to
375 cursor_coords.X, anything beyond the edge of the screen should 363 cursor_coords.X, anything beyond the edge of the screen should
376 come out empty... */ 364 come out empty... */
377 365
378 scroll_line (n, LEFT); 366 scroll_line (f, n, LEFT);
379} 367}
380 368
381static unsigned int sound_type = 0xFFFFFFFF; 369static unsigned int sound_type = 0xFFFFFFFF;
382#define MB_EMACS_SILENT (0xFFFFFFFF - 1) 370#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
383 371
384void 372void
385w32_sys_ring_bell (void) 373w32_sys_ring_bell (struct frame *f)
386{ 374{
387 if (sound_type == 0xFFFFFFFF) 375 if (sound_type == 0xFFFFFFFF)
388 { 376 {
@@ -428,7 +416,7 @@ SOUND is nil to use the normal beep. */)
428} 416}
429 417
430static void 418static void
431w32con_reset_terminal_modes (void) 419w32con_reset_terminal_modes (struct terminal *t)
432{ 420{
433#ifdef USE_SEPARATE_SCREEN 421#ifdef USE_SEPARATE_SCREEN
434 SetConsoleActiveScreenBuffer (prev_screen); 422 SetConsoleActiveScreenBuffer (prev_screen);
@@ -439,7 +427,7 @@ w32con_reset_terminal_modes (void)
439} 427}
440 428
441static void 429static void
442w32con_set_terminal_modes (void) 430w32con_set_terminal_modes (struct terminal *t)
443{ 431{
444 CONSOLE_CURSOR_INFO cci; 432 CONSOLE_CURSOR_INFO cci;
445 433
@@ -473,7 +461,7 @@ w32con_update_end (struct frame * f)
473} 461}
474 462
475static void 463static void
476w32con_set_terminal_window (int size) 464w32con_set_terminal_window (struct frame *f, int size)
477{ 465{
478} 466}
479 467
@@ -546,29 +534,34 @@ vga_stdcolor_name (int idx)
546 534
547typedef int (*term_hook) (); 535typedef int (*term_hook) ();
548 536
537/* TEMPORARY HACK to get w32console compiling. To support multiple consoles,
538 this needs to go! */
539struct terminal one_and_only_w32cons;
540
549void 541void
550initialize_w32_display (void) 542initialize_w32_display (void)
551{ 543{
552 CONSOLE_SCREEN_BUFFER_INFO info; 544 CONSOLE_SCREEN_BUFFER_INFO info;
553 545 struct terminal *term = &one_and_only_w32cons;
554 cursor_to_hook = w32con_move_cursor; 546
555 raw_cursor_to_hook = w32con_move_cursor; 547 term->cursor_to_hook = w32con_move_cursor;
556 clear_to_end_hook = w32con_clear_to_end; 548 term->raw_cursor_to_hook = w32con_move_cursor;
557 clear_frame_hook = w32con_clear_frame; 549 term->clear_to_end_hook = w32con_clear_to_end;
558 clear_end_of_line_hook = w32con_clear_end_of_line; 550 term->clear_frame_hook = w32con_clear_frame;
559 ins_del_lines_hook = w32con_ins_del_lines; 551 term->clear_end_of_line_hook = w32con_clear_end_of_line;
560 insert_glyphs_hook = w32con_insert_glyphs; 552 term->ins_del_lines_hook = w32con_ins_del_lines;
561 write_glyphs_hook = w32con_write_glyphs; 553 term->insert_glyphs_hook = w32con_insert_glyphs;
562 delete_glyphs_hook = w32con_delete_glyphs; 554 term->write_glyphs_hook = w32con_write_glyphs;
563 ring_bell_hook = w32_sys_ring_bell; 555 term->delete_glyphs_hook = w32con_delete_glyphs;
564 reset_terminal_modes_hook = w32con_reset_terminal_modes; 556 term->ring_bell_hook = w32_sys_ring_bell;
565 set_terminal_modes_hook = w32con_set_terminal_modes; 557 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
566 set_terminal_window_hook = w32con_set_terminal_window; 558 term->set_terminal_modes_hook = w32con_set_terminal_modes;
567 update_begin_hook = w32con_update_begin; 559 term->set_terminal_window_hook = w32con_set_terminal_window;
568 update_end_hook = w32con_update_end; 560 term->update_begin_hook = w32con_update_begin;
569 561 term->update_end_hook = w32con_update_end;
570 read_socket_hook = w32_console_read_socket; 562
571 mouse_position_hook = w32_console_mouse_position; 563 term->read_socket_hook = w32_console_read_socket;
564 term->mouse_position_hook = w32_console_mouse_position;
572 565
573 /* Initialize interrupt_handle. */ 566 /* Initialize interrupt_handle. */
574 init_crit (); 567 init_crit ();
@@ -633,7 +626,6 @@ initialize_w32_display (void)
633 626
634 GetConsoleScreenBufferInfo (cur_screen, &info); 627 GetConsoleScreenBufferInfo (cur_screen, &info);
635 628
636 meta_key = 1;
637 char_attr_normal = info.wAttributes; 629 char_attr_normal = info.wAttributes;
638 630
639 /* Determine if the info returned by GetConsoleScreenBufferInfo 631 /* Determine if the info returned by GetConsoleScreenBufferInfo
@@ -674,6 +666,25 @@ initialize_w32_display (void)
674 666
675} 667}
676 668
669/* Initialize the tty-dependent part of frame F. The frame must
670 already have its device initialized. */
671void
672create_w32cons_output(struct frame *f)
673{
674 struct tty_output *tty;
675
676 if (! FRAME_TERMCAP_P (f))
677 abort ();
678
679 tty = xmalloc (sizeof (struct tty_output));
680 bzero (tty, sizeof (struct tty_output));
681
682 tty->display_info = FRAME_TERMINAL (f)->display_info.tty;
683 tty->display_info->meta_key = 1;
684
685 f->output_data.tty = tty;
686}
687
677DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0, 688DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
678 doc: /* Set screen colors. */) 689 doc: /* Set screen colors. */)
679 (foreground, background) 690 (foreground, background)
diff --git a/src/w32fns.c b/src/w32fns.c
index be3570231dc..e7a4bb3d5ed 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1818,10 +1818,8 @@ x_set_tool_bar_lines (f, value, oldval)
1818 below the menu bar. */ 1818 below the menu bar. */
1819 if (FRAME_W32_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) 1819 if (FRAME_W32_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1820 { 1820 {
1821 updating_frame = f; 1821 clear_frame (f);
1822 clear_frame ();
1823 clear_current_matrices (f); 1822 clear_current_matrices (f);
1824 updating_frame = NULL;
1825 } 1823 }
1826 1824
1827 /* If the tool bar gets smaller, the internal border below it 1825 /* If the tool bar gets smaller, the internal border below it
@@ -4180,7 +4178,7 @@ This function is an internal primitive--use `make-frame' instead. */)
4180 display = Qnil; 4178 display = Qnil;
4181 dpyinfo = check_x_display_info (display); 4179 dpyinfo = check_x_display_info (display);
4182#ifdef MULTI_KBOARD 4180#ifdef MULTI_KBOARD
4183 kb = dpyinfo->kboard; 4181 kb = dpyinfo->terminal->kboard;
4184#else 4182#else
4185 kb = &the_only_kboard; 4183 kb = &the_only_kboard;
4186#endif 4184#endif
@@ -4228,6 +4226,9 @@ This function is an internal primitive--use `make-frame' instead. */)
4228 /* By default, make scrollbars the system standard width. */ 4226 /* By default, make scrollbars the system standard width. */
4229 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); 4227 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL);
4230 4228
4229 f->terminal = dpyinfo->terminal;
4230 f->terminal->reference_count++;
4231
4231 f->output_method = output_w32; 4232 f->output_method = output_w32;
4232 f->output_data.w32 = 4233 f->output_data.w32 =
4233 (struct w32_output *) xmalloc (sizeof (struct w32_output)); 4234 (struct w32_output *) xmalloc (sizeof (struct w32_output));
@@ -4442,6 +4443,22 @@ This function is an internal primitive--use `make-frame' instead. */)
4442 /* Must have been Qnil. */ 4443 /* Must have been Qnil. */
4443 ; 4444 ;
4444 } 4445 }
4446
4447 /* Initialize `default-minibuffer-frame' in case this is the first
4448 frame on this terminal. */
4449 if (FRAME_HAS_MINIBUF_P (f)
4450 && (!FRAMEP (kb->Vdefault_minibuffer_frame)
4451 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
4452 kb->Vdefault_minibuffer_frame = frame;
4453
4454 /* All remaining specified parameters, which have not been "used"
4455 by x_get_arg and friends, now go in the misc. alist of the frame. */
4456 for (tem = parameters; !NILP (tem); tem = XCDR (tem))
4457 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
4458 f->param_alist = Fcons (XCAR (tem), f->param_alist);
4459
4460 store_frame_param (f, Qwindow_system, Qw32);
4461
4445 UNGCPRO; 4462 UNGCPRO;
4446 4463
4447 /* Make sure windows on this frame appear in calls to next-window 4464 /* Make sure windows on this frame appear in calls to next-window
@@ -6716,8 +6733,10 @@ terminate Emacs if we can't open the connection. */)
6716 if (! NILP (xrm_string)) 6733 if (! NILP (xrm_string))
6717 CHECK_STRING (xrm_string); 6734 CHECK_STRING (xrm_string);
6718 6735
6736#if 0
6719 if (! EQ (Vwindow_system, intern ("w32"))) 6737 if (! EQ (Vwindow_system, intern ("w32")))
6720 error ("Not using Microsoft Windows"); 6738 error ("Not using Microsoft Windows");
6739#endif
6721 6740
6722 /* Allow color mapping to be defined externally; first look in user's 6741 /* Allow color mapping to be defined externally; first look in user's
6723 HOME directory, then in Emacs etc dir for a file called rgb.txt. */ 6742 HOME directory, then in Emacs etc dir for a file called rgb.txt. */
@@ -7257,6 +7276,8 @@ x_create_tip_frame (dpyinfo, parms, text)
7257 the frame is live, as per FRAME_LIVE_P. If we get a signal 7276 the frame is live, as per FRAME_LIVE_P. If we get a signal
7258 from this point on, x_destroy_window might screw up reference 7277 from this point on, x_destroy_window might screw up reference
7259 counts etc. */ 7278 counts etc. */
7279 f->terminal = dpyinfo->terminal;
7280 f->terminal->reference_count++;
7260 f->output_method = output_w32; 7281 f->output_method = output_w32;
7261 f->output_data.w32 = 7282 f->output_data.w32 =
7262 (struct w32_output *) xmalloc (sizeof (struct w32_output)); 7283 (struct w32_output *) xmalloc (sizeof (struct w32_output));
@@ -7420,6 +7441,8 @@ x_create_tip_frame (dpyinfo, parms, text)
7420 Qnil)); 7441 Qnil));
7421 } 7442 }
7422 7443
7444 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qw32), Qnil));
7445
7423 f->no_split = 1; 7446 f->no_split = 1;
7424 7447
7425 UNGCPRO; 7448 UNGCPRO;
diff --git a/src/w32inevt.c b/src/w32inevt.c
index fa2d34c2998..17cfd384400 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -643,7 +643,9 @@ maybe_generate_resize_event ()
643} 643}
644 644
645int 645int
646w32_console_read_socket (int sd, int expected, struct input_event *hold_quit) 646w32_console_read_socket (struct terminal *terminal,
647 int expected,
648 struct input_event *hold_quit)
647{ 649{
648 BOOL no_events = TRUE; 650 BOOL no_events = TRUE;
649 int nev, ret = 0, add; 651 int nev, ret = 0, add;
diff --git a/src/w32inevt.h b/src/w32inevt.h
index 53f36e3a348..08d85a0b2e4 100644
--- a/src/w32inevt.h
+++ b/src/w32inevt.h
@@ -22,7 +22,7 @@ Boston, MA 02110-1301, USA. */
22#ifndef EMACS_W32INEVT_H 22#ifndef EMACS_W32INEVT_H
23#define EMACS_W32INEVT_H 23#define EMACS_W32INEVT_H
24 24
25extern int w32_console_read_socket (int sd, int numchars, 25extern int w32_console_read_socket (struct terminal *term, int numchars,
26 struct input_event *hold_quit); 26 struct input_event *hold_quit);
27extern void w32_console_mouse_position (FRAME_PTR *f, int insist, 27extern void w32_console_mouse_position (FRAME_PTR *f, int insist,
28 Lisp_Object *bar_window, 28 Lisp_Object *bar_window,
diff --git a/src/w32menu.c b/src/w32menu.c
index f0d582d388a..e5638cc4bfd 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -20,15 +20,16 @@ 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 <signal.h>
24 23
24#include <signal.h>
25#include <stdio.h> 25#include <stdio.h>
26#include <mbstring.h> 26#include <mbstring.h>
27
27#include "lisp.h" 28#include "lisp.h"
28#include "termhooks.h"
29#include "keyboard.h" 29#include "keyboard.h"
30#include "keymap.h" 30#include "keymap.h"
31#include "frame.h" 31#include "frame.h"
32#include "termhooks.h"
32#include "window.h" 33#include "window.h"
33#include "blockinput.h" 34#include "blockinput.h"
34#include "buffer.h" 35#include "buffer.h"
@@ -674,8 +675,8 @@ cached information about equivalent key sequences. */)
674 enum scroll_bar_part part; 675 enum scroll_bar_part part;
675 unsigned long time; 676 unsigned long time;
676 677
677 if (mouse_position_hook) 678 if (FRAME_TERMINAL (new_f)->mouse_position_hook)
678 (*mouse_position_hook) (&new_f, 1, &bar_window, 679 (*FRAME_TERMINAL (new_f)->mouse_position_hook) (&new_f, 1, &bar_window,
679 &part, &x, &y, &time); 680 &part, &x, &y, &time);
680 if (new_f != 0) 681 if (new_f != 0)
681 XSETFRAME (window, new_f); 682 XSETFRAME (window, new_f);
diff --git a/src/w32term.c b/src/w32term.c
index 6f97426d499..100af4ebc21 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -234,9 +234,9 @@ static void x_font_min_bounds P_ ((XFontStruct *, int *, int *));
234int x_compute_min_glyph_bounds P_ ((struct frame *)); 234int x_compute_min_glyph_bounds P_ ((struct frame *));
235static void x_update_end P_ ((struct frame *)); 235static void x_update_end P_ ((struct frame *));
236static void w32_frame_up_to_date P_ ((struct frame *)); 236static void w32_frame_up_to_date P_ ((struct frame *));
237static void w32_set_terminal_modes P_ ((void)); 237static void w32_set_terminal_modes P_ ((struct terminal *));
238static void w32_reset_terminal_modes P_ ((void)); 238static void w32_reset_terminal_modes P_ ((struct terminal *));
239static void x_clear_frame P_ ((void)); 239static void x_clear_frame P_ ((struct frame *));
240static void frame_highlight P_ ((struct frame *)); 240static void frame_highlight P_ ((struct frame *));
241static void frame_unhighlight P_ ((struct frame *)); 241static void frame_unhighlight P_ ((struct frame *));
242static void x_new_focus_frame P_ ((struct w32_display_info *, 242static void x_new_focus_frame P_ ((struct w32_display_info *,
@@ -848,7 +848,7 @@ w32_destroy_fringe_bitmap (which)
848 rarely happens). */ 848 rarely happens). */
849 849
850static void 850static void
851w32_set_terminal_modes (void) 851w32_set_terminal_modes (struct terminal *term)
852{ 852{
853} 853}
854 854
@@ -856,7 +856,7 @@ w32_set_terminal_modes (void)
856 the W32 windows go away, and suspending requires no action. */ 856 the W32 windows go away, and suspending requires no action. */
857 857
858static void 858static void
859w32_reset_terminal_modes (void) 859w32_reset_terminal_modes (struct terminal *term)
860{ 860{
861} 861}
862 862
@@ -2655,16 +2655,10 @@ w32_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
2655 for X frames. */ 2655 for X frames. */
2656 2656
2657static void 2657static void
2658x_delete_glyphs (n) 2658x_delete_glyphs (f, n)
2659 struct frame *f;
2659 register int n; 2660 register int n;
2660{ 2661{
2661 struct frame *f;
2662
2663 if (updating_frame)
2664 f = updating_frame;
2665 else
2666 f = SELECTED_FRAME ();
2667
2668 if (! FRAME_W32_P (f)) 2662 if (! FRAME_W32_P (f))
2669 return; 2663 return;
2670 2664
@@ -2676,15 +2670,8 @@ x_delete_glyphs (n)
2676 frame. Otherwise clear the selected frame. */ 2670 frame. Otherwise clear the selected frame. */
2677 2671
2678static void 2672static void
2679x_clear_frame () 2673x_clear_frame (struct frame *f)
2680{ 2674{
2681 struct frame *f;
2682
2683 if (updating_frame)
2684 f = updating_frame;
2685 else
2686 f = SELECTED_FRAME ();
2687
2688 if (! FRAME_W32_P (f)) 2675 if (! FRAME_W32_P (f))
2689 return; 2676 return;
2690 2677
@@ -2711,18 +2698,14 @@ x_clear_frame ()
2711/* Make audible bell. */ 2698/* Make audible bell. */
2712 2699
2713static void 2700static void
2714w32_ring_bell (void) 2701w32_ring_bell (struct frame *f)
2715{ 2702{
2716 struct frame *f;
2717
2718 f = SELECTED_FRAME ();
2719
2720 BLOCK_INPUT; 2703 BLOCK_INPUT;
2721 2704
2722 if (FRAME_W32_P (f) && visible_bell) 2705 if (FRAME_W32_P (f) && visible_bell)
2723 { 2706 {
2724 int i; 2707 int i;
2725 HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); 2708 HWND hwnd = FRAME_W32_WINDOW (f);
2726 2709
2727 for (i = 0; i < 5; i++) 2710 for (i = 0; i < 5; i++)
2728 { 2711 {
@@ -2732,7 +2715,7 @@ w32_ring_bell (void)
2732 FlashWindow (hwnd, FALSE); 2715 FlashWindow (hwnd, FALSE);
2733 } 2716 }
2734 else 2717 else
2735 w32_sys_ring_bell (); 2718 w32_sys_ring_bell (f);
2736 2719
2737 UNBLOCK_INPUT; 2720 UNBLOCK_INPUT;
2738} 2721}
@@ -2759,16 +2742,10 @@ w32_set_terminal_window (n)
2759 lines or deleting -N lines at vertical position VPOS. */ 2742 lines or deleting -N lines at vertical position VPOS. */
2760 2743
2761static void 2744static void
2762x_ins_del_lines (vpos, n) 2745x_ins_del_lines (f, vpos, n)
2746 struct frame *f;
2763 int vpos, n; 2747 int vpos, n;
2764{ 2748{
2765 struct frame *f;
2766
2767 if (updating_frame)
2768 f = updating_frame;
2769 else
2770 f = SELECTED_FRAME ();
2771
2772 if (! FRAME_W32_P (f)) 2749 if (! FRAME_W32_P (f))
2773 return; 2750 return;
2774 2751
@@ -5935,8 +5912,8 @@ x_free_frame_resources (f)
5935 5912
5936 free_frame_menubar (f); 5913 free_frame_menubar (f);
5937 5914
5938 unload_color (f, f->output_data.x->foreground_pixel); 5915 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
5939 unload_color (f, f->output_data.x->background_pixel); 5916 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
5940 unload_color (f, f->output_data.w32->cursor_pixel); 5917 unload_color (f, f->output_data.w32->cursor_pixel);
5941 unload_color (f, f->output_data.w32->cursor_foreground_pixel); 5918 unload_color (f, f->output_data.w32->cursor_foreground_pixel);
5942 unload_color (f, f->output_data.w32->border_pixel); 5919 unload_color (f, f->output_data.w32->border_pixel);
@@ -5975,14 +5952,13 @@ x_free_frame_resources (f)
5975 5952
5976 5953
5977/* Destroy the window of frame F. */ 5954/* Destroy the window of frame F. */
5978 5955void
5979x_destroy_window (f) 5956x_destroy_window (f)
5980 struct frame *f; 5957 struct frame *f;
5981{ 5958{
5982 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f); 5959 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
5983 5960
5984 x_free_frame_resources (f); 5961 x_free_frame_resources (f);
5985
5986 dpyinfo->reference_count--; 5962 dpyinfo->reference_count--;
5987} 5963}
5988 5964
@@ -6242,6 +6218,116 @@ w32_make_rdb (xrm_option)
6242 return buffer; 6218 return buffer;
6243} 6219}
6244 6220
6221void
6222x_flush (struct frame * f)
6223{ /* Nothing to do */ }
6224
6225
6226extern frame_parm_handler w32_frame_parm_handlers[];
6227
6228static struct redisplay_interface w32_redisplay_interface =
6229{
6230 w32_frame_parm_handlers,
6231 x_produce_glyphs,
6232 x_write_glyphs,
6233 x_insert_glyphs,
6234 x_clear_end_of_line,
6235 x_scroll_run,
6236 x_after_update_window_line,
6237 x_update_window_begin,
6238 x_update_window_end,
6239 x_cursor_to,
6240 x_flush,
6241 0, /* flush_display_optional */
6242 x_clear_window_mouse_face,
6243 w32_get_glyph_overhangs,
6244 x_fix_overlapping_area,
6245 w32_draw_fringe_bitmap,
6246 w32_define_fringe_bitmap,
6247 w32_destroy_fringe_bitmap,
6248 w32_per_char_metric,
6249 w32_encode_char,
6250 NULL, /* w32_compute_glyph_string_overhangs */
6251 x_draw_glyph_string,
6252 w32_define_frame_cursor,
6253 w32_clear_frame_area,
6254 w32_draw_window_cursor,
6255 w32_draw_vertical_window_border,
6256 w32_shift_glyphs_for_insert
6257};
6258
6259static void x_delete_terminal (struct terminal *term);
6260
6261static struct terminal *
6262w32_create_terminal (struct w32_display_info *dpyinfo)
6263{
6264 struct terminal *terminal;
6265
6266 terminal = create_terminal ();
6267
6268 terminal->type = output_w32;
6269 terminal->display_info.w32 = dpyinfo;
6270 dpyinfo->terminal = terminal;
6271
6272 /* MSVC does not type K&R functions with no arguments correctly, and
6273 so we must explicitly cast them. */
6274 terminal->clear_frame_hook = x_clear_frame;
6275 terminal->ins_del_lines_hook = x_ins_del_lines;
6276 terminal->delete_glyphs_hook = x_delete_glyphs;
6277 terminal->ring_bell_hook = w32_ring_bell;
6278 terminal->reset_terminal_modes_hook = w32_reset_terminal_modes;
6279 terminal->set_terminal_modes_hook = w32_set_terminal_modes;
6280 terminal->update_begin_hook = x_update_begin;
6281 terminal->update_end_hook = x_update_end;
6282 terminal->set_terminal_window_hook = w32_set_terminal_window;
6283 terminal->read_socket_hook = w32_read_socket;
6284 terminal->frame_up_to_date_hook = w32_frame_up_to_date;
6285 terminal->mouse_position_hook = w32_mouse_position;
6286 terminal->frame_rehighlight_hook = w32_frame_rehighlight;
6287 terminal->frame_raise_lower_hook = w32_frame_raise_lower;
6288 // terminal->fullscreen_hook = XTfullscreen_hook;
6289 terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6290 terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6291 terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6292 terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
6293
6294 terminal->delete_frame_hook = x_destroy_window;
6295 terminal->delete_terminal_hook = x_delete_terminal;
6296
6297 terminal->rif = &w32_redisplay_interface;
6298 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
6299 terminal->char_ins_del_ok = 1;
6300 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
6301 terminal->fast_clear_end_of_line = 1; /* X does this well. */
6302 terminal->memory_below_frame = 0; /* We don't remember what scrolls
6303 off the bottom. */
6304
6305 return terminal;
6306}
6307
6308static void
6309x_delete_terminal (struct terminal *terminal)
6310{
6311 struct w32_display_info *dpyinfo = terminal->display_info.w32;
6312 int i;
6313
6314 /* Protect against recursive calls. Fdelete_frame in
6315 delete_terminal calls us back when it deletes our last frame. */
6316 if (terminal->deleted)
6317 return;
6318
6319 BLOCK_INPUT;
6320 /* Free the fonts in the font table. */
6321 for (i = 0; i < dpyinfo->n_fonts; i++)
6322 if (dpyinfo->font_table[i].name)
6323 {
6324 DeleteObject (((XFontStruct*)(dpyinfo->font_table[i].font))->hfont);
6325 }
6326
6327 x_delete_display (dpyinfo);
6328 UNBLOCK_INPUT;
6329}
6330
6245struct w32_display_info * 6331struct w32_display_info *
6246w32_term_init (display_name, xrm_option, resource_name) 6332w32_term_init (display_name, xrm_option, resource_name)
6247 Lisp_Object display_name; 6333 Lisp_Object display_name;
@@ -6249,6 +6335,7 @@ w32_term_init (display_name, xrm_option, resource_name)
6249 char *resource_name; 6335 char *resource_name;
6250{ 6336{
6251 struct w32_display_info *dpyinfo; 6337 struct w32_display_info *dpyinfo;
6338 struct terminal *terminal;
6252 HDC hdc; 6339 HDC hdc;
6253 6340
6254 BLOCK_INPUT; 6341 BLOCK_INPUT;
@@ -6262,6 +6349,12 @@ w32_term_init (display_name, xrm_option, resource_name)
6262 w32_initialize_display_info (display_name); 6349 w32_initialize_display_info (display_name);
6263 6350
6264 dpyinfo = &one_w32_display_info; 6351 dpyinfo = &one_w32_display_info;
6352 terminal = w32_create_terminal (dpyinfo);
6353
6354 /* Set the name of the terminal. */
6355 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
6356 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
6357 terminal->name[SBYTES (display_name)] = 0;
6265 6358
6266 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL; 6359 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
6267 6360
@@ -6291,6 +6384,9 @@ w32_term_init (display_name, xrm_option, resource_name)
6291 w32_defined_color (0, "black", &color, 1); 6384 w32_defined_color (0, "black", &color, 1);
6292 } 6385 }
6293 6386
6387 /* Add the default keyboard. */
6388 add_keyboard_wait_descriptor (0);
6389
6294 /* Create Fringe Bitmaps and store them for later use. 6390 /* Create Fringe Bitmaps and store them for later use.
6295 6391
6296 On W32, bitmaps are all unsigned short, as Windows requires 6392 On W32, bitmaps are all unsigned short, as Windows requires
@@ -6322,7 +6418,6 @@ w32_term_init (display_name, xrm_option, resource_name)
6322} 6418}
6323 6419
6324/* Get rid of display DPYINFO, assuming all frames are already gone. */ 6420/* Get rid of display DPYINFO, assuming all frames are already gone. */
6325
6326void 6421void
6327x_delete_display (dpyinfo) 6422x_delete_display (dpyinfo)
6328 struct w32_display_info *dpyinfo; 6423 struct w32_display_info *dpyinfo;
@@ -6373,73 +6468,9 @@ x_delete_display (dpyinfo)
6373 6468
6374DWORD WINAPI w32_msg_worker (void * arg); 6469DWORD WINAPI w32_msg_worker (void * arg);
6375 6470
6376void
6377x_flush (struct frame * f)
6378{ /* Nothing to do */ }
6379
6380extern frame_parm_handler w32_frame_parm_handlers[];
6381
6382static struct redisplay_interface w32_redisplay_interface =
6383{
6384 w32_frame_parm_handlers,
6385 x_produce_glyphs,
6386 x_write_glyphs,
6387 x_insert_glyphs,
6388 x_clear_end_of_line,
6389 x_scroll_run,
6390 x_after_update_window_line,
6391 x_update_window_begin,
6392 x_update_window_end,
6393 x_cursor_to,
6394 x_flush,
6395 0, /* flush_display_optional */
6396 x_clear_window_mouse_face,
6397 w32_get_glyph_overhangs,
6398 x_fix_overlapping_area,
6399 w32_draw_fringe_bitmap,
6400 w32_define_fringe_bitmap,
6401 w32_destroy_fringe_bitmap,
6402 w32_per_char_metric,
6403 w32_encode_char,
6404 NULL, /* w32_compute_glyph_string_overhangs */
6405 x_draw_glyph_string,
6406 w32_define_frame_cursor,
6407 w32_clear_frame_area,
6408 w32_draw_window_cursor,
6409 w32_draw_vertical_window_border,
6410 w32_shift_glyphs_for_insert
6411};
6412
6413static void 6471static void
6414w32_initialize () 6472w32_initialize ()
6415{ 6473{
6416 rif = &w32_redisplay_interface;
6417
6418 /* MSVC does not type K&R functions with no arguments correctly, and
6419 so we must explicitly cast them. */
6420 clear_frame_hook = (void (*)(void)) x_clear_frame;
6421 ring_bell_hook = (void (*)(void)) w32_ring_bell;
6422 update_begin_hook = x_update_begin;
6423 update_end_hook = x_update_end;
6424
6425 read_socket_hook = w32_read_socket;
6426
6427 frame_up_to_date_hook = w32_frame_up_to_date;
6428
6429 mouse_position_hook = w32_mouse_position;
6430 frame_rehighlight_hook = w32_frame_rehighlight;
6431 frame_raise_lower_hook = w32_frame_raise_lower;
6432 set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
6433 condemn_scroll_bars_hook = w32_condemn_scroll_bars;
6434 redeem_scroll_bar_hook = w32_redeem_scroll_bar;
6435 judge_scroll_bars_hook = w32_judge_scroll_bars;
6436
6437 scroll_region_ok = 1; /* we'll scroll partial frames */
6438 char_ins_del_ok = 1;
6439 line_ins_del_ok = 1; /* we'll just blt 'em */
6440 fast_clear_end_of_line = 1; /* X does this well */
6441 memory_below_frame = 0; /* we don't remember what scrolls
6442 off the bottom */
6443 baud_rate = 19200; 6474 baud_rate = 19200;
6444 6475
6445 w32_system_caret_hwnd = NULL; 6476 w32_system_caret_hwnd = NULL;
diff --git a/src/w32term.h b/src/w32term.h
index b73dcfc9ee2..3e7f3a3a6a9 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -100,6 +100,9 @@ struct w32_display_info
100 /* Chain of all w32_display_info structures. */ 100 /* Chain of all w32_display_info structures. */
101 struct w32_display_info *next; 101 struct w32_display_info *next;
102 102
103 /* The generic display parameters corresponding to this w32 display. */
104 struct terminal *terminal;
105
103 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). 106 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
104 The same cons cell also appears in x_display_name_list. */ 107 The same cons cell also appears in x_display_name_list. */
105 Lisp_Object name_list_element; 108 Lisp_Object name_list_element;
@@ -272,8 +275,10 @@ extern void w32_find_ccl_program();
272 diffs between X and w32 code. */ 275 diffs between X and w32 code. */
273struct x_output 276struct x_output
274{ 277{
278#if 0 /* These are also defined in struct frame. Use that instead. */
275 PIX_TYPE background_pixel; 279 PIX_TYPE background_pixel;
276 PIX_TYPE foreground_pixel; 280 PIX_TYPE foreground_pixel;
281#endif
277 282
278 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this 283 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
279 frame, or IMPLICIT if we received an EnterNotify. 284 frame, or IMPLICIT if we received an EnterNotify.
@@ -405,8 +410,6 @@ extern struct w32_output w32term_display;
405#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc) 410#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
406#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc) 411#define FRAME_X_WINDOW(f) ((f)->output_data.w32->window_desc)
407 412
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) 413#define FRAME_FONT(f) ((f)->output_data.w32->font)
411#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset) 414#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
412#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset) 415#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset)
@@ -590,10 +593,10 @@ do { \
590} while (0) 593} while (0)
591 594
592#define w32_clear_rect(f,hdc,lprect) \ 595#define w32_clear_rect(f,hdc,lprect) \
593w32_fill_rect (f,hdc,f->output_data.x->background_pixel,lprect) 596 w32_fill_rect (f, hdc, FRAME_BACKGROUND_PIXEL (f), lprect)
594 597
595#define w32_clear_area(f,hdc,px,py,nx,ny) \ 598#define w32_clear_area(f,hdc,px,py,nx,ny) \
596w32_fill_area (f,hdc,f->output_data.x->background_pixel,px,py,nx,ny) 599 w32_fill_area (f, hdc, FRAME_BACKGROUND_PIXEL (f), px, py, nx, ny)
597 600
598extern struct font_info *w32_load_font (); 601extern struct font_info *w32_load_font ();
599extern void w32_unload_font (); 602extern void w32_unload_font ();
@@ -688,6 +691,9 @@ extern void wait_for_sync ();
688 691
689extern BOOL parse_button (); 692extern BOOL parse_button ();
690 693
694extern void w32_sys_ring_bell (struct frame *f);
695extern void x_delete_display (struct w32_display_info *dpyinfo);
696
691/* Keypad command key support. W32 doesn't have virtual keys defined 697/* Keypad command key support. W32 doesn't have virtual keys defined
692 for the function keys on the keypad (they are mapped to the standard 698 for the function keys on the keypad (they are mapped to the standard
693 fuction keys), so we define our own. */ 699 fuction keys), so we define our own. */
diff --git a/src/widget.c b/src/widget.c
index 714da205a67..c76cce9e328 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 6fe78166ba1..3db1802a861 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"
@@ -7269,7 +7271,7 @@ and scrolling positions. */)
7269void 7271void
7270init_window_once () 7272init_window_once ()
7271{ 7273{
7272 struct frame *f = make_terminal_frame (); 7274 struct frame *f = make_initial_frame ();
7273 XSETFRAME (selected_frame, f); 7275 XSETFRAME (selected_frame, f);
7274 Vterminal_frame = selected_frame; 7276 Vterminal_frame = selected_frame;
7275 minibuf_window = f->minibuffer_window; 7277 minibuf_window = f->minibuffer_window;
diff --git a/src/window.h b/src/window.h
index ea8965392c4..c9ef865c4f0 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 d22c9a53bc3..d16e13ef722 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
@@ -7528,8 +7515,8 @@ message2_nolog (m, nbytes, multibyte)
7528 do_pending_window_change (0); 7515 do_pending_window_change (0);
7529 echo_area_display (1); 7516 echo_area_display (1);
7530 do_pending_window_change (0); 7517 do_pending_window_change (0);
7531 if (frame_up_to_date_hook != 0 && ! gc_in_progress) 7518 if (FRAME_TERMINAL (f)->frame_up_to_date_hook != 0 && ! gc_in_progress)
7532 (*frame_up_to_date_hook) (f); 7519 (*FRAME_TERMINAL (f)->frame_up_to_date_hook) (f);
7533 } 7520 }
7534} 7521}
7535 7522
@@ -7632,8 +7619,8 @@ message3_nolog (m, nbytes, multibyte)
7632 do_pending_window_change (0); 7619 do_pending_window_change (0);
7633 echo_area_display (1); 7620 echo_area_display (1);
7634 do_pending_window_change (0); 7621 do_pending_window_change (0);
7635 if (frame_up_to_date_hook != 0 && ! gc_in_progress) 7622 if (FRAME_TERMINAL (f)->frame_up_to_date_hook != 0 && ! gc_in_progress)
7636 (*frame_up_to_date_hook) (f); 7623 (*FRAME_TERMINAL (f)->frame_up_to_date_hook) (f);
7637 } 7624 }
7638} 7625}
7639 7626
@@ -7871,6 +7858,10 @@ ensure_echo_area_buffers ()
7871 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a 7858 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7872 suitable buffer from echo_buffer[] and clear it. 7859 suitable buffer from echo_buffer[] and clear it.
7873 7860
7861 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7862 that the current message becomes the last displayed one, make
7863 choose a suitable buffer for echo_area_buffer[0], and clear it.
7864
7874 Value is what FN returns. */ 7865 Value is what FN returns. */
7875 7866
7876static int 7867static int
@@ -7895,6 +7886,17 @@ with_echo_area_buffer (w, which, fn, a1, a2, a3, a4)
7895 this_one = 0, the_other = 1; 7886 this_one = 0, the_other = 1;
7896 else if (which > 0) 7887 else if (which > 0)
7897 this_one = 1, the_other = 0; 7888 this_one = 1, the_other = 0;
7889 else
7890 {
7891 this_one = 0, the_other = 1;
7892 clear_buffer_p = 1;
7893
7894 /* We need a fresh one in case the current echo buffer equals
7895 the one containing the last displayed echo area message. */
7896 if (!NILP (echo_area_buffer[this_one])
7897 && EQ (echo_area_buffer[this_one], echo_area_buffer[the_other]))
7898 echo_area_buffer[this_one] = Qnil;
7899 }
7898 7900
7899 /* Choose a suitable buffer from echo_buffer[] is we don't 7901 /* Choose a suitable buffer from echo_buffer[] is we don't
7900 have one. */ 7902 have one. */
@@ -8532,7 +8534,7 @@ set_message (s, string, nbytes, multibyte_p)
8532 = ((s && multibyte_p) 8534 = ((s && multibyte_p)
8533 || (STRINGP (string) && STRING_MULTIBYTE (string))); 8535 || (STRINGP (string) && STRING_MULTIBYTE (string)));
8534 8536
8535 with_echo_area_buffer (0, 0, set_message_1, 8537 with_echo_area_buffer (0, -1, set_message_1,
8536 (EMACS_INT) s, string, nbytes, multibyte_p); 8538 (EMACS_INT) s, string, nbytes, multibyte_p);
8537 message_buf_print = 0; 8539 message_buf_print = 0;
8538 help_echo_showing_p = 0; 8540 help_echo_showing_p = 0;
@@ -8562,7 +8564,6 @@ set_message_1 (a1, a2, nbytes, multibyte_p)
8562 8564
8563 /* Insert new message at BEG. */ 8565 /* Insert new message at BEG. */
8564 TEMP_SET_PT_BOTH (BEG, BEG_BYTE); 8566 TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
8565 Ferase_buffer ();
8566 8567
8567 if (STRINGP (string)) 8568 if (STRINGP (string))
8568 { 8569 {
@@ -8658,11 +8659,11 @@ clear_garbaged_frames ()
8658 { 8659 {
8659 Lisp_Object tail, frame; 8660 Lisp_Object tail, frame;
8660 int changed_count = 0; 8661 int changed_count = 0;
8661 8662
8662 FOR_EACH_FRAME (tail, frame) 8663 FOR_EACH_FRAME (tail, frame)
8663 { 8664 {
8664 struct frame *f = XFRAME (frame); 8665 struct frame *f = XFRAME (frame);
8665 8666
8666 if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f)) 8667 if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f))
8667 { 8668 {
8668 if (f->resized_p) 8669 if (f->resized_p)
@@ -8676,7 +8677,7 @@ clear_garbaged_frames ()
8676 f->resized_p = 0; 8677 f->resized_p = 0;
8677 } 8678 }
8678 } 8679 }
8679 8680
8680 frame_garbaged = 0; 8681 frame_garbaged = 0;
8681 if (changed_count) 8682 if (changed_count)
8682 ++windows_or_buffers_changed; 8683 ++windows_or_buffers_changed;
@@ -8709,11 +8710,10 @@ echo_area_display (update_frame_p)
8709/* The terminal frame is used as the first Emacs frame on the Mac OS. */ 8710/* The terminal frame is used as the first Emacs frame on the Mac OS. */
8710#ifndef MAC_OS8 8711#ifndef MAC_OS8
8711#ifdef HAVE_WINDOW_SYSTEM 8712#ifdef HAVE_WINDOW_SYSTEM
8712 /* When Emacs starts, selected_frame may be a visible terminal 8713 /* When Emacs starts, selected_frame may be the initial terminal
8713 frame, even if we run under a window system. If we let this 8714 frame. If we let this through, a message would be displayed on
8714 through, a message would be displayed on the terminal. */ 8715 the terminal. */
8715 if (EQ (selected_frame, Vterminal_frame) 8716 if (FRAME_INITIAL_P (XFRAME (selected_frame)))
8716 && !NILP (Vwindow_system))
8717 return 0; 8717 return 0;
8718#endif /* HAVE_WINDOW_SYSTEM */ 8718#endif /* HAVE_WINDOW_SYSTEM */
8719#endif 8719#endif
@@ -8764,7 +8764,7 @@ echo_area_display (update_frame_p)
8764 Can do with a display update of the echo area, 8764 Can do with a display update of the echo area,
8765 unless we displayed some mode lines. */ 8765 unless we displayed some mode lines. */
8766 update_single_window (w, 1); 8766 update_single_window (w, 1);
8767 rif->flush_display (f); 8767 FRAME_RIF (f)->flush_display (f);
8768 } 8768 }
8769 else 8769 else
8770 update_frame (f, 1, 1); 8770 update_frame (f, 1, 1);
@@ -8779,8 +8779,10 @@ echo_area_display (update_frame_p)
8779 else if (!EQ (mini_window, selected_window)) 8779 else if (!EQ (mini_window, selected_window))
8780 windows_or_buffers_changed++; 8780 windows_or_buffers_changed++;
8781 8781
8782 /* The current message is now also the last one displayed. */ 8782 /* Last displayed message is now the current message. */
8783 echo_area_buffer[1] = echo_area_buffer[0]; 8783 echo_area_buffer[1] = echo_area_buffer[0];
8784 /* Inform read_char that we're not echoing. */
8785 echo_message_buffer = Qnil;
8784 8786
8785 /* Prevent redisplay optimization in redisplay_internal by resetting 8787 /* Prevent redisplay optimization in redisplay_internal by resetting
8786 this_line_start_pos. This is done because the mini-buffer now 8788 this_line_start_pos. This is done because the mini-buffer now
@@ -9334,8 +9336,8 @@ x_cursor_to (vpos, hpos, y, x)
9334 { 9336 {
9335 BLOCK_INPUT; 9337 BLOCK_INPUT;
9336 display_and_set_cursor (w, 1, hpos, vpos, x, y); 9338 display_and_set_cursor (w, 1, hpos, vpos, x, y);
9337 if (rif->flush_display_optional) 9339 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
9338 rif->flush_display_optional (SELECTED_FRAME ()); 9340 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9339 UNBLOCK_INPUT; 9341 UNBLOCK_INPUT;
9340 } 9342 }
9341} 9343}
@@ -10787,6 +10789,8 @@ select_frame_for_redisplay (frame)
10787 Lisp_Object tail, sym, val; 10789 Lisp_Object tail, sym, val;
10788 Lisp_Object old = selected_frame; 10790 Lisp_Object old = selected_frame;
10789 10791
10792 xassert (FRAMEP (frame) && FRAME_LIVE_P (XFRAME (frame)));
10793
10790 selected_frame = frame; 10794 selected_frame = frame;
10791 10795
10792 for (tail = XFRAME (frame)->param_alist; CONSP (tail); tail = XCDR (tail)) 10796 for (tail = XFRAME (frame)->param_alist; CONSP (tail); tail = XCDR (tail))
@@ -10924,17 +10928,16 @@ redisplay_internal (preserve_echo_area)
10924 if (face_change_count) 10928 if (face_change_count)
10925 ++windows_or_buffers_changed; 10929 ++windows_or_buffers_changed;
10926 10930
10927 if (! FRAME_WINDOW_P (sf) 10931 if (FRAME_TERMCAP_P (sf)
10928 && previous_terminal_frame != sf) 10932 && FRAME_TTY (sf)->previous_frame != sf)
10929 { 10933 {
10930 /* Since frames on an ASCII terminal share the same display 10934 /* Since frames on a single ASCII terminal share the same
10931 area, displaying a different frame means redisplay the whole 10935 display area, displaying a different frame means redisplay
10932 thing. */ 10936 the whole thing. */
10933 windows_or_buffers_changed++; 10937 windows_or_buffers_changed++;
10934 SET_FRAME_GARBAGED (sf); 10938 SET_FRAME_GARBAGED (sf);
10935 XSETFRAME (Vterminal_frame, sf); 10939 FRAME_TTY (sf)->previous_frame = sf;
10936 } 10940 }
10937 previous_terminal_frame = sf;
10938 10941
10939 /* Set the visible flags for all frames. Do this before checking 10942 /* Set the visible flags for all frames. Do this before checking
10940 for resized or garbaged frames; they want to know if their frames 10943 for resized or garbaged frames; they want to know if their frames
@@ -10956,6 +10959,7 @@ redisplay_internal (preserve_echo_area)
10956 } 10959 }
10957 } 10960 }
10958 10961
10962
10959 /* Notice any pending interrupt request to change frame size. */ 10963 /* Notice any pending interrupt request to change frame size. */
10960 do_pending_window_change (1); 10964 do_pending_window_change (1);
10961 10965
@@ -11317,7 +11321,7 @@ redisplay_internal (preserve_echo_area)
11317 { 11321 {
11318 struct frame *f = XFRAME (frame); 11322 struct frame *f = XFRAME (frame);
11319 11323
11320 if (FRAME_WINDOW_P (f) || f == sf) 11324 if (FRAME_WINDOW_P (f) || FRAME_TERMCAP_P (f) || f == sf)
11321 { 11325 {
11322 if (! EQ (frame, selected_frame)) 11326 if (! EQ (frame, selected_frame))
11323 /* Select the frame, for the sake of frame-local 11327 /* Select the frame, for the sake of frame-local
@@ -11326,16 +11330,16 @@ redisplay_internal (preserve_echo_area)
11326 11330
11327 /* Mark all the scroll bars to be removed; we'll redeem 11331 /* Mark all the scroll bars to be removed; we'll redeem
11328 the ones we want when we redisplay their windows. */ 11332 the ones we want when we redisplay their windows. */
11329 if (condemn_scroll_bars_hook) 11333 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
11330 condemn_scroll_bars_hook (f); 11334 FRAME_TERMINAL (f)->condemn_scroll_bars_hook (f);
11331 11335
11332 if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f)) 11336 if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f))
11333 redisplay_windows (FRAME_ROOT_WINDOW (f)); 11337 redisplay_windows (FRAME_ROOT_WINDOW (f));
11334 11338
11335 /* Any scroll bars which redisplay_windows should have 11339 /* Any scroll bars which redisplay_windows should have
11336 nuked should now go away. */ 11340 nuked should now go away. */
11337 if (judge_scroll_bars_hook) 11341 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
11338 judge_scroll_bars_hook (f); 11342 FRAME_TERMINAL (f)->judge_scroll_bars_hook (f);
11339 11343
11340 /* If fonts changed, display again. */ 11344 /* If fonts changed, display again. */
11341 /* ??? rms: I suspect it is a mistake to jump all the way 11345 /* ??? rms: I suspect it is a mistake to jump all the way
@@ -11382,12 +11386,12 @@ redisplay_internal (preserve_echo_area)
11382 FOR_EACH_FRAME (tail, frame) 11386 FOR_EACH_FRAME (tail, frame)
11383 { 11387 {
11384 struct frame *f = XFRAME (frame); 11388 struct frame *f = XFRAME (frame);
11385 if (f->updated_p) 11389 if (f->updated_p)
11386 { 11390 {
11387 mark_window_display_accurate (f->root_window, 1); 11391 mark_window_display_accurate (f->root_window, 1);
11388 if (frame_up_to_date_hook) 11392 if (FRAME_TERMINAL (f)->frame_up_to_date_hook)
11389 frame_up_to_date_hook (f); 11393 FRAME_TERMINAL (f)->frame_up_to_date_hook (f);
11390 } 11394 }
11391 } 11395 }
11392 } 11396 }
11393 } 11397 }
@@ -11472,8 +11476,8 @@ redisplay_internal (preserve_echo_area)
11472 /* Say overlay arrows are up to date. */ 11476 /* Say overlay arrows are up to date. */
11473 update_overlay_arrows (1); 11477 update_overlay_arrows (1);
11474 11478
11475 if (frame_up_to_date_hook != 0) 11479 if (FRAME_TERMINAL (sf)->frame_up_to_date_hook != 0)
11476 frame_up_to_date_hook (sf); 11480 FRAME_TERMINAL (sf)->frame_up_to_date_hook (sf);
11477 } 11481 }
11478 11482
11479 update_mode_lines = 0; 11483 update_mode_lines = 0;
@@ -11583,8 +11587,9 @@ redisplay_preserve_echo_area (from_where)
11583 else 11587 else
11584 redisplay_internal (1); 11588 redisplay_internal (1);
11585 11589
11586 if (rif != NULL && rif->flush_display_optional) 11590 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11587 rif->flush_display_optional (NULL); 11591 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
11592 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL);
11588} 11593}
11589 11594
11590 11595
@@ -11592,7 +11597,8 @@ redisplay_preserve_echo_area (from_where)
11592 redisplay_internal. Reset redisplaying_p to the value it had 11597 redisplay_internal. Reset redisplaying_p to the value it had
11593 before redisplay_internal was called, and clear 11598 before redisplay_internal was called, and clear
11594 prevent_freeing_realized_faces_p. It also selects the previously 11599 prevent_freeing_realized_faces_p. It also selects the previously
11595 selected frame. */ 11600 selected frame, unless it has been deleted (by an X connection
11601 failure during redisplay, for example). */
11596 11602
11597static Lisp_Object 11603static Lisp_Object
11598unwind_redisplay (val) 11604unwind_redisplay (val)
@@ -11603,7 +11609,8 @@ unwind_redisplay (val)
11603 old_redisplaying_p = XCAR (val); 11609 old_redisplaying_p = XCAR (val);
11604 redisplaying_p = XFASTINT (old_redisplaying_p); 11610 redisplaying_p = XFASTINT (old_redisplaying_p);
11605 old_frame = XCDR (val); 11611 old_frame = XCDR (val);
11606 if (! EQ (old_frame, selected_frame)) 11612 if (! EQ (old_frame, selected_frame)
11613 && FRAME_LIVE_P (XFRAME (old_frame)))
11607 select_frame_for_redisplay (old_frame); 11614 select_frame_for_redisplay (old_frame);
11608 return Qnil; 11615 return Qnil;
11609} 11616}
@@ -12752,7 +12759,9 @@ set_vertical_scroll_bar (w)
12752 start = end = whole = 0; 12759 start = end = whole = 0;
12753 12760
12754 /* Indicate what this scroll bar ought to be displaying now. */ 12761 /* Indicate what this scroll bar ought to be displaying now. */
12755 set_vertical_scroll_bar_hook (w, end - start, whole, start); 12762 if (FRAME_TERMINAL (XFRAME (w->frame))->set_vertical_scroll_bar_hook)
12763 (*FRAME_TERMINAL (XFRAME (w->frame))->set_vertical_scroll_bar_hook)
12764 (w, end - start, whole, start);
12756} 12765}
12757 12766
12758 12767
@@ -13471,20 +13480,22 @@ redisplay_window (window, just_this_one_p)
13471 display_menu_bar (w); 13480 display_menu_bar (w);
13472 13481
13473#ifdef HAVE_WINDOW_SYSTEM 13482#ifdef HAVE_WINDOW_SYSTEM
13483 if (FRAME_WINDOW_P (f))
13484 {
13474#if defined (USE_GTK) || USE_MAC_TOOLBAR 13485#if defined (USE_GTK) || USE_MAC_TOOLBAR
13475 redisplay_tool_bar_p = FRAME_EXTERNAL_TOOL_BAR (f); 13486 redisplay_tool_bar_p = FRAME_EXTERNAL_TOOL_BAR (f);
13476#else 13487#else
13477 redisplay_tool_bar_p = WINDOWP (f->tool_bar_window) 13488 redisplay_tool_bar_p = WINDOWP (f->tool_bar_window)
13478 && (FRAME_TOOL_BAR_LINES (f) > 0 13489 && (FRAME_TOOL_BAR_LINES (f) > 0
13479 || !NILP (Vauto_resize_tool_bars)); 13490 || !NILP (Vauto_resize_tool_bars));
13480
13481#endif 13491#endif
13482 13492
13483 if (redisplay_tool_bar_p && redisplay_tool_bar (f)) 13493 if (redisplay_tool_bar_p && redisplay_tool_bar (f))
13484 { 13494 {
13485 extern int ignore_mouse_drag_p; 13495 extern int ignore_mouse_drag_p;
13486 ignore_mouse_drag_p = 1; 13496 ignore_mouse_drag_p = 1;
13487 } 13497 }
13498 }
13488#endif 13499#endif
13489 } 13500 }
13490 13501
@@ -13518,7 +13529,8 @@ redisplay_window (window, just_this_one_p)
13518 13529
13519 /* Note that we actually used the scroll bar attached to this 13530 /* Note that we actually used the scroll bar attached to this
13520 window, so it shouldn't be deleted at the end of redisplay. */ 13531 window, so it shouldn't be deleted at the end of redisplay. */
13521 redeem_scroll_bar_hook (w); 13532 if (FRAME_TERMINAL (f)->redeem_scroll_bar_hook)
13533 (*FRAME_TERMINAL (f)->redeem_scroll_bar_hook) (w);
13522 } 13534 }
13523 13535
13524 /* Restore current_buffer and value of point in it. */ 13536 /* Restore current_buffer and value of point in it. */
@@ -13787,10 +13799,10 @@ try_window_reusing_current_matrix (w)
13787 if (run.height > 0 && run.current_y != run.desired_y) 13799 if (run.height > 0 && run.current_y != run.desired_y)
13788 { 13800 {
13789 update_begin (f); 13801 update_begin (f);
13790 rif->update_window_begin_hook (w); 13802 FRAME_RIF (f)->update_window_begin_hook (w);
13791 rif->clear_window_mouse_face (w); 13803 FRAME_RIF (f)->clear_window_mouse_face (w);
13792 rif->scroll_run_hook (w, &run); 13804 FRAME_RIF (f)->scroll_run_hook (w, &run);
13793 rif->update_window_end_hook (w, 0, 0); 13805 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
13794 update_end (f); 13806 update_end (f);
13795 } 13807 }
13796 13808
@@ -13959,10 +13971,10 @@ try_window_reusing_current_matrix (w)
13959 if (run.height) 13971 if (run.height)
13960 { 13972 {
13961 update_begin (f); 13973 update_begin (f);
13962 rif->update_window_begin_hook (w); 13974 FRAME_RIF (f)->update_window_begin_hook (w);
13963 rif->clear_window_mouse_face (w); 13975 FRAME_RIF (f)->clear_window_mouse_face (w);
13964 rif->scroll_run_hook (w, &run); 13976 FRAME_RIF (f)->scroll_run_hook (w, &run);
13965 rif->update_window_end_hook (w, 0, 0); 13977 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
13966 update_end (f); 13978 update_end (f);
13967 } 13979 }
13968 13980
@@ -14412,7 +14424,7 @@ try_window_id (w)
14412 14424
14413 /* Window must either use window-based redisplay or be full width. */ 14425 /* Window must either use window-based redisplay or be full width. */
14414 if (!FRAME_WINDOW_P (f) 14426 if (!FRAME_WINDOW_P (f)
14415 && (!line_ins_del_ok 14427 && (!FRAME_LINE_INS_DEL_OK (f)
14416 || !WINDOW_FULL_WIDTH_P (w))) 14428 || !WINDOW_FULL_WIDTH_P (w)))
14417 GIVE_UP (4); 14429 GIVE_UP (4);
14418 14430
@@ -14821,10 +14833,10 @@ try_window_id (w)
14821 14833
14822 if (FRAME_WINDOW_P (f)) 14834 if (FRAME_WINDOW_P (f))
14823 { 14835 {
14824 rif->update_window_begin_hook (w); 14836 FRAME_RIF (f)->update_window_begin_hook (w);
14825 rif->clear_window_mouse_face (w); 14837 FRAME_RIF (f)->clear_window_mouse_face (w);
14826 rif->scroll_run_hook (w, &run); 14838 FRAME_RIF (f)->scroll_run_hook (w, &run);
14827 rif->update_window_end_hook (w, 0, 0); 14839 FRAME_RIF (f)->update_window_end_hook (w, 0, 0);
14828 } 14840 }
14829 else 14841 else
14830 { 14842 {
@@ -14842,36 +14854,36 @@ try_window_id (w)
14842 { 14854 {
14843 /* Scroll last_unchanged_at_beg_row to the end of the 14855 /* Scroll last_unchanged_at_beg_row to the end of the
14844 window down dvpos lines. */ 14856 window down dvpos lines. */
14845 set_terminal_window (end); 14857 set_terminal_window (f, end);
14846 14858
14847 /* On dumb terminals delete dvpos lines at the end 14859 /* On dumb terminals delete dvpos lines at the end
14848 before inserting dvpos empty lines. */ 14860 before inserting dvpos empty lines. */
14849 if (!scroll_region_ok) 14861 if (!FRAME_SCROLL_REGION_OK (f))
14850 ins_del_lines (end - dvpos, -dvpos); 14862 ins_del_lines (f, end - dvpos, -dvpos);
14851 14863
14852 /* Insert dvpos empty lines in front of 14864 /* Insert dvpos empty lines in front of
14853 last_unchanged_at_beg_row. */ 14865 last_unchanged_at_beg_row. */
14854 ins_del_lines (from, dvpos); 14866 ins_del_lines (f, from, dvpos);
14855 } 14867 }
14856 else if (dvpos < 0) 14868 else if (dvpos < 0)
14857 { 14869 {
14858 /* Scroll up last_unchanged_at_beg_vpos to the end of 14870 /* Scroll up last_unchanged_at_beg_vpos to the end of
14859 the window to last_unchanged_at_beg_vpos - |dvpos|. */ 14871 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14860 set_terminal_window (end); 14872 set_terminal_window (f, end);
14861 14873
14862 /* Delete dvpos lines in front of 14874 /* Delete dvpos lines in front of
14863 last_unchanged_at_beg_vpos. ins_del_lines will set 14875 last_unchanged_at_beg_vpos. ins_del_lines will set
14864 the cursor to the given vpos and emit |dvpos| delete 14876 the cursor to the given vpos and emit |dvpos| delete
14865 line sequences. */ 14877 line sequences. */
14866 ins_del_lines (from + dvpos, dvpos); 14878 ins_del_lines (f, from + dvpos, dvpos);
14867 14879
14868 /* On a dumb terminal insert dvpos empty lines at the 14880 /* On a dumb terminal insert dvpos empty lines at the
14869 end. */ 14881 end. */
14870 if (!scroll_region_ok) 14882 if (!FRAME_SCROLL_REGION_OK (f))
14871 ins_del_lines (end + dvpos, -dvpos); 14883 ins_del_lines (f, end + dvpos, -dvpos);
14872 } 14884 }
14873 14885
14874 set_terminal_window (0); 14886 set_terminal_window (f, 0);
14875 } 14887 }
14876 14888
14877 update_end (f); 14889 update_end (f);
@@ -16445,7 +16457,7 @@ display_menu_bar (w)
16445 16457
16446 /* Don't do all this for graphical frames. */ 16458 /* Don't do all this for graphical frames. */
16447#ifdef HAVE_NTGUI 16459#ifdef HAVE_NTGUI
16448 if (!NILP (Vwindow_system)) 16460 if (FRAME_W32_P (f))
16449 return; 16461 return;
16450#endif 16462#endif
16451#if defined (USE_X_TOOLKIT) || defined (USE_GTK) 16463#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
@@ -16676,10 +16688,10 @@ display_mode_line (w, face_id, format)
16676 /* Temporarily make frame's keyboard the current kboard so that 16688 /* Temporarily make frame's keyboard the current kboard so that
16677 kboard-local variables in the mode_line_format will get the right 16689 kboard-local variables in the mode_line_format will get the right
16678 values. */ 16690 values. */
16679 push_frame_kboard (it.f); 16691 push_kboard (FRAME_KBOARD (it.f));
16680 record_unwind_save_match_data (); 16692 record_unwind_save_match_data ();
16681 display_mode_element (&it, 0, 0, 0, format, Qnil, 0); 16693 display_mode_element (&it, 0, 0, 0, format, Qnil, 0);
16682 pop_frame_kboard (); 16694 pop_kboard ();
16683 16695
16684 unbind_to (count, Qnil); 16696 unbind_to (count, Qnil);
16685 16697
@@ -17394,9 +17406,9 @@ are the selected window and the window's buffer). */)
17394 = (NILP (face) ? Qnil : Fcons (Qface, Fcons (face, Qnil))); 17406 = (NILP (face) ? Qnil : Fcons (Qface, Fcons (face, Qnil)));
17395 } 17407 }
17396 17408
17397 push_frame_kboard (it.f); 17409 push_kboard (FRAME_KBOARD (it.f));
17398 display_mode_element (&it, 0, 0, 0, format, Qnil, 0); 17410 display_mode_element (&it, 0, 0, 0, format, Qnil, 0);
17399 pop_frame_kboard (); 17411 pop_kboard ();
17400 17412
17401 if (no_props) 17413 if (no_props)
17402 { 17414 {
@@ -18030,8 +18042,8 @@ decode_mode_spec (w, c, field_width, precision, multibyte)
18030 { 18042 {
18031 /* No need to mention EOL here--the terminal never needs 18043 /* No need to mention EOL here--the terminal never needs
18032 to do EOL conversion. */ 18044 to do EOL conversion. */
18033 p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0); 18045 p = decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f)->symbol, p, 0);
18034 p = decode_mode_spec_coding (terminal_coding.symbol, p, 0); 18046 p = decode_mode_spec_coding (FRAME_TERMINAL_CODING (f)->symbol, p, 0);
18035 } 18047 }
18036 p = decode_mode_spec_coding (b->buffer_file_coding_system, 18048 p = decode_mode_spec_coding (b->buffer_file_coding_system,
18037 p, eol_flag); 18049 p, eol_flag);
@@ -18544,6 +18556,8 @@ calc_pixel_width_or_height (res, it, prop, font, width_p, align_to)
18544 if (NILP (prop)) 18556 if (NILP (prop))
18545 return OK_PIXELS (0); 18557 return OK_PIXELS (0);
18546 18558
18559 xassert (FRAME_LIVE_P (it->f));
18560
18547 if (SYMBOLP (prop)) 18561 if (SYMBOLP (prop))
18548 { 18562 {
18549 if (SCHARS (SYMBOL_NAME (prop)) == 2) 18563 if (SCHARS (SYMBOL_NAME (prop)) == 2)
@@ -18660,7 +18674,8 @@ calc_pixel_width_or_height (res, it, prop, font, width_p, align_to)
18660 if (SYMBOLP (car)) 18674 if (SYMBOLP (car))
18661 { 18675 {
18662#ifdef HAVE_WINDOW_SYSTEM 18676#ifdef HAVE_WINDOW_SYSTEM
18663 if (valid_image_p (prop)) 18677 if (FRAME_WINDOW_P (it->f)
18678 && valid_image_p (prop))
18664 { 18679 {
18665 int id = lookup_image (it->f, prop); 18680 int id = lookup_image (it->f, prop);
18666 struct image *img = IMAGE_FROM_ID (it->f, id); 18681 struct image *img = IMAGE_FROM_ID (it->f, id);
@@ -18901,7 +18916,7 @@ get_glyph_face_and_encoding (f, glyph, char2b, two_byte_p)
18901 = FONT_INFO_FROM_ID (f, face->font_info_id); 18916 = FONT_INFO_FROM_ID (f, face->font_info_id);
18902 if (font_info) 18917 if (font_info)
18903 glyph->font_type 18918 glyph->font_type
18904 = rif->encode_char (glyph->u.ch, char2b, font_info, two_byte_p); 18919 = FRAME_RIF (f)->encode_char (glyph->u.ch, char2b, font_info, two_byte_p);
18905 } 18920 }
18906 } 18921 }
18907 18922
@@ -19134,7 +19149,7 @@ x_get_glyph_overhangs (glyph, f, left, right)
19134 font = face->font; 19149 font = face->font;
19135 font_info = FONT_INFO_FROM_ID (f, face->font_info_id); 19150 font_info = FONT_INFO_FROM_ID (f, face->font_info_id);
19136 if (font /* ++KFS: Should this be font_info ? */ 19151 if (font /* ++KFS: Should this be font_info ? */
19137 && (pcm = rif->per_char_metric (font, &char2b, glyph->font_type))) 19152 && (pcm = FRAME_RIF (f)->per_char_metric (font, &char2b, glyph->font_type)))
19138 { 19153 {
19139 if (pcm->rbearing > pcm->width) 19154 if (pcm->rbearing > pcm->width)
19140 *right = pcm->rbearing - pcm->width; 19155 *right = pcm->rbearing - pcm->width;
@@ -19302,7 +19317,7 @@ get_char_face_and_encoding (f, c, face_id, char2b, multibyte_p, display_p)
19302 struct font_info *font_info 19317 struct font_info *font_info
19303 = FONT_INFO_FROM_ID (f, face->font_info_id); 19318 = FONT_INFO_FROM_ID (f, face->font_info_id);
19304 if (font_info) 19319 if (font_info)
19305 rif->encode_char (c, char2b, font_info, 0); 19320 FRAME_RIF (f)->encode_char (c, char2b, font_info, 0);
19306 } 19321 }
19307 } 19322 }
19308 19323
@@ -19365,8 +19380,8 @@ compute_overhangs_and_x (s, x, backward_p)
19365 { 19380 {
19366 while (s) 19381 while (s)
19367 { 19382 {
19368 if (rif->compute_glyph_string_overhangs) 19383 if (FRAME_RIF (s->f)->compute_glyph_string_overhangs)
19369 rif->compute_glyph_string_overhangs (s); 19384 FRAME_RIF (s->f)->compute_glyph_string_overhangs (s);
19370 x -= s->width; 19385 x -= s->width;
19371 s->x = x; 19386 s->x = x;
19372 s = s->prev; 19387 s = s->prev;
@@ -19376,8 +19391,8 @@ compute_overhangs_and_x (s, x, backward_p)
19376 { 19391 {
19377 while (s) 19392 while (s)
19378 { 19393 {
19379 if (rif->compute_glyph_string_overhangs) 19394 if (FRAME_RIF (s->f)->compute_glyph_string_overhangs)
19380 rif->compute_glyph_string_overhangs (s); 19395 FRAME_RIF (s->f)->compute_glyph_string_overhangs (s);
19381 s->x = x; 19396 s->x = x;
19382 x += s->width; 19397 x += s->width;
19383 s = s->next; 19398 s = s->next;
@@ -19665,9 +19680,9 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps)
19665 struct glyph_string *h, *t; 19680 struct glyph_string *h, *t;
19666 19681
19667 /* Compute overhangs for all glyph strings. */ 19682 /* Compute overhangs for all glyph strings. */
19668 if (rif->compute_glyph_string_overhangs) 19683 if (FRAME_RIF (f)->compute_glyph_string_overhangs)
19669 for (s = head; s; s = s->next) 19684 for (s = head; s; s = s->next)
19670 rif->compute_glyph_string_overhangs (s); 19685 FRAME_RIF (f)->compute_glyph_string_overhangs (s);
19671 19686
19672 /* Prepend glyph strings for glyphs in front of the first glyph 19687 /* Prepend glyph strings for glyphs in front of the first glyph
19673 string that are overwritten because of the first glyph 19688 string that are overwritten because of the first glyph
@@ -19745,7 +19760,7 @@ draw_glyphs (w, x, row, area, start, end, hl, overlaps)
19745 19760
19746 /* Draw all strings. */ 19761 /* Draw all strings. */
19747 for (s = head; s; s = s->next) 19762 for (s = head; s; s = s->next)
19748 rif->draw_glyph_string (s); 19763 FRAME_RIF (f)->draw_glyph_string (s);
19749 19764
19750 if (area == TEXT_AREA 19765 if (area == TEXT_AREA
19751 && !row->full_width_p 19766 && !row->full_width_p
@@ -20440,20 +20455,20 @@ x_produce_glyphs (it)
20440 20455
20441 it->nglyphs = 1; 20456 it->nglyphs = 1;
20442 20457
20443 pcm = rif->per_char_metric (font, &char2b, 20458 pcm = FRAME_RIF (it->f)->per_char_metric
20444 FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display)); 20459 (font, &char2b, FONT_TYPE_FOR_UNIBYTE (font, it->char_to_display));
20445 20460
20446 if (it->override_ascent >= 0) 20461 if (it->override_ascent >= 0)
20447 { 20462 {
20448 it->ascent = it->override_ascent; 20463 it->ascent = it->override_ascent;
20449 it->descent = it->override_descent; 20464 it->descent = it->override_descent;
20450 boff = it->override_boff; 20465 boff = it->override_boff;
20451 } 20466 }
20452 else 20467 else
20453 { 20468 {
20454 it->ascent = FONT_BASE (font) + boff; 20469 it->ascent = FONT_BASE (font) + boff;
20455 it->descent = FONT_DESCENT (font) - boff; 20470 it->descent = FONT_DESCENT (font) - boff;
20456 } 20471 }
20457 20472
20458 if (pcm) 20473 if (pcm)
20459 { 20474 {
@@ -20671,8 +20686,8 @@ x_produce_glyphs (it)
20671 from the charset width; this is what old redisplay code 20686 from the charset width; this is what old redisplay code
20672 did. */ 20687 did. */
20673 20688
20674 pcm = rif->per_char_metric (font, &char2b, 20689 pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20675 FONT_TYPE_FOR_MULTIBYTE (font, it->c)); 20690 FONT_TYPE_FOR_MULTIBYTE (font, it->c));
20676 20691
20677 if (font_not_found_p || !pcm) 20692 if (font_not_found_p || !pcm)
20678 { 20693 {
@@ -20803,8 +20818,8 @@ x_produce_glyphs (it)
20803 20818
20804 /* Initialize the bounding box. */ 20819 /* Initialize the bounding box. */
20805 if (font_info 20820 if (font_info
20806 && (pcm = rif->per_char_metric (font, &char2b, 20821 && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20807 FONT_TYPE_FOR_MULTIBYTE (font, it->c)))) 20822 FONT_TYPE_FOR_MULTIBYTE (font, it->c))))
20808 { 20823 {
20809 width = pcm->width; 20824 width = pcm->width;
20810 ascent = pcm->ascent; 20825 ascent = pcm->ascent;
@@ -20862,8 +20877,8 @@ x_produce_glyphs (it)
20862 } 20877 }
20863 20878
20864 if (font_info 20879 if (font_info
20865 && (pcm = rif->per_char_metric (font, &char2b, 20880 && (pcm = FRAME_RIF (it->f)->per_char_metric (font, &char2b,
20866 FONT_TYPE_FOR_MULTIBYTE (font, ch)))) 20881 FONT_TYPE_FOR_MULTIBYTE (font, ch))))
20867 { 20882 {
20868 width = pcm->width; 20883 width = pcm->width;
20869 ascent = pcm->ascent; 20884 ascent = pcm->ascent;
@@ -21103,8 +21118,8 @@ x_insert_glyphs (start, len)
21103 frame_x = window_box_left (w, updated_area) + output_cursor.x; 21118 frame_x = window_box_left (w, updated_area) + output_cursor.x;
21104 frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y); 21119 frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, output_cursor.y);
21105 21120
21106 rif->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width, 21121 FRAME_RIF (f)->shift_glyphs_for_insert (f, frame_x, frame_y, shifted_region_width,
21107 line_height, shift_by_width); 21122 line_height, shift_by_width);
21108 21123
21109 /* Write the glyphs. */ 21124 /* Write the glyphs. */
21110 hpos = start - row->glyphs[updated_area]; 21125 hpos = start - row->glyphs[updated_area];
@@ -21186,8 +21201,8 @@ x_clear_end_of_line (to_x)
21186 if (to_x > from_x && to_y > from_y) 21201 if (to_x > from_x && to_y > from_y)
21187 { 21202 {
21188 BLOCK_INPUT; 21203 BLOCK_INPUT;
21189 rif->clear_frame_area (f, from_x, from_y, 21204 FRAME_RIF (f)->clear_frame_area (f, from_x, from_y,
21190 to_x - from_x, to_y - from_y); 21205 to_x - from_x, to_y - from_y);
21191 UNBLOCK_INPUT; 21206 UNBLOCK_INPUT;
21192 } 21207 }
21193} 21208}
@@ -21700,7 +21715,7 @@ erase_phys_cursor (w)
21700 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, max (x, left_x)); 21715 x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, max (x, left_x));
21701 21716
21702 if (width > 0) 21717 if (width > 0)
21703 rif->clear_frame_area (f, x, y, width, cursor_row->visible_height); 21718 FRAME_RIF (f)->clear_frame_area (f, x, y, width, cursor_row->visible_height);
21704 } 21719 }
21705 21720
21706 /* Erase the cursor by redrawing the character underneath it. */ 21721 /* Erase the cursor by redrawing the character underneath it. */
@@ -21797,9 +21812,9 @@ display_and_set_cursor (w, on, hpos, vpos, x, y)
21797 w->phys_cursor.vpos = vpos; 21812 w->phys_cursor.vpos = vpos;
21798 } 21813 }
21799 21814
21800 rif->draw_window_cursor (w, glyph_row, x, y, 21815 FRAME_RIF (f)->draw_window_cursor (w, glyph_row, x, y,
21801 new_cursor_type, new_cursor_width, 21816 new_cursor_type, new_cursor_width,
21802 on, active_cursor); 21817 on, active_cursor);
21803} 21818}
21804 21819
21805 21820
@@ -21948,11 +21963,11 @@ show_mouse_face (dpyinfo, draw)
21948 21963
21949 /* Change the mouse cursor. */ 21964 /* Change the mouse cursor. */
21950 if (draw == DRAW_NORMAL_TEXT && !EQ (dpyinfo->mouse_face_window, f->tool_bar_window)) 21965 if (draw == DRAW_NORMAL_TEXT && !EQ (dpyinfo->mouse_face_window, f->tool_bar_window))
21951 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor); 21966 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor);
21952 else if (draw == DRAW_MOUSE_FACE) 21967 else if (draw == DRAW_MOUSE_FACE)
21953 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor); 21968 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor);
21954 else 21969 else
21955 rif->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor); 21970 FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor);
21956} 21971}
21957 21972
21958/* EXPORT: 21973/* EXPORT:
@@ -22391,7 +22406,6 @@ on_hot_spot_p (hot_spot, x, y)
22391 return inside; 22406 return inside;
22392 } 22407 }
22393 } 22408 }
22394 /* If we don't understand the format, pretend we're not in the hot-spot. */
22395 return 0; 22409 return 0;
22396} 22410}
22397 22411
@@ -22471,7 +22485,7 @@ define_frame_cursor1 (f, cursor, pointer)
22471 } 22485 }
22472 22486
22473 if (cursor != No_Cursor) 22487 if (cursor != No_Cursor)
22474 rif->define_frame_cursor (f, cursor); 22488 FRAME_RIF (f)->define_frame_cursor (f, cursor);
22475} 22489}
22476 22490
22477/* Take proper action when mouse has moved to the mode or header line 22491/* Take proper action when mouse has moved to the mode or header line
@@ -23439,8 +23453,8 @@ phys_cursor_in_rect_p (w, r)
23439 I assume the effect is the same -- and this is portable. */ 23453 I assume the effect is the same -- and this is portable. */
23440 return x_intersect_rectangles (&cr, r, &result); 23454 return x_intersect_rectangles (&cr, r, &result);
23441 } 23455 }
23442 else 23456 /* If we don't understand the format, pretend we're not in the hot-spot. */
23443 return 0; 23457 return 0;
23444} 23458}
23445 23459
23446 23460
@@ -23452,6 +23466,8 @@ void
23452x_draw_vertical_border (w) 23466x_draw_vertical_border (w)
23453 struct window *w; 23467 struct window *w;
23454{ 23468{
23469 struct frame *f = XFRAME (WINDOW_FRAME (w));
23470
23455 /* We could do better, if we knew what type of scroll-bar the adjacent 23471 /* We could do better, if we knew what type of scroll-bar the adjacent
23456 windows (on either side) have... But we don't :-( 23472 windows (on either side) have... But we don't :-(
23457 However, I think this works ok. ++KFS 2003-04-25 */ 23473 However, I think this works ok. ++KFS 2003-04-25 */
@@ -23472,9 +23488,9 @@ x_draw_vertical_border (w)
23472 y1 -= 1; 23488 y1 -= 1;
23473 23489
23474 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0) 23490 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
23475 x1 -= 1; 23491 x1 -= 1;
23476 23492
23477 rif->draw_vertical_window_border (w, x1, y0, y1); 23493 FRAME_RIF (f)->draw_vertical_window_border (w, x1, y0, y1);
23478 } 23494 }
23479 else if (!WINDOW_LEFTMOST_P (w) 23495 else if (!WINDOW_LEFTMOST_P (w)
23480 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 23496 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
@@ -23485,9 +23501,9 @@ x_draw_vertical_border (w)
23485 y1 -= 1; 23501 y1 -= 1;
23486 23502
23487 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0) 23503 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
23488 x0 -= 1; 23504 x0 -= 1;
23489 23505
23490 rif->draw_vertical_window_border (w, x0, y0, y1); 23506 FRAME_RIF (f)->draw_vertical_window_border (w, x0, y0, y1);
23491 } 23507 }
23492} 23508}
23493 23509
diff --git a/src/xfaces.c b/src/xfaces.c
index ffaf2afda21..734e2eb3827 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,
@@ -6147,7 +6164,7 @@ tty_supports_face_attributes_p (f, attrs, def_face)
6147 /* See if the capabilities we selected above are supported, with the 6164 /* See if the capabilities we selected above are supported, with the
6148 given colors. */ 6165 given colors. */
6149 if (test_caps != 0 && 6166 if (test_caps != 0 &&
6150 ! tty_capable_p (f, test_caps, fg_tty_color.pixel, bg_tty_color.pixel)) 6167 ! tty_capable_p (FRAME_TTY (f), test_caps, fg_tty_color.pixel, bg_tty_color.pixel))
6151 return 0; 6168 return 0;
6152 6169
6153 6170
@@ -6951,7 +6968,8 @@ realize_basic_faces (f)
6951 { 6968 {
6952 FRAME_FACE_CACHE (f)->menu_face_changed_p = 0; 6969 FRAME_FACE_CACHE (f)->menu_face_changed_p = 0;
6953#ifdef USE_X_TOOLKIT 6970#ifdef USE_X_TOOLKIT
6954 x_update_menu_appearance (f); 6971 if (FRAME_WINDOW_P (f))
6972 x_update_menu_appearance (f);
6955#endif 6973#endif
6956 } 6974 }
6957 6975
@@ -7038,7 +7056,7 @@ realize_default_face (f)
7038 LFACE_FOREGROUND (lface) = XCDR (color); 7056 LFACE_FOREGROUND (lface) = XCDR (color);
7039 else if (FRAME_WINDOW_P (f)) 7057 else if (FRAME_WINDOW_P (f))
7040 return 0; 7058 return 0;
7041 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) 7059 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
7042 LFACE_FOREGROUND (lface) = build_string (unspecified_fg); 7060 LFACE_FOREGROUND (lface) = build_string (unspecified_fg);
7043 else 7061 else
7044 abort (); 7062 abort ();
@@ -7053,7 +7071,7 @@ realize_default_face (f)
7053 LFACE_BACKGROUND (lface) = XCDR (color); 7071 LFACE_BACKGROUND (lface) = XCDR (color);
7054 else if (FRAME_WINDOW_P (f)) 7072 else if (FRAME_WINDOW_P (f))
7055 return 0; 7073 return 0;
7056 else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) 7074 else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
7057 LFACE_BACKGROUND (lface) = build_string (unspecified_bg); 7075 LFACE_BACKGROUND (lface) = build_string (unspecified_bg);
7058 else 7076 else
7059 abort (); 7077 abort ();
@@ -7070,17 +7088,17 @@ realize_default_face (f)
7070 7088
7071#ifdef HAVE_WINDOW_SYSTEM 7089#ifdef HAVE_WINDOW_SYSTEM
7072#ifdef HAVE_X_WINDOWS 7090#ifdef HAVE_X_WINDOWS
7073 if (face->font != FRAME_FONT (f)) 7091 if (FRAME_X_P (f) && face->font != FRAME_FONT (f))
7074 { 7092 {
7075 /* This can happen when making a frame on a display that does 7093 /* This can happen when making a frame on a display that does
7076 not support the default font. */ 7094 not support the default font. */
7077 if (!face->font) 7095 if (!face->font)
7078 return 0; 7096 return 0;
7079 7097
7080 /* Otherwise, the font specified for the frame was not 7098 /* Otherwise, the font specified for the frame was not
7081 acceptable as a font for the default face (perhaps because 7099 acceptable as a font for the default face (perhaps because
7082 auto-scaled fonts are rejected), so we must adjust the frame 7100 auto-scaled fonts are rejected), so we must adjust the frame
7083 font. */ 7101 font. */
7084 x_set_font (f, build_string (face->font_name), Qnil); 7102 x_set_font (f, build_string (face->font_name), Qnil);
7085 } 7103 }
7086#endif /* HAVE_X_WINDOWS */ 7104#endif /* HAVE_X_WINDOWS */
@@ -7160,6 +7178,11 @@ realize_face (cache, attrs, c, base_face, former_face_id)
7160 face = realize_x_face (cache, attrs, c, base_face); 7178 face = realize_x_face (cache, attrs, c, base_face);
7161 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) 7179 else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
7162 face = realize_tty_face (cache, attrs, c); 7180 face = realize_tty_face (cache, attrs, c);
7181 else if (FRAME_INITIAL_P (cache->f))
7182 {
7183 /* Create a dummy face. */
7184 face = make_realized_face (attrs);
7185 }
7163 else 7186 else
7164 abort (); 7187 abort ();
7165 7188
diff --git a/src/xfns.c b/src/xfns.c
index 0c06abb44d4..e49f8cb3112 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
@@ -255,17 +256,18 @@ check_x_frame (frame)
255 return f; 256 return f;
256} 257}
257 258
258/* Let the user specify an X display with a frame. 259/* Let the user specify an X display with a Lisp object.
260 OBJECT may be nil, a frame or a terminal id.
259 nil stands for the selected frame--or, if that is not an X frame, 261 nil stands for the selected frame--or, if that is not an X frame,
260 the first X display on the list. */ 262 the first X display on the list. */
261 263
262struct x_display_info * 264struct x_display_info *
263check_x_display_info (frame) 265check_x_display_info (object)
264 Lisp_Object frame; 266 Lisp_Object object;
265{ 267{
266 struct x_display_info *dpyinfo = NULL; 268 struct x_display_info *dpyinfo = NULL;
267 269
268 if (NILP (frame)) 270 if (NILP (object))
269 { 271 {
270 struct frame *sf = XFRAME (selected_frame); 272 struct frame *sf = XFRAME (selected_frame);
271 273
@@ -276,11 +278,20 @@ check_x_display_info (frame)
276 else 278 else
277 error ("X windows are not in use or not initialized"); 279 error ("X windows are not in use or not initialized");
278 } 280 }
279 else if (STRINGP (frame)) 281 else if (INTEGERP (object))
280 dpyinfo = x_display_info_for_name (frame); 282 {
283 struct terminal *t = get_terminal (XINT (object), 1);
284
285 if (t->type != output_x_window)
286 error ("Terminal %d is not an X display", XINT (object));
287
288 dpyinfo = t->display_info.x;
289 }
290 else if (STRINGP (object))
291 dpyinfo = x_display_info_for_name (object);
281 else 292 else
282 { 293 {
283 FRAME_PTR f = check_x_frame (frame); 294 FRAME_PTR f = check_x_frame (object);
284 dpyinfo = FRAME_X_DISPLAY_INFO (f); 295 dpyinfo = FRAME_X_DISPLAY_INFO (f);
285 } 296 }
286 297
@@ -861,8 +872,8 @@ x_set_foreground_color (f, arg, oldval)
861 unsigned long fg, old_fg; 872 unsigned long fg, old_fg;
862 873
863 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 874 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
864 old_fg = x->foreground_pixel; 875 old_fg = FRAME_FOREGROUND_PIXEL (f);
865 x->foreground_pixel = fg; 876 FRAME_FOREGROUND_PIXEL (f) = fg;
866 877
867 if (FRAME_X_WINDOW (f) != 0) 878 if (FRAME_X_WINDOW (f) != 0)
868 { 879 {
@@ -899,8 +910,8 @@ x_set_background_color (f, arg, oldval)
899 unsigned long bg; 910 unsigned long bg;
900 911
901 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); 912 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
902 unload_color (f, x->background_pixel); 913 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
903 x->background_pixel = bg; 914 FRAME_BACKGROUND_PIXEL (f) = bg;
904 915
905 if (FRAME_X_WINDOW (f) != 0) 916 if (FRAME_X_WINDOW (f) != 0)
906 { 917 {
@@ -948,13 +959,13 @@ x_set_mouse_color (f, arg, oldval)
948 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; 959 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
949 Cursor hourglass_cursor, horizontal_drag_cursor; 960 Cursor hourglass_cursor, horizontal_drag_cursor;
950 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 961 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
951 unsigned long mask_color = x->background_pixel; 962 unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
952 963
953 /* Don't let pointers be invisible. */ 964 /* Don't let pointers be invisible. */
954 if (mask_color == pixel) 965 if (mask_color == pixel)
955 { 966 {
956 x_free_colors (f, &pixel, 1); 967 x_free_colors (f, &pixel, 1);
957 pixel = x_copy_color (f, x->foreground_pixel); 968 pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f));
958 } 969 }
959 970
960 unload_color (f, x->mouse_pixel); 971 unload_color (f, x->mouse_pixel);
@@ -1097,13 +1108,13 @@ x_set_cursor_color (f, arg, oldval)
1097 fore_pixel_allocated_p = 1; 1108 fore_pixel_allocated_p = 1;
1098 } 1109 }
1099 else 1110 else
1100 fore_pixel = x->background_pixel; 1111 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1101 1112
1102 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); 1113 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1103 pixel_allocated_p = 1; 1114 pixel_allocated_p = 1;
1104 1115
1105 /* Make sure that the cursor color differs from the background color. */ 1116 /* Make sure that the cursor color differs from the background color. */
1106 if (pixel == x->background_pixel) 1117 if (pixel == FRAME_BACKGROUND_PIXEL (f))
1107 { 1118 {
1108 if (pixel_allocated_p) 1119 if (pixel_allocated_p)
1109 { 1120 {
@@ -1119,7 +1130,7 @@ x_set_cursor_color (f, arg, oldval)
1119 x_free_colors (f, &fore_pixel, 1); 1130 x_free_colors (f, &fore_pixel, 1);
1120 fore_pixel_allocated_p = 0; 1131 fore_pixel_allocated_p = 0;
1121 } 1132 }
1122 fore_pixel = x->background_pixel; 1133 fore_pixel = FRAME_BACKGROUND_PIXEL (f);
1123 } 1134 }
1124 } 1135 }
1125 1136
@@ -1404,10 +1415,8 @@ x_set_tool_bar_lines (f, value, oldval)
1404 below the menu bar. */ 1415 below the menu bar. */
1405 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) 1416 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1406 { 1417 {
1407 updating_frame = f; 1418 clear_frame (f);
1408 clear_frame ();
1409 clear_current_matrices (f); 1419 clear_current_matrices (f);
1410 updating_frame = NULL;
1411 } 1420 }
1412 1421
1413 /* If the tool bar gets smaller, the internal border below it 1422 /* If the tool bar gets smaller, the internal border below it
@@ -1458,10 +1467,10 @@ x_set_scroll_bar_foreground (f, value, oldval)
1458 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) 1467 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1459 { 1468 {
1460 /* Remove all scroll bars because they have wrong colors. */ 1469 /* Remove all scroll bars because they have wrong colors. */
1461 if (condemn_scroll_bars_hook) 1470 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1462 (*condemn_scroll_bars_hook) (f); 1471 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1463 if (judge_scroll_bars_hook) 1472 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1464 (*judge_scroll_bars_hook) (f); 1473 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1465 1474
1466 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); 1475 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
1467 redraw_frame (f); 1476 redraw_frame (f);
@@ -1507,10 +1516,10 @@ x_set_scroll_bar_background (f, value, oldval)
1507 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) 1516 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1508 { 1517 {
1509 /* Remove all scroll bars because they have wrong colors. */ 1518 /* Remove all scroll bars because they have wrong colors. */
1510 if (condemn_scroll_bars_hook) 1519 if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook)
1511 (*condemn_scroll_bars_hook) (f); 1520 (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f);
1512 if (judge_scroll_bars_hook) 1521 if (FRAME_TERMINAL (f)->judge_scroll_bars_hook)
1513 (*judge_scroll_bars_hook) (f); 1522 (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f);
1514 1523
1515 update_face_from_frame_parameter (f, Qscroll_bar_background, value); 1524 update_face_from_frame_parameter (f, Qscroll_bar_background, value);
1516 redraw_frame (f); 1525 redraw_frame (f);
@@ -2738,7 +2747,7 @@ x_window (f)
2738 XSetWindowAttributes attributes; 2747 XSetWindowAttributes attributes;
2739 unsigned long attribute_mask; 2748 unsigned long attribute_mask;
2740 2749
2741 attributes.background_pixel = f->output_data.x->background_pixel; 2750 attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f);
2742 attributes.border_pixel = f->output_data.x->border_pixel; 2751 attributes.border_pixel = f->output_data.x->border_pixel;
2743 attributes.bit_gravity = StaticGravity; 2752 attributes.bit_gravity = StaticGravity;
2744 attributes.backing_store = NotUseful; 2753 attributes.backing_store = NotUseful;
@@ -2926,8 +2935,8 @@ x_make_gc (f)
2926 2935
2927 /* Normal video */ 2936 /* Normal video */
2928 gc_values.font = FRAME_FONT (f)->fid; 2937 gc_values.font = FRAME_FONT (f)->fid;
2929 gc_values.foreground = f->output_data.x->foreground_pixel; 2938 gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
2930 gc_values.background = f->output_data.x->background_pixel; 2939 gc_values.background = FRAME_BACKGROUND_PIXEL (f);
2931 gc_values.line_width = 0; /* Means 1 using fast algorithm. */ 2940 gc_values.line_width = 0; /* Means 1 using fast algorithm. */
2932 f->output_data.x->normal_gc 2941 f->output_data.x->normal_gc
2933 = XCreateGC (FRAME_X_DISPLAY (f), 2942 = XCreateGC (FRAME_X_DISPLAY (f),
@@ -2936,8 +2945,8 @@ x_make_gc (f)
2936 &gc_values); 2945 &gc_values);
2937 2946
2938 /* Reverse video style. */ 2947 /* Reverse video style. */
2939 gc_values.foreground = f->output_data.x->background_pixel; 2948 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2940 gc_values.background = f->output_data.x->foreground_pixel; 2949 gc_values.background = FRAME_FOREGROUND_PIXEL (f);
2941 f->output_data.x->reverse_gc 2950 f->output_data.x->reverse_gc
2942 = XCreateGC (FRAME_X_DISPLAY (f), 2951 = XCreateGC (FRAME_X_DISPLAY (f),
2943 FRAME_X_WINDOW (f), 2952 FRAME_X_WINDOW (f),
@@ -2945,7 +2954,7 @@ x_make_gc (f)
2945 &gc_values); 2954 &gc_values);
2946 2955
2947 /* Cursor has cursor-color background, background-color foreground. */ 2956 /* Cursor has cursor-color background, background-color foreground. */
2948 gc_values.foreground = f->output_data.x->background_pixel; 2957 gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
2949 gc_values.background = f->output_data.x->cursor_pixel; 2958 gc_values.background = f->output_data.x->cursor_pixel;
2950 gc_values.fill_style = FillOpaqueStippled; 2959 gc_values.fill_style = FillOpaqueStippled;
2951 gc_values.stipple 2960 gc_values.stipple
@@ -2969,8 +2978,8 @@ x_make_gc (f)
2969 = (XCreatePixmapFromBitmapData 2978 = (XCreatePixmapFromBitmapData
2970 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window, 2979 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2971 gray_bits, gray_width, gray_height, 2980 gray_bits, gray_width, gray_height,
2972 f->output_data.x->foreground_pixel, 2981 FRAME_FOREGROUND_PIXEL (f),
2973 f->output_data.x->background_pixel, 2982 FRAME_BACKGROUND_PIXEL (f),
2974 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); 2983 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2975 2984
2976 UNBLOCK_INPUT; 2985 UNBLOCK_INPUT;
@@ -3025,6 +3034,12 @@ unwind_create_frame (frame)
3025{ 3034{
3026 struct frame *f = XFRAME (frame); 3035 struct frame *f = XFRAME (frame);
3027 3036
3037 /* If frame is already dead, nothing to do. This can happen if the
3038 display is disconnected after the frame has become official, but
3039 before x_create_frame removes the unwind protect. */
3040 if (!FRAME_LIVE_P (f))
3041 return Qnil;
3042
3028 /* If frame is ``official'', nothing to do. */ 3043 /* If frame is ``official'', nothing to do. */
3029 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame)) 3044 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
3030 { 3045 {
@@ -3073,24 +3088,27 @@ This function is an internal primitive--use `make-frame' instead. */)
3073 Lisp_Object parent; 3088 Lisp_Object parent;
3074 struct kboard *kb; 3089 struct kboard *kb;
3075 3090
3076 check_x ();
3077
3078 parms = Fcopy_alist (parms); 3091 parms = Fcopy_alist (parms);
3079 3092
3080 /* Use this general default value to start with 3093 /* Use this general default value to start with
3081 until we know if this frame has a specified name. */ 3094 until we know if this frame has a specified name. */
3082 Vx_resource_name = Vinvocation_name; 3095 Vx_resource_name = Vinvocation_name;
3083 3096
3084 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); 3097 display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
3098 if (EQ (display, Qunbound))
3099 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
3085 if (EQ (display, Qunbound)) 3100 if (EQ (display, Qunbound))
3086 display = Qnil; 3101 display = Qnil;
3087 dpyinfo = check_x_display_info (display); 3102 dpyinfo = check_x_display_info (display);
3088#ifdef MULTI_KBOARD 3103#ifdef MULTI_KBOARD
3089 kb = dpyinfo->kboard; 3104 kb = dpyinfo->terminal->kboard;
3090#else 3105#else
3091 kb = &the_only_kboard; 3106 kb = &the_only_kboard;
3092#endif 3107#endif
3093 3108
3109 if (dpyinfo->terminal->deleted)
3110 error ("Terminal is being deleted, can't create new frames on it");
3111
3094 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); 3112 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
3095 if (!STRINGP (name) 3113 if (!STRINGP (name)
3096 && ! EQ (name, Qunbound) 3114 && ! EQ (name, Qunbound)
@@ -3131,6 +3149,9 @@ This function is an internal primitive--use `make-frame' instead. */)
3131 /* Note that X Windows does support scroll bars. */ 3149 /* Note that X Windows does support scroll bars. */
3132 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1; 3150 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
3133 3151
3152 f->terminal = dpyinfo->terminal;
3153 f->terminal->reference_count++;
3154
3134 f->output_method = output_x_window; 3155 f->output_method = output_x_window;
3135 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output)); 3156 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
3136 bzero (f->output_data.x, sizeof (struct x_output)); 3157 bzero (f->output_data.x, sizeof (struct x_output));
@@ -3157,9 +3178,6 @@ This function is an internal primitive--use `make-frame' instead. */)
3157 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; 3178 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
3158 dpyinfo_refcount = dpyinfo->reference_count; 3179 dpyinfo_refcount = dpyinfo->reference_count;
3159#endif /* GLYPH_DEBUG */ 3180#endif /* GLYPH_DEBUG */
3160#ifdef MULTI_KBOARD
3161 FRAME_KBOARD (f) = kb;
3162#endif
3163 3181
3164 /* These colors will be set anyway later, but it's important 3182 /* These colors will be set anyway later, but it's important
3165 to get the color reference counts right, so initialize them! */ 3183 to get the color reference counts right, so initialize them! */
@@ -3170,8 +3188,8 @@ This function is an internal primitive--use `make-frame' instead. */)
3170 /* Function x_decode_color can signal an error. Make 3188 /* Function x_decode_color can signal an error. Make
3171 sure to initialize color slots so that we won't try 3189 sure to initialize color slots so that we won't try
3172 to free colors we haven't allocated. */ 3190 to free colors we haven't allocated. */
3173 f->output_data.x->foreground_pixel = -1; 3191 FRAME_FOREGROUND_PIXEL (f) = -1;
3174 f->output_data.x->background_pixel = -1; 3192 FRAME_BACKGROUND_PIXEL (f) = -1;
3175 f->output_data.x->cursor_pixel = -1; 3193 f->output_data.x->cursor_pixel = -1;
3176 f->output_data.x->cursor_foreground_pixel = -1; 3194 f->output_data.x->cursor_foreground_pixel = -1;
3177 f->output_data.x->border_pixel = -1; 3195 f->output_data.x->border_pixel = -1;
@@ -3179,9 +3197,9 @@ This function is an internal primitive--use `make-frame' instead. */)
3179 3197
3180 black = build_string ("black"); 3198 black = build_string ("black");
3181 GCPRO1 (black); 3199 GCPRO1 (black);
3182 f->output_data.x->foreground_pixel 3200 FRAME_FOREGROUND_PIXEL (f)
3183 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3201 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3184 f->output_data.x->background_pixel 3202 FRAME_BACKGROUND_PIXEL (f)
3185 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3203 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3186 f->output_data.x->cursor_pixel 3204 f->output_data.x->cursor_pixel
3187 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 3205 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
@@ -3448,7 +3466,7 @@ This function is an internal primitive--use `make-frame' instead. */)
3448 } 3466 }
3449 3467
3450 /* Initialize `default-minibuffer-frame' in case this is the first 3468 /* Initialize `default-minibuffer-frame' in case this is the first
3451 frame on this display device. */ 3469 frame on this terminal. */
3452 if (FRAME_HAS_MINIBUF_P (f) 3470 if (FRAME_HAS_MINIBUF_P (f)
3453 && (!FRAMEP (kb->Vdefault_minibuffer_frame) 3471 && (!FRAMEP (kb->Vdefault_minibuffer_frame)
3454 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))) 3472 || !FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame))))
@@ -3460,6 +3478,8 @@ This function is an internal primitive--use `make-frame' instead. */)
3460 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) 3478 if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
3461 f->param_alist = Fcons (XCAR (tem), f->param_alist); 3479 f->param_alist = Fcons (XCAR (tem), f->param_alist);
3462 3480
3481 store_frame_param (f, Qwindow_system, Qx);
3482
3463 UNGCPRO; 3483 UNGCPRO;
3464 3484
3465 /* Make sure windows on this frame appear in calls to next-window 3485 /* Make sure windows on this frame appear in calls to next-window
@@ -3554,10 +3574,10 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3554 3574
3555DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, 3575DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
3556 doc: /* Internal function called by `display-color-p', which see. */) 3576 doc: /* Internal function called by `display-color-p', which see. */)
3557 (display) 3577 (terminal)
3558 Lisp_Object display; 3578 Lisp_Object terminal;
3559{ 3579{
3560 struct x_display_info *dpyinfo = check_x_display_info (display); 3580 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3561 3581
3562 if (dpyinfo->n_planes <= 2) 3582 if (dpyinfo->n_planes <= 2)
3563 return Qnil; 3583 return Qnil;
@@ -3579,13 +3599,13 @@ DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
3579 0, 1, 0, 3599 0, 1, 0,
3580 doc: /* Return t if the X display supports shades of gray. 3600 doc: /* Return t if the X display supports shades of gray.
3581Note that color displays do support shades of gray. 3601Note that color displays do support shades of gray.
3582The optional argument DISPLAY specifies which display to ask about. 3602The optional argument TERMINAL specifies which display to ask about.
3583DISPLAY should be either a frame or a display name (a string). 3603TERMINAL should be a terminal id, a frame or a display name (a string).
3584If omitted or nil, that stands for the selected frame's display. */) 3604If omitted or nil, that stands for the selected frame's display. */)
3585 (display) 3605 (terminal)
3586 Lisp_Object display; 3606 Lisp_Object terminal;
3587{ 3607{
3588 struct x_display_info *dpyinfo = check_x_display_info (display); 3608 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3589 3609
3590 if (dpyinfo->n_planes <= 1) 3610 if (dpyinfo->n_planes <= 1)
3591 return Qnil; 3611 return Qnil;
@@ -3607,56 +3627,56 @@ If omitted or nil, that stands for the selected frame's display. */)
3607 3627
3608DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, 3628DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
3609 0, 1, 0, 3629 0, 1, 0,
3610 doc: /* Returns the width in pixels of the X display DISPLAY. 3630 doc: /* Returns the width in pixels of the X display TERMINAL.
3611The optional argument DISPLAY specifies which display to ask about. 3631The optional argument TERMINAL specifies which display to ask about.
3612DISPLAY should be either a frame or a display name (a string). 3632TERMINAL should be a terminal id, a frame or a display name (a string).
3613If omitted or nil, that stands for the selected frame's display. */) 3633If omitted or nil, that stands for the selected frame's display. */)
3614 (display) 3634 (terminal)
3615 Lisp_Object display; 3635 Lisp_Object terminal;
3616{ 3636{
3617 struct x_display_info *dpyinfo = check_x_display_info (display); 3637 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3618 3638
3619 return make_number (dpyinfo->width); 3639 return make_number (dpyinfo->width);
3620} 3640}
3621 3641
3622DEFUN ("x-display-pixel-height", Fx_display_pixel_height, 3642DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
3623 Sx_display_pixel_height, 0, 1, 0, 3643 Sx_display_pixel_height, 0, 1, 0,
3624 doc: /* Returns the height in pixels of the X display DISPLAY. 3644 doc: /* Returns the height in pixels of the X display TERMINAL.
3625The optional argument DISPLAY specifies which display to ask about. 3645The optional argument TERMINAL specifies which display to ask about.
3626DISPLAY should be either a frame or a display name (a string). 3646TERMINAL should be a terminal id, a frame or a display name (a string).
3627If omitted or nil, that stands for the selected frame's display. */) 3647If omitted or nil, that stands for the selected frame's display. */)
3628 (display) 3648 (terminal)
3629 Lisp_Object display; 3649 Lisp_Object terminal;
3630{ 3650{
3631 struct x_display_info *dpyinfo = check_x_display_info (display); 3651 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3632 3652
3633 return make_number (dpyinfo->height); 3653 return make_number (dpyinfo->height);
3634} 3654}
3635 3655
3636DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, 3656DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
3637 0, 1, 0, 3657 0, 1, 0,
3638 doc: /* Returns the number of bitplanes of the X display DISPLAY. 3658 doc: /* Returns the number of bitplanes of the X display TERMINAL.
3639The optional argument DISPLAY specifies which display to ask about. 3659The optional argument TERMINAL specifies which display to ask about.
3640DISPLAY should be either a frame or a display name (a string). 3660TERMINAL should be a terminal id, a frame or a display name (a string).
3641If omitted or nil, that stands for the selected frame's display. */) 3661If omitted or nil, that stands for the selected frame's display. */)
3642 (display) 3662 (terminal)
3643 Lisp_Object display; 3663 Lisp_Object terminal;
3644{ 3664{
3645 struct x_display_info *dpyinfo = check_x_display_info (display); 3665 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3646 3666
3647 return make_number (dpyinfo->n_planes); 3667 return make_number (dpyinfo->n_planes);
3648} 3668}
3649 3669
3650DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, 3670DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
3651 0, 1, 0, 3671 0, 1, 0,
3652 doc: /* Returns the number of color cells of the X display DISPLAY. 3672 doc: /* Returns the number of color cells of the X display TERMINAL.
3653The optional argument DISPLAY specifies which display to ask about. 3673The optional argument TERMINAL specifies which display to ask about.
3654DISPLAY should be either a frame or a display name (a string). 3674TERMINAL should be a terminal id, a frame or a display name (a string).
3655If omitted or nil, that stands for the selected frame's display. */) 3675If omitted or nil, that stands for the selected frame's display. */)
3656 (display) 3676 (terminal)
3657 Lisp_Object display; 3677 Lisp_Object terminal;
3658{ 3678{
3659 struct x_display_info *dpyinfo = check_x_display_info (display); 3679 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3660 3680
3661 int nr_planes = DisplayPlanes (dpyinfo->display, 3681 int nr_planes = DisplayPlanes (dpyinfo->display,
3662 XScreenNumberOfScreen (dpyinfo->screen)); 3682 XScreenNumberOfScreen (dpyinfo->screen));
@@ -3674,29 +3694,29 @@ If omitted or nil, that stands for the selected frame's display. */)
3674DEFUN ("x-server-max-request-size", Fx_server_max_request_size, 3694DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
3675 Sx_server_max_request_size, 3695 Sx_server_max_request_size,
3676 0, 1, 0, 3696 0, 1, 0,
3677 doc: /* Returns the maximum request size of the X server of display DISPLAY. 3697 doc: /* Returns the maximum request size of the X server of display TERMINAL.
3678The optional argument DISPLAY specifies which display to ask about. 3698The optional argument TERMINAL specifies which display to ask about.
3679DISPLAY should be either a frame or a display name (a string). 3699TERMINAL should be a terminal id, a frame or a display name (a string).
3680If omitted or nil, that stands for the selected frame's display. */) 3700If omitted or nil, that stands for the selected frame's display. */)
3681 (display) 3701 (terminal)
3682 Lisp_Object display; 3702 Lisp_Object terminal;
3683{ 3703{
3684 struct x_display_info *dpyinfo = check_x_display_info (display); 3704 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3685 3705
3686 return make_number (MAXREQUEST (dpyinfo->display)); 3706 return make_number (MAXREQUEST (dpyinfo->display));
3687} 3707}
3688 3708
3689DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, 3709DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
3690 doc: /* Returns the "vendor ID" string of the X server of display DISPLAY. 3710 doc: /* Returns the "vendor ID" string of the X server of display TERMINAL.
3691\(Labelling every distributor as a "vendor" embodies the false assumption 3711\(Labelling every distributor as a "vendor" embodies the false assumption
3692that operating systems cannot be developed and distributed noncommercially.) 3712that operating systems cannot be developed and distributed noncommercially.)
3693The optional argument DISPLAY specifies which display to ask about. 3713The optional argument TERMINAL specifies which display to ask about.
3694DISPLAY should be either a frame or a display name (a string). 3714TERMINAL should be a terminal id, a frame or a display name (a string).
3695If omitted or nil, that stands for the selected frame's display. */) 3715If omitted or nil, that stands for the selected frame's display. */)
3696 (display) 3716 (terminal)
3697 Lisp_Object display; 3717 Lisp_Object terminal;
3698{ 3718{
3699 struct x_display_info *dpyinfo = check_x_display_info (display); 3719 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3700 char *vendor = ServerVendor (dpyinfo->display); 3720 char *vendor = ServerVendor (dpyinfo->display);
3701 3721
3702 if (! vendor) vendor = ""; 3722 if (! vendor) vendor = "";
@@ -3704,18 +3724,18 @@ If omitted or nil, that stands for the selected frame's display. */)
3704} 3724}
3705 3725
3706DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, 3726DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
3707 doc: /* Returns the version numbers of the X server of display DISPLAY. 3727 doc: /* Returns the version numbers of the X server of display TERMINAL.
3708The value is a list of three integers: the major and minor 3728The value is a list of three integers: the major and minor
3709version numbers of the X Protocol in use, and the distributor-specific release 3729version numbers of the X Protocol in use, and the distributor-specific release
3710number. See also the function `x-server-vendor'. 3730number. See also the function `x-server-vendor'.
3711 3731
3712The optional argument DISPLAY specifies which display to ask about. 3732The optional argument TERMINAL specifies which display to ask about.
3713DISPLAY should be either a frame or a display name (a string). 3733TERMINAL should be a terminal id, a frame or a display name (a string).
3714If omitted or nil, that stands for the selected frame's display. */) 3734If omitted or nil, that stands for the selected frame's display. */)
3715 (display) 3735 (terminal)
3716 Lisp_Object display; 3736 Lisp_Object terminal;
3717{ 3737{
3718 struct x_display_info *dpyinfo = check_x_display_info (display); 3738 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3719 Display *dpy = dpyinfo->display; 3739 Display *dpy = dpyinfo->display;
3720 3740
3721 return Fcons (make_number (ProtocolVersion (dpy)), 3741 return Fcons (make_number (ProtocolVersion (dpy)),
@@ -3724,55 +3744,55 @@ If omitted or nil, that stands for the selected frame's display. */)
3724} 3744}
3725 3745
3726DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, 3746DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3727 doc: /* Return the number of screens on the X server of display DISPLAY. 3747 doc: /* Return the number of screens on the X server of display TERMINAL.
3728The optional argument DISPLAY specifies which display to ask about. 3748The optional argument TERMINAL specifies which display to ask about.
3729DISPLAY should be either a frame or a display name (a string). 3749TERMINAL should be a terminal id, a frame or a display name (a string).
3730If omitted or nil, that stands for the selected frame's display. */) 3750If omitted or nil, that stands for the selected frame's display. */)
3731 (display) 3751 (terminal)
3732 Lisp_Object display; 3752 Lisp_Object terminal;
3733{ 3753{
3734 struct x_display_info *dpyinfo = check_x_display_info (display); 3754 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3735 3755
3736 return make_number (ScreenCount (dpyinfo->display)); 3756 return make_number (ScreenCount (dpyinfo->display));
3737} 3757}
3738 3758
3739DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, 3759DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3740 doc: /* Return the height in millimeters of the X display DISPLAY. 3760 doc: /* Return the height in millimeters of the X display TERMINAL.
3741The optional argument DISPLAY specifies which display to ask about. 3761The optional argument TERMINAL specifies which display to ask about.
3742DISPLAY should be either a frame or a display name (a string). 3762TERMINAL should be a terminal id, a frame or a display name (a string).
3743If omitted or nil, that stands for the selected frame's display. */) 3763If omitted or nil, that stands for the selected frame's display. */)
3744 (display) 3764 (terminal)
3745 Lisp_Object display; 3765 Lisp_Object terminal;
3746{ 3766{
3747 struct x_display_info *dpyinfo = check_x_display_info (display); 3767 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3748 3768
3749 return make_number (HeightMMOfScreen (dpyinfo->screen)); 3769 return make_number (HeightMMOfScreen (dpyinfo->screen));
3750} 3770}
3751 3771
3752DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, 3772DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3753 doc: /* Return the width in millimeters of the X display DISPLAY. 3773 doc: /* Return the width in millimeters of the X display TERMINAL.
3754The optional argument DISPLAY specifies which display to ask about. 3774The optional argument TERMINAL specifies which display to ask about.
3755DISPLAY should be either a frame or a display name (a string). 3775TERMINAL should be a terminal id, a frame or a display name (a string).
3756If omitted or nil, that stands for the selected frame's display. */) 3776If omitted or nil, that stands for the selected frame's display. */)
3757 (display) 3777 (terminal)
3758 Lisp_Object display; 3778 Lisp_Object terminal;
3759{ 3779{
3760 struct x_display_info *dpyinfo = check_x_display_info (display); 3780 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3761 3781
3762 return make_number (WidthMMOfScreen (dpyinfo->screen)); 3782 return make_number (WidthMMOfScreen (dpyinfo->screen));
3763} 3783}
3764 3784
3765DEFUN ("x-display-backing-store", Fx_display_backing_store, 3785DEFUN ("x-display-backing-store", Fx_display_backing_store,
3766 Sx_display_backing_store, 0, 1, 0, 3786 Sx_display_backing_store, 0, 1, 0,
3767 doc: /* Returns an indication of whether X display DISPLAY does backing store. 3787 doc: /* Returns an indication of whether X display TERMINAL does backing store.
3768The value may be `always', `when-mapped', or `not-useful'. 3788The value may be `always', `when-mapped', or `not-useful'.
3769The optional argument DISPLAY specifies which display to ask about. 3789The optional argument TERMINAL specifies which display to ask about.
3770DISPLAY should be either a frame or a display name (a string). 3790TERMINAL should be a terminal id, a frame or a display name (a string).
3771If omitted or nil, that stands for the selected frame's display. */) 3791If omitted or nil, that stands for the selected frame's display. */)
3772 (display) 3792 (terminal)
3773 Lisp_Object display; 3793 Lisp_Object terminal;
3774{ 3794{
3775 struct x_display_info *dpyinfo = check_x_display_info (display); 3795 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3776 Lisp_Object result; 3796 Lisp_Object result;
3777 3797
3778 switch (DoesBackingStore (dpyinfo->screen)) 3798 switch (DoesBackingStore (dpyinfo->screen))
@@ -3799,17 +3819,17 @@ If omitted or nil, that stands for the selected frame's display. */)
3799 3819
3800DEFUN ("x-display-visual-class", Fx_display_visual_class, 3820DEFUN ("x-display-visual-class", Fx_display_visual_class,
3801 Sx_display_visual_class, 0, 1, 0, 3821 Sx_display_visual_class, 0, 1, 0,
3802 doc: /* Return the visual class of the X display DISPLAY. 3822 doc: /* Return the visual class of the X display TERMINAL.
3803The value is one of the symbols `static-gray', `gray-scale', 3823The value is one of the symbols `static-gray', `gray-scale',
3804`static-color', `pseudo-color', `true-color', or `direct-color'. 3824`static-color', `pseudo-color', `true-color', or `direct-color'.
3805 3825
3806The optional argument DISPLAY specifies which display to ask about. 3826The optional argument TERMINAL specifies which display to ask about.
3807DISPLAY should be either a frame or a display name (a string). 3827TERMINAL should a terminal id, a frame or a display name (a string).
3808If omitted or nil, that stands for the selected frame's display. */) 3828If omitted or nil, that stands for the selected frame's display. */)
3809 (display) 3829 (terminal)
3810 Lisp_Object display; 3830 Lisp_Object terminal;
3811{ 3831{
3812 struct x_display_info *dpyinfo = check_x_display_info (display); 3832 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3813 Lisp_Object result; 3833 Lisp_Object result;
3814 3834
3815 switch (dpyinfo->visual->class) 3835 switch (dpyinfo->visual->class)
@@ -3842,14 +3862,14 @@ If omitted or nil, that stands for the selected frame's display. */)
3842 3862
3843DEFUN ("x-display-save-under", Fx_display_save_under, 3863DEFUN ("x-display-save-under", Fx_display_save_under,
3844 Sx_display_save_under, 0, 1, 0, 3864 Sx_display_save_under, 0, 1, 0,
3845 doc: /* Returns t if the X display DISPLAY supports the save-under feature. 3865 doc: /* Returns t if the X display TERMINAL supports the save-under feature.
3846The optional argument DISPLAY specifies which display to ask about. 3866The optional argument TERMINAL specifies which display to ask about.
3847DISPLAY should be either a frame or a display name (a string). 3867TERMINAL should be a terminal id, a frame or a display name (a string).
3848If omitted or nil, that stands for the selected frame's display. */) 3868If omitted or nil, that stands for the selected frame's display. */)
3849 (display) 3869 (terminal)
3850 Lisp_Object display; 3870 Lisp_Object terminal;
3851{ 3871{
3852 struct x_display_info *dpyinfo = check_x_display_info (display); 3872 struct x_display_info *dpyinfo = check_x_display_info (terminal);
3853 3873
3854 if (DoesSaveUnders (dpyinfo->screen) == True) 3874 if (DoesSaveUnders (dpyinfo->screen) == True)
3855 return Qt; 3875 return Qt;
@@ -4030,8 +4050,10 @@ x_display_info_for_name (name)
4030 4050
4031 CHECK_STRING (name); 4051 CHECK_STRING (name);
4032 4052
4033 if (! EQ (Vwindow_system, intern ("x"))) 4053#if 0
4034 error ("Not using X Windows"); 4054 if (! EQ (Vinitial_window_system, intern ("x")))
4055 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4056#endif
4035 4057
4036 for (dpyinfo = x_display_list, names = x_display_name_list; 4058 for (dpyinfo = x_display_list, names = x_display_name_list;
4037 dpyinfo; 4059 dpyinfo;
@@ -4078,8 +4100,10 @@ terminate Emacs if we can't open the connection. */)
4078 if (! NILP (xrm_string)) 4100 if (! NILP (xrm_string))
4079 CHECK_STRING (xrm_string); 4101 CHECK_STRING (xrm_string);
4080 4102
4081 if (! EQ (Vwindow_system, intern ("x"))) 4103#if 0
4082 error ("Not using X Windows"); 4104 if (! EQ (Vinitial_window_system, intern ("x")))
4105 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4106#endif
4083 4107
4084 if (! NILP (xrm_string)) 4108 if (! NILP (xrm_string))
4085 xrm_option = (unsigned char *) SDATA (xrm_string); 4109 xrm_option = (unsigned char *) SDATA (xrm_string);
@@ -4114,41 +4138,19 @@ An insecure way to solve the problem may be to use `xhost'.\n",
4114 4138
4115DEFUN ("x-close-connection", Fx_close_connection, 4139DEFUN ("x-close-connection", Fx_close_connection,
4116 Sx_close_connection, 1, 1, 0, 4140 Sx_close_connection, 1, 1, 0,
4117 doc: /* Close the connection to DISPLAY's X server. 4141 doc: /* Close the connection to TERMINAL's X server.
4118For DISPLAY, specify either a frame or a display name (a string). 4142For TERMINAL, specify a terminal id, a frame or a display name (a
4119If DISPLAY is nil, that stands for the selected frame's display. */) 4143string). If TERMINAL is nil, that stands for the selected frame's
4120 (display) 4144terminal. */)
4121 Lisp_Object display; 4145 (terminal)
4146 Lisp_Object terminal;
4122{ 4147{
4123 struct x_display_info *dpyinfo = check_x_display_info (display); 4148 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4124 int i;
4125 4149
4126 if (dpyinfo->reference_count > 0) 4150 if (dpyinfo->reference_count > 0)
4127 error ("Display still has frames on it"); 4151 error ("Display still has frames on it");
4128 4152
4129 BLOCK_INPUT; 4153 x_delete_terminal (dpyinfo->terminal);
4130 /* Free the fonts in the font table. */
4131 for (i = 0; i < dpyinfo->n_fonts; i++)
4132 if (dpyinfo->font_table[i].name)
4133 {
4134 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
4135 }
4136
4137 x_destroy_all_bitmaps (dpyinfo);
4138 XSetCloseDownMode (dpyinfo->display, DestroyAll);
4139
4140#ifdef USE_GTK
4141 xg_display_close (dpyinfo->display);
4142#else
4143#ifdef USE_X_TOOLKIT
4144 XtCloseDisplay (dpyinfo->display);
4145#else
4146 XCloseDisplay (dpyinfo->display);
4147#endif
4148#endif /* ! USE_GTK */
4149
4150 x_delete_display (dpyinfo);
4151 UNBLOCK_INPUT;
4152 4154
4153 return Qnil; 4155 return Qnil;
4154} 4156}
@@ -4172,13 +4174,13 @@ If ON is nil, allow buffering of requests.
4172Turning on synchronization prohibits the Xlib routines from buffering 4174Turning on synchronization prohibits the Xlib routines from buffering
4173requests and seriously degrades performance, but makes debugging much 4175requests and seriously degrades performance, but makes debugging much
4174easier. 4176easier.
4175The optional second argument DISPLAY specifies which display to act on. 4177The optional second argument TERMINAL specifies which display to act on.
4176DISPLAY should be either a frame or a display name (a string). 4178TERMINAL should be a terminal id, a frame or a display name (a string).
4177If DISPLAY is omitted or nil, that stands for the selected frame's display. */) 4179If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4178 (on, display) 4180 (on, terminal)
4179 Lisp_Object display, on; 4181 Lisp_Object terminal, on;
4180{ 4182{
4181 struct x_display_info *dpyinfo = check_x_display_info (display); 4183 struct x_display_info *dpyinfo = check_x_display_info (terminal);
4182 4184
4183 XSynchronize (dpyinfo->display, !EQ (on, Qnil)); 4185 XSynchronize (dpyinfo->display, !EQ (on, Qnil));
4184 4186
@@ -4482,10 +4484,6 @@ start_hourglass ()
4482 EMACS_TIME delay; 4484 EMACS_TIME delay;
4483 int secs, usecs = 0; 4485 int secs, usecs = 0;
4484 4486
4485 /* Don't bother for ttys. */
4486 if (NILP (Vwindow_system))
4487 return;
4488
4489 cancel_hourglass (); 4487 cancel_hourglass ();
4490 4488
4491 if (INTEGERP (Vhourglass_delay) 4489 if (INTEGERP (Vhourglass_delay)
@@ -4697,20 +4695,16 @@ x_create_tip_frame (dpyinfo, parms, text)
4697 int width, height; 4695 int width, height;
4698 int count = SPECPDL_INDEX (); 4696 int count = SPECPDL_INDEX ();
4699 struct gcpro gcpro1, gcpro2, gcpro3; 4697 struct gcpro gcpro1, gcpro2, gcpro3;
4700 struct kboard *kb;
4701 int face_change_count_before = face_change_count; 4698 int face_change_count_before = face_change_count;
4702 Lisp_Object buffer; 4699 Lisp_Object buffer;
4703 struct buffer *old_buffer; 4700 struct buffer *old_buffer;
4704 4701
4705 check_x (); 4702 check_x ();
4706 4703
4707 parms = Fcopy_alist (parms); 4704 if (dpyinfo->terminal->deleted)
4705 error ("Terminal is being deleted, can't create new frames on it");
4708 4706
4709#ifdef MULTI_KBOARD 4707 parms = Fcopy_alist (parms);
4710 kb = dpyinfo->kboard;
4711#else
4712 kb = &the_only_kboard;
4713#endif
4714 4708
4715 /* Get the name of the frame to use for resource lookup. */ 4709 /* Get the name of the frame to use for resource lookup. */
4716 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); 4710 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
@@ -4738,6 +4732,9 @@ x_create_tip_frame (dpyinfo, parms, text)
4738 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0; 4732 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
4739 record_unwind_protect (unwind_create_tip_frame, frame); 4733 record_unwind_protect (unwind_create_tip_frame, frame);
4740 4734
4735 f->terminal = dpyinfo->terminal;
4736 f->terminal->reference_count++;
4737
4741 /* By setting the output method, we're essentially saying that 4738 /* By setting the output method, we're essentially saying that
4742 the frame is live, as per FRAME_LIVE_P. If we get a signal 4739 the frame is live, as per FRAME_LIVE_P. If we get a signal
4743 from this point on, x_destroy_window might screw up reference 4740 from this point on, x_destroy_window might screw up reference
@@ -4759,9 +4756,6 @@ x_create_tip_frame (dpyinfo, parms, text)
4759 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount; 4756 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
4760 dpyinfo_refcount = dpyinfo->reference_count; 4757 dpyinfo_refcount = dpyinfo->reference_count;
4761#endif /* GLYPH_DEBUG */ 4758#endif /* GLYPH_DEBUG */
4762#ifdef MULTI_KBOARD
4763 FRAME_KBOARD (f) = kb;
4764#endif
4765 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window; 4759 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4766 f->output_data.x->explicit_parent = 0; 4760 f->output_data.x->explicit_parent = 0;
4767 4761
@@ -4771,11 +4765,21 @@ x_create_tip_frame (dpyinfo, parms, text)
4771 Lisp_Object black; 4765 Lisp_Object black;
4772 struct gcpro gcpro1; 4766 struct gcpro gcpro1;
4773 4767
4768 /* Function x_decode_color can signal an error. Make
4769 sure to initialize color slots so that we won't try
4770 to free colors we haven't allocated. */
4771 FRAME_FOREGROUND_PIXEL (f) = -1;
4772 FRAME_BACKGROUND_PIXEL (f) = -1;
4773 f->output_data.x->cursor_pixel = -1;
4774 f->output_data.x->cursor_foreground_pixel = -1;
4775 f->output_data.x->border_pixel = -1;
4776 f->output_data.x->mouse_pixel = -1;
4777
4774 black = build_string ("black"); 4778 black = build_string ("black");
4775 GCPRO1 (black); 4779 GCPRO1 (black);
4776 f->output_data.x->foreground_pixel 4780 FRAME_FOREGROUND_PIXEL (f)
4777 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4781 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4778 f->output_data.x->background_pixel 4782 FRAME_BACKGROUND_PIXEL (f)
4779 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4783 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4780 f->output_data.x->cursor_pixel 4784 f->output_data.x->cursor_pixel
4781 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); 4785 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
@@ -4961,6 +4965,8 @@ x_create_tip_frame (dpyinfo, parms, text)
4961 Qnil)); 4965 Qnil));
4962 } 4966 }
4963 4967
4968 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qx), Qnil));
4969
4964 f->no_split = 1; 4970 f->no_split = 1;
4965 4971
4966 UNGCPRO; 4972 UNGCPRO;
diff --git a/src/xmenu.c b/src/xmenu.c
index f68f3a41e3f..bf9a9101ef0 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"
@@ -745,6 +745,9 @@ mouse_position_for_popup (f, x, y)
745 Window root, dummy_window; 745 Window root, dummy_window;
746 int dummy; 746 int dummy;
747 747
748 if (! FRAME_X_P (f))
749 abort ();
750
748 BLOCK_INPUT; 751 BLOCK_INPUT;
749 752
750 XQueryPointer (FRAME_X_DISPLAY (f), 753 XQueryPointer (FRAME_X_DISPLAY (f),
@@ -940,6 +943,9 @@ no quit occurs and `x-popup-menu' returns nil. */)
940 xpos += XINT (x); 943 xpos += XINT (x);
941 ypos += XINT (y); 944 ypos += XINT (y);
942 945
946 if (! FRAME_X_P (f))
947 error ("Can not put X menu on non-X terminal");
948
943 XSETFRAME (Vmenu_updating_frame, f); 949 XSETFRAME (Vmenu_updating_frame, f);
944 } 950 }
945 else 951 else
@@ -1128,6 +1134,9 @@ for instance using the window manager, then this produces a quit and
1128 but I don't want to make one now. */ 1134 but I don't want to make one now. */
1129 CHECK_WINDOW (window); 1135 CHECK_WINDOW (window);
1130 1136
1137 if (! FRAME_X_P (f))
1138 error ("Can not put X dialog on non-X terminal");
1139
1131#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) 1140#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1132 /* Display a menu with these alternatives 1141 /* Display a menu with these alternatives
1133 in the middle of frame F. */ 1142 in the middle of frame F. */
@@ -1309,7 +1318,7 @@ popup_get_selection (initial_event, dpyinfo, id, do_timers)
1309 } 1318 }
1310} 1319}
1311 1320
1312DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i", 1321DEFUN ("x-menu-bar-open-internal", Fx_menu_bar_open_internal, Sx_menu_bar_open_internal, 0, 1, "i",
1313 doc: /* Start key navigation of the menu bar in FRAME. 1322 doc: /* Start key navigation of the menu bar in FRAME.
1314This initially opens the first menu bar item and you can then navigate with the 1323This initially opens the first menu bar item and you can then navigate with the
1315arrow keys, select a menu entry with the return key or cancel with the 1324arrow keys, select a menu entry with the return key or cancel with the
@@ -1388,7 +1397,7 @@ If FRAME is nil or not given, use the selected frame. */)
1388 1397
1389 1398
1390#ifdef USE_GTK 1399#ifdef USE_GTK
1391DEFUN ("menu-bar-open", Fmenu_bar_open, Smenu_bar_open, 0, 1, "i", 1400DEFUN ("x-menu-bar-open-internal", Fx_menu_bar_open_internal, Sx_menu_bar_open_internal, 0, 1, "i",
1392 doc: /* Start key navigation of the menu bar in FRAME. 1401 doc: /* Start key navigation of the menu bar in FRAME.
1393This initially opens the first menu bar item and you can then navigate with the 1402This initially opens the first menu bar item and you can then navigate with the
1394arrow keys, select a menu entry with the return key or cancel with the 1403arrow keys, select a menu entry with the return key or cancel with the
@@ -1464,6 +1473,9 @@ void
1464x_activate_menubar (f) 1473x_activate_menubar (f)
1465 FRAME_PTR f; 1474 FRAME_PTR f;
1466{ 1475{
1476 if (! FRAME_X_P (f))
1477 abort ();
1478
1467 if (!f->output_data.x->saved_menu_event->type) 1479 if (!f->output_data.x->saved_menu_event->type)
1468 return; 1480 return;
1469 1481
@@ -2098,9 +2110,14 @@ update_frame_menubar (f)
2098#ifdef USE_GTK 2110#ifdef USE_GTK
2099 return xg_update_frame_menubar (f); 2111 return xg_update_frame_menubar (f);
2100#else 2112#else
2101 struct x_output *x = f->output_data.x; 2113 struct x_output *x;
2102 int columns, rows; 2114 int columns, rows;
2103 2115
2116 if (! FRAME_X_P (f))
2117 abort ();
2118
2119 x = f->output_data.x;
2120
2104 if (!x->menubar_widget || XtIsManaged (x->menubar_widget)) 2121 if (!x->menubar_widget || XtIsManaged (x->menubar_widget))
2105 return 0; 2122 return 0;
2106 2123
@@ -2146,7 +2163,7 @@ set_frame_menubar (f, first_time, deep_p)
2146 int first_time; 2163 int first_time;
2147 int deep_p; 2164 int deep_p;
2148{ 2165{
2149 xt_or_gtk_widget menubar_widget = f->output_data.x->menubar_widget; 2166 xt_or_gtk_widget menubar_widget;
2150#ifdef USE_X_TOOLKIT 2167#ifdef USE_X_TOOLKIT
2151 LWLIB_ID id; 2168 LWLIB_ID id;
2152#endif 2169#endif
@@ -2156,6 +2173,10 @@ set_frame_menubar (f, first_time, deep_p)
2156 int *submenu_start, *submenu_end; 2173 int *submenu_start, *submenu_end;
2157 int *submenu_top_level_items, *submenu_n_panes; 2174 int *submenu_top_level_items, *submenu_n_panes;
2158 2175
2176 if (! FRAME_X_P (f))
2177 abort ();
2178
2179 menubar_widget = f->output_data.x->menubar_widget;
2159 2180
2160 XSETFRAME (Vmenu_updating_frame, f); 2181 XSETFRAME (Vmenu_updating_frame, f);
2161 2182
@@ -2508,6 +2529,9 @@ free_frame_menubar (f)
2508{ 2529{
2509 Widget menubar_widget; 2530 Widget menubar_widget;
2510 2531
2532 if (! FRAME_X_P (f))
2533 abort ();
2534
2511 menubar_widget = f->output_data.x->menubar_widget; 2535 menubar_widget = f->output_data.x->menubar_widget;
2512 2536
2513 f->output_data.x->menubar_height = 0; 2537 f->output_data.x->menubar_height = 0;
@@ -2660,6 +2684,9 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click)
2660 struct next_popup_x_y popup_x_y; 2684 struct next_popup_x_y popup_x_y;
2661 int specpdl_count = SPECPDL_INDEX (); 2685 int specpdl_count = SPECPDL_INDEX ();
2662 2686
2687 if (! FRAME_X_P (f))
2688 abort ();
2689
2663 xg_crazy_callback_abort = 1; 2690 xg_crazy_callback_abort = 1;
2664 menu = xg_create_widget ("popup", first_wv->name, f, first_wv, 2691 menu = xg_create_widget ("popup", first_wv->name, f, first_wv,
2665 G_CALLBACK (popup_selection_callback), 2692 G_CALLBACK (popup_selection_callback),
@@ -2768,6 +2795,9 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click)
2768 LWLIB_ID menu_id; 2795 LWLIB_ID menu_id;
2769 Widget menu; 2796 Widget menu;
2770 2797
2798 if (! FRAME_X_P (f))
2799 abort ();
2800
2771 menu_id = widget_id_tick++; 2801 menu_id = widget_id_tick++;
2772 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv, 2802 menu = lw_create_widget ("popup", first_wv->name, menu_id, first_wv,
2773 f->output_data.x->widget, 1, 0, 2803 f->output_data.x->widget, 1, 0,
@@ -2844,6 +2874,9 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
2844 2874
2845 int first_pane; 2875 int first_pane;
2846 2876
2877 if (! FRAME_X_P (f))
2878 abort ();
2879
2847 *error = NULL; 2880 *error = NULL;
2848 2881
2849 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH) 2882 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH)
@@ -3126,6 +3159,9 @@ create_and_show_dialog (f, first_wv)
3126{ 3159{
3127 GtkWidget *menu; 3160 GtkWidget *menu;
3128 3161
3162 if (! FRAME_X_P (f))
3163 abort ();
3164
3129 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv, 3165 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv,
3130 G_CALLBACK (dialog_selection_callback), 3166 G_CALLBACK (dialog_selection_callback),
3131 G_CALLBACK (popup_deactivate_callback), 3167 G_CALLBACK (popup_deactivate_callback),
@@ -3175,6 +3211,9 @@ create_and_show_dialog (f, first_wv)
3175{ 3211{
3176 LWLIB_ID dialog_id; 3212 LWLIB_ID dialog_id;
3177 3213
3214 if (!FRAME_X_P (f))
3215 abort();
3216
3178 dialog_id = widget_id_tick++; 3217 dialog_id = widget_id_tick++;
3179 lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv, 3218 lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv,
3180 f->output_data.x->widget, 1, 0, 3219 f->output_data.x->widget, 1, 0,
@@ -3227,6 +3266,9 @@ xdialog_show (f, keymaps, title, header, error_name)
3227 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ 3266 /* 1 means we've seen the boundary between left-hand elts and right-hand. */
3228 int boundary_seen = 0; 3267 int boundary_seen = 0;
3229 3268
3269 if (! FRAME_X_P (f))
3270 abort ();
3271
3230 *error_name = NULL; 3272 *error_name = NULL;
3231 3273
3232 if (menu_items_n_panes > 1) 3274 if (menu_items_n_panes > 1)
@@ -3502,6 +3544,9 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
3502 unsigned int dummy_uint; 3544 unsigned int dummy_uint;
3503 int specpdl_count = SPECPDL_INDEX (); 3545 int specpdl_count = SPECPDL_INDEX ();
3504 3546
3547 if (! FRAME_X_P (f))
3548 abort ();
3549
3505 *error = 0; 3550 *error = 0;
3506 if (menu_items_n_panes == 0) 3551 if (menu_items_n_panes == 0)
3507 return Qnil; 3552 return Qnil;
@@ -3806,8 +3851,9 @@ syms_of_xmenu ()
3806 defsubr (&Smenu_or_popup_active_p); 3851 defsubr (&Smenu_or_popup_active_p);
3807 3852
3808#if defined (USE_GTK) || defined (USE_X_TOOLKIT) 3853#if defined (USE_GTK) || defined (USE_X_TOOLKIT)
3809 defsubr (&Smenu_bar_open); 3854 defsubr (&Sx_menu_bar_open_internal);
3810 Ffset (intern ("accelerate-menu"), intern (Smenu_bar_open.symbol_name)); 3855 Ffset (intern ("accelerate-menu"),
3856 intern (Sx_menu_bar_open_internal.symbol_name));
3811#endif 3857#endif
3812 3858
3813#ifdef HAVE_MENUS 3859#ifdef HAVE_MENUS
diff --git a/src/xselect.c b/src/xselect.c
index 33468f0d63a..b2d47bd1175 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
@@ -1014,6 +1022,7 @@ x_handle_selection_clear (event)
1014 1022
1015 TRACE0 ("x_handle_selection_clear"); 1023 TRACE0 ("x_handle_selection_clear");
1016 1024
1025#ifdef MULTI_KBOARD
1017 /* If the new selection owner is also Emacs, 1026 /* If the new selection owner is also Emacs,
1018 don't clear the new selection. */ 1027 don't clear the new selection. */
1019 BLOCK_INPUT; 1028 BLOCK_INPUT;
@@ -1021,7 +1030,7 @@ x_handle_selection_clear (event)
1021 to see if this Emacs job now owns the selection 1030 to see if this Emacs job now owns the selection
1022 through that display. */ 1031 through that display. */
1023 for (t_dpyinfo = x_display_list; t_dpyinfo; t_dpyinfo = t_dpyinfo->next) 1032 for (t_dpyinfo = x_display_list; t_dpyinfo; t_dpyinfo = t_dpyinfo->next)
1024 if (t_dpyinfo->kboard == dpyinfo->kboard) 1033 if (t_dpyinfo->terminal->kboard == dpyinfo->terminal->kboard)
1025 { 1034 {
1026 Window owner_window 1035 Window owner_window
1027 = XGetSelectionOwner (t_dpyinfo->display, selection); 1036 = XGetSelectionOwner (t_dpyinfo->display, selection);
@@ -1032,7 +1041,8 @@ x_handle_selection_clear (event)
1032 } 1041 }
1033 } 1042 }
1034 UNBLOCK_INPUT; 1043 UNBLOCK_INPUT;
1035 1044#endif
1045
1036 selection_symbol = x_atom_to_symbol (display, selection); 1046 selection_symbol = x_atom_to_symbol (display, selection);
1037 1047
1038 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist); 1048 local_selection_data = assq_no_quit (selection_symbol, Vselection_alist);
@@ -1380,17 +1390,26 @@ x_get_foreign_selection (selection_symbol, target_type, time_stamp)
1380 Lisp_Object selection_symbol, target_type, time_stamp; 1390 Lisp_Object selection_symbol, target_type, time_stamp;
1381{ 1391{
1382 struct frame *sf = SELECTED_FRAME (); 1392 struct frame *sf = SELECTED_FRAME ();
1383 Window requestor_window = FRAME_X_WINDOW (sf); 1393 Window requestor_window;
1384 Display *display = FRAME_X_DISPLAY (sf); 1394 Display *display;
1385 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (sf); 1395 struct x_display_info *dpyinfo;
1386 Time requestor_time = last_event_timestamp; 1396 Time requestor_time = last_event_timestamp;
1387 Atom target_property = dpyinfo->Xatom_EMACS_TMP; 1397 Atom target_property;
1388 Atom selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol); 1398 Atom selection_atom;
1389 Atom type_atom; 1399 Atom type_atom;
1390 int secs, usecs; 1400 int secs, usecs;
1391 int count = SPECPDL_INDEX (); 1401 int count = SPECPDL_INDEX ();
1392 Lisp_Object frame; 1402 Lisp_Object frame;
1393 1403
1404 if (! FRAME_X_P (sf))
1405 return Qnil;
1406
1407 requestor_window = FRAME_X_WINDOW (sf);
1408 display = FRAME_X_DISPLAY (sf);
1409 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
1410 target_property = dpyinfo->Xatom_EMACS_TMP;
1411 selection_atom = symbol_to_x_atom (dpyinfo, display, selection_symbol);
1412
1394 if (CONSP (target_type)) 1413 if (CONSP (target_type))
1395 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type)); 1414 type_atom = symbol_to_x_atom (dpyinfo, display, XCAR (target_type));
1396 else 1415 else
@@ -2206,6 +2225,9 @@ Disowning it means there is no such selection. */)
2206 struct frame *sf = SELECTED_FRAME (); 2225 struct frame *sf = SELECTED_FRAME ();
2207 2226
2208 check_x (); 2227 check_x ();
2228 if (! FRAME_X_P (sf))
2229 return Qnil;
2230
2209 display = FRAME_X_DISPLAY (sf); 2231 display = FRAME_X_DISPLAY (sf);
2210 dpyinfo = FRAME_X_DISPLAY_INFO (sf); 2232 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
2211 CHECK_SYMBOL (selection); 2233 CHECK_SYMBOL (selection);
@@ -2367,6 +2389,10 @@ DEFUN ("x-get-cut-buffer-internal", Fx_get_cut_buffer_internal,
2367 struct frame *sf = SELECTED_FRAME (); 2389 struct frame *sf = SELECTED_FRAME ();
2368 2390
2369 check_x (); 2391 check_x ();
2392
2393 if (! FRAME_X_P (sf))
2394 return Qnil;
2395
2370 display = FRAME_X_DISPLAY (sf); 2396 display = FRAME_X_DISPLAY (sf);
2371 dpyinfo = FRAME_X_DISPLAY_INFO (sf); 2397 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
2372 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2398 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
@@ -2407,6 +2433,10 @@ DEFUN ("x-store-cut-buffer-internal", Fx_store_cut_buffer_internal,
2407 struct frame *sf = SELECTED_FRAME (); 2433 struct frame *sf = SELECTED_FRAME ();
2408 2434
2409 check_x (); 2435 check_x ();
2436
2437 if (! FRAME_X_P (sf))
2438 return Qnil;
2439
2410 display = FRAME_X_DISPLAY (sf); 2440 display = FRAME_X_DISPLAY (sf);
2411 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2441 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2412 2442
@@ -2463,8 +2493,12 @@ Positive means shift the values forward, negative means backward. */)
2463 Atom props[8]; 2493 Atom props[8];
2464 Display *display; 2494 Display *display;
2465 struct frame *sf = SELECTED_FRAME (); 2495 struct frame *sf = SELECTED_FRAME ();
2466 2496
2467 check_x (); 2497 check_x ();
2498
2499 if (! FRAME_X_P (sf))
2500 return Qnil;
2501
2468 display = FRAME_X_DISPLAY (sf); 2502 display = FRAME_X_DISPLAY (sf);
2469 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */ 2503 window = RootWindow (display, 0); /* Cut buffers are on screen 0 */
2470 CHECK_NUMBER (n); 2504 CHECK_NUMBER (n);
diff --git a/src/xsmfns.c b/src/xsmfns.c
index 1211c55eb03..77abf3b5072 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 fdff9b4f02e..0e56b04c1b0 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 *));
@@ -377,12 +382,18 @@ static void
377x_flush (f) 382x_flush (f)
378 struct frame *f; 383 struct frame *f;
379{ 384{
385 /* Don't call XFlush when it is not safe to redisplay; the X
386 connection may be broken. */
387 if (!NILP (Vinhibit_redisplay))
388 return;
389
380 BLOCK_INPUT; 390 BLOCK_INPUT;
381 if (f == NULL) 391 if (f == NULL)
382 { 392 {
383 Lisp_Object rest, frame; 393 Lisp_Object rest, frame;
384 FOR_EACH_FRAME (rest, frame) 394 FOR_EACH_FRAME (rest, frame)
385 x_flush (XFRAME (frame)); 395 if (FRAME_X_P (XFRAME (frame)))
396 x_flush (XFRAME (frame));
386 } 397 }
387 else if (FRAME_X_P (f)) 398 else if (FRAME_X_P (f))
388 XFlush (FRAME_X_DISPLAY (f)); 399 XFlush (FRAME_X_DISPLAY (f));
@@ -843,7 +854,7 @@ x_draw_fringe_bitmap (w, row, p)
843 rarely happens). */ 854 rarely happens). */
844 855
845static void 856static void
846XTset_terminal_modes () 857XTset_terminal_modes (struct terminal *terminal)
847{ 858{
848} 859}
849 860
@@ -851,7 +862,7 @@ XTset_terminal_modes ()
851 the X-windows go away, and suspending requires no action. */ 862 the X-windows go away, and suspending requires no action. */
852 863
853static void 864static void
854XTreset_terminal_modes () 865XTreset_terminal_modes (struct terminal *terminal)
855{ 866{
856} 867}
857 868
@@ -1464,7 +1475,8 @@ x_frame_of_widget (widget)
1464 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail)) 1475 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
1465 if (GC_FRAMEP (XCAR (tail)) 1476 if (GC_FRAMEP (XCAR (tail))
1466 && (f = XFRAME (XCAR (tail)), 1477 && (f = XFRAME (XCAR (tail)),
1467 (f->output_data.nothing != 1 1478 (FRAME_X_P (f)
1479 && f->output_data.nothing != 1
1468 && FRAME_X_DISPLAY_INFO (f) == dpyinfo)) 1480 && FRAME_X_DISPLAY_INFO (f) == dpyinfo))
1469 && f->output_data.x->widget == widget) 1481 && f->output_data.x->widget == widget)
1470 return f; 1482 return f;
@@ -2843,7 +2855,8 @@ x_shift_glyphs_for_insert (f, x, y, width, height, shift_by)
2843 for X frames. */ 2855 for X frames. */
2844 2856
2845static void 2857static void
2846x_delete_glyphs (n) 2858x_delete_glyphs (f, n)
2859 struct frame *f;
2847 register int n; 2860 register int n;
2848{ 2861{
2849 abort (); 2862 abort ();
@@ -2866,19 +2879,11 @@ x_clear_area (dpy, window, x, y, width, height, exposures)
2866} 2879}
2867 2880
2868 2881
2869/* Clear entire frame. If updating_frame is non-null, clear that 2882/* Clear an entire frame. */
2870 frame. Otherwise clear the selected frame. */
2871 2883
2872static void 2884static void
2873x_clear_frame () 2885x_clear_frame (struct frame *f)
2874{ 2886{
2875 struct frame *f;
2876
2877 if (updating_frame)
2878 f = updating_frame;
2879 else
2880 f = SELECTED_FRAME ();
2881
2882 /* Clearing the frame will erase any cursor, so mark them all as no 2887 /* Clearing the frame will erase any cursor, so mark them all as no
2883 longer visible. */ 2888 longer visible. */
2884 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); 2889 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
@@ -2957,8 +2962,8 @@ XTflash (f)
2957 XGCValues values; 2962 XGCValues values;
2958 2963
2959 values.function = GXxor; 2964 values.function = GXxor;
2960 values.foreground = (f->output_data.x->foreground_pixel 2965 values.foreground = (FRAME_FOREGROUND_PIXEL (f)
2961 ^ f->output_data.x->background_pixel); 2966 ^ FRAME_BACKGROUND_PIXEL (f));
2962 2967
2963 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 2968 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2964 GCFunction | GCForeground, &values); 2969 GCFunction | GCForeground, &values);
@@ -3124,7 +3129,8 @@ XTset_terminal_window (n)
3124 lines or deleting -N lines at vertical position VPOS. */ 3129 lines or deleting -N lines at vertical position VPOS. */
3125 3130
3126static void 3131static void
3127x_ins_del_lines (vpos, n) 3132x_ins_del_lines (f, vpos, n)
3133 struct frame *f;
3128 int vpos, n; 3134 int vpos, n;
3129{ 3135{
3130 abort (); 3136 abort ();
@@ -3761,7 +3767,8 @@ XTmouse_position (fp, insist, bar_window, part, x, y, time)
3761 3767
3762 /* Clear the mouse-moved flag for every frame on this display. */ 3768 /* Clear the mouse-moved flag for every frame on this display. */
3763 FOR_EACH_FRAME (tail, frame) 3769 FOR_EACH_FRAME (tail, frame)
3764 if (FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp)) 3770 if (FRAME_X_P (XFRAME (frame))
3771 && FRAME_X_DISPLAY (XFRAME (frame)) == FRAME_X_DISPLAY (*fp))
3765 XFRAME (frame)->mouse_moved = 0; 3772 XFRAME (frame)->mouse_moved = 0;
3766 3773
3767 last_mouse_scroll_bar = Qnil; 3774 last_mouse_scroll_bar = Qnil;
@@ -3950,6 +3957,9 @@ x_window_to_scroll_bar (display, window_id)
3950 if (! GC_FRAMEP (frame)) 3957 if (! GC_FRAMEP (frame))
3951 abort (); 3958 abort ();
3952 3959
3960 if (! FRAME_X_P (XFRAME (frame)))
3961 continue;
3962
3953 /* Scan this frame's scroll bar list for a scroll bar with the 3963 /* Scan this frame's scroll bar list for a scroll bar with the
3954 right window ID. */ 3964 right window ID. */
3955 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame)); 3965 condemned = FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame));
@@ -3984,11 +3994,14 @@ x_window_to_menu_bar (window)
3984 XGCTYPE (tail) == Lisp_Cons; 3994 XGCTYPE (tail) == Lisp_Cons;
3985 tail = XCDR (tail)) 3995 tail = XCDR (tail))
3986 { 3996 {
3987 Lisp_Object frame = XCAR (tail); 3997 if (FRAME_X_P (XFRAME (XCAR (tail))))
3988 Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget; 3998 {
3999 Lisp_Object frame = XCAR (tail);
4000 Widget menu_bar = XFRAME (frame)->output_data.x->menubar_widget;
3989 4001
3990 if (menu_bar && xlwmenu_window_p (menu_bar, window)) 4002 if (menu_bar && xlwmenu_window_p (menu_bar, window))
3991 return menu_bar; 4003 return menu_bar;
4004 }
3992 } 4005 }
3993 4006
3994 return NULL; 4007 return NULL;
@@ -4796,7 +4809,7 @@ x_scroll_bar_create (w, top, left, width, height)
4796 4809
4797 a.background_pixel = f->output_data.x->scroll_bar_background_pixel; 4810 a.background_pixel = f->output_data.x->scroll_bar_background_pixel;
4798 if (a.background_pixel == -1) 4811 if (a.background_pixel == -1)
4799 a.background_pixel = f->output_data.x->background_pixel; 4812 a.background_pixel = FRAME_BACKGROUND_PIXEL (f);
4800 4813
4801 a.event_mask = (ButtonPressMask | ButtonReleaseMask 4814 a.event_mask = (ButtonPressMask | ButtonReleaseMask
4802 | ButtonMotionMask | PointerMotionHintMask 4815 | ButtonMotionMask | PointerMotionHintMask
@@ -4973,7 +4986,7 @@ x_scroll_bar_set_handle (bar, start, end, rebuild)
4973 /* Restore the foreground color of the GC if we changed it above. */ 4986 /* Restore the foreground color of the GC if we changed it above. */
4974 if (f->output_data.x->scroll_bar_foreground_pixel != -1) 4987 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
4975 XSetForeground (FRAME_X_DISPLAY (f), gc, 4988 XSetForeground (FRAME_X_DISPLAY (f), gc,
4976 f->output_data.x->foreground_pixel); 4989 FRAME_FOREGROUND_PIXEL (f));
4977 4990
4978 /* Draw the empty space below the handle. Note that we can't 4991 /* Draw the empty space below the handle. Note that we can't
4979 clear zero-height areas; that means "clear to end of window." */ 4992 clear zero-height areas; that means "clear to end of window." */
@@ -5375,7 +5388,7 @@ x_scroll_bar_expose (bar, event)
5375 /* Restore the foreground color of the GC if we changed it above. */ 5388 /* Restore the foreground color of the GC if we changed it above. */
5376 if (f->output_data.x->scroll_bar_foreground_pixel != -1) 5389 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
5377 XSetForeground (FRAME_X_DISPLAY (f), gc, 5390 XSetForeground (FRAME_X_DISPLAY (f), gc,
5378 f->output_data.x->foreground_pixel); 5391 FRAME_FOREGROUND_PIXEL (f));
5379 5392
5380 UNBLOCK_INPUT; 5393 UNBLOCK_INPUT;
5381 5394
@@ -5775,7 +5788,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
5775 int count = 0; 5788 int count = 0;
5776 int do_help = 0; 5789 int do_help = 0;
5777 int nbytes = 0; 5790 int nbytes = 0;
5778 struct frame *f; 5791 struct frame *f = NULL;
5779 struct coding_system coding; 5792 struct coding_system coding;
5780 XEvent event = *eventp; 5793 XEvent event = *eventp;
5781 5794
@@ -6351,19 +6364,19 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
6351 bzero (&compose_status, sizeof (compose_status)); 6364 bzero (&compose_status, sizeof (compose_status));
6352 orig_keysym = keysym; 6365 orig_keysym = keysym;
6353 6366
6354 /* Common for all keysym input events. */ 6367 /* Common for all keysym input events. */
6355 XSETFRAME (inev.ie.frame_or_window, f); 6368 XSETFRAME (inev.ie.frame_or_window, f);
6356 inev.ie.modifiers 6369 inev.ie.modifiers
6357 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers); 6370 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers);
6358 inev.ie.timestamp = event.xkey.time; 6371 inev.ie.timestamp = event.xkey.time;
6359 6372
6360 /* First deal with keysyms which have defined 6373 /* First deal with keysyms which have defined
6361 translations to characters. */ 6374 translations to characters. */
6362 if (keysym >= 32 && keysym < 128) 6375 if (keysym >= 32 && keysym < 128)
6363 /* Avoid explicitly decoding each ASCII character. */ 6376 /* Avoid explicitly decoding each ASCII character. */
6364 { 6377 {
6365 inev.ie.kind = ASCII_KEYSTROKE_EVENT; 6378 inev.ie.kind = ASCII_KEYSTROKE_EVENT;
6366 inev.ie.code = keysym; 6379 inev.ie.code = keysym;
6367 goto done_keysym; 6380 goto done_keysym;
6368 } 6381 }
6369 6382
@@ -6408,18 +6421,18 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit)
6408 /* Now non-ASCII. */ 6421 /* Now non-ASCII. */
6409 if (HASH_TABLE_P (Vx_keysym_table) 6422 if (HASH_TABLE_P (Vx_keysym_table)
6410 && (NATNUMP (c = Fgethash (make_number (keysym), 6423 && (NATNUMP (c = Fgethash (make_number (keysym),
6411 Vx_keysym_table, 6424 Vx_keysym_table,
6412 Qnil)))) 6425 Qnil))))
6413 { 6426 {
6414 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) 6427 inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c))
6415 ? ASCII_KEYSTROKE_EVENT 6428 ? ASCII_KEYSTROKE_EVENT
6416 : MULTIBYTE_CHAR_KEYSTROKE_EVENT); 6429 : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
6417 inev.ie.code = XFASTINT (c); 6430 inev.ie.code = XFASTINT (c);
6418 goto done_keysym; 6431 goto done_keysym;
6419 } 6432 }
6420 6433
6421 /* Random non-modifier sorts of keysyms. */ 6434 /* Random non-modifier sorts of keysyms. */
6422 if (((keysym >= XK_BackSpace && keysym <= XK_Escape) 6435 if (((keysym >= XK_BackSpace && keysym <= XK_Escape)
6423 || keysym == XK_Delete 6436 || keysym == XK_Delete
6424#ifdef XK_ISO_Left_Tab 6437#ifdef XK_ISO_Left_Tab
6425 || (keysym >= XK_ISO_Left_Tab 6438 || (keysym >= XK_ISO_Left_Tab
@@ -7063,8 +7076,8 @@ x_dispatch_event (event, display)
7063 EXPECTED is nonzero if the caller knows input is available. */ 7076 EXPECTED is nonzero if the caller knows input is available. */
7064 7077
7065static int 7078static int
7066XTread_socket (sd, expected, hold_quit) 7079XTread_socket (terminal, expected, hold_quit)
7067 register int sd; 7080 struct terminal *terminal;
7068 int expected; 7081 int expected;
7069 struct input_event *hold_quit; 7082 struct input_event *hold_quit;
7070{ 7083{
@@ -7087,6 +7100,31 @@ XTread_socket (sd, expected, hold_quit)
7087 7100
7088 ++handling_signal; 7101 ++handling_signal;
7089 7102
7103#ifdef HAVE_X_SM
7104 /* Only check session manager input for the primary display. */
7105 if (terminal->id == 1 && x_session_have_connection ())
7106 {
7107 struct input_event inev;
7108 BLOCK_INPUT;
7109 /* We don't need to EVENT_INIT (inev) here, as
7110 x_session_check_input copies an entire input_event. */
7111 if (x_session_check_input (&inev))
7112 {
7113 kbd_buffer_store_event_hold (&inev, hold_quit);
7114 count++;
7115 }
7116 UNBLOCK_INPUT;
7117 }
7118#endif
7119
7120 /* For debugging, this gives a way to fake an I/O error. */
7121 if (terminal->display_info.x == XTread_socket_fake_io_error)
7122 {
7123 XTread_socket_fake_io_error = 0;
7124 x_io_error_quitter (dpyinfo->display);
7125 }
7126
7127#if 0 /* This loop is a noop now. */
7090 /* Find the display we are supposed to read input for. 7128 /* Find the display we are supposed to read input for.
7091 It's the one communicating on descriptor SD. */ 7129 It's the one communicating on descriptor SD. */
7092 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) 7130 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
@@ -7117,52 +7155,31 @@ XTread_socket (sd, expected, hold_quit)
7117#endif /* HAVE_SELECT */ 7155#endif /* HAVE_SELECT */
7118#endif /* SIGIO */ 7156#endif /* SIGIO */
7119#endif 7157#endif
7120 7158 }
7121 /* For debugging, this gives a way to fake an I/O error. */
7122 if (dpyinfo == XTread_socket_fake_io_error)
7123 {
7124 XTread_socket_fake_io_error = 0;
7125 x_io_error_quitter (dpyinfo->display);
7126 }
7127
7128#ifdef HAVE_X_SM
7129 {
7130 struct input_event inev;
7131 BLOCK_INPUT;
7132 /* We don't need to EVENT_INIT (inev) here, as
7133 x_session_check_input copies an entire input_event. */
7134 if (x_session_check_input (&inev))
7135 {
7136 kbd_buffer_store_event_hold (&inev, hold_quit);
7137 count++;
7138 }
7139 UNBLOCK_INPUT;
7140 }
7141#endif 7159#endif
7142 7160
7143#ifndef USE_GTK 7161#ifndef USE_GTK
7144 while (XPending (dpyinfo->display)) 7162 while (XPending (terminal->display_info.x->display))
7145 { 7163 {
7146 int finish; 7164 int finish;
7147 7165
7148 XNextEvent (dpyinfo->display, &event); 7166 XNextEvent (terminal->display_info.x->display, &event);
7149 7167
7150#ifdef HAVE_X_I18N 7168#ifdef HAVE_X_I18N
7151 /* Filter events for the current X input method. */ 7169 /* Filter events for the current X input method. */
7152 if (x_filter_event (dpyinfo, &event)) 7170 if (x_filter_event (terminal->display_info.x, &event))
7153 break; 7171 break;
7154#endif 7172#endif
7155 event_found = 1; 7173 event_found = 1;
7156 7174
7157 count += handle_one_xevent (dpyinfo, &event, &finish, hold_quit); 7175 count += handle_one_xevent (terminal->display_info.x,
7176 &event, &finish, hold_quit);
7158 7177
7159 if (finish == X_EVENT_GOTO_OUT) 7178 if (finish == X_EVENT_GOTO_OUT)
7160 goto out; 7179 goto out;
7161 }
7162#endif /* not USE_GTK */
7163 } 7180 }
7164 7181
7165#ifdef USE_GTK 7182#else /* USE_GTK */
7166 7183
7167 /* For GTK we must use the GTK event loop. But XEvents gets passed 7184 /* For GTK we must use the GTK event loop. But XEvents gets passed
7168 to our filter function above, and then to the big event switch. 7185 to our filter function above, and then to the big event switch.
@@ -7473,8 +7490,7 @@ x_draw_window_cursor (w, glyph_row, x, y, cursor_type, cursor_width, on_p, activ
7473 } 7490 }
7474 7491
7475#ifndef XFlush 7492#ifndef XFlush
7476 if (updating_frame != f) 7493 XFlush (FRAME_X_DISPLAY (f));
7477 XFlush (FRAME_X_DISPLAY (f));
7478#endif 7494#endif
7479} 7495}
7480 7496
@@ -7712,6 +7728,8 @@ x_clear_errors (dpy)
7712 x_error_message->string[0] = 0; 7728 x_error_message->string[0] = 0;
7713} 7729}
7714 7730
7731#if 0 /* See comment in unwind_to_catch why calling this is a bad
7732 * idea. --lorentey */
7715/* Close off all unclosed x_catch_errors calls. */ 7733/* Close off all unclosed x_catch_errors calls. */
7716 7734
7717void 7735void
@@ -7720,6 +7738,7 @@ x_fully_uncatch_errors ()
7720 while (x_error_message) 7738 while (x_error_message)
7721 x_uncatch_errors (); 7739 x_uncatch_errors ();
7722} 7740}
7741#endif
7723 7742
7724/* Nonzero if x_catch_errors has been done and not yet canceled. */ 7743/* Nonzero if x_catch_errors has been done and not yet canceled. */
7725 7744
@@ -7785,6 +7804,7 @@ x_connection_closed (dpy, error_message)
7785{ 7804{
7786 struct x_display_info *dpyinfo = x_display_info_for_display (dpy); 7805 struct x_display_info *dpyinfo = x_display_info_for_display (dpy);
7787 Lisp_Object frame, tail; 7806 Lisp_Object frame, tail;
7807 int index = SPECPDL_INDEX ();
7788 7808
7789 error_msg = (char *) alloca (strlen (error_message) + 1); 7809 error_msg = (char *) alloca (strlen (error_message) + 1);
7790 strcpy (error_msg, error_message); 7810 strcpy (error_msg, error_message);
@@ -7796,6 +7816,44 @@ x_connection_closed (dpy, error_message)
7796 the original message here. */ 7816 the original message here. */
7797 x_catch_errors (dpy); 7817 x_catch_errors (dpy);
7798 7818
7819 /* Inhibit redisplay while frames are being deleted. */
7820 specbind (Qinhibit_redisplay, Qt);
7821
7822 if (dpyinfo)
7823 {
7824 /* Protect display from being closed when we delete the last
7825 frame on it. */
7826 dpyinfo->reference_count++;
7827 dpyinfo->terminal->reference_count++;
7828 }
7829
7830 /* First delete frames whose mini-buffers are on frames
7831 that are on the dead display. */
7832 FOR_EACH_FRAME (tail, frame)
7833 {
7834 Lisp_Object minibuf_frame;
7835 minibuf_frame
7836 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
7837 if (FRAME_X_P (XFRAME (frame))
7838 && FRAME_X_P (XFRAME (minibuf_frame))
7839 && ! EQ (frame, minibuf_frame)
7840 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo)
7841 Fdelete_frame (frame, Qt);
7842 }
7843
7844 /* Now delete all remaining frames on the dead display.
7845 We are now sure none of these is used as the mini-buffer
7846 for another frame that we need to delete. */
7847 FOR_EACH_FRAME (tail, frame)
7848 if (FRAME_X_P (XFRAME (frame))
7849 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
7850 {
7851 /* Set this to t so that Fdelete_frame won't get confused
7852 trying to find a replacement. */
7853 FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt;
7854 Fdelete_frame (frame, Qt);
7855 }
7856
7799 /* We have to close the display to inform Xt that it doesn't 7857 /* We have to close the display to inform Xt that it doesn't
7800 exist anymore. If we don't, Xt will continue to wait for 7858 exist anymore. If we don't, Xt will continue to wait for
7801 events from the display. As a consequence, a sequence of 7859 events from the display. As a consequence, a sequence of
@@ -7828,43 +7886,23 @@ x_connection_closed (dpy, error_message)
7828 xg_display_close (dpyinfo->display); 7886 xg_display_close (dpyinfo->display);
7829#endif 7887#endif
7830 7888
7831 /* Indicate that this display is dead. */
7832 if (dpyinfo) 7889 if (dpyinfo)
7833 dpyinfo->display = 0;
7834
7835 /* First delete frames whose mini-buffers are on frames
7836 that are on the dead display. */
7837 FOR_EACH_FRAME (tail, frame)
7838 { 7890 {
7839 Lisp_Object minibuf_frame; 7891 /* Indicate that this display is dead. */
7840 minibuf_frame 7892 dpyinfo->display = 0;
7841 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame))));
7842 if (FRAME_X_P (XFRAME (frame))
7843 && FRAME_X_P (XFRAME (minibuf_frame))
7844 && ! EQ (frame, minibuf_frame)
7845 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame)) == dpyinfo)
7846 Fdelete_frame (frame, Qt);
7847 }
7848 7893
7849 /* Now delete all remaining frames on the dead display. 7894 dpyinfo->reference_count--;
7850 We are now sure none of these is used as the mini-buffer 7895 dpyinfo->terminal->reference_count--;
7851 for another frame that we need to delete. */ 7896 if (dpyinfo->reference_count != 0)
7852 FOR_EACH_FRAME (tail, frame) 7897 /* We have just closed all frames on this display. */
7853 if (FRAME_X_P (XFRAME (frame)) 7898 abort ();
7854 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
7855 {
7856 /* Set this to t so that Fdelete_frame won't get confused
7857 trying to find a replacement. */
7858 FRAME_KBOARD (XFRAME (frame))->Vdefault_minibuffer_frame = Qt;
7859 Fdelete_frame (frame, Qt);
7860 }
7861 7899
7862 if (dpyinfo) 7900 x_delete_display (dpyinfo);
7863 x_delete_display (dpyinfo); 7901 }
7864 7902
7865 x_uncatch_errors (); 7903 x_uncatch_errors ();
7866 7904
7867 if (x_display_list == 0) 7905 if (terminal_list == 0)
7868 { 7906 {
7869 fprintf (stderr, "%s\n", error_msg); 7907 fprintf (stderr, "%s\n", error_msg);
7870 shut_down_emacs (0, 0, Qnil); 7908 shut_down_emacs (0, 0, Qnil);
@@ -7878,6 +7916,7 @@ x_connection_closed (dpy, error_message)
7878 sigunblock (sigmask (SIGALRM)); 7916 sigunblock (sigmask (SIGALRM));
7879 TOTALLY_UNBLOCK_INPUT; 7917 TOTALLY_UNBLOCK_INPUT;
7880 7918
7919 unbind_to (index, Qnil);
7881 clear_waiting_for_input (); 7920 clear_waiting_for_input ();
7882 error ("%s", error_msg); 7921 error ("%s", error_msg);
7883} 7922}
@@ -8088,7 +8127,7 @@ xim_destroy_callback (xim, client_data, call_data)
8088 FOR_EACH_FRAME (tail, frame) 8127 FOR_EACH_FRAME (tail, frame)
8089 { 8128 {
8090 struct frame *f = XFRAME (frame); 8129 struct frame *f = XFRAME (frame);
8091 if (FRAME_X_DISPLAY_INFO (f) == dpyinfo) 8130 if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
8092 { 8131 {
8093 FRAME_XIC (f) = NULL; 8132 FRAME_XIC (f) = NULL;
8094 xic_free_xfontset (f); 8133 xic_free_xfontset (f);
@@ -8187,7 +8226,8 @@ xim_instantiate_callback (display, client_data, call_data)
8187 { 8226 {
8188 struct frame *f = XFRAME (frame); 8227 struct frame *f = XFRAME (frame);
8189 8228
8190 if (FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo) 8229 if (FRAME_X_P (f)
8230 && FRAME_X_DISPLAY_INFO (f) == xim_inst->dpyinfo)
8191 if (FRAME_XIC (f) == NULL) 8231 if (FRAME_XIC (f) == NULL)
8192 { 8232 {
8193 create_frame_xic (f); 8233 create_frame_xic (f);
@@ -9402,8 +9442,8 @@ x_free_frame_resources (f)
9402 XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 9442 XDestroyWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
9403#endif /* !USE_X_TOOLKIT */ 9443#endif /* !USE_X_TOOLKIT */
9404 9444
9405 unload_color (f, f->output_data.x->foreground_pixel); 9445 unload_color (f, FRAME_FOREGROUND_PIXEL (f));
9406 unload_color (f, f->output_data.x->background_pixel); 9446 unload_color (f, FRAME_BACKGROUND_PIXEL (f));
9407 unload_color (f, f->output_data.x->cursor_pixel); 9447 unload_color (f, f->output_data.x->cursor_pixel);
9408 unload_color (f, f->output_data.x->cursor_foreground_pixel); 9448 unload_color (f, f->output_data.x->cursor_foreground_pixel);
9409 unload_color (f, f->output_data.x->border_pixel); 9449 unload_color (f, f->output_data.x->border_pixel);
@@ -10569,6 +10609,7 @@ x_term_init (display_name, xrm_option, resource_name)
10569{ 10609{
10570 int connection; 10610 int connection;
10571 Display *dpy; 10611 Display *dpy;
10612 struct terminal *terminal;
10572 struct x_display_info *dpyinfo; 10613 struct x_display_info *dpyinfo;
10573 XrmDatabase xrdb; 10614 XrmDatabase xrdb;
10574 10615
@@ -10588,14 +10629,21 @@ x_term_init (display_name, xrm_option, resource_name)
10588 char **argv2 = argv; 10629 char **argv2 = argv;
10589 GdkAtom atom; 10630 GdkAtom atom;
10590 10631
10632#ifndef HAVE_GTK_MULTIDISPLAY
10633 if (!EQ (Vinitial_window_system, intern ("x")))
10634 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
10635#endif
10636
10591 if (x_initialized++ > 1) 10637 if (x_initialized++ > 1)
10592 { 10638 {
10639#ifdef HAVE_GTK_MULTIDISPLAY
10593 /* Opening another display. If xg_display_open returns less 10640 /* Opening another display. If xg_display_open returns less
10594 than zero, we are probably on GTK 2.0, which can only handle 10641 than zero, we are probably on GTK 2.0, which can only handle
10595 one display. GTK 2.2 or later can handle more than one. */ 10642 one display. GTK 2.2 or later can handle more than one. */
10596 if (xg_display_open (SDATA (display_name), &dpy) < 0) 10643 if (xg_display_open (SDATA (display_name), &dpy) < 0)
10644#endif
10597 error ("Sorry, this version of GTK can only handle one display"); 10645 error ("Sorry, this version of GTK can only handle one display");
10598 } 10646 }
10599 else 10647 else
10600 { 10648 {
10601 for (argc = 0; argc < NUM_ARGV; ++argc) 10649 for (argc = 0; argc < NUM_ARGV; ++argc)
@@ -10699,6 +10747,8 @@ x_term_init (display_name, xrm_option, resource_name)
10699 dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info)); 10747 dpyinfo = (struct x_display_info *) xmalloc (sizeof (struct x_display_info));
10700 bzero (dpyinfo, sizeof *dpyinfo); 10748 bzero (dpyinfo, sizeof *dpyinfo);
10701 10749
10750 terminal = x_create_terminal (dpyinfo);
10751
10702#ifdef MULTI_KBOARD 10752#ifdef MULTI_KBOARD
10703 { 10753 {
10704 struct x_display_info *share; 10754 struct x_display_info *share;
@@ -10710,30 +10760,30 @@ x_term_init (display_name, xrm_option, resource_name)
10710 SDATA (display_name))) 10760 SDATA (display_name)))
10711 break; 10761 break;
10712 if (share) 10762 if (share)
10713 dpyinfo->kboard = share->kboard; 10763 terminal->kboard = share->terminal->kboard;
10714 else 10764 else
10715 { 10765 {
10716 dpyinfo->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); 10766 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
10717 init_kboard (dpyinfo->kboard); 10767 init_kboard (terminal->kboard);
10718 if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound)) 10768 if (!EQ (XSYMBOL (Qvendor_specific_keysyms)->function, Qunbound))
10719 { 10769 {
10720 char *vendor = ServerVendor (dpy); 10770 char *vendor = ServerVendor (dpy);
10721 UNBLOCK_INPUT; 10771 UNBLOCK_INPUT;
10722 dpyinfo->kboard->Vsystem_key_alist 10772 terminal->kboard->Vsystem_key_alist
10723 = call1 (Qvendor_specific_keysyms, 10773 = call1 (Qvendor_specific_keysyms,
10724 vendor ? build_string (vendor) : empty_unibyte_string); 10774 vendor ? build_string (vendor) : empty_unibyte_string);
10725 BLOCK_INPUT; 10775 BLOCK_INPUT;
10726 } 10776 }
10727 10777
10728 dpyinfo->kboard->next_kboard = all_kboards; 10778 terminal->kboard->next_kboard = all_kboards;
10729 all_kboards = dpyinfo->kboard; 10779 all_kboards = terminal->kboard;
10730 /* Don't let the initial kboard remain current longer than necessary. 10780 /* Don't let the initial kboard remain current longer than necessary.
10731 That would cause problems if a file loaded on startup tries to 10781 That would cause problems if a file loaded on startup tries to
10732 prompt in the mini-buffer. */ 10782 prompt in the mini-buffer. */
10733 if (current_kboard == initial_kboard) 10783 if (current_kboard == initial_kboard)
10734 current_kboard = dpyinfo->kboard; 10784 current_kboard = terminal->kboard;
10735 } 10785 }
10736 dpyinfo->kboard->reference_count++; 10786 terminal->kboard->reference_count++;
10737 } 10787 }
10738#endif 10788#endif
10739 10789
@@ -10748,6 +10798,11 @@ x_term_init (display_name, xrm_option, resource_name)
10748 10798
10749 dpyinfo->display = dpy; 10799 dpyinfo->display = dpy;
10750 10800
10801 /* Set the name of the terminal. */
10802 terminal->name = (char *) xmalloc (SBYTES (display_name) + 1);
10803 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
10804 terminal->name[SBYTES (display_name)] = 0;
10805
10751#if 0 10806#if 0
10752 XSetAfterFunction (x_current_display, x_trace_wire); 10807 XSetAfterFunction (x_current_display, x_trace_wire);
10753#endif /* ! 0 */ 10808#endif /* ! 0 */
@@ -11043,8 +11098,10 @@ x_term_init (display_name, xrm_option, resource_name)
11043 } 11098 }
11044 11099
11045#ifdef HAVE_X_SM 11100#ifdef HAVE_X_SM
11046 /* Only do this for the first display. */ 11101 /* Only do this for the very first display in the Emacs session.
11047 if (!x_session_initialized++) 11102 Ignore X session management when Emacs was first started on a
11103 tty. */
11104 if (terminal->id == 1)
11048 x_session_initialize (dpyinfo); 11105 x_session_initialize (dpyinfo);
11049#endif 11106#endif
11050 11107
@@ -11053,7 +11110,7 @@ x_term_init (display_name, xrm_option, resource_name)
11053 return dpyinfo; 11110 return dpyinfo;
11054} 11111}
11055 11112
11056/* Get rid of display DPYINFO, assuming all frames are already gone, 11113/* Get rid of display DPYINFO, deleting all frames on it,
11057 and without sending any more commands to the X server. */ 11114 and without sending any more commands to the X server. */
11058 11115
11059void 11116void
@@ -11061,6 +11118,20 @@ x_delete_display (dpyinfo)
11061 struct x_display_info *dpyinfo; 11118 struct x_display_info *dpyinfo;
11062{ 11119{
11063 int i; 11120 int i;
11121 struct terminal *t;
11122
11123 /* Close all frames and delete the generic struct terminal for this
11124 X display. */
11125 for (t = terminal_list; t; t = t->next_terminal)
11126 if (t->type == output_x_window && t->display_info.x == dpyinfo)
11127 {
11128 /* Close X session management when we close its display. */
11129 if (t->id == 1 && x_session_have_connection ())
11130 x_session_close();
11131
11132 delete_terminal (t);
11133 break;
11134 }
11064 11135
11065 delete_keyboard_wait_descriptor (dpyinfo->connection); 11136 delete_keyboard_wait_descriptor (dpyinfo->connection);
11066 11137
@@ -11104,10 +11175,6 @@ x_delete_display (dpyinfo)
11104 XrmDestroyDatabase (dpyinfo->xrdb); 11175 XrmDestroyDatabase (dpyinfo->xrdb);
11105#endif 11176#endif
11106#endif 11177#endif
11107#ifdef MULTI_KBOARD
11108 if (--dpyinfo->kboard->reference_count == 0)
11109 delete_kboard (dpyinfo->kboard);
11110#endif
11111#ifdef HAVE_X_I18N 11178#ifdef HAVE_X_I18N
11112 if (dpyinfo->xim) 11179 if (dpyinfo->xim)
11113 xim_close_dpy (dpyinfo); 11180 xim_close_dpy (dpyinfo);
@@ -11189,71 +11256,129 @@ x_activate_timeout_atimer ()
11189extern frame_parm_handler x_frame_parm_handlers[]; 11256extern frame_parm_handler x_frame_parm_handlers[];
11190 11257
11191static struct redisplay_interface x_redisplay_interface = 11258static struct redisplay_interface x_redisplay_interface =
11192{ 11259 {
11193 x_frame_parm_handlers, 11260 x_frame_parm_handlers,
11194 x_produce_glyphs, 11261 x_produce_glyphs,
11195 x_write_glyphs, 11262 x_write_glyphs,
11196 x_insert_glyphs, 11263 x_insert_glyphs,
11197 x_clear_end_of_line, 11264 x_clear_end_of_line,
11198 x_scroll_run, 11265 x_scroll_run,
11199 x_after_update_window_line, 11266 x_after_update_window_line,
11200 x_update_window_begin, 11267 x_update_window_begin,
11201 x_update_window_end, 11268 x_update_window_end,
11202 x_cursor_to, 11269 x_cursor_to,
11203 x_flush, 11270 x_flush,
11204#ifdef XFlush 11271#ifdef XFlush
11205 x_flush, 11272 x_flush,
11206#else 11273#else
11207 0, /* flush_display_optional */ 11274 0, /* flush_display_optional */
11208#endif 11275#endif
11209 x_clear_window_mouse_face, 11276 x_clear_window_mouse_face,
11210 x_get_glyph_overhangs, 11277 x_get_glyph_overhangs,
11211 x_fix_overlapping_area, 11278 x_fix_overlapping_area,
11212 x_draw_fringe_bitmap, 11279 x_draw_fringe_bitmap,
11213 0, /* define_fringe_bitmap */ 11280 0, /* define_fringe_bitmap */
11214 0, /* destroy_fringe_bitmap */ 11281 0, /* destroy_fringe_bitmap */
11215 x_per_char_metric, 11282 x_per_char_metric,
11216 x_encode_char, 11283 x_encode_char,
11217 x_compute_glyph_string_overhangs, 11284 x_compute_glyph_string_overhangs,
11218 x_draw_glyph_string, 11285 x_draw_glyph_string,
11219 x_define_frame_cursor, 11286 x_define_frame_cursor,
11220 x_clear_frame_area, 11287 x_clear_frame_area,
11221 x_draw_window_cursor, 11288 x_draw_window_cursor,
11222 x_draw_vertical_window_border, 11289 x_draw_vertical_window_border,
11223 x_shift_glyphs_for_insert 11290 x_shift_glyphs_for_insert
11224}; 11291 };
11292
11293
11294/* This function is called when the last frame on a display is deleted. */
11295void
11296x_delete_terminal (struct terminal *terminal)
11297{
11298 struct x_display_info *dpyinfo = terminal->display_info.x;
11299 int i;
11300
11301 /* Protect against recursive calls. Fdelete_frame in
11302 delete_terminal calls us back when it deletes our last frame. */
11303 if (terminal->deleted)
11304 return;
11305
11306 BLOCK_INPUT;
11307 /* Free the fonts in the font table. */
11308 for (i = 0; i < dpyinfo->n_fonts; i++)
11309 if (dpyinfo->font_table[i].name)
11310 {
11311 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
11312 }
11313
11314 x_destroy_all_bitmaps (dpyinfo);
11315 XSetCloseDownMode (dpyinfo->display, DestroyAll);
11316
11317#ifdef USE_GTK
11318 xg_display_close (dpyinfo->display);
11319#else
11320#ifdef USE_X_TOOLKIT
11321 XtCloseDisplay (dpyinfo->display);
11322#else
11323 XCloseDisplay (dpyinfo->display);
11324#endif
11325#endif /* ! USE_GTK */
11326
11327 x_delete_display (dpyinfo);
11328 UNBLOCK_INPUT;
11329}
11330
11331
11332static struct terminal *
11333x_create_terminal (struct x_display_info *dpyinfo)
11334{
11335 struct terminal *terminal;
11336
11337 terminal = create_terminal ();
11338
11339 terminal->type = output_x_window;
11340 terminal->display_info.x = dpyinfo;
11341 dpyinfo->terminal = terminal;
11342
11343 /* kboard is initialized in x_term_init. */
11344
11345 terminal->clear_frame_hook = x_clear_frame;
11346 terminal->ins_del_lines_hook = x_ins_del_lines;
11347 terminal->delete_glyphs_hook = x_delete_glyphs;
11348 terminal->ring_bell_hook = XTring_bell;
11349 terminal->reset_terminal_modes_hook = XTreset_terminal_modes;
11350 terminal->set_terminal_modes_hook = XTset_terminal_modes;
11351 terminal->update_begin_hook = x_update_begin;
11352 terminal->update_end_hook = x_update_end;
11353 terminal->set_terminal_window_hook = XTset_terminal_window;
11354 terminal->read_socket_hook = XTread_socket;
11355 terminal->frame_up_to_date_hook = XTframe_up_to_date;
11356 terminal->mouse_position_hook = XTmouse_position;
11357 terminal->frame_rehighlight_hook = XTframe_rehighlight;
11358 terminal->frame_raise_lower_hook = XTframe_raise_lower;
11359 terminal->fullscreen_hook = XTfullscreen_hook;
11360 terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
11361 terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
11362 terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
11363 terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
11364
11365 terminal->delete_frame_hook = x_destroy_window;
11366 terminal->delete_terminal_hook = x_delete_terminal;
11367
11368 terminal->rif = &x_redisplay_interface;
11369 terminal->scroll_region_ok = 1; /* We'll scroll partial frames. */
11370 terminal->char_ins_del_ok = 1;
11371 terminal->line_ins_del_ok = 1; /* We'll just blt 'em. */
11372 terminal->fast_clear_end_of_line = 1; /* X does this well. */
11373 terminal->memory_below_frame = 0; /* We don't remember what scrolls
11374 off the bottom. */
11375
11376 return terminal;
11377}
11225 11378
11226void 11379void
11227x_initialize () 11380x_initialize ()
11228{ 11381{
11229 rif = &x_redisplay_interface;
11230
11231 clear_frame_hook = x_clear_frame;
11232 ins_del_lines_hook = x_ins_del_lines;
11233 delete_glyphs_hook = x_delete_glyphs;
11234 ring_bell_hook = XTring_bell;
11235 reset_terminal_modes_hook = XTreset_terminal_modes;
11236 set_terminal_modes_hook = XTset_terminal_modes;
11237 update_begin_hook = x_update_begin;
11238 update_end_hook = x_update_end;
11239 set_terminal_window_hook = XTset_terminal_window;
11240 read_socket_hook = XTread_socket;
11241 frame_up_to_date_hook = XTframe_up_to_date;
11242 mouse_position_hook = XTmouse_position;
11243 frame_rehighlight_hook = XTframe_rehighlight;
11244 frame_raise_lower_hook = XTframe_raise_lower;
11245 set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
11246 condemn_scroll_bars_hook = XTcondemn_scroll_bars;
11247 redeem_scroll_bar_hook = XTredeem_scroll_bar;
11248 judge_scroll_bars_hook = XTjudge_scroll_bars;
11249 fullscreen_hook = XTfullscreen_hook;
11250
11251 scroll_region_ok = 1; /* we'll scroll partial frames */
11252 char_ins_del_ok = 1;
11253 line_ins_del_ok = 1; /* we'll just blt 'em */
11254 fast_clear_end_of_line = 1; /* X does this well */
11255 memory_below_frame = 0; /* we don't remember what scrolls
11256 off the bottom */
11257 baud_rate = 19200; 11382 baud_rate = 19200;
11258 11383
11259 x_noop_count = 0; 11384 x_noop_count = 0;
@@ -11269,7 +11394,7 @@ x_initialize ()
11269#endif 11394#endif
11270 11395
11271 /* Try to use interrupt input; if we can't, then start polling. */ 11396 /* Try to use interrupt input; if we can't, then start polling. */
11272 Fset_input_mode (Qt, Qnil, Qt, Qnil); 11397 Fset_input_interrupt_mode (Qt);
11273 11398
11274#ifdef USE_X_TOOLKIT 11399#ifdef USE_X_TOOLKIT
11275 XtToolkitInitialize (); 11400 XtToolkitInitialize ();
@@ -11300,9 +11425,11 @@ x_initialize ()
11300 XSetIOErrorHandler (x_io_error_quitter); 11425 XSetIOErrorHandler (x_io_error_quitter);
11301 11426
11302 /* Disable Window Change signals; they are handled by X events. */ 11427 /* Disable Window Change signals; they are handled by X events. */
11428#if 0 /* Don't. We may want to open tty frames later. */
11303#ifdef SIGWINCH 11429#ifdef SIGWINCH
11304 signal (SIGWINCH, SIG_DFL); 11430 signal (SIGWINCH, SIG_DFL);
11305#endif /* SIGWINCH */ 11431#endif /* SIGWINCH */
11432#endif
11306 11433
11307 signal (SIGPIPE, x_connection_signal); 11434 signal (SIGPIPE, x_connection_signal);
11308} 11435}
diff --git a/src/xterm.h b/src/xterm.h
index edb35c199f4..c8b768f6187 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;
@@ -990,7 +992,6 @@ extern int x_had_errors_p P_ ((Display *));
990extern int x_catching_errors P_ ((void)); 992extern int x_catching_errors P_ ((void));
991extern void x_uncatch_errors P_ ((void)); 993extern void x_uncatch_errors P_ ((void));
992extern void x_clear_errors P_ ((Display *)); 994extern void x_clear_errors P_ ((Display *));
993extern void x_fully_uncatch_errors P_ ((void));
994extern void x_set_window_size P_ ((struct frame *, int, int, int)); 995extern void x_set_window_size P_ ((struct frame *, int, int, int));
995extern void x_set_mouse_position P_ ((struct frame *, int, int)); 996extern void x_set_mouse_position P_ ((struct frame *, int, int));
996extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int)); 997extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int));
@@ -1006,6 +1007,7 @@ extern void x_wm_set_size_hint P_ ((struct frame *, long, int));
1006extern void x_wm_set_window_state P_ ((struct frame *, int)); 1007extern void x_wm_set_window_state P_ ((struct frame *, int));
1007extern void x_wm_set_icon_pixmap P_ ((struct frame *, int)); 1008extern void x_wm_set_icon_pixmap P_ ((struct frame *, int));
1008extern void x_delete_display P_ ((struct x_display_info *)); 1009extern void x_delete_display P_ ((struct x_display_info *));
1010extern void x_delete_terminal P_ ((struct terminal *terminal));
1009extern void x_initialize P_ ((void)); 1011extern void x_initialize P_ ((void));
1010extern unsigned long x_copy_color P_ ((struct frame *, unsigned long)); 1012extern unsigned long x_copy_color P_ ((struct frame *, unsigned long));
1011#ifdef USE_X_TOOLKIT 1013#ifdef USE_X_TOOLKIT
@@ -1106,6 +1108,7 @@ extern void widget_store_internal_border P_ ((Widget));
1106extern void x_session_initialize P_ ((struct x_display_info *dpyinfo)); 1108extern void x_session_initialize P_ ((struct x_display_info *dpyinfo));
1107extern int x_session_check_input P_ ((struct input_event *bufp)); 1109extern int x_session_check_input P_ ((struct input_event *bufp));
1108extern int x_session_have_connection P_ ((void)); 1110extern int x_session_have_connection P_ ((void));
1111extern void x_session_close P_ ((void));
1109#endif 1112#endif
1110 1113
1111#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0 1114#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0