aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog393
-rw-r--r--src/buffer.c31
-rw-r--r--src/callproc.c25
-rw-r--r--src/coding.c43
-rw-r--r--src/coding.h22
-rw-r--r--src/conf_post.h9
-rw-r--r--src/cygw32.c33
-rw-r--r--src/cygw32.h14
-rw-r--r--src/dbusbind.c4
-rw-r--r--src/dispnew.c54
-rw-r--r--src/emacs.c38
-rw-r--r--src/font.c57
-rw-r--r--src/fontset.c9
-rw-r--r--src/frame.c247
-rw-r--r--src/frame.h14
-rw-r--r--src/fringe.c6
-rw-r--r--src/indent.c15
-rw-r--r--src/keyboard.c26
-rw-r--r--src/lisp.h32
-rw-r--r--src/lisp.mk6
-rw-r--r--src/makefile.w32-in5
-rw-r--r--src/minibuf.c4
-rw-r--r--src/msdos.c19
-rw-r--r--src/nsfns.m1
-rw-r--r--src/nsterm.m45
-rw-r--r--src/process.c221
-rw-r--r--src/process.h3
-rw-r--r--src/sysdep.c74
-rw-r--r--src/systty.h21
-rw-r--r--src/term.c36
-rw-r--r--src/termhooks.h12
-rw-r--r--src/terminal.c9
-rw-r--r--src/w32fns.c111
-rw-r--r--src/w32proc.c233
-rw-r--r--src/widget.c28
-rw-r--r--src/window.c219
-rw-r--r--src/window.h9
-rw-r--r--src/xdisp.c57
-rw-r--r--src/xfaces.c98
-rw-r--r--src/xfns.c10
-rw-r--r--src/xterm.c4
41 files changed, 1332 insertions, 965 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 835c550b426..37907cd555a 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,384 @@
12012-11-06 Paul Eggert <eggert@cs.ucla.edu>
2
3 Restore some duplicate definitions (Bug#12814).
4 This undoes part of the 2012-11-03 changes. Some people build
5 with plain -g rather than with -g3, and they need the duplicate
6 definitions for .gdbinit to work; see <http://bugs.gnu.org/12814#26>.
7 * lisp.h (GCTYPEBITS, ARRAY_MARK_FLAG, PSEUDOVECTOR_FLAG, VALMASK):
8 Define as macros, as well as as enums or as constants.
9
102012-11-06 Jan Djärv <jan.h.d@swipnet.se>
11
12 * nsterm.m (convert_ns_to_X_keysym, keyDown:): Add NSNumericPadKeyMask
13 to keypad keys (Bug#12816).
14
152012-11-06 Paul Eggert <eggert@cs.ucla.edu>
16
17 Minor adjustments of recently-changed frame functions.
18 * buffer.c (Fbuffer_list): Omit CHECK_FRAME, since arg is already
19 known to be a frame (we're in the FRAMEP branch).
20 * lisp.h (Qframep): Remove decl. frame.h declares this.
21 * window.c (quad): Args are of type EMACS_INT, not ptrdiff_t,
22 since they're meant for Lisp fixnum values.
23
242012-11-06 Dmitry Antipov <dmantipov@yandex.ru>
25
26 * window.c (Fwindow_combination_limit): Revert to the only
27 required argument and adjust docstring as suggested in
28 http://lists.gnu.org/archive/html/emacs-diffs/2012-11/msg01082.html
29 by Martin Rudalics <rudalics@gmx.at>.
30
312012-11-06 Dmitry Antipov <dmantipov@yandex.ru>
32
33 Widely used frame validity and checking functions.
34 * frame.h (decode_live_frame, decode_any_frame): Add prototypes.
35 * frame.c (decode_live_frame, decode_any_frame): New functions.
36 (delete_frame, Fredirect_frame_focus, Fframe_parameters)
37 (Fframe_parameter, Fframe_char_height, Fframe_char_width)
38 (Fframe_pixel_height, Fframe_pixel_width, Ftool_bar_pixel_width)
39 (Fframe_pointer_visible_p): Use decode_any_frame.
40 (Fmake_frame_visible, Fmake_frame_invisible, Ficonify_frame)
41 (Fraise_frame, Flower_frame, Fmodify_frame_parameters)
42 (Fset_frame_height, Fset_frame_width): Use decode_live_frame.
43 (Fframe_focus): Likewise. Allow zero number of arguments.
44 Adjust docstring.
45 (frame_buffer_list, frame_buffer_predicate): Remove.
46 * lisp.h (frame_buffer_predicate): Remove prototype.
47 * buffer.c (Fother_buffer): Use decode_any_frame.
48 * xdisp.c (Ftool_bar_lines_needed): Likewise.
49 * xfaces.c (Fcolor_gray_p, Fcolor_supported_p): Likewise.
50 * font.c (Ffont_face_attributes, Ffont_family_list, Fopen_font)
51 (Fclose_font, Ffont_info): Use decode_live_frame.
52 * fontset.c (check_fontset_name): Likewise.
53 * terminal.c (Fframe_terminal): Likewise.
54 * w32fns.c (check_x_frame): Likewise.
55 * window.c (Fminibuffer_window, Fwindow_at)
56 (Fcurrent_window_configuration): Likewise.
57 (Frun_window_configuration_change_hook, Fwindow_resize_apply):
58 Likewise. Allow zero number of arguments. Adjust docstring.
59 * dispnew.c (Fredraw_frame): Likewise.
60 * xfaces.c (frame_or_selected_frame): Remove.
61 (Fx_list_fonts, Finternal_get_lisp_face_attribute, Fface_font)
62 (Finternal_lisp_face_equal_p, Finternal_lisp_face_empty_p)
63 (Fframe_face_alist): Use decode_live_frame.
64 * xfns.c (check_x_frame): Likewise.
65
662012-11-06 Dmitry Antipov <dmantipov@yandex.ru>
67
68 * window.c (quad): New function.
69 (Fwindow_edges, Fwindow_pixel_edges, Fwindow_inside_edges)
70 (Fwindow_absolute_pixel_edges, Fwindow_inside_absolute_pixel_edges)
71 (Fwindow_inside_pixel_edges, Fpos_visible_in_window_p)
72 (Fwindow_line_height): Use it.
73 (Fwindow_fringes): Use list3.
74 (Fwindow_scroll_bars): Use list4.
75 (Fwindow_frame, Fwindow_top_child, Fwindow_left_child)
76 (Fwindow_combination_limit): Allow zero number of arguments.
77
782012-11-05 Eli Zaretskii <eliz@gnu.org>
79
80 * makefile.w32-in ($(BLD)/w32fns.$(O)): Depend on $(NT_INC)/unistd.h.
81
82 * w32fns.c: Include unistd.h, to avoid compiler warnings on Cygwin.
83 (emacs_abort) [CYGWIN]: Don't call _open_osfhandle; instead, use
84 file descriptor 2 for standard error. (Bug#12805)
85
862012-11-05 Chong Yidong <cyd@gnu.org>
87
88 * process.c (wait_reading_process_output): Revert previous change.
89
902012-11-05 Paul Eggert <eggert@cs.ucla.edu>
91
92 Assume at least POSIX.1-1988 for getpgrp, setpgid, setsid (Bug#12800).
93 This removes code that has been obsolete since around 1990.
94 * callproc.c (Fcall_process):
95 * emacs.c (main):
96 * process.c (create_process):
97 * term.c (dissociate_if_controlling_tty):
98 Assume setsid exists.
99 * callproc.c (child_setup): Assume setpgid exists and behaves as
100 per POSIX.1-1988 or later.
101 * conf_post.h (setpgid) [!HAVE_SETPGID]: Remove.
102 * emacs.c (shut_down_emacs):
103 * sysdep.c (sys_suspend, init_foreground_group):
104 Assume getpgrp behaves as per POSIX.1-1998 or later.
105 * msdos.c (setpgrp): Remove.
106 (tcgetpgrp, setpgid, setsid): New functions.
107 * systty.h (EMACS_GETPGRP): Remove. All callers now use getpgrp.
108 * term.c (no_controlling_tty): Remove; unused.
109 * w32proc.c (setpgrp): Remove.
110 (setsid, tcgetpgrp): New functions.
111
112 Simplify by assuming __fpending.
113 * dispnew.c: Include <fpending.h>, not <stdio_ext.h>.
114 (update_frame_1): Use __fpending, not PENDING_OUTPUT_COUNT.
115 Do not assume that __fpending's result fits in int.
116
1172012-11-04 Paul Eggert <eggert@cs.ucla.edu>
118
119 Remove EMACS_OUTQSIZE+sleep hack.
120 * dispnew.c (update_frame_1): Remove hack for terminals slower
121 than 2400 bps, which throttled Emacs by having it sleep. This
122 code hasn't worked since at least 2007, when the multi-tty stuff
123 was added, and anyway those old terminals are long dead.
124 * systty.h (EMACS_OUTQSIZE): Remove; unused. The macro isn't used even
125 without the dispnew.c change, as dispnew.c doesn't include systty.h.
126
127 Fix data-loss with --version (Bug#9574).
128 * emacs.c (close_output_streams): Use strerror, not emacs_strerror,
129 as we can't assume that emacs_strerror is initialized, and strerror
130 is good enough here.
131 (main): Invoke atexit earlier, to catch earlier instances of
132 sending data to stdout and exiting, e.g., "emacs --version >/dev/full".
133
1342012-11-04 Michael Marchionna <tralfaz@pacbell.net>
135
136 * nsterm.m: Add NSClearLineFunctionKey and keypad keys (Bug#8680).
137 (keyDown): Remap keypad keys to X11 virtual key codes.
138
1392012-11-03 Paul Eggert <eggert@cs.ucla.edu>
140
141 Fix data-loss with --batch (Bug#9574).
142 * emacs.c: Include <close-stream.h>.
143 (close_output_streams): New function.
144 (main): Pass it to atexit, so that Emacs closes stdout and stderr
145 and handles errors appropriately.
146 (Fkill_emacs): Don't worry about flushing, as close_output_stream
147 does that now.
148
149 Fix a race condition that causes Emacs to mess up glib (Bug#8855).
150 The symptom is a diagnostic "GLib-WARNING **: In call to
151 g_spawn_sync(), exit status of a child process was requested but
152 SIGCHLD action was set to SIG_IGN and ECHILD was received by
153 waitpid(), so exit status can't be returned." The diagnostic
154 is partly wrong, as the SIGCHLD action is not set to SIG_IGN.
155 The real bug is a race condition between Emacs and glib: Emacs
156 does a waitpid (-1, ...) and reaps glib's subprocess by mistake,
157 so that glib can't find it. Work around the bug by invoking
158 waitpid only on subprocesses that Emacs itself creates.
159 * process.c (create_process, record_child_status_change):
160 Don't use special value -1 in pid field, as the caller now must
161 know the pid rather than having the callee infer it. The
162 inference was sometimes incorrect anyway, due to another race.
163 (create_process): Set new 'alive' member if child is created.
164 (process_status_retrieved): New function.
165 (record_child_status_change): Use it.
166 Accept negative 1st argument, which means to wait for the
167 processes that Emacs already knows about. Move special-case code
168 for DOS_NT (which lacks WNOHANG) here, from caller. Keep track of
169 processes that have already been waited for, by testing and
170 clearing new 'alive' member.
171 (CAN_HANDLE_MULTIPLE_CHILDREN): Remove, as record_child_status_change
172 now does this internally.
173 (handle_child_signal): Let record_child_status_change do all
174 the work, since we do not want to reap all exited child processes,
175 only the child processes that Emacs itself created.
176 * process.h (Lisp_Process): New boolean member 'alive'.
177
178 Omit duplicate definitions no longer needed with gcc -g3.
179 * lisp.h (GCTYPEBITS, GCALIGNMENT, ARRAY_MARK_FLAG, PSEUDOVECTOR_FLAG)
180 (VALMASK, MOST_POSITIVE_FIXNUM, MOST_NEGATIVE_FIXNUM):
181 Define only as macros. There's no longer any need to also define
182 these symbols as enums or as constants, since we now assume
183 gcc -g3 when debugging.
184
1852012-11-03 Eli Zaretskii <eliz@gnu.org>
186
187 * lisp.mk: Adjust comments to the fact that term/internal is now
188 loaded from loadup.el.
189
190 * msdos.c (msdos_abort): Rename from emacs_abort, and make static.
191 (msdos_fatal_signal): New function.
192 (XMenuActivate): Adjust the call to kbd_buffer_events_waiting to
193 its argument list.
194
195 * conf_post.h (_GL_EXECINFO_INLINE) [MSDOS]: Define to "inline"
196 for GCC versions before 4.
197 (emacs_raise): Define to call msdos_fatal_signal.
198
199 * xdisp.c (init_from_display_pos): Fix initialization of the bidi
200 iterator when starting in the middle of a display or overlay
201 string. (Bug#12745)
202
2032012-11-03 Chong Yidong <cyd@gnu.org>
204
205 * process.c (wait_reading_process_output): Clean up the last
206 change.
207
2082012-11-03 Jim Paris <jim@jtan.com> (tiny change)
209
210 * process.c (wait_reading_process_output): Avoid a race condition
211 with SIGIO delivery (Bug#11536).
212
2132012-11-03 Chong Yidong <cyd@gnu.org>
214
215 * buffer.c (cursor_type): Untabify docstring.
216
2172012-11-03 Dmitry Antipov <dmantipov@yandex.ru>
218
219 * frame.h (struct frame): Drop can_have_scroll_bars member
220 which is meaningless for a long time. Adjust comments.
221 (FRAME_CAN_HAVE_SCROLL_BARS): Remove.
222 * frame.c, nsfns.m, term.c, w32fns.c, xfns.c: Adjust users.
223
2242012-11-03 Dmitry Antipov <dmantipov@yandex.ru>
225
226 * window.c (decode_next_window_args): Update window arg after
227 calling decode_live_window and so fix crash reported at
228 http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00035.html
229 by Juanma Barranquero <lekktu@gmail.com>.
230 (Fwindow_body_width, Fwindow_body_height): Simplify a bit.
231 * font.c (Ffont_at): Likewise.
232
2332012-11-01 Jan Djärv <jan.h.d@swipnet.se>
234
235 * widget.c (resize_cb): New function.
236 (EmacsFrameRealize): Add resize_cb as event handler (Bug#12733).
237 (EmacsFrameResize): Check if all is up to date before changing frame
238 size.
239
2402012-11-02 Eli Zaretskii <eliz@gnu.org>
241
242 Implement backtrace output for fatal errors on MS-Windows.
243 * w32fns.c (CaptureStackBackTrace_proc): New typedef.
244 (BACKTRACE_LIMIT_MAX): New macro.
245 (w32_backtrace): New function.
246 (emacs_abort): Use w32_backtrace when the user chooses not to
247 attach a debugger. Update the text of the abort dialog.
248
2492012-11-02 Dmitry Antipov <dmantipov@yandex.ru>
250
251 Window-related stuff cleanup here and there.
252 * dispnew.c (Finternal_show_cursor, Finternal_show_cursor_p):
253 Use decode_any_window.
254 * fringe.c (Ffringe_bitmaps_at_pos): Likewise.
255 * xdisp.c (Fformat_mode_line): Likewise.
256 * font.c (Ffont_at): Use decode_live_window.
257 * indent.c (Fcompute_motion, Fvertical_motion): Likewise.
258 * window.c (decode_next_window_args): Likewise.
259 (decode_any_window): Remove static.
260 * window.h (decode_any_window): Add prototype.
261 * lisp.h (CHECK_VALID_WINDOW, CHECK_LIVE_WINDOW): Move from here...
262 * window.h: ...to here, redefine via WINDOW_VALID_P and WINDOW_LIVE_P,
263 respectively.
264
2652012-11-02 Dmitry Antipov <dmantipov@yandex.ru>
266
267 Remove pad from struct input_event.
268 * termhooks.h (struct input_event): Remove padding field.
269 Adjust comment.
270 * keyboard.c (event_to_kboard): Simplify because frame_or_window
271 member is never cons for a long time. Adjust comment.
272 (mark_kboards): Adjust because SELECTION_REQUEST_EVENT and
273 SELECTION_CLEAR_EVENT has no Lisp_Objects to mark. Add comment.
274 * xterm.c (handle_one_xevent): Do not initialize frame_or_window
275 field of SELECTION_REQUEST_EVENT and SELECTION_CLEAR_EVENT.
276
2772012-11-01 Eli Zaretskii <eliz@gnu.org>
278
279 * w32proc.c (getpgrp, setpgid): New functions. (Bug#12776)
280
2812012-10-31 Paul Eggert <eggert@cs.ucla.edu>
282
283 Fix crash when using Emacs as commit editor for git (Bug#12697).
284 * callproc.c (setpgrp): Remove macro, as we now use setpgid
285 and it is configured in conf_post.h.
286 (Fcall_process): Don't invoke both setsid and setpgid; the former
287 is enough, if it exists.
288 * callproc.c (Fcall_process, child_setup):
289 * process.c (create_process): Use setpgid.
290 * conf_post.h (setpgid) [!HAVE_SETPGID]: New macro, which substitutes
291 for the real thing.
292 * dispnew.c (init_display): Initialize the foreground group
293 if we are running a tty display.
294 * emacs.c (main): Do not worry about setpgrp; init_display does it now.
295 * lisp.h (init_foreground_group): New decl.
296 * sysdep.c (inherited_pgroup): New static var.
297 (init_foreground_group, tcsetpgrp_without_stopping)
298 (narrow_foreground_group, widen_foreground_group): New functions.
299 (init_sys_modes): Narrow foreground group.
300 (reset_sys_modes): Widen foreground group.
301
3022012-10-31 Michael Albinus <michael.albinus@gmx.de>
303
304 * dbusbind.c: Fix cut'n'waste error. Use HAVE_DBUS_VALIDATE_INTERFACE.
305
3062012-10-31 Martin Rudalics <rudalics@gmx.at>
307
308 * minibuf.c (read_minibuf): Restore current buffer since
309 choose_minibuf_frame calling Fset_frame_selected_window may
310 change it (Bug#12766).
311
3122012-10-30 Jan Djärv <jan.h.d@swipnet.se>
313
314 * frame.c (Fframe_pixel_height): Fix documentation (Bug#12733).
315
3162012-10-30 Kenichi Handa <handa@gnu.org>
317
318 * font.c (Ffont_at): If WINDOW is specified and it is not
319 displaying the current buffer, signal an error.
320
3212012-10-29 Daniel Colascione <dancol@dancol.org>
322
323 * cygw32.h, cygw32.c (Qutf_16le, from_unicode, to_unicode): In
324 preparation for fixing bug#12739, move these functions from
325 here...
326
327 * coding.h, coding.c: ... to here, and compile them only when
328 WINDOWSNT or CYGWIN. Moving these functions out of cygw32 proper
329 lets us write cygw32-agnostic code for the HAVE_NTGUI case.
330
3312012-10-28 Eli Zaretskii <eliz@gnu.org>
332
333 * w32proc.c (TIMER_TICKS_PER_SEC): New macro.
334 (timer_loop, getitimer, setitimer): Use it instead of
335 CLOCKS_PER_SEC, which is no longer pertinent, since we don't use
336 'clock'.
337 (w32_get_timer_time): Use 10*TIMER_TICKS_PER_SEC instead of a
338 literal 10000.
339
3402012-10-28 Jan Djärv <jan.h.d@swipnet.se>
341
342 * nsterm.m (NO_APPDEFINED_DATA): New define.
343 (last_appdefined_event_data): New variable
344 (last_appdefined_event): Remove.
345 (ns_select): Initialize t from last_appdefined_event_data instead
346 of [last_appdefined_event data1].
347 (sendEvent:): Save [theEvent data1] to last_appdefined_event_data,
348 remove last_appdefined_event (Bug#12698).
349
3502012-10-28 Stefan Monnier <monnier@iro.umontreal.ca>
351
352 * frame.c (x_set_font): Catch internal error.
353
3542012-10-27 Eli Zaretskii <eliz@gnu.org>
355
356 Avoid overflow in w32 implementation of interval timers.
357 When possible, for ITIMER_PROF count only times the main thread
358 actually executes.
359 * w32proc.c <struct itimer_data>: 'expire' and 'reload' are now
360 'volatile ULONGLONG' types. All the other data which was
361 previously clock_t is now ULONGLONG. 'terminate' is 'volatile int'.
362 (GetThreadTimes_Proc): New typedef.
363 (w32_get_timer_time): New function, returns a suitable time value
364 for the timer.
365 (timer_loop): Enter critical section when accessing ULONGLONG
366 values of the itimer_data struct, as these accesses are no longer
367 atomic. Call 'w32_get_timer_time' instead of 'clock'.
368 Remove unused variable.
369 (init_timers): Initialize s_pfn_Get_Thread_Times.
370 (start_timer_thread): Don't assign itimer->caller_thread here.
371 (getitimer): Assign itimer->caller_thread here.
372 (setitimer): Always call getitimer to get the value of ticks_now.
373 (sys_spawnve): Avoid compiler warning about format mismatch.
374
3752012-10-26 Eli Zaretskii <eliz@gnu.org>
376
377 * w32fns.c (w32_wnd_proc) <WM_MOUSEMOVE>: Don't enable tracking of
378 mouse movement events if the menu bar is active. This avoids
379 producing a busy "hour-glass" cursor by Windows if the mouse
380 pointer is positioned over a tooltip shown for some menu item.
381
12012-10-25 Paul Eggert <eggert@cs.ucla.edu> 3822012-10-25 Paul Eggert <eggert@cs.ucla.edu>
2 383
3 Don't assume process IDs fit in int. 384 Don't assume process IDs fit in int.
@@ -64,8 +445,8 @@
64 445
652012-10-19 Eli Zaretskii <eliz@gnu.org> 4462012-10-19 Eli Zaretskii <eliz@gnu.org>
66 447
67 * puresize.h (BASE_PURESIZE): Bump the base value to 1700000. See 448 * puresize.h (BASE_PURESIZE): Bump the base value to 1700000.
68 http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00593.html 449 See http://lists.gnu.org/archive/html/emacs-devel/2012-10/msg00593.html
69 for the reasons. 450 for the reasons.
70 451
71 * alloc.c (NSTATICS): Decrease to 0x800. 452 * alloc.c (NSTATICS): Decrease to 0x800.
@@ -523,7 +904,7 @@
523 now a supported configuration. 904 now a supported configuration.
524 905
525 * Makefile.in: consolidate image variables into LIBIMAGE; add 906 * Makefile.in: consolidate image variables into LIBIMAGE; add
526 W32_OBJ and W32_LIBS. Compile new files. 907 W32_OBJ and W32_LIBS. Compile new files.
527 908
528 * conf_post.h: 909 * conf_post.h:
529 (_DebPrint) declare tracing facility for W32 debugging. We need 910 (_DebPrint) declare tracing facility for W32 debugging. We need
@@ -684,8 +1065,8 @@
684 (ns_clear_frame_area): Remove resize handle code. 1065 (ns_clear_frame_area): Remove resize handle code.
685 1066
686 * nsfns.m (ns_in_resize): Remove. 1067 * nsfns.m (ns_in_resize): Remove.
687 (x_set_icon_name, ns_set_name, ns_set_name_as_filename): Remove 1068 (x_set_icon_name, ns_set_name, ns_set_name_as_filename):
688 ns_in_resize check. 1069 Remove ns_in_resize check.
689 1070
6902012-10-07 Paul Eggert <eggert@cs.ucla.edu> 10712012-10-07 Paul Eggert <eggert@cs.ucla.edu>
691 1072
@@ -6006,7 +6387,7 @@
6006 * lisp.h (make_formatted_string): New prototype. 6387 * lisp.h (make_formatted_string): New prototype.
6007 * alloc.c (make_formatted_string): New function. 6388 * alloc.c (make_formatted_string): New function.
6008 * buffer.c (Fgenerate_new_buffer_name): Use it. 6389 * buffer.c (Fgenerate_new_buffer_name): Use it.
6009 * dbus.c (syms_of_dbusbind): Likewise. 6390 * dbusbind.c (syms_of_dbusbind): Likewise.
6010 * editfns.c (Fcurrent_time_zone): Likewise. 6391 * editfns.c (Fcurrent_time_zone): Likewise.
6011 * filelock.c (get_boot_time): Likewise. 6392 * filelock.c (get_boot_time): Likewise.
6012 * frame.c (make_terminal_frame, set_term_frame_name) 6393 * frame.c (make_terminal_frame, set_term_frame_name)
diff --git a/src/buffer.c b/src/buffer.c
index 0b3dde27968..bb69675346a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -406,7 +406,6 @@ followed by the rest of the buffers. */)
406 Lisp_Object framelist, prevlist, tail; 406 Lisp_Object framelist, prevlist, tail;
407 Lisp_Object args[3]; 407 Lisp_Object args[3];
408 408
409 CHECK_FRAME (frame);
410 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); 409 framelist = Fcopy_sequence (XFRAME (frame)->buffer_list);
411 prevlist = Fnreverse (Fcopy_sequence 410 prevlist = Fnreverse (Fcopy_sequence
412 (XFRAME (frame)->buried_buffer_list)); 411 (XFRAME (frame)->buried_buffer_list));
@@ -1543,17 +1542,11 @@ list first, followed by the list of all buffers. If no other buffer
1543exists, return the buffer `*scratch*' (creating it if necessary). */) 1542exists, return the buffer `*scratch*' (creating it if necessary). */)
1544 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) 1543 (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
1545{ 1544{
1546 Lisp_Object tail, buf, pred; 1545 struct frame *f = decode_any_frame (frame);
1547 Lisp_Object notsogood = Qnil; 1546 Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
1547 Lisp_Object buf, notsogood = Qnil;
1548 1548
1549 if (NILP (frame))
1550 frame = selected_frame;
1551
1552 CHECK_FRAME (frame);
1553
1554 pred = frame_buffer_predicate (frame);
1555 /* Consider buffers that have been seen in the frame first. */ 1549 /* Consider buffers that have been seen in the frame first. */
1556 tail = XFRAME (frame)->buffer_list;
1557 for (; CONSP (tail); tail = XCDR (tail)) 1550 for (; CONSP (tail); tail = XCDR (tail))
1558 { 1551 {
1559 buf = XCAR (tail); 1552 buf = XCAR (tail);
@@ -2109,7 +2102,7 @@ set_buffer_internal_1 (register struct buffer *b)
2109 return; 2102 return;
2110 2103
2111 BUFFER_CHECK_INDIRECTION (b); 2104 BUFFER_CHECK_INDIRECTION (b);
2112 2105
2113 old_buf = current_buffer; 2106 old_buf = current_buffer;
2114 current_buffer = b; 2107 current_buffer = b;
2115 last_known_column_point = -1; /* invalidate indentation cache */ 2108 last_known_column_point = -1; /* invalidate indentation cache */
@@ -6210,15 +6203,15 @@ is a member of the list. */);
6210 doc: /* Cursor to use when this buffer is in the selected window. 6203 doc: /* Cursor to use when this buffer is in the selected window.
6211Values are interpreted as follows: 6204Values are interpreted as follows:
6212 6205
6213 t use the cursor specified for the frame 6206 t use the cursor specified for the frame
6214 nil don't display a cursor 6207 nil don't display a cursor
6215 box display a filled box cursor 6208 box display a filled box cursor
6216 hollow display a hollow box cursor 6209 hollow display a hollow box cursor
6217 bar display a vertical bar cursor with default width 6210 bar display a vertical bar cursor with default width
6218 (bar . WIDTH) display a vertical bar cursor with width WIDTH 6211 (bar . WIDTH) display a vertical bar cursor with width WIDTH
6219 hbar display a horizontal bar cursor with default height 6212 hbar display a horizontal bar cursor with default height
6220 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT 6213 (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
6221 ANYTHING ELSE display a hollow box cursor 6214 ANYTHING ELSE display a hollow box cursor
6222 6215
6223When the buffer is displayed in a non-selected window, the 6216When the buffer is displayed in a non-selected window, the
6224cursor's appearance is instead controlled by the variable 6217cursor's appearance is instead controlled by the variable
diff --git a/src/callproc.c b/src/callproc.c
index b33882e54c2..c7bbe36e605 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -64,13 +64,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
64#include "nsterm.h" 64#include "nsterm.h"
65#endif 65#endif
66 66
67#ifdef HAVE_SETPGID
68#if !defined (USG)
69#undef setpgrp
70#define setpgrp setpgid
71#endif
72#endif
73
74/* Pattern used by call-process-region to make temp files. */ 67/* Pattern used by call-process-region to make temp files. */
75static Lisp_Object Vtemp_file_name_pattern; 68static Lisp_Object Vtemp_file_name_pattern;
76 69
@@ -618,14 +611,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
618 { 611 {
619 if (fd[0] >= 0) 612 if (fd[0] >= 0)
620 emacs_close (fd[0]); 613 emacs_close (fd[0]);
621#ifdef HAVE_SETSID 614
622 setsid (); 615 setsid ();
623#endif
624#if defined (USG)
625 setpgrp ();
626#else
627 setpgrp (pid, pid);
628#endif /* USG */
629 616
630 /* Emacs ignores SIGPIPE, but the child should not. */ 617 /* Emacs ignores SIGPIPE, but the child should not. */
631 signal (SIGPIPE, SIG_DFL); 618 signal (SIGPIPE, SIG_DFL);
@@ -1295,15 +1282,7 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1295 if (err != in && err != out) 1282 if (err != in && err != out)
1296 emacs_close (err); 1283 emacs_close (err);
1297 1284
1298#if defined (USG) 1285 setpgid (0, 0);
1299#ifndef SETPGRP_RELEASES_CTTY
1300 setpgrp (); /* No arguments but equivalent in this case */
1301#endif
1302#else /* not USG */
1303 setpgrp (pid, pid);
1304#endif /* not USG */
1305
1306 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1307 tcsetpgrp (0, pid); 1286 tcsetpgrp (0, pid);
1308 1287
1309 /* execvp does not accept an environment arg so the only way 1288 /* execvp does not accept an environment arg so the only way
diff --git a/src/coding.c b/src/coding.c
index 7628a9fbf2e..56202e4861d 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -343,6 +343,10 @@ Lisp_Object Qcoding_system_p, Qcoding_system_error;
343Lisp_Object Qemacs_mule, Qraw_text; 343Lisp_Object Qemacs_mule, Qraw_text;
344Lisp_Object Qutf_8_emacs; 344Lisp_Object Qutf_8_emacs;
345 345
346#if defined (WINDOWSNT) || defined (CYGWIN)
347static Lisp_Object Qutf_16le;
348#endif
349
346/* Coding-systems are handed between Emacs Lisp programs and C internal 350/* Coding-systems are handed between Emacs Lisp programs and C internal
347 routines by the following three variables. */ 351 routines by the following three variables. */
348/* Coding system to be used to encode text for terminal display when 352/* Coding system to be used to encode text for terminal display when
@@ -7971,6 +7975,40 @@ preferred_coding_system (void)
7971 return CODING_ID_NAME (id); 7975 return CODING_ID_NAME (id);
7972} 7976}
7973 7977
7978#if defined (WINDOWSNT) || defined (CYGWIN)
7979
7980Lisp_Object
7981from_unicode (Lisp_Object str)
7982{
7983 CHECK_STRING (str);
7984 if (!STRING_MULTIBYTE (str) &&
7985 SBYTES (str) & 1)
7986 {
7987 str = Fsubstring (str, make_number (0), make_number (-1));
7988 }
7989
7990 return code_convert_string_norecord (str, Qutf_16le, 0);
7991}
7992
7993wchar_t *
7994to_unicode (Lisp_Object str, Lisp_Object *buf)
7995{
7996 *buf = code_convert_string_norecord (str, Qutf_16le, 1);
7997 /* We need to make a another copy (in addition to the one made by
7998 code_convert_string_norecord) to ensure that the final string is
7999 _doubly_ zero terminated --- that is, that the string is
8000 terminated by two zero bytes and one utf-16le null character.
8001 Because strings are already terminated with a single zero byte,
8002 we just add one additional zero. */
8003 str = make_uninit_string (SBYTES (*buf) + 1);
8004 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
8005 SDATA (str) [SBYTES (*buf)] = '\0';
8006 *buf = str;
8007 return WCSDATA (*buf);
8008}
8009
8010#endif /* WINDOWSNT || CYGWIN */
8011
7974 8012
7975#ifdef emacs 8013#ifdef emacs
7976/*** 8. Emacs Lisp library functions ***/ 8014/*** 8. Emacs Lisp library functions ***/
@@ -10284,6 +10322,11 @@ syms_of_coding (void)
10284 DEFSYM (Qutf_8, "utf-8"); 10322 DEFSYM (Qutf_8, "utf-8");
10285 DEFSYM (Qutf_8_emacs, "utf-8-emacs"); 10323 DEFSYM (Qutf_8_emacs, "utf-8-emacs");
10286 10324
10325#if defined (WINDOWSNT) || defined (CYGWIN)
10326 /* No, not utf-16-le: that one has a BOM. */
10327 DEFSYM (Qutf_16le, "utf-16le");
10328#endif
10329
10287 DEFSYM (Qutf_16, "utf-16"); 10330 DEFSYM (Qutf_16, "utf-16");
10288 DEFSYM (Qbig, "big"); 10331 DEFSYM (Qbig, "big");
10289 DEFSYM (Qlittle, "little"); 10332 DEFSYM (Qlittle, "little");
diff --git a/src/coding.h b/src/coding.h
index 989552bf667..192be58f083 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -701,6 +701,28 @@ extern void encode_coding_object (struct coding_system *,
701 Lisp_Object, ptrdiff_t, ptrdiff_t, 701 Lisp_Object, ptrdiff_t, ptrdiff_t,
702 ptrdiff_t, ptrdiff_t, Lisp_Object); 702 ptrdiff_t, ptrdiff_t, Lisp_Object);
703 703
704#if defined (WINDOWSNT) || defined (CYGWIN)
705
706/* These functions use Lisp string objects to store the UTF-16LE
707 strings that modern versions of Windows expect. These strings are
708 not particularly useful to Lisp, and all Lisp strings should be
709 native Emacs multibyte. */
710
711/* Access the wide-character string stored in a Lisp string object. */
712#define WCSDATA(x) ((wchar_t *) SDATA (x))
713
714/* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
715 string, and store it in *BUF. BUF may safely point to STR on entry. */
716extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
717
718/* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
719 object, to a multi-byte Emacs string and return it. This function
720 calls code_convert_string_norecord internally and has all its
721 failure modes. STR itself is not modified. */
722extern Lisp_Object from_unicode (Lisp_Object str);
723
724#endif /* WINDOWSNT || CYGWIN */
725
704/* Macros for backward compatibility. */ 726/* Macros for backward compatibility. */
705 727
706#define decode_coding_region(coding, from, to) \ 728#define decode_coding_region(coding, from, to) \
diff --git a/src/conf_post.h b/src/conf_post.h
index aa008107ba6..66390ddf103 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -110,8 +110,17 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */
110#else 110#else
111# define lstat stat 111# define lstat stat
112#endif 112#endif
113/* The "portable" definition of _GL_INLINE on config.h does not work
114 with DJGPP GCC 3.4.4: it causes unresolved externals in sysdep.c,
115 although lib/execinfo.h is included and the inline functions there
116 are visible. */
117#if __GNUC__ < 4
118# define _GL_EXECINFO_INLINE inline
119#endif
113/* End of gnulib-related stuff. */ 120/* End of gnulib-related stuff. */
114 121
122#define emacs_raise(sig) msdos_fatal_signal (sig)
123
115/* Define one of these for easier conditionals. */ 124/* Define one of these for easier conditionals. */
116#ifdef HAVE_X_WINDOWS 125#ifdef HAVE_X_WINDOWS
117/* We need a little extra space, see ../../lisp/loadup.el and the 126/* We need a little extra space, see ../../lisp/loadup.el and the
diff --git a/src/cygw32.c b/src/cygw32.c
index 8f63461da2a..54f2076a891 100644
--- a/src/cygw32.c
+++ b/src/cygw32.c
@@ -22,7 +22,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#include "buffer.h" 22#include "buffer.h"
23#include <unistd.h> 23#include <unistd.h>
24#include <fcntl.h> 24#include <fcntl.h>
25static Lisp_Object Qutf_16le;
26 25
27static Lisp_Object 26static Lisp_Object
28fchdir_unwind (Lisp_Object dir_fd) 27fchdir_unwind (Lisp_Object dir_fd)
@@ -107,36 +106,6 @@ conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
107 return unbind_to (count, DECODE_FILE (converted)); 106 return unbind_to (count, DECODE_FILE (converted));
108} 107}
109 108
110Lisp_Object
111from_unicode (Lisp_Object str)
112{
113 CHECK_STRING (str);
114 if (!STRING_MULTIBYTE (str) &&
115 SBYTES (str) & 1)
116 {
117 str = Fsubstring (str, make_number (0), make_number (-1));
118 }
119
120 return code_convert_string_norecord (str, Qutf_16le, 0);
121}
122
123wchar_t *
124to_unicode (Lisp_Object str, Lisp_Object *buf)
125{
126 *buf = code_convert_string_norecord (str, Qutf_16le, 1);
127 /* We need to make a another copy (in addition to the one made by
128 code_convert_string_norecord) to ensure that the final string is
129 _doubly_ zero terminated --- that is, that the string is
130 terminated by two zero bytes and one utf-16le null character.
131 Because strings are already terminated with a single zero byte,
132 we just add one additional zero. */
133 str = make_uninit_string (SBYTES (*buf) + 1);
134 memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
135 SDATA (str) [SBYTES (*buf)] = '\0';
136 *buf = str;
137 return WCSDATA (*buf);
138}
139
140DEFUN ("cygwin-convert-path-to-windows", 109DEFUN ("cygwin-convert-path-to-windows",
141 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows, 110 Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
142 1, 2, 0, 111 1, 2, 0,
@@ -162,8 +131,6 @@ DEFUN ("cygwin-convert-path-from-windows",
162void 131void
163syms_of_cygw32 (void) 132syms_of_cygw32 (void)
164{ 133{
165 /* No, not utf-16-le: that one has a BOM. */
166 DEFSYM (Qutf_16le, "utf-16le");
167 defsubr (&Scygwin_convert_path_from_windows); 134 defsubr (&Scygwin_convert_path_from_windows);
168 defsubr (&Scygwin_convert_path_to_windows); 135 defsubr (&Scygwin_convert_path_to_windows);
169} 136}
diff --git a/src/cygw32.h b/src/cygw32.h
index 78e77a9a141..51571913fd1 100644
--- a/src/cygw32.h
+++ b/src/cygw32.h
@@ -33,20 +33,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "lisp.h" 33#include "lisp.h"
34#include "coding.h" 34#include "coding.h"
35 35
36/* *** Character conversion *** */
37
38/* Access the wide-character string stored in a Lisp string object. */
39#define WCSDATA(x) ((wchar_t *) SDATA (x))
40
41/* Convert the multi-byte string in STR to UTF-16LE encoded unibyte
42 string, and store it in *BUF. BUF may safely point to STR on entry. */
43extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
44
45/* Convert STR, a UTF-16LE encoded string embedded in a unibyte string
46 object, to a multi-byte Emacs string, and return it. */
47extern Lisp_Object from_unicode (Lisp_Object str);
48
49/* *** Misc *** */
50extern void syms_of_cygw32 (void); 36extern void syms_of_cygw32 (void);
51extern char * w32_strerror (int error_no); 37extern char * w32_strerror (int error_no);
52 38
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 08f34f47042..80086946fc4 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -299,8 +299,8 @@ xd_symbol_to_dbus_type (Lisp_Object object)
299 } \ 299 } \
300 } while (0) 300 } while (0)
301 301
302#if (HAVE_DBUS_VALIDATE_BUS_NAME || HAVE_DBUS_VALIDATE_PATH \ 302#if (HAVE_DBUS_VALIDATE_BUS_NAME || HAVE_DBUS_VALIDATE_PATH \
303 || XD_DBUS_VALIDATE_OBJECT || HAVE_DBUS_VALIDATE_MEMBER) 303 || HAVE_DBUS_VALIDATE_INTERFACE || HAVE_DBUS_VALIDATE_MEMBER)
304#define XD_DBUS_VALIDATE_OBJECT(object, func) \ 304#define XD_DBUS_VALIDATE_OBJECT(object, func) \
305 do { \ 305 do { \
306 if (!NILP (object)) \ 306 if (!NILP (object)) \
diff --git a/src/dispnew.c b/src/dispnew.c
index 89cca68c127..7a0901aafd6 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -56,9 +56,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
56#include "systime.h" 56#include "systime.h"
57#include <errno.h> 57#include <errno.h>
58 58
59#ifdef DISPNEW_NEEDS_STDIO_EXT 59#include <fpending.h>
60#include <stdio_ext.h>
61#endif
62 60
63#if defined (HAVE_TERM_H) && defined (GNU_LINUX) 61#if defined (HAVE_TERM_H) && defined (GNU_LINUX)
64#include <term.h> /* for tgetent */ 62#include <term.h> /* for tgetent */
@@ -3075,14 +3073,12 @@ window_to_frame_hpos (struct window *w, int hpos)
3075 Redrawing Frames 3073 Redrawing Frames
3076 **********************************************************************/ 3074 **********************************************************************/
3077 3075
3078DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 1, 1, 0, 3076DEFUN ("redraw-frame", Fredraw_frame, Sredraw_frame, 0, 1, 0,
3079 doc: /* Clear frame FRAME and output again what is supposed to appear on it. */) 3077 doc: /* Clear frame FRAME and output again what is supposed to appear on it.
3078If FRAME is omitted or nil, the selected frame is used. */)
3080 (Lisp_Object frame) 3079 (Lisp_Object frame)
3081{ 3080{
3082 struct frame *f; 3081 struct frame *f = decode_live_frame (frame);
3083
3084 CHECK_LIVE_FRAME (frame);
3085 f = XFRAME (frame);
3086 3082
3087 /* Ignore redraw requests, if frame has no glyphs yet. 3083 /* Ignore redraw requests, if frame has no glyphs yet.
3088 (Implementation note: It still has to be checked why we are 3084 (Implementation note: It still has to be checked why we are
@@ -4658,24 +4654,10 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p)
4658 FILE *display_output = FRAME_TTY (f)->output; 4654 FILE *display_output = FRAME_TTY (f)->output;
4659 if (display_output) 4655 if (display_output)
4660 { 4656 {
4661 int outq = PENDING_OUTPUT_COUNT (display_output); 4657 ptrdiff_t outq = __fpending (display_output);
4662 if (outq > 900 4658 if (outq > 900
4663 || (outq > 20 && ((i - 1) % preempt_count == 0))) 4659 || (outq > 20 && ((i - 1) % preempt_count == 0)))
4664 { 4660 fflush (display_output);
4665 fflush (display_output);
4666 if (preempt_count == 1)
4667 {
4668#ifdef EMACS_OUTQSIZE
4669 if (EMACS_OUTQSIZE (0, &outq) < 0)
4670 /* Probably not a tty. Ignore the error and reset
4671 the outq count. */
4672 outq = PENDING_OUTPUT_COUNT (FRAME_TTY (f->output));
4673#endif
4674 outq *= 10;
4675 if (baud_rate <= outq && baud_rate > 0)
4676 sleep (outq / baud_rate);
4677 }
4678 }
4679 } 4661 }
4680 } 4662 }
4681 4663
@@ -6294,6 +6276,8 @@ init_display (void)
6294 struct terminal *t; 6276 struct terminal *t;
6295 struct frame *f = XFRAME (selected_frame); 6277 struct frame *f = XFRAME (selected_frame);
6296 6278
6279 init_foreground_group ();
6280
6297 /* Open a display on the controlling tty. */ 6281 /* Open a display on the controlling tty. */
6298 t = init_tty (0, terminal_type, 1); /* Errors are fatal. */ 6282 t = init_tty (0, terminal_type, 1); /* Errors are fatal. */
6299 6283
@@ -6384,15 +6368,7 @@ don't show a cursor. */)
6384 /* Don't change cursor state while redisplaying. This could confuse 6368 /* Don't change cursor state while redisplaying. This could confuse
6385 output routines. */ 6369 output routines. */
6386 if (!redisplaying_p) 6370 if (!redisplaying_p)
6387 { 6371 decode_any_window (window)->cursor_off_p = NILP (show);
6388 if (NILP (window))
6389 window = selected_window;
6390 else
6391 CHECK_WINDOW (window);
6392
6393 XWINDOW (window)->cursor_off_p = NILP (show);
6394 }
6395
6396 return Qnil; 6372 return Qnil;
6397} 6373}
6398 6374
@@ -6403,15 +6379,7 @@ DEFUN ("internal-show-cursor-p", Finternal_show_cursor_p,
6403WINDOW nil or omitted means report on the selected window. */) 6379WINDOW nil or omitted means report on the selected window. */)
6404 (Lisp_Object window) 6380 (Lisp_Object window)
6405{ 6381{
6406 struct window *w; 6382 return decode_any_window (window)->cursor_off_p ? Qnil : Qt;
6407
6408 if (NILP (window))
6409 window = selected_window;
6410 else
6411 CHECK_WINDOW (window);
6412
6413 w = XWINDOW (window);
6414 return w->cursor_off_p ? Qnil : Qt;
6415} 6383}
6416 6384
6417DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame, 6385DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
diff --git a/src/emacs.c b/src/emacs.c
index 168eb35d3a3..894e4d3cb30 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27#include <sys/file.h> 27#include <sys/file.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#include <close-stream.h>
30#include <ignore-value.h> 31#include <ignore-value.h>
31 32
32#include "lisp.h" 33#include "lisp.h"
@@ -678,6 +679,22 @@ void (*__malloc_initialize_hook) (void) EXTERNALLY_VISIBLE = malloc_initialize_h
678 679
679#endif /* DOUG_LEA_MALLOC */ 680#endif /* DOUG_LEA_MALLOC */
680 681
682/* Close standard output and standard error, reporting any write
683 errors as best we can. This is intended for use with atexit. */
684static void
685close_output_streams (void)
686{
687 if (close_stream (stdout) != 0)
688 {
689 fprintf (stderr, "Write error to standard output: %s\n",
690 strerror (errno));
691 fflush (stderr);
692 _exit (EXIT_FAILURE);
693 }
694
695 if (close_stream (stderr) != 0)
696 _exit (EXIT_FAILURE);
697}
681 698
682/* ARGSUSED */ 699/* ARGSUSED */
683int 700int
@@ -734,6 +751,8 @@ main (int argc, char **argv)
734 unexec_init_emacs_zone (); 751 unexec_init_emacs_zone ();
735#endif 752#endif
736 753
754 atexit (close_output_streams);
755
737 sort_args (argc, argv); 756 sort_args (argc, argv);
738 argc = 0; 757 argc = 0;
739 while (argv[argc]) argc++; 758 while (argv[argc]) argc++;
@@ -1085,28 +1104,21 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1085 that it is not accessible to programs started from .emacs. */ 1104 that it is not accessible to programs started from .emacs. */
1086 fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC); 1105 fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC);
1087 1106
1088#ifdef HAVE_SETSID
1089 setsid (); 1107 setsid ();
1090#endif
1091#else /* DOS_NT */ 1108#else /* DOS_NT */
1092 fprintf (stderr, "This platform does not support the -daemon flag.\n"); 1109 fprintf (stderr, "This platform does not support the -daemon flag.\n");
1093 exit (1); 1110 exit (1);
1094#endif /* DOS_NT */ 1111#endif /* DOS_NT */
1095 } 1112 }
1096 1113
1114#if defined (HAVE_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
1097 if (! noninteractive) 1115 if (! noninteractive)
1098 { 1116 {
1099#if defined (USG5) && defined (INTERRUPT_INPUT) 1117 extern void malloc_enable_thread (void);
1100 setpgrp ();
1101#endif
1102#if defined (HAVE_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
1103 {
1104 extern void malloc_enable_thread (void);
1105 1118
1106 malloc_enable_thread (); 1119 malloc_enable_thread ();
1107 }
1108#endif
1109 } 1120 }
1121#endif
1110 1122
1111 init_signals (dumping); 1123 init_signals (dumping);
1112 1124
@@ -1878,8 +1890,6 @@ all of which are called before Emacs is actually killed. */)
1878 exit_code = (XINT (arg) < 0 1890 exit_code = (XINT (arg) < 0
1879 ? XINT (arg) | INT_MIN 1891 ? XINT (arg) | INT_MIN
1880 : XINT (arg) & INT_MAX); 1892 : XINT (arg) & INT_MAX);
1881 else if (noninteractive && (fflush (stdout) || ferror (stdout)))
1882 exit_code = EXIT_FAILURE;
1883 else 1893 else
1884 exit_code = EXIT_SUCCESS; 1894 exit_code = EXIT_SUCCESS;
1885 exit (exit_code); 1895 exit (exit_code);
@@ -1909,7 +1919,7 @@ shut_down_emacs (int sig, Lisp_Object stuff)
1909 /* If we are controlling the terminal, reset terminal modes. */ 1919 /* If we are controlling the terminal, reset terminal modes. */
1910#ifndef DOS_NT 1920#ifndef DOS_NT
1911 { 1921 {
1912 pid_t pgrp = EMACS_GETPGRP (0); 1922 pid_t pgrp = getpgrp ();
1913 pid_t tpgrp = tcgetpgrp (0); 1923 pid_t tpgrp = tcgetpgrp (0);
1914 if ((tpgrp != -1) && tpgrp == pgrp) 1924 if ((tpgrp != -1) && tpgrp == pgrp)
1915 { 1925 {
diff --git a/src/font.c b/src/font.c
index bff2356d6ca..41dbfd7a757 100644
--- a/src/font.c
+++ b/src/font.c
@@ -3993,16 +3993,11 @@ The optional argument FRAME specifies the frame that the face attributes
3993are to be displayed on. If omitted, the selected frame is used. */) 3993are to be displayed on. If omitted, the selected frame is used. */)
3994 (Lisp_Object font, Lisp_Object frame) 3994 (Lisp_Object font, Lisp_Object frame)
3995{ 3995{
3996 struct frame *f; 3996 struct frame *f = decode_live_frame (frame);
3997 Lisp_Object plist[10]; 3997 Lisp_Object plist[10];
3998 Lisp_Object val; 3998 Lisp_Object val;
3999 int n = 0; 3999 int n = 0;
4000 4000
4001 if (NILP (frame))
4002 frame = selected_frame;
4003 CHECK_LIVE_FRAME (frame);
4004 f = XFRAME (frame);
4005
4006 if (STRINGP (font)) 4001 if (STRINGP (font))
4007 { 4002 {
4008 int fontset = fs_query_fontset (font, 0); 4003 int fontset = fs_query_fontset (font, 0);
@@ -4152,18 +4147,15 @@ how close they are to PREFER. */)
4152 4147
4153DEFUN ("font-family-list", Ffont_family_list, Sfont_family_list, 0, 1, 0, 4148DEFUN ("font-family-list", Ffont_family_list, Sfont_family_list, 0, 1, 0,
4154 doc: /* List available font families on the current frame. 4149 doc: /* List available font families on the current frame.
4155Optional argument FRAME, if non-nil, specifies the target frame. */) 4150If FRAME is omitted or nil, the selected frame is used. */)
4156 (Lisp_Object frame) 4151 (Lisp_Object frame)
4157{ 4152{
4158 FRAME_PTR f; 4153 struct frame *f = decode_live_frame (frame);
4159 struct font_driver_list *driver_list; 4154 struct font_driver_list *driver_list;
4160 Lisp_Object list; 4155 Lisp_Object list = Qnil;
4156
4157 XSETFRAME (frame, f);
4161 4158
4162 if (NILP (frame))
4163 frame = selected_frame;
4164 CHECK_LIVE_FRAME (frame);
4165 f = XFRAME (frame);
4166 list = Qnil;
4167 for (driver_list = f->font_driver_list; driver_list; 4159 for (driver_list = f->font_driver_list; driver_list;
4168 driver_list = driver_list->next) 4160 driver_list = driver_list->next)
4169 if (driver_list->driver->list_family) 4161 if (driver_list->driver->list_family)
@@ -4531,11 +4523,9 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4531 (Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame) 4523 (Lisp_Object font_entity, Lisp_Object size, Lisp_Object frame)
4532{ 4524{
4533 EMACS_INT isize; 4525 EMACS_INT isize;
4526 struct frame *f = decode_live_frame (frame);
4534 4527
4535 CHECK_FONT_ENTITY (font_entity); 4528 CHECK_FONT_ENTITY (font_entity);
4536 if (NILP (frame))
4537 frame = selected_frame;
4538 CHECK_LIVE_FRAME (frame);
4539 4529
4540 if (NILP (size)) 4530 if (NILP (size))
4541 isize = XINT (AREF (font_entity, FONT_SIZE_INDEX)); 4531 isize = XINT (AREF (font_entity, FONT_SIZE_INDEX));
@@ -4543,7 +4533,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4543 { 4533 {
4544 CHECK_NUMBER_OR_FLOAT (size); 4534 CHECK_NUMBER_OR_FLOAT (size);
4545 if (FLOATP (size)) 4535 if (FLOATP (size))
4546 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), XFRAME (frame)->resy); 4536 isize = POINT_TO_PIXEL (XFLOAT_DATA (size), f->resy);
4547 else 4537 else
4548 isize = XINT (size); 4538 isize = XINT (size);
4549 if (! (INT_MIN <= isize && isize <= INT_MAX)) 4539 if (! (INT_MIN <= isize && isize <= INT_MAX))
@@ -4551,7 +4541,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0,
4551 if (isize == 0) 4541 if (isize == 0)
4552 isize = 120; 4542 isize = 120;
4553 } 4543 }
4554 return font_open_entity (XFRAME (frame), font_entity, isize); 4544 return font_open_entity (f, font_entity, isize);
4555} 4545}
4556 4546
4557DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0, 4547DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
@@ -4559,10 +4549,7 @@ DEFUN ("close-font", Fclose_font, Sclose_font, 1, 2, 0,
4559 (Lisp_Object font_object, Lisp_Object frame) 4549 (Lisp_Object font_object, Lisp_Object frame)
4560{ 4550{
4561 CHECK_FONT_OBJECT (font_object); 4551 CHECK_FONT_OBJECT (font_object);
4562 if (NILP (frame)) 4552 font_close_object (decode_live_frame (frame), font_object);
4563 frame = selected_frame;
4564 CHECK_LIVE_FRAME (frame);
4565 font_close_object (XFRAME (frame), font_object);
4566 return Qnil; 4553 return Qnil;
4567} 4554}
4568 4555
@@ -4760,18 +4747,20 @@ FONT is a font-spec, font-entity, or font-object. */)
4760DEFUN ("font-at", Ffont_at, Sfont_at, 1, 3, 0, 4747DEFUN ("font-at", Ffont_at, Sfont_at, 1, 3, 0,
4761 doc: /* Return a font-object for displaying a character at POSITION. 4748 doc: /* Return a font-object for displaying a character at POSITION.
4762Optional second arg WINDOW, if non-nil, is a window displaying 4749Optional second arg WINDOW, if non-nil, is a window displaying
4763the current buffer. It defaults to the currently selected window. */) 4750the current buffer. It defaults to the currently selected window.
4751Optional third arg STRING, if non-nil, is a string containing the target
4752character at index specified by POSITION. */)
4764 (Lisp_Object position, Lisp_Object window, Lisp_Object string) 4753 (Lisp_Object position, Lisp_Object window, Lisp_Object string)
4765{ 4754{
4766 struct window *w; 4755 struct window *w = decode_live_window (window);
4767 ptrdiff_t pos;
4768 4756
4769 if (NILP (string)) 4757 if (NILP (string))
4770 { 4758 {
4759 if (XBUFFER (w->buffer) != current_buffer)
4760 error ("Specified window is not displaying the current buffer.");
4771 CHECK_NUMBER_COERCE_MARKER (position); 4761 CHECK_NUMBER_COERCE_MARKER (position);
4772 if (! (BEGV <= XINT (position) && XINT (position) < ZV)) 4762 if (! (BEGV <= XINT (position) && XINT (position) < ZV))
4773 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV)); 4763 args_out_of_range_3 (position, make_number (BEGV), make_number (ZV));
4774 pos = XINT (position);
4775 } 4764 }
4776 else 4765 else
4777 { 4766 {
@@ -4779,14 +4768,9 @@ the current buffer. It defaults to the currently selected window. */)
4779 CHECK_STRING (string); 4768 CHECK_STRING (string);
4780 if (! (0 <= XINT (position) && XINT (position) < SCHARS (string))) 4769 if (! (0 <= XINT (position) && XINT (position) < SCHARS (string)))
4781 args_out_of_range (string, position); 4770 args_out_of_range (string, position);
4782 pos = XINT (position);
4783 } 4771 }
4784 if (NILP (window))
4785 window = selected_window;
4786 CHECK_LIVE_WINDOW (window);
4787 w = XWINDOW (window);
4788 4772
4789 return font_at (-1, pos, NULL, w, string); 4773 return font_at (-1, XINT (position), NULL, w, string);
4790} 4774}
4791 4775
4792#if 0 4776#if 0
@@ -4850,7 +4834,7 @@ where
4850If the named font is not yet loaded, return nil. */) 4834If the named font is not yet loaded, return nil. */)
4851 (Lisp_Object name, Lisp_Object frame) 4835 (Lisp_Object name, Lisp_Object frame)
4852{ 4836{
4853 FRAME_PTR f; 4837 struct frame *f;
4854 struct font *font; 4838 struct font *font;
4855 Lisp_Object info; 4839 Lisp_Object info;
4856 Lisp_Object font_object; 4840 Lisp_Object font_object;
@@ -4859,10 +4843,7 @@ If the named font is not yet loaded, return nil. */)
4859 4843
4860 if (! FONTP (name)) 4844 if (! FONTP (name))
4861 CHECK_STRING (name); 4845 CHECK_STRING (name);
4862 if (NILP (frame)) 4846 f = decode_live_frame (frame);
4863 frame = selected_frame;
4864 CHECK_LIVE_FRAME (frame);
4865 f = XFRAME (frame);
4866 4847
4867 if (STRINGP (name)) 4848 if (STRINGP (name))
4868 { 4849 {
diff --git a/src/fontset.c b/src/fontset.c
index da745b31ca1..b76a216bac2 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1326,17 +1326,14 @@ static Lisp_Object
1326check_fontset_name (Lisp_Object name, Lisp_Object *frame) 1326check_fontset_name (Lisp_Object name, Lisp_Object *frame)
1327{ 1327{
1328 int id; 1328 int id;
1329 struct frame *f = decode_live_frame (*frame);
1329 1330
1330 if (NILP (*frame)) 1331 XSETFRAME (*frame, f);
1331 *frame = selected_frame;
1332 CHECK_LIVE_FRAME (*frame);
1333 1332
1334 if (EQ (name, Qt)) 1333 if (EQ (name, Qt))
1335 return Vdefault_fontset; 1334 return Vdefault_fontset;
1336 if (NILP (name)) 1335 if (NILP (name))
1337 { 1336 id = FRAME_FONTSET (f);
1338 id = FRAME_FONTSET (XFRAME (*frame));
1339 }
1340 else 1337 else
1341 { 1338 {
1342 CHECK_STRING (name); 1339 CHECK_STRING (name);
diff --git a/src/frame.c b/src/frame.c
index 6478ad1e06f..52be8be270e 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -131,7 +131,24 @@ fset_minibuffer_window (struct frame *f, Lisp_Object val)
131 f->minibuffer_window = val; 131 f->minibuffer_window = val;
132} 132}
133 133
134 134struct frame *
135decode_live_frame (register Lisp_Object frame)
136{
137 if (NILP (frame))
138 frame = selected_frame;
139 CHECK_LIVE_FRAME (frame);
140 return XFRAME (frame);
141}
142
143struct frame *
144decode_any_frame (register Lisp_Object frame)
145{
146 if (NILP (frame))
147 frame = selected_frame;
148 CHECK_FRAME (frame);
149 return XFRAME (frame);
150}
151
135static void 152static void
136set_menu_bar_lines_1 (Lisp_Object window, int n) 153set_menu_bar_lines_1 (Lisp_Object window, int n)
137{ 154{
@@ -502,7 +519,6 @@ make_initial_frame (void)
502 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR; 519 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
503 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR; 520 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
504 521
505 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
506 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; 522 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
507 523
508 /* The default value of menu-bar-mode is t. */ 524 /* The default value of menu-bar-mode is t. */
@@ -551,7 +567,6 @@ make_terminal_frame (struct terminal *terminal)
551 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR; 567 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
552#endif /* not MSDOS */ 568#endif /* not MSDOS */
553 569
554 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
555 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; 570 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
556 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1; 571 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
557 572
@@ -1120,23 +1135,12 @@ other_visible_frames (FRAME_PTR f)
1120Lisp_Object 1135Lisp_Object
1121delete_frame (Lisp_Object frame, Lisp_Object force) 1136delete_frame (Lisp_Object frame, Lisp_Object force)
1122{ 1137{
1123 struct frame *f; 1138 struct frame *f = decode_any_frame (frame);
1124 struct frame *sf = SELECTED_FRAME (); 1139 struct frame *sf = SELECTED_FRAME ();
1125 struct kboard *kb; 1140 struct kboard *kb;
1126 1141
1127 int minibuffer_selected, is_tooltip_frame; 1142 int minibuffer_selected, is_tooltip_frame;
1128 1143
1129 if (EQ (frame, Qnil))
1130 {
1131 f = sf;
1132 XSETFRAME (frame, f);
1133 }
1134 else
1135 {
1136 CHECK_FRAME (frame);
1137 f = XFRAME (frame);
1138 }
1139
1140 if (! FRAME_LIVE_P (f)) 1144 if (! FRAME_LIVE_P (f))
1141 return Qnil; 1145 return Qnil;
1142 1146
@@ -1148,9 +1152,11 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
1148 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp)) 1152 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1149 error ("Attempt to delete the only frame"); 1153 error ("Attempt to delete the only frame");
1150 1154
1155 XSETFRAME (frame, f);
1156
1151 /* Does this frame have a minibuffer, and is it the surrogate 1157 /* Does this frame have a minibuffer, and is it the surrogate
1152 minibuffer for any other frame? */ 1158 minibuffer for any other frame? */
1153 if (FRAME_HAS_MINIBUF_P (XFRAME (frame))) 1159 if (FRAME_HAS_MINIBUF_P (f))
1154 { 1160 {
1155 Lisp_Object frames; 1161 Lisp_Object frames;
1156 1162
@@ -1665,25 +1671,23 @@ DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1665If omitted, FRAME defaults to the currently selected frame. */) 1671If omitted, FRAME defaults to the currently selected frame. */)
1666 (Lisp_Object frame) 1672 (Lisp_Object frame)
1667{ 1673{
1668 if (NILP (frame)) 1674 struct frame *f = decode_live_frame (frame);
1669 frame = selected_frame;
1670
1671 CHECK_LIVE_FRAME (frame);
1672 1675
1673 /* I think this should be done with a hook. */ 1676 /* I think this should be done with a hook. */
1674#ifdef HAVE_WINDOW_SYSTEM 1677#ifdef HAVE_WINDOW_SYSTEM
1675 if (FRAME_WINDOW_P (XFRAME (frame))) 1678 if (FRAME_WINDOW_P (f))
1676 { 1679 {
1677 FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); 1680 FRAME_SAMPLE_VISIBILITY (f);
1678 x_make_frame_visible (XFRAME (frame)); 1681 x_make_frame_visible (f);
1679 } 1682 }
1680#endif 1683#endif
1681 1684
1682 make_frame_visible_1 (XFRAME (frame)->root_window); 1685 make_frame_visible_1 (f->root_window);
1683 1686
1684 /* Make menu bar update for the Buffers and Frames menus. */ 1687 /* Make menu bar update for the Buffers and Frames menus. */
1685 windows_or_buffers_changed++; 1688 windows_or_buffers_changed++;
1686 1689
1690 XSETFRAME (frame, f);
1687 return frame; 1691 return frame;
1688} 1692}
1689 1693
@@ -1724,16 +1728,13 @@ always considered visible, whether or not they are currently being
1724displayed in the terminal. */) 1728displayed in the terminal. */)
1725 (Lisp_Object frame, Lisp_Object force) 1729 (Lisp_Object frame, Lisp_Object force)
1726{ 1730{
1727 if (NILP (frame)) 1731 struct frame *f = decode_live_frame (frame);
1728 frame = selected_frame;
1729 1732
1730 CHECK_LIVE_FRAME (frame); 1733 if (NILP (force) && !other_visible_frames (f))
1731
1732 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1733 error ("Attempt to make invisible the sole visible or iconified frame"); 1734 error ("Attempt to make invisible the sole visible or iconified frame");
1734 1735
1735 /* Don't allow minibuf_window to remain on a deleted frame. */ 1736 /* Don't allow minibuf_window to remain on a deleted frame. */
1736 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) 1737 if (EQ (f->minibuffer_window, minibuf_window))
1737 { 1738 {
1738 struct frame *sf = XFRAME (selected_frame); 1739 struct frame *sf = XFRAME (selected_frame);
1739 /* Use set_window_buffer instead of Fset_window_buffer (see 1740 /* Use set_window_buffer instead of Fset_window_buffer (see
@@ -1745,8 +1746,8 @@ displayed in the terminal. */)
1745 1746
1746 /* I think this should be done with a hook. */ 1747 /* I think this should be done with a hook. */
1747#ifdef HAVE_WINDOW_SYSTEM 1748#ifdef HAVE_WINDOW_SYSTEM
1748 if (FRAME_WINDOW_P (XFRAME (frame))) 1749 if (FRAME_WINDOW_P (f))
1749 x_make_frame_invisible (XFRAME (frame)); 1750 x_make_frame_invisible (f);
1750#endif 1751#endif
1751 1752
1752 /* Make menu bar update for the Buffers and Frames menus. */ 1753 /* Make menu bar update for the Buffers and Frames menus. */
@@ -1761,19 +1762,10 @@ DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1761If omitted, FRAME defaults to the currently selected frame. */) 1762If omitted, FRAME defaults to the currently selected frame. */)
1762 (Lisp_Object frame) 1763 (Lisp_Object frame)
1763{ 1764{
1764 if (NILP (frame)) 1765 struct frame *f = decode_live_frame (frame);
1765 frame = selected_frame;
1766
1767 CHECK_LIVE_FRAME (frame);
1768
1769#if 0 /* This isn't logically necessary, and it can do GC. */
1770 /* Don't let the frame remain selected. */
1771 if (EQ (frame, selected_frame))
1772 Fhandle_switch_frame (next_frame (frame, Qt));
1773#endif
1774 1766
1775 /* Don't allow minibuf_window to remain on an iconified frame. */ 1767 /* Don't allow minibuf_window to remain on an iconified frame. */
1776 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window)) 1768 if (EQ (f->minibuffer_window, minibuf_window))
1777 { 1769 {
1778 struct frame *sf = XFRAME (selected_frame); 1770 struct frame *sf = XFRAME (selected_frame);
1779 /* Use set_window_buffer instead of Fset_window_buffer (see 1771 /* Use set_window_buffer instead of Fset_window_buffer (see
@@ -1785,8 +1777,8 @@ If omitted, FRAME defaults to the currently selected frame. */)
1785 1777
1786 /* I think this should be done with a hook. */ 1778 /* I think this should be done with a hook. */
1787#ifdef HAVE_WINDOW_SYSTEM 1779#ifdef HAVE_WINDOW_SYSTEM
1788 if (FRAME_WINDOW_P (XFRAME (frame))) 1780 if (FRAME_WINDOW_P (f))
1789 x_iconify_frame (XFRAME (frame)); 1781 x_iconify_frame (f);
1790#endif 1782#endif
1791 1783
1792 /* Make menu bar update for the Buffers and Frames menus. */ 1784 /* Make menu bar update for the Buffers and Frames menus. */
@@ -1850,13 +1842,9 @@ If Emacs is displaying on an ordinary terminal or some other device which
1850doesn't support multiple overlapping frames, this function selects FRAME. */) 1842doesn't support multiple overlapping frames, this function selects FRAME. */)
1851 (Lisp_Object frame) 1843 (Lisp_Object frame)
1852{ 1844{
1853 struct frame *f; 1845 struct frame *f = decode_live_frame (frame);
1854 if (NILP (frame))
1855 frame = selected_frame;
1856 1846
1857 CHECK_LIVE_FRAME (frame); 1847 XSETFRAME (frame, f);
1858
1859 f = XFRAME (frame);
1860 1848
1861 if (FRAME_TERMCAP_P (f)) 1849 if (FRAME_TERMCAP_P (f))
1862 /* On a text terminal select FRAME. */ 1850 /* On a text terminal select FRAME. */
@@ -1879,14 +1867,7 @@ If Emacs is displaying on an ordinary terminal or some other device which
1879doesn't support multiple overlapping frames, this function does nothing. */) 1867doesn't support multiple overlapping frames, this function does nothing. */)
1880 (Lisp_Object frame) 1868 (Lisp_Object frame)
1881{ 1869{
1882 struct frame *f; 1870 struct frame *f = decode_live_frame (frame);
1883
1884 if (NILP (frame))
1885 frame = selected_frame;
1886
1887 CHECK_LIVE_FRAME (frame);
1888
1889 f = XFRAME (frame);
1890 1871
1891 if (FRAME_TERMINAL (f)->frame_raise_lower_hook) 1872 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1892 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0); 1873 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
@@ -1922,18 +1903,14 @@ is affected by `select-frame', while the latter is not.
1922The redirection lasts until `redirect-frame-focus' is called to change it. */) 1903The redirection lasts until `redirect-frame-focus' is called to change it. */)
1923 (Lisp_Object frame, Lisp_Object focus_frame) 1904 (Lisp_Object frame, Lisp_Object focus_frame)
1924{ 1905{
1925 struct frame *f;
1926
1927 /* Note that we don't check for a live frame here. It's reasonable 1906 /* Note that we don't check for a live frame here. It's reasonable
1928 to redirect the focus of a frame you're about to delete, if you 1907 to redirect the focus of a frame you're about to delete, if you
1929 know what other frame should receive those keystrokes. */ 1908 know what other frame should receive those keystrokes. */
1930 CHECK_FRAME (frame); 1909 struct frame *f = decode_any_frame (frame);
1931 1910
1932 if (! NILP (focus_frame)) 1911 if (! NILP (focus_frame))
1933 CHECK_LIVE_FRAME (focus_frame); 1912 CHECK_LIVE_FRAME (focus_frame);
1934 1913
1935 f = XFRAME (frame);
1936
1937 fset_focus_frame (f, focus_frame); 1914 fset_focus_frame (f, focus_frame);
1938 1915
1939 if (FRAME_TERMINAL (f)->frame_rehighlight_hook) 1916 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
@@ -1943,15 +1920,14 @@ The redirection lasts until `redirect-frame-focus' is called to change it. */)
1943} 1920}
1944 1921
1945 1922
1946DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0, 1923DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
1947 doc: /* Return the frame to which FRAME's keystrokes are currently being sent. 1924 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1948This returns nil if FRAME's focus is not redirected. 1925If FRAME is omitted or nil, the selected frame is used.
1926Return nil if FRAME's focus is not redirected.
1949See `redirect-frame-focus'. */) 1927See `redirect-frame-focus'. */)
1950 (Lisp_Object frame) 1928 (Lisp_Object frame)
1951{ 1929{
1952 CHECK_LIVE_FRAME (frame); 1930 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
1953
1954 return FRAME_FOCUS_FRAME (XFRAME (frame));
1955} 1931}
1956 1932
1957 1933
@@ -1974,22 +1950,6 @@ get_frame_param (register struct frame *frame, Lisp_Object prop)
1974} 1950}
1975#endif 1951#endif
1976 1952
1977/* Return the buffer-predicate of the selected frame. */
1978
1979Lisp_Object
1980frame_buffer_predicate (Lisp_Object frame)
1981{
1982 return XFRAME (frame)->buffer_predicate;
1983}
1984
1985/* Return the buffer-list of the selected frame. */
1986
1987static Lisp_Object
1988frame_buffer_list (Lisp_Object frame)
1989{
1990 return XFRAME (frame)->buffer_list;
1991}
1992
1993/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */ 1953/* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1994 1954
1995void 1955void
@@ -2168,20 +2128,14 @@ DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2168 doc: /* Return the parameters-alist of frame FRAME. 2128 doc: /* Return the parameters-alist of frame FRAME.
2169It is a list of elements of the form (PARM . VALUE), where PARM is a symbol. 2129It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2170The meaningful PARMs depend on the kind of frame. 2130The meaningful PARMs depend on the kind of frame.
2171If FRAME is omitted, return information on the currently selected frame. */) 2131If FRAME is omitted or nil, return information on the currently selected frame. */)
2172 (Lisp_Object frame) 2132 (Lisp_Object frame)
2173{ 2133{
2174 Lisp_Object alist; 2134 Lisp_Object alist;
2175 FRAME_PTR f; 2135 struct frame *f = decode_any_frame (frame);
2176 int height, width; 2136 int height, width;
2177 struct gcpro gcpro1; 2137 struct gcpro gcpro1;
2178 2138
2179 if (NILP (frame))
2180 frame = selected_frame;
2181
2182 CHECK_FRAME (frame);
2183 f = XFRAME (frame);
2184
2185 if (!FRAME_LIVE_P (f)) 2139 if (!FRAME_LIVE_P (f))
2186 return Qnil; 2140 return Qnil;
2187 2141
@@ -2242,9 +2196,8 @@ If FRAME is omitted, return information on the currently selected frame. */)
2242 : FRAME_MINIBUF_ONLY_P (f) ? Qonly 2196 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2243 : FRAME_MINIBUF_WINDOW (f))); 2197 : FRAME_MINIBUF_WINDOW (f)));
2244 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); 2198 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2245 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame)); 2199 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2246 store_in_alist (&alist, Qburied_buffer_list, 2200 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2247 XFRAME (frame)->buried_buffer_list);
2248 2201
2249 /* I think this should be done with a hook. */ 2202 /* I think this should be done with a hook. */
2250#ifdef HAVE_WINDOW_SYSTEM 2203#ifdef HAVE_WINDOW_SYSTEM
@@ -2269,17 +2222,12 @@ DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2269If FRAME is nil, describe the currently selected frame. */) 2222If FRAME is nil, describe the currently selected frame. */)
2270 (Lisp_Object frame, Lisp_Object parameter) 2223 (Lisp_Object frame, Lisp_Object parameter)
2271{ 2224{
2272 struct frame *f; 2225 struct frame *f = decode_any_frame (frame);
2273 Lisp_Object value; 2226 Lisp_Object value = Qnil;
2274 2227
2275 if (NILP (frame))
2276 frame = selected_frame;
2277 else
2278 CHECK_FRAME (frame);
2279 CHECK_SYMBOL (parameter); 2228 CHECK_SYMBOL (parameter);
2280 2229
2281 f = XFRAME (frame); 2230 XSETFRAME (frame, f);
2282 value = Qnil;
2283 2231
2284 if (FRAME_LIVE_P (f)) 2232 if (FRAME_LIVE_P (f))
2285 { 2233 {
@@ -2359,14 +2307,9 @@ Note that this functionality is obsolete as of Emacs 22.2, and its
2359use is not recommended. Explicitly check for a frame-parameter instead. */) 2307use is not recommended. Explicitly check for a frame-parameter instead. */)
2360 (Lisp_Object frame, Lisp_Object alist) 2308 (Lisp_Object frame, Lisp_Object alist)
2361{ 2309{
2362 FRAME_PTR f; 2310 struct frame *f = decode_live_frame (frame);
2363 register Lisp_Object tail, prop, val; 2311 register Lisp_Object tail, prop, val;
2364 2312
2365 if (EQ (frame, Qnil))
2366 frame = selected_frame;
2367 CHECK_LIVE_FRAME (frame);
2368 f = XFRAME (frame);
2369
2370 /* I think this should be done with a hook. */ 2313 /* I think this should be done with a hook. */
2371#ifdef HAVE_WINDOW_SYSTEM 2314#ifdef HAVE_WINDOW_SYSTEM
2372 if (FRAME_WINDOW_P (f)) 2315 if (FRAME_WINDOW_P (f))
@@ -2421,18 +2364,13 @@ use is not recommended. Explicitly check for a frame-parameter instead. */)
2421DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height, 2364DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2422 0, 1, 0, 2365 0, 1, 0,
2423 doc: /* Height in pixels of a line in the font in frame FRAME. 2366 doc: /* Height in pixels of a line in the font in frame FRAME.
2424If FRAME is omitted, the selected frame is used. 2367If FRAME is omitted or nil, the selected frame is used.
2425For a terminal frame, the value is always 1. */) 2368For a terminal frame, the value is always 1. */)
2426 (Lisp_Object frame) 2369 (Lisp_Object frame)
2427{ 2370{
2428 struct frame *f;
2429
2430 if (NILP (frame))
2431 frame = selected_frame;
2432 CHECK_FRAME (frame);
2433 f = XFRAME (frame);
2434
2435#ifdef HAVE_WINDOW_SYSTEM 2371#ifdef HAVE_WINDOW_SYSTEM
2372 struct frame *f = decode_any_frame (frame);
2373
2436 if (FRAME_WINDOW_P (f)) 2374 if (FRAME_WINDOW_P (f))
2437 return make_number (x_char_height (f)); 2375 return make_number (x_char_height (f));
2438 else 2376 else
@@ -2444,19 +2382,14 @@ For a terminal frame, the value is always 1. */)
2444DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width, 2382DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2445 0, 1, 0, 2383 0, 1, 0,
2446 doc: /* Width in pixels of characters in the font in frame FRAME. 2384 doc: /* Width in pixels of characters in the font in frame FRAME.
2447If FRAME is omitted, the selected frame is used. 2385If FRAME is omitted or nil, the selected frame is used.
2448On a graphical screen, the width is the standard width of the default font. 2386On a graphical screen, the width is the standard width of the default font.
2449For a terminal screen, the value is always 1. */) 2387For a terminal screen, the value is always 1. */)
2450 (Lisp_Object frame) 2388 (Lisp_Object frame)
2451{ 2389{
2452 struct frame *f;
2453
2454 if (NILP (frame))
2455 frame = selected_frame;
2456 CHECK_FRAME (frame);
2457 f = XFRAME (frame);
2458
2459#ifdef HAVE_WINDOW_SYSTEM 2390#ifdef HAVE_WINDOW_SYSTEM
2391 struct frame *f = decode_any_frame (frame);
2392
2460 if (FRAME_WINDOW_P (f)) 2393 if (FRAME_WINDOW_P (f))
2461 return make_number (x_char_width (f)); 2394 return make_number (x_char_width (f));
2462 else 2395 else
@@ -2467,30 +2400,22 @@ For a terminal screen, the value is always 1. */)
2467DEFUN ("frame-pixel-height", Fframe_pixel_height, 2400DEFUN ("frame-pixel-height", Fframe_pixel_height,
2468 Sframe_pixel_height, 0, 1, 0, 2401 Sframe_pixel_height, 0, 1, 0,
2469 doc: /* Return a FRAME's height in pixels. 2402 doc: /* Return a FRAME's height in pixels.
2470If FRAME is omitted, the selected frame is used. The exact value 2403If FRAME is omitted or nil, the selected frame is used. The exact value
2471of the result depends on the window-system and toolkit in use: 2404of the result depends on the window-system and toolkit in use:
2472 2405
2473In the Gtk+ version of Emacs, it includes only any window (including 2406In the Gtk+ version of Emacs, it includes only any window (including
2474the minibuffer or echo area), mode line, and header line. It does not 2407the minibuffer or echo area), mode line, and header line. It does not
2475include the tool bar or menu bar. 2408include the tool bar or menu bar.
2476 2409
2477With the Motif or Lucid toolkits, it also includes the tool bar (but 2410With other graphical versions, it also includes the tool bar and the
2478not the menu bar). 2411menu bar.
2479
2480In a graphical version with no toolkit, it includes both the tool bar
2481and menu bar.
2482 2412
2483For a text terminal, it includes the menu bar. In this case, the 2413For a text terminal, it includes the menu bar. In this case, the
2484result is really in characters rather than pixels (i.e., is identical 2414result is really in characters rather than pixels (i.e., is identical
2485to `frame-height'). */) 2415to `frame-height'). */)
2486 (Lisp_Object frame) 2416 (Lisp_Object frame)
2487{ 2417{
2488 struct frame *f; 2418 struct frame *f = decode_any_frame (frame);
2489
2490 if (NILP (frame))
2491 frame = selected_frame;
2492 CHECK_FRAME (frame);
2493 f = XFRAME (frame);
2494 2419
2495#ifdef HAVE_WINDOW_SYSTEM 2420#ifdef HAVE_WINDOW_SYSTEM
2496 if (FRAME_WINDOW_P (f)) 2421 if (FRAME_WINDOW_P (f))
@@ -2504,15 +2429,10 @@ DEFUN ("frame-pixel-width", Fframe_pixel_width,
2504 Sframe_pixel_width, 0, 1, 0, 2429 Sframe_pixel_width, 0, 1, 0,
2505 doc: /* Return FRAME's width in pixels. 2430 doc: /* Return FRAME's width in pixels.
2506For a terminal frame, the result really gives the width in characters. 2431For a terminal frame, the result really gives the width in characters.
2507If FRAME is omitted, the selected frame is used. */) 2432If FRAME is omitted or nil, the selected frame is used. */)
2508 (Lisp_Object frame) 2433 (Lisp_Object frame)
2509{ 2434{
2510 struct frame *f; 2435 struct frame *f = decode_any_frame (frame);
2511
2512 if (NILP (frame))
2513 frame = selected_frame;
2514 CHECK_FRAME (frame);
2515 f = XFRAME (frame);
2516 2436
2517#ifdef HAVE_WINDOW_SYSTEM 2437#ifdef HAVE_WINDOW_SYSTEM
2518 if (FRAME_WINDOW_P (f)) 2438 if (FRAME_WINDOW_P (f))
@@ -2526,17 +2446,15 @@ DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2526 Stool_bar_pixel_width, 0, 1, 0, 2446 Stool_bar_pixel_width, 0, 1, 0,
2527 doc: /* Return width in pixels of FRAME's tool bar. 2447 doc: /* Return width in pixels of FRAME's tool bar.
2528The result is greater than zero only when the tool bar is on the left 2448The result is greater than zero only when the tool bar is on the left
2529or right side of FRAME. If FRAME is omitted, the selected frame is 2449or right side of FRAME. If FRAME is omitted or nil, the selected frame
2530used. */) 2450is used. */)
2531 (Lisp_Object frame) 2451 (Lisp_Object frame)
2532{ 2452{
2533 if (NILP (frame))
2534 frame = selected_frame;
2535 CHECK_FRAME (frame);
2536
2537#ifdef FRAME_TOOLBAR_WIDTH 2453#ifdef FRAME_TOOLBAR_WIDTH
2538 if (FRAME_WINDOW_P (XFRAME (frame))) 2454 struct frame *f = decode_any_frame (frame);
2539 return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame))); 2455
2456 if (FRAME_WINDOW_P (f))
2457 return make_number (FRAME_TOOLBAR_WIDTH (f));
2540#endif 2458#endif
2541 return make_number (0); 2459 return make_number (0);
2542} 2460}
@@ -2547,13 +2465,9 @@ Optional third arg non-nil means that redisplay should use LINES lines
2547but that the idea of the actual height of the frame should not be changed. */) 2465but that the idea of the actual height of the frame should not be changed. */)
2548 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend) 2466 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2549{ 2467{
2550 register struct frame *f; 2468 register struct frame *f = decode_live_frame (frame);
2551 2469
2552 CHECK_TYPE_RANGED_INTEGER (int, lines); 2470 CHECK_TYPE_RANGED_INTEGER (int, lines);
2553 if (NILP (frame))
2554 frame = selected_frame;
2555 CHECK_LIVE_FRAME (frame);
2556 f = XFRAME (frame);
2557 2471
2558 /* I think this should be done with a hook. */ 2472 /* I think this should be done with a hook. */
2559#ifdef HAVE_WINDOW_SYSTEM 2473#ifdef HAVE_WINDOW_SYSTEM
@@ -2575,12 +2489,9 @@ Optional third arg non-nil means that redisplay should use COLS columns
2575but that the idea of the actual width of the frame should not be changed. */) 2489but that the idea of the actual width of the frame should not be changed. */)
2576 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend) 2490 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2577{ 2491{
2578 register struct frame *f; 2492 register struct frame *f = decode_live_frame (frame);
2493
2579 CHECK_TYPE_RANGED_INTEGER (int, cols); 2494 CHECK_TYPE_RANGED_INTEGER (int, cols);
2580 if (NILP (frame))
2581 frame = selected_frame;
2582 CHECK_LIVE_FRAME (frame);
2583 f = XFRAME (frame);
2584 2495
2585 /* I think this should be done with a hook. */ 2496 /* I think this should be done with a hook. */
2586#ifdef HAVE_WINDOW_SYSTEM 2497#ifdef HAVE_WINDOW_SYSTEM
@@ -3242,6 +3153,9 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3242 Lisp_Object ascii_font = fontset_ascii (fontset); 3153 Lisp_Object ascii_font = fontset_ascii (fontset);
3243 Lisp_Object spec = font_spec_from_name (ascii_font); 3154 Lisp_Object spec = font_spec_from_name (ascii_font);
3244 3155
3156 if (NILP (spec))
3157 signal_error ("Invalid font name", ascii_font);
3158
3245 if (! font_match_p (spec, font_object)) 3159 if (! font_match_p (spec, font_object))
3246 fontset = -1; 3160 fontset = -1;
3247 } 3161 }
@@ -4294,12 +4208,7 @@ Otherwise it returns nil. FRAME omitted or nil means the
4294selected frame. This is useful when `make-pointer-invisible' is set. */) 4208selected frame. This is useful when `make-pointer-invisible' is set. */)
4295 (Lisp_Object frame) 4209 (Lisp_Object frame)
4296{ 4210{
4297 if (NILP (frame)) 4211 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4298 frame = selected_frame;
4299
4300 CHECK_FRAME (frame);
4301
4302 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4303} 4212}
4304 4213
4305 4214
diff --git a/src/frame.h b/src/frame.h
index f8c3d99fedd..1dc3ebbaf13 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -409,10 +409,6 @@ struct frame
409 show no modeline for that window. */ 409 show no modeline for that window. */
410 unsigned wants_modeline : 1; 410 unsigned wants_modeline : 1;
411 411
412 /* Non-zero if the hardware device this frame is displaying on can
413 support scroll bars. */
414 char can_have_scroll_bars;
415
416 /* Non-0 means raise this frame to the top of the heap when selected. */ 412 /* Non-0 means raise this frame to the top of the heap when selected. */
417 unsigned auto_raise : 1; 413 unsigned auto_raise : 1;
418 414
@@ -438,8 +434,7 @@ struct frame
438 /* Nonzero means that the pointer is invisible. */ 434 /* Nonzero means that the pointer is invisible. */
439 unsigned pointer_invisible :1; 435 unsigned pointer_invisible :1;
440 436
441 /* If can_have_scroll_bars is non-zero, this is non-zero if we should 437 /* Nonzero if we should actually display the scroll bars on this frame. */
442 actually display them on this frame. */
443 enum vertical_scroll_bar_type vertical_scroll_bar_type; 438 enum vertical_scroll_bar_type vertical_scroll_bar_type;
444 439
445 /* What kind of text cursor should we draw in the future? 440 /* What kind of text cursor should we draw in the future?
@@ -767,11 +762,6 @@ typedef struct frame *FRAME_PTR;
767#define FRAME_SCROLL_BOTTOM_VPOS(f) (f)->scroll_bottom_vpos 762#define FRAME_SCROLL_BOTTOM_VPOS(f) (f)->scroll_bottom_vpos
768#define FRAME_FOCUS_FRAME(f) f->focus_frame 763#define FRAME_FOCUS_FRAME(f) f->focus_frame
769 764
770/* Nonzero if frame F supports scroll bars.
771 If this is zero, then it is impossible to enable scroll bars
772 on frame F. */
773#define FRAME_CAN_HAVE_SCROLL_BARS(f) ((f)->can_have_scroll_bars)
774
775/* This frame slot says whether scroll bars are currently enabled for frame F, 765/* This frame slot says whether scroll bars are currently enabled for frame F,
776 and which side they are on. */ 766 and which side they are on. */
777#define FRAME_VERTICAL_SCROLL_BAR_TYPE(f) ((f)->vertical_scroll_bar_type) 767#define FRAME_VERTICAL_SCROLL_BAR_TYPE(f) ((f)->vertical_scroll_bar_type)
@@ -953,6 +943,8 @@ extern Lisp_Object Qnoelisp;
953extern struct frame *last_nonminibuf_frame; 943extern struct frame *last_nonminibuf_frame;
954 944
955extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); 945extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
946extern struct frame *decode_live_frame (Lisp_Object);
947extern struct frame *decode_any_frame (Lisp_Object);
956extern struct frame *make_initial_frame (void); 948extern struct frame *make_initial_frame (void);
957extern struct frame *make_frame (int); 949extern struct frame *make_frame (int);
958#ifdef HAVE_WINDOW_SYSTEM 950#ifdef HAVE_WINDOW_SYSTEM
diff --git a/src/fringe.c b/src/fringe.c
index d788503e91e..a126292e1ff 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -1731,10 +1731,8 @@ Return nil if POS is not visible in WINDOW. */)
1731 struct glyph_row *row; 1731 struct glyph_row *row;
1732 ptrdiff_t textpos; 1732 ptrdiff_t textpos;
1733 1733
1734 if (NILP (window)) 1734 w = decode_any_window (window);
1735 window = selected_window; 1735 XSETWINDOW (window, w);
1736 CHECK_WINDOW (window);
1737 w = XWINDOW (window);
1738 1736
1739 if (!NILP (pos)) 1737 if (!NILP (pos))
1740 { 1738 {
diff --git a/src/indent.c b/src/indent.c
index bbc944d2518..eee96061e25 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1764,11 +1764,7 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1764 else 1764 else
1765 hscroll = tab_offset = 0; 1765 hscroll = tab_offset = 0;
1766 1766
1767 if (NILP (window)) 1767 w = decode_live_window (window);
1768 window = Fselected_window ();
1769 else
1770 CHECK_LIVE_WINDOW (window);
1771 w = XWINDOW (window);
1772 1768
1773 if (XINT (from) < BEGV || XINT (from) > ZV) 1769 if (XINT (from) < BEGV || XINT (from) > ZV)
1774 args_out_of_range_3 (from, make_number (BEGV), make_number (ZV)); 1770 args_out_of_range_3 (from, make_number (BEGV), make_number (ZV));
@@ -1790,8 +1786,7 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1790 1)) 1786 1))
1791 : XINT (XCAR (topos))), 1787 : XINT (XCAR (topos))),
1792 (NILP (width) ? -1 : XINT (width)), 1788 (NILP (width) ? -1 : XINT (width)),
1793 hscroll, tab_offset, 1789 hscroll, tab_offset, w);
1794 XWINDOW (window));
1795 1790
1796 XSETFASTINT (bufpos, pos->bufpos); 1791 XSETFASTINT (bufpos, pos->bufpos);
1797 XSETINT (hpos, pos->hpos); 1792 XSETINT (hpos, pos->hpos);
@@ -1988,11 +1983,7 @@ whether or not it is currently displayed in some window. */)
1988 } 1983 }
1989 1984
1990 CHECK_NUMBER (lines); 1985 CHECK_NUMBER (lines);
1991 if (! NILP (window)) 1986 w = decode_live_window (window);
1992 CHECK_WINDOW (window);
1993 else
1994 window = selected_window;
1995 w = XWINDOW (window);
1996 1987
1997 old_buffer = Qnil; 1988 old_buffer = Qnil;
1998 GCPRO3 (old_buffer, old_charpos, old_bytepos); 1989 GCPRO3 (old_buffer, old_charpos, old_bytepos);
diff --git a/src/keyboard.c b/src/keyboard.c
index 2f751d0ec72..7507b29d494 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3419,20 +3419,13 @@ int stop_character EXTERNALLY_VISIBLE;
3419static KBOARD * 3419static KBOARD *
3420event_to_kboard (struct input_event *event) 3420event_to_kboard (struct input_event *event)
3421{ 3421{
3422 Lisp_Object frame; 3422 Lisp_Object obj = event->frame_or_window;
3423 frame = event->frame_or_window; 3423 /* There are some events that set this field to nil or string. */
3424 if (CONSP (frame)) 3424 if (WINDOWP (obj))
3425 frame = XCAR (frame); 3425 obj = WINDOW_FRAME (XWINDOW (obj));
3426 else if (WINDOWP (frame)) 3426 /* Also ignore dead frames here. */
3427 frame = WINDOW_FRAME (XWINDOW (frame)); 3427 return ((FRAMEP (obj) && FRAME_LIVE_P (XFRAME (obj)))
3428 3428 ? FRAME_KBOARD (XFRAME (obj)) : NULL);
3429 /* There are still some events that don't set this field.
3430 For now, just ignore the problem.
3431 Also ignore dead frames here. */
3432 if (!FRAMEP (frame) || !FRAME_LIVE_P (XFRAME (frame)))
3433 return 0;
3434 else
3435 return FRAME_KBOARD (XFRAME (frame));
3436} 3429}
3437 3430
3438#ifdef subprocesses 3431#ifdef subprocesses
@@ -12193,14 +12186,15 @@ mark_kboards (void)
12193 { 12186 {
12194 if (event == kbd_buffer + KBD_BUFFER_SIZE) 12187 if (event == kbd_buffer + KBD_BUFFER_SIZE)
12195 event = kbd_buffer; 12188 event = kbd_buffer;
12189 /* These two special event types has no Lisp_Objects to mark. */
12196 if (event->kind != SELECTION_REQUEST_EVENT 12190 if (event->kind != SELECTION_REQUEST_EVENT
12197 && event->kind != SELECTION_CLEAR_EVENT) 12191 && event->kind != SELECTION_CLEAR_EVENT)
12198 { 12192 {
12199 mark_object (event->x); 12193 mark_object (event->x);
12200 mark_object (event->y); 12194 mark_object (event->y);
12195 mark_object (event->frame_or_window);
12196 mark_object (event->arg);
12201 } 12197 }
12202 mark_object (event->frame_or_window);
12203 mark_object (event->arg);
12204 } 12198 }
12205 } 12199 }
12206} 12200}
diff --git a/src/lisp.h b/src/lisp.h
index 17a9e5c1f6a..7a3b819116f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -160,11 +160,9 @@ enum Lisp_Bits
160#define GCTYPEBITS 3 160#define GCTYPEBITS 3
161 GCTYPEBITS, 161 GCTYPEBITS,
162 162
163 /* 2**GCTYPEBITS. This must also be a macro that expands to a 163 /* 2**GCTYPEBITS. This must be a macro that expands to a literal
164 literal integer constant, for MSVC. */ 164 integer constant, for MSVC. */
165 GCALIGNMENT =
166#define GCALIGNMENT 8 165#define GCALIGNMENT 8
167 GCALIGNMENT,
168 166
169 /* Number of bits in a Lisp_Object value, not counting the tag. */ 167 /* Number of bits in a Lisp_Object value, not counting the tag. */
170 VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS, 168 VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS,
@@ -528,14 +526,9 @@ static EMACS_INT const VALMASK
528#define EQ(x, y) (XHASH (x) == XHASH (y)) 526#define EQ(x, y) (XHASH (x) == XHASH (y))
529 527
530/* Largest and smallest representable fixnum values. These are the C 528/* Largest and smallest representable fixnum values. These are the C
531 values. They are macros for use in static initializers, and 529 values. They are macros for use in static initializers. */
532 constants for visibility to GDB. */
533static EMACS_INT const MOST_POSITIVE_FIXNUM =
534#define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS) 530#define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
535 MOST_POSITIVE_FIXNUM;
536static EMACS_INT const MOST_NEGATIVE_FIXNUM =
537#define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM) 531#define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
538 MOST_NEGATIVE_FIXNUM;
539 532
540/* Value is non-zero if I doesn't fit into a Lisp fixnum. It is 533/* Value is non-zero if I doesn't fit into a Lisp fixnum. It is
541 written this way so that it also works if I is of unsigned 534 written this way so that it also works if I is of unsigned
@@ -1796,20 +1789,6 @@ typedef struct {
1796#define CHECK_WINDOW_CONFIGURATION(x) \ 1789#define CHECK_WINDOW_CONFIGURATION(x) \
1797 CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x) 1790 CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x)
1798 1791
1799/* A window of any sort, leaf or interior, is "valid" if one of its
1800 buffer, vchild, or hchild members is non-nil. */
1801#define CHECK_VALID_WINDOW(x) \
1802 CHECK_TYPE (WINDOWP (x) \
1803 && (!NILP (XWINDOW (x)->buffer) \
1804 || !NILP (XWINDOW (x)->vchild) \
1805 || !NILP (XWINDOW (x)->hchild)), \
1806 Qwindow_valid_p, x)
1807
1808/* A window is "live" if and only if it shows a buffer. */
1809#define CHECK_LIVE_WINDOW(x) \
1810 CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), \
1811 Qwindow_live_p, x)
1812
1813#define CHECK_PROCESS(x) \ 1792#define CHECK_PROCESS(x) \
1814 CHECK_TYPE (PROCESSP (x), Qprocessp, x) 1793 CHECK_TYPE (PROCESSP (x), Qprocessp, x)
1815 1794
@@ -2663,9 +2642,6 @@ extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
2663 2642
2664EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST; 2643EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST;
2665 2644
2666/* Defined in frame.c. */
2667extern Lisp_Object Qframep;
2668
2669/* Defined in data.c. */ 2645/* Defined in data.c. */
2670extern Lisp_Object indirect_function (Lisp_Object); 2646extern Lisp_Object indirect_function (Lisp_Object);
2671extern Lisp_Object find_symbol_value (Lisp_Object); 2647extern Lisp_Object find_symbol_value (Lisp_Object);
@@ -3333,7 +3309,6 @@ extern Lisp_Object do_switch_frame (Lisp_Object, int, int, Lisp_Object);
3333#if HAVE_NS 3309#if HAVE_NS
3334extern Lisp_Object get_frame_param (struct frame *, Lisp_Object); 3310extern Lisp_Object get_frame_param (struct frame *, Lisp_Object);
3335#endif 3311#endif
3336extern Lisp_Object frame_buffer_predicate (Lisp_Object);
3337extern void frames_discard_buffer (Lisp_Object); 3312extern void frames_discard_buffer (Lisp_Object);
3338extern void syms_of_frame (void); 3313extern void syms_of_frame (void);
3339 3314
@@ -3479,6 +3454,7 @@ struct terminal;
3479extern char *get_current_dir_name (void); 3454extern char *get_current_dir_name (void);
3480#endif 3455#endif
3481extern void stuff_char (char c); 3456extern void stuff_char (char c);
3457extern void init_foreground_group (void);
3482extern void init_sigio (int); 3458extern void init_sigio (int);
3483extern void sys_subshell (void); 3459extern void sys_subshell (void);
3484extern void sys_suspend (void); 3460extern void sys_suspend (void);
diff --git a/src/lisp.mk b/src/lisp.mk
index 1f459d4d5f1..8c2710110e3 100644
--- a/src/lisp.mk
+++ b/src/lisp.mk
@@ -34,9 +34,9 @@
34## that does not have an explicit .el extension, but beware of any 34## that does not have an explicit .el extension, but beware of any
35## no-byte-compile ones. 35## no-byte-compile ones.
36 36
37## Confusingly, term/internal is not in loadup, but is unconditionally 37## Confusingly, international/cp51932 and international/eucjp-ms are
38## loaded by pc-win, which is. Ditto for international/cp51932 and 38## unconditionally loaded from language/japanese, instead of being
39## international/eucjp-ms, loaded from language/japanese. 39## loaded directly from loadup.el; FIXME.
40 40
41## Note that this list should not include lisp files which might not 41## Note that this list should not include lisp files which might not
42## be present, like site-load.el and site-init.el; this makefile 42## be present, like site-load.el and site-init.el; this makefile
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 5be1ccb70df..f5cab34d7dc 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -1475,8 +1475,8 @@ $(BLD)/unexw32.$(O) : \
1475 $(SRC)/w32.h \ 1475 $(SRC)/w32.h \
1476 $(SRC)/w32common.h \ 1476 $(SRC)/w32common.h \
1477 $(SRC)/w32heap.h \ 1477 $(SRC)/w32heap.h \
1478 $(LISP_H) \ 1478 $(CONFIG_H) \
1479 $(CONFIG_H) 1479 $(LISP_H)
1480 1480
1481$(BLD)/vm-limit.$(O) : \ 1481$(BLD)/vm-limit.$(O) : \
1482 $(SRC)/vm-limit.c \ 1482 $(SRC)/vm-limit.c \
@@ -1564,6 +1564,7 @@ $(BLD)/w32fns.$(O) : \
1564 $(SRC)/w32.h \ 1564 $(SRC)/w32.h \
1565 $(SRC)/w32common.h \ 1565 $(SRC)/w32common.h \
1566 $(SRC)/w32heap.h \ 1566 $(SRC)/w32heap.h \
1567 $(NT_INC)/unistd.h \
1567 $(BUFFER_H) \ 1568 $(BUFFER_H) \
1568 $(CCL_H) \ 1569 $(CCL_H) \
1569 $(CHARACTER_H) \ 1570 $(CHARACTER_H) \
diff --git a/src/minibuf.c b/src/minibuf.c
index 2cc89e75680..dcc4af37c13 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -472,6 +472,10 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
472 472
473 /* Choose the minibuffer window and frame, and take action on them. */ 473 /* Choose the minibuffer window and frame, and take action on them. */
474 474
475 /* Prepare for restoring the current buffer since choose_minibuf_frame
476 calling Fset_frame_selected_window may change it (Bug#12766). */
477 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
478
475 choose_minibuf_frame (); 479 choose_minibuf_frame ();
476 480
477 record_unwind_protect (choose_minibuf_frame_1, Qnil); 481 record_unwind_protect (choose_minibuf_frame_1, Qnil);
diff --git a/src/msdos.c b/src/msdos.c
index bac6b977fdf..dd05a8b2c5d 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -3305,7 +3305,7 @@ XMenuActivate (Display *foo, XMenu *menu, int *pane, int *selidx,
3305 Emacs will process them after we return and surprise the user. */ 3305 Emacs will process them after we return and surprise the user. */
3306 discard_mouse_events (); 3306 discard_mouse_events ();
3307 mouse_clear_clicks (); 3307 mouse_clear_clicks ();
3308 if (!kbd_buffer_events_waiting (1)) 3308 if (!kbd_buffer_events_waiting ())
3309 clear_input_pending (); 3309 clear_input_pending ();
3310 /* Allow mouse events generation by dos_rawgetc. */ 3310 /* Allow mouse events generation by dos_rawgetc. */
3311 mouse_preempted--; 3311 mouse_preempted--;
@@ -3927,8 +3927,10 @@ croak (char *badfunc)
3927/* 3927/*
3928 * A few unimplemented functions that we silently ignore. 3928 * A few unimplemented functions that we silently ignore.
3929 */ 3929 */
3930int setpgrp (void) {return 0; } 3930pid_t tcgetpgrp (int fd) { return 0; }
3931int setpgid (int pid, int pgid) { return 0; }
3931int setpriority (int x, int y, int z) { return 0; } 3932int setpriority (int x, int y, int z) { return 0; }
3933pid_t setsid (void) { return 0; }
3932 3934
3933#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4 3935#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 4
3934ssize_t 3936ssize_t
@@ -4214,8 +4216,8 @@ init_gettimeofday (void)
4214} 4216}
4215#endif 4217#endif
4216 4218
4217void 4219static void
4218emacs_abort (void) 4220msdos_abort (void)
4219{ 4221{
4220 dos_ttcooked (); 4222 dos_ttcooked ();
4221 ScreenSetCursor (10, 0); 4223 ScreenSetCursor (10, 0);
@@ -4233,6 +4235,15 @@ emacs_abort (void)
4233} 4235}
4234 4236
4235void 4237void
4238msdos_fatal_signal (int sig)
4239{
4240 if (sig == SIGABRT)
4241 msdos_abort ();
4242 else
4243 raise (sig);
4244}
4245
4246void
4236syms_of_msdos (void) 4247syms_of_msdos (void)
4237{ 4248{
4238 recent_doskeys = Fmake_vector (make_number (NUM_RECENT_DOSKEYS), Qnil); 4249 recent_doskeys = Fmake_vector (make_number (NUM_RECENT_DOSKEYS), Qnil);
diff --git a/src/nsfns.m b/src/nsfns.m
index 7a22ac547c3..e8bf696e7f5 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1175,7 +1175,6 @@ This function is an internal primitive--use `make-frame' instead. */)
1175 f = make_frame (1); 1175 f = make_frame (1);
1176 1176
1177 XSETFRAME (frame, f); 1177 XSETFRAME (frame, f);
1178 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
1179 1178
1180 f->terminal = dpyinfo->terminal; 1179 f->terminal = dpyinfo->terminal;
1181 1180
diff --git a/src/nsterm.m b/src/nsterm.m
index a4eaad47ac1..7ba1608268b 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -100,6 +100,7 @@ static unsigned convert_ns_to_X_keysym[] =
100 NSBeginFunctionKey, 0x58, 100 NSBeginFunctionKey, 0x58,
101 NSSelectFunctionKey, 0x60, 101 NSSelectFunctionKey, 0x60,
102 NSPrintFunctionKey, 0x61, 102 NSPrintFunctionKey, 0x61,
103 NSClearLineFunctionKey, 0x0B,
103 NSExecuteFunctionKey, 0x62, 104 NSExecuteFunctionKey, 0x62,
104 NSInsertFunctionKey, 0x63, 105 NSInsertFunctionKey, 0x63,
105 NSUndoFunctionKey, 0x65, 106 NSUndoFunctionKey, 0x65,
@@ -144,6 +145,23 @@ static unsigned convert_ns_to_X_keysym[] =
144 NSNewlineCharacter, 0x0D, 145 NSNewlineCharacter, 0x0D,
145 NSEnterCharacter, 0x8D, 146 NSEnterCharacter, 0x8D,
146 147
148 0x41|NSNumericPadKeyMask, 0xAE, /* KP_Decimal */
149 0x43|NSNumericPadKeyMask, 0xAA, /* KP_Multiply */
150 0x45|NSNumericPadKeyMask, 0xAB, /* KP_Add */
151 0x4B|NSNumericPadKeyMask, 0xAF, /* KP_Divide */
152 0x4E|NSNumericPadKeyMask, 0xAD, /* KP_Subtract */
153 0x51|NSNumericPadKeyMask, 0xBD, /* KP_Equal */
154 0x52|NSNumericPadKeyMask, 0xB0, /* KP_0 */
155 0x53|NSNumericPadKeyMask, 0xB1, /* KP_1 */
156 0x54|NSNumericPadKeyMask, 0xB2, /* KP_2 */
157 0x55|NSNumericPadKeyMask, 0xB3, /* KP_3 */
158 0x56|NSNumericPadKeyMask, 0xB4, /* KP_4 */
159 0x57|NSNumericPadKeyMask, 0xB5, /* KP_5 */
160 0x58|NSNumericPadKeyMask, 0xB6, /* KP_6 */
161 0x59|NSNumericPadKeyMask, 0xB7, /* KP_7 */
162 0x5B|NSNumericPadKeyMask, 0xB8, /* KP_8 */
163 0x5C|NSNumericPadKeyMask, 0xB9, /* KP_9 */
164
147 0x1B, 0x1B /* escape */ 165 0x1B, 0x1B /* escape */
148}; 166};
149 167
@@ -190,7 +208,8 @@ static BOOL ns_menu_bar_is_hidden = NO;
190 208
191/* event loop */ 209/* event loop */
192static BOOL send_appdefined = YES; 210static BOOL send_appdefined = YES;
193static NSEvent *last_appdefined_event = 0; 211#define NO_APPDEFINED_DATA (-8)
212static int last_appdefined_event_data = NO_APPDEFINED_DATA;
194static NSTimer *timed_entry = 0; 213static NSTimer *timed_entry = 0;
195static NSTimer *scroll_repeat_entry = nil; 214static NSTimer *scroll_repeat_entry = nil;
196static fd_set select_readfds, select_writefds; 215static fd_set select_readfds, select_writefds;
@@ -3436,8 +3455,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3436 -------------------------------------------------------------------------- */ 3455 -------------------------------------------------------------------------- */
3437{ 3456{
3438 int result; 3457 int result;
3439 NSEvent *ev; 3458 int t, k, nr = 0;
3440 int k, nr = 0;
3441 struct input_event event; 3459 struct input_event event;
3442 char c; 3460 char c;
3443 3461
@@ -3521,16 +3539,11 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3521 } 3539 }
3522 unblock_input (); 3540 unblock_input ();
3523 3541
3524 ev = last_appdefined_event; 3542 t = last_appdefined_event_data;
3525 3543
3526 if (ev) 3544 if (t != NO_APPDEFINED_DATA)
3527 { 3545 {
3528 int t; 3546 last_appdefined_event_data = NO_APPDEFINED_DATA;
3529 if ([ev type] != NSApplicationDefined)
3530 emacs_abort ();
3531
3532 t = [ev data1];
3533 last_appdefined_event = 0;
3534 3547
3535 if (t == -2) 3548 if (t == -2)
3536 { 3549 {
@@ -4307,7 +4320,7 @@ ns_term_shutdown (int sig)
4307 modal loop. Just defer it until later. */ 4320 modal loop. Just defer it until later. */
4308 if ([NSApp modalWindow] == nil) 4321 if ([NSApp modalWindow] == nil)
4309 { 4322 {
4310 last_appdefined_event = theEvent; 4323 last_appdefined_event_data = [theEvent data1];
4311 [self stop: self]; 4324 [self stop: self];
4312 } 4325 }
4313 else 4326 else
@@ -4759,12 +4772,12 @@ not_in_argv (NSString *arg)
4759 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (emacsframe); 4772 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (emacsframe);
4760 int code; 4773 int code;
4761 unsigned fnKeysym = 0; 4774 unsigned fnKeysym = 0;
4762 int flags;
4763 static NSMutableArray *nsEvArray; 4775 static NSMutableArray *nsEvArray;
4764#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 4776#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
4765 static BOOL firstTime = YES; 4777 static BOOL firstTime = YES;
4766#endif 4778#endif
4767 int left_is_none; 4779 int left_is_none;
4780 unsigned int flags = [theEvent modifierFlags];
4768 4781
4769 NSTRACE (keyDown); 4782 NSTRACE (keyDown);
4770 4783
@@ -4815,7 +4828,10 @@ not_in_argv (NSString *arg)
4815 /* (Carbon way: [theEvent keyCode]) */ 4828 /* (Carbon way: [theEvent keyCode]) */
4816 4829
4817 /* is it a "function key"? */ 4830 /* is it a "function key"? */
4818 fnKeysym = ns_convert_key (code); 4831 fnKeysym = (code < 0x00ff && (flags&NSNumericPadKeyMask))
4832 ? ns_convert_key ([theEvent keyCode] | NSNumericPadKeyMask)
4833 : ns_convert_key (code);
4834
4819 if (fnKeysym) 4835 if (fnKeysym)
4820 { 4836 {
4821 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace', 4837 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
@@ -4828,7 +4844,6 @@ not_in_argv (NSString *arg)
4828 4844
4829 /* are there modifiers? */ 4845 /* are there modifiers? */
4830 emacs_event->modifiers = 0; 4846 emacs_event->modifiers = 0;
4831 flags = [theEvent modifierFlags];
4832 4847
4833 if (flags & NSHelpKeyMask) 4848 if (flags & NSHelpKeyMask)
4834 emacs_event->modifiers |= hyper_modifier; 4849 emacs_event->modifiers |= hyper_modifier;
diff --git a/src/process.c b/src/process.c
index 307e82819d6..43f0239d301 100644
--- a/src/process.c
+++ b/src/process.c
@@ -130,6 +130,10 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *,
130 EMACS_TIME *, void *); 130 EMACS_TIME *, void *);
131#endif 131#endif
132 132
133/* This is for DOS_NT ports. FIXME: Remove this old portability cruft
134 by having DOS_NT ports implement waitpid instead of wait. Nowadays
135 POSIXish hosts all define waitpid, WNOHANG, and WUNTRACED, as these
136 have been standard since POSIX.1-1988. */
133#ifndef WNOHANG 137#ifndef WNOHANG
134# undef waitpid 138# undef waitpid
135# define waitpid(pid, status, options) wait (status) 139# define waitpid(pid, status, options) wait (status)
@@ -795,9 +799,8 @@ get_process (register Lisp_Object name)
795#ifdef SIGCHLD 799#ifdef SIGCHLD
796/* Fdelete_process promises to immediately forget about the process, but in 800/* Fdelete_process promises to immediately forget about the process, but in
797 reality, Emacs needs to remember those processes until they have been 801 reality, Emacs needs to remember those processes until they have been
798 treated by the SIGCHLD handler; otherwise this handler would consider the 802 treated by the SIGCHLD handler and waitpid has been invoked on them;
799 process as being synchronous and say that the synchronous process is 803 otherwise they might fill up the kernel's process table. */
800 dead. */
801static Lisp_Object deleted_pid_list; 804static Lisp_Object deleted_pid_list;
802#endif 805#endif
803 806
@@ -1704,16 +1707,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1704 if (inchannel > max_process_desc) 1707 if (inchannel > max_process_desc)
1705 max_process_desc = inchannel; 1708 max_process_desc = inchannel;
1706 1709
1707 /* Until we store the proper pid, enable the SIGCHLD handler 1710 /* This may signal an error. */
1708 to recognize an unknown pid as standing for this process.
1709 It is very important not to let this `marker' value stay
1710 in the table after this function has returned; if it does
1711 it might cause call-process to hang and subsequent asynchronous
1712 processes to get their return values scrambled. */
1713 XPROCESS (process)->pid = -1;
1714
1715 /* This must be called after the above line because it may signal an
1716 error. */
1717 setup_process_coding_systems (process); 1711 setup_process_coding_systems (process);
1718 1712
1719 encoded_current_dir = ENCODE_FILE (current_dir); 1713 encoded_current_dir = ENCODE_FILE (current_dir);
@@ -1745,7 +1739,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1745 /* Make the pty be the controlling terminal of the process. */ 1739 /* Make the pty be the controlling terminal of the process. */
1746#ifdef HAVE_PTYS 1740#ifdef HAVE_PTYS
1747 /* First, disconnect its current controlling terminal. */ 1741 /* First, disconnect its current controlling terminal. */
1748#ifdef HAVE_SETSID
1749 /* We tried doing setsid only if pty_flag, but it caused 1742 /* We tried doing setsid only if pty_flag, but it caused
1750 process_set_signal to fail on SGI when using a pipe. */ 1743 process_set_signal to fail on SGI when using a pipe. */
1751 setsid (); 1744 setsid ();
@@ -1758,14 +1751,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1758 ioctl (xforkin, TIOCSCTTY, 0); 1751 ioctl (xforkin, TIOCSCTTY, 0);
1759#endif 1752#endif
1760 } 1753 }
1761#else /* not HAVE_SETSID */
1762#ifdef USG
1763 /* It's very important to call setpgrp here and no time
1764 afterwards. Otherwise, we lose our controlling tty which
1765 is set when we open the pty. */
1766 setpgrp ();
1767#endif /* USG */
1768#endif /* not HAVE_SETSID */
1769#if defined (LDISC1) 1754#if defined (LDISC1)
1770 if (pty_flag && xforkin >= 0) 1755 if (pty_flag && xforkin >= 0)
1771 { 1756 {
@@ -1798,26 +1783,15 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1798 ioctl (j, TIOCNOTTY, 0); 1783 ioctl (j, TIOCNOTTY, 0);
1799 emacs_close (j); 1784 emacs_close (j);
1800 } 1785 }
1801#ifndef USG
1802 /* In order to get a controlling terminal on some versions
1803 of BSD, it is necessary to put the process in pgrp 0
1804 before it opens the terminal. */
1805#ifdef HAVE_SETPGID
1806 setpgid (0, 0);
1807#else
1808 setpgrp (0, 0);
1809#endif
1810#endif
1811 } 1786 }
1812#endif /* TIOCNOTTY */ 1787#endif /* TIOCNOTTY */
1813 1788
1814#if !defined (DONT_REOPEN_PTY) 1789#if !defined (DONT_REOPEN_PTY)
1815/*** There is a suggestion that this ought to be a 1790/*** There is a suggestion that this ought to be a
1816 conditional on TIOCSPGRP, 1791 conditional on TIOCSPGRP, or !defined TIOCSCTTY.
1817 or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
1818 Trying the latter gave the wrong results on Debian GNU/Linux 1.1; 1792 Trying the latter gave the wrong results on Debian GNU/Linux 1.1;
1819 that system does seem to need this code, even though 1793 that system does seem to need this code, even though
1820 both HAVE_SETSID and TIOCSCTTY are defined. */ 1794 both TIOCSCTTY is defined. */
1821 /* Now close the pty (if we had it open) and reopen it. 1795 /* Now close the pty (if we had it open) and reopen it.
1822 This makes the pty the controlling terminal of the subprocess. */ 1796 This makes the pty the controlling terminal of the subprocess. */
1823 if (pty_flag) 1797 if (pty_flag)
@@ -1886,6 +1860,8 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1886#endif 1860#endif
1887 1861
1888 XPROCESS (process)->pid = pid; 1862 XPROCESS (process)->pid = pid;
1863 if (0 <= pid)
1864 XPROCESS (process)->alive = 1;
1889 1865
1890 /* Stop blocking signals in the parent. */ 1866 /* Stop blocking signals in the parent. */
1891#ifdef SIGCHLD 1867#ifdef SIGCHLD
@@ -4443,7 +4419,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4443 if (EMACS_TIME_LT (timer_delay, timeout)) 4419 if (EMACS_TIME_LT (timer_delay, timeout))
4444 { 4420 {
4445 timeout = timer_delay; 4421 timeout = timer_delay;
4446 timeout_reduced_for_timers = 1; 4422 timeout_reduced_for_timers = 1;
4447 } 4423 }
4448 } 4424 }
4449 else 4425 else
@@ -6279,9 +6255,35 @@ process has been transmitted to the serial port. */)
6279 return process; 6255 return process;
6280} 6256}
6281 6257
6282/* On receipt of a signal that a child status has changed, loop asking 6258/* If the status of the process DESIRED has changed, return true and
6283 about children with changed statuses until the system says there 6259 set *STATUS to its exit status; otherwise, return false.
6284 are no more. 6260 If HAVE is nonnegative, assume that HAVE = waitpid (HAVE, STATUS, ...)
6261 has already been invoked, and do not invoke waitpid again. */
6262
6263static bool
6264process_status_retrieved (pid_t desired, pid_t have, int *status)
6265{
6266 if (have < 0)
6267 {
6268 /* Invoke waitpid only with a known process ID; do not invoke
6269 waitpid with a nonpositive argument. Otherwise, Emacs might
6270 reap an unwanted process by mistake. For example, invoking
6271 waitpid (-1, ...) can mess up glib by reaping glib's subprocesses,
6272 so that another thread running glib won't find them. */
6273 do
6274 have = waitpid (desired, status, WNOHANG | WUNTRACED);
6275 while (have < 0 && errno == EINTR);
6276 }
6277
6278 return have == desired;
6279}
6280
6281/* If PID is nonnegative, the child process PID with wait status W has
6282 changed its status; record this and return true.
6283
6284 If PID is negative, ignore W, and look for known child processes
6285 of Emacs whose status have changed. For each one found, record its new
6286 status.
6285 6287
6286 All we do is change the status; we do not run sentinels or print 6288 All we do is change the status; we do not run sentinels or print
6287 notifications. That is saved for the next time keyboard input is 6289 notifications. That is saved for the next time keyboard input is
@@ -6304,13 +6306,23 @@ process has been transmitted to the serial port. */)
6304 ** Malloc WARNING: This should never call malloc either directly or 6306 ** Malloc WARNING: This should never call malloc either directly or
6305 indirectly; if it does, that is a bug */ 6307 indirectly; if it does, that is a bug */
6306 6308
6307/* Record the changed status of the child process PID with wait status W. */
6308void 6309void
6309record_child_status_change (pid_t pid, int w) 6310record_child_status_change (pid_t pid, int w)
6310{ 6311{
6311#ifdef SIGCHLD 6312#ifdef SIGCHLD
6312 Lisp_Object proc; 6313
6313 struct Lisp_Process *p; 6314# ifdef WNOHANG
6315 /* On POSIXish hosts, record at most one child only if we already
6316 know one child that has exited. */
6317 bool record_at_most_one_child = 0 <= pid;
6318# else
6319 /* On DOS_NT (the only porting target that lacks WNOHANG),
6320 record the status of at most one child process, since the SIGCHLD
6321 handler must return right away. If any more processes want to
6322 signal us, we will get another signal. */
6323 bool record_at_most_one_child = 1;
6324# endif
6325
6314 Lisp_Object tail; 6326 Lisp_Object tail;
6315 6327
6316 /* Find the process that signaled us, and record its status. */ 6328 /* Find the process that signaled us, and record its status. */
@@ -6318,68 +6330,69 @@ record_child_status_change (pid_t pid, int w)
6318 /* The process can have been deleted by Fdelete_process. */ 6330 /* The process can have been deleted by Fdelete_process. */
6319 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) 6331 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail))
6320 { 6332 {
6333 bool all_pids_are_fixnums
6334 = (MOST_NEGATIVE_FIXNUM <= TYPE_MINIMUM (pid_t)
6335 && TYPE_MAXIMUM (pid_t) <= MOST_POSITIVE_FIXNUM);
6321 Lisp_Object xpid = XCAR (tail); 6336 Lisp_Object xpid = XCAR (tail);
6322 if ((INTEGERP (xpid) && pid == XINT (xpid)) 6337 if (all_pids_are_fixnums ? INTEGERP (xpid) : NUMBERP (xpid))
6323 || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid)))
6324 { 6338 {
6325 XSETCAR (tail, Qnil); 6339 pid_t deleted_pid;
6326 return; 6340 if (INTEGERP (xpid))
6341 deleted_pid = XINT (xpid);
6342 else
6343 deleted_pid = XFLOAT_DATA (xpid);
6344 if (process_status_retrieved (deleted_pid, pid, &w))
6345 {
6346 XSETCAR (tail, Qnil);
6347 if (record_at_most_one_child)
6348 return;
6349 }
6327 } 6350 }
6328 } 6351 }
6329 6352
6330 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ 6353 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */
6331 p = 0;
6332 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 6354 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
6333 { 6355 {
6334 proc = XCDR (XCAR (tail)); 6356 Lisp_Object proc = XCDR (XCAR (tail));
6335 p = XPROCESS (proc); 6357 struct Lisp_Process *p = XPROCESS (proc);
6336 if (EQ (p->type, Qreal) && p->pid == pid) 6358 if (p->alive && process_status_retrieved (p->pid, pid, &w))
6337 break; 6359 {
6338 p = 0; 6360 /* Change the status of the process that was found. */
6339 } 6361 p->tick = ++process_tick;
6340 6362 p->raw_status = w;
6341 /* Look for an asynchronous process whose pid hasn't been filled 6363 p->raw_status_new = 1;
6342 in yet. */
6343 if (! p)
6344 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
6345 {
6346 proc = XCDR (XCAR (tail));
6347 p = XPROCESS (proc);
6348 if (p->pid == -1)
6349 break;
6350 p = 0;
6351 }
6352 6364
6353 /* Change the status of the process that was found. */ 6365 /* If process has terminated, stop waiting for its output. */
6354 if (p) 6366 if (WIFSIGNALED (w) || WIFEXITED (w))
6355 { 6367 {
6356 int clear_desc_flag = 0; 6368 int clear_desc_flag = 0;
6369 p->alive = 0;
6370 if (p->infd >= 0)
6371 clear_desc_flag = 1;
6357 6372
6358 p->tick = ++process_tick; 6373 /* clear_desc_flag avoids a compiler bug in Microsoft C. */
6359 p->raw_status = w; 6374 if (clear_desc_flag)
6360 p->raw_status_new = 1; 6375 {
6376 FD_CLR (p->infd, &input_wait_mask);
6377 FD_CLR (p->infd, &non_keyboard_wait_mask);
6378 }
6379 }
6361 6380
6362 /* If process has terminated, stop waiting for its output. */ 6381 /* Tell wait_reading_process_output that it needs to wake up and
6363 if ((WIFSIGNALED (w) || WIFEXITED (w)) 6382 look around. */
6364 && p->infd >= 0) 6383 if (input_available_clear_time)
6365 clear_desc_flag = 1; 6384 *input_available_clear_time = make_emacs_time (0, 0);
6366 6385
6367 /* We use clear_desc_flag to avoid a compiler bug in Microsoft C. */ 6386 if (record_at_most_one_child)
6368 if (clear_desc_flag) 6387 return;
6369 {
6370 FD_CLR (p->infd, &input_wait_mask);
6371 FD_CLR (p->infd, &non_keyboard_wait_mask);
6372 } 6388 }
6373
6374 /* Tell wait_reading_process_output that it needs to wake up and
6375 look around. */
6376 if (input_available_clear_time)
6377 *input_available_clear_time = make_emacs_time (0, 0);
6378 } 6389 }
6379 /* There was no asynchronous process found for that pid: we have 6390
6380 a synchronous process. */ 6391 if (0 <= pid)
6381 else
6382 { 6392 {
6393 /* The caller successfully waited for a pid but no asynchronous
6394 process was found for it, so this is a synchronous process. */
6395
6383 synch_process_alive = 0; 6396 synch_process_alive = 0;
6384 6397
6385 /* Report the status of the synchronous process. */ 6398 /* Report the status of the synchronous process. */
@@ -6398,38 +6411,10 @@ record_child_status_change (pid_t pid, int w)
6398 6411
6399#ifdef SIGCHLD 6412#ifdef SIGCHLD
6400 6413
6401/* On some systems, the SIGCHLD handler must return right away. If
6402 any more processes want to signal us, we will get another signal.
6403 Otherwise, loop around to use up all the processes that have
6404 something to tell us. */
6405#if (defined WINDOWSNT \
6406 || (defined USG && !defined GNU_LINUX \
6407 && !(defined HPUX && defined WNOHANG)))
6408enum { CAN_HANDLE_MULTIPLE_CHILDREN = 0 };
6409#else
6410enum { CAN_HANDLE_MULTIPLE_CHILDREN = 1 };
6411#endif
6412
6413static void 6414static void
6414handle_child_signal (int sig) 6415handle_child_signal (int sig)
6415{ 6416{
6416 do 6417 record_child_status_change (-1, 0);
6417 {
6418 pid_t pid;
6419 int status;
6420
6421 do
6422 pid = waitpid (-1, &status, WNOHANG | WUNTRACED);
6423 while (pid < 0 && errno == EINTR);
6424
6425 /* PID == 0 means no processes found, PID == -1 means a real failure.
6426 Either way, we have done all our job. */
6427 if (pid <= 0)
6428 break;
6429
6430 record_child_status_change (pid, status);
6431 }
6432 while (CAN_HANDLE_MULTIPLE_CHILDREN);
6433} 6418}
6434 6419
6435static void 6420static void
diff --git a/src/process.h b/src/process.h
index ce3d2e702cc..74d1a124060 100644
--- a/src/process.h
+++ b/src/process.h
@@ -142,6 +142,9 @@ struct Lisp_Process
142 /* Flag to set coding-system of the process buffer from the 142 /* Flag to set coding-system of the process buffer from the
143 coding_system used to decode process output. */ 143 coding_system used to decode process output. */
144 unsigned int inherit_coding_system_flag : 1; 144 unsigned int inherit_coding_system_flag : 1;
145 /* Whether the process is alive, i.e., can be waited for. Running
146 processes can be waited for, but exited and fake processes cannot. */
147 unsigned int alive : 1;
145 /* Record the process status in the raw form in which it comes from `wait'. 148 /* Record the process status in the raw form in which it comes from `wait'.
146 This is to avoid consing in a signal handler. The `raw_status_new' 149 This is to avoid consing in a signal handler. The `raw_status_new'
147 flag indicates that `raw_status' contains a new status that still 150 flag indicates that `raw_status' contains a new status that still
diff --git a/src/sysdep.c b/src/sysdep.c
index c7174e91612..aa9d0f38c3c 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -452,7 +452,7 @@ sys_suspend (void)
452#if defined (SIGTSTP) && !defined (MSDOS) 452#if defined (SIGTSTP) && !defined (MSDOS)
453 453
454 { 454 {
455 pid_t pgrp = EMACS_GETPGRP (0); 455 pid_t pgrp = getpgrp ();
456 EMACS_KILLPG (pgrp, SIGTSTP); 456 EMACS_KILLPG (pgrp, SIGTSTP);
457 } 457 }
458 458
@@ -683,6 +683,75 @@ ignore_sigio (void)
683} 683}
684 684
685 685
686/* Saving and restoring the process group of Emacs's terminal. */
687
688/* The process group of which Emacs was a member when it initially
689 started.
690
691 If Emacs was in its own process group (i.e. inherited_pgroup ==
692 getpid ()), then we know we're running under a shell with job
693 control (Emacs would never be run as part of a pipeline).
694 Everything is fine.
695
696 If Emacs was not in its own process group, then we know we're
697 running under a shell (or a caller) that doesn't know how to
698 separate itself from Emacs (like sh). Emacs must be in its own
699 process group in order to receive SIGIO correctly. In this
700 situation, we put ourselves in our own pgroup, forcibly set the
701 tty's pgroup to our pgroup, and make sure to restore and reinstate
702 the tty's pgroup just like any other terminal setting. If
703 inherited_group was not the tty's pgroup, then we'll get a
704 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
705 it goes foreground in the future, which is what should happen. */
706
707static pid_t inherited_pgroup;
708
709void
710init_foreground_group (void)
711{
712 pid_t pgrp = getpgrp ();
713 inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
714}
715
716/* Safely set a controlling terminal FD's process group to PGID.
717 If we are not in the foreground already, POSIX requires tcsetpgrp
718 to deliver a SIGTTOU signal, which would stop us. This is an
719 annoyance, so temporarily ignore the signal.
720
721 In practice, platforms lacking SIGTTOU also lack tcsetpgrp, so
722 skip all this unless SIGTTOU is defined. */
723static void
724tcsetpgrp_without_stopping (int fd, pid_t pgid)
725{
726#ifdef SIGTTOU
727 signal_handler_t handler;
728 block_input ();
729 handler = signal (SIGTTOU, SIG_IGN);
730 tcsetpgrp (fd, pgid);
731 signal (SIGTTOU, handler);
732 unblock_input ();
733#endif
734}
735
736/* Split off the foreground process group to Emacs alone. When we are
737 in the foreground, but not started in our own process group,
738 redirect the tty device handle FD to point to our own process
739 group. FD must be the file descriptor of the controlling tty. */
740static void
741narrow_foreground_group (int fd)
742{
743 if (inherited_pgroup && setpgid (0, 0) == 0)
744 tcsetpgrp_without_stopping (fd, getpid ());
745}
746
747/* Set the tty to our original foreground group. */
748static void
749widen_foreground_group (int fd)
750{
751 if (inherited_pgroup && setpgid (0, inherited_pgroup) == 0)
752 tcsetpgrp_without_stopping (fd, inherited_pgroup);
753}
754
686/* Getting and setting emacs_tty structures. */ 755/* Getting and setting emacs_tty structures. */
687 756
688/* Set *TC to the parameters associated with the terminal FD. 757/* Set *TC to the parameters associated with the terminal FD.
@@ -799,6 +868,8 @@ init_sys_modes (struct tty_display_info *tty_out)
799 if (!tty_out->output) 868 if (!tty_out->output)
800 return; /* The tty is suspended. */ 869 return; /* The tty is suspended. */
801 870
871 narrow_foreground_group (fileno (tty_out->input));
872
802 if (! tty_out->old_tty) 873 if (! tty_out->old_tty)
803 tty_out->old_tty = xmalloc (sizeof *tty_out->old_tty); 874 tty_out->old_tty = xmalloc (sizeof *tty_out->old_tty);
804 875
@@ -1231,6 +1302,7 @@ reset_sys_modes (struct tty_display_info *tty_out)
1231 dos_ttcooked (); 1302 dos_ttcooked ();
1232#endif 1303#endif
1233 1304
1305 widen_foreground_group (fileno (tty_out->input));
1234} 1306}
1235 1307
1236#ifdef HAVE_PTYS 1308#ifdef HAVE_PTYS
diff --git a/src/systty.h b/src/systty.h
index b7f36c6c259..80bcaedf740 100644
--- a/src/systty.h
+++ b/src/systty.h
@@ -52,27 +52,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
52#endif /* not CDEL */ 52#endif /* not CDEL */
53#endif /* not _POSIX_VDISABLE */ 53#endif /* not _POSIX_VDISABLE */
54 54
55/* Get the number of characters queued for output. */
56
57/* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
58 queued for output to the terminal FD in *SIZE, if FD is a tty.
59 Returns -1 if there was an error (i.e. FD is not a tty), 0
60 otherwise. */
61#ifdef TIOCOUTQ
62#define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size)))
63#endif
64
65
66/* Manipulate a terminal's current process group. */
67
68/* EMACS_GETPGRP (arg) returns the process group of the process. */
69
70#if defined (GETPGRP_VOID)
71# define EMACS_GETPGRP(x) getpgrp()
72#else /* !GETPGRP_VOID */
73# define EMACS_GETPGRP(x) getpgrp(x)
74#endif /* !GETPGRP_VOID */
75
76/* Manipulate a TTY's input/output processing parameters. */ 55/* Manipulate a TTY's input/output processing parameters. */
77 56
78/* struct emacs_tty is a structure used to hold the current tty 57/* struct emacs_tty is a structure used to hold the current tty
diff --git a/src/term.c b/src/term.c
index 74b02b0af27..578c701858f 100644
--- a/src/term.c
+++ b/src/term.c
@@ -133,10 +133,6 @@ enum no_color_bit
133 133
134static int max_frame_cols; 134static int max_frame_cols;
135 135
136/* Non-zero if we have dropped our controlling tty and therefore
137 should not open a frame on stdout. */
138static int no_controlling_tty;
139
140 136
141 137
142#ifdef HAVE_GPM 138#ifdef HAVE_GPM
@@ -2918,36 +2914,9 @@ set_tty_hooks (struct terminal *terminal)
2918static void 2914static void
2919dissociate_if_controlling_tty (int fd) 2915dissociate_if_controlling_tty (int fd)
2920{ 2916{
2921#ifndef DOS_NT
2922 pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */ 2917 pid_t pgid = tcgetpgrp (fd); /* If tcgetpgrp succeeds, fd is the ctty. */
2923 if (pgid != -1) 2918 if (0 <= pgid)
2924 { 2919 setsid ();
2925#if defined (USG5)
2926 setpgrp ();
2927 no_controlling_tty = 1;
2928#elif defined (CYGWIN)
2929 setsid ();
2930 no_controlling_tty = 1;
2931#else
2932#ifdef TIOCNOTTY /* Try BSD ioctls. */
2933 sigset_t blocked;
2934 sigemptyset (&blocked);
2935 sigaddset (&blocked, SIGTTOU);
2936 pthread_sigmask (SIG_BLOCK, &blocked, 0);
2937 fd = emacs_open (DEV_TTY, O_RDWR, 0);
2938 if (fd != -1 && ioctl (fd, TIOCNOTTY, 0) != -1)
2939 {
2940 no_controlling_tty = 1;
2941 }
2942 if (fd != -1)
2943 emacs_close (fd);
2944 pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
2945#else
2946# error "Unknown system."
2947#endif /* ! TIOCNOTTY */
2948#endif /* ! USG */
2949 }
2950#endif /* !DOS_NT */
2951} 2920}
2952 2921
2953/* Create a termcap display on the tty device with the given name and 2922/* Create a termcap display on the tty device with the given name and
@@ -3235,7 +3204,6 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3235 FrameCols (tty) = FRAME_COLS (f); 3204 FrameCols (tty) = FRAME_COLS (f);
3236 tty->specified_window = FRAME_LINES (f); 3205 tty->specified_window = FRAME_LINES (f);
3237 3206
3238 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
3239 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none; 3207 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
3240 terminal->char_ins_del_ok = 1; 3208 terminal->char_ins_del_ok = 1;
3241 baud_rate = 19200; 3209 baud_rate = 19200;
diff --git a/src/termhooks.h b/src/termhooks.h
index 0b3260f13ab..256ba26e435 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -245,16 +245,8 @@ struct input_event
245 Lisp_Object x, y; 245 Lisp_Object x, y;
246 Time timestamp; 246 Time timestamp;
247 247
248 /* This is padding just to put the frame_or_window field 248 /* This field is copied into a vector while the event is in
249 past the size of struct selection_input_event. */ 249 the queue, so that garbage collections won't kill it. */
250 int *padding[2];
251
252 /* This field is copied into a vector while the event is in the queue,
253 so that garbage collections won't kill it. */
254 /* In a menu_bar_event, this is a cons cell whose car is the frame
255 and whose cdr is the Lisp object that is the event's value. */
256 /* This field is last so that struct selection_input_event
257 does not overlap with it. */
258 Lisp_Object frame_or_window; 250 Lisp_Object frame_or_window;
259 251
260 /* Additional event argument. This is used for TOOL_BAR_EVENTs and 252 /* Additional event argument. This is used for TOOL_BAR_EVENTs and
diff --git a/src/terminal.c b/src/terminal.c
index 2c0c60e7345..854ca61f19c 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -360,14 +360,7 @@ If FRAME is nil, the selected frame is used.
360The terminal device is represented by its integer identifier. */) 360The terminal device is represented by its integer identifier. */)
361 (Lisp_Object frame) 361 (Lisp_Object frame)
362{ 362{
363 struct terminal *t; 363 struct terminal *t = FRAME_TERMINAL (decode_live_frame (frame));
364
365 if (NILP (frame))
366 frame = selected_frame;
367
368 CHECK_LIVE_FRAME (frame);
369
370 t = FRAME_TERMINAL (XFRAME (frame));
371 364
372 if (!t) 365 if (!t)
373 return Qnil; 366 return Qnil;
diff --git a/src/w32fns.c b/src/w32fns.c
index 28e8ea02e05..24760054523 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -26,6 +26,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <limits.h> 26#include <limits.h>
27#include <errno.h> 27#include <errno.h>
28#include <math.h> 28#include <math.h>
29#include <fcntl.h>
30#include <unistd.h>
29 31
30#include "lisp.h" 32#include "lisp.h"
31#include "w32term.h" 33#include "w32term.h"
@@ -262,12 +264,8 @@ have_menus_p (void)
262FRAME_PTR 264FRAME_PTR
263check_x_frame (Lisp_Object frame) 265check_x_frame (Lisp_Object frame)
264{ 266{
265 FRAME_PTR f; 267 struct frame *f = decode_live_frame (frame);
266 268
267 if (NILP (frame))
268 frame = selected_frame;
269 CHECK_LIVE_FRAME (frame);
270 f = XFRAME (frame);
271 if (! FRAME_W32_P (f)) 269 if (! FRAME_W32_P (f))
272 error ("Non-W32 frame used"); 270 error ("Non-W32 frame used");
273 return f; 271 return f;
@@ -3331,7 +3329,19 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3331 versions, there is no way of telling when the mouse leaves the 3329 versions, there is no way of telling when the mouse leaves the
3332 frame, so we just have to put up with help-echo and mouse 3330 frame, so we just have to put up with help-echo and mouse
3333 highlighting remaining while the frame is not active. */ 3331 highlighting remaining while the frame is not active. */
3334 if (track_mouse_event_fn && !track_mouse_window) 3332 if (track_mouse_event_fn && !track_mouse_window
3333 /* If the menu bar is active, turning on tracking of mouse
3334 movement events might send these events to the tooltip
3335 frame, if the user happens to move the mouse pointer over
3336 the tooltip. But since we don't process events for
3337 tooltip frames, this causes Windows to present a
3338 hourglass cursor, which is ugly and unexpected. So don't
3339 enable tracking mouse events in this case; they will be
3340 restarted when the menu pops down. (Confusingly, the
3341 menubar_active member of f->output_data.w32, tested
3342 above, is only set when a menu was popped up _not_ from
3343 the frame's menu bar, but via x-popup-menu.) */
3344 && !menubar_in_use)
3335 { 3345 {
3336 TRACKMOUSEEVENT tme; 3346 TRACKMOUSEEVENT tme;
3337 tme.cbSize = sizeof (tme); 3347 tme.cbSize = sizeof (tme);
@@ -4271,9 +4281,6 @@ This function is an internal primitive--use `make-frame' instead. */)
4271 4281
4272 XSETFRAME (frame, f); 4282 XSETFRAME (frame, f);
4273 4283
4274 /* Note that Windows does support scroll bars. */
4275 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
4276
4277 /* By default, make scrollbars the system standard width. */ 4284 /* By default, make scrollbars the system standard width. */
4278 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL); 4285 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = GetSystemMetrics (SM_CXVSCROLL);
4279 4286
@@ -5374,7 +5381,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5374 Finsert (1, &text); 5381 Finsert (1, &text);
5375 set_buffer_internal_1 (old_buffer); 5382 set_buffer_internal_1 (old_buffer);
5376 5383
5377 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
5378 record_unwind_protect (unwind_create_tip_frame, frame); 5384 record_unwind_protect (unwind_create_tip_frame, frame);
5379 5385
5380 /* By setting the output method, we're essentially saying that 5386 /* By setting the output method, we're essentially saying that
@@ -7685,6 +7691,30 @@ globals_of_w32fns (void)
7685 syms_of_w32uniscribe (); 7691 syms_of_w32uniscribe ();
7686} 7692}
7687 7693
7694typedef USHORT (WINAPI * CaptureStackBackTrace_proc) (ULONG, ULONG, PVOID *,
7695 PULONG);
7696
7697#define BACKTRACE_LIMIT_MAX 62
7698
7699int
7700w32_backtrace (void **buffer, int limit)
7701{
7702 static CaptureStackBackTrace_proc s_pfn_CaptureStackBackTrace = NULL;
7703 HMODULE hm_kernel32 = NULL;
7704
7705 if (!s_pfn_CaptureStackBackTrace)
7706 {
7707 hm_kernel32 = LoadLibrary ("Kernel32.dll");
7708 s_pfn_CaptureStackBackTrace =
7709 (CaptureStackBackTrace_proc) GetProcAddress (hm_kernel32,
7710 "RtlCaptureStackBackTrace");
7711 }
7712 if (s_pfn_CaptureStackBackTrace)
7713 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX, limit),
7714 buffer, NULL);
7715 return 0;
7716}
7717
7688void 7718void
7689emacs_abort (void) 7719emacs_abort (void)
7690{ 7720{
@@ -7692,7 +7722,10 @@ emacs_abort (void)
7692 button = MessageBox (NULL, 7722 button = MessageBox (NULL,
7693 "A fatal error has occurred!\n\n" 7723 "A fatal error has occurred!\n\n"
7694 "Would you like to attach a debugger?\n\n" 7724 "Would you like to attach a debugger?\n\n"
7695 "Select YES to debug, NO to abort Emacs" 7725 "Select:\n"
7726 "YES -- to debug Emacs, or\n"
7727 "NO -- to abort Emacs and produce a backtrace\n"
7728 " (emacs_backtrace.txt in current directory)."
7696#if __GNUC__ 7729#if __GNUC__
7697 "\n\n(type \"gdb -p <emacs-PID>\" and\n" 7730 "\n\n(type \"gdb -p <emacs-PID>\" and\n"
7698 "\"continue\" inside GDB before clicking YES.)" 7731 "\"continue\" inside GDB before clicking YES.)"
@@ -7707,7 +7740,59 @@ emacs_abort (void)
7707 exit (2); /* tell the compiler we will never return */ 7740 exit (2); /* tell the compiler we will never return */
7708 case IDNO: 7741 case IDNO:
7709 default: 7742 default:
7710 abort (); 7743 {
7711 break; 7744 void *stack[BACKTRACE_LIMIT_MAX + 1];
7745 int i = w32_backtrace (stack, BACKTRACE_LIMIT_MAX + 1);
7746
7747 if (i)
7748 {
7749#ifdef CYGWIN
7750 int stderr_fd = 2;
7751#else
7752 HANDLE errout = GetStdHandle (STD_ERROR_HANDLE);
7753 int stderr_fd = -1;
7754#endif
7755 int errfile_fd = -1;
7756 int j;
7757
7758#ifndef CYGWIN
7759 if (errout && errout != INVALID_HANDLE_VALUE)
7760 stderr_fd = _open_osfhandle ((intptr_t)errout, O_APPEND | O_BINARY);
7761#endif
7762 if (stderr_fd >= 0)
7763 write (stderr_fd, "\r\nBacktrace:\r\n", 14);
7764 errfile_fd = _open ("emacs_backtrace.txt", O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
7765 if (errfile_fd >= 0)
7766 {
7767 lseek (errfile_fd, 0L, SEEK_END);
7768 write (errfile_fd, "\r\nBacktrace:\r\n", 14);
7769 }
7770
7771 for (j = 0; j < i; j++)
7772 {
7773 char buf[INT_BUFSIZE_BOUND (void *)];
7774
7775 /* stack[] gives the return addresses, whereas we want
7776 the address of the call, so decrease each address
7777 by approximate size of 1 CALL instruction. */
7778 sprintf (buf, "0x%p\r\n", stack[j] - sizeof(void *));
7779 if (stderr_fd >= 0)
7780 write (stderr_fd, buf, strlen (buf));
7781 if (errfile_fd >= 0)
7782 write (errfile_fd, buf, strlen (buf));
7783 }
7784 if (i == BACKTRACE_LIMIT_MAX)
7785 {
7786 if (stderr_fd >= 0)
7787 write (stderr_fd, "...\r\n", 5);
7788 if (errfile_fd >= 0)
7789 write (errfile_fd, "...\r\n", 5);
7790 }
7791 if (errfile_fd >= 0)
7792 close (errfile_fd);
7793 }
7794 abort ();
7795 break;
7796 }
7712 } 7797 }
7713} 7798}
diff --git a/src/w32proc.c b/src/w32proc.c
index 57b3860cb76..f35a2da537c 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -230,12 +230,30 @@ sigismember (const sigset_t *set, int signo)
230 return (*set & (1U << signo)) != 0; 230 return (*set & (1U << signo)) != 0;
231} 231}
232 232
233pid_t
234getpgrp (void)
235{
236 return getpid ();
237}
238
239pid_t
240tcgetpgrp (int fd)
241{
242 return getpid ();
243}
244
233int 245int
234setpgrp (int pid, int gid) 246setpgid (pid_t pid, pid_t pgid)
235{ 247{
236 return 0; 248 return 0;
237} 249}
238 250
251pid_t
252setsid (void)
253{
254 return getpid ();
255}
256
239/* Emulations of interval timers. 257/* Emulations of interval timers.
240 258
241 Limitations: only ITIMER_REAL and ITIMER_PROF are supported. 259 Limitations: only ITIMER_REAL and ITIMER_PROF are supported.
@@ -244,28 +262,92 @@ setpgrp (int pid, int gid)
244 the thread calls the appropriate signal handler when the timer 262 the thread calls the appropriate signal handler when the timer
245 expires, after stopping the thread which installed the timer. */ 263 expires, after stopping the thread which installed the timer. */
246 264
247/* FIXME: clock_t counts overflow after 49 days, need to handle the
248 wrap-around. */
249struct itimer_data { 265struct itimer_data {
250 clock_t expire; 266 volatile ULONGLONG expire;
251 clock_t reload; 267 volatile ULONGLONG reload;
252 int terminate; 268 volatile int terminate;
253 int type; 269 int type;
254 HANDLE caller_thread; 270 HANDLE caller_thread;
255 HANDLE timer_thread; 271 HANDLE timer_thread;
256}; 272};
257 273
258static clock_t ticks_now; 274static ULONGLONG ticks_now;
259static struct itimer_data real_itimer, prof_itimer; 275static struct itimer_data real_itimer, prof_itimer;
260static clock_t clocks_min; 276static ULONGLONG clocks_min;
261/* If non-zero, itimers are disabled. Used during shutdown, when we 277/* If non-zero, itimers are disabled. Used during shutdown, when we
262 delete the critical sections used by the timer threads. */ 278 delete the critical sections used by the timer threads. */
263static int disable_itimers; 279static int disable_itimers;
264 280
265static CRITICAL_SECTION crit_real, crit_prof; 281static CRITICAL_SECTION crit_real, crit_prof;
266 282
267#define MAX_SINGLE_SLEEP 30 283/* GetThreadTimes is not available on Windows 9X and possibly also on 2K. */
284typedef BOOL (WINAPI *GetThreadTimes_Proc) (
285 HANDLE hThread,
286 LPFILETIME lpCreationTime,
287 LPFILETIME lpExitTime,
288 LPFILETIME lpKernelTime,
289 LPFILETIME lpUserTime);
290
291static GetThreadTimes_Proc s_pfn_Get_Thread_Times;
292
293#define MAX_SINGLE_SLEEP 30
294#define TIMER_TICKS_PER_SEC 1000
295
296/* Return a suitable time value, in 1-ms units, for THREAD, a handle
297 to a thread. If THREAD is NULL or an invalid handle, return the
298 current wall-clock time since January 1, 1601 (UTC). Otherwise,
299 return the sum of kernel and user times used by THREAD since it was
300 created, plus its creation time. */
301static ULONGLONG
302w32_get_timer_time (HANDLE thread)
303{
304 ULONGLONG retval;
305 int use_system_time = 1;
306 /* The functions below return times in 100-ns units. */
307 const int tscale = 10 * TIMER_TICKS_PER_SEC;
308
309 if (thread && thread != INVALID_HANDLE_VALUE
310 && s_pfn_Get_Thread_Times != NULL)
311 {
312 FILETIME creation_ftime, exit_ftime, kernel_ftime, user_ftime;
313 ULARGE_INTEGER temp_creation, temp_kernel, temp_user;
268 314
315 if (s_pfn_Get_Thread_Times (thread, &creation_ftime, &exit_ftime,
316 &kernel_ftime, &user_ftime))
317 {
318 use_system_time = 0;
319 temp_creation.LowPart = creation_ftime.dwLowDateTime;
320 temp_creation.HighPart = creation_ftime.dwHighDateTime;
321 temp_kernel.LowPart = kernel_ftime.dwLowDateTime;
322 temp_kernel.HighPart = kernel_ftime.dwHighDateTime;
323 temp_user.LowPart = user_ftime.dwLowDateTime;
324 temp_user.HighPart = user_ftime.dwHighDateTime;
325 retval =
326 temp_creation.QuadPart / tscale + temp_kernel.QuadPart / tscale
327 + temp_user.QuadPart / tscale;
328 }
329 else
330 DebPrint (("GetThreadTimes failed with error code %lu\n",
331 GetLastError ()));
332 }
333
334 if (use_system_time)
335 {
336 FILETIME current_ftime;
337 ULARGE_INTEGER temp;
338
339 GetSystemTimeAsFileTime (&current_ftime);
340
341 temp.LowPart = current_ftime.dwLowDateTime;
342 temp.HighPart = current_ftime.dwHighDateTime;
343
344 retval = temp.QuadPart / tscale;
345 }
346
347 return retval;
348}
349
350/* Thread function for a timer thread. */
269static DWORD WINAPI 351static DWORD WINAPI
270timer_loop (LPVOID arg) 352timer_loop (LPVOID arg)
271{ 353{
@@ -273,14 +355,14 @@ timer_loop (LPVOID arg)
273 int which = itimer->type; 355 int which = itimer->type;
274 int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF; 356 int sig = (which == ITIMER_REAL) ? SIGALRM : SIGPROF;
275 CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof; 357 CRITICAL_SECTION *crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
276 const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / CLOCKS_PER_SEC; 358 const DWORD max_sleep = MAX_SINGLE_SLEEP * 1000 / TIMER_TICKS_PER_SEC;
277 int new_count = 0; 359 HANDLE hth = (which == ITIMER_REAL) ? NULL : itimer->caller_thread;
278 360
279 while (1) 361 while (1)
280 { 362 {
281 DWORD sleep_time; 363 DWORD sleep_time;
282 signal_handler handler; 364 signal_handler handler;
283 clock_t now, expire, reload; 365 ULONGLONG now, expire, reload;
284 366
285 /* Load new values if requested by setitimer. */ 367 /* Load new values if requested by setitimer. */
286 EnterCriticalSection (crit); 368 EnterCriticalSection (crit);
@@ -290,15 +372,14 @@ timer_loop (LPVOID arg)
290 if (itimer->terminate) 372 if (itimer->terminate)
291 return 0; 373 return 0;
292 374
293 if (itimer->expire == 0) 375 if (expire == 0)
294 { 376 {
295 /* We are idle. */ 377 /* We are idle. */
296 Sleep (max_sleep); 378 Sleep (max_sleep);
297 continue; 379 continue;
298 } 380 }
299 381
300 expire = itimer->expire; 382 if (expire > (now = w32_get_timer_time (hth)))
301 if (expire > (now = clock ()))
302 sleep_time = expire - now; 383 sleep_time = expire - now;
303 else 384 else
304 sleep_time = 0; 385 sleep_time = 0;
@@ -309,24 +390,30 @@ timer_loop (LPVOID arg)
309 if (itimer->terminate) 390 if (itimer->terminate)
310 return 0; 391 return 0;
311 Sleep (max_sleep); 392 Sleep (max_sleep);
393 EnterCriticalSection (crit);
312 expire = itimer->expire; 394 expire = itimer->expire;
313 sleep_time = (expire > (now = clock ())) ? expire - now : 0; 395 LeaveCriticalSection (crit);
396 sleep_time =
397 (expire > (now = w32_get_timer_time (hth))) ? expire - now : 0;
314 } 398 }
315 if (itimer->terminate) 399 if (itimer->terminate)
316 return 0; 400 return 0;
317 if (sleep_time > 0) 401 if (sleep_time > 0)
318 { 402 {
319 Sleep (sleep_time * 1000 / CLOCKS_PER_SEC); 403 Sleep (sleep_time * 1000 / TIMER_TICKS_PER_SEC);
320 /* Always sleep past the expiration time, to make sure we 404 /* Always sleep past the expiration time, to make sure we
321 never call the handler _before_ the expiration time, 405 never call the handler _before_ the expiration time,
322 always slightly after it. Sleep(5) makes sure we don't 406 always slightly after it. Sleep(5) makes sure we don't
323 hog the CPU by calling 'clock' with high frequency, and 407 hog the CPU by calling 'w32_get_timer_time' with high
324 also let other threads work. */ 408 frequency, and also let other threads work. */
325 while (clock () < expire) 409 while (w32_get_timer_time (hth) < expire)
326 Sleep (5); 410 Sleep (5);
327 } 411 }
328 412
329 if (itimer->expire == 0) 413 EnterCriticalSection (crit);
414 expire = itimer->expire;
415 LeaveCriticalSection (crit);
416 if (expire == 0)
330 continue; 417 continue;
331 418
332 /* Time's up. */ 419 /* Time's up. */
@@ -353,19 +440,21 @@ timer_loop (LPVOID arg)
353 ResumeThread (itimer->caller_thread); 440 ResumeThread (itimer->caller_thread);
354 } 441 }
355 442
356 if (itimer->expire == 0)
357 continue;
358
359 /* Update expiration time and loop. */ 443 /* Update expiration time and loop. */
360 EnterCriticalSection (crit); 444 EnterCriticalSection (crit);
361 expire = itimer->expire; 445 expire = itimer->expire;
446 if (expire == 0)
447 {
448 LeaveCriticalSection (crit);
449 continue;
450 }
362 reload = itimer->reload; 451 reload = itimer->reload;
363 if (reload > 0) 452 if (reload > 0)
364 { 453 {
365 now = clock (); 454 now = w32_get_timer_time (hth);
366 if (expire <= now) 455 if (expire <= now)
367 { 456 {
368 clock_t lag = now - expire; 457 ULONGLONG lag = now - expire;
369 458
370 /* If we missed some opportunities (presumably while 459 /* If we missed some opportunities (presumably while
371 sleeping or while the signal handler ran), skip 460 sleeping or while the signal handler ran), skip
@@ -448,6 +537,15 @@ term_timers (void)
448void 537void
449init_timers (void) 538init_timers (void)
450{ 539{
540 /* GetThreadTimes is not available on all versions of Windows, so
541 need to probe for its availability dynamically, and call it
542 through a pointer. */
543 s_pfn_Get_Thread_Times = NULL; /* in case dumped Emacs comes with a value */
544 if (os_subtype != OS_9X)
545 s_pfn_Get_Thread_Times =
546 (GetThreadTimes_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"),
547 "GetThreadTimes");
548
451 /* Make sure we start with zeroed out itimer structures, since 549 /* Make sure we start with zeroed out itimer structures, since
452 dumping may have left there traces of threads long dead. */ 550 dumping may have left there traces of threads long dead. */
453 memset (&real_itimer, 0, sizeof real_itimer); 551 memset (&real_itimer, 0, sizeof real_itimer);
@@ -473,14 +571,6 @@ start_timer_thread (int which)
473 return 0; 571 return 0;
474 572
475 /* Start a new thread. */ 573 /* Start a new thread. */
476 if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
477 GetCurrentProcess (), &itimer->caller_thread, 0,
478 FALSE, DUPLICATE_SAME_ACCESS))
479 {
480 errno = ESRCH;
481 return -1;
482 }
483
484 itimer->terminate = 0; 574 itimer->terminate = 0;
485 itimer->type = which; 575 itimer->type = which;
486 /* Request that no more than 64KB of stack be reserved for this 576 /* Request that no more than 64KB of stack be reserved for this
@@ -512,17 +602,16 @@ start_timer_thread (int which)
512int 602int
513getitimer (int which, struct itimerval *value) 603getitimer (int which, struct itimerval *value)
514{ 604{
515 volatile clock_t *t_expire; 605 volatile ULONGLONG *t_expire;
516 volatile clock_t *t_reload; 606 volatile ULONGLONG *t_reload;
517 clock_t expire, reload; 607 ULONGLONG expire, reload;
518 __int64 usecs; 608 __int64 usecs;
519 CRITICAL_SECTION *crit; 609 CRITICAL_SECTION *crit;
610 struct itimer_data *itimer;
520 611
521 if (disable_itimers) 612 if (disable_itimers)
522 return -1; 613 return -1;
523 614
524 ticks_now = clock ();
525
526 if (!value) 615 if (!value)
527 { 616 {
528 errno = EFAULT; 617 errno = EFAULT;
@@ -535,8 +624,22 @@ getitimer (int which, struct itimerval *value)
535 return -1; 624 return -1;
536 } 625 }
537 626
538 t_expire = (which == ITIMER_REAL) ? &real_itimer.expire: &prof_itimer.expire; 627 itimer = (which == ITIMER_REAL) ? &real_itimer : &prof_itimer;
539 t_reload = (which == ITIMER_REAL) ? &real_itimer.reload: &prof_itimer.reload; 628
629 if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
630 GetCurrentProcess (), &itimer->caller_thread, 0,
631 FALSE, DUPLICATE_SAME_ACCESS))
632 {
633 errno = ESRCH;
634 return -1;
635 }
636
637 ticks_now = w32_get_timer_time ((which == ITIMER_REAL)
638 ? NULL
639 : itimer->caller_thread);
640
641 t_expire = &itimer->expire;
642 t_reload = &itimer->reload;
540 crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof; 643 crit = (which == ITIMER_REAL) ? &crit_real : &crit_prof;
541 644
542 EnterCriticalSection (crit); 645 EnterCriticalSection (crit);
@@ -547,11 +650,13 @@ getitimer (int which, struct itimerval *value)
547 if (expire) 650 if (expire)
548 expire -= ticks_now; 651 expire -= ticks_now;
549 652
550 value->it_value.tv_sec = expire / CLOCKS_PER_SEC; 653 value->it_value.tv_sec = expire / TIMER_TICKS_PER_SEC;
551 usecs = (expire % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC; 654 usecs =
655 (expire % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC;
552 value->it_value.tv_usec = usecs; 656 value->it_value.tv_usec = usecs;
553 value->it_interval.tv_sec = reload / CLOCKS_PER_SEC; 657 value->it_interval.tv_sec = reload / TIMER_TICKS_PER_SEC;
554 usecs = (reload % CLOCKS_PER_SEC) * (__int64)1000000 / CLOCKS_PER_SEC; 658 usecs =
659 (reload % TIMER_TICKS_PER_SEC) * (__int64)1000000 / TIMER_TICKS_PER_SEC;
555 value->it_interval.tv_usec= usecs; 660 value->it_interval.tv_usec= usecs;
556 661
557 return 0; 662 return 0;
@@ -560,10 +665,11 @@ getitimer (int which, struct itimerval *value)
560int 665int
561setitimer(int which, struct itimerval *value, struct itimerval *ovalue) 666setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
562{ 667{
563 volatile clock_t *t_expire, *t_reload; 668 volatile ULONGLONG *t_expire, *t_reload;
564 clock_t expire, reload, expire_old, reload_old; 669 ULONGLONG expire, reload, expire_old, reload_old;
565 __int64 usecs; 670 __int64 usecs;
566 CRITICAL_SECTION *crit; 671 CRITICAL_SECTION *crit;
672 struct itimerval tem, *ptem;
567 673
568 if (disable_itimers) 674 if (disable_itimers)
569 return -1; 675 return -1;
@@ -573,26 +679,21 @@ setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
573 time we are called, measure the clock tick resolution. */ 679 time we are called, measure the clock tick resolution. */
574 if (!clocks_min) 680 if (!clocks_min)
575 { 681 {
576 clock_t t1, t2; 682 ULONGLONG t1, t2;
577 683
578 for (t1 = clock (); (t2 = clock ()) == t1; ) 684 for (t1 = w32_get_timer_time (NULL);
685 (t2 = w32_get_timer_time (NULL)) == t1; )
579 ; 686 ;
580 clocks_min = t2 - t1; 687 clocks_min = t2 - t1;
581 } 688 }
582 689
583 if (ovalue) 690 if (ovalue)
584 { 691 ptem = ovalue;
585 if (getitimer (which, ovalue)) /* also sets ticks_now */
586 return -1; /* errno already set */
587 }
588 else 692 else
589 ticks_now = clock (); 693 ptem = &tem;
590 694
591 if (which != ITIMER_REAL && which != ITIMER_PROF) 695 if (getitimer (which, ptem)) /* also sets ticks_now */
592 { 696 return -1; /* errno already set */
593 errno = EINVAL;
594 return -1;
595 }
596 697
597 t_expire = 698 t_expire =
598 (which == ITIMER_REAL) ? &real_itimer.expire : &prof_itimer.expire; 699 (which == ITIMER_REAL) ? &real_itimer.expire : &prof_itimer.expire;
@@ -612,26 +713,26 @@ setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
612 return 0; 713 return 0;
613 } 714 }
614 715
615 reload = value->it_interval.tv_sec * CLOCKS_PER_SEC; 716 reload = value->it_interval.tv_sec * TIMER_TICKS_PER_SEC;
616 717
617 usecs = value->it_interval.tv_usec; 718 usecs = value->it_interval.tv_usec;
618 if (value->it_interval.tv_sec == 0 719 if (value->it_interval.tv_sec == 0
619 && usecs && usecs * CLOCKS_PER_SEC < clocks_min * 1000000) 720 && usecs && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000)
620 reload = clocks_min; 721 reload = clocks_min;
621 else 722 else
622 { 723 {
623 usecs *= CLOCKS_PER_SEC; 724 usecs *= TIMER_TICKS_PER_SEC;
624 reload += usecs / 1000000; 725 reload += usecs / 1000000;
625 } 726 }
626 727
627 expire = value->it_value.tv_sec * CLOCKS_PER_SEC; 728 expire = value->it_value.tv_sec * TIMER_TICKS_PER_SEC;
628 usecs = value->it_value.tv_usec; 729 usecs = value->it_value.tv_usec;
629 if (value->it_value.tv_sec == 0 730 if (value->it_value.tv_sec == 0
630 && usecs * CLOCKS_PER_SEC < clocks_min * 1000000) 731 && usecs * TIMER_TICKS_PER_SEC < clocks_min * 1000000)
631 expire = clocks_min; 732 expire = clocks_min;
632 else 733 else
633 { 734 {
634 usecs *= CLOCKS_PER_SEC; 735 usecs *= TIMER_TICKS_PER_SEC;
635 expire += usecs / 1000000; 736 expire += usecs / 1000000;
636 } 737 }
637 738
@@ -1577,7 +1678,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
1577 numenv++; 1678 numenv++;
1578 } 1679 }
1579 /* extra env vars... */ 1680 /* extra env vars... */
1580 sprintf (ppid_env_var_buffer, "EM_PARENT_PROCESS_ID=%d", 1681 sprintf (ppid_env_var_buffer, "EM_PARENT_PROCESS_ID=%lu",
1581 GetCurrentProcessId ()); 1682 GetCurrentProcessId ());
1582 arglen += strlen (ppid_env_var_buffer) + 1; 1683 arglen += strlen (ppid_env_var_buffer) + 1;
1583 numenv++; 1684 numenv++;
diff --git a/src/widget.c b/src/widget.c
index 1f472c6231c..b4f7335c652 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -650,6 +650,16 @@ EmacsFrameInitialize (Widget request, Widget new, ArgList dum1, Cardinal *dum2)
650 set_frame_size (ew); 650 set_frame_size (ew);
651} 651}
652 652
653static void
654resize_cb (Widget widget,
655 XtPointer closure,
656 XEvent* event,
657 Boolean* continue_to_dispatch)
658{
659 EmacsFrame ew = (EmacsFrame) widget;
660 EmacsFrameResize (widget);
661}
662
653 663
654static void 664static void
655EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs) 665EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs)
@@ -665,6 +675,9 @@ EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs
665 *mask |= CWEventMask; 675 *mask |= CWEventMask;
666 XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask, 676 XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask,
667 attrs); 677 attrs);
678 /* Some ConfigureNotify events does not end up in EmacsFrameResize so
679 make sure we get them all. Seen with xfcwm4 for example. */
680 XtAddRawEventHandler (widget, StructureNotifyMask, False, resize_cb, NULL);
668 update_wm_hints (ew); 681 update_wm_hints (ew);
669} 682}
670 683
@@ -691,15 +704,22 @@ EmacsFrameResize (Widget widget)
691{ 704{
692 EmacsFrame ew = (EmacsFrame)widget; 705 EmacsFrame ew = (EmacsFrame)widget;
693 struct frame *f = ew->emacs_frame.frame; 706 struct frame *f = ew->emacs_frame.frame;
707 struct x_output *x = f->output_data.x;
694 int columns; 708 int columns;
695 int rows; 709 int rows;
696 710
697 pixel_to_char_size (ew, ew->core.width, ew->core.height, &columns, &rows); 711 pixel_to_char_size (ew, ew->core.width, ew->core.height, &columns, &rows);
698 change_frame_size (f, rows, columns, 0, 1, 0); 712 if (columns != FRAME_COLS (f)
699 update_wm_hints (ew); 713 || rows != FRAME_LINES (f)
700 update_various_frame_slots (ew); 714 || ew->core.width != FRAME_PIXEL_WIDTH (f)
715 || ew->core.height + x->menubar_height != FRAME_PIXEL_HEIGHT (f))
716 {
717 change_frame_size (f, rows, columns, 0, 1, 0);
718 update_wm_hints (ew);
719 update_various_frame_slots (ew);
701 720
702 cancel_mouse_face (f); 721 cancel_mouse_face (f);
722 }
703} 723}
704 724
705static Boolean 725static Boolean
diff --git a/src/window.c b/src/window.c
index c34e0d9300e..514119abef5 100644
--- a/src/window.c
+++ b/src/window.c
@@ -245,7 +245,7 @@ decode_live_window (register Lisp_Object window)
245 return XWINDOW (window); 245 return XWINDOW (window);
246} 246}
247 247
248static struct window * 248struct window *
249decode_any_window (register Lisp_Object window) 249decode_any_window (register Lisp_Object window)
250{ 250{
251 struct window *w; 251 struct window *w;
@@ -271,6 +271,15 @@ decode_valid_window (register Lisp_Object window)
271 return w; 271 return w;
272} 272}
273 273
274/* Build a frequently used 4-integer (X Y W H) list. */
275
276static Lisp_Object
277quad (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
278{
279 return list4 (make_number (x), make_number (y),
280 make_number (w), make_number (h));
281}
282
274DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, 283DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
275 doc: /* Return t if OBJECT is a window and nil otherwise. */) 284 doc: /* Return t if OBJECT is a window and nil otherwise. */)
276 (Lisp_Object object) 285 (Lisp_Object object)
@@ -297,7 +306,7 @@ Internal windows and deleted windows are not live. */)
297} 306}
298 307
299/* Frames and windows. */ 308/* Frames and windows. */
300DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0, 309DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 0, 1, 0,
301 doc: /* Return the frame that window WINDOW is on. 310 doc: /* Return the frame that window WINDOW is on.
302WINDOW must be a valid window and defaults to the selected one. */) 311WINDOW must be a valid window and defaults to the selected one. */)
303 (Lisp_Object window) 312 (Lisp_Object window)
@@ -332,10 +341,7 @@ DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
332If FRAME is omitted or nil, it defaults to the selected frame. */) 341If FRAME is omitted or nil, it defaults to the selected frame. */)
333 (Lisp_Object frame) 342 (Lisp_Object frame)
334{ 343{
335 if (NILP (frame)) 344 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame));
336 frame = selected_frame;
337 CHECK_LIVE_FRAME (frame);
338 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
339} 345}
340 346
341DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 347DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
@@ -557,7 +563,7 @@ Return nil for a window with no parent (e.g. a root window). */)
557 return decode_valid_window (window)->parent; 563 return decode_valid_window (window)->parent;
558} 564}
559 565
560DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 1, 1, 0, 566DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 0, 1, 0,
561 doc: /* Return the topmost child window of window WINDOW. 567 doc: /* Return the topmost child window of window WINDOW.
562WINDOW must be a valid window and defaults to the selected one. 568WINDOW must be a valid window and defaults to the selected one.
563Return nil if WINDOW is a live window (live windows have no children). 569Return nil if WINDOW is a live window (live windows have no children).
@@ -565,11 +571,10 @@ Return nil if WINDOW is an internal window whose children form a
565horizontal combination. */) 571horizontal combination. */)
566 (Lisp_Object window) 572 (Lisp_Object window)
567{ 573{
568 CHECK_WINDOW (window);
569 return decode_valid_window (window)->vchild; 574 return decode_valid_window (window)->vchild;
570} 575}
571 576
572DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 1, 1, 0, 577DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 0, 1, 0,
573 doc: /* Return the leftmost child window of window WINDOW. 578 doc: /* Return the leftmost child window of window WINDOW.
574WINDOW must be a valid window and defaults to the selected one. 579WINDOW must be a valid window and defaults to the selected one.
575Return nil if WINDOW is a live window (live windows have no children). 580Return nil if WINDOW is a live window (live windows have no children).
@@ -577,7 +582,6 @@ Return nil if WINDOW is an internal window whose children form a
577vertical combination. */) 582vertical combination. */)
578 (Lisp_Object window) 583 (Lisp_Object window)
579{ 584{
580 CHECK_WINDOW (window);
581 return decode_valid_window (window)->hchild; 585 return decode_valid_window (window)->hchild;
582} 586}
583 587
@@ -601,13 +605,16 @@ Return nil if WINDOW has no previous sibling. */)
601 605
602DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0, 606DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0,
603 doc: /* Return combination limit of window WINDOW. 607 doc: /* Return combination limit of window WINDOW.
604WINDOW must be a valid window and defaults to the selected one.
605If the return value is nil, child windows of WINDOW can be recombined with 608If the return value is nil, child windows of WINDOW can be recombined with
606WINDOW's siblings. A return value of t means that child windows of 609WINDOW's siblings. A return value of t means that child windows of
607WINDOW are never \(re-)combined with WINDOW's siblings. */) 610WINDOW are never \(re-)combined with WINDOW's siblings.
611
612WINDOW must be a valid window. The return value is meaningful for
613internal windows only. */)
608 (Lisp_Object window) 614 (Lisp_Object window)
609{ 615{
610 return decode_valid_window (window)->combination_limit; 616 CHECK_VALID_WINDOW (window);
617 return XWINDOW (window)->combination_limit;
611} 618}
612 619
613DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0, 620DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
@@ -775,8 +782,7 @@ area is only partially visible, that counts as a whole line; to
775exclude partially-visible lines, use `window-text-height'. */) 782exclude partially-visible lines, use `window-text-height'. */)
776 (Lisp_Object window) 783 (Lisp_Object window)
777{ 784{
778 struct window *w = decode_live_window (window); 785 return make_number (window_body_lines (decode_live_window (window)));
779 return make_number (window_body_lines (w));
780} 786}
781 787
782DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0, 788DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0,
@@ -788,8 +794,7 @@ marginal areas, or scroll bars. On a graphical display, the width is
788expressed as an integer multiple of the default character width. */) 794expressed as an integer multiple of the default character width. */)
789 (Lisp_Object window) 795 (Lisp_Object window)
790{ 796{
791 struct window *w = decode_live_window (window); 797 return make_number (window_body_cols (decode_live_window (window)));
792 return make_number (window_body_cols (w));
793} 798}
794 799
795DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, 800DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
@@ -832,10 +837,8 @@ Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
832window so that the location of point moves off-window. */) 837window so that the location of point moves off-window. */)
833 (Lisp_Object window, Lisp_Object ncol) 838 (Lisp_Object window, Lisp_Object ncol)
834{ 839{
835 struct window *w = decode_live_window (window);
836
837 CHECK_NUMBER (ncol); 840 CHECK_NUMBER (ncol);
838 return set_window_hscroll (w, XINT (ncol)); 841 return set_window_hscroll (decode_live_window (window), XINT (ncol));
839} 842}
840 843
841DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger, 844DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
@@ -880,11 +883,8 @@ header line, and/or mode line. For the edges of just the text area, use
880{ 883{
881 register struct window *w = decode_valid_window (window); 884 register struct window *w = decode_valid_window (window);
882 885
883 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)), 886 return quad (WINDOW_LEFT_EDGE_COL (w), WINDOW_TOP_EDGE_LINE (w),
884 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)), 887 WINDOW_RIGHT_EDGE_COL (w), WINDOW_BOTTOM_EDGE_LINE (w));
885 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
886 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
887 Qnil))));
888} 888}
889 889
890DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0, 890DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
@@ -903,11 +903,8 @@ of just the text area, use `window-inside-pixel-edges'. */)
903{ 903{
904 register struct window *w = decode_valid_window (window); 904 register struct window *w = decode_valid_window (window);
905 905
906 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)), 906 return quad (WINDOW_LEFT_EDGE_X (w), WINDOW_TOP_EDGE_Y (w),
907 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)), 907 WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
908 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
909 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
910 Qnil))));
911} 908}
912 909
913static void 910static void
@@ -949,13 +946,13 @@ of just the text area, use `window-inside-absolute-pixel-edges'. */)
949{ 946{
950 register struct window *w = decode_valid_window (window); 947 register struct window *w = decode_valid_window (window);
951 int add_x, add_y; 948 int add_x, add_y;
949
952 calc_absolute_offset (w, &add_x, &add_y); 950 calc_absolute_offset (w, &add_x, &add_y);
953 951
954 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w) + add_x), 952 return quad (WINDOW_LEFT_EDGE_X (w) + add_x,
955 Fcons (make_number (WINDOW_TOP_EDGE_Y (w) + add_y), 953 WINDOW_TOP_EDGE_Y (w) + add_y,
956 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w) + add_x), 954 WINDOW_RIGHT_EDGE_X (w) + add_x,
957 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w) + add_y), 955 WINDOW_BOTTOM_EDGE_Y (w) + add_y);
958 Qnil))));
959} 956}
960 957
961DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0, 958DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
@@ -974,16 +971,16 @@ display margins, fringes, header line, and/or mode line. */)
974{ 971{
975 register struct window *w = decode_live_window (window); 972 register struct window *w = decode_live_window (window);
976 973
977 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w) 974 return quad (WINDOW_BOX_LEFT_EDGE_COL (w)
978 + WINDOW_LEFT_MARGIN_COLS (w) 975 + WINDOW_LEFT_MARGIN_COLS (w)
979 + WINDOW_LEFT_FRINGE_COLS (w)), 976 + WINDOW_LEFT_FRINGE_COLS (w),
980 make_number (WINDOW_TOP_EDGE_LINE (w) 977 WINDOW_TOP_EDGE_LINE (w)
981 + WINDOW_HEADER_LINE_LINES (w)), 978 + WINDOW_HEADER_LINE_LINES (w),
982 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w) 979 WINDOW_BOX_RIGHT_EDGE_COL (w)
983 - WINDOW_RIGHT_MARGIN_COLS (w) 980 - WINDOW_RIGHT_MARGIN_COLS (w)
984 - WINDOW_RIGHT_FRINGE_COLS (w)), 981 - WINDOW_RIGHT_FRINGE_COLS (w),
985 make_number (WINDOW_BOTTOM_EDGE_LINE (w) 982 WINDOW_BOTTOM_EDGE_LINE (w)
986 - WINDOW_MODE_LINE_LINES (w))); 983 - WINDOW_MODE_LINE_LINES (w));
987} 984}
988 985
989DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0, 986DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
@@ -1001,16 +998,16 @@ display margins, fringes, header line, and/or mode line. */)
1001{ 998{
1002 register struct window *w = decode_live_window (window); 999 register struct window *w = decode_live_window (window);
1003 1000
1004 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w) 1001 return quad (WINDOW_BOX_LEFT_EDGE_X (w)
1005 + WINDOW_LEFT_MARGIN_WIDTH (w) 1002 + WINDOW_LEFT_MARGIN_WIDTH (w)
1006 + WINDOW_LEFT_FRINGE_WIDTH (w)), 1003 + WINDOW_LEFT_FRINGE_WIDTH (w),
1007 make_number (WINDOW_TOP_EDGE_Y (w) 1004 WINDOW_TOP_EDGE_Y (w)
1008 + WINDOW_HEADER_LINE_HEIGHT (w)), 1005 + WINDOW_HEADER_LINE_HEIGHT (w),
1009 make_number (WINDOW_BOX_RIGHT_EDGE_X (w) 1006 WINDOW_BOX_RIGHT_EDGE_X (w)
1010 - WINDOW_RIGHT_MARGIN_WIDTH (w) 1007 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1011 - WINDOW_RIGHT_FRINGE_WIDTH (w)), 1008 - WINDOW_RIGHT_FRINGE_WIDTH (w),
1012 make_number (WINDOW_BOTTOM_EDGE_Y (w) 1009 WINDOW_BOTTOM_EDGE_Y (w)
1013 - WINDOW_MODE_LINE_HEIGHT (w))); 1010 - WINDOW_MODE_LINE_HEIGHT (w));
1014} 1011}
1015 1012
1016DEFUN ("window-inside-absolute-pixel-edges", 1013DEFUN ("window-inside-absolute-pixel-edges",
@@ -1030,18 +1027,19 @@ display margins, fringes, header line, and/or mode line. */)
1030{ 1027{
1031 register struct window *w = decode_live_window (window); 1028 register struct window *w = decode_live_window (window);
1032 int add_x, add_y; 1029 int add_x, add_y;
1030
1033 calc_absolute_offset (w, &add_x, &add_y); 1031 calc_absolute_offset (w, &add_x, &add_y);
1034 1032
1035 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w) 1033 return quad (WINDOW_BOX_LEFT_EDGE_X (w)
1036 + WINDOW_LEFT_MARGIN_WIDTH (w) 1034 + WINDOW_LEFT_MARGIN_WIDTH (w)
1037 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x), 1035 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x,
1038 make_number (WINDOW_TOP_EDGE_Y (w) 1036 WINDOW_TOP_EDGE_Y (w)
1039 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y), 1037 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y,
1040 make_number (WINDOW_BOX_RIGHT_EDGE_X (w) 1038 WINDOW_BOX_RIGHT_EDGE_X (w)
1041 - WINDOW_RIGHT_MARGIN_WIDTH (w) 1039 - WINDOW_RIGHT_MARGIN_WIDTH (w)
1042 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x), 1040 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x,
1043 make_number (WINDOW_BOTTOM_EDGE_Y (w) 1041 WINDOW_BOTTOM_EDGE_Y (w)
1044 - WINDOW_MODE_LINE_HEIGHT (w) + add_y)); 1042 - WINDOW_MODE_LINE_HEIGHT (w) + add_y);
1045} 1043}
1046 1044
1047/* Test if the character at column X, row Y is within window W. 1045/* Test if the character at column X, row Y is within window W.
@@ -1374,12 +1372,7 @@ The top left corner of the frame is considered to be row 0,
1374column 0. */) 1372column 0. */)
1375 (Lisp_Object x, Lisp_Object y, Lisp_Object frame) 1373 (Lisp_Object x, Lisp_Object y, Lisp_Object frame)
1376{ 1374{
1377 struct frame *f; 1375 struct frame *f = decode_live_frame (frame);
1378
1379 if (NILP (frame))
1380 frame = selected_frame;
1381 CHECK_LIVE_FRAME (frame);
1382 f = XFRAME (frame);
1383 1376
1384 /* Check that arguments are integers or floats. */ 1377 /* Check that arguments are integers or floats. */
1385 CHECK_NUMBER_OR_FLOAT (x); 1378 CHECK_NUMBER_OR_FLOAT (x);
@@ -1627,8 +1620,7 @@ display row, and VPOS is the row number (0-based) containing POS. */)
1627 { 1620 {
1628 Lisp_Object part = Qnil; 1621 Lisp_Object part = Qnil;
1629 if (!fully_p) 1622 if (!fully_p)
1630 part = list4 (make_number (rtop), make_number (rbot), 1623 part = quad (rtop, rbot, rowh, vpos);
1631 make_number (rowh), make_number (vpos));
1632 in_window = Fcons (make_number (x), 1624 in_window = Fcons (make_number (x),
1633 Fcons (make_number (y), part)); 1625 Fcons (make_number (y), part));
1634 } 1626 }
@@ -1694,23 +1686,18 @@ Return nil if window display is not up-to-date. In that case, use
1694 if (!WINDOW_WANTS_HEADER_LINE_P (w)) 1686 if (!WINDOW_WANTS_HEADER_LINE_P (w))
1695 return Qnil; 1687 return Qnil;
1696 row = MATRIX_HEADER_LINE_ROW (w->current_matrix); 1688 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
1697 if (!row->enabled_p) 1689 return row->enabled_p ? quad (row->height, 0, 0, 0) : Qnil;
1698 return Qnil;
1699 return list4 (make_number (row->height),
1700 make_number (0), make_number (0),
1701 make_number (0));
1702 } 1690 }
1703 1691
1704 if (EQ (line, Qmode_line)) 1692 if (EQ (line, Qmode_line))
1705 { 1693 {
1706 row = MATRIX_MODE_LINE_ROW (w->current_matrix); 1694 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
1707 if (!row->enabled_p) 1695 return (row->enabled_p ?
1708 return Qnil; 1696 quad (row->height,
1709 return list4 (make_number (row->height), 1697 0, /* not accurate */
1710 make_number (0), /* not accurate */ 1698 WINDOW_HEADER_LINE_HEIGHT (w)
1711 make_number (WINDOW_HEADER_LINE_HEIGHT (w) 1699 + window_text_bottom_y (w), 0)
1712 + window_text_bottom_y (w)), 1700 : Qnil);
1713 make_number (0));
1714 } 1701 }
1715 1702
1716 CHECK_NUMBER (line); 1703 CHECK_NUMBER (line);
@@ -1739,10 +1726,7 @@ Return nil if window display is not up-to-date. In that case, use
1739 1726
1740 found_row: 1727 found_row:
1741 crop = max (0, (row->y + row->height) - max_y); 1728 crop = max (0, (row->y + row->height) - max_y);
1742 return list4 (make_number (row->height + min (0, row->y) - crop), 1729 return quad (row->height + min (0, row->y) - crop, i, row->y, crop);
1743 make_number (i),
1744 make_number (row->y),
1745 make_number (crop));
1746} 1730}
1747 1731
1748DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, 1732DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
@@ -2253,11 +2237,9 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf
2253static void 2237static void
2254decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames) 2238decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames)
2255{ 2239{
2256 if (NILP (*window)) 2240 struct window *w = decode_live_window (*window);
2257 *window = selected_window;
2258 else
2259 CHECK_LIVE_WINDOW (*window);
2260 2241
2242 XSETWINDOW (*window, w);
2261 /* MINIBUF nil may or may not include minibuffers. Decide if it 2243 /* MINIBUF nil may or may not include minibuffers. Decide if it
2262 does. */ 2244 does. */
2263 if (NILP (*minibuf)) 2245 if (NILP (*minibuf))
@@ -2273,7 +2255,7 @@ decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object
2273 if (NILP (*all_frames)) 2255 if (NILP (*all_frames))
2274 *all_frames 2256 *all_frames
2275 = (!EQ (*minibuf, Qlambda) 2257 = (!EQ (*minibuf, Qlambda)
2276 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame)) 2258 ? FRAME_MINIBUF_WINDOW (XFRAME (w->frame))
2277 : Qnil); 2259 : Qnil);
2278 else if (EQ (*all_frames, Qvisible)) 2260 else if (EQ (*all_frames, Qvisible))
2279 ; 2261 ;
@@ -3123,12 +3105,12 @@ run_window_configuration_change_hook (struct frame *f)
3123} 3105}
3124 3106
3125DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook, 3107DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
3126 Srun_window_configuration_change_hook, 1, 1, 0, 3108 Srun_window_configuration_change_hook, 0, 1, 0,
3127 doc: /* Run `window-configuration-change-hook' for FRAME. */) 3109 doc: /* Run `window-configuration-change-hook' for FRAME.
3110If FRAME is omitted or nil, it defaults to the selected frame. */)
3128 (Lisp_Object frame) 3111 (Lisp_Object frame)
3129{ 3112{
3130 CHECK_LIVE_FRAME (frame); 3113 run_window_configuration_change_hook (decode_live_frame (frame));
3131 run_window_configuration_change_hook (XFRAME (frame));
3132 return Qnil; 3114 return Qnil;
3133} 3115}
3134 3116
@@ -3655,10 +3637,12 @@ window_resize_apply (struct window *w, int horflag)
3655} 3637}
3656 3638
3657 3639
3658DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 1, 2, 0, 3640DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 0, 2, 0,
3659 doc: /* Apply requested size values for window-tree of FRAME. 3641 doc: /* Apply requested size values for window-tree of FRAME.
3660Optional argument HORIZONTAL omitted or nil means apply requested height 3642If FRAME is omitted or nil, it defaults to the selected frame.
3661values. HORIZONTAL non-nil means apply requested width values. 3643
3644Optional argument HORIZONTAL omitted or nil means apply requested
3645height values. HORIZONTAL non-nil means apply requested width values.
3662 3646
3663This function checks whether the requested values sum up to a valid 3647This function checks whether the requested values sum up to a valid
3664window layout, recursively assigns the new sizes of all child windows 3648window layout, recursively assigns the new sizes of all child windows
@@ -3669,17 +3653,10 @@ Note: This function does not check any of `window-fixed-size-p',
3669be applied on the Elisp level. */) 3653be applied on the Elisp level. */)
3670 (Lisp_Object frame, Lisp_Object horizontal) 3654 (Lisp_Object frame, Lisp_Object horizontal)
3671{ 3655{
3672 struct frame *f; 3656 struct frame *f = decode_live_frame (frame);
3673 struct window *r; 3657 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
3674 int horflag = !NILP (horizontal); 3658 int horflag = !NILP (horizontal);
3675 3659
3676 if (NILP (frame))
3677 frame = selected_frame;
3678 CHECK_LIVE_FRAME (frame);
3679
3680 f = XFRAME (frame);
3681 r = XWINDOW (FRAME_ROOT_WINDOW (f));
3682
3683 if (!window_resize_check (r, horflag) 3660 if (!window_resize_check (r, horflag)
3684 || ! EQ (r->new_total, 3661 || ! EQ (r->new_total,
3685 (horflag ? r->total_cols : r->total_lines))) 3662 (horflag ? r->total_cols : r->total_lines)))
@@ -6165,12 +6142,7 @@ saved by this function. */)
6165 register int n_windows; 6142 register int n_windows;
6166 register struct save_window_data *data; 6143 register struct save_window_data *data;
6167 register int i; 6144 register int i;
6168 FRAME_PTR f; 6145 struct frame *f = decode_live_frame (frame);
6169
6170 if (NILP (frame))
6171 frame = selected_frame;
6172 CHECK_LIVE_FRAME (frame);
6173 f = XFRAME (frame);
6174 6146
6175 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); 6147 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
6176 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols, 6148 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
@@ -6323,10 +6295,9 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6323{ 6295{
6324 struct window *w = decode_live_window (window); 6296 struct window *w = decode_live_window (window);
6325 6297
6326 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)), 6298 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6327 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)), 6299 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6328 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 6300 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) ? Qt : Qnil);
6329 ? Qt : Qnil), Qnil)));
6330} 6301}
6331 6302
6332 6303
@@ -6395,12 +6366,12 @@ value. */)
6395 (Lisp_Object window) 6366 (Lisp_Object window)
6396{ 6367{
6397 struct window *w = decode_live_window (window); 6368 struct window *w = decode_live_window (window);
6398 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6369
6370 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6399 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6371 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6400 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))), 6372 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6401 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)), 6373 make_number (WINDOW_SCROLL_BAR_COLS (w)),
6402 Fcons (w->vertical_scroll_bar_type, 6374 w->vertical_scroll_bar_type, Qnil);
6403 Fcons (Qnil, Qnil))));
6404} 6375}
6405 6376
6406 6377
diff --git a/src/window.h b/src/window.h
index 115b361194c..2a12226c0aa 100644
--- a/src/window.h
+++ b/src/window.h
@@ -970,17 +970,26 @@ struct glyph *get_phys_cursor_glyph (struct window *w);
970 || !NILP (XWINDOW (WINDOW)->vchild) \ 970 || !NILP (XWINDOW (WINDOW)->vchild) \
971 || !NILP (XWINDOW (WINDOW)->hchild))) 971 || !NILP (XWINDOW (WINDOW)->hchild)))
972 972
973/* A window of any sort, leaf or interior, is "valid" if one
974 of its buffer, vchild, or hchild members is non-nil. */
975#define CHECK_VALID_WINDOW(WINDOW) \
976 CHECK_TYPE (WINDOW_VALID_P (WINDOW), Qwindow_valid_p, WINDOW)
973 977
974/* Value is non-zero if WINDOW is a live window. */ 978/* Value is non-zero if WINDOW is a live window. */
975#define WINDOW_LIVE_P(WINDOW) \ 979#define WINDOW_LIVE_P(WINDOW) \
976 (WINDOWP (WINDOW) && !NILP (XWINDOW (WINDOW)->buffer)) 980 (WINDOWP (WINDOW) && !NILP (XWINDOW (WINDOW)->buffer))
977 981
982/* A window is "live" if and only if it shows a buffer. */
983#define CHECK_LIVE_WINDOW(WINDOW) \
984 CHECK_TYPE (WINDOW_LIVE_P (WINDOW), Qwindow_live_p, WINDOW)
985
978/* These used to be in lisp.h. */ 986/* These used to be in lisp.h. */
979 987
980extern Lisp_Object Qwindowp, Qwindow_live_p; 988extern Lisp_Object Qwindowp, Qwindow_live_p;
981extern Lisp_Object Vwindow_list; 989extern Lisp_Object Vwindow_list;
982 990
983extern struct window *decode_live_window (Lisp_Object); 991extern struct window *decode_live_window (Lisp_Object);
992extern struct window *decode_any_window (Lisp_Object);
984extern bool compare_window_configurations (Lisp_Object, Lisp_Object, bool); 993extern bool compare_window_configurations (Lisp_Object, Lisp_Object, bool);
985extern void mark_window_cursors_off (struct window *); 994extern void mark_window_cursors_off (struct window *);
986extern int window_internal_height (struct window *); 995extern int window_internal_height (struct window *);
diff --git a/src/xdisp.c b/src/xdisp.c
index 109aca9051c..a98572bde72 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -933,6 +933,7 @@ static enum move_it_result
933 move_it_in_display_line_to (struct it *, ptrdiff_t, int, 933 move_it_in_display_line_to (struct it *, ptrdiff_t, int,
934 enum move_operation_enum); 934 enum move_operation_enum);
935void move_it_vertically_backward (struct it *, int); 935void move_it_vertically_backward (struct it *, int);
936static void get_visually_first_element (struct it *);
936static void init_to_row_start (struct it *, struct window *, 937static void init_to_row_start (struct it *, struct window *,
937 struct glyph_row *); 938 struct glyph_row *);
938static int init_to_row_end (struct it *, struct window *, 939static int init_to_row_end (struct it *, struct window *,
@@ -3118,6 +3119,40 @@ init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
3118 eassert (STRINGP (it->string)); 3119 eassert (STRINGP (it->string));
3119 it->current.string_pos = pos->string_pos; 3120 it->current.string_pos = pos->string_pos;
3120 it->method = GET_FROM_STRING; 3121 it->method = GET_FROM_STRING;
3122 it->end_charpos = SCHARS (it->string);
3123 /* Set up the bidi iterator for this overlay string. */
3124 if (it->bidi_p)
3125 {
3126 it->bidi_it.string.lstring = it->string;
3127 it->bidi_it.string.s = NULL;
3128 it->bidi_it.string.schars = SCHARS (it->string);
3129 it->bidi_it.string.bufpos = it->overlay_strings_charpos;
3130 it->bidi_it.string.from_disp_str = it->string_from_display_prop_p;
3131 it->bidi_it.string.unibyte = !it->multibyte_p;
3132 bidi_init_it (IT_STRING_CHARPOS (*it), IT_STRING_BYTEPOS (*it),
3133 FRAME_WINDOW_P (it->f), &it->bidi_it);
3134
3135 /* Synchronize the state of the bidi iterator with
3136 pos->string_pos. For any string position other than
3137 zero, this will be done automagically when we resume
3138 iteration over the string and get_visually_first_element
3139 is called. But if string_pos is zero, and the string is
3140 to be reordered for display, we need to resync manually,
3141 since it could be that the iteration state recorded in
3142 pos ended at string_pos of 0 moving backwards in string. */
3143 if (CHARPOS (pos->string_pos) == 0)
3144 {
3145 get_visually_first_element (it);
3146 if (IT_STRING_CHARPOS (*it) != 0)
3147 do {
3148 /* Paranoia. */
3149 eassert (it->bidi_it.charpos < it->bidi_it.string.schars);
3150 bidi_move_to_visually_next (&it->bidi_it);
3151 } while (it->bidi_it.charpos != 0);
3152 }
3153 eassert (IT_STRING_CHARPOS (*it) == it->bidi_it.charpos
3154 && IT_STRING_BYTEPOS (*it) == it->bidi_it.bytepos);
3155 }
3121 } 3156 }
3122 3157
3123 if (CHARPOS (pos->string_pos) >= 0) 3158 if (CHARPOS (pos->string_pos) >= 0)
@@ -3127,6 +3162,9 @@ init_from_display_pos (struct it *it, struct window *w, struct display_pos *pos)
3127 IT should already be filled with that string. */ 3162 IT should already be filled with that string. */
3128 it->current.string_pos = pos->string_pos; 3163 it->current.string_pos = pos->string_pos;
3129 eassert (STRINGP (it->string)); 3164 eassert (STRINGP (it->string));
3165 if (it->bidi_p)
3166 bidi_init_it (IT_STRING_CHARPOS (*it), IT_STRING_BYTEPOS (*it),
3167 FRAME_WINDOW_P (it->f), &it->bidi_it);
3130 } 3168 }
3131 3169
3132 /* Restore position in display vector translations, control 3170 /* Restore position in display vector translations, control
@@ -11932,19 +11970,14 @@ tool_bar_lines_needed (struct frame *f, int *n_rows)
11932 11970
11933DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed, Stool_bar_lines_needed, 11971DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed, Stool_bar_lines_needed,
11934 0, 1, 0, 11972 0, 1, 0,
11935 doc: /* Return the number of lines occupied by the tool bar of FRAME. */) 11973 doc: /* Return the number of lines occupied by the tool bar of FRAME.
11974If FRAME is nil or omitted, use the selected frame. */)
11936 (Lisp_Object frame) 11975 (Lisp_Object frame)
11937{ 11976{
11938 struct frame *f; 11977 struct frame *f = decode_any_frame (frame);
11939 struct window *w; 11978 struct window *w;
11940 int nlines = 0; 11979 int nlines = 0;
11941 11980
11942 if (NILP (frame))
11943 frame = selected_frame;
11944 else
11945 CHECK_FRAME (frame);
11946 f = XFRAME (frame);
11947
11948 if (WINDOWP (f->tool_bar_window) 11981 if (WINDOWP (f->tool_bar_window)
11949 && (w = XWINDOW (f->tool_bar_window), 11982 && (w = XWINDOW (f->tool_bar_window),
11950 WINDOW_TOTAL_LINES (w) > 0)) 11983 WINDOW_TOTAL_LINES (w) > 0))
@@ -21123,10 +21156,8 @@ are the selected window and the WINDOW's buffer). */)
21123 Lisp_Object str; 21156 Lisp_Object str;
21124 int string_start = 0; 21157 int string_start = 0;
21125 21158
21126 if (NILP (window)) 21159 w = decode_any_window (window);
21127 window = selected_window; 21160 XSETWINDOW (window, w);
21128 CHECK_WINDOW (window);
21129 w = XWINDOW (window);
21130 21161
21131 if (NILP (buffer)) 21162 if (NILP (buffer))
21132 buffer = w->buffer; 21163 buffer = w->buffer;
@@ -21155,7 +21186,7 @@ are the selected window and the WINDOW's buffer). */)
21155 and set that to nil so that we don't alter the outer value. */ 21186 and set that to nil so that we don't alter the outer value. */
21156 record_unwind_protect (unwind_format_mode_line, 21187 record_unwind_protect (unwind_format_mode_line,
21157 format_mode_line_unwind_data 21188 format_mode_line_unwind_data
21158 (XFRAME (WINDOW_FRAME (XWINDOW (window))), 21189 (XFRAME (WINDOW_FRAME (w)),
21159 old_buffer, selected_window, 1)); 21190 old_buffer, selected_window, 1));
21160 mode_line_proptrans_alist = Qnil; 21191 mode_line_proptrans_alist = Qnil;
21161 21192
diff --git a/src/xfaces.c b/src/xfaces.c
index 221387c4b6d..41c618612ac 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -669,23 +669,6 @@ x_free_gc (struct frame *f, GC gc)
669} 669}
670#endif /* HAVE_NS */ 670#endif /* HAVE_NS */
671 671
672/* If FRAME is nil, return a pointer to the selected frame.
673 Otherwise, check that FRAME is a live frame, and return a pointer
674 to it. NPARAM is the parameter number of FRAME, for
675 CHECK_LIVE_FRAME. This is here because it's a frequent pattern in
676 Lisp function definitions. */
677
678static struct frame *
679frame_or_selected_frame (Lisp_Object frame, int nparam)
680{
681 if (NILP (frame))
682 frame = selected_frame;
683
684 CHECK_LIVE_FRAME (frame);
685 return XFRAME (frame);
686}
687
688
689/*********************************************************************** 672/***********************************************************************
690 Frames and faces 673 Frames and faces
691 ***********************************************************************/ 674 ***********************************************************************/
@@ -1204,15 +1187,9 @@ FRAME specifies the frame and thus the display for interpreting COLOR.
1204If FRAME is nil or omitted, use the selected frame. */) 1187If FRAME is nil or omitted, use the selected frame. */)
1205 (Lisp_Object color, Lisp_Object frame) 1188 (Lisp_Object color, Lisp_Object frame)
1206{ 1189{
1207 struct frame *f;
1208
1209 CHECK_STRING (color); 1190 CHECK_STRING (color);
1210 if (NILP (frame)) 1191 return (face_color_gray_p (decode_any_frame (frame), SSDATA (color))
1211 frame = selected_frame; 1192 ? Qt : Qnil);
1212 else
1213 CHECK_FRAME (frame);
1214 f = XFRAME (frame);
1215 return face_color_gray_p (f, SSDATA (color)) ? Qt : Qnil;
1216} 1193}
1217 1194
1218 1195
@@ -1225,17 +1202,10 @@ If FRAME is nil or omitted, use the selected frame.
1225COLOR must be a valid color name. */) 1202COLOR must be a valid color name. */)
1226 (Lisp_Object color, Lisp_Object frame, Lisp_Object background_p) 1203 (Lisp_Object color, Lisp_Object frame, Lisp_Object background_p)
1227{ 1204{
1228 struct frame *f;
1229
1230 CHECK_STRING (color); 1205 CHECK_STRING (color);
1231 if (NILP (frame)) 1206 return (face_color_supported_p (decode_any_frame (frame),
1232 frame = selected_frame; 1207 SSDATA (color), !NILP (background_p))
1233 else 1208 ? Qt : Qnil);
1234 CHECK_FRAME (frame);
1235 f = XFRAME (frame);
1236 if (face_color_supported_p (f, SSDATA (color), !NILP (background_p)))
1237 return Qt;
1238 return Qnil;
1239} 1209}
1240 1210
1241 1211
@@ -1683,9 +1653,7 @@ the WIDTH times as wide as FACE on FRAME. */)
1683 1653
1684 /* We can't simply call check_x_frame because this function may be 1654 /* We can't simply call check_x_frame because this function may be
1685 called before any frame is created. */ 1655 called before any frame is created. */
1686 if (NILP (frame)) 1656 f = decode_live_frame (frame);
1687 frame = selected_frame;
1688 f = frame_or_selected_frame (frame, 2);
1689 if (! FRAME_WINDOW_P (f)) 1657 if (! FRAME_WINDOW_P (f))
1690 { 1658 {
1691 /* Perhaps we have not yet created any frame. */ 1659 /* Perhaps we have not yet created any frame. */
@@ -1693,6 +1661,8 @@ the WIDTH times as wide as FACE on FRAME. */)
1693 frame = Qnil; 1661 frame = Qnil;
1694 face = Qnil; 1662 face = Qnil;
1695 } 1663 }
1664 else
1665 XSETFRAME (frame, f);
1696 1666
1697 /* Determine the width standard for comparison with the fonts we find. */ 1667 /* Determine the width standard for comparison with the fonts we find. */
1698 1668
@@ -3679,21 +3649,12 @@ frame. If FRAME is t, report on the defaults for face SYMBOL (for new
3679frames). If FRAME is omitted or nil, use the selected frame. */) 3649frames). If FRAME is omitted or nil, use the selected frame. */)
3680 (Lisp_Object symbol, Lisp_Object keyword, Lisp_Object frame) 3650 (Lisp_Object symbol, Lisp_Object keyword, Lisp_Object frame)
3681{ 3651{
3682 Lisp_Object lface, value = Qnil; 3652 struct frame *f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
3653 Lisp_Object lface = lface_from_face_name (f, symbol, 1), value = Qnil;
3683 3654
3684 CHECK_SYMBOL (symbol); 3655 CHECK_SYMBOL (symbol);
3685 CHECK_SYMBOL (keyword); 3656 CHECK_SYMBOL (keyword);
3686 3657
3687 if (EQ (frame, Qt))
3688 lface = lface_from_face_name (NULL, symbol, 1);
3689 else
3690 {
3691 if (NILP (frame))
3692 frame = selected_frame;
3693 CHECK_LIVE_FRAME (frame);
3694 lface = lface_from_face_name (XFRAME (frame), symbol, 1);
3695 }
3696
3697 if (EQ (keyword, QCfamily)) 3658 if (EQ (keyword, QCfamily))
3698 value = LFACE_FAMILY (lface); 3659 value = LFACE_FAMILY (lface);
3699 else if (EQ (keyword, QCfoundry)) 3660 else if (EQ (keyword, QCfoundry))
@@ -3876,7 +3837,7 @@ return the font name used for CHARACTER. */)
3876 } 3837 }
3877 else 3838 else
3878 { 3839 {
3879 struct frame *f = frame_or_selected_frame (frame, 1); 3840 struct frame *f = decode_live_frame (frame);
3880 int face_id = lookup_named_face (f, face, 1); 3841 int face_id = lookup_named_face (f, face, 1);
3881 struct face *fface = FACE_FROM_ID (f, face_id); 3842 struct face *fface = FACE_FROM_ID (f, face_id);
3882 3843
@@ -3963,14 +3924,11 @@ If FRAME is omitted or nil, use the selected frame. */)
3963 struct frame *f; 3924 struct frame *f;
3964 Lisp_Object lface1, lface2; 3925 Lisp_Object lface1, lface2;
3965 3926
3966 if (EQ (frame, Qt)) 3927 /* Don't use check_x_frame here because this function is called
3967 f = NULL; 3928 before X frames exist. At that time, if FRAME is nil,
3968 else 3929 selected_frame will be used which is the frame dumped with
3969 /* Don't use check_x_frame here because this function is called 3930 Emacs. That frame is not an X frame. */
3970 before X frames exist. At that time, if FRAME is nil, 3931 f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
3971 selected_frame will be used which is the frame dumped with
3972 Emacs. That frame is not an X frame. */
3973 f = frame_or_selected_frame (frame, 2);
3974 3932
3975 lface1 = lface_from_face_name (f, face1, 1); 3933 lface1 = lface_from_face_name (f, face1, 1);
3976 lface2 = lface_from_face_name (f, face2, 1); 3934 lface2 = lface_from_face_name (f, face2, 1);
@@ -3988,20 +3946,10 @@ If FRAME is t, report on the defaults for face FACE (for new frames).
3988If FRAME is omitted or nil, use the selected frame. */) 3946If FRAME is omitted or nil, use the selected frame. */)
3989 (Lisp_Object face, Lisp_Object frame) 3947 (Lisp_Object face, Lisp_Object frame)
3990{ 3948{
3991 struct frame *f; 3949 struct frame *f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
3992 Lisp_Object lface; 3950 Lisp_Object lface = lface_from_face_name (f, face, 1);
3993 int i; 3951 int i;
3994 3952
3995 if (NILP (frame))
3996 frame = selected_frame;
3997 CHECK_LIVE_FRAME (frame);
3998 f = XFRAME (frame);
3999
4000 if (EQ (frame, Qt))
4001 lface = lface_from_face_name (NULL, face, 1);
4002 else
4003 lface = lface_from_face_name (f, face, 1);
4004
4005 for (i = 1; i < LFACE_VECTOR_SIZE; ++i) 3953 for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
4006 if (!UNSPECIFIEDP (AREF (lface, i))) 3954 if (!UNSPECIFIEDP (AREF (lface, i)))
4007 break; 3955 break;
@@ -4016,8 +3964,7 @@ DEFUN ("frame-face-alist", Fframe_face_alist, Sframe_face_alist,
4016For internal use only. */) 3964For internal use only. */)
4017 (Lisp_Object frame) 3965 (Lisp_Object frame)
4018{ 3966{
4019 struct frame *f = frame_or_selected_frame (frame, 0); 3967 return decode_live_frame (frame)->face_alist;
4020 return f->face_alist;
4021} 3968}
4022 3969
4023 3970
@@ -4205,14 +4152,9 @@ or lists of the form (RED GREEN BLUE).
4205If FRAME is unspecified or nil, the current frame is used. */) 4152If FRAME is unspecified or nil, the current frame is used. */)
4206 (Lisp_Object color1, Lisp_Object color2, Lisp_Object frame) 4153 (Lisp_Object color1, Lisp_Object color2, Lisp_Object frame)
4207{ 4154{
4208 struct frame *f; 4155 struct frame *f = decode_live_frame (frame);
4209 XColor cdef1, cdef2; 4156 XColor cdef1, cdef2;
4210 4157
4211 if (NILP (frame))
4212 frame = selected_frame;
4213 CHECK_LIVE_FRAME (frame);
4214 f = XFRAME (frame);
4215
4216 if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1)) 4158 if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
4217 && !(STRINGP (color1) && defined_color (f, SSDATA (color1), &cdef1, 0))) 4159 && !(STRINGP (color1) && defined_color (f, SSDATA (color1), &cdef1, 0)))
4218 signal_error ("Invalid color", color1); 4160 signal_error ("Invalid color", color1);
diff --git a/src/xfns.c b/src/xfns.c
index d497cffe3df..9c99902b93d 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -164,12 +164,8 @@ have_menus_p (void)
164FRAME_PTR 164FRAME_PTR
165check_x_frame (Lisp_Object frame) 165check_x_frame (Lisp_Object frame)
166{ 166{
167 FRAME_PTR f; 167 struct frame *f = decode_live_frame (frame);
168 168
169 if (NILP (frame))
170 frame = selected_frame;
171 CHECK_LIVE_FRAME (frame);
172 f = XFRAME (frame);
173 if (! FRAME_X_P (f)) 169 if (! FRAME_X_P (f))
174 error ("Non-X frame used"); 170 error ("Non-X frame used");
175 return f; 171 return f;
@@ -3111,9 +3107,6 @@ This function is an internal primitive--use `make-frame' instead. */)
3111 3107
3112 XSETFRAME (frame, f); 3108 XSETFRAME (frame, f);
3113 3109
3114 /* Note that X Windows does support scroll bars. */
3115 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
3116
3117 f->terminal = dpyinfo->terminal; 3110 f->terminal = dpyinfo->terminal;
3118 3111
3119 f->output_method = output_x_window; 3112 f->output_method = output_x_window;
@@ -4596,7 +4589,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4596 Finsert (1, &text); 4589 Finsert (1, &text);
4597 set_buffer_internal_1 (old_buffer); 4590 set_buffer_internal_1 (old_buffer);
4598 4591
4599 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
4600 record_unwind_protect (unwind_create_tip_frame, frame); 4592 record_unwind_protect (unwind_create_tip_frame, frame);
4601 4593
4602 f->terminal = dpyinfo->terminal; 4594 f->terminal = dpyinfo->terminal;
diff --git a/src/xterm.c b/src/xterm.c
index a52a113ccda..a36b008c105 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3457,7 +3457,7 @@ x_focus_changed (int type, int state, struct x_display_info *dpyinfo, struct fra
3457 3457
3458 /* Don't stop displaying the initial startup message 3458 /* Don't stop displaying the initial startup message
3459 for a switch-frame event we don't need. */ 3459 for a switch-frame event we don't need. */
3460 /* When run as a deamon, Vterminal_frame is always NIL. */ 3460 /* When run as a daemon, Vterminal_frame is always NIL. */
3461 if ((NILP (Vterminal_frame) || EQ (Fdaemonp(), Qt)) 3461 if ((NILP (Vterminal_frame) || EQ (Fdaemonp(), Qt))
3462 && CONSP (Vframe_list) 3462 && CONSP (Vframe_list)
3463 && !NILP (XCDR (Vframe_list))) 3463 && !NILP (XCDR (Vframe_list)))
@@ -6117,7 +6117,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6117 SELECTION_EVENT_DISPLAY (&inev.sie) = eventp->display; 6117 SELECTION_EVENT_DISPLAY (&inev.sie) = eventp->display;
6118 SELECTION_EVENT_SELECTION (&inev.sie) = eventp->selection; 6118 SELECTION_EVENT_SELECTION (&inev.sie) = eventp->selection;
6119 SELECTION_EVENT_TIME (&inev.sie) = eventp->time; 6119 SELECTION_EVENT_TIME (&inev.sie) = eventp->time;
6120 inev.ie.frame_or_window = Qnil;
6121 } 6120 }
6122 break; 6121 break;
6123 6122
@@ -6137,7 +6136,6 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6137 SELECTION_EVENT_TARGET (&inev.sie) = eventp->target; 6136 SELECTION_EVENT_TARGET (&inev.sie) = eventp->target;
6138 SELECTION_EVENT_PROPERTY (&inev.sie) = eventp->property; 6137 SELECTION_EVENT_PROPERTY (&inev.sie) = eventp->property;
6139 SELECTION_EVENT_TIME (&inev.sie) = eventp->time; 6138 SELECTION_EVENT_TIME (&inev.sie) = eventp->time;
6140 inev.ie.frame_or_window = Qnil;
6141 } 6139 }
6142 break; 6140 break;
6143 6141