aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorBill Wohler2012-11-24 19:43:02 -0800
committerBill Wohler2012-11-24 19:43:02 -0800
commit5244bc019bf7376caff3bb198ff674e0ad9fb0e6 (patch)
tree02ee1615e904771f692ec2957c79a08ae029a13d /src/window.c
parent9f7e719509474e92f85955e22e57ffeebd4e96f3 (diff)
parentc07a6ded1df2f4156badc9add2953579622c3722 (diff)
downloademacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.tar.gz
emacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.zip
Merge from trunk.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c1993
1 files changed, 1130 insertions, 863 deletions
diff --git a/src/window.c b/src/window.c
index ef61d668499..9f3474fcd53 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,6 +1,6 @@
1/* Window creation, deletion and examination for GNU Emacs. 1/* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay. 2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2011 3 Copyright (C) 1985-1987, 1993-1998, 2000-2012
4 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -19,10 +19,13 @@ You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#include <config.h> 21#include <config.h>
22
23#define WINDOW_INLINE EXTERN_INLINE
24
22#include <stdio.h> 25#include <stdio.h>
23#include <setjmp.h>
24 26
25#include "lisp.h" 27#include "lisp.h"
28#include "character.h"
26#include "buffer.h" 29#include "buffer.h"
27#include "keyboard.h" 30#include "keyboard.h"
28#include "keymap.h" 31#include "keymap.h"
@@ -40,7 +43,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
40#ifdef HAVE_X_WINDOWS 43#ifdef HAVE_X_WINDOWS
41#include "xterm.h" 44#include "xterm.h"
42#endif /* HAVE_X_WINDOWS */ 45#endif /* HAVE_X_WINDOWS */
43#ifdef WINDOWSNT 46#ifdef HAVE_NTGUI
44#include "w32term.h" 47#include "w32term.h"
45#endif 48#endif
46#ifdef MSDOS 49#ifdef MSDOS
@@ -51,19 +54,18 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#endif 54#endif
52 55
53Lisp_Object Qwindowp, Qwindow_live_p; 56Lisp_Object Qwindowp, Qwindow_live_p;
57static Lisp_Object Qwindow_valid_p;
54static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer; 58static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer;
55static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer; 59static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
56static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window; 60static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
57static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically; 61static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
58static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command; 62static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
59static Lisp_Object Qsafe, Qabove, Qbelow; 63static Lisp_Object Qsafe, Qabove, Qbelow, Qwindow_size, Qclone_of;
60static Lisp_Object Qauto_buffer_name;
61 64
62static int displayed_window_lines (struct window *); 65static int displayed_window_lines (struct window *);
63static struct window *decode_window (Lisp_Object);
64static int count_windows (struct window *); 66static int count_windows (struct window *);
65static int get_leaf_windows (struct window *, struct window **, int); 67static int get_leaf_windows (struct window *, struct window **, int);
66static void window_scroll (Lisp_Object, int, int, int); 68static void window_scroll (Lisp_Object, EMACS_INT, int, int);
67static void window_scroll_pixel_based (Lisp_Object, int, int, int); 69static void window_scroll_pixel_based (Lisp_Object, int, int, int);
68static void window_scroll_line_based (Lisp_Object, int, int, int); 70static void window_scroll_line_based (Lisp_Object, int, int, int);
69static int freeze_window_start (struct window *, void *); 71static int freeze_window_start (struct window *, void *);
@@ -127,11 +129,113 @@ static int window_scroll_pixel_based_preserve_x;
127static int window_scroll_pixel_based_preserve_y; 129static int window_scroll_pixel_based_preserve_y;
128 130
129/* Same for window_scroll_line_based. */ 131/* Same for window_scroll_line_based. */
130static int window_scroll_preserve_hpos; 132static EMACS_INT window_scroll_preserve_hpos;
131static int window_scroll_preserve_vpos; 133static EMACS_INT window_scroll_preserve_vpos;
132 134
133static struct window * 135/* These setters are used only in this file, so they can be private. */
134decode_window (register Lisp_Object window) 136static void
137wset_combination_limit (struct window *w, Lisp_Object val)
138{
139 w->combination_limit = val;
140}
141static void
142wset_dedicated (struct window *w, Lisp_Object val)
143{
144 w->dedicated = val;
145}
146static void
147wset_display_table (struct window *w, Lisp_Object val)
148{
149 w->display_table = val;
150}
151static void
152wset_hchild (struct window *w, Lisp_Object val)
153{
154 w->hchild = val;
155}
156static 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)
168{
169 w->new_normal = val;
170}
171static void
172wset_new_total (struct window *w, Lisp_Object val)
173{
174 w->new_total = val;
175}
176static void
177wset_normal_cols (struct window *w, Lisp_Object val)
178{
179 w->normal_cols = val;
180}
181static void
182wset_normal_lines (struct window *w, Lisp_Object val)
183{
184 w->normal_lines = val;
185}
186static void
187wset_parent (struct window *w, Lisp_Object val)
188{
189 w->parent = val;
190}
191static void
192wset_pointm (struct window *w, Lisp_Object val)
193{
194 w->pointm = val;
195}
196static 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)
213{
214 w->start = val;
215}
216static void
217wset_temslot (struct window *w, Lisp_Object val)
218{
219 w->temslot = val;
220}
221static void
222wset_vchild (struct window *w, Lisp_Object val)
223{
224 w->vchild = val;
225}
226static void
227wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val)
228{
229 w->vertical_scroll_bar_type = val;
230}
231static void
232wset_window_parameters (struct window *w, Lisp_Object val)
233{
234 w->window_parameters = val;
235}
236
237struct window *
238decode_live_window (register Lisp_Object window)
135{ 239{
136 if (NILP (window)) 240 if (NILP (window))
137 return XWINDOW (selected_window); 241 return XWINDOW (selected_window);
@@ -140,14 +244,39 @@ decode_window (register Lisp_Object window)
140 return XWINDOW (window); 244 return XWINDOW (window);
141} 245}
142 246
143static struct window * 247struct window *
144decode_any_window (register Lisp_Object window) 248decode_any_window (register Lisp_Object window)
145{ 249{
250 struct window *w;
251
146 if (NILP (window)) 252 if (NILP (window))
147 return XWINDOW (selected_window); 253 return XWINDOW (selected_window);
148 254
149 CHECK_WINDOW (window); 255 CHECK_WINDOW (window);
150 return XWINDOW (window); 256 w = XWINDOW (window);
257 return w;
258}
259
260static struct window *
261decode_valid_window (register Lisp_Object window)
262{
263 struct window *w;
264
265 if (NILP (window))
266 return XWINDOW (selected_window);
267
268 CHECK_VALID_WINDOW (window);
269 w = XWINDOW (window);
270 return w;
271}
272
273/* Build a frequently used 4-integer (X Y W H) list. */
274
275static Lisp_Object
276list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h)
277{
278 return list4 (make_number (x), make_number (y),
279 make_number (w), make_number (h));
151} 280}
152 281
153DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0, 282DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
@@ -157,6 +286,15 @@ DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
157 return WINDOWP (object) ? Qt : Qnil; 286 return WINDOWP (object) ? Qt : Qnil;
158} 287}
159 288
289DEFUN ("window-valid-p", Fwindow_valid_p, Swindow_valid_p, 1, 1, 0,
290 doc: /* Return t if OBJECT is a valid window and nil otherwise.
291A valid window is either a window that displays a buffer or an internal
292window. Deleted windows are not live. */)
293 (Lisp_Object object)
294{
295 return WINDOW_VALID_P (object) ? Qt : Qnil;
296}
297
160DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0, 298DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
161 doc: /* Return t if OBJECT is a live window and nil otherwise. 299 doc: /* Return t if OBJECT is a live window and nil otherwise.
162A live window is a window that displays a buffer. 300A live window is a window that displays a buffer.
@@ -167,12 +305,12 @@ Internal windows and deleted windows are not live. */)
167} 305}
168 306
169/* Frames and windows. */ 307/* Frames and windows. */
170DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0, 308DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 0, 1, 0,
171 doc: /* Return the frame that window WINDOW is on. 309 doc: /* Return the frame that window WINDOW is on.
172If WINDOW is omitted or nil, it defaults to the selected window. */) 310WINDOW must be a valid window and defaults to the selected one. */)
173 (Lisp_Object window) 311 (Lisp_Object window)
174{ 312{
175 return decode_any_window (window)->frame; 313 return decode_valid_window (window)->frame;
176} 314}
177 315
178DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0, 316DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
@@ -186,8 +324,8 @@ With a window argument, return the root window of that window's frame. */)
186 324
187 if (NILP (frame_or_window)) 325 if (NILP (frame_or_window))
188 window = SELECTED_FRAME ()->root_window; 326 window = SELECTED_FRAME ()->root_window;
189 else if (WINDOWP (frame_or_window)) 327 else if (WINDOW_VALID_P (frame_or_window))
190 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window; 328 window = XFRAME (XWINDOW (frame_or_window)->frame)->root_window;
191 else 329 else
192 { 330 {
193 CHECK_LIVE_FRAME (frame_or_window); 331 CHECK_LIVE_FRAME (frame_or_window);
@@ -202,27 +340,24 @@ DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
202If FRAME is omitted or nil, it defaults to the selected frame. */) 340If FRAME is omitted or nil, it defaults to the selected frame. */)
203 (Lisp_Object frame) 341 (Lisp_Object frame)
204{ 342{
205 if (NILP (frame)) 343 return FRAME_MINIBUF_WINDOW (decode_live_frame (frame));
206 frame = selected_frame;
207 CHECK_LIVE_FRAME (frame);
208 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
209} 344}
210 345
211DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 346DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p,
212 Swindow_minibuffer_p, 0, 1, 0, 347 Swindow_minibuffer_p, 0, 1, 0,
213 doc: /* Return non-nil if WINDOW is a minibuffer window. 348 doc: /* Return non-nil if WINDOW is a minibuffer window.
214If WINDOW is omitted or nil, it defaults to the selected window. */) 349WINDOW must be a valid window and defaults to the selected one. */)
215 (Lisp_Object window) 350 (Lisp_Object window)
216{ 351{
217 return MINI_WINDOW_P (decode_any_window (window)) ? Qt : Qnil; 352 return MINI_WINDOW_P (decode_valid_window (window)) ? Qt : Qnil;
218} 353}
219 354
220/* Don't move this to window.el - this must be a safe routine. */ 355/* Don't move this to window.el - this must be a safe routine. */
221DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0, 356DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
222 doc: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW. 357 doc: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
223If omitted, FRAME-OR-WINDOW defaults to the currently selected frame. 358If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
224Else if FRAME-OR-WINDOW denotes any window, return the first window of 359Else if FRAME-OR-WINDOW denotes a valid window, return the first window
225that window's frame. If FRAME-OR-WINDOW denotes a live frame, return 360of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
226the first window of that frame. */) 361the first window of that frame. */)
227 (Lisp_Object frame_or_window) 362 (Lisp_Object frame_or_window)
228{ 363{
@@ -230,7 +365,7 @@ the first window of that frame. */)
230 365
231 if (NILP (frame_or_window)) 366 if (NILP (frame_or_window))
232 window = SELECTED_FRAME ()->root_window; 367 window = SELECTED_FRAME ()->root_window;
233 else if (WINDOWP (frame_or_window)) 368 else if (WINDOW_VALID_P (frame_or_window))
234 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window; 369 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->root_window;
235 else 370 else
236 { 371 {
@@ -245,7 +380,7 @@ the first window of that frame. */)
245 else if (! NILP (XWINDOW (window)->vchild)) 380 else if (! NILP (XWINDOW (window)->vchild))
246 window = XWINDOW (window)->vchild; 381 window = XWINDOW (window)->vchild;
247 else 382 else
248 abort (); 383 emacs_abort ();
249 } 384 }
250 385
251 return window; 386 return window;
@@ -255,16 +390,16 @@ DEFUN ("frame-selected-window", Fframe_selected_window,
255 Sframe_selected_window, 0, 1, 0, 390 Sframe_selected_window, 0, 1, 0,
256 doc: /* Return the selected window of FRAME-OR-WINDOW. 391 doc: /* Return the selected window of FRAME-OR-WINDOW.
257If omitted, FRAME-OR-WINDOW defaults to the currently selected frame. 392If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
258Else if FRAME-OR-WINDOW denotes any window, return the selected window 393Else if FRAME-OR-WINDOW denotes a valid window, return the selected
259of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return 394window of that window's frame. If FRAME-OR-WINDOW denotes a live frame,
260the selected window of that frame. */) 395return the selected window of that frame. */)
261 (Lisp_Object frame_or_window) 396 (Lisp_Object frame_or_window)
262{ 397{
263 Lisp_Object window; 398 Lisp_Object window;
264 399
265 if (NILP (frame_or_window)) 400 if (NILP (frame_or_window))
266 window = SELECTED_FRAME ()->selected_window; 401 window = SELECTED_FRAME ()->selected_window;
267 else if (WINDOWP (frame_or_window)) 402 else if (WINDOW_VALID_P (frame_or_window))
268 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->selected_window; 403 window = XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window)))->selected_window;
269 else 404 else
270 { 405 {
@@ -297,7 +432,10 @@ Return WINDOW. */)
297 if (EQ (frame, selected_frame)) 432 if (EQ (frame, selected_frame))
298 return Fselect_window (window, norecord); 433 return Fselect_window (window, norecord);
299 else 434 else
300 return XFRAME (frame)->selected_window = window; 435 {
436 fset_selected_window (XFRAME (frame), window);
437 return window;
438 }
301} 439}
302 440
303DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0, 441DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
@@ -330,18 +468,20 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
330 468
331 if (NILP (norecord)) 469 if (NILP (norecord))
332 { 470 {
333 ++window_select_count; 471 w->use_time = ++window_select_count;
334 XSETFASTINT (w->use_time, window_select_count);
335 record_buffer (w->buffer); 472 record_buffer (w->buffer);
336 } 473 }
337 474
475 /* Make the selected window's buffer current. */
476 Fset_buffer (w->buffer);
477
338 if (EQ (window, selected_window) && !inhibit_point_swap) 478 if (EQ (window, selected_window) && !inhibit_point_swap)
339 return window; 479 return window;
340 480
341 sf = SELECTED_FRAME (); 481 sf = SELECTED_FRAME ();
342 if (XFRAME (WINDOW_FRAME (w)) != sf) 482 if (XFRAME (WINDOW_FRAME (w)) != sf)
343 { 483 {
344 XFRAME (WINDOW_FRAME (w))->selected_window = window; 484 fset_selected_window (XFRAME (WINDOW_FRAME (w)), window);
345 /* Use this rather than Fhandle_switch_frame 485 /* Use this rather than Fhandle_switch_frame
346 so that FRAME_FOCUS_FRAME is moved appropriately as we 486 so that FRAME_FOCUS_FRAME is moved appropriately as we
347 move around in the state where a minibuffer in a separate 487 move around in the state where a minibuffer in a separate
@@ -352,11 +492,11 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
352 return window; 492 return window;
353 } 493 }
354 else 494 else
355 sf->selected_window = window; 495 fset_selected_window (sf, window);
356 496
357 /* Store the current buffer's actual point into the 497 /* Store the old selected window's buffer's point in pointm of the old
358 old selected window. It belongs to that window, 498 selected window. It belongs to that window, and when the window is
359 and when the window is not selected, must be in the window. */ 499 not selected, must be in the window. */
360 if (!inhibit_point_swap) 500 if (!inhibit_point_swap)
361 { 501 {
362 ow = XWINDOW (selected_window); 502 ow = XWINDOW (selected_window);
@@ -367,10 +507,7 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
367 } 507 }
368 508
369 selected_window = window; 509 selected_window = window;
370 510 bset_last_selected_window (XBUFFER (w->buffer), window);
371 Fset_buffer (w->buffer);
372
373 BVAR (XBUFFER (w->buffer), last_selected_window) = window;
374 511
375 /* Go to the point recorded in the window. 512 /* Go to the point recorded in the window.
376 This is important when the buffer is in more 513 This is important when the buffer is in more
@@ -378,7 +515,7 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
378 redisplay_window has altered point after scrolling, 515 redisplay_window has altered point after scrolling,
379 because it makes the change only in the window. */ 516 because it makes the change only in the window. */
380 { 517 {
381 register EMACS_INT new_point = marker_position (w->pointm); 518 register ptrdiff_t new_point = marker_position (w->pointm);
382 if (new_point < BEGV) 519 if (new_point < BEGV)
383 SET_PT (BEGV); 520 SET_PT (BEGV);
384 else if (new_point > ZV) 521 else if (new_point > ZV)
@@ -418,92 +555,96 @@ Return nil for an internal window or a deleted window. */)
418 555
419DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0, 556DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0,
420 doc: /* Return the parent window of window WINDOW. 557 doc: /* Return the parent window of window WINDOW.
421If WINDOW is omitted or nil, it defaults to the selected window. 558WINDOW must be a valid window and defaults to the selected one.
422Return nil for a window with no parent (e.g. a root window). */) 559Return nil for a window with no parent (e.g. a root window). */)
423 (Lisp_Object window) 560 (Lisp_Object window)
424{ 561{
425 return decode_any_window (window)->parent; 562 return decode_valid_window (window)->parent;
426} 563}
427 564
428DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 1, 1, 0, 565DEFUN ("window-top-child", Fwindow_top_child, Swindow_top_child, 0, 1, 0,
429 doc: /* Return the topmost child window of window WINDOW. 566 doc: /* Return the topmost child window of window WINDOW.
567WINDOW must be a valid window and defaults to the selected one.
430Return nil if WINDOW is a live window (live windows have no children). 568Return nil if WINDOW is a live window (live windows have no children).
431Return nil if WINDOW is an internal window whose children form a 569Return nil if WINDOW is an internal window whose children form a
432horizontal combination. */) 570horizontal combination. */)
433 (Lisp_Object window) 571 (Lisp_Object window)
434{ 572{
435 CHECK_WINDOW (window); 573 return decode_valid_window (window)->vchild;
436 return decode_any_window (window)->vchild;
437} 574}
438 575
439DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 1, 1, 0, 576DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 0, 1, 0,
440 doc: /* Return the leftmost child window of window WINDOW. 577 doc: /* Return the leftmost child window of window WINDOW.
578WINDOW must be a valid window and defaults to the selected one.
441Return nil if WINDOW is a live window (live windows have no children). 579Return nil if WINDOW is a live window (live windows have no children).
442Return nil if WINDOW is an internal window whose children form a 580Return nil if WINDOW is an internal window whose children form a
443vertical combination. */) 581vertical combination. */)
444 (Lisp_Object window) 582 (Lisp_Object window)
445{ 583{
446 CHECK_WINDOW (window); 584 return decode_valid_window (window)->hchild;
447 return decode_any_window (window)->hchild;
448} 585}
449 586
450DEFUN ("window-next-sibling", Fwindow_next_sibling, Swindow_next_sibling, 0, 1, 0, 587DEFUN ("window-next-sibling", Fwindow_next_sibling, Swindow_next_sibling, 0, 1, 0,
451 doc: /* Return the next sibling window of window WINDOW. 588 doc: /* Return the next sibling window of window WINDOW.
452If WINDOW is omitted or nil, it defaults to the selected window. 589WINDOW must be a valid window and defaults to the selected one.
453Return nil if WINDOW has no next sibling. */) 590Return nil if WINDOW has no next sibling. */)
454 (Lisp_Object window) 591 (Lisp_Object window)
455{ 592{
456 return decode_any_window (window)->next; 593 return decode_valid_window (window)->next;
457} 594}
458 595
459DEFUN ("window-prev-sibling", Fwindow_prev_sibling, Swindow_prev_sibling, 0, 1, 0, 596DEFUN ("window-prev-sibling", Fwindow_prev_sibling, Swindow_prev_sibling, 0, 1, 0,
460 doc: /* Return the previous sibling window of window WINDOW. 597 doc: /* Return the previous sibling window of window WINDOW.
461If WINDOW is omitted or nil, it defaults to the selected window. 598WINDOW must be a valid window and defaults to the selected one.
462Return nil if WINDOW has no previous sibling. */) 599Return nil if WINDOW has no previous sibling. */)
463 (Lisp_Object window) 600 (Lisp_Object window)
464{ 601{
465 return decode_any_window (window)->prev; 602 return decode_valid_window (window)->prev;
466} 603}
467 604
468DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0, 605DEFUN ("window-combination-limit", Fwindow_combination_limit, Swindow_combination_limit, 1, 1, 0,
469 doc: /* Return combination limit of window WINDOW. 606 doc: /* Return combination limit of window WINDOW.
470If the return value is nil, child windows of WINDOW can be recombined with 607If the return value is nil, child windows of WINDOW can be recombined with
471WINDOW's siblings. A return value of t means that child windows of 608WINDOW's siblings. A return value of t means that child windows of
472WINDOW are never \(re-)combined with WINDOW's siblings. */) 609WINDOW are never \(re-)combined with WINDOW's siblings.
610
611WINDOW must be a valid window. The return value is meaningful for
612internal windows only. */)
473 (Lisp_Object window) 613 (Lisp_Object window)
474{ 614{
475 return decode_any_window (window)->combination_limit; 615 CHECK_VALID_WINDOW (window);
616 return XWINDOW (window)->combination_limit;
476} 617}
477 618
478DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0, 619DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
479 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT. 620 doc: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
480If LIMIT is nil, child windows of WINDOW can be recombined with 621If LIMIT is nil, child windows of WINDOW can be recombined with WINDOW's
481WINDOW's siblings. LIMIT t means that child windows of WINDOW are 622siblings. LIMIT t means that child windows of WINDOW are never
482never \(re-)combined with WINDOW's siblings. Other values are reserved 623\(re-)combined with WINDOW's siblings. Other values are reserved for
483for future use. */) 624future use.
625
626WINDOW must be a valid window. Setting the combination limit is
627meaningful for internal windows only. */)
484 (Lisp_Object window, Lisp_Object limit) 628 (Lisp_Object window, Lisp_Object limit)
485{ 629{
486 register struct window *w = decode_any_window (window); 630 wset_combination_limit (decode_valid_window (window), limit);
487 631 return limit;
488 w->combination_limit = limit;
489
490 return w->combination_limit;
491} 632}
492 633
493DEFUN ("window-use-time", Fwindow_use_time, Swindow_use_time, 0, 1, 0, 634DEFUN ("window-use-time", Fwindow_use_time, Swindow_use_time, 0, 1, 0,
494 doc: /* Return the use time of window WINDOW. 635 doc: /* Return the use time of window WINDOW.
495If WINDOW is omitted or nil, it defaults to the selected window. 636WINDOW must be a live window and defaults to the selected one.
496The window with the highest use time is the most recently selected 637The window with the highest use time is the most recently selected
497one. The window with the lowest use time is the least recently 638one. The window with the lowest use time is the least recently
498selected one. */) 639selected one. */)
499 (Lisp_Object window) 640 (Lisp_Object window)
500{ 641{
501 return decode_window (window)->use_time; 642 return make_number (decode_live_window (window)->use_time);
502} 643}
503 644
504DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 1, 0, 645DEFUN ("window-total-height", Fwindow_total_height, Swindow_total_height, 0, 1, 0,
505 doc: /* Return the total height, in lines, of window WINDOW. 646 doc: /* Return the total height, in lines, of window WINDOW.
506If WINDOW is omitted or nil, it defaults to the selected window. 647WINDOW must be a valid window and defaults to the selected one.
507 648
508The return value includes the mode line and header line, if any. 649The return value includes the mode line and header line, if any.
509If WINDOW is an internal window, the total height is the height 650If WINDOW is an internal window, the total height is the height
@@ -513,12 +654,12 @@ On a graphical display, this total height is reported as an
513integer multiple of the default character height. */) 654integer multiple of the default character height. */)
514 (Lisp_Object window) 655 (Lisp_Object window)
515{ 656{
516 return decode_any_window (window)->total_lines; 657 return decode_valid_window (window)->total_lines;
517} 658}
518 659
519DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0, 660DEFUN ("window-total-width", Fwindow_total_width, Swindow_total_width, 0, 1, 0,
520 doc: /* Return the total width, in columns, of window WINDOW. 661 doc: /* Return the total width, in columns, of window WINDOW.
521If WINDOW is omitted or nil, it defaults to the selected window. 662WINDOW must be a valid window and defaults to the selected one.
522 663
523The return value includes any vertical dividers or scroll bars 664The return value includes any vertical dividers or scroll bars
524belonging to WINDOW. If WINDOW is an internal window, the total width 665belonging to WINDOW. If WINDOW is an internal window, the total width
@@ -528,35 +669,34 @@ On a graphical display, this total width is reported as an
528integer multiple of the default character width. */) 669integer multiple of the default character width. */)
529 (Lisp_Object window) 670 (Lisp_Object window)
530{ 671{
531 return decode_any_window (window)->total_cols; 672 return decode_valid_window (window)->total_cols;
532} 673}
533 674
534DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0, 675DEFUN ("window-new-total", Fwindow_new_total, Swindow_new_total, 0, 1, 0,
535 doc: /* Return the new total size of window WINDOW. 676 doc: /* Return the new total size of window WINDOW.
536If WINDOW is omitted or nil, it defaults to the selected window. */) 677WINDOW must be a valid window and defaults to the selected one. */)
537 (Lisp_Object window) 678 (Lisp_Object window)
538{ 679{
539 return decode_any_window (window)->new_total; 680 return decode_valid_window (window)->new_total;
540} 681}
541 682
542DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0, 683DEFUN ("window-normal-size", Fwindow_normal_size, Swindow_normal_size, 0, 2, 0,
543 doc: /* Return the normal height of window WINDOW. 684 doc: /* Return the normal height of window WINDOW.
544If WINDOW is omitted or nil, it defaults to the selected window. 685WINDOW must be a valid window and defaults to the selected one.
545If HORIZONTAL is non-nil, return the normal width of WINDOW. */) 686If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
546 (Lisp_Object window, Lisp_Object horizontal) 687 (Lisp_Object window, Lisp_Object horizontal)
547{ 688{
548 if (NILP (horizontal)) 689 struct window *w = decode_valid_window (window);
549 return decode_any_window (window)->normal_lines; 690
550 else 691 return NILP (horizontal) ? w->normal_lines : w->normal_cols;
551 return decode_any_window (window)->normal_cols;
552} 692}
553 693
554DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0, 694DEFUN ("window-new-normal", Fwindow_new_normal, Swindow_new_normal, 0, 1, 0,
555 doc: /* Return new normal size of window WINDOW. 695 doc: /* Return new normal size of window WINDOW.
556If WINDOW is omitted or nil, it defaults to the selected window. */) 696WINDOW must be a valid window and defaults to the selected one. */)
557 (Lisp_Object window) 697 (Lisp_Object window)
558{ 698{
559 return decode_any_window (window)->new_normal; 699 return decode_valid_window (window)->new_normal;
560} 700}
561 701
562DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0, 702DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
@@ -565,10 +705,10 @@ This is the distance, in columns, between the left edge of WINDOW and
565the left edge of the frame's window area. For instance, the return 705the left edge of the frame's window area. For instance, the return
566value is 0 if there is no window to the left of WINDOW. 706value is 0 if there is no window to the left of WINDOW.
567 707
568If WINDOW is omitted or nil, it defaults to the selected window. */) 708WINDOW must be a valid window and defaults to the selected one. */)
569 (Lisp_Object window) 709 (Lisp_Object window)
570{ 710{
571 return decode_any_window (window)->left_col; 711 return decode_valid_window (window)->left_col;
572} 712}
573 713
574DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0, 714DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
@@ -577,10 +717,10 @@ This is the distance, in lines, between the top of WINDOW and the top
577of the frame's window area. For instance, the return value is 0 if 717of the frame's window area. For instance, the return value is 0 if
578there is no window above WINDOW. 718there is no window above WINDOW.
579 719
580If WINDOW is omitted or nil, it defaults to the selected window. */) 720WINDOW must be a valid window and defaults to the selected one. */)
581 (Lisp_Object window) 721 (Lisp_Object window)
582{ 722{
583 return decode_any_window (window)->top_line; 723 return decode_valid_window (window)->top_line;
584} 724}
585 725
586/* Return the number of lines of W's body. Don't count any mode or 726/* Return the number of lines of W's body. Don't count any mode or
@@ -634,8 +774,7 @@ window_body_cols (struct window *w)
634 774
635DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 1, 0, 775DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 1, 0,
636 doc: /* Return the height, in lines, of WINDOW's text area. 776 doc: /* Return the height, in lines, of WINDOW's text area.
637If WINDOW is omitted or nil, it defaults to the selected window. 777WINDOW must be a live window and defaults to the selected one.
638Signal an error if the window is not live.
639 778
640The returned height does not include the mode line or header line. 779The returned height does not include the mode line or header line.
641On a graphical display, the height is expressed as an integer multiple 780On a graphical display, the height is expressed as an integer multiple
@@ -644,22 +783,19 @@ area is only partially visible, that counts as a whole line; to
644exclude partially-visible lines, use `window-text-height'. */) 783exclude partially-visible lines, use `window-text-height'. */)
645 (Lisp_Object window) 784 (Lisp_Object window)
646{ 785{
647 struct window *w = decode_window (window); 786 return make_number (window_body_lines (decode_live_window (window)));
648 return make_number (window_body_lines (w));
649} 787}
650 788
651DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0, 789DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 1, 0,
652 doc: /* Return the width, in columns, of WINDOW's text area. 790 doc: /* Return the width, in columns, of WINDOW's text area.
653If WINDOW is omitted or nil, it defaults to the selected window. 791WINDOW must be a live window and defaults to the selected one.
654Signal an error if the window is not live.
655 792
656The return value does not include any vertical dividers, fringe or 793The return value does not include any vertical dividers, fringe or
657marginal areas, or scroll bars. On a graphical display, the width is 794marginal areas, or scroll bars. On a graphical display, the width is
658expressed as an integer multiple of the default character width. */) 795expressed as an integer multiple of the default character width. */)
659 (Lisp_Object window) 796 (Lisp_Object window)
660{ 797{
661 struct window *w = decode_window (window); 798 return make_number (window_body_cols (decode_live_window (window)));
662 return make_number (window_body_cols (w));
663} 799}
664 800
665DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0, 801DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
@@ -667,85 +803,97 @@ DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
667WINDOW must be a live window and defaults to the selected one. */) 803WINDOW must be a live window and defaults to the selected one. */)
668 (Lisp_Object window) 804 (Lisp_Object window)
669{ 805{
670 return decode_window (window)->hscroll; 806 return make_number (decode_live_window (window)->hscroll);
807}
808
809/* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
810 range, returning the new amount as a fixnum. */
811static Lisp_Object
812set_window_hscroll (struct window *w, EMACS_INT hscroll)
813{
814 /* Horizontal scrolling has problems with large scroll amounts.
815 It's too slow with long lines, and even with small lines the
816 display can be messed up. For now, though, impose only the limits
817 required by the internal representation: horizontal scrolling must
818 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
819 (since it's stored in a ptrdiff_t). */
820 ptrdiff_t hscroll_max = min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX);
821 ptrdiff_t new_hscroll = clip_to_bounds (0, hscroll, hscroll_max);
822
823 /* Prevent redisplay shortcuts when changing the hscroll. */
824 if (w->hscroll != new_hscroll)
825 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
826
827 w->hscroll = new_hscroll;
828 return make_number (new_hscroll);
671} 829}
672 830
673DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0, 831DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
674 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL. 832 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
675If WINDOW is nil, the selected window is used. 833WINDOW must be a live window and defaults to the selected one.
676Return NCOL. NCOL should be zero or positive. 834Clip the number to a reasonable value if out of range.
835Return the new number. NCOL should be zero or positive.
677 836
678Note that if `automatic-hscrolling' is non-nil, you cannot scroll the 837Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
679window so that the location of point moves off-window. */) 838window so that the location of point moves off-window. */)
680 (Lisp_Object window, Lisp_Object ncol) 839 (Lisp_Object window, Lisp_Object ncol)
681{ 840{
682 struct window *w = decode_window (window);
683 int hscroll;
684
685 CHECK_NUMBER (ncol); 841 CHECK_NUMBER (ncol);
686 hscroll = max (0, XINT (ncol)); 842 return set_window_hscroll (decode_live_window (window), XINT (ncol));
687
688 /* Prevent redisplay shortcuts when changing the hscroll. */
689 if (XINT (w->hscroll) != hscroll)
690 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
691
692 w->hscroll = make_number (hscroll);
693 return ncol;
694} 843}
695 844
696DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger, 845DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
697 Swindow_redisplay_end_trigger, 0, 1, 0, 846 Swindow_redisplay_end_trigger, 0, 1, 0,
698 doc: /* Return WINDOW's redisplay end trigger value. 847 doc: /* Return WINDOW's redisplay end trigger value.
699WINDOW defaults to the selected window. 848WINDOW must be a live window and defaults to the selected one.
700See `set-window-redisplay-end-trigger' for more information. */) 849See `set-window-redisplay-end-trigger' for more information. */)
701 (Lisp_Object window) 850 (Lisp_Object window)
702{ 851{
703 return decode_window (window)->redisplay_end_trigger; 852 return decode_live_window (window)->redisplay_end_trigger;
704} 853}
705 854
706DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger, 855DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
707 Sset_window_redisplay_end_trigger, 2, 2, 0, 856 Sset_window_redisplay_end_trigger, 2, 2, 0,
708 doc: /* Set WINDOW's redisplay end trigger value to VALUE. 857 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
709VALUE should be a buffer position (typically a marker) or nil. 858WINDOW must be a live window and defaults to the selected one. VALUE
710If it is a buffer position, then if redisplay in WINDOW reaches a position 859should be a buffer position (typically a marker) or nil. If it is a
711beyond VALUE, the functions in `redisplay-end-trigger-functions' are called 860buffer position, then if redisplay in WINDOW reaches a position beyond
712with two arguments: WINDOW, and the end trigger value. 861VALUE, the functions in `redisplay-end-trigger-functions' are called
713Afterwards the end-trigger value is reset to nil. */) 862with two arguments: WINDOW, and the end trigger value. Afterwards the
863end-trigger value is reset to nil. */)
714 (register Lisp_Object window, Lisp_Object value) 864 (register Lisp_Object window, Lisp_Object value)
715{ 865{
716 register struct window *w; 866 wset_redisplay_end_trigger (decode_live_window (window), value);
717
718 w = decode_window (window);
719 w->redisplay_end_trigger = value;
720 return value; 867 return value;
721} 868}
722 869
723DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0, 870DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
724 doc: /* Return a list of the edge coordinates of WINDOW. 871 doc: /* Return a list of the edge coordinates of WINDOW.
725The list has the form (LEFT TOP RIGHT BOTTOM). 872WINDOW must be a valid window and defaults to the selected one.
726TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns, 873
727all relative to 0, 0 at top left corner of frame. 874The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
728 875count by lines, and LEFT and RIGHT count by columns, all relative to 0,
729RIGHT is one more than the rightmost column occupied by WINDOW. 8760 at top left corner of frame.
730BOTTOM is one more than the bottommost row occupied by WINDOW. 877
731The edges include the space used by WINDOW's scroll bar, display 878RIGHT is one more than the rightmost column occupied by WINDOW. BOTTOM
732margins, fringes, header line, and/or mode line. For the edges of 879is one more than the bottommost row occupied by WINDOW. The edges
733just the text area, use `window-inside-edges'. */) 880include the space used by WINDOW's scroll bar, display margins, fringes,
881header line, and/or mode line. For the edges of just the text area, use
882`window-inside-edges'. */)
734 (Lisp_Object window) 883 (Lisp_Object window)
735{ 884{
736 register struct window *w = decode_any_window (window); 885 register struct window *w = decode_valid_window (window);
737 886
738 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)), 887 return list4i (WINDOW_LEFT_EDGE_COL (w), WINDOW_TOP_EDGE_LINE (w),
739 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)), 888 WINDOW_RIGHT_EDGE_COL (w), WINDOW_BOTTOM_EDGE_LINE (w));
740 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
741 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
742 Qnil))));
743} 889}
744 890
745DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0, 891DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
746 doc: /* Return a list of the edge pixel coordinates of WINDOW. 892 doc: /* Return a list of the edge pixel coordinates of WINDOW.
747The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at 893WINDOW must be a valid window and defaults to the selected one.
748the top left corner of the frame. 894
895The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
8960, 0 at the top left corner of the frame.
749 897
750RIGHT is one more than the rightmost x position occupied by WINDOW. 898RIGHT is one more than the rightmost x position occupied by WINDOW.
751BOTTOM is one more than the bottommost y position occupied by WINDOW. 899BOTTOM is one more than the bottommost y position occupied by WINDOW.
@@ -754,13 +902,10 @@ margins, fringes, header line, and/or mode line. For the pixel edges
754of just the text area, use `window-inside-pixel-edges'. */) 902of just the text area, use `window-inside-pixel-edges'. */)
755 (Lisp_Object window) 903 (Lisp_Object window)
756{ 904{
757 register struct window *w = decode_any_window (window); 905 register struct window *w = decode_valid_window (window);
758 906
759 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)), 907 return list4i (WINDOW_LEFT_EDGE_X (w), WINDOW_TOP_EDGE_Y (w),
760 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)), 908 WINDOW_RIGHT_EDGE_X (w), WINDOW_BOTTOM_EDGE_Y (w));
761 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
762 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
763 Qnil))));
764} 909}
765 910
766static void 911static void
@@ -788,8 +933,10 @@ calc_absolute_offset (struct window *w, int *add_x, int *add_y)
788DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges, 933DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges,
789 Swindow_absolute_pixel_edges, 0, 1, 0, 934 Swindow_absolute_pixel_edges, 0, 1, 0,
790 doc: /* Return a list of the edge pixel coordinates of WINDOW. 935 doc: /* Return a list of the edge pixel coordinates of WINDOW.
791The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at 936WINDOW must be a valid window and defaults to the selected one.
792the top left corner of the display. 937
938The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
9390, 0 at the top left corner of the display.
793 940
794RIGHT is one more than the rightmost x position occupied by WINDOW. 941RIGHT is one more than the rightmost x position occupied by WINDOW.
795BOTTOM is one more than the bottommost y position occupied by WINDOW. 942BOTTOM is one more than the bottommost y position occupied by WINDOW.
@@ -798,47 +945,51 @@ margins, fringes, header line, and/or mode line. For the pixel edges
798of just the text area, use `window-inside-absolute-pixel-edges'. */) 945of just the text area, use `window-inside-absolute-pixel-edges'. */)
799 (Lisp_Object window) 946 (Lisp_Object window)
800{ 947{
801 register struct window *w = decode_any_window (window); 948 register struct window *w = decode_valid_window (window);
802 int add_x, add_y; 949 int add_x, add_y;
950
803 calc_absolute_offset (w, &add_x, &add_y); 951 calc_absolute_offset (w, &add_x, &add_y);
804 952
805 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w) + add_x), 953 return list4i (WINDOW_LEFT_EDGE_X (w) + add_x,
806 Fcons (make_number (WINDOW_TOP_EDGE_Y (w) + add_y), 954 WINDOW_TOP_EDGE_Y (w) + add_y,
807 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w) + add_x), 955 WINDOW_RIGHT_EDGE_X (w) + add_x,
808 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w) + add_y), 956 WINDOW_BOTTOM_EDGE_Y (w) + add_y);
809 Qnil))));
810} 957}
811 958
812DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0, 959DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
813 doc: /* Return a list of the edge coordinates of WINDOW. 960 doc: /* Return a list of the edge coordinates of WINDOW.
814The list has the form (LEFT TOP RIGHT BOTTOM). 961WINDOW must be a live window and defaults to the selected one.
815TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns, 962
816all relative to 0, 0 at top left corner of frame. 963The returned list has the form (LEFT TOP RIGHT BOTTOM). TOP and BOTTOM
964count by lines, and LEFT and RIGHT count by columns, all relative to 0,
9650 at top left corner of frame.
817 966
818RIGHT is one more than the rightmost column of WINDOW's text area. 967RIGHT is one more than the rightmost column of WINDOW's text area.
819BOTTOM is one more than the bottommost row of WINDOW's text area. 968BOTTOM is one more than the bottommost row of WINDOW's text area. The
820The inside edges do not include the space used by the WINDOW's scroll 969inside edges do not include the space used by the WINDOW's scroll bar,
821bar, display margins, fringes, header line, and/or mode line. */) 970display margins, fringes, header line, and/or mode line. */)
822 (Lisp_Object window) 971 (Lisp_Object window)
823{ 972{
824 register struct window *w = decode_window (window); 973 register struct window *w = decode_live_window (window);
825 974
826 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w) 975 return list4i ((WINDOW_BOX_LEFT_EDGE_COL (w)
827 + WINDOW_LEFT_MARGIN_COLS (w) 976 + WINDOW_LEFT_MARGIN_COLS (w)
828 + WINDOW_LEFT_FRINGE_COLS (w)), 977 + WINDOW_LEFT_FRINGE_COLS (w)),
829 make_number (WINDOW_TOP_EDGE_LINE (w) 978 (WINDOW_TOP_EDGE_LINE (w)
830 + WINDOW_HEADER_LINE_LINES (w)), 979 + WINDOW_HEADER_LINE_LINES (w)),
831 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w) 980 (WINDOW_BOX_RIGHT_EDGE_COL (w)
832 - WINDOW_RIGHT_MARGIN_COLS (w) 981 - WINDOW_RIGHT_MARGIN_COLS (w)
833 - WINDOW_RIGHT_FRINGE_COLS (w)), 982 - WINDOW_RIGHT_FRINGE_COLS (w)),
834 make_number (WINDOW_BOTTOM_EDGE_LINE (w) 983 (WINDOW_BOTTOM_EDGE_LINE (w)
835 - WINDOW_MODE_LINE_LINES (w))); 984 - WINDOW_MODE_LINE_LINES (w)));
836} 985}
837 986
838DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0, 987DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
839 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area. 988 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
840The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0) 989WINDOW must be a live window and defaults to the selected one.
841at the top left corner of the frame's window area. 990
991The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
992(0,0) at the top left corner of the frame's window area.
842 993
843RIGHT is one more than the rightmost x position of WINDOW's text area. 994RIGHT is one more than the rightmost x position of WINDOW's text area.
844BOTTOM is one more than the bottommost y position of WINDOW's text area. 995BOTTOM is one more than the bottommost y position of WINDOW's text area.
@@ -846,26 +997,28 @@ The inside edges do not include the space used by WINDOW's scroll bar,
846display margins, fringes, header line, and/or mode line. */) 997display margins, fringes, header line, and/or mode line. */)
847 (Lisp_Object window) 998 (Lisp_Object window)
848{ 999{
849 register struct window *w = decode_window (window); 1000 register struct window *w = decode_live_window (window);
850 1001
851 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w) 1002 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
852 + WINDOW_LEFT_MARGIN_WIDTH (w) 1003 + WINDOW_LEFT_MARGIN_WIDTH (w)
853 + WINDOW_LEFT_FRINGE_WIDTH (w)), 1004 + WINDOW_LEFT_FRINGE_WIDTH (w)),
854 make_number (WINDOW_TOP_EDGE_Y (w) 1005 (WINDOW_TOP_EDGE_Y (w)
855 + WINDOW_HEADER_LINE_HEIGHT (w)), 1006 + WINDOW_HEADER_LINE_HEIGHT (w)),
856 make_number (WINDOW_BOX_RIGHT_EDGE_X (w) 1007 (WINDOW_BOX_RIGHT_EDGE_X (w)
857 - WINDOW_RIGHT_MARGIN_WIDTH (w) 1008 - WINDOW_RIGHT_MARGIN_WIDTH (w)
858 - WINDOW_RIGHT_FRINGE_WIDTH (w)), 1009 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
859 make_number (WINDOW_BOTTOM_EDGE_Y (w) 1010 (WINDOW_BOTTOM_EDGE_Y (w)
860 - WINDOW_MODE_LINE_HEIGHT (w))); 1011 - WINDOW_MODE_LINE_HEIGHT (w)));
861} 1012}
862 1013
863DEFUN ("window-inside-absolute-pixel-edges", 1014DEFUN ("window-inside-absolute-pixel-edges",
864 Fwindow_inside_absolute_pixel_edges, 1015 Fwindow_inside_absolute_pixel_edges,
865 Swindow_inside_absolute_pixel_edges, 0, 1, 0, 1016 Swindow_inside_absolute_pixel_edges, 0, 1, 0,
866 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area. 1017 doc: /* Return a list of the edge pixel coordinates of WINDOW's text area.
867The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0) 1018WINDOW must be a live window and defaults to the selected one.
868at the top left corner of the frame's window area. 1019
1020The returned list has the form (LEFT TOP RIGHT BOTTOM), all relative to
1021(0,0) at the top left corner of the frame's window area.
869 1022
870RIGHT is one more than the rightmost x position of WINDOW's text area. 1023RIGHT is one more than the rightmost x position of WINDOW's text area.
871BOTTOM is one more than the bottommost y position of WINDOW's text area. 1024BOTTOM is one more than the bottommost y position of WINDOW's text area.
@@ -873,20 +1026,21 @@ The inside edges do not include the space used by WINDOW's scroll bar,
873display margins, fringes, header line, and/or mode line. */) 1026display margins, fringes, header line, and/or mode line. */)
874 (Lisp_Object window) 1027 (Lisp_Object window)
875{ 1028{
876 register struct window *w = decode_window (window); 1029 register struct window *w = decode_live_window (window);
877 int add_x, add_y; 1030 int add_x, add_y;
1031
878 calc_absolute_offset (w, &add_x, &add_y); 1032 calc_absolute_offset (w, &add_x, &add_y);
879 1033
880 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w) 1034 return list4i ((WINDOW_BOX_LEFT_EDGE_X (w)
881 + WINDOW_LEFT_MARGIN_WIDTH (w) 1035 + WINDOW_LEFT_MARGIN_WIDTH (w)
882 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x), 1036 + WINDOW_LEFT_FRINGE_WIDTH (w) + add_x),
883 make_number (WINDOW_TOP_EDGE_Y (w) 1037 (WINDOW_TOP_EDGE_Y (w)
884 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y), 1038 + WINDOW_HEADER_LINE_HEIGHT (w) + add_y),
885 make_number (WINDOW_BOX_RIGHT_EDGE_X (w) 1039 (WINDOW_BOX_RIGHT_EDGE_X (w)
886 - WINDOW_RIGHT_MARGIN_WIDTH (w) 1040 - WINDOW_RIGHT_MARGIN_WIDTH (w)
887 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x), 1041 - WINDOW_RIGHT_FRINGE_WIDTH (w) + add_x),
888 make_number (WINDOW_BOTTOM_EDGE_Y (w) 1042 (WINDOW_BOTTOM_EDGE_Y (w)
889 - WINDOW_MODE_LINE_HEIGHT (w) + add_y)); 1043 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
890} 1044}
891 1045
892/* Test if the character at column X, row Y is within window W. 1046/* Test if the character at column X, row Y is within window W.
@@ -1052,7 +1206,7 @@ window_relative_x_coord (struct window *w, enum window_part part, int x)
1052DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, 1206DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
1053 Scoordinates_in_window_p, 2, 2, 0, 1207 Scoordinates_in_window_p, 2, 2, 0,
1054 doc: /* Return non-nil if COORDINATES are in WINDOW. 1208 doc: /* Return non-nil if COORDINATES are in WINDOW.
1055WINDOW must be a live window. 1209WINDOW must be a live window and defaults to the selected one.
1056COORDINATES is a cons of the form (X . Y), X and Y being distances 1210COORDINATES is a cons of the form (X . Y), X and Y being distances
1057measured in characters from the upper-left corner of the frame. 1211measured in characters from the upper-left corner of the frame.
1058\(0 . 0) denotes the character in the upper left corner of the 1212\(0 . 0) denotes the character in the upper left corner of the
@@ -1074,8 +1228,7 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1074 int x, y; 1228 int x, y;
1075 Lisp_Object lx, ly; 1229 Lisp_Object lx, ly;
1076 1230
1077 CHECK_LIVE_WINDOW (window); 1231 w = decode_live_window (window);
1078 w = XWINDOW (window);
1079 f = XFRAME (w->frame); 1232 f = XFRAME (w->frame);
1080 CHECK_CONS (coordinates); 1233 CHECK_CONS (coordinates);
1081 lx = Fcar (coordinates); 1234 lx = Fcar (coordinates);
@@ -1124,7 +1277,7 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1124 return Qnil; 1277 return Qnil;
1125 1278
1126 default: 1279 default:
1127 abort (); 1280 emacs_abort ();
1128 } 1281 }
1129} 1282}
1130 1283
@@ -1220,12 +1373,7 @@ The top left corner of the frame is considered to be row 0,
1220column 0. */) 1373column 0. */)
1221 (Lisp_Object x, Lisp_Object y, Lisp_Object frame) 1374 (Lisp_Object x, Lisp_Object y, Lisp_Object frame)
1222{ 1375{
1223 struct frame *f; 1376 struct frame *f = decode_live_frame (frame);
1224
1225 if (NILP (frame))
1226 frame = selected_frame;
1227 CHECK_LIVE_FRAME (frame);
1228 f = XFRAME (frame);
1229 1377
1230 /* Check that arguments are integers or floats. */ 1378 /* Check that arguments are integers or floats. */
1231 CHECK_NUMBER_OR_FLOAT (x); 1379 CHECK_NUMBER_OR_FLOAT (x);
@@ -1243,22 +1391,21 @@ DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
1243 doc: /* Return current value of point in WINDOW. 1391 doc: /* Return current value of point in WINDOW.
1244WINDOW must be a live window and defaults to the selected one. 1392WINDOW must be a live window and defaults to the selected one.
1245 1393
1246For a nonselected window, this is the value point would have 1394For a nonselected window, this is the value point would have if that
1247if that window were selected. 1395window were selected.
1248 1396
1249Note that, when WINDOW is the selected window and its buffer 1397Note that, when WINDOW is selected, the value returned is the same as
1250is also currently selected, the value returned is the same as (point). 1398that returned by `point' for WINDOW's buffer. It would be more strictly
1251It would be more strictly correct to return the `top-level' value 1399correct to return the `top-level' value of `point', outside of any
1252of point, outside of any save-excursion forms. 1400`save-excursion' forms. But that is hard to define. */)
1253But that is hard to define. */)
1254 (Lisp_Object window) 1401 (Lisp_Object window)
1255{ 1402{
1256 register struct window *w = decode_window (window); 1403 register struct window *w = decode_live_window (window);
1257 1404
1258 if (w == XWINDOW (selected_window) 1405 if (w == XWINDOW (selected_window))
1259 && current_buffer == XBUFFER (w->buffer)) 1406 return make_number (BUF_PT (XBUFFER (w->buffer)));
1260 return Fpoint (); 1407 else
1261 return Fmarker_position (w->pointm); 1408 return Fmarker_position (w->pointm);
1262} 1409}
1263 1410
1264DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, 1411DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
@@ -1267,7 +1414,7 @@ WINDOW must be a live window and defaults to the selected one.
1267This is updated by redisplay or by calling `set-window-start'. */) 1414This is updated by redisplay or by calling `set-window-start'. */)
1268 (Lisp_Object window) 1415 (Lisp_Object window)
1269{ 1416{
1270 return Fmarker_position (decode_window (window)->start); 1417 return Fmarker_position (decode_live_window (window)->start);
1271} 1418}
1272 1419
1273/* This is text temporarily removed from the doc string below. 1420/* This is text temporarily removed from the doc string below.
@@ -1294,7 +1441,7 @@ if it isn't already recorded. */)
1294 (Lisp_Object window, Lisp_Object update) 1441 (Lisp_Object window, Lisp_Object update)
1295{ 1442{
1296 Lisp_Object value; 1443 Lisp_Object value;
1297 struct window *w = decode_window (window); 1444 struct window *w = decode_live_window (window);
1298 Lisp_Object buf; 1445 Lisp_Object buf;
1299 struct buffer *b; 1446 struct buffer *b;
1300 1447
@@ -1312,9 +1459,7 @@ if it isn't already recorded. */)
1312#endif 1459#endif
1313 1460
1314 if (! NILP (update) 1461 if (! NILP (update)
1315 && ! (! NILP (w->window_end_valid) 1462 && (windows_or_buffers_changed || NILP (w->window_end_valid))
1316 && XFASTINT (w->last_modified) >= BUF_MODIFF (b)
1317 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (b))
1318 && !noninteractive) 1463 && !noninteractive)
1319 { 1464 {
1320 struct text_pos startp; 1465 struct text_pos startp;
@@ -1361,44 +1506,56 @@ if it isn't already recorded. */)
1361 1506
1362DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0, 1507DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1363 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer. 1508 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1509WINDOW must be a live window and defaults to the selected one.
1364Return POS. */) 1510Return POS. */)
1365 (Lisp_Object window, Lisp_Object pos) 1511 (Lisp_Object window, Lisp_Object pos)
1366{ 1512{
1367 register struct window *w = decode_window (window); 1513 register struct window *w = decode_live_window (window);
1368 1514
1369 CHECK_NUMBER_COERCE_MARKER (pos); 1515 CHECK_NUMBER_COERCE_MARKER (pos);
1370 if (w == XWINDOW (selected_window)
1371 && XBUFFER (w->buffer) == current_buffer)
1372 Fgoto_char (pos);
1373 else
1374 set_marker_restricted (w->pointm, pos, w->buffer);
1375 1516
1376 /* We have to make sure that redisplay updates the window to show 1517 if (w == XWINDOW (selected_window))
1377 the new value of point. */ 1518 {
1378 if (!EQ (window, selected_window)) 1519 if (XBUFFER (w->buffer) == current_buffer)
1379 ++windows_or_buffers_changed; 1520 Fgoto_char (pos);
1521 else
1522 {
1523 struct buffer *old_buffer = current_buffer;
1524
1525 set_buffer_internal (XBUFFER (w->buffer));
1526 Fgoto_char (pos);
1527 set_buffer_internal (old_buffer);
1528 }
1529 }
1530 else
1531 {
1532 set_marker_restricted (w->pointm, pos, w->buffer);
1533 /* We have to make sure that redisplay updates the window to show
1534 the new value of point. */
1535 ++windows_or_buffers_changed;
1536 }
1380 1537
1381 return pos; 1538 return pos;
1382} 1539}
1383 1540
1384DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0, 1541DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1385 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer. 1542 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1386If WINDOW is nil, the selected window is used. Return POS. 1543WINDOW must be a live window and defaults to the selected one. Return
1387Optional third arg NOFORCE non-nil inhibits next redisplay from 1544POS. Optional third arg NOFORCE non-nil inhibits next redisplay from
1388overriding motion of point in order to display at this exact start. */) 1545overriding motion of point in order to display at this exact start. */)
1389 (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce) 1546 (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce)
1390{ 1547{
1391 register struct window *w = decode_window (window); 1548 register struct window *w = decode_live_window (window);
1392 1549
1393 CHECK_NUMBER_COERCE_MARKER (pos); 1550 CHECK_NUMBER_COERCE_MARKER (pos);
1394 set_marker_restricted (w->start, pos, w->buffer); 1551 set_marker_restricted (w->start, pos, w->buffer);
1395 /* this is not right, but much easier than doing what is right. */ 1552 /* this is not right, but much easier than doing what is right. */
1396 w->start_at_line_beg = Qnil; 1553 w->start_at_line_beg = 0;
1397 if (NILP (noforce)) 1554 if (NILP (noforce))
1398 w->force_start = Qt; 1555 w->force_start = 1;
1399 w->update_mode_line = Qt; 1556 w->update_mode_line = 1;
1400 XSETFASTINT (w->last_modified, 0); 1557 w->last_modified = 0;
1401 XSETFASTINT (w->last_overlay_modified, 0); 1558 w->last_overlay_modified = 0;
1402 if (!EQ (window, selected_window)) 1559 if (!EQ (window, selected_window))
1403 windows_or_buffers_changed++; 1560 windows_or_buffers_changed++;
1404 1561
@@ -1408,12 +1565,14 @@ overriding motion of point in order to display at this exact start. */)
1408DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, 1565DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
1409 Spos_visible_in_window_p, 0, 3, 0, 1566 Spos_visible_in_window_p, 0, 3, 0,
1410 doc: /* Return non-nil if position POS is currently on the frame in WINDOW. 1567 doc: /* Return non-nil if position POS is currently on the frame in WINDOW.
1411Return nil if that position is scrolled vertically out of view. 1568WINDOW must be a live window and defaults to the selected one.
1412If a character is only partially visible, nil is returned, unless the 1569
1413optional argument PARTIALLY is non-nil. 1570Return nil if that position is scrolled vertically out of view. If a
1414If POS is only out of view because of horizontal scrolling, return non-nil. 1571character is only partially visible, nil is returned, unless the
1415If POS is t, it specifies the position of the last visible glyph in WINDOW. 1572optional argument PARTIALLY is non-nil. If POS is only out of view
1416POS defaults to point in WINDOW; WINDOW defaults to the selected window. 1573because of horizontal scrolling, return non-nil. If POS is t, it
1574specifies the position of the last visible glyph in WINDOW. POS
1575defaults to point in WINDOW; WINDOW defaults to the selected window.
1417 1576
1418If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil, 1577If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1419return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]), 1578return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
@@ -1432,7 +1591,7 @@ display row, and VPOS is the row number (0-based) containing POS. */)
1432 int rtop, rbot, rowh, vpos, fully_p = 1; 1591 int rtop, rbot, rowh, vpos, fully_p = 1;
1433 int x, y; 1592 int x, y;
1434 1593
1435 w = decode_window (window); 1594 w = decode_live_window (window);
1436 buf = XBUFFER (w->buffer); 1595 buf = XBUFFER (w->buffer);
1437 SET_TEXT_POS_FROM_MARKER (top, w->start); 1596 SET_TEXT_POS_FROM_MARKER (top, w->start);
1438 1597
@@ -1462,8 +1621,7 @@ display row, and VPOS is the row number (0-based) containing POS. */)
1462 { 1621 {
1463 Lisp_Object part = Qnil; 1622 Lisp_Object part = Qnil;
1464 if (!fully_p) 1623 if (!fully_p)
1465 part = list4 (make_number (rtop), make_number (rbot), 1624 part = list4i (rtop, rbot, rowh, vpos);
1466 make_number (rowh), make_number (vpos));
1467 in_window = Fcons (make_number (x), 1625 in_window = Fcons (make_number (x),
1468 Fcons (make_number (y), part)); 1626 Fcons (make_number (y), part));
1469 } 1627 }
@@ -1474,7 +1632,7 @@ display row, and VPOS is the row number (0-based) containing POS. */)
1474DEFUN ("window-line-height", Fwindow_line_height, 1632DEFUN ("window-line-height", Fwindow_line_height,
1475 Swindow_line_height, 0, 2, 0, 1633 Swindow_line_height, 0, 2, 0,
1476 doc: /* Return height in pixels of text line LINE in window WINDOW. 1634 doc: /* Return height in pixels of text line LINE in window WINDOW.
1477WINDOW defaults to the selected window. 1635WINDOW must be a live window and defaults to the selected one.
1478 1636
1479Return height of current line if LINE is omitted or nil. Return height of 1637Return height of current line if LINE is omitted or nil. Return height of
1480header or mode line if LINE is `header-line' or `mode-line'. 1638header or mode line if LINE is `header-line' or `mode-line'.
@@ -1495,9 +1653,10 @@ Return nil if window display is not up-to-date. In that case, use
1495 register struct window *w; 1653 register struct window *w;
1496 register struct buffer *b; 1654 register struct buffer *b;
1497 struct glyph_row *row, *end_row; 1655 struct glyph_row *row, *end_row;
1498 int max_y, crop, i, n; 1656 int max_y, crop, i;
1657 EMACS_INT n;
1499 1658
1500 w = decode_window (window); 1659 w = decode_live_window (window);
1501 1660
1502 if (noninteractive || w->pseudo_window_p) 1661 if (noninteractive || w->pseudo_window_p)
1503 return Qnil; 1662 return Qnil;
@@ -1509,8 +1668,8 @@ Return nil if window display is not up-to-date. In that case, use
1509 if (NILP (w->window_end_valid) 1668 if (NILP (w->window_end_valid)
1510 || current_buffer->clip_changed 1669 || current_buffer->clip_changed
1511 || current_buffer->prevent_redisplay_optimizations_p 1670 || current_buffer->prevent_redisplay_optimizations_p
1512 || XFASTINT (w->last_modified) < BUF_MODIFF (b) 1671 || w->last_modified < BUF_MODIFF (b)
1513 || XFASTINT (w->last_overlay_modified) < BUF_OVERLAY_MODIFF (b)) 1672 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1514 return Qnil; 1673 return Qnil;
1515 1674
1516 if (NILP (line)) 1675 if (NILP (line))
@@ -1528,23 +1687,19 @@ Return nil if window display is not up-to-date. In that case, use
1528 if (!WINDOW_WANTS_HEADER_LINE_P (w)) 1687 if (!WINDOW_WANTS_HEADER_LINE_P (w))
1529 return Qnil; 1688 return Qnil;
1530 row = MATRIX_HEADER_LINE_ROW (w->current_matrix); 1689 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
1531 if (!row->enabled_p) 1690 return row->enabled_p ? list4i (row->height, 0, 0, 0) : Qnil;
1532 return Qnil;
1533 return list4 (make_number (row->height),
1534 make_number (0), make_number (0),
1535 make_number (0));
1536 } 1691 }
1537 1692
1538 if (EQ (line, Qmode_line)) 1693 if (EQ (line, Qmode_line))
1539 { 1694 {
1540 row = MATRIX_MODE_LINE_ROW (w->current_matrix); 1695 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
1541 if (!row->enabled_p) 1696 return (row->enabled_p ?
1542 return Qnil; 1697 list4i (row->height,
1543 return list4 (make_number (row->height), 1698 0, /* not accurate */
1544 make_number (0), /* not accurate */ 1699 (WINDOW_HEADER_LINE_HEIGHT (w)
1545 make_number (WINDOW_HEADER_LINE_HEIGHT (w) 1700 + window_text_bottom_y (w)),
1546 + window_text_bottom_y (w)), 1701 0)
1547 make_number (0)); 1702 : Qnil);
1548 } 1703 }
1549 1704
1550 CHECK_NUMBER (line); 1705 CHECK_NUMBER (line);
@@ -1573,10 +1728,7 @@ Return nil if window display is not up-to-date. In that case, use
1573 1728
1574 found_row: 1729 found_row:
1575 crop = max (0, (row->y + row->height) - max_y); 1730 crop = max (0, (row->y + row->height) - max_y);
1576 return list4 (make_number (row->height + min (0, row->y) - crop), 1731 return list4i (row->height + min (0, row->y) - crop, i, row->y, crop);
1577 make_number (i),
1578 make_number (row->y),
1579 make_number (crop));
1580} 1732}
1581 1733
1582DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p, 1734DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
@@ -1585,8 +1737,8 @@ DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1585More precisely, return the value assigned by the last call of 1737More precisely, return the value assigned by the last call of
1586`set-window-dedicated-p' for WINDOW. Return nil if that function was 1738`set-window-dedicated-p' for WINDOW. Return nil if that function was
1587never called with WINDOW as its argument, or the value set by that 1739never called with WINDOW as its argument, or the value set by that
1588function was internally reset since its last call. WINDOW defaults to 1740function was internally reset since its last call. WINDOW must be a
1589the selected window. 1741live window and defaults to the selected one.
1590 1742
1591When a window is dedicated to its buffer, `display-buffer' will refrain 1743When a window is dedicated to its buffer, `display-buffer' will refrain
1592from displaying another buffer in it. `get-lru-window' and 1744from displaying another buffer in it. `get-lru-window' and
@@ -1599,7 +1751,7 @@ window, unless that window is "strongly" dedicated to its buffer, that
1599is the value returned by `window-dedicated-p' is t. */) 1751is the value returned by `window-dedicated-p' is t. */)
1600 (Lisp_Object window) 1752 (Lisp_Object window)
1601{ 1753{
1602 return decode_window (window)->dedicated; 1754 return decode_live_window (window)->dedicated;
1603} 1755}
1604 1756
1605DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, 1757DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
@@ -1623,10 +1775,8 @@ buffer. If and when `set-window-buffer' displays another buffer in a
1623window, it also makes sure that the window is no more dedicated. */) 1775window, it also makes sure that the window is no more dedicated. */)
1624 (Lisp_Object window, Lisp_Object flag) 1776 (Lisp_Object window, Lisp_Object flag)
1625{ 1777{
1626 register struct window *w = decode_window (window); 1778 wset_dedicated (decode_live_window (window), flag);
1627 1779 return flag;
1628 w->dedicated = flag;
1629 return w->dedicated;
1630} 1780}
1631 1781
1632DEFUN ("window-prev-buffers", Fwindow_prev_buffers, Swindow_prev_buffers, 1782DEFUN ("window-prev-buffers", Fwindow_prev_buffers, Swindow_prev_buffers,
@@ -1639,7 +1789,7 @@ where BUFFER is a buffer, WINDOW-START is the start position of the
1639window for that buffer, and POS is a window-specific point value. */) 1789window for that buffer, and POS is a window-specific point value. */)
1640 (Lisp_Object window) 1790 (Lisp_Object window)
1641{ 1791{
1642 return decode_window (window)->prev_buffers; 1792 return decode_live_window (window)->prev_buffers;
1643} 1793}
1644 1794
1645DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers, 1795DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers,
@@ -1652,7 +1802,8 @@ where BUFFER is a buffer, WINDOW-START is the start position of the
1652window for that buffer, and POS is a window-specific point value. */) 1802window for that buffer, and POS is a window-specific point value. */)
1653 (Lisp_Object window, Lisp_Object prev_buffers) 1803 (Lisp_Object window, Lisp_Object prev_buffers)
1654{ 1804{
1655 return decode_window (window)->prev_buffers = prev_buffers; 1805 wset_prev_buffers (decode_live_window (window), prev_buffers);
1806 return prev_buffers;
1656} 1807}
1657 1808
1658DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers, 1809DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers,
@@ -1661,7 +1812,7 @@ DEFUN ("window-next-buffers", Fwindow_next_buffers, Swindow_next_buffers,
1661WINDOW must be a live window and defaults to the selected one. */) 1812WINDOW must be a live window and defaults to the selected one. */)
1662 (Lisp_Object window) 1813 (Lisp_Object window)
1663{ 1814{
1664 return decode_window (window)->next_buffers; 1815 return decode_live_window (window)->next_buffers;
1665} 1816}
1666 1817
1667DEFUN ("set-window-next-buffers", Fset_window_next_buffers, 1818DEFUN ("set-window-next-buffers", Fset_window_next_buffers,
@@ -1671,23 +1822,24 @@ WINDOW must be a live window and defaults to the selected one.
1671NEXT-BUFFERS should be a list of buffers. */) 1822NEXT-BUFFERS should be a list of buffers. */)
1672 (Lisp_Object window, Lisp_Object next_buffers) 1823 (Lisp_Object window, Lisp_Object next_buffers)
1673{ 1824{
1674 return decode_window (window)->next_buffers = next_buffers; 1825 wset_next_buffers (decode_live_window (window), next_buffers);
1826 return next_buffers;
1675} 1827}
1676 1828
1677DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters, 1829DEFUN ("window-parameters", Fwindow_parameters, Swindow_parameters,
1678 0, 1, 0, 1830 0, 1, 0,
1679 doc: /* Return the parameters of WINDOW and their values. 1831 doc: /* Return the parameters of WINDOW and their values.
1680WINDOW defaults to the selected window. The return value is a list of 1832WINDOW must be a valid window and defaults to the selected one. The
1681elements of the form (PARAMETER . VALUE). */) 1833return value is a list of elements of the form (PARAMETER . VALUE). */)
1682 (Lisp_Object window) 1834 (Lisp_Object window)
1683{ 1835{
1684 return Fcopy_alist (decode_any_window (window)->window_parameters); 1836 return Fcopy_alist (decode_valid_window (window)->window_parameters);
1685} 1837}
1686 1838
1687DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter, 1839DEFUN ("window-parameter", Fwindow_parameter, Swindow_parameter,
1688 2, 2, 0, 1840 2, 2, 0,
1689 doc: /* Return WINDOW's value for PARAMETER. 1841 doc: /* Return WINDOW's value for PARAMETER.
1690WINDOW defaults to the selected window. */) 1842WINDOW can be any window and defaults to the selected one. */)
1691 (Lisp_Object window, Lisp_Object parameter) 1843 (Lisp_Object window, Lisp_Object parameter)
1692{ 1844{
1693 Lisp_Object result; 1845 Lisp_Object result;
@@ -1699,7 +1851,8 @@ WINDOW defaults to the selected window. */)
1699DEFUN ("set-window-parameter", Fset_window_parameter, 1851DEFUN ("set-window-parameter", Fset_window_parameter,
1700 Sset_window_parameter, 3, 3, 0, 1852 Sset_window_parameter, 3, 3, 0,
1701 doc: /* Set WINDOW's value of PARAMETER to VALUE. 1853 doc: /* Set WINDOW's value of PARAMETER to VALUE.
1702WINDOW defaults to the selected window. Return VALUE. */) 1854WINDOW can be any window and defaults to the selected one.
1855Return VALUE. */)
1703 (Lisp_Object window, Lisp_Object parameter, Lisp_Object value) 1856 (Lisp_Object window, Lisp_Object parameter, Lisp_Object value)
1704{ 1857{
1705 register struct window *w = decode_any_window (window); 1858 register struct window *w = decode_any_window (window);
@@ -1707,7 +1860,8 @@ WINDOW defaults to the selected window. Return VALUE. */)
1707 1860
1708 old_alist_elt = Fassq (parameter, w->window_parameters); 1861 old_alist_elt = Fassq (parameter, w->window_parameters);
1709 if (NILP (old_alist_elt)) 1862 if (NILP (old_alist_elt))
1710 w->window_parameters = Fcons (Fcons (parameter, value), w->window_parameters); 1863 wset_window_parameters
1864 (w, Fcons (Fcons (parameter, value), w->window_parameters));
1711 else 1865 else
1712 Fsetcdr (old_alist_elt, value); 1866 Fsetcdr (old_alist_elt, value);
1713 return value; 1867 return value;
@@ -1716,10 +1870,10 @@ WINDOW defaults to the selected window. Return VALUE. */)
1716DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table, 1870DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1717 0, 1, 0, 1871 0, 1, 0,
1718 doc: /* Return the display-table that WINDOW is using. 1872 doc: /* Return the display-table that WINDOW is using.
1719WINDOW defaults to the selected window. */) 1873WINDOW must be a live window and defaults to the selected one. */)
1720 (Lisp_Object window) 1874 (Lisp_Object window)
1721{ 1875{
1722 return decode_window (window)->display_table; 1876 return decode_live_window (window)->display_table;
1723} 1877}
1724 1878
1725/* Get the display table for use on window W. This is either W's 1879/* Get the display table for use on window W. This is either W's
@@ -1748,13 +1902,11 @@ window_display_table (struct window *w)
1748} 1902}
1749 1903
1750DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0, 1904DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1751 doc: /* Set WINDOW's display-table to TABLE. */) 1905 doc: /* Set WINDOW's display-table to TABLE.
1906WINDOW must be a live window and defaults to the selected one. */)
1752 (register Lisp_Object window, Lisp_Object table) 1907 (register Lisp_Object window, Lisp_Object table)
1753{ 1908{
1754 register struct window *w; 1909 wset_display_table (decode_live_window (window), table);
1755
1756 w = decode_window (window);
1757 w->display_table = table;
1758 return table; 1910 return table;
1759} 1911}
1760 1912
@@ -1769,7 +1921,7 @@ unshow_buffer (register struct window *w)
1769 buf = w->buffer; 1921 buf = w->buffer;
1770 b = XBUFFER (buf); 1922 b = XBUFFER (buf);
1771 if (b != XMARKER (w->pointm)->buffer) 1923 if (b != XMARKER (w->pointm)->buffer)
1772 abort (); 1924 emacs_abort ();
1773 1925
1774#if 0 1926#if 0
1775 if (w == XWINDOW (selected_window) 1927 if (w == XWINDOW (selected_window)
@@ -1790,6 +1942,9 @@ unshow_buffer (register struct window *w)
1790 is actually stored in that buffer, and the window's pointm isn't used. 1942 is actually stored in that buffer, and the window's pointm isn't used.
1791 So don't clobber point in that buffer. */ 1943 So don't clobber point in that buffer. */
1792 if (! EQ (buf, XWINDOW (selected_window)->buffer) 1944 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1945 /* Don't clobber point in current buffer either (this could be
1946 useful in connection with bug#12208).
1947 && XBUFFER (buf) != current_buffer */
1793 /* This line helps to fix Horsley's testbug.el bug. */ 1948 /* This line helps to fix Horsley's testbug.el bug. */
1794 && !(WINDOWP (BVAR (b, last_selected_window)) 1949 && !(WINDOWP (BVAR (b, last_selected_window))
1795 && w != XWINDOW (BVAR (b, last_selected_window)) 1950 && w != XWINDOW (BVAR (b, last_selected_window))
@@ -1804,7 +1959,7 @@ unshow_buffer (register struct window *w)
1804 1959
1805 if (WINDOWP (BVAR (b, last_selected_window)) 1960 if (WINDOWP (BVAR (b, last_selected_window))
1806 && w == XWINDOW (BVAR (b, last_selected_window))) 1961 && w == XWINDOW (BVAR (b, last_selected_window)))
1807 BVAR (b, last_selected_window) = Qnil; 1962 bset_last_selected_window (b, Qnil);
1808} 1963}
1809 1964
1810/* Put NEW into the window structure in place of OLD. SETFLAG zero 1965/* Put NEW into the window structure in place of OLD. SETFLAG zero
@@ -1819,18 +1974,18 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
1819 /* If OLD is its frame's root window, then NEW is the new 1974 /* If OLD is its frame's root window, then NEW is the new
1820 root window for that frame. */ 1975 root window for that frame. */
1821 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame)))) 1976 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1822 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = new; 1977 fset_root_window (XFRAME (o->frame), new);
1823 1978
1824 if (setflag) 1979 if (setflag)
1825 { 1980 {
1826 n->left_col = o->left_col; 1981 wset_left_col (n, o->left_col);
1827 n->top_line = o->top_line; 1982 wset_top_line (n, o->top_line);
1828 n->total_cols = o->total_cols; 1983 wset_total_cols (n, o->total_cols);
1829 n->total_lines = o->total_lines; 1984 wset_total_lines (n, o->total_lines);
1830 n->normal_cols = o->normal_cols; 1985 wset_normal_cols (n, o->normal_cols);
1831 o->normal_cols = make_float (1.0); 1986 wset_normal_cols (o, make_float (1.0));
1832 n->normal_lines = o->normal_lines; 1987 wset_normal_lines (n, o->normal_lines);
1833 o->normal_lines = make_float (1.0); 1988 wset_normal_lines (o, make_float (1.0));
1834 n->desired_matrix = n->current_matrix = 0; 1989 n->desired_matrix = n->current_matrix = 0;
1835 n->vscroll = 0; 1990 n->vscroll = 0;
1836 memset (&n->cursor, 0, sizeof (n->cursor)); 1991 memset (&n->cursor, 0, sizeof (n->cursor));
@@ -1840,27 +1995,30 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
1840 n->phys_cursor_width = -1; 1995 n->phys_cursor_width = -1;
1841 n->must_be_updated_p = 0; 1996 n->must_be_updated_p = 0;
1842 n->pseudo_window_p = 0; 1997 n->pseudo_window_p = 0;
1843 XSETFASTINT (n->window_end_vpos, 0); 1998 wset_window_end_vpos (n, make_number (0));
1844 XSETFASTINT (n->window_end_pos, 0); 1999 wset_window_end_pos (n, make_number (0));
1845 n->window_end_valid = Qnil; 2000 wset_window_end_valid (n, Qnil);
1846 n->frozen_window_start_p = 0; 2001 n->frozen_window_start_p = 0;
1847 } 2002 }
1848 2003
1849 n->next = tem = o->next; 2004 tem = o->next;
2005 wset_next (n, tem);
1850 if (!NILP (tem)) 2006 if (!NILP (tem))
1851 XWINDOW (tem)->prev = new; 2007 wset_prev (XWINDOW (tem), new);
1852 2008
1853 n->prev = tem = o->prev; 2009 tem = o->prev;
2010 wset_prev (n, tem);
1854 if (!NILP (tem)) 2011 if (!NILP (tem))
1855 XWINDOW (tem)->next = new; 2012 wset_next (XWINDOW (tem), new);
1856 2013
1857 n->parent = tem = o->parent; 2014 tem = o->parent;
2015 wset_parent (n, tem);
1858 if (!NILP (tem)) 2016 if (!NILP (tem))
1859 { 2017 {
1860 if (EQ (XWINDOW (tem)->vchild, old)) 2018 if (EQ (XWINDOW (tem)->vchild, old))
1861 XWINDOW (tem)->vchild = new; 2019 wset_vchild (XWINDOW (tem), new);
1862 if (EQ (XWINDOW (tem)->hchild, old)) 2020 if (EQ (XWINDOW (tem)->hchild, old))
1863 XWINDOW (tem)->hchild = new; 2021 wset_hchild (XWINDOW (tem), new);
1864 } 2022 }
1865} 2023}
1866 2024
@@ -1893,34 +2051,34 @@ recombine_windows (Lisp_Object window)
1893 assign new normal sizes. */ 2051 assign new normal sizes. */
1894 if (NILP (w->prev)) 2052 if (NILP (w->prev))
1895 if (horflag) 2053 if (horflag)
1896 p->hchild = child; 2054 wset_hchild (p, child);
1897 else 2055 else
1898 p->vchild = child; 2056 wset_vchild (p, child);
1899 else 2057 else
1900 { 2058 {
1901 c->prev = w->prev; 2059 wset_prev (c, w->prev);
1902 XWINDOW (w->prev)->next = child; 2060 wset_next (XWINDOW (w->prev), child);
1903 } 2061 }
1904 2062
1905 while (c) 2063 while (c)
1906 { 2064 {
1907 c->parent = parent; 2065 wset_parent (c, parent);
1908 2066
1909 if (horflag) 2067 if (horflag)
1910 c->normal_cols 2068 wset_normal_cols (c,
1911 = make_float (XFLOATINT (c->total_cols) 2069 make_float (XFLOATINT (c->total_cols)
1912 / XFLOATINT (p->total_cols)); 2070 / XFLOATINT (p->total_cols)));
1913 else 2071 else
1914 c->normal_lines 2072 wset_normal_lines (c,
1915 = make_float (XFLOATINT (c->total_lines) 2073 make_float (XFLOATINT (c->total_lines)
1916 / XFLOATINT (p->total_lines)); 2074 / XFLOATINT (p->total_lines)));
1917 2075
1918 if (NILP (c->next)) 2076 if (NILP (c->next))
1919 { 2077 {
1920 if (!NILP (w->next)) 2078 if (!NILP (w->next))
1921 { 2079 {
1922 c->next = w->next; 2080 wset_next (c, w->next);
1923 XWINDOW (c->next)->prev = child; 2081 wset_prev (XWINDOW (c->next), child);
1924 } 2082 }
1925 2083
1926 c = 0; 2084 c = 0;
@@ -1933,7 +2091,8 @@ recombine_windows (Lisp_Object window)
1933 } 2091 }
1934 2092
1935 /* WINDOW can be deleted now. */ 2093 /* WINDOW can be deleted now. */
1936 w->vchild = w->hchild = Qnil; 2094 wset_vchild (w, Qnil);
2095 wset_hchild (w, Qnil);
1937 } 2096 }
1938 } 2097 }
1939} 2098}
@@ -1974,10 +2133,10 @@ window_list (void)
1974{ 2133{
1975 if (!CONSP (Vwindow_list)) 2134 if (!CONSP (Vwindow_list))
1976 { 2135 {
1977 Lisp_Object tail; 2136 Lisp_Object tail, frame;
1978 2137
1979 Vwindow_list = Qnil; 2138 Vwindow_list = Qnil;
1980 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) 2139 FOR_EACH_FRAME (tail, frame)
1981 { 2140 {
1982 Lisp_Object args[2]; 2141 Lisp_Object args[2];
1983 2142
@@ -1985,7 +2144,7 @@ window_list (void)
1985 new windows at the front of args[1], which means we 2144 new windows at the front of args[1], which means we
1986 have to reverse this list at the end. */ 2145 have to reverse this list at the end. */
1987 args[1] = Qnil; 2146 args[1] = Qnil;
1988 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]); 2147 foreach_window (XFRAME (frame), add_window_to_list, &args[1]);
1989 args[0] = Vwindow_list; 2148 args[0] = Vwindow_list;
1990 args[1] = Fnreverse (args[1]); 2149 args[1] = Fnreverse (args[1]);
1991 Vwindow_list = Fnconc (2, args); 2150 Vwindow_list = Fnconc (2, args);
@@ -2033,7 +2192,7 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf
2033 candidate_p = 1; 2192 candidate_p = 1;
2034 else if (NILP (all_frames)) 2193 else if (NILP (all_frames))
2035 { 2194 {
2036 xassert (WINDOWP (owindow)); 2195 eassert (WINDOWP (owindow));
2037 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame); 2196 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
2038 } 2197 }
2039 else if (EQ (all_frames, Qvisible)) 2198 else if (EQ (all_frames, Qvisible))
@@ -2080,11 +2239,9 @@ candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf
2080static void 2239static void
2081decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames) 2240decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object *all_frames)
2082{ 2241{
2083 if (NILP (*window)) 2242 struct window *w = decode_live_window (*window);
2084 *window = selected_window;
2085 else
2086 CHECK_LIVE_WINDOW (*window);
2087 2243
2244 XSETWINDOW (*window, w);
2088 /* MINIBUF nil may or may not include minibuffers. Decide if it 2245 /* MINIBUF nil may or may not include minibuffers. Decide if it
2089 does. */ 2246 does. */
2090 if (NILP (*minibuf)) 2247 if (NILP (*minibuf))
@@ -2098,9 +2255,10 @@ decode_next_window_args (Lisp_Object *window, Lisp_Object *minibuf, Lisp_Object
2098 2255
2099 /* ALL_FRAMES nil doesn't specify which frames to include. */ 2256 /* ALL_FRAMES nil doesn't specify which frames to include. */
2100 if (NILP (*all_frames)) 2257 if (NILP (*all_frames))
2101 *all_frames = (!EQ (*minibuf, Qlambda) 2258 *all_frames
2102 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame)) 2259 = (!EQ (*minibuf, Qlambda)
2103 : Qnil); 2260 ? FRAME_MINIBUF_WINDOW (XFRAME (w->frame))
2261 : Qnil);
2104 else if (EQ (*all_frames, Qvisible)) 2262 else if (EQ (*all_frames, Qvisible))
2105 ; 2263 ;
2106 else if (EQ (*all_frames, make_number (0))) 2264 else if (EQ (*all_frames, make_number (0)))
@@ -2453,7 +2611,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2453 if (EQ (w->buffer, obj)) 2611 if (EQ (w->buffer, obj))
2454 { 2612 {
2455 /* Undedicate WINDOW. */ 2613 /* Undedicate WINDOW. */
2456 w->dedicated = Qnil; 2614 wset_dedicated (w, Qnil);
2457 /* Make WINDOW show the buffer returned by 2615 /* Make WINDOW show the buffer returned by
2458 other_buffer_safely, don't run any hooks. */ 2616 other_buffer_safely, don't run any hooks. */
2459 set_window_buffer 2617 set_window_buffer
@@ -2471,7 +2629,7 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2471 if (EQ (w->buffer, obj)) 2629 if (EQ (w->buffer, obj))
2472 { 2630 {
2473 mark_window_display_accurate (window, 0); 2631 mark_window_display_accurate (window, 0);
2474 w->update_mode_line = Qt; 2632 w->update_mode_line = 1;
2475 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1; 2633 XBUFFER (obj)->prevent_redisplay_optimizations_p = 1;
2476 ++update_mode_lines; 2634 ++update_mode_lines;
2477 best_window = window; 2635 best_window = window;
@@ -2481,8 +2639,8 @@ window_loop (enum window_loop type, Lisp_Object obj, int mini, Lisp_Object frame
2481 /* Check for a window that has a killed buffer. */ 2639 /* Check for a window that has a killed buffer. */
2482 case CHECK_ALL_WINDOWS: 2640 case CHECK_ALL_WINDOWS:
2483 if (! NILP (w->buffer) 2641 if (! NILP (w->buffer)
2484 && NILP (BVAR (XBUFFER (w->buffer), name))) 2642 && !BUFFER_LIVE_P (XBUFFER (w->buffer)))
2485 abort (); 2643 emacs_abort ();
2486 break; 2644 break;
2487 2645
2488 case WINDOW_LOOP_UNUSED: 2646 case WINDOW_LOOP_UNUSED:
@@ -2546,8 +2704,8 @@ resize_root_window (Lisp_Object window, Lisp_Object delta, Lisp_Object horizonta
2546DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal, 2704DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal,
2547 Sdelete_other_windows_internal, 0, 2, "", 2705 Sdelete_other_windows_internal, 0, 2, "",
2548 doc: /* Make WINDOW fill its frame. 2706 doc: /* Make WINDOW fill its frame.
2549Only the frame WINDOW is on is affected. WINDOW may be any window and 2707Only the frame WINDOW is on is affected. WINDOW must be a valid window
2550defaults to the selected one. 2708and defaults to the selected one.
2551 2709
2552Optional argument ROOT, if non-nil, must specify an internal window such 2710Optional argument ROOT, if non-nil, must specify an internal window such
2553that WINDOW is in its window subtree. If this is the case, replace ROOT 2711that WINDOW is in its window subtree. If this is the case, replace ROOT
@@ -2563,10 +2721,10 @@ window-start value is reasonable when this function is called. */)
2563 struct window *w, *r, *s; 2721 struct window *w, *r, *s;
2564 struct frame *f; 2722 struct frame *f;
2565 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta; 2723 Lisp_Object sibling, pwindow, swindow IF_LINT (= Qnil), delta;
2566 EMACS_INT startpos IF_LINT (= 0); 2724 ptrdiff_t startpos IF_LINT (= 0);
2567 int top IF_LINT (= 0), new_top, resize_failed; 2725 int top IF_LINT (= 0), new_top, resize_failed;
2568 2726
2569 w = decode_any_window (window); 2727 w = decode_valid_window (window);
2570 XSETWINDOW (window, w); 2728 XSETWINDOW (window, w);
2571 f = XFRAME (w->frame); 2729 f = XFRAME (w->frame);
2572 2730
@@ -2579,7 +2737,7 @@ window-start value is reasonable when this function is called. */)
2579 else 2737 else
2580 /* ROOT must be an ancestor of WINDOW. */ 2738 /* ROOT must be an ancestor of WINDOW. */
2581 { 2739 {
2582 r = decode_any_window (root); 2740 r = decode_valid_window (root);
2583 pwindow = XWINDOW (window)->parent; 2741 pwindow = XWINDOW (window)->parent;
2584 while (!NILP (pwindow)) 2742 while (!NILP (pwindow))
2585 if (EQ (pwindow, root)) 2743 if (EQ (pwindow, root))
@@ -2610,7 +2768,7 @@ window-start value is reasonable when this function is called. */)
2610 if (EQ (selected_frame, w->frame)) 2768 if (EQ (selected_frame, w->frame))
2611 Fselect_window (window, Qnil); 2769 Fselect_window (window, Qnil);
2612 else 2770 else
2613 FRAME_SELECTED_WINDOW (f) = window; 2771 fset_selected_window (f, window);
2614 } 2772 }
2615 } 2773 }
2616 else 2774 else
@@ -2640,11 +2798,29 @@ window-start value is reasonable when this function is called. */)
2640 if (EQ (selected_frame, w->frame)) 2798 if (EQ (selected_frame, w->frame))
2641 Fselect_window (swindow, Qnil); 2799 Fselect_window (swindow, Qnil);
2642 else 2800 else
2643 FRAME_SELECTED_WINDOW (f) = swindow; 2801 fset_selected_window (f, swindow);
2644 } 2802 }
2645 } 2803 }
2646 2804
2647 BLOCK_INPUT; 2805 block_input ();
2806 if (!FRAME_INITIAL_P (f))
2807 {
2808 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
2809
2810 /* We are going to free the glyph matrices of WINDOW, and with
2811 that we might lose any information about glyph rows that have
2812 some of their glyphs highlighted in mouse face. (These rows
2813 are marked with a non-zero mouse_face_p flag.) If WINDOW
2814 indeed has some glyphs highlighted in mouse face, signal to
2815 frame's up-to-date hook that mouse highlight was overwritten,
2816 so that it will arrange for redisplaying the highlight. */
2817 if (EQ (hlinfo->mouse_face_window, window))
2818 {
2819 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
2820 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
2821 hlinfo->mouse_face_window = Qnil;
2822 }
2823 }
2648 free_window_matrices (r); 2824 free_window_matrices (r);
2649 2825
2650 windows_or_buffers_changed++; 2826 windows_or_buffers_changed++;
@@ -2655,8 +2831,9 @@ window-start value is reasonable when this function is called. */)
2655 if (NILP (w->buffer)) 2831 if (NILP (w->buffer))
2656 { 2832 {
2657 /* Resize child windows vertically. */ 2833 /* Resize child windows vertically. */
2658 XSETINT (delta, XINT (r->total_lines) - XINT (w->total_lines)); 2834 XSETINT (delta, XINT (r->total_lines)
2659 w->top_line = r->top_line; 2835 - XINT (w->total_lines));
2836 wset_top_line (w, r->top_line);
2660 resize_root_window (window, delta, Qnil, Qnil); 2837 resize_root_window (window, delta, Qnil, Qnil);
2661 if (window_resize_check (w, 0)) 2838 if (window_resize_check (w, 0))
2662 window_resize_apply (w, 0); 2839 window_resize_apply (w, 0);
@@ -2672,9 +2849,10 @@ window-start value is reasonable when this function is called. */)
2672 /* Resize child windows horizontally. */ 2849 /* Resize child windows horizontally. */
2673 if (!resize_failed) 2850 if (!resize_failed)
2674 { 2851 {
2675 w->left_col = r->left_col; 2852 wset_left_col (w, r->left_col);
2676 XSETINT (delta, XINT (r->total_cols) - XINT (w->total_cols)); 2853 XSETINT (delta,
2677 w->left_col = r->left_col; 2854 XINT (r->total_cols) - XINT (w->total_cols));
2855 wset_left_col (w, r->left_col);
2678 resize_root_window (window, delta, Qt, Qnil); 2856 resize_root_window (window, delta, Qt, Qnil);
2679 if (window_resize_check (w, 1)) 2857 if (window_resize_check (w, 1))
2680 window_resize_apply (w, 1); 2858 window_resize_apply (w, 1);
@@ -2702,32 +2880,32 @@ window-start value is reasonable when this function is called. */)
2702 { 2880 {
2703 sibling = w->prev; 2881 sibling = w->prev;
2704 s = XWINDOW (sibling); 2882 s = XWINDOW (sibling);
2705 s->next = w->next; 2883 wset_next (s, w->next);
2706 if (!NILP (s->next)) 2884 if (!NILP (s->next))
2707 XWINDOW (s->next)->prev = sibling; 2885 wset_prev (XWINDOW (s->next), sibling);
2708 } 2886 }
2709 else 2887 else
2710 /* Get SIBLING below (on the right of) WINDOW. */ 2888 /* Get SIBLING below (on the right of) WINDOW. */
2711 { 2889 {
2712 sibling = w->next; 2890 sibling = w->next;
2713 s = XWINDOW (sibling); 2891 s = XWINDOW (sibling);
2714 s->prev = Qnil; 2892 wset_prev (s, Qnil);
2715 if (!NILP (XWINDOW (w->parent)->vchild)) 2893 if (!NILP (XWINDOW (w->parent)->vchild))
2716 XWINDOW (w->parent)->vchild = sibling; 2894 wset_vchild (XWINDOW (w->parent), sibling);
2717 else 2895 else
2718 XWINDOW (w->parent)->hchild = sibling; 2896 wset_hchild (XWINDOW (w->parent), sibling);
2719 } 2897 }
2720 2898
2721 /* Delete ROOT and all child windows of ROOT. */ 2899 /* Delete ROOT and all child windows of ROOT. */
2722 if (!NILP (r->vchild)) 2900 if (!NILP (r->vchild))
2723 { 2901 {
2724 delete_all_child_windows (r->vchild); 2902 delete_all_child_windows (r->vchild);
2725 r->vchild = Qnil; 2903 wset_vchild (r, Qnil);
2726 } 2904 }
2727 else if (!NILP (r->hchild)) 2905 else if (!NILP (r->hchild))
2728 { 2906 {
2729 delete_all_child_windows (r->hchild); 2907 delete_all_child_windows (r->hchild);
2730 r->hchild = Qnil; 2908 wset_hchild (r, Qnil);
2731 } 2909 }
2732 2910
2733 replace_window (root, window, 1); 2911 replace_window (root, window, 1);
@@ -2754,20 +2932,19 @@ window-start value is reasonable when this function is called. */)
2754 pos = *vmotion (startpos, -top, w); 2932 pos = *vmotion (startpos, -top, w);
2755 2933
2756 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos); 2934 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2757 w->window_end_valid = Qnil; 2935 wset_window_end_valid (w, Qnil);
2758 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE 2936 w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
2759 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt 2937 || FETCH_BYTE (pos.bytepos - 1) == '\n');
2760 : Qnil);
2761 /* We need to do this, so that the window-scroll-functions 2938 /* We need to do this, so that the window-scroll-functions
2762 get called. */ 2939 get called. */
2763 w->optional_new_start = Qt; 2940 w->optional_new_start = 1;
2764 2941
2765 set_buffer_internal (obuf); 2942 set_buffer_internal (obuf);
2766 } 2943 }
2767 } 2944 }
2768 2945
2769 adjust_glyphs (f); 2946 adjust_glyphs (f);
2770 UNBLOCK_INPUT; 2947 unblock_input ();
2771 2948
2772 run_window_configuration_change_hook (f); 2949 run_window_configuration_change_hook (f);
2773 2950
@@ -2845,23 +3022,18 @@ adjust_window_margins (struct window *w)
2845 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0) 3022 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2846 { 3023 {
2847 if (WINDOW_LEFT_MARGIN_COLS (w) > 0) 3024 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2848 w->left_margin_cols = w->right_margin_cols 3025 {
2849 = make_number (margin_cols/2); 3026 wset_left_margin_cols (w, make_number (margin_cols / 2));
3027 wset_right_margin_cols (w, make_number (margin_cols / 2));
3028 }
2850 else 3029 else
2851 w->right_margin_cols = make_number (margin_cols); 3030 wset_right_margin_cols (w, make_number (margin_cols));
2852 } 3031 }
2853 else 3032 else
2854 w->left_margin_cols = make_number (margin_cols); 3033 wset_left_margin_cols (w, make_number (margin_cols));
2855 return 1; 3034 return 1;
2856} 3035}
2857 3036
2858static Lisp_Object Fset_window_margins (Lisp_Object, Lisp_Object, Lisp_Object);
2859static Lisp_Object Fset_window_fringes (Lisp_Object, Lisp_Object, Lisp_Object,
2860 Lisp_Object);
2861static Lisp_Object Fset_window_scroll_bars (Lisp_Object, Lisp_Object,
2862 Lisp_Object, Lisp_Object);
2863static Lisp_Object Fset_window_vscroll (Lisp_Object, Lisp_Object, Lisp_Object);
2864
2865/* The following three routines are needed for running a window's 3037/* The following three routines are needed for running a window's
2866 configuration change hook. */ 3038 configuration change hook. */
2867static void 3039static void
@@ -2889,18 +3061,18 @@ select_frame_norecord (Lisp_Object frame)
2889void 3061void
2890run_window_configuration_change_hook (struct frame *f) 3062run_window_configuration_change_hook (struct frame *f)
2891{ 3063{
2892 int count = SPECPDL_INDEX (); 3064 ptrdiff_t count = SPECPDL_INDEX ();
2893 Lisp_Object frame, global_wcch 3065 Lisp_Object frame, global_wcch
2894 = Fdefault_value (Qwindow_configuration_change_hook); 3066 = Fdefault_value (Qwindow_configuration_change_hook);
2895 XSETFRAME (frame, f); 3067 XSETFRAME (frame, f);
2896 3068
2897 if (NILP (Vrun_hooks)) 3069 if (NILP (Vrun_hooks) || !NILP (inhibit_lisp_code))
2898 return; 3070 return;
2899 3071
2900 /* Use the right buffer. Matters when running the local hooks. */ 3072 /* Use the right buffer. Matters when running the local hooks. */
2901 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) 3073 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
2902 { 3074 {
2903 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3075 record_unwind_current_buffer ();
2904 Fset_buffer (Fwindow_buffer (Qnil)); 3076 Fset_buffer (Fwindow_buffer (Qnil));
2905 } 3077 }
2906 3078
@@ -2920,7 +3092,7 @@ run_window_configuration_change_hook (struct frame *f)
2920 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook, 3092 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook,
2921 buffer))) 3093 buffer)))
2922 { 3094 {
2923 int inner_count = SPECPDL_INDEX (); 3095 ptrdiff_t inner_count = SPECPDL_INDEX ();
2924 record_unwind_protect (select_window_norecord, Fselected_window ()); 3096 record_unwind_protect (select_window_norecord, Fselected_window ());
2925 select_window_norecord (window); 3097 select_window_norecord (window);
2926 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, 3098 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
@@ -2935,12 +3107,12 @@ run_window_configuration_change_hook (struct frame *f)
2935} 3107}
2936 3108
2937DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook, 3109DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
2938 Srun_window_configuration_change_hook, 1, 1, 0, 3110 Srun_window_configuration_change_hook, 0, 1, 0,
2939 doc: /* Run `window-configuration-change-hook' for FRAME. */) 3111 doc: /* Run `window-configuration-change-hook' for FRAME.
2940 (Lisp_Object frame) 3112If FRAME is omitted or nil, it defaults to the selected frame. */)
3113 (Lisp_Object frame)
2941{ 3114{
2942 CHECK_LIVE_FRAME (frame); 3115 run_window_configuration_change_hook (decode_live_frame (frame));
2943 run_window_configuration_change_hook (XFRAME (frame));
2944 return Qnil; 3116 return Qnil;
2945} 3117}
2946 3118
@@ -2955,26 +3127,26 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
2955{ 3127{
2956 struct window *w = XWINDOW (window); 3128 struct window *w = XWINDOW (window);
2957 struct buffer *b = XBUFFER (buffer); 3129 struct buffer *b = XBUFFER (buffer);
2958 int count = SPECPDL_INDEX (); 3130 ptrdiff_t count = SPECPDL_INDEX ();
2959 int samebuf = EQ (buffer, w->buffer); 3131 int samebuf = EQ (buffer, w->buffer);
2960 3132
2961 w->buffer = buffer; 3133 wset_buffer (w, buffer);
2962 3134
2963 if (EQ (window, selected_window)) 3135 if (EQ (window, selected_window))
2964 BVAR (b, last_selected_window) = window; 3136 bset_last_selected_window (b, window);
2965 3137
2966 /* Let redisplay errors through. */ 3138 /* Let redisplay errors through. */
2967 b->display_error_modiff = 0; 3139 b->display_error_modiff = 0;
2968 3140
2969 /* Update time stamps of buffer display. */ 3141 /* Update time stamps of buffer display. */
2970 if (INTEGERP (BVAR (b, display_count))) 3142 if (INTEGERP (BVAR (b, display_count)))
2971 XSETINT (BVAR (b, display_count), XINT (BVAR (b, display_count)) + 1); 3143 bset_display_count (b, make_number (XINT (BVAR (b, display_count)) + 1));
2972 BVAR (b, display_time) = Fcurrent_time (); 3144 bset_display_time (b, Fcurrent_time ());
2973 3145
2974 XSETFASTINT (w->window_end_pos, 0); 3146 wset_window_end_pos (w, make_number (0));
2975 XSETFASTINT (w->window_end_vpos, 0); 3147 wset_window_end_vpos (w, make_number (0));
2976 memset (&w->last_cursor, 0, sizeof w->last_cursor); 3148 memset (&w->last_cursor, 0, sizeof w->last_cursor);
2977 w->window_end_valid = Qnil; 3149 wset_window_end_valid (w, Qnil);
2978 if (!(keep_margins_p && samebuf)) 3150 if (!(keep_margins_p && samebuf))
2979 { /* If we're not actually changing the buffer, don't reset hscroll and 3151 { /* If we're not actually changing the buffer, don't reset hscroll and
2980 vscroll. This case happens for example when called from 3152 vscroll. This case happens for example when called from
@@ -2984,16 +3156,16 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
2984 Resetting hscroll and vscroll here is problematic for things like 3156 Resetting hscroll and vscroll here is problematic for things like
2985 image-mode and doc-view-mode since it resets the image's position 3157 image-mode and doc-view-mode since it resets the image's position
2986 whenever we resize the frame. */ 3158 whenever we resize the frame. */
2987 w->hscroll = w->min_hscroll = make_number (0); 3159 w->hscroll = w->min_hscroll = 0;
2988 w->vscroll = 0; 3160 w->vscroll = 0;
2989 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b)); 3161 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
2990 set_marker_restricted (w->start, 3162 set_marker_restricted (w->start,
2991 make_number (b->last_window_start), 3163 make_number (b->last_window_start),
2992 buffer); 3164 buffer);
2993 w->start_at_line_beg = Qnil; 3165 w->start_at_line_beg = 0;
2994 w->force_start = Qnil; 3166 w->force_start = 0;
2995 XSETFASTINT (w->last_modified, 0); 3167 w->last_modified = 0;
2996 XSETFASTINT (w->last_overlay_modified, 0); 3168 w->last_overlay_modified = 0;
2997 } 3169 }
2998 /* Maybe we could move this into the `if' but it's not obviously safe and 3170 /* Maybe we could move this into the `if' but it's not obviously safe and
2999 I doubt it's worth the trouble. */ 3171 I doubt it's worth the trouble. */
@@ -3004,7 +3176,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3004 because that might itself be a local variable. */ 3176 because that might itself be a local variable. */
3005 if (window_initialized) 3177 if (window_initialized)
3006 { 3178 {
3007 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3179 record_unwind_current_buffer ();
3008 Fset_buffer (buffer); 3180 Fset_buffer (buffer);
3009 } 3181 }
3010 3182
@@ -3019,7 +3191,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3019 Lisp_Object save_left = w->left_margin_cols; 3191 Lisp_Object save_left = w->left_margin_cols;
3020 Lisp_Object save_right = w->right_margin_cols; 3192 Lisp_Object save_right = w->right_margin_cols;
3021 3193
3022 w->left_margin_cols = w->right_margin_cols = Qnil; 3194 wset_left_margin_cols (w, Qnil);
3195 wset_right_margin_cols (w, Qnil);
3023 3196
3024 Fset_window_fringes (window, 3197 Fset_window_fringes (window,
3025 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width), 3198 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width),
@@ -3029,8 +3202,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3029 BVAR (b, scroll_bar_width), 3202 BVAR (b, scroll_bar_width),
3030 BVAR (b, vertical_scroll_bar_type), Qnil); 3203 BVAR (b, vertical_scroll_bar_type), Qnil);
3031 3204
3032 w->left_margin_cols = save_left; 3205 wset_left_margin_cols (w, save_left);
3033 w->right_margin_cols = save_right; 3206 wset_right_margin_cols (w, save_right);
3034 3207
3035 Fset_window_margins (window, 3208 Fset_window_margins (window,
3036 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols)); 3209 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols));
@@ -3049,7 +3222,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3049 3222
3050DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0, 3223DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
3051 doc: /* Make WINDOW display BUFFER-OR-NAME as its contents. 3224 doc: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3052WINDOW has to be a live window and defaults to the selected one. 3225WINDOW must be a live window and defaults to the selected one.
3053BUFFER-OR-NAME must be a buffer or the name of an existing buffer. 3226BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3054 3227
3055Optional third argument KEEP-MARGINS non-nil means that WINDOW's current 3228Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
@@ -3066,12 +3239,12 @@ This function runs `window-scroll-functions' before running
3066 (register Lisp_Object window, Lisp_Object buffer_or_name, Lisp_Object keep_margins) 3239 (register Lisp_Object window, Lisp_Object buffer_or_name, Lisp_Object keep_margins)
3067{ 3240{
3068 register Lisp_Object tem, buffer; 3241 register Lisp_Object tem, buffer;
3069 register struct window *w = decode_window (window); 3242 register struct window *w = decode_live_window (window);
3070 3243
3071 XSETWINDOW (window, w); 3244 XSETWINDOW (window, w);
3072 buffer = Fget_buffer (buffer_or_name); 3245 buffer = Fget_buffer (buffer_or_name);
3073 CHECK_BUFFER (buffer); 3246 CHECK_BUFFER (buffer);
3074 if (NILP (BVAR (XBUFFER (buffer), name))) 3247 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
3075 error ("Attempt to display deleted buffer"); 3248 error ("Attempt to display deleted buffer");
3076 3249
3077 tem = w->buffer; 3250 tem = w->buffer;
@@ -3089,7 +3262,7 @@ This function runs `window-scroll-functions' before running
3089 else 3262 else
3090 /* WINDOW is weakly dedicated to its buffer, reset 3263 /* WINDOW is weakly dedicated to its buffer, reset
3091 dedication. */ 3264 dedication. */
3092 w->dedicated = Qnil; 3265 wset_dedicated (w, Qnil);
3093 3266
3094 call1 (Qrecord_window_buffer, window); 3267 call1 (Qrecord_window_buffer, window);
3095 } 3268 }
@@ -3127,7 +3300,7 @@ displaying that buffer. */)
3127 { 3300 {
3128 struct window *w = XWINDOW (object); 3301 struct window *w = XWINDOW (object);
3129 mark_window_display_accurate (object, 0); 3302 mark_window_display_accurate (object, 0);
3130 w->update_mode_line = Qt; 3303 w->update_mode_line = 1;
3131 if (BUFFERP (w->buffer)) 3304 if (BUFFERP (w->buffer))
3132 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; 3305 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3133 ++update_mode_lines; 3306 ++update_mode_lines;
@@ -3136,7 +3309,7 @@ displaying that buffer. */)
3136 3309
3137 if (STRINGP (object)) 3310 if (STRINGP (object))
3138 object = Fget_buffer (object); 3311 object = Fget_buffer (object);
3139 if (BUFFERP (object) && !NILP (BVAR (XBUFFER (object), name))) 3312 if (BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object)))
3140 { 3313 {
3141 /* Walk all windows looking for buffer, and force update 3314 /* Walk all windows looking for buffer, and force update
3142 of each of those windows. */ 3315 of each of those windows. */
@@ -3151,7 +3324,7 @@ displaying that buffer. */)
3151 return Qnil; 3324 return Qnil;
3152} 3325}
3153 3326
3154 3327/* Obsolete since 24.3. */
3155void 3328void
3156temp_output_buffer_show (register Lisp_Object buf) 3329temp_output_buffer_show (register Lisp_Object buf)
3157{ 3330{
@@ -3159,7 +3332,7 @@ temp_output_buffer_show (register Lisp_Object buf)
3159 register Lisp_Object window; 3332 register Lisp_Object window;
3160 register struct window *w; 3333 register struct window *w;
3161 3334
3162 BVAR (XBUFFER (buf), directory) = BVAR (current_buffer, directory); 3335 bset_directory (XBUFFER (buf), BVAR (current_buffer, directory));
3163 3336
3164 Fset_buffer (buf); 3337 Fset_buffer (buf);
3165 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF; 3338 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
@@ -3178,15 +3351,15 @@ temp_output_buffer_show (register Lisp_Object buf)
3178 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window))); 3351 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3179 Vminibuf_scroll_window = window; 3352 Vminibuf_scroll_window = window;
3180 w = XWINDOW (window); 3353 w = XWINDOW (window);
3181 XSETFASTINT (w->hscroll, 0); 3354 w->hscroll = 0;
3182 XSETFASTINT (w->min_hscroll, 0); 3355 w->min_hscroll = 0;
3183 set_marker_restricted_both (w->start, buf, BEG, BEG); 3356 set_marker_restricted_both (w->start, buf, BEG, BEG);
3184 set_marker_restricted_both (w->pointm, buf, BEG, BEG); 3357 set_marker_restricted_both (w->pointm, buf, BEG, BEG);
3185 3358
3186 /* Run temp-buffer-show-hook, with the chosen window selected 3359 /* Run temp-buffer-show-hook, with the chosen window selected
3187 and its buffer current. */ 3360 and its buffer current. */
3188 { 3361 {
3189 int count = SPECPDL_INDEX (); 3362 ptrdiff_t count = SPECPDL_INDEX ();
3190 Lisp_Object prev_window, prev_buffer; 3363 Lisp_Object prev_window, prev_buffer;
3191 prev_window = selected_window; 3364 prev_window = selected_window;
3192 XSETBUFFER (prev_buffer, old); 3365 XSETBUFFER (prev_buffer, old);
@@ -3204,16 +3377,6 @@ temp_output_buffer_show (register Lisp_Object buf)
3204 } 3377 }
3205 } 3378 }
3206} 3379}
3207
3208DEFUN ("internal-temp-output-buffer-show",
3209 Ftemp_output_buffer_show, Stemp_output_buffer_show,
3210 1, 1, 0,
3211 doc: /* Internal function for `with-output-to-temp-buffer'. */)
3212 (Lisp_Object buf)
3213{
3214 temp_output_buffer_show (buf);
3215 return Qnil;
3216}
3217 3380
3218/* Make new window, have it replace WINDOW in window-tree, and make 3381/* Make new window, have it replace WINDOW in window-tree, and make
3219 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only 3382 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
@@ -3223,31 +3386,29 @@ make_parent_window (Lisp_Object window, int horflag)
3223{ 3386{
3224 Lisp_Object parent; 3387 Lisp_Object parent;
3225 register struct window *o, *p; 3388 register struct window *o, *p;
3226 int i;
3227 3389
3228 o = XWINDOW (window); 3390 o = XWINDOW (window);
3229 p = allocate_window (); 3391 p = allocate_window ();
3230 for (i = 0; i < VECSIZE (struct window); ++i) 3392 memcpy ((char *) p + sizeof (struct vectorlike_header),
3231 ((struct Lisp_Vector *) p)->contents[i] 3393 (char *) o + sizeof (struct vectorlike_header),
3232 = ((struct Lisp_Vector *) o)->contents[i]; 3394 word_size * VECSIZE (struct window));
3233 XSETWINDOW (parent, p); 3395 XSETWINDOW (parent, p);
3234 3396
3235 ++sequence_number; 3397 p->sequence_number = ++sequence_number;
3236 XSETFASTINT (p->sequence_number, sequence_number);
3237 3398
3238 replace_window (window, parent, 1); 3399 replace_window (window, parent, 1);
3239 3400
3240 o->next = Qnil; 3401 wset_next (o, Qnil);
3241 o->prev = Qnil; 3402 wset_prev (o, Qnil);
3242 o->parent = parent; 3403 wset_parent (o, parent);
3243 3404
3244 p->hchild = horflag ? window : Qnil; 3405 wset_hchild (p, horflag ? window : Qnil);
3245 p->vchild = horflag ? Qnil : window; 3406 wset_vchild (p, horflag ? Qnil : window);
3246 p->start = Qnil; 3407 wset_start (p, Qnil);
3247 p->pointm = Qnil; 3408 wset_pointm (p, Qnil);
3248 p->buffer = Qnil; 3409 wset_buffer (p, Qnil);
3249 p->combination_limit = Qnil; 3410 wset_combination_limit (p, Qnil);
3250 p->window_parameters = Qnil; 3411 wset_window_parameters (p, Qnil);
3251} 3412}
3252 3413
3253/* Make new window from scratch. */ 3414/* Make new window from scratch. */
@@ -3258,57 +3419,33 @@ make_window (void)
3258 register struct window *w; 3419 register struct window *w;
3259 3420
3260 w = allocate_window (); 3421 w = allocate_window ();
3261 /* Initialize all Lisp data. */ 3422 /* Initialize Lisp data. Note that allocate_window initializes all
3262 w->frame = w->mini_p = Qnil; 3423 Lisp data to nil, so do it only for slots which should not be nil. */
3263 w->next = w->prev = w->hchild = w->vchild = w->parent = Qnil; 3424 wset_left_col (w, make_number (0));
3264 XSETFASTINT (w->left_col, 0); 3425 wset_top_line (w, make_number (0));
3265 XSETFASTINT (w->top_line, 0); 3426 wset_total_lines (w, make_number (0));
3266 XSETFASTINT (w->total_lines, 0); 3427 wset_total_cols (w, make_number (0));
3267 XSETFASTINT (w->total_cols, 0); 3428 wset_normal_lines (w, make_float (1.0));
3268 w->normal_lines = make_float (1.0); 3429 wset_normal_cols (w, make_float (1.0));
3269 w->normal_cols = make_float (1.0); 3430 wset_new_total (w, make_number (0));
3270 XSETFASTINT (w->new_total, 0); 3431 wset_new_normal (w, make_number (0));
3271 XSETFASTINT (w->new_normal, 0); 3432 wset_start (w, Fmake_marker ());
3272 w->buffer = Qnil; 3433 wset_pointm (w, Fmake_marker ());
3273 w->start = Fmake_marker (); 3434 wset_vertical_scroll_bar_type (w, Qt);
3274 w->pointm = Fmake_marker (); 3435 wset_window_end_pos (w, make_number (0));
3275 w->force_start = w->optional_new_start = Qnil; 3436 wset_window_end_vpos (w, make_number (0));
3276 XSETFASTINT (w->hscroll, 0); 3437 /* These Lisp fields are marked specially so they're not set to nil by
3277 XSETFASTINT (w->min_hscroll, 0); 3438 allocate_window. */
3278 XSETFASTINT (w->use_time, 0); 3439 wset_prev_buffers (w, Qnil);
3279 ++sequence_number; 3440 wset_next_buffers (w, Qnil);
3280 XSETFASTINT (w->sequence_number, sequence_number); 3441
3281 w->temslot = w->last_modified = w->last_overlay_modified = Qnil; 3442 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3282 XSETFASTINT (w->last_point, 0); 3443 non-Lisp data, so do it only for slots which should not be zero. */
3283 w->last_had_star = w->vertical_scroll_bar = Qnil;
3284 w->left_margin_cols = w->right_margin_cols = Qnil;
3285 w->left_fringe_width = w->right_fringe_width = Qnil;
3286 w->fringes_outside_margins = Qnil;
3287 w->scroll_bar_width = Qnil;
3288 w->vertical_scroll_bar_type = Qt;
3289 w->last_mark_x = w->last_mark_y = Qnil;
3290 XSETFASTINT (w->window_end_pos, 0);
3291 XSETFASTINT (w->window_end_vpos, 0);
3292 w->window_end_valid = w->update_mode_line = Qnil;
3293 w->start_at_line_beg = w->display_table = w->dedicated = Qnil;
3294 w->base_line_number = w->base_line_pos = w->region_showing = Qnil;
3295 w->column_number_displayed = w->redisplay_end_trigger = Qnil;
3296 w->combination_limit = w->window_parameters = Qnil;
3297 w->prev_buffers = w->next_buffers = Qnil;
3298 /* Initialize non-Lisp data. */
3299 w->desired_matrix = w->current_matrix = 0;
3300 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3444 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3301 memset (&w->cursor, 0, sizeof (w->cursor));
3302 memset (&w->last_cursor, 0, sizeof (w->last_cursor));
3303 memset (&w->phys_cursor, 0, sizeof (w->phys_cursor));
3304 w->phys_cursor_type = -1; 3445 w->phys_cursor_type = -1;
3305 w->phys_cursor_width = -1; 3446 w->phys_cursor_width = -1;
3306 w->phys_cursor_on_p = 0; 3447 w->sequence_number = ++sequence_number;
3307 w->last_cursor_off_p = w->cursor_off_p = 0; 3448
3308 w->must_be_updated_p = 0;
3309 w->pseudo_window_p = 0;
3310 w->frozen_window_start_p = 0;
3311 w->vscroll = 0;
3312 /* Reset window_list. */ 3449 /* Reset window_list. */
3313 Vwindow_list = Qnil; 3450 Vwindow_list = Qnil;
3314 /* Return window. */ 3451 /* Return window. */
@@ -3318,6 +3455,7 @@ make_window (void)
3318 3455
3319DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0, 3456DEFUN ("set-window-new-total", Fset_window_new_total, Sset_window_new_total, 2, 3, 0,
3320 doc: /* Set new total size of WINDOW to SIZE. 3457 doc: /* Set new total size of WINDOW to SIZE.
3458WINDOW must be a valid window and defaults to the selected one.
3321Return SIZE. 3459Return SIZE.
3322 3460
3323Optional argument ADD non-nil means add SIZE to the new total size of 3461Optional argument ADD non-nil means add SIZE to the new total size of
@@ -3326,28 +3464,27 @@ WINDOW and return the sum.
3326Note: This function does not operate on any child windows of WINDOW. */) 3464Note: This function does not operate on any child windows of WINDOW. */)
3327 (Lisp_Object window, Lisp_Object size, Lisp_Object add) 3465 (Lisp_Object window, Lisp_Object size, Lisp_Object add)
3328{ 3466{
3329 struct window *w = decode_any_window (window); 3467 struct window *w = decode_valid_window (window);
3330 3468
3331 CHECK_NUMBER (size); 3469 CHECK_NUMBER (size);
3332 if (NILP (add)) 3470 if (NILP (add))
3333 XSETINT (w->new_total, XINT (size)); 3471 wset_new_total (w, size);
3334 else 3472 else
3335 XSETINT (w->new_total, XINT (w->new_total) + XINT (size)); 3473 wset_new_total (w, make_number (XINT (w->new_total) + XINT (size)));
3336 3474
3337 return w->new_total; 3475 return w->new_total;
3338} 3476}
3339 3477
3340DEFUN ("set-window-new-normal", Fset_window_new_normal, Sset_window_new_normal, 1, 2, 0, 3478DEFUN ("set-window-new-normal", Fset_window_new_normal, Sset_window_new_normal, 1, 2, 0,
3341 doc: /* Set new normal size of WINDOW to SIZE. 3479 doc: /* Set new normal size of WINDOW to SIZE.
3480WINDOW must be a valid window and defaults to the selected one.
3342Return SIZE. 3481Return SIZE.
3343 3482
3344Note: This function does not operate on any child windows of WINDOW. */) 3483Note: This function does not operate on any child windows of WINDOW. */)
3345 (Lisp_Object window, Lisp_Object size) 3484 (Lisp_Object window, Lisp_Object size)
3346{ 3485{
3347 struct window *w = decode_any_window (window); 3486 wset_new_normal (decode_valid_window (window), size);
3348 3487 return size;
3349 w->new_normal = size;
3350 return w->new_normal;
3351} 3488}
3352 3489
3353/* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is 3490/* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
@@ -3448,17 +3585,17 @@ window_resize_apply (struct window *w, int horflag)
3448 parent window has been set *before*. */ 3585 parent window has been set *before*. */
3449 if (horflag) 3586 if (horflag)
3450 { 3587 {
3451 w->total_cols = w->new_total; 3588 wset_total_cols (w, w->new_total);
3452 if (NUMBERP (w->new_normal)) 3589 if (NUMBERP (w->new_normal))
3453 w->normal_cols = w->new_normal; 3590 wset_normal_cols (w, w->new_normal);
3454 3591
3455 pos = XINT (w->left_col); 3592 pos = XINT (w->left_col);
3456 } 3593 }
3457 else 3594 else
3458 { 3595 {
3459 w->total_lines = w->new_total; 3596 wset_total_lines (w, w->new_total);
3460 if (NUMBERP (w->new_normal)) 3597 if (NUMBERP (w->new_normal))
3461 w->normal_lines = w->new_normal; 3598 wset_normal_lines (w, w->new_normal);
3462 3599
3463 pos = XINT (w->top_line); 3600 pos = XINT (w->top_line);
3464 } 3601 }
@@ -3470,9 +3607,9 @@ window_resize_apply (struct window *w, int horflag)
3470 while (c) 3607 while (c)
3471 { 3608 {
3472 if (horflag) 3609 if (horflag)
3473 XSETFASTINT (c->left_col, pos); 3610 wset_left_col (c, make_number (pos));
3474 else 3611 else
3475 XSETFASTINT (c->top_line, pos); 3612 wset_top_line (c, make_number (pos));
3476 window_resize_apply (c, horflag); 3613 window_resize_apply (c, horflag);
3477 if (!horflag) 3614 if (!horflag)
3478 pos = pos + XINT (c->total_lines); 3615 pos = pos + XINT (c->total_lines);
@@ -3486,9 +3623,9 @@ window_resize_apply (struct window *w, int horflag)
3486 while (c) 3623 while (c)
3487 { 3624 {
3488 if (horflag) 3625 if (horflag)
3489 XSETFASTINT (c->left_col, pos); 3626 wset_left_col (c, make_number (pos));
3490 else 3627 else
3491 XSETFASTINT (c->top_line, pos); 3628 wset_top_line (c, make_number (pos));
3492 window_resize_apply (c, horflag); 3629 window_resize_apply (c, horflag);
3493 if (horflag) 3630 if (horflag)
3494 pos = pos + XINT (c->total_cols); 3631 pos = pos + XINT (c->total_cols);
@@ -3497,15 +3634,17 @@ window_resize_apply (struct window *w, int horflag)
3497 } 3634 }
3498 3635
3499 /* Clear out some redisplay caches. */ 3636 /* Clear out some redisplay caches. */
3500 XSETFASTINT (w->last_modified, 0); 3637 w->last_modified = 0;
3501 XSETFASTINT (w->last_overlay_modified, 0); 3638 w->last_overlay_modified = 0;
3502} 3639}
3503 3640
3504 3641
3505DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 1, 2, 0, 3642DEFUN ("window-resize-apply", Fwindow_resize_apply, Swindow_resize_apply, 0, 2, 0,
3506 doc: /* Apply requested size values for window-tree of FRAME. 3643 doc: /* Apply requested size values for window-tree of FRAME.
3507Optional argument HORIZONTAL omitted or nil means apply requested height 3644If FRAME is omitted or nil, it defaults to the selected frame.
3508values. HORIZONTAL non-nil means apply requested width values. 3645
3646Optional argument HORIZONTAL omitted or nil means apply requested
3647height values. HORIZONTAL non-nil means apply requested width values.
3509 3648
3510This function checks whether the requested values sum up to a valid 3649This function checks whether the requested values sum up to a valid
3511window layout, recursively assigns the new sizes of all child windows 3650window layout, recursively assigns the new sizes of all child windows
@@ -3516,29 +3655,23 @@ Note: This function does not check any of `window-fixed-size-p',
3516be applied on the Elisp level. */) 3655be applied on the Elisp level. */)
3517 (Lisp_Object frame, Lisp_Object horizontal) 3656 (Lisp_Object frame, Lisp_Object horizontal)
3518{ 3657{
3519 struct frame *f; 3658 struct frame *f = decode_live_frame (frame);
3520 struct window *r; 3659 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
3521 int horflag = !NILP (horizontal); 3660 int horflag = !NILP (horizontal);
3522 3661
3523 if (NILP (frame))
3524 frame = selected_frame;
3525 CHECK_LIVE_FRAME (frame);
3526
3527 f = XFRAME (frame);
3528 r = XWINDOW (FRAME_ROOT_WINDOW (f));
3529
3530 if (!window_resize_check (r, horflag) 3662 if (!window_resize_check (r, horflag)
3531 || ! EQ (r->new_total, (horflag ? r->total_cols : r->total_lines))) 3663 || ! EQ (r->new_total,
3664 (horflag ? r->total_cols : r->total_lines)))
3532 return Qnil; 3665 return Qnil;
3533 3666
3534 BLOCK_INPUT; 3667 block_input ();
3535 window_resize_apply (r, horflag); 3668 window_resize_apply (r, horflag);
3536 3669
3537 windows_or_buffers_changed++; 3670 windows_or_buffers_changed++;
3538 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 3671 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3539 3672
3540 adjust_glyphs (f); 3673 adjust_glyphs (f);
3541 UNBLOCK_INPUT; 3674 unblock_input ();
3542 3675
3543 run_window_configuration_change_hook (f); 3676 run_window_configuration_change_hook (f);
3544 3677
@@ -3568,23 +3701,25 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3568 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f)) 3701 - ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
3569 ? 1 : 0))); 3702 ? 1 : 0)));
3570 3703
3571 XSETFASTINT (r->top_line, FRAME_TOP_MARGIN (f)); 3704 wset_top_line (r, make_number (FRAME_TOP_MARGIN (f)));
3572 if (NILP (r->vchild) && NILP (r->hchild)) 3705 if (NILP (r->vchild) && NILP (r->hchild))
3573 /* For a leaf root window just set the size. */ 3706 /* For a leaf root window just set the size. */
3574 if (horflag) 3707 if (horflag)
3575 XSETFASTINT (r->total_cols, new_size); 3708 wset_total_cols (r, make_number (new_size));
3576 else 3709 else
3577 XSETFASTINT (r->total_lines, new_size); 3710 wset_total_lines (r, make_number (new_size));
3578 else 3711 else
3579 { 3712 {
3580 /* old_size is the old size of the frame's root window. */ 3713 /* old_size is the old size of the frame's root window. */
3581 int old_size = XFASTINT (horflag ? r->total_cols : r->total_lines); 3714 int old_size = XFASTINT (horflag ? r->total_cols
3715 : r->total_lines);
3582 Lisp_Object delta; 3716 Lisp_Object delta;
3583 3717
3584 XSETINT (delta, new_size - old_size); 3718 XSETINT (delta, new_size - old_size);
3585 /* Try a "normal" resize first. */ 3719 /* Try a "normal" resize first. */
3586 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil); 3720 resize_root_window (root, delta, horflag ? Qt : Qnil, Qnil);
3587 if (window_resize_check (r, horflag) && new_size == XINT (r->new_total)) 3721 if (window_resize_check (r, horflag)
3722 && new_size == XINT (r->new_total))
3588 window_resize_apply (r, horflag); 3723 window_resize_apply (r, horflag);
3589 else 3724 else
3590 { 3725 {
@@ -3607,9 +3742,9 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3607 root = f->selected_window; 3742 root = f->selected_window;
3608 Fdelete_other_windows_internal (root, Qnil); 3743 Fdelete_other_windows_internal (root, Qnil);
3609 if (horflag) 3744 if (horflag)
3610 XSETFASTINT (XWINDOW (root)->total_cols, new_size); 3745 wset_total_cols (XWINDOW (root), make_number (new_size));
3611 else 3746 else
3612 XSETFASTINT (XWINDOW (root)->total_lines, new_size); 3747 wset_total_lines (XWINDOW (root), make_number (new_size));
3613 } 3748 }
3614 } 3749 }
3615 } 3750 }
@@ -3619,14 +3754,17 @@ resize_frame_windows (struct frame *f, int size, int horflag)
3619 { 3754 {
3620 m = XWINDOW (mini); 3755 m = XWINDOW (mini);
3621 if (horflag) 3756 if (horflag)
3622 XSETFASTINT (m->total_cols, size); 3757 wset_total_cols (m, make_number (size));
3623 else 3758 else
3624 { 3759 {
3625 /* Are we sure we always want 1 line here? */ 3760 /* Are we sure we always want 1 line here? */
3626 XSETFASTINT (m->total_lines, 1); 3761 wset_total_lines (m, make_number (1));
3627 XSETFASTINT (m->top_line, XINT (r->top_line) + XINT (r->total_lines)); 3762 wset_top_line
3763 (m, make_number (XINT (r->top_line) + XINT (r->total_lines)));
3628 } 3764 }
3629 } 3765 }
3766
3767 windows_or_buffers_changed++;
3630} 3768}
3631 3769
3632 3770
@@ -3679,7 +3817,7 @@ set correctly. See the code of `split-window' for how this is done. */)
3679 We do that if either `window-combination-limit' is t, or OLD has no 3817 We do that if either `window-combination-limit' is t, or OLD has no
3680 parent, or OLD is ortho-combined. */ 3818 parent, or OLD is ortho-combined. */
3681 combination_limit = 3819 combination_limit =
3682 !NILP (Vwindow_combination_limit) 3820 EQ (Vwindow_combination_limit, Qt)
3683 || NILP (o->parent) 3821 || NILP (o->parent)
3684 || NILP (horflag 3822 || NILP (horflag
3685 ? (XWINDOW (o->parent)->hchild) 3823 ? (XWINDOW (o->parent)->hchild)
@@ -3705,14 +3843,14 @@ set correctly. See the code of `split-window' for how this is done. */)
3705 { 3843 {
3706 p = XWINDOW (o->parent); 3844 p = XWINDOW (o->parent);
3707 /* Temporarily pretend we split the parent window. */ 3845 /* Temporarily pretend we split the parent window. */
3708 XSETINT (p->new_total, 3846 wset_new_total
3709 XINT (horflag ? p->total_cols : p->total_lines) 3847 (p, make_number (XINT (horflag ? p->total_cols : p->total_lines)
3710 - XINT (total_size)); 3848 - XINT (total_size)));
3711 if (!window_resize_check (p, horflag)) 3849 if (!window_resize_check (p, horflag))
3712 error ("Window sizes don't fit"); 3850 error ("Window sizes don't fit");
3713 else 3851 else
3714 /* Undo the temporary pretension. */ 3852 /* Undo the temporary pretension. */
3715 p->new_total = horflag ? p->total_cols : p->total_lines; 3853 wset_new_total (p, horflag ? p->total_cols : p->total_lines);
3716 } 3854 }
3717 else 3855 else
3718 { 3856 {
@@ -3729,16 +3867,18 @@ set correctly. See the code of `split-window' for how this is done. */)
3729 /* Save the old value of o->normal_cols/lines. It gets corrupted 3867 /* Save the old value of o->normal_cols/lines. It gets corrupted
3730 by make_parent_window and we need it below for assigning it to 3868 by make_parent_window and we need it below for assigning it to
3731 p->new_normal. */ 3869 p->new_normal. */
3732 Lisp_Object new_normal = horflag ? o->normal_cols : o->normal_lines; 3870 Lisp_Object new_normal
3871 = horflag ? o->normal_cols : o->normal_lines;
3733 3872
3734 make_parent_window (old, horflag); 3873 make_parent_window (old, horflag);
3735 p = XWINDOW (o->parent); 3874 p = XWINDOW (o->parent);
3736 /* Store value of `window-combination-limit' in new parent's 3875 if (EQ (Vwindow_combination_limit, Qt))
3737 combination_limit slot. */ 3876 /* Store t in the new parent's combination_limit slot to avoid
3738 p->combination_limit = Vwindow_combination_limit; 3877 that its children get merged into another window. */
3878 wset_combination_limit (p, Qt);
3739 /* These get applied below. */ 3879 /* These get applied below. */
3740 p->new_total = horflag ? o->total_cols : o->total_lines; 3880 wset_new_total (p, horflag ? o->total_cols : o->total_lines);
3741 p->new_normal = new_normal; 3881 wset_new_normal (p, new_normal);
3742 } 3882 }
3743 else 3883 else
3744 p = XWINDOW (o->parent); 3884 p = XWINDOW (o->parent);
@@ -3747,69 +3887,70 @@ set correctly. See the code of `split-window' for how this is done. */)
3747 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 3887 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3748 new = make_window (); 3888 new = make_window ();
3749 n = XWINDOW (new); 3889 n = XWINDOW (new);
3750 n->frame = frame; 3890 wset_frame (n, frame);
3751 n->parent = o->parent; 3891 wset_parent (n, o->parent);
3752 n->vchild = n->hchild = Qnil; 3892 wset_vchild (n, Qnil);
3893 wset_hchild (n, Qnil);
3753 3894
3754 if (EQ (side, Qabove) || EQ (side, Qleft)) 3895 if (EQ (side, Qabove) || EQ (side, Qleft))
3755 { 3896 {
3756 n->prev = o->prev; 3897 wset_prev (n, o->prev);
3757 if (NILP (n->prev)) 3898 if (NILP (n->prev))
3758 if (horflag) 3899 if (horflag)
3759 p->hchild = new; 3900 wset_hchild (p, new);
3760 else 3901 else
3761 p->vchild = new; 3902 wset_vchild (p, new);
3762 else 3903 else
3763 XWINDOW (n->prev)->next = new; 3904 wset_next (XWINDOW (n->prev), new);
3764 n->next = old; 3905 wset_next (n, old);
3765 o->prev = new; 3906 wset_prev (o, new);
3766 } 3907 }
3767 else 3908 else
3768 { 3909 {
3769 n->next = o->next; 3910 wset_next (n, o->next);
3770 if (!NILP (n->next)) 3911 if (!NILP (n->next))
3771 XWINDOW (n->next)->prev = new; 3912 wset_prev (XWINDOW (n->next), new);
3772 n->prev = old; 3913 wset_prev (n, old);
3773 o->next = new; 3914 wset_next (o, new);
3774 } 3915 }
3775 3916
3776 n->buffer = Qt; 3917 wset_buffer (n, Qt);
3777 n->window_end_valid = Qnil; 3918 wset_window_end_valid (n, Qnil);
3778 memset (&n->last_cursor, 0, sizeof n->last_cursor); 3919 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3779 3920
3780 /* Get special geometry settings from reference window. */ 3921 /* Get special geometry settings from reference window. */
3781 n->left_margin_cols = r->left_margin_cols; 3922 wset_left_margin_cols (n, r->left_margin_cols);
3782 n->right_margin_cols = r->right_margin_cols; 3923 wset_right_margin_cols (n, r->right_margin_cols);
3783 n->left_fringe_width = r->left_fringe_width; 3924 wset_left_fringe_width (n, r->left_fringe_width);
3784 n->right_fringe_width = r->right_fringe_width; 3925 wset_right_fringe_width (n, r->right_fringe_width);
3785 n->fringes_outside_margins = r->fringes_outside_margins; 3926 n->fringes_outside_margins = r->fringes_outside_margins;
3786 n->scroll_bar_width = r->scroll_bar_width; 3927 wset_scroll_bar_width (n, r->scroll_bar_width);
3787 n->vertical_scroll_bar_type = r->vertical_scroll_bar_type; 3928 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type);
3788 3929
3789 /* Directly assign orthogonal coordinates and sizes. */ 3930 /* Directly assign orthogonal coordinates and sizes. */
3790 if (horflag) 3931 if (horflag)
3791 { 3932 {
3792 n->top_line = o->top_line; 3933 wset_top_line (n, o->top_line);
3793 n->total_lines = o->total_lines; 3934 wset_total_lines (n, o->total_lines);
3794 } 3935 }
3795 else 3936 else
3796 { 3937 {
3797 n->left_col = o->left_col; 3938 wset_left_col (n, o->left_col);
3798 n->total_cols = o->total_cols; 3939 wset_total_cols (n, o->total_cols);
3799 } 3940 }
3800 3941
3801 /* Iso-coordinates and sizes are assigned by window_resize_apply, 3942 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3802 get them ready here. */ 3943 get them ready here. */
3803 n->new_total = total_size; 3944 wset_new_total (n, total_size);
3804 n->new_normal = normal_size; 3945 wset_new_normal (n, normal_size);
3805 3946
3806 BLOCK_INPUT; 3947 block_input ();
3807 window_resize_apply (p, horflag); 3948 window_resize_apply (p, horflag);
3808 adjust_glyphs (f); 3949 adjust_glyphs (f);
3809 /* Set buffer of NEW to buffer of reference window. Don't run 3950 /* Set buffer of NEW to buffer of reference window. Don't run
3810 any hooks. */ 3951 any hooks. */
3811 set_window_buffer (new, r->buffer, 0, 1); 3952 set_window_buffer (new, r->buffer, 0, 1);
3812 UNBLOCK_INPUT; 3953 unblock_input ();
3813 3954
3814 /* Maybe we should run the scroll functions in Elisp (which already 3955 /* Maybe we should run the scroll functions in Elisp (which already
3815 runs the configuration change hook). */ 3956 runs the configuration change hook). */
@@ -3835,7 +3976,8 @@ Signal an error when WINDOW is the only window on its frame. */)
3835 3976
3836 w = decode_any_window (window); 3977 w = decode_any_window (window);
3837 XSETWINDOW (window, w); 3978 XSETWINDOW (window, w);
3838 if (NILP (w->buffer) && NILP (w->hchild) && NILP (w->vchild)) 3979 if (NILP (w->buffer)
3980 && NILP (w->hchild) && NILP (w->vchild))
3839 /* It's a no-op to delete an already deleted window. */ 3981 /* It's a no-op to delete an already deleted window. */
3840 return Qnil; 3982 return Qnil;
3841 3983
@@ -3866,53 +4008,65 @@ Signal an error when WINDOW is the only window on its frame. */)
3866 before_sibling = 1; 4008 before_sibling = 1;
3867 sibling = w->next; 4009 sibling = w->next;
3868 s = XWINDOW (sibling); 4010 s = XWINDOW (sibling);
3869 s->prev = Qnil; 4011 wset_prev (s, Qnil);
3870 if (horflag) 4012 if (horflag)
3871 p->hchild = sibling; 4013 wset_hchild (p, sibling);
3872 else 4014 else
3873 p->vchild = sibling; 4015 wset_vchild (p, sibling);
3874 } 4016 }
3875 else 4017 else
3876 /* Get SIBLING above (on the left of) WINDOW. */ 4018 /* Get SIBLING above (on the left of) WINDOW. */
3877 { 4019 {
3878 sibling = w->prev; 4020 sibling = w->prev;
3879 s = XWINDOW (sibling); 4021 s = XWINDOW (sibling);
3880 s->next = w->next; 4022 wset_next (s, w->next);
3881 if (!NILP (s->next)) 4023 if (!NILP (s->next))
3882 XWINDOW (s->next)->prev = sibling; 4024 wset_prev (XWINDOW (s->next), sibling);
3883 } 4025 }
3884 4026
3885 if (window_resize_check (r, horflag) 4027 if (window_resize_check (r, horflag)
3886 && EQ (r->new_total, (horflag ? r->total_cols : r->total_lines))) 4028 && EQ (r->new_total,
4029 (horflag ? r->total_cols : r->total_lines)))
3887 /* We can delete WINDOW now. */ 4030 /* We can delete WINDOW now. */
3888 { 4031 {
4032
3889 /* Block input. */ 4033 /* Block input. */
3890 BLOCK_INPUT; 4034 block_input ();
3891 window_resize_apply (p, horflag); 4035 window_resize_apply (p, horflag);
3892 4036
4037 /* If this window is referred to by the dpyinfo's mouse
4038 highlight, invalidate that slot to be safe (Bug#9904). */
4039 if (!FRAME_INITIAL_P (f))
4040 {
4041 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
4042
4043 if (EQ (hlinfo->mouse_face_window, window))
4044 hlinfo->mouse_face_window = Qnil;
4045 }
4046
3893 windows_or_buffers_changed++; 4047 windows_or_buffers_changed++;
3894 Vwindow_list = Qnil; 4048 Vwindow_list = Qnil;
3895 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4049 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3896 4050
3897 w->next = Qnil; /* Don't delete w->next too. */ 4051 wset_next (w, Qnil); /* Don't delete w->next too. */
3898 free_window_matrices (w); 4052 free_window_matrices (w);
3899 4053
3900 if (!NILP (w->vchild)) 4054 if (!NILP (w->vchild))
3901 { 4055 {
3902 delete_all_child_windows (w->vchild); 4056 delete_all_child_windows (w->vchild);
3903 w->vchild = Qnil; 4057 wset_vchild (w, Qnil);
3904 } 4058 }
3905 else if (!NILP (w->hchild)) 4059 else if (!NILP (w->hchild))
3906 { 4060 {
3907 delete_all_child_windows (w->hchild); 4061 delete_all_child_windows (w->hchild);
3908 w->hchild = Qnil; 4062 wset_hchild (w, Qnil);
3909 } 4063 }
3910 else if (!NILP (w->buffer)) 4064 else if (!NILP (w->buffer))
3911 { 4065 {
3912 unshow_buffer (w); 4066 unshow_buffer (w);
3913 unchain_marker (XMARKER (w->pointm)); 4067 unchain_marker (XMARKER (w->pointm));
3914 unchain_marker (XMARKER (w->start)); 4068 unchain_marker (XMARKER (w->start));
3915 w->buffer = Qnil; 4069 wset_buffer (w, Qnil);
3916 } 4070 }
3917 4071
3918 if (NILP (s->prev) && NILP (s->next)) 4072 if (NILP (s->prev) && NILP (s->next))
@@ -3923,10 +4077,11 @@ Signal an error when WINDOW is the only window on its frame. */)
3923 replace_window (parent, sibling, 0); 4077 replace_window (parent, sibling, 0);
3924 /* Have SIBLING inherit the following three slot values from 4078 /* Have SIBLING inherit the following three slot values from
3925 PARENT (the combination_limit slot is not inherited). */ 4079 PARENT (the combination_limit slot is not inherited). */
3926 s->normal_cols = p->normal_cols; 4080 wset_normal_cols (s, p->normal_cols);
3927 s->normal_lines = p->normal_lines; 4081 wset_normal_lines (s, p->normal_lines);
3928 /* Mark PARENT as deleted. */ 4082 /* Mark PARENT as deleted. */
3929 p->vchild = p->hchild = Qnil; 4083 wset_vchild (p, Qnil);
4084 wset_hchild (p, Qnil);
3930 /* Try to merge SIBLING into its new parent. */ 4085 /* Try to merge SIBLING into its new parent. */
3931 recombine_windows (sibling); 4086 recombine_windows (sibling);
3932 } 4087 }
@@ -3946,9 +4101,9 @@ Signal an error when WINDOW is the only window on its frame. */)
3946 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window)) 4101 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3947 Fselect_window (new_selected_window, Qt); 4102 Fselect_window (new_selected_window, Qt);
3948 else 4103 else
3949 FRAME_SELECTED_WINDOW (f) = new_selected_window; 4104 fset_selected_window (f, new_selected_window);
3950 4105
3951 UNBLOCK_INPUT; 4106 unblock_input ();
3952 4107
3953 /* Now look whether `get-mru-window' gets us something. */ 4108 /* Now look whether `get-mru-window' gets us something. */
3954 mru_window = call1 (Qget_mru_window, frame); 4109 mru_window = call1 (Qget_mru_window, frame);
@@ -3960,10 +4115,10 @@ Signal an error when WINDOW is the only window on its frame. */)
3960 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window)) 4115 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
3961 Fselect_window (new_selected_window, Qnil); 4116 Fselect_window (new_selected_window, Qnil);
3962 else 4117 else
3963 FRAME_SELECTED_WINDOW (f) = new_selected_window; 4118 fset_selected_window (f, new_selected_window);
3964 } 4119 }
3965 else 4120 else
3966 UNBLOCK_INPUT; 4121 unblock_input ();
3967 4122
3968 /* Must be run by the caller: 4123 /* Must be run by the caller:
3969 run_window_configuration_change_hook (f); */ 4124 run_window_configuration_change_hook (f); */
@@ -3973,17 +4128,17 @@ Signal an error when WINDOW is the only window on its frame. */)
3973 { 4128 {
3974 if (before_sibling) 4129 if (before_sibling)
3975 { 4130 {
3976 s->prev = window; 4131 wset_prev (s, window);
3977 if (horflag) 4132 if (horflag)
3978 p->hchild = window; 4133 wset_hchild (p, window);
3979 else 4134 else
3980 p->vchild = window; 4135 wset_vchild (p, window);
3981 } 4136 }
3982 else 4137 else
3983 { 4138 {
3984 s->next = window; 4139 wset_next (s, window);
3985 if (!NILP (w->next)) 4140 if (!NILP (w->next))
3986 XWINDOW (w->next)->prev = window; 4141 wset_prev (XWINDOW (w->next), window);
3987 } 4142 }
3988 error ("Deletion failed"); 4143 error ("Deletion failed");
3989 } 4144 }
@@ -4004,8 +4159,8 @@ grow_mini_window (struct window *w, int delta)
4004 struct window *r; 4159 struct window *r;
4005 Lisp_Object root, value; 4160 Lisp_Object root, value;
4006 4161
4007 xassert (MINI_WINDOW_P (w)); 4162 eassert (MINI_WINDOW_P (w));
4008 xassert (delta >= 0); 4163 eassert (delta >= 0);
4009 4164
4010 root = FRAME_ROOT_WINDOW (f); 4165 root = FRAME_ROOT_WINDOW (f);
4011 r = XWINDOW (root); 4166 r = XWINDOW (root);
@@ -4013,17 +4168,20 @@ grow_mini_window (struct window *w, int delta)
4013 root, make_number (- delta)); 4168 root, make_number (- delta));
4014 if (INTEGERP (value) && window_resize_check (r, 0)) 4169 if (INTEGERP (value) && window_resize_check (r, 0))
4015 { 4170 {
4016 BLOCK_INPUT; 4171 block_input ();
4017 window_resize_apply (r, 0); 4172 window_resize_apply (r, 0);
4018 4173
4019 /* Grow the mini-window. */ 4174 /* Grow the mini-window. */
4020 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines)); 4175 wset_top_line
4021 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - XINT (value)); 4176 (w, make_number (XFASTINT (r->top_line) + XFASTINT (r->total_lines)));
4022 XSETFASTINT (w->last_modified, 0); 4177 wset_total_lines
4023 XSETFASTINT (w->last_overlay_modified, 0); 4178 (w, make_number (XFASTINT (w->total_lines) - XINT (value)));
4179 w->last_modified = 0;
4180 w->last_overlay_modified = 0;
4024 4181
4182 windows_or_buffers_changed++;
4025 adjust_glyphs (f); 4183 adjust_glyphs (f);
4026 UNBLOCK_INPUT; 4184 unblock_input ();
4027 } 4185 }
4028} 4186}
4029 4187
@@ -4037,7 +4195,7 @@ shrink_mini_window (struct window *w)
4037 Lisp_Object root, value; 4195 Lisp_Object root, value;
4038 EMACS_INT size; 4196 EMACS_INT size;
4039 4197
4040 xassert (MINI_WINDOW_P (w)); 4198 eassert (MINI_WINDOW_P (w));
4041 4199
4042 size = XINT (w->total_lines); 4200 size = XINT (w->total_lines);
4043 if (size > 1) 4201 if (size > 1)
@@ -4048,18 +4206,20 @@ shrink_mini_window (struct window *w)
4048 root, make_number (size - 1)); 4206 root, make_number (size - 1));
4049 if (INTEGERP (value) && window_resize_check (r, 0)) 4207 if (INTEGERP (value) && window_resize_check (r, 0))
4050 { 4208 {
4051 BLOCK_INPUT; 4209 block_input ();
4052 window_resize_apply (r, 0); 4210 window_resize_apply (r, 0);
4053 4211
4054 /* Shrink the mini-window. */ 4212 /* Shrink the mini-window. */
4055 XSETFASTINT (w->top_line, XFASTINT (r->top_line) + XFASTINT (r->total_lines)); 4213 wset_top_line (w, make_number (XFASTINT (r->top_line)
4056 XSETFASTINT (w->total_lines, 1); 4214 + XFASTINT (r->total_lines)));
4215 wset_total_lines (w, make_number (1));
4057 4216
4058 XSETFASTINT (w->last_modified, 0); 4217 w->last_modified = 0;
4059 XSETFASTINT (w->last_overlay_modified, 0); 4218 w->last_overlay_modified = 0;
4060 4219
4220 windows_or_buffers_changed++;
4061 adjust_glyphs (f); 4221 adjust_glyphs (f);
4062 UNBLOCK_INPUT; 4222 unblock_input ();
4063 } 4223 }
4064 /* If the above failed for whatever strange reason we must make a 4224 /* If the above failed for whatever strange reason we must make a
4065 one window frame here. The same routine will be needed when 4225 one window frame here. The same routine will be needed when
@@ -4091,16 +4251,17 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini
4091 && XINT (w->new_total) > 0 4251 && XINT (w->new_total) > 0
4092 && height == XINT (r->new_total) + XINT (w->new_total)) 4252 && height == XINT (r->new_total) + XINT (w->new_total))
4093 { 4253 {
4094 BLOCK_INPUT; 4254 block_input ();
4095 window_resize_apply (r, 0); 4255 window_resize_apply (r, 0);
4096 4256
4097 w->total_lines = w->new_total; 4257 wset_total_lines (w, w->new_total);
4098 XSETFASTINT (w->top_line, XINT (r->top_line) + XINT (r->total_lines)); 4258 wset_top_line (w, make_number (XINT (r->top_line)
4259 + XINT (r->total_lines)));
4099 4260
4100 windows_or_buffers_changed++; 4261 windows_or_buffers_changed++;
4101 FRAME_WINDOW_SIZES_CHANGED (f) = 1; 4262 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4102 adjust_glyphs (f); 4263 adjust_glyphs (f);
4103 UNBLOCK_INPUT; 4264 unblock_input ();
4104 4265
4105 run_window_configuration_change_hook (f); 4266 run_window_configuration_change_hook (f);
4106 return Qt; 4267 return Qt;
@@ -4166,9 +4327,10 @@ window_internal_height (struct window *w)
4166 respectively. */ 4327 respectively. */
4167 4328
4168static void 4329static void
4169window_scroll (Lisp_Object window, int n, int whole, int noerror) 4330window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4170{ 4331{
4171 immediate_quit = 1; 4332 immediate_quit = 1;
4333 n = clip_to_bounds (INT_MIN, n, INT_MAX);
4172 4334
4173 /* If we must, use the pixel-based version which is much slower than 4335 /* If we must, use the pixel-based version which is much slower than
4174 the line-based one but can handle varying line heights. */ 4336 the line-based one but can handle varying line heights. */
@@ -4198,6 +4360,11 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4198 void *itdata = NULL; 4360 void *itdata = NULL;
4199 4361
4200 SET_TEXT_POS_FROM_MARKER (start, w->start); 4362 SET_TEXT_POS_FROM_MARKER (start, w->start);
4363 /* Scrolling a minibuffer window via scroll bar when the echo area
4364 shows long text sometimes resets the minibuffer contents behind
4365 our backs. */
4366 if (CHARPOS (start) > ZV)
4367 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
4201 4368
4202 /* If PT is not visible in WINDOW, move back one half of 4369 /* If PT is not visible in WINDOW, move back one half of
4203 the screen. Allow PT to be partially visible, otherwise 4370 the screen. Allow PT to be partially visible, otherwise
@@ -4264,7 +4431,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4264 /* Maybe modify window start instead of scrolling. */ 4431 /* Maybe modify window start instead of scrolling. */
4265 if (rbot > 0 || w->vscroll < 0) 4432 if (rbot > 0 || w->vscroll < 0)
4266 { 4433 {
4267 EMACS_INT spos; 4434 ptrdiff_t spos;
4268 4435
4269 Fset_window_vscroll (window, make_number (0), Qt); 4436 Fset_window_vscroll (window, make_number (0), Qt);
4270 /* If there are other text lines above the current row, 4437 /* If there are other text lines above the current row,
@@ -4275,13 +4442,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4275 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV); 4442 spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
4276 set_marker_restricted (w->start, make_number (spos), 4443 set_marker_restricted (w->start, make_number (spos),
4277 w->buffer); 4444 w->buffer);
4278 w->start_at_line_beg = Qt; 4445 w->start_at_line_beg = 1;
4279 w->update_mode_line = Qt; 4446 w->update_mode_line = 1;
4280 XSETFASTINT (w->last_modified, 0); 4447 w->last_modified = 0;
4281 XSETFASTINT (w->last_overlay_modified, 0); 4448 w->last_overlay_modified = 0;
4282 /* Set force_start so that redisplay_window will run the 4449 /* Set force_start so that redisplay_window will run the
4283 window-scroll-functions. */ 4450 window-scroll-functions. */
4284 w->force_start = Qt; 4451 w->force_start = 1;
4285 return; 4452 return;
4286 } 4453 }
4287 } 4454 }
@@ -4319,7 +4486,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4319 start_display (&it, w, start); 4486 start_display (&it, w, start);
4320 if (whole) 4487 if (whole)
4321 { 4488 {
4322 EMACS_INT start_pos = IT_CHARPOS (it); 4489 ptrdiff_t start_pos = IT_CHARPOS (it);
4323 int dy = WINDOW_FRAME_LINE_HEIGHT (w); 4490 int dy = WINDOW_FRAME_LINE_HEIGHT (w);
4324 dy = max ((window_box_height (w) 4491 dy = max ((window_box_height (w)
4325 - next_screen_context_lines * dy), 4492 - next_screen_context_lines * dy),
@@ -4406,8 +4573,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4406 4573
4407 if (! vscrolled) 4574 if (! vscrolled)
4408 { 4575 {
4409 EMACS_INT pos = IT_CHARPOS (it); 4576 ptrdiff_t pos = IT_CHARPOS (it);
4410 EMACS_INT bytepos; 4577 ptrdiff_t bytepos;
4411 4578
4412 /* If in the middle of a multi-glyph character move forward to 4579 /* If in the middle of a multi-glyph character move forward to
4413 the next character. */ 4580 the next character. */
@@ -4421,14 +4588,13 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4421 set_marker_restricted (w->start, make_number (pos), 4588 set_marker_restricted (w->start, make_number (pos),
4422 w->buffer); 4589 w->buffer);
4423 bytepos = XMARKER (w->start)->bytepos; 4590 bytepos = XMARKER (w->start)->bytepos;
4424 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n') 4591 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
4425 ? Qt : Qnil); 4592 w->update_mode_line = 1;
4426 w->update_mode_line = Qt; 4593 w->last_modified = 0;
4427 XSETFASTINT (w->last_modified, 0); 4594 w->last_overlay_modified = 0;
4428 XSETFASTINT (w->last_overlay_modified, 0);
4429 /* Set force_start so that redisplay_window will run the 4595 /* Set force_start so that redisplay_window will run the
4430 window-scroll-functions. */ 4596 window-scroll-functions. */
4431 w->force_start = Qt; 4597 w->force_start = 1;
4432 } 4598 }
4433 4599
4434 /* The rest of this function uses current_y in a nonstandard way, 4600 /* The rest of this function uses current_y in a nonstandard way,
@@ -4439,7 +4605,8 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4439 This code wants current_y to be zero at the window start position 4605 This code wants current_y to be zero at the window start position
4440 even if there is a header line. */ 4606 even if there is a header line. */
4441 this_scroll_margin = max (0, scroll_margin); 4607 this_scroll_margin = max (0, scroll_margin);
4442 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4); 4608 this_scroll_margin
4609 = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4443 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f); 4610 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4444 4611
4445 if (n > 0) 4612 if (n > 0)
@@ -4477,7 +4644,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4477 } 4644 }
4478 else if (n < 0) 4645 else if (n < 0)
4479 { 4646 {
4480 EMACS_INT charpos, bytepos; 4647 ptrdiff_t charpos, bytepos;
4481 int partial_p; 4648 int partial_p;
4482 4649
4483 /* Save our position, for the 4650 /* Save our position, for the
@@ -4554,12 +4721,12 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4554 in `grep-mode-font-lock-keywords'). So we use a marker to record 4721 in `grep-mode-font-lock-keywords'). So we use a marker to record
4555 the old point position, to prevent crashes in SET_PT_BOTH. */ 4722 the old point position, to prevent crashes in SET_PT_BOTH. */
4556 Lisp_Object opoint_marker = Fpoint_marker (); 4723 Lisp_Object opoint_marker = Fpoint_marker ();
4557 register EMACS_INT pos, pos_byte; 4724 register ptrdiff_t pos, pos_byte;
4558 register int ht = window_internal_height (w); 4725 register int ht = window_internal_height (w);
4559 register Lisp_Object tem; 4726 register Lisp_Object tem;
4560 int lose; 4727 int lose;
4561 Lisp_Object bolp; 4728 Lisp_Object bolp;
4562 EMACS_INT startpos; 4729 ptrdiff_t startpos;
4563 Lisp_Object original_pos = Qnil; 4730 Lisp_Object original_pos = Qnil;
4564 4731
4565 /* If scrolling screen-fulls, compute the number of lines to 4732 /* If scrolling screen-fulls, compute the number of lines to
@@ -4578,10 +4745,10 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4578 struct position posit 4745 struct position posit
4579 = *compute_motion (startpos, 0, 0, 0, 4746 = *compute_motion (startpos, 0, 0, 0,
4580 PT, ht, 0, 4747 PT, ht, 0,
4581 -1, XINT (w->hscroll), 4748 -1, w->hscroll,
4582 0, w); 4749 0, w);
4583 window_scroll_preserve_vpos = posit.vpos; 4750 window_scroll_preserve_vpos = posit.vpos;
4584 window_scroll_preserve_hpos = posit.hpos + XINT (w->hscroll); 4751 window_scroll_preserve_hpos = posit.hpos + w->hscroll;
4585 } 4752 }
4586 4753
4587 original_pos = Fcons (make_number (window_scroll_preserve_hpos), 4754 original_pos = Fcons (make_number (window_scroll_preserve_hpos),
@@ -4621,13 +4788,13 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4621 max (0, min (scroll_margin, XINT (w->total_lines) / 4)); 4788 max (0, min (scroll_margin, XINT (w->total_lines) / 4));
4622 4789
4623 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte); 4790 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4624 w->start_at_line_beg = bolp; 4791 w->start_at_line_beg = !NILP (bolp);
4625 w->update_mode_line = Qt; 4792 w->update_mode_line = 1;
4626 XSETFASTINT (w->last_modified, 0); 4793 w->last_modified = 0;
4627 XSETFASTINT (w->last_overlay_modified, 0); 4794 w->last_overlay_modified = 0;
4628 /* Set force_start so that redisplay_window will run 4795 /* Set force_start so that redisplay_window will run
4629 the window-scroll-functions. */ 4796 the window-scroll-functions. */
4630 w->force_start = Qt; 4797 w->force_start = 1;
4631 4798
4632 if (!NILP (Vscroll_preserve_screen_position) 4799 if (!NILP (Vscroll_preserve_screen_position)
4633 && (whole || !EQ (Vscroll_preserve_screen_position, Qt))) 4800 && (whole || !EQ (Vscroll_preserve_screen_position, Qt)))
@@ -4708,9 +4875,9 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4708static void 4875static void
4709scroll_command (Lisp_Object n, int direction) 4876scroll_command (Lisp_Object n, int direction)
4710{ 4877{
4711 int count = SPECPDL_INDEX (); 4878 ptrdiff_t count = SPECPDL_INDEX ();
4712 4879
4713 xassert (eabs (direction) == 1); 4880 eassert (eabs (direction) == 1);
4714 4881
4715 /* If selected window's buffer isn't current, make it current for 4882 /* If selected window's buffer isn't current, make it current for
4716 the moment. But don't screw up if window_scroll gets an error. */ 4883 the moment. But don't screw up if window_scroll gets an error. */
@@ -4823,7 +4990,7 @@ specifies the window to scroll. This takes precedence over
4823{ 4990{
4824 Lisp_Object window; 4991 Lisp_Object window;
4825 struct window *w; 4992 struct window *w;
4826 int count = SPECPDL_INDEX (); 4993 ptrdiff_t count = SPECPDL_INDEX ();
4827 4994
4828 window = Fother_window_for_scrolling (); 4995 window = Fother_window_for_scrolling ();
4829 w = XWINDOW (window); 4996 w = XWINDOW (window);
@@ -4842,7 +5009,7 @@ specifies the window to scroll. This takes precedence over
4842 else 5009 else
4843 { 5010 {
4844 if (CONSP (arg)) 5011 if (CONSP (arg))
4845 arg = Fcar (arg); 5012 arg = XCAR (arg);
4846 CHECK_NUMBER (arg); 5013 CHECK_NUMBER (arg);
4847 window_scroll (window, XINT (arg), 0, 1); 5014 window_scroll (window, XINT (arg), 0, 1);
4848 } 5015 }
@@ -4864,17 +5031,11 @@ will not scroll a window to a column less than the value returned
4864by this function. This happens in an interactive call. */) 5031by this function. This happens in an interactive call. */)
4865 (register Lisp_Object arg, Lisp_Object set_minimum) 5032 (register Lisp_Object arg, Lisp_Object set_minimum)
4866{ 5033{
4867 Lisp_Object result;
4868 int hscroll;
4869 struct window *w = XWINDOW (selected_window); 5034 struct window *w = XWINDOW (selected_window);
4870 5035 EMACS_INT requested_arg = (NILP (arg)
4871 if (NILP (arg)) 5036 ? window_body_cols (w) - 2
4872 XSETFASTINT (arg, window_body_cols (w) - 2); 5037 : XINT (Fprefix_numeric_value (arg)));
4873 else 5038 Lisp_Object result = set_window_hscroll (w, w->hscroll + requested_arg);
4874 arg = Fprefix_numeric_value (arg);
4875
4876 hscroll = XINT (w->hscroll) + XINT (arg);
4877 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4878 5039
4879 if (!NILP (set_minimum)) 5040 if (!NILP (set_minimum))
4880 w->min_hscroll = w->hscroll; 5041 w->min_hscroll = w->hscroll;
@@ -4893,17 +5054,11 @@ will not scroll a window to a column less than the value returned
4893by this function. This happens in an interactive call. */) 5054by this function. This happens in an interactive call. */)
4894 (register Lisp_Object arg, Lisp_Object set_minimum) 5055 (register Lisp_Object arg, Lisp_Object set_minimum)
4895{ 5056{
4896 Lisp_Object result;
4897 int hscroll;
4898 struct window *w = XWINDOW (selected_window); 5057 struct window *w = XWINDOW (selected_window);
4899 5058 EMACS_INT requested_arg = (NILP (arg)
4900 if (NILP (arg)) 5059 ? window_body_cols (w) - 2
4901 XSETFASTINT (arg, window_body_cols (w) - 2); 5060 : XINT (Fprefix_numeric_value (arg)));
4902 else 5061 Lisp_Object result = set_window_hscroll (w, w->hscroll - requested_arg);
4903 arg = Fprefix_numeric_value (arg);
4904
4905 hscroll = XINT (w->hscroll) - XINT (arg);
4906 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4907 5062
4908 if (!NILP (set_minimum)) 5063 if (!NILP (set_minimum))
4909 w->min_hscroll = w->hscroll; 5064 w->min_hscroll = w->hscroll;
@@ -5005,7 +5160,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5005 struct buffer *buf = XBUFFER (w->buffer); 5160 struct buffer *buf = XBUFFER (w->buffer);
5006 struct buffer *obuf = current_buffer; 5161 struct buffer *obuf = current_buffer;
5007 int center_p = 0; 5162 int center_p = 0;
5008 EMACS_INT charpos, bytepos; 5163 ptrdiff_t charpos, bytepos;
5009 EMACS_INT iarg IF_LINT (= 0); 5164 EMACS_INT iarg IF_LINT (= 0);
5010 int this_scroll_margin; 5165 int this_scroll_margin;
5011 5166
@@ -5070,7 +5225,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5070 { 5225 {
5071 struct it it; 5226 struct it it;
5072 struct text_pos pt; 5227 struct text_pos pt;
5073 int nlines = min (INT_MAX, -iarg); 5228 ptrdiff_t nlines = min (PTRDIFF_MAX, -iarg);
5074 int extra_line_spacing; 5229 int extra_line_spacing;
5075 int h = window_box_height (w); 5230 int h = window_box_height (w);
5076 void *itdata = bidi_shelve_cache (); 5231 void *itdata = bidi_shelve_cache ();
@@ -5169,14 +5324,12 @@ and redisplay normally--don't erase and redraw the frame. */)
5169 5324
5170 /* Set the new window start. */ 5325 /* Set the new window start. */
5171 set_marker_both (w->start, w->buffer, charpos, bytepos); 5326 set_marker_both (w->start, w->buffer, charpos, bytepos);
5172 w->window_end_valid = Qnil; 5327 wset_window_end_valid (w, Qnil);
5173 5328
5174 w->optional_new_start = Qt; 5329 w->optional_new_start = 1;
5175 5330
5176 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n') 5331 w->start_at_line_beg = (bytepos == BEGV_BYTE ||
5177 w->start_at_line_beg = Qt; 5332 FETCH_BYTE (bytepos - 1) == '\n');
5178 else
5179 w->start_at_line_beg = Qnil;
5180 5333
5181 set_buffer_internal (obuf); 5334 set_buffer_internal (obuf);
5182 return Qnil; 5335 return Qnil;
@@ -5185,13 +5338,13 @@ and redisplay normally--don't erase and redraw the frame. */)
5185DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height, 5338DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5186 0, 1, 0, 5339 0, 1, 0,
5187 doc: /* Return the height in lines of the text display area of WINDOW. 5340 doc: /* Return the height in lines of the text display area of WINDOW.
5188If WINDOW is omitted or nil, it defaults to the selected window. 5341WINDOW must be a live window and defaults to the selected one.
5189 5342
5190The returned height does not include the mode line, any header line, 5343The returned height does not include the mode line, any header line,
5191nor any partial-height lines at the bottom of the text area. */) 5344nor any partial-height lines at the bottom of the text area. */)
5192 (Lisp_Object window) 5345 (Lisp_Object window)
5193{ 5346{
5194 struct window *w = decode_window (window); 5347 struct window *w = decode_live_window (window);
5195 int pixel_height = window_box_height (w); 5348 int pixel_height = window_box_height (w);
5196 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame)); 5349 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5197 return make_number (line_height); 5350 return make_number (line_height);
@@ -5227,8 +5380,8 @@ zero means top of window, negative means relative to bottom of window. */)
5227 int height = window_internal_height (w); 5380 int height = window_internal_height (w);
5228 Fvertical_motion (make_number (- (height / 2)), window); 5381 Fvertical_motion (make_number (- (height / 2)), window);
5229 set_marker_both (w->start, w->buffer, PT, PT_BYTE); 5382 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5230 w->start_at_line_beg = Fbolp (); 5383 w->start_at_line_beg = !NILP (Fbolp ());
5231 w->force_start = Qt; 5384 w->force_start = 1;
5232 } 5385 }
5233 else 5386 else
5234 Fgoto_char (w->start); 5387 Fgoto_char (w->start);
@@ -5352,9 +5505,8 @@ the return value is nil. Otherwise the value is t. */)
5352 struct Lisp_Vector *saved_windows; 5505 struct Lisp_Vector *saved_windows;
5353 Lisp_Object new_current_buffer; 5506 Lisp_Object new_current_buffer;
5354 Lisp_Object frame; 5507 Lisp_Object frame;
5355 Lisp_Object auto_buffer_name;
5356 FRAME_PTR f; 5508 FRAME_PTR f;
5357 EMACS_INT old_point = -1; 5509 ptrdiff_t old_point = -1;
5358 5510
5359 CHECK_WINDOW_CONFIGURATION (configuration); 5511 CHECK_WINDOW_CONFIGURATION (configuration);
5360 5512
@@ -5362,7 +5514,7 @@ the return value is nil. Otherwise the value is t. */)
5362 saved_windows = XVECTOR (data->saved_windows); 5514 saved_windows = XVECTOR (data->saved_windows);
5363 5515
5364 new_current_buffer = data->current_buffer; 5516 new_current_buffer = data->current_buffer;
5365 if (NILP (BVAR (XBUFFER (new_current_buffer), name))) 5517 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer)))
5366 new_current_buffer = Qnil; 5518 new_current_buffer = Qnil;
5367 else 5519 else
5368 { 5520 {
@@ -5410,6 +5562,7 @@ the return value is nil. Otherwise the value is t. */)
5410 { 5562 {
5411 Lisp_Object window; 5563 Lisp_Object window;
5412 Lisp_Object dead_windows = Qnil; 5564 Lisp_Object dead_windows = Qnil;
5565 register Lisp_Object tem, par, pers;
5413 register struct window *w; 5566 register struct window *w;
5414 register struct saved_window *p; 5567 register struct saved_window *p;
5415 struct window *root_window; 5568 struct window *root_window;
@@ -5427,9 +5580,24 @@ the return value is nil. Otherwise the value is t. */)
5427 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); 5580 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5428 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); 5581 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5429 5582
5583 /* Don't do this within the main loop below: This may call Lisp
5584 code and is thus potentially unsafe while input is blocked. */
5585 for (k = 0; k < saved_windows->header.size; k++)
5586 {
5587 p = SAVED_WINDOW_N (saved_windows, k);
5588 window = p->window;
5589 w = XWINDOW (window);
5590 if (!NILP (w->buffer)
5591 && !EQ (w->buffer, p->buffer)
5592 && BUFFER_LIVE_P (XBUFFER (p->buffer)))
5593 /* If a window we restore gets another buffer, record the
5594 window's old buffer. */
5595 call1 (Qrecord_window_buffer, window);
5596 }
5597
5430 /* The mouse highlighting code could get screwed up 5598 /* The mouse highlighting code could get screwed up
5431 if it runs during this. */ 5599 if it runs during this. */
5432 BLOCK_INPUT; 5600 block_input ();
5433 5601
5434 if (data->frame_lines != previous_frame_lines 5602 if (data->frame_lines != previous_frame_lines
5435 || data->frame_cols != previous_frame_cols) 5603 || data->frame_cols != previous_frame_cols)
@@ -5470,9 +5638,8 @@ the return value is nil. Otherwise the value is t. */)
5470 really like to do is to free only those matrices not reused 5638 really like to do is to free only those matrices not reused
5471 below. */ 5639 below. */
5472 root_window = XWINDOW (FRAME_ROOT_WINDOW (f)); 5640 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5473 leaf_windows 5641 leaf_windows = alloca (count_windows (root_window)
5474 = (struct window **) alloca (count_windows (root_window) 5642 * sizeof *leaf_windows);
5475 * sizeof (struct window *));
5476 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0); 5643 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5477 5644
5478 /* Kludge Alert! 5645 /* Kludge Alert!
@@ -5489,34 +5656,34 @@ the return value is nil. Otherwise the value is t. */)
5489 p = SAVED_WINDOW_N (saved_windows, k); 5656 p = SAVED_WINDOW_N (saved_windows, k);
5490 window = p->window; 5657 window = p->window;
5491 w = XWINDOW (window); 5658 w = XWINDOW (window);
5492 w->next = Qnil; 5659 wset_next (w, Qnil);
5493 5660
5494 if (!NILP (p->parent)) 5661 if (!NILP (p->parent))
5495 w->parent = SAVED_WINDOW_N (saved_windows, 5662 wset_parent
5496 XFASTINT (p->parent))->window; 5663 (w, SAVED_WINDOW_N (saved_windows, XFASTINT (p->parent))->window);
5497 else 5664 else
5498 w->parent = Qnil; 5665 wset_parent (w, Qnil);
5499 5666
5500 if (!NILP (p->prev)) 5667 if (!NILP (p->prev))
5501 { 5668 {
5502 w->prev = SAVED_WINDOW_N (saved_windows, 5669 wset_prev
5503 XFASTINT (p->prev))->window; 5670 (w, SAVED_WINDOW_N (saved_windows, XFASTINT (p->prev))->window);
5504 XWINDOW (w->prev)->next = p->window; 5671 wset_next (XWINDOW (w->prev), p->window);
5505 } 5672 }
5506 else 5673 else
5507 { 5674 {
5508 w->prev = Qnil; 5675 wset_prev (w, Qnil);
5509 if (!NILP (w->parent)) 5676 if (!NILP (w->parent))
5510 { 5677 {
5511 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols)) 5678 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5512 { 5679 {
5513 XWINDOW (w->parent)->vchild = p->window; 5680 wset_vchild (XWINDOW (w->parent), p->window);
5514 XWINDOW (w->parent)->hchild = Qnil; 5681 wset_hchild (XWINDOW (w->parent), Qnil);
5515 } 5682 }
5516 else 5683 else
5517 { 5684 {
5518 XWINDOW (w->parent)->hchild = p->window; 5685 wset_hchild (XWINDOW (w->parent), p->window);
5519 XWINDOW (w->parent)->vchild = Qnil; 5686 wset_vchild (XWINDOW (w->parent), Qnil);
5520 } 5687 }
5521 } 5688 }
5522 } 5689 }
@@ -5524,40 +5691,62 @@ the return value is nil. Otherwise the value is t. */)
5524 /* If we squirreled away the buffer in the window's height, 5691 /* If we squirreled away the buffer in the window's height,
5525 restore it now. */ 5692 restore it now. */
5526 if (BUFFERP (w->total_lines)) 5693 if (BUFFERP (w->total_lines))
5527 w->buffer = w->total_lines; 5694 wset_buffer (w, w->total_lines);
5528 w->left_col = p->left_col; 5695 wset_left_col (w, p->left_col);
5529 w->top_line = p->top_line; 5696 wset_top_line (w, p->top_line);
5530 w->total_cols = p->total_cols; 5697 wset_total_cols (w, p->total_cols);
5531 w->total_lines = p->total_lines; 5698 wset_total_lines (w, p->total_lines);
5532 w->normal_cols = p->normal_cols; 5699 wset_normal_cols (w, p->normal_cols);
5533 w->normal_lines = p->normal_lines; 5700 wset_normal_lines (w, p->normal_lines);
5534 w->hscroll = p->hscroll; 5701 w->hscroll = XFASTINT (p->hscroll);
5535 w->min_hscroll = p->min_hscroll; 5702 w->min_hscroll = XFASTINT (p->min_hscroll);
5536 w->display_table = p->display_table; 5703 wset_display_table (w, p->display_table);
5537 w->left_margin_cols = p->left_margin_cols; 5704 wset_left_margin_cols (w, p->left_margin_cols);
5538 w->right_margin_cols = p->right_margin_cols; 5705 wset_right_margin_cols (w, p->right_margin_cols);
5539 w->left_fringe_width = p->left_fringe_width; 5706 wset_left_fringe_width (w, p->left_fringe_width);
5540 w->right_fringe_width = p->right_fringe_width; 5707 wset_right_fringe_width (w, p->right_fringe_width);
5541 w->fringes_outside_margins = p->fringes_outside_margins; 5708 w->fringes_outside_margins = !NILP (p->fringes_outside_margins);
5542 w->scroll_bar_width = p->scroll_bar_width; 5709 wset_scroll_bar_width (w, p->scroll_bar_width);
5543 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type; 5710 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type);
5544 w->dedicated = p->dedicated; 5711 wset_dedicated (w, p->dedicated);
5545 w->combination_limit = p->combination_limit; 5712 wset_combination_limit (w, p->combination_limit);
5546 w->window_parameters = p->window_parameters; 5713 /* Restore any window parameters that have been saved.
5547 XSETFASTINT (w->last_modified, 0); 5714 Parameters that have not been saved are left alone. */
5548 XSETFASTINT (w->last_overlay_modified, 0); 5715 for (tem = p->window_parameters; CONSP (tem); tem = XCDR (tem))
5716 {
5717 pers = XCAR (tem);
5718 if (CONSP (pers))
5719 {
5720 if (NILP (XCDR (pers)))
5721 {
5722 par = Fassq (XCAR (pers), w->window_parameters);
5723 if (CONSP (par) && !NILP (XCDR (par)))
5724 /* Reset a parameter to nil if and only if it
5725 has a non-nil association. Don't make new
5726 associations. */
5727 Fsetcdr (par, Qnil);
5728 }
5729 else
5730 /* Always restore a non-nil value. */
5731 Fset_window_parameter (window, XCAR (pers), XCDR (pers));
5732 }
5733 }
5734
5735 w->last_modified = 0;
5736 w->last_overlay_modified = 0;
5549 5737
5550 /* Reinstall the saved buffer and pointers into it. */ 5738 /* Reinstall the saved buffer and pointers into it. */
5551 if (NILP (p->buffer)) 5739 if (NILP (p->buffer))
5552 /* An internal window. */ 5740 /* An internal window. */
5553 w->buffer = p->buffer; 5741 wset_buffer (w, p->buffer);
5554 else if (!NILP (BVAR (XBUFFER (p->buffer), name))) 5742 else if (BUFFER_LIVE_P (XBUFFER (p->buffer)))
5555 /* If saved buffer is alive, install it. */ 5743 /* If saved buffer is alive, install it. */
5556 { 5744 {
5557 w->buffer = p->buffer; 5745 wset_buffer (w, p->buffer);
5558 w->start_at_line_beg = p->start_at_line_beg; 5746 w->start_at_line_beg = !NILP (p->start_at_line_beg);
5559 set_marker_restricted (w->start, p->start, w->buffer); 5747 set_marker_restricted (w->start, p->start, w->buffer);
5560 set_marker_restricted (w->pointm, p->pointm, w->buffer); 5748 set_marker_restricted (w->pointm, p->pointm,
5749 w->buffer);
5561 Fset_marker (BVAR (XBUFFER (w->buffer), mark), 5750 Fset_marker (BVAR (XBUFFER (w->buffer), mark),
5562 p->mark, w->buffer); 5751 p->mark, w->buffer);
5563 5752
@@ -5567,30 +5756,23 @@ the return value is nil. Otherwise the value is t. */)
5567 if (!EQ (p->buffer, new_current_buffer) 5756 if (!EQ (p->buffer, new_current_buffer)
5568 && XBUFFER (p->buffer) == current_buffer) 5757 && XBUFFER (p->buffer) == current_buffer)
5569 Fgoto_char (w->pointm); 5758 Fgoto_char (w->pointm);
5570 } 5759 }
5571 else if (!NILP (w->buffer) && !NILP (BVAR (XBUFFER (w->buffer), name))) 5760 else if (!NILP (w->buffer)
5572 /* Keep window's old buffer; make sure the markers are 5761 && BUFFER_LIVE_P (XBUFFER (w->buffer)))
5573 real. */ 5762 /* Keep window's old buffer; make sure the markers are
5574 { 5763 real. */
5575 /* Set window markers at start of visible range. */ 5764 {
5576 if (XMARKER (w->start)->buffer == 0) 5765 /* Set window markers at start of visible range. */
5577 set_marker_restricted (w->start, make_number (0), 5766 if (XMARKER (w->start)->buffer == 0)
5578 w->buffer); 5767 set_marker_restricted (w->start, make_number (0),
5579 if (XMARKER (w->pointm)->buffer == 0) 5768 w->buffer);
5580 set_marker_restricted_both (w->pointm, w->buffer, 5769 if (XMARKER (w->pointm)->buffer == 0)
5581 BUF_PT (XBUFFER (w->buffer)), 5770 set_marker_restricted_both
5582 BUF_PT_BYTE (XBUFFER (w->buffer))); 5771 (w->pointm, w->buffer,
5583 w->start_at_line_beg = Qt; 5772 BUF_PT (XBUFFER (w->buffer)),
5584 } 5773 BUF_PT_BYTE (XBUFFER (w->buffer)));
5585 else if (STRINGP (auto_buffer_name = 5774 w->start_at_line_beg = 1;
5586 Fwindow_parameter (window, Qauto_buffer_name)) 5775 }
5587 && SCHARS (auto_buffer_name) != 0
5588 && !NILP (w->buffer = Fget_buffer_create (auto_buffer_name)))
5589 {
5590 set_marker_restricted (w->start, make_number (0), w->buffer);
5591 set_marker_restricted (w->pointm, make_number (0), w->buffer);
5592 w->start_at_line_beg = Qt;
5593 }
5594 else 5776 else
5595 /* Window has no live buffer, get one. */ 5777 /* Window has no live buffer, get one. */
5596 { 5778 {
@@ -5598,21 +5780,23 @@ the return value is nil. Otherwise the value is t. */)
5598 avoid showing an unimportant buffer and, if necessary, to 5780 avoid showing an unimportant buffer and, if necessary, to
5599 recreate *scratch* in the course (part of Juanma's bs-show 5781 recreate *scratch* in the course (part of Juanma's bs-show
5600 scenario from March 2011). */ 5782 scenario from March 2011). */
5601 w->buffer = other_buffer_safely (Fcurrent_buffer ()); 5783 wset_buffer (w, other_buffer_safely (Fcurrent_buffer ()));
5602 /* This will set the markers to beginning of visible 5784 /* This will set the markers to beginning of visible
5603 range. */ 5785 range. */
5604 set_marker_restricted (w->start, make_number (0), w->buffer); 5786 set_marker_restricted (w->start,
5605 set_marker_restricted (w->pointm, make_number (0), w->buffer); 5787 make_number (0), w->buffer);
5606 w->start_at_line_beg = Qt; 5788 set_marker_restricted (w->pointm,
5789 make_number (0), w->buffer);
5790 w->start_at_line_beg = 1;
5607 if (!NILP (w->dedicated)) 5791 if (!NILP (w->dedicated))
5608 /* Record this window as dead. */ 5792 /* Record this window as dead. */
5609 dead_windows = Fcons (window, dead_windows); 5793 dead_windows = Fcons (window, dead_windows);
5610 /* Make sure window is no more dedicated. */ 5794 /* Make sure window is no more dedicated. */
5611 w->dedicated = Qnil; 5795 wset_dedicated (w, Qnil);
5612 } 5796 }
5613 } 5797 }
5614 5798
5615 FRAME_ROOT_WINDOW (f) = data->root_window; 5799 fset_root_window (f, data->root_window);
5616 /* Arrange *not* to restore point in the buffer that was 5800 /* Arrange *not* to restore point in the buffer that was
5617 current when the window configuration was saved. */ 5801 current when the window configuration was saved. */
5618 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)) 5802 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
@@ -5655,7 +5839,7 @@ the return value is nil. Otherwise the value is t. */)
5655 if (NILP (leaf_windows[i]->buffer)) 5839 if (NILP (leaf_windows[i]->buffer))
5656 { 5840 {
5657 /* Assert it's not reused as a combination. */ 5841 /* Assert it's not reused as a combination. */
5658 xassert (NILP (leaf_windows[i]->hchild) 5842 eassert (NILP (leaf_windows[i]->hchild)
5659 && NILP (leaf_windows[i]->vchild)); 5843 && NILP (leaf_windows[i]->vchild));
5660 free_window_matrices (leaf_windows[i]); 5844 free_window_matrices (leaf_windows[i]);
5661 } 5845 }
@@ -5664,7 +5848,7 @@ the return value is nil. Otherwise the value is t. */)
5664 } 5848 }
5665 5849
5666 adjust_glyphs (f); 5850 adjust_glyphs (f);
5667 UNBLOCK_INPUT; 5851 unblock_input ();
5668 5852
5669 /* Scan dead buffer windows. */ 5853 /* Scan dead buffer windows. */
5670 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows)) 5854 for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows))
@@ -5686,7 +5870,13 @@ the return value is nil. Otherwise the value is t. */)
5686 } 5870 }
5687 5871
5688 if (!NILP (new_current_buffer)) 5872 if (!NILP (new_current_buffer))
5689 Fset_buffer (new_current_buffer); 5873 {
5874 Fset_buffer (new_current_buffer);
5875 /* If the new current buffer doesn't appear in the selected
5876 window, go to its old point (see bug#12208). */
5877 if (!EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5878 Fgoto_char (make_number (old_point));
5879 }
5690 5880
5691 Vminibuf_scroll_window = data->minibuf_scroll_window; 5881 Vminibuf_scroll_window = data->minibuf_scroll_window;
5692 minibuf_selected_window = data->minibuf_selected_window; 5882 minibuf_selected_window = data->minibuf_selected_window;
@@ -5708,24 +5898,25 @@ delete_all_child_windows (Lisp_Object window)
5708 /* Delete WINDOW's siblings (we traverse postorderly). */ 5898 /* Delete WINDOW's siblings (we traverse postorderly). */
5709 delete_all_child_windows (w->next); 5899 delete_all_child_windows (w->next);
5710 5900
5711 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */ 5901 /* See Fset_window_configuration for excuse. */
5902 wset_total_lines (w, w->buffer);
5712 5903
5713 if (!NILP (w->vchild)) 5904 if (!NILP (w->vchild))
5714 { 5905 {
5715 delete_all_child_windows (w->vchild); 5906 delete_all_child_windows (w->vchild);
5716 w->vchild = Qnil; 5907 wset_vchild (w, Qnil);
5717 } 5908 }
5718 else if (!NILP (w->hchild)) 5909 else if (!NILP (w->hchild))
5719 { 5910 {
5720 delete_all_child_windows (w->hchild); 5911 delete_all_child_windows (w->hchild);
5721 w->hchild = Qnil; 5912 wset_hchild (w, Qnil);
5722 } 5913 }
5723 else if (!NILP (w->buffer)) 5914 else if (!NILP (w->buffer))
5724 { 5915 {
5725 unshow_buffer (w); 5916 unshow_buffer (w);
5726 unchain_marker (XMARKER (w->pointm)); 5917 unchain_marker (XMARKER (w->pointm));
5727 unchain_marker (XMARKER (w->start)); 5918 unchain_marker (XMARKER (w->start));
5728 w->buffer = Qnil; 5919 wset_buffer (w, Qnil);
5729 } 5920 }
5730 5921
5731 Vwindow_list = Qnil; 5922 Vwindow_list = Qnil;
@@ -5784,7 +5975,7 @@ get_phys_cursor_glyph (struct window *w)
5784 if (!row->enabled_p) 5975 if (!row->enabled_p)
5785 return NULL; 5976 return NULL;
5786 5977
5787 if (XINT (w->hscroll)) 5978 if (w->hscroll)
5788 { 5979 {
5789 /* When the window is hscrolled, cursor hpos can legitimately be 5980 /* When the window is hscrolled, cursor hpos can legitimately be
5790 out of bounds, but we draw the cursor at the corresponding 5981 out of bounds, but we draw the cursor at the corresponding
@@ -5810,14 +6001,14 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5810{ 6001{
5811 register struct saved_window *p; 6002 register struct saved_window *p;
5812 register struct window *w; 6003 register struct window *w;
5813 register Lisp_Object tem; 6004 register Lisp_Object tem, pers, par;
5814 6005
5815 for (;!NILP (window); window = w->next) 6006 for (;!NILP (window); window = w->next)
5816 { 6007 {
5817 p = SAVED_WINDOW_N (vector, i); 6008 p = SAVED_WINDOW_N (vector, i);
5818 w = XWINDOW (window); 6009 w = XWINDOW (window);
5819 6010
5820 XSETFASTINT (w->temslot, i); i++; 6011 wset_temslot (w, make_number (i)); i++;
5821 p->window = window; 6012 p->window = window;
5822 p->buffer = w->buffer; 6013 p->buffer = w->buffer;
5823 p->left_col = w->left_col; 6014 p->left_col = w->left_col;
@@ -5826,36 +6017,82 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
5826 p->total_lines = w->total_lines; 6017 p->total_lines = w->total_lines;
5827 p->normal_cols = w->normal_cols; 6018 p->normal_cols = w->normal_cols;
5828 p->normal_lines = w->normal_lines; 6019 p->normal_lines = w->normal_lines;
5829 p->hscroll = w->hscroll; 6020 XSETFASTINT (p->hscroll, w->hscroll);
5830 p->min_hscroll = w->min_hscroll; 6021 XSETFASTINT (p->min_hscroll, w->min_hscroll);
5831 p->display_table = w->display_table; 6022 p->display_table = w->display_table;
5832 p->left_margin_cols = w->left_margin_cols; 6023 p->left_margin_cols = w->left_margin_cols;
5833 p->right_margin_cols = w->right_margin_cols; 6024 p->right_margin_cols = w->right_margin_cols;
5834 p->left_fringe_width = w->left_fringe_width; 6025 p->left_fringe_width = w->left_fringe_width;
5835 p->right_fringe_width = w->right_fringe_width; 6026 p->right_fringe_width = w->right_fringe_width;
5836 p->fringes_outside_margins = w->fringes_outside_margins; 6027 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil;
5837 p->scroll_bar_width = w->scroll_bar_width; 6028 p->scroll_bar_width = w->scroll_bar_width;
5838 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type; 6029 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5839 p->dedicated = w->dedicated; 6030 p->dedicated = w->dedicated;
5840 p->combination_limit = w->combination_limit; 6031 p->combination_limit = w->combination_limit;
5841 p->window_parameters = w->window_parameters; 6032 p->window_parameters = Qnil;
5842 if (!NILP (w->buffer)) 6033
6034 if (!NILP (Vwindow_persistent_parameters))
5843 { 6035 {
5844 /* Save w's value of point in the window configuration. 6036 /* Run cycle detection on Vwindow_persistent_parameters. */
5845 If w is the selected window, then get the value of point 6037 Lisp_Object tortoise, hare;
5846 from the buffer; pointm is garbage in the selected window. */ 6038
5847 if (EQ (window, selected_window)) 6039 hare = tortoise = Vwindow_persistent_parameters;
6040 while (CONSP (hare))
6041 {
6042 hare = XCDR (hare);
6043 if (!CONSP (hare))
6044 break;
6045
6046 hare = XCDR (hare);
6047 tortoise = XCDR (tortoise);
6048
6049 if (EQ (hare, tortoise))
6050 /* Reset Vwindow_persistent_parameters to Qnil. */
6051 {
6052 Vwindow_persistent_parameters = Qnil;
6053 break;
6054 }
6055 }
6056
6057 for (tem = Vwindow_persistent_parameters; CONSP (tem);
6058 tem = XCDR (tem))
5848 { 6059 {
5849 p->pointm = Fmake_marker (); 6060 pers = XCAR (tem);
5850 set_marker_both (p->pointm, w->buffer, 6061 /* Save values for persistent window parameters. */
5851 BUF_PT (XBUFFER (w->buffer)), 6062 if (CONSP (pers) && !NILP (XCDR (pers)))
5852 BUF_PT_BYTE (XBUFFER (w->buffer))); 6063 {
6064 par = Fassq (XCAR (pers), w->window_parameters);
6065 if (NILP (par))
6066 /* If the window has no value for the parameter,
6067 make one. */
6068 p->window_parameters = Fcons (Fcons (XCAR (pers), Qnil),
6069 p->window_parameters);
6070 else
6071 /* If the window has a value for the parameter,
6072 save it. */
6073 p->window_parameters = Fcons (Fcons (XCAR (par),
6074 XCDR (par)),
6075 p->window_parameters);
6076 }
5853 } 6077 }
6078 }
6079
6080 if (!NILP (w->buffer))
6081 {
6082 /* Save w's value of point in the window configuration. If w
6083 is the selected window, then get the value of point from
6084 the buffer; pointm is garbage in the selected window. */
6085 if (EQ (window, selected_window))
6086 p->pointm = build_marker (XBUFFER (w->buffer),
6087 BUF_PT (XBUFFER (w->buffer)),
6088 BUF_PT_BYTE (XBUFFER (w->buffer)));
5854 else 6089 else
5855 p->pointm = Fcopy_marker (w->pointm, Qnil); 6090 p->pointm = Fcopy_marker (w->pointm, Qnil);
6091 XMARKER (p->pointm)->insertion_type
6092 = !NILP (Vwindow_point_insertion_type);
5856 6093
5857 p->start = Fcopy_marker (w->start, Qnil); 6094 p->start = Fcopy_marker (w->start, Qnil);
5858 p->start_at_line_beg = w->start_at_line_beg; 6095 p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil;
5859 6096
5860 tem = BVAR (XBUFFER (w->buffer), mark); 6097 tem = BVAR (XBUFFER (w->buffer), mark);
5861 p->mark = Fcopy_marker (tem, Qnil); 6098 p->mark = Fcopy_marker (tem, Qnil);
@@ -5896,19 +6133,16 @@ and for each displayed buffer, where display starts, and the positions of
5896point and mark. An exception is made for point in the current buffer: 6133point and mark. An exception is made for point in the current buffer:
5897its value is -not- saved. 6134its value is -not- saved.
5898This also records the currently selected frame, and FRAME's focus 6135This also records the currently selected frame, and FRAME's focus
5899redirection (see `redirect-frame-focus'). */) 6136redirection (see `redirect-frame-focus'). The variable
6137`window-persistent-parameters' specifies which window parameters are
6138saved by this function. */)
5900 (Lisp_Object frame) 6139 (Lisp_Object frame)
5901{ 6140{
5902 register Lisp_Object tem; 6141 register Lisp_Object tem;
5903 register int n_windows; 6142 register int n_windows;
5904 register struct save_window_data *data; 6143 register struct save_window_data *data;
5905 register int i; 6144 register int i;
5906 FRAME_PTR f; 6145 struct frame *f = decode_live_frame (frame);
5907
5908 if (NILP (frame))
5909 frame = selected_frame;
5910 CHECK_LIVE_FRAME (frame);
5911 f = XFRAME (frame);
5912 6146
5913 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); 6147 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5914 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols, 6148 data = ALLOCATE_PSEUDOVECTOR (struct save_window_data, frame_cols,
@@ -5928,8 +6162,8 @@ redirection (see `redirect-frame-focus'). */)
5928 tem = Fmake_vector (make_number (n_windows), Qnil); 6162 tem = Fmake_vector (make_number (n_windows), Qnil);
5929 data->saved_windows = tem; 6163 data->saved_windows = tem;
5930 for (i = 0; i < n_windows; i++) 6164 for (i = 0; i < n_windows; i++)
5931 XVECTOR (tem)->contents[i] 6165 ASET (tem, i,
5932 = Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil); 6166 Fmake_vector (make_number (VECSIZE (struct saved_window)), Qnil));
5933 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0); 6167 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
5934 XSETWINDOW_CONFIGURATION (tem, data); 6168 XSETWINDOW_CONFIGURATION (tem, data);
5935 return (tem); 6169 return (tem);
@@ -5942,14 +6176,15 @@ redirection (see `redirect-frame-focus'). */)
5942DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, 6176DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
5943 2, 3, 0, 6177 2, 3, 0,
5944 doc: /* Set width of marginal areas of window WINDOW. 6178 doc: /* Set width of marginal areas of window WINDOW.
5945If WINDOW is nil, set margins of the currently selected window. 6179WINDOW must be a live window and defaults to the selected one.
6180
5946Second arg LEFT-WIDTH specifies the number of character cells to 6181Second arg LEFT-WIDTH specifies the number of character cells to
5947reserve for the left marginal area. Optional third arg RIGHT-WIDTH 6182reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5948does the same for the right marginal area. A nil width parameter 6183does the same for the right marginal area. A nil width parameter
5949means no margin. */) 6184means no margin. */)
5950 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width) 6185 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
5951{ 6186{
5952 struct window *w = decode_window (window); 6187 struct window *w = decode_live_window (window);
5953 6188
5954 /* Translate negative or zero widths to nil. 6189 /* Translate negative or zero widths to nil.
5955 Margins that are too wide have to be checked elsewhere. */ 6190 Margins that are too wide have to be checked elsewhere. */
@@ -5971,8 +6206,8 @@ means no margin. */)
5971 if (!EQ (w->left_margin_cols, left_width) 6206 if (!EQ (w->left_margin_cols, left_width)
5972 || !EQ (w->right_margin_cols, right_width)) 6207 || !EQ (w->right_margin_cols, right_width))
5973 { 6208 {
5974 w->left_margin_cols = left_width; 6209 wset_left_margin_cols (w, left_width);
5975 w->right_margin_cols = right_width; 6210 wset_right_margin_cols (w, right_width);
5976 6211
5977 adjust_window_margins (w); 6212 adjust_window_margins (w);
5978 6213
@@ -5987,13 +6222,14 @@ means no margin. */)
5987DEFUN ("window-margins", Fwindow_margins, Swindow_margins, 6222DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
5988 0, 1, 0, 6223 0, 1, 0,
5989 doc: /* Get width of marginal areas of window WINDOW. 6224 doc: /* Get width of marginal areas of window WINDOW.
5990If WINDOW is omitted or nil, it defaults to the selected window. 6225WINDOW must be a live window and defaults to the selected one.
6226
5991Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH). 6227Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5992If a marginal area does not exist, its width will be returned 6228If a marginal area does not exist, its width will be returned
5993as nil. */) 6229as nil. */)
5994 (Lisp_Object window) 6230 (Lisp_Object window)
5995{ 6231{
5996 struct window *w = decode_window (window); 6232 struct window *w = decode_live_window (window);
5997 return Fcons (w->left_margin_cols, w->right_margin_cols); 6233 return Fcons (w->left_margin_cols, w->right_margin_cols);
5998} 6234}
5999 6235
@@ -6006,8 +6242,8 @@ as nil. */)
6006DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, 6242DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6007 2, 4, 0, 6243 2, 4, 0,
6008 doc: /* Set the fringe widths of window WINDOW. 6244 doc: /* Set the fringe widths of window WINDOW.
6009If WINDOW is nil, set the fringe widths of the currently selected 6245WINDOW must be a live window and defaults to the selected one.
6010window. 6246
6011Second arg LEFT-WIDTH specifies the number of pixels to reserve for 6247Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6012the left fringe. Optional third arg RIGHT-WIDTH specifies the right 6248the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6013fringe width. If a fringe width arg is nil, that means to use the 6249fringe width. If a fringe width arg is nil, that means to use the
@@ -6018,7 +6254,8 @@ outside of the display margins. By default, fringes are drawn between
6018display marginal areas and the text area. */) 6254display marginal areas and the text area. */)
6019 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins) 6255 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6020{ 6256{
6021 struct window *w = decode_window (window); 6257 struct window *w = decode_live_window (window);
6258 int outside = !NILP (outside_margins);
6022 6259
6023 if (!NILP (left_width)) 6260 if (!NILP (left_width))
6024 CHECK_NATNUM (left_width); 6261 CHECK_NATNUM (left_width);
@@ -6029,16 +6266,16 @@ display marginal areas and the text area. */)
6029 if (FRAME_WINDOW_P (WINDOW_XFRAME (w)) 6266 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6030 && (!EQ (w->left_fringe_width, left_width) 6267 && (!EQ (w->left_fringe_width, left_width)
6031 || !EQ (w->right_fringe_width, right_width) 6268 || !EQ (w->right_fringe_width, right_width)
6032 || !EQ (w->fringes_outside_margins, outside_margins))) 6269 || w->fringes_outside_margins != outside))
6033 { 6270 {
6034 w->left_fringe_width = left_width; 6271 wset_left_fringe_width (w, left_width);
6035 w->right_fringe_width = right_width; 6272 wset_right_fringe_width (w, right_width);
6036 w->fringes_outside_margins = outside_margins; 6273 w->fringes_outside_margins = outside;
6037 6274
6038 adjust_window_margins (w); 6275 adjust_window_margins (w);
6039 6276
6040 clear_glyph_matrix (w->current_matrix); 6277 clear_glyph_matrix (w->current_matrix);
6041 w->window_end_valid = Qnil; 6278 wset_window_end_valid (w, Qnil);
6042 6279
6043 ++windows_or_buffers_changed; 6280 ++windows_or_buffers_changed;
6044 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6281 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
@@ -6051,16 +6288,16 @@ display marginal areas and the text area. */)
6051DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes, 6288DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
6052 0, 1, 0, 6289 0, 1, 0,
6053 doc: /* Get width of fringes of window WINDOW. 6290 doc: /* Get width of fringes of window WINDOW.
6054If WINDOW is omitted or nil, it defaults to the selected window. 6291WINDOW must be a live window and defaults to the selected one.
6292
6055Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */) 6293Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6056 (Lisp_Object window) 6294 (Lisp_Object window)
6057{ 6295{
6058 struct window *w = decode_window (window); 6296 struct window *w = decode_live_window (window);
6059 6297
6060 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)), 6298 return list3 (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
6061 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)), 6299 make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
6062 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 6300 WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) ? Qt : Qnil);
6063 ? Qt : Qnil), Qnil)));
6064} 6301}
6065 6302
6066 6303
@@ -6072,7 +6309,8 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6072DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, 6309DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6073 Sset_window_scroll_bars, 2, 4, 0, 6310 Sset_window_scroll_bars, 2, 4, 0,
6074 doc: /* Set width and type of scroll bars of window WINDOW. 6311 doc: /* Set width and type of scroll bars of window WINDOW.
6075If window is nil, set scroll bars of the currently selected window. 6312WINDOW must be a live window and defaults to the selected one.
6313
6076Second parameter WIDTH specifies the pixel width for the scroll bar; 6314Second parameter WIDTH specifies the pixel width for the scroll bar;
6077this is automatically adjusted to a multiple of the frame column width. 6315this is automatically adjusted to a multiple of the frame column width.
6078Third parameter VERTICAL-TYPE specifies the type of the vertical scroll 6316Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
@@ -6082,11 +6320,11 @@ If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6082Fourth parameter HORIZONTAL-TYPE is currently unused. */) 6320Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6083 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type) 6321 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6084{ 6322{
6085 struct window *w = decode_window (window); 6323 struct window *w = decode_live_window (window);
6086 6324
6087 if (!NILP (width)) 6325 if (!NILP (width))
6088 { 6326 {
6089 CHECK_NATNUM (width); 6327 CHECK_RANGED_INTEGER (width, 0, INT_MAX);
6090 6328
6091 if (XINT (width) == 0) 6329 if (XINT (width) == 0)
6092 vertical_type = Qnil; 6330 vertical_type = Qnil;
@@ -6101,13 +6339,13 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6101 if (!EQ (w->scroll_bar_width, width) 6339 if (!EQ (w->scroll_bar_width, width)
6102 || !EQ (w->vertical_scroll_bar_type, vertical_type)) 6340 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6103 { 6341 {
6104 w->scroll_bar_width = width; 6342 wset_scroll_bar_width (w, width);
6105 w->vertical_scroll_bar_type = vertical_type; 6343 wset_vertical_scroll_bar_type (w, vertical_type);
6106 6344
6107 adjust_window_margins (w); 6345 adjust_window_margins (w);
6108 6346
6109 clear_glyph_matrix (w->current_matrix); 6347 clear_glyph_matrix (w->current_matrix);
6110 w->window_end_valid = Qnil; 6348 wset_window_end_valid (w, Qnil);
6111 6349
6112 ++windows_or_buffers_changed; 6350 ++windows_or_buffers_changed;
6113 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6351 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
@@ -6120,19 +6358,20 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6120DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars, 6358DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
6121 0, 1, 0, 6359 0, 1, 0,
6122 doc: /* Get width and type of scroll bars of window WINDOW. 6360 doc: /* Get width and type of scroll bars of window WINDOW.
6123If WINDOW is omitted or nil, it defaults to the selected window. 6361WINDOW must be a live window and defaults to the selected one.
6362
6124Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE). 6363Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6125If WIDTH is nil or TYPE is t, the window is using the frame's corresponding 6364If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6126value. */) 6365value. */)
6127 (Lisp_Object window) 6366 (Lisp_Object window)
6128{ 6367{
6129 struct window *w = decode_window (window); 6368 struct window *w = decode_live_window (window);
6130 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6369
6370 return list4 (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6131 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w) 6371 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
6132 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))), 6372 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
6133 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)), 6373 make_number (WINDOW_SCROLL_BAR_COLS (w)),
6134 Fcons (w->vertical_scroll_bar_type, 6374 w->vertical_scroll_bar_type, Qnil);
6135 Fcons (Qnil, Qnil))));
6136} 6375}
6137 6376
6138 6377
@@ -6149,15 +6388,8 @@ optional second arg PIXELS-P means value is measured in pixels. */)
6149 (Lisp_Object window, Lisp_Object pixels_p) 6388 (Lisp_Object window, Lisp_Object pixels_p)
6150{ 6389{
6151 Lisp_Object result; 6390 Lisp_Object result;
6152 struct frame *f; 6391 struct window *w = decode_live_window (window);
6153 struct window *w; 6392 struct frame *f = XFRAME (w->frame);
6154
6155 if (NILP (window))
6156 window = selected_window;
6157 else
6158 CHECK_WINDOW (window);
6159 w = XWINDOW (window);
6160 f = XFRAME (w->frame);
6161 6393
6162 if (FRAME_WINDOW_P (f)) 6394 if (FRAME_WINDOW_P (f))
6163 result = (NILP (pixels_p) 6395 result = (NILP (pixels_p)
@@ -6181,18 +6413,11 @@ result of this rounding.
6181If PIXELS-P is non-nil, the return value is VSCROLL. */) 6413If PIXELS-P is non-nil, the return value is VSCROLL. */)
6182 (Lisp_Object window, Lisp_Object vscroll, Lisp_Object pixels_p) 6414 (Lisp_Object window, Lisp_Object vscroll, Lisp_Object pixels_p)
6183{ 6415{
6184 struct window *w; 6416 struct window *w = decode_live_window (window);
6185 struct frame *f; 6417 struct frame *f = XFRAME (w->frame);
6186 6418
6187 if (NILP (window))
6188 window = selected_window;
6189 else
6190 CHECK_WINDOW (window);
6191 CHECK_NUMBER_OR_FLOAT (vscroll); 6419 CHECK_NUMBER_OR_FLOAT (vscroll);
6192 6420
6193 w = XWINDOW (window);
6194 f = XFRAME (w->frame);
6195
6196 if (FRAME_WINDOW_P (f)) 6421 if (FRAME_WINDOW_P (f))
6197 { 6422 {
6198 int old_dy = w->vscroll; 6423 int old_dy = w->vscroll;
@@ -6296,15 +6521,17 @@ freeze_window_starts (struct frame *f, int freeze_p)
6296/* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2 6521/* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6297 describe the same state of affairs. This is used by Fequal. 6522 describe the same state of affairs. This is used by Fequal.
6298 6523
6299 ignore_positions non-zero means ignore non-matching scroll positions 6524 IGNORE_POSITIONS means ignore non-matching scroll positions
6300 and the like. 6525 and the like.
6301 6526
6302 This ignores a couple of things like the dedication status of 6527 This ignores a couple of things like the dedication status of
6303 window, combination_limit and the like. This might have to be 6528 window, combination_limit and the like. This might have to be
6304 fixed. */ 6529 fixed. */
6305 6530
6306int 6531bool
6307compare_window_configurations (Lisp_Object configuration1, Lisp_Object configuration2, int ignore_positions) 6532compare_window_configurations (Lisp_Object configuration1,
6533 Lisp_Object configuration2,
6534 bool ignore_positions)
6308{ 6535{
6309 register struct save_window_data *d1, *d2; 6536 register struct save_window_data *d1, *d2;
6310 struct Lisp_Vector *sws1, *sws2; 6537 struct Lisp_Vector *sws1, *sws2;
@@ -6420,6 +6647,7 @@ syms_of_window (void)
6420 DEFSYM (Qwindowp, "windowp"); 6647 DEFSYM (Qwindowp, "windowp");
6421 DEFSYM (Qwindow_configuration_p, "window-configuration-p"); 6648 DEFSYM (Qwindow_configuration_p, "window-configuration-p");
6422 DEFSYM (Qwindow_live_p, "window-live-p"); 6649 DEFSYM (Qwindow_live_p, "window-live-p");
6650 DEFSYM (Qwindow_valid_p, "window-valid-p");
6423 DEFSYM (Qwindow_deletable_p, "window-deletable-p"); 6651 DEFSYM (Qwindow_deletable_p, "window-deletable-p");
6424 DEFSYM (Qdelete_window, "delete-window"); 6652 DEFSYM (Qdelete_window, "delete-window");
6425 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window"); 6653 DEFSYM (Qwindow_resize_root_window, "window--resize-root-window");
@@ -6429,10 +6657,11 @@ syms_of_window (void)
6429 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows"); 6657 DEFSYM (Qreplace_buffer_in_windows, "replace-buffer-in-windows");
6430 DEFSYM (Qrecord_window_buffer, "record-window-buffer"); 6658 DEFSYM (Qrecord_window_buffer, "record-window-buffer");
6431 DEFSYM (Qget_mru_window, "get-mru-window"); 6659 DEFSYM (Qget_mru_window, "get-mru-window");
6660 DEFSYM (Qwindow_size, "window-size");
6432 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook"); 6661 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6433 DEFSYM (Qabove, "above"); 6662 DEFSYM (Qabove, "above");
6434 DEFSYM (Qbelow, "below"); 6663 DEFSYM (Qbelow, "below");
6435 DEFSYM (Qauto_buffer_name, "auto-buffer-name"); 6664 DEFSYM (Qclone_of, "clone-of");
6436 6665
6437 staticpro (&Vwindow_list); 6666 staticpro (&Vwindow_list);
6438 6667
@@ -6524,28 +6753,67 @@ This variable takes no effect if `window-combination-limit' is non-nil. */);
6524 Vwindow_combination_resize = Qnil; 6753 Vwindow_combination_resize = Qnil;
6525 6754
6526 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit, 6755 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit,
6527 doc: /* If t, splitting a window makes a new parent window. 6756 doc: /* If non-nil, splitting a window makes a new parent window.
6528If this variable is nil, splitting a window will create a new parent 6757The following values are recognized:
6529window only if the window has no parent window or the window shall 6758
6530become a combination orthogonal to the one it is part of. 6759nil means splitting a window will create a new parent window only if the
6531 6760 window has no parent window or the window shall become part of a
6532If this variable is t, splitting a window always creates a new parent 6761 combination orthogonal to the one it is part of.
6533window. If all splits behave this way, each frame's window tree is a 6762
6534binary tree and every window but the frame's root window has exactly one 6763`window-size' means that splitting a window for displaying a buffer
6535sibling. 6764 makes a new parent window provided `display-buffer' is supposed to
6536 6765 explicitly set the window's size due to the presence of a
6537Other values are reserved for future use. 6766 `window-height' or `window-width' entry in the alist used by
6538 6767 `display-buffer'. Otherwise, this value is handled like nil.
6539The value of this variable is also assigned to the combination limit of 6768
6540the new parent window. The combination limit of a window can be 6769`temp-buffer' means that splitting a window for displaying a temporary
6541retrieved via the function `window-combination-limit' and altered by the 6770 buffer always makes a new parent window. Otherwise, this value is
6542function `set-window-combination-limit'. */); 6771 handled like nil.
6543 Vwindow_combination_limit = Qnil; 6772
6773`display-buffer' means that splitting a window for displaying a buffer
6774 always makes a new parent window. Since temporary buffers are
6775 displayed by the function `display-buffer', this value is stronger
6776 than `temp-buffer'. Splitting a window for other purpose makes a
6777 new parent window only if needed.
6778
6779t means that splitting a window always creates a new parent window. If
6780 all splits behave this way, each frame's window tree is a binary
6781 tree and every window but the frame's root window has exactly one
6782 sibling.
6783
6784Other values are reserved for future use. */);
6785 Vwindow_combination_limit = Qwindow_size;
6786
6787 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters,
6788 doc: /* Alist of persistent window parameters.
6789This alist specifies which window parameters shall get saved by
6790`current-window-configuration' and `window-state-get' and subsequently
6791restored to their previous values by `set-window-configuration' and
6792`window-state-put'.
6793
6794The car of each entry of this alist is the symbol specifying the
6795parameter. The cdr is one of the following:
6796
6797nil means the parameter is neither saved by `window-state-get' nor by
6798`current-window-configuration'.
6799
6800t means the parameter is saved by `current-window-configuration' and,
6801provided its WRITABLE argument is nil, by `window-state-get'.
6802
6803The symbol `writable' means the parameter is saved unconditionally by
6804both `current-window-configuration' and `window-state-get'. Do not use
6805this value for parameters without read syntax (like windows or frames).
6806
6807Parameters not saved by `current-window-configuration' or
6808`window-state-get' are left alone by `set-window-configuration'
6809respectively are not installed by `window-state-put'. */);
6810 Vwindow_persistent_parameters = list1 (Fcons (Qclone_of, Qt));
6544 6811
6545 defsubr (&Sselected_window); 6812 defsubr (&Sselected_window);
6546 defsubr (&Sminibuffer_window); 6813 defsubr (&Sminibuffer_window);
6547 defsubr (&Swindow_minibuffer_p); 6814 defsubr (&Swindow_minibuffer_p);
6548 defsubr (&Swindowp); 6815 defsubr (&Swindowp);
6816 defsubr (&Swindow_valid_p);
6549 defsubr (&Swindow_live_p); 6817 defsubr (&Swindow_live_p);
6550 defsubr (&Swindow_frame); 6818 defsubr (&Swindow_frame);
6551 defsubr (&Sframe_root_window); 6819 defsubr (&Sframe_root_window);
@@ -6606,7 +6874,6 @@ function `set-window-combination-limit'. */);
6606 defsubr (&Srun_window_configuration_change_hook); 6874 defsubr (&Srun_window_configuration_change_hook);
6607 defsubr (&Sselect_window); 6875 defsubr (&Sselect_window);
6608 defsubr (&Sforce_window_update); 6876 defsubr (&Sforce_window_update);
6609 defsubr (&Stemp_output_buffer_show);
6610 defsubr (&Ssplit_window_internal); 6877 defsubr (&Ssplit_window_internal);
6611 defsubr (&Sscroll_up); 6878 defsubr (&Sscroll_up);
6612 defsubr (&Sscroll_down); 6879 defsubr (&Sscroll_down);