aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Tromey2013-08-19 21:53:07 -0600
committerTom Tromey2013-08-19 21:53:07 -0600
commit6d75555c5cc3d2a629646cee7629e67530fa7a36 (patch)
tree3852804dd234ad613ea8691332e10b92c027e87d /src
parentcc231cbe45d27a1906d268fb72d3b4105a2e9c65 (diff)
parent8c2f38aaab7a7a2f0605416fc2ee38701e41ab61 (diff)
downloademacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.tar.gz
emacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.zip
merge from trunk
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog1104
-rw-r--r--src/ChangeLog.92
-rw-r--r--src/Makefile.in6
-rw-r--r--src/alloc.c29
-rw-r--r--src/bidi.c39
-rw-r--r--src/buffer.c94
-rw-r--r--src/buffer.h19
-rw-r--r--src/callint.c11
-rw-r--r--src/callproc.c773
-rw-r--r--src/casefiddle.c2
-rw-r--r--src/cmds.c2
-rw-r--r--src/coding.c2
-rw-r--r--src/composite.c30
-rw-r--r--src/composite.h88
-rw-r--r--src/data.c17
-rw-r--r--src/decompress.c231
-rw-r--r--src/dispextern.h30
-rw-r--r--src/dispnew.c135
-rw-r--r--src/doc.c2
-rw-r--r--src/editfns.c18
-rw-r--r--src/emacs.c10
-rw-r--r--src/eval.c163
-rw-r--r--src/fileio.c88
-rw-r--r--src/filelock.c33
-rw-r--r--src/fns.c4
-rw-r--r--src/font.c155
-rw-r--r--src/font.h60
-rw-r--r--src/fontset.c21
-rw-r--r--src/fontset.h6
-rw-r--r--src/frame.c131
-rw-r--r--src/frame.h33
-rw-r--r--src/fringe.c43
-rw-r--r--src/ftfont.c24
-rw-r--r--src/ftxfont.c22
-rw-r--r--src/gtkutil.c149
-rw-r--r--src/gtkutil.h46
-rw-r--r--src/image.c362
-rw-r--r--src/indent.c6
-rw-r--r--src/insdel.c58
-rw-r--r--src/keyboard.c16
-rw-r--r--src/keymap.c3
-rw-r--r--src/lisp.h31
-rw-r--r--src/lisp.mk1
-rw-r--r--src/marker.c6
-rw-r--r--src/menu.c9
-rw-r--r--src/menu.h10
-rw-r--r--src/minibuf.c27
-rw-r--r--src/msdos.c18
-rw-r--r--src/msdos.h2
-rw-r--r--src/nsfns.m43
-rw-r--r--src/nsfont.m31
-rw-r--r--src/nsmenu.m66
-rw-r--r--src/nsterm.h47
-rw-r--r--src/nsterm.m124
-rw-r--r--src/process.c289
-rw-r--r--src/process.h15
-rw-r--r--src/regex.c9
-rw-r--r--src/scroll.c20
-rw-r--r--src/search.c4
-rw-r--r--src/sheap.c17
-rw-r--r--src/syntax.c1
-rw-r--r--src/sysdep.c12
-rw-r--r--src/syswait.h3
-rw-r--r--src/term.c43
-rw-r--r--src/termcap.c4
-rw-r--r--src/terminal.c4
-rw-r--r--src/textprop.c41
-rw-r--r--src/w16select.c12
-rw-r--r--src/w32.c99
-rw-r--r--src/w32fns.c60
-rw-r--r--src/w32font.c41
-rw-r--r--src/w32font.h10
-rw-r--r--src/w32inevt.c12
-rw-r--r--src/w32inevt.h2
-rw-r--r--src/w32menu.c32
-rw-r--r--src/w32notify.c2
-rw-r--r--src/w32term.c129
-rw-r--r--src/w32term.h10
-rw-r--r--src/w32uniscribe.c23
-rw-r--r--src/w32xfns.c8
-rw-r--r--src/widget.c36
-rw-r--r--src/window.c437
-rw-r--r--src/window.h134
-rw-r--r--src/xdisp.c509
-rw-r--r--src/xfaces.c63
-rw-r--r--src/xfns.c102
-rw-r--r--src/xfont.c41
-rw-r--r--src/xftfont.c28
-rw-r--r--src/xmenu.c125
-rw-r--r--src/xrdb.c18
-rw-r--r--src/xselect.c28
-rw-r--r--src/xsettings.c9
-rw-r--r--src/xsmfns.c3
-rw-r--r--src/xterm.c200
-rw-r--r--src/xterm.h10
95 files changed, 4242 insertions, 2885 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 38fa72b0506..e21d82bdc09 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,1099 @@
12013-08-20 Paul Eggert <eggert@cs.ucla.edu>
2
3 * image.c (SIGNATURE_DIGESTSIZE): Remove.
4 (struct animation_cache): Make signature a flexible array member.
5 All uses changed. This is a tad slower but may insulate us better
6 from future changes to ImageMagick.
7
82013-08-19 Paul Eggert <eggert@cs.ucla.edu>
9
10 * image.c: Shrink memory needed for animation cache.
11 (SIGNATURE_DIGESTSIZE): New constant.
12 (struct animation_cache): Make 'signature' a fixed size array of bytes.
13 (imagemagick_create_cache): Copy the signature. This saves
14 several KB of memory that ImageMagick wastes per signature.
15 Don't bother updating the update_time, as the caller does that now.
16 (imagemagick_prune_animation_cache): Don't destroy the signature, as
17 it's a fixed size struct member now.
18 (imagemagick_get_animation_cache): Always destroy the signature,
19 as it's now imagemagick_create_cache's responsibility to copy it.
20 Avoid duplicate calls to strcmp and to imagemagick_create_cache,
21 and use memcmp rather than strcmp.
22 eassert that ImageMagick returns a signature of the specified length.
23
242013-08-19 Lars Magne Ingebrigtsen <larsi@gnus.org>
25
26 * image.c (imagemagick_get_animation_cache): Don't segfault on
27 each invocation.
28 (imagemagick_get_animation_cache): Revert to previous definition
29 so that it actually works. But keep the memory leak fix.
30 (imagemagick_get_animation_cache): Fix memory leak.
31
322013-08-19 Paul Eggert <eggert@cs.ucla.edu>
33
34 * image.c: Fix animation cache signature memory leak.
35 Fix some other minor performance problems while we're at it.
36 (imagemagick_create_cache): Clear just the members that
37 need clearing. Don't set update_time, as caller does that now.
38 (imagemagick_prune_animation_cache, imagemagick_get_animation_cache):
39 Simplify by using pointer-to-pointer instead of a prev pointer.
40 (imagemagick_prune_animation_cache): Use make_emacs_time rather
41 than EMACS_TIME_FROM_DOUBLE, and DestroyString rather than free.
42 (imagemagick_get_animation_cache): Don't xstrdup the image signature;
43 it's already a copy. Free the signature probe unless it's cached.
44
45 * process.c (handle_child_signal): Fix crash; deleted pid (Bug#15106).
46 This was introduced by my 2013-08-12 fix for Bug#15035.
47
482013-08-19 Dmitry Antipov <dmantipov@yandex.ru>
49
50 * image.c (imagemagick_create_cache, imagemagick_get_animation_cache)
51 (imagemagick_prune_animation_cache): Now static.
52
532013-08-18 Lars Magne Ingebrigtsen <larsi@gnus.org>
54
55 * image.c (imagemagick_get_animation_cache): Don't segfault when
56 pruning all entries.
57
582013-08-18 Ken Brown <kbrown@cornell.edu>
59
60 * sheap.c (STATIC_HEAP_SIZE): Adjust to current needs; use bigger
61 static heap if ENABLE_CHECKING is defined.
62 (max_bss_sbrk_ptr): New variable.
63 (bss_sbrk): Use it.
64 (report_sheap_usage): Report maximum static heap usage instead of
65 ending static heap usage.
66
672013-08-17 Eli Zaretskii <eliz@gnu.org>
68
69 * decompress.c (Fzlib_available_p) [WINDOWSNT]: Update the value
70 of zlib_initialized according to the results of calling
71 init_zlib_functions.
72
732013-08-16 Lars Magne Ingebrigtsen <larsi@gnus.org>
74
75 * image.c: Implement an ImageMagick per-image cache.
76 (imagemagick_get_animation_cache): Fix a double-free error.
77 (imagemagick_load_image): Remove the ping_wand code, which only
78 apparently saved time on invalid animated images, and slowed down
79 everything else. Optimise for the common case.
80
812013-08-16 Xue Fuqiao <xfq.free@gmail.com>
82
83 * buffer.c (syms_of_buffer) <buffer-undo-list>: Doc fix.
84
85 * editfns.c (insert_before_markers): Mention overlay in the doc string.
86
87 * marker.c (set_marker): Remove documentation of undefined behavior.
88
892013-08-15 Lars Magne Ingebrigtsen <larsi@gnus.org>
90
91 * image.c (imagemagick_compute_animated_image): Animate correctly
92 when sub-images are smaller than the main image.
93 (imagemagick_compute_animated_image): Setting the iterator row to
94 zero is apparently not allowed.
95 (imagemagick_compute_animated_image): Allow images that say they
96 have sub-images that are bigger than the main image, but just crop
97 them.
98
992013-08-15 Jan Djärv <jan.h.d@swipnet.se>
100
101 * nsmenu.m (menuWillOpen:): Fix preprocessor test (Bug#15001).
102
1032013-08-15 Lars Magne Ingebrigtsen <larsi@gnus.org>
104
105 * image.c (imagemagick_compute_animated_image): Respect the GIF
106 disposal methods.
107
1082013-08-15 Ken Brown <kbrown@cornell.edu>
109
110 * emacs.c (main): Update comment about G_SLICE_ALWAYS_MALLOC.
111 * gmalloc.c (memalign) [CYGWIN]: Revert last change; it's not
112 needed.
113
1142013-08-15 Paul Eggert <eggert@cs.ucla.edu>
115
116 Fix minor problems found by static checking.
117 * frame.c (delete_frame):
118 * xdisp.c (next_element_from_display_vector):
119 Avoid uninitialized local.
120 * image.c (imagemagick_compute_animated_image): Port to C89.
121 Prefer usual GNU indentation style for loops.
122 Be more careful about bizarrely large sizes, by using ptrdiff_t
123 instead of int.
124
1252013-08-15 Dmitry Antipov <dmantipov@yandex.ru>
126
127 Fix infinite frame selection loop (Bug#15025).
128 * frame.c (delete_frame): Prefer fast ad-hoc loop to next_frame.
129
1302013-08-15 Eli Zaretskii <eliz@gnu.org>
131
132 * xdisp.c (compute_window_start_on_continuation_line): When
133 WORD_WRAP is in effect, use move_it_to instead of move_it_by_lines
134 to make sure we end up setting the window start at the leftmost
135 visible character of the display line. This avoids funky
136 horizontal shifting because the window start is not kept on the
137 same position. (Bug#15090)
138 (next_element_from_display_vector): Support 'box' face attribute
139 in the face definitions of a display vector. (Bug#15099)
140
1412013-08-15 Lars Magne Ingebrigtsen <larsi@gnus.org>
142
143 * image.c (imagemagick_compute_animated_image): Implement animated
144 images (bug#14700).
145 (imagemagick_compute_animated_image): Fix some compilation
146 warnings. Implement a very simple cache to make the animation
147 usable at all, but it should be replaced with a per-image cache.
148
1492013-08-15 Dmitry Antipov <dmantipov@yandex.ru>
150
151 * lisp.h (FOR_EACH_ALIST_VALUE): New macro
152 to do `for' loops over alist values.
153 * buffer.h (FOR_EACH_BUFFER):
154 * process.c (FOR_EACH_PROCESS): Use it.
155 (handle_child_signal, status_notify, Fget_buffer_process)
156 (kill_buffer_processes): Use FOR_EACH_PROCESS.
157
1582013-08-15 Dmitry Antipov <dmantipov@yandex.ru>
159
160 * term.c (get_named_tty, create_tty_output, tty_free_frame_resources)
161 (tty_free_frame_resources, delete_tty): Prefer eassert to emacs_abort.
162 * image.c (make_image_cache): For struct image_cache, prefer xmalloc
163 to xzalloc and so avoid redundant call to memset.
164 * xterm.c (x_term_init): Avoid unnecessary initializations of dpyinfo
165 members because it is allocated with xzalloc and so already zeroed.
166
1672013-08-14 Ken Brown <kbrown@cornell.edu>
168
169 * gmalloc.c (memalign) [CYGWIN]: Rename to emacs_memalign
170 (Bug#15094).
171
1722013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
173
174 Utility function and macro to copy Lisp string to C string.
175 * lisp.h (xlispstrdupa): New macro.
176 (xlispstrdup): New prototype.
177 * alloc.c (xlispstrdup): New function.
178 * callint.c (Fcall_interactively):
179 * fileio.c (Ffile_name_directory, Fexpand_file_name)
180 (Fsubstitute_in_file_name):
181 * frame.c (Fmake_terminal_frame): Use xlispstrdupa.
182 * image.c (x_create_bitmap_from_file):
183 * w32term.c (w32_term_init):
184 * xterm.c (x_term_init): Use xlispstrdup.
185
1862013-08-14 Lars Magne Ingebrigtsen <larsi@gnus.org>
187
188 * image.c (imagemagick_load_image): Make animated pictures work.
189 There's still some problems with background color settings, though
190 (bug#14700).
191
192 * decompress.c (unwind_decompress): Always restore point.
193
1942013-08-14 Xue Fuqiao <xfq.free@gmail.com>
195
196 * marker.c (set_marker): Reformat documentation.
197
1982013-08-14 Paul Eggert <eggert@cs.ucla.edu>
199
200 * xdisp.c (cursor_type_changed): Now static.
201
202 * image.c (imagemagick_filename_hint): New arg HINT_BUFFER.
203 Use changed. This avoids the need to call xmalloc and for the
204 caller to call xfree, and avoids memory leaks in some situations.
205
2062013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
207
208 * xdisp.c (adjust_window_ends): Move duplicated code to new function.
209 (try_window, try_window_reusing_current_matrix, try_window_id): Use it.
210 (redisplay_window): If window_end_valid is cleared due to non-zero
211 windows_or_buffers_changed, clear current_matrix_up_to_date_p and
212 so do not call to try_cursor_movement for that window.
213
2142013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
215
216 * window.h (struct window): Convert window_end_pos and
217 window_end_vpos from Lisp_Object to ptrdiff_t and int, respectively.
218 (wset_window_end_pos, wset_window_end_vpos): Remove.
219 * dispnew.c (adjust_glyph_matrix):
220 * window.c (Fwindow_end, replace_window, set_window_buffer)
221 (make_window):
222 * xdisp.c (check_window_end, move_it_to, redisplay_internal)
223 (set_vertical_scroll_bar, redisplay_window, try_window)
224 (try_window_reusing_current_matrix, find_first_unchanged_at_end_row)
225 (try_window_id, decode_mode_spec, mouse_face_from_buffer_pos)
226 (note_mouse_highlight): Adjust users.
227 (try_cursor_movement): Likewise. Convert old precondition to eassert.
228 Add comment.
229
2302013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
231
232 Fix --enable-gcc-warnings errors introduced in 2013-08-13 commit.
233 * image.c (imagemagick_filename_hint): Use `const char *' and
234 prefer SSDATA to SDATA to avoid warnings.
235
2362013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
237
238 Cleanup window fringes, margins and scroll bars adjustments.
239 * window.c (set_window_fringes, set_window_margins)
240 (set_window_scroll_bars, apply_window_adjustment): New functions.
241 (set_window_buffer, Fset_window_margins, Fset_window_fringes)
242 (Fset_window_scroll_bars): Use them.
243
2442013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
245
246 * window.h (struct window): Convert scroll_bar_width
247 from Lisp_Object to integer. Adjust comment.
248 (WINDOW_CONFIG_SCROLL_BAR_WIDTH, WINDOW_CONFIG_SCROLL_BAR_COLS):
249 Adjust users.
250 * window.c (wset_scroll_bar_width): Remove.
251 (make_window): Initialize scroll_bar_width.
252 (Fsplit_window_internal): Use direct assignment.
253 (Fset_window_configuration, save_window_save):
254 Convert Lisp_Object to integer and back where appropriate.
255 (Fset_window_scroll_bars): Adjust user. Return t if any scroll
256 bar was actually changed, and mention this in docstring.
257
2582013-08-13 Paul Eggert <eggert@cs.ucla.edu>
259
260 * decompress.c: Minor simplifications.
261 (Fzlib_decompress_region): Don't bother verifying
262 that avail_out <= UINT_MAX, as that was confusing.
263 Mention the restriction in a comment instead.
264 Prefer 'int' to 'ptrdiff_t' when 'int' is wide enough.
265
2662013-08-13 Jan Djärv <jan.h.d@swipnet.se>
267
268 * nsmenu.m (x_activate_menubar): Check for OSX >= 10.5
269 (trackingNotification:): Call ns_check_menu_open only for OSX >= 10.5.
270
2712013-08-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
272
273 * image.c (imagemagick_filename_hint): Check for errors in the
274 alist structure.
275
2762013-08-13 Eli Zaretskii <eliz@gnu.org>
277
278 * window.c (Fwindow_margins): Return nil when there's no marginal
279 area, as per the documented API.
280
281 * w32term.c (x_scroll_bar_create): Use ALLOCATE_PSEUDOVECTOR, not
282 Fmake_vector, as scroll bar's struct members are not all Lisp
283 objects now. This avoids crashes in GC.
284
285 * w32term.h (struct scroll_bar): Convert fringe_extended_p to a
286 bool, so its address could be taken.
287
2882013-08-13 Lars Magne Ingebrigtsen <larsi@gnus.org>
289
290 * image.c (imagemagick_filename_hint): New function to possibly
291 apply `image-content-type-suffixes'.
292 (imagemagick_load_image): Use it.
293
2942013-08-13 Eli Zaretskii <eliz@gnu.org>
295
296 * decompress.c (Fzlib_decompress_region) [WINDOWSNT]: Return Qnil
297 if loading zlib failed.
298
2992013-08-13 Jan Djärv <jan.h.d@swipnet.se>
300
301 * nsterm.m (ns_set_vertical_scroll_bar): Fix breakage intruduced by
302 2013-08-13 checkin below. Change bool to BOOL, rule is:
303 All Obj-C code uses BOOL, except for interfaces callable from C.
304
305 * nsterm.h: Fix CGFloat for OSX 10.4 (Bug#15086).
306
3072013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
308
309 * window.h (WINDOW_FRINGE_EXTENDED_P): New macro.
310 * nsterm.m (ns_set_vertical_scroll_bar): Use it. Use convenient
311 bool instead of BOOL.
312 * w32term.h (struct scroll_bar): Convert fringe_extended_p
313 from Lisp_Object to bitfield. Adjust comment.
314 * w32term.c (x_scroll_bar_create): Adjust user.
315 Use WINDOW_FRINGE_EXTENDED_P and bool for boolean.
316 * xterm.c (XTset_vertical_scroll_bar): Likewise.
317 Use bool for boolean.
318 * xterm.h (struct scroll_bar): Prefer commonly used `unsigned'
319 to `unsigned int' when defining a bitfield.
320
3212013-08-13 Paul Eggert <eggert@cs.ucla.edu>
322
323 * decompress.c (Fzlib_decompress_region): Try to clarify 'avail_out'.
324
3252013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
326
327 * window.h (struct window): Convert left_margin_cols and
328 right_margin_cols from Lisp_Objects to integers. Adjust comment.
329 (WINDOW_LEFT_MARGIN_COLS, WINDOW_RIGHT_MARGIN_COLS)
330 (WINDOW_LEFT_MARGIN_WIDTH, WINDOW_RIGHT_MARGIN_WIDTH):
331 Adjust users.
332 * dispnew.c (margin_glyphs_to_reserve): Convert 3rd arg to int.
333 Adjust comment.
334 (showing_window_margins_p, update_window_line, update_frame_1):
335 * fringe.c (draw_fringe_bitmap_1):
336 * xdisp.c (window_box_width): Adjust users.
337 * window.c (wset_left_margin_cols, wset_right_margin_cols): Remove.
338 (adjust_window_margins, set_window_buffer, Fsplit_window_internal):
339 Use direct assignment.
340 (Fset_window_configuration, save_window_save, Fwindow_margins):
341 Convert Lisp_Object to integer and back where appropriate.
342 (Fset_window_margins): Adjust user. Return t if any margin
343 was actually changed, and mention this in docstring.
344
3452013-08-13 Xue Fuqiao <xfq.free@gmail.com>
346
347 * syntax.c (forward_word):
348 * cmds.c (forward_char, backward_char): Mention the optional argument.
349
3502013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
351
352 * window.h (struct window): Convert left_fringe_width
353 and right_fringe_width from Lisp_Objects to integers.
354 Adjust comment.
355 (WINDOW_FRINGE_COLS, WINDOW_LEFT_FRINGE_WIDTH)
356 (WINDOW_RIGHT_FRINGE_WIDTH): Adjust users.
357 * window.c (wset_left_fringe_width, wset_right_fringe_width):
358 Remove.
359 (make_window): Initialize new integer fields to -1.
360 (Fsplit_window_internal): Use direct assignment.
361 (Fset_window_configuration, save_window_save): Convert
362 Lisp_Object to integer and back where appropriate.
363 (Fset_window_fringes): Adjust user. Return t if any fringe
364 was actually changed, and mention this in docstring.
365
3662013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
367
368 * keyboard.c (Fdiscard_input): Do not increment update_mode_lines.
369 * nsfns.m (x_set_cursor_type):
370 * w32fns.c (x_set_cursor_type):
371 * xfns.m (x_set_cursor_type): Do not set cursor_type_changed here...
372 * xdisp.c (set_frame_cursor_types): ...but in common code.
373
3742013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
375
376 * font.c (clear_font_cache): New function, stripped from...
377 (Fclear_font_cache): ...here, which now uses the function
378 above. Adjust comment.
379 * font.h (clear_font_cache): Add prototype.
380 * xfaces.c (clear_face_cache): Use clear_font_cache.
381
3822013-08-13 Dmitry Antipov <dmantipov@yandex.ru>
383
384 * window.c (Fset_window_start): Compare `w', not `window' because
385 `w' might not be equal to `window' after call to decode_live_window.
386
3872013-08-12 Paul Eggert <eggert@cs.ucla.edu>
388
389 * process.c (deactivate_process): Reset fds to -1 (Bug#15035).
390 This fixes a problem introduced by the Bug#15035 patch
391 when using GPG. Reported by Herbert J. Skuhra.
392
3932013-08-12 Eli Zaretskii <eliz@gnu.org>
394
395 * decompress.c <zlib_initialized> [WINDOWSNT]: New static variable.
396 (Fzlib_decompress_region) [WINDOWSNT]: Call init_zlib_functions if
397 not yet initialized.
398
3992013-08-12 Lars Magne Ingebrigtsen <larsi@gnus.org>
400
401 * decompress.c (Fzlib_decompress_region): Support zlib
402 decompression, too, and rename.
403
4042013-08-12 Paul Eggert <eggert@cs.ucla.edu>
405
406 Minor zlib configuration tweaks.
407 * decompress.c (fn_inflateInit2) [!WINDOWSNT]:
408 Don't assume presence of fn_inflateInit2_ zlib internal function.
409
4102013-08-12 Lars Magne Ingebrigtsen <larsi@gnus.org>
411
412 * decompress.c (Fzlib_decompress_gzipped_region): Rename to
413 include the zlib prefix.
414
4152013-08-12 Eli Zaretskii <eliz@gnu.org>
416
417 * decompress.c [WINDOWSNT]: Include windows.h and w32.h.
418 (DEF_ZLIB_FN, LOAD_ZLIB_FN) [WINDOWSNT]: New macros. Use them to
419 define static variables that are pointers to zlib functions to be
420 dynamically loaded.
421 (init_zlib_functions) [WINDOWSNT]: New function.
422 (fn_inflateInit2_, fn_inflate, fn_inflateEnd, fn_inflateInit2):
423 New macros.
424 (Fdecompress_gzipped_region, unwind_decompress): Use the fn_*
425 macros instead of invoking the zlib functions directly.
426 (syms_of_decompress): DEFSYM Qzlib_dll. Staticpro
427 Szlib_available_p.
428
4292013-08-12 Dmitry Antipov <dmantipov@yandex.ru>
430
431 Avoid looping over all frame windows to freeze and unfreeze.
432 * window.h (struct window): Drop frozen_window_start_p.
433 (freeze_window_starts): Drop prototype.
434 * frame.h (struct frame): New frozen_window_starts flag.
435 (FRAME_WINDOWS_FROZEN): New macro.
436 * window.c (freeze_window_start, freeze_window_starts):
437 Remove.
438 (select_window, replace_window): Adjust users.
439 * xdisp.c (resize_mini_window): Use FRAME_WINDOWS_FROZEN.
440 (window_frozen_p): New function.
441 (redisplay_window): Use it.
442
4432013-08-12 Paul Eggert <eggert@cs.ucla.edu>
444
445 Fix some fd issues when running subprocesses (Bug#15035).
446 Fix bugs that can leak files or file descriptors on errors.
447 Don't unlink open temp files, as that's hard for users to diagnose
448 when things go awry (e.g., temp disk exhausted).
449 Don't bother to lock temp files. Check for invalid recursion.
450 * callproc.c (synch_process_fd): Remove. All uses removed.
451 (synch_process_tempfile): New var or macro.
452 (CALLPROC_STDOUT, CALLPROC_STDERR, CALLPROC_PIPEREAD, CALLPROC_FDS):
453 New constants.
454 (record_kill_process): New arg, the temp name. All callers changed.
455 (delete_temp_file): Now just a simple wrapper around unlink.
456 (call_process_kill): New arg, the call_process_fd array.
457 Close them all. Clear synch_process_pid. Remove the temp file,
458 or arrange for it to be removed.
459 (call_process_cleanup) [MSDOS]: Arg no longer contains file name;
460 that's been moved to synch_process_tempfile. Caller changed.
461 Do not remove the tempfile; that's now call_process_kill's
462 responsibility.
463 (call_process_cleanup) [!MSDOS]: Do not record unwind-protect for
464 call_process_kill; the caller now does that.
465 (call_process_cleanup): Do not close the process fd; that's now
466 call_process_kill's responsibility.
467 (Fcall_process): Implement via new function call_process, which
468 has most of the old body of Fcall_process, but with a different API.
469 (call_process): New function that does not open or close filefd if
470 it is nonnegative. Record which fds need to be closed, and let
471 call_process_kill close (and remove the tempfile, on MSDOS) on error.
472 Signal an error if invoked recursively (could be done via a hook).
473 Simplify creation of the tempfile in the MSDOS case.
474 Don't create the output file until after checking for the executable.
475 Report any failure to open /dev/null.
476 Don't open /dev/null for writing twice; once is enough.
477 Don't create pipe if all output is being discarded or sent to file.
478 Don't worry about setting up the coding system or reading from the
479 pipe if all output is being discarded.
480 Hoist fd_error local into top level, to lessen block nesting.
481 Don't record deleted pid here; now done by Fcall_process_region.
482 (Fcall_process) [MSDOS]: Report mktemp failure immediately,
483 and note its success in synch_process_tempfile.
484 Do not leak resources when child_setup fails.
485 (Fcall_process) [!MSDOS && !WINDOWSNT]: Remove duplicate assignment
486 to child_errno. Remove unnecessary close of fd0; it's close-on-exec.
487 (create_temp_file): Now returns open fd, with an additional
488 Lisp_Object * argument to return the name. All callers changed.
489 Do not close the file; rewind it instead, and leave it open for
490 the caller. Do not lock the temp file. Unwind-protect the file
491 and the file-descriptor.
492 (Fcall_process_region): If the input is /dev/null, unwind-protect it.
493 If an asynchrounous process, record it here, not in call_process.
494 (syms_of_callproc) [MSDOS]: Initialize synch_process_tempfile.
495 * eval.c (set_unwind_protect): New function.
496 * fileio.c (write_region): New function, generalized from the
497 old Fwrite_region. Do not lock temp files.
498 (Fwrite_region): Use it.
499 * lisp.h (set_unwind_protect, write_region): New decls.
500 * process.c: Include <verify.h>.
501 (make_process): Mark fds as initially closed.
502 (deleted_pid_list): Now a list of pid-filename pairs.
503 All uses changed.
504 (close_process_fd): New function.
505 (SUBPROCESS_STDIN, WRITE_TO_SUBPROCESS, READ_FROM_SUBPROCESS)
506 (SUBPROCESS_STDOUT, READ_FROM_EXEC_MONITOR, EXEC_MONITOR_OUTPUT):
507 New constants. Verify that their number matches PROCESS_OPEN_FDS.
508 (create_process, create_pty, Fmake_serial_process)
509 (server_accept_connection): Record which fds need to be closed,
510 and let deactivate_process close them.
511 (Fmake_network_process): Do not discard the unwind-protect
512 until it's safe to do so.
513 (deactivate_process): Close the fds opened by create_process etc.
514 (Fprocess_send_eof): Adjust to new way of recording open fds.
515 Report an error if /dev/null can't be opened, instead of aborting.
516 * process.h (PROCESS_OPEN_FDS): New constant.
517 (struct Lisp_Process): New member open_fds.
518 (record_kill_process, record_deleted_pid): Adjust signatures.
519 (record_deleted_pid): Move decl here ...
520 * syswait.h (record_deleted_pid): ... from here.
521
5222013-08-11 Paul Eggert <eggert@cs.ucla.edu>
523
524 * decompress.c: Fix bugs with large buffers and weird inputs.
525 Tune a bit. Reindent as per usual Emacs style.
526 (BUFFER_SIZE): Remove.
527 (Fdecompress_gzipped_region): Do not mishandle input buffers with
528 more than UINT_MAX bytes. Decompress into the gap instead of into
529 an auto buffer, as this should avoid copying. Return nil if
530 'inflate' returns Z_NEED_DICT, as we have no dictionary. Do not
531 set immediate_quit; we shouldn't trust zlib code that much.
532
5332013-08-11 Lars Magne Ingebrigtsen <larsi@gnus.org>
534
535 * decompress.c (Fdecompress_gzipped_region): Respect all zlib
536 errors, and really move the gap to where we want it.
537
538 * lisp.h: Include decompress.c support.
539
540 * emacs.c (main): Include decompress.c support.
541
542 * Makefile.in: Include -lz if present.
543
5442013-08-11 Jan Djärv <jan.h.d@swipnet.se>
545
546 * nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:frame:
547 (initWithTitle:): Initialize frame to 0.
548 (fillWithWidgetValue:): Call fillWithWidgetValue:frame.
549 (fillWithWidgetValue:frame:): Renamed from
550 fillWithWidgetValue:setDelegate, call initWithTile:frame: if f.
551
552 * nsterm.h (EmacsMenu): fillWithWidgetValue:setDelegate renamed to
553 fillWithWidgetValue:frame:
554
555 * nsfns.m (Fns_convert_utf8_nfd_to_nfc): Allocate and release pool to
556 remove memory leak warnings.
557
558 * nsterm.m (menu_pending_title, ns_get_pending_menu_title): Remove.
559 (ns_check_menu_open): Handle menu == nil. Remove assignment to
560 menu_pending_title.
561
562 * nsmenu.m (ns_update_menubar): Call fillWithWidgetValue:setDelegate.
563 (x_activate_menubar): Update the whole menu.
564 (trackingNotification:): Call ns_check_menu_open if tracking ends.
565 (menuWillOpen:): Increment trackingMenu. For OSX <= 10.6, exit if
566 current event is not NSSystemDefined (Bug#15001).
567 Call ns_check_menu_open only if trackingMenu is 2.
568 (menuDidClose:): New method, decrease trackingMenu.
569 (fillWithWidgetValue:setDelegate:): New method.
570 (fillWithWidgetValue:): Call the above.
571
572 * nsterm.h (EmacsMenu): Add fillWithWidgetValue:setDelegate:
573
5742013-08-11 Paul Eggert <eggert@cs.ucla.edu>
575
576 Omit some unnecessary casts.
577 Many of these go back to the old pre-C89 days, when they may have
578 been needed, but we've been assuming C89 or later for a while now.
579 * alloc.c (live_string_p, live_cons_p, live_symbol_p)
580 (live_float_p, live_misc_p, live_vector_p):
581 * buffer.c (compare_overlays, cmp_for_strings, mmap_find)
582 (mmap_alloc, alloc_buffer_text, enlarge_buffer_text)
583 (defvar_per_buffer):
584 * callint.c (Fcall_interactively):
585 * doc.c (Fsubstitute_command_keys):
586 * filelock.c (get_boot_time):
587 * frame.c (xrdb_get_resource):
588 * gtkutil.c (hierarchy_ch_cb, qttip_cb, style_changed_cb)
589 (delete_cb, xg_dialog_response_cb, xg_maybe_add_timer)
590 (xg_get_file_name_from_selector, menuitem_destroy_callback)
591 (menuitem_highlight_callback, menu_destroy_callback)
592 (xg_update_menu_item, xg_modify_menubar_widgets, menubar_map_cb)
593 (xg_tool_bar_callback, xg_get_tool_bar_widgets)
594 (xg_tool_bar_detach_callback, xg_tool_bar_attach_callback)
595 (xg_tool_bar_help_callback, tb_size_cb):
596 * image.c (xpm_alloc_color, png_read_from_memory)
597 (png_read_from_file, png_load_body, our_memory_skip_input_data)
598 (jpeg_memory_src, jpeg_file_src, imagemagick_load_image)
599 (syms_of_image):
600 * keymap.c (describe_map):
601 * nsfns.m (Fns_display_monitor_attributes_list):
602 * nsmenu.m (process_dialog:):
603 * nsterm.m (hold_event):
604 * process.c (wait_reading_process_output):
605 * regex.c (REGEX_REALLOCATE, re_set_registers, re_exec, regexec):
606 * scroll.c (do_direct_scrolling, scrolling_1):
607 * termcap.c (tgetent):
608 * window.c (check_window_containing, add_window_to_list)
609 (freeze_window_starts):
610 * xdisp.c (compare_overlay_entries, vmessage):
611 * xfns.c (x_window, x_get_monitor_attributes_xinerama)
612 (x_get_monitor_attributes_xrandr)
613 (Fx_display_monitor_attributes_list, x_display_info_for_name)
614 (Fx_open_connection, file_dialog_cb, file_dialog_unmap_cb):
615 * xfont.c (xfont_match, xfont_open):
616 * xmenu.c (x_menu_wait_for_event, menu_highlight_callback)
617 (menubar_selection_callback, menu_position_func)
618 (popup_selection_callback, create_and_show_popup_menu)
619 (dialog_selection_callback, create_and_show_dialog):
620 * xrdb.c (x_get_string_resource):
621 (main) [TESTRM]:
622 * xsmfns.c (x_session_check_input):
623 * xterm.c (x_draw_glyphless_glyph_string_foreground)
624 (xm_scroll_callback, xg_scroll_callback, xg_end_scroll_callback)
625 (xaw_jump_callback, xaw_scroll_callback):
626 Omit unnecessary casts.
627
6282013-08-10 Paul Eggert <eggert@cs.ucla.edu>
629
630 Minor string-length refactoring.
631 * alloc.c (xstrdup): Use memcpy, not strcpy, since the length's known.
632 * frame.c (make_monitor_attribute_list):
633 Prefer build_string to strlen + make_string.
634
6352013-08-10 Jan Djärv <jan.h.d@swipnet.se>
636
637 * xterm.c (x_error_handler): Also ignore BadWindow for X_SetInputFocus,
638 don't check minor_code (Bug#14417).
639
6402013-08-09 Eli Zaretskii <eliz@gnu.org>
641
642 * xdisp.c (draw_glyphs): Don't compare row pointers, compare row
643 vertical positions instead. This avoids calling MATRIX_ROW with
644 row numbers that are possibly beyond valid limits. (Bug#15064)
645
6462013-08-09 Dmitry Antipov <dmantipov@yandex.ru>
647
648 Use xstrdup and build_unibyte_string where applicable.
649 * alloc.c (xstrdup): Tiny cleanup. Add eassert.
650 * xfns.c (x_window):
651 * xrdb.c (x_get_customization_string):
652 * xterm.c (xim_initialize):
653 * w32fns.c (w32_window): Use xstrdup.
654 (w32_display_monitor_attributes_list):
655 * emacs.c (init_cmdargs):
656 * keyboard.c (PUSH_C_STR):
657 * nsfont.m (nsfont_open):
658 * sysdep.c (system_process_attributes):
659 * w32.c (system_process_attributes):
660 * xdisp.c (message1, message1_nolog): Use build_unibyte_string.
661
6622013-08-09 Eli Zaretskii <eliz@gnu.org>
663
664 * w32.c (PEXCEPTION_POINTERS, PEXCEPTION_RECORD, PCONTEXT): Define
665 variables of these types so that GDB would know about them, as aid
666 for debugging fatal exceptions. (Bug#15024) See also
667 http://sourceware.org/ml/gdb/2013-08/msg00010.html for related
668 discussions.
669
6702013-08-08 Jan Djärv <jan.h.d@swipnet.se>
671
672 * nsterm.m (ns_update_begin): Don't change clip path if it would be
673 larger than the NSWindow (Bug#14934).
674
6752013-08-08 Dmitry Antipov <dmantipov@yandex.ru>
676
677 Redesign redisplay interface to drop global variable updated_window.
678 Always pass currently updated window as a parameter to update routines.
679 * dispextern.h (updated_window): Remove declaration.
680 (struct redisplay_interface): Pass window parameter to
681 write_glyphs, insert_glyphs, clear_end_of_line, cursor_to
682 and after_update_window_hook.
683 (x_write_glyphs, x_insert_glyphs, x_clear_end_of_line, x_cursor_to):
684 Adjust prototypes.
685 * dispnew.c (updated_window): Remove.
686 (redraw_overlapped_rows, update_marginal_area, update_text_area)
687 (update_window_line): Adjust to match redisplay interface changes.
688 * nsterm.m (ns_update_window_begin, ns_update_window_end)
689 (ns_scroll_run, ns_after_update_window_line):
690 * w32term.c (x_update_window_begin, x_update_window_end)
691 (x_after_update_window_line, x_scroll_run):
692 * xterm.c (x_update_window_begin, x_update_window_end)
693 (x_after_update_window_line, x_scroll_run):
694 * xdisp.c (x_write_glyphs, x_insert_glyphs, x_clear_end_of_line):
695 Likewise. Adjust comments where appropriate.
696 (x_cursor_to): Simplify because this is always called during window
697 update (but install debugging check anyway).
698 (expose_window): Check must_be_updated_p flag to see whether this
699 function is called during window update.
700
7012013-08-08 Dmitry Antipov <dmantipov@yandex.ru>
702
703 Do not reset window modification event counters excessively.
704 These leftovers and poor man's tricky methods to catch extra
705 redisplay's attention are no longer needed.
706 * frame.c (set_menu_bar_lines_1):
707 * minibuf.c (read_minibuf_unwind):
708 * window.c (Fset_window_start, set_window_buffer, window_resize_apply)
709 (grow_mini_window, shrink_mini_window, window_scroll_pixel_based)
710 (window_scroll_line_based, Fset_window_configuration):
711 * xdisp.c (redisplay_window): Do not reset last_modified and
712 last_overlay_modified counters.
713
7142013-08-07 Jan Djärv <jan.h.d@swipnet.se>
715
716 * xselect.c (x_send_client_event): Set send_event and serial, memset
717 data.l as it might be bigger than data.b. Use 24 bit mask to
718 XSendEvent (Bug#15034).
719
7202013-08-07 Eli Zaretskii <eliz@gnu.org>
721
722 * xdisp.c (prepare_menu_bars): Don't call x_consider_frame_title
723 for TTY frames that are not the top frame on their console.
724 (Bug#14616)
725
7262013-08-07 Martin Rudalics <rudalics@gmx.at>
727
728 * w32term.c (w32fullscreen_hook): Really maximize frame when
729 asked for (Bug#14841).
730
7312013-08-07 Dmitry Antipov <dmantipov@yandex.ru>
732
733 Prefer selected_window to Fselected_window, likewise for frames.
734 * buffer.c (Fbuffer_swap_text):
735 * data.c (Fvariable_binding_locus):
736 * window.c (run_window_configuration_change_hook): Adjust users.
737 * w16select.c (Fw16_set_clipboard_data, Fw16_get_clipboard_data):
738 Use decode_live_frame.
739
7402013-08-07 Dmitry Antipov <dmantipov@yandex.ru>
741
742 Be more careful if selected window shows the buffer other than current,
743 use window_outdated only if this is not so. This change should also
744 address some weird issues discussed in Bug#13012.
745 * window.h (window_outdated): New prototype.
746 * window.c (window_outdated): Now here. Convert from static and
747 always assume window's buffer.
748 (Fwindow_end, Fwindow_line_height): Use it.
749 * xdisp.c (reconsider_clip_changes): Remove prototype, drop 2nd arg
750 and always assume window's buffer.
751 (redisplay_window): Adjust user.
752 (redisplay_internal): Call to reconsider_clip_changes once and
753 check whether mode line should be updated only if selected window
754 shows current buffer.
755 (run_window_scroll_functions): Use eassert for debugging check.
756 (Fmove_point_visually, note_mouse_highlight): Use window_outdated.
757
7582013-08-06 Dmitry Antipov <dmantipov@yandex.ru>
759
760 * window.c (window_scroll, window_scroll_pixel_based)
761 (window_scroll_line_based): Use bool for booleans.
762
7632013-08-06 Paul Eggert <eggert@cs.ucla.edu>
764
765 * process.c: Fix minor off-by-one issues in descriptor counts.
766 This shouldn't fix any real bugs, but it cleans up the code a bit.
767 (max_process_desc, max_input_desc): -1, not 0, means none.
768 All uses changed.
769 (delete_input_desc): New function.
770 (delete_write_fd, delete_keyboard_wait_descriptor): Use it.
771 (deactivate_process): Scan backwards when recomuting max_process_desc;
772 that should be faster.
773 (init_process_emacs): Initialize max_input_desc.
774
7752013-08-06 Dmitry Antipov <dmantipov@yandex.ru>
776
777 Use region cache to speedup bidi_find_paragraph_start.
778 * buffer.h (struct buffer): New member bidi_paragraph_cache.
779 Rename cache_long_line_scans to cache_long_scans.
780 * buffer.c (bset_cache_long_line_scans): Rename to
781 bset_cache_long_scans.
782 (Fget_buffer_create, Fmake_indirect_buffer, Fkill_buffer)
783 (Fbuffer_swap_text, init_buffer_once): Take bidi_paragraph_cache
784 into account.
785 (syms_of_buffer): Rename cache-long-line-scans to
786 cache-long-scans. Adjust docstring.
787 * search.c (newline_cache_on_off):
788 * indent.c (width_run_cache_on_off): Adjust users.
789 * bidi.c (bidi_paragraph_cache_on_off): New function.
790 (bidi_find_paragraph_start): Use bidi_paragraph_cache if needed.
791 * insdel.c (prepare_to_modify_buffer): Invalidate
792 bidi_paragraph_cache if enabled.
793
7942013-08-06 Dmitry Antipov <dmantipov@yandex.ru>
795
796 Invalidate region caches only if buffer text is going to be changed.
797 * lisp.h (modify_region_1): Remove 3rd arg and rename to...
798 (modify_text): ...new prototype.
799 (prepare_to_modify_buffer_1): New prototype.
800 * textprop.c (modify_region): Rename to...
801 (modify_text_properties): ...new function.
802 (add_text_properties_1, set_text_properties, Fremove_text_properties)
803 (Fremove_list_of_text_properties): Adjust users.
804 * insdel.c (modify_region_1): Remove 3rd arg and reimplement as...
805 (modify_text): ...new function.
806 (prepare_to_modify_buffer): Reimplement mostly as a wrapper for...
807 (prepare_to_modify_buffer_1): ...new function.
808 * casefiddle.c (casify_region):
809 * editfns.c (Fsubst_char_in_region, Ftranslate_region_internal)
810 (Ftranspose_regions): Use modify_text.
811
8122013-08-05 Stefan Monnier <monnier@iro.umontreal.ca>
813
814 * lisp.mk (lisp): Add nadvice.elc.
815
8162013-08-05 Dmitry Antipov <dmantipov@yandex.ru>
817
818 New macro to iterate over live buffers similar to frames.
819 * buffer.h (FOR_EACH_LIVE_BUFFER): New macro.
820 (Vbuffer_alist, Qpriority, Qbefore_string, Qafter_string):
821 Declare buffer-related variables here to offload lisp.h.
822 * buffer.c (Vbuffer_alist): Adjust comment.
823 (Fget_file_buffer, get_truename_buffer, Fother_buffer)
824 (other_buffer_safely):
825 * data.c (store_symval_forwarding):
826 * dispnew.c (Fframe_or_buffer_changed_p):
827 * fileio.c (Fdo_auto_save):
828 * filelock.c (unlock_all_files):
829 * minibuf.c (read_minibuf): Use FOR_EACH_LIVE_BUFFER.
830
8312013-08-04 Paul Eggert <eggert@cs.ucla.edu>
832
833 Fix some minor races in hosts lacking mkostemp (Bug#15015).
834 * callproc.c (create_temp_file):
835 * filelock.c (create_lock_file):
836 Assume mkostemp, since it's now provided by Gnulib.
837
8382013-08-04 Eli Zaretskii <eliz@gnu.org>
839
840 * w32.c (mkostemp): New function.
841 (mktemp): Remove, no longer used. Most of the code reused in
842 mkostemp. (Bug#15015)
843 (mktemp): Don't undef.
844
8452013-08-04 Dmitry Antipov <dmantipov@yandex.ru>
846
847 * dispnew.c (glyph_matrix_count, glyph_pool_count):
848 Move under GLYPH_DEBUG and ENABLE_CHECKING.
849 (new_glyph_matrix, free_glyph_matrix, new_glyph_pool)
850 (free_glyph_pool, check_glyph_memory): Likewise for
851 all users. Adjust comments where appropriate.
852
8532013-08-03 Paul Eggert <eggert@cs.ucla.edu>
854
855 * composite.h: Minor fixups.
856 (composition_registered_p): Rename from COMPOSITION_REGISTERD_P
857 to fix a misspelling, and change it to an inline function while
858 we're at it (it need not be a macro). All uses changed.
859 (composition_method, composition_valid_p):
860 Rewrite to avoid assignments in if-conditions.
861
8622013-08-03 Dmitry Antipov <dmantipov@yandex.ru>
863
864 Do not use global Lisp_Object in composition macros.
865 * composite.h (composition_temp): Remove declaration.
866 (COMPOSITION_METHOD, COMPOSITION_VALID_P): Replace with...
867 (composition_method, composition_valid_p): ...inline functions.
868 (compose_region): Remove the leftover.
869 * composite.c (composition_temp): Remove.
870 (run_composition_function, update_compositions)
871 (composition_compute_stop_pos, composition_adjust_point)
872 (Ffind_composition_internal):
873 * coding.c (handle_composition_annotation):
874 * xdisp.c (handle_composition_prop, check_point_in_composition):
875 Related users changed.
876
8772013-08-03 Dmitry Antipov <dmantipov@yandex.ru>
878
879 Drop FRAME_PTR typedef.
880 * composite.c, font.c, font.h, fontset.c, fontset.h, frame.c, frame.h:
881 * ftfont.c, ftxfont.c, gtkutil.c, gtkutil.h, image.c, keyboard.c:
882 * menu.c, menu.h, msdos.c, nsfns.m, nsfont.m, nsmenu.m, nsterm.h:
883 * nsterm.m, scroll.c, term.c, w32fns.c, w32font.c, w32font.h:
884 * w32inevt.c, w32inevt.h, w32menu.c, w32notify.c, w32term.c, w32term.h:
885 * w32uniscribe.c, w32xfns.c, widget.c, window.c, xdisp.c, xfaces.c:
886 * xfns.c, xfont.c, xftfont.c, xmenu.c, xselect.c, xterm.c:
887 All related users changed.
888
8892013-08-02 Stefan Monnier <monnier@iro.umontreal.ca>
890
891 * eval.c (default_toplevel_binding): New function.
892 (Fdefvar): Use it.
893 (unbind_to, backtrace_eval_unrewind): Do a bit of CSE simplification.
894 (Fdefault_toplevel_value, Fset_default_toplevel_value): New subrs.
895 (syms_of_eval): Export them.
896 * data.c (Fdefault_value): Micro cleanup.
897 * term.c (init_tty): Use "false".
898
8992013-08-02 Dmitry Antipov <dmantipov@yandex.ru>
900
901 Fix X GC leak in GTK and raw (no toolkit) X ports.
902 * xterm.c (x_free_frame_resources): If white and black relief
903 GCs are allocated, always free them here.
904 * xfns.c (x_make_gc): Omit redundant initialization.
905 * widget.c (create_frame_gcs): Remove the leftover.
906 (EmacsFrameDestroy): Do nothing because all GCs are now freed
907 in x_free_frame_resources.
908
9092013-08-02 Jan Djärv <jan.h.d@swipnet.se>
910
911 * nsterm.m (windowWillResize:toSize:): Only change title if
912 ! maximizing_resize && FULLSCREEN_NONE (Bug#15005). strdup title before
913 modifying it.
914 (viewDidEndLiveResize): New method.
915
916 * nsterm.h (EmacsView): Add maximizing_resize, put it and old_title
917 inside NS_IMPL_COCOA.
918
9192013-08-02 Dmitry Antipov <dmantipov@yandex.ru>
920
921 * insdel.c (adjust_after_replace, replace_range, del_range_2):
922 Do not check whether undo is enabled because record_insert and
923 record_delete does that themselves.
924
9252013-08-02 Dmitry Antipov <dmantipov@yandex.ru>
926
927 * xterm.h (struct x_output) [HAVE_X_I18N]: Remove xic_base_fontname
928 member which is not really used any more.
929 (FRAME_XIC_BASE_FONTNAME): Remove.
930 * xfns.c (xic_free_fontset): Adjust user.
931 * xmenu.c (mouse_position_for_popup, x_activate_menubar)
932 (update_frame_menubar, set_frame_menubar, free_frame_menubar)
933 (create_and_show_popup_menu, xmenu_show, create_and_show_dialog)
934 (xdialog_show): Use eassert for debugging check.
935 * w32term.c (x_unfocus_frame): Remove unused dummy function.
936
9372013-08-01 Paul Eggert <eggert@cs.ucla.edu>
938
939 * fileio.c, fns.c (merge): Move extern decl from here ...
940 * lisp.h (merge): ... to here.
941
9422013-08-01 Dmitry Antipov <dmantipov@yandex.ru>
943
944 Fix last font-related change.
945 * w32font.h (w32font_list_internal, w32font_match_internal):
946 Fix prototype.
947 * w32uniscribe.c (uniscribe_list, uniscribe_match):
948 (uniscribe_list_family): Adjust to match font API change.
949 MS-Windows breakage reported by Juanma Barranquero <lekktu@gmail.com>
950 at http://lists.gnu.org/archive/html/emacs-devel/2013-08/msg00006.html.
951
9522013-08-01 Dmitry Antipov <dmantipov@yandex.ru>
953
954 * frame.h (FRAME_MOUSE_UPDATE):
955 * nsterm.m (ns_frame_up_to_date): Omit redundant check
956 whether hlinfo->mouse_face_mouse_frame is non-NULL.
957
9582013-08-01 Dmitry Antipov <dmantipov@yandex.ru>
959
960 Avoid redundant Lisp_Object <-> struct frame conversions in font API.
961 * font.h (struct font_driver): Change list, match, and list_family
962 functions to accept struct frame * as first arg.
963 * font.c (font_score, font_compare, font_sort_entities): Remove
964 prototypes.
965 (font_sort_entities, font_list_entities, font_select_entity):
966 (font_find_for_lface, Flist_fonts, Ffont_family_list): Adjust to
967 match font API change.
968 * xfont.c (xfont_list, xfont_match, xfont_list_family):
969 * ftfont.c (ftfont_list, ftfont_match, ftfont_list_family):
970 * ftxfont.c (ftxfont_list, ftxfont_match):
971 * xftfont.c (xftfont_list, xftfont_match):
972 * nsfont.m (nsfont_list, nsfont_match, nsfont_list_family):
973 * w32font.c (w32font_list, w32font_match, w32font_list):
974 (w32font_list_internal, w32_font_match_internal): Likewise.
975 * xfaces.c (Fx_family_fonts): Adjust user.
976
9772013-08-01 Dmitry Antipov <dmantipov@yandex.ru>
978
979 Do not use pure Xism x_wm_set_icon_position in non-X ports.
980 * frame.c (x_set_frame_parameters): Call to x_wm_set_icon_position
981 only if HAVE_X_WINDOWS is in use.
982 * frame.h (x_set_frame_parameters): Move under HAVE_X_WINDOWS.
983 * nsterm.m (x_wm_set_icon_position): Remove no-op.
984 * w32term.c (x_wm_set_icon_position): Likewise.
985 * w32fns.c (x_icon): Adjust user.
986
9872013-08-01 Dmitry Antipov <dmantipov@yandex.ru>
988
989 * xterm.c (last_mouse_press_frame): Remove the
990 leftover which is not really used any more.
991 (handle_one_xevent, syms_of_xterm): Adjust users.
992 (x_flush): Call XFlush once per each X display, not frame.
993 This is better because this code always unconditionally skips
994 non-X frames in Vframe_list and issues the only XFlush if we
995 have more than one X frame on the same X display.
996 (any_help_event_p, x_draw_glyph_string_background, x_display_ok):
997 Use bool for booleans.
998 (x_draw_glyph_string_background, cvt_string_to_pixel):
999 (cvt_pixel_dtor): Drop unnecessary prototypes.
1000 * xterm.h (x_display_ok): Adjust prototype.
1001
10022013-07-31 Dmitry Antipov <dmantipov@yandex.ru>
1003
1004 Drop unnecessary functions that deals with frame pixel size.
1005 * frame.h, msdos.h, w32term.h, xterm.h (x_pixel_width)
1006 (x_pixel_height): Drop prototypes.
1007 * msdos.c, nsfns.m, w32fns.c, xfns.c (x_pixel_width)
1008 (x_pixel_height): Drop implementations.
1009 * frame.c (Fframe_pixel_height): Use FRAME_PIXEL_HEIGHT
1010 which should be always valid for window frame.
1011 (Frame_pixel_width): Likewise with FRAME_PIXEL_WIDTH.
1012 * w32menu.c (Fx_popup_dialog):
1013 * xmenu.c (Fx_popup_dialog): Likewise for both.
1014
10152013-07-31 Dmitry Antipov <dmantipov@yandex.ru>
1016
1017 * frame.c (Fmake_terminal_frame): Use store_in_alist to setup
1018 frame parameters and call to Fmodify_frame_parameters just once.
1019 (Fset_frame_height, Fset_frame_width): Mention nil frame in docstring.
1020 (Fset_frame_size, Fset_frame_position): Use decode_live_frame
1021 and mention nil frame in docstring.
1022
10232013-07-31 Dmitry Antipov <dmantipov@yandex.ru>
1024
1025 * frame.c (make_frame, x_set_frame_parameters): Use bool for boolean.
1026 (x_figure_window_size): Likewise. Adjust to return long.
1027 (syms_of_frame): Do not DEFSYM Qterminal_live_p.
1028 (toplevel): Move Qterminal_live_p to...
1029 * terminal.c (toplevel): ...here, make it static, and...
1030 (syms_of_terminal): ...DEFSYM here.
1031 * frame.h (Qterminal_live_p): Remove declaration.
1032 (make_frame, x_figure_window_size): Adjust prototype.
1033 * nsfns.m (Fx_create_frame): Use long for window flags.
1034
10352013-07-30 Paul Eggert <eggert@cs.ucla.edu>
1036
1037 Fix tempfile bug on platforms lacking mkostemp and mkstemp (Bug#14986).
1038 * callproc.c (create_temp_file) [! (HAVE_MKOSTEMP || HAVE_MKSTEMP)]:
1039 Do not assume that emacs_close (INT_MAX) is a no-op.
1040
10412013-07-30 Dmitry Antipov <dmantipov@yandex.ru>
1042
1043 * xfaces.c (make_face_cache): For struct face_cache, prefer
1044 xmalloc to xzalloc and so avoid redundant call to memset.
1045 (Finternal_set_lisp_face_attribute): Fix comment typo and style.
1046
10472013-07-30 Dmitry Antipov <dmantipov@yandex.ru>
1048
1049 * fringe.c (draw_window_fringes, update_window_fringes)
1050 (compute_fringe_widths):
1051 * w32term.c (x_draw_glyph_string):
1052 * window.c (candidate_window_p, Frecenter):
1053 * xfaces.c (realize_basic_faces, realize_default_face)
1054 (Fbitmap_space_p, Finternal_set_lisp_face_attribute)
1055 (x_update_menu_appearance, face_attr_equal_p, lface_equal_p):
1056 * xfns.c (x_set_cursor_color, xic_free_xfontset):
1057 * xmenu.c (Fx_menu_bar_open_internal):
1058 * xselect.c (x_reply_selection_request, Fx_get_atom_name):
1059 * xsettings.c (xft_settings_event):
1060 * xterm.c (x_draw_glyph_string, x_had_errors_p):
1061 Use bool for booleans. Adjust style and comments where
1062 appropriate.
1063 * dispextern.h (draw_window_fringes, update_window_fringes)
1064 (compute_fringe_widths):
1065 * xterm.h (x_had_errors_p): Adjust prototype.
1066
10672013-07-30 Dmitry Antipov <dmantipov@yandex.ru>
1068
1069 * frame.c (Fmodify_frame_parameters): Always check 2nd arg with
1070 CHECK_LIST. Rewrite the loop to avoid useless local variable.
1071
10722013-07-29 Dmitry Antipov <dmantipov@yandex.ru>
1073
1074 * fns.c (toplevel): Remove comment before Fsafe_length because
1075 it checks for QUIT.
1076
10772013-07-28 Paul Eggert <eggert@cs.ucla.edu>
1078
1079 * frame.c (delete_frame): Avoid unnecessary 'this_f' test (Bug#14970).
1080
10812013-07-28 Eli Zaretskii <eliz@gnu.org>
1082
1083 * w32fns.c (w32_wnd_proc) <WM_IME_STARTCOMPOSITION>: Make sure the
1084 frame which got the message is still alive, before dereferencing
1085 its pointer. (Bug#14970)
1086
1087 * frame.c (delete_frame): Test "this" frame's minibuffer window to
1088 be a live window, before using it as such. (Bug#14970)
1089
10902013-07-27 Eli Zaretskii <eliz@gnu.org>
1091
1092 * w32term.c (w32_read_socket) <WM_KILLFOCUS>: Call
1093 w32_detect_focus_change instead of doing part of its job by hand.
1094 This fixes the problem whereby FOCUS_OUT events were not sent to
1095 the event queue.
1096
12013-07-26 Eli Zaretskii <eliz@gnu.org> 10972013-07-26 Eli Zaretskii <eliz@gnu.org>
2 1098
3 * process.c (Fprocess_list): Doc fix. 1099 * process.c (Fprocess_list): Doc fix.
@@ -269,7 +1365,7 @@
269 code a bit. It makes no difference on POSIXish platforms but 1365 code a bit. It makes no difference on POSIXish platforms but
270 apparently it fixes a bug on w32. 1366 apparently it fixes a bug on w32.
271 1367
272 Fix bug where insert-file-contents closes a file twice. (Bug#14839). 1368 Fix bug where insert-file-contents closes a file twice (Bug#14839).
273 * fileio.c (close_file_unwind): Don't close if FD is negative; 1369 * fileio.c (close_file_unwind): Don't close if FD is negative;
274 this can happen when unwinding a zapped file descriptor. 1370 this can happen when unwinding a zapped file descriptor.
275 (Finsert_file_contents): Unwind-protect the fd before the point marker, 1371 (Finsert_file_contents): Unwind-protect the fd before the point marker,
@@ -422,7 +1518,7 @@
422 (make_lispy_focus_in, make_lispy_focus_out): Declare and define. 1518 (make_lispy_focus_in, make_lispy_focus_out): Declare and define.
423 (kbd_buffer_get_event): For FOCUS_IN, make a focus_in event if no 1519 (kbd_buffer_get_event): For FOCUS_IN, make a focus_in event if no
424 switch frame event is made. Check ! NILP (event->arg) if X11 (moved 1520 switch frame event is made. Check ! NILP (event->arg) if X11 (moved
425 from xterm.c). Make focus_out event for FOCUS_OUT_EVENT if NS or X11 1521 from xterm.c). Make focus_out event for FOCUS_OUT_EVENT if NS or X11
426 and there is a focused frame. 1522 and there is a focused frame.
427 (head_table): Add focus-in and focus-out. 1523 (head_table): Add focus-in and focus-out.
428 (keys_of_keyboard): Add focus-in and focus-out to Vspecial_event_map, 1524 (keys_of_keyboard): Add focus-in and focus-out to Vspecial_event_map,
@@ -795,7 +1891,7 @@
795 (emacswrite_sig, emacs_perror): New functions. 1891 (emacswrite_sig, emacs_perror): New functions.
796 * xrdb.c (fatal): Don't invoke perror, since errno might be garbage. 1892 * xrdb.c (fatal): Don't invoke perror, since errno might be garbage.
797 1893
7982013-07-08 Magnus Henoch <magnus.henoch@gmail.com> (tiny change). 18942013-07-08 Magnus Henoch <magnus.henoch@gmail.com> (tiny change)
799 1895
800 * image.c (imagemagick_load_image): Do not use MagickExportImagePixels 1896 * image.c (imagemagick_load_image): Do not use MagickExportImagePixels
801 on NS even if it is present. Pixmap on NS is a void*. 1897 on NS even if it is present. Pixmap on NS is a void*.
@@ -1470,7 +2566,7 @@
1470 Now static. 2566 Now static.
1471 * lisp.h: Remove the abovementioned defns and decls. 2567 * lisp.h: Remove the abovementioned defns and decls.
1472 2568
1473 Use functions, not macros, for XINT etc. (Bug#11935). 2569 Use functions, not macros, for XINT etc (Bug#11935).
1474 In lisp.h, prefer functions to function-like macros, and 2570 In lisp.h, prefer functions to function-like macros, and
1475 constants to object-like macros, when either will do. This: 2571 constants to object-like macros, when either will do. This:
1476 . simplifies use, as there's no more need to worry about 2572 . simplifies use, as there's no more need to worry about
diff --git a/src/ChangeLog.9 b/src/ChangeLog.9
index b451b78944f..2e1d41b2495 100644
--- a/src/ChangeLog.9
+++ b/src/ChangeLog.9
@@ -10644,7 +10644,7 @@
10644 (syms_of_xfns) [GLYPH_DEBUG]: Don't defsubr removed functions. 10644 (syms_of_xfns) [GLYPH_DEBUG]: Don't defsubr removed functions.
10645 (syms_of_xfns): Initialize Qcenter. 10645 (syms_of_xfns): Initialize Qcenter.
10646 10646
10647 * eval.c (Fsignal): If lisp_eval_depth or spepdl_size are near 10647 * eval.c (Fsignal): If lisp_eval_depth or specpdl_size are near
10648 to the limits, increase the limits. 10648 to the limits, increase the limits.
10649 10649
106502000-05-01 Kenichi Handa <handa@etl.go.jp> 106502000-05-01 Kenichi Handa <handa@etl.go.jp>
diff --git a/src/Makefile.in b/src/Makefile.in
index ce709a6bc44..5b1a7b525d0 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -243,6 +243,8 @@ IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
243LIBXML2_LIBS = @LIBXML2_LIBS@ 243LIBXML2_LIBS = @LIBXML2_LIBS@
244LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ 244LIBXML2_CFLAGS = @LIBXML2_CFLAGS@
245 245
246LIBZ = @LIBZ@
247
246XRANDR_LIBS = @XRANDR_LIBS@ 248XRANDR_LIBS = @XRANDR_LIBS@
247XRANDR_CFLAGS = @XRANDR_CFLAGS@ 249XRANDR_CFLAGS = @XRANDR_CFLAGS@
248 250
@@ -374,7 +376,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
374 process.o gnutls.o callproc.o \ 376 process.o gnutls.o callproc.o \
375 region-cache.o sound.o atimer.o \ 377 region-cache.o sound.o atimer.o \
376 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \ 378 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \
377 profiler.o \ 379 profiler.o decompress.o \
378 thread.o systhread.o \ 380 thread.o systhread.o \
379 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 381 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
380 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) 382 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ)
@@ -430,7 +432,7 @@ LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
430 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 432 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
431 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \ 433 $(FREETYPE_LIBS) $(FONTCONFIG_LIBS) $(LIBOTF_LIBS) $(M17N_FLT_LIBS) \
432 $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \ 434 $(LIBGNUTLS_LIBS) $(LIB_PTHREAD) $(LIB_PTHREAD_SIGMASK) \
433 $(GFILENOTIFY_LIBS) $(LIB_MATH) 435 $(GFILENOTIFY_LIBS) $(LIB_MATH) $(LIBZ)
434 436
435all: emacs$(EXEEXT) $(OTHER_FILES) 437all: emacs$(EXEEXT) $(OTHER_FILES)
436.PHONY: all 438.PHONY: all
diff --git a/src/alloc.c b/src/alloc.c
index 0eb54f8b271..4cc9b3e1a13 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -788,10 +788,19 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
788char * 788char *
789xstrdup (const char *s) 789xstrdup (const char *s)
790{ 790{
791 size_t len = strlen (s) + 1; 791 ptrdiff_t size;
792 char *p = xmalloc (len); 792 eassert (s);
793 memcpy (p, s, len); 793 size = strlen (s) + 1;
794 return p; 794 return memcpy (xmalloc (size), s, size);
795}
796
797/* Like above, but duplicates Lisp string to C string. */
798
799char *
800xlispstrdup (Lisp_Object string)
801{
802 ptrdiff_t size = SBYTES (string) + 1;
803 return memcpy (xmalloc (size), SSDATA (string), size);
795} 804}
796 805
797/* Like putenv, but (1) use the equivalent of xmalloc and (2) the 806/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
@@ -4057,7 +4066,7 @@ live_string_p (struct mem_node *m, void *p)
4057{ 4066{
4058 if (m->type == MEM_TYPE_STRING) 4067 if (m->type == MEM_TYPE_STRING)
4059 { 4068 {
4060 struct string_block *b = (struct string_block *) m->start; 4069 struct string_block *b = m->start;
4061 ptrdiff_t offset = (char *) p - (char *) &b->strings[0]; 4070 ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
4062 4071
4063 /* P must point to the start of a Lisp_String structure, and it 4072 /* P must point to the start of a Lisp_String structure, and it
@@ -4080,7 +4089,7 @@ live_cons_p (struct mem_node *m, void *p)
4080{ 4089{
4081 if (m->type == MEM_TYPE_CONS) 4090 if (m->type == MEM_TYPE_CONS)
4082 { 4091 {
4083 struct cons_block *b = (struct cons_block *) m->start; 4092 struct cons_block *b = m->start;
4084 ptrdiff_t offset = (char *) p - (char *) &b->conses[0]; 4093 ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
4085 4094
4086 /* P must point to the start of a Lisp_Cons, not be 4095 /* P must point to the start of a Lisp_Cons, not be
@@ -4106,7 +4115,7 @@ live_symbol_p (struct mem_node *m, void *p)
4106{ 4115{
4107 if (m->type == MEM_TYPE_SYMBOL) 4116 if (m->type == MEM_TYPE_SYMBOL)
4108 { 4117 {
4109 struct symbol_block *b = (struct symbol_block *) m->start; 4118 struct symbol_block *b = m->start;
4110 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0]; 4119 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
4111 4120
4112 /* P must point to the start of a Lisp_Symbol, not be 4121 /* P must point to the start of a Lisp_Symbol, not be
@@ -4132,7 +4141,7 @@ live_float_p (struct mem_node *m, void *p)
4132{ 4141{
4133 if (m->type == MEM_TYPE_FLOAT) 4142 if (m->type == MEM_TYPE_FLOAT)
4134 { 4143 {
4135 struct float_block *b = (struct float_block *) m->start; 4144 struct float_block *b = m->start;
4136 ptrdiff_t offset = (char *) p - (char *) &b->floats[0]; 4145 ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
4137 4146
4138 /* P must point to the start of a Lisp_Float and not be 4147 /* P must point to the start of a Lisp_Float and not be
@@ -4156,7 +4165,7 @@ live_misc_p (struct mem_node *m, void *p)
4156{ 4165{
4157 if (m->type == MEM_TYPE_MISC) 4166 if (m->type == MEM_TYPE_MISC)
4158 { 4167 {
4159 struct marker_block *b = (struct marker_block *) m->start; 4168 struct marker_block *b = m->start;
4160 ptrdiff_t offset = (char *) p - (char *) &b->markers[0]; 4169 ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
4161 4170
4162 /* P must point to the start of a Lisp_Misc, not be 4171 /* P must point to the start of a Lisp_Misc, not be
@@ -4183,7 +4192,7 @@ live_vector_p (struct mem_node *m, void *p)
4183 if (m->type == MEM_TYPE_VECTOR_BLOCK) 4192 if (m->type == MEM_TYPE_VECTOR_BLOCK)
4184 { 4193 {
4185 /* This memory node corresponds to a vector block. */ 4194 /* This memory node corresponds to a vector block. */
4186 struct vector_block *block = (struct vector_block *) m->start; 4195 struct vector_block *block = m->start;
4187 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data; 4196 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data;
4188 4197
4189 /* P is in the block's allocation range. Scan the block 4198 /* P is in the block's allocation range. Scan the block
diff --git a/src/bidi.c b/src/bidi.c
index c31d208ecbc..7d082a94997 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -61,6 +61,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
61#include "character.h" 61#include "character.h"
62#include "buffer.h" 62#include "buffer.h"
63#include "dispextern.h" 63#include "dispextern.h"
64#include "region-cache.h"
64 65
65static bool bidi_initialized = 0; 66static bool bidi_initialized = 0;
66 67
@@ -1085,6 +1086,29 @@ bidi_at_paragraph_end (ptrdiff_t charpos, ptrdiff_t bytepos)
1085 return val; 1086 return val;
1086} 1087}
1087 1088
1089/* If the user has requested the long scans caching, make sure that
1090 BIDI cache is enabled. Otherwise, make sure it's disabled. */
1091
1092static struct region_cache *
1093bidi_paragraph_cache_on_off (void)
1094{
1095 if (NILP (BVAR (current_buffer, cache_long_scans)))
1096 {
1097 if (current_buffer->bidi_paragraph_cache)
1098 {
1099 free_region_cache (current_buffer->bidi_paragraph_cache);
1100 current_buffer->bidi_paragraph_cache = 0;
1101 }
1102 return NULL;
1103 }
1104 else
1105 {
1106 if (!current_buffer->bidi_paragraph_cache)
1107 current_buffer->bidi_paragraph_cache = new_region_cache ();
1108 return current_buffer->bidi_paragraph_cache;
1109 }
1110}
1111
1088/* On my 2005-vintage machine, searching back for paragraph start 1112/* On my 2005-vintage machine, searching back for paragraph start
1089 takes ~1 ms per line. And bidi_paragraph_init is called 4 times 1113 takes ~1 ms per line. And bidi_paragraph_init is called 4 times
1090 when user types C-p. The number below limits each call to 1114 when user types C-p. The number below limits each call to
@@ -1100,7 +1124,8 @@ bidi_find_paragraph_start (ptrdiff_t pos, ptrdiff_t pos_byte)
1100{ 1124{
1101 Lisp_Object re = paragraph_start_re; 1125 Lisp_Object re = paragraph_start_re;
1102 ptrdiff_t limit = ZV, limit_byte = ZV_BYTE; 1126 ptrdiff_t limit = ZV, limit_byte = ZV_BYTE;
1103 ptrdiff_t n = 0; 1127 struct region_cache *bpc = bidi_paragraph_cache_on_off ();
1128 ptrdiff_t n = 0, oldpos = pos, next;
1104 1129
1105 while (pos_byte > BEGV_BYTE 1130 while (pos_byte > BEGV_BYTE
1106 && n++ < MAX_PARAGRAPH_SEARCH 1131 && n++ < MAX_PARAGRAPH_SEARCH
@@ -1111,10 +1136,18 @@ bidi_find_paragraph_start (ptrdiff_t pos, ptrdiff_t pos_byte)
1111 of the text over which we scan back includes 1136 of the text over which we scan back includes
1112 paragraph_start_re? */ 1137 paragraph_start_re? */
1113 DEC_BOTH (pos, pos_byte); 1138 DEC_BOTH (pos, pos_byte);
1114 pos = find_newline_no_quit (pos, pos_byte, -1, &pos_byte); 1139 if (bpc && region_cache_backward (current_buffer, bpc, pos, &next))
1140 {
1141 pos = next, pos_byte = CHAR_TO_BYTE (pos);
1142 break;
1143 }
1144 else
1145 pos = find_newline_no_quit (pos, pos_byte, -1, &pos_byte);
1115 } 1146 }
1116 if (n >= MAX_PARAGRAPH_SEARCH) 1147 if (n >= MAX_PARAGRAPH_SEARCH)
1117 pos_byte = BEGV_BYTE; 1148 pos = BEGV, pos_byte = BEGV_BYTE;
1149 if (bpc)
1150 know_region_cache (current_buffer, bpc, pos, oldpos);
1118 return pos_byte; 1151 return pos_byte;
1119} 1152}
1120 1153
diff --git a/src/buffer.c b/src/buffer.c
index 3ca1bd98b29..8a1ad607e0b 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -106,9 +106,9 @@ static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
106static void swap_out_buffer_local_variables (struct buffer *b); 106static void swap_out_buffer_local_variables (struct buffer *b);
107static void reset_buffer_local_variables (struct buffer *, bool); 107static void reset_buffer_local_variables (struct buffer *, bool);
108 108
109/* Alist of all buffer names vs the buffers. */ 109/* Alist of all buffer names vs the buffers. This used to be
110/* This used to be a variable, but is no longer, 110 a Lisp-visible variable, but is no longer, to prevent lossage
111 to prevent lossage due to user rplac'ing this alist or its elements. */ 111 due to user rplac'ing this alist or its elements. */
112Lisp_Object Vbuffer_alist; 112Lisp_Object Vbuffer_alist;
113 113
114static Lisp_Object Qkill_buffer_query_functions; 114static Lisp_Object Qkill_buffer_query_functions;
@@ -201,9 +201,9 @@ bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val)
201 b->INTERNAL_FIELD (buffer_file_coding_system) = val; 201 b->INTERNAL_FIELD (buffer_file_coding_system) = val;
202} 202}
203static void 203static void
204bset_cache_long_line_scans (struct buffer *b, Lisp_Object val) 204bset_cache_long_scans (struct buffer *b, Lisp_Object val)
205{ 205{
206 b->INTERNAL_FIELD (cache_long_line_scans) = val; 206 b->INTERNAL_FIELD (cache_long_scans) = val;
207} 207}
208static void 208static void
209bset_case_fold_search (struct buffer *b, Lisp_Object val) 209bset_case_fold_search (struct buffer *b, Lisp_Object val)
@@ -476,8 +476,7 @@ If there is no such live buffer, return nil.
476See also `find-buffer-visiting'. */) 476See also `find-buffer-visiting'. */)
477 (register Lisp_Object filename) 477 (register Lisp_Object filename)
478{ 478{
479 register Lisp_Object tail, buf, tem; 479 register Lisp_Object tail, buf, handler;
480 Lisp_Object handler;
481 480
482 CHECK_STRING (filename); 481 CHECK_STRING (filename);
483 filename = Fexpand_file_name (filename, Qnil); 482 filename = Fexpand_file_name (filename, Qnil);
@@ -492,13 +491,10 @@ See also `find-buffer-visiting'. */)
492 return BUFFERP (handled_buf) ? handled_buf : Qnil; 491 return BUFFERP (handled_buf) ? handled_buf : Qnil;
493 } 492 }
494 493
495 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 494 FOR_EACH_LIVE_BUFFER (tail, buf)
496 { 495 {
497 buf = Fcdr (XCAR (tail));
498 if (!BUFFERP (buf)) continue;
499 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; 496 if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue;
500 tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename); 497 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename)))
501 if (!NILP (tem))
502 return buf; 498 return buf;
503 } 499 }
504 return Qnil; 500 return Qnil;
@@ -507,15 +503,12 @@ See also `find-buffer-visiting'. */)
507Lisp_Object 503Lisp_Object
508get_truename_buffer (register Lisp_Object filename) 504get_truename_buffer (register Lisp_Object filename)
509{ 505{
510 register Lisp_Object tail, buf, tem; 506 register Lisp_Object tail, buf;
511 507
512 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 508 FOR_EACH_LIVE_BUFFER (tail, buf)
513 { 509 {
514 buf = Fcdr (XCAR (tail));
515 if (!BUFFERP (buf)) continue;
516 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; 510 if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue;
517 tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename); 511 if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename)))
518 if (!NILP (tem))
519 return buf; 512 return buf;
520 } 513 }
521 return Qnil; 514 return Qnil;
@@ -588,6 +581,7 @@ even if it is dead. The return value is never nil. */)
588 581
589 b->newline_cache = 0; 582 b->newline_cache = 0;
590 b->width_run_cache = 0; 583 b->width_run_cache = 0;
584 b->bidi_paragraph_cache = 0;
591 bset_width_table (b, Qnil); 585 bset_width_table (b, Qnil);
592 b->prevent_redisplay_optimizations_p = 1; 586 b->prevent_redisplay_optimizations_p = 1;
593 587
@@ -811,6 +805,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
811 805
812 b->newline_cache = 0; 806 b->newline_cache = 0;
813 b->width_run_cache = 0; 807 b->width_run_cache = 0;
808 b->bidi_paragraph_cache = 0;
814 bset_width_table (b, Qnil); 809 bset_width_table (b, Qnil);
815 810
816 name = Fcopy_sequence (name); 811 name = Fcopy_sequence (name);
@@ -1579,10 +1574,8 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1579 } 1574 }
1580 1575
1581 /* Consider alist of all buffers next. */ 1576 /* Consider alist of all buffers next. */
1582 tail = Vbuffer_alist; 1577 FOR_EACH_LIVE_BUFFER (tail, buf)
1583 for (; CONSP (tail); tail = XCDR (tail))
1584 { 1578 {
1585 buf = Fcdr (XCAR (tail));
1586 if (candidate_buffer (buf, buffer) 1579 if (candidate_buffer (buf, buffer)
1587 /* If the frame has a buffer_predicate, disregard buffers that 1580 /* If the frame has a buffer_predicate, disregard buffers that
1588 don't fit the predicate. */ 1581 don't fit the predicate. */
@@ -1619,12 +1612,9 @@ other_buffer_safely (Lisp_Object buffer)
1619{ 1612{
1620 Lisp_Object tail, buf; 1613 Lisp_Object tail, buf;
1621 1614
1622 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 1615 FOR_EACH_LIVE_BUFFER (tail, buf)
1623 { 1616 if (candidate_buffer (buf, buffer))
1624 buf = Fcdr (XCAR (tail)); 1617 return buf;
1625 if (candidate_buffer (buf, buffer))
1626 return buf;
1627 }
1628 1618
1629 buf = Fget_buffer (build_string ("*scratch*")); 1619 buf = Fget_buffer (build_string ("*scratch*"));
1630 if (NILP (buf)) 1620 if (NILP (buf))
@@ -1958,6 +1948,11 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1958 free_region_cache (b->width_run_cache); 1948 free_region_cache (b->width_run_cache);
1959 b->width_run_cache = 0; 1949 b->width_run_cache = 0;
1960 } 1950 }
1951 if (b->bidi_paragraph_cache)
1952 {
1953 free_region_cache (b->bidi_paragraph_cache);
1954 b->bidi_paragraph_cache = 0;
1955 }
1961 bset_width_table (b, Qnil); 1956 bset_width_table (b, Qnil);
1962 unblock_input (); 1957 unblock_input ();
1963 bset_undo_list (b, Qnil); 1958 bset_undo_list (b, Qnil);
@@ -2368,6 +2363,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2368 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; 2363 current_buffer->clip_changed = 1; other_buffer->clip_changed = 1;
2369 swapfield (newline_cache, struct region_cache *); 2364 swapfield (newline_cache, struct region_cache *);
2370 swapfield (width_run_cache, struct region_cache *); 2365 swapfield (width_run_cache, struct region_cache *);
2366 swapfield (bidi_paragraph_cache, struct region_cache *);
2371 current_buffer->prevent_redisplay_optimizations_p = 1; 2367 current_buffer->prevent_redisplay_optimizations_p = 1;
2372 other_buffer->prevent_redisplay_optimizations_p = 1; 2368 other_buffer->prevent_redisplay_optimizations_p = 1;
2373 swapfield (overlays_before, struct Lisp_Overlay *); 2369 swapfield (overlays_before, struct Lisp_Overlay *);
@@ -2414,7 +2410,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2414 live window points to that window's buffer. So since we 2410 live window points to that window's buffer. So since we
2415 just swapped the markers between the two buffers, we need 2411 just swapped the markers between the two buffers, we need
2416 to undo the effect of this swap for window markers. */ 2412 to undo the effect of this swap for window markers. */
2417 Lisp_Object w = Fselected_window (), ws = Qnil; 2413 Lisp_Object w = selected_window, ws = Qnil;
2418 Lisp_Object buf1, buf2; 2414 Lisp_Object buf1, buf2;
2419 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer); 2415 XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer);
2420 2416
@@ -3151,8 +3147,8 @@ struct sortvec
3151static int 3147static int
3152compare_overlays (const void *v1, const void *v2) 3148compare_overlays (const void *v1, const void *v2)
3153{ 3149{
3154 const struct sortvec *s1 = (const struct sortvec *) v1; 3150 const struct sortvec *s1 = v1;
3155 const struct sortvec *s2 = (const struct sortvec *) v2; 3151 const struct sortvec *s2 = v2;
3156 if (s1->priority != s2->priority) 3152 if (s1->priority != s2->priority)
3157 return s1->priority < s2->priority ? -1 : 1; 3153 return s1->priority < s2->priority ? -1 : 1;
3158 if (s1->beg != s2->beg) 3154 if (s1->beg != s2->beg)
@@ -3258,8 +3254,8 @@ static ptrdiff_t overlay_str_len;
3258static int 3254static int
3259cmp_for_strings (const void *as1, const void *as2) 3255cmp_for_strings (const void *as1, const void *as2)
3260{ 3256{
3261 struct sortstr *s1 = (struct sortstr *)as1; 3257 struct sortstr const *s1 = as1;
3262 struct sortstr *s2 = (struct sortstr *)as2; 3258 struct sortstr const *s2 = as2;
3263 if (s1->size != s2->size) 3259 if (s1->size != s2->size)
3264 return s2->size < s1->size ? -1 : 1; 3260 return s2->size < s1->size ? -1 : 1;
3265 if (s1->priority != s2->priority) 3261 if (s1->priority != s2->priority)
@@ -4757,7 +4753,7 @@ static struct mmap_region *
4757mmap_find (void *start, void *end) 4753mmap_find (void *start, void *end)
4758{ 4754{
4759 struct mmap_region *r; 4755 struct mmap_region *r;
4760 char *s = (char *) start, *e = (char *) end; 4756 char *s = start, *e = end;
4761 4757
4762 for (r = mmap_regions; r; r = r->next) 4758 for (r = mmap_regions; r; r = r->next)
4763 { 4759 {
@@ -4916,7 +4912,7 @@ mmap_alloc (void **var, size_t nbytes)
4916 } 4912 }
4917 else 4913 else
4918 { 4914 {
4919 struct mmap_region *r = (struct mmap_region *) p; 4915 struct mmap_region *r = p;
4920 4916
4921 r->nbytes_specified = nbytes; 4917 r->nbytes_specified = nbytes;
4922 r->nbytes_mapped = map; 4918 r->nbytes_mapped = map;
@@ -5056,7 +5052,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes)
5056 memory_full (nbytes); 5052 memory_full (nbytes);
5057 } 5053 }
5058 5054
5059 b->text->beg = (unsigned char *) p; 5055 b->text->beg = p;
5060 unblock_input (); 5056 unblock_input ();
5061} 5057}
5062 5058
@@ -5084,7 +5080,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta)
5084 memory_full (nbytes); 5080 memory_full (nbytes);
5085 } 5081 }
5086 5082
5087 BUF_BEG_ADDR (b) = (unsigned char *) p; 5083 BUF_BEG_ADDR (b) = p;
5088 unblock_input (); 5084 unblock_input ();
5089} 5085}
5090 5086
@@ -5182,7 +5178,7 @@ init_buffer_once (void)
5182 bset_buffer_file_coding_system (&buffer_defaults, Qnil); 5178 bset_buffer_file_coding_system (&buffer_defaults, Qnil);
5183 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); 5179 XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70);
5184 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); 5180 XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0);
5185 bset_cache_long_line_scans (&buffer_defaults, Qnil); 5181 bset_cache_long_scans (&buffer_defaults, Qnil);
5186 bset_file_truename (&buffer_defaults, Qnil); 5182 bset_file_truename (&buffer_defaults, Qnil);
5187 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); 5183 XSETFASTINT (BVAR (&buffer_defaults, display_count), 0);
5188 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); 5184 XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0);
@@ -5246,7 +5242,7 @@ init_buffer_once (void)
5246 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx; 5242 XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx;
5247 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx; 5243 XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx;
5248 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx; 5244 XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx;
5249 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_line_scans), idx); ++idx; 5245 XSETFASTINT (BVAR (&buffer_local_flags, cache_long_scans), idx); ++idx;
5250 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx; 5246 XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx;
5251 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx; 5247 XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx;
5252 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx; 5248 XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx;
@@ -5402,11 +5398,7 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
5402 bo_fwd->predicate = predicate; 5398 bo_fwd->predicate = predicate;
5403 sym->declared_special = 1; 5399 sym->declared_special = 1;
5404 sym->redirect = SYMBOL_FORWARDED; 5400 sym->redirect = SYMBOL_FORWARDED;
5405 { 5401 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *) bo_fwd);
5406 /* I tried to do the job without a cast, but it seems impossible.
5407 union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */
5408 SET_SYMBOL_FWD (sym, (union Lisp_Fwd *)bo_fwd);
5409 }
5410 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); 5402 XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym);
5411 5403
5412 if (PER_BUFFER_IDX (offset) == 0) 5404 if (PER_BUFFER_IDX (offset) == 0)
@@ -6115,7 +6107,7 @@ An entry (apply FUN-NAME . ARGS) means undo the change with
6115 6107
6116An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo 6108An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
6117in the active region. BEG and END is the range affected by this entry 6109in the active region. BEG and END is the range affected by this entry
6118and DELTA is the number of bytes added or deleted in that range by 6110and DELTA is the number of characters added or deleted in that range by
6119this change. 6111this change.
6120 6112
6121An entry (MARKER . DISTANCE) indicates that the marker MARKER 6113An entry (MARKER . DISTANCE) indicates that the marker MARKER
@@ -6133,8 +6125,8 @@ If the value of the variable is t, undo information is not recorded. */);
6133 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil, 6125 DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil,
6134 doc: /* Non-nil means the mark and region are currently active in this buffer. */); 6126 doc: /* Non-nil means the mark and region are currently active in this buffer. */);
6135 6127
6136 DEFVAR_PER_BUFFER ("cache-long-line-scans", &BVAR (current_buffer, cache_long_line_scans), Qnil, 6128 DEFVAR_PER_BUFFER ("cache-long-scans", &BVAR (current_buffer, cache_long_scans), Qnil,
6137 doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly. 6129 doc: /* Non-nil means that Emacs should use caches in attempt to speedup buffer scans.
6138 6130
6139Normally, the line-motion functions work by scanning the buffer for 6131Normally, the line-motion functions work by scanning the buffer for
6140newlines. Columnar operations (like `move-to-column' and 6132newlines. Columnar operations (like `move-to-column' and
@@ -6144,18 +6136,24 @@ buffer's lines are very long (say, more than 500 characters), these
6144motion functions will take longer to execute. Emacs may also take 6136motion functions will take longer to execute. Emacs may also take
6145longer to update the display. 6137longer to update the display.
6146 6138
6147If `cache-long-line-scans' is non-nil, these motion functions cache the 6139If `cache-long-scans' is non-nil, these motion functions cache the
6148results of their scans, and consult the cache to avoid rescanning 6140results of their scans, and consult the cache to avoid rescanning
6149regions of the buffer until the text is modified. The caches are most 6141regions of the buffer until the text is modified. The caches are most
6150beneficial when they prevent the most searching---that is, when the 6142beneficial when they prevent the most searching---that is, when the
6151buffer contains long lines and large regions of characters with the 6143buffer contains long lines and large regions of characters with the
6152same, fixed screen width. 6144same, fixed screen width.
6153 6145
6154When `cache-long-line-scans' is non-nil, processing short lines will 6146When `cache-long-scans' is non-nil, processing short lines will
6155become slightly slower (because of the overhead of consulting the 6147become slightly slower (because of the overhead of consulting the
6156cache), and the caches will use memory roughly proportional to the 6148cache), and the caches will use memory roughly proportional to the
6157number of newlines and characters whose screen width varies. 6149number of newlines and characters whose screen width varies.
6158 6150
6151Bidirectional editing also requires buffer scans to find paragraph
6152separators. If you have large paragraphs or no paragraph separators
6153at all, these scans may be slow. If `cache-long-scans' is non-nil,
6154results of these scans are cached. This doesn't help too much if
6155paragraphs are of the reasonable (few thousands of characters) size.
6156
6159The caches require no explicit maintenance; their accuracy is 6157The caches require no explicit maintenance; their accuracy is
6160maintained internally by the Emacs primitives. Enabling or disabling 6158maintained internally by the Emacs primitives. Enabling or disabling
6161the cache should not affect the behavior of any of the motion 6159the cache should not affect the behavior of any of the motion
diff --git a/src/buffer.h b/src/buffer.h
index 6c0058ee8f3..a2645981e01 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -632,9 +632,9 @@ struct buffer
632 /* List of symbols naming the file format used for auto-save file. */ 632 /* List of symbols naming the file format used for auto-save file. */
633 Lisp_Object INTERNAL_FIELD (auto_save_file_format); 633 Lisp_Object INTERNAL_FIELD (auto_save_file_format);
634 634
635 /* True if the newline position cache and width run cache are 635 /* True if the newline position cache, width run cache and BIDI paragraph
636 enabled. See search.c and indent.c. */ 636 cache are enabled. See search.c, indent.c and bidi.c for details. */
637 Lisp_Object INTERNAL_FIELD (cache_long_line_scans); 637 Lisp_Object INTERNAL_FIELD (cache_long_scans);
638 638
639 /* If the width run cache is enabled, this table contains the 639 /* If the width run cache is enabled, this table contains the
640 character widths width_run_cache (see above) assumes. When we 640 character widths width_run_cache (see above) assumes. When we
@@ -839,9 +839,12 @@ struct buffer
839 the character's width; if it maps a character to zero, we don't 839 the character's width; if it maps a character to zero, we don't
840 know what its width is. This allows compute_motion to process 840 know what its width is. This allows compute_motion to process
841 such regions very quickly, using algebra instead of inspecting 841 such regions very quickly, using algebra instead of inspecting
842 each character. See also width_table, below. */ 842 each character. See also width_table, below.
843
844 The latter cache is used to speedup bidi_find_paragraph_start. */
843 struct region_cache *newline_cache; 845 struct region_cache *newline_cache;
844 struct region_cache *width_run_cache; 846 struct region_cache *width_run_cache;
847 struct region_cache *bidi_paragraph_cache;
845 848
846 /* Non-zero means don't use redisplay optimizations for 849 /* Non-zero means don't use redisplay optimizations for
847 displaying this buffer. */ 850 displaying this buffer. */
@@ -1116,9 +1119,17 @@ record_unwind_current_buffer (void)
1116 } \ 1119 } \
1117 } while (0) 1120 } while (0)
1118 1121
1122extern Lisp_Object Vbuffer_alist;
1119extern Lisp_Object Qbefore_change_functions; 1123extern Lisp_Object Qbefore_change_functions;
1120extern Lisp_Object Qafter_change_functions; 1124extern Lisp_Object Qafter_change_functions;
1121extern Lisp_Object Qfirst_change_hook; 1125extern Lisp_Object Qfirst_change_hook;
1126extern Lisp_Object Qpriority, Qbefore_string, Qafter_string;
1127
1128/* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
1129 a `for' loop which iterates over the buffers from Vbuffer_alist. */
1130
1131#define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \
1132 FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
1122 1133
1123/* Get text properties of B. */ 1134/* Get text properties of B. */
1124 1135
diff --git a/src/callint.c b/src/callint.c
index 38431226508..25096af5068 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -331,12 +331,9 @@ invoke it. If KEYS is omitted or nil, the return value of
331 331
332 /* If SPECS is set to a string, use it as an interactive prompt. */ 332 /* If SPECS is set to a string, use it as an interactive prompt. */
333 if (STRINGP (specs)) 333 if (STRINGP (specs))
334 { 334 /* Make a copy of string so that if a GC relocates specs,
335 /* Make a copy of string so that if a GC relocates specs, 335 `string' will still be valid. */
336 `string' will still be valid. */ 336 string = xlispstrdupa (specs);
337 string = alloca (SBYTES (specs) + 1);
338 memcpy (string, SSDATA (specs), SBYTES (specs) + 1);
339 }
340 else 337 else
341 { 338 {
342 Lisp_Object input; 339 Lisp_Object input;
@@ -529,7 +526,7 @@ invoke it. If KEYS is omitted or nil, the return value of
529 make_number (SCHARS (callint_message)), 526 make_number (SCHARS (callint_message)),
530 Qface, Qminibuffer_prompt, callint_message); 527 Qface, Qminibuffer_prompt, callint_message);
531 args[i] = Fread_char (callint_message, Qnil, Qnil); 528 args[i] = Fread_char (callint_message, Qnil, Qnil);
532 message1_nolog ((char *) 0); 529 message1_nolog (0);
533 /* Passing args[i] directly stimulates compiler bug. */ 530 /* Passing args[i] directly stimulates compiler bug. */
534 teml = args[i]; 531 teml = args[i];
535 /* See bug#8479. */ 532 /* See bug#8479. */
diff --git a/src/callproc.c b/src/callproc.c
index 91f29bd589b..2a9162cb5cc 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -68,9 +68,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
68/* Pattern used by call-process-region to make temp files. */ 68/* Pattern used by call-process-region to make temp files. */
69static Lisp_Object Vtemp_file_name_pattern; 69static Lisp_Object Vtemp_file_name_pattern;
70 70
71/* The next two variables are valid only while record-unwind-protect 71/* The next two variables are used while record-unwind-protect is in place
72 is in place during call-process for a synchronous subprocess. At 72 during call-process for a subprocess for which record_deleted_pid has
73 other times, their contents are irrelevant. Doing this via static 73 not yet been called. At other times, synch_process_pid is zero and
74 synch_process_tempfile's contents are irrelevant. Doing this via static
74 C variables is more convenient than putting them into the arguments 75 C variables is more convenient than putting them into the arguments
75 of record-unwind-protect, as they need to be updated at randomish 76 of record-unwind-protect, as they need to be updated at randomish
76 times in the code, and Lisp cannot always store these values as 77 times in the code, and Lisp cannot always store these values as
@@ -80,8 +81,28 @@ static Lisp_Object Vtemp_file_name_pattern;
80/* If nonzero, a process-ID that has not been reaped. */ 81/* If nonzero, a process-ID that has not been reaped. */
81static pid_t synch_process_pid; 82static pid_t synch_process_pid;
82 83
83/* If nonnegative, a file descriptor that has not been closed. */ 84/* If a string, the name of a temp file that has not been removed. */
84static int synch_process_fd; 85#ifdef MSDOS
86static Lisp_Object synch_process_tempfile;
87#else
88# define synch_process_tempfile make_number (0)
89#endif
90
91/* Indexes of file descriptors that need closing on call_process_kill. */
92enum
93 {
94 /* The subsidiary process's stdout and stderr. stdin is handled
95 separately, in either Fcall_process_region or create_temp_file. */
96 CALLPROC_STDOUT, CALLPROC_STDERR,
97
98 /* How to read from a pipe (or substitute) from the subsidiary process. */
99 CALLPROC_PIPEREAD,
100
101 /* A bound on the number of file descriptors. */
102 CALLPROC_FDS
103 };
104
105static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int);
85 106
86/* Block SIGCHLD. */ 107/* Block SIGCHLD. */
87 108
@@ -107,80 +128,68 @@ unblock_child_signal (void)
107 reaped on receipt of the first SIGCHLD after the critical section. */ 128 reaped on receipt of the first SIGCHLD after the critical section. */
108 129
109void 130void
110record_kill_process (struct Lisp_Process *p) 131record_kill_process (struct Lisp_Process *p, Lisp_Object tempfile)
111{ 132{
112 block_child_signal (); 133 block_child_signal ();
113 134
114 if (p->alive) 135 if (p->alive)
115 { 136 {
137 record_deleted_pid (p->pid, tempfile);
116 p->alive = 0; 138 p->alive = 0;
117 record_deleted_pid (p->pid);
118 kill (- p->pid, SIGKILL); 139 kill (- p->pid, SIGKILL);
119 } 140 }
120 141
121 unblock_child_signal (); 142 unblock_child_signal ();
122} 143}
123 144
124/* Clean up when exiting call_process_cleanup. */ 145/* Clean up files, file descriptors and processes created by Fcall_process. */
125 146
126static void 147static void
127call_process_kill (void) 148delete_temp_file (Lisp_Object name)
128{ 149{
129 if (synch_process_fd >= 0) 150 unlink (SSDATA (name));
130 emacs_close (synch_process_fd); 151}
152
153static void
154call_process_kill (void *ptr)
155{
156 int *callproc_fd = ptr;
157 int i;
158 for (i = 0; i < CALLPROC_FDS; i++)
159 if (0 <= callproc_fd[i])
160 emacs_close (callproc_fd[i]);
131 161
132 if (synch_process_pid) 162 if (synch_process_pid)
133 { 163 {
134 struct Lisp_Process proc; 164 struct Lisp_Process proc;
135 proc.alive = 1; 165 proc.alive = 1;
136 proc.pid = synch_process_pid; 166 proc.pid = synch_process_pid;
137 record_kill_process (&proc); 167 record_kill_process (&proc, synch_process_tempfile);
168 synch_process_pid = 0;
138 } 169 }
170 else if (STRINGP (synch_process_tempfile))
171 delete_temp_file (synch_process_tempfile);
139} 172}
140 173
141/* Clean up when exiting Fcall_process. 174/* Clean up when exiting Fcall_process: restore the buffer, and
142 On MSDOS, delete the temporary file on any kind of termination. 175 kill the subsidiary process group if the process still exists. */
143 On Unix, kill the process and any children on termination by signal. */
144 176
145static void 177static void
146call_process_cleanup (Lisp_Object arg) 178call_process_cleanup (Lisp_Object buffer)
147{ 179{
148#ifdef MSDOS
149 Lisp_Object buffer = Fcar (arg);
150 Lisp_Object file = Fcdr (arg);
151#else
152 Lisp_Object buffer = arg;
153#endif
154
155 Fset_buffer (buffer); 180 Fset_buffer (buffer);
156 181
157#ifndef MSDOS
158 /* If the process still exists, kill its process group. */
159 if (synch_process_pid) 182 if (synch_process_pid)
160 { 183 {
161 ptrdiff_t count = SPECPDL_INDEX ();
162 kill (-synch_process_pid, SIGINT); 184 kill (-synch_process_pid, SIGINT);
163 record_unwind_protect_void (call_process_kill);
164 message1 ("Waiting for process to die...(type C-g again to kill it instantly)"); 185 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
165 immediate_quit = 1; 186 immediate_quit = 1;
166 QUIT; 187 QUIT;
167 wait_for_termination (synch_process_pid, 0, 1); 188 wait_for_termination (synch_process_pid, 0, 1);
168 synch_process_pid = 0; 189 synch_process_pid = 0;
169 immediate_quit = 0; 190 immediate_quit = 0;
170 specpdl_ptr = specpdl + count; /* Discard the unwind protect. */
171 message1 ("Waiting for process to die...done"); 191 message1 ("Waiting for process to die...done");
172 } 192 }
173#endif
174
175 if (synch_process_fd >= 0)
176 emacs_close (synch_process_fd);
177
178#ifdef MSDOS
179 /* FILE is "" when we didn't actually create a temporary file in
180 call-process. */
181 if (!(strcmp (SDATA (file), NULL_DEVICE) == 0 || SREF (file, 0) == '\0'))
182 unlink (SDATA (file));
183#endif
184} 193}
185 194
186#ifdef DOS_NT 195#ifdef DOS_NT
@@ -218,10 +227,42 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
218usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) */) 227usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) */)
219 (ptrdiff_t nargs, Lisp_Object *args) 228 (ptrdiff_t nargs, Lisp_Object *args)
220{ 229{
221 Lisp_Object infile, buffer, current_dir, path; 230 Lisp_Object infile, encoded_infile;
231 int filefd;
232 struct gcpro gcpro1;
233 ptrdiff_t count = SPECPDL_INDEX ();
234
235 if (nargs >= 2 && ! NILP (args[1]))
236 {
237 infile = Fexpand_file_name (args[1], BVAR (current_buffer, directory));
238 CHECK_STRING (infile);
239 }
240 else
241 infile = build_string (NULL_DEVICE);
242
243 GCPRO1 (infile);
244 encoded_infile = STRING_MULTIBYTE (infile) ? ENCODE_FILE (infile) : infile;
245
246 filefd = emacs_open (SSDATA (encoded_infile), O_RDONLY, 0);
247 if (filefd < 0)
248 report_file_error ("Opening process input file", infile);
249 record_unwind_protect_int (close_file_unwind, filefd);
250 UNGCPRO;
251 return unbind_to (count, call_process (nargs, args, filefd));
252}
253
254/* Like Fcall_process (NARGS, ARGS), except use FILEFD as the input file.
255 At entry, the specpdl stack top entry must be close_file_unwind (FILEFD). */
256
257static Lisp_Object
258call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd)
259{
260 Lisp_Object buffer, current_dir, path;
222 bool display_p; 261 bool display_p;
223 int fd0, fd1, filefd; 262 int fd0;
263 int callproc_fd[CALLPROC_FDS];
224 int status; 264 int status;
265 ptrdiff_t i;
225 ptrdiff_t count = SPECPDL_INDEX (); 266 ptrdiff_t count = SPECPDL_INDEX ();
226 USE_SAFE_ALLOCA; 267 USE_SAFE_ALLOCA;
227 268
@@ -231,19 +272,21 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
231 Lisp_Object error_file; 272 Lisp_Object error_file;
232 Lisp_Object output_file = Qnil; 273 Lisp_Object output_file = Qnil;
233#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ 274#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
234 char *outf, *tempfile = NULL; 275 char *tempfile = NULL;
235 int outfilefd;
236 int pid; 276 int pid;
237#else 277#else
238 pid_t pid; 278 pid_t pid;
239#endif 279#endif
240 int child_errno; 280 int child_errno;
241 int fd_output = -1; 281 int fd_output, fd_error;
242 struct coding_system process_coding; /* coding-system of process output */ 282 struct coding_system process_coding; /* coding-system of process output */
243 struct coding_system argument_coding; /* coding-system of arguments */ 283 struct coding_system argument_coding; /* coding-system of arguments */
244 /* Set to the return value of Ffind_operation_coding_system. */ 284 /* Set to the return value of Ffind_operation_coding_system. */
245 Lisp_Object coding_systems; 285 Lisp_Object coding_systems;
246 bool output_to_buffer = 1; 286 bool discard_output;
287
288 if (synch_process_pid)
289 error ("call-process invoked recursively");
247 290
248 /* Qt denotes that Ffind_operation_coding_system is not yet called. */ 291 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
249 coding_systems = Qt; 292 coding_systems = Qt;
@@ -262,7 +305,6 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
262 /* Decide the coding-system for giving arguments. */ 305 /* Decide the coding-system for giving arguments. */
263 { 306 {
264 Lisp_Object val, *args2; 307 Lisp_Object val, *args2;
265 ptrdiff_t i;
266 308
267 /* If arguments are supplied, we may have to encode them. */ 309 /* If arguments are supplied, we may have to encode them. */
268 if (nargs >= 5) 310 if (nargs >= 5)
@@ -301,24 +343,16 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
301 } 343 }
302 } 344 }
303 345
304 if (nargs >= 2 && ! NILP (args[1])) 346 if (nargs < 3)
305 { 347 buffer = Qnil;
306 infile = Fexpand_file_name (args[1], BVAR (current_buffer, directory));
307 CHECK_STRING (infile);
308 }
309 else 348 else
310 infile = build_string (NULL_DEVICE);
311
312 if (nargs >= 3)
313 { 349 {
314 buffer = args[2]; 350 buffer = args[2];
315 351
316 /* If BUFFER is a list, its meaning is (BUFFER-FOR-STDOUT 352 /* If BUFFER is a list, its meaning is (BUFFER-FOR-STDOUT
317 FILE-FOR-STDERR), unless the first element is :file, in which case see 353 FILE-FOR-STDERR), unless the first element is :file, in which case see
318 the next paragraph. */ 354 the next paragraph. */
319 if (CONSP (buffer) 355 if (CONSP (buffer) && !EQ (XCAR (buffer), QCfile))
320 && (! SYMBOLP (XCAR (buffer))
321 || strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer))), ":file")))
322 { 356 {
323 if (CONSP (XCDR (buffer))) 357 if (CONSP (XCDR (buffer)))
324 { 358 {
@@ -335,9 +369,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
335 } 369 }
336 370
337 /* If the buffer is (still) a list, it might be a (:file "file") spec. */ 371 /* If the buffer is (still) a list, it might be a (:file "file") spec. */
338 if (CONSP (buffer) 372 if (CONSP (buffer) && EQ (XCAR (buffer), QCfile))
339 && SYMBOLP (XCAR (buffer))
340 && ! strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer))), ":file"))
341 { 373 {
342 output_file = Fexpand_file_name (XCAR (XCDR (buffer)), 374 output_file = Fexpand_file_name (XCAR (XCDR (buffer)),
343 BVAR (current_buffer, directory)); 375 BVAR (current_buffer, directory));
@@ -345,9 +377,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
345 buffer = Qnil; 377 buffer = Qnil;
346 } 378 }
347 379
348 if (!(EQ (buffer, Qnil) 380 if (! (NILP (buffer) || EQ (buffer, Qt) || INTEGERP (buffer)))
349 || EQ (buffer, Qt)
350 || INTEGERP (buffer)))
351 { 381 {
352 Lisp_Object spec_buffer; 382 Lisp_Object spec_buffer;
353 spec_buffer = buffer; 383 spec_buffer = buffer;
@@ -358,8 +388,6 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
358 CHECK_BUFFER (buffer); 388 CHECK_BUFFER (buffer);
359 } 389 }
360 } 390 }
361 else
362 buffer = Qnil;
363 391
364 /* Make sure that the child will be able to chdir to the current 392 /* Make sure that the child will be able to chdir to the current
365 buffer's current directory, or its unhandled equivalent. We 393 buffer's current directory, or its unhandled equivalent. We
@@ -372,11 +400,11 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
372 protected by the caller, so all we really have to worry about is 400 protected by the caller, so all we really have to worry about is
373 buffer. */ 401 buffer. */
374 { 402 {
375 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 403 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
376 404
377 current_dir = BVAR (current_buffer, directory); 405 current_dir = BVAR (current_buffer, directory);
378 406
379 GCPRO5 (infile, buffer, current_dir, error_file, output_file); 407 GCPRO4 (buffer, current_dir, error_file, output_file);
380 408
381 current_dir = Funhandled_file_name_directory (current_dir); 409 current_dir = Funhandled_file_name_directory (current_dir);
382 if (NILP (current_dir)) 410 if (NILP (current_dir))
@@ -390,8 +418,6 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
390 report_file_error ("Setting current directory", 418 report_file_error ("Setting current directory",
391 BVAR (current_buffer, directory)); 419 BVAR (current_buffer, directory));
392 420
393 if (STRING_MULTIBYTE (infile))
394 infile = ENCODE_FILE (infile);
395 if (STRING_MULTIBYTE (current_dir)) 421 if (STRING_MULTIBYTE (current_dir))
396 current_dir = ENCODE_FILE (current_dir); 422 current_dir = ENCODE_FILE (current_dir);
397 if (STRINGP (error_file) && STRING_MULTIBYTE (error_file)) 423 if (STRINGP (error_file) && STRING_MULTIBYTE (error_file))
@@ -403,44 +429,23 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
403 429
404 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]); 430 display_p = INTERACTIVE && nargs >= 4 && !NILP (args[3]);
405 431
406 filefd = emacs_open (SSDATA (infile), O_RDONLY, 0); 432 for (i = 0; i < CALLPROC_FDS; i++)
407 if (filefd < 0) 433 callproc_fd[i] = -1;
408 { 434#ifdef MSDOS
409 int open_errno = errno; 435 synch_process_tempfile = make_number (0);
410 report_file_errno ("Opening process input file", DECODE_FILE (infile), 436#endif
411 open_errno); 437 record_unwind_protect_ptr (call_process_kill, callproc_fd);
412 }
413
414 if (STRINGP (output_file))
415 {
416 fd_output = emacs_open (SSDATA (output_file),
417 O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
418 default_output_mode);
419 if (fd_output < 0)
420 {
421 int open_errno = errno;
422 output_file = DECODE_FILE (output_file);
423 report_file_errno ("Opening process output file",
424 output_file, open_errno);
425 }
426 if (STRINGP (error_file) || NILP (error_file))
427 output_to_buffer = 0;
428 }
429 438
430 /* Search for program; barf if not found. */ 439 /* Search for program; barf if not found. */
431 { 440 {
432 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 441 struct gcpro gcpro1, gcpro2, gcpro3;
433 int ok; 442 int ok;
434 443
435 GCPRO4 (infile, buffer, current_dir, error_file); 444 GCPRO3 (buffer, current_dir, error_file);
436 ok = openp (Vexec_path, args[0], Vexec_suffixes, &path, make_number (X_OK)); 445 ok = openp (Vexec_path, args[0], Vexec_suffixes, &path, make_number (X_OK));
437 UNGCPRO; 446 UNGCPRO;
438 if (ok < 0) 447 if (ok < 0)
439 { 448 report_file_error ("Searching for program", args[0]);
440 int openp_errno = errno;
441 emacs_close (filefd);
442 report_file_errno ("Searching for program", args[0], openp_errno);
443 }
444 } 449 }
445 450
446 /* If program file name starts with /: for quoting a magic name, 451 /* If program file name starts with /: for quoting a magic name,
@@ -452,9 +457,9 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
452 new_argv = SAFE_ALLOCA ((nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv); 457 new_argv = SAFE_ALLOCA ((nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
453 458
454 { 459 {
455 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 460 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
456 461
457 GCPRO5 (infile, buffer, current_dir, path, error_file); 462 GCPRO4 (buffer, current_dir, path, error_file);
458 if (nargs > 4) 463 if (nargs > 4)
459 { 464 {
460 ptrdiff_t i; 465 ptrdiff_t i;
@@ -479,254 +484,213 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
479 UNGCPRO; 484 UNGCPRO;
480 } 485 }
481 486
482#ifdef MSDOS /* MW, July 1993 */ 487 discard_output = INTEGERP (buffer) || (NILP (buffer) && NILP (output_file));
483 488
484 /* If we're redirecting STDOUT to a file, that file is already open 489#ifdef MSDOS
485 on fd_output. */ 490 if (! discard_output && ! STRINGP (output_file))
486 if (fd_output < 0)
487 { 491 {
488 if ((outf = egetenv ("TMPDIR"))) 492 char const *tmpdir = egetenv ("TMPDIR");
489 strcpy (tempfile = alloca (strlen (outf) + 20), outf); 493 char const *outf = tmpdir ? tmpdir : "";
490 else 494 tempfile = alloca (strlen (outf) + 20);
491 { 495 strcpy (tempfile, outf);
492 tempfile = alloca (20);
493 *tempfile = '\0';
494 }
495 dostounix_filename (tempfile, 0); 496 dostounix_filename (tempfile, 0);
496 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/') 497 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
497 strcat (tempfile, "/"); 498 strcat (tempfile, "/");
498 strcat (tempfile, "detmp.XXX"); 499 strcat (tempfile, "detmp.XXX");
499 mktemp (tempfile); 500 mktemp (tempfile);
500 outfilefd = emacs_open (tempfile, O_WRONLY | O_CREAT | O_TRUNC, 501 if (!*tempfile)
501 S_IREAD | S_IWRITE); 502 report_file_error ("Opening process output file", Qnil);
502 if (outfilefd < 0) 503 output_file = build_string (tempfile);
504 synch_process_tempfile = output_file;
505 }
506#endif
507
508 if (discard_output)
509 {
510 fd_output = emacs_open (NULL_DEVICE, O_WRONLY, 0);
511 if (fd_output < 0)
512 report_file_error ("Opening null device", Qnil);
513 }
514 else if (STRINGP (output_file))
515 {
516 fd_output = emacs_open (SSDATA (output_file),
517 O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
518 default_output_mode);
519 if (fd_output < 0)
503 { 520 {
504 int open_errno = errno; 521 int open_errno = errno;
505 emacs_close (filefd); 522 output_file = DECODE_FILE (output_file);
506 report_file_errno ("Opening process output file", 523 report_file_errno ("Opening process output file",
507 build_string (tempfile), open_errno); 524 output_file, open_errno);
508 } 525 }
509 } 526 }
510 else 527 else
511 outfilefd = fd_output;
512 fd0 = filefd;
513 fd1 = outfilefd;
514#endif /* MSDOS */
515
516 if (INTEGERP (buffer))
517 { 528 {
518 fd0 = -1;
519 fd1 = emacs_open (NULL_DEVICE, O_WRONLY, 0);
520 }
521 else
522 {
523#ifndef MSDOS
524 int fd[2]; 529 int fd[2];
525 if (emacs_pipe (fd) != 0) 530 if (emacs_pipe (fd) != 0)
526 { 531 report_file_error ("Creating process pipe", Qnil);
527 int pipe_errno = errno; 532 callproc_fd[CALLPROC_PIPEREAD] = fd[0];
528 emacs_close (filefd); 533 fd_output = fd[1];
529 report_file_errno ("Creating process pipe", Qnil, pipe_errno);
530 }
531 fd0 = fd[0];
532 fd1 = fd[1];
533#endif
534 } 534 }
535 callproc_fd[CALLPROC_STDOUT] = fd_output;
535 536
536 { 537 fd_error = fd_output;
537 int fd_error = fd1;
538
539 if (fd_output >= 0)
540 fd1 = fd_output;
541 538
542 if (NILP (error_file)) 539 if (STRINGP (error_file) || (NILP (error_file) && !discard_output))
543 fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0); 540 {
544 else if (STRINGP (error_file)) 541 fd_error = emacs_open ((STRINGP (error_file)
545 fd_error = emacs_open (SSDATA (error_file), 542 ? SSDATA (error_file)
543 : NULL_DEVICE),
546 O_WRONLY | O_CREAT | O_TRUNC | O_TEXT, 544 O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
547 default_output_mode); 545 default_output_mode);
548 546 if (fd_error < 0)
549 if (fd_error < 0) 547 {
550 { 548 int open_errno = errno;
551 int open_errno = errno; 549 report_file_errno ("Cannot redirect stderr",
552 emacs_close (filefd); 550 (STRINGP (error_file)
553 if (fd0 != filefd) 551 ? DECODE_FILE (error_file)
554 emacs_close (fd0); 552 : build_string (NULL_DEVICE)),
555 if (fd1 >= 0) 553 open_errno);
556 emacs_close (fd1); 554 }
557#ifdef MSDOS 555 callproc_fd[CALLPROC_STDERR] = fd_error;
558 unlink (tempfile); 556 }
559#endif
560 if (NILP (error_file))
561 error_file = build_string (NULL_DEVICE);
562 else if (STRINGP (error_file))
563 error_file = DECODE_FILE (error_file);
564 report_file_errno ("Cannot redirect stderr", error_file, open_errno);
565 }
566 557
567#ifdef MSDOS /* MW, July 1993 */ 558#ifdef MSDOS /* MW, July 1993 */
568 /* Note that on MSDOS `child_setup' actually returns the child process 559 /* Note that on MSDOS `child_setup' actually returns the child process
569 exit status, not its PID, so assign it to status below. */ 560 exit status, not its PID, so assign it to status below. */
570 pid = child_setup (filefd, outfilefd, fd_error, new_argv, 0, current_dir); 561 pid = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
571 child_errno = errno; 562
572 563 if (pid < 0)
573 emacs_close (outfilefd); 564 {
574 if (fd_error != outfilefd) 565 child_errno = errno;
575 emacs_close (fd_error); 566 unbind_to (count, Qnil);
576 if (pid < 0) 567 synchronize_system_messages_locale ();
577 { 568 return
578 synchronize_system_messages_locale (); 569 code_convert_string_norecord (build_string (strerror (child_errno)),
579 return 570 Vlocale_coding_system, 0);
580 code_convert_string_norecord (build_string (strerror (child_errno)), 571 }
581 Vlocale_coding_system, 0); 572 status = pid;
582 } 573
583 status = pid; 574 for (i = 0; i < CALLPROC_FDS; i++)
584 fd1 = -1; /* No harm in closing that one! */ 575 if (0 <= callproc_fd[i])
585 if (tempfile)
586 { 576 {
587 /* Since CRLF is converted to LF within `decode_coding', we 577 emacs_close (callproc_fd[i]);
588 can always open a file with binary mode. */ 578 callproc_fd[i] = -1;
589 fd0 = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
590 if (fd0 < 0)
591 {
592 int open_errno = errno;
593 unlink (tempfile);
594 emacs_close (filefd);
595 report_file_errno ("Cannot re-open temporary file",
596 build_string (tempfile), open_errno);
597 }
598 } 579 }
599 else 580 emacs_close (filefd);
600 fd0 = -1; /* We are not going to read from tempfile. */ 581 clear_unwind_protect (count - 1);
582
583 if (tempfile)
584 {
585 /* Since CRLF is converted to LF within `decode_coding', we
586 can always open a file with binary mode. */
587 callproc_fd[CALLPROC_PIPEREAD] = emacs_open (tempfile,
588 O_RDONLY | O_BINARY, 0);
589 if (callproc_fd[CALLPROC_PIPEREAD] < 0)
590 {
591 int open_errno = errno;
592 report_file_errno ("Cannot re-open temporary file",
593 build_string (tempfile), open_errno);
594 }
595 }
596
601#endif /* MSDOS */ 597#endif /* MSDOS */
602 598
603 /* Do the unwind-protect now, even though the pid is not known, so 599 /* Do the unwind-protect now, even though the pid is not known, so
604 that no storage allocation is done in the critical section. 600 that no storage allocation is done in the critical section.
605 The actual PID will be filled in during the critical section. */ 601 The actual PID will be filled in during the critical section. */
606 synch_process_pid = 0; 602 record_unwind_protect (call_process_cleanup, Fcurrent_buffer ());
607 synch_process_fd = fd0;
608 603
609#ifdef MSDOS 604#ifndef MSDOS
610 /* MSDOS needs different cleanup information. */
611 record_unwind_protect (call_process_cleanup,
612 Fcons (Fcurrent_buffer (),
613 build_string (tempfile ? tempfile : "")));
614#else
615 record_unwind_protect (call_process_cleanup, Fcurrent_buffer ());
616 605
617 block_input (); 606 block_input ();
618 block_child_signal (); 607 block_child_signal ();
619 608
620#ifdef WINDOWSNT 609#ifdef WINDOWSNT
621 pid = child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir); 610 pid = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
622 /* We need to record the input file of this child, for when we are
623 called from call-process-region to create an async subprocess.
624 That's because call-process-region's unwind procedure will
625 attempt to delete the temporary input file, which will fail
626 because that file is still in use. Recording it with the child
627 will allow us to delete the file when the subprocess exits.
628 The second part of this is in delete_temp_file, q.v. */
629 if (pid > 0 && INTEGERP (buffer) && nargs >= 2 && !NILP (args[1]))
630 record_infile (pid, xstrdup (SSDATA (infile)));
631#else /* not WINDOWSNT */ 611#else /* not WINDOWSNT */
632 612
633 /* vfork, and prevent local vars from being clobbered by the vfork. */ 613 /* vfork, and prevent local vars from being clobbered by the vfork. */
634 { 614 {
635 Lisp_Object volatile buffer_volatile = buffer; 615 Lisp_Object volatile buffer_volatile = buffer;
636 Lisp_Object volatile coding_systems_volatile = coding_systems; 616 Lisp_Object volatile coding_systems_volatile = coding_systems;
637 Lisp_Object volatile current_dir_volatile = current_dir; 617 Lisp_Object volatile current_dir_volatile = current_dir;
638 bool volatile display_p_volatile = display_p; 618 bool volatile display_p_volatile = display_p;
639 bool volatile output_to_buffer_volatile = output_to_buffer; 619 bool volatile sa_must_free_volatile = sa_must_free;
640 bool volatile sa_must_free_volatile = sa_must_free; 620 int volatile fd_error_volatile = fd_error;
641 int volatile fd1_volatile = fd1; 621 int volatile filefd_volatile = filefd;
642 int volatile fd_error_volatile = fd_error; 622 ptrdiff_t volatile count_volatile = count;
643 int volatile fd_output_volatile = fd_output; 623 ptrdiff_t volatile sa_count_volatile = sa_count;
644 int volatile filefd_volatile = filefd; 624 char **volatile new_argv_volatile = new_argv;
645 ptrdiff_t volatile count_volatile = count; 625 int volatile callproc_fd_volatile[CALLPROC_FDS];
646 ptrdiff_t volatile sa_count_volatile = sa_count; 626 for (i = 0; i < CALLPROC_FDS; i++)
647 char **volatile new_argv_volatile = new_argv; 627 callproc_fd_volatile[i] = callproc_fd[i];
648 628
649 pid = vfork (); 629 pid = vfork ();
650 child_errno = errno; 630
651 631 buffer = buffer_volatile;
652 buffer = buffer_volatile; 632 coding_systems = coding_systems_volatile;
653 coding_systems = coding_systems_volatile; 633 current_dir = current_dir_volatile;
654 current_dir = current_dir_volatile; 634 display_p = display_p_volatile;
655 display_p = display_p_volatile; 635 sa_must_free = sa_must_free_volatile;
656 output_to_buffer = output_to_buffer_volatile; 636 fd_error = fd_error_volatile;
657 sa_must_free = sa_must_free_volatile; 637 filefd = filefd_volatile;
658 fd1 = fd1_volatile; 638 count = count_volatile;
659 fd_error = fd_error_volatile; 639 sa_count = sa_count_volatile;
660 fd_output = fd_output_volatile; 640 new_argv = new_argv_volatile;
661 filefd = filefd_volatile; 641
662 count = count_volatile; 642 for (i = 0; i < CALLPROC_FDS; i++)
663 sa_count = sa_count_volatile; 643 callproc_fd[i] = callproc_fd_volatile[i];
664 new_argv = new_argv_volatile; 644 fd_output = callproc_fd[CALLPROC_STDOUT];
665 645 }
666 fd0 = synch_process_fd;
667 }
668
669 if (pid == 0)
670 {
671 unblock_child_signal ();
672 646
673 if (fd0 >= 0) 647 if (pid == 0)
674 emacs_close (fd0); 648 {
649 unblock_child_signal ();
675 650
676 setsid (); 651 setsid ();
677 652
678 /* Emacs ignores SIGPIPE, but the child should not. */ 653 /* Emacs ignores SIGPIPE, but the child should not. */
679 signal (SIGPIPE, SIG_DFL); 654 signal (SIGPIPE, SIG_DFL);
680 655
681 child_setup (filefd, fd1, fd_error, new_argv, 0, current_dir); 656 child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir);
682 } 657 }
683 658
684#endif /* not WINDOWSNT */ 659#endif /* not WINDOWSNT */
685 660
686 child_errno = errno; 661 child_errno = errno;
687 662
688 if (pid > 0) 663 if (pid > 0)
689 { 664 synch_process_pid = pid;
690 if (INTEGERP (buffer))
691 record_deleted_pid (pid);
692 else
693 synch_process_pid = pid;
694 }
695 665
696 unblock_child_signal (); 666 unblock_child_signal ();
697 unblock_input (); 667 unblock_input ();
698 668
699 /* The MSDOS case did this already. */
700 if (fd_error >= 0)
701 emacs_close (fd_error);
702#endif /* not MSDOS */ 669#endif /* not MSDOS */
703 670
704 /* Close most of our file descriptors, but not fd0
705 since we will use that to read input from. */
706 emacs_close (filefd);
707 if (fd_output >= 0)
708 emacs_close (fd_output);
709 if (fd1 >= 0 && fd1 != fd_error)
710 emacs_close (fd1);
711 }
712
713 if (pid < 0) 671 if (pid < 0)
714 report_file_errno ("Doing vfork", Qnil, child_errno); 672 report_file_errno ("Doing vfork", Qnil, child_errno);
715 673
674 /* Close our file descriptors, except for callproc_fd[CALLPROC_PIPEREAD]
675 since we will use that to read input from. */
676 for (i = 0; i < CALLPROC_FDS; i++)
677 if (i != CALLPROC_PIPEREAD && 0 <= callproc_fd[i])
678 {
679 emacs_close (callproc_fd[i]);
680 callproc_fd[i] = -1;
681 }
682 emacs_close (filefd);
683 clear_unwind_protect (count - 1);
684
716 if (INTEGERP (buffer)) 685 if (INTEGERP (buffer))
717 return unbind_to (count, Qnil); 686 return unbind_to (count, Qnil);
718 687
719 if (BUFFERP (buffer)) 688 if (BUFFERP (buffer))
720 Fset_buffer (buffer); 689 Fset_buffer (buffer);
721 690
722 if (NILP (buffer)) 691 fd0 = callproc_fd[CALLPROC_PIPEREAD];
723 { 692
724 /* If BUFFER is nil, we must read process output once and then 693 if (0 <= fd0)
725 discard it, so setup coding system but with nil. */
726 setup_coding_system (Qnil, &process_coding);
727 process_coding.dst_multibyte = 0;
728 }
729 else
730 { 694 {
731 Lisp_Object val, *args2; 695 Lisp_Object val, *args2;
732 696
@@ -762,13 +726,13 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
762 setup_coding_system (val, &process_coding); 726 setup_coding_system (val, &process_coding);
763 process_coding.dst_multibyte 727 process_coding.dst_multibyte
764 = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); 728 = ! NILP (BVAR (current_buffer, enable_multibyte_characters));
729 process_coding.src_multibyte = 0;
765 } 730 }
766 process_coding.src_multibyte = 0;
767 731
768 immediate_quit = 1; 732 immediate_quit = 1;
769 QUIT; 733 QUIT;
770 734
771 if (output_to_buffer) 735 if (0 <= fd0)
772 { 736 {
773 enum { CALLPROC_BUFFER_SIZE_MIN = 16 * 1024 }; 737 enum { CALLPROC_BUFFER_SIZE_MIN = 16 * 1024 };
774 enum { CALLPROC_BUFFER_SIZE_MAX = 4 * CALLPROC_BUFFER_SIZE_MIN }; 738 enum { CALLPROC_BUFFER_SIZE_MAX = 4 * CALLPROC_BUFFER_SIZE_MIN };
@@ -779,9 +743,8 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
779 EMACS_INT total_read = 0; 743 EMACS_INT total_read = 0;
780 int carryover = 0; 744 int carryover = 0;
781 bool display_on_the_fly = display_p; 745 bool display_on_the_fly = display_p;
782 struct coding_system saved_coding; 746 struct coding_system saved_coding = process_coding;
783 747
784 saved_coding = process_coding;
785 while (1) 748 while (1)
786 { 749 {
787 /* Repeatedly read until we've filled as much as possible 750 /* Repeatedly read until we've filled as much as possible
@@ -812,58 +775,54 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
812 /* Now NREAD is the total amount of data in the buffer. */ 775 /* Now NREAD is the total amount of data in the buffer. */
813 immediate_quit = 0; 776 immediate_quit = 0;
814 777
815 if (!NILP (buffer)) 778 if (NILP (BVAR (current_buffer, enable_multibyte_characters))
816 { 779 && ! CODING_MAY_REQUIRE_DECODING (&process_coding))
817 if (NILP (BVAR (current_buffer, enable_multibyte_characters)) 780 insert_1_both (buf, nread, nread, 0, 1, 0);
818 && ! CODING_MAY_REQUIRE_DECODING (&process_coding)) 781 else
819 insert_1_both (buf, nread, nread, 0, 1, 0); 782 { /* We have to decode the input. */
820 else 783 Lisp_Object curbuf;
821 { /* We have to decode the input. */ 784 ptrdiff_t count1 = SPECPDL_INDEX ();
822 Lisp_Object curbuf; 785
823 ptrdiff_t count1 = SPECPDL_INDEX (); 786 XSETBUFFER (curbuf, current_buffer);
824 787 /* We cannot allow after-change-functions be run
825 XSETBUFFER (curbuf, current_buffer); 788 during decoding, because that might modify the
826 /* We cannot allow after-change-functions be run 789 buffer, while we rely on process_coding.produced to
827 during decoding, because that might modify the 790 faithfully reflect inserted text until we
828 buffer, while we rely on process_coding.produced to 791 TEMP_SET_PT_BOTH below. */
829 faithfully reflect inserted text until we 792 specbind (Qinhibit_modification_hooks, Qt);
830 TEMP_SET_PT_BOTH below. */ 793 decode_coding_c_string (&process_coding,
831 specbind (Qinhibit_modification_hooks, Qt); 794 (unsigned char *) buf, nread, curbuf);
832 decode_coding_c_string (&process_coding, 795 unbind_to (count1, Qnil);
833 (unsigned char *) buf, nread, curbuf); 796 if (display_on_the_fly
834 unbind_to (count1, Qnil); 797 && CODING_REQUIRE_DETECTION (&saved_coding)
835 if (display_on_the_fly 798 && ! CODING_REQUIRE_DETECTION (&process_coding))
836 && CODING_REQUIRE_DETECTION (&saved_coding) 799 {
837 && ! CODING_REQUIRE_DETECTION (&process_coding)) 800 /* We have detected some coding system, but the
838 { 801 detection may have been via insufficient data.
839 /* We have detected some coding system. But, 802 So give up displaying on the fly. */
840 there's a possibility that the detection was 803 if (process_coding.produced > 0)
841 done by insufficient data. So, we give up 804 del_range_2 (process_coding.dst_pos,
842 displaying on the fly. */ 805 process_coding.dst_pos_byte,
843 if (process_coding.produced > 0) 806 (process_coding.dst_pos
844 del_range_2 (process_coding.dst_pos, 807 + process_coding.produced_char),
845 process_coding.dst_pos_byte, 808 (process_coding.dst_pos_byte
846 process_coding.dst_pos 809 + process_coding.produced),
847 + process_coding.produced_char, 810 0);
848 process_coding.dst_pos_byte 811 display_on_the_fly = 0;
849 + process_coding.produced, 0); 812 process_coding = saved_coding;
850 display_on_the_fly = 0; 813 carryover = nread;
851 process_coding = saved_coding; 814 /* Make the above condition always fail in the future. */
852 carryover = nread; 815 saved_coding.common_flags
853 /* This is to make the above condition always 816 &= ~CODING_REQUIRE_DETECTION_MASK;
854 fails in the future. */ 817 continue;
855 saved_coding.common_flags
856 &= ~CODING_REQUIRE_DETECTION_MASK;
857 continue;
858 }
859
860 TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
861 PT_BYTE + process_coding.produced);
862 carryover = process_coding.carryover_bytes;
863 if (carryover > 0)
864 memcpy (buf, process_coding.carryover,
865 process_coding.carryover_bytes);
866 } 818 }
819
820 TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
821 PT_BYTE + process_coding.produced);
822 carryover = process_coding.carryover_bytes;
823 if (carryover > 0)
824 memcpy (buf, process_coding.carryover,
825 process_coding.carryover_bytes);
867 } 826 }
868 827
869 if (process_coding.mode & CODING_MODE_LAST_BLOCK) 828 if (process_coding.mode & CODING_MODE_LAST_BLOCK)
@@ -882,7 +841,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
882 first = 0; 841 first = 0;
883 redisplay_preserve_echo_area (1); 842 redisplay_preserve_echo_area (1);
884 /* This variable might have been set to 0 for code 843 /* This variable might have been set to 0 for code
885 detection. In that case, we set it back to 1 because 844 detection. In that case, set it back to 1 because
886 we should have already detected a coding system. */ 845 we should have already detected a coding system. */
887 display_on_the_fly = 1; 846 display_on_the_fly = 1;
888 } 847 }
@@ -901,7 +860,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
901 860
902#ifndef MSDOS 861#ifndef MSDOS
903 /* Wait for it to terminate, unless it already has. */ 862 /* Wait for it to terminate, unless it already has. */
904 wait_for_termination (pid, &status, !output_to_buffer); 863 wait_for_termination (pid, &status, fd0 < 0);
905#endif 864#endif
906 865
907 immediate_quit = 0; 866 immediate_quit = 0;
@@ -931,37 +890,18 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
931 return make_number (WEXITSTATUS (status)); 890 return make_number (WEXITSTATUS (status));
932} 891}
933 892
934static void
935delete_temp_file (Lisp_Object name)
936{
937 /* Suppress jka-compr handling, etc. */
938 ptrdiff_t count = SPECPDL_INDEX ();
939 specbind (intern ("file-name-handler-alist"), Qnil);
940#ifdef WINDOWSNT
941 /* If this is called when the subprocess didn't exit yet, the
942 attempt to delete its input file will fail. In that case, we
943 schedule the file for deletion when the subprocess exits. This
944 is the 2nd part of handling this situation; see the call to
945 record_infile in call-process above, for the first part. */
946 if (!internal_delete_file (name))
947 {
948 Lisp_Object encoded_file = ENCODE_FILE (name);
949
950 record_pending_deletion (SSDATA (encoded_file));
951 }
952#else
953 internal_delete_file (name);
954#endif
955 unbind_to (count, Qnil);
956}
957
958/* Create a temporary file suitable for storing the input data of 893/* Create a temporary file suitable for storing the input data of
959 call-process-region. NARGS and ARGS are the same as for 894 call-process-region. NARGS and ARGS are the same as for
960 call-process-region. */ 895 call-process-region. Store into *FILENAME_STRING_PTR a Lisp string
896 naming the file, and return a file descriptor for reading.
897 Unwind-protect the file, so that the file descriptor will be closed
898 and the file removed when the caller unwinds the specpdl stack. */
961 899
962static Lisp_Object 900static int
963create_temp_file (ptrdiff_t nargs, Lisp_Object *args) 901create_temp_file (ptrdiff_t nargs, Lisp_Object *args,
902 Lisp_Object *filename_string_ptr)
964{ 903{
904 int fd;
965 struct gcpro gcpro1; 905 struct gcpro gcpro1;
966 Lisp_Object filename_string; 906 Lisp_Object filename_string;
967 Lisp_Object val, start, end; 907 Lisp_Object val, start, end;
@@ -988,6 +928,7 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args)
988 { 928 {
989 Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir); 929 Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
990 char *tempfile; 930 char *tempfile;
931 ptrdiff_t count;
991 932
992#ifdef WINDOWSNT 933#ifdef WINDOWSNT
993 /* Cannot use the result of Fexpand_file_name, because it 934 /* Cannot use the result of Fexpand_file_name, because it
@@ -1008,26 +949,14 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args)
1008 GCPRO1 (filename_string); 949 GCPRO1 (filename_string);
1009 tempfile = SSDATA (filename_string); 950 tempfile = SSDATA (filename_string);
1010 951
1011 { 952 count = SPECPDL_INDEX ();
1012 int fd; 953 record_unwind_protect_nothing ();
1013 954 fd = mkostemp (tempfile, O_CLOEXEC);
1014#ifdef HAVE_MKOSTEMP 955 if (fd < 0)
1015 fd = mkostemp (tempfile, O_CLOEXEC); 956 report_file_error ("Failed to open temporary file using pattern",
1016#elif defined HAVE_MKSTEMP 957 pattern);
1017 fd = mkstemp (tempfile); 958 set_unwind_protect (count, delete_temp_file, filename_string);
1018#else 959 record_unwind_protect_int (close_file_unwind, fd);
1019 errno = EEXIST;
1020 mktemp (tempfile);
1021 /* INT_MAX denotes success, because close (INT_MAX) does nothing. */
1022 fd = *tempfile ? INT_MAX : -1;
1023#endif
1024 if (fd < 0)
1025 report_file_error ("Failed to open temporary file using pattern",
1026 pattern);
1027 emacs_close (fd);
1028 }
1029
1030 record_unwind_protect (delete_temp_file, filename_string);
1031 } 960 }
1032 961
1033 start = args[0]; 962 start = args[0];
@@ -1058,15 +987,20 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args)
1058 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we 987 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
1059 happen to get a ".Z" suffix. */ 988 happen to get a ".Z" suffix. */
1060 specbind (intern ("file-name-handler-alist"), Qnil); 989 specbind (intern ("file-name-handler-alist"), Qnil);
1061 Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil); 990 write_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil, fd);
1062 991
1063 unbind_to (count1, Qnil); 992 unbind_to (count1, Qnil);
1064 } 993 }
1065 994
995 if (lseek (fd, 0, SEEK_SET) < 0)
996 report_file_error ("Setting file position", filename_string);
997
1066 /* Note that Fcall_process takes care of binding 998 /* Note that Fcall_process takes care of binding
1067 coding-system-for-read. */ 999 coding-system-for-read. */
1068 1000
1069 RETURN_UNGCPRO (filename_string); 1001 *filename_string_ptr = filename_string;
1002 UNGCPRO;
1003 return fd;
1070} 1004}
1071 1005
1072DEFUN ("call-process-region", Fcall_process_region, Scall_process_region, 1006DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
@@ -1096,12 +1030,13 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
1096usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */) 1030usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
1097 (ptrdiff_t nargs, Lisp_Object *args) 1031 (ptrdiff_t nargs, Lisp_Object *args)
1098{ 1032{
1099 struct gcpro gcpro1; 1033 struct gcpro gcpro1, gcpro2;
1100 Lisp_Object infile; 1034 Lisp_Object infile, val;
1101 ptrdiff_t count = SPECPDL_INDEX (); 1035 ptrdiff_t count = SPECPDL_INDEX ();
1102 Lisp_Object start = args[0]; 1036 Lisp_Object start = args[0];
1103 Lisp_Object end = args[1]; 1037 Lisp_Object end = args[1];
1104 bool empty_input; 1038 bool empty_input;
1039 int fd;
1105 1040
1106 if (STRINGP (start)) 1041 if (STRINGP (start))
1107 empty_input = SCHARS (start) == 0; 1042 empty_input = SCHARS (start) == 0;
@@ -1115,8 +1050,19 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1115 empty_input = XINT (start) == XINT (end); 1050 empty_input = XINT (start) == XINT (end);
1116 } 1051 }
1117 1052
1118 infile = empty_input ? Qnil : create_temp_file (nargs, args); 1053 if (!empty_input)
1119 GCPRO1 (infile); 1054 fd = create_temp_file (nargs, args, &infile);
1055 else
1056 {
1057 infile = Qnil;
1058 fd = emacs_open (NULL_DEVICE, O_RDONLY, 0);
1059 if (fd < 0)
1060 report_file_error ("Opening null device", Qnil);
1061 record_unwind_protect_int (close_file_unwind, fd);
1062 }
1063
1064 val = infile;
1065 GCPRO2 (infile, val);
1120 1066
1121 if (nargs > 3 && !NILP (args[3])) 1067 if (nargs > 3 && !NILP (args[3]))
1122 Fdelete_region (start, end); 1068 Fdelete_region (start, end);
@@ -1133,7 +1079,17 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
1133 } 1079 }
1134 args[1] = infile; 1080 args[1] = infile;
1135 1081
1136 RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args))); 1082 val = call_process (nargs, args, fd);
1083
1084 if (!empty_input && 4 < nargs
1085 && (INTEGERP (CONSP (args[4]) ? XCAR (args[4]) : args[4])))
1086 {
1087 record_deleted_pid (synch_process_pid, infile);
1088 synch_process_pid = 0;
1089 clear_unwind_protect (count);
1090 }
1091
1092 RETURN_UNGCPRO (unbind_to (count, val));
1137} 1093}
1138 1094
1139#ifndef WINDOWSNT 1095#ifndef WINDOWSNT
@@ -1694,6 +1650,11 @@ syms_of_callproc (void)
1694#endif 1650#endif
1695 staticpro (&Vtemp_file_name_pattern); 1651 staticpro (&Vtemp_file_name_pattern);
1696 1652
1653#ifdef MSDOS
1654 synch_process_tempfile = make_number (0);
1655 staticpro (&synch_process_tempfile);
1656#endif
1657
1697 DEFVAR_LISP ("shell-file-name", Vshell_file_name, 1658 DEFVAR_LISP ("shell-file-name", Vshell_file_name,
1698 doc: /* File name to load inferior shells from. 1659 doc: /* File name to load inferior shells from.
1699Initialized from the SHELL environment variable, or to a system-dependent 1660Initialized from the SHELL environment variable, or to a system-dependent
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 7f5b99752fa..5a40790f87f 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -214,7 +214,7 @@ casify_region (enum case_action flag, Lisp_Object b, Lisp_Object e)
214 validate_region (&b, &e); 214 validate_region (&b, &e);
215 start = XFASTINT (b); 215 start = XFASTINT (b);
216 end = XFASTINT (e); 216 end = XFASTINT (e);
217 modify_region_1 (start, end, false); 217 modify_text (start, end);
218 record_change (start, end - start); 218 record_change (start, end - start);
219 start_byte = CHAR_TO_BYTE (start); 219 start_byte = CHAR_TO_BYTE (start);
220 220
diff --git a/src/cmds.c b/src/cmds.c
index 3ebad50184a..ce91877f85e 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -86,6 +86,7 @@ DEFUN ("forward-char", Fforward_char, Sforward_char, 0, 1, "^p",
86 doc: /* Move point N characters forward (backward if N is negative). 86 doc: /* Move point N characters forward (backward if N is negative).
87On reaching end or beginning of buffer, stop and signal error. 87On reaching end or beginning of buffer, stop and signal error.
88Interactively, N is the numeric prefix argument. 88Interactively, N is the numeric prefix argument.
89If N is omitted or nil, move point 1 character forward.
89 90
90Depending on the bidirectional context, the movement may be to the 91Depending on the bidirectional context, the movement may be to the
91right or to the left on the screen. This is in contrast with 92right or to the left on the screen. This is in contrast with
@@ -99,6 +100,7 @@ DEFUN ("backward-char", Fbackward_char, Sbackward_char, 0, 1, "^p",
99 doc: /* Move point N characters backward (forward if N is negative). 100 doc: /* Move point N characters backward (forward if N is negative).
100On attempt to pass beginning or end of buffer, stop and signal error. 101On attempt to pass beginning or end of buffer, stop and signal error.
101Interactively, N is the numeric prefix argument. 102Interactively, N is the numeric prefix argument.
103If N is omitted or nil, move point 1 character backward.
102 104
103Depending on the bidirectional context, the movement may be to the 105Depending on the bidirectional context, the movement may be to the
104right or to the left on the screen. This is in contrast with 106right or to the left on the screen. This is in contrast with
diff --git a/src/coding.c b/src/coding.c
index 0cdd8f9cd9e..5b637627763 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7497,7 +7497,7 @@ handle_composition_annotation (ptrdiff_t pos, ptrdiff_t limit,
7497 /* We found a composition. Store the corresponding 7497 /* We found a composition. Store the corresponding
7498 annotation data in BUF. */ 7498 annotation data in BUF. */
7499 int *head = buf; 7499 int *head = buf;
7500 enum composition_method method = COMPOSITION_METHOD (prop); 7500 enum composition_method method = composition_method (prop);
7501 int nchars = COMPOSITION_LENGTH (prop); 7501 int nchars = COMPOSITION_LENGTH (prop);
7502 7502
7503 ADD_COMPOSITION_DATA (buf, nchars, 0, method); 7503 ADD_COMPOSITION_DATA (buf, nchars, 0, method);
diff --git a/src/composite.c b/src/composite.c
index 99b5da22af5..28942fe4f74 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -160,10 +160,6 @@ static Lisp_Object Qauto_composition_function;
160 auto-compositions. */ 160 auto-compositions. */
161#define MAX_AUTO_COMPOSITION_LOOKBACK 3 161#define MAX_AUTO_COMPOSITION_LOOKBACK 3
162 162
163/* Temporary variable used in macros COMPOSITION_XXX. */
164Lisp_Object composition_temp;
165
166
167/* Return COMPOSITION-ID of a composition at buffer position 163/* Return COMPOSITION-ID of a composition at buffer position
168 CHARPOS/BYTEPOS and length NCHARS. The `composition' property of 164 CHARPOS/BYTEPOS and length NCHARS. The `composition' property of
169 the sequence is PROP. STRING, if non-nil, is a string that 165 the sequence is PROP. STRING, if non-nil, is a string that
@@ -478,11 +474,11 @@ run_composition_function (ptrdiff_t from, ptrdiff_t to, Lisp_Object prop)
478 valid too. */ 474 valid too. */
479 if (from > BEGV 475 if (from > BEGV
480 && find_composition (from - 1, -1, &start, &end, &prop, Qnil) 476 && find_composition (from - 1, -1, &start, &end, &prop, Qnil)
481 && !COMPOSITION_VALID_P (start, end, prop)) 477 && !composition_valid_p (start, end, prop))
482 from = start; 478 from = start;
483 if (to < ZV 479 if (to < ZV
484 && find_composition (to, -1, &start, &end, &prop, Qnil) 480 && find_composition (to, -1, &start, &end, &prop, Qnil)
485 && !COMPOSITION_VALID_P (start, end, prop)) 481 && !composition_valid_p (start, end, prop))
486 to = end; 482 to = end;
487 if (!NILP (Ffboundp (func))) 483 if (!NILP (Ffboundp (func)))
488 call2 (func, make_number (from), make_number (to)); 484 call2 (func, make_number (from), make_number (to));
@@ -524,7 +520,7 @@ update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
524 latter to the copy of it. */ 520 latter to the copy of it. */
525 if (from > BEGV 521 if (from > BEGV
526 && find_composition (from - 1, -1, &start, &end, &prop, Qnil) 522 && find_composition (from - 1, -1, &start, &end, &prop, Qnil)
527 && COMPOSITION_VALID_P (start, end, prop)) 523 && composition_valid_p (start, end, prop))
528 { 524 {
529 min_pos = start; 525 min_pos = start;
530 if (end > to) 526 if (end > to)
@@ -538,7 +534,7 @@ update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
538 } 534 }
539 else if (from < ZV 535 else if (from < ZV
540 && find_composition (from, -1, &start, &from, &prop, Qnil) 536 && find_composition (from, -1, &start, &from, &prop, Qnil)
541 && COMPOSITION_VALID_P (start, from, prop)) 537 && composition_valid_p (start, from, prop))
542 { 538 {
543 if (from > to) 539 if (from > to)
544 max_pos = from; 540 max_pos = from;
@@ -553,7 +549,7 @@ update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
553 (to - 1). */ 549 (to - 1). */
554 while (from < to - 1 550 while (from < to - 1
555 && find_composition (from, to, &start, &from, &prop, Qnil) 551 && find_composition (from, to, &start, &from, &prop, Qnil)
556 && COMPOSITION_VALID_P (start, from, prop) 552 && composition_valid_p (start, from, prop)
557 && from < to - 1) 553 && from < to - 1)
558 run_composition_function (start, from, prop); 554 run_composition_function (start, from, prop);
559 } 555 }
@@ -562,7 +558,7 @@ update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
562 { 558 {
563 if (from < to 559 if (from < to
564 && find_composition (to - 1, -1, &start, &end, &prop, Qnil) 560 && find_composition (to - 1, -1, &start, &end, &prop, Qnil)
565 && COMPOSITION_VALID_P (start, end, prop)) 561 && composition_valid_p (start, end, prop))
566 { 562 {
567 /* TO should be also at composition boundary. But, 563 /* TO should be also at composition boundary. But,
568 insertion or deletion will make two compositions adjacent 564 insertion or deletion will make two compositions adjacent
@@ -580,7 +576,7 @@ update_compositions (ptrdiff_t from, ptrdiff_t to, int check_mask)
580 } 576 }
581 else if (to < ZV 577 else if (to < ZV
582 && find_composition (to, -1, &start, &end, &prop, Qnil) 578 && find_composition (to, -1, &start, &end, &prop, Qnil)
583 && COMPOSITION_VALID_P (start, end, prop)) 579 && composition_valid_p (start, end, prop))
584 { 580 {
585 run_composition_function (start, end, prop); 581 run_composition_function (start, end, prop);
586 max_pos = end; 582 max_pos = end;
@@ -901,7 +897,7 @@ autocmp_chars (Lisp_Object rule, ptrdiff_t charpos, ptrdiff_t bytepos,
901 Lisp_Object string) 897 Lisp_Object string)
902{ 898{
903 ptrdiff_t count = SPECPDL_INDEX (); 899 ptrdiff_t count = SPECPDL_INDEX ();
904 FRAME_PTR f = XFRAME (win->frame); 900 struct frame *f = XFRAME (win->frame);
905 Lisp_Object pos = make_number (charpos); 901 Lisp_Object pos = make_number (charpos);
906 ptrdiff_t to; 902 ptrdiff_t to;
907 ptrdiff_t pt = PT, pt_byte = PT_BYTE; 903 ptrdiff_t pt = PT, pt_byte = PT_BYTE;
@@ -1012,7 +1008,7 @@ composition_compute_stop_pos (struct composition_it *cmp_it, ptrdiff_t charpos,
1012 if (charpos < endpos 1008 if (charpos < endpos
1013 && find_composition (charpos, endpos, &start, &end, &prop, string) 1009 && find_composition (charpos, endpos, &start, &end, &prop, string)
1014 && start >= charpos 1010 && start >= charpos
1015 && COMPOSITION_VALID_P (start, end, prop)) 1011 && composition_valid_p (start, end, prop))
1016 { 1012 {
1017 cmp_it->stop_pos = endpos = start; 1013 cmp_it->stop_pos = endpos = start;
1018 cmp_it->ch = -1; 1014 cmp_it->ch = -1;
@@ -1672,7 +1668,7 @@ composition_adjust_point (ptrdiff_t last_pt, ptrdiff_t new_pt)
1672 1668
1673 /* At first check the static composition. */ 1669 /* At first check the static composition. */
1674 if (get_property_and_range (new_pt, Qcomposition, &val, &beg, &end, Qnil) 1670 if (get_property_and_range (new_pt, Qcomposition, &val, &beg, &end, Qnil)
1675 && COMPOSITION_VALID_P (beg, end, val)) 1671 && composition_valid_p (beg, end, val))
1676 { 1672 {
1677 if (beg < new_pt /* && end > new_pt <- It's always the case. */ 1673 if (beg < new_pt /* && end > new_pt <- It's always the case. */
1678 && (last_pt <= beg || last_pt >= end)) 1674 && (last_pt <= beg || last_pt >= end))
@@ -1872,12 +1868,12 @@ See `find-composition' for more details. */)
1872 && (e <= XINT (pos) ? e > end : s < start)) 1868 && (e <= XINT (pos) ? e > end : s < start))
1873 return list3 (make_number (s), make_number (e), gstring); 1869 return list3 (make_number (s), make_number (e), gstring);
1874 } 1870 }
1875 if (!COMPOSITION_VALID_P (start, end, prop)) 1871 if (!composition_valid_p (start, end, prop))
1876 return list3 (make_number (start), make_number (end), Qnil); 1872 return list3 (make_number (start), make_number (end), Qnil);
1877 if (NILP (detail_p)) 1873 if (NILP (detail_p))
1878 return list3 (make_number (start), make_number (end), Qt); 1874 return list3 (make_number (start), make_number (end), Qt);
1879 1875
1880 if (COMPOSITION_REGISTERD_P (prop)) 1876 if (composition_registered_p (prop))
1881 id = COMPOSITION_ID (prop); 1877 id = COMPOSITION_ID (prop);
1882 else 1878 else
1883 { 1879 {
@@ -1890,7 +1886,7 @@ See `find-composition' for more details. */)
1890 if (id >= 0) 1886 if (id >= 0)
1891 { 1887 {
1892 Lisp_Object components, relative_p, mod_func; 1888 Lisp_Object components, relative_p, mod_func;
1893 enum composition_method method = COMPOSITION_METHOD (prop); 1889 enum composition_method method = composition_method (prop);
1894 int width = composition_table[id]->width; 1890 int width = composition_table[id]->width;
1895 1891
1896 components = Fcopy_sequence (COMPOSITION_COMPONENTS (prop)); 1892 components = Fcopy_sequence (COMPOSITION_COMPONENTS (prop));
diff --git a/src/composite.h b/src/composite.h
index 603291044bc..53665b36bd1 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -49,69 +49,41 @@ enum composition_method {
49/* Maximum number of components a single composition can have. */ 49/* Maximum number of components a single composition can have. */
50#define MAX_COMPOSITION_COMPONENTS 16 50#define MAX_COMPOSITION_COMPONENTS 16
51 51
52/* These macros access information about a composition that 52/* These operations access information about a composition that
53 has `composition' property PROP. PROP is: 53 has `composition' property PROP. PROP is:
54 ((LENGTH . COMPONENTS) . MODIFICATION-FUNC) 54 ((LENGTH . COMPONENTS) . MODIFICATION-FUNC)
55 or 55 or
56 (COMPOSITION-ID . (LENGTH COMPONENTS . MODIFICATION-FUNC)) 56 (COMPOSITION-ID . (LENGTH COMPONENTS . MODIFICATION-FUNC))
57 They don't check validity of PROP. */ 57 They don't check validity of PROP. */
58 58
59/* Temporary variable used only in the following macros. */ 59/* Return true if PROP is already registered. */
60extern Lisp_Object composition_temp; 60COMPOSITE_INLINE bool
61 61composition_registered_p (Lisp_Object prop)
62/* Return 1 if the composition is already registered. */ 62{
63#define COMPOSITION_REGISTERD_P(prop) INTEGERP (XCAR (prop)) 63 return INTEGERP (XCAR (prop));
64}
64 65
65/* Return ID number of the already registered composition. */ 66/* Return ID number of the already registered composition. */
66#define COMPOSITION_ID(prop) XINT (XCAR (prop)) 67#define COMPOSITION_ID(prop) XINT (XCAR (prop))
67 68
68/* Return length of the composition. */ 69/* Return length of the composition. */
69#define COMPOSITION_LENGTH(prop) \ 70#define COMPOSITION_LENGTH(prop) \
70 (COMPOSITION_REGISTERD_P (prop) \ 71 (composition_registered_p (prop) \
71 ? XINT (XCAR (XCDR (prop))) \ 72 ? XINT (XCAR (XCDR (prop))) \
72 : XINT (XCAR (XCAR (prop)))) 73 : XINT (XCAR (XCAR (prop))))
73 74
74/* Return components of the composition. */ 75/* Return components of the composition. */
75#define COMPOSITION_COMPONENTS(prop) \ 76#define COMPOSITION_COMPONENTS(prop) \
76 (COMPOSITION_REGISTERD_P (prop) \ 77 (composition_registered_p (prop) \
77 ? XCAR (XCDR (XCDR (prop))) \ 78 ? XCAR (XCDR (XCDR (prop))) \
78 : XCDR (XCAR (prop))) 79 : XCDR (XCAR (prop)))
79 80
80/* Return modification function of the composition. */ 81/* Return modification function of the composition. */
81#define COMPOSITION_MODIFICATION_FUNC(prop) \ 82#define COMPOSITION_MODIFICATION_FUNC(prop) \
82 (COMPOSITION_REGISTERD_P (prop) \ 83 (composition_registered_p (prop) \
83 ? XCDR (XCDR (XCDR (prop))) \ 84 ? XCDR (XCDR (XCDR (prop))) \
84 : CONSP (prop) ? XCDR (prop) : Qnil) 85 : CONSP (prop) ? XCDR (prop) : Qnil)
85 86
86/* Return the method of composition. */
87#define COMPOSITION_METHOD(prop) \
88 (COMPOSITION_REGISTERD_P (prop) \
89 ? composition_table[COMPOSITION_ID (prop)]->method \
90 : (composition_temp = XCDR (XCAR (prop)), \
91 (NILP (composition_temp) \
92 ? COMPOSITION_RELATIVE \
93 : (INTEGERP (composition_temp) || STRINGP (composition_temp)) \
94 ? COMPOSITION_WITH_ALTCHARS \
95 : COMPOSITION_WITH_RULE_ALTCHARS)))
96
97/* Return 1 if the composition is valid. It is valid if length of
98 the composition equals to (END - START). */
99#define COMPOSITION_VALID_P(start, end, prop) \
100 (CONSP (prop) \
101 && (COMPOSITION_REGISTERD_P (prop) \
102 ? (COMPOSITION_ID (prop) >= 0 \
103 && COMPOSITION_ID (prop) <= n_compositions \
104 && CONSP (XCDR (prop))) \
105 : (composition_temp = XCAR (prop), \
106 (CONSP (composition_temp) \
107 && (composition_temp = XCDR (composition_temp), \
108 (NILP (composition_temp) \
109 || STRINGP (composition_temp) \
110 || VECTORP (composition_temp) \
111 || INTEGERP (composition_temp) \
112 || CONSP (composition_temp)))))) \
113 && (end - start) == COMPOSITION_LENGTH (prop))
114
115/* Return the Nth glyph of composition specified by CMP. CMP is a 87/* Return the Nth glyph of composition specified by CMP. CMP is a
116 pointer to `struct composition'. */ 88 pointer to `struct composition'. */
117#define COMPOSITION_GLYPH(cmp, n) \ 89#define COMPOSITION_GLYPH(cmp, n) \
@@ -227,12 +199,48 @@ extern bool find_composition (ptrdiff_t, ptrdiff_t, ptrdiff_t *, ptrdiff_t *,
227 Lisp_Object *, Lisp_Object); 199 Lisp_Object *, Lisp_Object);
228extern void update_compositions (ptrdiff_t, ptrdiff_t, int); 200extern void update_compositions (ptrdiff_t, ptrdiff_t, int);
229extern void make_composition_value_copy (Lisp_Object); 201extern void make_composition_value_copy (Lisp_Object);
230extern void compose_region (int, int, Lisp_Object, Lisp_Object,
231 Lisp_Object);
232extern void syms_of_composite (void); 202extern void syms_of_composite (void);
233extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object, 203extern void compose_text (ptrdiff_t, ptrdiff_t, Lisp_Object, Lisp_Object,
234 Lisp_Object); 204 Lisp_Object);
235 205
206/* Return the method of a composition with property PROP. */
207
208COMPOSITE_INLINE enum composition_method
209composition_method (Lisp_Object prop)
210{
211 if (composition_registered_p (prop))
212 return composition_table[COMPOSITION_ID (prop)]->method;
213 else
214 {
215 Lisp_Object temp = XCDR (XCAR (prop));
216 return (NILP (temp)
217 ? COMPOSITION_RELATIVE
218 : INTEGERP (temp) || STRINGP (temp)
219 ? COMPOSITION_WITH_ALTCHARS
220 : COMPOSITION_WITH_RULE_ALTCHARS);
221 }
222}
223
224/* Given offsets START and END, return true if PROP is a valid composition
225 property with length END - START. */
226
227COMPOSITE_INLINE bool
228composition_valid_p (ptrdiff_t start, ptrdiff_t end, Lisp_Object prop)
229{
230 return (CONSP (prop)
231 && (composition_registered_p (prop)
232 ? (COMPOSITION_ID (prop) >= 0
233 && COMPOSITION_ID (prop) <= n_compositions
234 && CONSP (XCDR (prop)))
235 : (CONSP (XCAR (prop))
236 && (NILP (XCDR (XCAR (prop)))
237 || STRINGP (XCDR (XCAR (prop)))
238 || VECTORP (XCDR (XCAR (prop)))
239 || INTEGERP (XCDR (XCAR (prop)))
240 || CONSP (XCDR (XCAR (prop))))))
241 && COMPOSITION_LENGTH (prop) == end - start);
242}
243
236/* Macros for lispy glyph-string. This is completely different from 244/* Macros for lispy glyph-string. This is completely different from
237 struct glyph_string. */ 245 struct glyph_string. */
238 246
diff --git a/src/data.c b/src/data.c
index 25a9e698481..95cbd471d33 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1018,19 +1018,14 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva
1018 - (char *) &buffer_defaults); 1018 - (char *) &buffer_defaults);
1019 int idx = PER_BUFFER_IDX (offset); 1019 int idx = PER_BUFFER_IDX (offset);
1020 1020
1021 Lisp_Object tail; 1021 Lisp_Object tail, buf;
1022 1022
1023 if (idx <= 0) 1023 if (idx <= 0)
1024 break; 1024 break;
1025 1025
1026 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 1026 FOR_EACH_LIVE_BUFFER (tail, buf)
1027 { 1027 {
1028 Lisp_Object lbuf; 1028 struct buffer *b = XBUFFER (buf);
1029 struct buffer *b;
1030
1031 lbuf = Fcdr (XCAR (tail));
1032 if (!BUFFERP (lbuf)) continue;
1033 b = XBUFFER (lbuf);
1034 1029
1035 if (! PER_BUFFER_VALUE_P (b, idx)) 1030 if (! PER_BUFFER_VALUE_P (b, idx))
1036 set_per_buffer_value (b, offset, newval); 1031 set_per_buffer_value (b, offset, newval);
@@ -1421,9 +1416,7 @@ for this variable. The default value is meaningful for variables with
1421local bindings in certain buffers. */) 1416local bindings in certain buffers. */)
1422 (Lisp_Object symbol) 1417 (Lisp_Object symbol)
1423{ 1418{
1424 register Lisp_Object value; 1419 Lisp_Object value = default_value (symbol);
1425
1426 value = default_value (symbol);
1427 if (!EQ (value, Qunbound)) 1420 if (!EQ (value, Qunbound))
1428 return value; 1421 return value;
1429 1422
@@ -2019,7 +2012,7 @@ If the current binding is global (the default), the value is nil. */)
2019 { 2012 {
2020 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); 2013 union Lisp_Fwd *valcontents = SYMBOL_FWD (sym);
2021 if (KBOARD_OBJFWDP (valcontents)) 2014 if (KBOARD_OBJFWDP (valcontents))
2022 return Fframe_terminal (Fselected_frame ()); 2015 return Fframe_terminal (selected_frame);
2023 else if (!BUFFER_OBJFWDP (valcontents)) 2016 else if (!BUFFER_OBJFWDP (valcontents))
2024 return Qnil; 2017 return Qnil;
2025 } 2018 }
diff --git a/src/decompress.c b/src/decompress.c
new file mode 100644
index 00000000000..c49f39a8ba1
--- /dev/null
+++ b/src/decompress.c
@@ -0,0 +1,231 @@
1/* Interface to zlib.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <config.h>
20
21#ifdef HAVE_ZLIB
22
23#include <zlib.h>
24
25#include "lisp.h"
26#include "character.h"
27#include "buffer.h"
28
29#include <verify.h>
30
31static Lisp_Object Qzlib_dll;
32
33#ifdef WINDOWSNT
34#include <windows.h>
35#include "w32.h"
36
37/* Macro for defining functions that will be loaded from the zlib DLL. */
38#define DEF_ZLIB_FN(rettype,func,args) static rettype (FAR CDECL *fn_##func)args
39
40/* Macro for loading zlib functions from the library. */
41#define LOAD_ZLIB_FN(lib,func) { \
42 fn_##func = (void *) GetProcAddress (lib, #func); \
43 if (!fn_##func) return false; \
44 }
45
46DEF_ZLIB_FN (int, inflateInit2_,
47 (z_streamp strm, int windowBits, const char *version, int stream_size));
48
49DEF_ZLIB_FN (int, inflate,
50 (z_streamp strm, int flush));
51
52DEF_ZLIB_FN (int, inflateEnd,
53 (z_streamp strm));
54
55static bool zlib_initialized;
56
57static bool
58init_zlib_functions (void)
59{
60 HMODULE library = w32_delayed_load (Qzlib_dll);
61
62 if (!library)
63 {
64 message1 ("zlib library not found");
65 return false;
66 }
67
68 LOAD_ZLIB_FN (library, inflateInit2_);
69 LOAD_ZLIB_FN (library, inflate);
70 LOAD_ZLIB_FN (library, inflateEnd);
71 return true;
72}
73
74#define fn_inflateInit2(strm, windowBits) \
75 fn_inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
76
77#else /* !WINDOWSNT */
78
79#define fn_inflateInit2 inflateInit2
80#define fn_inflate inflate
81#define fn_inflateEnd inflateEnd
82
83#endif /* WINDOWSNT */
84
85
86struct decompress_unwind_data
87{
88 ptrdiff_t old_point, start;
89 z_stream *stream;
90};
91
92static void
93unwind_decompress (void *ddata)
94{
95 struct decompress_unwind_data *data = ddata;
96 fn_inflateEnd (data->stream);
97
98 /* Delete any uncompressed data already inserted on error. */
99 if (data->start)
100 del_range (data->start, PT);
101
102 /* Put point where it was, or if the buffer has shrunk because the
103 compressed data is bigger than the uncompressed, at
104 point-max. */
105 SET_PT (min (data->old_point, ZV));
106}
107
108DEFUN ("zlib-available-p", Fzlib_available_p, Szlib_available_p, 0, 0, 0,
109 doc: /* Return t if zlib decompression is available in this instance of Emacs. */)
110 (void)
111{
112#ifdef WINDOWSNT
113 Lisp_Object found = Fassq (Qzlib_dll, Vlibrary_cache);
114 if (CONSP (found))
115 return XCDR (found);
116 else
117 {
118 Lisp_Object status;
119 zlib_initialized = init_zlib_functions ();
120 status = zlib_initialized ? Qt : Qnil;
121 Vlibrary_cache = Fcons (Fcons (Qzlib_dll, status), Vlibrary_cache);
122 return status;
123 }
124#else
125 return Qt;
126#endif
127}
128
129DEFUN ("zlib-decompress-region", Fzlib_decompress_region,
130 Szlib_decompress_region,
131 2, 2, 0,
132 doc: /* Decompress a gzip- or zlib-compressed region.
133Replace the text in the region by the decompressed data.
134On failure, return nil and leave the data in place.
135This function can be called only in unibyte buffers. */)
136 (Lisp_Object start, Lisp_Object end)
137{
138 ptrdiff_t istart, iend, pos_byte;
139 z_stream stream;
140 int inflate_status;
141 struct decompress_unwind_data unwind_data;
142 ptrdiff_t count = SPECPDL_INDEX ();
143
144 validate_region (&start, &end);
145
146 if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
147 error ("This function can be called only in unibyte buffers");
148
149#ifdef WINDOWSNT
150 if (!zlib_initialized)
151 zlib_initialized = init_zlib_functions ();
152 if (!zlib_initialized)
153 return Qnil;
154#endif
155
156 /* This is a unibyte buffer, so character positions and bytes are
157 the same. */
158 istart = XINT (start);
159 iend = XINT (end);
160 move_gap_both (iend, iend);
161
162 stream.zalloc = Z_NULL;
163 stream.zfree = Z_NULL;
164 stream.opaque = Z_NULL;
165 stream.avail_in = 0;
166 stream.next_in = Z_NULL;
167
168 /* The magic number 32 apparently means "autodetect both the gzip and
169 zlib formats" according to zlib.h. */
170 if (fn_inflateInit2 (&stream, MAX_WBITS + 32) != Z_OK)
171 return Qnil;
172
173 unwind_data.start = iend;
174 unwind_data.stream = &stream;
175 unwind_data.old_point = PT;
176
177 record_unwind_protect_ptr (unwind_decompress, &unwind_data);
178
179 /* Insert the decompressed data at the end of the compressed data. */
180 SET_PT (iend);
181
182 pos_byte = istart;
183
184 /* Keep calling 'inflate' until it reports an error or end-of-input. */
185 do
186 {
187 /* Maximum number of bytes that one 'inflate' call should read and write.
188 Do not make avail_out too large, as that might unduly delay C-g.
189 zlib requires that avail_in and avail_out not exceed UINT_MAX. */
190 ptrdiff_t avail_in = min (iend - pos_byte, UINT_MAX);
191 int avail_out = 16 * 1024;
192 int decompressed;
193
194 if (GAP_SIZE < avail_out)
195 make_gap (avail_out - GAP_SIZE);
196 stream.next_in = BYTE_POS_ADDR (pos_byte);
197 stream.avail_in = avail_in;
198 stream.next_out = GPT_ADDR;
199 stream.avail_out = avail_out;
200 inflate_status = fn_inflate (&stream, Z_NO_FLUSH);
201 pos_byte += avail_in - stream.avail_in;
202 decompressed = avail_out - stream.avail_out;
203 insert_from_gap (decompressed, decompressed, 0);
204 QUIT;
205 }
206 while (inflate_status == Z_OK);
207
208 if (inflate_status != Z_STREAM_END)
209 return unbind_to (count, Qnil);
210
211 unwind_data.start = 0;
212
213 /* Delete the compressed data. */
214 del_range (istart, iend);
215
216 return unbind_to (count, Qt);
217}
218
219
220/***********************************************************************
221 Initialization
222 ***********************************************************************/
223void
224syms_of_decompress (void)
225{
226 DEFSYM (Qzlib_dll, "zlib");
227 defsubr (&Szlib_decompress_region);
228 defsubr (&Szlib_available_p);
229}
230
231#endif /* HAVE_ZLIB */
diff --git a/src/dispextern.h b/src/dispextern.h
index e0d04231d3a..7a4fa2ea774 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1197,11 +1197,6 @@ extern bool fonts_changed_p;
1197 1197
1198extern struct glyph space_glyph; 1198extern struct glyph space_glyph;
1199 1199
1200/* Window being updated by update_window. This is non-null as long as
1201 update_window has not finished, and null otherwise. */
1202
1203extern struct window *updated_window;
1204
1205/* Glyph row and area updated by update_window_line. */ 1200/* Glyph row and area updated by update_window_line. */
1206 1201
1207extern struct glyph_row *updated_row; 1202extern struct glyph_row *updated_row;
@@ -2718,12 +2713,12 @@ struct redisplay_interface
2718 2713
2719 /* Write or insert LEN glyphs from STRING at the nominal output 2714 /* Write or insert LEN glyphs from STRING at the nominal output
2720 position. */ 2715 position. */
2721 void (*write_glyphs) (struct glyph *string, int len); 2716 void (*write_glyphs) (struct window *w, struct glyph *string, int len);
2722 void (*insert_glyphs) (struct glyph *start, int len); 2717 void (*insert_glyphs) (struct window *w, struct glyph *start, int len);
2723 2718
2724 /* Clear from nominal output position to X. X < 0 means clear 2719 /* Clear from nominal output position to X. X < 0 means clear
2725 to right end of display. */ 2720 to right end of display. */
2726 void (*clear_end_of_line) (int x); 2721 void (*clear_end_of_line) (struct window *w, int x);
2727 2722
2728 /* Function to call to scroll the display as described by RUN on 2723 /* Function to call to scroll the display as described by RUN on
2729 window W. */ 2724 window W. */
@@ -2732,7 +2727,8 @@ struct redisplay_interface
2732 /* Function to call after a line in a display has been completely 2727 /* Function to call after a line in a display has been completely
2733 updated. Used to draw truncation marks and alike. DESIRED_ROW 2728 updated. Used to draw truncation marks and alike. DESIRED_ROW
2734 is the desired row which has been updated. */ 2729 is the desired row which has been updated. */
2735 void (*after_update_window_line_hook) (struct glyph_row *desired_row); 2730 void (*after_update_window_line_hook) (struct window *w,
2731 struct glyph_row *desired_row);
2736 2732
2737 /* Function to call before beginning to update window W in 2733 /* Function to call before beginning to update window W in
2738 window-based redisplay. */ 2734 window-based redisplay. */
@@ -2749,7 +2745,7 @@ struct redisplay_interface
2749 /* Move cursor to row/column position VPOS/HPOS, pixel coordinates 2745 /* Move cursor to row/column position VPOS/HPOS, pixel coordinates
2750 Y/X. HPOS/VPOS are window-relative row and column numbers and X/Y 2746 Y/X. HPOS/VPOS are window-relative row and column numbers and X/Y
2751 are window-relative pixel positions. */ 2747 are window-relative pixel positions. */
2752 void (*cursor_to) (int vpos, int hpos, int y, int x); 2748 void (*cursor_to) (struct window *w, int vpos, int hpos, int y, int x);
2753 2749
2754 /* Flush the display of frame F. For X, this is XFlush. */ 2750 /* Flush the display of frame F. For X, this is XFlush. */
2755 void (*flush_display) (struct frame *f); 2751 void (*flush_display) (struct frame *f);
@@ -3182,9 +3178,9 @@ extern void x_get_glyph_overhangs (struct glyph *, struct frame *,
3182 int *, int *); 3178 int *, int *);
3183extern void x_produce_glyphs (struct it *); 3179extern void x_produce_glyphs (struct it *);
3184 3180
3185extern void x_write_glyphs (struct glyph *, int); 3181extern void x_write_glyphs (struct window *, struct glyph *, int);
3186extern void x_insert_glyphs (struct glyph *, int len); 3182extern void x_insert_glyphs (struct window *, struct glyph *, int len);
3187extern void x_clear_end_of_line (int); 3183extern void x_clear_end_of_line (struct window *, int);
3188 3184
3189extern struct cursor_pos output_cursor; 3185extern struct cursor_pos output_cursor;
3190 3186
@@ -3200,7 +3196,7 @@ extern void display_and_set_cursor (struct window *,
3200 int, int, int, int, int); 3196 int, int, int, int, int);
3201 3197
3202extern void set_output_cursor (struct cursor_pos *); 3198extern void set_output_cursor (struct cursor_pos *);
3203extern void x_cursor_to (int, int, int, int); 3199extern void x_cursor_to (struct window *, int, int, int, int);
3204 3200
3205extern void x_update_cursor (struct frame *, int); 3201extern void x_update_cursor (struct frame *, int);
3206extern void x_clear_cursor (struct window *); 3202extern void x_clear_cursor (struct window *);
@@ -3235,9 +3231,9 @@ extern void tty_draw_row_with_mouse_face (struct window *, struct glyph_row *,
3235int lookup_fringe_bitmap (Lisp_Object); 3231int lookup_fringe_bitmap (Lisp_Object);
3236void draw_fringe_bitmap (struct window *, struct glyph_row *, int); 3232void draw_fringe_bitmap (struct window *, struct glyph_row *, int);
3237void draw_row_fringe_bitmaps (struct window *, struct glyph_row *); 3233void draw_row_fringe_bitmaps (struct window *, struct glyph_row *);
3238int draw_window_fringes (struct window *, int); 3234bool draw_window_fringes (struct window *, bool);
3239int update_window_fringes (struct window *, int); 3235bool update_window_fringes (struct window *, bool);
3240void compute_fringe_widths (struct frame *, int); 3236void compute_fringe_widths (struct frame *, bool);
3241 3237
3242#ifdef HAVE_NTGUI 3238#ifdef HAVE_NTGUI
3243void w32_init_fringe (struct redisplay_interface *); 3239void w32_init_fringe (struct redisplay_interface *);
diff --git a/src/dispnew.c b/src/dispnew.c
index 522a0e6a30d..b7e44e425bf 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -135,10 +135,6 @@ struct frame *last_nonminibuf_frame;
135 135
136static bool delayed_size_change; 136static bool delayed_size_change;
137 137
138/* Updated window if != 0. Set by update_window. */
139
140struct window *updated_window;
141
142/* Glyph row updated in update_window_line, and area that is updated. */ 138/* Glyph row updated in update_window_line, and area that is updated. */
143 139
144struct glyph_row *updated_row; 140struct glyph_row *updated_row;
@@ -148,12 +144,16 @@ int updated_area;
148 144
149struct glyph space_glyph; 145struct glyph space_glyph;
150 146
147#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
148
151/* Counts of allocated structures. These counts serve to diagnose 149/* Counts of allocated structures. These counts serve to diagnose
152 memory leaks and double frees. */ 150 memory leaks and double frees. */
153 151
154static int glyph_matrix_count; 152static int glyph_matrix_count;
155static int glyph_pool_count; 153static int glyph_pool_count;
156 154
155#endif /* GLYPH_DEBUG and ENABLE_CHECKING */
156
157/* If non-null, the frame whose frame matrices are manipulated. If 157/* If non-null, the frame whose frame matrices are manipulated. If
158 null, window matrices are worked on. */ 158 null, window matrices are worked on. */
159 159
@@ -307,9 +307,11 @@ new_glyph_matrix (struct glyph_pool *pool)
307{ 307{
308 struct glyph_matrix *result = xzalloc (sizeof *result); 308 struct glyph_matrix *result = xzalloc (sizeof *result);
309 309
310#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
310 /* Increment number of allocated matrices. This count is used 311 /* Increment number of allocated matrices. This count is used
311 to detect memory leaks. */ 312 to detect memory leaks. */
312 ++glyph_matrix_count; 313 ++glyph_matrix_count;
314#endif
313 315
314 /* Set pool and return. */ 316 /* Set pool and return. */
315 result->pool = pool; 317 result->pool = pool;
@@ -319,10 +321,10 @@ new_glyph_matrix (struct glyph_pool *pool)
319 321
320/* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed. 322/* Free glyph matrix MATRIX. Passing in a null MATRIX is allowed.
321 323
322 The global counter glyph_matrix_count is decremented when a matrix 324 If GLYPH_DEBUG and ENABLE_CHECKING are in effect, the global counter
323 is freed. If the count gets negative, more structures were freed 325 glyph_matrix_count is decremented when a matrix is freed. If the count
324 than allocated, i.e. one matrix was freed more than once or a bogus 326 gets negative, more structures were freed than allocated, i.e. one matrix
325 pointer was passed to this function. 327 was freed more than once or a bogus pointer was passed to this function.
326 328
327 If MATRIX->pool is null, this means that the matrix manages its own 329 If MATRIX->pool is null, this means that the matrix manages its own
328 glyph memory---this is done for matrices on X frames. Freeing the 330 glyph memory---this is done for matrices on X frames. Freeing the
@@ -335,10 +337,12 @@ free_glyph_matrix (struct glyph_matrix *matrix)
335 { 337 {
336 int i; 338 int i;
337 339
340#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
338 /* Detect the case that more matrices are freed than were 341 /* Detect the case that more matrices are freed than were
339 allocated. */ 342 allocated. */
340 if (--glyph_matrix_count < 0) 343 --glyph_matrix_count;
341 emacs_abort (); 344 eassert (glyph_matrix_count >= 0);
345#endif
342 346
343 /* Free glyph memory if MATRIX owns it. */ 347 /* Free glyph memory if MATRIX owns it. */
344 if (matrix->pool == NULL) 348 if (matrix->pool == NULL)
@@ -355,25 +359,19 @@ free_glyph_matrix (struct glyph_matrix *matrix)
355/* Return the number of glyphs to reserve for a marginal area of 359/* Return the number of glyphs to reserve for a marginal area of
356 window W. TOTAL_GLYPHS is the number of glyphs in a complete 360 window W. TOTAL_GLYPHS is the number of glyphs in a complete
357 display line of window W. MARGIN gives the width of the marginal 361 display line of window W. MARGIN gives the width of the marginal
358 area in canonical character units. MARGIN should be an integer 362 area in canonical character units. */
359 or a float. */
360 363
361static int 364static int
362margin_glyphs_to_reserve (struct window *w, int total_glyphs, Lisp_Object margin) 365margin_glyphs_to_reserve (struct window *w, int total_glyphs, int margin)
363{ 366{
364 int n; 367 if (margin > 0)
365
366 if (NUMBERP (margin))
367 { 368 {
368 int width = w->total_cols; 369 int width = w->total_cols;
369 double d = max (0, XFLOATINT (margin)); 370 double d = max (0, margin);
370 d = min (width / 2 - 1, d); 371 d = min (width / 2 - 1, d);
371 n = (int) ((double) total_glyphs / width * d); 372 return (int) ((double) total_glyphs / width * d);
372 } 373 }
373 else 374 return 0;
374 n = 0;
375
376 return n;
377} 375}
378 376
379/* Return true if ROW's hash value is correct. 377/* Return true if ROW's hash value is correct.
@@ -600,8 +598,7 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y
600 598
601 /* Window end is invalid, if inside of the rows that 599 /* Window end is invalid, if inside of the rows that
602 are invalidated below. */ 600 are invalidated below. */
603 if (INTEGERP (w->window_end_vpos) 601 if (w->window_end_vpos >= i)
604 && XFASTINT (w->window_end_vpos) >= i)
605 w->window_end_valid = 0; 602 w->window_end_valid = 0;
606 603
607 while (i < matrix->nrows) 604 while (i < matrix->nrows)
@@ -1310,38 +1307,41 @@ row_equal_p (struct glyph_row *a, struct glyph_row *b, bool mouse_face_p)
1310 See dispextern.h for an overall explanation of glyph pools. 1307 See dispextern.h for an overall explanation of glyph pools.
1311 ***********************************************************************/ 1308 ***********************************************************************/
1312 1309
1313/* Allocate a glyph_pool structure. The structure returned is 1310/* Allocate a glyph_pool structure. The structure returned is initialized
1314 initialized with zeros. The global variable glyph_pool_count is 1311 with zeros. If GLYPH_DEBUG and ENABLE_CHECKING are in effect, the global
1315 incremented for each pool allocated. */ 1312 variable glyph_pool_count is incremented for each pool allocated. */
1316 1313
1317static struct glyph_pool * 1314static struct glyph_pool *
1318new_glyph_pool (void) 1315new_glyph_pool (void)
1319{ 1316{
1320 struct glyph_pool *result = xzalloc (sizeof *result); 1317 struct glyph_pool *result = xzalloc (sizeof *result);
1321 1318
1319#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
1322 /* For memory leak and double deletion checking. */ 1320 /* For memory leak and double deletion checking. */
1323 ++glyph_pool_count; 1321 ++glyph_pool_count;
1322#endif
1324 1323
1325 return result; 1324 return result;
1326} 1325}
1327 1326
1328 1327
1329/* Free a glyph_pool structure POOL. The function may be called with 1328/* Free a glyph_pool structure POOL. The function may be called with
1330 a null POOL pointer. The global variable glyph_pool_count is 1329 a null POOL pointer. If GLYPH_DEBUG and ENABLE_CHECKING are in effect,
1331 decremented with every pool structure freed. If this count gets 1330 global variable glyph_pool_count is decremented with every pool structure
1332 negative, more structures were freed than allocated, i.e. one 1331 freed. If this count gets negative, more structures were freed than
1333 structure must have been freed more than once or a bogus pointer 1332 allocated, i.e. one structure must have been freed more than once or
1334 was passed to free_glyph_pool. */ 1333 a bogus pointer was passed to free_glyph_pool. */
1335 1334
1336static void 1335static void
1337free_glyph_pool (struct glyph_pool *pool) 1336free_glyph_pool (struct glyph_pool *pool)
1338{ 1337{
1339 if (pool) 1338 if (pool)
1340 { 1339 {
1340#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
1341 /* More freed than allocated? */ 1341 /* More freed than allocated? */
1342 --glyph_pool_count; 1342 --glyph_pool_count;
1343 eassert (glyph_pool_count >= 0); 1343 eassert (glyph_pool_count >= 0);
1344 1344#endif
1345 xfree (pool->glyphs); 1345 xfree (pool->glyphs);
1346 xfree (pool); 1346 xfree (pool);
1347 } 1347 }
@@ -1860,7 +1860,7 @@ showing_window_margins_p (struct window *w)
1860 if (showing_window_margins_p (XWINDOW (w->contents))) 1860 if (showing_window_margins_p (XWINDOW (w->contents)))
1861 return 1; 1861 return 1;
1862 } 1862 }
1863 else if (!NILP (w->left_margin_cols) || !NILP (w->right_margin_cols)) 1863 else if (w->left_margin_cols > 0 || w->right_margin_cols > 0)
1864 return 1; 1864 return 1;
1865 1865
1866 w = NILP (w->next) ? 0 : XWINDOW (w->next); 1866 w = NILP (w->next) ? 0 : XWINDOW (w->next);
@@ -2254,11 +2254,11 @@ check_glyph_memory (void)
2254 FOR_EACH_FRAME (tail, frame) 2254 FOR_EACH_FRAME (tail, frame)
2255 free_glyphs (XFRAME (frame)); 2255 free_glyphs (XFRAME (frame));
2256 2256
2257#if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2257 /* Check that nothing is left allocated. */ 2258 /* Check that nothing is left allocated. */
2258 if (glyph_matrix_count) 2259 eassert (glyph_matrix_count == 0);
2259 emacs_abort (); 2260 eassert (glyph_pool_count == 0);
2260 if (glyph_pool_count) 2261#endif
2261 emacs_abort ();
2262} 2262}
2263 2263
2264 2264
@@ -2275,7 +2275,7 @@ check_glyph_memory (void)
2275 screen. We build such a view by constructing a frame matrix from 2275 screen. We build such a view by constructing a frame matrix from
2276 window matrices in this section. 2276 window matrices in this section.
2277 2277
2278 Windows that must be updated have their must_be_update_p flag set. 2278 Windows that must be updated have their must_be_updated_p flag set.
2279 For all such windows, their desired matrix is made part of the 2279 For all such windows, their desired matrix is made part of the
2280 desired frame matrix. For other windows, their current matrix is 2280 desired frame matrix. For other windows, their current matrix is
2281 made part of the desired frame matrix. 2281 made part of the desired frame matrix.
@@ -3232,12 +3232,12 @@ redraw_overlapped_rows (struct window *w, int yb)
3232 { 3232 {
3233 updated_row = row; 3233 updated_row = row;
3234 updated_area = area; 3234 updated_area = area;
3235 FRAME_RIF (f)->cursor_to (i, 0, row->y, 3235 FRAME_RIF (f)->cursor_to (w, i, 0, row->y,
3236 area == TEXT_AREA ? row->x : 0); 3236 area == TEXT_AREA ? row->x : 0);
3237 if (row->used[area]) 3237 if (row->used[area])
3238 FRAME_RIF (f)->write_glyphs (row->glyphs[area], 3238 FRAME_RIF (f)->write_glyphs (w, row->glyphs[area],
3239 row->used[area]); 3239 row->used[area]);
3240 FRAME_RIF (f)->clear_end_of_line (-1); 3240 FRAME_RIF (f)->clear_end_of_line (w, -1);
3241 } 3241 }
3242 3242
3243 row->overlapped_p = 0; 3243 row->overlapped_p = 0;
@@ -3523,10 +3523,10 @@ update_marginal_area (struct window *w, int area, int vpos)
3523 /* Set cursor to start of glyphs, write them, and clear to the end 3523 /* Set cursor to start of glyphs, write them, and clear to the end
3524 of the area. I don't think that something more sophisticated is 3524 of the area. I don't think that something more sophisticated is
3525 necessary here, since marginal areas will not be the default. */ 3525 necessary here, since marginal areas will not be the default. */
3526 rif->cursor_to (vpos, 0, desired_row->y, 0); 3526 rif->cursor_to (w, vpos, 0, desired_row->y, 0);
3527 if (desired_row->used[area]) 3527 if (desired_row->used[area])
3528 rif->write_glyphs (desired_row->glyphs[area], desired_row->used[area]); 3528 rif->write_glyphs (w, desired_row->glyphs[area], desired_row->used[area]);
3529 rif->clear_end_of_line (-1); 3529 rif->clear_end_of_line (w, -1);
3530} 3530}
3531 3531
3532 3532
@@ -3564,14 +3564,14 @@ update_text_area (struct window *w, int vpos)
3564 && !(current_row->mode_line_p && vpos > 0)) 3564 && !(current_row->mode_line_p && vpos > 0))
3565 || current_row->x != desired_row->x) 3565 || current_row->x != desired_row->x)
3566 { 3566 {
3567 rif->cursor_to (vpos, 0, desired_row->y, desired_row->x); 3567 rif->cursor_to (w, vpos, 0, desired_row->y, desired_row->x);
3568 3568
3569 if (desired_row->used[TEXT_AREA]) 3569 if (desired_row->used[TEXT_AREA])
3570 rif->write_glyphs (desired_row->glyphs[TEXT_AREA], 3570 rif->write_glyphs (w, desired_row->glyphs[TEXT_AREA],
3571 desired_row->used[TEXT_AREA]); 3571 desired_row->used[TEXT_AREA]);
3572 3572
3573 /* Clear to end of window. */ 3573 /* Clear to end of window. */
3574 rif->clear_end_of_line (-1); 3574 rif->clear_end_of_line (w, -1);
3575 changed_p = 1; 3575 changed_p = 1;
3576 3576
3577 /* This erases the cursor. We do this here because 3577 /* This erases the cursor. We do this here because
@@ -3707,8 +3707,8 @@ update_text_area (struct window *w, int vpos)
3707 break; 3707 break;
3708 } 3708 }
3709 3709
3710 rif->cursor_to (vpos, start_hpos, desired_row->y, start_x); 3710 rif->cursor_to (w, vpos, start_hpos, desired_row->y, start_x);
3711 rif->write_glyphs (start, i - start_hpos); 3711 rif->write_glyphs (w, start, i - start_hpos);
3712 changed_p = 1; 3712 changed_p = 1;
3713 } 3713 }
3714 } 3714 }
@@ -3716,8 +3716,8 @@ update_text_area (struct window *w, int vpos)
3716 /* Write the rest. */ 3716 /* Write the rest. */
3717 if (i < desired_row->used[TEXT_AREA]) 3717 if (i < desired_row->used[TEXT_AREA])
3718 { 3718 {
3719 rif->cursor_to (vpos, i, desired_row->y, x); 3719 rif->cursor_to (w, vpos, i, desired_row->y, x);
3720 rif->write_glyphs (desired_glyph, desired_row->used[TEXT_AREA] - i); 3720 rif->write_glyphs (w, desired_glyph, desired_row->used[TEXT_AREA] - i);
3721 changed_p = 1; 3721 changed_p = 1;
3722 } 3722 }
3723 3723
@@ -3737,9 +3737,9 @@ update_text_area (struct window *w, int vpos)
3737 { 3737 {
3738 /* If old row extends to the end of the text area, clear. */ 3738 /* If old row extends to the end of the text area, clear. */
3739 if (i >= desired_row->used[TEXT_AREA]) 3739 if (i >= desired_row->used[TEXT_AREA])
3740 rif->cursor_to (vpos, i, desired_row->y, 3740 rif->cursor_to (w, vpos, i, desired_row->y,
3741 desired_row->pixel_width); 3741 desired_row->pixel_width);
3742 rif->clear_end_of_line (-1); 3742 rif->clear_end_of_line (w, -1);
3743 changed_p = 1; 3743 changed_p = 1;
3744 } 3744 }
3745 else if (desired_row->pixel_width < current_row->pixel_width) 3745 else if (desired_row->pixel_width < current_row->pixel_width)
@@ -3749,7 +3749,7 @@ update_text_area (struct window *w, int vpos)
3749 int xlim; 3749 int xlim;
3750 3750
3751 if (i >= desired_row->used[TEXT_AREA]) 3751 if (i >= desired_row->used[TEXT_AREA])
3752 rif->cursor_to (vpos, i, desired_row->y, 3752 rif->cursor_to (w, vpos, i, desired_row->y,
3753 desired_row->pixel_width); 3753 desired_row->pixel_width);
3754 3754
3755 /* If cursor is displayed at the end of the line, make sure 3755 /* If cursor is displayed at the end of the line, make sure
@@ -3767,7 +3767,7 @@ update_text_area (struct window *w, int vpos)
3767 } 3767 }
3768 else 3768 else
3769 xlim = current_row->pixel_width; 3769 xlim = current_row->pixel_width;
3770 rif->clear_end_of_line (xlim); 3770 rif->clear_end_of_line (w, xlim);
3771 changed_p = 1; 3771 changed_p = 1;
3772 } 3772 }
3773 } 3773 }
@@ -3800,8 +3800,7 @@ update_window_line (struct window *w, int vpos, bool *mouse_face_overwritten_p)
3800 eassert (desired_row->enabled_p); 3800 eassert (desired_row->enabled_p);
3801 3801
3802 /* Update display of the left margin area, if there is one. */ 3802 /* Update display of the left margin area, if there is one. */
3803 if (!desired_row->full_width_p 3803 if (!desired_row->full_width_p && w->left_margin_cols > 0)
3804 && !NILP (w->left_margin_cols))
3805 { 3804 {
3806 changed_p = 1; 3805 changed_p = 1;
3807 update_marginal_area (w, LEFT_MARGIN_AREA, vpos); 3806 update_marginal_area (w, LEFT_MARGIN_AREA, vpos);
@@ -3821,8 +3820,7 @@ update_window_line (struct window *w, int vpos, bool *mouse_face_overwritten_p)
3821 } 3820 }
3822 3821
3823 /* Update display of the right margin area, if there is one. */ 3822 /* Update display of the right margin area, if there is one. */
3824 if (!desired_row->full_width_p 3823 if (!desired_row->full_width_p && w->right_margin_cols > 0)
3825 && !NILP (w->right_margin_cols))
3826 { 3824 {
3827 changed_p = 1; 3825 changed_p = 1;
3828 update_marginal_area (w, RIGHT_MARGIN_AREA, vpos); 3826 update_marginal_area (w, RIGHT_MARGIN_AREA, vpos);
@@ -3839,7 +3837,7 @@ update_window_line (struct window *w, int vpos, bool *mouse_face_overwritten_p)
3839 || desired_row->exact_window_width_line_p != current_row->exact_window_width_line_p 3837 || desired_row->exact_window_width_line_p != current_row->exact_window_width_line_p
3840 || (MATRIX_ROW_CONTINUATION_LINE_P (desired_row) 3838 || (MATRIX_ROW_CONTINUATION_LINE_P (desired_row)
3841 != MATRIX_ROW_CONTINUATION_LINE_P (current_row))) 3839 != MATRIX_ROW_CONTINUATION_LINE_P (current_row)))
3842 rif->after_update_window_line_hook (desired_row); 3840 rif->after_update_window_line_hook (w, desired_row);
3843 } 3841 }
3844 3842
3845 /* Update current_row from desired_row. */ 3843 /* Update current_row from desired_row. */
@@ -3928,7 +3926,7 @@ set_window_cursor_after_update (struct window *w)
3928 Horizontal position is -1 when cursor is on the left fringe. */ 3926 Horizontal position is -1 when cursor is on the left fringe. */
3929 hpos = clip_to_bounds (-1, hpos, w->current_matrix->matrix_w - 1); 3927 hpos = clip_to_bounds (-1, hpos, w->current_matrix->matrix_w - 1);
3930 vpos = clip_to_bounds (0, vpos, w->current_matrix->nrows - 1); 3928 vpos = clip_to_bounds (0, vpos, w->current_matrix->nrows - 1);
3931 rif->cursor_to (vpos, hpos, cy, cx); 3929 rif->cursor_to (w, vpos, hpos, cy, cx);
3932} 3930}
3933 3931
3934 3932
@@ -4599,10 +4597,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p)
4599 int x = WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos); 4597 int x = WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos);
4600 int y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos); 4598 int y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos);
4601 4599
4602 if (INTEGERP (w->left_margin_cols)) 4600 x += max (0, w->left_margin_cols);
4603 x += XFASTINT (w->left_margin_cols);
4604
4605 /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */
4606 cursor_to (f, y, x); 4601 cursor_to (f, y, x);
4607 } 4602 }
4608 } 4603 }
@@ -5884,9 +5879,8 @@ pass nil for VARIABLE. */)
5884 goto changed; 5879 goto changed;
5885 } 5880 }
5886 /* Check that the buffer info matches. */ 5881 /* Check that the buffer info matches. */
5887 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5882 FOR_EACH_LIVE_BUFFER (tail, buf)
5888 { 5883 {
5889 buf = XCDR (XCAR (tail));
5890 /* Ignore buffers that aren't included in buffer lists. */ 5884 /* Ignore buffers that aren't included in buffer lists. */
5891 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ') 5885 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
5892 continue; 5886 continue;
@@ -5916,7 +5910,7 @@ pass nil for VARIABLE. */)
5916 n = 1; 5910 n = 1;
5917 FOR_EACH_FRAME (tail, frame) 5911 FOR_EACH_FRAME (tail, frame)
5918 n += 2; 5912 n += 2;
5919 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5913 FOR_EACH_LIVE_BUFFER (tail, buf)
5920 n += 3; 5914 n += 3;
5921 /* Reallocate the vector if data has grown to need it, 5915 /* Reallocate the vector if data has grown to need it,
5922 or if it has shrunk a lot. */ 5916 or if it has shrunk a lot. */
@@ -5941,9 +5935,8 @@ pass nil for VARIABLE. */)
5941 ASET (state, idx, XFRAME (frame)->name); 5935 ASET (state, idx, XFRAME (frame)->name);
5942 idx++; 5936 idx++;
5943 } 5937 }
5944 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5938 FOR_EACH_LIVE_BUFFER (tail, buf)
5945 { 5939 {
5946 buf = XCDR (XCAR (tail));
5947 /* Ignore buffers that aren't included in buffer lists. */ 5940 /* Ignore buffers that aren't included in buffer lists. */
5948 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ') 5941 if (SREF (BVAR (XBUFFER (buf), name), 0) == ' ')
5949 continue; 5942 continue;
diff --git a/src/doc.c b/src/doc.c
index 009616f4f87..d3f8fde08f6 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -905,7 +905,7 @@ Otherwise, return a new string, without any text properties. */)
905 If this one's not active, get nil. */ 905 If this one's not active, get nil. */
906 earlier_maps = Fcdr (Fmemq (tem, Freverse (active_maps))); 906 earlier_maps = Fcdr (Fmemq (tem, Freverse (active_maps)));
907 describe_map_tree (tem, 1, Fnreverse (earlier_maps), 907 describe_map_tree (tem, 1, Fnreverse (earlier_maps),
908 Qnil, (char *)0, 1, 0, 0, 1); 908 Qnil, 0, 1, 0, 0, 1);
909 } 909 }
910 tem = Fbuffer_string (); 910 tem = Fbuffer_string ();
911 Ferase_buffer (); 911 Ferase_buffer ();
diff --git a/src/editfns.c b/src/editfns.c
index 50bde90788d..bbaeaea5240 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2330,6 +2330,10 @@ to multibyte for insertion (see `unibyte-char-to-multibyte').
2330If the current buffer is unibyte, multibyte strings are converted 2330If the current buffer is unibyte, multibyte strings are converted
2331to unibyte for insertion. 2331to unibyte for insertion.
2332 2332
2333If an overlay begins at the insertion point, the inserted text falls
2334outside the overlay; if a nonempty overlay ends at the insertion
2335point, the inserted text falls inside that overlay.
2336
2333usage: (insert-before-markers &rest ARGS) */) 2337usage: (insert-before-markers &rest ARGS) */)
2334 (ptrdiff_t nargs, Lisp_Object *args) 2338 (ptrdiff_t nargs, Lisp_Object *args)
2335{ 2339{
@@ -2928,7 +2932,7 @@ Both characters must have the same length of multi-byte form. */)
2928 else if (!changed) 2932 else if (!changed)
2929 { 2933 {
2930 changed = -1; 2934 changed = -1;
2931 modify_region_1 (pos, XINT (end), false); 2935 modify_text (pos, XINT (end));
2932 2936
2933 if (! NILP (noundo)) 2937 if (! NILP (noundo))
2934 { 2938 {
@@ -3104,7 +3108,7 @@ It returns the number of characters changed. */)
3104 pos = XINT (start); 3108 pos = XINT (start);
3105 pos_byte = CHAR_TO_BYTE (pos); 3109 pos_byte = CHAR_TO_BYTE (pos);
3106 end_pos = XINT (end); 3110 end_pos = XINT (end);
3107 modify_region_1 (pos, end_pos, false); 3111 modify_text (pos, end_pos);
3108 3112
3109 cnt = 0; 3113 cnt = 0;
3110 for (; pos < end_pos; ) 3114 for (; pos < end_pos; )
@@ -4615,7 +4619,7 @@ Transposing beyond buffer boundaries is an error. */)
4615 4619
4616 if (end1 == start2) /* adjacent regions */ 4620 if (end1 == start2) /* adjacent regions */
4617 { 4621 {
4618 modify_region_1 (start1, end2, false); 4622 modify_text (start1, end2);
4619 record_change (start1, len1 + len2); 4623 record_change (start1, len1 + len2);
4620 4624
4621 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4625 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
@@ -4674,8 +4678,8 @@ Transposing beyond buffer boundaries is an error. */)
4674 { 4678 {
4675 USE_SAFE_ALLOCA; 4679 USE_SAFE_ALLOCA;
4676 4680
4677 modify_region_1 (start1, end1, false); 4681 modify_text (start1, end1);
4678 modify_region_1 (start2, end2, false); 4682 modify_text (start2, end2);
4679 record_change (start1, len1); 4683 record_change (start1, len1);
4680 record_change (start2, len2); 4684 record_change (start2, len2);
4681 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4685 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
@@ -4708,7 +4712,7 @@ Transposing beyond buffer boundaries is an error. */)
4708 { 4712 {
4709 USE_SAFE_ALLOCA; 4713 USE_SAFE_ALLOCA;
4710 4714
4711 modify_region_1 (start1, end2, false); 4715 modify_text (start1, end2);
4712 record_change (start1, (end2 - start1)); 4716 record_change (start1, (end2 - start1));
4713 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4717 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
4714 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); 4718 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
@@ -4741,7 +4745,7 @@ Transposing beyond buffer boundaries is an error. */)
4741 USE_SAFE_ALLOCA; 4745 USE_SAFE_ALLOCA;
4742 4746
4743 record_change (start1, (end2 - start1)); 4747 record_change (start1, (end2 - start1));
4744 modify_region_1 (start1, end2, false); 4748 modify_text (start1, end2);
4745 4749
4746 tmp_interval1 = copy_intervals (cur_intv, start1, len1); 4750 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
4747 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); 4751 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
diff --git a/src/emacs.c b/src/emacs.c
index 6d406407a9d..e6d612b8417 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -513,8 +513,7 @@ init_cmdargs (int argc, char **argv, int skip_args)
513 They are decoded in the function command-line after we know 513 They are decoded in the function command-line after we know
514 locale-coding-system. */ 514 locale-coding-system. */
515 Vcommand_line_args 515 Vcommand_line_args
516 = Fcons (make_unibyte_string (argv[i], strlen (argv[i])), 516 = Fcons (build_unibyte_string (argv[i]), Vcommand_line_args);
517 Vcommand_line_args);
518 } 517 }
519 518
520 unbind_to (count, Qnil); 519 unbind_to (count, Qnil);
@@ -689,7 +688,8 @@ main (int argc, char **argv)
689 stack_bottom = &stack_bottom_variable; 688 stack_bottom = &stack_bottom_variable;
690 689
691#ifdef G_SLICE_ALWAYS_MALLOC 690#ifdef G_SLICE_ALWAYS_MALLOC
692 /* This is used by the Cygwin build. */ 691 /* This is used by the Cygwin build. It's not needed starting with
692 cygwin-1.7.24, but it doesn't do any harm. */
693 xputenv ("G_SLICE=always-malloc"); 693 xputenv ("G_SLICE=always-malloc");
694#endif 694#endif
695 695
@@ -1398,6 +1398,10 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1398 syms_of_xml (); 1398 syms_of_xml ();
1399#endif 1399#endif
1400 1400
1401#ifdef HAVE_ZLIB
1402 syms_of_decompress ();
1403#endif
1404
1401 syms_of_menu (); 1405 syms_of_menu ();
1402 1406
1403#ifdef HAVE_NTGUI 1407#ifdef HAVE_NTGUI
diff --git a/src/eval.c b/src/eval.c
index e93c3473ae8..d36defc8fe4 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -678,6 +678,51 @@ The return value is BASE-VARIABLE. */)
678 return base_variable; 678 return base_variable;
679} 679}
680 680
681static union specbinding *
682default_toplevel_binding (Lisp_Object symbol)
683{
684 union specbinding *binding = NULL;
685 union specbinding *pdl = specpdl_ptr;
686 while (pdl > specpdl)
687 {
688 switch ((--pdl)->kind)
689 {
690 case SPECPDL_LET_DEFAULT:
691 case SPECPDL_LET:
692 if (EQ (specpdl_symbol (pdl), symbol))
693 binding = pdl;
694 break;
695 }
696 }
697 return binding;
698}
699
700DEFUN ("default-toplevel-value", Fdefault_toplevel_value, Sdefault_toplevel_value, 1, 1, 0,
701 doc: /* Return SYMBOL's toplevel default value.
702"Toplevel" means outside of any let binding. */)
703 (Lisp_Object symbol)
704{
705 union specbinding *binding = default_toplevel_binding (symbol);
706 Lisp_Object value
707 = binding ? specpdl_old_value (binding) : Fdefault_value (symbol);
708 if (!EQ (value, Qunbound))
709 return value;
710 xsignal1 (Qvoid_variable, symbol);
711}
712
713DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value,
714 Sset_default_toplevel_value, 2, 2, 0,
715 doc: /* Set SYMBOL's toplevel default value to VALUE.
716"Toplevel" means outside of any let binding. */)
717 (Lisp_Object symbol, Lisp_Object value)
718{
719 union specbinding *binding = default_toplevel_binding (symbol);
720 if (binding)
721 set_specpdl_old_value (binding, value);
722 else
723 Fset_default (symbol, value);
724 return Qnil;
725}
681 726
682DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, 727DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
683 doc: /* Define SYMBOL as a variable, and return SYMBOL. 728 doc: /* Define SYMBOL as a variable, and return SYMBOL.
@@ -726,18 +771,10 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
726 else 771 else
727 { /* Check if there is really a global binding rather than just a let 772 { /* Check if there is really a global binding rather than just a let
728 binding that shadows the global unboundness of the var. */ 773 binding that shadows the global unboundness of the var. */
729 union specbinding *pdl = specpdl_ptr; 774 union specbinding *binding = default_toplevel_binding (sym);
730 while (pdl > specpdl) 775 if (binding && EQ (specpdl_old_value (binding), Qunbound))
731 { 776 {
732 if ((--pdl)->kind >= SPECPDL_LET 777 set_specpdl_old_value (binding, eval_sub (XCAR (tail)));
733 && EQ (specpdl_symbol (pdl), sym)
734 && EQ (specpdl_old_value (pdl), Qunbound))
735 {
736 message_with_string
737 ("Warning: defvar ignored because %s is let-bound",
738 SYMBOL_NAME (sym), 1);
739 break;
740 }
741 } 778 }
742 } 779 }
743 tail = XCDR (tail); 780 tail = XCDR (tail);
@@ -3325,53 +3362,50 @@ do_one_unbind (union specbinding *this_binding, int unwinding)
3325 switch (this_binding->kind) 3362 switch (this_binding->kind)
3326 { 3363 {
3327 case SPECPDL_UNWIND: 3364 case SPECPDL_UNWIND:
3328 specpdl_ptr->unwind.func (specpdl_ptr->unwind.arg); 3365 this_binding->unwind.func (this_binding->unwind.arg);
3329 break; 3366 break;
3330 case SPECPDL_UNWIND_PTR: 3367 case SPECPDL_UNWIND_PTR:
3331 specpdl_ptr->unwind_ptr.func (specpdl_ptr->unwind_ptr.arg); 3368 this_binding->unwind_ptr.func (this_binding->unwind_ptr.arg);
3332 break; 3369 break;
3333 case SPECPDL_UNWIND_INT: 3370 case SPECPDL_UNWIND_INT:
3334 specpdl_ptr->unwind_int.func (specpdl_ptr->unwind_int.arg); 3371 this_binding->unwind_int.func (this_binding->unwind_int.arg);
3335 break; 3372 break;
3336 case SPECPDL_UNWIND_VOID: 3373 case SPECPDL_UNWIND_VOID:
3337 specpdl_ptr->unwind_void.func (); 3374 this_binding->unwind_void.func ();
3338 break; 3375 break;
3339 case SPECPDL_BACKTRACE: 3376 case SPECPDL_BACKTRACE:
3340 break; 3377 break;
3341 case SPECPDL_LET: 3378 case SPECPDL_LET:
3342 /* If variable has a trivial value (no forwarding), we can 3379 { /* If variable has a trivial value (no forwarding), we can
3343 just set it. No need to check for constant symbols here, 3380 just set it. No need to check for constant symbols here,
3344 since that was already done by specbind. */ 3381 since that was already done by specbind. */
3345 if (XSYMBOL (specpdl_symbol (this_binding))->redirect 3382 struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (this_binding));
3346 == SYMBOL_PLAINVAL) 3383 if (sym->redirect == SYMBOL_PLAINVAL)
3347 SET_SYMBOL_VAL (XSYMBOL (specpdl_symbol (this_binding)), 3384 {
3348 specpdl_old_value (this_binding)); 3385 SET_SYMBOL_VAL (sym, specpdl_old_value (this_binding));
3349 else 3386 break;
3350 /* NOTE: we only ever come here if make_local_foo was used for 3387 }
3351 the first time on this var within this let. */ 3388 else
3352 Fset_default (specpdl_symbol (this_binding), 3389 { /* FALLTHROUGH!!
3353 specpdl_old_value (this_binding)); 3390 NOTE: we only ever come here if make_local_foo was used for
3391 the first time on this var within this let. */
3392 }
3393 }
3394 case SPECPDL_LET_DEFAULT:
3395 Fset_default (specpdl_symbol (this_binding),
3396 specpdl_old_value (this_binding));
3354 break; 3397 break;
3355 case SPECPDL_LET_LOCAL: 3398 case SPECPDL_LET_LOCAL:
3356 case SPECPDL_LET_DEFAULT: 3399 {
3357 { /* If the symbol is a list, it is really (SYMBOL WHERE
3358 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3359 frame. If WHERE is a buffer or frame, this indicates we
3360 bound a variable that had a buffer-local or frame-local
3361 binding. WHERE nil means that the variable had the default
3362 value when it was bound. CURRENT-BUFFER is the buffer that
3363 was current when the variable was bound. */
3364 Lisp_Object symbol = specpdl_symbol (this_binding); 3400 Lisp_Object symbol = specpdl_symbol (this_binding);
3365 Lisp_Object where = specpdl_where (this_binding); 3401 Lisp_Object where = specpdl_where (this_binding);
3402 Lisp_Object old_value = specpdl_old_value (this_binding);
3366 eassert (BUFFERP (where)); 3403 eassert (BUFFERP (where));
3367 3404
3368 if (this_binding->kind == SPECPDL_LET_DEFAULT)
3369 Fset_default (symbol, specpdl_old_value (this_binding));
3370 /* If this was a local binding, reset the value in the appropriate 3405 /* If this was a local binding, reset the value in the appropriate
3371 buffer, but only if that buffer's binding still exists. */ 3406 buffer, but only if that buffer's binding still exists. */
3372 else if (!NILP (Flocal_variable_p (symbol, where))) 3407 if (!NILP (Flocal_variable_p (symbol, where)))
3373 set_internal (symbol, specpdl_old_value (this_binding), 3408 set_internal (symbol, old_value, where, 1);
3374 where, 1);
3375 } 3409 }
3376 break; 3410 break;
3377 } 3411 }
@@ -3406,6 +3440,16 @@ clear_unwind_protect (ptrdiff_t count)
3406 previous value without invoking it. */ 3440 previous value without invoking it. */
3407 3441
3408void 3442void
3443set_unwind_protect (ptrdiff_t count, void (*func) (Lisp_Object),
3444 Lisp_Object arg)
3445{
3446 union specbinding *p = specpdl + count;
3447 p->unwind.kind = SPECPDL_UNWIND;
3448 p->unwind.func = func;
3449 p->unwind.arg = arg;
3450}
3451
3452void
3409set_unwind_protect_ptr (ptrdiff_t count, void (*func) (void *), void *arg) 3453set_unwind_protect_ptr (ptrdiff_t count, void (*func) (void *), void *arg)
3410{ 3454{
3411 union specbinding *p = specpdl + count; 3455 union specbinding *p = specpdl + count;
@@ -3592,7 +3636,7 @@ nearest activation frame. */)
3592 directly in the pre-existing specpdl elements (i.e. we swap the current 3636 directly in the pre-existing specpdl elements (i.e. we swap the current
3593 value and the old value stored in the specpdl), kind of like the inplace 3637 value and the old value stored in the specpdl), kind of like the inplace
3594 pointer-reversal trick. As it turns out, the rewind does the same as the 3638 pointer-reversal trick. As it turns out, the rewind does the same as the
3595 unwind, except it starts from the other end of the spepdl stack, so we use 3639 unwind, except it starts from the other end of the specpdl stack, so we use
3596 the same function for both unwind and rewind. */ 3640 the same function for both unwind and rewind. */
3597static void 3641static void
3598backtrace_eval_unrewind (int distance) 3642backtrace_eval_unrewind (int distance)
@@ -3622,24 +3666,23 @@ backtrace_eval_unrewind (int distance)
3622 case SPECPDL_BACKTRACE: 3666 case SPECPDL_BACKTRACE:
3623 break; 3667 break;
3624 case SPECPDL_LET: 3668 case SPECPDL_LET:
3625 /* If variable has a trivial value (no forwarding), we can 3669 { /* If variable has a trivial value (no forwarding), we can
3626 just set it. No need to check for constant symbols here, 3670 just set it. No need to check for constant symbols here,
3627 since that was already done by specbind. */ 3671 since that was already done by specbind. */
3628 if (XSYMBOL (specpdl_symbol (tmp))->redirect 3672 struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (tmp));
3629 == SYMBOL_PLAINVAL) 3673 if (sym->redirect == SYMBOL_PLAINVAL)
3630 { 3674 {
3631 struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (tmp)); 3675 Lisp_Object old_value = specpdl_old_value (tmp);
3632 Lisp_Object old_value = specpdl_old_value (tmp); 3676 set_specpdl_old_value (tmp, SYMBOL_VAL (sym));
3633 set_specpdl_old_value (tmp, SYMBOL_VAL (sym)); 3677 SET_SYMBOL_VAL (sym, old_value);
3634 SET_SYMBOL_VAL (sym, old_value); 3678 break;
3635 break; 3679 }
3636 } 3680 else
3637 else 3681 { /* FALLTHROUGH!!
3638 { 3682 NOTE: we only ever come here if make_local_foo was used for
3639 /* FALLTHROUGH! 3683 the first time on this var within this let. */
3640 NOTE: we only ever come here if make_local_foo was used for 3684 }
3641 the first time on this var within this let. */ 3685 }
3642 }
3643 case SPECPDL_LET_DEFAULT: 3686 case SPECPDL_LET_DEFAULT:
3644 { 3687 {
3645 Lisp_Object sym = specpdl_symbol (tmp); 3688 Lisp_Object sym = specpdl_symbol (tmp);
@@ -3908,6 +3951,8 @@ alist of active lexical bindings. */);
3908 defsubr (&Ssetq); 3951 defsubr (&Ssetq);
3909 defsubr (&Squote); 3952 defsubr (&Squote);
3910 defsubr (&Sfunction); 3953 defsubr (&Sfunction);
3954 defsubr (&Sdefault_toplevel_value);
3955 defsubr (&Sset_default_toplevel_value);
3911 defsubr (&Sdefvar); 3956 defsubr (&Sdefvar);
3912 defsubr (&Sdefvaralias); 3957 defsubr (&Sdefvaralias);
3913 defsubr (&Sdefconst); 3958 defsubr (&Sdefconst);
diff --git a/src/fileio.c b/src/fileio.c
index c47b3533145..08caf102266 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -366,8 +366,7 @@ Given a Unix syntax file name, returns a string ending in slash. */)
366 } 366 }
367 367
368#ifdef DOS_NT 368#ifdef DOS_NT
369 beg = alloca (SBYTES (filename) + 1); 369 beg = xlispstrdupa (filename);
370 memcpy (beg, SSDATA (filename), SBYTES (filename) + 1);
371#else 370#else
372 beg = SSDATA (filename); 371 beg = SSDATA (filename);
373#endif 372#endif
@@ -944,8 +943,7 @@ filesystem tree, not (expand-file-name ".." dirname). */)
944#endif 943#endif
945 944
946 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */ 945 /* Make a local copy of nm[] to protect it from GC in DECODE_FILE below. */
947 nm = alloca (SBYTES (name) + 1); 946 nm = xlispstrdupa (name);
948 memcpy (nm, SSDATA (name), SBYTES (name) + 1);
949 947
950#ifdef DOS_NT 948#ifdef DOS_NT
951 /* Note if special escape prefix is present, but remove for now. */ 949 /* Note if special escape prefix is present, but remove for now. */
@@ -1693,8 +1691,7 @@ those `/' is discarded. */)
1693 /* Always work on a copy of the string, in case GC happens during 1691 /* Always work on a copy of the string, in case GC happens during
1694 decode of environment variables, causing the original Lisp_String 1692 decode of environment variables, causing the original Lisp_String
1695 data to be relocated. */ 1693 data to be relocated. */
1696 nm = alloca (SBYTES (filename) + 1); 1694 nm = xlispstrdupa (filename);
1697 memcpy (nm, SDATA (filename), SBYTES (filename) + 1);
1698 1695
1699#ifdef DOS_NT 1696#ifdef DOS_NT
1700 dostounix_filename (nm, multibyte); 1697 dostounix_filename (nm, multibyte);
@@ -4746,25 +4743,39 @@ This does code conversion according to the value of
4746 4743
4747This calls `write-region-annotate-functions' at the start, and 4744This calls `write-region-annotate-functions' at the start, and
4748`write-region-post-annotation-function' at the end. */) 4745`write-region-post-annotation-function' at the end. */)
4749 (Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append, Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew) 4746 (Lisp_Object start, Lisp_Object end, Lisp_Object filename, Lisp_Object append,
4747 Lisp_Object visit, Lisp_Object lockname, Lisp_Object mustbenew)
4748{
4749 return write_region (start, end, filename, append, visit, lockname, mustbenew,
4750 -1);
4751}
4752
4753/* Like Fwrite_region, except that if DESC is nonnegative, it is a file
4754 descriptor for FILENAME, so do not open or close FILENAME. */
4755
4756Lisp_Object
4757write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4758 Lisp_Object append, Lisp_Object visit, Lisp_Object lockname,
4759 Lisp_Object mustbenew, int desc)
4750{ 4760{
4751 int desc;
4752 int open_flags; 4761 int open_flags;
4753 int mode; 4762 int mode;
4754 off_t offset IF_LINT (= 0); 4763 off_t offset IF_LINT (= 0);
4764 bool open_and_close_file = desc < 0;
4755 bool ok; 4765 bool ok;
4756 int save_errno = 0; 4766 int save_errno = 0;
4757 const char *fn; 4767 const char *fn;
4758 struct stat st; 4768 struct stat st;
4759 EMACS_TIME modtime; 4769 EMACS_TIME modtime;
4760 ptrdiff_t count = SPECPDL_INDEX (); 4770 ptrdiff_t count = SPECPDL_INDEX ();
4761 ptrdiff_t count1; 4771 ptrdiff_t count1 IF_LINT (= 0);
4762 Lisp_Object handler; 4772 Lisp_Object handler;
4763 Lisp_Object visit_file; 4773 Lisp_Object visit_file;
4764 Lisp_Object annotations; 4774 Lisp_Object annotations;
4765 Lisp_Object encoded_filename; 4775 Lisp_Object encoded_filename;
4766 bool visiting = (EQ (visit, Qt) || STRINGP (visit)); 4776 bool visiting = (EQ (visit, Qt) || STRINGP (visit));
4767 bool quietly = !NILP (visit); 4777 bool quietly = !NILP (visit);
4778 bool file_locked = 0;
4768 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 4779 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
4769 struct buffer *given_buffer; 4780 struct buffer *given_buffer;
4770 struct coding_system coding; 4781 struct coding_system coding;
@@ -4832,7 +4843,6 @@ This calls `write-region-annotate-functions' at the start, and
4832 record_unwind_protect (build_annotations_unwind, 4843 record_unwind_protect (build_annotations_unwind,
4833 Vwrite_region_annotation_buffers); 4844 Vwrite_region_annotation_buffers);
4834 Vwrite_region_annotation_buffers = list1 (Fcurrent_buffer ()); 4845 Vwrite_region_annotation_buffers = list1 (Fcurrent_buffer ());
4835 count1 = SPECPDL_INDEX ();
4836 4846
4837 given_buffer = current_buffer; 4847 given_buffer = current_buffer;
4838 4848
@@ -4871,8 +4881,11 @@ This calls `write-region-annotate-functions' at the start, and
4871 coding.mode |= CODING_MODE_SELECTIVE_DISPLAY; 4881 coding.mode |= CODING_MODE_SELECTIVE_DISPLAY;
4872 4882
4873#ifdef CLASH_DETECTION 4883#ifdef CLASH_DETECTION
4874 if (!auto_saving) 4884 if (open_and_close_file && !auto_saving)
4875 lock_file (lockname); 4885 {
4886 lock_file (lockname);
4887 file_locked = 1;
4888 }
4876#endif /* CLASH_DETECTION */ 4889#endif /* CLASH_DETECTION */
4877 4890
4878 encoded_filename = ENCODE_FILE (filename); 4891 encoded_filename = ENCODE_FILE (filename);
@@ -4889,19 +4902,23 @@ This calls `write-region-annotate-functions' at the start, and
4889 mode = auto_saving ? auto_save_mode_bits : 0666; 4902 mode = auto_saving ? auto_save_mode_bits : 0666;
4890#endif 4903#endif
4891 4904
4892 desc = emacs_open (fn, open_flags, mode); 4905 if (open_and_close_file)
4893
4894 if (desc < 0)
4895 { 4906 {
4896 int open_errno = errno; 4907 desc = emacs_open (fn, open_flags, mode);
4908 if (desc < 0)
4909 {
4910 int open_errno = errno;
4897#ifdef CLASH_DETECTION 4911#ifdef CLASH_DETECTION
4898 if (!auto_saving) unlock_file (lockname); 4912 if (file_locked)
4913 unlock_file (lockname);
4899#endif /* CLASH_DETECTION */ 4914#endif /* CLASH_DETECTION */
4900 UNGCPRO; 4915 UNGCPRO;
4901 report_file_errno ("Opening output file", filename, open_errno); 4916 report_file_errno ("Opening output file", filename, open_errno);
4902 } 4917 }
4903 4918
4904 record_unwind_protect_int (close_file_unwind, desc); 4919 count1 = SPECPDL_INDEX ();
4920 record_unwind_protect_int (close_file_unwind, desc);
4921 }
4905 4922
4906 if (NUMBERP (append)) 4923 if (NUMBERP (append))
4907 { 4924 {
@@ -4910,7 +4927,8 @@ This calls `write-region-annotate-functions' at the start, and
4910 { 4927 {
4911 int lseek_errno = errno; 4928 int lseek_errno = errno;
4912#ifdef CLASH_DETECTION 4929#ifdef CLASH_DETECTION
4913 if (!auto_saving) unlock_file (lockname); 4930 if (file_locked)
4931 unlock_file (lockname);
4914#endif /* CLASH_DETECTION */ 4932#endif /* CLASH_DETECTION */
4915 UNGCPRO; 4933 UNGCPRO;
4916 report_file_errno ("Lseek error", filename, lseek_errno); 4934 report_file_errno ("Lseek error", filename, lseek_errno);
@@ -4945,9 +4963,9 @@ This calls `write-region-annotate-functions' at the start, and
4945 4963
4946 immediate_quit = 0; 4964 immediate_quit = 0;
4947 4965
4948 /* fsync is not crucial for auto-save files, since they might lose 4966 /* fsync is not crucial for temporary files. Nor for auto-save
4949 some work anyway. */ 4967 files, since they might lose some work anyway. */
4950 if (!auto_saving && !write_region_inhibit_fsync) 4968 if (open_and_close_file && !auto_saving && !write_region_inhibit_fsync)
4951 { 4969 {
4952 /* Transfer data and metadata to disk, retrying if interrupted. 4970 /* Transfer data and metadata to disk, retrying if interrupted.
4953 fsync can report a write failure here, e.g., due to disk full 4971 fsync can report a write failure here, e.g., due to disk full
@@ -4971,12 +4989,15 @@ This calls `write-region-annotate-functions' at the start, and
4971 ok = 0, save_errno = errno; 4989 ok = 0, save_errno = errno;
4972 } 4990 }
4973 4991
4974 /* NFS can report a write failure now. */ 4992 if (open_and_close_file)
4975 if (emacs_close (desc) < 0) 4993 {
4976 ok = 0, save_errno = errno; 4994 /* NFS can report a write failure now. */
4995 if (emacs_close (desc) < 0)
4996 ok = 0, save_errno = errno;
4977 4997
4978 /* Discard the unwind protect for close_file_unwind. */ 4998 /* Discard the unwind protect for close_file_unwind. */
4979 specpdl_ptr = specpdl + count1; 4999 specpdl_ptr = specpdl + count1;
5000 }
4980 5001
4981 /* Some file systems have a bug where st_mtime is not updated 5002 /* Some file systems have a bug where st_mtime is not updated
4982 properly after a write. For example, CIFS might not see the 5003 properly after a write. For example, CIFS might not see the
@@ -5052,7 +5073,7 @@ This calls `write-region-annotate-functions' at the start, and
5052 unbind_to (count, Qnil); 5073 unbind_to (count, Qnil);
5053 5074
5054#ifdef CLASH_DETECTION 5075#ifdef CLASH_DETECTION
5055 if (!auto_saving) 5076 if (file_locked)
5056 unlock_file (lockname); 5077 unlock_file (lockname);
5057#endif /* CLASH_DETECTION */ 5078#endif /* CLASH_DETECTION */
5058 5079
@@ -5096,8 +5117,6 @@ This calls `write-region-annotate-functions' at the start, and
5096 return Qnil; 5117 return Qnil;
5097} 5118}
5098 5119
5099Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
5100
5101DEFUN ("car-less-than-car", Fcar_less_than_car, Scar_less_than_car, 2, 2, 0, 5120DEFUN ("car-less-than-car", Fcar_less_than_car, Scar_less_than_car, 2, 2, 0,
5102 doc: /* Return t if (car A) is numerically less than (car B). */) 5121 doc: /* Return t if (car A) is numerically less than (car B). */)
5103 (Lisp_Object a, Lisp_Object b) 5122 (Lisp_Object a, Lisp_Object b)
@@ -5620,9 +5639,8 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5620 couldn't handle some ange-ftp'd file. */ 5639 couldn't handle some ange-ftp'd file. */
5621 5640
5622 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) 5641 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++)
5623 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 5642 FOR_EACH_LIVE_BUFFER (tail, buf)
5624 { 5643 {
5625 buf = XCDR (XCAR (tail));
5626 b = XBUFFER (buf); 5644 b = XBUFFER (buf);
5627 5645
5628 /* Record all the buffers that have auto save mode 5646 /* Record all the buffers that have auto save mode
diff --git a/src/filelock.c b/src/filelock.c
index b9c991e4baf..df72eff5950 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -181,7 +181,7 @@ get_boot_time (void)
181 since utmp is typically much smaller than wtmp. 181 since utmp is typically much smaller than wtmp.
182 Passing a null pointer causes get_boot_time_1 182 Passing a null pointer causes get_boot_time_1
183 to inspect the default file, namely utmp. */ 183 to inspect the default file, namely utmp. */
184 get_boot_time_1 ((char *) 0, 0); 184 get_boot_time_1 (0, 0);
185 if (boot_time) 185 if (boot_time)
186 return boot_time; 186 return boot_time;
187 187
@@ -411,28 +411,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
411 memcpy (nonce, lfname, lfdirlen); 411 memcpy (nonce, lfname, lfdirlen);
412 strcpy (nonce + lfdirlen, nonce_base); 412 strcpy (nonce + lfdirlen, nonce_base);
413 413
414#if HAVE_MKOSTEMP
415 /* Prefer mkostemp to mkstemp, as it avoids a window where FD is
416 temporarily open without close-on-exec. */
417 fd = mkostemp (nonce, O_BINARY | O_CLOEXEC); 414 fd = mkostemp (nonce, O_BINARY | O_CLOEXEC);
418#elif HAVE_MKSTEMP
419 /* Prefer mkstemp to mktemp, as it avoids a race between
420 mktemp and emacs_open. */
421 fd = mkstemp (nonce);
422#else
423 mktemp (nonce);
424 fd = emacs_open (nonce, O_WRONLY | O_CREAT | O_EXCL | O_BINARY,
425 S_IRUSR | S_IWUSR);
426#endif
427
428 if (fd < 0) 415 if (fd < 0)
429 err = errno; 416 err = errno;
430 else 417 else
431 { 418 {
432 ptrdiff_t lock_info_len; 419 ptrdiff_t lock_info_len;
433#if ! (HAVE_MKOSTEMP && O_CLOEXEC) 420 if (! O_CLOEXEC)
434 fcntl (fd, F_SETFD, FD_CLOEXEC); 421 fcntl (fd, F_SETFD, FD_CLOEXEC);
435#endif
436 lock_info_len = strlen (lock_info_str); 422 lock_info_len = strlen (lock_info_str);
437 err = 0; 423 err = 0;
438 /* Use 'write', not 'emacs_write', as garbage collection 424 /* Use 'write', not 'emacs_write', as garbage collection
@@ -759,16 +745,15 @@ unlock_file (Lisp_Object fn)
759void 745void
760unlock_all_files (void) 746unlock_all_files (void)
761{ 747{
762 register Lisp_Object tail; 748 register Lisp_Object tail, buf;
763 register struct buffer *b; 749 register struct buffer *b;
764 750
765 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) 751 FOR_EACH_LIVE_BUFFER (tail, buf)
766 { 752 {
767 b = XBUFFER (XCDR (XCAR (tail))); 753 b = XBUFFER (buf);
768 if (STRINGP (BVAR (b, file_truename)) && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) 754 if (STRINGP (BVAR (b, file_truename))
769 { 755 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
770 unlock_file (BVAR (b, file_truename)); 756 unlock_file (BVAR (b, file_truename));
771 }
772 } 757 }
773} 758}
774 759
diff --git a/src/fns.c b/src/fns.c
index 9fd0ad2a9d1..de90fd731fb 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -146,8 +146,6 @@ To get the number of bytes, use `string-bytes'. */)
146 return val; 146 return val;
147} 147}
148 148
149/* This does not check for quits. That is safe since it must terminate. */
150
151DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0, 149DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0,
152 doc: /* Return the length of a list, but avoid error or infinite loop. 150 doc: /* Return the length of a list, but avoid error or infinite loop.
153This function never gets an error. If LIST is not really a list, 151This function never gets an error. If LIST is not really a list,
@@ -1740,8 +1738,6 @@ See also the function `nreverse', which is used more often. */)
1740 return new; 1738 return new;
1741} 1739}
1742 1740
1743Lisp_Object merge (Lisp_Object org_l1, Lisp_Object org_l2, Lisp_Object pred);
1744
1745DEFUN ("sort", Fsort, Ssort, 2, 2, 0, 1741DEFUN ("sort", Fsort, Ssort, 2, 2, 0,
1746 doc: /* Sort LIST, stably, comparing elements using PREDICATE. 1742 doc: /* Sort LIST, stably, comparing elements using PREDICATE.
1747Returns the sorted list. LIST is modified by side effects. 1743Returns the sorted list. LIST is modified by side effects.
diff --git a/src/font.c b/src/font.c
index 124d5f9bd9e..6a8262623dc 100644
--- a/src/font.c
+++ b/src/font.c
@@ -204,9 +204,9 @@ font_make_object (int size, Lisp_Object entity, int pixelsize)
204 204
205 205
206 206
207static int font_pixel_size (FRAME_PTR f, Lisp_Object); 207static int font_pixel_size (struct frame *f, Lisp_Object);
208static Lisp_Object font_open_entity (FRAME_PTR, Lisp_Object, int); 208static Lisp_Object font_open_entity (struct frame *, Lisp_Object, int);
209static Lisp_Object font_matching_entity (FRAME_PTR, Lisp_Object *, 209static Lisp_Object font_matching_entity (struct frame *, Lisp_Object *,
210 Lisp_Object); 210 Lisp_Object);
211static unsigned font_encode_char (Lisp_Object, int); 211static unsigned font_encode_char (Lisp_Object, int);
212 212
@@ -269,7 +269,7 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
269/* Return a pixel size of font-spec SPEC on frame F. */ 269/* Return a pixel size of font-spec SPEC on frame F. */
270 270
271static int 271static int
272font_pixel_size (FRAME_PTR f, Lisp_Object spec) 272font_pixel_size (struct frame *f, Lisp_Object spec)
273{ 273{
274#ifdef HAVE_WINDOW_SYSTEM 274#ifdef HAVE_WINDOW_SYSTEM
275 Lisp_Object size = AREF (spec, FONT_SIZE_INDEX); 275 Lisp_Object size = AREF (spec, FONT_SIZE_INDEX);
@@ -2037,11 +2037,6 @@ font_otf_Anchor (OTF_Anchor *anchor)
2037 2037
2038/* Font sorting. */ 2038/* Font sorting. */
2039 2039
2040static unsigned font_score (Lisp_Object, Lisp_Object *);
2041static int font_compare (const void *, const void *);
2042static Lisp_Object font_sort_entities (Lisp_Object, Lisp_Object,
2043 Lisp_Object, int);
2044
2045static double 2040static double
2046font_rescale_ratio (Lisp_Object font_entity) 2041font_rescale_ratio (Lisp_Object font_entity)
2047{ 2042{
@@ -2186,14 +2181,14 @@ font_compare (const void *d1, const void *d2)
2186 such a case. */ 2181 such a case. */
2187 2182
2188static Lisp_Object 2183static Lisp_Object
2189font_sort_entities (Lisp_Object list, Lisp_Object prefer, Lisp_Object frame, int best_only) 2184font_sort_entities (Lisp_Object list, Lisp_Object prefer,
2185 struct frame *f, int best_only)
2190{ 2186{
2191 Lisp_Object prefer_prop[FONT_SPEC_MAX]; 2187 Lisp_Object prefer_prop[FONT_SPEC_MAX];
2192 int len, maxlen, i; 2188 int len, maxlen, i;
2193 struct font_sort_data *data; 2189 struct font_sort_data *data;
2194 unsigned best_score; 2190 unsigned best_score;
2195 Lisp_Object best_entity; 2191 Lisp_Object best_entity;
2196 struct frame *f = XFRAME (frame);
2197 Lisp_Object tail, vec IF_LINT (= Qnil); 2192 Lisp_Object tail, vec IF_LINT (= Qnil);
2198 USE_SAFE_ALLOCA; 2193 USE_SAFE_ALLOCA;
2199 2194
@@ -2201,7 +2196,7 @@ font_sort_entities (Lisp_Object list, Lisp_Object prefer, Lisp_Object frame, int
2201 prefer_prop[i] = AREF (prefer, i); 2196 prefer_prop[i] = AREF (prefer, i);
2202 if (FLOATP (prefer_prop[FONT_SIZE_INDEX])) 2197 if (FLOATP (prefer_prop[FONT_SIZE_INDEX]))
2203 prefer_prop[FONT_SIZE_INDEX] 2198 prefer_prop[FONT_SIZE_INDEX]
2204 = make_number (font_pixel_size (XFRAME (frame), prefer)); 2199 = make_number (font_pixel_size (f, prefer));
2205 2200
2206 if (NILP (XCDR (list))) 2201 if (NILP (XCDR (list)))
2207 { 2202 {
@@ -2502,14 +2497,14 @@ font_match_p (Lisp_Object spec, Lisp_Object font)
2502 is a number frames sharing this cache, and FONT-CACHE-DATA is a 2497 is a number frames sharing this cache, and FONT-CACHE-DATA is a
2503 cons (FONT-SPEC FONT-ENTITY ...). */ 2498 cons (FONT-SPEC FONT-ENTITY ...). */
2504 2499
2505static void font_prepare_cache (FRAME_PTR, struct font_driver *); 2500static void font_prepare_cache (struct frame *, struct font_driver *);
2506static void font_finish_cache (FRAME_PTR, struct font_driver *); 2501static void font_finish_cache (struct frame *, struct font_driver *);
2507static Lisp_Object font_get_cache (FRAME_PTR, struct font_driver *); 2502static Lisp_Object font_get_cache (struct frame *, struct font_driver *);
2508static void font_clear_cache (FRAME_PTR, Lisp_Object, 2503static void font_clear_cache (struct frame *, Lisp_Object,
2509 struct font_driver *); 2504 struct font_driver *);
2510 2505
2511static void 2506static void
2512font_prepare_cache (FRAME_PTR f, struct font_driver *driver) 2507font_prepare_cache (struct frame *f, struct font_driver *driver)
2513{ 2508{
2514 Lisp_Object cache, val; 2509 Lisp_Object cache, val;
2515 2510
@@ -2531,7 +2526,7 @@ font_prepare_cache (FRAME_PTR f, struct font_driver *driver)
2531 2526
2532 2527
2533static void 2528static void
2534font_finish_cache (FRAME_PTR f, struct font_driver *driver) 2529font_finish_cache (struct frame *f, struct font_driver *driver)
2535{ 2530{
2536 Lisp_Object cache, val, tmp; 2531 Lisp_Object cache, val, tmp;
2537 2532
@@ -2552,7 +2547,7 @@ font_finish_cache (FRAME_PTR f, struct font_driver *driver)
2552 2547
2553 2548
2554static Lisp_Object 2549static Lisp_Object
2555font_get_cache (FRAME_PTR f, struct font_driver *driver) 2550font_get_cache (struct frame *f, struct font_driver *driver)
2556{ 2551{
2557 Lisp_Object val = driver->get_cache (f); 2552 Lisp_Object val = driver->get_cache (f);
2558 Lisp_Object type = driver->type; 2553 Lisp_Object type = driver->type;
@@ -2567,7 +2562,7 @@ font_get_cache (FRAME_PTR f, struct font_driver *driver)
2567 2562
2568 2563
2569static void 2564static void
2570font_clear_cache (FRAME_PTR f, Lisp_Object cache, struct font_driver *driver) 2565font_clear_cache (struct frame *f, Lisp_Object cache, struct font_driver *driver)
2571{ 2566{
2572 Lisp_Object tail, elt; 2567 Lisp_Object tail, elt;
2573 Lisp_Object tail2, entity; 2568 Lisp_Object tail2, entity;
@@ -2692,9 +2687,8 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
2692 same font-driver. */ 2687 same font-driver. */
2693 2688
2694Lisp_Object 2689Lisp_Object
2695font_list_entities (Lisp_Object frame, Lisp_Object spec) 2690font_list_entities (struct frame *f, Lisp_Object spec)
2696{ 2691{
2697 FRAME_PTR f = XFRAME (frame);
2698 struct font_driver_list *driver_list = f->font_driver_list; 2692 struct font_driver_list *driver_list = f->font_driver_list;
2699 Lisp_Object ftype, val; 2693 Lisp_Object ftype, val;
2700 Lisp_Object list = Qnil; 2694 Lisp_Object list = Qnil;
@@ -2738,7 +2732,7 @@ font_list_entities (Lisp_Object frame, Lisp_Object spec)
2738 { 2732 {
2739 Lisp_Object copy; 2733 Lisp_Object copy;
2740 2734
2741 val = driver_list->driver->list (frame, scratch_font_spec); 2735 val = driver_list->driver->list (f, scratch_font_spec);
2742 if (NILP (val)) 2736 if (NILP (val))
2743 val = zero_vector; 2737 val = zero_vector;
2744 else 2738 else
@@ -2766,14 +2760,12 @@ font_list_entities (Lisp_Object frame, Lisp_Object spec)
2766 font-related attributes. */ 2760 font-related attributes. */
2767 2761
2768static Lisp_Object 2762static Lisp_Object
2769font_matching_entity (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec) 2763font_matching_entity (struct frame *f, Lisp_Object *attrs, Lisp_Object spec)
2770{ 2764{
2771 struct font_driver_list *driver_list = f->font_driver_list; 2765 struct font_driver_list *driver_list = f->font_driver_list;
2772 Lisp_Object ftype, size, entity; 2766 Lisp_Object ftype, size, entity;
2773 Lisp_Object frame;
2774 Lisp_Object work = copy_font_spec (spec); 2767 Lisp_Object work = copy_font_spec (spec);
2775 2768
2776 XSETFRAME (frame, f);
2777 ftype = AREF (spec, FONT_TYPE_INDEX); 2769 ftype = AREF (spec, FONT_TYPE_INDEX);
2778 size = AREF (spec, FONT_SIZE_INDEX); 2770 size = AREF (spec, FONT_SIZE_INDEX);
2779 2771
@@ -2797,7 +2789,7 @@ font_matching_entity (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec)
2797 entity = XCDR (entity); 2789 entity = XCDR (entity);
2798 else 2790 else
2799 { 2791 {
2800 entity = driver_list->driver->match (frame, work); 2792 entity = driver_list->driver->match (f, work);
2801 copy = copy_font_spec (work); 2793 copy = copy_font_spec (work);
2802 ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type); 2794 ASET (copy, FONT_TYPE_INDEX, driver_list->driver->type);
2803 XSETCDR (cache, Fcons (Fcons (copy, entity), XCDR (cache))); 2795 XSETCDR (cache, Fcons (Fcons (copy, entity), XCDR (cache)));
@@ -2814,7 +2806,7 @@ font_matching_entity (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec)
2814 opened font object. */ 2806 opened font object. */
2815 2807
2816static Lisp_Object 2808static Lisp_Object
2817font_open_entity (FRAME_PTR f, Lisp_Object entity, int pixel_size) 2809font_open_entity (struct frame *f, Lisp_Object entity, int pixel_size)
2818{ 2810{
2819 struct font_driver_list *driver_list; 2811 struct font_driver_list *driver_list;
2820 Lisp_Object objlist, size, val, font_object; 2812 Lisp_Object objlist, size, val, font_object;
@@ -2892,7 +2884,7 @@ font_open_entity (FRAME_PTR f, Lisp_Object entity, int pixel_size)
2892/* Close FONT_OBJECT that is opened on frame F. */ 2884/* Close FONT_OBJECT that is opened on frame F. */
2893 2885
2894static void 2886static void
2895font_close_object (FRAME_PTR f, Lisp_Object font_object) 2887font_close_object (struct frame *f, Lisp_Object font_object)
2896{ 2888{
2897 struct font *font = XFONT_OBJECT (font_object); 2889 struct font *font = XFONT_OBJECT (font_object);
2898 2890
@@ -2912,7 +2904,7 @@ font_close_object (FRAME_PTR f, Lisp_Object font_object)
2912 FONT is a font-entity and it must be opened to check. */ 2904 FONT is a font-entity and it must be opened to check. */
2913 2905
2914int 2906int
2915font_has_char (FRAME_PTR f, Lisp_Object font, int c) 2907font_has_char (struct frame *f, Lisp_Object font, int c)
2916{ 2908{
2917 struct font *fontp; 2909 struct font *fontp;
2918 2910
@@ -3039,12 +3031,12 @@ font_clear_prop (Lisp_Object *attrs, enum font_property_index prop)
3039 supports C and is the best match for ATTRS and PIXEL_SIZE. */ 3031 supports C and is the best match for ATTRS and PIXEL_SIZE. */
3040 3032
3041static Lisp_Object 3033static Lisp_Object
3042font_select_entity (Lisp_Object frame, Lisp_Object entities, Lisp_Object *attrs, int pixel_size, int c) 3034font_select_entity (struct frame *f, Lisp_Object entities,
3035 Lisp_Object *attrs, int pixel_size, int c)
3043{ 3036{
3044 Lisp_Object font_entity; 3037 Lisp_Object font_entity;
3045 Lisp_Object prefer; 3038 Lisp_Object prefer;
3046 int i; 3039 int i;
3047 FRAME_PTR f = XFRAME (frame);
3048 3040
3049 if (NILP (XCDR (entities)) 3041 if (NILP (XCDR (entities))
3050 && ASIZE (XCAR (entities)) == 1) 3042 && ASIZE (XCAR (entities)) == 1)
@@ -3075,7 +3067,7 @@ font_select_entity (Lisp_Object frame, Lisp_Object entities, Lisp_Object *attrs,
3075 FONT_SET_STYLE (prefer, FONT_WIDTH_INDEX, attrs[LFACE_SWIDTH_INDEX]); 3067 FONT_SET_STYLE (prefer, FONT_WIDTH_INDEX, attrs[LFACE_SWIDTH_INDEX]);
3076 ASET (prefer, FONT_SIZE_INDEX, make_number (pixel_size)); 3068 ASET (prefer, FONT_SIZE_INDEX, make_number (pixel_size));
3077 3069
3078 return font_sort_entities (entities, prefer, frame, c); 3070 return font_sort_entities (entities, prefer, f, c);
3079} 3071}
3080 3072
3081/* Return a font-entity that satisfies SPEC and is the best match for 3073/* Return a font-entity that satisfies SPEC and is the best match for
@@ -3083,10 +3075,10 @@ font_select_entity (Lisp_Object frame, Lisp_Object entities, Lisp_Object *attrs,
3083 character that the entity must support. */ 3075 character that the entity must support. */
3084 3076
3085Lisp_Object 3077Lisp_Object
3086font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c) 3078font_find_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec, int c)
3087{ 3079{
3088 Lisp_Object work; 3080 Lisp_Object work;
3089 Lisp_Object frame, entities, val; 3081 Lisp_Object entities, val;
3090 Lisp_Object foundry[3], *family, registry[3], adstyle[3]; 3082 Lisp_Object foundry[3], *family, registry[3], adstyle[3];
3091 int pixel_size; 3083 int pixel_size;
3092 int i, j, k, l; 3084 int i, j, k, l;
@@ -3118,7 +3110,6 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3118 3110
3119 work = copy_font_spec (spec); 3111 work = copy_font_spec (spec);
3120 ASET (work, FONT_TYPE_INDEX, AREF (spec, FONT_TYPE_INDEX)); 3112 ASET (work, FONT_TYPE_INDEX, AREF (spec, FONT_TYPE_INDEX));
3121 XSETFRAME (frame, f);
3122 pixel_size = font_pixel_size (f, spec); 3113 pixel_size = font_pixel_size (f, spec);
3123 if (pixel_size == 0 && INTEGERP (attrs[LFACE_HEIGHT_INDEX])) 3114 if (pixel_size == 0 && INTEGERP (attrs[LFACE_HEIGHT_INDEX]))
3124 { 3115 {
@@ -3212,10 +3203,10 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3212 for (l = 0; SYMBOLP (adstyle[l]); l++) 3203 for (l = 0; SYMBOLP (adstyle[l]); l++)
3213 { 3204 {
3214 ASET (work, FONT_ADSTYLE_INDEX, adstyle[l]); 3205 ASET (work, FONT_ADSTYLE_INDEX, adstyle[l]);
3215 entities = font_list_entities (frame, work); 3206 entities = font_list_entities (f, work);
3216 if (! NILP (entities)) 3207 if (! NILP (entities))
3217 { 3208 {
3218 val = font_select_entity (frame, entities, 3209 val = font_select_entity (f, entities,
3219 attrs, pixel_size, c); 3210 attrs, pixel_size, c);
3220 if (! NILP (val)) 3211 if (! NILP (val))
3221 return val; 3212 return val;
@@ -3231,7 +3222,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c)
3231 3222
3232 3223
3233Lisp_Object 3224Lisp_Object
3234font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_Object spec) 3225font_open_for_lface (struct frame *f, Lisp_Object entity, Lisp_Object *attrs, Lisp_Object spec)
3235{ 3226{
3236 int size; 3227 int size;
3237 3228
@@ -3278,7 +3269,7 @@ font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_O
3278 font-object. */ 3269 font-object. */
3279 3270
3280Lisp_Object 3271Lisp_Object
3281font_load_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec) 3272font_load_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec)
3282{ 3273{
3283 Lisp_Object entity, name; 3274 Lisp_Object entity, name;
3284 3275
@@ -3307,7 +3298,7 @@ font_load_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec)
3307/* Make FACE on frame F ready to use the font opened for FACE. */ 3298/* Make FACE on frame F ready to use the font opened for FACE. */
3308 3299
3309void 3300void
3310font_prepare_for_face (FRAME_PTR f, struct face *face) 3301font_prepare_for_face (struct frame *f, struct face *face)
3311{ 3302{
3312 if (face->font->driver->prepare_face) 3303 if (face->font->driver->prepare_face)
3313 face->font->driver->prepare_face (f, face); 3304 face->font->driver->prepare_face (f, face);
@@ -3317,7 +3308,7 @@ font_prepare_for_face (FRAME_PTR f, struct face *face)
3317/* Make FACE on frame F stop using the font opened for FACE. */ 3308/* Make FACE on frame F stop using the font opened for FACE. */
3318 3309
3319void 3310void
3320font_done_for_face (FRAME_PTR f, struct face *face) 3311font_done_for_face (struct frame *f, struct face *face)
3321{ 3312{
3322 if (face->font->driver->done_face) 3313 if (face->font->driver->done_face)
3323 face->font->driver->done_face (f, face); 3314 face->font->driver->done_face (f, face);
@@ -3329,7 +3320,7 @@ font_done_for_face (FRAME_PTR f, struct face *face)
3329 font is found, return Qnil. */ 3320 font is found, return Qnil. */
3330 3321
3331Lisp_Object 3322Lisp_Object
3332font_open_by_spec (FRAME_PTR f, Lisp_Object spec) 3323font_open_by_spec (struct frame *f, Lisp_Object spec)
3333{ 3324{
3334 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 3325 Lisp_Object attrs[LFACE_VECTOR_SIZE];
3335 3326
@@ -3353,7 +3344,7 @@ font_open_by_spec (FRAME_PTR f, Lisp_Object spec)
3353 found, return Qnil. */ 3344 found, return Qnil. */
3354 3345
3355Lisp_Object 3346Lisp_Object
3356font_open_by_name (FRAME_PTR f, Lisp_Object name) 3347font_open_by_name (struct frame *f, Lisp_Object name)
3357{ 3348{
3358 Lisp_Object args[2]; 3349 Lisp_Object args[2];
3359 Lisp_Object spec, ret; 3350 Lisp_Object spec, ret;
@@ -3383,7 +3374,7 @@ font_open_by_name (FRAME_PTR f, Lisp_Object name)
3383 (e.g. syms_of_xfont). */ 3374 (e.g. syms_of_xfont). */
3384 3375
3385void 3376void
3386register_font_driver (struct font_driver *driver, FRAME_PTR f) 3377register_font_driver (struct font_driver *driver, struct frame *f)
3387{ 3378{
3388 struct font_driver_list *root = f ? f->font_driver_list : font_driver_list; 3379 struct font_driver_list *root = f ? f->font_driver_list : font_driver_list;
3389 struct font_driver_list *prev, *list; 3380 struct font_driver_list *prev, *list;
@@ -3411,7 +3402,7 @@ register_font_driver (struct font_driver *driver, FRAME_PTR f)
3411} 3402}
3412 3403
3413void 3404void
3414free_font_driver_list (FRAME_PTR f) 3405free_font_driver_list (struct frame *f)
3415{ 3406{
3416 struct font_driver_list *list, *next; 3407 struct font_driver_list *list, *next;
3417 3408
@@ -3433,7 +3424,7 @@ free_font_driver_list (FRAME_PTR f)
3433 F. */ 3424 F. */
3434 3425
3435Lisp_Object 3426Lisp_Object
3436font_update_drivers (FRAME_PTR f, Lisp_Object new_drivers) 3427font_update_drivers (struct frame *f, Lisp_Object new_drivers)
3437{ 3428{
3438 Lisp_Object active_drivers = Qnil; 3429 Lisp_Object active_drivers = Qnil;
3439 struct font_driver_list *list; 3430 struct font_driver_list *list;
@@ -3522,7 +3513,7 @@ font_update_drivers (FRAME_PTR f, Lisp_Object new_drivers)
3522} 3513}
3523 3514
3524int 3515int
3525font_put_frame_data (FRAME_PTR f, struct font_driver *driver, void *data) 3516font_put_frame_data (struct frame *f, struct font_driver *driver, void *data)
3526{ 3517{
3527 struct font_data_list *list, *prev; 3518 struct font_data_list *list, *prev;
3528 3519
@@ -3556,7 +3547,7 @@ font_put_frame_data (FRAME_PTR f, struct font_driver *driver, void *data)
3556 3547
3557 3548
3558void * 3549void *
3559font_get_frame_data (FRAME_PTR f, struct font_driver *driver) 3550font_get_frame_data (struct frame *f, struct font_driver *driver)
3560{ 3551{
3561 struct font_data_list *list; 3552 struct font_data_list *list;
3562 3553
@@ -3630,7 +3621,7 @@ static Lisp_Object
3630font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, 3621font_at (int c, ptrdiff_t pos, struct face *face, struct window *w,
3631 Lisp_Object string) 3622 Lisp_Object string)
3632{ 3623{
3633 FRAME_PTR f; 3624 struct frame *f;
3634 bool multibyte; 3625 bool multibyte;
3635 Lisp_Object font_object; 3626 Lisp_Object font_object;
3636 3627
@@ -4110,12 +4101,10 @@ control the order of the returned list. Fonts are sorted by
4110how close they are to PREFER. */) 4101how close they are to PREFER. */)
4111 (Lisp_Object font_spec, Lisp_Object frame, Lisp_Object num, Lisp_Object prefer) 4102 (Lisp_Object font_spec, Lisp_Object frame, Lisp_Object num, Lisp_Object prefer)
4112{ 4103{
4104 struct frame *f = decode_live_frame (frame);
4113 Lisp_Object vec, list; 4105 Lisp_Object vec, list;
4114 EMACS_INT n = 0; 4106 EMACS_INT n = 0;
4115 4107
4116 if (NILP (frame))
4117 frame = selected_frame;
4118 CHECK_LIVE_FRAME (frame);
4119 CHECK_FONT_SPEC (font_spec); 4108 CHECK_FONT_SPEC (font_spec);
4120 if (! NILP (num)) 4109 if (! NILP (num))
4121 { 4110 {
@@ -4127,7 +4116,7 @@ how close they are to PREFER. */)
4127 if (! NILP (prefer)) 4116 if (! NILP (prefer))
4128 CHECK_FONT_SPEC (prefer); 4117 CHECK_FONT_SPEC (prefer);
4129 4118
4130 list = font_list_entities (frame, font_spec); 4119 list = font_list_entities (f, font_spec);
4131 if (NILP (list)) 4120 if (NILP (list))
4132 return Qnil; 4121 return Qnil;
4133 if (NILP (XCDR (list)) 4122 if (NILP (XCDR (list))
@@ -4135,7 +4124,7 @@ how close they are to PREFER. */)
4135 return list1 (AREF (XCAR (list), 0)); 4124 return list1 (AREF (XCAR (list), 0));
4136 4125
4137 if (! NILP (prefer)) 4126 if (! NILP (prefer))
4138 vec = font_sort_entities (list, prefer, frame, 0); 4127 vec = font_sort_entities (list, prefer, f, 0);
4139 else 4128 else
4140 vec = font_vconcat_entity_vectors (list); 4129 vec = font_vconcat_entity_vectors (list);
4141 if (n == 0 || n >= ASIZE (vec)) 4130 if (n == 0 || n >= ASIZE (vec))
@@ -4163,13 +4152,11 @@ If FRAME is omitted or nil, the selected frame is used. */)
4163 struct font_driver_list *driver_list; 4152 struct font_driver_list *driver_list;
4164 Lisp_Object list = Qnil; 4153 Lisp_Object list = Qnil;
4165 4154
4166 XSETFRAME (frame, f);
4167
4168 for (driver_list = f->font_driver_list; driver_list; 4155 for (driver_list = f->font_driver_list; driver_list;
4169 driver_list = driver_list->next) 4156 driver_list = driver_list->next)
4170 if (driver_list->driver->list_family) 4157 if (driver_list->driver->list_family)
4171 { 4158 {
4172 Lisp_Object val = driver_list->driver->list_family (frame); 4159 Lisp_Object val = driver_list->driver->list_family (f);
4173 Lisp_Object tail = list; 4160 Lisp_Object tail = list;
4174 4161
4175 for (; CONSP (val); val = XCDR (val)) 4162 for (; CONSP (val); val = XCDR (val))
@@ -4239,36 +4226,38 @@ the consecutive wildcards are folded into one. */)
4239 return make_string (name, namelen); 4226 return make_string (name, namelen);
4240} 4227}
4241 4228
4229void
4230clear_font_cache (struct frame *f)
4231{
4232 struct font_driver_list *driver_list = f->font_driver_list;
4233
4234 for (; driver_list; driver_list = driver_list->next)
4235 if (driver_list->on)
4236 {
4237 Lisp_Object val, tmp, cache = driver_list->driver->get_cache (f);
4238
4239 val = XCDR (cache);
4240 while (! NILP (val)
4241 && ! EQ (XCAR (XCAR (val)), driver_list->driver->type))
4242 val = XCDR (val);
4243 eassert (! NILP (val));
4244 tmp = XCDR (XCAR (val));
4245 if (XINT (XCAR (tmp)) == 0)
4246 {
4247 font_clear_cache (f, XCAR (val), driver_list->driver);
4248 XSETCDR (cache, XCDR (val));
4249 }
4250 }
4251}
4252
4242DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0, 4253DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0,
4243 doc: /* Clear font cache. */) 4254 doc: /* Clear font cache of each frame. */)
4244 (void) 4255 (void)
4245{ 4256{
4246 Lisp_Object list, frame; 4257 Lisp_Object list, frame;
4247 4258
4248 FOR_EACH_FRAME (list, frame) 4259 FOR_EACH_FRAME (list, frame)
4249 { 4260 clear_font_cache (XFRAME (frame));
4250 FRAME_PTR f = XFRAME (frame);
4251 struct font_driver_list *driver_list = f->font_driver_list;
4252
4253 for (; driver_list; driver_list = driver_list->next)
4254 if (driver_list->on)
4255 {
4256 Lisp_Object cache = driver_list->driver->get_cache (f);
4257 Lisp_Object val, tmp;
4258
4259 val = XCDR (cache);
4260 while (! NILP (val)
4261 && ! EQ (XCAR (XCAR (val)), driver_list->driver->type))
4262 val = XCDR (val);
4263 eassert (! NILP (val));
4264 tmp = XCDR (XCAR (val));
4265 if (XINT (XCAR (tmp)) == 0)
4266 {
4267 font_clear_cache (f, XCAR (val), driver_list->driver);
4268 XSETCDR (cache, XCDR (val));
4269 }
4270 }
4271 }
4272 4261
4273 return Qnil; 4262 return Qnil;
4274} 4263}
@@ -4795,7 +4784,7 @@ Type C-l to recover what previously shown. */)
4795 (Lisp_Object font_object, Lisp_Object string) 4784 (Lisp_Object font_object, Lisp_Object string)
4796{ 4785{
4797 Lisp_Object frame = selected_frame; 4786 Lisp_Object frame = selected_frame;
4798 FRAME_PTR f = XFRAME (frame); 4787 struct frame *f = XFRAME (frame);
4799 struct font *font; 4788 struct font *font;
4800 struct face *face; 4789 struct face *face;
4801 int i, len, width; 4790 int i, len, width;
diff --git a/src/font.h b/src/font.h
index ffed0461ff7..adb4a582fd8 100644
--- a/src/font.h
+++ b/src/font.h
@@ -504,7 +504,7 @@ struct font_driver
504 504
505 /* Return a cache of font-entities on frame F. The cache must be a 505 /* Return a cache of font-entities on frame F. The cache must be a
506 cons whose cdr part is the actual cache area. */ 506 cons whose cdr part is the actual cache area. */
507 Lisp_Object (*get_cache) (FRAME_PTR F); 507 Lisp_Object (*get_cache) (struct frame *f);
508 508
509 /* List fonts exactly matching with FONT_SPEC on FRAME. The value 509 /* List fonts exactly matching with FONT_SPEC on FRAME. The value
510 is a list of font-entities. The font properties to be considered 510 is a list of font-entities. The font properties to be considered
@@ -527,7 +527,7 @@ struct font_driver
527 527
528 This and the following `match' are the only APIs that allocate 528 This and the following `match' are the only APIs that allocate
529 font-entities. */ 529 font-entities. */
530 Lisp_Object (*list) (Lisp_Object frame, Lisp_Object font_spec); 530 Lisp_Object (*list) (struct frame *frame, Lisp_Object font_spec);
531 531
532 /* Return a font-entity most closely matching with FONT_SPEC on 532 /* Return a font-entity most closely matching with FONT_SPEC on
533 FRAME. Which font property to consider, and how to calculate the 533 FRAME. Which font property to consider, and how to calculate the
@@ -536,12 +536,12 @@ struct font_driver
536 536
537 The properties that the font-entity has is the same as `list' 537 The properties that the font-entity has is the same as `list'
538 method. */ 538 method. */
539 Lisp_Object (*match) (Lisp_Object frame, Lisp_Object font_spec); 539 Lisp_Object (*match) (struct frame *f, Lisp_Object spec);
540 540
541 /* Optional. 541 /* Optional.
542 List available families. The value is a list of family names 542 List available families. The value is a list of family names
543 (symbols). */ 543 (symbols). */
544 Lisp_Object (*list_family) (Lisp_Object frame); 544 Lisp_Object (*list_family) (struct frame *f);
545 545
546 /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value). 546 /* Optional (if FONT_EXTRA_INDEX is not Lisp_Save_Value).
547 Free FONT_EXTRA_INDEX field of FONT_ENTITY. */ 547 Free FONT_EXTRA_INDEX field of FONT_ENTITY. */
@@ -549,21 +549,21 @@ struct font_driver
549 549
550 /* Open a font specified by FONT_ENTITY on frame F. If the font is 550 /* Open a font specified by FONT_ENTITY on frame F. If the font is
551 scalable, open it with PIXEL_SIZE. */ 551 scalable, open it with PIXEL_SIZE. */
552 Lisp_Object (*open) (FRAME_PTR f, Lisp_Object font_entity, 552 Lisp_Object (*open) (struct frame *f, Lisp_Object font_entity,
553 int pixel_size); 553 int pixel_size);
554 554
555 /* Close FONT on frame F. */ 555 /* Close FONT on frame F. */
556 void (*close) (FRAME_PTR f, struct font *font); 556 void (*close) (struct frame *f, struct font *font);
557 557
558 /* Optional (if FACE->extra is not used). 558 /* Optional (if FACE->extra is not used).
559 Prepare FACE for displaying characters by FONT on frame F by 559 Prepare FACE for displaying characters by FONT on frame F by
560 storing some data in FACE->extra. If successful, return 0. 560 storing some data in FACE->extra. If successful, return 0.
561 Otherwise, return -1. */ 561 Otherwise, return -1. */
562 int (*prepare_face) (FRAME_PTR f, struct face *face); 562 int (*prepare_face) (struct frame *f, struct face *face);
563 563
564 /* Optional. 564 /* Optional.
565 Done FACE for displaying characters by FACE->font on frame F. */ 565 Done FACE for displaying characters by FACE->font on frame F. */
566 void (*done_face) (FRAME_PTR f, struct face *face); 566 void (*done_face) (struct frame *f, struct face *face);
567 567
568 /* Optional. 568 /* Optional.
569 If FONT (FONT-ENTITY or FONT-OBJECT) has a glyph for character C 569 If FONT (FONT-ENTITY or FONT-OBJECT) has a glyph for character C
@@ -646,12 +646,12 @@ struct font_driver
646 Make the font driver ready for frame F. Usually this function 646 Make the font driver ready for frame F. Usually this function
647 makes some data specific to F and stores it in F by calling 647 makes some data specific to F and stores it in F by calling
648 font_put_frame_data (). */ 648 font_put_frame_data (). */
649 int (*start_for_frame) (FRAME_PTR f); 649 int (*start_for_frame) (struct frame *f);
650 650
651 /* Optional. 651 /* Optional.
652 End using the driver for frame F. Usually this function free 652 End using the driver for frame F. Usually this function free
653 some data stored for F. */ 653 some data stored for F. */
654 int (*end_for_frame) (FRAME_PTR f); 654 int (*end_for_frame) (struct frame *f);
655 655
656 /* Optional. 656 /* Optional.
657 657
@@ -674,7 +674,7 @@ struct font_driver
674 If FONT is usable on frame F, return 0. Otherwise return -1. 674 If FONT is usable on frame F, return 0. Otherwise return -1.
675 This method is used only for debugging. If this method is NULL, 675 This method is used only for debugging. If this method is NULL,
676 Emacs assumes that the font is usable on any frame. */ 676 Emacs assumes that the font is usable on any frame. */
677 int (*check) (FRAME_PTR F, struct font *font); 677 int (*check) (struct frame *f, struct font *font);
678 678
679 /* Optional. 679 /* Optional.
680 680
@@ -698,8 +698,8 @@ struct font_driver
698 698
699 699
700/* Chain of font drivers. There's one global font driver list 700/* Chain of font drivers. There's one global font driver list
701 (font_driver_list in font.c). In addition, each frame has its own 701 (font_driver_list in font.c). In addition, each frame has
702 font driver list at FRAME_PTR->font_driver_list. */ 702 its own font driver list at F->font_driver_list. */
703 703
704struct font_driver_list 704struct font_driver_list
705{ 705{
@@ -713,8 +713,8 @@ struct font_driver_list
713}; 713};
714 714
715 715
716/* Chain of arbitrary data specific to each font driver. Each frame 716/* Chain of arbitrary data specific to each font driver.
717 has its own font data list at FRAME_PTR->font_data_list. */ 717 Each frame has its own font data list at F->font_data_list. */
718 718
719struct font_data_list 719struct font_data_list
720{ 720{
@@ -742,28 +742,28 @@ extern Lisp_Object font_style_symbolic (Lisp_Object font,
742 bool for_face); 742 bool for_face);
743 743
744extern bool font_match_p (Lisp_Object spec, Lisp_Object font); 744extern bool font_match_p (Lisp_Object spec, Lisp_Object font);
745extern Lisp_Object font_list_entities (Lisp_Object frame, 745extern Lisp_Object font_list_entities (struct frame *, Lisp_Object);
746 Lisp_Object spec);
747 746
748extern Lisp_Object font_get_name (Lisp_Object font_object); 747extern Lisp_Object font_get_name (Lisp_Object font_object);
749extern Lisp_Object font_spec_from_name (Lisp_Object font_name); 748extern Lisp_Object font_spec_from_name (Lisp_Object font_name);
750extern Lisp_Object font_get_frame (Lisp_Object font_object); 749extern Lisp_Object font_get_frame (Lisp_Object font_object);
751extern int font_has_char (FRAME_PTR, Lisp_Object, int); 750extern int font_has_char (struct frame *, Lisp_Object, int);
752 751
753extern void font_clear_prop (Lisp_Object *attrs, 752extern void font_clear_prop (Lisp_Object *attrs,
754 enum font_property_index prop); 753 enum font_property_index prop);
755extern Lisp_Object font_find_for_lface (FRAME_PTR f, Lisp_Object *lface, 754extern Lisp_Object font_find_for_lface (struct frame *f, Lisp_Object *lface,
756 Lisp_Object spec, int c); 755 Lisp_Object spec, int c);
757extern Lisp_Object font_open_for_lface (FRAME_PTR f, Lisp_Object entity, 756extern Lisp_Object font_open_for_lface (struct frame *f, Lisp_Object entity,
758 Lisp_Object *lface, 757 Lisp_Object *lface,
759 Lisp_Object spec); 758 Lisp_Object spec);
760extern Lisp_Object font_load_for_lface (FRAME_PTR f, Lisp_Object *lface, 759extern Lisp_Object font_load_for_lface (struct frame *f, Lisp_Object *lface,
761 Lisp_Object spec); 760 Lisp_Object spec);
762extern void font_prepare_for_face (FRAME_PTR f, struct face *face); 761extern void font_prepare_for_face (struct frame *f, struct face *face);
763extern void font_done_for_face (FRAME_PTR f, struct face *face); 762extern void font_done_for_face (struct frame *f, struct face *face);
763extern void clear_font_cache (struct frame *);
764 764
765extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec); 765extern Lisp_Object font_open_by_spec (struct frame *f, Lisp_Object spec);
766extern Lisp_Object font_open_by_name (FRAME_PTR f, Lisp_Object name); 766extern Lisp_Object font_open_by_name (struct frame *f, Lisp_Object name);
767 767
768extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len, 768extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
769 bool force_symbol); 769 bool force_symbol);
@@ -778,9 +778,9 @@ extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size,
778 char *name, int bytes); 778 char *name, int bytes);
779extern int font_unparse_fcname (Lisp_Object font, int pixel_size, 779extern int font_unparse_fcname (Lisp_Object font, int pixel_size,
780 char *name, int bytes); 780 char *name, int bytes);
781extern void register_font_driver (struct font_driver *driver, FRAME_PTR f); 781extern void register_font_driver (struct font_driver *driver, struct frame *f);
782extern void free_font_driver_list (FRAME_PTR f); 782extern void free_font_driver_list (struct frame *f);
783extern Lisp_Object font_update_drivers (FRAME_PTR f, Lisp_Object list); 783extern Lisp_Object font_update_drivers (struct frame *f, Lisp_Object list);
784extern Lisp_Object font_range (ptrdiff_t, ptrdiff_t, ptrdiff_t *, 784extern Lisp_Object font_range (ptrdiff_t, ptrdiff_t, ptrdiff_t *,
785 struct window *, struct face *, 785 struct window *, struct face *,
786 Lisp_Object); 786 Lisp_Object);
@@ -789,10 +789,10 @@ extern void font_fill_lglyph_metrics (Lisp_Object, Lisp_Object);
789extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop, 789extern Lisp_Object font_put_extra (Lisp_Object font, Lisp_Object prop,
790 Lisp_Object val); 790 Lisp_Object val);
791 791
792extern int font_put_frame_data (FRAME_PTR f, 792extern int font_put_frame_data (struct frame *f,
793 struct font_driver *driver, 793 struct font_driver *driver,
794 void *data); 794 void *data);
795extern void *font_get_frame_data (FRAME_PTR f, 795extern void *font_get_frame_data (struct frame *f,
796 struct font_driver *driver); 796 struct font_driver *driver);
797 797
798extern void font_filter_properties (Lisp_Object font, 798extern void font_filter_properties (Lisp_Object font,
diff --git a/src/fontset.c b/src/fontset.c
index 6a6a434add0..0bf716bf1b2 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -539,8 +539,9 @@ fontset_find_font (Lisp_Object fontset, int c, struct face *face, int id,
539{ 539{
540 Lisp_Object vec, font_group; 540 Lisp_Object vec, font_group;
541 int i, charset_matched = 0, found_index; 541 int i, charset_matched = 0, found_index;
542 FRAME_PTR f = (FRAMEP (FONTSET_FRAME (fontset)) 542 struct frame *f = (FRAMEP (FONTSET_FRAME (fontset))
543 ? XFRAME (FONTSET_FRAME (fontset)) : XFRAME (selected_frame)); 543 ? XFRAME (FONTSET_FRAME (fontset))
544 : XFRAME (selected_frame));
544 Lisp_Object rfont_def; 545 Lisp_Object rfont_def;
545 546
546 font_group = fontset_get_font_group (fontset, fallback ? -1 : c); 547 font_group = fontset_get_font_group (fontset, fallback ? -1 : c);
@@ -859,7 +860,7 @@ fontset_ascii (int id)
859} 860}
860 861
861static void 862static void
862free_realized_fontset (FRAME_PTR f, Lisp_Object fontset) 863free_realized_fontset (struct frame *f, Lisp_Object fontset)
863{ 864{
864#if 0 865#if 0
865 Lisp_Object tail; 866 Lisp_Object tail;
@@ -877,7 +878,7 @@ free_realized_fontset (FRAME_PTR f, Lisp_Object fontset)
877 free_realized_face. */ 878 free_realized_face. */
878 879
879void 880void
880free_face_fontset (FRAME_PTR f, struct face *face) 881free_face_fontset (struct frame *f, struct face *face)
881{ 882{
882 Lisp_Object fontset; 883 Lisp_Object fontset;
883 884
@@ -930,7 +931,7 @@ face_suitable_for_char_p (struct face *face, int c)
930 the macro FACE_FOR_CHAR. */ 931 the macro FACE_FOR_CHAR. */
931 932
932int 933int
933face_for_char (FRAME_PTR f, struct face *face, int c, int pos, Lisp_Object object) 934face_for_char (struct frame *f, struct face *face, int c, int pos, Lisp_Object object)
934{ 935{
935 Lisp_Object fontset, rfont_def, charset; 936 Lisp_Object fontset, rfont_def, charset;
936 int face_id; 937 int face_id;
@@ -1048,7 +1049,7 @@ font_for_char (struct face *face, int c, int pos, Lisp_Object object)
1048 Called from realize_x_face. */ 1049 Called from realize_x_face. */
1049 1050
1050int 1051int
1051make_fontset_for_ascii_face (FRAME_PTR f, int base_fontset_id, struct face *face) 1052make_fontset_for_ascii_face (struct frame *f, int base_fontset_id, struct face *face)
1052{ 1053{
1053 Lisp_Object base_fontset, fontset, frame; 1054 Lisp_Object base_fontset, fontset, frame;
1054 1055
@@ -1227,7 +1228,7 @@ If REGEXPP is non-nil, PATTERN is a regular expression. */)
1227/* Return a list of base fontset names matching PATTERN on frame F. */ 1228/* Return a list of base fontset names matching PATTERN on frame F. */
1228 1229
1229Lisp_Object 1230Lisp_Object
1230list_fontsets (FRAME_PTR f, Lisp_Object pattern, int size) 1231list_fontsets (struct frame *f, Lisp_Object pattern, int size)
1231{ 1232{
1232 Lisp_Object frame, regexp, val; 1233 Lisp_Object frame, regexp, val;
1233 int id; 1234 int id;
@@ -1284,7 +1285,7 @@ free_realized_fontsets (Lisp_Object base)
1284 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail); 1285 for (tail = FONTSET_FACE_ALIST (this); CONSP (tail);
1285 tail = XCDR (tail)) 1286 tail = XCDR (tail))
1286 { 1287 {
1287 FRAME_PTR f = XFRAME (FONTSET_FRAME (this)); 1288 struct frame *f = XFRAME (FONTSET_FRAME (this));
1288 int face_id = XINT (XCDR (XCAR (tail))); 1289 int face_id = XINT (XCDR (XCAR (tail)));
1289 struct face *face = FACE_FROM_ID (f, face_id); 1290 struct face *face = FACE_FROM_ID (f, face_id);
1290 1291
@@ -1612,7 +1613,7 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1612 name = FONTSET_NAME (fontset); 1613 name = FONTSET_NAME (fontset);
1613 FOR_EACH_FRAME (tail, fr) 1614 FOR_EACH_FRAME (tail, fr)
1614 { 1615 {
1615 FRAME_PTR f = XFRAME (fr); 1616 struct frame *f = XFRAME (fr);
1616 Lisp_Object font_object; 1617 Lisp_Object font_object;
1617 struct face *face; 1618 struct face *face;
1618 1619
@@ -2140,7 +2141,7 @@ dump_fontset (Lisp_Object fontset)
2140 frame = FONTSET_FRAME (fontset); 2141 frame = FONTSET_FRAME (fontset);
2141 if (FRAMEP (frame)) 2142 if (FRAMEP (frame))
2142 { 2143 {
2143 FRAME_PTR f = XFRAME (frame); 2144 struct frame *f = XFRAME (frame);
2144 2145
2145 if (FRAME_LIVE_P (f)) 2146 if (FRAME_LIVE_P (f))
2146 ASET (vec, 1, 2147 ASET (vec, 1,
diff --git a/src/fontset.h b/src/fontset.h
index 926520c8001..fd16c7178f5 100644
--- a/src/fontset.h
+++ b/src/fontset.h
@@ -28,12 +28,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28 28
29struct face; 29struct face;
30 30
31extern void free_face_fontset (FRAME_PTR, struct face *); 31extern void free_face_fontset (struct frame *, struct face *);
32extern int face_for_char (FRAME_PTR, struct face *, int, 32extern int face_for_char (struct frame *, struct face *, int,
33 int, Lisp_Object); 33 int, Lisp_Object);
34extern Lisp_Object font_for_char (struct face *, int, int, Lisp_Object); 34extern Lisp_Object font_for_char (struct face *, int, int, Lisp_Object);
35 35
36extern int make_fontset_for_ascii_face (FRAME_PTR, int, struct face *); 36extern int make_fontset_for_ascii_face (struct frame *, int, struct face *);
37extern int fontset_from_font (Lisp_Object); 37extern int fontset_from_font (Lisp_Object);
38extern int fs_query_fontset (Lisp_Object, int); 38extern int fs_query_fontset (Lisp_Object, int);
39extern Lisp_Object list_fontsets (struct frame *, Lisp_Object, int); 39extern Lisp_Object list_fontsets (struct frame *, Lisp_Object, int);
diff --git a/src/frame.c b/src/frame.c
index 5fa54052cd2..5ee001f4d98 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -69,7 +69,6 @@ Lisp_Object Qnoelisp;
69static Lisp_Object Qx_frame_parameter; 69static Lisp_Object Qx_frame_parameter;
70Lisp_Object Qx_resource_name; 70Lisp_Object Qx_resource_name;
71Lisp_Object Qterminal; 71Lisp_Object Qterminal;
72Lisp_Object Qterminal_live_p;
73 72
74/* Frame parameters (set or reported). */ 73/* Frame parameters (set or reported). */
75 74
@@ -186,7 +185,6 @@ set_menu_bar_lines_1 (Lisp_Object window, int n)
186{ 185{
187 struct window *w = XWINDOW (window); 186 struct window *w = XWINDOW (window);
188 187
189 w->last_modified = 0;
190 w->top_line += n; 188 w->top_line += n;
191 w->total_lines -= n; 189 w->total_lines -= n;
192 190
@@ -310,7 +308,7 @@ predicates which report frame's specific UI-related capabilities. */)
310} 308}
311 309
312struct frame * 310struct frame *
313make_frame (int mini_p) 311make_frame (bool mini_p)
314{ 312{
315 Lisp_Object frame; 313 Lisp_Object frame;
316 register struct frame *f; 314 register struct frame *f;
@@ -694,24 +692,16 @@ affects all frames on the same terminal device. */)
694 ? FRAME_TTY (XFRAME (selected_frame))->name 692 ? FRAME_TTY (XFRAME (selected_frame))->name
695 : NULL)); 693 : NULL));
696 if (!NILP (tty)) 694 if (!NILP (tty))
697 { 695 name = xlispstrdupa (tty);
698 name = alloca (SBYTES (tty) + 1);
699 memcpy (name, SSDATA (tty), SBYTES (tty));
700 name[SBYTES (tty)] = 0;
701 }
702 696
703 tty_type = get_future_frame_param 697 tty_type = get_future_frame_param
704 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame)) 698 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
705 ? FRAME_TTY (XFRAME (selected_frame))->type 699 ? FRAME_TTY (XFRAME (selected_frame))->type
706 : NULL)); 700 : NULL));
707 if (!NILP (tty_type)) 701 if (!NILP (tty_type))
708 { 702 type = xlispstrdupa (tty_type);
709 type = alloca (SBYTES (tty_type) + 1);
710 memcpy (type, SSDATA (tty_type), SBYTES (tty_type));
711 type[SBYTES (tty_type)] = 0;
712 }
713 703
714 t = init_tty (name, type, 0); /* Errors are not fatal. */ 704 t = init_tty (name, type, 0); /* Errors are not fatal. */
715 } 705 }
716 706
717 f = make_terminal_frame (t); 707 f = make_terminal_frame (t);
@@ -725,16 +715,13 @@ affects all frames on the same terminal device. */)
725 adjust_glyphs (f); 715 adjust_glyphs (f);
726 calculate_costs (f); 716 calculate_costs (f);
727 XSETFRAME (frame, f); 717 XSETFRAME (frame, f);
718
719 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
720 store_in_alist (&parms, Qtty,
721 (t->display_info.tty->name
722 ? build_string (t->display_info.tty->name)
723 : Qnil));
728 Fmodify_frame_parameters (frame, parms); 724 Fmodify_frame_parameters (frame, parms);
729 Fmodify_frame_parameters
730 (frame, list1 (Fcons (Qtty_type,
731 build_string (t->display_info.tty->type))));
732 if (t->display_info.tty->name != NULL)
733 Fmodify_frame_parameters
734 (frame, list1 (Fcons (Qtty,
735 build_string (t->display_info.tty->name))));
736 else
737 Fmodify_frame_parameters (frame, list1 (Fcons (Qtty, Qnil)));
738 725
739 /* Make the frame face alist be frame-specific, so that each 726 /* Make the frame face alist be frame-specific, so that each
740 frame could change its face definitions independently. */ 727 frame could change its face definitions independently. */
@@ -1097,7 +1084,7 @@ Otherwise, include all frames. */)
1097 (Exception: if F is the terminal frame, and we are using X, return 1.) */ 1084 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1098 1085
1099static int 1086static int
1100other_visible_frames (FRAME_PTR f) 1087other_visible_frames (struct frame *f)
1101{ 1088{
1102 Lisp_Object frames, this; 1089 Lisp_Object frames, this;
1103 1090
@@ -1157,10 +1144,14 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
1157 1144
1158 FOR_EACH_FRAME (frames, this) 1145 FOR_EACH_FRAME (frames, this)
1159 { 1146 {
1160 if (! EQ (this, frame) 1147 Lisp_Object fminiw;
1161 && EQ (frame, 1148
1162 WINDOW_FRAME (XWINDOW 1149 if (EQ (this, frame))
1163 (FRAME_MINIBUF_WINDOW (XFRAME (this)))))) 1150 continue;
1151
1152 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1153
1154 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1164 { 1155 {
1165 /* If we MUST delete this frame, delete the other first. 1156 /* If we MUST delete this frame, delete the other first.
1166 But do this only if FORCE equals `noelisp'. */ 1157 But do this only if FORCE equals `noelisp'. */
@@ -1206,10 +1197,18 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
1206 /* Don't let the frame remain selected. */ 1197 /* Don't let the frame remain selected. */
1207 if (f == sf) 1198 if (f == sf)
1208 { 1199 {
1209 Lisp_Object tail, frame1; 1200 Lisp_Object tail;
1210 1201 Lisp_Object frame1 = Qnil;
1211 /* Look for another visible frame on the same terminal. */ 1202
1212 frame1 = next_frame (frame, Qvisible); 1203 /* Look for another visible frame on the same terminal.
1204 Do not call next_frame here because it may loop forever.
1205 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1206 FOR_EACH_FRAME (tail, frame1)
1207 if (!EQ (frame, frame1)
1208 && (FRAME_TERMINAL (XFRAME (frame))
1209 == FRAME_TERMINAL (XFRAME (frame1)))
1210 && FRAME_VISIBLE_P (XFRAME (frame1)))
1211 break;
1213 1212
1214 /* If there is none, find *some* other frame. */ 1213 /* If there is none, find *some* other frame. */
1215 if (NILP (frame1) || EQ (frame1, frame)) 1214 if (NILP (frame1) || EQ (frame1, frame))
@@ -1467,7 +1466,7 @@ passing the normal return value to that function as an argument,
1467and returns whatever that function returns. */) 1466and returns whatever that function returns. */)
1468 (void) 1467 (void)
1469{ 1468{
1470 FRAME_PTR f; 1469 struct frame *f;
1471 Lisp_Object lispy_dummy; 1470 Lisp_Object lispy_dummy;
1472 Lisp_Object x, y, retval; 1471 Lisp_Object x, y, retval;
1473 struct gcpro gcpro1; 1472 struct gcpro gcpro1;
@@ -1513,7 +1512,7 @@ to read the mouse position, it returns the selected frame for FRAME
1513and nil for X and Y. */) 1512and nil for X and Y. */)
1514 (void) 1513 (void)
1515{ 1514{
1516 FRAME_PTR f; 1515 struct frame *f;
1517 Lisp_Object lispy_dummy; 1516 Lisp_Object lispy_dummy;
1518 Lisp_Object x, y; 1517 Lisp_Object x, y;
1519 1518
@@ -2249,7 +2248,9 @@ use is not recommended. Explicitly check for a frame-parameter instead. */)
2249 (Lisp_Object frame, Lisp_Object alist) 2248 (Lisp_Object frame, Lisp_Object alist)
2250{ 2249{
2251 struct frame *f = decode_live_frame (frame); 2250 struct frame *f = decode_live_frame (frame);
2252 register Lisp_Object tail, prop, val; 2251 register Lisp_Object prop, val;
2252
2253 CHECK_LIST (alist);
2253 2254
2254 /* I think this should be done with a hook. */ 2255 /* I think this should be done with a hook. */
2255#ifdef HAVE_WINDOW_SYSTEM 2256#ifdef HAVE_WINDOW_SYSTEM
@@ -2274,12 +2275,11 @@ use is not recommended. Explicitly check for a frame-parameter instead. */)
2274 2275
2275 /* Extract parm names and values into those vectors. */ 2276 /* Extract parm names and values into those vectors. */
2276 2277
2277 i = 0; 2278 for (i = 0; CONSP (alist); alist = XCDR (alist))
2278 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2279 { 2279 {
2280 Lisp_Object elt; 2280 Lisp_Object elt;
2281 2281
2282 elt = XCAR (tail); 2282 elt = XCAR (alist);
2283 parms[i] = Fcar (elt); 2283 parms[i] = Fcar (elt);
2284 values[i] = Fcdr (elt); 2284 values[i] = Fcdr (elt);
2285 i++; 2285 i++;
@@ -2360,7 +2360,7 @@ to `frame-height'). */)
2360 2360
2361#ifdef HAVE_WINDOW_SYSTEM 2361#ifdef HAVE_WINDOW_SYSTEM
2362 if (FRAME_WINDOW_P (f)) 2362 if (FRAME_WINDOW_P (f))
2363 return make_number (x_pixel_height (f)); 2363 return make_number (FRAME_PIXEL_HEIGHT (f));
2364 else 2364 else
2365#endif 2365#endif
2366 return make_number (FRAME_LINES (f)); 2366 return make_number (FRAME_LINES (f));
@@ -2377,7 +2377,7 @@ If FRAME is omitted or nil, the selected frame is used. */)
2377 2377
2378#ifdef HAVE_WINDOW_SYSTEM 2378#ifdef HAVE_WINDOW_SYSTEM
2379 if (FRAME_WINDOW_P (f)) 2379 if (FRAME_WINDOW_P (f))
2380 return make_number (x_pixel_width (f)); 2380 return make_number (FRAME_PIXEL_WIDTH (f));
2381 else 2381 else
2382#endif 2382#endif
2383 return make_number (FRAME_COLS (f)); 2383 return make_number (FRAME_COLS (f));
@@ -2402,8 +2402,9 @@ is used. */)
2402 2402
2403DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0, 2403DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2404 doc: /* Specify that the frame FRAME has LINES lines. 2404 doc: /* Specify that the frame FRAME has LINES lines.
2405Optional third arg non-nil means that redisplay should use LINES lines 2405If FRAME is nil, the selected frame is used. Optional third arg
2406but that the idea of the actual height of the frame should not be changed. */) 2406non-nil means that redisplay should use LINES lines but that the
2407idea of the actual height of the frame should not be changed. */)
2407 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend) 2408 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2408{ 2409{
2409 register struct frame *f = decode_live_frame (frame); 2410 register struct frame *f = decode_live_frame (frame);
@@ -2426,8 +2427,9 @@ but that the idea of the actual height of the frame should not be changed. */)
2426 2427
2427DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0, 2428DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2428 doc: /* Specify that the frame FRAME has COLS columns. 2429 doc: /* Specify that the frame FRAME has COLS columns.
2429Optional third arg non-nil means that redisplay should use COLS columns 2430If FRAME is nil, the selected frame is used. Optional third arg
2430but that the idea of the actual width of the frame should not be changed. */) 2431non-nil means that redisplay should use COLS columns but that the
2432idea of the actual width of the frame should not be changed. */)
2431 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend) 2433 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2432{ 2434{
2433 register struct frame *f = decode_live_frame (frame); 2435 register struct frame *f = decode_live_frame (frame);
@@ -2449,15 +2451,14 @@ but that the idea of the actual width of the frame should not be changed. */)
2449} 2451}
2450 2452
2451DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0, 2453DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2452 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */) 2454 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters.
2455If FRAME is nil, the selected frame is used. */)
2453 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows) 2456 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2454{ 2457{
2455 register struct frame *f; 2458 register struct frame *f = decode_live_frame (frame);
2456 2459
2457 CHECK_LIVE_FRAME (frame);
2458 CHECK_TYPE_RANGED_INTEGER (int, cols); 2460 CHECK_TYPE_RANGED_INTEGER (int, cols);
2459 CHECK_TYPE_RANGED_INTEGER (int, rows); 2461 CHECK_TYPE_RANGED_INTEGER (int, rows);
2460 f = XFRAME (frame);
2461 2462
2462 /* I think this should be done with a hook. */ 2463 /* I think this should be done with a hook. */
2463#ifdef HAVE_WINDOW_SYSTEM 2464#ifdef HAVE_WINDOW_SYSTEM
@@ -2479,17 +2480,16 @@ DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2479DEFUN ("set-frame-position", Fset_frame_position, 2480DEFUN ("set-frame-position", Fset_frame_position,
2480 Sset_frame_position, 3, 3, 0, 2481 Sset_frame_position, 3, 3, 0,
2481 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET. 2482 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2482This is actually the position of the upper left corner of the frame. 2483If FRAME is nil, the selected frame is used. XOFFSET and YOFFSET are
2483Negative values for XOFFSET or YOFFSET are interpreted relative to 2484actually the position of the upper left corner of the frame. Negative
2484the rightmost or bottommost possible position (that stays within the screen). */) 2485values for XOFFSET or YOFFSET are interpreted relative to the rightmost
2486or bottommost possible position (that stays within the screen). */)
2485 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset) 2487 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2486{ 2488{
2487 register struct frame *f; 2489 register struct frame *f = decode_live_frame (frame);
2488 2490
2489 CHECK_LIVE_FRAME (frame);
2490 CHECK_TYPE_RANGED_INTEGER (int, xoffset); 2491 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2491 CHECK_TYPE_RANGED_INTEGER (int, yoffset); 2492 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2492 f = XFRAME (frame);
2493 2493
2494 /* I think this should be done with a hook. */ 2494 /* I think this should be done with a hook. */
2495#ifdef HAVE_WINDOW_SYSTEM 2495#ifdef HAVE_WINDOW_SYSTEM
@@ -2609,7 +2609,7 @@ x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int
2609 to store the new value in the parameter alist. */ 2609 to store the new value in the parameter alist. */
2610 2610
2611void 2611void
2612x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist) 2612x_set_frame_parameters (struct frame *f, Lisp_Object alist)
2613{ 2613{
2614 Lisp_Object tail; 2614 Lisp_Object tail;
2615 2615
@@ -2628,9 +2628,9 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2628 Lisp_Object *parms; 2628 Lisp_Object *parms;
2629 Lisp_Object *values; 2629 Lisp_Object *values;
2630 ptrdiff_t i, p; 2630 ptrdiff_t i, p;
2631 int left_no_change = 0, top_no_change = 0; 2631 bool left_no_change = 0, top_no_change = 0;
2632 int icon_left_no_change = 0, icon_top_no_change = 0; 2632 bool icon_left_no_change = 0, icon_top_no_change = 0;
2633 int size_changed = 0; 2633 bool size_changed = 0;
2634 struct gcpro gcpro1, gcpro2; 2634 struct gcpro gcpro1, gcpro2;
2635 2635
2636 i = 0; 2636 i = 0;
@@ -2866,10 +2866,11 @@ x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2866 /* Actually set that position, and convert to absolute. */ 2866 /* Actually set that position, and convert to absolute. */
2867 x_set_offset (f, leftpos, toppos, -1); 2867 x_set_offset (f, leftpos, toppos, -1);
2868 } 2868 }
2869 2869#ifdef HAVE_X_WINDOWS
2870 if ((!NILP (icon_left) || !NILP (icon_top)) 2870 if ((!NILP (icon_left) || !NILP (icon_top))
2871 && ! (icon_left_no_change && icon_top_no_change)) 2871 && ! (icon_left_no_change && icon_top_no_change))
2872 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top)); 2872 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2873#endif /* HAVE_X_WINDOWS */
2873 } 2874 }
2874 2875
2875 UNGCPRO; 2876 UNGCPRO;
@@ -3346,7 +3347,7 @@ x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3346/* Return non-nil if frame F wants a bitmap icon. */ 3347/* Return non-nil if frame F wants a bitmap icon. */
3347 3348
3348Lisp_Object 3349Lisp_Object
3349x_icon_type (FRAME_PTR f) 3350x_icon_type (struct frame *f)
3350{ 3351{
3351 Lisp_Object tem; 3352 Lisp_Object tem;
3352 3353
@@ -3543,7 +3544,7 @@ xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Li
3543 3544
3544 value = x_get_string_resource (rdb, name_key, class_key); 3545 value = x_get_string_resource (rdb, name_key, class_key);
3545 3546
3546 if (value != (char *) 0 && *value) 3547 if (value && *value)
3547 return build_string (value); 3548 return build_string (value);
3548 else 3549 else
3549 return Qnil; 3550 return Qnil;
@@ -3934,8 +3935,8 @@ On Nextstep, this just calls `ns-parse-geometry'. */)
3934#define DEFAULT_ROWS 35 3935#define DEFAULT_ROWS 35
3935#define DEFAULT_COLS 80 3936#define DEFAULT_COLS 80
3936 3937
3937int 3938long
3938x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p) 3939x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p)
3939{ 3940{
3940 register Lisp_Object tem0, tem1, tem2; 3941 register Lisp_Object tem0, tem1, tem2;
3941 long window_prompting = 0; 3942 long window_prompting = 0;
@@ -4202,8 +4203,7 @@ make_monitor_attribute_list (struct MonitorInfo *monitors,
4202 mi->work.width, mi->work.height); 4203 mi->work.width, mi->work.height);
4203 geometry = list4i (mi->geom.x, mi->geom.y, 4204 geometry = list4i (mi->geom.x, mi->geom.y,
4204 mi->geom.width, mi->geom.height); 4205 mi->geom.width, mi->geom.height);
4205 attributes = Fcons (Fcons (Qsource, 4206 attributes = Fcons (Fcons (Qsource, build_string (source)),
4206 make_string (source, strlen (source))),
4207 attributes); 4207 attributes);
4208 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), 4208 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4209 attributes); 4209 attributes);
@@ -4286,7 +4286,6 @@ syms_of_frame (void)
4286 DEFSYM (Qx_frame_parameter, "x-frame-parameter"); 4286 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4287 4287
4288 DEFSYM (Qterminal, "terminal"); 4288 DEFSYM (Qterminal, "terminal");
4289 DEFSYM (Qterminal_live_p, "terminal-live-p");
4290 4289
4291 DEFSYM (Qgeometry, "geometry"); 4290 DEFSYM (Qgeometry, "geometry");
4292 DEFSYM (Qworkarea, "workarea"); 4291 DEFSYM (Qworkarea, "workarea");
diff --git a/src/frame.h b/src/frame.h
index 31d3e73c3c3..e44003b15ca 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -410,6 +410,10 @@ struct frame
410 /* Nonzero means that the pointer is invisible. */ 410 /* Nonzero means that the pointer is invisible. */
411 unsigned pointer_invisible :1; 411 unsigned pointer_invisible :1;
412 412
413 /* Nonzero means that all windows except mini-window and
414 selected window on this frame have frozen window starts. */
415 unsigned frozen_window_starts : 1;
416
413 /* Nonzero if we should actually display the scroll bars on this frame. */ 417 /* Nonzero if we should actually display the scroll bars on this frame. */
414 enum vertical_scroll_bar_type vertical_scroll_bar_type; 418 enum vertical_scroll_bar_type vertical_scroll_bar_type;
415 419
@@ -591,8 +595,6 @@ default_pixels_per_inch_y (void)
591/* Return a pointer to the image cache of frame F. */ 595/* Return a pointer to the image cache of frame F. */
592#define FRAME_IMAGE_CACHE(F) ((F)->terminal->image_cache) 596#define FRAME_IMAGE_CACHE(F) ((F)->terminal->image_cache)
593 597
594typedef struct frame *FRAME_PTR;
595
596#define XFRAME(p) \ 598#define XFRAME(p) \
597 (eassert (FRAMEP (p)), (struct frame *) XUNTAG (p, Lisp_Vectorlike)) 599 (eassert (FRAMEP (p)), (struct frame *) XUNTAG (p, Lisp_Vectorlike))
598#define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME)) 600#define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME))
@@ -763,6 +765,10 @@ typedef struct frame *FRAME_PTR;
763/* Not really implemented. */ 765/* Not really implemented. */
764#define FRAME_WANTS_MODELINE_P(f) (f)->wants_modeline 766#define FRAME_WANTS_MODELINE_P(f) (f)->wants_modeline
765 767
768/* Nonzero if all windows except selected window and mini window
769 are frozen on frame F. */
770#define FRAME_WINDOWS_FROZEN(f) (f)->frozen_window_starts
771
766/* Nonzero if a size change has been requested for frame F 772/* Nonzero if a size change has been requested for frame F
767 but not yet really put into effect. This can be true temporarily 773 but not yet really put into effect. This can be true temporarily
768 when an X event comes in at a bad time. */ 774 when an X event comes in at a bad time. */
@@ -929,10 +935,9 @@ typedef struct frame *FRAME_PTR;
929 if (frame == hlinfo->mouse_face_mouse_frame) \ 935 if (frame == hlinfo->mouse_face_mouse_frame) \
930 { \ 936 { \
931 block_input (); \ 937 block_input (); \
932 if (hlinfo->mouse_face_mouse_frame) \ 938 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, \
933 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, \ 939 hlinfo->mouse_face_mouse_x, \
934 hlinfo->mouse_face_mouse_x, \ 940 hlinfo->mouse_face_mouse_y); \
935 hlinfo->mouse_face_mouse_y); \
936 unblock_input (); \ 941 unblock_input (); \
937 } \ 942 } \
938 } while (0) 943 } while (0)
@@ -952,7 +957,7 @@ typedef struct frame *FRAME_PTR;
952extern Lisp_Object Qframep, Qframe_live_p; 957extern Lisp_Object Qframep, Qframe_live_p;
953extern Lisp_Object Qtty, Qtty_type; 958extern Lisp_Object Qtty, Qtty_type;
954extern Lisp_Object Qtty_color_mode; 959extern Lisp_Object Qtty_color_mode;
955extern Lisp_Object Qterminal, Qterminal_live_p; 960extern Lisp_Object Qterminal;
956extern Lisp_Object Qnoelisp; 961extern Lisp_Object Qnoelisp;
957 962
958extern struct frame *last_nonminibuf_frame; 963extern struct frame *last_nonminibuf_frame;
@@ -962,7 +967,7 @@ extern struct frame *decode_window_system_frame (Lisp_Object);
962extern struct frame *decode_live_frame (Lisp_Object); 967extern struct frame *decode_live_frame (Lisp_Object);
963extern struct frame *decode_any_frame (Lisp_Object); 968extern struct frame *decode_any_frame (Lisp_Object);
964extern struct frame *make_initial_frame (void); 969extern struct frame *make_initial_frame (void);
965extern struct frame *make_frame (int); 970extern struct frame *make_frame (bool);
966#ifdef HAVE_WINDOW_SYSTEM 971#ifdef HAVE_WINDOW_SYSTEM
967extern struct frame *make_minibuffer_frame (void); 972extern struct frame *make_minibuffer_frame (void);
968extern struct frame *make_frame_without_minibuffer (Lisp_Object, 973extern struct frame *make_frame_without_minibuffer (Lisp_Object,
@@ -1207,8 +1212,7 @@ extern Lisp_Object Qrun_hook_with_args;
1207 1212
1208extern void x_set_scroll_bar_default_width (struct frame *); 1213extern void x_set_scroll_bar_default_width (struct frame *);
1209extern void x_set_offset (struct frame *, int, int, int); 1214extern void x_set_offset (struct frame *, int, int, int);
1210extern void x_wm_set_icon_position (struct frame *, int, int); 1215extern void x_wm_set_size_hint (struct frame *f, long flags, bool user_position);
1211extern void x_wm_set_size_hint (FRAME_PTR f, long flags, bool user_position);
1212 1216
1213extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int); 1217extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
1214 1218
@@ -1242,7 +1246,7 @@ extern void x_set_scroll_bar_width (struct frame *, Lisp_Object,
1242 1246
1243extern Lisp_Object x_icon_type (struct frame *); 1247extern Lisp_Object x_icon_type (struct frame *);
1244 1248
1245extern int x_figure_window_size (struct frame *, Lisp_Object, int); 1249extern long x_figure_window_size (struct frame *, Lisp_Object, bool);
1246 1250
1247extern void x_set_alpha (struct frame *, Lisp_Object, Lisp_Object); 1251extern void x_set_alpha (struct frame *, Lisp_Object, Lisp_Object);
1248 1252
@@ -1264,8 +1268,6 @@ extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
1264extern void x_make_frame_visible (struct frame *f); 1268extern void x_make_frame_visible (struct frame *f);
1265extern void x_make_frame_invisible (struct frame *f); 1269extern void x_make_frame_invisible (struct frame *f);
1266extern void x_iconify_frame (struct frame *f); 1270extern void x_iconify_frame (struct frame *f);
1267extern int x_pixel_width (struct frame *f);
1268extern int x_pixel_height (struct frame *f);
1269extern void x_set_frame_alpha (struct frame *f); 1271extern void x_set_frame_alpha (struct frame *f);
1270extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); 1272extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
1271extern void x_set_tool_bar_lines (struct frame *f, 1273extern void x_set_tool_bar_lines (struct frame *f,
@@ -1280,9 +1282,12 @@ extern void x_set_menu_bar_lines (struct frame *,
1280extern void free_frame_menubar (struct frame *); 1282extern void free_frame_menubar (struct frame *);
1281extern void x_free_frame_resources (struct frame *); 1283extern void x_free_frame_resources (struct frame *);
1282 1284
1283#if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT 1285#if defined HAVE_X_WINDOWS
1286extern void x_wm_set_icon_position (struct frame *, int, int);
1287#if !defined USE_X_TOOLKIT
1284extern char *x_get_resource_string (const char *, const char *); 1288extern char *x_get_resource_string (const char *, const char *);
1285#endif 1289#endif
1290#endif
1286 1291
1287extern void x_query_colors (struct frame *f, XColor *, int); 1292extern void x_query_colors (struct frame *f, XColor *, int);
1288extern void x_query_color (struct frame *f, XColor *); 1293extern void x_query_color (struct frame *f, XColor *);
diff --git a/src/fringe.c b/src/fringe.c
index f728cd6d5ff..492eddae8d4 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -666,7 +666,7 @@ draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int o
666 and OTOH leaving out that one pixel leaves behind 666 and OTOH leaving out that one pixel leaves behind
667 traces of the cursor, if it was in column zero 667 traces of the cursor, if it was in column zero
668 before drawing non-empty margin area. */ 668 before drawing non-empty margin area. */
669 && NILP (w->left_margin_cols)) 669 && w->left_margin_cols == 0)
670 ? 1 : 0); 670 ? 1 : 0);
671 p.bx = x - wd; 671 p.bx = x - wd;
672 p.nx = wd; 672 p.nx = wd;
@@ -890,31 +890,32 @@ draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
890/* Draw the fringes of window W. Only fringes for rows marked for 890/* Draw the fringes of window W. Only fringes for rows marked for
891 update in redraw_fringe_bitmaps_p are drawn. 891 update in redraw_fringe_bitmaps_p are drawn.
892 892
893 Return >0 if left or right fringe was redrawn in any way. 893 Return nonzero if left or right fringe was redrawn in any way.
894 894
895 If NO_FRINGE is non-zero, also return >0 if either fringe has zero width. 895 If NO_FRINGE_P is non-zero, also return nonzero if either fringe
896 has zero width.
896 897
897 A return value >0 indicates that the vertical line between windows 898 A return nonzero value indicates that the vertical line between
898 needs update (as it may be drawn in the fringe). 899 windows needs update (as it may be drawn in the fringe).
899*/ 900*/
900 901
901int 902bool
902draw_window_fringes (struct window *w, int no_fringe) 903draw_window_fringes (struct window *w, bool no_fringe_p)
903{ 904{
904 struct glyph_row *row; 905 struct glyph_row *row;
905 int yb = window_text_bottom_y (w); 906 int yb = window_text_bottom_y (w);
906 int nrows = w->current_matrix->nrows; 907 int nrows = w->current_matrix->nrows;
907 int y, rn; 908 int y, rn;
908 int updated = 0; 909 bool updated_p = 0;
909 910
910 if (w->pseudo_window_p) 911 if (w->pseudo_window_p)
911 return 0; 912 return updated_p;
912 913
913 /* Must draw line if no fringe */ 914 /* Must draw line if no fringe */
914 if (no_fringe 915 if (no_fringe_p
915 && (WINDOW_LEFT_FRINGE_WIDTH (w) == 0 916 && (WINDOW_LEFT_FRINGE_WIDTH (w) == 0
916 || WINDOW_RIGHT_FRINGE_WIDTH (w) == 0)) 917 || WINDOW_RIGHT_FRINGE_WIDTH (w) == 0))
917 updated++; 918 updated_p = 1;
918 919
919 for (y = w->vscroll, rn = 0, row = w->current_matrix->rows; 920 for (y = w->vscroll, rn = 0, row = w->current_matrix->rows;
920 y < yb && rn < nrows; 921 y < yb && rn < nrows;
@@ -924,10 +925,10 @@ draw_window_fringes (struct window *w, int no_fringe)
924 continue; 925 continue;
925 draw_row_fringe_bitmaps (w, row); 926 draw_row_fringe_bitmaps (w, row);
926 row->redraw_fringe_bitmaps_p = 0; 927 row->redraw_fringe_bitmaps_p = 0;
927 updated++; 928 updated_p = 1;
928 } 929 }
929 930
930 return updated; 931 return updated_p;
931} 932}
932 933
933 934
@@ -936,14 +937,14 @@ draw_window_fringes (struct window *w, int no_fringe)
936 937
937 If KEEP_CURRENT_P is 0, update current_matrix too. */ 938 If KEEP_CURRENT_P is 0, update current_matrix too. */
938 939
939int 940bool
940update_window_fringes (struct window *w, int keep_current_p) 941update_window_fringes (struct window *w, bool keep_current_p)
941{ 942{
942 struct glyph_row *row, *cur = 0; 943 struct glyph_row *row, *cur = 0;
943 int yb = window_text_bottom_y (w); 944 int yb = window_text_bottom_y (w);
944 int rn, nrows = w->current_matrix->nrows; 945 int rn, nrows = w->current_matrix->nrows;
945 int y; 946 int y;
946 int redraw_p = 0; 947 bool redraw_p = 0;
947 Lisp_Object boundary_top = Qnil, boundary_bot = Qnil; 948 Lisp_Object boundary_top = Qnil, boundary_bot = Qnil;
948 Lisp_Object arrow_top = Qnil, arrow_bot = Qnil; 949 Lisp_Object arrow_top = Qnil, arrow_bot = Qnil;
949 Lisp_Object empty_pos; 950 Lisp_Object empty_pos;
@@ -1169,7 +1170,7 @@ update_window_fringes (struct window *w, int keep_current_p)
1169 int left, right; 1170 int left, right;
1170 unsigned left_face_id, right_face_id; 1171 unsigned left_face_id, right_face_id;
1171 int left_offset, right_offset; 1172 int left_offset, right_offset;
1172 int periodic_p; 1173 bool periodic_p;
1173 1174
1174 row = w->desired_matrix->rows + rn; 1175 row = w->desired_matrix->rows + rn;
1175 cur = w->current_matrix->rows + rn; 1176 cur = w->current_matrix->rows + rn;
@@ -1285,7 +1286,7 @@ update_window_fringes (struct window *w, int keep_current_p)
1285 || periodic_p != cur->fringe_bitmap_periodic_p 1286 || periodic_p != cur->fringe_bitmap_periodic_p
1286 || cur->redraw_fringe_bitmaps_p) 1287 || cur->redraw_fringe_bitmaps_p)
1287 { 1288 {
1288 redraw_p = row->redraw_fringe_bitmaps_p = 1; 1289 redraw_p = 1, row->redraw_fringe_bitmaps_p = 1;
1289 if (!keep_current_p) 1290 if (!keep_current_p)
1290 { 1291 {
1291 cur->redraw_fringe_bitmaps_p = 1; 1292 cur->redraw_fringe_bitmaps_p = 1;
@@ -1304,7 +1305,7 @@ update_window_fringes (struct window *w, int keep_current_p)
1304 1305
1305 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap) 1306 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
1306 { 1307 {
1307 redraw_p = row->redraw_fringe_bitmaps_p = 1; 1308 redraw_p = 1, row->redraw_fringe_bitmaps_p = 1;
1308 if (!keep_current_p) 1309 if (!keep_current_p)
1309 { 1310 {
1310 cur->redraw_fringe_bitmaps_p = 1; 1311 cur->redraw_fringe_bitmaps_p = 1;
@@ -1339,7 +1340,7 @@ update_window_fringes (struct window *w, int keep_current_p)
1339*/ 1340*/
1340 1341
1341void 1342void
1342compute_fringe_widths (struct frame *f, int redraw) 1343compute_fringe_widths (struct frame *f, bool redraw_p)
1343{ 1344{
1344 int o_left = FRAME_LEFT_FRINGE_WIDTH (f); 1345 int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
1345 int o_right = FRAME_RIGHT_FRINGE_WIDTH (f); 1346 int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
@@ -1410,7 +1411,7 @@ compute_fringe_widths (struct frame *f, int redraw)
1410 FRAME_FRINGE_COLS (f) = 0; 1411 FRAME_FRINGE_COLS (f) = 0;
1411 } 1412 }
1412 1413
1413 if (redraw && FRAME_VISIBLE_P (f)) 1414 if (redraw_p && FRAME_VISIBLE_P (f))
1414 if (o_left != FRAME_LEFT_FRINGE_WIDTH (f) || 1415 if (o_left != FRAME_LEFT_FRINGE_WIDTH (f) ||
1415 o_right != FRAME_RIGHT_FRINGE_WIDTH (f) || 1416 o_right != FRAME_RIGHT_FRINGE_WIDTH (f) ||
1416 o_cols != FRAME_FRINGE_COLS (f)) 1417 o_cols != FRAME_FRINGE_COLS (f))
diff --git a/src/ftfont.c b/src/ftfont.c
index 10090cb3bda..3636f86f5c4 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -493,12 +493,12 @@ ftfont_get_otf (struct ftfont_info *ftfont_info)
493} 493}
494#endif /* HAVE_LIBOTF */ 494#endif /* HAVE_LIBOTF */
495 495
496static Lisp_Object ftfont_get_cache (FRAME_PTR); 496static Lisp_Object ftfont_get_cache (struct frame *);
497static Lisp_Object ftfont_list (Lisp_Object, Lisp_Object); 497static Lisp_Object ftfont_list (struct frame *, Lisp_Object);
498static Lisp_Object ftfont_match (Lisp_Object, Lisp_Object); 498static Lisp_Object ftfont_match (struct frame *, Lisp_Object);
499static Lisp_Object ftfont_list_family (Lisp_Object); 499static Lisp_Object ftfont_list_family (struct frame *);
500static Lisp_Object ftfont_open (FRAME_PTR, Lisp_Object, int); 500static Lisp_Object ftfont_open (struct frame *, Lisp_Object, int);
501static void ftfont_close (FRAME_PTR, struct font *); 501static void ftfont_close (struct frame *, struct font *);
502static int ftfont_has_char (Lisp_Object, int); 502static int ftfont_has_char (Lisp_Object, int);
503static unsigned ftfont_encode_char (struct font *, int); 503static unsigned ftfont_encode_char (struct font *, int);
504static int ftfont_text_extents (struct font *, unsigned *, int, 504static int ftfont_text_extents (struct font *, unsigned *, int,
@@ -568,7 +568,7 @@ struct font_driver ftfont_driver =
568 }; 568 };
569 569
570static Lisp_Object 570static Lisp_Object
571ftfont_get_cache (FRAME_PTR f) 571ftfont_get_cache (struct frame *f)
572{ 572{
573 return freetype_font_cache; 573 return freetype_font_cache;
574} 574}
@@ -884,7 +884,7 @@ ftfont_spec_pattern (Lisp_Object spec, char *otlayout, struct OpenTypeSpec **ots
884} 884}
885 885
886static Lisp_Object 886static Lisp_Object
887ftfont_list (Lisp_Object frame, Lisp_Object spec) 887ftfont_list (struct frame *f, Lisp_Object spec)
888{ 888{
889 Lisp_Object val = Qnil, family, adstyle; 889 Lisp_Object val = Qnil, family, adstyle;
890 int i; 890 int i;
@@ -1080,7 +1080,7 @@ ftfont_list (Lisp_Object frame, Lisp_Object spec)
1080} 1080}
1081 1081
1082static Lisp_Object 1082static Lisp_Object
1083ftfont_match (Lisp_Object frame, Lisp_Object spec) 1083ftfont_match (struct frame *f, Lisp_Object spec)
1084{ 1084{
1085 Lisp_Object entity = Qnil; 1085 Lisp_Object entity = Qnil;
1086 FcPattern *pattern, *match = NULL; 1086 FcPattern *pattern, *match = NULL;
@@ -1130,7 +1130,7 @@ ftfont_match (Lisp_Object frame, Lisp_Object spec)
1130} 1130}
1131 1131
1132static Lisp_Object 1132static Lisp_Object
1133ftfont_list_family (Lisp_Object frame) 1133ftfont_list_family (struct frame *f)
1134{ 1134{
1135 Lisp_Object list = Qnil; 1135 Lisp_Object list = Qnil;
1136 FcPattern *pattern = NULL; 1136 FcPattern *pattern = NULL;
@@ -1173,7 +1173,7 @@ ftfont_list_family (Lisp_Object frame)
1173 1173
1174 1174
1175static Lisp_Object 1175static Lisp_Object
1176ftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size) 1176ftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
1177{ 1177{
1178 struct ftfont_info *ftfont_info; 1178 struct ftfont_info *ftfont_info;
1179 struct font *font; 1179 struct font *font;
@@ -1317,7 +1317,7 @@ ftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
1317} 1317}
1318 1318
1319static void 1319static void
1320ftfont_close (FRAME_PTR f, struct font *font) 1320ftfont_close (struct frame *f, struct font *font)
1321{ 1321{
1322 struct ftfont_info *ftfont_info = (struct ftfont_info *) font; 1322 struct ftfont_info *ftfont_info = (struct ftfont_info *) font;
1323 Lisp_Object val, cache; 1323 Lisp_Object val, cache;
diff --git a/src/ftxfont.c b/src/ftxfont.c
index 8c56ee05adc..63d03b0e244 100644
--- a/src/ftxfont.c
+++ b/src/ftxfont.c
@@ -57,7 +57,7 @@ struct ftxfont_frame_data
57/* Return an array of 6 GCs for antialiasing. */ 57/* Return an array of 6 GCs for antialiasing. */
58 58
59static GC * 59static GC *
60ftxfont_get_gcs (FRAME_PTR f, long unsigned int foreground, long unsigned int background) 60ftxfont_get_gcs (struct frame *f, long unsigned int foreground, long unsigned int background)
61{ 61{
62 XColor color; 62 XColor color;
63 XGCValues xgcv; 63 XGCValues xgcv;
@@ -134,7 +134,7 @@ ftxfont_get_gcs (FRAME_PTR f, long unsigned int foreground, long unsigned int ba
134} 134}
135 135
136static int 136static int
137ftxfont_draw_bitmap (FRAME_PTR f, GC gc_fore, GC *gcs, struct font *font, 137ftxfont_draw_bitmap (struct frame *f, GC gc_fore, GC *gcs, struct font *font,
138 unsigned int code, int x, int y, XPoint *p, int size, 138 unsigned int code, int x, int y, XPoint *p, int size,
139 int *n, bool flush) 139 int *n, bool flush)
140{ 140{
@@ -212,7 +212,7 @@ ftxfont_draw_bitmap (FRAME_PTR f, GC gc_fore, GC *gcs, struct font *font,
212} 212}
213 213
214static void 214static void
215ftxfont_draw_background (FRAME_PTR f, struct font *font, GC gc, int x, int y, 215ftxfont_draw_background (struct frame *f, struct font *font, GC gc, int x, int y,
216 int width) 216 int width)
217{ 217{
218 XGCValues xgcv; 218 XGCValues xgcv;
@@ -226,9 +226,9 @@ ftxfont_draw_background (FRAME_PTR f, struct font *font, GC gc, int x, int y,
226} 226}
227 227
228static Lisp_Object 228static Lisp_Object
229ftxfont_list (Lisp_Object frame, Lisp_Object spec) 229ftxfont_list (struct frame *f, Lisp_Object spec)
230{ 230{
231 Lisp_Object list = ftfont_driver.list (frame, spec), tail; 231 Lisp_Object list = ftfont_driver.list (f, spec), tail;
232 232
233 for (tail = list; CONSP (tail); tail = XCDR (tail)) 233 for (tail = list; CONSP (tail); tail = XCDR (tail))
234 ASET (XCAR (tail), FONT_TYPE_INDEX, Qftx); 234 ASET (XCAR (tail), FONT_TYPE_INDEX, Qftx);
@@ -236,9 +236,9 @@ ftxfont_list (Lisp_Object frame, Lisp_Object spec)
236} 236}
237 237
238static Lisp_Object 238static Lisp_Object
239ftxfont_match (Lisp_Object frame, Lisp_Object spec) 239ftxfont_match (struct frame *f, Lisp_Object spec)
240{ 240{
241 Lisp_Object entity = ftfont_driver.match (frame, spec); 241 Lisp_Object entity = ftfont_driver.match (f, spec);
242 242
243 if (VECTORP (entity)) 243 if (VECTORP (entity))
244 ASET (entity, FONT_TYPE_INDEX, Qftx); 244 ASET (entity, FONT_TYPE_INDEX, Qftx);
@@ -246,7 +246,7 @@ ftxfont_match (Lisp_Object frame, Lisp_Object spec)
246} 246}
247 247
248static Lisp_Object 248static Lisp_Object
249ftxfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size) 249ftxfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
250{ 250{
251 Lisp_Object font_object; 251 Lisp_Object font_object;
252 struct font *font; 252 struct font *font;
@@ -260,7 +260,7 @@ ftxfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
260} 260}
261 261
262static void 262static void
263ftxfont_close (FRAME_PTR f, struct font *font) 263ftxfont_close (struct frame *f, struct font *font)
264{ 264{
265 ftfont_driver.close (f, font); 265 ftfont_driver.close (f, font);
266} 266}
@@ -269,7 +269,7 @@ static int
269ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y, 269ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
270 bool with_background) 270 bool with_background)
271{ 271{
272 FRAME_PTR f = s->f; 272 struct frame *f = s->f;
273 struct face *face = s->face; 273 struct face *face = s->face;
274 struct font *font = s->font; 274 struct font *font = s->font;
275 XPoint p[0x700]; 275 XPoint p[0x700];
@@ -338,7 +338,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
338} 338}
339 339
340static int 340static int
341ftxfont_end_for_frame (FRAME_PTR f) 341ftxfont_end_for_frame (struct frame *f)
342{ 342{
343 struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver); 343 struct ftxfont_frame_data *data = font_get_frame_data (f, &ftxfont_driver);
344 344
diff --git a/src/gtkutil.c b/src/gtkutil.c
index f8ddf6a90f6..7e304d417d8 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -136,7 +136,7 @@ static GdkDisplay *gdpy_def;
136 W can be a GtkMenu or a GtkWindow widget. */ 136 W can be a GtkMenu or a GtkWindow widget. */
137 137
138static void 138static void
139xg_set_screen (GtkWidget *w, FRAME_PTR f) 139xg_set_screen (GtkWidget *w, struct frame *f)
140{ 140{
141 if (FRAME_X_DISPLAY (f) != DEFAULT_GDK_DISPLAY ()) 141 if (FRAME_X_DISPLAY (f) != DEFAULT_GDK_DISPLAY ())
142 { 142 {
@@ -280,7 +280,7 @@ xg_create_default_cursor (Display *dpy)
280} 280}
281 281
282static GdkPixbuf * 282static GdkPixbuf *
283xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix) 283xg_get_pixbuf_from_pixmap (struct frame *f, Pixmap pix)
284{ 284{
285 int iunused; 285 int iunused;
286 GdkPixbuf *tmp_buf; 286 GdkPixbuf *tmp_buf;
@@ -311,7 +311,7 @@ xg_get_pixbuf_from_pixmap (FRAME_PTR f, Pixmap pix)
311/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */ 311/* Apply GMASK to GPIX and return a GdkPixbuf with an alpha channel. */
312 312
313static GdkPixbuf * 313static GdkPixbuf *
314xg_get_pixbuf_from_pix_and_mask (FRAME_PTR f, 314xg_get_pixbuf_from_pix_and_mask (struct frame *f,
315 Pixmap pix, 315 Pixmap pix,
316 Pixmap mask) 316 Pixmap mask)
317{ 317{
@@ -387,7 +387,7 @@ file_for_image (Lisp_Object image)
387 If OLD_WIDGET is not NULL, that widget is modified. */ 387 If OLD_WIDGET is not NULL, that widget is modified. */
388 388
389static GtkWidget * 389static GtkWidget *
390xg_get_image_for_pixmap (FRAME_PTR f, 390xg_get_image_for_pixmap (struct frame *f,
391 struct image *img, 391 struct image *img,
392 GtkWidget *widget, 392 GtkWidget *widget,
393 GtkImage *old_widget) 393 GtkImage *old_widget)
@@ -641,7 +641,7 @@ hierarchy_ch_cb (GtkWidget *widget,
641 GtkWidget *previous_toplevel, 641 GtkWidget *previous_toplevel,
642 gpointer user_data) 642 gpointer user_data)
643{ 643{
644 FRAME_PTR f = (FRAME_PTR) user_data; 644 struct frame *f = user_data;
645 struct x_output *x = f->output_data.x; 645 struct x_output *x = f->output_data.x;
646 GtkWidget *top = gtk_widget_get_toplevel (x->ttip_lbl); 646 GtkWidget *top = gtk_widget_get_toplevel (x->ttip_lbl);
647 647
@@ -663,7 +663,7 @@ qttip_cb (GtkWidget *widget,
663 GtkTooltip *tooltip, 663 GtkTooltip *tooltip,
664 gpointer user_data) 664 gpointer user_data)
665{ 665{
666 FRAME_PTR f = (FRAME_PTR) user_data; 666 struct frame *f = user_data;
667 struct x_output *x = f->output_data.x; 667 struct x_output *x = f->output_data.x;
668 if (x->ttip_widget == NULL) 668 if (x->ttip_widget == NULL)
669 { 669 {
@@ -707,7 +707,7 @@ qttip_cb (GtkWidget *widget,
707 Return true if a system tooltip is available. */ 707 Return true if a system tooltip is available. */
708 708
709bool 709bool
710xg_prepare_tooltip (FRAME_PTR f, 710xg_prepare_tooltip (struct frame *f,
711 Lisp_Object string, 711 Lisp_Object string,
712 int *width, 712 int *width,
713 int *height) 713 int *height)
@@ -764,7 +764,7 @@ xg_prepare_tooltip (FRAME_PTR f,
764 xg_prepare_tooltip must have been called before this function. */ 764 xg_prepare_tooltip must have been called before this function. */
765 765
766void 766void
767xg_show_tooltip (FRAME_PTR f, int root_x, int root_y) 767xg_show_tooltip (struct frame *f, int root_x, int root_y)
768{ 768{
769#ifdef USE_GTK_TOOLTIP 769#ifdef USE_GTK_TOOLTIP
770 struct x_output *x = f->output_data.x; 770 struct x_output *x = f->output_data.x;
@@ -783,7 +783,7 @@ xg_show_tooltip (FRAME_PTR f, int root_x, int root_y)
783 system tooltips). */ 783 system tooltips). */
784 784
785bool 785bool
786xg_hide_tooltip (FRAME_PTR f) 786xg_hide_tooltip (struct frame *f)
787{ 787{
788 bool ret = 0; 788 bool ret = 0;
789#ifdef USE_GTK_TOOLTIP 789#ifdef USE_GTK_TOOLTIP
@@ -827,7 +827,7 @@ my_log_handler (const gchar *log_domain, GLogLevelFlags log_level,
827 F is the frame we shall set geometry for. */ 827 F is the frame we shall set geometry for. */
828 828
829static void 829static void
830xg_set_geometry (FRAME_PTR f) 830xg_set_geometry (struct frame *f)
831{ 831{
832 if (f->size_hint_flags & (USPosition | PPosition)) 832 if (f->size_hint_flags & (USPosition | PPosition))
833 { 833 {
@@ -865,7 +865,7 @@ xg_set_geometry (FRAME_PTR f)
865 and use a GtkFixed widget, this doesn't happen automatically. */ 865 and use a GtkFixed widget, this doesn't happen automatically. */
866 866
867static void 867static void
868xg_clear_under_internal_border (FRAME_PTR f) 868xg_clear_under_internal_border (struct frame *f)
869{ 869{
870 if (FRAME_INTERNAL_BORDER_WIDTH (f) > 0) 870 if (FRAME_INTERNAL_BORDER_WIDTH (f) > 0)
871 { 871 {
@@ -903,7 +903,7 @@ xg_clear_under_internal_border (FRAME_PTR f)
903 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */ 903 PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */
904 904
905void 905void
906xg_frame_resized (FRAME_PTR f, int pixelwidth, int pixelheight) 906xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight)
907{ 907{
908 int rows, columns; 908 int rows, columns;
909 909
@@ -939,7 +939,7 @@ xg_frame_resized (FRAME_PTR f, int pixelwidth, int pixelheight)
939 COLUMNS/ROWS is the size the edit area shall have after the resize. */ 939 COLUMNS/ROWS is the size the edit area shall have after the resize. */
940 940
941void 941void
942xg_frame_set_char_size (FRAME_PTR f, int cols, int rows) 942xg_frame_set_char_size (struct frame *f, int cols, int rows)
943{ 943{
944 int pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows) 944 int pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, rows)
945 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); 945 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f);
@@ -1002,7 +1002,7 @@ xg_frame_set_char_size (FRAME_PTR f, int cols, int rows)
1002 The policy is to keep the number of editable lines. */ 1002 The policy is to keep the number of editable lines. */
1003 1003
1004static void 1004static void
1005xg_height_or_width_changed (FRAME_PTR f) 1005xg_height_or_width_changed (struct frame *f)
1006{ 1006{
1007 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 1007 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1008 FRAME_TOTAL_PIXEL_WIDTH (f), 1008 FRAME_TOTAL_PIXEL_WIDTH (f),
@@ -1042,7 +1042,7 @@ xg_win_to_widget (Display *dpy, Window wdesc)
1042/* Set the background of widget W to PIXEL. */ 1042/* Set the background of widget W to PIXEL. */
1043 1043
1044static void 1044static void
1045xg_set_widget_bg (FRAME_PTR f, GtkWidget *w, long unsigned int pixel) 1045xg_set_widget_bg (struct frame *f, GtkWidget *w, long unsigned int pixel)
1046{ 1046{
1047#ifdef HAVE_GTK3 1047#ifdef HAVE_GTK3
1048 GdkRGBA bg; 1048 GdkRGBA bg;
@@ -1073,7 +1073,7 @@ style_changed_cb (GObject *go,
1073 gpointer user_data) 1073 gpointer user_data)
1074{ 1074{
1075 struct input_event event; 1075 struct input_event event;
1076 GdkDisplay *gdpy = (GdkDisplay *) user_data; 1076 GdkDisplay *gdpy = user_data;
1077 const char *display_name = gdk_display_get_name (gdpy); 1077 const char *display_name = gdk_display_get_name (gdpy);
1078 Display *dpy = GDK_DISPLAY_XDISPLAY (gdpy); 1078 Display *dpy = GDK_DISPLAY_XDISPLAY (gdpy);
1079 1079
@@ -1093,7 +1093,7 @@ style_changed_cb (GObject *go,
1093 Lisp_Object rest, frame; 1093 Lisp_Object rest, frame;
1094 FOR_EACH_FRAME (rest, frame) 1094 FOR_EACH_FRAME (rest, frame)
1095 { 1095 {
1096 FRAME_PTR f = XFRAME (frame); 1096 struct frame *f = XFRAME (frame);
1097 if (FRAME_LIVE_P (f) 1097 if (FRAME_LIVE_P (f)
1098 && FRAME_X_P (f) 1098 && FRAME_X_P (f)
1099 && FRAME_X_DISPLAY (f) == dpy) 1099 && FRAME_X_DISPLAY (f) == dpy)
@@ -1115,7 +1115,7 @@ delete_cb (GtkWidget *widget,
1115#ifdef HAVE_GTK3 1115#ifdef HAVE_GTK3
1116 /* The event doesn't arrive in the normal event loop. Send event 1116 /* The event doesn't arrive in the normal event loop. Send event
1117 here. */ 1117 here. */
1118 FRAME_PTR f = (FRAME_PTR) user_data; 1118 struct frame *f = user_data;
1119 struct input_event ie; 1119 struct input_event ie;
1120 1120
1121 EVENT_INIT (ie); 1121 EVENT_INIT (ie);
@@ -1131,7 +1131,7 @@ delete_cb (GtkWidget *widget,
1131 Return true if creation succeeded. */ 1131 Return true if creation succeeded. */
1132 1132
1133bool 1133bool
1134xg_create_frame_widgets (FRAME_PTR f) 1134xg_create_frame_widgets (struct frame *f)
1135{ 1135{
1136 GtkWidget *wtop; 1136 GtkWidget *wtop;
1137 GtkWidget *wvbox, *whbox; 1137 GtkWidget *wvbox, *whbox;
@@ -1300,7 +1300,7 @@ xg_create_frame_widgets (FRAME_PTR f)
1300} 1300}
1301 1301
1302void 1302void
1303xg_free_frame_widgets (FRAME_PTR f) 1303xg_free_frame_widgets (struct frame *f)
1304{ 1304{
1305 if (FRAME_GTK_OUTER_WIDGET (f)) 1305 if (FRAME_GTK_OUTER_WIDGET (f))
1306 { 1306 {
@@ -1332,7 +1332,7 @@ xg_free_frame_widgets (FRAME_PTR f)
1332 flag (this is useful when FLAGS is 0). */ 1332 flag (this is useful when FLAGS is 0). */
1333 1333
1334void 1334void
1335x_wm_set_size_hint (FRAME_PTR f, long int flags, bool user_position) 1335x_wm_set_size_hint (struct frame *f, long int flags, bool user_position)
1336{ 1336{
1337 /* Must use GTK routines here, otherwise GTK resets the size hints 1337 /* Must use GTK routines here, otherwise GTK resets the size hints
1338 to its own defaults. */ 1338 to its own defaults. */
@@ -1432,7 +1432,7 @@ x_wm_set_size_hint (FRAME_PTR f, long int flags, bool user_position)
1432 BG is the pixel value to change to. */ 1432 BG is the pixel value to change to. */
1433 1433
1434void 1434void
1435xg_set_background_color (FRAME_PTR f, long unsigned int bg) 1435xg_set_background_color (struct frame *f, long unsigned int bg)
1436{ 1436{
1437 if (FRAME_GTK_WIDGET (f)) 1437 if (FRAME_GTK_WIDGET (f))
1438 { 1438 {
@@ -1447,7 +1447,7 @@ xg_set_background_color (FRAME_PTR f, long unsigned int bg)
1447 functions so GTK does not overwrite the icon. */ 1447 functions so GTK does not overwrite the icon. */
1448 1448
1449void 1449void
1450xg_set_frame_icon (FRAME_PTR f, Pixmap icon_pixmap, Pixmap icon_mask) 1450xg_set_frame_icon (struct frame *f, Pixmap icon_pixmap, Pixmap icon_mask)
1451{ 1451{
1452 GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (f, 1452 GdkPixbuf *gp = xg_get_pixbuf_from_pix_and_mask (f,
1453 icon_pixmap, 1453 icon_pixmap,
@@ -1642,7 +1642,7 @@ xg_dialog_response_cb (GtkDialog *w,
1642 gint response, 1642 gint response,
1643 gpointer user_data) 1643 gpointer user_data)
1644{ 1644{
1645 struct xg_dialog_data *dd = (struct xg_dialog_data *)user_data; 1645 struct xg_dialog_data *dd = user_data;
1646 dd->response = response; 1646 dd->response = response;
1647 g_main_loop_quit (dd->loop); 1647 g_main_loop_quit (dd->loop);
1648} 1648}
@@ -1671,7 +1671,7 @@ pop_down_dialog (void *arg)
1671static gboolean 1671static gboolean
1672xg_maybe_add_timer (gpointer data) 1672xg_maybe_add_timer (gpointer data)
1673{ 1673{
1674 struct xg_dialog_data *dd = (struct xg_dialog_data *) data; 1674 struct xg_dialog_data *dd = data;
1675 EMACS_TIME next_time = timer_check (); 1675 EMACS_TIME next_time = timer_check ();
1676 1676
1677 dd->timerid = 0; 1677 dd->timerid = 0;
@@ -1693,7 +1693,7 @@ xg_maybe_add_timer (gpointer data)
1693 The dialog W is not destroyed when this function returns. */ 1693 The dialog W is not destroyed when this function returns. */
1694 1694
1695static int 1695static int
1696xg_dialog_run (FRAME_PTR f, GtkWidget *w) 1696xg_dialog_run (struct frame *f, GtkWidget *w)
1697{ 1697{
1698 ptrdiff_t count = SPECPDL_INDEX (); 1698 ptrdiff_t count = SPECPDL_INDEX ();
1699 struct xg_dialog_data dd; 1699 struct xg_dialog_data dd;
@@ -1813,7 +1813,7 @@ xg_toggle_notify_cb (GObject *gobject, GParamSpec *arg1, gpointer user_data)
1813 Returns the created widget. */ 1813 Returns the created widget. */
1814 1814
1815static GtkWidget * 1815static GtkWidget *
1816xg_get_file_with_chooser (FRAME_PTR f, 1816xg_get_file_with_chooser (struct frame *f,
1817 char *prompt, 1817 char *prompt,
1818 char *default_filename, 1818 char *default_filename,
1819 bool mustmatch_p, bool only_dir_p, 1819 bool mustmatch_p, bool only_dir_p,
@@ -1921,7 +1921,7 @@ static char *
1921xg_get_file_name_from_selector (GtkWidget *w) 1921xg_get_file_name_from_selector (GtkWidget *w)
1922{ 1922{
1923 GtkFileSelection *filesel = GTK_FILE_SELECTION (w); 1923 GtkFileSelection *filesel = GTK_FILE_SELECTION (w);
1924 return xstrdup ((char*) gtk_file_selection_get_filename (filesel)); 1924 return xstrdup (gtk_file_selection_get_filename (filesel));
1925} 1925}
1926 1926
1927/* Create a file selection dialog. 1927/* Create a file selection dialog.
@@ -1935,7 +1935,7 @@ xg_get_file_name_from_selector (GtkWidget *w)
1935 Returns the created widget. */ 1935 Returns the created widget. */
1936 1936
1937static GtkWidget * 1937static GtkWidget *
1938xg_get_file_with_selection (FRAME_PTR f, 1938xg_get_file_with_selection (struct frame *f,
1939 char *prompt, 1939 char *prompt,
1940 char *default_filename, 1940 char *default_filename,
1941 bool mustmatch_p, bool only_dir_p, 1941 bool mustmatch_p, bool only_dir_p,
@@ -1977,7 +1977,7 @@ xg_get_file_with_selection (FRAME_PTR f,
1977 The returned string must be freed by the caller. */ 1977 The returned string must be freed by the caller. */
1978 1978
1979char * 1979char *
1980xg_get_file_name (FRAME_PTR f, 1980xg_get_file_name (struct frame *f,
1981 char *prompt, 1981 char *prompt,
1982 char *default_filename, 1982 char *default_filename,
1983 bool mustmatch_p, 1983 bool mustmatch_p,
@@ -2051,7 +2051,7 @@ extern Lisp_Object Qxft;
2051 DEFAULT_NAME, if non-zero, is the default font name. */ 2051 DEFAULT_NAME, if non-zero, is the default font name. */
2052 2052
2053Lisp_Object 2053Lisp_Object
2054xg_get_font (FRAME_PTR f, const char *default_name) 2054xg_get_font (struct frame *f, const char *default_name)
2055{ 2055{
2056 GtkWidget *w; 2056 GtkWidget *w;
2057 int done = 0; 2057 int done = 0;
@@ -2169,7 +2169,7 @@ static xg_list_node xg_menu_item_cb_list;
2169 allocated xg_menu_cb_data if CL_DATA is NULL. */ 2169 allocated xg_menu_cb_data if CL_DATA is NULL. */
2170 2170
2171static xg_menu_cb_data * 2171static xg_menu_cb_data *
2172make_cl_data (xg_menu_cb_data *cl_data, FRAME_PTR f, GCallback highlight_cb) 2172make_cl_data (xg_menu_cb_data *cl_data, struct frame *f, GCallback highlight_cb)
2173{ 2173{
2174 if (! cl_data) 2174 if (! cl_data)
2175 { 2175 {
@@ -2201,7 +2201,7 @@ make_cl_data (xg_menu_cb_data *cl_data, FRAME_PTR f, GCallback highlight_cb)
2201 2201
2202static void 2202static void
2203update_cl_data (xg_menu_cb_data *cl_data, 2203update_cl_data (xg_menu_cb_data *cl_data,
2204 FRAME_PTR f, 2204 struct frame *f,
2205 GCallback highlight_cb) 2205 GCallback highlight_cb)
2206{ 2206{
2207 if (cl_data) 2207 if (cl_data)
@@ -2251,7 +2251,7 @@ xg_mark_data (void)
2251 2251
2252 FOR_EACH_FRAME (rest, frame) 2252 FOR_EACH_FRAME (rest, frame)
2253 { 2253 {
2254 FRAME_PTR f = XFRAME (frame); 2254 struct frame *f = XFRAME (frame);
2255 2255
2256 if (FRAME_X_P (f) && FRAME_GTK_OUTER_WIDGET (f)) 2256 if (FRAME_X_P (f) && FRAME_GTK_OUTER_WIDGET (f))
2257 { 2257 {
@@ -2277,7 +2277,7 @@ menuitem_destroy_callback (GtkWidget *w, gpointer client_data)
2277{ 2277{
2278 if (client_data) 2278 if (client_data)
2279 { 2279 {
2280 xg_menu_item_cb_data *data = (xg_menu_item_cb_data*) client_data; 2280 xg_menu_item_cb_data *data = client_data;
2281 xg_list_remove (&xg_menu_item_cb_list, &data->ptrs); 2281 xg_list_remove (&xg_menu_item_cb_list, &data->ptrs);
2282 xfree (data); 2282 xfree (data);
2283 } 2283 }
@@ -2301,8 +2301,7 @@ menuitem_highlight_callback (GtkWidget *w,
2301 2301
2302 ev.crossing = *event; 2302 ev.crossing = *event;
2303 subwidget = gtk_get_event_widget (&ev); 2303 subwidget = gtk_get_event_widget (&ev);
2304 data = (xg_menu_item_cb_data *) g_object_get_data (G_OBJECT (subwidget), 2304 data = g_object_get_data (G_OBJECT (subwidget), XG_ITEM_DATA);
2305 XG_ITEM_DATA);
2306 if (data) 2305 if (data)
2307 { 2306 {
2308 if (! NILP (data->help) && data->cl_data->highlight_cb) 2307 if (! NILP (data->help) && data->cl_data->highlight_cb)
@@ -2323,7 +2322,7 @@ menuitem_highlight_callback (GtkWidget *w,
2323static void 2322static void
2324menu_destroy_callback (GtkWidget *w, gpointer client_data) 2323menu_destroy_callback (GtkWidget *w, gpointer client_data)
2325{ 2324{
2326 unref_cl_data ((xg_menu_cb_data*) client_data); 2325 unref_cl_data (client_data);
2327} 2326}
2328 2327
2329/* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both 2328/* Make a GTK widget that contains both UTF8_LABEL and UTF8_KEY (both
@@ -2480,7 +2479,7 @@ xg_have_tear_offs (void)
2480 2479
2481static GtkWidget * 2480static GtkWidget *
2482xg_create_one_menuitem (widget_value *item, 2481xg_create_one_menuitem (widget_value *item,
2483 FRAME_PTR f, 2482 struct frame *f,
2484 GCallback select_cb, 2483 GCallback select_cb,
2485 GCallback highlight_cb, 2484 GCallback highlight_cb,
2486 xg_menu_cb_data *cl_data, 2485 xg_menu_cb_data *cl_data,
@@ -2551,7 +2550,7 @@ xg_create_one_menuitem (widget_value *item,
2551 2550
2552static GtkWidget * 2551static GtkWidget *
2553create_menus (widget_value *data, 2552create_menus (widget_value *data,
2554 FRAME_PTR f, 2553 struct frame *f,
2555 GCallback select_cb, 2554 GCallback select_cb,
2556 GCallback deactivate_cb, 2555 GCallback deactivate_cb,
2557 GCallback highlight_cb, 2556 GCallback highlight_cb,
@@ -2694,9 +2693,9 @@ create_menus (widget_value *data,
2694 Returns the widget created. */ 2693 Returns the widget created. */
2695 2694
2696GtkWidget * 2695GtkWidget *
2697xg_create_widget (const char *type, const char *name, FRAME_PTR f, widget_value *val, 2696xg_create_widget (const char *type, const char *name, struct frame *f,
2698 GCallback select_cb, GCallback deactivate_cb, 2697 widget_value *val, GCallback select_cb,
2699 GCallback highlight_cb) 2698 GCallback deactivate_cb, GCallback highlight_cb)
2700{ 2699{
2701 GtkWidget *w = 0; 2700 GtkWidget *w = 0;
2702 bool menu_bar_p = strcmp (type, "menubar") == 0; 2701 bool menu_bar_p = strcmp (type, "menubar") == 0;
@@ -2802,7 +2801,7 @@ xg_destroy_widgets (GList *list)
2802 2801
2803static void 2802static void
2804xg_update_menubar (GtkWidget *menubar, 2803xg_update_menubar (GtkWidget *menubar,
2805 FRAME_PTR f, 2804 struct frame *f,
2806 GList **list, 2805 GList **list,
2807 GList *iter, 2806 GList *iter,
2808 int pos, 2807 int pos,
@@ -3064,8 +3063,7 @@ xg_update_menu_item (widget_value *val,
3064 else if (val->enabled && ! gtk_widget_get_sensitive (w)) 3063 else if (val->enabled && ! gtk_widget_get_sensitive (w))
3065 gtk_widget_set_sensitive (w, TRUE); 3064 gtk_widget_set_sensitive (w, TRUE);
3066 3065
3067 cb_data = (xg_menu_item_cb_data*) g_object_get_data (G_OBJECT (w), 3066 cb_data = g_object_get_data (G_OBJECT (w), XG_ITEM_DATA);
3068 XG_ITEM_DATA);
3069 if (cb_data) 3067 if (cb_data)
3070 { 3068 {
3071 cb_data->call_data = val->call_data; 3069 cb_data->call_data = val->call_data;
@@ -3119,7 +3117,7 @@ xg_update_radio_item (widget_value *val, GtkWidget *w)
3119 3117
3120static GtkWidget * 3118static GtkWidget *
3121xg_update_submenu (GtkWidget *submenu, 3119xg_update_submenu (GtkWidget *submenu,
3122 FRAME_PTR f, 3120 struct frame *f,
3123 widget_value *val, 3121 widget_value *val,
3124 GCallback select_cb, 3122 GCallback select_cb,
3125 GCallback deactivate_cb, 3123 GCallback deactivate_cb,
@@ -3261,8 +3259,8 @@ xg_update_submenu (GtkWidget *submenu,
3261 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */ 3259 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. */
3262 3260
3263void 3261void
3264xg_modify_menubar_widgets (GtkWidget *menubar, FRAME_PTR f, widget_value *val, 3262xg_modify_menubar_widgets (GtkWidget *menubar, struct frame *f,
3265 bool deep_p, 3263 widget_value *val, bool deep_p,
3266 GCallback select_cb, GCallback deactivate_cb, 3264 GCallback select_cb, GCallback deactivate_cb,
3267 GCallback highlight_cb) 3265 GCallback highlight_cb)
3268{ 3266{
@@ -3271,8 +3269,7 @@ xg_modify_menubar_widgets (GtkWidget *menubar, FRAME_PTR f, widget_value *val,
3271 3269
3272 if (! list) return; 3270 if (! list) return;
3273 3271
3274 cl_data = (xg_menu_cb_data*) g_object_get_data (G_OBJECT (menubar), 3272 cl_data = g_object_get_data (G_OBJECT (menubar), XG_FRAME_DATA);
3275 XG_FRAME_DATA);
3276 3273
3277 xg_update_menubar (menubar, f, &list, list, 0, val->contents, 3274 xg_update_menubar (menubar, f, &list, list, 0, val->contents,
3278 select_cb, deactivate_cb, highlight_cb, cl_data); 3275 select_cb, deactivate_cb, highlight_cb, cl_data);
@@ -3336,7 +3333,7 @@ static void
3336menubar_map_cb (GtkWidget *w, gpointer user_data) 3333menubar_map_cb (GtkWidget *w, gpointer user_data)
3337{ 3334{
3338 GtkRequisition req; 3335 GtkRequisition req;
3339 FRAME_PTR f = (FRAME_PTR) user_data; 3336 struct frame *f = user_data;
3340 gtk_widget_get_preferred_size (w, NULL, &req); 3337 gtk_widget_get_preferred_size (w, NULL, &req);
3341 if (FRAME_MENUBAR_HEIGHT (f) != req.height) 3338 if (FRAME_MENUBAR_HEIGHT (f) != req.height)
3342 { 3339 {
@@ -3349,7 +3346,7 @@ menubar_map_cb (GtkWidget *w, gpointer user_data)
3349 changed. */ 3346 changed. */
3350 3347
3351void 3348void
3352xg_update_frame_menubar (FRAME_PTR f) 3349xg_update_frame_menubar (struct frame *f)
3353{ 3350{
3354 struct x_output *x = f->output_data.x; 3351 struct x_output *x = f->output_data.x;
3355 GtkRequisition req; 3352 GtkRequisition req;
@@ -3387,7 +3384,7 @@ xg_update_frame_menubar (FRAME_PTR f)
3387 This is used when deleting a frame, and when turning off the menu bar. */ 3384 This is used when deleting a frame, and when turning off the menu bar. */
3388 3385
3389void 3386void
3390free_frame_menubar (FRAME_PTR f) 3387free_frame_menubar (struct frame *f)
3391{ 3388{
3392 struct x_output *x = f->output_data.x; 3389 struct x_output *x = f->output_data.x;
3393 3390
@@ -3406,7 +3403,7 @@ free_frame_menubar (FRAME_PTR f)
3406} 3403}
3407 3404
3408bool 3405bool
3409xg_event_is_for_menubar (FRAME_PTR f, XEvent *event) 3406xg_event_is_for_menubar (struct frame *f, XEvent *event)
3410{ 3407{
3411 struct x_output *x = f->output_data.x; 3408 struct x_output *x = f->output_data.x;
3412 GList *iter; 3409 GList *iter;
@@ -3619,7 +3616,7 @@ xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data)
3619 to set resources for the widget. */ 3616 to set resources for the widget. */
3620 3617
3621void 3618void
3622xg_create_scroll_bar (FRAME_PTR f, 3619xg_create_scroll_bar (struct frame *f,
3623 struct scroll_bar *bar, 3620 struct scroll_bar *bar,
3624 GCallback scroll_callback, 3621 GCallback scroll_callback,
3625 GCallback end_callback, 3622 GCallback end_callback,
@@ -3681,7 +3678,7 @@ xg_create_scroll_bar (FRAME_PTR f,
3681/* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */ 3678/* Remove the scroll bar represented by SCROLLBAR_ID from the frame F. */
3682 3679
3683void 3680void
3684xg_remove_scroll_bar (FRAME_PTR f, ptrdiff_t scrollbar_id) 3681xg_remove_scroll_bar (struct frame *f, ptrdiff_t scrollbar_id)
3685{ 3682{
3686 GtkWidget *w = xg_get_widget_from_map (scrollbar_id); 3683 GtkWidget *w = xg_get_widget_from_map (scrollbar_id);
3687 if (w) 3684 if (w)
@@ -3699,7 +3696,7 @@ xg_remove_scroll_bar (FRAME_PTR f, ptrdiff_t scrollbar_id)
3699 WIDTH, HEIGHT is the size in pixels the bar shall have. */ 3696 WIDTH, HEIGHT is the size in pixels the bar shall have. */
3700 3697
3701void 3698void
3702xg_update_scrollbar_pos (FRAME_PTR f, 3699xg_update_scrollbar_pos (struct frame *f,
3703 ptrdiff_t scrollbar_id, 3700 ptrdiff_t scrollbar_id,
3704 int top, 3701 int top,
3705 int left, 3702 int left,
@@ -3781,7 +3778,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
3781{ 3778{
3782 GtkWidget *wscroll = xg_get_widget_from_map (bar->x_window); 3779 GtkWidget *wscroll = xg_get_widget_from_map (bar->x_window);
3783 3780
3784 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 3781 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3785 3782
3786 if (wscroll && NILP (bar->dragging)) 3783 if (wscroll && NILP (bar->dragging))
3787 { 3784 {
@@ -3861,7 +3858,7 @@ xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
3861 frame. This function does additional checks. */ 3858 frame. This function does additional checks. */
3862 3859
3863bool 3860bool
3864xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event) 3861xg_event_is_for_scrollbar (struct frame *f, XEvent *event)
3865{ 3862{
3866 bool retval = 0; 3863 bool retval = 0;
3867 3864
@@ -3946,7 +3943,7 @@ xg_tool_bar_callback (GtkWidget *w, gpointer client_data)
3946 gpointer gmod = g_object_get_data (G_OBJECT (w), XG_TOOL_BAR_LAST_MODIFIER); 3943 gpointer gmod = g_object_get_data (G_OBJECT (w), XG_TOOL_BAR_LAST_MODIFIER);
3947 intptr_t mod = (intptr_t) gmod; 3944 intptr_t mod = (intptr_t) gmod;
3948 3945
3949 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); 3946 struct frame *f = g_object_get_data (G_OBJECT (w), XG_FRAME_DATA);
3950 Lisp_Object key, frame; 3947 Lisp_Object key, frame;
3951 struct input_event event; 3948 struct input_event event;
3952 EVENT_INIT (event); 3949 EVENT_INIT (event);
@@ -4019,8 +4016,8 @@ static GtkWidget *
4019xg_get_tool_bar_widgets (GtkWidget *vb, GtkWidget **wimage) 4016xg_get_tool_bar_widgets (GtkWidget *vb, GtkWidget **wimage)
4020{ 4017{
4021 GList *clist = gtk_container_get_children (GTK_CONTAINER (vb)); 4018 GList *clist = gtk_container_get_children (GTK_CONTAINER (vb));
4022 GtkWidget *c1 = (GtkWidget *) clist->data; 4019 GtkWidget *c1 = clist->data;
4023 GtkWidget *c2 = clist->next ? (GtkWidget *) clist->next->data : NULL; 4020 GtkWidget *c2 = clist->next ? clist->next->data : NULL;
4024 4021
4025 *wimage = GTK_IS_IMAGE (c1) ? c1 : c2; 4022 *wimage = GTK_IS_IMAGE (c1) ? c1 : c2;
4026 g_list_free (clist); 4023 g_list_free (clist);
@@ -4149,7 +4146,7 @@ xg_tool_bar_detach_callback (GtkHandleBox *wbox,
4149 GtkWidget *w, 4146 GtkWidget *w,
4150 gpointer client_data) 4147 gpointer client_data)
4151{ 4148{
4152 FRAME_PTR f = (FRAME_PTR) client_data; 4149 struct frame *f = client_data;
4153 4150
4154 g_object_set (G_OBJECT (w), "show-arrow", !x_gtk_whole_detached_tool_bar, 4151 g_object_set (G_OBJECT (w), "show-arrow", !x_gtk_whole_detached_tool_bar,
4155 NULL); 4152 NULL);
@@ -4186,7 +4183,7 @@ xg_tool_bar_attach_callback (GtkHandleBox *wbox,
4186 GtkWidget *w, 4183 GtkWidget *w,
4187 gpointer client_data) 4184 gpointer client_data)
4188{ 4185{
4189 FRAME_PTR f = (FRAME_PTR) client_data; 4186 struct frame *f = client_data;
4190 g_object_set (G_OBJECT (w), "show-arrow", TRUE, NULL); 4187 g_object_set (G_OBJECT (w), "show-arrow", TRUE, NULL);
4191 4188
4192 if (f) 4189 if (f)
@@ -4224,7 +4221,7 @@ xg_tool_bar_help_callback (GtkWidget *w,
4224 gpointer client_data) 4221 gpointer client_data)
4225{ 4222{
4226 intptr_t idx = (intptr_t) client_data; 4223 intptr_t idx = (intptr_t) client_data;
4227 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); 4224 struct frame *f = g_object_get_data (G_OBJECT (w), XG_FRAME_DATA);
4228 Lisp_Object help, frame; 4225 Lisp_Object help, frame;
4229 4226
4230 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items)) 4227 if (! f || ! f->n_tool_bar_items || NILP (f->tool_bar_items))
@@ -4297,7 +4294,7 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
4297/* Attach a tool bar to frame F. */ 4294/* Attach a tool bar to frame F. */
4298 4295
4299static void 4296static void
4300xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos) 4297xg_pack_tool_bar (struct frame *f, Lisp_Object pos)
4301{ 4298{
4302 struct x_output *x = f->output_data.x; 4299 struct x_output *x = f->output_data.x;
4303 bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright); 4300 bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright);
@@ -4354,7 +4351,7 @@ xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
4354 x->toolbar_is_packed = true; 4351 x->toolbar_is_packed = true;
4355} 4352}
4356 4353
4357static bool xg_update_tool_bar_sizes (FRAME_PTR f); 4354static bool xg_update_tool_bar_sizes (struct frame *f);
4358 4355
4359static void 4356static void
4360tb_size_cb (GtkWidget *widget, 4357tb_size_cb (GtkWidget *widget,
@@ -4364,7 +4361,7 @@ tb_size_cb (GtkWidget *widget,
4364 /* When tool bar is created it has one preferred size. But when size is 4361 /* When tool bar is created it has one preferred size. But when size is
4365 allocated between widgets, it may get another. So we must update 4362 allocated between widgets, it may get another. So we must update
4366 size hints if tool bar size changes. Seen on Fedora 18 at least. */ 4363 size hints if tool bar size changes. Seen on Fedora 18 at least. */
4367 FRAME_PTR f = (FRAME_PTR) user_data; 4364 struct frame *f = user_data;
4368 if (xg_update_tool_bar_sizes (f)) 4365 if (xg_update_tool_bar_sizes (f))
4369 x_wm_set_size_hint (f, 0, 0); 4366 x_wm_set_size_hint (f, 0, 0);
4370} 4367}
@@ -4372,7 +4369,7 @@ tb_size_cb (GtkWidget *widget,
4372/* Create a tool bar for frame F. */ 4369/* Create a tool bar for frame F. */
4373 4370
4374static void 4371static void
4375xg_create_tool_bar (FRAME_PTR f) 4372xg_create_tool_bar (struct frame *f)
4376{ 4373{
4377 struct x_output *x = f->output_data.x; 4374 struct x_output *x = f->output_data.x;
4378#if GTK_CHECK_VERSION (3, 3, 6) 4375#if GTK_CHECK_VERSION (3, 3, 6)
@@ -4415,7 +4412,7 @@ xg_create_tool_bar (FRAME_PTR f)
4415 Returns IMAGE if RTL is not found. */ 4412 Returns IMAGE if RTL is not found. */
4416 4413
4417static Lisp_Object 4414static Lisp_Object
4418find_rtl_image (FRAME_PTR f, Lisp_Object image, Lisp_Object rtl) 4415find_rtl_image (struct frame *f, Lisp_Object image, Lisp_Object rtl)
4419{ 4416{
4420 int i; 4417 int i;
4421 Lisp_Object file, rtl_name; 4418 Lisp_Object file, rtl_name;
@@ -4443,7 +4440,7 @@ find_rtl_image (FRAME_PTR f, Lisp_Object image, Lisp_Object rtl)
4443} 4440}
4444 4441
4445static GtkToolItem * 4442static GtkToolItem *
4446xg_make_tool_item (FRAME_PTR f, 4443xg_make_tool_item (struct frame *f,
4447 GtkWidget *wimage, 4444 GtkWidget *wimage,
4448 GtkWidget **wbutton, 4445 GtkWidget **wbutton,
4449 const char *label, 4446 const char *label,
@@ -4606,7 +4603,7 @@ xg_tool_item_stale_p (GtkWidget *wbutton, const char *stock_name,
4606} 4603}
4607 4604
4608static bool 4605static bool
4609xg_update_tool_bar_sizes (FRAME_PTR f) 4606xg_update_tool_bar_sizes (struct frame *f)
4610{ 4607{
4611 struct x_output *x = f->output_data.x; 4608 struct x_output *x = f->output_data.x;
4612 GtkRequisition req; 4609 GtkRequisition req;
@@ -4654,7 +4651,7 @@ xg_update_tool_bar_sizes (FRAME_PTR f)
4654/* Update the tool bar for frame F. Add new buttons and remove old. */ 4651/* Update the tool bar for frame F. Add new buttons and remove old. */
4655 4652
4656void 4653void
4657update_frame_tool_bar (FRAME_PTR f) 4654update_frame_tool_bar (struct frame *f)
4658{ 4655{
4659 int i, j; 4656 int i, j;
4660 struct x_output *x = f->output_data.x; 4657 struct x_output *x = f->output_data.x;
@@ -4929,7 +4926,7 @@ update_frame_tool_bar (FRAME_PTR f)
4929 Remove the tool bar. */ 4926 Remove the tool bar. */
4930 4927
4931void 4928void
4932free_frame_tool_bar (FRAME_PTR f) 4929free_frame_tool_bar (struct frame *f)
4933{ 4930{
4934 struct x_output *x = f->output_data.x; 4931 struct x_output *x = f->output_data.x;
4935 4932
@@ -4976,7 +4973,7 @@ free_frame_tool_bar (FRAME_PTR f)
4976} 4973}
4977 4974
4978void 4975void
4979xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos) 4976xg_change_toolbar_position (struct frame *f, Lisp_Object pos)
4980{ 4977{
4981 struct x_output *x = f->output_data.x; 4978 struct x_output *x = f->output_data.x;
4982 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x); 4979 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x);
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 288b3e99299..482331a8934 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -55,7 +55,7 @@ typedef struct xg_menu_cb_data_
55{ 55{
56 xg_list_node ptrs; 56 xg_list_node ptrs;
57 57
58 FRAME_PTR f; 58 struct frame *f;
59 Lisp_Object menu_bar_vector; 59 Lisp_Object menu_bar_vector;
60 int menu_bar_items_used; 60 int menu_bar_items_used;
61 GCallback highlight_cb; 61 GCallback highlight_cb;
@@ -81,46 +81,46 @@ extern void free_widget_value (struct _widget_value *);
81 81
82extern bool xg_uses_old_file_dialog (void) ATTRIBUTE_CONST; 82extern bool xg_uses_old_file_dialog (void) ATTRIBUTE_CONST;
83 83
84extern char *xg_get_file_name (FRAME_PTR f, 84extern char *xg_get_file_name (struct frame *f,
85 char *prompt, 85 char *prompt,
86 char *default_filename, 86 char *default_filename,
87 bool mustmatch_p, 87 bool mustmatch_p,
88 bool only_dir_p); 88 bool only_dir_p);
89 89
90extern Lisp_Object xg_get_font (FRAME_PTR f, const char *); 90extern Lisp_Object xg_get_font (struct frame *f, const char *);
91 91
92extern GtkWidget *xg_create_widget (const char *type, 92extern GtkWidget *xg_create_widget (const char *type,
93 const char *name, 93 const char *name,
94 FRAME_PTR f, 94 struct frame *f,
95 struct _widget_value *val, 95 struct _widget_value *val,
96 GCallback select_cb, 96 GCallback select_cb,
97 GCallback deactivate_cb, 97 GCallback deactivate_cb,
98 GCallback highlight_cb); 98 GCallback highlight_cb);
99 99
100extern void xg_modify_menubar_widgets (GtkWidget *menubar, 100extern void xg_modify_menubar_widgets (GtkWidget *menubar,
101 FRAME_PTR f, 101 struct frame *f,
102 struct _widget_value *val, 102 struct _widget_value *val,
103 bool deep_p, 103 bool deep_p,
104 GCallback select_cb, 104 GCallback select_cb,
105 GCallback deactivate_cb, 105 GCallback deactivate_cb,
106 GCallback highlight_cb); 106 GCallback highlight_cb);
107 107
108extern void xg_update_frame_menubar (FRAME_PTR f); 108extern void xg_update_frame_menubar (struct frame *f);
109 109
110extern bool xg_event_is_for_menubar (FRAME_PTR f, XEvent *event); 110extern bool xg_event_is_for_menubar (struct frame *f, XEvent *event);
111 111
112extern bool xg_have_tear_offs (void); 112extern bool xg_have_tear_offs (void);
113 113
114extern ptrdiff_t xg_get_scroll_id_for_window (Display *dpy, Window wid); 114extern ptrdiff_t xg_get_scroll_id_for_window (Display *dpy, Window wid);
115 115
116extern void xg_create_scroll_bar (FRAME_PTR f, 116extern void xg_create_scroll_bar (struct frame *f,
117 struct scroll_bar *bar, 117 struct scroll_bar *bar,
118 GCallback scroll_callback, 118 GCallback scroll_callback,
119 GCallback end_callback, 119 GCallback end_callback,
120 const char *scroll_bar_name); 120 const char *scroll_bar_name);
121extern void xg_remove_scroll_bar (FRAME_PTR f, ptrdiff_t scrollbar_id); 121extern void xg_remove_scroll_bar (struct frame *f, ptrdiff_t scrollbar_id);
122 122
123extern void xg_update_scrollbar_pos (FRAME_PTR f, 123extern void xg_update_scrollbar_pos (struct frame *f,
124 ptrdiff_t scrollbar_id, 124 ptrdiff_t scrollbar_id,
125 int top, 125 int top,
126 int left, 126 int left,
@@ -131,40 +131,40 @@ extern void xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
131 int portion, 131 int portion,
132 int position, 132 int position,
133 int whole); 133 int whole);
134extern bool xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event); 134extern bool xg_event_is_for_scrollbar (struct frame *f, XEvent *event);
135extern int xg_get_default_scrollbar_width (void); 135extern int xg_get_default_scrollbar_width (void);
136 136
137extern void update_frame_tool_bar (FRAME_PTR f); 137extern void update_frame_tool_bar (struct frame *f);
138extern void free_frame_tool_bar (FRAME_PTR f); 138extern void free_frame_tool_bar (struct frame *f);
139extern void xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos); 139extern void xg_change_toolbar_position (struct frame *f, Lisp_Object pos);
140 140
141extern void xg_frame_resized (FRAME_PTR f, 141extern void xg_frame_resized (struct frame *f,
142 int pixelwidth, 142 int pixelwidth,
143 int pixelheight); 143 int pixelheight);
144extern void xg_frame_set_char_size (FRAME_PTR f, int cols, int rows); 144extern void xg_frame_set_char_size (struct frame *f, int cols, int rows);
145extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc); 145extern GtkWidget * xg_win_to_widget (Display *dpy, Window wdesc);
146 146
147extern void xg_display_open (char *display_name, Display **dpy); 147extern void xg_display_open (char *display_name, Display **dpy);
148extern void xg_display_close (Display *dpy); 148extern void xg_display_close (Display *dpy);
149extern GdkCursor * xg_create_default_cursor (Display *dpy); 149extern GdkCursor * xg_create_default_cursor (Display *dpy);
150 150
151extern bool xg_create_frame_widgets (FRAME_PTR f); 151extern bool xg_create_frame_widgets (struct frame *f);
152extern void xg_free_frame_widgets (FRAME_PTR f); 152extern void xg_free_frame_widgets (struct frame *f);
153extern void xg_set_background_color (FRAME_PTR f, unsigned long bg); 153extern void xg_set_background_color (struct frame *f, unsigned long bg);
154extern bool xg_check_special_colors (struct frame *f, 154extern bool xg_check_special_colors (struct frame *f,
155 const char *color_name, 155 const char *color_name,
156 XColor *color); 156 XColor *color);
157 157
158extern void xg_set_frame_icon (FRAME_PTR f, 158extern void xg_set_frame_icon (struct frame *f,
159 Pixmap icon_pixmap, 159 Pixmap icon_pixmap,
160 Pixmap icon_mask); 160 Pixmap icon_mask);
161 161
162extern bool xg_prepare_tooltip (FRAME_PTR f, 162extern bool xg_prepare_tooltip (struct frame *f,
163 Lisp_Object string, 163 Lisp_Object string,
164 int *width, 164 int *width,
165 int *height); 165 int *height);
166extern void xg_show_tooltip (FRAME_PTR f, int root_x, int root_y); 166extern void xg_show_tooltip (struct frame *f, int root_x, int root_y);
167extern bool xg_hide_tooltip (FRAME_PTR f); 167extern bool xg_hide_tooltip (struct frame *f);
168 168
169 169
170/* Mark all callback data that are Lisp_object:s during GC. */ 170/* Mark all callback data that are Lisp_object:s during GC. */
diff --git a/src/image.c b/src/image.c
index 1f8cb520dca..2db44d07c81 100644
--- a/src/image.c
+++ b/src/image.c
@@ -164,20 +164,20 @@ XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel)
164/* Functions to access the contents of a bitmap, given an id. */ 164/* Functions to access the contents of a bitmap, given an id. */
165 165
166int 166int
167x_bitmap_height (FRAME_PTR f, ptrdiff_t id) 167x_bitmap_height (struct frame *f, ptrdiff_t id)
168{ 168{
169 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height; 169 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height;
170} 170}
171 171
172int 172int
173x_bitmap_width (FRAME_PTR f, ptrdiff_t id) 173x_bitmap_width (struct frame *f, ptrdiff_t id)
174{ 174{
175 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width; 175 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width;
176} 176}
177 177
178#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) 178#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
179ptrdiff_t 179ptrdiff_t
180x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id) 180x_bitmap_pixmap (struct frame *f, ptrdiff_t id)
181{ 181{
182 /* HAVE_NTGUI needs the explicit cast here. */ 182 /* HAVE_NTGUI needs the explicit cast here. */
183 return (ptrdiff_t) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 183 return (ptrdiff_t) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
@@ -186,7 +186,7 @@ x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id)
186 186
187#ifdef HAVE_X_WINDOWS 187#ifdef HAVE_X_WINDOWS
188int 188int
189x_bitmap_mask (FRAME_PTR f, ptrdiff_t id) 189x_bitmap_mask (struct frame *f, ptrdiff_t id)
190{ 190{
191 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask; 191 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask;
192} 192}
@@ -195,7 +195,7 @@ x_bitmap_mask (FRAME_PTR f, ptrdiff_t id)
195/* Allocate a new bitmap record. Returns index of new record. */ 195/* Allocate a new bitmap record. Returns index of new record. */
196 196
197static ptrdiff_t 197static ptrdiff_t
198x_allocate_bitmap_record (FRAME_PTR f) 198x_allocate_bitmap_record (struct frame *f)
199{ 199{
200 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 200 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
201 ptrdiff_t i; 201 ptrdiff_t i;
@@ -216,7 +216,7 @@ x_allocate_bitmap_record (FRAME_PTR f)
216/* Add one reference to the reference count of the bitmap with id ID. */ 216/* Add one reference to the reference count of the bitmap with id ID. */
217 217
218void 218void
219x_reference_bitmap (FRAME_PTR f, ptrdiff_t id) 219x_reference_bitmap (struct frame *f, ptrdiff_t id)
220{ 220{
221 ++FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].refcount; 221 ++FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].refcount;
222} 222}
@@ -302,11 +302,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
302 id = x_allocate_bitmap_record (f); 302 id = x_allocate_bitmap_record (f);
303 dpyinfo->bitmaps[id - 1].img = bitmap; 303 dpyinfo->bitmaps[id - 1].img = bitmap;
304 dpyinfo->bitmaps[id - 1].refcount = 1; 304 dpyinfo->bitmaps[id - 1].refcount = 1;
305 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1); 305 dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
306 dpyinfo->bitmaps[id - 1].depth = 1; 306 dpyinfo->bitmaps[id - 1].depth = 1;
307 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap); 307 dpyinfo->bitmaps[id - 1].height = ns_image_width (bitmap);
308 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap); 308 dpyinfo->bitmaps[id - 1].width = ns_image_height (bitmap);
309 strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
310 return id; 309 return id;
311#endif 310#endif
312 311
@@ -345,11 +344,10 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
345 dpyinfo->bitmaps[id - 1].pixmap = bitmap; 344 dpyinfo->bitmaps[id - 1].pixmap = bitmap;
346 dpyinfo->bitmaps[id - 1].have_mask = 0; 345 dpyinfo->bitmaps[id - 1].have_mask = 0;
347 dpyinfo->bitmaps[id - 1].refcount = 1; 346 dpyinfo->bitmaps[id - 1].refcount = 1;
348 dpyinfo->bitmaps[id - 1].file = xmalloc (SBYTES (file) + 1); 347 dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
349 dpyinfo->bitmaps[id - 1].depth = 1; 348 dpyinfo->bitmaps[id - 1].depth = 1;
350 dpyinfo->bitmaps[id - 1].height = height; 349 dpyinfo->bitmaps[id - 1].height = height;
351 dpyinfo->bitmaps[id - 1].width = width; 350 dpyinfo->bitmaps[id - 1].width = width;
352 strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
353 351
354 return id; 352 return id;
355#endif /* HAVE_X_WINDOWS */ 353#endif /* HAVE_X_WINDOWS */
@@ -384,7 +382,7 @@ free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm)
384/* Remove reference to bitmap with id number ID. */ 382/* Remove reference to bitmap with id number ID. */
385 383
386void 384void
387x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id) 385x_destroy_bitmap (struct frame *f, ptrdiff_t id)
388{ 386{
389 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 387 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
390 388
@@ -1362,14 +1360,12 @@ static void cache_image (struct frame *f, struct image *img);
1362struct image_cache * 1360struct image_cache *
1363make_image_cache (void) 1361make_image_cache (void)
1364{ 1362{
1365 struct image_cache *c = xzalloc (sizeof *c); 1363 struct image_cache *c = xmalloc (sizeof *c);
1366 int size;
1367 1364
1368 size = 50; 1365 c->size = 50;
1369 c->images = xmalloc (size * sizeof *c->images); 1366 c->used = c->refcount = 0;
1370 c->size = size; 1367 c->images = xmalloc (c->size * sizeof *c->images);
1371 size = IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets; 1368 c->buckets = xzalloc (IMAGE_CACHE_BUCKETS_SIZE * sizeof *c->buckets);
1372 c->buckets = xzalloc (size);
1373 return c; 1369 return c;
1374} 1370}
1375 1371
@@ -3332,7 +3328,7 @@ static int
3332xpm_alloc_color (Display *dpy, Colormap cmap, char *color_name, XColor *color, 3328xpm_alloc_color (Display *dpy, Colormap cmap, char *color_name, XColor *color,
3333 void *closure) 3329 void *closure)
3334{ 3330{
3335 return xpm_lookup_color ((struct frame *) closure, color_name, color); 3331 return xpm_lookup_color (closure, color_name, color);
3336} 3332}
3337 3333
3338 3334
@@ -5652,8 +5648,7 @@ struct png_memory_storage
5652static void 5648static void
5653png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length) 5649png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length)
5654{ 5650{
5655 struct png_memory_storage *tbr 5651 struct png_memory_storage *tbr = fn_png_get_io_ptr (png_ptr);
5656 = (struct png_memory_storage *) fn_png_get_io_ptr (png_ptr);
5657 5652
5658 if (length > tbr->len - tbr->index) 5653 if (length > tbr->len - tbr->index)
5659 fn_png_error (png_ptr, "Read error"); 5654 fn_png_error (png_ptr, "Read error");
@@ -5670,7 +5665,7 @@ png_read_from_memory (png_structp png_ptr, png_bytep data, png_size_t length)
5670static void 5665static void
5671png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length) 5666png_read_from_file (png_structp png_ptr, png_bytep data, png_size_t length)
5672{ 5667{
5673 FILE *fp = (FILE *) fn_png_get_io_ptr (png_ptr); 5668 FILE *fp = fn_png_get_io_ptr (png_ptr);
5674 5669
5675 if (fread (data, 1, length, fp) < length) 5670 if (fread (data, 1, length, fp) < length)
5676 fn_png_error (png_ptr, "Read error"); 5671 fn_png_error (png_ptr, "Read error");
@@ -5814,9 +5809,9 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
5814 5809
5815 /* Read image info. */ 5810 /* Read image info. */
5816 if (!NILP (specified_data)) 5811 if (!NILP (specified_data))
5817 fn_png_set_read_fn (png_ptr, (void *) &tbr, png_read_from_memory); 5812 fn_png_set_read_fn (png_ptr, &tbr, png_read_from_memory);
5818 else 5813 else
5819 fn_png_set_read_fn (png_ptr, (void *) fp, png_read_from_file); 5814 fn_png_set_read_fn (png_ptr, fp, png_read_from_file);
5820 5815
5821 fn_png_set_sig_bytes (png_ptr, sizeof sig); 5816 fn_png_set_sig_bytes (png_ptr, sizeof sig);
5822 fn_png_read_info (png_ptr, info_ptr); 5817 fn_png_read_info (png_ptr, info_ptr);
@@ -6306,7 +6301,7 @@ our_memory_fill_input_buffer (j_decompress_ptr cinfo)
6306static void 6301static void
6307our_memory_skip_input_data (j_decompress_ptr cinfo, long int num_bytes) 6302our_memory_skip_input_data (j_decompress_ptr cinfo, long int num_bytes)
6308{ 6303{
6309 struct jpeg_source_mgr *src = (struct jpeg_source_mgr *) cinfo->src; 6304 struct jpeg_source_mgr *src = cinfo->src;
6310 6305
6311 if (src) 6306 if (src)
6312 { 6307 {
@@ -6326,19 +6321,17 @@ our_memory_skip_input_data (j_decompress_ptr cinfo, long int num_bytes)
6326static void 6321static void
6327jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, ptrdiff_t len) 6322jpeg_memory_src (j_decompress_ptr cinfo, JOCTET *data, ptrdiff_t len)
6328{ 6323{
6329 struct jpeg_source_mgr *src; 6324 struct jpeg_source_mgr *src = cinfo->src;
6330 6325
6331 if (cinfo->src == NULL) 6326 if (! src)
6332 { 6327 {
6333 /* First time for this JPEG object? */ 6328 /* First time for this JPEG object? */
6334 cinfo->src = (struct jpeg_source_mgr *) 6329 src = cinfo->mem->alloc_small ((j_common_ptr) cinfo,
6335 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 6330 JPOOL_PERMANENT, sizeof *src);
6336 sizeof (struct jpeg_source_mgr)); 6331 cinfo->src = src;
6337 src = (struct jpeg_source_mgr *) cinfo->src;
6338 src->next_input_byte = data; 6332 src->next_input_byte = data;
6339 } 6333 }
6340 6334
6341 src = (struct jpeg_source_mgr *) cinfo->src;
6342 src->init_source = our_common_init_source; 6335 src->init_source = our_common_init_source;
6343 src->fill_input_buffer = our_memory_fill_input_buffer; 6336 src->fill_input_buffer = our_memory_fill_input_buffer;
6344 src->skip_input_data = our_memory_skip_input_data; 6337 src->skip_input_data = our_memory_skip_input_data;
@@ -6430,20 +6423,17 @@ our_stdio_skip_input_data (j_decompress_ptr cinfo, long int num_bytes)
6430static void 6423static void
6431jpeg_file_src (j_decompress_ptr cinfo, FILE *fp) 6424jpeg_file_src (j_decompress_ptr cinfo, FILE *fp)
6432{ 6425{
6433 struct jpeg_stdio_mgr *src; 6426 struct jpeg_stdio_mgr *src = (struct jpeg_stdio_mgr *) cinfo->src;
6434 6427
6435 if (cinfo->src != NULL) 6428 if (! src)
6436 src = (struct jpeg_stdio_mgr *) cinfo->src;
6437 else
6438 { 6429 {
6439 /* First time for this JPEG object? */ 6430 /* First time for this JPEG object? */
6440 cinfo->src = (struct jpeg_source_mgr *) 6431 src = cinfo->mem->alloc_small ((j_common_ptr) cinfo,
6441 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 6432 JPOOL_PERMANENT, sizeof *src);
6442 sizeof (struct jpeg_stdio_mgr)); 6433 cinfo->src = (struct jpeg_source_mgr *) src;
6443 src = (struct jpeg_stdio_mgr *) cinfo->src; 6434 src->buffer = cinfo->mem->alloc_small ((j_common_ptr) cinfo,
6444 src->buffer = (JOCTET *) 6435 JPOOL_PERMANENT,
6445 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 6436 JPEG_STDIO_BUFFER_SIZE);
6446 JPEG_STDIO_BUFFER_SIZE);
6447 } 6437 }
6448 6438
6449 src->file = fp; 6439 src->file = fp;
@@ -7746,6 +7736,7 @@ enum imagemagick_keyword_index
7746 IMAGEMAGICK_WIDTH, 7736 IMAGEMAGICK_WIDTH,
7747 IMAGEMAGICK_MAX_HEIGHT, 7737 IMAGEMAGICK_MAX_HEIGHT,
7748 IMAGEMAGICK_MAX_WIDTH, 7738 IMAGEMAGICK_MAX_WIDTH,
7739 IMAGEMAGICK_FORMAT,
7749 IMAGEMAGICK_ROTATION, 7740 IMAGEMAGICK_ROTATION,
7750 IMAGEMAGICK_CROP, 7741 IMAGEMAGICK_CROP,
7751 IMAGEMAGICK_LAST 7742 IMAGEMAGICK_LAST
@@ -7770,6 +7761,7 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7770 {":width", IMAGE_INTEGER_VALUE, 0}, 7761 {":width", IMAGE_INTEGER_VALUE, 0},
7771 {":max-height", IMAGE_INTEGER_VALUE, 0}, 7762 {":max-height", IMAGE_INTEGER_VALUE, 0},
7772 {":max-width", IMAGE_INTEGER_VALUE, 0}, 7763 {":max-width", IMAGE_INTEGER_VALUE, 0},
7764 {":format", IMAGE_SYMBOL_VALUE, 0},
7773 {":rotation", IMAGE_NUMBER_VALUE, 0}, 7765 {":rotation", IMAGE_NUMBER_VALUE, 0},
7774 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0} 7766 {":crop", IMAGE_DONT_CHECK_VALUE_TYPE, 0}
7775 }; 7767 };
@@ -7848,6 +7840,233 @@ imagemagick_error (MagickWand *wand)
7848 description = (char *) MagickRelinquishMemory (description); 7840 description = (char *) MagickRelinquishMemory (description);
7849} 7841}
7850 7842
7843/* Possibly give ImageMagick some extra help to determine the image
7844 type by supplying a "dummy" filename based on the Content-Type. */
7845
7846static char *
7847imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent])
7848{
7849 Lisp_Object symbol = intern ("image-format-suffixes");
7850 Lisp_Object val = find_symbol_value (symbol);
7851 Lisp_Object format;
7852
7853 if (! CONSP (val))
7854 return NULL;
7855
7856 format = image_spec_value (spec, intern (":format"), NULL);
7857 val = Fcar_safe (Fcdr_safe (Fassq (format, val)));
7858 if (! STRINGP (val))
7859 return NULL;
7860
7861 /* It's OK to truncate the hint if it has MaxTextExtent or more bytes,
7862 as ImageMagick would ignore the extra bytes anyway. */
7863 snprintf (hint_buffer, MaxTextExtent, "/tmp/foo.%s", SSDATA (val));
7864 return hint_buffer;
7865}
7866
7867/* Animated images (e.g., GIF89a) are composed from one "master image"
7868 (which is the first one, and then there's a number of images that
7869 follow. If following images have non-transparent colors, these are
7870 composed "on top" of the master image. So, in general, one has to
7871 compute ann the preceding images to be able to display a particular
7872 sub-image.
7873
7874 Computing all the preceding images is too slow, so we maintain a
7875 cache of previously computed images. We have to maintain a cache
7876 separate from the image cache, because the images may be scaled
7877 before display. */
7878
7879struct animation_cache
7880{
7881 MagickWand *wand;
7882 int index;
7883 EMACS_TIME update_time;
7884 struct animation_cache *next;
7885 char signature[FLEXIBLE_ARRAY_MEMBER];
7886};
7887
7888static struct animation_cache *animation_cache = NULL;
7889
7890static struct animation_cache *
7891imagemagick_create_cache (char *signature)
7892{
7893 struct animation_cache *cache
7894 = xmalloc (offsetof (struct animation_cache, signature)
7895 + strlen (signature) + 1);
7896 cache->wand = 0;
7897 cache->index = 0;
7898 cache->next = 0;
7899 strcpy (cache->signature, signature);
7900 return cache;
7901}
7902
7903/* Discard cached images that haven't been used for a minute. */
7904static void
7905imagemagick_prune_animation_cache (void)
7906{
7907 struct animation_cache **pcache = &animation_cache;
7908 EMACS_TIME old = sub_emacs_time (current_emacs_time (),
7909 make_emacs_time (60, 0));
7910
7911 while (*pcache)
7912 {
7913 struct animation_cache *cache = *pcache;
7914 if (EMACS_TIME_LE (old, cache->update_time))
7915 pcache = &cache->next;
7916 else
7917 {
7918 if (cache->wand)
7919 DestroyMagickWand (cache->wand);
7920 *pcache = cache->next;
7921 xfree (cache);
7922 }
7923 }
7924}
7925
7926static struct animation_cache *
7927imagemagick_get_animation_cache (MagickWand *wand)
7928{
7929 char *signature = MagickGetImageSignature (wand);
7930 struct animation_cache *cache;
7931 struct animation_cache **pcache = &animation_cache;
7932
7933 imagemagick_prune_animation_cache ();
7934
7935 while (1)
7936 {
7937 cache = *pcache;
7938 if (! cache)
7939 {
7940 *pcache = cache = imagemagick_create_cache (signature);
7941 break;
7942 }
7943 if (strcmp (signature, cache->signature) == 0)
7944 break;
7945 pcache = &cache->next;
7946 }
7947
7948 DestroyString (signature);
7949 cache->update_time = current_emacs_time ();
7950 return cache;
7951}
7952
7953static MagickWand *
7954imagemagick_compute_animated_image (MagickWand *super_wand, int ino)
7955{
7956 int i;
7957 MagickWand *composite_wand;
7958 size_t dest_width, dest_height;
7959 struct animation_cache *cache = imagemagick_get_animation_cache (super_wand);
7960
7961 MagickSetIteratorIndex (super_wand, 0);
7962
7963 if (ino == 0 || cache->wand == NULL || cache->index > ino)
7964 {
7965 composite_wand = MagickGetImage (super_wand);
7966 if (cache->wand)
7967 DestroyMagickWand (cache->wand);
7968 }
7969 else
7970 composite_wand = cache->wand;
7971
7972 dest_width = MagickGetImageWidth (composite_wand);
7973 dest_height = MagickGetImageHeight (composite_wand);
7974
7975 for (i = max (1, cache->index + 1); i <= ino; i++)
7976 {
7977 MagickWand *sub_wand;
7978 PixelIterator *source_iterator, *dest_iterator;
7979 PixelWand **source, **dest;
7980 size_t source_width, source_height;
7981 ssize_t source_left, source_top;
7982 MagickPixelPacket pixel;
7983 DisposeType dispose;
7984 ptrdiff_t lines = 0;
7985
7986 MagickSetIteratorIndex (super_wand, i);
7987 sub_wand = MagickGetImage (super_wand);
7988
7989 MagickGetImagePage (sub_wand, &source_width, &source_height,
7990 &source_left, &source_top);
7991
7992 /* This flag says how to handle transparent pixels. */
7993 dispose = MagickGetImageDispose (sub_wand);
7994
7995 source_iterator = NewPixelIterator (sub_wand);
7996 if (! source_iterator)
7997 {
7998 DestroyMagickWand (composite_wand);
7999 DestroyMagickWand (sub_wand);
8000 cache->wand = NULL;
8001 image_error ("Imagemagick pixel iterator creation failed",
8002 Qnil, Qnil);
8003 return NULL;
8004 }
8005
8006 dest_iterator = NewPixelIterator (composite_wand);
8007 if (! dest_iterator)
8008 {
8009 DestroyMagickWand (composite_wand);
8010 DestroyMagickWand (sub_wand);
8011 DestroyPixelIterator (source_iterator);
8012 cache->wand = NULL;
8013 image_error ("Imagemagick pixel iterator creation failed",
8014 Qnil, Qnil);
8015 return NULL;
8016 }
8017
8018 /* The sub-image may not start at origin, so move the destination
8019 iterator to where the sub-image should start. */
8020 if (source_top > 0)
8021 {
8022 PixelSetIteratorRow (dest_iterator, source_top);
8023 lines = source_top;
8024 }
8025
8026 while ((source = PixelGetNextIteratorRow (source_iterator, &source_width))
8027 != NULL)
8028 {
8029 ptrdiff_t x;
8030
8031 /* Sanity check. This shouldn't happen, but apparently
8032 does in some pictures. */
8033 if (++lines >= dest_height)
8034 break;
8035
8036 dest = PixelGetNextIteratorRow (dest_iterator, &dest_width);
8037 for (x = 0; x < source_width; x++)
8038 {
8039 /* Sanity check. This shouldn't happen, but apparently
8040 also does in some pictures. */
8041 if (x + source_left > dest_width)
8042 break;
8043 /* Normally we only copy over non-transparent pixels,
8044 but if the disposal method is "Background", then we
8045 copy over all pixels. */
8046 if (dispose == BackgroundDispose ||
8047 PixelGetAlpha (source[x]))
8048 {
8049 PixelGetMagickColor (source[x], &pixel);
8050 PixelSetMagickColor (dest[x + source_left], &pixel);
8051 }
8052 }
8053 PixelSyncIterator (dest_iterator);
8054 }
8055
8056 DestroyPixelIterator (source_iterator);
8057 DestroyPixelIterator (dest_iterator);
8058 DestroyMagickWand (sub_wand);
8059 }
8060
8061 /* Cache a copy for the next iteration. The current wand will be
8062 destroyed by the caller. */
8063 cache->wand = CloneMagickWand (composite_wand);
8064 cache->index = ino;
8065
8066 return composite_wand;
8067}
8068
8069
7851/* Helper function for imagemagick_load, which does the actual loading 8070/* Helper function for imagemagick_load, which does the actual loading
7852 given contents and size, apart from frame and image structures, 8071 given contents and size, apart from frame and image structures,
7853 passed from imagemagick_load. Uses librimagemagick to do most of 8072 passed from imagemagick_load. Uses librimagemagick to do most of
@@ -7870,7 +8089,6 @@ imagemagick_load_image (struct frame *f, struct image *img,
7870 XImagePtr ximg; 8089 XImagePtr ximg;
7871 int x, y; 8090 int x, y;
7872 MagickWand *image_wand; 8091 MagickWand *image_wand;
7873 MagickWand *ping_wand;
7874 PixelIterator *iterator; 8092 PixelIterator *iterator;
7875 PixelWand **pixels, *bg_wand = NULL; 8093 PixelWand **pixels, *bg_wand = NULL;
7876 MagickPixelPacket pixel; 8094 MagickPixelPacket pixel;
@@ -7881,6 +8099,8 @@ imagemagick_load_image (struct frame *f, struct image *img,
7881 int desired_width, desired_height; 8099 int desired_width, desired_height;
7882 double rotation; 8100 double rotation;
7883 int pixelwidth; 8101 int pixelwidth;
8102 char hint_buffer[MaxTextExtent];
8103 char *filename_hint = NULL;
7884 8104
7885 /* Handle image index for image types who can contain more than one image. 8105 /* Handle image index for image types who can contain more than one image.
7886 Interface :index is same as for GIF. First we "ping" the image to see how 8106 Interface :index is same as for GIF. First we "ping" the image to see how
@@ -7891,48 +8111,48 @@ imagemagick_load_image (struct frame *f, struct image *img,
7891 MagickWandGenesis (); 8111 MagickWandGenesis ();
7892 image = image_spec_value (img->spec, QCindex, NULL); 8112 image = image_spec_value (img->spec, QCindex, NULL);
7893 ino = INTEGERP (image) ? XFASTINT (image) : 0; 8113 ino = INTEGERP (image) ? XFASTINT (image) : 0;
7894 ping_wand = NewMagickWand (); 8114 image_wand = NewMagickWand ();
7895 /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */
7896 8115
7897 status = filename 8116 if (filename)
7898 ? MagickPingImage (ping_wand, filename) 8117 status = MagickReadImage (image_wand, filename);
7899 : MagickPingImageBlob (ping_wand, contents, size); 8118 else
8119 {
8120 filename_hint = imagemagick_filename_hint (img->spec, hint_buffer);
8121 MagickSetFilename (image_wand, filename_hint);
8122 status = MagickReadImageBlob (image_wand, contents, size);
8123 }
7900 8124
7901 if (status == MagickFalse) 8125 if (status == MagickFalse)
7902 { 8126 {
7903 imagemagick_error (ping_wand); 8127 imagemagick_error (image_wand);
7904 DestroyMagickWand (ping_wand); 8128 DestroyMagickWand (image_wand);
7905 return 0; 8129 return 0;
7906 } 8130 }
7907 8131
7908 if (ino < 0 || ino >= MagickGetNumberImages (ping_wand)) 8132 if (ino < 0 || ino >= MagickGetNumberImages (image_wand))
7909 { 8133 {
7910 image_error ("Invalid image number `%s' in image `%s'", 8134 image_error ("Invalid image number `%s' in image `%s'",
7911 image, img->spec); 8135 image, img->spec);
7912 DestroyMagickWand (ping_wand); 8136 DestroyMagickWand (image_wand);
7913 return 0; 8137 return 0;
7914 } 8138 }
7915 8139
7916 if (MagickGetNumberImages (ping_wand) > 1) 8140 if (MagickGetNumberImages (image_wand) > 1)
7917 img->lisp_data = 8141 img->lisp_data =
7918 Fcons (Qcount, 8142 Fcons (Qcount,
7919 Fcons (make_number (MagickGetNumberImages (ping_wand)), 8143 Fcons (make_number (MagickGetNumberImages (image_wand)),
7920 img->lisp_data)); 8144 img->lisp_data));
7921 8145
7922 DestroyMagickWand (ping_wand); 8146 /* If we have an animated image, get the new wand based on the
7923 8147 "super-wand". */
7924 /* Now we know how many images are inside the file. If it's not a 8148 if (MagickGetNumberImages (image_wand) > 1)
7925 bundle, the number is one. Load the image data. */
7926
7927 image_wand = NewMagickWand ();
7928
7929 if ((filename
7930 ? MagickReadImage (image_wand, filename)
7931 : MagickReadImageBlob (image_wand, contents, size))
7932 == MagickFalse)
7933 { 8149 {
7934 imagemagick_error (image_wand); 8150 MagickWand *super_wand = image_wand;
7935 goto imagemagick_error; 8151 image_wand = imagemagick_compute_animated_image (super_wand, ino);
8152 if (! image_wand)
8153 image_wand = super_wand;
8154 else
8155 DestroyMagickWand (super_wand);
7936 } 8156 }
7937 8157
7938 /* Retrieve the frame's background color, for use later. */ 8158 /* Retrieve the frame's background color, for use later. */
@@ -8120,7 +8340,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
8120 8340
8121 /* Copy pixels from the imagemagick image structure to the x image map. */ 8341 /* Copy pixels from the imagemagick image structure to the x image map. */
8122 iterator = NewPixelIterator (image_wand); 8342 iterator = NewPixelIterator (image_wand);
8123 if (iterator == (PixelIterator *) NULL) 8343 if (! iterator)
8124 { 8344 {
8125#ifdef COLOR_TABLE_SUPPORT 8345#ifdef COLOR_TABLE_SUPPORT
8126 free_color_table (); 8346 free_color_table ();
@@ -8135,7 +8355,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
8135 for (y = 0; y < image_height; y++) 8355 for (y = 0; y < image_height; y++)
8136 { 8356 {
8137 pixels = PixelGetNextIteratorRow (iterator, &width); 8357 pixels = PixelGetNextIteratorRow (iterator, &width);
8138 if (pixels == (PixelWand **) NULL) 8358 if (! pixels)
8139 break; 8359 break;
8140 for (x = 0; x < (long) width; x++) 8360 for (x = 0; x < (long) width; x++)
8141 { 8361 {
@@ -9200,7 +9420,7 @@ A cross is always drawn on black & white displays. */);
9200 9420
9201 DEFVAR_LISP ("x-bitmap-file-path", Vx_bitmap_file_path, 9421 DEFVAR_LISP ("x-bitmap-file-path", Vx_bitmap_file_path,
9202 doc: /* List of directories to search for window system bitmap files. */); 9422 doc: /* List of directories to search for window system bitmap files. */);
9203 Vx_bitmap_file_path = decode_env_path ((char *) 0, PATH_BITMAPS); 9423 Vx_bitmap_file_path = decode_env_path (0, PATH_BITMAPS);
9204 9424
9205 DEFVAR_LISP ("image-cache-eviction-delay", Vimage_cache_eviction_delay, 9425 DEFVAR_LISP ("image-cache-eviction-delay", Vimage_cache_eviction_delay,
9206 doc: /* Maximum time after which images are removed from the cache. 9426 doc: /* Maximum time after which images are removed from the cache.
diff --git a/src/indent.c b/src/indent.c
index 47358e17db8..6aaf86579d7 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -141,13 +141,13 @@ recompute_width_table (struct buffer *buf, struct Lisp_Char_Table *disptab)
141 XSETFASTINT (widthtab->contents[i], character_width (i, disptab)); 141 XSETFASTINT (widthtab->contents[i], character_width (i, disptab));
142} 142}
143 143
144/* Allocate or free the width run cache, as requested by the current 144/* Allocate or free the width run cache, as requested by the
145 state of current_buffer's cache_long_line_scans variable. */ 145 current state of current_buffer's cache_long_scans variable. */
146 146
147static void 147static void
148width_run_cache_on_off (void) 148width_run_cache_on_off (void)
149{ 149{
150 if (NILP (BVAR (current_buffer, cache_long_line_scans)) 150 if (NILP (BVAR (current_buffer, cache_long_scans))
151 /* And, for the moment, this feature doesn't work on multibyte 151 /* And, for the moment, this feature doesn't work on multibyte
152 characters. */ 152 characters. */
153 || !NILP (BVAR (current_buffer, enable_multibyte_characters))) 153 || !NILP (BVAR (current_buffer, enable_multibyte_characters)))
diff --git a/src/insdel.c b/src/insdel.c
index 15d585568a0..f746fd34330 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1211,12 +1211,9 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte,
1211 adjust_markers_for_insert (from, from_byte, 1211 adjust_markers_for_insert (from, from_byte,
1212 from + len, from_byte + len_byte, 0); 1212 from + len, from_byte + len_byte, 0);
1213 1213
1214 if (! EQ (BVAR (current_buffer, undo_list), Qt)) 1214 if (nchars_del > 0)
1215 { 1215 record_delete (from, prev_text);
1216 if (nchars_del > 0) 1216 record_insert (from, len);
1217 record_delete (from, prev_text);
1218 record_insert (from, len);
1219 }
1220 1217
1221 if (len > nchars_del) 1218 if (len > nchars_del)
1222 adjust_overlays_for_insert (from, len - nchars_del); 1219 adjust_overlays_for_insert (from, len - nchars_del);
@@ -1373,12 +1370,12 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1373 emacs_abort (); 1370 emacs_abort ();
1374#endif 1371#endif
1375 1372
1376 if (! EQ (BVAR (current_buffer, undo_list), Qt)) 1373 /* Record the insertion first, so that when we undo,
1374 the deletion will be undone first. Thus, undo
1375 will insert before deleting, and thus will keep
1376 the markers before and after this text separate. */
1377 if (!NILP (deletion))
1377 { 1378 {
1378 /* Record the insertion first, so that when we undo,
1379 the deletion will be undone first. Thus, undo
1380 will insert before deleting, and thus will keep
1381 the markers before and after this text separate. */
1382 record_insert (from + SCHARS (deletion), inschars); 1379 record_insert (from + SCHARS (deletion), inschars);
1383 record_delete (from, deletion); 1380 record_delete (from, deletion);
1384 } 1381 }
@@ -1718,8 +1715,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1718 so that undo handles this after reinserting the text. */ 1715 so that undo handles this after reinserting the text. */
1719 adjust_markers_for_delete (from, from_byte, to, to_byte); 1716 adjust_markers_for_delete (from, from_byte, to, to_byte);
1720 1717
1721 if (! EQ (BVAR (current_buffer, undo_list), Qt)) 1718 record_delete (from, deletion);
1722 record_delete (from, deletion);
1723 MODIFF++; 1719 MODIFF++;
1724 CHARS_MODIFF = MODIFF; 1720 CHARS_MODIFF = MODIFF;
1725 1721
@@ -1760,27 +1756,22 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte,
1760 return deletion; 1756 return deletion;
1761} 1757}
1762 1758
1763/* Call this if you're about to change the region of current buffer 1759/* Call this if you're about to change the text of current buffer
1764 from character positions START to END. This checks the read-only 1760 from character positions START to END. This checks the read-only
1765 properties of the region, calls the necessary modification hooks, 1761 properties of the region, calls the necessary modification hooks,
1766 and warns the next redisplay that it should pay attention to that 1762 and warns the next redisplay that it should pay attention to that
1767 area. 1763 area. */
1768
1769 If PRESERVE_CHARS_MODIFF, do not update CHARS_MODIFF.
1770 Otherwise set CHARS_MODIFF to the new value of MODIFF. */
1771 1764
1772void 1765void
1773modify_region_1 (ptrdiff_t start, ptrdiff_t end, bool preserve_chars_modiff) 1766modify_text (ptrdiff_t start, ptrdiff_t end)
1774{ 1767{
1775 prepare_to_modify_buffer (start, end, NULL); 1768 prepare_to_modify_buffer (start, end, NULL);
1776 1769
1777 BUF_COMPUTE_UNCHANGED (current_buffer, start - 1, end); 1770 BUF_COMPUTE_UNCHANGED (current_buffer, start - 1, end);
1778
1779 if (MODIFF <= SAVE_MODIFF) 1771 if (MODIFF <= SAVE_MODIFF)
1780 record_first_change (); 1772 record_first_change ();
1781 MODIFF++; 1773 MODIFF++;
1782 if (! preserve_chars_modiff) 1774 CHARS_MODIFF = MODIFF;
1783 CHARS_MODIFF = MODIFF;
1784 1775
1785 bset_point_before_scroll (current_buffer, Qnil); 1776 bset_point_before_scroll (current_buffer, Qnil);
1786} 1777}
@@ -1796,8 +1787,8 @@ modify_region_1 (ptrdiff_t start, ptrdiff_t end, bool preserve_chars_modiff)
1796 by holding its value temporarily in a marker. */ 1787 by holding its value temporarily in a marker. */
1797 1788
1798void 1789void
1799prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end, 1790prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end,
1800 ptrdiff_t *preserve_ptr) 1791 ptrdiff_t *preserve_ptr)
1801{ 1792{
1802 struct buffer *base_buffer; 1793 struct buffer *base_buffer;
1803 1794
@@ -1868,6 +1859,17 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
1868 } 1859 }
1869 1860
1870 signal_before_change (start, end, preserve_ptr); 1861 signal_before_change (start, end, preserve_ptr);
1862 Vdeactivate_mark = Qt;
1863}
1864
1865/* Like above, but called when we know that the buffer text
1866 will be modified and region caches should be invalidated. */
1867
1868void
1869prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
1870 ptrdiff_t *preserve_ptr)
1871{
1872 prepare_to_modify_buffer_1 (start, end, preserve_ptr);
1871 1873
1872 if (current_buffer->newline_cache) 1874 if (current_buffer->newline_cache)
1873 invalidate_region_cache (current_buffer, 1875 invalidate_region_cache (current_buffer,
@@ -1877,10 +1879,12 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
1877 invalidate_region_cache (current_buffer, 1879 invalidate_region_cache (current_buffer,
1878 current_buffer->width_run_cache, 1880 current_buffer->width_run_cache,
1879 start - BEG, Z - end); 1881 start - BEG, Z - end);
1880 1882 if (current_buffer->bidi_paragraph_cache)
1881 Vdeactivate_mark = Qt; 1883 invalidate_region_cache (current_buffer,
1884 current_buffer->bidi_paragraph_cache,
1885 start - BEG, Z - end);
1882} 1886}
1883 1887
1884/* These macros work with an argument named `preserve_ptr' 1888/* These macros work with an argument named `preserve_ptr'
1885 and a local variable named `preserve_marker'. */ 1889 and a local variable named `preserve_marker'. */
1886 1890
diff --git a/src/keyboard.c b/src/keyboard.c
index 830f70bc1f5..8a99d5a0766 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1281,7 +1281,7 @@ static
1281#endif 1281#endif
1282bool ignore_mouse_drag_p; 1282bool ignore_mouse_drag_p;
1283 1283
1284static FRAME_PTR 1284static struct frame *
1285some_mouse_moved (void) 1285some_mouse_moved (void)
1286{ 1286{
1287 Lisp_Object tail, frame; 1287 Lisp_Object tail, frame;
@@ -2163,7 +2163,7 @@ show_help_echo (Lisp_Object help, Lisp_Object window, Lisp_Object object,
2163 This causes trouble if we are trying to read a mouse motion 2163 This causes trouble if we are trying to read a mouse motion
2164 event (i.e., if we are inside a `track-mouse' form), so we 2164 event (i.e., if we are inside a `track-mouse' form), so we
2165 restore the mouse_moved flag. */ 2165 restore the mouse_moved flag. */
2166 FRAME_PTR f = NILP (do_mouse_tracking) ? NULL : some_mouse_moved (); 2166 struct frame *f = NILP (do_mouse_tracking) ? NULL : some_mouse_moved ();
2167 help = call1 (Qmouse_fixup_help_message, help); 2167 help = call1 (Qmouse_fixup_help_message, help);
2168 if (f) 2168 if (f)
2169 f->mouse_moved = 1; 2169 f->mouse_moved = 1;
@@ -4152,7 +4152,7 @@ kbd_buffer_get_event (KBOARD **kbp,
4152 /* Try generating a mouse motion event. */ 4152 /* Try generating a mouse motion event. */
4153 else if (!NILP (do_mouse_tracking) && some_mouse_moved ()) 4153 else if (!NILP (do_mouse_tracking) && some_mouse_moved ())
4154 { 4154 {
4155 FRAME_PTR f = some_mouse_moved (); 4155 struct frame *f = some_mouse_moved ();
4156 Lisp_Object bar_window; 4156 Lisp_Object bar_window;
4157 enum scroll_bar_part part; 4157 enum scroll_bar_part part;
4158 Lisp_Object x, y; 4158 Lisp_Object x, y;
@@ -5898,7 +5898,7 @@ make_lispy_event (struct input_event *event)
5898 5898
5899 case DRAG_N_DROP_EVENT: 5899 case DRAG_N_DROP_EVENT:
5900 { 5900 {
5901 FRAME_PTR f; 5901 struct frame *f;
5902 Lisp_Object head, position; 5902 Lisp_Object head, position;
5903 Lisp_Object files; 5903 Lisp_Object files;
5904 5904
@@ -5977,7 +5977,7 @@ make_lispy_event (struct input_event *event)
5977#ifdef HAVE_GPM 5977#ifdef HAVE_GPM
5978 case GPM_CLICK_EVENT: 5978 case GPM_CLICK_EVENT:
5979 { 5979 {
5980 FRAME_PTR f = XFRAME (event->frame_or_window); 5980 struct frame *f = XFRAME (event->frame_or_window);
5981 Lisp_Object head, position; 5981 Lisp_Object head, position;
5982 Lisp_Object *start_pos_ptr; 5982 Lisp_Object *start_pos_ptr;
5983 Lisp_Object start_pos; 5983 Lisp_Object start_pos;
@@ -6031,7 +6031,7 @@ make_lispy_event (struct input_event *event)
6031} 6031}
6032 6032
6033static Lisp_Object 6033static Lisp_Object
6034make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part, 6034make_lispy_movement (struct frame *frame, Lisp_Object bar_window, enum scroll_bar_part part,
6035 Lisp_Object x, Lisp_Object y, Time t) 6035 Lisp_Object x, Lisp_Object y, Time t)
6036{ 6036{
6037 /* Is it a scroll bar movement? */ 6037 /* Is it a scroll bar movement? */
@@ -8431,7 +8431,7 @@ read_char_minibuf_menu_prompt (int commandflag,
8431 return Qnil; 8431 return Qnil;
8432 8432
8433#define PUSH_C_STR(str, listvar) \ 8433#define PUSH_C_STR(str, listvar) \
8434 listvar = Fcons (make_unibyte_string (str, strlen (str)), listvar) 8434 listvar = Fcons (build_unibyte_string (str), listvar)
8435 8435
8436 /* Prompt string always starts with map's prompt, and a space. */ 8436 /* Prompt string always starts with map's prompt, and a space. */
8437 prompt_strings = Fcons (name, prompt_strings); 8437 prompt_strings = Fcons (name, prompt_strings);
@@ -10124,8 +10124,6 @@ Also end any kbd macro being defined. */)
10124 end_kbd_macro (); 10124 end_kbd_macro ();
10125 } 10125 }
10126 10126
10127 update_mode_lines++;
10128
10129 Vunread_command_events = Qnil; 10127 Vunread_command_events = Qnil;
10130 10128
10131 discard_tty_input (); 10129 discard_tty_input ();
diff --git a/src/keymap.c b/src/keymap.c
index d13a6274347..7a18cd5d983 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -3249,8 +3249,7 @@ describe_map (Lisp_Object map, Lisp_Object prefix,
3249 for (tail = map; CONSP (tail); tail = XCDR (tail)) 3249 for (tail = map; CONSP (tail); tail = XCDR (tail))
3250 length_needed++; 3250 length_needed++;
3251 3251
3252 vect = ((struct describe_map_elt *) 3252 vect = alloca (length_needed * sizeof *vect);
3253 alloca (sizeof (struct describe_map_elt) * length_needed));
3254 3253
3255 for (tail = map; CONSP (tail); tail = XCDR (tail)) 3254 for (tail = map; CONSP (tail); tail = XCDR (tail))
3256 { 3255 {
diff --git a/src/lisp.h b/src/lisp.h
index 952991a32d9..60a553cc7d1 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -775,6 +775,7 @@ extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p;
775extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil; 775extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil;
776extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp; 776extern Lisp_Object Qnumberp, Qstringp, Qsymbolp, Qvectorp;
777extern Lisp_Object Qvector_or_char_table_p, Qwholenump; 777extern Lisp_Object Qvector_or_char_table_p, Qwholenump;
778extern Lisp_Object Qwindow;
778extern Lisp_Object Ffboundp (Lisp_Object); 779extern Lisp_Object Ffboundp (Lisp_Object);
779extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object); 780extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
780 781
@@ -3371,6 +3372,7 @@ extern struct hash_table_test hashtest_eql, hashtest_equal;
3371 3372
3372extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, 3373extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
3373 ptrdiff_t, ptrdiff_t); 3374 ptrdiff_t, ptrdiff_t);
3375extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);
3374extern Lisp_Object do_yes_or_no_p (Lisp_Object); 3376extern Lisp_Object do_yes_or_no_p (Lisp_Object);
3375extern Lisp_Object concat2 (Lisp_Object, Lisp_Object); 3377extern Lisp_Object concat2 (Lisp_Object, Lisp_Object);
3376extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object); 3378extern Lisp_Object concat3 (Lisp_Object, Lisp_Object, Lisp_Object);
@@ -3437,8 +3439,9 @@ extern void del_range_byte (ptrdiff_t, ptrdiff_t, bool);
3437extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool); 3439extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
3438extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t, 3440extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
3439 ptrdiff_t, ptrdiff_t, bool); 3441 ptrdiff_t, ptrdiff_t, bool);
3440extern void modify_region_1 (ptrdiff_t, ptrdiff_t, bool); 3442extern void modify_text (ptrdiff_t, ptrdiff_t);
3441extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *); 3443extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3444extern void prepare_to_modify_buffer_1 (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
3442extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t); 3445extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
3443extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t, 3446extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
3444 ptrdiff_t, ptrdiff_t); 3447 ptrdiff_t, ptrdiff_t);
@@ -3816,11 +3819,12 @@ extern Lisp_Object internal_condition_case_n
3816 Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *)); 3819 Lisp_Object, Lisp_Object (*) (Lisp_Object, ptrdiff_t, Lisp_Object *));
3817extern void specbind (Lisp_Object, Lisp_Object); 3820extern void specbind (Lisp_Object, Lisp_Object);
3818extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object); 3821extern void record_unwind_protect (void (*) (Lisp_Object), Lisp_Object);
3819extern void record_unwind_protect_int (void (*) (int), int);
3820extern void record_unwind_protect_ptr (void (*) (void *), void *); 3822extern void record_unwind_protect_ptr (void (*) (void *), void *);
3823extern void record_unwind_protect_int (void (*) (int), int);
3821extern void record_unwind_protect_void (void (*) (void)); 3824extern void record_unwind_protect_void (void (*) (void));
3822extern void record_unwind_protect_nothing (void); 3825extern void record_unwind_protect_nothing (void);
3823extern void clear_unwind_protect (ptrdiff_t); 3826extern void clear_unwind_protect (ptrdiff_t);
3827extern void set_unwind_protect (ptrdiff_t, void (*) (Lisp_Object), Lisp_Object);
3824extern void set_unwind_protect_ptr (ptrdiff_t, void (*) (void *), void *); 3828extern void set_unwind_protect_ptr (ptrdiff_t, void (*) (void *), void *);
3825extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object); 3829extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
3826extern void rebind_for_thread_switch (void); 3830extern void rebind_for_thread_switch (void);
@@ -3874,9 +3878,7 @@ extern void fix_start_end_in_overlays (ptrdiff_t, ptrdiff_t);
3874extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool, 3878extern void report_overlay_modification (Lisp_Object, Lisp_Object, bool,
3875 Lisp_Object, Lisp_Object, Lisp_Object); 3879 Lisp_Object, Lisp_Object, Lisp_Object);
3876extern bool overlay_touches_p (ptrdiff_t); 3880extern bool overlay_touches_p (ptrdiff_t);
3877extern Lisp_Object Vbuffer_alist;
3878extern Lisp_Object other_buffer_safely (Lisp_Object); 3881extern Lisp_Object other_buffer_safely (Lisp_Object);
3879extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
3880extern Lisp_Object get_truename_buffer (Lisp_Object); 3882extern Lisp_Object get_truename_buffer (Lisp_Object);
3881extern void init_buffer_once (void); 3883extern void init_buffer_once (void);
3882extern void init_buffer (void); 3884extern void init_buffer (void);
@@ -3907,6 +3909,9 @@ extern Lisp_Object Qfile_directory_p;
3907extern Lisp_Object Qinsert_file_contents; 3909extern Lisp_Object Qinsert_file_contents;
3908extern Lisp_Object Qfile_name_history; 3910extern Lisp_Object Qfile_name_history;
3909extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object); 3911extern Lisp_Object expand_and_dir_to_file (Lisp_Object, Lisp_Object);
3912extern Lisp_Object write_region (Lisp_Object, Lisp_Object, Lisp_Object,
3913 Lisp_Object, Lisp_Object, Lisp_Object,
3914 Lisp_Object, int);
3910EXFUN (Fread_file_name, 6); /* Not a normal DEFUN. */ 3915EXFUN (Fread_file_name, 6); /* Not a normal DEFUN. */
3911extern void close_file_unwind (int); 3916extern void close_file_unwind (int);
3912extern void fclose_unwind (void *); 3917extern void fclose_unwind (void *);
@@ -4289,6 +4294,11 @@ extern void syms_of_xml (void);
4289extern void xml_cleanup_parser (void); 4294extern void xml_cleanup_parser (void);
4290#endif 4295#endif
4291 4296
4297#ifdef HAVE_ZLIB
4298/* Defined in decompress.c. */
4299extern void syms_of_decompress (void);
4300#endif
4301
4292#ifdef HAVE_DBUS 4302#ifdef HAVE_DBUS
4293/* Defined in dbusbind.c. */ 4303/* Defined in dbusbind.c. */
4294void syms_of_dbusbind (void); 4304void syms_of_dbusbind (void);
@@ -4322,10 +4332,17 @@ extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t);
4322extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t); 4332extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
4323 4333
4324extern char *xstrdup (const char *); 4334extern char *xstrdup (const char *);
4335extern char *xlispstrdup (Lisp_Object);
4325extern void xputenv (const char *); 4336extern void xputenv (const char *);
4326 4337
4327extern char *egetenv (const char *); 4338extern char *egetenv (const char *);
4328 4339
4340/* Copy Lisp string to temporary (allocated on stack) C string. */
4341
4342#define xlispstrdupa(string) \
4343 memcpy (alloca (SBYTES (string) + 1), \
4344 SSDATA (string), SBYTES (string) + 1)
4345
4329/* Set up the name of the machine we're running on. */ 4346/* Set up the name of the machine we're running on. */
4330extern void init_system_name (void); 4347extern void init_system_name (void);
4331 4348
@@ -4402,6 +4419,12 @@ extern void *record_xmalloc (size_t);
4402 memory_full (SIZE_MAX); \ 4419 memory_full (SIZE_MAX); \
4403 } while (0) 4420 } while (0)
4404 4421
4422/* Do a `for' loop over alist values. */
4423
4424#define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var) \
4425 for (list_var = head_var; \
4426 (CONSP (list_var) && (value_var = XCDR (XCAR (list_var)), 1)); \
4427 list_var = XCDR (list_var))
4405 4428
4406/* Check whether it's time for GC, and run it if so. */ 4429/* Check whether it's time for GC, and run it if so. */
4407 4430
diff --git a/src/lisp.mk b/src/lisp.mk
index edd81bcf493..a9a661ea3a8 100644
--- a/src/lisp.mk
+++ b/src/lisp.mk
@@ -71,6 +71,7 @@ lisp = \
71 $(lispsource)/faces.elc \ 71 $(lispsource)/faces.elc \
72 $(lispsource)/button.elc \ 72 $(lispsource)/button.elc \
73 $(lispsource)/startup.elc \ 73 $(lispsource)/startup.elc \
74 $(lispsource)/emacs-lisp/nadvice.elc \
74 $(lispsource)/minibuffer.elc \ 75 $(lispsource)/minibuffer.elc \
75 $(lispsource)/abbrev.elc \ 76 $(lispsource)/abbrev.elc \
76 $(lispsource)/simple.elc \ 77 $(lispsource)/simple.elc \
diff --git a/src/marker.c b/src/marker.c
index 6c50def51a3..2f91bdf9727 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -534,9 +534,9 @@ set_marker_internal (Lisp_Object marker, Lisp_Object position,
534} 534}
535 535
536DEFUN ("set-marker", Fset_marker, Sset_marker, 2, 3, 0, 536DEFUN ("set-marker", Fset_marker, Sset_marker, 2, 3, 0,
537 doc: /* Position MARKER before character number POSITION in BUFFER, 537 doc: /* Position MARKER before character number POSITION in BUFFER.
538which defaults to the current buffer. If POSITION is nil, 538If BUFFER is omitted or nil, it defaults to the current buffer. If
539makes marker point nowhere so it no longer slows down 539POSITION is nil, makes marker point nowhere so it no longer slows down
540editing in any buffer. Returns MARKER. */) 540editing in any buffer. Returns MARKER. */)
541 (Lisp_Object marker, Lisp_Object position, Lisp_Object buffer) 541 (Lisp_Object marker, Lisp_Object position, Lisp_Object buffer)
542{ 542{
diff --git a/src/menu.c b/src/menu.c
index 6b4a22d3052..6fce5b91caf 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -867,7 +867,8 @@ update_submenu_strings (widget_value *first_wv)
867 VECTOR is an array of menu events for the whole menu. */ 867 VECTOR is an array of menu events for the whole menu. */
868 868
869void 869void
870find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object vector, void *client_data) 870find_and_call_menu_selection (struct frame *f, int menu_bar_items_used,
871 Lisp_Object vector, void *client_data)
871{ 872{
872 Lisp_Object prefix, entry; 873 Lisp_Object prefix, entry;
873 Lisp_Object *subprefix_stack; 874 Lisp_Object *subprefix_stack;
@@ -950,7 +951,7 @@ find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object
950/* As above, but return the menu selection instead of storing in kb buffer. 951/* As above, but return the menu selection instead of storing in kb buffer.
951 If KEYMAPS, return full prefixes to selection. */ 952 If KEYMAPS, return full prefixes to selection. */
952Lisp_Object 953Lisp_Object
953find_and_return_menu_selection (FRAME_PTR f, bool keymaps, void *client_data) 954find_and_return_menu_selection (struct frame *f, bool keymaps, void *client_data)
954{ 955{
955 Lisp_Object prefix, entry; 956 Lisp_Object prefix, entry;
956 int i; 957 int i;
@@ -1060,7 +1061,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1060 Lisp_Object title; 1061 Lisp_Object title;
1061 const char *error_name = NULL; 1062 const char *error_name = NULL;
1062 Lisp_Object selection = Qnil; 1063 Lisp_Object selection = Qnil;
1063 FRAME_PTR f = NULL; 1064 struct frame *f = NULL;
1064 Lisp_Object x, y, window; 1065 Lisp_Object x, y, window;
1065 bool keymaps = 0; 1066 bool keymaps = 0;
1066 bool for_click = 0; 1067 bool for_click = 0;
@@ -1116,7 +1117,7 @@ no quit occurs and `x-popup-menu' returns nil. */)
1116 if (get_current_pos_p) 1117 if (get_current_pos_p)
1117 { 1118 {
1118 /* Use the mouse's current position. */ 1119 /* Use the mouse's current position. */
1119 FRAME_PTR new_f = SELECTED_FRAME (); 1120 struct frame *new_f = SELECTED_FRAME ();
1120#ifdef HAVE_X_WINDOWS 1121#ifdef HAVE_X_WINDOWS
1121 /* Can't use mouse_position_hook for X since it returns 1122 /* Can't use mouse_position_hook for X since it returns
1122 coordinates relative to the window the mouse is in, 1123 coordinates relative to the window the mouse is in,
diff --git a/src/menu.h b/src/menu.h
index f60873eadb3..0f94ad8000b 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -35,20 +35,20 @@ extern void list_of_panes (Lisp_Object);
35 || defined (HAVE_NS) 35 || defined (HAVE_NS)
36extern void free_menubar_widget_value_tree (widget_value *); 36extern void free_menubar_widget_value_tree (widget_value *);
37extern void update_submenu_strings (widget_value *); 37extern void update_submenu_strings (widget_value *);
38extern void find_and_call_menu_selection (FRAME_PTR, int, 38extern void find_and_call_menu_selection (struct frame *, int,
39 Lisp_Object, void *); 39 Lisp_Object, void *);
40extern widget_value *xmalloc_widget_value (void); 40extern widget_value *xmalloc_widget_value (void);
41extern widget_value *digest_single_submenu (int, int, bool); 41extern widget_value *digest_single_submenu (int, int, bool);
42#endif 42#endif
43 43
44#ifdef HAVE_X_WINDOWS 44#ifdef HAVE_X_WINDOWS
45extern void mouse_position_for_popup (FRAME_PTR f, int *x, int *y); 45extern void mouse_position_for_popup (struct frame *f, int *x, int *y);
46#endif 46#endif
47 47
48extern Lisp_Object w32_menu_show (FRAME_PTR, int, int, int, int, 48extern Lisp_Object w32_menu_show (struct frame *, int, int, int, int,
49 Lisp_Object, const char **); 49 Lisp_Object, const char **);
50extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, bool, bool, 50extern Lisp_Object ns_menu_show (struct frame *, int, int, bool, bool,
51 Lisp_Object, const char **); 51 Lisp_Object, const char **);
52extern Lisp_Object xmenu_show (FRAME_PTR, int, int, bool, bool, 52extern Lisp_Object xmenu_show (struct frame *, int, int, bool, bool,
53 Lisp_Object, const char **, Time); 53 Lisp_Object, const char **, Time);
54#endif /* MENU_H */ 54#endif /* MENU_H */
diff --git a/src/minibuf.c b/src/minibuf.c
index 2c33b83c11b..7403fc6c32d 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -568,22 +568,15 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
568 bset_directory (current_buffer, ambient_dir); 568 bset_directory (current_buffer, ambient_dir);
569 else 569 else
570 { 570 {
571 Lisp_Object buf_list; 571 Lisp_Object tail, buf;
572 572
573 for (buf_list = Vbuffer_alist; 573 FOR_EACH_LIVE_BUFFER (tail, buf)
574 CONSP (buf_list); 574 if (STRINGP (BVAR (XBUFFER (buf), directory)))
575 buf_list = XCDR (buf_list)) 575 {
576 { 576 bset_directory (current_buffer,
577 Lisp_Object other_buf; 577 BVAR (XBUFFER (buf), directory));
578 578 break;
579 other_buf = XCDR (XCAR (buf_list)); 579 }
580 if (STRINGP (BVAR (XBUFFER (other_buf), directory)))
581 {
582 bset_directory (current_buffer,
583 BVAR (XBUFFER (other_buf), directory));
584 break;
585 }
586 }
587 } 580 }
588 581
589 if (!EQ (mini_frame, selected_frame)) 582 if (!EQ (mini_frame, selected_frame))
@@ -877,10 +870,8 @@ read_minibuf_unwind (void)
877 if (minibuf_level == 0) 870 if (minibuf_level == 0)
878 resize_mini_window (XWINDOW (window), 0); 871 resize_mini_window (XWINDOW (window), 0);
879 872
880 /* Make sure minibuffer window is erased, not ignored. */ 873 /* Enforce full redisplay. FIXME: make it more selective. */
881 windows_or_buffers_changed++; 874 windows_or_buffers_changed++;
882 XWINDOW (window)->last_modified = 0;
883 XWINDOW (window)->last_overlay_modified = 0;
884 875
885 /* In case the previous minibuffer displayed in this miniwindow is 876 /* In case the previous minibuffer displayed in this miniwindow is
886 dead, we may keep displaying this buffer (tho it's inactive), so reset it, 877 dead, we may keep displaying this buffer (tho it's inactive), so reset it,
diff --git a/src/msdos.c b/src/msdos.c
index a2bcc06ac17..88a2eb60726 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -298,7 +298,7 @@ mouse_button_depressed (int b, int *xp, int *yp)
298} 298}
299 299
300void 300void
301mouse_get_pos (FRAME_PTR *f, int insist, Lisp_Object *bar_window, 301mouse_get_pos (struct frame **f, int insist, Lisp_Object *bar_window,
302 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, 302 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
303 Time *time) 303 Time *time)
304{ 304{
@@ -1158,7 +1158,7 @@ IT_display_cursor (int on)
1158 to put the cursor at the end of the text displayed there. */ 1158 to put the cursor at the end of the text displayed there. */
1159 1159
1160static void 1160static void
1161IT_cmgoto (FRAME_PTR f) 1161IT_cmgoto (struct frame *f)
1162{ 1162{
1163 /* Only set the cursor to where it should be if the display is 1163 /* Only set the cursor to where it should be if the display is
1164 already in sync with the window contents. */ 1164 already in sync with the window contents. */
@@ -1760,7 +1760,7 @@ IT_set_frame_parameters (struct frame *f, Lisp_Object alist)
1760 } 1760 }
1761} 1761}
1762 1762
1763extern void init_frame_faces (FRAME_PTR); 1763extern void init_frame_faces (struct frame *);
1764 1764
1765#endif /* !HAVE_X_WINDOWS */ 1765#endif /* !HAVE_X_WINDOWS */
1766 1766
@@ -3320,18 +3320,6 @@ XMenuDestroy (Display *foo, XMenu *menu)
3320 xfree (menu); 3320 xfree (menu);
3321 menu_help_message = prev_menu_help_message = NULL; 3321 menu_help_message = prev_menu_help_message = NULL;
3322} 3322}
3323
3324int
3325x_pixel_width (struct frame *f)
3326{
3327 return FRAME_COLS (f);
3328}
3329
3330int
3331x_pixel_height (struct frame *f)
3332{
3333 return FRAME_LINES (f);
3334}
3335#endif /* !HAVE_X_WINDOWS */ 3323#endif /* !HAVE_X_WINDOWS */
3336 3324
3337/* ----------------------- DOS / UNIX conversion --------------------- */ 3325/* ----------------------- DOS / UNIX conversion --------------------- */
diff --git a/src/msdos.h b/src/msdos.h
index ee0d49464ae..6a6fe349131 100644
--- a/src/msdos.h
+++ b/src/msdos.h
@@ -74,8 +74,6 @@ struct window;
74/* Defined in xfns.c; emulated on msdos.c */ 74/* Defined in xfns.c; emulated on msdos.c */
75 75
76extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); 76extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
77extern int x_pixel_width (struct frame *);
78extern int x_pixel_height (struct frame *);
79 77
80#define XFreeGC (void) 78#define XFreeGC (void)
81#define x_destroy_bitmap(p1,p2) 79#define x_destroy_bitmap(p1,p2)
diff --git a/src/nsfns.m b/src/nsfns.m
index 121ac539646..fc276c2b12d 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -143,7 +143,7 @@ check_ns_display_info (Lisp_Object object)
143 dpyinfo = ns_display_info_for_name (object); 143 dpyinfo = ns_display_info_for_name (object);
144 else 144 else
145 { 145 {
146 FRAME_PTR f = decode_window_system_frame (object); 146 struct frame *f = decode_window_system_frame (object);
147 dpyinfo = FRAME_NS_DISPLAY_INFO (f); 147 dpyinfo = FRAME_NS_DISPLAY_INFO (f);
148 } 148 }
149 149
@@ -431,7 +431,7 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
431} 431}
432 432
433static void 433static void
434ns_set_name_internal (FRAME_PTR f, Lisp_Object name) 434ns_set_name_internal (struct frame *f, Lisp_Object name)
435{ 435{
436 struct gcpro gcpro1; 436 struct gcpro gcpro1;
437 Lisp_Object encoded_name, encoded_icon_name; 437 Lisp_Object encoded_name, encoded_icon_name;
@@ -503,7 +503,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
503 specified a name for the frame; the name will override any set by the 503 specified a name for the frame; the name will override any set by the
504 redisplay code. */ 504 redisplay code. */
505static void 505static void
506x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 506x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
507{ 507{
508 NSTRACE (x_explicitly_set_name); 508 NSTRACE (x_explicitly_set_name);
509 ns_set_name (f, arg, 1); 509 ns_set_name (f, arg, 1);
@@ -514,7 +514,7 @@ x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
514 name; names set this way will never override names set by the user's 514 name; names set this way will never override names set by the user's
515 lisp code. */ 515 lisp code. */
516void 516void
517x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 517x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
518{ 518{
519 NSTRACE (x_implicitly_set_name); 519 NSTRACE (x_implicitly_set_name);
520 520
@@ -857,14 +857,10 @@ ns_cursor_type_to_lisp (int arg)
857 857
858/* This is the same as the xfns.c definition. */ 858/* This is the same as the xfns.c definition. */
859static void 859static void
860x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 860x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
861{ 861{
862 set_frame_cursor_types (f, arg); 862 set_frame_cursor_types (f, arg);
863
864 /* Make sure the cursor gets redrawn. */
865 cursor_type_changed = 1;
866} 863}
867
868 864
869/* called to set mouse pointer color, but all other terms use it to 865/* called to set mouse pointer color, but all other terms use it to
870 initialize pointer types (and don't set the color ;) */ 866 initialize pointer types (and don't set the color ;) */
@@ -1068,7 +1064,7 @@ This function is an internal primitive--use `make-frame' instead. */)
1068 Lisp_Object frame, tem; 1064 Lisp_Object frame, tem;
1069 Lisp_Object name; 1065 Lisp_Object name;
1070 int minibuffer_only = 0; 1066 int minibuffer_only = 0;
1071 int window_prompting = 0; 1067 long window_prompting = 0;
1072 int width, height; 1068 int width, height;
1073 ptrdiff_t count = specpdl_ptr - specpdl; 1069 ptrdiff_t count = specpdl_ptr - specpdl;
1074 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 1070 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
@@ -2035,13 +2031,17 @@ DEFUN ("ns-convert-utf8-nfd-to-nfc", Fns_convert_utf8_nfd_to_nfc,
2035/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping, 2031/* TODO: If GNUstep ever implements precomposedStringWithCanonicalMapping,
2036 remove this. */ 2032 remove this. */
2037 NSString *utfStr; 2033 NSString *utfStr;
2034 Lisp_Object ret;
2038 2035
2039 CHECK_STRING (str); 2036 CHECK_STRING (str);
2040 utfStr = [NSString stringWithUTF8String: SSDATA (str)]; 2037 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2038 utfStr = [NSString stringWithUTF8String: SSDATA (str)];
2041#ifdef NS_IMPL_COCOA 2039#ifdef NS_IMPL_COCOA
2042 utfStr = [utfStr precomposedStringWithCanonicalMapping]; 2040 utfStr = [utfStr precomposedStringWithCanonicalMapping];
2043#endif 2041#endif
2044 return build_string ([utfStr UTF8String]); 2042 ret = build_string ([utfStr UTF8String]);
2043 [pool release];
2044 return ret;
2045} 2045}
2046 2046
2047 2047
@@ -2231,21 +2231,6 @@ x_get_focus_frame (struct frame *frame)
2231 return nsfocus; 2231 return nsfocus;
2232} 2232}
2233 2233
2234
2235int
2236x_pixel_width (struct frame *f)
2237{
2238 return FRAME_PIXEL_WIDTH (f);
2239}
2240
2241
2242int
2243x_pixel_height (struct frame *f)
2244{
2245 return FRAME_PIXEL_HEIGHT (f);
2246}
2247
2248
2249void 2234void
2250x_sync (struct frame *f) 2235x_sync (struct frame *f)
2251{ 2236{
@@ -2462,7 +2447,7 @@ Internal use only, use `display-monitor-attributes-list' instead. */)
2462 if (n_monitors == 0) 2447 if (n_monitors == 0)
2463 return Qnil; 2448 return Qnil;
2464 2449
2465 monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); 2450 monitors = xzalloc (n_monitors * sizeof *monitors);
2466 2451
2467 for (i = 0; i < [screens count]; ++i) 2452 for (i = 0; i < [screens count]; ++i)
2468 { 2453 {
diff --git a/src/nsfont.m b/src/nsfont.m
index df7ef0bb0bc..235150e3aef 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -619,13 +619,13 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch)
619 ========================================================================== */ 619 ========================================================================== */
620 620
621 621
622static Lisp_Object nsfont_get_cache (FRAME_PTR frame); 622static Lisp_Object nsfont_get_cache (struct frame *frame);
623static Lisp_Object nsfont_list (Lisp_Object frame, Lisp_Object font_spec); 623static Lisp_Object nsfont_list (struct frame *, Lisp_Object);
624static Lisp_Object nsfont_match (Lisp_Object frame, Lisp_Object font_spec); 624static Lisp_Object nsfont_match (struct frame *, Lisp_Object);
625static Lisp_Object nsfont_list_family (Lisp_Object frame); 625static Lisp_Object nsfont_list_family (struct frame *);
626static Lisp_Object nsfont_open (FRAME_PTR f, Lisp_Object font_entity, 626static Lisp_Object nsfont_open (struct frame *f, Lisp_Object font_entity,
627 int pixel_size); 627 int pixel_size);
628static void nsfont_close (FRAME_PTR f, struct font *font); 628static void nsfont_close (struct frame *f, struct font *font);
629static int nsfont_has_char (Lisp_Object entity, int c); 629static int nsfont_has_char (Lisp_Object entity, int c);
630static unsigned int nsfont_encode_char (struct font *font, int c); 630static unsigned int nsfont_encode_char (struct font *font, int c);
631static int nsfont_text_extents (struct font *font, unsigned int *code, 631static int nsfont_text_extents (struct font *font, unsigned int *code,
@@ -659,7 +659,7 @@ struct font_driver nsfont_driver =
659/* Return a cache of font-entities on FRAME. The cache must be a 659/* Return a cache of font-entities on FRAME. The cache must be a
660 cons whose cdr part is the actual cache area. */ 660 cons whose cdr part is the actual cache area. */
661static Lisp_Object 661static Lisp_Object
662nsfont_get_cache (FRAME_PTR frame) 662nsfont_get_cache (struct frame *frame)
663{ 663{
664 Display_Info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame); 664 Display_Info *dpyinfo = FRAME_NS_DISPLAY_INFO (frame);
665 return (dpyinfo->name_list_element); 665 return (dpyinfo->name_list_element);
@@ -679,9 +679,9 @@ nsfont_get_cache (FRAME_PTR frame)
679 weight, slant, width, size (0 if scalable), 679 weight, slant, width, size (0 if scalable),
680 dpi, spacing, avgwidth (0 if scalable) */ 680 dpi, spacing, avgwidth (0 if scalable) */
681static Lisp_Object 681static Lisp_Object
682nsfont_list (Lisp_Object frame, Lisp_Object font_spec) 682nsfont_list (struct frame *f, Lisp_Object font_spec)
683{ 683{
684 return ns_findfonts (font_spec, NO); 684 return ns_findfonts (font_spec, NO);
685} 685}
686 686
687 687
@@ -690,16 +690,16 @@ nsfont_list (Lisp_Object frame, Lisp_Object font_spec)
690 `face-font-selection-order' is ignored here. 690 `face-font-selection-order' is ignored here.
691 Properties to be considered are same as for list(). */ 691 Properties to be considered are same as for list(). */
692static Lisp_Object 692static Lisp_Object
693nsfont_match (Lisp_Object frame, Lisp_Object font_spec) 693nsfont_match (struct frame *f, Lisp_Object font_spec)
694{ 694{
695 return ns_findfonts(font_spec, YES); 695 return ns_findfonts (font_spec, YES);
696} 696}
697 697
698 698
699/* List available families. The value is a list of family names 699/* List available families. The value is a list of family names
700 (symbols). */ 700 (symbols). */
701static Lisp_Object 701static Lisp_Object
702nsfont_list_family (Lisp_Object frame) 702nsfont_list_family (struct frame *f)
703{ 703{
704 Lisp_Object list = Qnil; 704 Lisp_Object list = Qnil;
705 NSEnumerator *families; 705 NSEnumerator *families;
@@ -724,7 +724,7 @@ nsfont_list_family (Lisp_Object frame)
724/* Open a font specified by FONT_ENTITY on frame F. If the font is 724/* Open a font specified by FONT_ENTITY on frame F. If the font is
725 scalable, open it with PIXEL_SIZE. */ 725 scalable, open it with PIXEL_SIZE. */
726static Lisp_Object 726static Lisp_Object
727nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) 727nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
728{ 728{
729 BOOL synthItal; 729 BOOL synthItal;
730 unsigned int traits = 0; 730 unsigned int traits = 0;
@@ -920,8 +920,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
920 font->underline_thickness = lrint (font_info->underwidth); 920 font->underline_thickness = lrint (font_info->underwidth);
921 921
922 font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil); 922 font->props[FONT_NAME_INDEX] = Ffont_xlfd_name (font_object, Qnil);
923 font->props[FONT_FULLNAME_INDEX] = 923 font->props[FONT_FULLNAME_INDEX] = build_unibyte_string (font_info->name);
924 make_unibyte_string (font_info->name, strlen (font_info->name));
925 } 924 }
926 unblock_input (); 925 unblock_input ();
927 926
@@ -931,7 +930,7 @@ nsfont_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
931 930
932/* Close FONT on frame F. */ 931/* Close FONT on frame F. */
933static void 932static void
934nsfont_close (FRAME_PTR f, struct font *font) 933nsfont_close (struct frame *f, struct font *font)
935{ 934{
936 struct nsfont_info *font_info = (struct nsfont_info *)font; 935 struct nsfont_info *font_info = (struct nsfont_info *)font;
937 int i; 936 int i;
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 02fe0b04ca0..5af813ac758 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -366,7 +366,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
366 } 366 }
367 else 367 else
368 { 368 {
369 [menu fillWithWidgetValue: first_wv->contents]; 369 [menu fillWithWidgetValue: first_wv->contents frame: f];
370 } 370 }
371 371
372 } 372 }
@@ -504,23 +504,11 @@ void
504x_activate_menubar (struct frame *f) 504x_activate_menubar (struct frame *f)
505{ 505{
506#ifdef NS_IMPL_COCOA 506#ifdef NS_IMPL_COCOA
507 NSArray *a = [[NSApp mainMenu] itemArray]; 507#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
508 /* Update each submenu separately so ns_update_menubar doesn't reset 508 ns_update_menubar (f, true, nil);
509 the delegate. */
510 int i = 0;
511 while (i < [a count])
512 {
513 EmacsMenu *menu = (EmacsMenu *)[[a objectAtIndex:i] submenu];
514 const char *title = [[menu title] UTF8String];
515 if (strcmp (title, ns_get_pending_menu_title ()) == 0)
516 {
517 ns_update_menubar (f, true, menu);
518 break;
519 }
520 ++i;
521 }
522 ns_check_pending_open_menu (); 509 ns_check_pending_open_menu ();
523#endif 510#endif
511#endif
524} 512}
525 513
526 514
@@ -541,6 +529,7 @@ x_activate_menubar (struct frame *f)
541/* override designated initializer */ 529/* override designated initializer */
542- initWithTitle: (NSString *)title 530- initWithTitle: (NSString *)title
543{ 531{
532 frame = 0;
544 if ((self = [super initWithTitle: title])) 533 if ((self = [super initWithTitle: title]))
545 [self setAutoenablesItems: NO]; 534 [self setAutoenablesItems: NO];
546 return self; 535 return self;
@@ -576,17 +565,36 @@ extern NSString *NSMenuDidBeginTrackingNotification;
576 /* Update menu in menuNeedsUpdate only while tracking menus. */ 565 /* Update menu in menuNeedsUpdate only while tracking menus. */
577 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification 566 trackingMenu = ([notification name] == NSMenuDidBeginTrackingNotification
578 ? 1 : 0); 567 ? 1 : 0);
568#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
569 if (! trackingMenu) ns_check_menu_open (nil);
570#endif
579} 571}
580 572
581#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 573#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
582- (void)menuWillOpen:(NSMenu *)menu 574- (void)menuWillOpen:(NSMenu *)menu
583{ 575{
584 ns_check_menu_open (menu); 576 ++trackingMenu;
585}
586#endif
587 577
578#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
579 // On 10.6 we get repeated calls, only the one for NSSystemDefined is "real".
580 if ([[NSApp currentEvent] type] != NSSystemDefined) return;
588#endif 581#endif
589 582
583 /* When dragging from one menu to another, we get willOpen followed by didClose,
584 i.e. trackingMenu == 3 in willOpen and then 2 after didClose.
585 We have updated all menus, so avoid doing it when trackingMenu == 3. */
586 if (trackingMenu == 2)
587 ns_check_menu_open (menu);
588}
589
590- (void)menuDidClose:(NSMenu *)menu
591{
592 --trackingMenu;
593}
594#endif /* OSX >= 10.5 */
595
596#endif /* NS_IMPL_COCOA */
597
590/* delegate method called when a submenu is being opened: run a 'deep' call 598/* delegate method called when a submenu is being opened: run a 'deep' call
591 to set_frame_menubar */ 599 to set_frame_menubar */
592- (void)menuNeedsUpdate: (NSMenu *)menu 600- (void)menuNeedsUpdate: (NSMenu *)menu
@@ -722,6 +730,11 @@ extern NSString *NSMenuDidBeginTrackingNotification;
722 730
723- (void)fillWithWidgetValue: (void *)wvptr 731- (void)fillWithWidgetValue: (void *)wvptr
724{ 732{
733 [self fillWithWidgetValue: wvptr frame:nil];
734}
735
736- (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f
737{
725 widget_value *wv = (widget_value *)wvptr; 738 widget_value *wv = (widget_value *)wvptr;
726 739
727 /* clear existing contents */ 740 /* clear existing contents */
@@ -735,7 +748,12 @@ extern NSString *NSMenuDidBeginTrackingNotification;
735 748
736 if (wv->contents) 749 if (wv->contents)
737 { 750 {
738 EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: [item title]]; 751 EmacsMenu *submenu;
752
753 if (f)
754 submenu = [[EmacsMenu alloc] initWithTitle: [item title] frame:f];
755 else
756 submenu = [[EmacsMenu alloc] initWithTitle: [item title]];
739 757
740 [self setSubmenu: submenu forItem: item]; 758 [self setSubmenu: submenu forItem: item];
741 [submenu fillWithWidgetValue: wv->contents]; 759 [submenu fillWithWidgetValue: wv->contents];
@@ -806,7 +824,7 @@ extern NSString *NSMenuDidBeginTrackingNotification;
806 ========================================================================== */ 824 ========================================================================== */
807 825
808Lisp_Object 826Lisp_Object
809ns_menu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, 827ns_menu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
810 Lisp_Object title, const char **error) 828 Lisp_Object title, const char **error)
811{ 829{
812 EmacsMenu *pmenu; 830 EmacsMenu *pmenu;
@@ -1028,7 +1046,7 @@ ns_menu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
1028 ========================================================================== */ 1046 ========================================================================== */
1029 1047
1030void 1048void
1031free_frame_tool_bar (FRAME_PTR f) 1049free_frame_tool_bar (struct frame *f)
1032/* -------------------------------------------------------------------------- 1050/* --------------------------------------------------------------------------
1033 Under NS we just hide the toolbar until it might be needed again. 1051 Under NS we just hide the toolbar until it might be needed again.
1034 -------------------------------------------------------------------------- */ 1052 -------------------------------------------------------------------------- */
@@ -1040,7 +1058,7 @@ free_frame_tool_bar (FRAME_PTR f)
1040} 1058}
1041 1059
1042void 1060void
1043update_frame_tool_bar (FRAME_PTR f) 1061update_frame_tool_bar (struct frame *f)
1044/* -------------------------------------------------------------------------- 1062/* --------------------------------------------------------------------------
1045 Update toolbar contents 1063 Update toolbar contents
1046 -------------------------------------------------------------------------- */ 1064 -------------------------------------------------------------------------- */
@@ -1665,7 +1683,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1665 } 1683 }
1666 1684
1667 if (buttons > 0) 1685 if (buttons > 0)
1668 button_values = (Lisp_Object *) xmalloc (buttons * sizeof (*button_values)); 1686 button_values = xmalloc (buttons * sizeof *button_values);
1669 1687
1670 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list)) 1688 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list))
1671 { 1689 {
diff --git a/src/nsterm.h b/src/nsterm.h
index 745b8a4145b..c34067991f6 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -53,9 +53,24 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
53 53
54/* CGFloat on GNUStep may be 4 or 8 byte, but functions expect float* for some 54/* CGFloat on GNUStep may be 4 or 8 byte, but functions expect float* for some
55 versions. 55 versions.
56 On Cocoa, functions expect CGFloat*. Make compatible type. */ 56 On Cocoa >= 10.5, functions expect CGFloat*. Make compatible type. */
57#if defined (NS_IMPL_COCOA) || GNUSTEP_GUI_MAJOR_VERSION > 0 || \ 57#ifdef NS_IMPL_COCOA
58 GNUSTEP_GUI_MINOR_VERSION >= 22 58
59#ifndef NS_HAVE_NSINTEGER
60#if defined (__LP64__) && __LP64__
61typedef double CGFloat;
62typedef long NSInteger;
63typedef unsigned long NSUInteger;
64#else
65typedef float CGFloat;
66typedef int NSInteger;
67typedef unsigned int NSUInteger;
68#endif /* not LP64 */
69#endif /* not NS_HAVE_NSINTEGER */
70
71typedef CGFloat EmacsCGFloat;
72
73#elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
59typedef CGFloat EmacsCGFloat; 74typedef CGFloat EmacsCGFloat;
60#else 75#else
61typedef float EmacsCGFloat; 76typedef float EmacsCGFloat;
@@ -109,7 +124,10 @@ typedef float EmacsCGFloat;
109@interface EmacsView : NSView <NSTextInput> 124@interface EmacsView : NSView <NSTextInput>
110#endif 125#endif
111 { 126 {
127#ifdef NS_IMPL_COCOA
112 char *old_title; 128 char *old_title;
129 BOOL maximizing_resize;
130#endif
113 BOOL windowClosing; 131 BOOL windowClosing;
114 NSString *workingText; 132 NSString *workingText;
115 BOOL processingCompose; 133 BOOL processingCompose;
@@ -193,6 +211,7 @@ typedef float EmacsCGFloat;
193- (NSString *)parseKeyEquiv: (const char *)key; 211- (NSString *)parseKeyEquiv: (const char *)key;
194- (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr; 212- (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
195- (void)fillWithWidgetValue: (void *)wvptr; 213- (void)fillWithWidgetValue: (void *)wvptr;
214- (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
196- (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f; 215- (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
197- (void) clear; 216- (void) clear;
198- (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f 217- (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
@@ -420,18 +439,6 @@ extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
420@end 439@end
421#endif 440#endif
422 441
423#ifndef NS_HAVE_NSINTEGER
424#if defined (__LP64__) && __LP64__
425typedef double CGFloat;
426typedef long NSInteger;
427typedef unsigned long NSUInteger;
428#else
429typedef float CGFloat;
430typedef int NSInteger;
431typedef unsigned int NSUInteger;
432#endif /* not LP64 */
433#endif /* not NS_HAVE_NSINTEGER */
434
435#endif /* __OBJC__ */ 442#endif /* __OBJC__ */
436 443
437 444
@@ -778,7 +785,7 @@ void ns_dump_glyphstring (struct glyph_string *s);
778 785
779/* Implemented in nsterm, published in or needed from nsfns. */ 786/* Implemented in nsterm, published in or needed from nsfns. */
780extern Lisp_Object Qfontsize; 787extern Lisp_Object Qfontsize;
781extern Lisp_Object ns_list_fonts (FRAME_PTR f, Lisp_Object pattern, 788extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
782 int size, int maxnames); 789 int size, int maxnames);
783extern void ns_clear_frame (struct frame *f); 790extern void ns_clear_frame (struct frame *f);
784 791
@@ -824,11 +831,11 @@ extern void ns_release_autorelease_pool (void *);
824extern const char *ns_get_defaults_value (const char *key); 831extern const char *ns_get_defaults_value (const char *key);
825 832
826/* in nsmenu */ 833/* in nsmenu */
827extern void update_frame_tool_bar (FRAME_PTR f); 834extern void update_frame_tool_bar (struct frame *f);
828extern void free_frame_tool_bar (FRAME_PTR f); 835extern void free_frame_tool_bar (struct frame *f);
829extern void find_and_call_menu_selection (FRAME_PTR f, 836extern void find_and_call_menu_selection (struct frame *f,
830 int menu_bar_items_used, Lisp_Object vector, void *client_data); 837 int menu_bar_items_used, Lisp_Object vector, void *client_data);
831extern Lisp_Object find_and_return_menu_selection (FRAME_PTR f, 838extern Lisp_Object find_and_return_menu_selection (struct frame *f,
832 bool keymaps, 839 bool keymaps,
833 void *client_data); 840 void *client_data);
834extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object contents, 841extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object contents,
diff --git a/src/nsterm.m b/src/nsterm.m
index 61538798337..f374bfd90c6 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -250,9 +250,6 @@ static int menu_will_open_state = MENU_NONE;
250 250
251/* Saved position for menu click. */ 251/* Saved position for menu click. */
252static CGPoint menu_mouse_point; 252static CGPoint menu_mouse_point;
253
254/* Title for the menu to open. */
255static char *menu_pending_title = 0;
256#endif 253#endif
257 254
258/* Convert modifiers in a NeXTstep event to emacs style modifiers. */ 255/* Convert modifiers in a NeXTstep event to emacs style modifiers. */
@@ -344,8 +341,8 @@ hold_event (struct input_event *event)
344 { 341 {
345 if (hold_event_q.cap == 0) hold_event_q.cap = 10; 342 if (hold_event_q.cap == 0) hold_event_q.cap = 10;
346 else hold_event_q.cap *= 2; 343 else hold_event_q.cap *= 2;
347 hold_event_q.q = (struct input_event *) 344 hold_event_q.q =
348 xrealloc (hold_event_q.q, hold_event_q.cap * sizeof (*hold_event_q.q)); 345 xrealloc (hold_event_q.q, hold_event_q.cap * sizeof *hold_event_q.q);
349 } 346 }
350 347
351 hold_event_q.q[hold_event_q.nr++] = *event; 348 hold_event_q.q[hold_event_q.nr++] = *event;
@@ -691,9 +688,18 @@ ns_update_begin (struct frame *f)
691 { 688 {
692 NSBezierPath *bp; 689 NSBezierPath *bp;
693 NSRect r = [view frame]; 690 NSRect r = [view frame];
694 bp = [[NSBezierPath bezierPathWithRect: r] retain]; 691 NSRect cr = [[view window] frame];
695 [bp setClip]; 692 /* If a large frame size is set, r may be larger than the window frame
696 [bp release]; 693 before constrained. In that case don't change the clip path, as we
694 will clear in to the tool bar and title bar. */
695 if (r.size.height
696 + FRAME_NS_TITLEBAR_HEIGHT (f)
697 + FRAME_TOOLBAR_HEIGHT (f) <= cr.size.height)
698 {
699 bp = [[NSBezierPath bezierPathWithRect: r] retain];
700 [bp setClip];
701 [bp release];
702 }
697 } 703 }
698#endif 704#endif
699 705
@@ -711,9 +717,9 @@ ns_update_window_begin (struct window *w)
711 -------------------------------------------------------------------------- */ 717 -------------------------------------------------------------------------- */
712{ 718{
713 struct frame *f = XFRAME (WINDOW_FRAME (w)); 719 struct frame *f = XFRAME (WINDOW_FRAME (w));
714 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 720 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
721
715 NSTRACE (ns_update_window_begin); 722 NSTRACE (ns_update_window_begin);
716 updated_window = w;
717 set_output_cursor (&w->cursor); 723 set_output_cursor (&w->cursor);
718 724
719 block_input (); 725 block_input ();
@@ -770,7 +776,6 @@ ns_update_window_end (struct window *w, int cursor_on_p,
770 hlinfo->mouse_face_window = Qnil; 776 hlinfo->mouse_face_window = Qnil;
771 } 777 }
772 778
773 updated_window = NULL;
774 NSTRACE (update_window_end); 779 NSTRACE (update_window_end);
775} 780}
776 781
@@ -785,9 +790,9 @@ ns_update_end (struct frame *f)
785 EmacsView *view = FRAME_NS_VIEW (f); 790 EmacsView *view = FRAME_NS_VIEW (f);
786 791
787/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */ 792/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
788 MOUSE_HL_INFO (f)->mouse_face_defer = 0; 793 MOUSE_HL_INFO (f)->mouse_face_defer = 0;
789 794
790 block_input (); 795 block_input ();
791 796
792 [view unlockFocus]; 797 [view unlockFocus];
793 [[view window] flushWindow]; 798 [[view window] flushWindow];
@@ -1353,7 +1358,7 @@ x_set_window_size (struct frame *f, int change_grav, int cols, int rows)
1353 1358
1354 1359
1355static void 1360static void
1356ns_fullscreen_hook (FRAME_PTR f) 1361ns_fullscreen_hook (struct frame *f)
1357{ 1362{
1358 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); 1363 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1359 1364
@@ -1883,10 +1888,9 @@ ns_frame_up_to_date (struct frame *f)
1883 { 1888 {
1884 block_input (); 1889 block_input ();
1885 ns_update_begin(f); 1890 ns_update_begin(f);
1886 if (hlinfo->mouse_face_mouse_frame) 1891 note_mouse_highlight (hlinfo->mouse_face_mouse_frame,
1887 note_mouse_highlight (hlinfo->mouse_face_mouse_frame, 1892 hlinfo->mouse_face_mouse_x,
1888 hlinfo->mouse_face_mouse_x, 1893 hlinfo->mouse_face_mouse_y);
1889 hlinfo->mouse_face_mouse_y);
1890 ns_update_end(f); 1894 ns_update_end(f);
1891 unblock_input (); 1895 unblock_input ();
1892 } 1896 }
@@ -2085,7 +2089,6 @@ ns_scroll_run (struct window *w, struct run *run)
2085 2089
2086 block_input (); 2090 block_input ();
2087 2091
2088 updated_window = w;
2089 x_clear_cursor (w); 2092 x_clear_cursor (w);
2090 2093
2091 { 2094 {
@@ -2103,12 +2106,11 @@ ns_scroll_run (struct window *w, struct run *run)
2103 2106
2104 2107
2105static void 2108static void
2106ns_after_update_window_line (struct glyph_row *desired_row) 2109ns_after_update_window_line (struct window *w, struct glyph_row *desired_row)
2107/* -------------------------------------------------------------------------- 2110/* --------------------------------------------------------------------------
2108 External (RIF): preparatory to fringe update after text was updated 2111 External (RIF): preparatory to fringe update after text was updated
2109 -------------------------------------------------------------------------- */ 2112 -------------------------------------------------------------------------- */
2110{ 2113{
2111 struct window *w = updated_window;
2112 struct frame *f; 2114 struct frame *f;
2113 int width, height; 2115 int width, height;
2114 2116
@@ -3392,12 +3394,6 @@ check_native_fs ()
3392/* GNUStep and OSX <= 10.4 does not have cancelTracking. */ 3394/* GNUStep and OSX <= 10.4 does not have cancelTracking. */
3393#if defined (NS_IMPL_COCOA) && \ 3395#if defined (NS_IMPL_COCOA) && \
3394 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 3396 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
3395const char *
3396ns_get_pending_menu_title ()
3397{
3398 return menu_pending_title;
3399}
3400
3401/* Check if menu open should be cancelled or continued as normal. */ 3397/* Check if menu open should be cancelled or continued as normal. */
3402void 3398void
3403ns_check_menu_open (NSMenu *menu) 3399ns_check_menu_open (NSMenu *menu)
@@ -3406,6 +3402,14 @@ ns_check_menu_open (NSMenu *menu)
3406 NSArray *a = [[NSApp mainMenu] itemArray]; 3402 NSArray *a = [[NSApp mainMenu] itemArray];
3407 int i; 3403 int i;
3408 BOOL found = NO; 3404 BOOL found = NO;
3405
3406 if (menu == nil) // Menu tracking ended.
3407 {
3408 if (menu_will_open_state == MENU_OPENING)
3409 menu_will_open_state = MENU_NONE;
3410 return;
3411 }
3412
3409 for (i = 0; ! found && i < [a count]; i++) 3413 for (i = 0; ! found && i < [a count]; i++)
3410 found = menu == [[a objectAtIndex:i] submenu]; 3414 found = menu == [[a objectAtIndex:i] submenu];
3411 if (found) 3415 if (found)
@@ -3423,8 +3427,6 @@ ns_check_menu_open (NSMenu *menu)
3423 CGEventRef ourEvent = CGEventCreate (NULL); 3427 CGEventRef ourEvent = CGEventCreate (NULL);
3424 menu_mouse_point = CGEventGetLocation (ourEvent); 3428 menu_mouse_point = CGEventGetLocation (ourEvent);
3425 CFRelease (ourEvent); 3429 CFRelease (ourEvent);
3426 xfree (menu_pending_title);
3427 menu_pending_title = xstrdup ([[menu title] UTF8String]);
3428 } 3430 }
3429 else if (menu_will_open_state == MENU_OPENING) 3431 else if (menu_will_open_state == MENU_OPENING)
3430 { 3432 {
@@ -3738,16 +3740,7 @@ ns_set_vertical_scroll_bar (struct window *window,
3738 v = [view frame]; 3740 v = [view frame];
3739 r.origin.y = (v.size.height - r.size.height - r.origin.y); 3741 r.origin.y = (v.size.height - r.size.height - r.origin.y);
3740 3742
3741 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (window)) 3743 fringe_extended_p = WINDOW_FRINGE_EXTENDED_P (window);
3742 fringe_extended_p = (WINDOW_LEFTMOST_P (window)
3743 && WINDOW_LEFT_FRINGE_WIDTH (window)
3744 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (window)
3745 || WINDOW_LEFT_MARGIN_COLS (window) == 0));
3746 else
3747 fringe_extended_p = (WINDOW_RIGHTMOST_P (window)
3748 && WINDOW_RIGHT_FRINGE_WIDTH (window)
3749 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (window)
3750 || WINDOW_RIGHT_MARGIN_COLS (window) == 0));
3751 3744
3752 XSETWINDOW (win, window); 3745 XSETWINDOW (win, window);
3753 block_input (); 3746 block_input ();
@@ -3863,15 +3856,6 @@ ns_judge_scroll_bars (struct frame *f)
3863 [eview updateFrameSize: NO]; 3856 [eview updateFrameSize: NO];
3864} 3857}
3865 3858
3866
3867void
3868x_wm_set_icon_position (struct frame *f, int icon_x, int icon_y)
3869{
3870 /* XXX irrelevant under NS */
3871}
3872
3873
3874
3875/* ========================================================================== 3859/* ==========================================================================
3876 3860
3877 Initialization 3861 Initialization
@@ -4473,9 +4457,9 @@ ns_term_shutdown (int sig)
4473 4457
4474#ifdef NS_IMPL_COCOA 4458#ifdef NS_IMPL_COCOA
4475 /* If no dialog and none of our frames have focus and it is a move, skip it. 4459 /* If no dialog and none of our frames have focus and it is a move, skip it.
4476 It is a mouse move in an auxillary menu, i.e. on the top right on OSX, 4460 It is a mouse move in an auxiliary menu, i.e. on the top right on OSX,
4477 such as Wifi, sound, date or similar. 4461 such as Wifi, sound, date or similar.
4478 This prevents "spooky" highlightning in the frame under the menu. */ 4462 This prevents "spooky" highlighting in the frame under the menu. */
4479 if (type == NSMouseMoved && [NSApp modalWindow] == nil) 4463 if (type == NSMouseMoved && [NSApp modalWindow] == nil)
4480 { 4464 {
4481 struct ns_display_info *di; 4465 struct ns_display_info *di;
@@ -5673,17 +5657,17 @@ not_in_argv (NSString *arg)
5673 old_title = 0; 5657 old_title = 0;
5674 } 5658 }
5675 } 5659 }
5676 else 5660 else if (fs_state == FULLSCREEN_NONE && ! maximizing_resize)
5677 { 5661 {
5678 char *size_title; 5662 char *size_title;
5679 NSWindow *window = [self window]; 5663 NSWindow *window = [self window];
5680 if (old_title == 0) 5664 if (old_title == 0)
5681 { 5665 {
5682 const char *t = [[[self window] title] UTF8String]; 5666 char *t = strdup ([[[self window] title] UTF8String]);
5683 char *pos = strstr (t, " — "); 5667 char *pos = strstr (t, " — ");
5684 if (pos) 5668 if (pos)
5685 *pos = '\0'; 5669 *pos = '\0';
5686 old_title = xstrdup (t); 5670 old_title = t;
5687 } 5671 }
5688 size_title = xmalloc (strlen (old_title) + 40); 5672 size_title = xmalloc (strlen (old_title) + 40);
5689 esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows); 5673 esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows);
@@ -5722,21 +5706,27 @@ not_in_argv (NSString *arg)
5722 NSTRACE (windowDidResize); 5706 NSTRACE (windowDidResize);
5723/*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */ 5707/*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5724 5708
5709if (cols > 0 && rows > 0)
5710 {
5711 [self updateFrameSize: YES];
5712 }
5713
5714 ns_send_appdefined (-1);
5715}
5716
5725#ifdef NS_IMPL_COCOA 5717#ifdef NS_IMPL_COCOA
5718- (void)viewDidEndLiveResize
5719{
5720 [super viewDidEndLiveResize];
5726 if (old_title != 0) 5721 if (old_title != 0)
5727 { 5722 {
5723 [[self window] setTitle: [NSString stringWithUTF8String: old_title]];
5728 xfree (old_title); 5724 xfree (old_title);
5729 old_title = 0; 5725 old_title = 0;
5730 } 5726 }
5731#endif /* NS_IMPL_COCOA */ 5727 maximizing_resize = NO;
5732
5733 if (cols > 0 && rows > 0)
5734 {
5735 [self updateFrameSize: YES];
5736 }
5737
5738 ns_send_appdefined (-1);
5739} 5728}
5729#endif /* NS_IMPL_COCOA */
5740 5730
5741 5731
5742- (void)windowDidBecomeKey: (NSNotification *)notification 5732- (void)windowDidBecomeKey: (NSNotification *)notification
@@ -5841,7 +5831,10 @@ not_in_argv (NSString *arg)
5841 5831
5842 FRAME_NS_VIEW (f) = self; 5832 FRAME_NS_VIEW (f) = self;
5843 emacsframe = f; 5833 emacsframe = f;
5834#ifdef NS_IMPL_COCOA
5844 old_title = 0; 5835 old_title = 0;
5836 maximizing_resize = NO;
5837#endif
5845 5838
5846 win = [[EmacsWindow alloc] 5839 win = [[EmacsWindow alloc]
5847 initWithContentRect: r 5840 initWithContentRect: r
@@ -5984,6 +5977,9 @@ not_in_argv (NSString *arg)
5984 maximized_width = -1; 5977 maximized_width = -1;
5985 result.origin.y = defaultFrame.origin.y; 5978 result.origin.y = defaultFrame.origin.y;
5986 [self setFSValue: FULLSCREEN_HEIGHT]; 5979 [self setFSValue: FULLSCREEN_HEIGHT];
5980#ifdef NS_IMPL_COCOA
5981 maximizing_resize = YES;
5982#endif
5987 } 5983 }
5988 else if (next_maximized == FULLSCREEN_WIDTH) 5984 else if (next_maximized == FULLSCREEN_WIDTH)
5989 { 5985 {
@@ -6002,12 +5998,18 @@ not_in_argv (NSString *arg)
6002 maximized_width = result.size.width; 5998 maximized_width = result.size.width;
6003 maximized_height = result.size.height; 5999 maximized_height = result.size.height;
6004 [self setFSValue: FULLSCREEN_MAXIMIZED]; 6000 [self setFSValue: FULLSCREEN_MAXIMIZED];
6001#ifdef NS_IMPL_COCOA
6002 maximizing_resize = YES;
6003#endif
6005 } 6004 }
6006 else 6005 else
6007 { 6006 {
6008 /* restore */ 6007 /* restore */
6009 result = ns_userRect.size.height ? ns_userRect : result; 6008 result = ns_userRect.size.height ? ns_userRect : result;
6010 ns_userRect = NSMakeRect (0, 0, 0, 0); 6009 ns_userRect = NSMakeRect (0, 0, 0, 0);
6010#ifdef NS_IMPL_COCOA
6011 maximizing_resize = fs_state != FULLSCREEN_NONE;
6012#endif
6011 [self setFSValue: FULLSCREEN_NONE]; 6013 [self setFSValue: FULLSCREEN_NONE];
6012 maximized_width = maximized_height = -1; 6014 maximized_width = maximized_height = -1;
6013 } 6015 }
diff --git a/src/process.c b/src/process.c
index 33d8ccbbc35..91483e5839f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -92,6 +92,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
92 92
93#include <c-ctype.h> 93#include <c-ctype.h>
94#include <sig2str.h> 94#include <sig2str.h>
95#include <verify.h>
95 96
96#endif /* subprocesses */ 97#endif /* subprocesses */
97 98
@@ -301,7 +302,7 @@ static void exec_sentinel (Lisp_Object proc, Lisp_Object reason);
301static int num_pending_connects; 302static int num_pending_connects;
302#endif /* NON_BLOCKING_CONNECT */ 303#endif /* NON_BLOCKING_CONNECT */
303 304
304/* The largest descriptor currently in use for input. */ 305/* The largest descriptor currently in use; -1 if none. */
305static int max_desc; 306static int max_desc;
306 307
307/* Indexed by descriptor, gives the process (if any) for that descriptor */ 308/* Indexed by descriptor, gives the process (if any) for that descriptor */
@@ -335,6 +336,12 @@ static struct sockaddr_and_len {
335#define DATAGRAM_CONN_P(proc) (0) 336#define DATAGRAM_CONN_P(proc) (0)
336#endif 337#endif
337 338
339/* FOR_EACH_PROCESS (LIST_VAR, PROC_VAR) followed by a statement is
340 a `for' loop which iterates over processes from Vprocess_alist. */
341
342#define FOR_EACH_PROCESS(list_var, proc_var) \
343 FOR_EACH_ALIST_VALUE (Vprocess_alist, list_var, proc_var)
344
338/* These setters are used only in this file, so they can be private. */ 345/* These setters are used only in this file, so they can be private. */
339static void 346static void
340pset_buffer (struct Lisp_Process *p, Lisp_Object val) 347pset_buffer (struct Lisp_Process *p, Lisp_Object val)
@@ -543,6 +550,22 @@ recompute_max_desc (void)
543 } 550 }
544} 551}
545 552
553/* FD is no longer an input descriptor; update max_input_desc accordingly. */
554
555static void
556delete_input_desc (int fd)
557{
558 if (fd == max_input_desc)
559 {
560 do
561 fd--;
562 while (0 <= fd && ! (FD_ISSET (fd, &input_wait_mask)
563 || FD_ISSET (fd, &write_mask)));
564
565 max_input_desc = fd;
566 }
567}
568
546/* Stop monitoring file descriptor FD for when write is possible. */ 569/* Stop monitoring file descriptor FD for when write is possible. */
547 570
548void 571void
@@ -862,6 +885,8 @@ make_process (Lisp_Object name)
862 non-Lisp data, so do it only for slots which should not be zero. */ 885 non-Lisp data, so do it only for slots which should not be zero. */
863 p->infd = -1; 886 p->infd = -1;
864 p->outfd = -1; 887 p->outfd = -1;
888 for (i = 0; i < PROCESS_OPEN_FDS; i++)
889 p->open_fd[i] = -1;
865 890
866#ifdef HAVE_GNUTLS 891#ifdef HAVE_GNUTLS
867 p->gnutls_initstage = GNUTLS_STAGE_EMPTY; 892 p->gnutls_initstage = GNUTLS_STAGE_EMPTY;
@@ -979,13 +1004,17 @@ get_process (register Lisp_Object name)
979 treated by the SIGCHLD handler and waitpid has been invoked on them; 1004 treated by the SIGCHLD handler and waitpid has been invoked on them;
980 otherwise they might fill up the kernel's process table. 1005 otherwise they might fill up the kernel's process table.
981 1006
982 Some processes created by call-process are also put onto this list. */ 1007 Some processes created by call-process are also put onto this list.
1008
1009 Members of this list are (process-ID . filename) pairs. The
1010 process-ID is a number; the filename, if a string, is a file that
1011 needs to be removed after the process exits. */
983static Lisp_Object deleted_pid_list; 1012static Lisp_Object deleted_pid_list;
984 1013
985void 1014void
986record_deleted_pid (pid_t pid) 1015record_deleted_pid (pid_t pid, Lisp_Object filename)
987{ 1016{
988 deleted_pid_list = Fcons (make_fixnum_or_float (pid), 1017 deleted_pid_list = Fcons (Fcons (make_fixnum_or_float (pid), filename),
989 /* GC treated elements set to nil. */ 1018 /* GC treated elements set to nil. */
990 Fdelq (Qnil, deleted_pid_list)); 1019 Fdelq (Qnil, deleted_pid_list));
991 1020
@@ -1013,7 +1042,7 @@ nil, indicating the current buffer's process. */)
1013 else 1042 else
1014 { 1043 {
1015 if (p->alive) 1044 if (p->alive)
1016 record_kill_process (p); 1045 record_kill_process (p, Qnil);
1017 1046
1018 if (p->infd >= 0) 1047 if (p->infd >= 0)
1019 { 1048 {
@@ -1796,17 +1825,45 @@ start_process_unwind (Lisp_Object proc)
1796 remove_process (proc); 1825 remove_process (proc);
1797} 1826}
1798 1827
1828/* If *FD_ADDR is nonnegative, close it, and mark it as closed. */
1829
1830static void
1831close_process_fd (int *fd_addr)
1832{
1833 int fd = *fd_addr;
1834 if (0 <= fd)
1835 {
1836 *fd_addr = -1;
1837 emacs_close (fd);
1838 }
1839}
1840
1841/* Indexes of file descriptors in open_fds. */
1842enum
1843 {
1844 /* The pipe from Emacs to its subprocess. */
1845 SUBPROCESS_STDIN,
1846 WRITE_TO_SUBPROCESS,
1847
1848 /* The main pipe from the subprocess to Emacs. */
1849 READ_FROM_SUBPROCESS,
1850 SUBPROCESS_STDOUT,
1851
1852 /* The pipe from the subprocess to Emacs that is closed when the
1853 subprocess execs. */
1854 READ_FROM_EXEC_MONITOR,
1855 EXEC_MONITOR_OUTPUT
1856 };
1857
1858verify (PROCESS_OPEN_FDS == EXEC_MONITOR_OUTPUT + 1);
1799 1859
1800static void 1860static void
1801create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) 1861create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1802{ 1862{
1863 struct Lisp_Process *p = XPROCESS (process);
1803 int inchannel, outchannel; 1864 int inchannel, outchannel;
1804 pid_t pid; 1865 pid_t pid;
1805 int vfork_errno; 1866 int vfork_errno;
1806 int sv[2];
1807#ifndef WINDOWSNT
1808 int wait_child_setup[2];
1809#endif
1810 int forkin, forkout; 1867 int forkin, forkout;
1811 bool pty_flag = 0; 1868 bool pty_flag = 0;
1812 char pty_name[PTY_NAME_SIZE]; 1869 char pty_name[PTY_NAME_SIZE];
@@ -1820,6 +1877,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1820 1877
1821 if (inchannel >= 0) 1878 if (inchannel >= 0)
1822 { 1879 {
1880 p->open_fd[READ_FROM_SUBPROCESS] = inchannel;
1823#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 1881#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1824 /* On most USG systems it does not work to open the pty's tty here, 1882 /* On most USG systems it does not work to open the pty's tty here,
1825 then close it and reopen it in the child. */ 1883 then close it and reopen it in the child. */
@@ -1828,6 +1886,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1828 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1886 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
1829 if (forkin < 0) 1887 if (forkin < 0)
1830 report_file_error ("Opening pty", Qnil); 1888 report_file_error ("Opening pty", Qnil);
1889 p->open_fd[SUBPROCESS_STDIN] = forkin;
1831#else 1890#else
1832 forkin = forkout = -1; 1891 forkin = forkout = -1;
1833#endif /* not USG, or USG_SUBTTY_WORKS */ 1892#endif /* not USG, or USG_SUBTTY_WORKS */
@@ -1836,23 +1895,17 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1836 } 1895 }
1837 else 1896 else
1838 { 1897 {
1839 if (emacs_pipe (sv) != 0) 1898 if (emacs_pipe (p->open_fd + SUBPROCESS_STDIN) != 0
1899 || emacs_pipe (p->open_fd + READ_FROM_SUBPROCESS) != 0)
1840 report_file_error ("Creating pipe", Qnil); 1900 report_file_error ("Creating pipe", Qnil);
1841 inchannel = sv[0]; 1901 forkin = p->open_fd[SUBPROCESS_STDIN];
1842 forkout = sv[1]; 1902 outchannel = p->open_fd[WRITE_TO_SUBPROCESS];
1843 if (emacs_pipe (sv) != 0) 1903 inchannel = p->open_fd[READ_FROM_SUBPROCESS];
1844 { 1904 forkout = p->open_fd[SUBPROCESS_STDOUT];
1845 int pipe_errno = errno;
1846 emacs_close (inchannel);
1847 emacs_close (forkout);
1848 report_file_errno ("Creating pipe", Qnil, pipe_errno);
1849 }
1850 outchannel = sv[1];
1851 forkin = sv[0];
1852 } 1905 }
1853 1906
1854#ifndef WINDOWSNT 1907#ifndef WINDOWSNT
1855 if (emacs_pipe (wait_child_setup) != 0) 1908 if (emacs_pipe (p->open_fd + READ_FROM_EXEC_MONITOR) != 0)
1856 report_file_error ("Creating pipe", Qnil); 1909 report_file_error ("Creating pipe", Qnil);
1857#endif 1910#endif
1858 1911
@@ -1861,16 +1914,16 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1861 1914
1862 /* Record this as an active process, with its channels. */ 1915 /* Record this as an active process, with its channels. */
1863 chan_process[inchannel] = process; 1916 chan_process[inchannel] = process;
1864 XPROCESS (process)->infd = inchannel; 1917 p->infd = inchannel;
1865 XPROCESS (process)->outfd = outchannel; 1918 p->outfd = outchannel;
1866 1919
1867 /* Previously we recorded the tty descriptor used in the subprocess. 1920 /* Previously we recorded the tty descriptor used in the subprocess.
1868 It was only used for getting the foreground tty process, so now 1921 It was only used for getting the foreground tty process, so now
1869 we just reopen the device (see emacs_get_tty_pgrp) as this is 1922 we just reopen the device (see emacs_get_tty_pgrp) as this is
1870 more portable (see USG_SUBTTY_WORKS above). */ 1923 more portable (see USG_SUBTTY_WORKS above). */
1871 1924
1872 XPROCESS (process)->pty_flag = pty_flag; 1925 p->pty_flag = pty_flag;
1873 pset_status (XPROCESS (process), Qrun); 1926 pset_status (p, Qrun);
1874 1927
1875 add_process_read_fd (inchannel); 1928 add_process_read_fd (inchannel);
1876 1929
@@ -1887,25 +1940,21 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1887 { 1940 {
1888 Lisp_Object volatile encoded_current_dir_volatile = encoded_current_dir; 1941 Lisp_Object volatile encoded_current_dir_volatile = encoded_current_dir;
1889 Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name; 1942 Lisp_Object volatile lisp_pty_name_volatile = lisp_pty_name;
1890 Lisp_Object volatile process_volatile = process;
1891 char **volatile new_argv_volatile = new_argv; 1943 char **volatile new_argv_volatile = new_argv;
1892 int volatile forkin_volatile = forkin; 1944 int volatile forkin_volatile = forkin;
1893 int volatile forkout_volatile = forkout; 1945 int volatile forkout_volatile = forkout;
1894 int volatile wait_child_setup_0_volatile = wait_child_setup[0]; 1946 struct Lisp_Process *p_volatile = p;
1895 int volatile wait_child_setup_1_volatile = wait_child_setup[1];
1896 1947
1897 pid = vfork (); 1948 pid = vfork ();
1898 1949
1899 encoded_current_dir = encoded_current_dir_volatile; 1950 encoded_current_dir = encoded_current_dir_volatile;
1900 lisp_pty_name = lisp_pty_name_volatile; 1951 lisp_pty_name = lisp_pty_name_volatile;
1901 process = process_volatile;
1902 new_argv = new_argv_volatile; 1952 new_argv = new_argv_volatile;
1903 forkin = forkin_volatile; 1953 forkin = forkin_volatile;
1904 forkout = forkout_volatile; 1954 forkout = forkout_volatile;
1905 wait_child_setup[0] = wait_child_setup_0_volatile; 1955 p = p_volatile;
1906 wait_child_setup[1] = wait_child_setup_1_volatile;
1907 1956
1908 pty_flag = XPROCESS (process)->pty_flag; 1957 pty_flag = p->pty_flag;
1909 } 1958 }
1910 1959
1911 if (pid == 0) 1960 if (pid == 0)
@@ -2021,42 +2070,42 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2021 /* Back in the parent process. */ 2070 /* Back in the parent process. */
2022 2071
2023 vfork_errno = errno; 2072 vfork_errno = errno;
2024 XPROCESS (process)->pid = pid; 2073 p->pid = pid;
2025 if (pid >= 0) 2074 if (pid >= 0)
2026 XPROCESS (process)->alive = 1; 2075 p->alive = 1;
2027 2076
2028 /* Stop blocking in the parent. */ 2077 /* Stop blocking in the parent. */
2029 unblock_child_signal (); 2078 unblock_child_signal ();
2030 unblock_input (); 2079 unblock_input ();
2031 2080
2032 if (forkin >= 0)
2033 emacs_close (forkin);
2034 if (forkin != forkout && forkout >= 0)
2035 emacs_close (forkout);
2036
2037 if (pid < 0) 2081 if (pid < 0)
2038 report_file_errno ("Doing vfork", Qnil, vfork_errno); 2082 report_file_errno ("Doing vfork", Qnil, vfork_errno);
2039 else 2083 else
2040 { 2084 {
2041 /* vfork succeeded. */ 2085 /* vfork succeeded. */
2042 2086
2087 /* Close the pipe ends that the child uses, or the child's pty. */
2088 close_process_fd (&p->open_fd[SUBPROCESS_STDIN]);
2089 close_process_fd (&p->open_fd[SUBPROCESS_STDOUT]);
2090
2043#ifdef WINDOWSNT 2091#ifdef WINDOWSNT
2044 register_child (pid, inchannel); 2092 register_child (pid, inchannel);
2045#endif /* WINDOWSNT */ 2093#endif /* WINDOWSNT */
2046 2094
2047 pset_tty_name (XPROCESS (process), lisp_pty_name); 2095 pset_tty_name (p, lisp_pty_name);
2048 2096
2049#ifndef WINDOWSNT 2097#ifndef WINDOWSNT
2050 /* Wait for child_setup to complete in case that vfork is 2098 /* Wait for child_setup to complete in case that vfork is
2051 actually defined as fork. The descriptor wait_child_setup[1] 2099 actually defined as fork. The descriptor
2100 XPROCESS (proc)->open_fd[EXEC_MONITOR_OUTPUT]
2052 of a pipe is closed at the child side either by close-on-exec 2101 of a pipe is closed at the child side either by close-on-exec
2053 on successful execve or the _exit call in child_setup. */ 2102 on successful execve or the _exit call in child_setup. */
2054 { 2103 {
2055 char dummy; 2104 char dummy;
2056 2105
2057 emacs_close (wait_child_setup[1]); 2106 close_process_fd (&p->open_fd[EXEC_MONITOR_OUTPUT]);
2058 emacs_read (wait_child_setup[0], &dummy, 1); 2107 emacs_read (p->open_fd[READ_FROM_EXEC_MONITOR], &dummy, 1);
2059 emacs_close (wait_child_setup[0]); 2108 close_process_fd (&p->open_fd[READ_FROM_EXEC_MONITOR]);
2060 } 2109 }
2061#endif 2110#endif
2062 } 2111 }
@@ -2065,16 +2114,13 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
2065static void 2114static void
2066create_pty (Lisp_Object process) 2115create_pty (Lisp_Object process)
2067{ 2116{
2117 struct Lisp_Process *p = XPROCESS (process);
2068 char pty_name[PTY_NAME_SIZE]; 2118 char pty_name[PTY_NAME_SIZE];
2069 int inchannel, outchannel; 2119 int pty_fd = NILP (Vprocess_connection_type) ? -1 : allocate_pty (pty_name);
2070
2071 inchannel = outchannel = -1;
2072
2073 if (!NILP (Vprocess_connection_type))
2074 outchannel = inchannel = allocate_pty (pty_name);
2075 2120
2076 if (inchannel >= 0) 2121 if (pty_fd >= 0)
2077 { 2122 {
2123 p->open_fd[SUBPROCESS_STDIN] = pty_fd;
2078#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 2124#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
2079 /* On most USG systems it does not work to open the pty's tty here, 2125 /* On most USG systems it does not work to open the pty's tty here,
2080 then close it and reopen it in the child. */ 2126 then close it and reopen it in the child. */
@@ -2083,6 +2129,7 @@ create_pty (Lisp_Object process)
2083 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 2129 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
2084 if (forkout < 0) 2130 if (forkout < 0)
2085 report_file_error ("Opening pty", Qnil); 2131 report_file_error ("Opening pty", Qnil);
2132 p->open_fd[WRITE_TO_SUBPROCESS] = forkout;
2086#if defined (DONT_REOPEN_PTY) 2133#if defined (DONT_REOPEN_PTY)
2087 /* In the case that vfork is defined as fork, the parent process 2134 /* In the case that vfork is defined as fork, the parent process
2088 (Emacs) may send some data before the child process completes 2135 (Emacs) may send some data before the child process completes
@@ -2091,28 +2138,29 @@ create_pty (Lisp_Object process)
2091#endif /* DONT_REOPEN_PTY */ 2138#endif /* DONT_REOPEN_PTY */
2092#endif /* not USG, or USG_SUBTTY_WORKS */ 2139#endif /* not USG, or USG_SUBTTY_WORKS */
2093 2140
2094 fcntl (inchannel, F_SETFL, O_NONBLOCK); 2141 fcntl (pty_fd, F_SETFL, O_NONBLOCK);
2095 fcntl (outchannel, F_SETFL, O_NONBLOCK);
2096 2142
2097 /* Record this as an active process, with its channels. 2143 /* Record this as an active process, with its channels.
2098 As a result, child_setup will close Emacs's side of the pipes. */ 2144 As a result, child_setup will close Emacs's side of the pipes. */
2099 chan_process[inchannel] = process; 2145 chan_process[pty_fd] = process;
2100 XPROCESS (process)->infd = inchannel; 2146 p->infd = pty_fd;
2101 XPROCESS (process)->outfd = outchannel; 2147 p->outfd = pty_fd;
2102 2148
2103 /* Previously we recorded the tty descriptor used in the subprocess. 2149 /* Previously we recorded the tty descriptor used in the subprocess.
2104 It was only used for getting the foreground tty process, so now 2150 It was only used for getting the foreground tty process, so now
2105 we just reopen the device (see emacs_get_tty_pgrp) as this is 2151 we just reopen the device (see emacs_get_tty_pgrp) as this is
2106 more portable (see USG_SUBTTY_WORKS above). */ 2152 more portable (see USG_SUBTTY_WORKS above). */
2107 2153
2108 XPROCESS (process)->pty_flag = 1; 2154 p->pty_flag = 1;
2109 pset_status (XPROCESS (process), Qrun); 2155 pset_status (p, Qrun);
2110 setup_process_coding_systems (process); 2156 setup_process_coding_systems (process);
2111 2157
2112 pset_tty_name (XPROCESS (process), build_string (pty_name)); 2158 fixme;
2159
2160 pset_tty_name (p, build_string (pty_name));
2113 } 2161 }
2114 2162
2115 XPROCESS (process)->pid = -2; 2163 p->pid = -2;
2116} 2164}
2117 2165
2118 2166
@@ -2718,6 +2766,7 @@ usage: (make-serial-process &rest ARGS) */)
2718 p = XPROCESS (proc); 2766 p = XPROCESS (proc);
2719 2767
2720 fd = serial_open (port); 2768 fd = serial_open (port);
2769 p->open_fd[SUBPROCESS_STDIN] = fd;
2721 p->infd = fd; 2770 p->infd = fd;
2722 p->outfd = fd; 2771 p->outfd = fd;
2723 if (fd > max_desc) 2772 if (fd > max_desc)
@@ -3477,12 +3526,6 @@ usage: (make-network-process &rest ARGS) */)
3477 } 3526 }
3478#endif 3527#endif
3479 3528
3480 /* Discard the unwind protect for closing S, if any. */
3481 specpdl_ptr = specpdl + count1;
3482
3483 /* Unwind bind_polling_period and request_sigio. */
3484 unbind_to (count, Qnil);
3485
3486 if (s < 0) 3529 if (s < 0)
3487 { 3530 {
3488 /* If non-blocking got this far - and failed - assume non-blocking is 3531 /* If non-blocking got this far - and failed - assume non-blocking is
@@ -3524,8 +3567,17 @@ usage: (make-network-process &rest ARGS) */)
3524 if ((tem = Fplist_get (contact, QCstop), !NILP (tem))) 3567 if ((tem = Fplist_get (contact, QCstop), !NILP (tem)))
3525 pset_command (p, Qt); 3568 pset_command (p, Qt);
3526 p->pid = 0; 3569 p->pid = 0;
3570
3571 p->open_fd[SUBPROCESS_STDIN] = inch;
3527 p->infd = inch; 3572 p->infd = inch;
3528 p->outfd = outch; 3573 p->outfd = outch;
3574
3575 /* Discard the unwind protect for closing S, if any. */
3576 specpdl_ptr = specpdl + count1;
3577
3578 /* Unwind bind_polling_period and request_sigio. */
3579 unbind_to (count, Qnil);
3580
3529 if (is_server && socktype != SOCK_DGRAM) 3581 if (is_server && socktype != SOCK_DGRAM)
3530 pset_status (p, Qlisten); 3582 pset_status (p, Qlisten);
3531 3583
@@ -3957,17 +4009,15 @@ FLAGS is the current flags of the interface. */)
3957static void 4009static void
3958deactivate_process (Lisp_Object proc) 4010deactivate_process (Lisp_Object proc)
3959{ 4011{
3960 register int inchannel, outchannel; 4012 int inchannel;
3961 register struct Lisp_Process *p = XPROCESS (proc); 4013 struct Lisp_Process *p = XPROCESS (proc);
4014 int i;
3962 4015
3963#ifdef HAVE_GNUTLS 4016#ifdef HAVE_GNUTLS
3964 /* Delete GnuTLS structures in PROC, if any. */ 4017 /* Delete GnuTLS structures in PROC, if any. */
3965 emacs_gnutls_deinit (proc); 4018 emacs_gnutls_deinit (proc);
3966#endif /* HAVE_GNUTLS */ 4019#endif /* HAVE_GNUTLS */
3967 4020
3968 inchannel = p->infd;
3969 outchannel = p->outfd;
3970
3971#ifdef ADAPTIVE_READ_BUFFERING 4021#ifdef ADAPTIVE_READ_BUFFERING
3972 if (p->read_output_delay > 0) 4022 if (p->read_output_delay > 0)
3973 { 4023 {
@@ -3978,14 +4028,17 @@ deactivate_process (Lisp_Object proc)
3978 } 4028 }
3979#endif 4029#endif
3980 4030
4031 inchannel = p->infd;
4032
4033 /* Beware SIGCHLD hereabouts. */
3981 if (inchannel >= 0) 4034 if (inchannel >= 0)
3982 { 4035 flush_pending_output (inchannel);
3983 /* Beware SIGCHLD hereabouts. */
3984 flush_pending_output (inchannel);
3985 emacs_close (inchannel);
3986 if (outchannel >= 0 && outchannel != inchannel)
3987 emacs_close (outchannel);
3988 4036
4037 for (i = 0; i < PROCESS_OPEN_FDS; i++)
4038 close_process_fd (&p->open_fd[i]);
4039
4040 if (inchannel >= 0)
4041 {
3989 p->infd = -1; 4042 p->infd = -1;
3990 p->outfd = -1; 4043 p->outfd = -1;
3991#ifdef DATAGRAM_SOCKETS 4044#ifdef DATAGRAM_SOCKETS
@@ -4263,6 +4316,7 @@ server_accept_connection (Lisp_Object server, int channel)
4263 /* Discard the unwind protect for closing S. */ 4316 /* Discard the unwind protect for closing S. */
4264 specpdl_ptr = specpdl + count; 4317 specpdl_ptr = specpdl + count;
4265 4318
4319 p->open_fd[SUBPROCESS_STDIN] = s;
4266 p->infd = s; 4320 p->infd = s;
4267 p->outfd = s; 4321 p->outfd = s;
4268 pset_status (p, Qrun); 4322 pset_status (p, Qrun);
@@ -4682,7 +4736,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4682#endif 4736#endif
4683 , max_desc + 1, 4737 , max_desc + 1,
4684 &Available, 4738 &Available,
4685 (check_write ? &Writeok : (SELECT_TYPE *)0), 4739 (check_write ? &Writeok : 0),
4686 NULL, &timeout, NULL); 4740 NULL, &timeout, NULL);
4687 4741
4688#ifdef HAVE_GNUTLS 4742#ifdef HAVE_GNUTLS
@@ -6160,7 +6214,8 @@ process has been transmitted to the serial port. */)
6160 } 6214 }
6161 else 6215 else
6162 { 6216 {
6163 int old_outfd, new_outfd; 6217 int old_outfd = XPROCESS (proc)->outfd;
6218 int new_outfd;
6164 6219
6165#ifdef HAVE_SHUTDOWN 6220#ifdef HAVE_SHUTDOWN
6166 /* If this is a network connection, or socketpair is used 6221 /* If this is a network connection, or socketpair is used
@@ -6168,18 +6223,15 @@ process has been transmitted to the serial port. */)
6168 (In some old system, shutdown to socketpair doesn't work. 6223 (In some old system, shutdown to socketpair doesn't work.
6169 Then we just can't win.) */ 6224 Then we just can't win.) */
6170 if (EQ (XPROCESS (proc)->type, Qnetwork) 6225 if (EQ (XPROCESS (proc)->type, Qnetwork)
6171 || XPROCESS (proc)->outfd == XPROCESS (proc)->infd) 6226 || XPROCESS (proc)->infd == old_outfd)
6172 shutdown (XPROCESS (proc)->outfd, 1); 6227 shutdown (old_outfd, 1);
6173 /* In case of socketpair, outfd == infd, so don't close it. */ 6228#endif
6174 if (XPROCESS (proc)->outfd != XPROCESS (proc)->infd) 6229 close_process_fd (&XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS]);
6175 emacs_close (XPROCESS (proc)->outfd);
6176#else /* not HAVE_SHUTDOWN */
6177 emacs_close (XPROCESS (proc)->outfd);
6178#endif /* not HAVE_SHUTDOWN */
6179 new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); 6230 new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0);
6180 if (new_outfd < 0) 6231 if (new_outfd < 0)
6181 emacs_abort (); 6232 report_file_error ("Opening null device", Qnil);
6182 old_outfd = XPROCESS (proc)->outfd; 6233 XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS] = new_outfd;
6234 XPROCESS (proc)->outfd = new_outfd;
6183 6235
6184 if (!proc_encode_coding_system[new_outfd]) 6236 if (!proc_encode_coding_system[new_outfd])
6185 proc_encode_coding_system[new_outfd] 6237 proc_encode_coding_system[new_outfd]
@@ -6188,8 +6240,6 @@ process has been transmitted to the serial port. */)
6188 = *proc_encode_coding_system[old_outfd]; 6240 = *proc_encode_coding_system[old_outfd];
6189 memset (proc_encode_coding_system[old_outfd], 0, 6241 memset (proc_encode_coding_system[old_outfd], 0,
6190 sizeof (struct coding_system)); 6242 sizeof (struct coding_system));
6191
6192 XPROCESS (proc)->outfd = new_outfd;
6193 } 6243 }
6194 return process; 6244 return process;
6195} 6245}
@@ -6255,7 +6305,7 @@ static signal_handler_t volatile lib_child_handler;
6255static void 6305static void
6256handle_child_signal (int sig) 6306handle_child_signal (int sig)
6257{ 6307{
6258 Lisp_Object tail; 6308 Lisp_Object tail, proc;
6259 6309
6260 /* Find the process that signaled us, and record its status. */ 6310 /* Find the process that signaled us, and record its status. */
6261 6311
@@ -6266,7 +6316,11 @@ handle_child_signal (int sig)
6266 bool all_pids_are_fixnums 6316 bool all_pids_are_fixnums
6267 = (MOST_NEGATIVE_FIXNUM <= TYPE_MINIMUM (pid_t) 6317 = (MOST_NEGATIVE_FIXNUM <= TYPE_MINIMUM (pid_t)
6268 && TYPE_MAXIMUM (pid_t) <= MOST_POSITIVE_FIXNUM); 6318 && TYPE_MAXIMUM (pid_t) <= MOST_POSITIVE_FIXNUM);
6269 Lisp_Object xpid = XCAR (tail); 6319 Lisp_Object head = XCAR (tail);
6320 Lisp_Object xpid;
6321 if (! CONSP (head))
6322 continue;
6323 xpid = XCAR (head);
6270 if (all_pids_are_fixnums ? INTEGERP (xpid) : NUMBERP (xpid)) 6324 if (all_pids_are_fixnums ? INTEGERP (xpid) : NUMBERP (xpid))
6271 { 6325 {
6272 pid_t deleted_pid; 6326 pid_t deleted_pid;
@@ -6275,14 +6329,17 @@ handle_child_signal (int sig)
6275 else 6329 else
6276 deleted_pid = XFLOAT_DATA (xpid); 6330 deleted_pid = XFLOAT_DATA (xpid);
6277 if (child_status_changed (deleted_pid, 0, 0)) 6331 if (child_status_changed (deleted_pid, 0, 0))
6278 XSETCAR (tail, Qnil); 6332 {
6333 if (STRINGP (XCDR (head)))
6334 unlink (SSDATA (XCDR (head)));
6335 XSETCAR (tail, Qnil);
6336 }
6279 } 6337 }
6280 } 6338 }
6281 6339
6282 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ 6340 /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */
6283 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 6341 FOR_EACH_PROCESS (tail, proc)
6284 { 6342 {
6285 Lisp_Object proc = XCDR (XCAR (tail));
6286 struct Lisp_Process *p = XPROCESS (proc); 6343 struct Lisp_Process *p = XPROCESS (proc);
6287 int status; 6344 int status;
6288 6345
@@ -6434,13 +6491,10 @@ status_notify (struct Lisp_Process *deleting_process)
6434 that we run, we get called again to handle their status changes. */ 6491 that we run, we get called again to handle their status changes. */
6435 update_tick = process_tick; 6492 update_tick = process_tick;
6436 6493
6437 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 6494 FOR_EACH_PROCESS (tail, proc)
6438 { 6495 {
6439 Lisp_Object symbol; 6496 Lisp_Object symbol;
6440 register struct Lisp_Process *p; 6497 register struct Lisp_Process *p = XPROCESS (proc);
6441
6442 proc = Fcdr (XCAR (tail));
6443 p = XPROCESS (proc);
6444 6498
6445 if (p->tick != p->update_tick) 6499 if (p->tick != p->update_tick)
6446 { 6500 {
@@ -6970,12 +7024,9 @@ BUFFER may be a buffer or the name of one. */)
6970 buf = Fget_buffer (buffer); 7024 buf = Fget_buffer (buffer);
6971 if (NILP (buf)) return Qnil; 7025 if (NILP (buf)) return Qnil;
6972 7026
6973 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 7027 FOR_EACH_PROCESS (tail, proc)
6974 { 7028 if (EQ (XPROCESS (proc)->buffer, buf))
6975 proc = Fcdr (XCAR (tail)); 7029 return proc;
6976 if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
6977 return proc;
6978 }
6979#endif /* subprocesses */ 7030#endif /* subprocesses */
6980 return Qnil; 7031 return Qnil;
6981} 7032}
@@ -7008,18 +7059,14 @@ kill_buffer_processes (Lisp_Object buffer)
7008#ifdef subprocesses 7059#ifdef subprocesses
7009 Lisp_Object tail, proc; 7060 Lisp_Object tail, proc;
7010 7061
7011 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) 7062 FOR_EACH_PROCESS (tail, proc)
7012 { 7063 if (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))
7013 proc = XCDR (XCAR (tail)); 7064 {
7014 if (PROCESSP (proc) 7065 if (NETCONN_P (proc) || SERIALCONN_P (proc))
7015 && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))) 7066 Fdelete_process (proc);
7016 { 7067 else if (XPROCESS (proc)->infd >= 0)
7017 if (NETCONN_P (proc) || SERIALCONN_P (proc)) 7068 process_send_signal (proc, SIGHUP, Qnil, 1);
7018 Fdelete_process (proc); 7069 }
7019 else if (XPROCESS (proc)->infd >= 0)
7020 process_send_signal (proc, SIGHUP, Qnil, 1);
7021 }
7022 }
7023#else /* subprocesses */ 7070#else /* subprocesses */
7024 /* Since we have no subprocesses, this does nothing. */ 7071 /* Since we have no subprocesses, this does nothing. */
7025#endif /* subprocesses */ 7072#endif /* subprocesses */
@@ -7183,7 +7230,7 @@ init_process_emacs (void)
7183 catch_child_signal (); 7230 catch_child_signal ();
7184 } 7231 }
7185 7232
7186 max_desc = 0; 7233 max_desc = -1;
7187 memset (fd_callback_info, 0, sizeof (fd_callback_info)); 7234 memset (fd_callback_info, 0, sizeof (fd_callback_info));
7188 7235
7189#ifdef NON_BLOCKING_CONNECT 7236#ifdef NON_BLOCKING_CONNECT
diff --git a/src/process.h b/src/process.h
index 89c7e8b1259..95881d10f58 100644
--- a/src/process.h
+++ b/src/process.h
@@ -31,6 +31,11 @@ INLINE_HEADER_BEGIN
31# define PROCESS_INLINE INLINE 31# define PROCESS_INLINE INLINE
32#endif 32#endif
33 33
34/* Bound on number of file descriptors opened on behalf of a process,
35 that need to be closed. */
36
37enum { PROCESS_OPEN_FDS = 6 };
38
34/* This structure records information about a subprocess 39/* This structure records information about a subprocess
35 or network connection. */ 40 or network connection. */
36 41
@@ -118,6 +123,9 @@ struct Lisp_Process
118 int infd; 123 int infd;
119 /* Descriptor by which we write to this process */ 124 /* Descriptor by which we write to this process */
120 int outfd; 125 int outfd;
126 /* Descriptors that were created for this process and that need
127 closing. Unused entries are negative. */
128 int open_fd[PROCESS_OPEN_FDS];
121 /* Event-count of last event in which this process changed status. */ 129 /* Event-count of last event in which this process changed status. */
122 EMACS_INT tick; 130 EMACS_INT tick;
123 /* Event-count of last such event reported. */ 131 /* Event-count of last such event reported. */
@@ -213,13 +221,16 @@ enum
213 221
214extern void block_child_signal (void); 222extern void block_child_signal (void);
215extern void unblock_child_signal (void); 223extern void unblock_child_signal (void);
216extern void record_kill_process (struct Lisp_Process *); 224extern void record_kill_process (struct Lisp_Process *, Lisp_Object);
217 225
218/* Defined in process.c. */ 226/* Defined in sysdep.c. */
219 227
220extern Lisp_Object list_system_processes (void); 228extern Lisp_Object list_system_processes (void);
221extern Lisp_Object system_process_attributes (Lisp_Object); 229extern Lisp_Object system_process_attributes (Lisp_Object);
222 230
231/* Defined in process.c. */
232
233extern void record_deleted_pid (pid_t, Lisp_Object);
223extern void hold_keyboard_input (void); 234extern void hold_keyboard_input (void);
224extern void unhold_keyboard_input (void); 235extern void unhold_keyboard_input (void);
225extern bool kbd_on_hold_p (void); 236extern bool kbd_on_hold_p (void);
diff --git a/src/regex.c b/src/regex.c
index 5024f748884..75661a27892 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -468,7 +468,7 @@ init_syntax_once (void)
468 468
469/* Assumes a `char *destination' variable. */ 469/* Assumes a `char *destination' variable. */
470# define REGEX_REALLOCATE(source, osize, nsize) \ 470# define REGEX_REALLOCATE(source, osize, nsize) \
471 (destination = (char *) alloca (nsize), \ 471 (destination = alloca (nsize), \
472 memcpy (destination, source, osize)) 472 memcpy (destination, source, osize))
473 473
474/* No need to do anything to free, after alloca. */ 474/* No need to do anything to free, after alloca. */
@@ -4212,7 +4212,7 @@ re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs, uns
4212 { 4212 {
4213 bufp->regs_allocated = REGS_UNALLOCATED; 4213 bufp->regs_allocated = REGS_UNALLOCATED;
4214 regs->num_regs = 0; 4214 regs->num_regs = 0;
4215 regs->start = regs->end = (regoff_t *) 0; 4215 regs->start = regs->end = 0;
4216 } 4216 }
4217} 4217}
4218WEAK_ALIAS (__re_set_registers, re_set_registers) 4218WEAK_ALIAS (__re_set_registers, re_set_registers)
@@ -6393,8 +6393,7 @@ weak_function
6393re_exec (const char *s) 6393re_exec (const char *s)
6394{ 6394{
6395 const size_t len = strlen (s); 6395 const size_t len = strlen (s);
6396 return (re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0) 6396 return re_search (&re_comp_buf, s, len, 0, len, 0) >= 0;
6397 >= 0);
6398} 6397}
6399#endif /* _REGEX_RE_COMP */ 6398#endif /* _REGEX_RE_COMP */
6400 6399
@@ -6558,7 +6557,7 @@ regexec (const regex_t *_Restrict_ preg, const char *_Restrict_ string,
6558 /* Perform the searching operation. */ 6557 /* Perform the searching operation. */
6559 ret = re_search (&private_preg, string, len, 6558 ret = re_search (&private_preg, string, len,
6560 /* start: */ 0, /* range: */ len, 6559 /* start: */ 0, /* range: */ len,
6561 want_reg_info ? &regs : (struct re_registers *) 0); 6560 want_reg_info ? &regs : 0);
6562 6561
6563 /* Copy the register information to the POSIX structure. */ 6562 /* Copy the register information to the POSIX structure. */
6564 if (want_reg_info) 6563 if (want_reg_info)
diff --git a/src/scroll.c b/src/scroll.c
index 037e338c696..b9ed8c04ba8 100644
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -86,7 +86,7 @@ static void do_scrolling (struct frame *,
86 new contents appears. */ 86 new contents appears. */
87 87
88static void 88static void
89calculate_scrolling (FRAME_PTR frame, 89calculate_scrolling (struct frame *frame,
90 /* matrix is of size window_size + 1 on each side. */ 90 /* matrix is of size window_size + 1 on each side. */
91 struct matrix_elt *matrix, 91 struct matrix_elt *matrix,
92 int window_size, int lines_below, 92 int window_size, int lines_below,
@@ -422,7 +422,7 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
422 is the equivalent of draw_cost for the old line contents */ 422 is the equivalent of draw_cost for the old line contents */
423 423
424static void 424static void
425calculate_direct_scrolling (FRAME_PTR frame, 425calculate_direct_scrolling (struct frame *frame,
426 /* matrix is of size window_size + 1 on each side. */ 426 /* matrix is of size window_size + 1 on each side. */
427 struct matrix_elt *matrix, 427 struct matrix_elt *matrix,
428 int window_size, int lines_below, 428 int window_size, int lines_below,
@@ -652,8 +652,7 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
652 652
653 /* A queue of deletions and insertions to be performed. */ 653 /* A queue of deletions and insertions to be performed. */
654 struct alt_queue { int count, pos, window; }; 654 struct alt_queue { int count, pos, window; };
655 struct alt_queue *queue_start = (struct alt_queue *) 655 struct alt_queue *queue_start = alloca (window_size * sizeof *queue_start);
656 alloca (window_size * sizeof *queue_start);
657 struct alt_queue *queue = queue_start; 656 struct alt_queue *queue = queue_start;
658 657
659 /* True if a terminal window has been set with set_terminal_window. */ 658 /* True if a terminal window has been set with set_terminal_window. */
@@ -793,13 +792,12 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
793 792
794 793
795void 794void
796scrolling_1 (FRAME_PTR frame, int window_size, int unchanged_at_top, 795scrolling_1 (struct frame *frame, int window_size, int unchanged_at_top,
797 int unchanged_at_bottom, int *draw_cost, int *old_draw_cost, 796 int unchanged_at_bottom, int *draw_cost, int *old_draw_cost,
798 int *old_hash, int *new_hash, int free_at_end) 797 int *old_hash, int *new_hash, int free_at_end)
799{ 798{
800 struct matrix_elt *matrix; 799 struct matrix_elt *matrix
801 matrix = ((struct matrix_elt *) 800 = alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix);
802 alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
803 801
804 if (FRAME_SCROLL_REGION_OK (frame)) 802 if (FRAME_SCROLL_REGION_OK (frame))
805 { 803 {
@@ -883,7 +881,7 @@ scrolling_max_lines_saved (int start, int end,
883 overhead and multiply factor values */ 881 overhead and multiply factor values */
884 882
885static void 883static void
886line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn, 884line_ins_del (struct frame *frame, int ov1, int pf1, int ovn, int pfn,
887 register int *ov, register int *mf) 885 register int *ov, register int *mf)
888{ 886{
889 register int i; 887 register int i;
@@ -901,7 +899,7 @@ line_ins_del (FRAME_PTR frame, int ov1, int pf1, int ovn, int pfn,
901} 899}
902 900
903static void 901static void
904ins_del_costs (FRAME_PTR frame, 902ins_del_costs (struct frame *frame,
905 const char *one_line_string, const char *multi_string, 903 const char *one_line_string, const char *multi_string,
906 const char *setup_string, const char *cleanup_string, 904 const char *setup_string, const char *cleanup_string,
907 int *costvec, int *ncostvec, 905 int *costvec, int *ncostvec,
@@ -957,7 +955,7 @@ ins_del_costs (FRAME_PTR frame,
957 */ 955 */
958 956
959void 957void
960do_line_insertion_deletion_costs (FRAME_PTR frame, 958do_line_insertion_deletion_costs (struct frame *frame,
961 const char *ins_line_string, 959 const char *ins_line_string,
962 const char *multi_ins_string, 960 const char *multi_ins_string,
963 const char *del_line_string, 961 const char *del_line_string,
diff --git a/src/search.c b/src/search.c
index e1147aca858..8916960cf62 100644
--- a/src/search.c
+++ b/src/search.c
@@ -598,14 +598,14 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte,
598 598
599/* The newline cache: remembering which sections of text have no newlines. */ 599/* The newline cache: remembering which sections of text have no newlines. */
600 600
601/* If the user has requested newline caching, make sure it's on. 601/* If the user has requested the long scans caching, make sure it's on.
602 Otherwise, make sure it's off. 602 Otherwise, make sure it's off.
603 This is our cheezy way of associating an action with the change of 603 This is our cheezy way of associating an action with the change of
604 state of a buffer-local variable. */ 604 state of a buffer-local variable. */
605static void 605static void
606newline_cache_on_off (struct buffer *buf) 606newline_cache_on_off (struct buffer *buf)
607{ 607{
608 if (NILP (BVAR (buf, cache_long_line_scans))) 608 if (NILP (BVAR (buf, cache_long_scans)))
609 { 609 {
610 /* It should be off. */ 610 /* It should be off. */
611 if (buf->newline_cache) 611 if (buf->newline_cache)
diff --git a/src/sheap.c b/src/sheap.c
index 54eef60c27d..daff0c1d700 100644
--- a/src/sheap.c
+++ b/src/sheap.c
@@ -26,10 +26,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <unistd.h> 26#include <unistd.h>
27 27
28#ifdef __x86_64__ 28#ifdef __x86_64__
29#ifdef ENABLE_CHECKING
30#define STATIC_HEAP_SIZE (28 * 1024 * 1024)
31#else
32#define STATIC_HEAP_SIZE (19 * 1024 * 1024)
33#endif
34#else /* x86 */
35#ifdef ENABLE_CHECKING
29#define STATIC_HEAP_SIZE (18 * 1024 * 1024) 36#define STATIC_HEAP_SIZE (18 * 1024 * 1024)
30#else 37#else
31#define STATIC_HEAP_SIZE (13 * 1024 * 1024) 38#define STATIC_HEAP_SIZE (13 * 1024 * 1024)
32#endif 39#endif
40#endif /* x86 */
33 41
34int debug_sheap = 0; 42int debug_sheap = 0;
35 43
@@ -37,6 +45,7 @@ int debug_sheap = 0;
37 45
38char bss_sbrk_buffer[STATIC_HEAP_SIZE]; 46char bss_sbrk_buffer[STATIC_HEAP_SIZE];
39char *bss_sbrk_ptr; 47char *bss_sbrk_ptr;
48char *max_bss_sbrk_ptr;
40int bss_sbrk_did_unexec; 49int bss_sbrk_did_unexec;
41 50
42void * 51void *
@@ -44,7 +53,7 @@ bss_sbrk (ptrdiff_t request_size)
44{ 53{
45 if (!bss_sbrk_ptr) 54 if (!bss_sbrk_ptr)
46 { 55 {
47 bss_sbrk_ptr = bss_sbrk_buffer; 56 max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer;
48#ifdef CYGWIN 57#ifdef CYGWIN
49 sbrk (BLOCKSIZE); /* force space for fork to work */ 58 sbrk (BLOCKSIZE); /* force space for fork to work */
50#endif 59#endif
@@ -85,6 +94,8 @@ bss_sbrk (ptrdiff_t request_size)
85 if (debug_sheap) 94 if (debug_sheap)
86 printf ("allocated 0x%08x size %d\n", ret, request_size); 95 printf ("allocated 0x%08x size %d\n", ret, request_size);
87 bss_sbrk_ptr += (int) request_size; 96 bss_sbrk_ptr += (int) request_size;
97 if (bss_sbrk_ptr > max_bss_sbrk_ptr)
98 max_bss_sbrk_ptr = bss_sbrk_ptr;
88 return ret; 99 return ret;
89 } 100 }
90} 101}
@@ -93,8 +104,8 @@ void
93report_sheap_usage (int die_if_pure_storage_exceeded) 104report_sheap_usage (int die_if_pure_storage_exceeded)
94{ 105{
95 char buf[200]; 106 char buf[200];
96 sprintf (buf, "Static heap usage: %d of %d bytes", 107 sprintf (buf, "Maximum static heap usage: %d of %d bytes",
97 bss_sbrk_ptr - bss_sbrk_buffer, STATIC_HEAP_SIZE); 108 max_bss_sbrk_ptr - bss_sbrk_buffer, STATIC_HEAP_SIZE);
98 /* Don't log messages, cause at this point, we're not allowed to create 109 /* Don't log messages, cause at this point, we're not allowed to create
99 buffers. */ 110 buffers. */
100 message1_nolog (buf); 111 message1_nolog (buf);
diff --git a/src/syntax.c b/src/syntax.c
index 6d52d115889..f5b37303a4a 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1464,6 +1464,7 @@ scan_words (register ptrdiff_t from, register EMACS_INT count)
1464 1464
1465DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "^p", 1465DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "^p",
1466 doc: /* Move point forward ARG words (backward if ARG is negative). 1466 doc: /* Move point forward ARG words (backward if ARG is negative).
1467If ARG is omitted or nil, move point forward one word.
1467Normally returns t. 1468Normally returns t.
1468If an edge of the buffer or a field boundary is reached, point is left there 1469If an edge of the buffer or a field boundary is reached, point is left there
1469and the function returns nil. Field boundaries are not noticed if 1470and the function returns nil. Field boundaries are not noticed if
diff --git a/src/sysdep.c b/src/sysdep.c
index 11a6f4a76ce..201ba9d104d 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3243,13 +3243,11 @@ system_process_attributes (Lisp_Object pid)
3243 attrs); 3243 attrs);
3244 3244
3245 decoded_cmd = (code_convert_string_norecord 3245 decoded_cmd = (code_convert_string_norecord
3246 (make_unibyte_string (pinfo.pr_fname, 3246 (build_unibyte_string (pinfo.pr_fname),
3247 strlen (pinfo.pr_fname)),
3248 Vlocale_coding_system, 0)); 3247 Vlocale_coding_system, 0));
3249 attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); 3248 attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
3250 decoded_cmd = (code_convert_string_norecord 3249 decoded_cmd = (code_convert_string_norecord
3251 (make_unibyte_string (pinfo.pr_psargs, 3250 (build_unibyte_string (pinfo.pr_psargs),
3252 strlen (pinfo.pr_psargs)),
3253 Vlocale_coding_system, 0)); 3251 Vlocale_coding_system, 0));
3254 attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs); 3252 attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
3255 } 3253 }
@@ -3319,9 +3317,9 @@ system_process_attributes (Lisp_Object pid)
3319 if (gr) 3317 if (gr)
3320 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); 3318 attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
3321 3319
3322 decoded_comm = code_convert_string_norecord 3320 decoded_comm = (code_convert_string_norecord
3323 (make_unibyte_string (proc.ki_comm, strlen (proc.ki_comm)), 3321 (build_unibyte_string (proc.ki_comm),
3324 Vlocale_coding_system, 0); 3322 Vlocale_coding_system, 0));
3325 3323
3326 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); 3324 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
3327 { 3325 {
diff --git a/src/syswait.h b/src/syswait.h
index 03e5cb5fe2e..4ae9129d7ed 100644
--- a/src/syswait.h
+++ b/src/syswait.h
@@ -52,9 +52,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
52#define WTERMSIG(status) ((status) & 0x7f) 52#define WTERMSIG(status) ((status) & 0x7f)
53#endif 53#endif
54 54
55/* Defined in process.c. */
56extern void record_deleted_pid (pid_t);
57
58/* Defined in sysdep.c. */ 55/* Defined in sysdep.c. */
59extern void wait_for_termination (pid_t, int *, bool); 56extern void wait_for_termination (pid_t, int *, bool);
60extern pid_t child_status_changed (pid_t, int *, int); 57extern pid_t child_status_changed (pid_t, int *, int);
diff --git a/src/term.c b/src/term.c
index 376d6e7831a..2966466aed2 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2233,8 +2233,7 @@ get_named_tty (const char *name)
2233{ 2233{
2234 struct terminal *t; 2234 struct terminal *t;
2235 2235
2236 if (!name) 2236 eassert (name);
2237 emacs_abort ();
2238 2237
2239 for (t = terminal_list; t; t = t->next_terminal) 2238 for (t = terminal_list; t; t = t->next_terminal)
2240 { 2239 {
@@ -2522,7 +2521,7 @@ tty_draw_row_with_mouse_face (struct window *w, struct glyph_row *row,
2522} 2521}
2523 2522
2524static bool 2523static bool
2525term_mouse_movement (FRAME_PTR frame, Gpm_Event *event) 2524term_mouse_movement (struct frame *frame, Gpm_Event *event)
2526{ 2525{
2527 /* Has the mouse moved off the glyph it was on at the last sighting? */ 2526 /* Has the mouse moved off the glyph it was on at the last sighting? */
2528 if (event->x != last_mouse_x || event->y != last_mouse_y) 2527 if (event->x != last_mouse_x || event->y != last_mouse_y)
@@ -2563,7 +2562,7 @@ timeval_to_Time (struct timeval const *t)
2563 This clears mouse_moved until the next motion 2562 This clears mouse_moved until the next motion
2564 event arrives. */ 2563 event arrives. */
2565static void 2564static void
2566term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 2565term_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
2567 enum scroll_bar_part *part, Lisp_Object *x, 2566 enum scroll_bar_part *part, Lisp_Object *x,
2568 Lisp_Object *y, Time *timeptr) 2567 Lisp_Object *y, Time *timeptr)
2569{ 2568{
@@ -2786,8 +2785,7 @@ create_tty_output (struct frame *f)
2786{ 2785{
2787 struct tty_output *t = xzalloc (sizeof *t); 2786 struct tty_output *t = xzalloc (sizeof *t);
2788 2787
2789 if (! FRAME_TERMCAP_P (f)) 2788 eassert (FRAME_TERMCAP_P (f));
2790 emacs_abort ();
2791 2789
2792 t->display_info = FRAME_TERMINAL (f)->display_info.tty; 2790 t->display_info = FRAME_TERMINAL (f)->display_info.tty;
2793 2791
@@ -2799,8 +2797,7 @@ create_tty_output (struct frame *f)
2799static void 2797static void
2800tty_free_frame_resources (struct frame *f) 2798tty_free_frame_resources (struct frame *f)
2801{ 2799{
2802 if (! FRAME_TERMCAP_P (f)) 2800 eassert (FRAME_TERMCAP_P (f));
2803 emacs_abort ();
2804 2801
2805 if (FRAME_FACE_CACHE (f)) 2802 if (FRAME_FACE_CACHE (f))
2806 free_frame_faces (f); 2803 free_frame_faces (f);
@@ -2815,8 +2812,7 @@ tty_free_frame_resources (struct frame *f)
2815static void 2812static void
2816tty_free_frame_resources (struct frame *f) 2813tty_free_frame_resources (struct frame *f)
2817{ 2814{
2818 if (! FRAME_TERMCAP_P (f) && ! FRAME_MSDOS_P (f)) 2815 eassert (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f));
2819 emacs_abort ();
2820 2816
2821 if (FRAME_FACE_CACHE (f)) 2817 if (FRAME_FACE_CACHE (f))
2822 free_frame_faces (f); 2818 free_frame_faces (f);
@@ -2933,7 +2929,7 @@ dissociate_if_controlling_tty (int fd)
2933 2929
2934 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100". 2930 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
2935 2931
2936 If MUST_SUCCEED is true, then all errors are fatal. */ 2932 If MUST_SUCCEED is true, then all errors are fatal. */
2937 2933
2938struct terminal * 2934struct terminal *
2939init_tty (const char *name, const char *terminal_type, bool must_succeed) 2935init_tty (const char *name, const char *terminal_type, bool must_succeed)
@@ -2944,7 +2940,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
2944 int status; 2940 int status;
2945 struct tty_display_info *tty = NULL; 2941 struct tty_display_info *tty = NULL;
2946 struct terminal *terminal = NULL; 2942 struct terminal *terminal = NULL;
2947 bool ctty = 0; /* True if asked to open controlling tty. */ 2943 bool ctty = false; /* True if asked to open controlling tty. */
2948 2944
2949 if (!terminal_type) 2945 if (!terminal_type)
2950 maybe_fatal (must_succeed, 0, 2946 maybe_fatal (must_succeed, 0,
@@ -3031,7 +3027,7 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
3031 tty->termcap_term_buffer = xmalloc (buffer_size); 3027 tty->termcap_term_buffer = xmalloc (buffer_size);
3032 3028
3033 /* On some systems, tgetent tries to access the controlling 3029 /* On some systems, tgetent tries to access the controlling
3034 terminal. */ 3030 terminal. */
3035 block_tty_out_signal (); 3031 block_tty_out_signal ();
3036 status = tgetent (tty->termcap_term_buffer, terminal_type); 3032 status = tgetent (tty->termcap_term_buffer, terminal_type);
3037 unblock_tty_out_signal (); 3033 unblock_tty_out_signal ();
@@ -3101,13 +3097,13 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3101 Right (tty) = tgetstr ("nd", address); 3097 Right (tty) = tgetstr ("nd", address);
3102 Down (tty) = tgetstr ("do", address); 3098 Down (tty) = tgetstr ("do", address);
3103 if (!Down (tty)) 3099 if (!Down (tty))
3104 Down (tty) = tgetstr ("nl", address); /* Obsolete name for "do" */ 3100 Down (tty) = tgetstr ("nl", address); /* Obsolete name for "do". */
3105 if (tgetflag ("bs")) 3101 if (tgetflag ("bs"))
3106 Left (tty) = "\b"; /* can't possibly be longer! */ 3102 Left (tty) = "\b"; /* Can't possibly be longer! */
3107 else /* (Actually, "bs" is obsolete...) */ 3103 else /* (Actually, "bs" is obsolete...) */
3108 Left (tty) = tgetstr ("le", address); 3104 Left (tty) = tgetstr ("le", address);
3109 if (!Left (tty)) 3105 if (!Left (tty))
3110 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le" */ 3106 Left (tty) = tgetstr ("bc", address); /* Obsolete name for "le". */
3111 tty->TS_pad_char = tgetstr ("pc", address); 3107 tty->TS_pad_char = tgetstr ("pc", address);
3112 tty->TS_repeat = tgetstr ("rp", address); 3108 tty->TS_repeat = tgetstr ("rp", address);
3113 tty->TS_end_standout_mode = tgetstr ("se", address); 3109 tty->TS_end_standout_mode = tgetstr ("se", address);
@@ -3229,7 +3225,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3229 don't think we're losing anything by turning it off. */ 3225 don't think we're losing anything by turning it off. */
3230 terminal->line_ins_del_ok = 0; 3226 terminal->line_ins_del_ok = 0;
3231 3227
3232 tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ 3228 tty->TN_max_colors = 16; /* Must be non-zero for tty-display-color-p. */
3233#endif /* DOS_NT */ 3229#endif /* DOS_NT */
3234 3230
3235#ifdef HAVE_GPM 3231#ifdef HAVE_GPM
@@ -3325,16 +3321,16 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3325 tty->Wcm->cm_tab = 0; 3321 tty->Wcm->cm_tab = 0;
3326 /* We can't support standout mode, because it uses magic cookies. */ 3322 /* We can't support standout mode, because it uses magic cookies. */
3327 tty->TS_standout_mode = 0; 3323 tty->TS_standout_mode = 0;
3328 /* But that means we cannot rely on ^M to go to column zero! */ 3324 /* But that means we cannot rely on ^M to go to column zero! */
3329 CR (tty) = 0; 3325 CR (tty) = 0;
3330 /* LF can't be trusted either -- can alter hpos */ 3326 /* LF can't be trusted either -- can alter hpos. */
3331 /* if move at column 0 thru a line with TS_standout_mode */ 3327 /* If move at column 0 thru a line with TS_standout_mode. */
3332 Down (tty) = 0; 3328 Down (tty) = 0;
3333 } 3329 }
3334 3330
3335 tty->specified_window = FrameRows (tty); 3331 tty->specified_window = FrameRows (tty);
3336 3332
3337 if (Wcm_init (tty) == -1) /* can't do cursor motion */ 3333 if (Wcm_init (tty) == -1) /* Can't do cursor motion. */
3338 { 3334 {
3339 maybe_fatal (must_succeed, terminal, 3335 maybe_fatal (must_succeed, terminal,
3340 "Terminal type \"%s\" is not powerful enough to run Emacs", 3336 "Terminal type \"%s\" is not powerful enough to run Emacs",
@@ -3443,8 +3439,7 @@ delete_tty (struct terminal *terminal)
3443 if (!terminal->name) 3439 if (!terminal->name)
3444 return; 3440 return;
3445 3441
3446 if (terminal->type != output_termcap) 3442 eassert (terminal->type == output_termcap);
3447 emacs_abort ();
3448 3443
3449 tty = terminal->display_info.tty; 3444 tty = terminal->display_info.tty;
3450 3445
diff --git a/src/termcap.c b/src/termcap.c
index be05828eea6..aa225d9b3b1 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -406,7 +406,7 @@ tgetent (char *bp, const char *name)
406 406
407 if (termcap_name && !filep && !strcmp (name, getenv ("TERM"))) 407 if (termcap_name && !filep && !strcmp (name, getenv ("TERM")))
408 { 408 {
409 indirect = tgetst1 (find_capability (termcap_name, "tc"), (char **) 0); 409 indirect = tgetst1 (find_capability (termcap_name, "tc"), 0);
410 if (!indirect) 410 if (!indirect)
411 { 411 {
412 if (!bp) 412 if (!bp)
@@ -490,7 +490,7 @@ tgetent (char *bp, const char *name)
490 /* Does this entry refer to another terminal type's entry? 490 /* Does this entry refer to another terminal type's entry?
491 If something is found, copy it into heap and null-terminate it. */ 491 If something is found, copy it into heap and null-terminate it. */
492 tc_search_point = find_capability (tc_search_point, "tc"); 492 tc_search_point = find_capability (tc_search_point, "tc");
493 term = tgetst1 (tc_search_point, (char **) 0); 493 term = tgetst1 (tc_search_point, 0);
494 } 494 }
495 495
496 emacs_close (fd); 496 emacs_close (fd);
diff --git a/src/terminal.c b/src/terminal.c
index c55fd4eb077..4b5532e3a44 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -39,6 +39,8 @@ static int next_terminal_id;
39/* The initial terminal device, created by initial_term_init. */ 39/* The initial terminal device, created by initial_term_init. */
40struct terminal *initial_terminal; 40struct terminal *initial_terminal;
41 41
42static Lisp_Object Qterminal_live_p;
43
42static void delete_initial_terminal (struct terminal *); 44static void delete_initial_terminal (struct terminal *);
43 45
44/* This setter is used only in this file, so it can be private. */ 46/* This setter is used only in this file, so it can be private. */
@@ -549,6 +551,8 @@ Each function is called with argument, the terminal.
549This may be called just before actually deleting the terminal, 551This may be called just before actually deleting the terminal,
550or some time later. */); 552or some time later. */);
551 Vdelete_terminal_functions = Qnil; 553 Vdelete_terminal_functions = Qnil;
554
555 DEFSYM (Qterminal_live_p, "terminal-live-p");
552 DEFSYM (Qdelete_terminal_functions, "delete-terminal-functions"); 556 DEFSYM (Qdelete_terminal_functions, "delete-terminal-functions");
553 DEFSYM (Qrun_hook_with_args, "run-hook-with-args"); 557 DEFSYM (Qrun_hook_with_args, "run-hook-with-args");
554 558
diff --git a/src/textprop.c b/src/textprop.c
index 282ae11d4ac..b804f345047 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -93,15 +93,25 @@ text_read_only (Lisp_Object propval)
93 xsignal0 (Qtext_read_only); 93 xsignal0 (Qtext_read_only);
94} 94}
95 95
96/* Prepare to modify the region of BUFFER from START to END. */ 96/* Prepare to modify the text properties of BUFFER from START to END. */
97 97
98static void 98static void
99modify_region (Lisp_Object buffer, Lisp_Object start, Lisp_Object end) 99modify_text_properties (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
100{ 100{
101 ptrdiff_t b = XINT (start), e = XINT (end);
101 struct buffer *buf = XBUFFER (buffer), *old = current_buffer; 102 struct buffer *buf = XBUFFER (buffer), *old = current_buffer;
102 103
103 set_buffer_internal (buf); 104 set_buffer_internal (buf);
104 modify_region_1 (XINT (start), XINT (end), true); 105
106 prepare_to_modify_buffer_1 (b, e, NULL);
107
108 BUF_COMPUTE_UNCHANGED (buf, b - 1, e);
109 if (MODIFF <= SAVE_MODIFF)
110 record_first_change ();
111 MODIFF++;
112
113 bset_point_before_scroll (current_buffer, Qnil);
114
105 set_buffer_internal (old); 115 set_buffer_internal (old);
106} 116}
107 117
@@ -1213,9 +1223,9 @@ add_text_properties_1 (Lisp_Object start, Lisp_Object end,
1213 ptrdiff_t prev_total_length = TOTAL_LENGTH (i); 1223 ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
1214 ptrdiff_t prev_pos = i->position; 1224 ptrdiff_t prev_pos = i->position;
1215 1225
1216 modify_region (object, start, end); 1226 modify_text_properties (object, start, end);
1217 /* If someone called us recursively as a side effect of 1227 /* If someone called us recursively as a side effect of
1218 modify_region, and changed the intervals behind our back 1228 modify_text_properties, and changed the intervals behind our back
1219 (could happen if lock_file, called by prepare_to_modify_buffer, 1229 (could happen if lock_file, called by prepare_to_modify_buffer,
1220 triggers redisplay, and that calls add-text-properties again 1230 triggers redisplay, and that calls add-text-properties again
1221 in the same buffer), we cannot continue with I, because its 1231 in the same buffer), we cannot continue with I, because its
@@ -1357,7 +1367,8 @@ into it. */)
1357 otherwise. */ 1367 otherwise. */
1358 1368
1359Lisp_Object 1369Lisp_Object
1360set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object, Lisp_Object coherent_change_p) 1370set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
1371 Lisp_Object object, Lisp_Object coherent_change_p)
1361{ 1372{
1362 register INTERVAL i; 1373 register INTERVAL i;
1363 Lisp_Object ostart, oend; 1374 Lisp_Object ostart, oend;
@@ -1403,7 +1414,7 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
1403 } 1414 }
1404 1415
1405 if (BUFFERP (object) && !NILP (coherent_change_p)) 1416 if (BUFFERP (object) && !NILP (coherent_change_p))
1406 modify_region (object, start, end); 1417 modify_text_properties (object, start, end);
1407 1418
1408 set_text_properties_1 (start, end, properties, object, i); 1419 set_text_properties_1 (start, end, properties, object, i);
1409 1420
@@ -1558,9 +1569,9 @@ Use `set-text-properties' if you want to remove all text properties. */)
1558 ptrdiff_t prev_total_length = TOTAL_LENGTH (i); 1569 ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
1559 ptrdiff_t prev_pos = i->position; 1570 ptrdiff_t prev_pos = i->position;
1560 1571
1561 modify_region (object, start, end); 1572 modify_text_properties (object, start, end);
1562 /* If someone called us recursively as a side effect of 1573 /* If someone called us recursively as a side effect of
1563 modify_region, and changed the intervals behind our back 1574 modify_text_properties, and changed the intervals behind our back
1564 (could happen if lock_file, called by prepare_to_modify_buffer, 1575 (could happen if lock_file, called by prepare_to_modify_buffer,
1565 triggers redisplay, and that calls add-text-properties again 1576 triggers redisplay, and that calls add-text-properties again
1566 in the same buffer), we cannot continue with I, because its 1577 in the same buffer), we cannot continue with I, because its
@@ -1667,9 +1678,9 @@ Return t if any property was actually removed, nil otherwise. */)
1667 1678
1668 /* We are at the beginning of an interval, with len to scan. 1679 /* We are at the beginning of an interval, with len to scan.
1669 The flag `modified' records if changes have been made. 1680 The flag `modified' records if changes have been made.
1670 When object is a buffer, we must call modify_region before changes are 1681 When object is a buffer, we must call modify_text_properties
1671 made and signal_after_change when we are done. 1682 before changes are made and signal_after_change when we are done.
1672 We call modify_region before calling remove_properties if modified == 0, 1683 We call modify_text_properties before calling remove_properties if modified == 0,
1673 and we call signal_after_change before returning if modified != 0. */ 1684 and we call signal_after_change before returning if modified != 0. */
1674 for (;;) 1685 for (;;)
1675 { 1686 {
@@ -1693,7 +1704,7 @@ Return t if any property was actually removed, nil otherwise. */)
1693 else if (LENGTH (i) == len) 1704 else if (LENGTH (i) == len)
1694 { 1705 {
1695 if (!modified && BUFFERP (object)) 1706 if (!modified && BUFFERP (object))
1696 modify_region (object, start, end); 1707 modify_text_properties (object, start, end);
1697 remove_properties (Qnil, properties, i, object); 1708 remove_properties (Qnil, properties, i, object);
1698 if (BUFFERP (object)) 1709 if (BUFFERP (object))
1699 signal_after_change (XINT (start), XINT (end) - XINT (start), 1710 signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1706,7 +1717,7 @@ Return t if any property was actually removed, nil otherwise. */)
1706 i = split_interval_left (i, len); 1717 i = split_interval_left (i, len);
1707 copy_properties (unchanged, i); 1718 copy_properties (unchanged, i);
1708 if (!modified && BUFFERP (object)) 1719 if (!modified && BUFFERP (object))
1709 modify_region (object, start, end); 1720 modify_text_properties (object, start, end);
1710 remove_properties (Qnil, properties, i, object); 1721 remove_properties (Qnil, properties, i, object);
1711 if (BUFFERP (object)) 1722 if (BUFFERP (object))
1712 signal_after_change (XINT (start), XINT (end) - XINT (start), 1723 signal_after_change (XINT (start), XINT (end) - XINT (start),
@@ -1717,7 +1728,7 @@ Return t if any property was actually removed, nil otherwise. */)
1717 if (interval_has_some_properties_list (properties, i)) 1728 if (interval_has_some_properties_list (properties, i))
1718 { 1729 {
1719 if (!modified && BUFFERP (object)) 1730 if (!modified && BUFFERP (object))
1720 modify_region (object, start, end); 1731 modify_text_properties (object, start, end);
1721 remove_properties (Qnil, properties, i, object); 1732 remove_properties (Qnil, properties, i, object);
1722 modified = 1; 1733 modified = 1;
1723 } 1734 }
diff --git a/src/w16select.c b/src/w16select.c
index 3bcc663e565..864757b3e61 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -452,11 +452,7 @@ DEFUN ("w16-set-clipboard-data", Fw16_set_clipboard_data, Sw16_set_clipboard_dat
452 452
453 CHECK_STRING (string); 453 CHECK_STRING (string);
454 454
455 if (NILP (frame)) 455 if (!FRAME_MSDOS_P (decode_live_frame (frame)))
456 frame = Fselected_frame ();
457
458 CHECK_LIVE_FRAME (frame);
459 if ( !FRAME_MSDOS_P (XFRAME (frame)))
460 goto done; 456 goto done;
461 457
462 block_input (); 458 block_input ();
@@ -558,11 +554,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
558 Lisp_Object ret = Qnil; 554 Lisp_Object ret = Qnil;
559 int require_decoding = 0; 555 int require_decoding = 0;
560 556
561 if (NILP (frame)) 557 if (!FRAME_MSDOS_P (decode_live_frame (frame)))
562 frame = Fselected_frame ();
563
564 CHECK_LIVE_FRAME (frame);
565 if ( !FRAME_MSDOS_P (XFRAME (frame)))
566 goto done; 558 goto done;
567 559
568 block_input (); 560 block_input ();
diff --git a/src/w32.c b/src/w32.c
index fb2d7c75972..21dbf49ed7c 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -47,7 +47,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
47#undef fopen 47#undef fopen
48#undef link 48#undef link
49#undef mkdir 49#undef mkdir
50#undef mktemp
51#undef open 50#undef open
52#undef rename 51#undef rename
53#undef rmdir 52#undef rmdir
@@ -90,6 +89,21 @@ typedef struct _MEMORY_STATUS_EX {
90 DWORDLONG ullAvailExtendedVirtual; 89 DWORDLONG ullAvailExtendedVirtual;
91} MEMORY_STATUS_EX,*LPMEMORY_STATUS_EX; 90} MEMORY_STATUS_EX,*LPMEMORY_STATUS_EX;
92 91
92/* These are here so that GDB would know about these data types. This
93 allows to attach GDB to Emacs when a fatal exception is triggered
94 and Windows pops up the "application needs to be closed" dialog.
95 At that point, _gnu_exception_handler, the top-level exception
96 handler installed by the MinGW startup code, is somewhere on the
97 call-stack of the main thread, so going to that call frame and
98 looking at the argument to _gnu_exception_handler, which is a
99 PEXCEPTION_POINTERS pointer, can reveal the exception code
100 (excptr->ExceptionRecord->ExceptionCode) and the address where the
101 exception happened (excptr->ExceptionRecord->ExceptionAddress), as
102 well as some additional information specific to the exception. */
103PEXCEPTION_POINTERS excptr;
104PEXCEPTION_RECORD excprec;
105PCONTEXT ctxrec;
106
93#include <lmcons.h> 107#include <lmcons.h>
94#include <shlobj.h> 108#include <shlobj.h>
95 109
@@ -3414,25 +3428,46 @@ sys_mkdir (const char * path)
3414 return _mkdir (map_w32_filename (path, NULL)); 3428 return _mkdir (map_w32_filename (path, NULL));
3415} 3429}
3416 3430
3417/* Because of long name mapping issues, we need to implement this 3431int
3418 ourselves. Also, MSVC's _mktemp returns NULL when it can't generate 3432sys_open (const char * path, int oflag, int mode)
3419 a unique name, instead of setting the input template to an empty 3433{
3420 string. 3434 const char* mpath = map_w32_filename (path, NULL);
3435 int res = -1;
3421 3436
3422 Standard algorithm seems to be use pid or tid with a letter on the 3437 /* If possible, try to open file without _O_CREAT, to be able to
3423 front (in place of the 6 X's) and cycle through the letters to find a 3438 write to existing hidden and system files. Force all file
3424 unique name. We extend that to allow any reasonable character as the 3439 handles to be non-inheritable. */
3425 first of the 6 X's. */ 3440 if ((oflag & (_O_CREAT | _O_EXCL)) != (_O_CREAT | _O_EXCL))
3426char * 3441 res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
3427sys_mktemp (char * template) 3442 if (res < 0)
3443 res = _open (mpath, oflag | _O_NOINHERIT, mode);
3444
3445 return res;
3446}
3447
3448/* Implementation of mkostemp for MS-Windows, to avoid race conditions
3449 when using mktemp.
3450
3451 Standard algorithm for generating a temporary file name seems to be
3452 use pid or tid with a letter on the front (in place of the 6 X's)
3453 and cycle through the letters to find a unique name. We extend
3454 that to allow any reasonable character as the first of the 6 X's,
3455 so that the number of simultaneously used temporary files will be
3456 greater. */
3457
3458int
3459mkostemp (char * template, int flags)
3428{ 3460{
3429 char * p; 3461 char * p;
3430 int i; 3462 int i, fd = -1;
3431 unsigned uid = GetCurrentThreadId (); 3463 unsigned uid = GetCurrentThreadId ();
3464 int save_errno = errno;
3432 static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#"; 3465 static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
3433 3466
3467 errno = EINVAL;
3434 if (template == NULL) 3468 if (template == NULL)
3435 return NULL; 3469 return -1;
3470
3436 p = template + strlen (template); 3471 p = template + strlen (template);
3437 i = 5; 3472 i = 5;
3438 /* replace up to the last 5 X's with uid in decimal */ 3473 /* replace up to the last 5 X's with uid in decimal */
@@ -3447,38 +3482,22 @@ sys_mktemp (char * template)
3447 i = 0; 3482 i = 0;
3448 do 3483 do
3449 { 3484 {
3450 int save_errno = errno;
3451 p[0] = first_char[i]; 3485 p[0] = first_char[i];
3452 if (faccessat (AT_FDCWD, template, F_OK, AT_EACCESS) < 0) 3486 if ((fd = sys_open (template,
3487 flags | _O_CREAT | _O_EXCL | _O_RDWR,
3488 S_IRUSR | S_IWUSR)) >= 0
3489 || errno != EEXIST)
3453 { 3490 {
3454 errno = save_errno; 3491 if (fd >= 0)
3455 return template; 3492 errno = save_errno;
3493 return fd;
3456 } 3494 }
3457 } 3495 }
3458 while (++i < sizeof (first_char)); 3496 while (++i < sizeof (first_char));
3459 } 3497 }
3460 3498
3461 /* Template is badly formed or else we can't generate a unique name, 3499 /* Template is badly formed or else we can't generate a unique name. */
3462 so return empty string */ 3500 return -1;
3463 template[0] = 0;
3464 return template;
3465}
3466
3467int
3468sys_open (const char * path, int oflag, int mode)
3469{
3470 const char* mpath = map_w32_filename (path, NULL);
3471 int res = -1;
3472
3473 /* If possible, try to open file without _O_CREAT, to be able to
3474 write to existing hidden and system files. Force all file
3475 handles to be non-inheritable. */
3476 if ((oflag & (_O_CREAT | _O_EXCL)) != (_O_CREAT | _O_EXCL))
3477 res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
3478 if (res < 0)
3479 res = _open (mpath, oflag | _O_NOINHERIT, mode);
3480
3481 return res;
3482} 3501}
3483 3502
3484int 3503int
@@ -5750,8 +5769,8 @@ system_process_attributes (Lisp_Object pid)
5750 { 5769 {
5751 /* Decode the command name from locale-specific 5770 /* Decode the command name from locale-specific
5752 encoding. */ 5771 encoding. */
5753 cmd_str = make_unibyte_string (pe.szExeFile, 5772 cmd_str = build_unibyte_string (pe.szExeFile);
5754 strlen (pe.szExeFile)); 5773
5755 decoded_cmd = 5774 decoded_cmd =
5756 code_convert_string_norecord (cmd_str, 5775 code_convert_string_norecord (cmd_str,
5757 Vlocale_coding_system, 0); 5776 Vlocale_coding_system, 0);
diff --git a/src/w32fns.c b/src/w32fns.c
index 675b716f3b0..b8c445a3a36 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -285,7 +285,7 @@ check_x_display_info (Lisp_Object frame)
285 return x_display_info_for_name (frame); 285 return x_display_info_for_name (frame);
286 else 286 else
287 { 287 {
288 FRAME_PTR f; 288 struct frame *f;
289 289
290 CHECK_LIVE_FRAME (frame); 290 CHECK_LIVE_FRAME (frame);
291 f = XFRAME (frame); 291 f = XFRAME (frame);
@@ -344,7 +344,7 @@ void x_set_tool_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
344 not Emacs's own window. */ 344 not Emacs's own window. */
345 345
346void 346void
347x_real_positions (FRAME_PTR f, int *xptr, int *yptr) 347x_real_positions (struct frame *f, int *xptr, int *yptr)
348{ 348{
349 POINT pt; 349 POINT pt;
350 RECT rect; 350 RECT rect;
@@ -1019,7 +1019,7 @@ x_to_w32_color (const char * colorname)
1019} 1019}
1020 1020
1021void 1021void
1022w32_regenerate_palette (FRAME_PTR f) 1022w32_regenerate_palette (struct frame *f)
1023{ 1023{
1024 struct w32_palette_entry * list; 1024 struct w32_palette_entry * list;
1025 LOGPALETTE * log_palette; 1025 LOGPALETTE * log_palette;
@@ -1069,7 +1069,7 @@ w32_regenerate_palette (FRAME_PTR f)
1069#if 0 1069#if 0
1070/* Keep these around in case we ever want to track color usage. */ 1070/* Keep these around in case we ever want to track color usage. */
1071void 1071void
1072w32_map_color (FRAME_PTR f, COLORREF color) 1072w32_map_color (struct frame *f, COLORREF color)
1073{ 1073{
1074 struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; 1074 struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list;
1075 1075
@@ -1100,7 +1100,7 @@ w32_map_color (FRAME_PTR f, COLORREF color)
1100} 1100}
1101 1101
1102void 1102void
1103w32_unmap_color (FRAME_PTR f, COLORREF color) 1103w32_unmap_color (struct frame *f, COLORREF color)
1104{ 1104{
1105 struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list; 1105 struct w32_palette_entry * list = FRAME_W32_DISPLAY_INFO (f)->color_list;
1106 struct w32_palette_entry **prev = &FRAME_W32_DISPLAY_INFO (f)->color_list; 1106 struct w32_palette_entry **prev = &FRAME_W32_DISPLAY_INFO (f)->color_list;
@@ -1153,7 +1153,7 @@ gamma_correct (struct frame *f, COLORREF *color)
1153 If ALLOC is nonzero, allocate a new colormap cell. */ 1153 If ALLOC is nonzero, allocate a new colormap cell. */
1154 1154
1155int 1155int
1156w32_defined_color (FRAME_PTR f, const char *color, XColor *color_def, int alloc) 1156w32_defined_color (struct frame *f, const char *color, XColor *color_def, int alloc)
1157{ 1157{
1158 register Lisp_Object tem; 1158 register Lisp_Object tem;
1159 COLORREF w32_color_ref; 1159 COLORREF w32_color_ref;
@@ -1224,7 +1224,7 @@ w32_defined_color (FRAME_PTR f, const char *color, XColor *color_def, int alloc)
1224 ARG says. */ 1224 ARG says. */
1225 1225
1226int 1226int
1227x_decode_color (FRAME_PTR f, Lisp_Object arg, int def) 1227x_decode_color (struct frame *f, Lisp_Object arg, int def)
1228{ 1228{
1229 XColor cdef; 1229 XColor cdef;
1230 1230
@@ -1525,14 +1525,11 @@ x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1525 1525
1526 1526
1527void 1527void
1528x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1528x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1529{ 1529{
1530 set_frame_cursor_types (f, arg); 1530 set_frame_cursor_types (f, arg);
1531
1532 /* Make sure the cursor gets redrawn. */
1533 cursor_type_changed = 1;
1534} 1531}
1535 1532
1536void 1533void
1537x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 1534x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1538{ 1535{
@@ -1787,7 +1784,7 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
1787 specified a name for the frame; the name will override any set by the 1784 specified a name for the frame; the name will override any set by the
1788 redisplay code. */ 1785 redisplay code. */
1789void 1786void
1790x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1787x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1791{ 1788{
1792 x_set_name (f, arg, 1); 1789 x_set_name (f, arg, 1);
1793} 1790}
@@ -1796,7 +1793,7 @@ x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
1796 name; names set this way will never override names set by the user's 1793 name; names set this way will never override names set by the user's
1797 lisp code. */ 1794 lisp code. */
1798void 1795void
1799x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1796x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1800{ 1797{
1801 x_set_name (f, arg, 0); 1798 x_set_name (f, arg, 0);
1802} 1799}
@@ -3213,6 +3210,8 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3213 described by W was deleted, as indicated by its buffer 3210 described by W was deleted, as indicated by its buffer
3214 field being reset to nil. */ 3211 field being reset to nil. */
3215 f = x_window_to_frame (dpyinfo, hwnd); 3212 f = x_window_to_frame (dpyinfo, hwnd);
3213 if (!(f && FRAME_LIVE_P (f)))
3214 break;
3216 w = XWINDOW (FRAME_SELECTED_WINDOW (f)); 3215 w = XWINDOW (FRAME_SELECTED_WINDOW (f));
3217 /* Punt if someone changed the frame's selected window 3216 /* Punt if someone changed the frame's selected window
3218 behind our back. */ 3217 behind our back. */
@@ -4122,12 +4121,7 @@ w32_window (struct frame *f, long window_prompting, int minibuffer_only)
4122 for the window manager, so GC relocation won't bother it. 4121 for the window manager, so GC relocation won't bother it.
4123 4122
4124 Elsewhere we specify the window name for the window manager. */ 4123 Elsewhere we specify the window name for the window manager. */
4125 4124 f->namebuf = xstrdup (SSDATA (Vx_resource_name));
4126 {
4127 char *str = SSDATA (Vx_resource_name);
4128 f->namebuf = xmalloc (strlen (str) + 1);
4129 strcpy (f->namebuf, str);
4130 }
4131 4125
4132 my_create_window (f); 4126 my_create_window (f);
4133 4127
@@ -4180,9 +4174,6 @@ x_icon (struct frame *f, Lisp_Object parms)
4180 4174
4181 block_input (); 4175 block_input ();
4182 4176
4183 if (! EQ (icon_x, Qunbound))
4184 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
4185
4186#if 0 /* TODO */ 4177#if 0 /* TODO */
4187 /* Start up iconic or window? */ 4178 /* Start up iconic or window? */
4188 x_wm_set_window_state 4179 x_wm_set_window_state
@@ -4646,7 +4637,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
4646 (Lisp_Object color, Lisp_Object frame) 4637 (Lisp_Object color, Lisp_Object frame)
4647{ 4638{
4648 XColor foo; 4639 XColor foo;
4649 FRAME_PTR f = decode_window_system_frame (frame); 4640 struct frame *f = decode_window_system_frame (frame);
4650 4641
4651 CHECK_STRING (color); 4642 CHECK_STRING (color);
4652 4643
@@ -4661,7 +4652,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
4661 (Lisp_Object color, Lisp_Object frame) 4652 (Lisp_Object color, Lisp_Object frame)
4662{ 4653{
4663 XColor foo; 4654 XColor foo;
4664 FRAME_PTR f = decode_window_system_frame (frame); 4655 struct frame *f = decode_window_system_frame (frame);
4665 4656
4666 CHECK_STRING (color); 4657 CHECK_STRING (color);
4667 4658
@@ -4993,8 +4984,8 @@ w32_display_monitor_attributes_list (void)
4993 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), 4984 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4994 attributes); 4985 attributes);
4995 4986
4996 name = DECODE_SYSTEM (make_unibyte_string (mi.szDevice, 4987 name = DECODE_SYSTEM (build_unibyte_string (mi.szDevice));
4997 strlen (mi.szDevice))); 4988
4998 attributes = Fcons (Fcons (Qname, name), attributes); 4989 attributes = Fcons (Fcons (Qname, name), attributes);
4999 4990
5000 attributes = Fcons (Fcons (Qmm_size, list2i (width_mm, height_mm)), 4991 attributes = Fcons (Fcons (Qmm_size, list2i (width_mm, height_mm)),
@@ -5137,19 +5128,6 @@ SOUND is nil to use the normal beep. */)
5137 return sound; 5128 return sound;
5138} 5129}
5139 5130
5140
5141int
5142x_pixel_width (register struct frame *f)
5143{
5144 return FRAME_PIXEL_WIDTH (f);
5145}
5146
5147int
5148x_pixel_height (register struct frame *f)
5149{
5150 return FRAME_PIXEL_HEIGHT (f);
5151}
5152
5153int 5131int
5154x_screen_planes (register struct frame *f) 5132x_screen_planes (register struct frame *f)
5155{ 5133{
@@ -6624,7 +6602,7 @@ screen saver if defined.
6624If optional parameter FRAME is not specified, use selected frame. */) 6602If optional parameter FRAME is not specified, use selected frame. */)
6625 (Lisp_Object command, Lisp_Object frame) 6603 (Lisp_Object command, Lisp_Object frame)
6626{ 6604{
6627 FRAME_PTR f = decode_window_system_frame (frame); 6605 struct frame *f = decode_window_system_frame (frame);
6628 6606
6629 CHECK_NUMBER (command); 6607 CHECK_NUMBER (command);
6630 6608
diff --git a/src/w32font.c b/src/w32font.c
index 105daa06365..4a97fd90a4e 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -99,7 +99,7 @@ static Lisp_Object Qw32_charset_thai, Qw32_charset_johab, Qw32_charset_mac;
99/* Font spacing symbols - defined in font.c. */ 99/* Font spacing symbols - defined in font.c. */
100extern Lisp_Object Qc, Qp, Qm; 100extern Lisp_Object Qc, Qp, Qm;
101 101
102static void fill_in_logfont (FRAME_PTR, LOGFONT *, Lisp_Object); 102static void fill_in_logfont (struct frame *, LOGFONT *, Lisp_Object);
103 103
104static BYTE w32_antialias_type (Lisp_Object); 104static BYTE w32_antialias_type (Lisp_Object);
105static Lisp_Object lispy_antialias_type (BYTE); 105static Lisp_Object lispy_antialias_type (BYTE);
@@ -297,7 +297,7 @@ intern_font_name (char * string)
297 Return a cache of font-entities on FRAME. The cache must be a 297 Return a cache of font-entities on FRAME. The cache must be a
298 cons whose cdr part is the actual cache area. */ 298 cons whose cdr part is the actual cache area. */
299Lisp_Object 299Lisp_Object
300w32font_get_cache (FRAME_PTR f) 300w32font_get_cache (struct frame *f)
301{ 301{
302 struct w32_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 302 struct w32_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
303 303
@@ -309,9 +309,9 @@ w32font_get_cache (FRAME_PTR f)
309 is a vector of font-entities. This is the sole API that 309 is a vector of font-entities. This is the sole API that
310 allocates font-entities. */ 310 allocates font-entities. */
311static Lisp_Object 311static Lisp_Object
312w32font_list (Lisp_Object frame, Lisp_Object font_spec) 312w32font_list (struct frame *f, Lisp_Object font_spec)
313{ 313{
314 Lisp_Object fonts = w32font_list_internal (frame, font_spec, 0); 314 Lisp_Object fonts = w32font_list_internal (f, font_spec, 0);
315 FONT_ADD_LOG ("w32font-list", font_spec, fonts); 315 FONT_ADD_LOG ("w32font-list", font_spec, fonts);
316 return fonts; 316 return fonts;
317} 317}
@@ -321,9 +321,9 @@ w32font_list (Lisp_Object frame, Lisp_Object font_spec)
321 FRAME. The closeness is determined by the font backend, thus 321 FRAME. The closeness is determined by the font backend, thus
322 `face-font-selection-order' is ignored here. */ 322 `face-font-selection-order' is ignored here. */
323static Lisp_Object 323static Lisp_Object
324w32font_match (Lisp_Object frame, Lisp_Object font_spec) 324w32font_match (struct frame *f, Lisp_Object font_spec)
325{ 325{
326 Lisp_Object entity = w32font_match_internal (frame, font_spec, 0); 326 Lisp_Object entity = w32font_match_internal (f, font_spec, 0);
327 FONT_ADD_LOG ("w32font-match", font_spec, entity); 327 FONT_ADD_LOG ("w32font-match", font_spec, entity);
328 return entity; 328 return entity;
329} 329}
@@ -332,12 +332,11 @@ w32font_match (Lisp_Object frame, Lisp_Object font_spec)
332 List available families. The value is a list of family names 332 List available families. The value is a list of family names
333 (symbols). */ 333 (symbols). */
334static Lisp_Object 334static Lisp_Object
335w32font_list_family (Lisp_Object frame) 335w32font_list_family (struct frame *f)
336{ 336{
337 Lisp_Object list = Qnil; 337 Lisp_Object list = Qnil;
338 LOGFONT font_match_pattern; 338 LOGFONT font_match_pattern;
339 HDC dc; 339 HDC dc;
340 FRAME_PTR f = XFRAME (frame);
341 340
342 memset (&font_match_pattern, 0, sizeof (font_match_pattern)); 341 memset (&font_match_pattern, 0, sizeof (font_match_pattern));
343 font_match_pattern.lfCharSet = DEFAULT_CHARSET; 342 font_match_pattern.lfCharSet = DEFAULT_CHARSET;
@@ -356,7 +355,7 @@ w32font_list_family (Lisp_Object frame)
356 Open a font specified by FONT_ENTITY on frame F. 355 Open a font specified by FONT_ENTITY on frame F.
357 If the font is scalable, open it with PIXEL_SIZE. */ 356 If the font is scalable, open it with PIXEL_SIZE. */
358static Lisp_Object 357static Lisp_Object
359w32font_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) 358w32font_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
360{ 359{
361 Lisp_Object font_object 360 Lisp_Object font_object
362 = font_make_object (VECSIZE (struct w32font_info), 361 = font_make_object (VECSIZE (struct w32font_info),
@@ -380,7 +379,7 @@ w32font_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
380/* w32 implementation of close for font_backend. 379/* w32 implementation of close for font_backend.
381 Close FONT on frame F. */ 380 Close FONT on frame F. */
382void 381void
383w32font_close (FRAME_PTR f, struct font *font) 382w32font_close (struct frame *f, struct font *font)
384{ 383{
385 int i; 384 int i;
386 struct w32font_info *w32_font = (struct w32font_info *) font; 385 struct w32font_info *w32_font = (struct w32font_info *) font;
@@ -732,13 +731,13 @@ w32font_free_entity (Lisp_Object entity);
732 storing some data in FACE->extra. If successful, return 0. 731 storing some data in FACE->extra. If successful, return 0.
733 Otherwise, return -1. 732 Otherwise, return -1.
734static int 733static int
735w32font_prepare_face (FRAME_PTR f, struct face *face); 734w32font_prepare_face (struct frame *f, struct face *face);
736 */ 735 */
737/* w32 implementation of done_face for font backend. 736/* w32 implementation of done_face for font backend.
738 Optional. 737 Optional.
739 Done FACE for displaying characters by FACE->font on frame F. 738 Done FACE for displaying characters by FACE->font on frame F.
740static void 739static void
741w32font_done_face (FRAME_PTR f, struct face *face); */ 740w32font_done_face (struct frame *f, struct face *face); */
742 741
743/* w32 implementation of get_bitmap for font backend. 742/* w32 implementation of get_bitmap for font backend.
744 Optional. 743 Optional.
@@ -811,15 +810,14 @@ w32font_otf_drive (struct font *font, Lisp_Object features,
811 Additional parameter opentype_only restricts the returned fonts to 810 Additional parameter opentype_only restricts the returned fonts to
812 opentype fonts, which can be used with the Uniscribe backend. */ 811 opentype fonts, which can be used with the Uniscribe backend. */
813Lisp_Object 812Lisp_Object
814w32font_list_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_only) 813w32font_list_internal (struct frame *f, Lisp_Object font_spec, int opentype_only)
815{ 814{
816 struct font_callback_data match_data; 815 struct font_callback_data match_data;
817 HDC dc; 816 HDC dc;
818 FRAME_PTR f = XFRAME (frame);
819 817
820 match_data.orig_font_spec = font_spec; 818 match_data.orig_font_spec = font_spec;
821 match_data.list = Qnil; 819 match_data.list = Qnil;
822 match_data.frame = frame; 820 XSETFRAME (match_data.frame, f);
823 821
824 memset (&match_data.pattern, 0, sizeof (LOGFONT)); 822 memset (&match_data.pattern, 0, sizeof (LOGFONT));
825 fill_in_logfont (f, &match_data.pattern, font_spec); 823 fill_in_logfont (f, &match_data.pattern, font_spec);
@@ -864,14 +862,13 @@ w32font_list_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_on
864 Additional parameter opentype_only restricts the returned fonts to 862 Additional parameter opentype_only restricts the returned fonts to
865 opentype fonts, which can be used with the Uniscribe backend. */ 863 opentype fonts, which can be used with the Uniscribe backend. */
866Lisp_Object 864Lisp_Object
867w32font_match_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_only) 865w32font_match_internal (struct frame *f, Lisp_Object font_spec, int opentype_only)
868{ 866{
869 struct font_callback_data match_data; 867 struct font_callback_data match_data;
870 HDC dc; 868 HDC dc;
871 FRAME_PTR f = XFRAME (frame);
872 869
873 match_data.orig_font_spec = font_spec; 870 match_data.orig_font_spec = font_spec;
874 match_data.frame = frame; 871 XSETFRAME (match_data.frame, f);
875 match_data.list = Qnil; 872 match_data.list = Qnil;
876 873
877 memset (&match_data.pattern, 0, sizeof (LOGFONT)); 874 memset (&match_data.pattern, 0, sizeof (LOGFONT));
@@ -892,7 +889,7 @@ w32font_match_internal (Lisp_Object frame, Lisp_Object font_spec, int opentype_o
892} 889}
893 890
894int 891int
895w32font_open_internal (FRAME_PTR f, Lisp_Object font_entity, 892w32font_open_internal (struct frame *f, Lisp_Object font_entity,
896 int pixel_size, Lisp_Object font_object) 893 int pixel_size, Lisp_Object font_object)
897{ 894{
898 int len, size; 895 int len, size;
@@ -1964,7 +1961,7 @@ w32_to_fc_weight (int n)
1964 1961
1965/* Fill in all the available details of LOGFONT from FONT_SPEC. */ 1962/* Fill in all the available details of LOGFONT from FONT_SPEC. */
1966static void 1963static void
1967fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec) 1964fill_in_logfont (struct frame *f, LOGFONT *logfont, Lisp_Object font_spec)
1968{ 1965{
1969 Lisp_Object tmp, extra; 1966 Lisp_Object tmp, extra;
1970 int dpi = FRAME_RES_Y (f); 1967 int dpi = FRAME_RES_Y (f);
@@ -2114,7 +2111,7 @@ static void
2114list_all_matching_fonts (struct font_callback_data *match_data) 2111list_all_matching_fonts (struct font_callback_data *match_data)
2115{ 2112{
2116 HDC dc; 2113 HDC dc;
2117 Lisp_Object families = w32font_list_family (match_data->frame); 2114 Lisp_Object families = w32font_list_family (XFRAME (match_data->frame));
2118 struct frame *f = XFRAME (match_data->frame); 2115 struct frame *f = XFRAME (match_data->frame);
2119 2116
2120 dc = get_frame_dc (f); 2117 dc = get_frame_dc (f);
@@ -2467,7 +2464,7 @@ If EXCLUDE-PROPORTIONAL is non-nil, exclude proportional fonts
2467in the font selection dialog. */) 2464in the font selection dialog. */)
2468 (Lisp_Object frame, Lisp_Object exclude_proportional) 2465 (Lisp_Object frame, Lisp_Object exclude_proportional)
2469{ 2466{
2470 FRAME_PTR f = decode_window_system_frame (frame); 2467 struct frame *f = decode_window_system_frame (frame);
2471 CHOOSEFONT cf; 2468 CHOOSEFONT cf;
2472 LOGFONT lf; 2469 LOGFONT lf;
2473 TEXTMETRIC tm; 2470 TEXTMETRIC tm;
diff --git a/src/w32font.h b/src/w32font.h
index b4345478a22..56220860863 100644
--- a/src/w32font.h
+++ b/src/w32font.h
@@ -63,16 +63,16 @@ struct w32font_info
63 63
64#define CACHE_BLOCKSIZE 128 64#define CACHE_BLOCKSIZE 128
65 65
66Lisp_Object w32font_get_cache (FRAME_PTR fe); 66Lisp_Object w32font_get_cache (struct frame *fe);
67Lisp_Object w32font_list_internal (Lisp_Object frame, 67Lisp_Object w32font_list_internal (struct frame *f,
68 Lisp_Object font_spec, 68 Lisp_Object font_spec,
69 int opentype_only); 69 int opentype_only);
70Lisp_Object w32font_match_internal (Lisp_Object frame, 70Lisp_Object w32font_match_internal (struct frame *f,
71 Lisp_Object font_spec, 71 Lisp_Object font_spec,
72 int opentype_only); 72 int opentype_only);
73int w32font_open_internal (FRAME_PTR f, Lisp_Object font_entity, 73int w32font_open_internal (struct frame *f, Lisp_Object font_entity,
74 int pixel_size, Lisp_Object font_object); 74 int pixel_size, Lisp_Object font_object);
75void w32font_close (FRAME_PTR f, struct font *font); 75void w32font_close (struct frame *f, struct font *font);
76int w32font_has_char (Lisp_Object entity, int c); 76int w32font_has_char (Lisp_Object entity, int c);
77int w32font_text_extents (struct font *font, unsigned *code, int nglyphs, 77int w32font_text_extents (struct font *font, unsigned *code, int nglyphs,
78 struct font_metrics *metrics); 78 struct font_metrics *metrics);
diff --git a/src/w32inevt.c b/src/w32inevt.c
index 88a3f9739cd..ce36f291b00 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -103,10 +103,10 @@ fill_queue (BOOL block)
103} 103}
104 104
105/* In a generic, multi-frame world this should take a console handle 105/* In a generic, multi-frame world this should take a console handle
106 and return the frame for it 106 and return the frame for it.
107 107
108 Right now, there's only one frame so return it. */ 108 Right now, there's only one frame so return it. */
109static FRAME_PTR 109static struct frame *
110get_frame (void) 110get_frame (void)
111{ 111{
112 return SELECTED_FRAME (); 112 return SELECTED_FRAME ();
@@ -394,7 +394,7 @@ key_event (KEY_EVENT_RECORD *event, struct input_event *emacs_ev, int *isdead)
394 394
395/* Mouse position hook. */ 395/* Mouse position hook. */
396void 396void
397w32_console_mouse_position (FRAME_PTR *f, 397w32_console_mouse_position (struct frame **f,
398 int insist, 398 int insist,
399 Lisp_Object *bar_window, 399 Lisp_Object *bar_window,
400 enum scroll_bar_part *part, 400 enum scroll_bar_part *part,
@@ -461,7 +461,7 @@ do_mouse_event (MOUSE_EVENT_RECORD *event,
461 461
462 if (event->dwEventFlags == MOUSE_MOVED) 462 if (event->dwEventFlags == MOUSE_MOVED)
463 { 463 {
464 FRAME_PTR f = SELECTED_FRAME (); 464 struct frame *f = SELECTED_FRAME ();
465 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 465 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
466 int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y; 466 int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y;
467 467
@@ -555,7 +555,7 @@ do_mouse_event (MOUSE_EVENT_RECORD *event,
555static void 555static void
556resize_event (WINDOW_BUFFER_SIZE_RECORD *event) 556resize_event (WINDOW_BUFFER_SIZE_RECORD *event)
557{ 557{
558 FRAME_PTR f = get_frame (); 558 struct frame *f = get_frame ();
559 559
560 change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1, 0); 560 change_frame_size (f, event->dwSize.Y, event->dwSize.X, 0, 1, 0);
561 SET_FRAME_GARBAGED (f); 561 SET_FRAME_GARBAGED (f);
@@ -565,7 +565,7 @@ static void
565maybe_generate_resize_event (void) 565maybe_generate_resize_event (void)
566{ 566{
567 CONSOLE_SCREEN_BUFFER_INFO info; 567 CONSOLE_SCREEN_BUFFER_INFO info;
568 FRAME_PTR f = get_frame (); 568 struct frame *f = get_frame ();
569 569
570 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info); 570 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
571 571
diff --git a/src/w32inevt.h b/src/w32inevt.h
index 8a7e4fed06a..070d1ad7b03 100644
--- a/src/w32inevt.h
+++ b/src/w32inevt.h
@@ -23,7 +23,7 @@ extern int w32_console_unicode_input;
23 23
24extern int w32_console_read_socket (struct terminal *term, 24extern int w32_console_read_socket (struct terminal *term,
25 struct input_event *hold_quit); 25 struct input_event *hold_quit);
26extern void w32_console_mouse_position (FRAME_PTR *f, int insist, 26extern void w32_console_mouse_position (struct frame **f, int insist,
27 Lisp_Object *bar_window, 27 Lisp_Object *bar_window,
28 enum scroll_bar_part *part, 28 enum scroll_bar_part *part,
29 Lisp_Object *x, Lisp_Object *y, 29 Lisp_Object *x, Lisp_Object *y,
diff --git a/src/w32menu.c b/src/w32menu.c
index 346402b7c6b..34020fa61d2 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -100,13 +100,13 @@ MessageBoxW_Proc unicode_message_box = NULL;
100 100
101Lisp_Object Qdebug_on_next_call; 101Lisp_Object Qdebug_on_next_call;
102 102
103void set_frame_menubar (FRAME_PTR, bool, bool); 103void set_frame_menubar (struct frame *, bool, bool);
104 104
105#ifdef HAVE_DIALOGS 105#ifdef HAVE_DIALOGS
106static Lisp_Object w32_dialog_show (FRAME_PTR, int, Lisp_Object, char**); 106static Lisp_Object w32_dialog_show (struct frame *, int, Lisp_Object, char**);
107#else 107#else
108static int is_simple_dialog (Lisp_Object); 108static int is_simple_dialog (Lisp_Object);
109static Lisp_Object simple_dialog_show (FRAME_PTR, Lisp_Object, Lisp_Object); 109static Lisp_Object simple_dialog_show (struct frame *, Lisp_Object, Lisp_Object);
110#endif 110#endif
111 111
112static void utf8to16 (unsigned char *, int, WCHAR *); 112static void utf8to16 (unsigned char *, int, WCHAR *);
@@ -137,7 +137,7 @@ If HEADER is non-nil, the frame title for the box is "Information",
137otherwise it is "Question". */) 137otherwise it is "Question". */)
138 (Lisp_Object position, Lisp_Object contents, Lisp_Object header) 138 (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
139{ 139{
140 FRAME_PTR f = NULL; 140 struct frame *f = NULL;
141 Lisp_Object window; 141 Lisp_Object window;
142 142
143 /* Decode the first argument: find the window or frame to use. */ 143 /* Decode the first argument: find the window or frame to use. */
@@ -147,7 +147,7 @@ otherwise it is "Question". */)
147 { 147 {
148#if 0 /* Using the frame the mouse is on may not be right. */ 148#if 0 /* Using the frame the mouse is on may not be right. */
149 /* Use the mouse's current position. */ 149 /* Use the mouse's current position. */
150 FRAME_PTR new_f = SELECTED_FRAME (); 150 struct frame *new_f = SELECTED_FRAME ();
151 Lisp_Object bar_window; 151 Lisp_Object bar_window;
152 enum scroll_bar_part part; 152 enum scroll_bar_part part;
153 Time time; 153 Time time;
@@ -206,8 +206,8 @@ otherwise it is "Question". */)
206 in the middle of frame F. */ 206 in the middle of frame F. */
207 Lisp_Object x, y, frame, newpos; 207 Lisp_Object x, y, frame, newpos;
208 XSETFRAME (frame, f); 208 XSETFRAME (frame, f);
209 XSETINT (x, x_pixel_width (f) / 2); 209 XSETINT (x, FRAME_PIXEL_WIDTH (f) / 2);
210 XSETINT (y, x_pixel_height (f) / 2); 210 XSETINT (y, FRAME_PIXEL_HEIGHT (f) / 2);
211 newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil)); 211 newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil));
212 return Fx_popup_menu (newpos, 212 return Fx_popup_menu (newpos,
213 Fcons (Fcar (contents), Fcons (contents, Qnil))); 213 Fcons (Fcar (contents), Fcons (contents, Qnil)));
@@ -252,7 +252,7 @@ otherwise it is "Question". */)
252 This way we can safely execute Lisp code. */ 252 This way we can safely execute Lisp code. */
253 253
254void 254void
255x_activate_menubar (FRAME_PTR f) 255x_activate_menubar (struct frame *f)
256{ 256{
257 set_frame_menubar (f, 0, 1); 257 set_frame_menubar (f, 0, 1);
258 258
@@ -269,7 +269,7 @@ x_activate_menubar (FRAME_PTR f)
269 and put the appropriate events into the keyboard buffer. */ 269 and put the appropriate events into the keyboard buffer. */
270 270
271void 271void
272menubar_selection_callback (FRAME_PTR f, void * client_data) 272menubar_selection_callback (struct frame *f, void * client_data)
273{ 273{
274 Lisp_Object prefix, entry; 274 Lisp_Object prefix, entry;
275 Lisp_Object vector; 275 Lisp_Object vector;
@@ -361,7 +361,7 @@ menubar_selection_callback (FRAME_PTR f, void * client_data)
361 it is set the first time this is called, from initialize_frame_menubar. */ 361 it is set the first time this is called, from initialize_frame_menubar. */
362 362
363void 363void
364set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p) 364set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
365{ 365{
366 HMENU menubar_widget = f->output_data.w32->menubar_widget; 366 HMENU menubar_widget = f->output_data.w32->menubar_widget;
367 Lisp_Object items; 367 Lisp_Object items;
@@ -613,7 +613,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
613 is visible. */ 613 is visible. */
614 614
615void 615void
616initialize_frame_menubar (FRAME_PTR f) 616initialize_frame_menubar (struct frame *f)
617{ 617{
618 /* This function is called before the first chance to redisplay 618 /* This function is called before the first chance to redisplay
619 the frame. It has to be, so the frame will have the right size. */ 619 the frame. It has to be, so the frame will have the right size. */
@@ -625,7 +625,7 @@ initialize_frame_menubar (FRAME_PTR f)
625 This is used when deleting a frame, and when turning off the menu bar. */ 625 This is used when deleting a frame, and when turning off the menu bar. */
626 626
627void 627void
628free_frame_menubar (FRAME_PTR f) 628free_frame_menubar (struct frame *f)
629{ 629{
630 block_input (); 630 block_input ();
631 631
@@ -656,7 +656,7 @@ free_frame_menubar (FRAME_PTR f)
656 (We return nil on failure, but the value doesn't actually matter.) */ 656 (We return nil on failure, but the value doesn't actually matter.) */
657 657
658Lisp_Object 658Lisp_Object
659w32_menu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, 659w32_menu_show (struct frame *f, int x, int y, int for_click, int keymaps,
660 Lisp_Object title, const char **error) 660 Lisp_Object title, const char **error)
661{ 661{
662 int i; 662 int i;
@@ -983,7 +983,7 @@ static char * button_names [] = {
983 "button6", "button7", "button8", "button9", "button10" }; 983 "button6", "button7", "button8", "button9", "button10" };
984 984
985static Lisp_Object 985static Lisp_Object
986w32_dialog_show (FRAME_PTR f, int keymaps, 986w32_dialog_show (struct frame *f, int keymaps,
987 Lisp_Object title, Lisp_Object header, 987 Lisp_Object title, Lisp_Object header,
988 char **error) 988 char **error)
989{ 989{
@@ -1219,7 +1219,7 @@ is_simple_dialog (Lisp_Object contents)
1219} 1219}
1220 1220
1221static Lisp_Object 1221static Lisp_Object
1222simple_dialog_show (FRAME_PTR f, Lisp_Object contents, Lisp_Object header) 1222simple_dialog_show (struct frame *f, Lisp_Object contents, Lisp_Object header)
1223{ 1223{
1224 int answer; 1224 int answer;
1225 UINT type; 1225 UINT type;
@@ -1699,7 +1699,7 @@ DEFUN ("menu-or-popup-active-p", Fmenu_or_popup_active_p, Smenu_or_popup_active_
1699 (void) 1699 (void)
1700{ 1700{
1701#ifdef HAVE_MENUS 1701#ifdef HAVE_MENUS
1702 FRAME_PTR f; 1702 struct frame *f;
1703 f = SELECTED_FRAME (); 1703 f = SELECTED_FRAME ();
1704 return (f->output_data.w32->menubar_active > 0) ? Qt : Qnil; 1704 return (f->output_data.w32->menubar_active > 0) ? Qt : Qnil;
1705#else 1705#else
diff --git a/src/w32notify.c b/src/w32notify.c
index 95ab298f2d3..a48a83daf53 100644
--- a/src/w32notify.c
+++ b/src/w32notify.c
@@ -129,7 +129,7 @@ send_notifications (BYTE *info, DWORD info_size, void *desc,
129 volatile int *terminate) 129 volatile int *terminate)
130{ 130{
131 int done = 0; 131 int done = 0;
132 FRAME_PTR f = SELECTED_FRAME (); 132 struct frame *f = SELECTED_FRAME ();
133 133
134 /* A single buffer is used to communicate all notifications to the 134 /* A single buffer is used to communicate all notifications to the
135 main thread. Since both the main thread and several watcher 135 main thread. Since both the main thread and several watcher
diff --git a/src/w32term.c b/src/w32term.c
index 0b22fd178e4..7d51850559b 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -181,7 +181,7 @@ int w32_keyboard_codepage;
181 181
182/* Where the mouse was last time we reported a mouse event. */ 182/* Where the mouse was last time we reported a mouse event. */
183static RECT last_mouse_glyph; 183static RECT last_mouse_glyph;
184static FRAME_PTR last_mouse_glyph_frame; 184static struct frame *last_mouse_glyph_frame;
185 185
186/* The scroll bar in which the last motion event occurred. 186/* The scroll bar in which the last motion event occurred.
187 187
@@ -249,7 +249,7 @@ static void my_set_focus (struct frame *, HWND);
249#endif 249#endif
250static void my_set_foreground_window (HWND); 250static void my_set_foreground_window (HWND);
251static void my_destroy_window (struct frame *, HWND); 251static void my_destroy_window (struct frame *, HWND);
252static void w32fullscreen_hook (FRAME_PTR); 252static void w32fullscreen_hook (struct frame *);
253 253
254#ifdef GLYPH_DEBUG 254#ifdef GLYPH_DEBUG
255static void x_check_font (struct frame *, struct font *); 255static void x_check_font (struct frame *, struct font *);
@@ -450,7 +450,7 @@ w32_draw_rectangle (HDC hdc, XGCValues *gc, int x, int y,
450 450
451/* Draw a filled rectangle at the specified position. */ 451/* Draw a filled rectangle at the specified position. */
452void 452void
453w32_fill_rect (FRAME_PTR f, HDC hdc, COLORREF pix, RECT *lprect) 453w32_fill_rect (struct frame *f, HDC hdc, COLORREF pix, RECT *lprect)
454{ 454{
455 HBRUSH hb; 455 HBRUSH hb;
456 456
@@ -460,7 +460,7 @@ w32_fill_rect (FRAME_PTR f, HDC hdc, COLORREF pix, RECT *lprect)
460} 460}
461 461
462void 462void
463w32_clear_window (FRAME_PTR f) 463w32_clear_window (struct frame *f)
464{ 464{
465 RECT rect; 465 RECT rect;
466 HDC hdc = get_frame_dc (f); 466 HDC hdc = get_frame_dc (f);
@@ -577,8 +577,7 @@ x_update_begin (struct frame *f)
577} 577}
578 578
579 579
580/* Start update of window W. Set the global variable updated_window 580/* Start update of window W. Set output_cursor to the cursor
581 to the window being updated and set output_cursor to the cursor
582 position of W. */ 581 position of W. */
583 582
584static void 583static void
@@ -593,7 +592,6 @@ x_update_window_begin (struct window *w)
593 SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0); 592 SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0);
594 } 593 }
595 594
596 updated_window = w;
597 set_output_cursor (&w->cursor); 595 set_output_cursor (&w->cursor);
598 596
599 block_input (); 597 block_input ();
@@ -664,7 +662,7 @@ w32_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
664} 662}
665 663
666 664
667/* End update of window W (which is equal to updated_window). 665/* End update of window W.
668 666
669 Draw vertical borders between horizontally adjacent windows, and 667 Draw vertical borders between horizontally adjacent windows, and
670 display W's cursor if CURSOR_ON_P is non-zero. 668 display W's cursor if CURSOR_ON_P is non-zero.
@@ -714,8 +712,6 @@ x_update_window_end (struct window *w, int cursor_on_p,
714 { 712 {
715 SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0); 713 SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0);
716 } 714 }
717
718 updated_window = NULL;
719} 715}
720 716
721 717
@@ -733,9 +729,8 @@ x_update_end (struct frame *f)
733} 729}
734 730
735 731
736/* This function is called from various places in xdisp.c whenever a 732/* This function is called from various places in xdisp.c
737 complete update has been performed. The global variable 733 whenever a complete update has been performed. */
738 updated_window is not available here. */
739 734
740static void 735static void
741w32_frame_up_to_date (struct frame *f) 736w32_frame_up_to_date (struct frame *f)
@@ -747,15 +742,13 @@ w32_frame_up_to_date (struct frame *f)
747 742
748/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay 743/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
749 arrow bitmaps, or clear the fringes if no bitmaps are required 744 arrow bitmaps, or clear the fringes if no bitmaps are required
750 before DESIRED_ROW is made current. The window being updated is 745 before DESIRED_ROW is made current. This function is called from
751 found in updated_window. This function is called from
752 update_window_line only if it is known that there are differences 746 update_window_line only if it is known that there are differences
753 between bitmaps to be drawn between current row and DESIRED_ROW. */ 747 between bitmaps to be drawn between current row and DESIRED_ROW. */
754 748
755static void 749static void
756x_after_update_window_line (struct glyph_row *desired_row) 750x_after_update_window_line (struct window *w, struct glyph_row *desired_row)
757{ 751{
758 struct window *w = updated_window;
759 struct frame *f; 752 struct frame *f;
760 int width, height; 753 int width, height;
761 754
@@ -766,7 +759,7 @@ x_after_update_window_line (struct glyph_row *desired_row)
766 759
767 /* When a window has disappeared, make sure that no rest of 760 /* When a window has disappeared, make sure that no rest of
768 full-width rows stays visible in the internal border. Could 761 full-width rows stays visible in the internal border. Could
769 check here if updated_window is the leftmost/rightmost window, 762 check here if updated window is the leftmost/rightmost window,
770 but I guess it's not worth doing since vertically split windows 763 but I guess it's not worth doing since vertically split windows
771 are almost never used, internal border is rarely set, and the 764 are almost never used, internal border is rarely set, and the
772 overhead is very small. */ 765 overhead is very small. */
@@ -2360,7 +2353,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
2360static void 2353static void
2361x_draw_glyph_string (struct glyph_string *s) 2354x_draw_glyph_string (struct glyph_string *s)
2362{ 2355{
2363 int relief_drawn_p = 0; 2356 bool relief_drawn_p = 0;
2364 2357
2365 /* If S draws into the background of its successor, draw the 2358 /* If S draws into the background of its successor, draw the
2366 background of the successor first so that S can draw into it. 2359 background of the successor first so that S can draw into it.
@@ -2806,7 +2799,6 @@ x_scroll_run (struct window *w, struct run *run)
2806 block_input (); 2799 block_input ();
2807 2800
2808 /* Cursor off. Will be switched on again in x_update_window_end. */ 2801 /* Cursor off. Will be switched on again in x_update_window_end. */
2809 updated_window = w;
2810 x_clear_cursor (w); 2802 x_clear_cursor (w);
2811 2803
2812 { 2804 {
@@ -3370,7 +3362,7 @@ static MSG last_mouse_motion_event;
3370static Lisp_Object last_mouse_motion_frame; 3362static Lisp_Object last_mouse_motion_frame;
3371 3363
3372static int 3364static int
3373note_mouse_movement (FRAME_PTR frame, MSG *msg) 3365note_mouse_movement (struct frame *frame, MSG *msg)
3374{ 3366{
3375 int mouse_x = LOWORD (msg->lParam); 3367 int mouse_x = LOWORD (msg->lParam);
3376 int mouse_y = HIWORD (msg->lParam); 3368 int mouse_y = HIWORD (msg->lParam);
@@ -3419,7 +3411,7 @@ note_mouse_movement (FRAME_PTR frame, MSG *msg)
3419 ************************************************************************/ 3411 ************************************************************************/
3420 3412
3421static struct scroll_bar *x_window_to_scroll_bar (Window); 3413static struct scroll_bar *x_window_to_scroll_bar (Window);
3422static void x_scroll_bar_report_motion (FRAME_PTR *, Lisp_Object *, 3414static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
3423 enum scroll_bar_part *, 3415 enum scroll_bar_part *,
3424 Lisp_Object *, Lisp_Object *, 3416 Lisp_Object *, Lisp_Object *,
3425 unsigned long *); 3417 unsigned long *);
@@ -3461,11 +3453,11 @@ w32_define_cursor (Window window, Cursor cursor)
3461 movement. */ 3453 movement. */
3462 3454
3463static void 3455static void
3464w32_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 3456w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
3465 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, 3457 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
3466 unsigned long *time) 3458 unsigned long *time)
3467{ 3459{
3468 FRAME_PTR f1; 3460 struct frame *f1;
3469 3461
3470 block_input (); 3462 block_input ();
3471 3463
@@ -3696,7 +3688,7 @@ my_create_scrollbar (struct frame * f, struct scroll_bar * bar)
3696/*#define ATTACH_THREADS*/ 3688/*#define ATTACH_THREADS*/
3697 3689
3698static BOOL 3690static BOOL
3699my_show_window (FRAME_PTR f, HWND hwnd, int how) 3691my_show_window (struct frame *f, HWND hwnd, int how)
3700{ 3692{
3701#ifndef ATTACH_THREADS 3693#ifndef ATTACH_THREADS
3702 return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW, 3694 return SendMessage (FRAME_W32_WINDOW (f), WM_EMACS_SHOWWINDOW,
@@ -3765,7 +3757,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
3765 HWND hwnd; 3757 HWND hwnd;
3766 SCROLLINFO si; 3758 SCROLLINFO si;
3767 struct scroll_bar *bar 3759 struct scroll_bar *bar
3768 = XSCROLL_BAR (Fmake_vector (make_number (VECSIZE (struct scroll_bar)), Qnil)); 3760 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, fringe_extended_p, PVEC_OTHER);
3769 Lisp_Object barobj; 3761 Lisp_Object barobj;
3770 3762
3771 block_input (); 3763 block_input ();
@@ -3778,7 +3770,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
3778 XSETINT (bar->start, 0); 3770 XSETINT (bar->start, 0);
3779 XSETINT (bar->end, 0); 3771 XSETINT (bar->end, 0);
3780 bar->dragging = Qnil; 3772 bar->dragging = Qnil;
3781 bar->fringe_extended_p = Qnil; 3773 bar->fringe_extended_p = 0;
3782 3774
3783 /* Requires geometry to be set before call to create the real window */ 3775 /* Requires geometry to be set before call to create the real window */
3784 3776
@@ -3816,7 +3808,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
3816static void 3808static void
3817x_scroll_bar_remove (struct scroll_bar *bar) 3809x_scroll_bar_remove (struct scroll_bar *bar)
3818{ 3810{
3819 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 3811 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
3820 3812
3821 block_input (); 3813 block_input ();
3822 3814
@@ -3842,7 +3834,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3842 struct scroll_bar *bar; 3834 struct scroll_bar *bar;
3843 int top, height, left, sb_left, width, sb_width; 3835 int top, height, left, sb_left, width, sb_width;
3844 int window_y, window_height; 3836 int window_y, window_height;
3845 int fringe_extended_p; 3837 bool fringe_extended_p;
3846 3838
3847 /* Get window dimensions. */ 3839 /* Get window dimensions. */
3848 window_box (w, -1, 0, &window_y, 0, &window_height); 3840 window_box (w, -1, 0, &window_y, 0, &window_height);
@@ -3866,16 +3858,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3866 else 3858 else
3867 sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width); 3859 sb_left = left + (WINDOW_LEFTMOST_P (w) ? 0 : width - sb_width);
3868 3860
3869 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 3861 fringe_extended_p = WINDOW_FRINGE_EXTENDED_P (w);
3870 fringe_extended_p = (WINDOW_LEFTMOST_P (w)
3871 && WINDOW_LEFT_FRINGE_WIDTH (w)
3872 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
3873 || WINDOW_LEFT_MARGIN_COLS (w) == 0));
3874 else
3875 fringe_extended_p = (WINDOW_RIGHTMOST_P (w)
3876 && WINDOW_RIGHT_FRINGE_WIDTH (w)
3877 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
3878 || WINDOW_RIGHT_MARGIN_COLS (w) == 0));
3879 3862
3880 /* Does the scroll bar exist yet? */ 3863 /* Does the scroll bar exist yet? */
3881 if (NILP (w->vertical_scroll_bar)) 3864 if (NILP (w->vertical_scroll_bar))
@@ -3904,11 +3887,11 @@ w32_set_vertical_scroll_bar (struct window *w,
3904 hwnd = SCROLL_BAR_W32_WINDOW (bar); 3887 hwnd = SCROLL_BAR_W32_WINDOW (bar);
3905 3888
3906 /* If already correctly positioned, do nothing. */ 3889 /* If already correctly positioned, do nothing. */
3907 if ( XINT (bar->left) == sb_left 3890 if (XINT (bar->left) == sb_left
3908 && XINT (bar->top) == top 3891 && XINT (bar->top) == top
3909 && XINT (bar->width) == sb_width 3892 && XINT (bar->width) == sb_width
3910 && XINT (bar->height) == height 3893 && XINT (bar->height) == height
3911 && !NILP (bar->fringe_extended_p) == fringe_extended_p ) 3894 && bar->fringe_extended_p == fringe_extended_p)
3912 { 3895 {
3913 /* Redraw after clear_frame. */ 3896 /* Redraw after clear_frame. */
3914 if (!my_show_window (f, hwnd, SW_NORMAL)) 3897 if (!my_show_window (f, hwnd, SW_NORMAL))
@@ -3958,7 +3941,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3958 unblock_input (); 3941 unblock_input ();
3959 } 3942 }
3960 } 3943 }
3961 bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil; 3944 bar->fringe_extended_p = fringe_extended_p;
3962 3945
3963 w32_set_scroll_bar_thumb (bar, portion, position, whole); 3946 w32_set_scroll_bar_thumb (bar, portion, position, whole);
3964 XSETVECTOR (barobj, bar); 3947 XSETVECTOR (barobj, bar);
@@ -3979,7 +3962,7 @@ w32_set_vertical_scroll_bar (struct window *w,
3979 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ 3962 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
3980 3963
3981static void 3964static void
3982w32_condemn_scroll_bars (FRAME_PTR frame) 3965w32_condemn_scroll_bars (struct frame *frame)
3983{ 3966{
3984 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ 3967 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
3985 while (! NILP (FRAME_SCROLL_BARS (frame))) 3968 while (! NILP (FRAME_SCROLL_BARS (frame)))
@@ -4047,7 +4030,7 @@ w32_redeem_scroll_bar (struct window *window)
4047 last call to `*condemn_scroll_bars_hook'. */ 4030 last call to `*condemn_scroll_bars_hook'. */
4048 4031
4049static void 4032static void
4050w32_judge_scroll_bars (FRAME_PTR f) 4033w32_judge_scroll_bars (struct frame *f)
4051{ 4034{
4052 Lisp_Object bar, next; 4035 Lisp_Object bar, next;
4053 4036
@@ -4185,14 +4168,14 @@ w32_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg,
4185 on the scroll bar. */ 4168 on the scroll bar. */
4186 4169
4187static void 4170static void
4188x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window, 4171x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
4189 enum scroll_bar_part *part, 4172 enum scroll_bar_part *part,
4190 Lisp_Object *x, Lisp_Object *y, 4173 Lisp_Object *x, Lisp_Object *y,
4191 unsigned long *time) 4174 unsigned long *time)
4192{ 4175{
4193 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 4176 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
4194 Window w = SCROLL_BAR_W32_WINDOW (bar); 4177 Window w = SCROLL_BAR_W32_WINDOW (bar);
4195 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 4178 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
4196 int pos; 4179 int pos;
4197 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height)); 4180 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
4198 SCROLLINFO si; 4181 SCROLLINFO si;
@@ -4244,7 +4227,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
4244 redraw them. */ 4227 redraw them. */
4245 4228
4246void 4229void
4247x_scroll_bar_clear (FRAME_PTR f) 4230x_scroll_bar_clear (struct frame *f)
4248{ 4231{
4249 Lisp_Object bar; 4232 Lisp_Object bar;
4250 4233
@@ -4629,7 +4612,7 @@ w32_read_socket (struct terminal *terminal,
4629 { 4612 {
4630 /* If we decide we want to generate an event to be seen 4613 /* If we decide we want to generate an event to be seen
4631 by the rest of Emacs, we put it here. */ 4614 by the rest of Emacs, we put it here. */
4632 int tool_bar_p = 0; 4615 bool tool_bar_p = 0;
4633 int button; 4616 int button;
4634 int up; 4617 int up;
4635 4618
@@ -4923,16 +4906,11 @@ w32_read_socket (struct terminal *terminal,
4923 break; 4906 break;
4924 4907
4925 case WM_KILLFOCUS: 4908 case WM_KILLFOCUS:
4909 w32_detect_focus_change (dpyinfo, &msg, &inev);
4926 f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd); 4910 f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd);
4927 4911
4928 if (f) 4912 if (f)
4929 { 4913 {
4930 if (f == dpyinfo->w32_focus_event_frame)
4931 dpyinfo->w32_focus_event_frame = 0;
4932
4933 if (f == dpyinfo->w32_focus_frame)
4934 x_new_focus_frame (dpyinfo, 0);
4935
4936 if (f == hlinfo->mouse_face_mouse_frame) 4914 if (f == hlinfo->mouse_face_mouse_frame)
4937 { 4915 {
4938 /* If we move outside the frame, then we're 4916 /* If we move outside the frame, then we're
@@ -4979,7 +4957,7 @@ w32_read_socket (struct terminal *terminal,
4979 if (f) 4957 if (f)
4980 { 4958 {
4981 extern void menubar_selection_callback 4959 extern void menubar_selection_callback
4982 (FRAME_PTR f, void * client_data); 4960 (struct frame *f, void * client_data);
4983 menubar_selection_callback (f, (void *)msg.msg.wParam); 4961 menubar_selection_callback (f, (void *)msg.msg.wParam);
4984 } 4962 }
4985 4963
@@ -5076,7 +5054,7 @@ w32_read_socket (struct terminal *terminal,
5076 5054
5077 FOR_EACH_FRAME (tail, frame) 5055 FOR_EACH_FRAME (tail, frame)
5078 { 5056 {
5079 FRAME_PTR f = XFRAME (frame); 5057 struct frame *f = XFRAME (frame);
5080 /* The tooltip has been drawn already. Avoid the 5058 /* The tooltip has been drawn already. Avoid the
5081 SET_FRAME_GARBAGED below. */ 5059 SET_FRAME_GARBAGED below. */
5082 if (EQ (frame, tip_frame)) 5060 if (EQ (frame, tip_frame))
@@ -5697,7 +5675,7 @@ x_check_fullscreen (struct frame *f)
5697} 5675}
5698 5676
5699static void 5677static void
5700w32fullscreen_hook (FRAME_PTR f) 5678w32fullscreen_hook (struct frame *f)
5701{ 5679{
5702 if (FRAME_VISIBLE_P (f)) 5680 if (FRAME_VISIBLE_P (f))
5703 { 5681 {
@@ -5722,7 +5700,9 @@ w32fullscreen_hook (FRAME_PTR f)
5722 w32_fullscreen_rect (hwnd, f->want_fullscreen, 5700 w32_fullscreen_rect (hwnd, f->want_fullscreen,
5723 FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect); 5701 FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect);
5724 FRAME_PREV_FSMODE (f) = f->want_fullscreen; 5702 FRAME_PREV_FSMODE (f) = f->want_fullscreen;
5725 if (f->want_fullscreen == FULLSCREEN_BOTH) 5703 if (f->want_fullscreen == FULLSCREEN_MAXIMIZED)
5704 PostMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, 0xf030, 0);
5705 else if (f->want_fullscreen == FULLSCREEN_BOTH)
5726 { 5706 {
5727 SetWindowLong (hwnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW); 5707 SetWindowLong (hwnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
5728 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top, 5708 SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top,
@@ -5894,11 +5874,6 @@ x_focus_on_frame (struct frame *f)
5894 unblock_input (); 5874 unblock_input ();
5895} 5875}
5896 5876
5897void
5898x_unfocus_frame (struct frame *f)
5899{
5900}
5901
5902/* Raise frame F. */ 5877/* Raise frame F. */
5903void 5878void
5904x_raise_frame (struct frame *f) 5879x_raise_frame (struct frame *f)
@@ -5974,7 +5949,7 @@ x_lower_frame (struct frame *f)
5974} 5949}
5975 5950
5976static void 5951static void
5977w32_frame_raise_lower (FRAME_PTR f, int raise_flag) 5952w32_frame_raise_lower (struct frame *f, int raise_flag)
5978{ 5953{
5979 if (! FRAME_W32_P (f)) 5954 if (! FRAME_W32_P (f))
5980 return; 5955 return;
@@ -6230,22 +6205,6 @@ x_wm_set_size_hint (struct frame *f, long flags, bool user_position)
6230 leave_crit (); 6205 leave_crit ();
6231} 6206}
6232 6207
6233/* Window manager things */
6234void
6235x_wm_set_icon_position (struct frame *f, int icon_x, int icon_y)
6236{
6237#if 0
6238 Window window = FRAME_W32_WINDOW (f);
6239
6240 f->display.x->wm_hints.flags |= IconPositionHint;
6241 f->display.x->wm_hints.icon_x = icon_x;
6242 f->display.x->wm_hints.icon_y = icon_y;
6243
6244 XSetWMHints (FRAME_X_DISPLAY (f), window, &f->display.x->wm_hints);
6245#endif
6246}
6247
6248
6249/*********************************************************************** 6208/***********************************************************************
6250 Fonts 6209 Fonts
6251 ***********************************************************************/ 6210 ***********************************************************************/
@@ -6504,9 +6463,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
6504 terminal = w32_create_terminal (dpyinfo); 6463 terminal = w32_create_terminal (dpyinfo);
6505 6464
6506 /* Set the name of the terminal. */ 6465 /* Set the name of the terminal. */
6507 terminal->name = xmalloc (SBYTES (display_name) + 1); 6466 terminal->name = xlispstrdup (display_name);
6508 strncpy (terminal->name, SDATA (display_name), SBYTES (display_name));
6509 terminal->name[SBYTES (display_name)] = 0;
6510 6467
6511 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL; 6468 dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
6512 6469
diff --git a/src/w32term.h b/src/w32term.h
index ace58758302..41c5c71832a 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -205,7 +205,7 @@ extern void x_focus_on_frame (struct frame *f);
205 205
206extern struct w32_display_info *w32_term_init (Lisp_Object, 206extern struct w32_display_info *w32_term_init (Lisp_Object,
207 char *, char *); 207 char *, char *);
208extern int w32_defined_color (FRAME_PTR f, const char *color, 208extern int w32_defined_color (struct frame *f, const char *color,
209 XColor *color_def, int alloc); 209 XColor *color_def, int alloc);
210extern void x_set_window_size (struct frame *f, int change_grav, 210extern void x_set_window_size (struct frame *f, int change_grav,
211 int cols, int rows); 211 int cols, int rows);
@@ -218,8 +218,6 @@ extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
218extern void x_make_frame_visible (struct frame *f); 218extern void x_make_frame_visible (struct frame *f);
219extern void x_make_frame_invisible (struct frame *f); 219extern void x_make_frame_invisible (struct frame *f);
220extern void x_iconify_frame (struct frame *f); 220extern void x_iconify_frame (struct frame *f);
221extern int x_pixel_width (struct frame *f);
222extern int x_pixel_height (struct frame *f);
223extern void x_set_frame_alpha (struct frame *f); 221extern void x_set_frame_alpha (struct frame *f);
224extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); 222extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
225extern void x_set_tool_bar_lines (struct frame *f, 223extern void x_set_tool_bar_lines (struct frame *f,
@@ -453,9 +451,11 @@ struct scroll_bar {
453 being dragged, this is Qnil. */ 451 being dragged, this is Qnil. */
454 Lisp_Object dragging; 452 Lisp_Object dragging;
455 453
456 /* t if the background of the fringe that is adjacent to a scroll 454 /* 1 if the background of the fringe that is adjacent to a scroll
457 bar is extended to the gap between the fringe and the bar. */ 455 bar is extended to the gap between the fringe and the bar. */
458 Lisp_Object fringe_extended_p; 456 /* Note: this could be a bit field, but we need to take its address
457 in ALLOCATE_PSEUDOVECTOR (see x_scroll_bar_create). */
458 bool fringe_extended_p;
459}; 459};
460 460
461/* Turning a lisp vector value into a pointer to a struct scroll_bar. */ 461/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c
index c153c8f3565..b31baa0e65c 100644
--- a/src/w32uniscribe.c
+++ b/src/w32uniscribe.c
@@ -69,28 +69,27 @@ memq_no_quit (Lisp_Object elt, Lisp_Object list)
69 69
70/* Font backend interface implementation. */ 70/* Font backend interface implementation. */
71static Lisp_Object 71static Lisp_Object
72uniscribe_list (Lisp_Object frame, Lisp_Object font_spec) 72uniscribe_list (struct frame *f, Lisp_Object font_spec)
73{ 73{
74 Lisp_Object fonts = w32font_list_internal (frame, font_spec, 1); 74 Lisp_Object fonts = w32font_list_internal (f, font_spec, 1);
75 FONT_ADD_LOG ("uniscribe-list", font_spec, fonts); 75 FONT_ADD_LOG ("uniscribe-list", font_spec, fonts);
76 return fonts; 76 return fonts;
77} 77}
78 78
79static Lisp_Object 79static Lisp_Object
80uniscribe_match (Lisp_Object frame, Lisp_Object font_spec) 80uniscribe_match (struct frame *f, Lisp_Object font_spec)
81{ 81{
82 Lisp_Object entity = w32font_match_internal (frame, font_spec, 1); 82 Lisp_Object entity = w32font_match_internal (f, font_spec, 1);
83 FONT_ADD_LOG ("uniscribe-match", font_spec, entity); 83 FONT_ADD_LOG ("uniscribe-match", font_spec, entity);
84 return entity; 84 return entity;
85} 85}
86 86
87static Lisp_Object 87static Lisp_Object
88uniscribe_list_family (Lisp_Object frame) 88uniscribe_list_family (struct frame *f)
89{ 89{
90 Lisp_Object list = Qnil; 90 Lisp_Object list = Qnil;
91 LOGFONT font_match_pattern; 91 LOGFONT font_match_pattern;
92 HDC dc; 92 HDC dc;
93 FRAME_PTR f = XFRAME (frame);
94 93
95 memset (&font_match_pattern, 0, sizeof (font_match_pattern)); 94 memset (&font_match_pattern, 0, sizeof (font_match_pattern));
96 /* Limit enumerated fonts to outline fonts to save time. */ 95 /* Limit enumerated fonts to outline fonts to save time. */
@@ -107,7 +106,7 @@ uniscribe_list_family (Lisp_Object frame)
107} 106}
108 107
109static Lisp_Object 108static Lisp_Object
110uniscribe_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size) 109uniscribe_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
111{ 110{
112 Lisp_Object font_object 111 Lisp_Object font_object
113 = font_make_object (VECSIZE (struct uniscribe_font_info), 112 = font_make_object (VECSIZE (struct uniscribe_font_info),
@@ -136,7 +135,7 @@ uniscribe_open (FRAME_PTR f, Lisp_Object font_entity, int pixel_size)
136} 135}
137 136
138static void 137static void
139uniscribe_close (FRAME_PTR f, struct font *font) 138uniscribe_close (struct frame *f, struct font *font)
140{ 139{
141 struct uniscribe_font_info *uniscribe_font 140 struct uniscribe_font_info *uniscribe_font
142 = (struct uniscribe_font_info *) font; 141 = (struct uniscribe_font_info *) font;
@@ -600,8 +599,8 @@ uniscribe_encode_char (struct font *font, int c)
600 int x, int y, int with_background); 599 int x, int y, int with_background);
601 600
602 Unused: 601 Unused:
603 int uniscribe_prepare_face (FRAME_PTR f, struct face *face); 602 int uniscribe_prepare_face (struct frame *f, struct face *face);
604 void uniscribe_done_face (FRAME_PTR f, struct face *face); 603 void uniscribe_done_face (struct frame *f, struct face *face);
605 int uniscribe_get_bitmap (struct font *font, unsigned code, 604 int uniscribe_get_bitmap (struct font *font, unsigned code,
606 struct font_bitmap *bitmap, int bits_per_pixel); 605 struct font_bitmap *bitmap, int bits_per_pixel);
607 void uniscribe_free_bitmap (struct font *font, struct font_bitmap *bitmap); 606 void uniscribe_free_bitmap (struct font *font, struct font_bitmap *bitmap);
@@ -609,8 +608,8 @@ uniscribe_encode_char (struct font *font, int c)
609 void uniscribe_free_outline (struct font *font, void *outline); 608 void uniscribe_free_outline (struct font *font, void *outline);
610 int uniscribe_anchor_point (struct font *font, unsigned code, 609 int uniscribe_anchor_point (struct font *font, unsigned code,
611 int index, int *x, int *y); 610 int index, int *x, int *y);
612 int uniscribe_start_for_frame (FRAME_PTR f); 611 int uniscribe_start_for_frame (struct frame *f);
613 int uniscribe_end_for_frame (FRAME_PTR f); 612 int uniscribe_end_for_frame (struct frame *f);
614 613
615*/ 614*/
616 615
diff --git a/src/w32xfns.c b/src/w32xfns.c
index 03611e19768..19c6b72bf89 100644
--- a/src/w32xfns.c
+++ b/src/w32xfns.c
@@ -90,7 +90,7 @@ signal_quit (void)
90} 90}
91 91
92void 92void
93select_palette (FRAME_PTR f, HDC hdc) 93select_palette (struct frame *f, HDC hdc)
94{ 94{
95 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); 95 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f);
96 96
@@ -117,7 +117,7 @@ select_palette (FRAME_PTR f, HDC hdc)
117} 117}
118 118
119void 119void
120deselect_palette (FRAME_PTR f, HDC hdc) 120deselect_palette (struct frame *f, HDC hdc)
121{ 121{
122 if (f->output_data.w32->old_palette) 122 if (f->output_data.w32->old_palette)
123 SelectPalette (hdc, f->output_data.w32->old_palette, FALSE); 123 SelectPalette (hdc, f->output_data.w32->old_palette, FALSE);
@@ -126,7 +126,7 @@ deselect_palette (FRAME_PTR f, HDC hdc)
126/* Get a DC for frame and select palette for drawing; force an update of 126/* Get a DC for frame and select palette for drawing; force an update of
127 all frames if palette's mapping changes. */ 127 all frames if palette's mapping changes. */
128HDC 128HDC
129get_frame_dc (FRAME_PTR f) 129get_frame_dc (struct frame *f)
130{ 130{
131 HDC hdc; 131 HDC hdc;
132 132
@@ -146,7 +146,7 @@ get_frame_dc (FRAME_PTR f)
146} 146}
147 147
148int 148int
149release_frame_dc (FRAME_PTR f, HDC hdc) 149release_frame_dc (struct frame *f, HDC hdc)
150{ 150{
151 int ret; 151 int ret;
152 152
diff --git a/src/widget.c b/src/widget.c
index e2c8e9fa23f..ec0b506046b 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -503,26 +503,6 @@ widget_update_wm_size_hints (Widget widget)
503 update_wm_hints (ew); 503 update_wm_hints (ew);
504} 504}
505 505
506
507#if 0
508
509static void
510create_frame_gcs (EmacsFrame ew)
511{
512 struct frame *s = ew->emacs_frame.frame;
513
514 s->output_data.x->normal_gc
515 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
516 s->output_data.x->reverse_gc
517 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
518 s->output_data.x->cursor_gc
519 = XCreateGC (XtDisplay (ew), RootWindowOfScreen (XtScreen (ew)), 0, 0);
520 s->output_data.x->black_relief.gc = 0;
521 s->output_data.x->white_relief.gc = 0;
522}
523
524#endif /* 0 */
525
526static char setup_frame_cursor_bits[] = 506static char setup_frame_cursor_bits[] =
527{ 507{
528 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 508 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -683,19 +663,7 @@ EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs
683static void 663static void
684EmacsFrameDestroy (Widget widget) 664EmacsFrameDestroy (Widget widget)
685{ 665{
686 EmacsFrame ew = (EmacsFrame) widget; 666 /* All GCs are now freed in x_free_frame_resources. */
687 struct frame* s = ew->emacs_frame.frame;
688
689 if (! s) emacs_abort ();
690 if (! s->output_data.x) emacs_abort ();
691
692 block_input ();
693 x_free_gcs (s);
694 if (s->output_data.x->white_relief.gc)
695 XFreeGC (XtDisplay (widget), s->output_data.x->white_relief.gc);
696 if (s->output_data.x->black_relief.gc)
697 XFreeGC (XtDisplay (widget), s->output_data.x->black_relief.gc);
698 unblock_input ();
699} 667}
700 668
701static void 669static void
@@ -838,7 +806,7 @@ void
838widget_store_internal_border (Widget widget) 806widget_store_internal_border (Widget widget)
839{ 807{
840 EmacsFrame ew = (EmacsFrame) widget; 808 EmacsFrame ew = (EmacsFrame) widget;
841 FRAME_PTR f = ew->emacs_frame.frame; 809 struct frame *f = ew->emacs_frame.frame;
842 810
843 ew->emacs_frame.internal_border_width = f->internal_border_width; 811 ew->emacs_frame.internal_border_width = f->internal_border_width;
844} 812}
diff --git a/src/window.c b/src/window.c
index bf4ce1dbe39..a1a069e0e7d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -66,14 +66,11 @@ static Lisp_Object Qsafe, Qabove, Qbelow, Qwindow_size, Qclone_of;
66static int displayed_window_lines (struct window *); 66static int displayed_window_lines (struct window *);
67static int count_windows (struct window *); 67static int count_windows (struct window *);
68static int get_leaf_windows (struct window *, struct window **, int); 68static int get_leaf_windows (struct window *, struct window **, int);
69static void window_scroll (Lisp_Object, EMACS_INT, int, int); 69static void window_scroll (Lisp_Object, EMACS_INT, bool, int);
70static void window_scroll_pixel_based (Lisp_Object, int, int, int); 70static void window_scroll_pixel_based (Lisp_Object, int, bool, int);
71static void window_scroll_line_based (Lisp_Object, int, int, int); 71static void window_scroll_line_based (Lisp_Object, int, bool, int);
72static int freeze_window_start (struct window *, void *);
73static Lisp_Object window_list (void); 72static Lisp_Object window_list (void);
74static int add_window_to_list (struct window *, void *); 73static int add_window_to_list (struct window *, void *);
75static int candidate_window_p (Lisp_Object, Lisp_Object, Lisp_Object,
76 Lisp_Object);
77static Lisp_Object next_window (Lisp_Object, Lisp_Object, 74static Lisp_Object next_window (Lisp_Object, Lisp_Object,
78 Lisp_Object, int); 75 Lisp_Object, int);
79static void decode_next_window_args (Lisp_Object *, Lisp_Object *, 76static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
@@ -90,6 +87,14 @@ static void window_resize_apply (struct window *, bool);
90static Lisp_Object select_window (Lisp_Object, Lisp_Object, int); 87static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
91static void select_window_1 (Lisp_Object, bool); 88static void select_window_1 (Lisp_Object, bool);
92 89
90static struct window *set_window_fringes (struct window *, Lisp_Object,
91 Lisp_Object, Lisp_Object);
92static struct window *set_window_margins (struct window *, Lisp_Object,
93 Lisp_Object);
94static struct window *set_window_scroll_bars (struct window *, Lisp_Object,
95 Lisp_Object, Lisp_Object);
96static void apply_window_adjustment (struct window *);
97
93/* This is the window in which the terminal's cursor should 98/* This is the window in which the terminal's cursor should
94 be left when nothing is being done with it. This must 99 be left when nothing is being done with it. This must
95 always be a leaf window, and its buffer is selected by 100 always be a leaf window, and its buffer is selected by
@@ -154,16 +159,6 @@ wset_display_table (struct window *w, Lisp_Object val)
154 w->display_table = val; 159 w->display_table = val;
155} 160}
156static void 161static void
157wset_left_fringe_width (struct window *w, Lisp_Object val)
158{
159 w->left_fringe_width = val;
160}
161static void
162wset_left_margin_cols (struct window *w, Lisp_Object val)
163{
164 w->left_margin_cols = val;
165}
166static void
167wset_new_normal (struct window *w, Lisp_Object val) 162wset_new_normal (struct window *w, Lisp_Object val)
168{ 163{
169 w->new_normal = val; 164 w->new_normal = val;
@@ -194,21 +189,6 @@ wset_pointm (struct window *w, Lisp_Object val)
194 w->pointm = val; 189 w->pointm = val;
195} 190}
196static void 191static void
197wset_right_fringe_width (struct window *w, Lisp_Object val)
198{
199 w->right_fringe_width = val;
200}
201static void
202wset_right_margin_cols (struct window *w, Lisp_Object val)
203{
204 w->right_margin_cols = val;
205}
206static void
207wset_scroll_bar_width (struct window *w, Lisp_Object val)
208{
209 w->scroll_bar_width = val;
210}
211static void
212wset_start (struct window *w, Lisp_Object val) 192wset_start (struct window *w, Lisp_Object val)
213{ 193{
214 w->start = val; 194 w->start = val;
@@ -241,6 +221,17 @@ wset_combination (struct window *w, bool horflag, Lisp_Object val)
241 w->horizontal = horflag; 221 w->horizontal = horflag;
242} 222}
243 223
224/* Nonzero if leaf window W doesn't reflect the actual state
225 of displayed buffer due to its text or overlays change. */
226
227bool
228window_outdated (struct window *w)
229{
230 struct buffer *b = XBUFFER (w->contents);
231 return (w->last_modified < BUF_MODIFF (b)
232 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b));
233}
234
244struct window * 235struct window *
245decode_live_window (register Lisp_Object window) 236decode_live_window (register Lisp_Object window)
246{ 237{
@@ -490,7 +481,6 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
490 CHECK_LIVE_WINDOW (window); 481 CHECK_LIVE_WINDOW (window);
491 482
492 w = XWINDOW (window); 483 w = XWINDOW (window);
493 w->frozen_window_start_p = 0;
494 484
495 /* Make the selected window's buffer current. */ 485 /* Make the selected window's buffer current. */
496 Fset_buffer (w->contents); 486 Fset_buffer (w->contents);
@@ -1355,7 +1345,7 @@ struct check_window_data
1355static int 1345static int
1356check_window_containing (struct window *w, void *user_data) 1346check_window_containing (struct window *w, void *user_data)
1357{ 1347{
1358 struct check_window_data *cw = (struct check_window_data *) user_data; 1348 struct check_window_data *cw = user_data;
1359 enum window_part found; 1349 enum window_part found;
1360 int continue_p = 1; 1350 int continue_p = 1;
1361 1351
@@ -1508,8 +1498,7 @@ if it isn't already recorded. */)
1508 || !w->window_end_valid 1498 || !w->window_end_valid
1509 || b->clip_changed 1499 || b->clip_changed
1510 || b->prevent_redisplay_optimizations_p 1500 || b->prevent_redisplay_optimizations_p
1511 || w->last_modified < BUF_MODIFF (b) 1501 || window_outdated (w))
1512 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1513 && !noninteractive) 1502 && !noninteractive)
1514 { 1503 {
1515 struct text_pos startp; 1504 struct text_pos startp;
@@ -1550,7 +1539,7 @@ if it isn't already recorded. */)
1550 set_buffer_internal (old_buffer); 1539 set_buffer_internal (old_buffer);
1551 } 1540 }
1552 else 1541 else
1553 XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos)); 1542 XSETINT (value, BUF_Z (b) - w->window_end_pos);
1554 1543
1555 return value; 1544 return value;
1556} 1545}
@@ -1606,9 +1595,8 @@ overriding motion of point in order to display at this exact start. */)
1606 if (NILP (noforce)) 1595 if (NILP (noforce))
1607 w->force_start = 1; 1596 w->force_start = 1;
1608 w->update_mode_line = 1; 1597 w->update_mode_line = 1;
1609 w->last_modified = 0; 1598 if (w != XWINDOW (selected_window))
1610 w->last_overlay_modified = 0; 1599 /* Enforce full redisplay. FIXME: make it more selective. */
1611 if (!EQ (window, selected_window))
1612 windows_or_buffers_changed++; 1600 windows_or_buffers_changed++;
1613 1601
1614 return pos; 1602 return pos;
@@ -1722,8 +1710,7 @@ Return nil if window display is not up-to-date. In that case, use
1722 || windows_or_buffers_changed 1710 || windows_or_buffers_changed
1723 || b->clip_changed 1711 || b->clip_changed
1724 || b->prevent_redisplay_optimizations_p 1712 || b->prevent_redisplay_optimizations_p
1725 || w->last_modified < BUF_MODIFF (b) 1713 || window_outdated (w))
1726 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1727 return Qnil; 1714 return Qnil;
1728 1715
1729 if (NILP (line)) 1716 if (NILP (line))
@@ -2046,10 +2033,9 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
2046 n->phys_cursor_width = -1; 2033 n->phys_cursor_width = -1;
2047 n->must_be_updated_p = 0; 2034 n->must_be_updated_p = 0;
2048 n->pseudo_window_p = 0; 2035 n->pseudo_window_p = 0;
2049 wset_window_end_vpos (n, make_number (0)); 2036 n->window_end_vpos = 0;
2050 wset_window_end_pos (n, make_number (0)); 2037 n->window_end_pos = 0;
2051 n->window_end_valid = 0; 2038 n->window_end_valid = 0;
2052 n->frozen_window_start_p = 0;
2053 } 2039 }
2054 2040
2055 tem = o->next; 2041 tem = o->next;
@@ -2158,7 +2144,7 @@ delete_deletable_window (Lisp_Object window)
2158static int 2144static int
2159add_window_to_list (struct window *w, void *user_data) 2145add_window_to_list (struct window *w, void *user_data)
2160{ 2146{
2161 Lisp_Object *list = (Lisp_Object *) user_data; 2147 Lisp_Object *list = user_data;
2162 Lisp_Object window; 2148 Lisp_Object window;
2163 XSETWINDOW (window, w); 2149 XSETWINDOW (window, w);
2164 *list = Fcons (window, *list); 2150 *list = Fcons (window, *list);
@@ -2213,12 +2199,13 @@ window_list (void)
2213 a window means search the frame that window belongs to, 2199 a window means search the frame that window belongs to,
2214 a frame means consider windows on that frame, only. */ 2200 a frame means consider windows on that frame, only. */
2215 2201
2216static int 2202static bool
2217candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf, Lisp_Object all_frames) 2203candidate_window_p (Lisp_Object window, Lisp_Object owindow,
2204 Lisp_Object minibuf, Lisp_Object all_frames)
2218{ 2205{
2219 struct window *w = XWINDOW (window); 2206 struct window *w = XWINDOW (window);
2220 struct frame *f = XFRAME (w->frame); 2207 struct frame *f = XFRAME (w->frame);
2221 int candidate_p = 1; 2208 bool candidate_p = 1;
2222 2209
2223 if (!BUFFERP (w->contents)) 2210 if (!BUFFERP (w->contents))
2224 candidate_p = 0; 2211 candidate_p = 0;
@@ -3020,7 +3007,7 @@ replace_buffer_in_windows_safely (Lisp_Object buffer)
3020 minimum allowable size. */ 3007 minimum allowable size. */
3021 3008
3022void 3009void
3023check_frame_size (FRAME_PTR frame, int *rows, int *cols) 3010check_frame_size (struct frame *frame, int *rows, int *cols)
3024{ 3011{
3025 /* For height, we have to see: 3012 /* For height, we have to see:
3026 how many windows the frame has at minimum (one or two), 3013 how many windows the frame has at minimum (one or two),
@@ -3064,15 +3051,12 @@ adjust_window_margins (struct window *w)
3064 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0) 3051 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
3065 { 3052 {
3066 if (WINDOW_LEFT_MARGIN_COLS (w) > 0) 3053 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
3067 { 3054 w->left_margin_cols = w->right_margin_cols = margin_cols / 2;
3068 wset_left_margin_cols (w, make_number (margin_cols / 2));
3069 wset_right_margin_cols (w, make_number (margin_cols / 2));
3070 }
3071 else 3055 else
3072 wset_right_margin_cols (w, make_number (margin_cols)); 3056 w->right_margin_cols = margin_cols;
3073 } 3057 }
3074 else 3058 else
3075 wset_left_margin_cols (w, make_number (margin_cols)); 3059 w->left_margin_cols = margin_cols;
3076 return 1; 3060 return 1;
3077} 3061}
3078 3062
@@ -3120,7 +3104,7 @@ run_window_configuration_change_hook (struct frame *f)
3120 3104
3121 if (SELECTED_FRAME () != f) 3105 if (SELECTED_FRAME () != f)
3122 { 3106 {
3123 record_unwind_protect (select_frame_norecord, Fselected_frame ()); 3107 record_unwind_protect (select_frame_norecord, selected_frame);
3124 select_frame_norecord (frame); 3108 select_frame_norecord (frame);
3125 } 3109 }
3126 3110
@@ -3135,7 +3119,7 @@ run_window_configuration_change_hook (struct frame *f)
3135 buffer))) 3119 buffer)))
3136 { 3120 {
3137 ptrdiff_t inner_count = SPECPDL_INDEX (); 3121 ptrdiff_t inner_count = SPECPDL_INDEX ();
3138 record_unwind_protect (select_window_norecord, Fselected_window ()); 3122 record_unwind_protect (select_window_norecord, selected_window);
3139 select_window_norecord (window); 3123 select_window_norecord (window);
3140 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, 3124 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
3141 buffer)); 3125 buffer));
@@ -3186,8 +3170,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3186 bset_display_count (b, make_number (XINT (BVAR (b, display_count)) + 1)); 3170 bset_display_count (b, make_number (XINT (BVAR (b, display_count)) + 1));
3187 bset_display_time (b, Fcurrent_time ()); 3171 bset_display_time (b, Fcurrent_time ());
3188 3172
3189 wset_window_end_pos (w, make_number (0)); 3173 w->window_end_pos = 0;
3190 wset_window_end_vpos (w, make_number (0)); 3174 w->window_end_vpos = 0;
3191 memset (&w->last_cursor, 0, sizeof w->last_cursor); 3175 memset (&w->last_cursor, 0, sizeof w->last_cursor);
3192 3176
3193 if (!(keep_margins_p && samebuf)) 3177 if (!(keep_margins_p && samebuf))
@@ -3207,8 +3191,6 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3207 buffer); 3191 buffer);
3208 w->start_at_line_beg = 0; 3192 w->start_at_line_beg = 0;
3209 w->force_start = 0; 3193 w->force_start = 0;
3210 w->last_modified = 0;
3211 w->last_overlay_modified = 0;
3212 } 3194 }
3213 /* Maybe we could move this into the `if' but it's not obviously safe and 3195 /* Maybe we could move this into the `if' but it's not obviously safe and
3214 I doubt it's worth the trouble. */ 3196 I doubt it's worth the trouble. */
@@ -3228,28 +3210,14 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3228 if (!keep_margins_p) 3210 if (!keep_margins_p)
3229 { 3211 {
3230 /* Set left and right marginal area width etc. from buffer. */ 3212 /* Set left and right marginal area width etc. from buffer. */
3231 3213 set_window_fringes (w, BVAR (b, left_fringe_width),
3232 /* This may call adjust_window_margins three times, so 3214 BVAR (b, right_fringe_width),
3233 temporarily disable window margins. */ 3215 BVAR (b, fringes_outside_margins));
3234 Lisp_Object save_left = w->left_margin_cols; 3216 set_window_scroll_bars (w, BVAR (b, scroll_bar_width),
3235 Lisp_Object save_right = w->right_margin_cols; 3217 BVAR (b, vertical_scroll_bar_type), Qnil);
3236 3218 set_window_margins (w, BVAR (b, left_margin_cols),
3237 wset_left_margin_cols (w, Qnil); 3219 BVAR (b, right_margin_cols));
3238 wset_right_margin_cols (w, Qnil); 3220 apply_window_adjustment (w);
3239
3240 Fset_window_fringes (window,
3241 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width),
3242 BVAR (b, fringes_outside_margins));
3243
3244 Fset_window_scroll_bars (window,
3245 BVAR (b, scroll_bar_width),
3246 BVAR (b, vertical_scroll_bar_type), Qnil);
3247
3248 wset_left_margin_cols (w, save_left);
3249 wset_right_margin_cols (w, save_right);
3250
3251 Fset_window_margins (window,
3252 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols));
3253 } 3221 }
3254 3222
3255 if (run_hooks_p) 3223 if (run_hooks_p)
@@ -3469,8 +3437,6 @@ make_window (void)
3469 wset_start (w, Fmake_marker ()); 3437 wset_start (w, Fmake_marker ());
3470 wset_pointm (w, Fmake_marker ()); 3438 wset_pointm (w, Fmake_marker ());
3471 wset_vertical_scroll_bar_type (w, Qt); 3439 wset_vertical_scroll_bar_type (w, Qt);
3472 wset_window_end_pos (w, make_number (0));
3473 wset_window_end_vpos (w, make_number (0));
3474 /* These Lisp fields are marked specially so they're not set to nil by 3440 /* These Lisp fields are marked specially so they're not set to nil by
3475 allocate_window. */ 3441 allocate_window. */
3476 wset_prev_buffers (w, Qnil); 3442 wset_prev_buffers (w, Qnil);
@@ -3479,8 +3445,10 @@ make_window (void)
3479 /* Initialize non-Lisp data. Note that allocate_window zeroes out all 3445 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3480 non-Lisp data, so do it only for slots which should not be zero. */ 3446 non-Lisp data, so do it only for slots which should not be zero. */
3481 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3447 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3448 w->left_fringe_width = w->right_fringe_width = -1;
3482 w->phys_cursor_type = -1; 3449 w->phys_cursor_type = -1;
3483 w->phys_cursor_width = -1; 3450 w->phys_cursor_width = -1;
3451 w->scroll_bar_width = -1;
3484 w->column_number_displayed = -1; 3452 w->column_number_displayed = -1;
3485 3453
3486 /* Reset window_list. */ 3454 /* Reset window_list. */
@@ -3669,10 +3637,6 @@ window_resize_apply (struct window *w, bool horflag)
3669 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3637 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3670 } 3638 }
3671 } 3639 }
3672
3673 /* Clear out some redisplay caches. */
3674 w->last_modified = 0;
3675 w->last_overlay_modified = 0;
3676} 3640}
3677 3641
3678 3642
@@ -3950,12 +3914,12 @@ set correctly. See the code of `split-window' for how this is done. */)
3950 memset (&n->last_cursor, 0, sizeof n->last_cursor); 3914 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3951 3915
3952 /* Get special geometry settings from reference window. */ 3916 /* Get special geometry settings from reference window. */
3953 wset_left_margin_cols (n, r->left_margin_cols); 3917 n->left_margin_cols = r->left_margin_cols;
3954 wset_right_margin_cols (n, r->right_margin_cols); 3918 n->right_margin_cols = r->right_margin_cols;
3955 wset_left_fringe_width (n, r->left_fringe_width); 3919 n->left_fringe_width = r->left_fringe_width;
3956 wset_right_fringe_width (n, r->right_fringe_width); 3920 n->right_fringe_width = r->right_fringe_width;
3957 n->fringes_outside_margins = r->fringes_outside_margins; 3921 n->fringes_outside_margins = r->fringes_outside_margins;
3958 wset_scroll_bar_width (n, r->scroll_bar_width); 3922 n->scroll_bar_width = r->scroll_bar_width;
3959 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type); 3923 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type);
3960 3924
3961 /* Directly assign orthogonal coordinates and sizes. */ 3925 /* Directly assign orthogonal coordinates and sizes. */
@@ -4191,9 +4155,7 @@ grow_mini_window (struct window *w, int delta)
4191 /* Grow the mini-window. */ 4155 /* Grow the mini-window. */
4192 w->top_line = r->top_line + r->total_lines; 4156 w->top_line = r->top_line + r->total_lines;
4193 w->total_lines -= XINT (value); 4157 w->total_lines -= XINT (value);
4194 w->last_modified = 0; 4158 /* Enforce full redisplay. FIXME: make it more selective. */
4195 w->last_overlay_modified = 0;
4196
4197 windows_or_buffers_changed++; 4159 windows_or_buffers_changed++;
4198 adjust_glyphs (f); 4160 adjust_glyphs (f);
4199 unblock_input (); 4161 unblock_input ();
@@ -4227,10 +4189,7 @@ shrink_mini_window (struct window *w)
4227 /* Shrink the mini-window. */ 4189 /* Shrink the mini-window. */
4228 w->top_line = r->top_line + r->total_lines; 4190 w->top_line = r->top_line + r->total_lines;
4229 w->total_lines = 1; 4191 w->total_lines = 1;
4230 4192 /* Enforce full redisplay. FIXME: make it more selective. */
4231 w->last_modified = 0;
4232 w->last_overlay_modified = 0;
4233
4234 windows_or_buffers_changed++; 4193 windows_or_buffers_changed++;
4235 adjust_glyphs (f); 4194 adjust_glyphs (f);
4236 unblock_input (); 4195 unblock_input ();
@@ -4337,7 +4296,7 @@ window_internal_height (struct window *w)
4337 respectively. */ 4296 respectively. */
4338 4297
4339static void 4298static void
4340window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror) 4299window_scroll (Lisp_Object window, EMACS_INT n, bool whole, int noerror)
4341{ 4300{
4342 immediate_quit = 1; 4301 immediate_quit = 1;
4343 n = clip_to_bounds (INT_MIN, n, INT_MAX); 4302 n = clip_to_bounds (INT_MIN, n, INT_MAX);
@@ -4358,7 +4317,7 @@ window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4358 descriptions. */ 4317 descriptions. */
4359 4318
4360static void 4319static void
4361window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror) 4320window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4362{ 4321{
4363 struct it it; 4322 struct it it;
4364 struct window *w = XWINDOW (window); 4323 struct window *w = XWINDOW (window);
@@ -4456,8 +4415,6 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4456 w->contents); 4415 w->contents);
4457 w->start_at_line_beg = 1; 4416 w->start_at_line_beg = 1;
4458 w->update_mode_line = 1; 4417 w->update_mode_line = 1;
4459 w->last_modified = 0;
4460 w->last_overlay_modified = 0;
4461 /* Set force_start so that redisplay_window will run the 4418 /* Set force_start so that redisplay_window will run the
4462 window-scroll-functions. */ 4419 window-scroll-functions. */
4463 w->force_start = 1; 4420 w->force_start = 1;
@@ -4602,8 +4559,6 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4602 bytepos = marker_byte_position (w->start); 4559 bytepos = marker_byte_position (w->start);
4603 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n'); 4560 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
4604 w->update_mode_line = 1; 4561 w->update_mode_line = 1;
4605 w->last_modified = 0;
4606 w->last_overlay_modified = 0;
4607 /* Set force_start so that redisplay_window will run the 4562 /* Set force_start so that redisplay_window will run the
4608 window-scroll-functions. */ 4563 window-scroll-functions. */
4609 w->force_start = 1; 4564 w->force_start = 1;
@@ -4726,7 +4681,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4726 See the comment of window_scroll for parameter descriptions. */ 4681 See the comment of window_scroll for parameter descriptions. */
4727 4682
4728static void 4683static void
4729window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror) 4684window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4730{ 4685{
4731 register struct window *w = XWINDOW (window); 4686 register struct window *w = XWINDOW (window);
4732 /* Fvertical_motion enters redisplay, which can trigger 4687 /* Fvertical_motion enters redisplay, which can trigger
@@ -4738,7 +4693,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4738 register ptrdiff_t pos, pos_byte; 4693 register ptrdiff_t pos, pos_byte;
4739 register int ht = window_internal_height (w); 4694 register int ht = window_internal_height (w);
4740 register Lisp_Object tem; 4695 register Lisp_Object tem;
4741 int lose; 4696 bool lose;
4742 Lisp_Object bolp; 4697 Lisp_Object bolp;
4743 ptrdiff_t startpos = marker_position (w->start); 4698 ptrdiff_t startpos = marker_position (w->start);
4744 ptrdiff_t startbyte = marker_byte_position (w->start); 4699 ptrdiff_t startbyte = marker_byte_position (w->start);
@@ -4802,8 +4757,6 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4802 set_marker_restricted_both (w->start, w->contents, pos, pos_byte); 4757 set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
4803 w->start_at_line_beg = !NILP (bolp); 4758 w->start_at_line_beg = !NILP (bolp);
4804 w->update_mode_line = 1; 4759 w->update_mode_line = 1;
4805 w->last_modified = 0;
4806 w->last_overlay_modified = 0;
4807 /* Set force_start so that redisplay_window will run 4760 /* Set force_start so that redisplay_window will run
4808 the window-scroll-functions. */ 4761 the window-scroll-functions. */
4809 w->force_start = 1; 4762 w->force_start = 1;
@@ -5172,7 +5125,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5172 struct window *w = XWINDOW (selected_window); 5125 struct window *w = XWINDOW (selected_window);
5173 struct buffer *buf = XBUFFER (w->contents); 5126 struct buffer *buf = XBUFFER (w->contents);
5174 struct buffer *obuf = current_buffer; 5127 struct buffer *obuf = current_buffer;
5175 int center_p = 0; 5128 bool center_p = 0;
5176 ptrdiff_t charpos, bytepos; 5129 ptrdiff_t charpos, bytepos;
5177 EMACS_INT iarg IF_LINT (= 0); 5130 EMACS_INT iarg IF_LINT (= 0);
5178 int this_scroll_margin; 5131 int this_scroll_margin;
@@ -5517,7 +5470,7 @@ the return value is nil. Otherwise the value is t. */)
5517 struct Lisp_Vector *saved_windows; 5470 struct Lisp_Vector *saved_windows;
5518 Lisp_Object new_current_buffer; 5471 Lisp_Object new_current_buffer;
5519 Lisp_Object frame; 5472 Lisp_Object frame;
5520 FRAME_PTR f; 5473 struct frame *f;
5521 ptrdiff_t old_point = -1; 5474 ptrdiff_t old_point = -1;
5522 5475
5523 CHECK_WINDOW_CONFIGURATION (configuration); 5476 CHECK_WINDOW_CONFIGURATION (configuration);
@@ -5704,12 +5657,12 @@ the return value is nil. Otherwise the value is t. */)
5704 w->hscroll = XFASTINT (p->hscroll); 5657 w->hscroll = XFASTINT (p->hscroll);
5705 w->min_hscroll = XFASTINT (p->min_hscroll); 5658 w->min_hscroll = XFASTINT (p->min_hscroll);
5706 wset_display_table (w, p->display_table); 5659 wset_display_table (w, p->display_table);
5707 wset_left_margin_cols (w, p->left_margin_cols); 5660 w->left_margin_cols = XINT (p->left_margin_cols);
5708 wset_right_margin_cols (w, p->right_margin_cols); 5661 w->right_margin_cols = XINT (p->right_margin_cols);
5709 wset_left_fringe_width (w, p->left_fringe_width); 5662 w->left_fringe_width = XINT (p->left_fringe_width);
5710 wset_right_fringe_width (w, p->right_fringe_width); 5663 w->right_fringe_width = XINT (p->right_fringe_width);
5711 w->fringes_outside_margins = !NILP (p->fringes_outside_margins); 5664 w->fringes_outside_margins = !NILP (p->fringes_outside_margins);
5712 wset_scroll_bar_width (w, p->scroll_bar_width); 5665 w->scroll_bar_width = XINT (p->scroll_bar_width);
5713 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type); 5666 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type);
5714 wset_dedicated (w, p->dedicated); 5667 wset_dedicated (w, p->dedicated);
5715 wset_combination_limit (w, p->combination_limit); 5668 wset_combination_limit (w, p->combination_limit);
@@ -5735,9 +5688,6 @@ the return value is nil. Otherwise the value is t. */)
5735 } 5688 }
5736 } 5689 }
5737 5690
5738 w->last_modified = 0;
5739 w->last_overlay_modified = 0;
5740
5741 if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) 5691 if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
5742 /* If saved buffer is alive, install it. */ 5692 /* If saved buffer is alive, install it. */
5743 { 5693 {
@@ -6008,12 +5958,12 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
6008 XSETFASTINT (p->hscroll, w->hscroll); 5958 XSETFASTINT (p->hscroll, w->hscroll);
6009 XSETFASTINT (p->min_hscroll, w->min_hscroll); 5959 XSETFASTINT (p->min_hscroll, w->min_hscroll);
6010 p->display_table = w->display_table; 5960 p->display_table = w->display_table;
6011 p->left_margin_cols = w->left_margin_cols; 5961 p->left_margin_cols = make_number (w->left_margin_cols);
6012 p->right_margin_cols = w->right_margin_cols; 5962 p->right_margin_cols = make_number (w->right_margin_cols);
6013 p->left_fringe_width = w->left_fringe_width; 5963 p->left_fringe_width = make_number (w->left_fringe_width);
6014 p->right_fringe_width = w->right_fringe_width; 5964 p->right_fringe_width = make_number (w->right_fringe_width);
6015 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil; 5965 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil;
6016 p->scroll_bar_width = w->scroll_bar_width; 5966 p->scroll_bar_width = make_number (w->scroll_bar_width);
6017 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type; 5967 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
6018 p->dedicated = w->dedicated; 5968 p->dedicated = w->dedicated;
6019 p->combination_limit = w->combination_limit; 5969 p->combination_limit = w->combination_limit;
@@ -6154,11 +6104,46 @@ saved by this function. */)
6154 XSETWINDOW_CONFIGURATION (tem, data); 6104 XSETWINDOW_CONFIGURATION (tem, data);
6155 return (tem); 6105 return (tem);
6156} 6106}
6107
6108/* Called after W's margins, fringes or scroll bars was adjusted. */
6109
6110static void
6111apply_window_adjustment (struct window *w)
6112{
6113 eassert (w);
6114 adjust_window_margins (w);
6115 clear_glyph_matrix (w->current_matrix);
6116 w->window_end_valid = 0;
6117 windows_or_buffers_changed++;
6118 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6119}
6120
6157 6121
6158/*********************************************************************** 6122/***********************************************************************
6159 Marginal Areas 6123 Marginal Areas
6160 ***********************************************************************/ 6124 ***********************************************************************/
6161 6125
6126static struct window *
6127set_window_margins (struct window *w, Lisp_Object left_width,
6128 Lisp_Object right_width)
6129{
6130 int left, right;
6131
6132 /* FIXME: what about margins that are too wide? */
6133 left = (NILP (left_width) ? 0
6134 : (CHECK_NATNUM (left_width), XINT (left_width)));
6135 right = (NILP (right_width) ? 0
6136 : (CHECK_NATNUM (right_width), XINT (right_width)));
6137
6138 if (w->left_margin_cols != left || w->right_margin_cols != right)
6139 {
6140 w->left_margin_cols = left;
6141 w->right_margin_cols = right;
6142 return w;
6143 }
6144 return NULL;
6145}
6146
6162DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, 6147DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
6163 2, 3, 0, 6148 2, 3, 0,
6164 doc: /* Set width of marginal areas of window WINDOW. 6149 doc: /* Set width of marginal areas of window WINDOW.
@@ -6167,41 +6152,14 @@ WINDOW must be a live window and defaults to the selected one.
6167Second arg LEFT-WIDTH specifies the number of character cells to 6152Second arg LEFT-WIDTH specifies the number of character cells to
6168reserve for the left marginal area. Optional third arg RIGHT-WIDTH 6153reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6169does the same for the right marginal area. A nil width parameter 6154does the same for the right marginal area. A nil width parameter
6170means no margin. */) 6155means no margin.
6156
6157Return t if any margin was actually changed and nil otherwise. */)
6171 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width) 6158 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
6172{ 6159{
6173 struct window *w = decode_live_window (window); 6160 struct window *w = set_window_margins (decode_live_window (window),
6174 6161 left_width, right_width);
6175 /* Translate negative or zero widths to nil. 6162 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6176 Margins that are too wide have to be checked elsewhere. */
6177
6178 if (!NILP (left_width))
6179 {
6180 CHECK_NUMBER (left_width);
6181 if (XINT (left_width) <= 0)
6182 left_width = Qnil;
6183 }
6184
6185 if (!NILP (right_width))
6186 {
6187 CHECK_NUMBER (right_width);
6188 if (XINT (right_width) <= 0)
6189 right_width = Qnil;
6190 }
6191
6192 if (!EQ (w->left_margin_cols, left_width)
6193 || !EQ (w->right_margin_cols, right_width))
6194 {
6195 wset_left_margin_cols (w, left_width);
6196 wset_right_margin_cols (w, right_width);
6197
6198 adjust_window_margins (w);
6199
6200 ++windows_or_buffers_changed;
6201 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6202 }
6203
6204 return Qnil;
6205} 6163}
6206 6164
6207 6165
@@ -6216,7 +6174,8 @@ as nil. */)
6216 (Lisp_Object window) 6174 (Lisp_Object window)
6217{ 6175{
6218 struct window *w = decode_live_window (window); 6176 struct window *w = decode_live_window (window);
6219 return Fcons (w->left_margin_cols, w->right_margin_cols); 6177 return Fcons (w->left_margin_cols ? make_number (w->left_margin_cols) : Qnil,
6178 w->right_margin_cols ? make_number (w->right_margin_cols) : Qnil);
6220} 6179}
6221 6180
6222 6181
@@ -6225,6 +6184,31 @@ as nil. */)
6225 Fringes 6184 Fringes
6226 ***********************************************************************/ 6185 ***********************************************************************/
6227 6186
6187static struct window *
6188set_window_fringes (struct window *w, Lisp_Object left_width,
6189 Lisp_Object right_width, Lisp_Object outside_margins)
6190{
6191 int left, right, outside = !NILP (outside_margins);
6192
6193 left = (NILP (left_width) ? -1
6194 : (CHECK_NATNUM (left_width), XINT (left_width)));
6195 right = (NILP (right_width) ? -1
6196 : (CHECK_NATNUM (right_width), XINT (right_width)));
6197
6198 /* Do nothing on a tty or if nothing to actually change. */
6199 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6200 && (w->left_fringe_width != left
6201 || w->right_fringe_width != right
6202 || w->fringes_outside_margins != outside))
6203 {
6204 w->left_fringe_width = left;
6205 w->right_fringe_width = right;
6206 w->fringes_outside_margins = outside;
6207 return w;
6208 }
6209 return NULL;
6210}
6211
6228DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, 6212DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6229 2, 4, 0, 6213 2, 4, 0,
6230 doc: /* Set the fringe widths of window WINDOW. 6214 doc: /* Set the fringe widths of window WINDOW.
@@ -6237,37 +6221,16 @@ frame's default fringe width. Default fringe widths can be set with
6237the command `set-fringe-style'. 6221the command `set-fringe-style'.
6238If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes 6222If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6239outside of the display margins. By default, fringes are drawn between 6223outside of the display margins. By default, fringes are drawn between
6240display marginal areas and the text area. */) 6224display marginal areas and the text area.
6241 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6242{
6243 struct window *w = decode_live_window (window);
6244 int outside = !NILP (outside_margins);
6245
6246 if (!NILP (left_width))
6247 CHECK_NATNUM (left_width);
6248 if (!NILP (right_width))
6249 CHECK_NATNUM (right_width);
6250
6251 /* Do nothing on a tty. */
6252 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6253 && (!EQ (w->left_fringe_width, left_width)
6254 || !EQ (w->right_fringe_width, right_width)
6255 || w->fringes_outside_margins != outside))
6256 {
6257 wset_left_fringe_width (w, left_width);
6258 wset_right_fringe_width (w, right_width);
6259 w->fringes_outside_margins = outside;
6260
6261 adjust_window_margins (w);
6262
6263 clear_glyph_matrix (w->current_matrix);
6264 w->window_end_valid = 0;
6265 6225
6266 ++windows_or_buffers_changed; 6226Return t if any fringe was actually changed and nil otherwise. */)
6267 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6227 (Lisp_Object window, Lisp_Object left_width,
6268 } 6228 Lisp_Object right_width, Lisp_Object outside_margins)
6269 6229{
6270 return Qnil; 6230 struct window *w
6231 = set_window_fringes (decode_live_window (window),
6232 left_width, right_width, outside_margins);
6233 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6271} 6234}
6272 6235
6273 6236
@@ -6292,29 +6255,14 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6292 Scroll bars 6255 Scroll bars
6293 ***********************************************************************/ 6256 ***********************************************************************/
6294 6257
6295DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, 6258static struct window *
6296 Sset_window_scroll_bars, 2, 4, 0, 6259set_window_scroll_bars (struct window *w, Lisp_Object width,
6297 doc: /* Set width and type of scroll bars of window WINDOW. 6260 Lisp_Object vertical_type, Lisp_Object horizontal_type)
6298WINDOW must be a live window and defaults to the selected one.
6299
6300Second parameter WIDTH specifies the pixel width for the scroll bar;
6301this is automatically adjusted to a multiple of the frame column width.
6302Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6303bar: left, right, or nil.
6304If WIDTH is nil, use the frame's scroll-bar width.
6305If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6306Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6307 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6308{ 6261{
6309 struct window *w = decode_live_window (window); 6262 int iwidth = (NILP (width) ? -1 : (CHECK_NATNUM (width), XINT (width)));
6310 6263
6311 if (!NILP (width)) 6264 if (iwidth == 0)
6312 { 6265 vertical_type = Qnil;
6313 CHECK_RANGED_INTEGER (width, 0, INT_MAX);
6314
6315 if (XINT (width) == 0)
6316 vertical_type = Qnil;
6317 }
6318 6266
6319 if (!(NILP (vertical_type) 6267 if (!(NILP (vertical_type)
6320 || EQ (vertical_type, Qleft) 6268 || EQ (vertical_type, Qleft)
@@ -6322,22 +6270,37 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6322 || EQ (vertical_type, Qt))) 6270 || EQ (vertical_type, Qt)))
6323 error ("Invalid type of vertical scroll bar"); 6271 error ("Invalid type of vertical scroll bar");
6324 6272
6325 if (!EQ (w->scroll_bar_width, width) 6273 if (w->scroll_bar_width != iwidth
6326 || !EQ (w->vertical_scroll_bar_type, vertical_type)) 6274 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6327 { 6275 {
6328 wset_scroll_bar_width (w, width); 6276 w->scroll_bar_width = iwidth;
6329 wset_vertical_scroll_bar_type (w, vertical_type); 6277 wset_vertical_scroll_bar_type (w, vertical_type);
6278 return w;
6279 }
6280 return NULL;
6281}
6330 6282
6331 adjust_window_margins (w); 6283DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6332 6284 Sset_window_scroll_bars, 2, 4, 0,
6333 clear_glyph_matrix (w->current_matrix); 6285 doc: /* Set width and type of scroll bars of window WINDOW.
6334 w->window_end_valid = 0; 6286WINDOW must be a live window and defaults to the selected one.
6335 6287
6336 ++windows_or_buffers_changed; 6288Second parameter WIDTH specifies the pixel width for the scroll bar;
6337 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6289this is automatically adjusted to a multiple of the frame column width.
6338 } 6290Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6291bar: left, right, or nil.
6292If WIDTH is nil, use the frame's scroll-bar width.
6293If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6294Fourth parameter HORIZONTAL-TYPE is currently unused.
6339 6295
6340 return Qnil; 6296Return t if scroll bars was actually changed and nil otherwise. */)
6297 (Lisp_Object window, Lisp_Object width,
6298 Lisp_Object vertical_type, Lisp_Object horizontal_type)
6299{
6300 struct window *w
6301 = set_window_scroll_bars (decode_live_window (window),
6302 width, vertical_type, horizontal_type);
6303 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6341} 6304}
6342 6305
6343 6306
@@ -6466,38 +6429,6 @@ foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *u
6466 return cont; 6429 return cont;
6467} 6430}
6468 6431
6469
6470/* Freeze or unfreeze the window start of W unless it is a
6471 mini-window or the selected window. FREEZE_P non-null means freeze
6472 the window start. */
6473
6474static int
6475freeze_window_start (struct window *w, void *freeze_p)
6476{
6477 if (MINI_WINDOW_P (w)
6478 || (WINDOWP (selected_window) /* Can be nil in corner cases. */
6479 && (w == XWINDOW (selected_window)
6480 || (MINI_WINDOW_P (XWINDOW (selected_window))
6481 && ! NILP (Vminibuf_scroll_window)
6482 && w == XWINDOW (Vminibuf_scroll_window)))))
6483 freeze_p = NULL;
6484
6485 w->frozen_window_start_p = freeze_p != NULL;
6486 return 1;
6487}
6488
6489
6490/* Freeze or unfreeze the window starts of all leaf windows on frame
6491 F, except the selected window and a mini-window. FREEZE_P non-zero
6492 means freeze the window start. */
6493
6494void
6495freeze_window_starts (struct frame *f, bool freeze_p)
6496{
6497 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6498}
6499
6500
6501/*********************************************************************** 6432/***********************************************************************
6502 Initialization 6433 Initialization
6503 ***********************************************************************/ 6434 ***********************************************************************/
diff --git a/src/window.h b/src/window.h
index 5da6165c48d..c64641825e3 100644
--- a/src/window.h
+++ b/src/window.h
@@ -141,32 +141,10 @@ struct window
141 it yet, or if the frame doesn't have any scroll bars, this is nil. */ 141 it yet, or if the frame doesn't have any scroll bars, this is nil. */
142 Lisp_Object vertical_scroll_bar; 142 Lisp_Object vertical_scroll_bar;
143 143
144 /* Width of left and right marginal areas. A value of nil means
145 no margin. */
146 Lisp_Object left_margin_cols;
147 Lisp_Object right_margin_cols;
148
149 /* Width of left and right fringes.
150 A value of nil or t means use frame values. */
151 Lisp_Object left_fringe_width;
152 Lisp_Object right_fringe_width;
153
154 /* Pixel width of scroll bars.
155 A value of nil or t means use frame values. */
156 Lisp_Object scroll_bar_width;
157
158 /* Type of vertical scroll bar. A value of nil means 144 /* Type of vertical scroll bar. A value of nil means
159 no scroll bar. A value of t means use frame value. */ 145 no scroll bar. A value of t means use frame value. */
160 Lisp_Object vertical_scroll_bar_type; 146 Lisp_Object vertical_scroll_bar_type;
161 147
162 /* Z - the buffer position of the last glyph in the current
163 matrix of W. Only valid if window_end_valid is nonzero. */
164 Lisp_Object window_end_pos;
165
166 /* Glyph matrix row of the last glyph in the current matrix
167 of W. Only valid if window_end_valid is nonzero. */
168 Lisp_Object window_end_vpos;
169
170 /* Display-table to use for displaying chars in this window. 148 /* Display-table to use for displaying chars in this window.
171 Nil means use the buffer's own display-table. */ 149 Nil means use the buffer's own display-table. */
172 Lisp_Object display_table; 150 Lisp_Object display_table;
@@ -269,6 +247,28 @@ struct window
269 /* This is handy for undrawing the cursor. */ 247 /* This is handy for undrawing the cursor. */
270 int phys_cursor_ascent, phys_cursor_height; 248 int phys_cursor_ascent, phys_cursor_height;
271 249
250 /* Width of left and right fringes, in pixels.
251 A value of -1 means use frame values. */
252 int left_fringe_width;
253 int right_fringe_width;
254
255 /* Width of left and right marginal areas in columns.
256 A value of 0 means no margin. */
257 int left_margin_cols;
258 int right_margin_cols;
259
260 /* Pixel width of scroll bars.
261 A value of -1 means use frame values. */
262 int scroll_bar_width;
263
264 /* Z - the buffer position of the last glyph in the current
265 matrix of W. Only valid if window_end_valid is nonzero. */
266 ptrdiff_t window_end_pos;
267
268 /* Glyph matrix row of the last glyph in the current matrix
269 of W. Only valid if window_end_valid is nonzero. */
270 int window_end_vpos;
271
272 /* Non-zero if this window is a minibuffer window. */ 272 /* Non-zero if this window is a minibuffer window. */
273 unsigned mini : 1; 273 unsigned mini : 1;
274 274
@@ -316,11 +316,6 @@ struct window
316 Currently only used for menu bar windows of frames. */ 316 Currently only used for menu bar windows of frames. */
317 unsigned pseudo_window_p : 1; 317 unsigned pseudo_window_p : 1;
318 318
319 /* 1 means the window start of this window is frozen and may not
320 be changed during redisplay. If point is not in the window,
321 accept that. */
322 unsigned frozen_window_start_p : 1;
323
324 /* Non-zero means fringes are drawn outside display margins. 319 /* Non-zero means fringes are drawn outside display margins.
325 Otherwise draw them between margin areas and text. */ 320 Otherwise draw them between margin areas and text. */
326 unsigned fringes_outside_margins : 1; 321 unsigned fringes_outside_margins : 1;
@@ -371,16 +366,6 @@ wset_vertical_scroll_bar (struct window *w, Lisp_Object val)
371 w->vertical_scroll_bar = val; 366 w->vertical_scroll_bar = val;
372} 367}
373WINDOW_INLINE void 368WINDOW_INLINE void
374wset_window_end_pos (struct window *w, Lisp_Object val)
375{
376 w->window_end_pos = val;
377}
378WINDOW_INLINE void
379wset_window_end_vpos (struct window *w, Lisp_Object val)
380{
381 w->window_end_vpos = val;
382}
383WINDOW_INLINE void
384wset_prev_buffers (struct window *w, Lisp_Object val) 369wset_prev_buffers (struct window *w, Lisp_Object val)
385{ 370{
386 w->prev_buffers = val; 371 w->prev_buffers = val;
@@ -605,33 +590,21 @@ wset_next_buffers (struct window *w, Lisp_Object val)
605 590
606/* Width of left margin area in columns. */ 591/* Width of left margin area in columns. */
607 592
608#define WINDOW_LEFT_MARGIN_COLS(W) \ 593#define WINDOW_LEFT_MARGIN_COLS(W) (W->left_margin_cols)
609 (NILP (W->left_margin_cols) \
610 ? 0 \
611 : XINT (W->left_margin_cols))
612 594
613/* Width of right marginal area in columns. */ 595/* Width of right marginal area in columns. */
614 596
615#define WINDOW_RIGHT_MARGIN_COLS(W) \ 597#define WINDOW_RIGHT_MARGIN_COLS(W) (W->right_margin_cols)
616 (NILP (W->right_margin_cols) \
617 ? 0 \
618 : XINT (W->right_margin_cols))
619 598
620/* Width of left margin area in pixels. */ 599/* Width of left margin area in pixels. */
621 600
622#define WINDOW_LEFT_MARGIN_WIDTH(W) \ 601#define WINDOW_LEFT_MARGIN_WIDTH(W) \
623 (NILP (W->left_margin_cols) \ 602 (W->left_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W))
624 ? 0 \
625 : (XINT (W->left_margin_cols) \
626 * WINDOW_FRAME_COLUMN_WIDTH (W)))
627 603
628/* Width of right marginal area in pixels. */ 604/* Width of right marginal area in pixels. */
629 605
630#define WINDOW_RIGHT_MARGIN_WIDTH(W) \ 606#define WINDOW_RIGHT_MARGIN_WIDTH(W) \
631 (NILP (W->right_margin_cols) \ 607 (W->right_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W))
632 ? 0 \
633 : (XINT (W->right_margin_cols) \
634 * WINDOW_FRAME_COLUMN_WIDTH (W)))
635 608
636/* Total width of fringes reserved for drawing truncation bitmaps, 609/* Total width of fringes reserved for drawing truncation bitmaps,
637 continuation bitmaps and alike. The width is in canonical char 610 continuation bitmaps and alike. The width is in canonical char
@@ -640,10 +613,10 @@ wset_next_buffers (struct window *w, Lisp_Object val)
640 able to split windows horizontally nicely. */ 613 able to split windows horizontally nicely. */
641 614
642#define WINDOW_FRINGE_COLS(W) \ 615#define WINDOW_FRINGE_COLS(W) \
643 ((INTEGERP (W->left_fringe_width) \ 616 ((W->left_fringe_width >= 0 \
644 || INTEGERP (W->right_fringe_width)) \ 617 && W->right_fringe_width >= 0) \
645 ? ((WINDOW_LEFT_FRINGE_WIDTH (W) \ 618 ? ((W->left_fringe_width \
646 + WINDOW_RIGHT_FRINGE_WIDTH (W) \ 619 + W->right_fringe_width \
647 + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \ 620 + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
648 / WINDOW_FRAME_COLUMN_WIDTH (W)) \ 621 / WINDOW_FRAME_COLUMN_WIDTH (W)) \
649 : FRAME_FRINGE_COLS (WINDOW_XFRAME (W))) 622 : FRAME_FRINGE_COLS (WINDOW_XFRAME (W)))
@@ -663,13 +636,11 @@ wset_next_buffers (struct window *w, Lisp_Object val)
663/* Pixel-width of the left and right fringe. */ 636/* Pixel-width of the left and right fringe. */
664 637
665#define WINDOW_LEFT_FRINGE_WIDTH(W) \ 638#define WINDOW_LEFT_FRINGE_WIDTH(W) \
666 (INTEGERP (W->left_fringe_width) \ 639 (W->left_fringe_width >= 0 ? W->left_fringe_width \
667 ? XFASTINT (W->left_fringe_width) \
668 : FRAME_LEFT_FRINGE_WIDTH (WINDOW_XFRAME (W))) 640 : FRAME_LEFT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
669 641
670#define WINDOW_RIGHT_FRINGE_WIDTH(W) \ 642#define WINDOW_RIGHT_FRINGE_WIDTH(W) \
671 (INTEGERP (W->right_fringe_width) \ 643 (W->right_fringe_width >= 0 ? W->right_fringe_width \
672 ? XFASTINT (W->right_fringe_width) \
673 : FRAME_RIGHT_FRINGE_WIDTH (WINDOW_XFRAME (W))) 644 : FRAME_RIGHT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
674 645
675/* Total width of fringes in pixels. */ 646/* Total width of fringes in pixels. */
@@ -714,8 +685,7 @@ wset_next_buffers (struct window *w, Lisp_Object val)
714 nonzero. */ 685 nonzero. */
715 686
716#define WINDOW_CONFIG_SCROLL_BAR_WIDTH(w) \ 687#define WINDOW_CONFIG_SCROLL_BAR_WIDTH(w) \
717 (INTEGERP (w->scroll_bar_width) \ 688 (w->scroll_bar_width >= 0 ? w->scroll_bar_width \
718 ? XFASTINT (w->scroll_bar_width) \
719 : FRAME_CONFIG_SCROLL_BAR_WIDTH (WINDOW_XFRAME (w))) 689 : FRAME_CONFIG_SCROLL_BAR_WIDTH (WINDOW_XFRAME (w)))
720 690
721/* Width that a scroll bar in window W should have, if there is one. 691/* Width that a scroll bar in window W should have, if there is one.
@@ -723,8 +693,8 @@ wset_next_buffers (struct window *w, Lisp_Object val)
723 this is still nonzero. */ 693 this is still nonzero. */
724 694
725#define WINDOW_CONFIG_SCROLL_BAR_COLS(w) \ 695#define WINDOW_CONFIG_SCROLL_BAR_COLS(w) \
726 (INTEGERP (w->scroll_bar_width) \ 696 (w->scroll_bar_width >= 0 \
727 ? ((XFASTINT (w->scroll_bar_width) \ 697 ? ((w->scroll_bar_width \
728 + WINDOW_FRAME_COLUMN_WIDTH (w) - 1) \ 698 + WINDOW_FRAME_COLUMN_WIDTH (w) - 1) \
729 / WINDOW_FRAME_COLUMN_WIDTH (w)) \ 699 / WINDOW_FRAME_COLUMN_WIDTH (w)) \
730 : FRAME_CONFIG_SCROLL_BAR_COLS (WINDOW_XFRAME (w))) 700 : FRAME_CONFIG_SCROLL_BAR_COLS (WINDOW_XFRAME (w)))
@@ -847,13 +817,25 @@ wset_next_buffers (struct window *w, Lisp_Object val)
847#define WINDOW_TEXT_TO_FRAME_PIXEL_X(W, X) \ 817#define WINDOW_TEXT_TO_FRAME_PIXEL_X(W, X) \
848 (window_box_left ((W), TEXT_AREA) + (X)) 818 (window_box_left ((W), TEXT_AREA) + (X))
849 819
850/* This is the window in which the terminal's cursor should 820/* Nonzero if the background of the window W's fringe that is adjacent to
851 be left when nothing is being done with it. This must 821 a scroll bar is extended to the gap between the fringe and the bar. */
852 always be a leaf window, and its buffer is selected by 822
853 the top level editing loop at the end of each command. 823#define WINDOW_FRINGE_EXTENDED_P(w) \
824 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) \
825 ? (WINDOW_LEFTMOST_P (w) \
826 && WINDOW_LEFT_FRINGE_WIDTH (w) \
827 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) \
828 || WINDOW_LEFT_MARGIN_COLS (w) == 0)) \
829 : (WINDOW_RIGHTMOST_P (w) \
830 && WINDOW_RIGHT_FRINGE_WIDTH (w) \
831 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) \
832 || WINDOW_RIGHT_MARGIN_COLS (w) == 0)))
854 833
855 This value is always the same as 834/* This is the window in which the terminal's cursor should be left when
856 FRAME_SELECTED_WINDOW (selected_frame). */ 835 nothing is being done with it. This must always be a leaf window, and its
836 buffer is selected by the top level editing loop at the end of each command.
837
838 This value is always the same as FRAME_SELECTED_WINDOW (selected_frame). */
857 839
858extern Lisp_Object selected_window; 840extern Lisp_Object selected_window;
859 841
@@ -888,7 +870,6 @@ extern Lisp_Object window_from_coordinates (struct frame *, int, int,
888extern void resize_frame_windows (struct frame *, int, bool); 870extern void resize_frame_windows (struct frame *, int, bool);
889extern void restore_window_configuration (Lisp_Object); 871extern void restore_window_configuration (Lisp_Object);
890extern void delete_all_child_windows (Lisp_Object); 872extern void delete_all_child_windows (Lisp_Object);
891extern void freeze_window_starts (struct frame *, bool);
892extern void grow_mini_window (struct window *, int); 873extern void grow_mini_window (struct window *, int);
893extern void shrink_mini_window (struct window *); 874extern void shrink_mini_window (struct window *);
894extern int window_relative_x_coord (struct window *, enum window_part, int); 875extern int window_relative_x_coord (struct window *, enum window_part, int);
@@ -925,10 +906,6 @@ extern int update_mode_lines;
925 906
926extern int windows_or_buffers_changed; 907extern int windows_or_buffers_changed;
927 908
928/* Nonzero means a frame's cursor type has been changed. */
929
930extern int cursor_type_changed;
931
932/* If *ROWS or *COLS are too small a size for FRAME, set them to the 909/* If *ROWS or *COLS are too small a size for FRAME, set them to the
933 minimum allowable size. */ 910 minimum allowable size. */
934 911
@@ -973,6 +950,7 @@ extern void replace_buffer_in_windows (Lisp_Object);
973extern void replace_buffer_in_windows_safely (Lisp_Object); 950extern void replace_buffer_in_windows_safely (Lisp_Object);
974/* This looks like a setter, but it is a bit special. */ 951/* This looks like a setter, but it is a bit special. */
975extern void wset_buffer (struct window *, Lisp_Object); 952extern void wset_buffer (struct window *, Lisp_Object);
953extern bool window_outdated (struct window *);
976extern void init_window_once (void); 954extern void init_window_once (void);
977extern void init_window (void); 955extern void init_window (void);
978extern void syms_of_window (void); 956extern void syms_of_window (void);
diff --git a/src/xdisp.c b/src/xdisp.c
index 1da7de5759c..ea1cd7dd2bc 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -524,7 +524,7 @@ int windows_or_buffers_changed;
524 524
525/* Nonzero means a frame's cursor type has been changed. */ 525/* Nonzero means a frame's cursor type has been changed. */
526 526
527int cursor_type_changed; 527static int cursor_type_changed;
528 528
529/* Nonzero after display_mode_line if %l was used and it displayed a 529/* Nonzero after display_mode_line if %l was used and it displayed a
530 line number. */ 530 line number. */
@@ -804,7 +804,6 @@ static void pint2str (char *, int, ptrdiff_t);
804static void pint2hrstr (char *, int, ptrdiff_t); 804static void pint2hrstr (char *, int, ptrdiff_t);
805static struct text_pos run_window_scroll_functions (Lisp_Object, 805static struct text_pos run_window_scroll_functions (Lisp_Object,
806 struct text_pos); 806 struct text_pos);
807static void reconsider_clip_changes (struct window *, struct buffer *);
808static int text_outside_line_unchanged_p (struct window *, 807static int text_outside_line_unchanged_p (struct window *,
809 ptrdiff_t, ptrdiff_t); 808 ptrdiff_t, ptrdiff_t);
810static void store_mode_line_noprop_char (char); 809static void store_mode_line_noprop_char (char);
@@ -983,22 +982,18 @@ window_box_width (struct window *w, int area)
983 982
984 if (area == TEXT_AREA) 983 if (area == TEXT_AREA)
985 { 984 {
986 if (INTEGERP (w->left_margin_cols)) 985 cols -= max (0, w->left_margin_cols);
987 cols -= XFASTINT (w->left_margin_cols); 986 cols -= max (0, w->right_margin_cols);
988 if (INTEGERP (w->right_margin_cols))
989 cols -= XFASTINT (w->right_margin_cols);
990 pixels = -WINDOW_TOTAL_FRINGE_WIDTH (w); 987 pixels = -WINDOW_TOTAL_FRINGE_WIDTH (w);
991 } 988 }
992 else if (area == LEFT_MARGIN_AREA) 989 else if (area == LEFT_MARGIN_AREA)
993 { 990 {
994 cols = (INTEGERP (w->left_margin_cols) 991 cols = max (0, w->left_margin_cols);
995 ? XFASTINT (w->left_margin_cols) : 0);
996 pixels = 0; 992 pixels = 0;
997 } 993 }
998 else if (area == RIGHT_MARGIN_AREA) 994 else if (area == RIGHT_MARGIN_AREA)
999 { 995 {
1000 cols = (INTEGERP (w->right_margin_cols) 996 cols = max (0, w->right_margin_cols);
1001 ? XFASTINT (w->right_margin_cols) : 0);
1002 pixels = 0; 997 pixels = 0;
1003 } 998 }
1004 } 999 }
@@ -1854,7 +1849,7 @@ estimate_mode_line_height (struct frame *f, enum face_id face_id)
1854 not force the value into range. */ 1849 not force the value into range. */
1855 1850
1856void 1851void
1857pixel_to_glyph_coords (FRAME_PTR f, register int pix_x, register int pix_y, 1852pixel_to_glyph_coords (struct frame *f, register int pix_x, register int pix_y,
1858 int *x, int *y, NativeRectangle *bounds, int noclip) 1853 int *x, int *y, NativeRectangle *bounds, int noclip)
1859{ 1854{
1860 1855
@@ -2466,7 +2461,16 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2466 2461
2467#endif /* HAVE_WINDOW_SYSTEM */ 2462#endif /* HAVE_WINDOW_SYSTEM */
2468 2463
2469 2464static void
2465adjust_window_ends (struct window *w, struct glyph_row *row, bool current)
2466{
2467 eassert (w);
2468 w->window_end_pos = Z - MATRIX_ROW_END_CHARPOS (row);
2469 w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row);
2470 w->window_end_vpos
2471 = MATRIX_ROW_VPOS (row, current ? w->current_matrix : w->desired_matrix);
2472}
2473
2470/*********************************************************************** 2474/***********************************************************************
2471 Lisp form evaluation 2475 Lisp form evaluation
2472 ***********************************************************************/ 2476 ***********************************************************************/
@@ -2602,8 +2606,7 @@ check_window_end (struct window *w)
2602 if (!MINI_WINDOW_P (w) && w->window_end_valid) 2606 if (!MINI_WINDOW_P (w) && w->window_end_valid)
2603 { 2607 {
2604 struct glyph_row *row; 2608 struct glyph_row *row;
2605 eassert ((row = MATRIX_ROW (w->current_matrix, 2609 eassert ((row = MATRIX_ROW (w->current_matrix, w->window_end_vpos),
2606 XFASTINT (w->window_end_vpos)),
2607 !row->enabled_p 2610 !row->enabled_p
2608 || MATRIX_ROW_DISPLAYS_TEXT_P (row) 2611 || MATRIX_ROW_DISPLAYS_TEXT_P (row)
2609 || MATRIX_ROW_VPOS (row, w->current_matrix) == 0)); 2612 || MATRIX_ROW_VPOS (row, w->current_matrix) == 0));
@@ -5346,7 +5349,7 @@ handle_composition_prop (struct it *it)
5346 composition (in the case that the composition is from the current 5349 composition (in the case that the composition is from the current
5347 buffer), draw a glyph composed from the composition components. */ 5350 buffer), draw a glyph composed from the composition components. */
5348 if (find_composition (pos, -1, &start, &end, &prop, string) 5351 if (find_composition (pos, -1, &start, &end, &prop, string)
5349 && COMPOSITION_VALID_P (start, end, prop) 5352 && composition_valid_p (start, end, prop)
5350 && (STRINGP (it->string) || (PT <= start || PT >= end))) 5353 && (STRINGP (it->string) || (PT <= start || PT >= end)))
5351 { 5354 {
5352 if (start < pos) 5355 if (start < pos)
@@ -5509,8 +5512,8 @@ next_overlay_string (struct it *it)
5509static int 5512static int
5510compare_overlay_entries (const void *e1, const void *e2) 5513compare_overlay_entries (const void *e1, const void *e2)
5511{ 5514{
5512 struct overlay_entry *entry1 = (struct overlay_entry *) e1; 5515 struct overlay_entry const *entry1 = e1;
5513 struct overlay_entry *entry2 = (struct overlay_entry *) e2; 5516 struct overlay_entry const *entry2 = e2;
5514 int result; 5517 int result;
5515 5518
5516 if (entry1->after_string_p != entry2->after_string_p) 5519 if (entry1->after_string_p != entry2->after_string_p)
@@ -7458,6 +7461,8 @@ static int
7458next_element_from_display_vector (struct it *it) 7461next_element_from_display_vector (struct it *it)
7459{ 7462{
7460 Lisp_Object gc; 7463 Lisp_Object gc;
7464 int prev_face_id = it->face_id;
7465 int next_face_id;
7461 7466
7462 /* Precondition. */ 7467 /* Precondition. */
7463 eassert (it->dpvec && it->current.dpvec_index >= 0); 7468 eassert (it->dpvec && it->current.dpvec_index >= 0);
@@ -7470,6 +7475,8 @@ next_element_from_display_vector (struct it *it)
7470 7475
7471 if (GLYPH_CODE_P (gc)) 7476 if (GLYPH_CODE_P (gc))
7472 { 7477 {
7478 struct face *this_face, *prev_face, *next_face;
7479
7473 it->c = GLYPH_CODE_CHAR (gc); 7480 it->c = GLYPH_CODE_CHAR (gc);
7474 it->len = CHAR_BYTES (it->c); 7481 it->len = CHAR_BYTES (it->c);
7475 7482
@@ -7485,6 +7492,41 @@ next_element_from_display_vector (struct it *it)
7485 it->face_id = merge_faces (it->f, Qt, lface_id, 7492 it->face_id = merge_faces (it->f, Qt, lface_id,
7486 it->saved_face_id); 7493 it->saved_face_id);
7487 } 7494 }
7495
7496 /* Glyphs in the display vector could have the box face, so we
7497 need to set the related flags in the iterator, as
7498 appropriate. */
7499 this_face = FACE_FROM_ID (it->f, it->face_id);
7500 prev_face = FACE_FROM_ID (it->f, prev_face_id);
7501
7502 /* Is this character the first character of a box-face run? */
7503 it->start_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
7504 && (!prev_face
7505 || prev_face->box == FACE_NO_BOX));
7506
7507 /* For the last character of the box-face run, we need to look
7508 either at the next glyph from the display vector, or at the
7509 face we saw before the display vector. */
7510 next_face_id = it->saved_face_id;
7511 if (it->current.dpvec_index < it->dpend - it->dpvec - 1)
7512 {
7513 if (it->dpvec_face_id >= 0)
7514 next_face_id = it->dpvec_face_id;
7515 else
7516 {
7517 int lface_id =
7518 GLYPH_CODE_FACE (it->dpvec[it->current.dpvec_index + 1]);
7519
7520 if (lface_id > 0)
7521 next_face_id = merge_faces (it->f, Qt, lface_id,
7522 it->saved_face_id);
7523 }
7524 }
7525 next_face = FACE_FROM_ID (it->f, next_face_id);
7526 it->end_of_box_run_p = (this_face && this_face->box != FACE_NO_BOX
7527 && (!next_face
7528 || next_face->box == FACE_NO_BOX));
7529 it->face_box_p = this_face && this_face->box != FACE_NO_BOX;
7488 } 7530 }
7489 else 7531 else
7490 /* Display table entry is invalid. Return a space. */ 7532 /* Display table entry is invalid. Return a space. */
@@ -9059,7 +9101,7 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
9059 && it->current_x == it->last_visible_x - 1 9101 && it->current_x == it->last_visible_x - 1
9060 && it->c != '\n' 9102 && it->c != '\n'
9061 && it->c != '\t' 9103 && it->c != '\t'
9062 && it->vpos < XFASTINT (it->w->window_end_vpos)) 9104 && it->vpos < it->w->window_end_vpos)
9063 { 9105 {
9064 it->continuation_lines_width += it->current_x; 9106 it->continuation_lines_width += it->current_x;
9065 it->current_x = it->hpos = it->max_ascent = it->max_descent = 0; 9107 it->current_x = it->hpos = it->max_ascent = it->max_descent = 0;
@@ -9790,7 +9832,7 @@ message3_nolog (Lisp_Object m)
9790void 9832void
9791message1 (const char *m) 9833message1 (const char *m)
9792{ 9834{
9793 message3 (m ? make_unibyte_string (m, strlen (m)) : Qnil); 9835 message3 (m ? build_unibyte_string (m) : Qnil);
9794} 9836}
9795 9837
9796 9838
@@ -9799,7 +9841,7 @@ message1 (const char *m)
9799void 9841void
9800message1_nolog (const char *m) 9842message1_nolog (const char *m)
9801{ 9843{
9802 message3_nolog (m ? make_unibyte_string (m, strlen (m)) : Qnil); 9844 message3_nolog (m ? build_unibyte_string (m) : Qnil);
9803} 9845}
9804 9846
9805/* Display a message M which contains a single %s 9847/* Display a message M which contains a single %s
@@ -9909,7 +9951,7 @@ vmessage (const char *m, va_list ap)
9909 ptrdiff_t maxsize = FRAME_MESSAGE_BUF_SIZE (f); 9951 ptrdiff_t maxsize = FRAME_MESSAGE_BUF_SIZE (f);
9910 char *message_buf = alloca (maxsize + 1); 9952 char *message_buf = alloca (maxsize + 1);
9911 9953
9912 len = doprnt (message_buf, maxsize, m, (char *)0, ap); 9954 len = doprnt (message_buf, maxsize, m, 0, ap);
9913 9955
9914 message3 (make_string (message_buf, len)); 9956 message3 (make_string (message_buf, len));
9915 } 9957 }
@@ -10461,7 +10503,8 @@ resize_mini_window (struct window *w, int exact_p)
10461 if (height > WINDOW_TOTAL_LINES (w)) 10503 if (height > WINDOW_TOTAL_LINES (w))
10462 { 10504 {
10463 int old_height = WINDOW_TOTAL_LINES (w); 10505 int old_height = WINDOW_TOTAL_LINES (w);
10464 freeze_window_starts (f, 1); 10506
10507 FRAME_WINDOWS_FROZEN (f) = 1;
10465 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w)); 10508 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w));
10466 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height; 10509 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height;
10467 } 10510 }
@@ -10469,7 +10512,8 @@ resize_mini_window (struct window *w, int exact_p)
10469 && (exact_p || BEGV == ZV)) 10512 && (exact_p || BEGV == ZV))
10470 { 10513 {
10471 int old_height = WINDOW_TOTAL_LINES (w); 10514 int old_height = WINDOW_TOTAL_LINES (w);
10472 freeze_window_starts (f, 0); 10515
10516 FRAME_WINDOWS_FROZEN (f) = 0;
10473 shrink_mini_window (w); 10517 shrink_mini_window (w);
10474 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height; 10518 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height;
10475 } 10519 }
@@ -10480,19 +10524,21 @@ resize_mini_window (struct window *w, int exact_p)
10480 if (height > WINDOW_TOTAL_LINES (w)) 10524 if (height > WINDOW_TOTAL_LINES (w))
10481 { 10525 {
10482 int old_height = WINDOW_TOTAL_LINES (w); 10526 int old_height = WINDOW_TOTAL_LINES (w);
10483 freeze_window_starts (f, 1); 10527
10528 FRAME_WINDOWS_FROZEN (f) = 1;
10484 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w)); 10529 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w));
10485 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height; 10530 window_height_changed_p = WINDOW_TOTAL_LINES (w) != old_height;
10486 } 10531 }
10487 else if (height < WINDOW_TOTAL_LINES (w)) 10532 else if (height < WINDOW_TOTAL_LINES (w))
10488 { 10533 {
10489 int old_height = WINDOW_TOTAL_LINES (w); 10534 int old_height = WINDOW_TOTAL_LINES (w);
10490 freeze_window_starts (f, 0); 10535
10536 FRAME_WINDOWS_FROZEN (f) = 0;
10491 shrink_mini_window (w); 10537 shrink_mini_window (w);
10492 10538
10493 if (height) 10539 if (height)
10494 { 10540 {
10495 freeze_window_starts (f, 1); 10541 FRAME_WINDOWS_FROZEN (f) = 1;
10496 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w)); 10542 grow_mini_window (w, height - WINDOW_TOTAL_LINES (w));
10497 } 10543 }
10498 10544
@@ -10850,17 +10896,6 @@ buffer_shared_and_changed (void)
10850 && UNCHANGED_MODIFIED < MODIFF); 10896 && UNCHANGED_MODIFIED < MODIFF);
10851} 10897}
10852 10898
10853/* Nonzero if W doesn't reflect the actual state of current buffer due
10854 to its text or overlays change. FIXME: this may be called when
10855 XBUFFER (w->contents) != current_buffer, which looks suspicious. */
10856
10857static int
10858window_outdated (struct window *w)
10859{
10860 return (w->last_modified < MODIFF
10861 || w->last_overlay_modified < OVERLAY_MODIFF);
10862}
10863
10864/* Nonzero if W's buffer was changed but not saved or Transient Mark mode 10899/* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10865 is enabled and mark of W's buffer was changed since last W's update. */ 10900 is enabled and mark of W's buffer was changed since last W's update. */
10866 10901
@@ -10886,6 +10921,31 @@ mode_line_update_needed (struct window *w)
10886 && (w->column_number_displayed != current_column ())); 10921 && (w->column_number_displayed != current_column ()));
10887} 10922}
10888 10923
10924/* Nonzero if window start of W is frozen and may not be changed during
10925 redisplay. */
10926
10927static bool
10928window_frozen_p (struct window *w)
10929{
10930 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w))))
10931 {
10932 Lisp_Object window;
10933
10934 XSETWINDOW (window, w);
10935 if (MINI_WINDOW_P (w))
10936 return 0;
10937 else if (EQ (window, selected_window))
10938 return 0;
10939 else if (MINI_WINDOW_P (XWINDOW (selected_window))
10940 && EQ (window, Vminibuf_scroll_window))
10941 /* This special window can't be frozen too. */
10942 return 0;
10943 else
10944 return 1;
10945 }
10946 return 0;
10947}
10948
10889/*********************************************************************** 10949/***********************************************************************
10890 Mode Lines and Frame Titles 10950 Mode Lines and Frame Titles
10891 ***********************************************************************/ 10951 ***********************************************************************/
@@ -11181,7 +11241,18 @@ prepare_menu_bars (void)
11181 { 11241 {
11182 f = XFRAME (frame); 11242 f = XFRAME (frame);
11183 if (!EQ (frame, tooltip_frame) 11243 if (!EQ (frame, tooltip_frame)
11184 && (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))) 11244 && (FRAME_ICONIFIED_P (f)
11245 || FRAME_VISIBLE_P (f) == 1
11246 /* Exclude TTY frames that are obscured because they
11247 are not the top frame on their console. This is
11248 because x_consider_frame_title actually switches
11249 to the frame, which for TTY frames means it is
11250 marked as garbaged, and will be completely
11251 redrawn on the next redisplay cycle. This causes
11252 TTY frames to be completely redrawn, when there
11253 are more than one of them, even though nothing
11254 should be changed on display. */
11255 || (FRAME_VISIBLE_P (f) == 2 && FRAME_WINDOW_P (f))))
11185 x_consider_frame_title (frame); 11256 x_consider_frame_title (frame);
11186 } 11257 }
11187 } 11258 }
@@ -11386,7 +11457,7 @@ struct cursor_pos output_cursor;
11386 11457
11387/* EXPORT: 11458/* EXPORT:
11388 Set the global variable output_cursor to CURSOR. All cursor 11459 Set the global variable output_cursor to CURSOR. All cursor
11389 positions are relative to updated_window. */ 11460 positions are relative to currently updated window. */
11390 11461
11391void 11462void
11392set_output_cursor (struct cursor_pos *cursor) 11463set_output_cursor (struct cursor_pos *cursor)
@@ -11401,41 +11472,24 @@ set_output_cursor (struct cursor_pos *cursor)
11401/* EXPORT for RIF: 11472/* EXPORT for RIF:
11402 Set a nominal cursor position. 11473 Set a nominal cursor position.
11403 11474
11404 HPOS and VPOS are column/row positions in a window glyph matrix. X 11475 HPOS and VPOS are column/row positions in a window glyph matrix.
11405 and Y are window text area relative pixel positions. 11476 X and Y are window text area relative pixel positions.
11406 11477
11407 If this is done during an update, updated_window will contain the 11478 This is always done during window update, so the position is the
11408 window that is being updated and the position is the future output 11479 future output cursor position for currently updated window W.
11409 cursor position for that window. If updated_window is null, use 11480 NOTE: W is used only to check whether this function is called
11410 selected_window and display the cursor at the given position. */ 11481 in a consistent manner via the redisplay interface. */
11411 11482
11412void 11483void
11413x_cursor_to (int vpos, int hpos, int y, int x) 11484x_cursor_to (struct window *w, int vpos, int hpos, int y, int x)
11414{ 11485{
11415 struct window *w; 11486 eassert (w);
11416
11417 /* If updated_window is not set, work on selected_window. */
11418 if (updated_window)
11419 w = updated_window;
11420 else
11421 w = XWINDOW (selected_window);
11422 11487
11423 /* Set the output cursor. */ 11488 /* Set the output cursor. */
11424 output_cursor.hpos = hpos; 11489 output_cursor.hpos = hpos;
11425 output_cursor.vpos = vpos; 11490 output_cursor.vpos = vpos;
11426 output_cursor.x = x; 11491 output_cursor.x = x;
11427 output_cursor.y = y; 11492 output_cursor.y = y;
11428
11429 /* If not called as part of an update, really display the cursor.
11430 This will also set the cursor position of W. */
11431 if (updated_window == NULL)
11432 {
11433 block_input ();
11434 display_and_set_cursor (w, 1, hpos, vpos, x, y);
11435 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional)
11436 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11437 unblock_input ();
11438 }
11439} 11493}
11440 11494
11441#endif /* HAVE_WINDOW_SYSTEM */ 11495#endif /* HAVE_WINDOW_SYSTEM */
@@ -11449,7 +11503,7 @@ x_cursor_to (int vpos, int hpos, int y, int x)
11449 11503
11450/* Where the mouse was last time we reported a mouse event. */ 11504/* Where the mouse was last time we reported a mouse event. */
11451 11505
11452FRAME_PTR last_mouse_frame; 11506struct frame *last_mouse_frame;
11453 11507
11454/* Tool-bar item index of the item on which a mouse button was pressed 11508/* Tool-bar item index of the item on which a mouse button was pressed
11455 or -1. */ 11509 or -1. */
@@ -12852,7 +12906,7 @@ check_point_in_composition (struct buffer *prev_buf, ptrdiff_t prev_pt,
12852 12906
12853 if (prev_pt > BUF_BEGV (buf) && prev_pt < BUF_ZV (buf) 12907 if (prev_pt > BUF_BEGV (buf) && prev_pt < BUF_ZV (buf)
12854 && find_composition (prev_pt, -1, &start, &end, &prop, buffer) 12908 && find_composition (prev_pt, -1, &start, &end, &prop, buffer)
12855 && COMPOSITION_VALID_P (start, end, prop) 12909 && composition_valid_p (start, end, prop)
12856 && start < prev_pt && end > prev_pt) 12910 && start < prev_pt && end > prev_pt)
12857 /* The last point was within the composition. Return 1 iff 12911 /* The last point was within the composition. Return 1 iff
12858 point moved out of the composition. */ 12912 point moved out of the composition. */
@@ -12862,17 +12916,17 @@ check_point_in_composition (struct buffer *prev_buf, ptrdiff_t prev_pt,
12862 /* Check a composition at the current point. */ 12916 /* Check a composition at the current point. */
12863 return (pt > BUF_BEGV (buf) && pt < BUF_ZV (buf) 12917 return (pt > BUF_BEGV (buf) && pt < BUF_ZV (buf)
12864 && find_composition (pt, -1, &start, &end, &prop, buffer) 12918 && find_composition (pt, -1, &start, &end, &prop, buffer)
12865 && COMPOSITION_VALID_P (start, end, prop) 12919 && composition_valid_p (start, end, prop)
12866 && start < pt && end > pt); 12920 && start < pt && end > pt);
12867} 12921}
12868 12922
12869 12923/* Reconsider the clip changes of buffer which is displayed in W. */
12870/* Reconsider the setting of B->clip_changed which is displayed
12871 in window W. */
12872 12924
12873static void 12925static void
12874reconsider_clip_changes (struct window *w, struct buffer *b) 12926reconsider_clip_changes (struct window *w)
12875{ 12927{
12928 struct buffer *b = XBUFFER (w->contents);
12929
12876 if (b->clip_changed 12930 if (b->clip_changed
12877 && w->window_end_valid 12931 && w->window_end_valid
12878 && w->current_matrix->buffer == b 12932 && w->current_matrix->buffer == b
@@ -12885,24 +12939,17 @@ reconsider_clip_changes (struct window *w, struct buffer *b)
12885 we set b->clip_changed to 1 to force updating the screen. If 12939 we set b->clip_changed to 1 to force updating the screen. If
12886 b->clip_changed has already been set to 1, we can skip this 12940 b->clip_changed has already been set to 1, we can skip this
12887 check. */ 12941 check. */
12888 if (!b->clip_changed && BUFFERP (w->contents) && w->window_end_valid) 12942 if (!b->clip_changed && w->window_end_valid)
12889 { 12943 {
12890 ptrdiff_t pt; 12944 ptrdiff_t pt = (w == XWINDOW (selected_window)
12945 ? PT : marker_position (w->pointm));
12891 12946
12892 if (w == XWINDOW (selected_window)) 12947 if ((w->current_matrix->buffer != b || pt != w->last_point)
12893 pt = PT;
12894 else
12895 pt = marker_position (w->pointm);
12896
12897 if ((w->current_matrix->buffer != XBUFFER (w->contents)
12898 || pt != w->last_point)
12899 && check_point_in_composition (w->current_matrix->buffer, 12948 && check_point_in_composition (w->current_matrix->buffer,
12900 w->last_point, 12949 w->last_point, b, pt))
12901 XBUFFER (w->contents), pt))
12902 b->clip_changed = 1; 12950 b->clip_changed = 1;
12903 } 12951 }
12904} 12952}
12905
12906 12953
12907#define STOP_POLLING \ 12954#define STOP_POLLING \
12908do { if (! polling_stopped_here) stop_polling (); \ 12955do { if (! polling_stopped_here) stop_polling (); \
@@ -12923,10 +12970,10 @@ redisplay_internal (void)
12923 struct window *sw; 12970 struct window *sw;
12924 struct frame *fr; 12971 struct frame *fr;
12925 int pending; 12972 int pending;
12926 int must_finish = 0; 12973 bool must_finish = 0, match_p;
12927 struct text_pos tlbufpos, tlendpos; 12974 struct text_pos tlbufpos, tlendpos;
12928 int number_of_visible_frames; 12975 int number_of_visible_frames;
12929 ptrdiff_t count, count1; 12976 ptrdiff_t count;
12930 struct frame *sf; 12977 struct frame *sf;
12931 int polling_stopped_here = 0; 12978 int polling_stopped_here = 0;
12932 Lisp_Object tail, frame; 12979 Lisp_Object tail, frame;
@@ -12983,7 +13030,6 @@ redisplay_internal (void)
12983 sw = w; 13030 sw = w;
12984 13031
12985 pending = 0; 13032 pending = 0;
12986 reconsider_clip_changes (w, current_buffer);
12987 last_escape_glyph_frame = NULL; 13033 last_escape_glyph_frame = NULL;
12988 last_escape_glyph_face_id = (1 << FACE_ID_BITS); 13034 last_escape_glyph_face_id = (1 << FACE_ID_BITS);
12989 last_glyphless_glyph_frame = NULL; 13035 last_glyphless_glyph_frame = NULL;
@@ -13038,10 +13084,7 @@ redisplay_internal (void)
13038 /* do_pending_window_change could change the selected_window due to 13084 /* do_pending_window_change could change the selected_window due to
13039 frame resizing which makes the selected window too small. */ 13085 frame resizing which makes the selected window too small. */
13040 if (WINDOWP (selected_window) && (w = XWINDOW (selected_window)) != sw) 13086 if (WINDOWP (selected_window) && (w = XWINDOW (selected_window)) != sw)
13041 { 13087 sw = w;
13042 sw = w;
13043 reconsider_clip_changes (w, current_buffer);
13044 }
13045 13088
13046 /* Clear frames marked as garbaged. */ 13089 /* Clear frames marked as garbaged. */
13047 clear_garbaged_frames (); 13090 clear_garbaged_frames ();
@@ -13053,22 +13096,31 @@ redisplay_internal (void)
13053 if (windows_or_buffers_changed) 13096 if (windows_or_buffers_changed)
13054 update_mode_lines++; 13097 update_mode_lines++;
13055 13098
13056 /* Detect case that we need to write or remove a star in the mode line. */ 13099 reconsider_clip_changes (w);
13057 if ((SAVE_MODIFF < MODIFF) != w->last_had_star) 13100
13101 /* In most cases selected window displays current buffer. */
13102 match_p = XBUFFER (w->contents) == current_buffer;
13103 if (match_p)
13058 { 13104 {
13059 w->update_mode_line = 1; 13105 ptrdiff_t count1;
13060 if (buffer_shared_and_changed ())
13061 update_mode_lines++;
13062 }
13063 13106
13064 /* Avoid invocation of point motion hooks by `current_column' below. */ 13107 /* Detect case that we need to write or remove a star in the mode line. */
13065 count1 = SPECPDL_INDEX (); 13108 if ((SAVE_MODIFF < MODIFF) != w->last_had_star)
13066 specbind (Qinhibit_point_motion_hooks, Qt); 13109 {
13110 w->update_mode_line = 1;
13111 if (buffer_shared_and_changed ())
13112 update_mode_lines++;
13113 }
13067 13114
13068 if (mode_line_update_needed (w)) 13115 /* Avoid invocation of point motion hooks by `current_column' below. */
13069 w->update_mode_line = 1; 13116 count1 = SPECPDL_INDEX ();
13117 specbind (Qinhibit_point_motion_hooks, Qt);
13070 13118
13071 unbind_to (count1, Qnil); 13119 if (mode_line_update_needed (w))
13120 w->update_mode_line = 1;
13121
13122 unbind_to (count1, Qnil);
13123 }
13072 13124
13073 consider_all_windows_p = (update_mode_lines 13125 consider_all_windows_p = (update_mode_lines
13074 || buffer_shared_and_changed () 13126 || buffer_shared_and_changed ()
@@ -13167,7 +13219,7 @@ redisplay_internal (void)
13167 && !FRAME_OBSCURED_P (XFRAME (w->frame)) 13219 && !FRAME_OBSCURED_P (XFRAME (w->frame))
13168 /* Make sure recorded data applies to current buffer, etc. */ 13220 /* Make sure recorded data applies to current buffer, etc. */
13169 && this_line_buffer == current_buffer 13221 && this_line_buffer == current_buffer
13170 && current_buffer == XBUFFER (w->contents) 13222 && match_p
13171 && !w->force_start 13223 && !w->force_start
13172 && !w->optional_new_start 13224 && !w->optional_new_start
13173 /* Point must be on the line that we have info recorded about. */ 13225 /* Point must be on the line that we have info recorded about. */
@@ -13263,12 +13315,12 @@ redisplay_internal (void)
13263 adjusted. */ 13315 adjusted. */
13264 if (MATRIX_ROW_DISPLAYS_TEXT_P (it.glyph_row - 1)) 13316 if (MATRIX_ROW_DISPLAYS_TEXT_P (it.glyph_row - 1))
13265 { 13317 {
13266 if (XFASTINT (w->window_end_vpos) < this_line_vpos) 13318 if (w->window_end_vpos < this_line_vpos)
13267 wset_window_end_vpos (w, make_number (this_line_vpos)); 13319 w->window_end_vpos = this_line_vpos;
13268 } 13320 }
13269 else if (XFASTINT (w->window_end_vpos) == this_line_vpos 13321 else if (w->window_end_vpos == this_line_vpos
13270 && this_line_vpos > 0) 13322 && this_line_vpos > 0)
13271 wset_window_end_vpos (w, make_number (this_line_vpos - 1)); 13323 w->window_end_vpos = this_line_vpos - 1;
13272 w->window_end_valid = 0; 13324 w->window_end_valid = 0;
13273 13325
13274 /* Update hint: No need to try to scroll in update_window. */ 13326 /* Update hint: No need to try to scroll in update_window. */
@@ -14458,8 +14510,7 @@ run_window_scroll_functions (Lisp_Object window, struct text_pos startp)
14458 struct window *w = XWINDOW (window); 14510 struct window *w = XWINDOW (window);
14459 SET_MARKER_FROM_TEXT_POS (w->start, startp); 14511 SET_MARKER_FROM_TEXT_POS (w->start, startp);
14460 14512
14461 if (current_buffer != XBUFFER (w->contents)) 14513 eassert (current_buffer == XBUFFER (w->contents));
14462 emacs_abort ();
14463 14514
14464 if (!NILP (Vwindow_scroll_functions)) 14515 if (!NILP (Vwindow_scroll_functions))
14465 { 14516 {
@@ -14900,7 +14951,25 @@ compute_window_start_on_continuation_line (struct window *w)
14900 { 14951 {
14901 min_distance = distance; 14952 min_distance = distance;
14902 pos = it.current.pos; 14953 pos = it.current.pos;
14903 move_it_by_lines (&it, 1); 14954 if (it.line_wrap == WORD_WRAP)
14955 {
14956 /* Under WORD_WRAP, move_it_by_lines is likely to
14957 overshoot and stop not at the first, but the
14958 second character from the left margin. So in
14959 that case, we need a more tight control on the X
14960 coordinate of the iterator than move_it_by_lines
14961 promises in its contract. The method is to first
14962 go to the last (rightmost) visible character of a
14963 line, then move to the leftmost character on the
14964 next line in a separate call. */
14965 move_it_to (&it, ZV, it.last_visible_x, it.current_y, -1,
14966 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
14967 move_it_to (&it, ZV, 0,
14968 it.current_y + it.max_ascent + it.max_descent, -1,
14969 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y);
14970 }
14971 else
14972 move_it_by_lines (&it, 1);
14904 } 14973 }
14905 14974
14906 /* Set the window start there. */ 14975 /* Set the window start there. */
@@ -14952,6 +15021,10 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
14952 if-statement below. Now, this field is converted to 15021 if-statement below. Now, this field is converted to
14953 ptrdiff_t, thus zero means invalid position in a buffer. */ 15022 ptrdiff_t, thus zero means invalid position in a buffer. */
14954 eassert (w->last_point > 0); 15023 eassert (w->last_point > 0);
15024 /* Likewise there was a check whether window_end_vpos is nil or larger
15025 than the window. Now window_end_vpos is int and so never nil, but
15026 let's leave eassert to check whether it fits in the window. */
15027 eassert (w->window_end_vpos < w->current_matrix->nrows);
14955 15028
14956 /* Handle case where text has not changed, only point, and it has 15029 /* Handle case where text has not changed, only point, and it has
14957 not moved off the frame. */ 15030 not moved off the frame. */
@@ -14979,13 +15052,6 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
14979 since the handling of this_line_start_pos, etc., in redisplay 15052 since the handling of this_line_start_pos, etc., in redisplay
14980 handles the same cases. */ 15053 handles the same cases. */
14981 && !EQ (window, minibuf_window) 15054 && !EQ (window, minibuf_window)
14982 /* When splitting windows or for new windows, it happens that
14983 redisplay is called with a nil window_end_vpos or one being
14984 larger than the window. This should really be fixed in
14985 window.c. I don't have this on my list, now, so we do
14986 approximately the same as the old redisplay code. --gerd. */
14987 && INTEGERP (w->window_end_vpos)
14988 && XFASTINT (w->window_end_vpos) < w->current_matrix->nrows
14989 && (FRAME_WINDOW_P (f) 15055 && (FRAME_WINDOW_P (f)
14990 || !overlay_arrow_in_current_buffer_p ())) 15056 || !overlay_arrow_in_current_buffer_p ()))
14991 { 15057 {
@@ -15299,7 +15365,7 @@ set_vertical_scroll_bar (struct window *w)
15299 start = marker_position (w->start) - BUF_BEGV (buf); 15365 start = marker_position (w->start) - BUF_BEGV (buf);
15300 /* I don't think this is guaranteed to be right. For the 15366 /* I don't think this is guaranteed to be right. For the
15301 moment, we'll pretend it is. */ 15367 moment, we'll pretend it is. */
15302 end = BUF_Z (buf) - XFASTINT (w->window_end_pos) - BUF_BEGV (buf); 15368 end = BUF_Z (buf) - w->window_end_pos - BUF_BEGV (buf);
15303 15369
15304 if (end < start) 15370 if (end < start)
15305 end = start; 15371 end = start;
@@ -15360,7 +15426,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15360 eassert (XMARKER (w->pointm)->buffer == buffer); 15426 eassert (XMARKER (w->pointm)->buffer == buffer);
15361 15427
15362 restart: 15428 restart:
15363 reconsider_clip_changes (w, buffer); 15429 reconsider_clip_changes (w);
15364 frame_line_height = default_line_pixel_height (w); 15430 frame_line_height = default_line_pixel_height (w);
15365 15431
15366 /* Has the mode line to be updated? */ 15432 /* Has the mode line to be updated? */
@@ -15440,8 +15506,8 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15440 && !current_buffer->clip_changed 15506 && !current_buffer->clip_changed
15441 && !window_outdated (w)); 15507 && !window_outdated (w));
15442 15508
15443 /* When windows_or_buffers_changed is non-zero, we can't rely on 15509 /* When windows_or_buffers_changed is non-zero, we can't rely
15444 the window end being valid, so set it to nil there. */ 15510 on the window end being valid, so set it to zero there. */
15445 if (windows_or_buffers_changed) 15511 if (windows_or_buffers_changed)
15446 { 15512 {
15447 /* If window starts on a continuation line, maybe adjust the 15513 /* If window starts on a continuation line, maybe adjust the
@@ -15450,6 +15516,9 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15450 compute_window_start_on_continuation_line (w); 15516 compute_window_start_on_continuation_line (w);
15451 15517
15452 w->window_end_valid = 0; 15518 w->window_end_valid = 0;
15519 /* If so, we also can't rely on current matrix
15520 and should not fool try_cursor_movement below. */
15521 current_matrix_up_to_date_p = 0;
15453 } 15522 }
15454 15523
15455 /* Some sanity checks. */ 15524 /* Some sanity checks. */
@@ -15531,7 +15600,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15531 15600
15532 /* Handle case where place to start displaying has been specified, 15601 /* Handle case where place to start displaying has been specified,
15533 unless the specified location is outside the accessible range. */ 15602 unless the specified location is outside the accessible range. */
15534 if (w->force_start || w->frozen_window_start_p) 15603 if (w->force_start || window_frozen_p (w))
15535 { 15604 {
15536 /* We set this later on if we have to adjust point. */ 15605 /* We set this later on if we have to adjust point. */
15537 int new_vpos = -1; 15606 int new_vpos = -1;
@@ -15559,8 +15628,6 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15559 startp = run_window_scroll_functions (window, startp); 15628 startp = run_window_scroll_functions (window, startp);
15560 } 15629 }
15561 15630
15562 w->last_modified = 0;
15563 w->last_overlay_modified = 0;
15564 if (CHARPOS (startp) < BEGV) 15631 if (CHARPOS (startp) < BEGV)
15565 SET_TEXT_POS (startp, BEGV, BEGV_BYTE); 15632 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
15566 else if (CHARPOS (startp) > ZV) 15633 else if (CHARPOS (startp) > ZV)
@@ -15578,7 +15645,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15578 goto need_larger_matrices; 15645 goto need_larger_matrices;
15579 } 15646 }
15580 15647
15581 if (w->cursor.vpos < 0 && !w->frozen_window_start_p) 15648 if (w->cursor.vpos < 0 && !window_frozen_p (w))
15582 { 15649 {
15583 /* If point does not appear, try to move point so it does 15650 /* If point does not appear, try to move point so it does
15584 appear. The desired matrix has been built above, so we 15651 appear. The desired matrix has been built above, so we
@@ -15806,9 +15873,6 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15806 15873
15807 try_to_scroll: 15874 try_to_scroll:
15808 15875
15809 w->last_modified = 0;
15810 w->last_overlay_modified = 0;
15811
15812 /* Redisplay the mode line. Select the buffer properly for that. */ 15876 /* Redisplay the mode line. Select the buffer properly for that. */
15813 if (!update_mode_line) 15877 if (!update_mode_line)
15814 { 15878 {
@@ -15994,7 +16058,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
15994 line.) */ 16058 line.) */
15995 if (w->cursor.vpos < 0) 16059 if (w->cursor.vpos < 0)
15996 { 16060 {
15997 if (w->window_end_valid && PT >= Z - XFASTINT (w->window_end_pos)) 16061 if (w->window_end_valid && PT >= Z - w->window_end_pos)
15998 { 16062 {
15999 clear_glyph_matrix (w->desired_matrix); 16063 clear_glyph_matrix (w->desired_matrix);
16000 move_it_by_lines (&it, 1); 16064 move_it_by_lines (&it, 1);
@@ -16287,8 +16351,7 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
16287 } 16351 }
16288 16352
16289 /* If bottom moved off end of frame, change mode line percentage. */ 16353 /* If bottom moved off end of frame, change mode line percentage. */
16290 if (XFASTINT (w->window_end_pos) <= 0 16354 if (w->window_end_pos <= 0 && Z != IT_CHARPOS (it))
16291 && Z != IT_CHARPOS (it))
16292 w->update_mode_line = 1; 16355 w->update_mode_line = 1;
16293 16356
16294 /* Set window_end_pos to the offset of the last character displayed 16357 /* Set window_end_pos to the offset of the last character displayed
@@ -16297,21 +16360,16 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
16297 if (last_text_row) 16360 if (last_text_row)
16298 { 16361 {
16299 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row)); 16362 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row));
16300 w->window_end_bytepos 16363 adjust_window_ends (w, last_text_row, 0);
16301 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row);
16302 wset_window_end_pos
16303 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (last_text_row)));
16304 wset_window_end_vpos
16305 (w, make_number (MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)));
16306 eassert 16364 eassert
16307 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->desired_matrix, 16365 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->desired_matrix,
16308 XFASTINT (w->window_end_vpos)))); 16366 w->window_end_vpos)));
16309 } 16367 }
16310 else 16368 else
16311 { 16369 {
16312 w->window_end_bytepos = Z_BYTE - ZV_BYTE; 16370 w->window_end_bytepos = Z_BYTE - ZV_BYTE;
16313 wset_window_end_pos (w, make_number (Z - ZV)); 16371 w->window_end_pos = Z - ZV;
16314 wset_window_end_vpos (w, make_number (0)); 16372 w->window_end_vpos = 0;
16315 } 16373 }
16316 16374
16317 /* But that is not valid info until redisplay finishes. */ 16375 /* But that is not valid info until redisplay finishes. */
@@ -16535,32 +16593,15 @@ try_window_reusing_current_matrix (struct window *w)
16535 The value of last_text_row is the last displayed line 16593 The value of last_text_row is the last displayed line
16536 containing text. */ 16594 containing text. */
16537 if (last_reused_text_row) 16595 if (last_reused_text_row)
16538 { 16596 adjust_window_ends (w, last_reused_text_row, 1);
16539 w->window_end_bytepos
16540 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_reused_text_row);
16541 wset_window_end_pos
16542 (w, make_number (Z
16543 - MATRIX_ROW_END_CHARPOS (last_reused_text_row)));
16544 wset_window_end_vpos
16545 (w, make_number (MATRIX_ROW_VPOS (last_reused_text_row,
16546 w->current_matrix)));
16547 }
16548 else if (last_text_row) 16597 else if (last_text_row)
16549 { 16598 adjust_window_ends (w, last_text_row, 0);
16550 w->window_end_bytepos
16551 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row);
16552 wset_window_end_pos
16553 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (last_text_row)));
16554 wset_window_end_vpos
16555 (w, make_number (MATRIX_ROW_VPOS (last_text_row,
16556 w->desired_matrix)));
16557 }
16558 else 16599 else
16559 { 16600 {
16560 /* This window must be completely empty. */ 16601 /* This window must be completely empty. */
16561 w->window_end_bytepos = Z_BYTE - ZV_BYTE; 16602 w->window_end_bytepos = Z_BYTE - ZV_BYTE;
16562 wset_window_end_pos (w, make_number (Z - ZV)); 16603 w->window_end_pos = Z - ZV;
16563 wset_window_end_vpos (w, make_number (0)); 16604 w->window_end_vpos = 0;
16564 } 16605 }
16565 w->window_end_valid = 0; 16606 w->window_end_valid = 0;
16566 16607
@@ -16745,20 +16786,9 @@ try_window_reusing_current_matrix (struct window *w)
16745 the window end is in reused rows which in turn means that 16786 the window end is in reused rows which in turn means that
16746 only its vpos can have changed. */ 16787 only its vpos can have changed. */
16747 if (last_text_row) 16788 if (last_text_row)
16748 { 16789 adjust_window_ends (w, last_text_row, 0);
16749 w->window_end_bytepos
16750 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row);
16751 wset_window_end_pos
16752 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (last_text_row)));
16753 wset_window_end_vpos
16754 (w, make_number (MATRIX_ROW_VPOS (last_text_row,
16755 w->desired_matrix)));
16756 }
16757 else 16790 else
16758 { 16791 w->window_end_vpos -= nrows_scrolled;
16759 wset_window_end_vpos
16760 (w, make_number (XFASTINT (w->window_end_vpos) - nrows_scrolled));
16761 }
16762 16792
16763 w->window_end_valid = 0; 16793 w->window_end_valid = 0;
16764 w->desired_matrix->no_scrolling_p = 1; 16794 w->desired_matrix->no_scrolling_p = 1;
@@ -16898,11 +16928,11 @@ find_first_unchanged_at_end_row (struct window *w,
16898 /* A value of window_end_pos >= END_UNCHANGED means that the window 16928 /* A value of window_end_pos >= END_UNCHANGED means that the window
16899 end is in the range of changed text. If so, there is no 16929 end is in the range of changed text. If so, there is no
16900 unchanged row at the end of W's current matrix. */ 16930 unchanged row at the end of W's current matrix. */
16901 if (XFASTINT (w->window_end_pos) >= END_UNCHANGED) 16931 if (w->window_end_pos >= END_UNCHANGED)
16902 return NULL; 16932 return NULL;
16903 16933
16904 /* Set row to the last row in W's current matrix displaying text. */ 16934 /* Set row to the last row in W's current matrix displaying text. */
16905 row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); 16935 row = MATRIX_ROW (w->current_matrix, w->window_end_vpos);
16906 16936
16907 /* If matrix is entirely empty, no unchanged row exists. */ 16937 /* If matrix is entirely empty, no unchanged row exists. */
16908 if (MATRIX_ROW_DISPLAYS_TEXT_P (row)) 16938 if (MATRIX_ROW_DISPLAYS_TEXT_P (row))
@@ -16913,7 +16943,7 @@ find_first_unchanged_at_end_row (struct window *w,
16913 buffer positions in the current matrix to current buffer 16943 buffer positions in the current matrix to current buffer
16914 positions for characters not in changed text. */ 16944 positions for characters not in changed text. */
16915 ptrdiff_t Z_old = 16945 ptrdiff_t Z_old =
16916 MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos); 16946 MATRIX_ROW_END_CHARPOS (row) + w->window_end_pos;
16917 ptrdiff_t Z_BYTE_old = 16947 ptrdiff_t Z_BYTE_old =
16918 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos; 16948 MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos;
16919 ptrdiff_t last_unchanged_pos, last_unchanged_pos_old; 16949 ptrdiff_t last_unchanged_pos, last_unchanged_pos_old;
@@ -17247,7 +17277,7 @@ try_window_id (struct window *w)
17247 This case happens with stealth-fontification. Note that although 17277 This case happens with stealth-fontification. Note that although
17248 the display is unchanged, glyph positions in the matrix have to 17278 the display is unchanged, glyph positions in the matrix have to
17249 be adjusted, of course. */ 17279 be adjusted, of course. */
17250 row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); 17280 row = MATRIX_ROW (w->current_matrix, w->window_end_vpos);
17251 if (MATRIX_ROW_DISPLAYS_TEXT_P (row) 17281 if (MATRIX_ROW_DISPLAYS_TEXT_P (row)
17252 && ((last_changed_charpos < CHARPOS (start) 17282 && ((last_changed_charpos < CHARPOS (start)
17253 && CHARPOS (start) == BEGV) 17283 && CHARPOS (start) == BEGV)
@@ -17259,7 +17289,7 @@ try_window_id (struct window *w)
17259 17289
17260 /* Compute how many chars/bytes have been added to or removed 17290 /* Compute how many chars/bytes have been added to or removed
17261 from the buffer. */ 17291 from the buffer. */
17262 Z_old = MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos); 17292 Z_old = MATRIX_ROW_END_CHARPOS (row) + w->window_end_pos;
17263 Z_BYTE_old = MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos; 17293 Z_BYTE_old = MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos;
17264 Z_delta = Z - Z_old; 17294 Z_delta = Z - Z_old;
17265 Z_delta_bytes = Z_BYTE - Z_BYTE_old; 17295 Z_delta_bytes = Z_BYTE - Z_BYTE_old;
@@ -17330,10 +17360,8 @@ try_window_id (struct window *w)
17330 { 17360 {
17331 /* We have to compute the window end anew since text 17361 /* We have to compute the window end anew since text
17332 could have been added/removed after it. */ 17362 could have been added/removed after it. */
17333 wset_window_end_pos 17363 w->window_end_pos = Z - MATRIX_ROW_END_CHARPOS (row);
17334 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (row))); 17364 w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row);
17335 w->window_end_bytepos
17336 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row);
17337 17365
17338 /* Set the cursor. */ 17366 /* Set the cursor. */
17339 row = row_containing_pos (w, PT, r0, NULL, 0); 17367 row = row_containing_pos (w, PT, r0, NULL, 0);
@@ -17366,7 +17394,7 @@ try_window_id (struct window *w)
17366 17394
17367 /* Give up if the window ends in strings. Overlay strings 17395 /* Give up if the window ends in strings. Overlay strings
17368 at the end are difficult to handle, so don't try. */ 17396 at the end are difficult to handle, so don't try. */
17369 row = MATRIX_ROW (current_matrix, XFASTINT (w->window_end_vpos)); 17397 row = MATRIX_ROW (current_matrix, w->window_end_vpos);
17370 if (MATRIX_ROW_START_CHARPOS (row) == MATRIX_ROW_END_CHARPOS (row)) 17398 if (MATRIX_ROW_START_CHARPOS (row) == MATRIX_ROW_END_CHARPOS (row))
17371 GIVE_UP (20); 17399 GIVE_UP (20);
17372 17400
@@ -17712,7 +17740,7 @@ try_window_id (struct window *w)
17712 /* Set last_row to the glyph row in the current matrix where the 17740 /* Set last_row to the glyph row in the current matrix where the
17713 window end line is found. It has been moved up or down in 17741 window end line is found. It has been moved up or down in
17714 the matrix by dvpos. */ 17742 the matrix by dvpos. */
17715 int last_vpos = XFASTINT (w->window_end_vpos) + dvpos; 17743 int last_vpos = w->window_end_vpos + dvpos;
17716 struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos); 17744 struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos);
17717 17745
17718 /* If last_row is the window end line, it should display text. */ 17746 /* If last_row is the window end line, it should display text. */
@@ -17756,8 +17784,7 @@ try_window_id (struct window *w)
17756 } 17784 }
17757 17785
17758 /* Update window_end_pos and window_end_vpos. */ 17786 /* Update window_end_pos and window_end_vpos. */
17759 if (first_unchanged_at_end_row 17787 if (first_unchanged_at_end_row && !last_text_row_at_end)
17760 && !last_text_row_at_end)
17761 { 17788 {
17762 /* Window end line if one of the preserved rows from the current 17789 /* Window end line if one of the preserved rows from the current
17763 matrix. Set row to the last row displaying text in current 17790 matrix. Set row to the last row displaying text in current
@@ -17767,23 +17794,13 @@ try_window_id (struct window *w)
17767 row = find_last_row_displaying_text (w->current_matrix, &it, 17794 row = find_last_row_displaying_text (w->current_matrix, &it,
17768 first_unchanged_at_end_row); 17795 first_unchanged_at_end_row);
17769 eassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row)); 17796 eassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row));
17770 17797 adjust_window_ends (w, row, 1);
17771 wset_window_end_pos (w, make_number (Z - MATRIX_ROW_END_CHARPOS (row)));
17772 w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row);
17773 wset_window_end_vpos
17774 (w, make_number (MATRIX_ROW_VPOS (row, w->current_matrix)));
17775 eassert (w->window_end_bytepos >= 0); 17798 eassert (w->window_end_bytepos >= 0);
17776 IF_DEBUG (debug_method_add (w, "A")); 17799 IF_DEBUG (debug_method_add (w, "A"));
17777 } 17800 }
17778 else if (last_text_row_at_end) 17801 else if (last_text_row_at_end)
17779 { 17802 {
17780 wset_window_end_pos 17803 adjust_window_ends (w, last_text_row_at_end, 0);
17781 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (last_text_row_at_end)));
17782 w->window_end_bytepos
17783 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row_at_end);
17784 wset_window_end_vpos
17785 (w, make_number (MATRIX_ROW_VPOS (last_text_row_at_end,
17786 desired_matrix)));
17787 eassert (w->window_end_bytepos >= 0); 17804 eassert (w->window_end_bytepos >= 0);
17788 IF_DEBUG (debug_method_add (w, "B")); 17805 IF_DEBUG (debug_method_add (w, "B"));
17789 } 17806 }
@@ -17792,12 +17809,7 @@ try_window_id (struct window *w)
17792 /* We have displayed either to the end of the window or at the 17809 /* We have displayed either to the end of the window or at the
17793 end of the window, i.e. the last row with text is to be found 17810 end of the window, i.e. the last row with text is to be found
17794 in the desired matrix. */ 17811 in the desired matrix. */
17795 wset_window_end_pos 17812 adjust_window_ends (w, last_text_row, 0);
17796 (w, make_number (Z - MATRIX_ROW_END_CHARPOS (last_text_row)));
17797 w->window_end_bytepos
17798 = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row);
17799 wset_window_end_vpos
17800 (w, make_number (MATRIX_ROW_VPOS (last_text_row, desired_matrix)));
17801 eassert (w->window_end_bytepos >= 0); 17813 eassert (w->window_end_bytepos >= 0);
17802 } 17814 }
17803 else if (first_unchanged_at_end_row == NULL 17815 else if (first_unchanged_at_end_row == NULL
@@ -17807,7 +17819,7 @@ try_window_id (struct window *w)
17807 /* Displayed to end of window, but no line containing text was 17819 /* Displayed to end of window, but no line containing text was
17808 displayed. Lines were deleted at the end of the window. */ 17820 displayed. Lines were deleted at the end of the window. */
17809 int first_vpos = WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0; 17821 int first_vpos = WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0;
17810 int vpos = XFASTINT (w->window_end_vpos); 17822 int vpos = w->window_end_vpos;
17811 struct glyph_row *current_row = current_matrix->rows + vpos; 17823 struct glyph_row *current_row = current_matrix->rows + vpos;
17812 struct glyph_row *desired_row = desired_matrix->rows + vpos; 17824 struct glyph_row *desired_row = desired_matrix->rows + vpos;
17813 17825
@@ -17825,8 +17837,8 @@ try_window_id (struct window *w)
17825 } 17837 }
17826 17838
17827 eassert (row != NULL); 17839 eassert (row != NULL);
17828 wset_window_end_vpos (w, make_number (vpos + 1)); 17840 w->window_end_vpos = vpos + 1;
17829 wset_window_end_pos (w, make_number (Z - MATRIX_ROW_END_CHARPOS (row))); 17841 w->window_end_pos = Z - MATRIX_ROW_END_CHARPOS (row);
17830 w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row); 17842 w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row);
17831 eassert (w->window_end_bytepos >= 0); 17843 eassert (w->window_end_bytepos >= 0);
17832 IF_DEBUG (debug_method_add (w, "C")); 17844 IF_DEBUG (debug_method_add (w, "C"));
@@ -17834,8 +17846,8 @@ try_window_id (struct window *w)
17834 else 17846 else
17835 emacs_abort (); 17847 emacs_abort ();
17836 17848
17837 IF_DEBUG (debug_end_pos = XFASTINT (w->window_end_pos); 17849 IF_DEBUG (debug_end_pos = w->window_end_pos;
17838 debug_end_vpos = XFASTINT (w->window_end_vpos)); 17850 debug_end_vpos = w->window_end_vpos);
17839 17851
17840 /* Record that display has not been completed. */ 17852 /* Record that display has not been completed. */
17841 w->window_end_valid = 0; 17853 w->window_end_valid = 0;
@@ -20115,7 +20127,7 @@ Value is the new character position of point. */)
20115 (Lisp_Object direction) 20127 (Lisp_Object direction)
20116{ 20128{
20117 struct window *w = XWINDOW (selected_window); 20129 struct window *w = XWINDOW (selected_window);
20118 struct buffer *b = NULL; 20130 struct buffer *b = XBUFFER (w->contents);
20119 struct glyph_row *row; 20131 struct glyph_row *row;
20120 int dir; 20132 int dir;
20121 Lisp_Object paragraph_dir; 20133 Lisp_Object paragraph_dir;
@@ -20135,9 +20147,6 @@ Value is the new character position of point. */)
20135 else 20147 else
20136 dir = -1; 20148 dir = -1;
20137 20149
20138 if (BUFFERP (w->contents))
20139 b = XBUFFER (w->contents);
20140
20141 /* If current matrix is up-to-date, we can use the information 20150 /* If current matrix is up-to-date, we can use the information
20142 recorded in the glyphs, at least as long as the goal is on the 20151 recorded in the glyphs, at least as long as the goal is on the
20143 screen. */ 20152 screen. */
@@ -20146,8 +20155,7 @@ Value is the new character position of point. */)
20146 && b 20155 && b
20147 && !b->clip_changed 20156 && !b->clip_changed
20148 && !b->prevent_redisplay_optimizations_p 20157 && !b->prevent_redisplay_optimizations_p
20149 && w->last_modified >= BUF_MODIFF (b) 20158 && !window_outdated (w)
20150 && w->last_overlay_modified >= BUF_OVERLAY_MODIFF (b)
20151 && w->cursor.vpos >= 0 20159 && w->cursor.vpos >= 0
20152 && w->cursor.vpos < w->current_matrix->nrows 20160 && w->cursor.vpos < w->current_matrix->nrows
20153 && (row = MATRIX_ROW (w->current_matrix, w->cursor.vpos))->enabled_p) 20161 && (row = MATRIX_ROW (w->current_matrix, w->cursor.vpos))->enabled_p)
@@ -22007,7 +22015,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
22007 ptrdiff_t pos = marker_position (w->start); 22015 ptrdiff_t pos = marker_position (w->start);
22008 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b); 22016 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
22009 22017
22010 if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b)) 22018 if (w->window_end_pos <= BUF_Z (b) - BUF_ZV (b))
22011 { 22019 {
22012 if (pos <= BUF_BEGV (b)) 22020 if (pos <= BUF_BEGV (b))
22013 return "All"; 22021 return "All";
@@ -22036,7 +22044,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
22036 case 'P': 22044 case 'P':
22037 { 22045 {
22038 ptrdiff_t toppos = marker_position (w->start); 22046 ptrdiff_t toppos = marker_position (w->start);
22039 ptrdiff_t botpos = BUF_Z (b) - XFASTINT (w->window_end_pos); 22047 ptrdiff_t botpos = BUF_Z (b) - w->window_end_pos;
22040 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b); 22048 ptrdiff_t total = BUF_ZV (b) - BUF_BEGV (b);
22041 22049
22042 if (botpos >= BUF_ZV (b)) 22050 if (botpos >= BUF_ZV (b))
@@ -23856,17 +23864,15 @@ draw_glyphs (struct window *w, int x, struct glyph_row *row,
23856 && hlinfo->mouse_face_beg_row >= 0 23864 && hlinfo->mouse_face_beg_row >= 0
23857 && hlinfo->mouse_face_end_row >= 0) 23865 && hlinfo->mouse_face_end_row >= 0)
23858 { 23866 {
23859 struct glyph_row *mouse_beg_row, *mouse_end_row; 23867 ptrdiff_t row_vpos = MATRIX_ROW_VPOS (row, w->current_matrix);
23860
23861 mouse_beg_row = MATRIX_ROW (w->current_matrix, hlinfo->mouse_face_beg_row);
23862 mouse_end_row = MATRIX_ROW (w->current_matrix, hlinfo->mouse_face_end_row);
23863 23868
23864 if (row >= mouse_beg_row && row <= mouse_end_row) 23869 if (row_vpos >= hlinfo->mouse_face_beg_row
23870 && row_vpos <= hlinfo->mouse_face_end_row)
23865 { 23871 {
23866 check_mouse_face = 1; 23872 check_mouse_face = 1;
23867 mouse_beg_col = (row == mouse_beg_row) 23873 mouse_beg_col = (row_vpos == hlinfo->mouse_face_beg_row)
23868 ? hlinfo->mouse_face_beg_col : 0; 23874 ? hlinfo->mouse_face_beg_col : 0;
23869 mouse_end_col = (row == mouse_end_row) 23875 mouse_end_col = (row_vpos == hlinfo->mouse_face_end_row)
23870 ? hlinfo->mouse_face_end_col 23876 ? hlinfo->mouse_face_end_col
23871 : row->used[TEXT_AREA]; 23877 : row->used[TEXT_AREA];
23872 } 23878 }
@@ -25758,16 +25764,15 @@ x_produce_glyphs (struct it *it)
25758/* EXPORT for RIF: 25764/* EXPORT for RIF:
25759 Output LEN glyphs starting at START at the nominal cursor position. 25765 Output LEN glyphs starting at START at the nominal cursor position.
25760 Advance the nominal cursor over the text. The global variable 25766 Advance the nominal cursor over the text. The global variable
25761 updated_window contains the window being updated, updated_row is 25767 updated_row is the glyph row being updated, and updated_area is the
25762 the glyph row being updated, and updated_area is the area of that 25768 area of that row being updated. */
25763 row being updated. */
25764 25769
25765void 25770void
25766x_write_glyphs (struct glyph *start, int len) 25771x_write_glyphs (struct window *w, struct glyph *start, int len)
25767{ 25772{
25768 int x, hpos, chpos = updated_window->phys_cursor.hpos; 25773 int x, hpos, chpos = w->phys_cursor.hpos;
25769 25774
25770 eassert (updated_window && updated_row); 25775 eassert (updated_row);
25771 /* When the window is hscrolled, cursor hpos can legitimately be out 25776 /* When the window is hscrolled, cursor hpos can legitimately be out
25772 of bounds, but we draw the cursor at the corresponding window 25777 of bounds, but we draw the cursor at the corresponding window
25773 margin in that case. */ 25778 margin in that case. */
@@ -25781,18 +25786,18 @@ x_write_glyphs (struct glyph *start, int len)
25781 /* Write glyphs. */ 25786 /* Write glyphs. */
25782 25787
25783 hpos = start - updated_row->glyphs[updated_area]; 25788 hpos = start - updated_row->glyphs[updated_area];
25784 x = draw_glyphs (updated_window, output_cursor.x, 25789 x = draw_glyphs (w, output_cursor.x,
25785 updated_row, updated_area, 25790 updated_row, updated_area,
25786 hpos, hpos + len, 25791 hpos, hpos + len,
25787 DRAW_NORMAL_TEXT, 0); 25792 DRAW_NORMAL_TEXT, 0);
25788 25793
25789 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */ 25794 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25790 if (updated_area == TEXT_AREA 25795 if (updated_area == TEXT_AREA
25791 && updated_window->phys_cursor_on_p 25796 && w->phys_cursor_on_p
25792 && updated_window->phys_cursor.vpos == output_cursor.vpos 25797 && w->phys_cursor.vpos == output_cursor.vpos
25793 && chpos >= hpos 25798 && chpos >= hpos
25794 && chpos < hpos + len) 25799 && chpos < hpos + len)
25795 updated_window->phys_cursor_on_p = 0; 25800 w->phys_cursor_on_p = 0;
25796 25801
25797 unblock_input (); 25802 unblock_input ();
25798 25803
@@ -25806,19 +25811,17 @@ x_write_glyphs (struct glyph *start, int len)
25806 Insert LEN glyphs from START at the nominal cursor position. */ 25811 Insert LEN glyphs from START at the nominal cursor position. */
25807 25812
25808void 25813void
25809x_insert_glyphs (struct glyph *start, int len) 25814x_insert_glyphs (struct window *w, struct glyph *start, int len)
25810{ 25815{
25811 struct frame *f; 25816 struct frame *f;
25812 struct window *w;
25813 int line_height, shift_by_width, shifted_region_width; 25817 int line_height, shift_by_width, shifted_region_width;
25814 struct glyph_row *row; 25818 struct glyph_row *row;
25815 struct glyph *glyph; 25819 struct glyph *glyph;
25816 int frame_x, frame_y; 25820 int frame_x, frame_y;
25817 ptrdiff_t hpos; 25821 ptrdiff_t hpos;
25818 25822
25819 eassert (updated_window && updated_row); 25823 eassert (updated_row);
25820 block_input (); 25824 block_input ();
25821 w = updated_window;
25822 f = XFRAME (WINDOW_FRAME (w)); 25825 f = XFRAME (WINDOW_FRAME (w));
25823 25826
25824 /* Get the height of the line we are in. */ 25827 /* Get the height of the line we are in. */
@@ -25860,18 +25863,17 @@ x_insert_glyphs (struct glyph *start, int len)
25860 (inclusive) to pixel column TO_X (exclusive). The idea is that 25863 (inclusive) to pixel column TO_X (exclusive). The idea is that
25861 everything from TO_X onward is already erased. 25864 everything from TO_X onward is already erased.
25862 25865
25863 TO_X is a pixel position relative to updated_area of 25866 TO_X is a pixel position relative to updated_area of currently
25864 updated_window. TO_X == -1 means clear to the end of this area. */ 25867 updated window W. TO_X == -1 means clear to the end of this area. */
25865 25868
25866void 25869void
25867x_clear_end_of_line (int to_x) 25870x_clear_end_of_line (struct window *w, int to_x)
25868{ 25871{
25869 struct frame *f; 25872 struct frame *f;
25870 struct window *w = updated_window;
25871 int max_x, min_y, max_y; 25873 int max_x, min_y, max_y;
25872 int from_x, from_y, to_y; 25874 int from_x, from_y, to_y;
25873 25875
25874 eassert (updated_window && updated_row); 25876 eassert (updated_row);
25875 f = XFRAME (w->frame); 25877 f = XFRAME (w->frame);
25876 25878
25877 if (updated_row->full_width_p) 25879 if (updated_row->full_width_p)
@@ -26010,6 +26012,9 @@ set_frame_cursor_types (struct frame *f, Lisp_Object arg)
26010 } 26012 }
26011 else 26013 else
26012 FRAME_BLINK_OFF_CURSOR (f) = DEFAULT_CURSOR; 26014 FRAME_BLINK_OFF_CURSOR (f) = DEFAULT_CURSOR;
26015
26016 /* Make sure the cursor gets redrawn. */
26017 cursor_type_changed = 1;
26013} 26018}
26014 26019
26015 26020
@@ -27048,7 +27053,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
27048 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */ 27053 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27049 rows_from_pos_range (w, start_charpos, end_charpos, disp_string, &r1, &r2); 27054 rows_from_pos_range (w, start_charpos, end_charpos, disp_string, &r1, &r2);
27050 if (r1 == NULL) 27055 if (r1 == NULL)
27051 r1 = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); 27056 r1 = MATRIX_ROW (w->current_matrix, w->window_end_vpos);
27052 /* If the before-string or display-string contains newlines, 27057 /* If the before-string or display-string contains newlines,
27053 rows_from_pos_range skips to its last row. Move back. */ 27058 rows_from_pos_range skips to its last row. Move back. */
27054 if (!NILP (before_string) || !NILP (disp_string)) 27059 if (!NILP (before_string) || !NILP (disp_string))
@@ -27070,7 +27075,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
27070 } 27075 }
27071 if (r2 == NULL) 27076 if (r2 == NULL)
27072 { 27077 {
27073 r2 = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); 27078 r2 = MATRIX_ROW (w->current_matrix, w->window_end_vpos);
27074 hlinfo->mouse_face_past_end = 1; 27079 hlinfo->mouse_face_past_end = 1;
27075 } 27080 }
27076 else if (!NILP (after_string)) 27081 else if (!NILP (after_string))
@@ -27078,7 +27083,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
27078 /* If the after-string has newlines, advance to its last row. */ 27083 /* If the after-string has newlines, advance to its last row. */
27079 struct glyph_row *next; 27084 struct glyph_row *next;
27080 struct glyph_row *last 27085 struct glyph_row *last
27081 = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); 27086 = MATRIX_ROW (w->current_matrix, w->window_end_vpos);
27082 27087
27083 for (next = r2 + 1; 27088 for (next = r2 + 1;
27084 next <= last 27089 next <= last
@@ -28142,10 +28147,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
28142 /* Are we in a window whose display is up to date? 28147 /* Are we in a window whose display is up to date?
28143 And verify the buffer's text has not changed. */ 28148 And verify the buffer's text has not changed. */
28144 b = XBUFFER (w->contents); 28149 b = XBUFFER (w->contents);
28145 if (part == ON_TEXT 28150 if (part == ON_TEXT && w->window_end_valid && !window_outdated (w))
28146 && w->window_end_valid
28147 && w->last_modified == BUF_MODIFF (b)
28148 && w->last_overlay_modified == BUF_OVERLAY_MODIFF (b))
28149 { 28151 {
28150 int hpos, vpos, dx, dy, area = LAST_AREA; 28152 int hpos, vpos, dx, dy, area = LAST_AREA;
28151 ptrdiff_t pos; 28153 ptrdiff_t pos;
@@ -28387,8 +28389,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
28387 : Qnil; 28389 : Qnil;
28388 Lisp_Object lim2 = 28390 Lisp_Object lim2 =
28389 NILP (BVAR (XBUFFER (buffer), bidi_display_reordering)) 28391 NILP (BVAR (XBUFFER (buffer), bidi_display_reordering))
28390 ? make_number (BUF_Z (XBUFFER (buffer)) 28392 ? make_number (BUF_Z (XBUFFER (buffer)) - w->window_end_pos)
28391 - XFASTINT (w->window_end_pos))
28392 : Qnil; 28393 : Qnil;
28393 28394
28394 if (NILP (overlay)) 28395 if (NILP (overlay))
@@ -28836,7 +28837,7 @@ expose_window (struct window *w, XRectangle *fr)
28836 /* When we're currently updating the window, display and current 28837 /* When we're currently updating the window, display and current
28837 matrix usually don't agree. Arrange for a thorough display 28838 matrix usually don't agree. Arrange for a thorough display
28838 later. */ 28839 later. */
28839 if (w == updated_window) 28840 if (w->must_be_updated_p)
28840 { 28841 {
28841 SET_FRAME_GARBAGED (f); 28842 SET_FRAME_GARBAGED (f);
28842 return 0; 28843 return 0;
diff --git a/src/xfaces.c b/src/xfaces.c
index f647ff2e209..b76f9d24180 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -448,8 +448,8 @@ static struct face *realize_non_ascii_face (struct frame *, Lisp_Object,
448 struct face *); 448 struct face *);
449static struct face *realize_x_face (struct face_cache *, Lisp_Object *); 449static struct face *realize_x_face (struct face_cache *, Lisp_Object *);
450static struct face *realize_tty_face (struct face_cache *, Lisp_Object *); 450static struct face *realize_tty_face (struct face_cache *, Lisp_Object *);
451static int realize_basic_faces (struct frame *); 451static bool realize_basic_faces (struct frame *);
452static int realize_default_face (struct frame *); 452static bool realize_default_face (struct frame *);
453static void realize_named_face (struct frame *, Lisp_Object, int); 453static void realize_named_face (struct frame *, Lisp_Object, int);
454static struct face_cache *make_face_cache (struct frame *); 454static struct face_cache *make_face_cache (struct frame *);
455static void clear_face_gcs (struct face_cache *); 455static void clear_face_gcs (struct face_cache *);
@@ -759,11 +759,6 @@ clear_face_cache (int clear_fonts_p)
759 if (clear_fonts_p 759 if (clear_fonts_p
760 || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT) 760 || ++clear_font_table_count == CLEAR_FONT_TABLE_COUNT)
761 { 761 {
762#if 0
763 /* Not yet implemented. */
764 clear_font_cache (frame);
765#endif
766
767 /* From time to time see if we can unload some fonts. This also 762 /* From time to time see if we can unload some fonts. This also
768 frees all realized faces on all frames. Fonts needed by 763 frees all realized faces on all frames. Fonts needed by
769 faces will be loaded again when faces are realized again. */ 764 faces will be loaded again when faces are realized again. */
@@ -774,7 +769,10 @@ clear_face_cache (int clear_fonts_p)
774 struct frame *f = XFRAME (frame); 769 struct frame *f = XFRAME (frame);
775 if (FRAME_WINDOW_P (f) 770 if (FRAME_WINDOW_P (f)
776 && FRAME_X_DISPLAY_INFO (f)->n_fonts > CLEAR_FONT_TABLE_NFONTS) 771 && FRAME_X_DISPLAY_INFO (f)->n_fonts > CLEAR_FONT_TABLE_NFONTS)
777 free_all_realized_faces (frame); 772 {
773 clear_font_cache (f);
774 free_all_realized_faces (frame);
775 }
778 } 776 }
779 } 777 }
780 else 778 else
@@ -819,7 +817,7 @@ the pixmap. Bits are stored row by row, each row occupies
819\(WIDTH + 7)/8 bytes. */) 817\(WIDTH + 7)/8 bytes. */)
820 (Lisp_Object object) 818 (Lisp_Object object)
821{ 819{
822 int pixmap_p = 0; 820 bool pixmap_p = 0;
823 821
824 if (STRINGP (object)) 822 if (STRINGP (object))
825 /* If OBJECT is a string, it's a file name. */ 823 /* If OBJECT is a string, it's a file name. */
@@ -869,7 +867,7 @@ the pixmap. Bits are stored row by row, each row occupies
869 if these pointers are not null. */ 867 if these pointers are not null. */
870 868
871static ptrdiff_t 869static ptrdiff_t
872load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr, 870load_pixmap (struct frame *f, Lisp_Object name, unsigned int *w_ptr,
873 unsigned int *h_ptr) 871 unsigned int *h_ptr)
874{ 872{
875 ptrdiff_t bitmap_id; 873 ptrdiff_t bitmap_id;
@@ -1530,15 +1528,12 @@ the face font sort order. */)
1530 (Lisp_Object family, Lisp_Object frame) 1528 (Lisp_Object family, Lisp_Object frame)
1531{ 1529{
1532 Lisp_Object font_spec, list, *drivers, vec; 1530 Lisp_Object font_spec, list, *drivers, vec;
1531 struct frame *f = decode_live_frame (frame);
1533 ptrdiff_t i, nfonts; 1532 ptrdiff_t i, nfonts;
1534 EMACS_INT ndrivers; 1533 EMACS_INT ndrivers;
1535 Lisp_Object result; 1534 Lisp_Object result;
1536 USE_SAFE_ALLOCA; 1535 USE_SAFE_ALLOCA;
1537 1536
1538 if (NILP (frame))
1539 frame = selected_frame;
1540 CHECK_LIVE_FRAME (frame);
1541
1542 font_spec = Ffont_spec (0, NULL); 1537 font_spec = Ffont_spec (0, NULL);
1543 if (!NILP (family)) 1538 if (!NILP (family))
1544 { 1539 {
@@ -1546,7 +1541,7 @@ the face font sort order. */)
1546 font_parse_family_registry (family, Qnil, font_spec); 1541 font_parse_family_registry (family, Qnil, font_spec);
1547 } 1542 }
1548 1543
1549 list = font_list_entities (frame, font_spec); 1544 list = font_list_entities (f, font_spec);
1550 if (NILP (list)) 1545 if (NILP (list))
1551 return Qnil; 1546 return Qnil;
1552 1547
@@ -1589,7 +1584,7 @@ the face font sort order. */)
1589 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX)); 1584 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX));
1590 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font)); 1585 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font));
1591 point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10, 1586 point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10,
1592 FRAME_RES_Y (XFRAME (frame))); 1587 FRAME_RES_Y (f));
1593 ASET (v, 2, make_number (point)); 1588 ASET (v, 2, make_number (point));
1594 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font)); 1589 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font));
1595 ASET (v, 4, FONT_SLANT_SYMBOLIC (font)); 1590 ASET (v, 4, FONT_SLANT_SYMBOLIC (font));
@@ -2854,7 +2849,7 @@ FRAME 0 means change the face on all frames, and change the default
2854 } 2849 }
2855 else if (EQ (attr, QCunderline)) 2850 else if (EQ (attr, QCunderline))
2856 { 2851 {
2857 int valid_p = 0; 2852 bool valid_p = 0;
2858 2853
2859 if (UNSPECIFIEDP (value) || IGNORE_DEFFACE_P (value)) 2854 if (UNSPECIFIEDP (value) || IGNORE_DEFFACE_P (value))
2860 valid_p = 1; 2855 valid_p = 1;
@@ -2941,7 +2936,7 @@ FRAME 0 means change the face on all frames, and change the default
2941 } 2936 }
2942 else if (EQ (attr, QCbox)) 2937 else if (EQ (attr, QCbox))
2943 { 2938 {
2944 int valid_p; 2939 bool valid_p;
2945 2940
2946 /* Allow t meaning a simple box of width 1 in foreground color 2941 /* Allow t meaning a simple box of width 1 in foreground color
2947 of the face. */ 2942 of the face. */
@@ -3078,7 +3073,7 @@ FRAME 0 means change the face on all frames, and change the default
3078 { 3073 {
3079 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value)) 3074 if (!UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
3080 { 3075 {
3081 FRAME_PTR f; 3076 struct frame *f;
3082 3077
3083 old_value = LFACE_FONT (lface); 3078 old_value = LFACE_FONT (lface);
3084 if (! FONTP (value)) 3079 if (! FONTP (value))
@@ -3247,10 +3242,9 @@ FRAME 0 means change the face on all frames, and change the default
3247#endif /* HAVE_WINDOW_SYSTEM */ 3242#endif /* HAVE_WINDOW_SYSTEM */
3248 else if (EQ (face, Qmenu)) 3243 else if (EQ (face, Qmenu))
3249 { 3244 {
3250 /* Indicate that we have to update the menu bar when 3245 /* Indicate that we have to update the menu bar when realizing
3251 realizing faces on FRAME. FRAME t change the 3246 faces on FRAME. FRAME t change the default for new frames.
3252 default for new frames. We do this by setting 3247 We do this by setting the flag in new face caches. */
3253 setting the flag in new face caches */
3254 if (FRAMEP (frame)) 3248 if (FRAMEP (frame))
3255 { 3249 {
3256 struct frame *f = XFRAME (frame); 3250 struct frame *f = XFRAME (frame);
@@ -3510,7 +3504,7 @@ x_update_menu_appearance (struct frame *f)
3510 Lisp_Object lface = lface_from_face_name (f, Qmenu, 1); 3504 Lisp_Object lface = lface_from_face_name (f, Qmenu, 1);
3511 struct face *face = FACE_FROM_ID (f, MENU_FACE_ID); 3505 struct face *face = FACE_FROM_ID (f, MENU_FACE_ID);
3512 const char *myname = SSDATA (Vx_resource_name); 3506 const char *myname = SSDATA (Vx_resource_name);
3513 int changed_p = 0; 3507 bool changed_p = 0;
3514#ifdef USE_MOTIF 3508#ifdef USE_MOTIF
3515 const char *popup_path = "popup_menu"; 3509 const char *popup_path = "popup_menu";
3516#else 3510#else
@@ -3858,7 +3852,7 @@ return the font name used for CHARACTER. */)
3858 all attributes are `equal'. Tries to be fast because this function 3852 all attributes are `equal'. Tries to be fast because this function
3859 is called quite often. */ 3853 is called quite often. */
3860 3854
3861static int 3855static bool
3862face_attr_equal_p (Lisp_Object v1, Lisp_Object v2) 3856face_attr_equal_p (Lisp_Object v1, Lisp_Object v2)
3863{ 3857{
3864 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil, 3858 /* Type can differ, e.g. when one attribute is unspecified, i.e. nil,
@@ -3891,10 +3885,11 @@ face_attr_equal_p (Lisp_Object v1, Lisp_Object v2)
3891 all attributes are `equal'. Tries to be fast because this function 3885 all attributes are `equal'. Tries to be fast because this function
3892 is called quite often. */ 3886 is called quite often. */
3893 3887
3894static int 3888static bool
3895lface_equal_p (Lisp_Object *v1, Lisp_Object *v2) 3889lface_equal_p (Lisp_Object *v1, Lisp_Object *v2)
3896{ 3890{
3897 int i, equal_p = 1; 3891 int i;
3892 bool equal_p = 1;
3898 3893
3899 for (i = 1; i < LFACE_VECTOR_SIZE && equal_p; ++i) 3894 for (i = 1; i < LFACE_VECTOR_SIZE && equal_p; ++i)
3900 equal_p = face_attr_equal_p (v1[i], v2[i]); 3895 equal_p = face_attr_equal_p (v1[i], v2[i]);
@@ -4166,13 +4161,11 @@ If FRAME is unspecified or nil, the current frame is used. */)
4166static struct face_cache * 4161static struct face_cache *
4167make_face_cache (struct frame *f) 4162make_face_cache (struct frame *f)
4168{ 4163{
4169 struct face_cache *c; 4164 struct face_cache *c = xmalloc (sizeof *c);
4170 int size;
4171 4165
4172 c = xzalloc (sizeof *c); 4166 c->buckets = xzalloc (FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets);
4173 size = FACE_CACHE_BUCKETS_SIZE * sizeof *c->buckets;
4174 c->buckets = xzalloc (size);
4175 c->size = 50; 4167 c->size = 50;
4168 c->used = 0;
4176 c->faces_by_id = xmalloc (c->size * sizeof *c->faces_by_id); 4169 c->faces_by_id = xmalloc (c->size * sizeof *c->faces_by_id);
4177 c->f = f; 4170 c->f = f;
4178 c->menu_face_changed_p = menu_face_changed_default; 4171 c->menu_face_changed_p = menu_face_changed_default;
@@ -5201,10 +5194,10 @@ face_fontset (Lisp_Object attrs[LFACE_VECTOR_SIZE])
5201 of F don't contain enough information needed to realize the default 5194 of F don't contain enough information needed to realize the default
5202 face. */ 5195 face. */
5203 5196
5204static int 5197static bool
5205realize_basic_faces (struct frame *f) 5198realize_basic_faces (struct frame *f)
5206{ 5199{
5207 int success_p = 0; 5200 bool success_p = 0;
5208 ptrdiff_t count = SPECPDL_INDEX (); 5201 ptrdiff_t count = SPECPDL_INDEX ();
5209 5202
5210 /* Block input here so that we won't be surprised by an X expose 5203 /* Block input here so that we won't be surprised by an X expose
@@ -5249,7 +5242,7 @@ realize_basic_faces (struct frame *f)
5249 specified, make it fully-specified. Attributes of the default face 5242 specified, make it fully-specified. Attributes of the default face
5250 that are not explicitly specified are taken from frame parameters. */ 5243 that are not explicitly specified are taken from frame parameters. */
5251 5244
5252static int 5245static bool
5253realize_default_face (struct frame *f) 5246realize_default_face (struct frame *f)
5254{ 5247{
5255 struct face_cache *c = FRAME_FACE_CACHE (f); 5248 struct face_cache *c = FRAME_FACE_CACHE (f);
diff --git a/src/xfns.c b/src/xfns.c
index a3eff1a5cce..0c91e298ec8 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -176,7 +176,7 @@ check_x_display_info (Lisp_Object object)
176 dpyinfo = x_display_info_for_name (object); 176 dpyinfo = x_display_info_for_name (object);
177 else 177 else
178 { 178 {
179 FRAME_PTR f = decode_window_system_frame (object); 179 struct frame *f = decode_window_system_frame (object);
180 dpyinfo = FRAME_X_DISPLAY_INFO (f); 180 dpyinfo = FRAME_X_DISPLAY_INFO (f);
181 } 181 }
182 182
@@ -369,7 +369,7 @@ x_top_window_to_frame (struct x_display_info *dpyinfo, int wdesc)
369 not Emacs's own window. */ 369 not Emacs's own window. */
370 370
371void 371void
372x_real_positions (FRAME_PTR f, int *xptr, int *yptr) 372x_real_positions (struct frame *f, int *xptr, int *yptr)
373{ 373{
374 int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0); 374 int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0);
375 int real_x = 0, real_y = 0; 375 int real_x = 0, real_y = 0;
@@ -565,7 +565,7 @@ x_defined_color (struct frame *f, const char *color_name,
565 Signal an error if color can't be allocated. */ 565 Signal an error if color can't be allocated. */
566 566
567static int 567static int
568x_decode_color (FRAME_PTR f, Lisp_Object color_name, int mono_color) 568x_decode_color (struct frame *f, Lisp_Object color_name, int mono_color)
569{ 569{
570 XColor cdef; 570 XColor cdef;
571 571
@@ -626,7 +626,7 @@ x_set_tool_bar_position (struct frame *f,
626 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */ 626 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
627 627
628int 628int
629xg_set_icon (FRAME_PTR f, Lisp_Object file) 629xg_set_icon (struct frame *f, Lisp_Object file)
630{ 630{
631 int result = 0; 631 int result = 0;
632 Lisp_Object found; 632 Lisp_Object found;
@@ -660,7 +660,7 @@ xg_set_icon (FRAME_PTR f, Lisp_Object file)
660} 660}
661 661
662int 662int
663xg_set_icon_from_xpm_data (FRAME_PTR f, const char **data) 663xg_set_icon_from_xpm_data (struct frame *f, const char **data)
664{ 664{
665 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data); 665 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data);
666 666
@@ -942,7 +942,7 @@ static void
942x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 942x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
943{ 943{
944 unsigned long fore_pixel, pixel; 944 unsigned long fore_pixel, pixel;
945 int fore_pixel_allocated_p = 0, pixel_allocated_p = 0; 945 bool fore_pixel_allocated_p = 0, pixel_allocated_p = 0;
946 struct x_output *x = f->output_data.x; 946 struct x_output *x = f->output_data.x;
947 947
948 if (!NILP (Vx_cursor_fore_pixel)) 948 if (!NILP (Vx_cursor_fore_pixel))
@@ -1050,14 +1050,11 @@ x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1050 1050
1051 1051
1052static void 1052static void
1053x_set_cursor_type (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1053x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1054{ 1054{
1055 set_frame_cursor_types (f, arg); 1055 set_frame_cursor_types (f, arg);
1056
1057 /* Make sure the cursor gets redrawn. */
1058 cursor_type_changed = 1;
1059} 1056}
1060 1057
1061static void 1058static void
1062x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 1059x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1063{ 1060{
@@ -1449,7 +1446,7 @@ x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp,
1449 icon name to NAME. */ 1446 icon name to NAME. */
1450 1447
1451static void 1448static void
1452x_set_name_internal (FRAME_PTR f, Lisp_Object name) 1449x_set_name_internal (struct frame *f, Lisp_Object name)
1453{ 1450{
1454 if (FRAME_X_WINDOW (f)) 1451 if (FRAME_X_WINDOW (f))
1455 { 1452 {
@@ -1608,7 +1605,7 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
1608 specified a name for the frame; the name will override any set by the 1605 specified a name for the frame; the name will override any set by the
1609 redisplay code. */ 1606 redisplay code. */
1610static void 1607static void
1611x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1608x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1612{ 1609{
1613 x_set_name (f, arg, 1); 1610 x_set_name (f, arg, 1);
1614} 1611}
@@ -1617,7 +1614,7 @@ x_explicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval)
1617 name; names set this way will never override names set by the user's 1614 name; names set this way will never override names set by the user's
1618 lisp code. */ 1615 lisp code. */
1619void 1616void
1620x_implicitly_set_name (FRAME_PTR f, Lisp_Object arg, Lisp_Object oldval) 1617x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1621{ 1618{
1622 x_set_name (f, arg, 0); 1619 x_set_name (f, arg, 0);
1623} 1620}
@@ -1730,7 +1727,7 @@ x_default_scroll_bar_color_parameter (struct frame *f,
1730 for example, but Xt doesn't). */ 1727 for example, but Xt doesn't). */
1731 1728
1732static void 1729static void
1733hack_wm_protocols (FRAME_PTR f, Widget widget) 1730hack_wm_protocols (struct frame *f, Widget widget)
1734{ 1731{
1735 Display *dpy = XtDisplay (widget); 1732 Display *dpy = XtDisplay (widget);
1736 Window w = XtWindow (widget); 1733 Window w = XtWindow (widget);
@@ -2066,7 +2063,7 @@ void
2066xic_free_xfontset (struct frame *f) 2063xic_free_xfontset (struct frame *f)
2067{ 2064{
2068 Lisp_Object rest, frame; 2065 Lisp_Object rest, frame;
2069 int shared_p = 0; 2066 bool shared_p = 0;
2070 2067
2071 if (!FRAME_XIC_FONTSET (f)) 2068 if (!FRAME_XIC_FONTSET (f))
2072 return; 2069 return;
@@ -2088,9 +2085,6 @@ xic_free_xfontset (struct frame *f)
2088 /* The fontset is not used anymore. It is safe to free it. */ 2085 /* The fontset is not used anymore. It is safe to free it. */
2089 XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); 2086 XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
2090 2087
2091 if (FRAME_XIC_BASE_FONTNAME (f))
2092 xfree (FRAME_XIC_BASE_FONTNAME (f));
2093 FRAME_XIC_BASE_FONTNAME (f) = NULL;
2094 FRAME_XIC_FONTSET (f) = NULL; 2088 FRAME_XIC_FONTSET (f) = NULL;
2095} 2089}
2096 2090
@@ -2316,12 +2310,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2316 for the window manager, so GC relocation won't bother it. 2310 for the window manager, so GC relocation won't bother it.
2317 2311
2318 Elsewhere we specify the window name for the window manager. */ 2312 Elsewhere we specify the window name for the window manager. */
2319 2313 f->namebuf = xstrdup (SSDATA (Vx_resource_name));
2320 {
2321 char *str = SSDATA (Vx_resource_name);
2322 f->namebuf = xmalloc (strlen (str) + 1);
2323 strcpy (f->namebuf, str);
2324 }
2325 2314
2326 ac = 0; 2315 ac = 0;
2327 XtSetArg (al[ac], XtNallowShellResize, 1); ac++; 2316 XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
@@ -2339,12 +2328,8 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2339 /* maybe_set_screen_title_format (shell_widget); */ 2328 /* maybe_set_screen_title_format (shell_widget); */
2340 2329
2341 pane_widget = lw_create_widget ("main", "pane", widget_id_tick++, 2330 pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
2342 (widget_value *) NULL, 2331 NULL, shell_widget, False,
2343 shell_widget, False, 2332 NULL, NULL, NULL, NULL);
2344 (lw_callback) NULL,
2345 (lw_callback) NULL,
2346 (lw_callback) NULL,
2347 (lw_callback) NULL);
2348 2333
2349 ac = 0; 2334 ac = 0;
2350 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; 2335 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
@@ -2491,8 +2476,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2491 */ 2476 */
2492 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget), 2477 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
2493 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, 2478 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2494 XA_ATOM, 32, PropModeAppend, 2479 XA_ATOM, 32, PropModeAppend, NULL, 0);
2495 (unsigned char*) NULL, 0);
2496 2480
2497 /* Make all the standard events reach the Emacs frame. */ 2481 /* Make all the standard events reach the Emacs frame. */
2498 attributes.event_mask = STANDARD_EVENT_SET; 2482 attributes.event_mask = STANDARD_EVENT_SET;
@@ -2541,7 +2525,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2541#else /* not USE_X_TOOLKIT */ 2525#else /* not USE_X_TOOLKIT */
2542#ifdef USE_GTK 2526#ifdef USE_GTK
2543static void 2527static void
2544x_window (FRAME_PTR f) 2528x_window (struct frame *f)
2545{ 2529{
2546 if (! xg_create_frame_widgets (f)) 2530 if (! xg_create_frame_widgets (f))
2547 error ("Unable to create window"); 2531 error ("Unable to create window");
@@ -2791,10 +2775,6 @@ x_make_gc (struct frame *f)
2791 | GCFillStyle | GCLineWidth), 2775 | GCFillStyle | GCLineWidth),
2792 &gc_values); 2776 &gc_values);
2793 2777
2794 /* Reliefs. */
2795 f->output_data.x->white_relief.gc = 0;
2796 f->output_data.x->black_relief.gc = 0;
2797
2798 /* Create the gray border tile used when the pointer is not in 2778 /* Create the gray border tile used when the pointer is not in
2799 the frame. Since this depends on the frame's pixel values, 2779 the frame. Since this depends on the frame's pixel values,
2800 this must be done on a per-frame basis. */ 2780 this must be done on a per-frame basis. */
@@ -3492,7 +3472,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
3492 (Lisp_Object color, Lisp_Object frame) 3472 (Lisp_Object color, Lisp_Object frame)
3493{ 3473{
3494 XColor foo; 3474 XColor foo;
3495 FRAME_PTR f = decode_window_system_frame (frame); 3475 struct frame *f = decode_window_system_frame (frame);
3496 3476
3497 CHECK_STRING (color); 3477 CHECK_STRING (color);
3498 3478
@@ -3507,7 +3487,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3507 (Lisp_Object color, Lisp_Object frame) 3487 (Lisp_Object color, Lisp_Object frame)
3508{ 3488{
3509 XColor foo; 3489 XColor foo;
3510 FRAME_PTR f = decode_window_system_frame (frame); 3490 struct frame *f = decode_window_system_frame (frame);
3511 3491
3512 CHECK_STRING (color); 3492 CHECK_STRING (color);
3513 3493
@@ -4021,7 +4001,7 @@ x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo)
4021 / x_display_pixel_width (dpyinfo)); 4001 / x_display_pixel_width (dpyinfo));
4022 mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen) 4002 mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen)
4023 / x_display_pixel_height (dpyinfo)); 4003 / x_display_pixel_height (dpyinfo));
4024 monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); 4004 monitors = xzalloc (n_monitors * sizeof *monitors);
4025 for (i = 0; i < n_monitors; ++i) 4005 for (i = 0; i < n_monitors; ++i)
4026 { 4006 {
4027 struct MonitorInfo *mi = &monitors[i]; 4007 struct MonitorInfo *mi = &monitors[i];
@@ -4081,7 +4061,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
4081 return Qnil; 4061 return Qnil;
4082 } 4062 }
4083 n_monitors = resources->noutput; 4063 n_monitors = resources->noutput;
4084 monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); 4064 monitors = xzalloc (n_monitors * sizeof *monitors);
4085 4065
4086#ifdef HAVE_XRRGETOUTPUTPRIMARY 4066#ifdef HAVE_XRRGETOUTPUTPRIMARY
4087 pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window); 4067 pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window);
@@ -4237,7 +4217,7 @@ Internal use only, use `display-monitor-attributes-list' instead. */)
4237#endif 4217#endif
4238 n_monitors = gdk_screen_get_n_monitors (gscreen); 4218 n_monitors = gdk_screen_get_n_monitors (gscreen);
4239 monitor_frames = Fmake_vector (make_number (n_monitors), Qnil); 4219 monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
4240 monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors)); 4220 monitors = xzalloc (n_monitors * sizeof *monitors);
4241 4221
4242 FOR_EACH_FRAME (rest, frame) 4222 FOR_EACH_FRAME (rest, frame)
4243 { 4223 {
@@ -4325,19 +4305,6 @@ Internal use only, use `display-monitor-attributes-list' instead. */)
4325 return attributes_list; 4305 return attributes_list;
4326} 4306}
4327 4307
4328
4329int
4330x_pixel_width (register struct frame *f)
4331{
4332 return FRAME_PIXEL_WIDTH (f);
4333}
4334
4335int
4336x_pixel_height (register struct frame *f)
4337{
4338 return FRAME_PIXEL_HEIGHT (f);
4339}
4340
4341/************************************************************************ 4308/************************************************************************
4342 X Displays 4309 X Displays
4343 ************************************************************************/ 4310 ************************************************************************/
@@ -4488,8 +4455,7 @@ x_display_info_for_name (Lisp_Object name)
4488 4455
4489 validate_x_resource_name (); 4456 validate_x_resource_name ();
4490 4457
4491 dpyinfo = x_term_init (name, (char *)0, 4458 dpyinfo = x_term_init (name, 0, SSDATA (Vx_resource_name));
4492 SSDATA (Vx_resource_name));
4493 4459
4494 if (dpyinfo == 0) 4460 if (dpyinfo == 0)
4495 error ("Cannot connect to X server %s", SDATA (name)); 4461 error ("Cannot connect to X server %s", SDATA (name));
@@ -4522,10 +4488,7 @@ terminate Emacs if we can't open the connection.
4522 error ("Not using X Windows"); /* That doesn't stop us anymore. */ 4488 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4523#endif 4489#endif
4524 4490
4525 if (! NILP (xrm_string)) 4491 xrm_option = NILP (xrm_string) ? 0 : SSDATA (xrm_string);
4526 xrm_option = SSDATA (xrm_string);
4527 else
4528 xrm_option = (char *) 0;
4529 4492
4530 validate_x_resource_name (); 4493 validate_x_resource_name ();
4531 4494
@@ -4606,7 +4569,7 @@ If TERMINAL is omitted or nil, that stands for the selected frame's display. */
4606/* Wait for responses to all X commands issued so far for frame F. */ 4569/* Wait for responses to all X commands issued so far for frame F. */
4607 4570
4608void 4571void
4609x_sync (FRAME_PTR f) 4572x_sync (struct frame *f)
4610{ 4573{
4611 block_input (); 4574 block_input ();
4612 XSync (FRAME_X_DISPLAY (f), False); 4575 XSync (FRAME_X_DISPLAY (f), False);
@@ -5749,8 +5712,8 @@ DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
5749static void 5712static void
5750file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data) 5713file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data)
5751{ 5714{
5752 int *result = (int *) client_data; 5715 int *result = client_data;
5753 XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data; 5716 XmAnyCallbackStruct *cb = call_data;
5754 *result = cb->reason; 5717 *result = cb->reason;
5755} 5718}
5756 5719
@@ -5763,7 +5726,7 @@ file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data)
5763static void 5726static void
5764file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data) 5727file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data)
5765{ 5728{
5766 int *result = (int *) client_data; 5729 int *result = client_data;
5767 *result = XmCR_CANCEL; 5730 *result = XmCR_CANCEL;
5768} 5731}
5769 5732
@@ -5790,7 +5753,8 @@ or directory must exist.
5790This function is only defined on NS, MS Windows, and X Windows with the 5753This function is only defined on NS, MS Windows, and X Windows with the
5791Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. 5754Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5792Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 5755Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5793 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 5756 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename,
5757 Lisp_Object mustmatch, Lisp_Object only_dir_p)
5794{ 5758{
5795 int result; 5759 int result;
5796 struct frame *f = SELECTED_FRAME (); 5760 struct frame *f = SELECTED_FRAME ();
@@ -5963,7 +5927,7 @@ Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5963Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) 5927Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5964 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) 5928 (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p)
5965{ 5929{
5966 FRAME_PTR f = SELECTED_FRAME (); 5930 struct frame *f = SELECTED_FRAME ();
5967 char *fn; 5931 char *fn;
5968 Lisp_Object file = Qnil; 5932 Lisp_Object file = Qnil;
5969 Lisp_Object decoded_file; 5933 Lisp_Object decoded_file;
@@ -6026,7 +5990,7 @@ FRAME is the frame on which to pop up the font chooser. If omitted or
6026nil, it defaults to the selected frame. */) 5990nil, it defaults to the selected frame. */)
6027 (Lisp_Object frame, Lisp_Object ignored) 5991 (Lisp_Object frame, Lisp_Object ignored)
6028{ 5992{
6029 FRAME_PTR f = decode_window_system_frame (frame); 5993 struct frame *f = decode_window_system_frame (frame);
6030 Lisp_Object font; 5994 Lisp_Object font;
6031 Lisp_Object font_param; 5995 Lisp_Object font_param;
6032 char *default_name = NULL; 5996 char *default_name = NULL;
diff --git a/src/xfont.c b/src/xfont.c
index 9647a51ac6e..1aface6f972 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -114,19 +114,19 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b)
114 ? NULL : pcm); 114 ? NULL : pcm);
115} 115}
116 116
117static Lisp_Object xfont_get_cache (FRAME_PTR); 117static Lisp_Object xfont_get_cache (struct frame *);
118static Lisp_Object xfont_list (Lisp_Object, Lisp_Object); 118static Lisp_Object xfont_list (struct frame *, Lisp_Object);
119static Lisp_Object xfont_match (Lisp_Object, Lisp_Object); 119static Lisp_Object xfont_match (struct frame *, Lisp_Object);
120static Lisp_Object xfont_list_family (Lisp_Object); 120static Lisp_Object xfont_list_family (struct frame *);
121static Lisp_Object xfont_open (FRAME_PTR, Lisp_Object, int); 121static Lisp_Object xfont_open (struct frame *, Lisp_Object, int);
122static void xfont_close (FRAME_PTR, struct font *); 122static void xfont_close (struct frame *, struct font *);
123static int xfont_prepare_face (FRAME_PTR, struct face *); 123static int xfont_prepare_face (struct frame *, struct face *);
124static int xfont_has_char (Lisp_Object, int); 124static int xfont_has_char (Lisp_Object, int);
125static unsigned xfont_encode_char (struct font *, int); 125static unsigned xfont_encode_char (struct font *, int);
126static int xfont_text_extents (struct font *, unsigned *, int, 126static int xfont_text_extents (struct font *, unsigned *, int,
127 struct font_metrics *); 127 struct font_metrics *);
128static int xfont_draw (struct glyph_string *, int, int, int, int, bool); 128static int xfont_draw (struct glyph_string *, int, int, int, int, bool);
129static int xfont_check (FRAME_PTR, struct font *); 129static int xfont_check (struct frame *, struct font *);
130 130
131struct font_driver xfont_driver = 131struct font_driver xfont_driver =
132 { 132 {
@@ -152,7 +152,7 @@ struct font_driver xfont_driver =
152 }; 152 };
153 153
154static Lisp_Object 154static Lisp_Object
155xfont_get_cache (FRAME_PTR f) 155xfont_get_cache (struct frame *f)
156{ 156{
157 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 157 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
158 158
@@ -486,9 +486,8 @@ xfont_list_pattern (Display *display, const char *pattern,
486} 486}
487 487
488static Lisp_Object 488static Lisp_Object
489xfont_list (Lisp_Object frame, Lisp_Object spec) 489xfont_list (struct frame *f, Lisp_Object spec)
490{ 490{
491 FRAME_PTR f = XFRAME (frame);
492 Display *display = FRAME_X_DISPLAY_INFO (f)->display; 491 Display *display = FRAME_X_DISPLAY_INFO (f)->display;
493 Lisp_Object registry, list, val, extra, script; 492 Lisp_Object registry, list, val, extra, script;
494 int len; 493 int len;
@@ -565,9 +564,8 @@ xfont_list (Lisp_Object frame, Lisp_Object spec)
565} 564}
566 565
567static Lisp_Object 566static Lisp_Object
568xfont_match (Lisp_Object frame, Lisp_Object spec) 567xfont_match (struct frame *f, Lisp_Object spec)
569{ 568{
570 FRAME_PTR f = XFRAME (frame);
571 Display *display = FRAME_X_DISPLAY_INFO (f)->display; 569 Display *display = FRAME_X_DISPLAY_INFO (f)->display;
572 Lisp_Object extra, val, entity; 570 Lisp_Object extra, val, entity;
573 char name[512]; 571 char name[512];
@@ -595,9 +593,7 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
595 { 593 {
596 if (XGetFontProperty (xfont, XA_FONT, &value)) 594 if (XGetFontProperty (xfont, XA_FONT, &value))
597 { 595 {
598 char *s; 596 char *s = XGetAtomName (display, (Atom) value);
599
600 s = (char *) XGetAtomName (display, (Atom) value);
601 597
602 /* If DXPC (a Differential X Protocol Compressor) 598 /* If DXPC (a Differential X Protocol Compressor)
603 Ver.3.7 is running, XGetAtomName will return null 599 Ver.3.7 is running, XGetAtomName will return null
@@ -622,9 +618,8 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
622} 618}
623 619
624static Lisp_Object 620static Lisp_Object
625xfont_list_family (Lisp_Object frame) 621xfont_list_family (struct frame *f)
626{ 622{
627 FRAME_PTR f = XFRAME (frame);
628 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 623 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
629 char **names; 624 char **names;
630 int num_fonts, i; 625 int num_fonts, i;
@@ -679,7 +674,7 @@ xfont_list_family (Lisp_Object frame)
679} 674}
680 675
681static Lisp_Object 676static Lisp_Object
682xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size) 677xfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
683{ 678{
684 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 679 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
685 Display *display = dpyinfo->display; 680 Display *display = dpyinfo->display;
@@ -763,7 +758,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
763 char *p0, *p; 758 char *p0, *p;
764 int dashes = 0; 759 int dashes = 0;
765 760
766 p0 = p = (char *) XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value); 761 p0 = p = XGetAtomName (FRAME_X_DISPLAY (f), (Atom) value);
767 /* Count the number of dashes in the "full name". 762 /* Count the number of dashes in the "full name".
768 If it is too few, this isn't really the font's full name, 763 If it is too few, this isn't really the font's full name,
769 so don't use it. 764 so don't use it.
@@ -895,7 +890,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
895} 890}
896 891
897static void 892static void
898xfont_close (FRAME_PTR f, struct font *font) 893xfont_close (struct frame *f, struct font *font)
899{ 894{
900 block_input (); 895 block_input ();
901 XFreeFont (FRAME_X_DISPLAY (f), ((struct xfont_info *) font)->xfont); 896 XFreeFont (FRAME_X_DISPLAY (f), ((struct xfont_info *) font)->xfont);
@@ -903,7 +898,7 @@ xfont_close (FRAME_PTR f, struct font *font)
903} 898}
904 899
905static int 900static int
906xfont_prepare_face (FRAME_PTR f, struct face *face) 901xfont_prepare_face (struct frame *f, struct face *face)
907{ 902{
908 block_input (); 903 block_input ();
909 XSetFont (FRAME_X_DISPLAY (f), face->gc, 904 XSetFont (FRAME_X_DISPLAY (f), face->gc,
@@ -1092,7 +1087,7 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1092} 1087}
1093 1088
1094static int 1089static int
1095xfont_check (FRAME_PTR f, struct font *font) 1090xfont_check (struct frame *f, struct font *font)
1096{ 1091{
1097 struct xfont_info *xfont = (struct xfont_info *) font; 1092 struct xfont_info *xfont = (struct xfont_info *) font;
1098 1093
diff --git a/src/xftfont.c b/src/xftfont.c
index 166a70acd85..f2b4c2abe2b 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -70,7 +70,7 @@ struct xftface_info
70 XftColor xft_bg; /* color for face->background */ 70 XftColor xft_bg; /* color for face->background */
71}; 71};
72 72
73static void xftfont_get_colors (FRAME_PTR, struct face *, GC gc, 73static void xftfont_get_colors (struct frame *, struct face *, GC gc,
74 struct xftface_info *, 74 struct xftface_info *,
75 XftColor *fg, XftColor *bg); 75 XftColor *fg, XftColor *bg);
76 76
@@ -80,7 +80,9 @@ static void xftfont_get_colors (FRAME_PTR, struct face *, GC gc,
80 may be NULL. */ 80 may be NULL. */
81 81
82static void 82static void
83xftfont_get_colors (FRAME_PTR f, struct face *face, GC gc, struct xftface_info *xftface_info, XftColor *fg, XftColor *bg) 83xftfont_get_colors (struct frame *f, struct face *face, GC gc,
84 struct xftface_info *xftface_info,
85 XftColor *fg, XftColor *bg)
84{ 86{
85 if (xftface_info && face->gc == gc) 87 if (xftface_info && face->gc == gc)
86 { 88 {
@@ -139,9 +141,9 @@ xftfont_get_colors (FRAME_PTR f, struct face *face, GC gc, struct xftface_info *
139struct font_driver xftfont_driver; 141struct font_driver xftfont_driver;
140 142
141static Lisp_Object 143static Lisp_Object
142xftfont_list (Lisp_Object frame, Lisp_Object spec) 144xftfont_list (struct frame *f, Lisp_Object spec)
143{ 145{
144 Lisp_Object list = ftfont_driver.list (frame, spec), tail; 146 Lisp_Object list = ftfont_driver.list (f, spec), tail;
145 147
146 for (tail = list; CONSP (tail); tail = XCDR (tail)) 148 for (tail = list; CONSP (tail); tail = XCDR (tail))
147 ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft); 149 ASET (XCAR (tail), FONT_TYPE_INDEX, Qxft);
@@ -149,9 +151,9 @@ xftfont_list (Lisp_Object frame, Lisp_Object spec)
149} 151}
150 152
151static Lisp_Object 153static Lisp_Object
152xftfont_match (Lisp_Object frame, Lisp_Object spec) 154xftfont_match (struct frame *f, Lisp_Object spec)
153{ 155{
154 Lisp_Object entity = ftfont_driver.match (frame, spec); 156 Lisp_Object entity = ftfont_driver.match (f, spec);
155 157
156 if (! NILP (entity)) 158 if (! NILP (entity))
157 ASET (entity, FONT_TYPE_INDEX, Qxft); 159 ASET (entity, FONT_TYPE_INDEX, Qxft);
@@ -262,7 +264,7 @@ xftfont_add_rendering_parameters (FcPattern *pat, Lisp_Object entity)
262} 264}
263 265
264static Lisp_Object 266static Lisp_Object
265xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size) 267xftfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
266{ 268{
267 FcResult result; 269 FcResult result;
268 Display *display = FRAME_X_DISPLAY (f); 270 Display *display = FRAME_X_DISPLAY (f);
@@ -484,7 +486,7 @@ xftfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
484} 486}
485 487
486static void 488static void
487xftfont_close (FRAME_PTR f, struct font *font) 489xftfont_close (struct frame *f, struct font *font)
488{ 490{
489 struct xftfont_info *xftfont_info = (struct xftfont_info *) font; 491 struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
490 492
@@ -499,7 +501,7 @@ xftfont_close (FRAME_PTR f, struct font *font)
499} 501}
500 502
501static int 503static int
502xftfont_prepare_face (FRAME_PTR f, struct face *face) 504xftfont_prepare_face (struct frame *f, struct face *face)
503{ 505{
504 struct xftface_info *xftface_info; 506 struct xftface_info *xftface_info;
505 507
@@ -522,7 +524,7 @@ xftfont_prepare_face (FRAME_PTR f, struct face *face)
522} 524}
523 525
524static void 526static void
525xftfont_done_face (FRAME_PTR f, struct face *face) 527xftfont_done_face (struct frame *f, struct face *face)
526{ 528{
527 struct xftface_info *xftface_info; 529 struct xftface_info *xftface_info;
528 530
@@ -595,7 +597,7 @@ xftfont_text_extents (struct font *font, unsigned int *code, int nglyphs, struct
595} 597}
596 598
597static XftDraw * 599static XftDraw *
598xftfont_get_xft_draw (FRAME_PTR f) 600xftfont_get_xft_draw (struct frame *f)
599{ 601{
600 XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver); 602 XftDraw *xft_draw = font_get_frame_data (f, &xftfont_driver);
601 603
@@ -617,7 +619,7 @@ static int
617xftfont_draw (struct glyph_string *s, int from, int to, int x, int y, 619xftfont_draw (struct glyph_string *s, int from, int to, int x, int y,
618 bool with_background) 620 bool with_background)
619{ 621{
620 FRAME_PTR f = s->f; 622 struct frame *f = s->f;
621 struct face *face = s->face; 623 struct face *face = s->face;
622 struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font; 624 struct xftfont_info *xftfont_info = (struct xftfont_info *) s->font;
623 struct xftface_info *xftface_info = NULL; 625 struct xftface_info *xftface_info = NULL;
@@ -677,7 +679,7 @@ xftfont_shape (Lisp_Object lgstring)
677#endif 679#endif
678 680
679static int 681static int
680xftfont_end_for_frame (FRAME_PTR f) 682xftfont_end_for_frame (struct frame *f)
681{ 683{
682 XftDraw *xft_draw; 684 XftDraw *xft_draw;
683 685
diff --git a/src/xmenu.c b/src/xmenu.c
index 6c0e3dd78a6..95ae5393553 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -111,7 +111,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
111static Lisp_Object Qdebug_on_next_call; 111static Lisp_Object Qdebug_on_next_call;
112 112
113#if defined (USE_X_TOOLKIT) || defined (USE_GTK) 113#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
114static Lisp_Object xdialog_show (FRAME_PTR, bool, Lisp_Object, Lisp_Object, 114static Lisp_Object xdialog_show (struct frame *, bool, Lisp_Object, Lisp_Object,
115 const char **); 115 const char **);
116#endif 116#endif
117 117
@@ -130,7 +130,7 @@ static struct frame *
130menubar_id_to_frame (LWLIB_ID id) 130menubar_id_to_frame (LWLIB_ID id)
131{ 131{
132 Lisp_Object tail, frame; 132 Lisp_Object tail, frame;
133 FRAME_PTR f; 133 struct frame *f;
134 134
135 FOR_EACH_FRAME (tail, frame) 135 FOR_EACH_FRAME (tail, frame)
136 { 136 {
@@ -154,13 +154,12 @@ menubar_id_to_frame (LWLIB_ID id)
154 the scroll bar or the edit window. Fx_popup_menu needs to be 154 the scroll bar or the edit window. Fx_popup_menu needs to be
155 sure it is the edit window. */ 155 sure it is the edit window. */
156void 156void
157mouse_position_for_popup (FRAME_PTR f, int *x, int *y) 157mouse_position_for_popup (struct frame *f, int *x, int *y)
158{ 158{
159 Window root, dummy_window; 159 Window root, dummy_window;
160 int dummy; 160 int dummy;
161 161
162 if (! FRAME_X_P (f)) 162 eassert (FRAME_X_P (f));
163 emacs_abort ();
164 163
165 block_input (); 164 block_input ();
166 165
@@ -220,7 +219,7 @@ for instance using the window manager, then this produces a quit and
220`x-popup-dialog' does not return. */) 219`x-popup-dialog' does not return. */)
221 (Lisp_Object position, Lisp_Object contents, Lisp_Object header) 220 (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
222{ 221{
223 FRAME_PTR f = NULL; 222 struct frame *f = NULL;
224 Lisp_Object window; 223 Lisp_Object window;
225 224
226 /* Decode the first argument: find the window or frame to use. */ 225 /* Decode the first argument: find the window or frame to use. */
@@ -230,7 +229,7 @@ for instance using the window manager, then this produces a quit and
230 { 229 {
231#if 0 /* Using the frame the mouse is on may not be right. */ 230#if 0 /* Using the frame the mouse is on may not be right. */
232 /* Use the mouse's current position. */ 231 /* Use the mouse's current position. */
233 FRAME_PTR new_f = SELECTED_FRAME (); 232 struct frame *new_f = SELECTED_FRAME ();
234 Lisp_Object bar_window; 233 Lisp_Object bar_window;
235 enum scroll_bar_part part; 234 enum scroll_bar_part part;
236 Time time; 235 Time time;
@@ -294,8 +293,8 @@ for instance using the window manager, then this produces a quit and
294 { 293 {
295 Lisp_Object x, y, frame, newpos; 294 Lisp_Object x, y, frame, newpos;
296 XSETFRAME (frame, f); 295 XSETFRAME (frame, f);
297 XSETINT (x, x_pixel_width (f) / 2); 296 XSETINT (x, FRAME_PIXEL_WIDTH (f) / 2);
298 XSETINT (y, x_pixel_height (f) / 2); 297 XSETINT (y, FRAME_PIXEL_HEIGHT (f) / 2);
299 newpos = list2 (list2 (x, y), frame); 298 newpos = list2 (list2 (x, y), frame);
300 299
301 return Fx_popup_menu (newpos, 300 return Fx_popup_menu (newpos,
@@ -374,7 +373,7 @@ x_menu_wait_for_event (void *data)
374#elif defined USE_GTK 373#elif defined USE_GTK
375 ! gtk_events_pending () 374 ! gtk_events_pending ()
376#else 375#else
377 ! XPending ((Display*) data) 376 ! XPending (data)
378#endif 377#endif
379 ) 378 )
380 { 379 {
@@ -482,7 +481,7 @@ If FRAME is nil or not given, use the selected frame. */)
482 (Lisp_Object frame) 481 (Lisp_Object frame)
483{ 482{
484 XEvent ev; 483 XEvent ev;
485 FRAME_PTR f = decode_window_system_frame (frame); 484 struct frame *f = decode_window_system_frame (frame);
486 Widget menubar; 485 Widget menubar;
487 block_input (); 486 block_input ();
488 487
@@ -493,7 +492,7 @@ If FRAME is nil or not given, use the selected frame. */)
493 if (menubar) 492 if (menubar)
494 { 493 {
495 Window child; 494 Window child;
496 int error_p = 0; 495 bool error_p = 0;
497 496
498 x_catch_errors (FRAME_X_DISPLAY (f)); 497 x_catch_errors (FRAME_X_DISPLAY (f));
499 memset (&ev, 0, sizeof ev); 498 memset (&ev, 0, sizeof ev);
@@ -560,10 +559,7 @@ If FRAME is nil or not given, use the selected frame. */)
560 (Lisp_Object frame) 559 (Lisp_Object frame)
561{ 560{
562 GtkWidget *menubar; 561 GtkWidget *menubar;
563 FRAME_PTR f; 562 struct frame *f;
564
565 /* gcc 2.95 doesn't accept the FRAME_PTR declaration after
566 block_input (). */
567 563
568 block_input (); 564 block_input ();
569 f = decode_window_system_frame (frame); 565 f = decode_window_system_frame (frame);
@@ -621,10 +617,9 @@ popup_widget_loop (int do_timers, GtkWidget *widget)
621 execute Lisp code. */ 617 execute Lisp code. */
622 618
623void 619void
624x_activate_menubar (FRAME_PTR f) 620x_activate_menubar (struct frame *f)
625{ 621{
626 if (! FRAME_X_P (f)) 622 eassert (FRAME_X_P (f));
627 emacs_abort ();
628 623
629 if (!f->output_data.x->saved_menu_event->type) 624 if (!f->output_data.x->saved_menu_event->type)
630 return; 625 return;
@@ -684,7 +679,7 @@ popup_deactivate_callback (
684 for that widget. 679 for that widget.
685 F is the frame if known, or NULL if not known. */ 680 F is the frame if known, or NULL if not known. */
686static void 681static void
687show_help_event (FRAME_PTR f, xt_or_gtk_widget widget, Lisp_Object help) 682show_help_event (struct frame *f, xt_or_gtk_widget widget, Lisp_Object help)
688{ 683{
689 Lisp_Object frame; 684 Lisp_Object frame;
690 685
@@ -727,8 +722,7 @@ menu_highlight_callback (GtkWidget *widget, gpointer call_data)
727 xg_menu_item_cb_data *cb_data; 722 xg_menu_item_cb_data *cb_data;
728 Lisp_Object help; 723 Lisp_Object help;
729 724
730 cb_data = (xg_menu_item_cb_data*) g_object_get_data (G_OBJECT (widget), 725 cb_data = g_object_get_data (G_OBJECT (widget), XG_ITEM_DATA);
731 XG_ITEM_DATA);
732 if (! cb_data) return; 726 if (! cb_data) return;
733 727
734 help = call_data ? cb_data->help : Qnil; 728 help = call_data ? cb_data->help : Qnil;
@@ -746,15 +740,11 @@ menu_highlight_callback (GtkWidget *widget, gpointer call_data)
746static void 740static void
747menu_highlight_callback (Widget widget, LWLIB_ID id, void *call_data) 741menu_highlight_callback (Widget widget, LWLIB_ID id, void *call_data)
748{ 742{
749 struct frame *f; 743 widget_value *wv = call_data;
750 Lisp_Object help; 744 Lisp_Object help = wv ? wv->help : Qnil;
751
752 widget_value *wv = (widget_value *) call_data;
753
754 help = wv ? wv->help : Qnil;
755 745
756 /* Determine the frame for the help event. */ 746 /* Determine the frame for the help event. */
757 f = menubar_id_to_frame (id); 747 struct frame *f = menubar_id_to_frame (id);
758 748
759 show_help_event (f, widget, help); 749 show_help_event (f, widget, help);
760} 750}
@@ -774,7 +764,7 @@ static int xg_crazy_callback_abort;
774static void 764static void
775menubar_selection_callback (GtkWidget *widget, gpointer client_data) 765menubar_selection_callback (GtkWidget *widget, gpointer client_data)
776{ 766{
777 xg_menu_item_cb_data *cb_data = (xg_menu_item_cb_data*) client_data; 767 xg_menu_item_cb_data *cb_data = client_data;
778 768
779 if (xg_crazy_callback_abort) 769 if (xg_crazy_callback_abort)
780 return; 770 return;
@@ -817,7 +807,7 @@ menubar_selection_callback (GtkWidget *widget, gpointer client_data)
817static void 807static void
818menubar_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data) 808menubar_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
819{ 809{
820 FRAME_PTR f; 810 struct frame *f;
821 811
822 f = menubar_id_to_frame (id); 812 f = menubar_id_to_frame (id);
823 if (!f) 813 if (!f)
@@ -831,7 +821,7 @@ menubar_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
831 changed. */ 821 changed. */
832 822
833static void 823static void
834update_frame_menubar (FRAME_PTR f) 824update_frame_menubar (struct frame *f)
835{ 825{
836#ifdef USE_GTK 826#ifdef USE_GTK
837 xg_update_frame_menubar (f); 827 xg_update_frame_menubar (f);
@@ -839,8 +829,7 @@ update_frame_menubar (FRAME_PTR f)
839 struct x_output *x; 829 struct x_output *x;
840 int columns, rows; 830 int columns, rows;
841 831
842 if (! FRAME_X_P (f)) 832 eassert (FRAME_X_P (f));
843 emacs_abort ();
844 833
845 x = f->output_data.x; 834 x = f->output_data.x;
846 835
@@ -914,7 +903,7 @@ apply_systemfont_to_menu (struct frame *f, Widget w)
914 it is set the first time this is called, from initialize_frame_menubar. */ 903 it is set the first time this is called, from initialize_frame_menubar. */
915 904
916void 905void
917set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p) 906set_frame_menubar (struct frame *f, bool first_time, bool deep_p)
918{ 907{
919 xt_or_gtk_widget menubar_widget; 908 xt_or_gtk_widget menubar_widget;
920#ifdef USE_X_TOOLKIT 909#ifdef USE_X_TOOLKIT
@@ -927,8 +916,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
927 bool *submenu_top_level_items; 916 bool *submenu_top_level_items;
928 int *submenu_n_panes; 917 int *submenu_n_panes;
929 918
930 if (! FRAME_X_P (f)) 919 eassert (FRAME_X_P (f));
931 emacs_abort ();
932 920
933 menubar_widget = f->output_data.x->menubar_widget; 921 menubar_widget = f->output_data.x->menubar_widget;
934 922
@@ -1267,7 +1255,7 @@ set_frame_menubar (FRAME_PTR f, bool first_time, bool deep_p)
1267 is visible. */ 1255 is visible. */
1268 1256
1269void 1257void
1270initialize_frame_menubar (FRAME_PTR f) 1258initialize_frame_menubar (struct frame *f)
1271{ 1259{
1272 /* This function is called before the first chance to redisplay 1260 /* This function is called before the first chance to redisplay
1273 the frame. It has to be, so the frame will have the right size. */ 1261 the frame. It has to be, so the frame will have the right size. */
@@ -1282,12 +1270,11 @@ initialize_frame_menubar (FRAME_PTR f)
1282 1270
1283#ifndef USE_GTK 1271#ifndef USE_GTK
1284void 1272void
1285free_frame_menubar (FRAME_PTR f) 1273free_frame_menubar (struct frame *f)
1286{ 1274{
1287 Widget menubar_widget; 1275 Widget menubar_widget;
1288 1276
1289 if (! FRAME_X_P (f)) 1277 eassert (FRAME_X_P (f));
1290 emacs_abort ();
1291 1278
1292 menubar_widget = f->output_data.x->menubar_widget; 1279 menubar_widget = f->output_data.x->menubar_widget;
1293 1280
@@ -1360,7 +1347,7 @@ static Lisp_Object *volatile menu_item_selection;
1360 create_and_show_popup_menu below. */ 1347 create_and_show_popup_menu below. */
1361struct next_popup_x_y 1348struct next_popup_x_y
1362{ 1349{
1363 FRAME_PTR f; 1350 struct frame *f;
1364 int x; 1351 int x;
1365 int y; 1352 int y;
1366}; 1353};
@@ -1378,7 +1365,7 @@ struct next_popup_x_y
1378static void 1365static void
1379menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data) 1366menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
1380{ 1367{
1381 struct next_popup_x_y* data = (struct next_popup_x_y*)user_data; 1368 struct next_popup_x_y *data = user_data;
1382 GtkRequisition req; 1369 GtkRequisition req;
1383 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (data->f); 1370 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (data->f);
1384 int disp_width = x_display_pixel_width (dpyinfo); 1371 int disp_width = x_display_pixel_width (dpyinfo);
@@ -1399,10 +1386,10 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer
1399static void 1386static void
1400popup_selection_callback (GtkWidget *widget, gpointer client_data) 1387popup_selection_callback (GtkWidget *widget, gpointer client_data)
1401{ 1388{
1402 xg_menu_item_cb_data *cb_data = (xg_menu_item_cb_data*) client_data; 1389 xg_menu_item_cb_data *cb_data = client_data;
1403 1390
1404 if (xg_crazy_callback_abort) return; 1391 if (xg_crazy_callback_abort) return;
1405 if (cb_data) menu_item_selection = (Lisp_Object *) cb_data->call_data; 1392 if (cb_data) menu_item_selection = cb_data->call_data;
1406} 1393}
1407 1394
1408static void 1395static void
@@ -1418,7 +1405,7 @@ pop_down_menu (void *arg)
1418 menu pops down. 1405 menu pops down.
1419 menu_item_selection will be set to the selection. */ 1406 menu_item_selection will be set to the selection. */
1420static void 1407static void
1421create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, 1408create_and_show_popup_menu (struct frame *f, widget_value *first_wv, int x, int y,
1422 bool for_click, Time timestamp) 1409 bool for_click, Time timestamp)
1423{ 1410{
1424 int i; 1411 int i;
@@ -1434,8 +1421,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
1434 use_pos_func = 1; 1421 use_pos_func = 1;
1435#endif 1422#endif
1436 1423
1437 if (! FRAME_X_P (f)) 1424 eassert (FRAME_X_P (f));
1438 emacs_abort ();
1439 1425
1440 xg_crazy_callback_abort = 1; 1426 xg_crazy_callback_abort = 1;
1441 menu = xg_create_widget ("popup", first_wv->name, f, first_wv, 1427 menu = xg_create_widget ("popup", first_wv->name, f, first_wv,
@@ -1506,7 +1492,7 @@ LWLIB_ID widget_id_tick;
1506static void 1492static void
1507popup_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data) 1493popup_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
1508{ 1494{
1509 menu_item_selection = (Lisp_Object *) client_data; 1495 menu_item_selection = client_data;
1510} 1496}
1511 1497
1512/* ARG is the LWLIB ID of the dialog box, represented 1498/* ARG is the LWLIB ID of the dialog box, represented
@@ -1528,7 +1514,7 @@ pop_down_menu (Lisp_Object arg)
1528 menu pops down. 1514 menu pops down.
1529 menu_item_selection will be set to the selection. */ 1515 menu_item_selection will be set to the selection. */
1530static void 1516static void
1531create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, 1517create_and_show_popup_menu (struct frame *f, widget_value *first_wv,
1532 int x, int y, bool for_click, Time timestamp) 1518 int x, int y, bool for_click, Time timestamp)
1533{ 1519{
1534 int i; 1520 int i;
@@ -1539,8 +1525,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
1539 LWLIB_ID menu_id; 1525 LWLIB_ID menu_id;
1540 Widget menu; 1526 Widget menu;
1541 1527
1542 if (! FRAME_X_P (f)) 1528 eassert (FRAME_X_P (f));
1543 emacs_abort ();
1544 1529
1545#ifdef USE_LUCID 1530#ifdef USE_LUCID
1546 apply_systemfont_to_menu (f, f->output_data.x->widget); 1531 apply_systemfont_to_menu (f, f->output_data.x->widget);
@@ -1593,7 +1578,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
1593 make_number (menu_id & ~(-1 << (fact))))); 1578 make_number (menu_id & ~(-1 << (fact)))));
1594 1579
1595 /* Process events that apply to the menu. */ 1580 /* Process events that apply to the menu. */
1596 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id, 1); 1581 popup_get_selection (0, FRAME_X_DISPLAY_INFO (f), menu_id, 1);
1597 1582
1598 unbind_to (specpdl_count, Qnil); 1583 unbind_to (specpdl_count, Qnil);
1599 } 1584 }
@@ -1608,7 +1593,7 @@ cleanup_widget_value_tree (void *arg)
1608} 1593}
1609 1594
1610Lisp_Object 1595Lisp_Object
1611xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, 1596xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
1612 Lisp_Object title, const char **error_name, Time timestamp) 1597 Lisp_Object title, const char **error_name, Time timestamp)
1613{ 1598{
1614 int i; 1599 int i;
@@ -1623,8 +1608,7 @@ xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
1623 1608
1624 ptrdiff_t specpdl_count = SPECPDL_INDEX (); 1609 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
1625 1610
1626 if (! FRAME_X_P (f)) 1611 eassert (FRAME_X_P (f));
1627 emacs_abort ();
1628 1612
1629 *error_name = NULL; 1613 *error_name = NULL;
1630 1614
@@ -1893,7 +1877,7 @@ dialog_selection_callback (GtkWidget *widget, gpointer client_data)
1893 /* Treat the pointer as an integer. There's no problem 1877 /* Treat the pointer as an integer. There's no problem
1894 as long as pointers have enough bits to hold small integers. */ 1878 as long as pointers have enough bits to hold small integers. */
1895 if ((intptr_t) client_data != -1) 1879 if ((intptr_t) client_data != -1)
1896 menu_item_selection = (Lisp_Object *) client_data; 1880 menu_item_selection = client_data;
1897 1881
1898 popup_activated_flag = 0; 1882 popup_activated_flag = 0;
1899} 1883}
@@ -1902,12 +1886,11 @@ dialog_selection_callback (GtkWidget *widget, gpointer client_data)
1902 dialog pops down. 1886 dialog pops down.
1903 menu_item_selection will be set to the selection. */ 1887 menu_item_selection will be set to the selection. */
1904static void 1888static void
1905create_and_show_dialog (FRAME_PTR f, widget_value *first_wv) 1889create_and_show_dialog (struct frame *f, widget_value *first_wv)
1906{ 1890{
1907 GtkWidget *menu; 1891 GtkWidget *menu;
1908 1892
1909 if (! FRAME_X_P (f)) 1893 eassert (FRAME_X_P (f));
1910 emacs_abort ();
1911 1894
1912 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv, 1895 menu = xg_create_widget ("dialog", first_wv->name, f, first_wv,
1913 G_CALLBACK (dialog_selection_callback), 1896 G_CALLBACK (dialog_selection_callback),
@@ -1936,7 +1919,7 @@ dialog_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
1936 /* Treat the pointer as an integer. There's no problem 1919 /* Treat the pointer as an integer. There's no problem
1937 as long as pointers have enough bits to hold small integers. */ 1920 as long as pointers have enough bits to hold small integers. */
1938 if ((intptr_t) client_data != -1) 1921 if ((intptr_t) client_data != -1)
1939 menu_item_selection = (Lisp_Object *) client_data; 1922 menu_item_selection = client_data;
1940 1923
1941 block_input (); 1924 block_input ();
1942 lw_destroy_all_widgets (id); 1925 lw_destroy_all_widgets (id);
@@ -1949,12 +1932,11 @@ dialog_selection_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
1949 dialog pops down. 1932 dialog pops down.
1950 menu_item_selection will be set to the selection. */ 1933 menu_item_selection will be set to the selection. */
1951static void 1934static void
1952create_and_show_dialog (FRAME_PTR f, widget_value *first_wv) 1935create_and_show_dialog (struct frame *f, widget_value *first_wv)
1953{ 1936{
1954 LWLIB_ID dialog_id; 1937 LWLIB_ID dialog_id;
1955 1938
1956 if (!FRAME_X_P (f)) 1939 eassert (FRAME_X_P (f));
1957 emacs_abort ();
1958 1940
1959 dialog_id = widget_id_tick++; 1941 dialog_id = widget_id_tick++;
1960#ifdef USE_LUCID 1942#ifdef USE_LUCID
@@ -1980,8 +1962,7 @@ create_and_show_dialog (FRAME_PTR f, widget_value *first_wv)
1980 Fcons (make_number (dialog_id >> (fact)), 1962 Fcons (make_number (dialog_id >> (fact)),
1981 make_number (dialog_id & ~(-1 << (fact))))); 1963 make_number (dialog_id & ~(-1 << (fact)))));
1982 1964
1983 popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), 1965 popup_get_selection (0, FRAME_X_DISPLAY_INFO (f), dialog_id, 1);
1984 dialog_id, 1);
1985 1966
1986 unbind_to (count, Qnil); 1967 unbind_to (count, Qnil);
1987 } 1968 }
@@ -1994,7 +1975,7 @@ static const char * button_names [] = {
1994 "button6", "button7", "button8", "button9", "button10" }; 1975 "button6", "button7", "button8", "button9", "button10" };
1995 1976
1996static Lisp_Object 1977static Lisp_Object
1997xdialog_show (FRAME_PTR f, 1978xdialog_show (struct frame *f,
1998 bool keymaps, 1979 bool keymaps,
1999 Lisp_Object title, 1980 Lisp_Object title,
2000 Lisp_Object header, 1981 Lisp_Object header,
@@ -2012,8 +1993,7 @@ xdialog_show (FRAME_PTR f,
2012 1993
2013 ptrdiff_t specpdl_count = SPECPDL_INDEX (); 1994 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
2014 1995
2015 if (! FRAME_X_P (f)) 1996 eassert (FRAME_X_P (f));
2016 emacs_abort ();
2017 1997
2018 *error_name = NULL; 1998 *error_name = NULL;
2019 1999
@@ -2225,7 +2205,7 @@ menu_help_callback (char const *help_string, int pane, int item)
2225static void 2205static void
2226pop_down_menu (Lisp_Object arg) 2206pop_down_menu (Lisp_Object arg)
2227{ 2207{
2228 FRAME_PTR f = XSAVE_POINTER (arg, 0); 2208 struct frame *f = XSAVE_POINTER (arg, 0);
2229 XMenu *menu = XSAVE_POINTER (arg, 1); 2209 XMenu *menu = XSAVE_POINTER (arg, 1);
2230 2210
2231 block_input (); 2211 block_input ();
@@ -2253,7 +2233,7 @@ pop_down_menu (Lisp_Object arg)
2253 2233
2254 2234
2255Lisp_Object 2235Lisp_Object
2256xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps, 2236xmenu_show (struct frame *f, int x, int y, bool for_click, bool keymaps,
2257 Lisp_Object title, const char **error_name, Time timestamp) 2237 Lisp_Object title, const char **error_name, Time timestamp)
2258{ 2238{
2259 Window root; 2239 Window root;
@@ -2269,8 +2249,7 @@ xmenu_show (FRAME_PTR f, int x, int y, bool for_click, bool keymaps,
2269 unsigned int dummy_uint; 2249 unsigned int dummy_uint;
2270 ptrdiff_t specpdl_count = SPECPDL_INDEX (); 2250 ptrdiff_t specpdl_count = SPECPDL_INDEX ();
2271 2251
2272 if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f)) 2252 eassert (FRAME_X_P (f) || FRAME_MSDOS_P (f));
2273 emacs_abort ();
2274 2253
2275 *error_name = 0; 2254 *error_name = 0;
2276 if (menu_items_n_panes == 0) 2255 if (menu_items_n_panes == 0)
diff --git a/src/xrdb.c b/src/xrdb.c
index 7c9cd53fa8c..60dcdae080d 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -75,18 +75,9 @@ x_get_customization_string (XrmDatabase db, const char *name,
75 sprintf (full_class, "%s.%s", class, "Customization"); 75 sprintf (full_class, "%s.%s", class, "Customization");
76 76
77 result = x_get_string_resource (db, full_name, full_class); 77 result = x_get_string_resource (db, full_name, full_class);
78 78 return result ? xstrdup (result) : NULL;
79 if (result)
80 {
81 char *copy = xmalloc (strlen (result) + 1);
82 strcpy (copy, result);
83 return copy;
84 }
85 else
86 return 0;
87} 79}
88 80
89
90/* Expand all the Xt-style %-escapes in STRING, whose length is given 81/* Expand all the Xt-style %-escapes in STRING, whose length is given
91 by STRING_LEN. Here are the escapes we're supposed to recognize: 82 by STRING_LEN. Here are the escapes we're supposed to recognize:
92 83
@@ -605,7 +596,7 @@ x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
605 if (x_get_resource (rdb, name, class, x_rm_string, &value)) 596 if (x_get_resource (rdb, name, class, x_rm_string, &value))
606 return (char *) value.addr; 597 return (char *) value.addr;
607 598
608 return (char *) 0; 599 return 0;
609} 600}
610 601
611/* Stand-alone test facilities. */ 602/* Stand-alone test facilities. */
@@ -655,10 +646,7 @@ main (int argc, char **argv)
655 displayname = "localhost:0.0"; 646 displayname = "localhost:0.0";
656 647
657 lp = member ("-xrm", arg_list); 648 lp = member ("-xrm", arg_list);
658 if (! NIL (lp)) 649 resource_string = NIL (lp) ? 0 : car (cdr (lp));
659 resource_string = car (cdr (lp));
660 else
661 resource_string = (char *) 0;
662 650
663 lp = member ("-c", arg_list); 651 lp = member ("-c", arg_list);
664 if (! NIL (lp)) 652 if (! NIL (lp))
diff --git a/src/xselect.c b/src/xselect.c
index 6a80eddc82c..e5f2e214fba 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -654,7 +654,7 @@ x_reply_selection_request (struct input_event *event,
654 if (cs->wait_object) 654 if (cs->wait_object)
655 { 655 {
656 int format_bytes = cs->format / 8; 656 int format_bytes = cs->format / 8;
657 int had_errors = x_had_errors_p (display); 657 bool had_errors_p = x_had_errors_p (display);
658 unblock_input (); 658 unblock_input ();
659 659
660 bytes_remaining = cs->size; 660 bytes_remaining = cs->size;
@@ -662,7 +662,7 @@ x_reply_selection_request (struct input_event *event,
662 662
663 /* Wait for the requestor to ack by deleting the property. 663 /* Wait for the requestor to ack by deleting the property.
664 This can run Lisp code (process handlers) or signal. */ 664 This can run Lisp code (process handlers) or signal. */
665 if (! had_errors) 665 if (! had_errors_p)
666 { 666 {
667 TRACE1 ("Waiting for ACK (deletion of %s)", 667 TRACE1 ("Waiting for ACK (deletion of %s)",
668 XGetAtomName (display, cs->property)); 668 XGetAtomName (display, cs->property));
@@ -694,10 +694,10 @@ x_reply_selection_request (struct input_event *event,
694 cs->data += i * ((cs->format == 32) ? sizeof (long) 694 cs->data += i * ((cs->format == 32) ? sizeof (long)
695 : format_bytes); 695 : format_bytes);
696 XFlush (display); 696 XFlush (display);
697 had_errors = x_had_errors_p (display); 697 had_errors_p = x_had_errors_p (display);
698 unblock_input (); 698 unblock_input ();
699 699
700 if (had_errors) break; 700 if (had_errors_p) break;
701 701
702 /* Wait for the requestor to ack this chunk by deleting 702 /* Wait for the requestor to ack this chunk by deleting
703 the property. This can run Lisp code or signal. */ 703 the property. This can run Lisp code or signal. */
@@ -993,7 +993,7 @@ x_handle_selection_event (struct input_event *event)
993 We do this when about to delete a frame. */ 993 We do this when about to delete a frame. */
994 994
995void 995void
996x_clear_frame_selections (FRAME_PTR f) 996x_clear_frame_selections (struct frame *f)
997{ 997{
998 Lisp_Object frame; 998 Lisp_Object frame;
999 Lisp_Object rest; 999 Lisp_Object rest;
@@ -2377,7 +2377,7 @@ x_property_data_to_lisp (struct frame *f, const unsigned char *data,
2377/* Get the mouse position in frame relative coordinates. */ 2377/* Get the mouse position in frame relative coordinates. */
2378 2378
2379static void 2379static void
2380mouse_position_for_drop (FRAME_PTR f, int *x, int *y) 2380mouse_position_for_drop (struct frame *f, int *x, int *y)
2381{ 2381{
2382 Window root, dummy_window; 2382 Window root, dummy_window;
2383 int dummy; 2383 int dummy;
@@ -2427,17 +2427,17 @@ If the value is 0 or the atom is not known, return the empty string. */)
2427 Lisp_Object ret = Qnil; 2427 Lisp_Object ret = Qnil;
2428 Display *dpy = FRAME_X_DISPLAY (f); 2428 Display *dpy = FRAME_X_DISPLAY (f);
2429 Atom atom; 2429 Atom atom;
2430 int had_errors; 2430 bool had_errors_p;
2431 2431
2432 CONS_TO_INTEGER (value, Atom, atom); 2432 CONS_TO_INTEGER (value, Atom, atom);
2433 2433
2434 block_input (); 2434 block_input ();
2435 x_catch_errors (dpy); 2435 x_catch_errors (dpy);
2436 name = atom ? XGetAtomName (dpy, atom) : empty; 2436 name = atom ? XGetAtomName (dpy, atom) : empty;
2437 had_errors = x_had_errors_p (dpy); 2437 had_errors_p = x_had_errors_p (dpy);
2438 x_uncatch_errors (); 2438 x_uncatch_errors ();
2439 2439
2440 if (!had_errors) 2440 if (!had_errors_p)
2441 ret = build_string (name); 2441 ret = build_string (name);
2442 2442
2443 if (atom && name) XFree (name); 2443 if (atom && name) XFree (name);
@@ -2628,6 +2628,8 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2628 2628
2629 block_input (); 2629 block_input ();
2630 2630
2631 event.xclient.send_event = True;
2632 event.xclient.serial = 0;
2631 event.xclient.message_type = message_type; 2633 event.xclient.message_type = message_type;
2632 event.xclient.display = dpyinfo->display; 2634 event.xclient.display = dpyinfo->display;
2633 2635
@@ -2635,19 +2637,19 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2635 when sending to the root window. */ 2637 when sending to the root window. */
2636 event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest; 2638 event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest;
2637 2639
2638 2640 memset (event.xclient.data.l, 0, sizeof (event.xclient.data.l));
2639 memset (event.xclient.data.b, 0, sizeof (event.xclient.data.b));
2640 x_fill_property_data (dpyinfo->display, values, event.xclient.data.b, 2641 x_fill_property_data (dpyinfo->display, values, event.xclient.data.b,
2641 event.xclient.format); 2642 event.xclient.format);
2642 2643
2643 /* If event mask is 0 the event is sent to the client that created 2644 /* If event mask is 0 the event is sent to the client that created
2644 the destination window. But if we are sending to the root window, 2645 the destination window. But if we are sending to the root window,
2645 there is no such client. Then we set the event mask to 0xffff. The 2646 there is no such client. Then we set the event mask to 0xffffff. The
2646 event then goes to clients selecting for events on the root window. */ 2647 event then goes to clients selecting for events on the root window. */
2647 x_catch_errors (dpyinfo->display); 2648 x_catch_errors (dpyinfo->display);
2648 { 2649 {
2649 int propagate = to_root ? False : True; 2650 int propagate = to_root ? False : True;
2650 unsigned mask = to_root ? 0xffff : 0; 2651 long mask = to_root ? 0xffffff : 0;
2652
2651 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event); 2653 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event);
2652 XFlush (dpyinfo->display); 2654 XFlush (dpyinfo->display);
2653 } 2655 }
diff --git a/src/xsettings.c b/src/xsettings.c
index 45f8435d9f4..b5d5f4db59b 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -756,8 +756,7 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p)
756void 756void
757xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) 757xft_settings_event (struct x_display_info *dpyinfo, XEvent *event)
758{ 758{
759 int check_window_p = 0; 759 bool check_window_p = 0, apply_settings_p = 0;
760 int apply_settings = 0;
761 760
762 switch (event->type) 761 switch (event->type)
763 { 762 {
@@ -777,7 +776,7 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event)
777 if (event->xproperty.window == dpyinfo->xsettings_window 776 if (event->xproperty.window == dpyinfo->xsettings_window
778 && event->xproperty.state == PropertyNewValue 777 && event->xproperty.state == PropertyNewValue
779 && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop) 778 && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop)
780 apply_settings = 1; 779 apply_settings_p = 1;
781 break; 780 break;
782 } 781 }
783 782
@@ -787,10 +786,10 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event)
787 dpyinfo->xsettings_window = None; 786 dpyinfo->xsettings_window = None;
788 get_prop_window (dpyinfo); 787 get_prop_window (dpyinfo);
789 if (dpyinfo->xsettings_window != None) 788 if (dpyinfo->xsettings_window != None)
790 apply_settings = 1; 789 apply_settings_p = 1;
791 } 790 }
792 791
793 if (apply_settings) 792 if (apply_settings_p)
794 read_and_apply_settings (dpyinfo, True); 793 read_and_apply_settings (dpyinfo, True);
795} 794}
796 795
diff --git a/src/xsmfns.c b/src/xsmfns.c
index cb7122202df..526d4c3610b 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -107,8 +107,7 @@ x_session_check_input (int fd, void *data)
107 will be called. */ 107 will be called. */
108 emacs_event.kind = NO_EVENT; 108 emacs_event.kind = NO_EVENT;
109 109
110 ret = IceProcessMessages (SmcGetIceConnection (smc_conn), 110 ret = IceProcessMessages (SmcGetIceConnection (smc_conn), 0, 0);
111 (IceReplyWaitInfo *)0, (Bool *)0);
112 if (ret != IceProcessMessagesSuccess) 111 if (ret != IceProcessMessagesSuccess)
113 { 112 {
114 /* Either IO error or Connection closed. */ 113 /* Either IO error or Connection closed. */
diff --git a/src/xterm.c b/src/xterm.c
index b3534871da9..b5c5a5cb584 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -145,7 +145,7 @@ int use_xim = 0; /* configure --without-xim */
145/* Non-zero means that a HELP_EVENT has been generated since Emacs 145/* Non-zero means that a HELP_EVENT has been generated since Emacs
146 start. */ 146 start. */
147 147
148static int any_help_event_p; 148static bool any_help_event_p;
149 149
150/* Last window where we saw the mouse. Used by mouse-autoselect-window. */ 150/* Last window where we saw the mouse. Used by mouse-autoselect-window. */
151static Lisp_Object last_window; 151static Lisp_Object last_window;
@@ -212,8 +212,7 @@ static unsigned long ignore_next_mouse_click_timeout;
212/* Where the mouse was last time we reported a mouse event. */ 212/* Where the mouse was last time we reported a mouse event. */
213 213
214static XRectangle last_mouse_glyph; 214static XRectangle last_mouse_glyph;
215static FRAME_PTR last_mouse_glyph_frame; 215static struct frame *last_mouse_glyph_frame;
216static Lisp_Object last_mouse_press_frame;
217 216
218/* The scroll bar in which the last X motion event occurred. 217/* The scroll bar in which the last X motion event occurred.
219 218
@@ -288,8 +287,6 @@ enum xembed_message
288 XEMBED_ACTIVATE_ACCELERATOR = 14 287 XEMBED_ACTIVATE_ACCELERATOR = 14
289 }; 288 };
290 289
291/* Used in x_flush. */
292
293static bool x_alloc_nearest_color_1 (Display *, Colormap, XColor *); 290static bool x_alloc_nearest_color_1 (Display *, Colormap, XColor *);
294static void x_set_window_size_1 (struct frame *, int, int, int); 291static void x_set_window_size_1 (struct frame *, int, int, int);
295static void x_raise_frame (struct frame *); 292static void x_raise_frame (struct frame *);
@@ -323,7 +320,6 @@ static void x_clip_to_row (struct window *, struct glyph_row *, int, GC);
323static void x_flush (struct frame *f); 320static void x_flush (struct frame *f);
324static void x_update_begin (struct frame *); 321static void x_update_begin (struct frame *);
325static void x_update_window_begin (struct window *); 322static void x_update_window_begin (struct window *);
326static void x_after_update_window_line (struct glyph_row *);
327static struct scroll_bar *x_window_to_scroll_bar (Display *, Window); 323static struct scroll_bar *x_window_to_scroll_bar (Display *, Window);
328static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *, 324static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
329 enum scroll_bar_part *, 325 enum scroll_bar_part *,
@@ -357,15 +353,18 @@ x_flush (struct frame *f)
357 return; 353 return;
358 354
359 block_input (); 355 block_input ();
360 if (f == NULL) 356 if (f)
357 {
358 eassert (FRAME_X_P (f));
359 XFlush (FRAME_X_DISPLAY (f));
360 }
361 else
361 { 362 {
362 Lisp_Object rest, frame; 363 /* Flush all displays and so all frames on them. */
363 FOR_EACH_FRAME (rest, frame) 364 struct x_display_info *xdi;
364 if (FRAME_X_P (XFRAME (frame))) 365 for (xdi = x_display_list; xdi; xdi = xdi->next)
365 x_flush (XFRAME (frame)); 366 XFlush (xdi->display);
366 } 367 }
367 else if (FRAME_X_P (f))
368 XFlush (FRAME_X_DISPLAY (f));
369 unblock_input (); 368 unblock_input ();
370} 369}
371 370
@@ -554,8 +553,7 @@ x_update_begin (struct frame *f)
554} 553}
555 554
556 555
557/* Start update of window W. Set the global variable updated_window 556/* Start update of window W. Set output_cursor to the cursor
558 to the window being updated and set output_cursor to the cursor
559 position of W. */ 557 position of W. */
560 558
561static void 559static void
@@ -564,7 +562,6 @@ x_update_window_begin (struct window *w)
564 struct frame *f = XFRAME (WINDOW_FRAME (w)); 562 struct frame *f = XFRAME (WINDOW_FRAME (w));
565 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 563 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
566 564
567 updated_window = w;
568 set_output_cursor (&w->cursor); 565 set_output_cursor (&w->cursor);
569 566
570 block_input (); 567 block_input ();
@@ -601,7 +598,7 @@ x_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
601 f->output_data.x->normal_gc, x, y0, x, y1); 598 f->output_data.x->normal_gc, x, y0, x, y1);
602} 599}
603 600
604/* End update of window W (which is equal to updated_window). 601/* End update of window W.
605 602
606 Draw vertical borders between horizontally adjacent windows, and 603 Draw vertical borders between horizontally adjacent windows, and
607 display W's cursor if CURSOR_ON_P is non-zero. 604 display W's cursor if CURSOR_ON_P is non-zero.
@@ -642,8 +639,6 @@ x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritt
642 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1; 639 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
643 hlinfo->mouse_face_window = Qnil; 640 hlinfo->mouse_face_window = Qnil;
644 } 641 }
645
646 updated_window = NULL;
647} 642}
648 643
649 644
@@ -664,9 +659,8 @@ x_update_end (struct frame *f)
664} 659}
665 660
666 661
667/* This function is called from various places in xdisp.c whenever a 662/* This function is called from various places in xdisp.c
668 complete update has been performed. The global variable 663 whenever a complete update has been performed. */
669 updated_window is not available here. */
670 664
671static void 665static void
672XTframe_up_to_date (struct frame *f) 666XTframe_up_to_date (struct frame *f)
@@ -678,15 +672,13 @@ XTframe_up_to_date (struct frame *f)
678 672
679/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay 673/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
680 arrow bitmaps, or clear the fringes if no bitmaps are required 674 arrow bitmaps, or clear the fringes if no bitmaps are required
681 before DESIRED_ROW is made current. The window being updated is 675 before DESIRED_ROW is made current. This function is called from
682 found in updated_window. This function It is called from
683 update_window_line only if it is known that there are differences 676 update_window_line only if it is known that there are differences
684 between bitmaps to be drawn between current row and DESIRED_ROW. */ 677 between bitmaps to be drawn between current row and DESIRED_ROW. */
685 678
686static void 679static void
687x_after_update_window_line (struct glyph_row *desired_row) 680x_after_update_window_line (struct window *w, struct glyph_row *desired_row)
688{ 681{
689 struct window *w = updated_window;
690 struct frame *f; 682 struct frame *f;
691 int width, height; 683 int width, height;
692 684
@@ -697,7 +689,7 @@ x_after_update_window_line (struct glyph_row *desired_row)
697 689
698 /* When a window has disappeared, make sure that no rest of 690 /* When a window has disappeared, make sure that no rest of
699 full-width rows stays visible in the internal border. Could 691 full-width rows stays visible in the internal border. Could
700 check here if updated_window is the leftmost/rightmost window, 692 check here if updated window is the leftmost/rightmost window,
701 but I guess it's not worth doing since vertically split windows 693 but I guess it's not worth doing since vertically split windows
702 are almost never used, internal border is rarely set, and the 694 are almost never used, internal border is rarely set, and the
703 overhead is very small. */ 695 overhead is very small. */
@@ -877,8 +869,6 @@ XTreset_terminal_modes (struct terminal *terminal)
877 869
878static void x_set_glyph_string_clipping (struct glyph_string *); 870static void x_set_glyph_string_clipping (struct glyph_string *);
879static void x_set_glyph_string_gc (struct glyph_string *); 871static void x_set_glyph_string_gc (struct glyph_string *);
880static void x_draw_glyph_string_background (struct glyph_string *,
881 int);
882static void x_draw_glyph_string_foreground (struct glyph_string *); 872static void x_draw_glyph_string_foreground (struct glyph_string *);
883static void x_draw_composite_glyph_string_foreground (struct glyph_string *); 873static void x_draw_composite_glyph_string_foreground (struct glyph_string *);
884static void x_draw_glyph_string_box (struct glyph_string *); 874static void x_draw_glyph_string_box (struct glyph_string *);
@@ -1163,7 +1153,7 @@ x_clear_glyph_string_rect (struct glyph_string *s, int x, int y, int w, int h)
1163 contains the first component of a composition. */ 1153 contains the first component of a composition. */
1164 1154
1165static void 1155static void
1166x_draw_glyph_string_background (struct glyph_string *s, int force_p) 1156x_draw_glyph_string_background (struct glyph_string *s, bool force_p)
1167{ 1157{
1168 /* Nothing to do if background has already been drawn or if it 1158 /* Nothing to do if background has already been drawn or if it
1169 shouldn't be drawn in the first place. */ 1159 shouldn't be drawn in the first place. */
@@ -1376,7 +1366,7 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
1376 } 1366 }
1377 else if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE) 1367 else if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE)
1378 { 1368 {
1379 sprintf ((char *) buf, "%0*X", 1369 sprintf (buf, "%0*X",
1380 glyph->u.glyphless.ch < 0x10000 ? 4 : 6, 1370 glyph->u.glyphless.ch < 0x10000 ? 4 : 6,
1381 glyph->u.glyphless.ch); 1371 glyph->u.glyphless.ch);
1382 str = buf; 1372 str = buf;
@@ -1413,11 +1403,6 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
1413 1403
1414#ifdef USE_X_TOOLKIT 1404#ifdef USE_X_TOOLKIT
1415 1405
1416static Boolean cvt_string_to_pixel (Display *, XrmValue *, Cardinal *,
1417 XrmValue *, XrmValue *, XtPointer *);
1418static void cvt_pixel_dtor (XtAppContext, XrmValue *, XtPointer,
1419 XrmValue *, Cardinal *);
1420
1421#ifdef USE_LUCID 1406#ifdef USE_LUCID
1422 1407
1423/* Return the frame on which widget WIDGET is used.. Abort if frame 1408/* Return the frame on which widget WIDGET is used.. Abort if frame
@@ -2691,7 +2676,7 @@ x_draw_underwave (struct glyph_string *s)
2691static void 2676static void
2692x_draw_glyph_string (struct glyph_string *s) 2677x_draw_glyph_string (struct glyph_string *s)
2693{ 2678{
2694 int relief_drawn_p = 0; 2679 bool relief_drawn_p = 0;
2695 2680
2696 /* If S draws into the background of its successors, draw the 2681 /* If S draws into the background of its successors, draw the
2697 background of the successors first so that S can draw into it. 2682 background of the successors first so that S can draw into it.
@@ -3195,7 +3180,7 @@ XTflash (struct frame *f)
3195 3180
3196 3181
3197static void 3182static void
3198XTtoggle_invisible_pointer (FRAME_PTR f, int invisible) 3183XTtoggle_invisible_pointer (struct frame *f, int invisible)
3199{ 3184{
3200 block_input (); 3185 block_input ();
3201 if (invisible) 3186 if (invisible)
@@ -3330,7 +3315,6 @@ x_scroll_run (struct window *w, struct run *run)
3330 block_input (); 3315 block_input ();
3331 3316
3332 /* Cursor off. Will be switched on again in x_update_window_end. */ 3317 /* Cursor off. Will be switched on again in x_update_window_end. */
3333 updated_window = w;
3334 x_clear_cursor (w); 3318 x_clear_cursor (w);
3335 3319
3336 XCopyArea (FRAME_X_DISPLAY (f), 3320 XCopyArea (FRAME_X_DISPLAY (f),
@@ -3804,7 +3788,7 @@ static XMotionEvent last_mouse_motion_event;
3804static Lisp_Object last_mouse_motion_frame; 3788static Lisp_Object last_mouse_motion_frame;
3805 3789
3806static int 3790static int
3807note_mouse_movement (FRAME_PTR frame, XMotionEvent *event) 3791note_mouse_movement (struct frame *frame, XMotionEvent *event)
3808{ 3792{
3809 last_mouse_movement_time = event->time; 3793 last_mouse_movement_time = event->time;
3810 last_mouse_motion_event = *event; 3794 last_mouse_motion_event = *event;
@@ -3880,11 +3864,11 @@ redo_mouse_highlight (void)
3880 movement. */ 3864 movement. */
3881 3865
3882static void 3866static void
3883XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 3867XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
3884 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, 3868 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
3885 Time *timestamp) 3869 Time *timestamp)
3886{ 3870{
3887 FRAME_PTR f1; 3871 struct frame *f1;
3888 3872
3889 block_input (); 3873 block_input ();
3890 3874
@@ -4344,8 +4328,8 @@ x_scroll_bar_to_input_event (XEvent *event, struct input_event *ievent)
4344static void 4328static void
4345xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4329xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4346{ 4330{
4347 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4331 struct scroll_bar *bar = client_data;
4348 XmScrollBarCallbackStruct *cs = (XmScrollBarCallbackStruct *) call_data; 4332 XmScrollBarCallbackStruct *cs = call_data;
4349 int part = -1, whole = 0, portion = 0; 4333 int part = -1, whole = 0, portion = 0;
4350 4334
4351 switch (cs->reason) 4335 switch (cs->reason)
@@ -4419,11 +4403,11 @@ xg_scroll_callback (GtkRange *range,
4419 gdouble value, 4403 gdouble value,
4420 gpointer user_data) 4404 gpointer user_data)
4421{ 4405{
4422 struct scroll_bar *bar = (struct scroll_bar *) user_data; 4406 struct scroll_bar *bar = user_data;
4423 gdouble position; 4407 gdouble position;
4424 int part = -1, whole = 0, portion = 0; 4408 int part = -1, whole = 0, portion = 0;
4425 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); 4409 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range));
4426 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (range), XG_FRAME_DATA); 4410 struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA);
4427 4411
4428 if (xg_ignore_gtk_scrollbar) return FALSE; 4412 if (xg_ignore_gtk_scrollbar) return FALSE;
4429 position = gtk_adjustment_get_value (adj); 4413 position = gtk_adjustment_get_value (adj);
@@ -4478,7 +4462,7 @@ xg_end_scroll_callback (GtkWidget *widget,
4478 GdkEventButton *event, 4462 GdkEventButton *event,
4479 gpointer user_data) 4463 gpointer user_data)
4480{ 4464{
4481 struct scroll_bar *bar = (struct scroll_bar *) user_data; 4465 struct scroll_bar *bar = user_data;
4482 bar->dragging = Qnil; 4466 bar->dragging = Qnil;
4483 if (WINDOWP (window_being_scrolled)) 4467 if (WINDOWP (window_being_scrolled))
4484 { 4468 {
@@ -4501,8 +4485,9 @@ xg_end_scroll_callback (GtkWidget *widget,
4501static void 4485static void
4502xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4486xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4503{ 4487{
4504 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4488 struct scroll_bar *bar = client_data;
4505 float top = *(float *) call_data; 4489 float *top_addr = call_data;
4490 float top = *top_addr;
4506 float shown; 4491 float shown;
4507 int whole, portion, height; 4492 int whole, portion, height;
4508 int part; 4493 int part;
@@ -4543,9 +4528,9 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4543static void 4528static void
4544xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4529xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4545{ 4530{
4546 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4531 struct scroll_bar *bar = client_data;
4547 /* The position really is stored cast to a pointer. */ 4532 /* The position really is stored cast to a pointer. */
4548 int position = (long) call_data; 4533 int position = (intptr_t) call_data;
4549 Dimension height; 4534 Dimension height;
4550 int part; 4535 int part;
4551 4536
@@ -5040,7 +5025,7 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5040{ 5025{
5041 int dragging = ! NILP (bar->dragging); 5026 int dragging = ! NILP (bar->dragging);
5042 Window w = bar->x_window; 5027 Window w = bar->x_window;
5043 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5028 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5044 GC gc = f->output_data.x->normal_gc; 5029 GC gc = f->output_data.x->normal_gc;
5045 5030
5046 /* If the display is already accurate, do nothing. */ 5031 /* If the display is already accurate, do nothing. */
@@ -5170,7 +5155,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5170 int top, height, left, sb_left, width, sb_width; 5155 int top, height, left, sb_left, width, sb_width;
5171 int window_y, window_height; 5156 int window_y, window_height;
5172#ifdef USE_TOOLKIT_SCROLL_BARS 5157#ifdef USE_TOOLKIT_SCROLL_BARS
5173 int fringe_extended_p; 5158 bool fringe_extended_p;
5174#endif 5159#endif
5175 5160
5176 /* Get window dimensions. */ 5161 /* Get window dimensions. */
@@ -5203,16 +5188,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5203#endif 5188#endif
5204 5189
5205#ifdef USE_TOOLKIT_SCROLL_BARS 5190#ifdef USE_TOOLKIT_SCROLL_BARS
5206 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 5191 fringe_extended_p = WINDOW_FRINGE_EXTENDED_P (w);
5207 fringe_extended_p = (WINDOW_LEFTMOST_P (w)
5208 && WINDOW_LEFT_FRINGE_WIDTH (w)
5209 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5210 || WINDOW_LEFT_MARGIN_COLS (w) == 0));
5211 else
5212 fringe_extended_p = (WINDOW_RIGHTMOST_P (w)
5213 && WINDOW_RIGHT_FRINGE_WIDTH (w)
5214 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5215 || WINDOW_RIGHT_MARGIN_COLS (w) == 0));
5216#endif 5192#endif
5217 5193
5218 /* Does the scroll bar exist yet? */ 5194 /* Does the scroll bar exist yet? */
@@ -5381,7 +5357,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5381 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */ 5357 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5382 5358
5383static void 5359static void
5384XTcondemn_scroll_bars (FRAME_PTR frame) 5360XTcondemn_scroll_bars (struct frame *frame)
5385{ 5361{
5386 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */ 5362 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5387 while (! NILP (FRAME_SCROLL_BARS (frame))) 5363 while (! NILP (FRAME_SCROLL_BARS (frame)))
@@ -5449,7 +5425,7 @@ XTredeem_scroll_bar (struct window *window)
5449 last call to `*condemn_scroll_bars_hook'. */ 5425 last call to `*condemn_scroll_bars_hook'. */
5450 5426
5451static void 5427static void
5452XTjudge_scroll_bars (FRAME_PTR f) 5428XTjudge_scroll_bars (struct frame *f)
5453{ 5429{
5454 Lisp_Object bar, next; 5430 Lisp_Object bar, next;
5455 5431
@@ -5485,7 +5461,7 @@ static void
5485x_scroll_bar_expose (struct scroll_bar *bar, XEvent *event) 5461x_scroll_bar_expose (struct scroll_bar *bar, XEvent *event)
5486{ 5462{
5487 Window w = bar->x_window; 5463 Window w = bar->x_window;
5488 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5464 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5489 GC gc = f->output_data.x->normal_gc; 5465 GC gc = f->output_data.x->normal_gc;
5490 int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM; 5466 int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM;
5491 5467
@@ -5584,7 +5560,7 @@ x_scroll_bar_handle_click (struct scroll_bar *bar, XEvent *event, struct input_e
5584static void 5560static void
5585x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event) 5561x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
5586{ 5562{
5587 FRAME_PTR f = XFRAME (XWINDOW (bar->window)->frame); 5563 struct frame *f = XFRAME (XWINDOW (bar->window)->frame);
5588 5564
5589 last_mouse_movement_time = event->xmotion.time; 5565 last_mouse_movement_time = event->xmotion.time;
5590 5566
@@ -5612,13 +5588,13 @@ x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
5612 on the scroll bar. */ 5588 on the scroll bar. */
5613 5589
5614static void 5590static void
5615x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window, 5591x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
5616 enum scroll_bar_part *part, Lisp_Object *x, 5592 enum scroll_bar_part *part, Lisp_Object *x,
5617 Lisp_Object *y, Time *timestamp) 5593 Lisp_Object *y, Time *timestamp)
5618{ 5594{
5619 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 5595 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
5620 Window w = bar->x_window; 5596 Window w = bar->x_window;
5621 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 5597 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5622 int win_x, win_y; 5598 int win_x, win_y;
5623 Window dummy_window; 5599 Window dummy_window;
5624 int dummy_coord; 5600 int dummy_coord;
@@ -5686,7 +5662,7 @@ x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
5686 redraw them. */ 5662 redraw them. */
5687 5663
5688static void 5664static void
5689x_scroll_bar_clear (FRAME_PTR f) 5665x_scroll_bar_clear (struct frame *f)
5690{ 5666{
5691#ifndef USE_TOOLKIT_SCROLL_BARS 5667#ifndef USE_TOOLKIT_SCROLL_BARS
5692 Lisp_Object bar; 5668 Lisp_Object bar;
@@ -6854,7 +6830,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6854 { 6830 {
6855 /* If we decide we want to generate an event to be seen 6831 /* If we decide we want to generate an event to be seen
6856 by the rest of Emacs, we put it here. */ 6832 by the rest of Emacs, we put it here. */
6857 int tool_bar_p = 0; 6833 bool tool_bar_p = 0;
6858 6834
6859 memset (&compose_status, 0, sizeof (compose_status)); 6835 memset (&compose_status, 0, sizeof (compose_status));
6860 last_mouse_glyph_frame = 0; 6836 last_mouse_glyph_frame = 0;
@@ -6975,14 +6951,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6975 && event.xbutton.same_screen) 6951 && event.xbutton.same_screen)
6976 { 6952 {
6977 SET_SAVED_BUTTON_EVENT; 6953 SET_SAVED_BUTTON_EVENT;
6978 XSETFRAME (last_mouse_press_frame, f);
6979 *finish = X_EVENT_DROP; 6954 *finish = X_EVENT_DROP;
6980 } 6955 }
6981 else if (event.type == ButtonPress)
6982 {
6983 last_mouse_press_frame = Qnil;
6984 goto OTHER;
6985 }
6986 else 6956 else
6987 goto OTHER; 6957 goto OTHER;
6988#endif /* USE_X_TOOLKIT || USE_GTK */ 6958#endif /* USE_X_TOOLKIT || USE_GTK */
@@ -7663,7 +7633,7 @@ x_check_errors (Display *dpy, const char *format)
7663/* Nonzero if we had any X protocol errors 7633/* Nonzero if we had any X protocol errors
7664 since we did x_catch_errors on DPY. */ 7634 since we did x_catch_errors on DPY. */
7665 7635
7666int 7636bool
7667x_had_errors_p (Display *dpy) 7637x_had_errors_p (Display *dpy)
7668{ 7638{
7669 /* Make sure to catch any errors incurred so far. */ 7639 /* Make sure to catch any errors incurred so far. */
@@ -7829,9 +7799,8 @@ static int
7829x_error_handler (Display *display, XErrorEvent *event) 7799x_error_handler (Display *display, XErrorEvent *event)
7830{ 7800{
7831#if defined USE_GTK && defined HAVE_GTK3 7801#if defined USE_GTK && defined HAVE_GTK3
7832 if (event->error_code == BadMatch 7802 if ((event->error_code == BadMatch || event->error_code == BadWindow)
7833 && event->request_code == X_SetInputFocus 7803 && event->request_code == X_SetInputFocus)
7834 && event->minor_code == 0)
7835 { 7804 {
7836 return 0; 7805 return 0;
7837 } 7806 }
@@ -8102,13 +8071,10 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
8102 { 8071 {
8103#ifdef HAVE_X11R6_XIM 8072#ifdef HAVE_X11R6_XIM
8104 struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst); 8073 struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst);
8105 ptrdiff_t len;
8106 8074
8107 dpyinfo->xim_callback_data = xim_inst; 8075 dpyinfo->xim_callback_data = xim_inst;
8108 xim_inst->dpyinfo = dpyinfo; 8076 xim_inst->dpyinfo = dpyinfo;
8109 len = strlen (resource_name); 8077 xim_inst->resource_name = xstrdup (resource_name);
8110 xim_inst->resource_name = xmalloc (len + 1);
8111 memcpy (xim_inst->resource_name, resource_name, len + 1);
8112 XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, 8078 XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
8113 resource_name, emacs_class, 8079 resource_name, emacs_class,
8114 xim_instantiate_callback, 8080 xim_instantiate_callback,
@@ -8537,7 +8503,7 @@ do_ewmh_fullscreen (struct frame *f)
8537} 8503}
8538 8504
8539static void 8505static void
8540XTfullscreen_hook (FRAME_PTR f) 8506XTfullscreen_hook (struct frame *f)
8541{ 8507{
8542 if (FRAME_VISIBLE_P (f)) 8508 if (FRAME_VISIBLE_P (f))
8543 { 8509 {
@@ -8938,7 +8904,7 @@ x_lower_frame (struct frame *f)
8938/* Request focus with XEmbed */ 8904/* Request focus with XEmbed */
8939 8905
8940void 8906void
8941xembed_request_focus (FRAME_PTR f) 8907xembed_request_focus (struct frame *f)
8942{ 8908{
8943 /* See XEmbed Protocol Specification at 8909 /* See XEmbed Protocol Specification at
8944 http://freedesktop.org/wiki/Specifications/xembed-spec */ 8910 http://freedesktop.org/wiki/Specifications/xembed-spec */
@@ -8950,7 +8916,7 @@ xembed_request_focus (FRAME_PTR f)
8950/* Activate frame with Extended Window Manager Hints */ 8916/* Activate frame with Extended Window Manager Hints */
8951 8917
8952void 8918void
8953x_ewmh_activate_frame (FRAME_PTR f) 8919x_ewmh_activate_frame (struct frame *f)
8954{ 8920{
8955 /* See Window Manager Specification/Extended Window Manager Hints at 8921 /* See Window Manager Specification/Extended Window Manager Hints at
8956 http://freedesktop.org/wiki/Specifications/wm-spec */ 8922 http://freedesktop.org/wiki/Specifications/wm-spec */
@@ -8968,7 +8934,7 @@ x_ewmh_activate_frame (FRAME_PTR f)
8968} 8934}
8969 8935
8970static void 8936static void
8971XTframe_raise_lower (FRAME_PTR f, int raise_flag) 8937XTframe_raise_lower (struct frame *f, int raise_flag)
8972{ 8938{
8973 if (raise_flag) 8939 if (raise_flag)
8974 x_raise_frame (f); 8940 x_raise_frame (f);
@@ -9452,6 +9418,19 @@ x_free_frame_resources (struct frame *f)
9452 unload_color (f, f->output_data.x->black_relief.pixel); 9418 unload_color (f, f->output_data.x->black_relief.pixel);
9453 9419
9454 x_free_gcs (f); 9420 x_free_gcs (f);
9421
9422 /* Free extra GCs allocated by x_setup_relief_colors. */
9423 if (f->output_data.x->white_relief.gc)
9424 {
9425 XFreeGC (dpyinfo->display, f->output_data.x->white_relief.gc);
9426 f->output_data.x->white_relief.gc = 0;
9427 }
9428 if (f->output_data.x->black_relief.gc)
9429 {
9430 XFreeGC (dpyinfo->display, f->output_data.x->black_relief.gc);
9431 f->output_data.x->black_relief.gc = 0;
9432 }
9433
9455 XFlush (FRAME_X_DISPLAY (f)); 9434 XFlush (FRAME_X_DISPLAY (f));
9456 } 9435 }
9457 9436
@@ -9817,18 +9796,11 @@ get_bits_and_offset (long unsigned int mask, int *bits, int *offset)
9817/* Return 1 if display DISPLAY is available for use, 0 otherwise. 9796/* Return 1 if display DISPLAY is available for use, 0 otherwise.
9818 But don't permanently open it, just test its availability. */ 9797 But don't permanently open it, just test its availability. */
9819 9798
9820int 9799bool
9821x_display_ok (const char *display) 9800x_display_ok (const char *display)
9822{ 9801{
9823 int dpy_ok = 1; 9802 Display *dpy = XOpenDisplay (display);
9824 Display *dpy; 9803 return dpy ? (XCloseDisplay (dpy), 1) : 0;
9825
9826 dpy = XOpenDisplay (display);
9827 if (dpy)
9828 XCloseDisplay (dpy);
9829 else
9830 dpy_ok = 0;
9831 return dpy_ok;
9832} 9804}
9833 9805
9834#ifdef USE_GTK 9806#ifdef USE_GTK
@@ -10066,9 +10038,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10066 dpyinfo->display = dpy; 10038 dpyinfo->display = dpy;
10067 10039
10068 /* Set the name of the terminal. */ 10040 /* Set the name of the terminal. */
10069 terminal->name = xmalloc (SBYTES (display_name) + 1); 10041 terminal->name = xlispstrdup (display_name);
10070 memcpy (terminal->name, SSDATA (display_name), SBYTES (display_name));
10071 terminal->name[SBYTES (display_name)] = 0;
10072 10042
10073#if 0 10043#if 0
10074 XSetAfterFunction (x_current_display, x_trace_wire); 10044 XSetAfterFunction (x_current_display, x_trace_wire);
@@ -10110,33 +10080,15 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10110 select_visual (dpyinfo); 10080 select_visual (dpyinfo);
10111 dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen); 10081 dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen);
10112 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen); 10082 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen);
10113 dpyinfo->client_leader_window = 0;
10114 dpyinfo->grabbed = 0;
10115 dpyinfo->reference_count = 0;
10116 dpyinfo->icon_bitmap_id = -1; 10083 dpyinfo->icon_bitmap_id = -1;
10117 dpyinfo->n_fonts = 0;
10118 dpyinfo->bitmaps = 0;
10119 dpyinfo->bitmaps_size = 0;
10120 dpyinfo->bitmaps_last = 0;
10121 dpyinfo->scratch_cursor_gc = 0;
10122 hlinfo->mouse_face_mouse_frame = 0;
10123 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1; 10084 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
10124 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1; 10085 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
10125 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID; 10086 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
10126 hlinfo->mouse_face_window = Qnil; 10087 hlinfo->mouse_face_window = Qnil;
10127 hlinfo->mouse_face_overlay = Qnil; 10088 hlinfo->mouse_face_overlay = Qnil;
10128 hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0;
10129 hlinfo->mouse_face_defer = 0;
10130 hlinfo->mouse_face_hidden = 0;
10131 dpyinfo->x_focus_frame = 0;
10132 dpyinfo->x_focus_event_frame = 0;
10133 dpyinfo->x_highlight_frame = 0;
10134 dpyinfo->wm_type = X_WMTYPE_UNKNOWN; 10089 dpyinfo->wm_type = X_WMTYPE_UNKNOWN;
10135 10090
10136 /* See if we can construct pixel values from RGB values. */ 10091 /* See if we can construct pixel values from RGB values. */
10137 dpyinfo->red_bits = dpyinfo->blue_bits = dpyinfo->green_bits = 0;
10138 dpyinfo->red_offset = dpyinfo->blue_offset = dpyinfo->green_offset = 0;
10139
10140 if (dpyinfo->visual->class == TrueColor) 10092 if (dpyinfo->visual->class == TrueColor)
10141 { 10093 {
10142 get_bits_and_offset (dpyinfo->visual->red_mask, 10094 get_bits_and_offset (dpyinfo->visual->red_mask,
@@ -10297,14 +10249,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10297 } 10249 }
10298 10250
10299 dpyinfo->x_dnd_atoms_size = 8; 10251 dpyinfo->x_dnd_atoms_size = 8;
10300 dpyinfo->x_dnd_atoms_length = 0;
10301 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms 10252 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms
10302 * dpyinfo->x_dnd_atoms_size); 10253 * dpyinfo->x_dnd_atoms_size);
10303 10254
10304 dpyinfo->net_supported_atoms = NULL;
10305 dpyinfo->nr_net_supported_atoms = 0;
10306 dpyinfo->net_supported_window = 0;
10307
10308 connection = ConnectionNumber (dpyinfo->display); 10255 connection = ConnectionNumber (dpyinfo->display);
10309 dpyinfo->connection = connection; 10256 dpyinfo->connection = connection;
10310 dpyinfo->gray 10257 dpyinfo->gray
@@ -10728,9 +10675,6 @@ syms_of_xterm (void)
10728 DEFSYM (Qvendor_specific_keysyms, "vendor-specific-keysyms"); 10675 DEFSYM (Qvendor_specific_keysyms, "vendor-specific-keysyms");
10729 DEFSYM (Qlatin_1, "latin-1"); 10676 DEFSYM (Qlatin_1, "latin-1");
10730 10677
10731 staticpro (&last_mouse_press_frame);
10732 last_mouse_press_frame = Qnil;
10733
10734#ifdef USE_GTK 10678#ifdef USE_GTK
10735 xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg"); 10679 xg_default_icon_file = build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10736 staticpro (&xg_default_icon_file); 10680 staticpro (&xg_default_icon_file);
diff --git a/src/xterm.h b/src/xterm.h
index 5415a77cf58..fbc2f05a375 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -403,7 +403,7 @@ extern Lisp_Object x_display_name_list;
403extern struct x_display_info *x_display_info_for_display (Display *); 403extern struct x_display_info *x_display_info_for_display (Display *);
404 404
405extern struct x_display_info *x_term_init (Lisp_Object, char *, char *); 405extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
406extern int x_display_ok (const char *); 406extern bool x_display_ok (const char *);
407 407
408extern void select_visual (struct x_display_info *); 408extern void select_visual (struct x_display_info *);
409 409
@@ -590,7 +590,6 @@ struct x_output
590 XIC xic; 590 XIC xic;
591 XIMStyle xic_style; 591 XIMStyle xic_style;
592 XFontSet xic_xfs; 592 XFontSet xic_xfs;
593 char *xic_base_fontname;
594#endif 593#endif
595 594
596 /* Relief GCs, colors etc. */ 595 /* Relief GCs, colors etc. */
@@ -754,7 +753,6 @@ enum
754#define FRAME_X_XIM_STYLES(f) (FRAME_X_DISPLAY_INFO (f)->xim_styles) 753#define FRAME_X_XIM_STYLES(f) (FRAME_X_DISPLAY_INFO (f)->xim_styles)
755#define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style) 754#define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
756#define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs) 755#define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
757#define FRAME_XIC_BASE_FONTNAME(f) ((f)->output_data.x->xic_base_fontname)
758 756
759/* Value is the smallest width of any character in any font on frame F. */ 757/* Value is the smallest width of any character in any font on frame F. */
760 758
@@ -817,7 +815,7 @@ struct scroll_bar
817 815
818 /* 1 if the background of the fringe that is adjacent to a scroll 816 /* 1 if the background of the fringe that is adjacent to a scroll
819 bar is extended to the gap between the fringe and the bar. */ 817 bar is extended to the gap between the fringe and the bar. */
820 unsigned int fringe_extended_p : 1; 818 unsigned fringe_extended_p : 1;
821}; 819};
822 820
823/* Turning a lisp vector value into a pointer to a struct scroll_bar. */ 821/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
@@ -947,7 +945,7 @@ extern int x_text_icon (struct frame *, const char *);
947extern void x_catch_errors (Display *); 945extern void x_catch_errors (Display *);
948extern void x_check_errors (Display *, const char *) 946extern void x_check_errors (Display *, const char *)
949 ATTRIBUTE_FORMAT_PRINTF (2, 0); 947 ATTRIBUTE_FORMAT_PRINTF (2, 0);
950extern int x_had_errors_p (Display *); 948extern bool x_had_errors_p (Display *);
951extern void x_uncatch_errors (void); 949extern void x_uncatch_errors (void);
952extern void x_clear_errors (Display *); 950extern void x_clear_errors (Display *);
953extern void x_set_window_size (struct frame *, int, int, int); 951extern void x_set_window_size (struct frame *, int, int, int);
@@ -1031,8 +1029,6 @@ extern void destroy_frame_xic (struct frame *);
1031extern void xic_set_preeditarea (struct window *, int, int); 1029extern void xic_set_preeditarea (struct window *, int, int);
1032extern void xic_set_statusarea (struct frame *); 1030extern void xic_set_statusarea (struct frame *);
1033extern void xic_set_xfontset (struct frame *, const char *); 1031extern void xic_set_xfontset (struct frame *, const char *);
1034extern int x_pixel_width (struct frame *);
1035extern int x_pixel_height (struct frame *);
1036extern bool x_defined_color (struct frame *, const char *, XColor *, bool); 1032extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1037#ifdef HAVE_X_I18N 1033#ifdef HAVE_X_I18N
1038extern void free_frame_xic (struct frame *); 1034extern void free_frame_xic (struct frame *);